Skip to content

Commit 1dfa54a

Browse files
Attribute @draw:concave of <draw:regular-polygon> does not have the datatype boolean, but only 'true' and 'false' as explicit values. Added method to assume in this case the datatype Boolean
1 parent 1d1c7f7 commit 1dfa54a

File tree

5 files changed

+68
-60
lines changed

5 files changed

+68
-60
lines changed

generator/schema2template/src/main/java/schema2template/grammar/OdfModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ public String getDefaultAttributeValue(String attributeName, String parentElemen
162162
if (defaultValueByElementParents == null) {
163163
return null;
164164
}
165-
// Not for ODF, but need extension if there are two attributes (same name)
166-
// with different defaults in same named parent?
165+
// Not for ODF, but need extension if there are two attributes (same name)
166+
// with different defaults in same named parent?
167167
defaultValue = defaultValueByElementParents.get(parentElementName);
168168
if (defaultValue == null) {
169169
defaultValue = defaultValueByElementParents.get(ALL_ELEMENTS);

generator/schema2template/src/main/java/schema2template/grammar/XMLModel.java

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package schema2template.grammar;
2525

26+
import static schema2template.grammar.PuzzlePiece.NAME_VISITOR;
27+
2628
import com.sun.msv.grammar.Expression;
2729
import com.sun.msv.grammar.Grammar;
2830
import com.sun.msv.grammar.NameClassAndExpression;
@@ -45,7 +47,6 @@
4547
import org.apache.xml.serialize.OutputFormat;
4648
import org.apache.xml.serialize.XMLSerializer;
4749
import org.xml.sax.SAXException;
48-
import static schema2template.grammar.PuzzlePiece.NAME_VISITOR;
4950

5051
/**
5152
* The most important model, the first access to the XML Schema information.
@@ -322,18 +323,21 @@ public PuzzlePiece getAttribute(String qName, String qParentName) {
322323
PuzzlePiece attribute = null;
323324
if (attributes == null) {
324325
return null;
325-
}else {
326-
for (PuzzlePiece ppAttribute : attributes.withMultiples().getCollection()) {
327-
// If there is more than one name for this expression, create more than one PuzzlePiece
328-
for (PuzzlePiece ppElement : ppAttribute.getParents().getCollection()) {
329-
List<String> names =
330-
(List<String>) ((NameClassAndExpression) ppElement.getExpression()).getNameClass().visit(NAME_VISITOR);
331-
if(names != null && names.contains(qParentName)){
332-
attribute = ppAttribute;
333-
break;
334-
}
335-
}
326+
} else {
327+
for (PuzzlePiece ppAttribute : attributes.withMultiples().getCollection()) {
328+
// If there is more than one name for this expression, create more than one PuzzlePiece
329+
for (PuzzlePiece ppElement : ppAttribute.getParents().getCollection()) {
330+
List<String> names =
331+
(List<String>)
332+
((NameClassAndExpression) ppElement.getExpression())
333+
.getNameClass()
334+
.visit(NAME_VISITOR);
335+
if (names != null && names.contains(qParentName)) {
336+
attribute = ppAttribute;
337+
break;
338+
}
336339
}
340+
}
337341
}
338342
return attribute;
339343
}
@@ -347,34 +351,38 @@ public PuzzlePiece getAttribute(String qName, String qParentName) {
347351
* @return String of given Datatype
348352
*/
349353
public String getAttributeDataType(String qName, String qParentName) {
350-
String dataType = "String";
351-
PuzzlePiece attr = getAttribute(qName, qParentName);
352-
Collection<PuzzlePiece> d = attr.getDatatypes().getCollection();
353-
Boolean isBoolean = null;
354-
if(d.size() == 1){
355-
dataType = d.iterator().next().getQName();
356-
}else if(!d.isEmpty()){
357-
System.out.println("There are multiple datatypes!");
358-
} else {
359-
Iterator valueIterator = attr.getValues().getCollection().iterator();
360-
361-
while(valueIterator.hasNext()){
362-
String value = valueIterator.next().toString();
363-
if(value.equals("true") || value.equals("false")){
364-
isBoolean = Boolean.TRUE;
365-
}else{
366-
isBoolean = null;
367-
break;
368-
}
369-
}
370-
if(isBoolean != null && isBoolean){
371-
dataType = "Boolean";
372-
}
354+
String dataType = "String";
355+
PuzzlePiece attr = getAttribute(qName, qParentName);
356+
Collection<PuzzlePiece> d = attr.getDatatypes().getCollection();
357+
Boolean isBoolean = null;
358+
if (d.size() == 1) {
359+
dataType = d.iterator().next().getQName();
360+
} else if (!d.isEmpty()) {
361+
System.err.println(
362+
"\n***********\nThere are multiple datatypes for attribute '" + qName + "'\n");
363+
Iterator dataTypesIter = d.iterator();
364+
while (dataTypesIter.hasNext()) {
365+
System.err.println(dataTypesIter.next().toString());
373366
}
374-
return dataType;
367+
} else { // @draw:concave just uses 'false' and 'true' without datatype
368+
Iterator valueIterator = attr.getValues().getCollection().iterator();
369+
370+
while (valueIterator.hasNext()) {
371+
String value = valueIterator.next().toString();
372+
if (value.equals("true") || value.equals("false")) {
373+
isBoolean = Boolean.TRUE;
374+
} else {
375+
isBoolean = null;
376+
break;
377+
}
378+
}
379+
if (isBoolean != null && isBoolean) {
380+
dataType = "Boolean";
381+
}
382+
}
383+
return dataType;
375384
}
376385

377-
378386
/**
379387
* Get attribute by tag name and hash code. The hash code distincts Attributes sharing the same
380388
* tag name.

generator/schema2template/src/test/resources/test-reference/odf/generation/odfdom-java/odf-schema-1.0/org/odftoolkit/odfdom/dom/element/draw/DrawRegularPolygonElement.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,25 @@ public OdfName getOdfName() {
7979
*
8080
* Attribute is mandatory.
8181
*
82-
* @return - the <code>String</code> , the value or <code>null</code>, if the attribute is not set and no default value defined.
82+
* @return - the <code>Boolean</code> , the value or <code>null</code>, if the attribute is not set and no default value defined.
8383
*/
84-
public String getDrawConcaveAttribute() {
84+
public Boolean getDrawConcaveAttribute() {
8585
DrawConcaveAttribute attr = (DrawConcaveAttribute) getOdfAttribute(OdfDocumentNamespace.DRAW, "concave");
86-
if (attr != null) {
87-
return String.valueOf(attr.getValue());
86+
if (attr != null && !attr.getValue().isEmpty()) {
87+
return Boolean.valueOf(attr.booleanValue());
8888
}
8989
return null;
9090
}
9191

9292
/**
9393
* Sets the value of ODFDOM attribute representation <code>DrawConcaveAttribute</code> , See {@odf.attribute draw:concave}
9494
*
95-
* @param drawConcaveValue The type is <code>String</code>
95+
* @param drawConcaveValue The type is <code>Boolean</code>
9696
*/
97-
public void setDrawConcaveAttribute(String drawConcaveValue) {
97+
public void setDrawConcaveAttribute(Boolean drawConcaveValue) {
9898
DrawConcaveAttribute attr = new DrawConcaveAttribute((OdfFileDom) this.ownerDocument);
9999
setOdfAttribute(attr);
100-
attr.setValue(drawConcaveValue);
100+
attr.setBooleanValue(drawConcaveValue.booleanValue());
101101
}
102102

103103
/**

generator/schema2template/src/test/resources/test-reference/odf/generation/odfdom-java/odf-schema-1.1/org/odftoolkit/odfdom/dom/element/draw/DrawRegularPolygonElement.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,25 @@ public void setDrawCaptionIdAttribute(String drawCaptionIdValue) {
106106
*
107107
* Attribute is mandatory.
108108
*
109-
* @return - the <code>String</code> , the value or <code>null</code>, if the attribute is not set and no default value defined.
109+
* @return - the <code>Boolean</code> , the value or <code>null</code>, if the attribute is not set and no default value defined.
110110
*/
111-
public String getDrawConcaveAttribute() {
111+
public Boolean getDrawConcaveAttribute() {
112112
DrawConcaveAttribute attr = (DrawConcaveAttribute) getOdfAttribute(OdfDocumentNamespace.DRAW, "concave");
113-
if (attr != null) {
114-
return String.valueOf(attr.getValue());
113+
if (attr != null && !attr.getValue().isEmpty()) {
114+
return Boolean.valueOf(attr.booleanValue());
115115
}
116116
return null;
117117
}
118118

119119
/**
120120
* Sets the value of ODFDOM attribute representation <code>DrawConcaveAttribute</code> , See {@odf.attribute draw:concave}
121121
*
122-
* @param drawConcaveValue The type is <code>String</code>
122+
* @param drawConcaveValue The type is <code>Boolean</code>
123123
*/
124-
public void setDrawConcaveAttribute(String drawConcaveValue) {
124+
public void setDrawConcaveAttribute(Boolean drawConcaveValue) {
125125
DrawConcaveAttribute attr = new DrawConcaveAttribute((OdfFileDom) this.ownerDocument);
126126
setOdfAttribute(attr);
127-
attr.setValue(drawConcaveValue);
127+
attr.setBooleanValue(drawConcaveValue.booleanValue());
128128
}
129129

130130
/**

generator/schema2template/src/test/resources/test-reference/odf/generation/odfdom-java/odf-schema-1.2/org/odftoolkit/odfdom/dom/element/draw/DrawRegularPolygonElement.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,25 @@ public void setDrawCaptionIdAttribute(String drawCaptionIdValue) {
106106
*
107107
* Attribute is mandatory.
108108
*
109-
* @return - the <code>String</code> , the value or <code>null</code>, if the attribute is not set and no default value defined.
109+
* @return - the <code>Boolean</code> , the value or <code>null</code>, if the attribute is not set and no default value defined.
110110
*/
111-
public String getDrawConcaveAttribute() {
111+
public Boolean getDrawConcaveAttribute() {
112112
DrawConcaveAttribute attr = (DrawConcaveAttribute) getOdfAttribute(OdfDocumentNamespace.DRAW, "concave");
113-
if (attr != null) {
114-
return String.valueOf(attr.getValue());
113+
if (attr != null && !attr.getValue().isEmpty()) {
114+
return Boolean.valueOf(attr.booleanValue());
115115
}
116116
return null;
117117
}
118118

119119
/**
120120
* Sets the value of ODFDOM attribute representation <code>DrawConcaveAttribute</code> , See {@odf.attribute draw:concave}
121121
*
122-
* @param drawConcaveValue The type is <code>String</code>
122+
* @param drawConcaveValue The type is <code>Boolean</code>
123123
*/
124-
public void setDrawConcaveAttribute(String drawConcaveValue) {
124+
public void setDrawConcaveAttribute(Boolean drawConcaveValue) {
125125
DrawConcaveAttribute attr = new DrawConcaveAttribute((OdfFileDom) this.ownerDocument);
126126
setOdfAttribute(attr);
127-
attr.setValue(drawConcaveValue);
127+
attr.setBooleanValue(drawConcaveValue.booleanValue());
128128
}
129129

130130
/**

0 commit comments

Comments
 (0)