]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Attribute namespace handling overrides. 42/2642/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 4 Feb 2019 14:16:25 +0000 (16:16 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 4 Feb 2019 14:16:25 +0000 (16:16 +0200)
gitlab #3

Change-Id: I1968b61f24a3227a3a3634580fa63e3123b2c2c0

org.simantics.interop/graph.tg
org.simantics.xml.sax.base/build.properties
org.simantics.xml.sax.ontology/graph.tg
org.simantics.xml.sax/src/org/simantics/xml/data/XmlDataConverter.java
org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java

index 1a9703033a41fca525a444577e186c023895b029..0aba0de3e17771a7e5bb8ea0656adc8f4c9ce6a4 100644 (file)
Binary files a/org.simantics.interop/graph.tg and b/org.simantics.interop/graph.tg differ
index d7586c21ab4f398385f66e8422ee9cde9b04139f..21a6c989ec06e97251b51ed84de4cc61ec873c18 100644 (file)
@@ -1,5 +1,6 @@
-source.. = src/\r
-output.. = bin/\r
-bin.includes = META-INF/,\\r
-               .,\\r
-               adapters.xml\r
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               adapters.xml,\
+               scl/
index f19a643af8303f2a21073045636444c33f3a839d..863c8e2f46622c145897094e089d70fbc776b1f3 100644 (file)
Binary files a/org.simantics.xml.sax.ontology/graph.tg and b/org.simantics.xml.sax.ontology/graph.tg differ
index 83cd7af77efd359f66dd234246928f178140f86b..2b4078d997a2d19334eedad125f39b1b3798af2c 100644 (file)
@@ -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");
index aea2ff050d7fa2dceb39e8a84615b3eefe23d8d5..3aea73436367a3ab596f94a5e9854f83c3bb8dc5 100644 (file)
@@ -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();
index 51707cb6d351ca7a04556a8f2404afefd8bab3ed..6621cc716f17853f3549644bf2f6b42cf8cc6d44 100644 (file)
@@ -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;
        }