This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch coheigea/gst in repository https://gitbox.apache.org/repos/asf/ws-xmlschema.git
commit d0e51fff0ec36af9433f0f0f91bf724b7afc4713 Author: Colm O hEigeartaigh <[email protected]> AuthorDate: Thu Sep 24 14:49:07 2026 +0100 Read "1" and surrounding whitespace as true for xs:boolean attributes --- .../apache/ws/commons/schema/SchemaBuilder.java | 36 ++++++++++------------ .../apache/ws/commons/schema/XmlSchemaFacet.java | 5 +-- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java b/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java index c4ff118e..8aa39151 100644 --- a/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java +++ b/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java @@ -195,6 +195,17 @@ public class SchemaBuilder { } } + /** + * Reads an xs:boolean attribute value. XML Schema allows "1" as well as "true", and surrounding + * whitespace, so taking only "true" read abstract="1" or nillable=" true " as false and dropped + * the setting from the model. As before, "true" is accepted in any case, and a value that is + * not a boolean at all is read as false. + */ + static boolean parseBoolean(String value) { + final String trimmed = value.trim(); + return "true".equalsIgnoreCase(trimmed) || "1".equals(trimmed); + } + private static int getIntProperty(String name, int defaultValue) { try { Integer value = Integer.getInteger(name); @@ -437,20 +448,10 @@ public class SchemaBuilder { ct.setFinal(XmlSchemaDerivationMethod.schemaValueOf(finalstr)); } if (complexEl.hasAttribute("abstract")) { - String abs = complexEl.getAttribute("abstract"); - if (abs.equalsIgnoreCase("true")) { - ct.setAbstract(true); - } else { - ct.setAbstract(false); - } + ct.setAbstract(parseBoolean(complexEl.getAttribute("abstract"))); } if (complexEl.hasAttribute("mixed")) { - String mixed = complexEl.getAttribute("mixed"); - if (mixed.equalsIgnoreCase("true")) { - ct.setMixed(true); - } else { - ct.setMixed(false); - } + ct.setMixed(parseBoolean(complexEl.getAttribute("mixed"))); } // process extra attributes and elements @@ -562,7 +563,7 @@ public class SchemaBuilder { } if (el.hasAttribute("abstract")) { - element.setAbstractElement(Boolean.valueOf(el.getAttribute("abstract")).booleanValue()); + element.setAbstractElement(parseBoolean(el.getAttribute("abstract"))); } if (el.hasAttribute("block")) { @@ -586,7 +587,7 @@ public class SchemaBuilder { } if (el.hasAttribute("nillable")) { - element.setNillable(Boolean.valueOf(el.getAttribute("nillable")).booleanValue()); + element.setNillable(parseBoolean(el.getAttribute("nillable"))); } if (el.hasAttribute("substitutionGroup")) { @@ -1313,12 +1314,7 @@ public class SchemaBuilder { } if (complexEl.hasAttribute("mixed")) { - String mixed = complexEl.getAttribute("mixed"); - if (mixed.equalsIgnoreCase("true")) { - complexContent.setMixed(true); - } else { - complexContent.setMixed(false); - } + complexContent.setMixed(parseBoolean(complexEl.getAttribute("mixed"))); } return complexContent; diff --git a/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaFacet.java b/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaFacet.java index 6a1000e8..ba5d6a7a 100644 --- a/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaFacet.java +++ b/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaFacet.java @@ -45,10 +45,7 @@ public abstract class XmlSchemaFacet extends XmlSchemaAnnotated { public static XmlSchemaFacet construct(Element el) { String name = el.getLocalName(); - boolean fixed = false; - if (el.getAttribute("fixed").equals("true")) { - fixed = true; - } + boolean fixed = SchemaBuilder.parseBoolean(el.getAttribute("fixed")); XmlSchemaFacet facet; if ("enumeration".equals(name)) { facet = new XmlSchemaEnumerationFacet();
