Hi Ben,
On Thu, Oct 15, 2015 at 12:11 AM, Ben Caradoc-Davies <b...@transient.nz> wrote: > If mixed content is prohibited, would this change your implementation? > What if I forced the "unrestricted content" into a string with no XML elements inside? I could e.g. change the code so that the value is converted to a String and then XML escaped (i.e. < becomes < and so on). I am not sure that unrestrictedContent is a self-explanatory name, but I am > trying to enlarge my understanding. Not sure either, perhaps you can come up with a better name. However, as said above, I could force the content to be simple, in which case I might as well reuse the "simpleContent" special property that is already taken care of by the current code. With this patch, I could successfully encode a swe:DataArray/swe:values >> element with string content. >> > BTW, I did some more debugging and found out why your suggestion of forcing the type of swe:values to gml:CodeType using <targetAttributeNode>gml:CodeType</targetAttributeNode> did not work! Previously, I had done two separate attribute mappings, one setting the <targetAttributeNode> but no value, the second setting the value but without <targetAttributeNode>: <!-- this DID NOT work --> <AttributeMapping> <targetAttribute>om:result/swe:DataArray/swe:values</targetAttribute> <targetAttributeNode>gml:CodeType</targetAttributeNode> </AttributeMapping> <AttributeMapping> <targetAttribute>om:result/swe:DataArray/swe:values</targetAttribute> <encodeIfEmpty>true</encodeIfEmpty> <sourceExpression> <OCQL>array_values</OCQL> </sourceExpression> </AttributeMapping> Now, I created just one attribute mapping with <targetAttributeNode>, and it works: <!-- this works! --> <AttributeMapping> <targetAttribute>om:result/swe:DataArray/swe:values</targetAttribute> <targetAttributeNode>gml:CodeType</targetAttributeNode> <encodeIfEmpty>true</encodeIfEmpty> <sourceExpression> <OCQL>array_values</OCQL> </sourceExpression> </AttributeMapping> OK, so this could be fine as a workaround... but not as a general solution, I believe. Moreover, I tried to set the contents of swe:values to some element-only complex type (i.e. swe:TextPropertyType) and that did not work either: <AttributeMapping> <targetAttribute>om:result/swe:DataArray/swe:values</targetAttribute> <targetAttributeNode>gml:TextPropertyType</targetAttributeNode> </AttributeMapping> <AttributeMapping> <targetAttribute>om:result/swe:DataArray/swe:values/swe:Text/swe:value</targetAttribute> <encodeIfEmpty>true</encodeIfEmpty> <sourceExpression> <OCQL>array_values</OCQL> </sourceExpression> </AttributeMapping> I have a pretty simple fix for that (see attached patch), I can prepare a separate PR if you think it's worth it. -- Best regards, Stefano Costa == GeoServer Professional Services from the experts! Visithttp://goo.gl/it488V for more information. == Dott. Stefano Costa Senior Software Engineer GeoSolutions S.A.S. Via Poggio alle Viti 1187 55054 Massarosa (LU) Italy phone: +39 0584 962313 fax: +39 0584 1660272 http://www.geo-solutions.ithttp://twitter.com/geosolutions_it ------------------------------------------------------- AVVERTENZE AI SENSI DEL D.Lgs. 196/2003 Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003. The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.
diff --git a/modules/extension/xsd/xsd-gml3/src/main/java/org/geotools/gml3/bindings/ComplexSupportXSAnyTypeBinding.java b/modules/extension/xsd/xsd-gml3/src/main/java/org/geotools/gml3/bindings/ComplexSupportXSAnyTypeBinding.java index 81767e3..072ed35 100644 --- a/modules/extension/xsd/xsd-gml3/src/main/java/org/geotools/gml3/bindings/ComplexSupportXSAnyTypeBinding.java +++ b/modules/extension/xsd/xsd-gml3/src/main/java/org/geotools/gml3/bindings/ComplexSupportXSAnyTypeBinding.java @@ -43,6 +43,7 @@ import org.opengis.feature.Attribute; import org.opengis.feature.ComplexAttribute; import org.opengis.feature.GeometryAttribute; import org.opengis.feature.Property; +import org.opengis.feature.type.AttributeType; import org.opengis.feature.type.Name; import org.opengis.feature.type.PropertyDescriptor; import org.opengis.filter.identity.Identifier; @@ -131,12 +132,25 @@ public class ComplexSupportXSAnyTypeBinding extends XSAnyTypeBinding { if(object == null) { return null; } - + + XSDTypeDefinition actualTypeDef = null; + // if object is a complex attribute, take type definition from its type's user data, + // as it may have been overridden (e.g. by using <targetAttributeNode> directive in app-schema) + if (object instanceof ComplexAttribute) { + AttributeType complexAttrType = ((ComplexAttribute) object).getDescriptor().getType(); + actualTypeDef = (XSDTypeDefinition) complexAttrType.getUserData().get( + XSDTypeDefinition.class); + } + // fallback on element's type definition + if (actualTypeDef == null) { + actualTypeDef = element.getTypeDefinition(); + } + List<Object[/* 2 */]> properties = new ArrayList<Object[/* 2 */]>(); - XSDTypeDefinition typeDef = element.getTypeDefinition(); - boolean isAnyType = typeDef.getName() != null && typeDef.getTargetNamespace() != null - && typeDef.getName().equals(XS.ANYTYPE.getLocalPart()) - && typeDef.getTargetNamespace().equals(XS.NAMESPACE); + boolean isAnyType = actualTypeDef.getName() != null + && actualTypeDef.getTargetNamespace() != null + && actualTypeDef.getName().equals(XS.ANYTYPE.getLocalPart()) + && actualTypeDef.getTargetNamespace().equals(XS.NAMESPACE); if (isAnyType) { Collection complexAtts; if (object instanceof Collection) { @@ -175,7 +189,7 @@ public class ComplexSupportXSAnyTypeBinding extends XSAnyTypeBinding { if (object instanceof ComplexAttribute) { ComplexAttribute complex = (ComplexAttribute) object; for (XSDParticle childParticle : (List<XSDParticle>) Schemas.getChildElementParticles( - element.getTypeDefinition(), true)) { + actualTypeDef, true)) { XSDElementDeclaration childElement = (XSDElementDeclaration) childParticle .getContent(); if (childElement.isElementDeclarationReference()) { @@ -240,7 +254,7 @@ public class ComplexSupportXSAnyTypeBinding extends XSAnyTypeBinding { } List<XSDParticle> anyElementParticles = new ArrayList<XSDParticle>(Schemas - .getAnyElementParticles(element.getTypeDefinition())); + .getAnyElementParticles(actualTypeDef)); if (anyElementParticles.size() > 0) { Collection complexAtts = null; if (object instanceof Collection) { @@ -299,7 +313,7 @@ public class ComplexSupportXSAnyTypeBinding extends XSAnyTypeBinding { */ else { List<XSDParticle> elementParticles = new ArrayList<XSDParticle>(Schemas - .getChildElementParticles(element.getTypeDefinition(), false)); + .getChildElementParticles(actualTypeDef, false)); for (Object complex : complexAtts) { if (complex instanceof ComplexAttribute) { ComplexAttribute newComplexAtt = (ComplexAttribute) complex;
------------------------------------------------------------------------------
_______________________________________________ GeoTools-Devel mailing list GeoTools-Devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel