From: Marko Luukkainen Date: Mon, 4 Feb 2019 14:16:25 +0000 (+0200) Subject: Attribute namespace handling overrides. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F2642%2F1;p=simantics%2Finterop.git Attribute namespace handling overrides. gitlab #3 Change-Id: I1968b61f24a3227a3a3634580fa63e3123b2c2c0 --- diff --git a/org.simantics.interop/graph.tg b/org.simantics.interop/graph.tg index 1a97030..0aba0de 100644 Binary files a/org.simantics.interop/graph.tg and b/org.simantics.interop/graph.tg differ diff --git a/org.simantics.xml.sax.base/build.properties b/org.simantics.xml.sax.base/build.properties index d7586c2..21a6c98 100644 --- a/org.simantics.xml.sax.base/build.properties +++ b/org.simantics.xml.sax.base/build.properties @@ -1,5 +1,6 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - adapters.xml +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + adapters.xml,\ + scl/ diff --git a/org.simantics.xml.sax.ontology/graph.tg b/org.simantics.xml.sax.ontology/graph.tg index f19a643..863c8e2 100644 Binary files a/org.simantics.xml.sax.ontology/graph.tg and b/org.simantics.xml.sax.ontology/graph.tg differ 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"); diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java index aea2ff0..3aea734 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java @@ -605,6 +605,8 @@ public class OntologyGenerator implements SchemaConversionComponent { return obj.getLibShortName()+"."+getAttributeGroupPrefix()+rel+obj.getName(); case SIMPLE_TYPE: return obj.getLibShortName()+"."+getSimpleTypePrefix()+rel+obj.getName(); + case ATTRIBUTE: + return obj.getLibShortName()+"."+rel+obj.getName(); } } else { SchemaObject o = obj; @@ -626,6 +628,8 @@ public class OntologyGenerator implements SchemaConversionComponent { return obj.getLibShortName()+"."+getAttributeGroupPrefix()+rel+name; case SIMPLE_TYPE: return obj.getLibShortName()+"."+getSimpleTypePrefix()+rel+name; + case ATTRIBUTE: + return obj.getLibShortName()+"."+rel+obj.getName(); } } throw new RuntimeException(); diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java index 51707cb..6621cc7 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java @@ -28,6 +28,7 @@ import org.w3._2001.xmlschema.Any; import org.w3._2001.xmlschema.Attribute; import org.w3._2001.xmlschema.AttributeGroup; import org.w3._2001.xmlschema.ComplexContent; +import org.w3._2001.xmlschema.ComplexRestrictionType; import org.w3._2001.xmlschema.ComplexType; import org.w3._2001.xmlschema.Element; import org.w3._2001.xmlschema.ExplicitGroup; @@ -541,6 +542,13 @@ public final class SchemaConversionBase { QName type = extensionType.getBase(); return type; } + ComplexRestrictionType restriction = complexContent.getRestriction(); + if (restriction != null) + return restriction.getBase(); + } + if (complexType.isMixed()) { + // Handle characters data of mixed ComplexType as String. + return new QName(SCHEMA_NS, "string"); } return null; }