X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fdata%2FXmlDataConverter.java;fp=org.simantics.xml.sax%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fdata%2FXmlDataConverter.java;h=2b4078d997a2d19334eedad125f39b1b3798af2c;hb=ffd0151a26057732dc81543a12ae2c1bc00af4b4;hp=83cd7af77efd359f66dd234246928f178140f86b;hpb=e6033ad7c18d4c6719da06fa7d8eb08a75d280f9;p=simantics%2Finterop.git diff --git a/org.simantics.xml.sax/src/org/simantics/xml/data/XmlDataConverter.java b/org.simantics.xml.sax/src/org/simantics/xml/data/XmlDataConverter.java index 83cd7af..2b4078d 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/data/XmlDataConverter.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/data/XmlDataConverter.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; @@ -59,8 +60,10 @@ public class XmlDataConverter { String pluginName; - private boolean useElementNSforAttributes = true; // If true, attributes with undefined namespace are written to the same name space as teh element. If false. the attributes are written to the root namespace. - private boolean ignoreAttributeNS = true; // Completely ignore attribute namespaces. When true, all attributes are written to the elements. + private boolean useElementNSforAttributes = true; // If true, attributes with undefined namespace are written to the same name space as the element. If false. the attributes are written to the root namespace. + private boolean ignoreAttributeNS = false; // Completely ignore attribute namespaces. When true, all attributes are written to the elements. + private String ignorePattern = "(\\w)*"; // Ignore attribute namespaces. When pattern exists, and local name of a attribute matches the regexp, the interpreted namespace is ignored. + private boolean nonStandardBooleans = false; // Accept non standard boolean values (True, False). private String[] header; @@ -278,7 +281,7 @@ public class XmlDataConverter { org.w3._2001.xmlschema.Attribute schemaAttribute = updateAttributeType(localAttribute, newType); String attrNs = getNS(attribute, currentNS); - if (!ignoreAttributeNS && attribute.getName().getNamespaceURI().length() > 0) { + if (!ignoreAttributeNs(attribute) && attribute.getName().getNamespaceURI().length() > 0) { // Attribute has explicit ns definition. if (localAttribute.getRef() != null) { // current local attribute is reference, check that the namespaces match @@ -398,7 +401,7 @@ public class XmlDataConverter { } private String getNS(Attribute attribute, String currentNS) { - if (ignoreAttributeNS) + if (ignoreAttributeNs(attribute)) return currentNS; String attrNs = attribute.getName().getNamespaceURI(); if (attrNs.length() == 0) { @@ -411,6 +414,19 @@ public class XmlDataConverter { } + + private boolean ignoreAttributeNs(Attribute attribute) { + if (ignoreAttributeNS) + return true; + + + if (ignorePattern != null) { + return attribute.getName().getLocalPart().matches(ignorePattern); + } + return false; + } + + private org.w3._2001.xmlschema.Attribute addAttribute(Attribute attribute, ComplexType complexType, String currentNS) { String attrNs = getNS(attribute, currentNS); String attrName = attribute.getName().getLocalPart(); @@ -474,8 +490,14 @@ public class XmlDataConverter { private QName getType(String value) { - if ("true".equals(value) || "false".equals(value)) // || "1".equals(value) || "0".equals(value)) - return new QName(SchemaConversionBase.SCHEMA_NS, "boolean"); + if (!nonStandardBooleans) { + if ("true".equals(value) || "false".equals(value)) // || "1".equals(value) || "0".equals(value)) + return new QName(SchemaConversionBase.SCHEMA_NS, "boolean"); + } else { + if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { + return new QName(SchemaConversionBase.SCHEMA_NS, "boolean"); + } + } try { Integer.parseInt(value); return new QName(SchemaConversionBase.SCHEMA_NS, "integer");