From 346583f7344dc5dce3ebb7b183aaa22c9e2a1aa3 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 4 Feb 2019 16:16:25 +0200 Subject: [PATCH] Attribute namespace handling overrides. gitlab #3 Change-Id: I1968b61f24a3227a3a3634580fa63e3123b2c2c0 --- org.simantics.interop/graph.tg | Bin 2415 -> 2440 bytes org.simantics.xml.sax.base/build.properties | 11 +++--- org.simantics.xml.sax.ontology/graph.tg | Bin 4755 -> 4780 bytes .../simantics/xml/data/XmlDataConverter.java | 34 ++++++++++++++---- .../simantics/xml/sax/OntologyGenerator.java | 4 +++ .../xml/sax/SchemaConversionBase.java | 8 +++++ 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/org.simantics.interop/graph.tg b/org.simantics.interop/graph.tg index 1a9703033a41fca525a444577e186c023895b029..0aba0de3e17771a7e5bb8ea0656adc8f4c9ce6a4 100644 GIT binary patch delta 48 zcmaDa)FG_SnqHJxkio#fzzD+p$%)AssVRCHiNzVo`6;PPKtYCgHgW$q@+EQt05uN{ AV*mgE delta 23 ccmeAWelNtwnqHJxkio#fzzD<)8`Tpz0Y`HM1poj5 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 f19a643af8303f2a21073045636444c33f3a839d..863c8e2f46622c145897094e089d70fbc776b1f3 100644 GIT binary patch delta 48 zcmbQNx<*xi_@% delta 23 dcmZ3ZI$4#EHN7aYAcKK{ff0xqHmbJ@0RTpP1s?za 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; } -- 2.47.1