From: <jde...@sv...> - 2006-10-31 04:33:42
|
Author: jdeolive Date: 2006-10-30 20:32:00 -0800 (Mon, 30 Oct 2006) New Revision: 22488 Modified: geotools/trunk/gt/modules/extension/xml-xsd/src/main/java/org/geotools= /xml/impl/ParserHandler.java Log: checking for properties for parsing unknown elements Modified: geotools/trunk/gt/modules/extension/xml-xsd/src/main/java/org/g= eotools/xml/impl/ParserHandler.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/modules/extension/xml-xsd/src/main/java/org/geotool= s/xml/impl/ParserHandler.java 2006-10-31 04:31:37 UTC (rev 22487) +++ geotools/trunk/gt/modules/extension/xml-xsd/src/main/java/org/geotool= s/xml/impl/ParserHandler.java 2006-10-31 04:32:00 UTC (rev 22488) @@ -16,11 +16,15 @@ package org.geotools.xml.impl; =20 import org.eclipse.xsd.XSDElementDeclaration; +import org.eclipse.xsd.XSDFactory; import org.eclipse.xsd.XSDSchema; +import org.eclipse.xsd.XSDSimpleTypeDefinition; import org.eclipse.xsd.util.XSDSchemaLocationResolver; import org.eclipse.xsd.util.XSDSchemaLocator; +import org.eclipse.xsd.util.XSDUtil; import org.geotools.xml.BindingFactory; import org.geotools.xml.Configuration; +import org.geotools.xml.Parser; import org.geotools.xml.SchemaIndex; import org.geotools.xml.Schemas; import org.picocontainer.MutablePicoContainer; @@ -49,7 +53,7 @@ */ public class ParserHandler extends DefaultHandler { /** execution stack **/ - Stack handlers; + protected Stack handlers; =20 /** namespace support **/ NamespaceSupport namespaces; @@ -157,16 +161,25 @@ //TODO: this processing is too loose, do some validation wil= l ya! String[] locations =3D null; =20 - for (int i =3D 0; i < attributes.getLength(); i++) { - String name =3D attributes.getQName(i); + if ( context.getComponentInstance( Parser.Properties.IGNORE_= SCHEMA_LOCATION ) !=3D null ) { + //use the configuration + locations =3D new String[] { + config.getNamespaceURI(), config.getSchemaFileURL()=09 + }; + } + else { + for (int i =3D 0; i < attributes.getLength(); i++) { + String name =3D attributes.getQName(i); =20 - if (name.endsWith("schemaLocation")) { - //create an array of alternating namespace, location= pairs - locations =3D attributes.getValue(i).split(" +"); + if (name.endsWith("schemaLocation")) { + //create an array of alternating namespace, loca= tion pairs + locations =3D attributes.getValue(i).split(" +")= ; =20 - break; + break; + } } } + =20 =20 //look up schema overrides XSDSchemaLocator[] locators =3D findSchemaLocators(); @@ -273,6 +286,24 @@ } } =20 + if ( handler =3D=3D null ) { + //check the parser flag, and just parse it anyways + if( context.getComponentInstance( Parser.Properties.PARSE_UNKNO= WN_ELEMENTS ) !=3D null) { + //create a mock element declaration + XSDElementDeclaration decl =3D XSDFactory.eINSTANCE.createXSDE= lementDeclaration(); + decl.setName( qualifiedName.getLocalPart() ); + decl.setTargetNamespace( qualifiedName.getNamespaceURI() ); + =09 + //set the type to be of string + XSDSimpleTypeDefinition type =3D (XSDSimpleTypeDefinition)=20 + XSDUtil.getSchemaForSchema( XSDUtil.SCHEMA_FOR_SCHEMA_URI_200= 1 ) + .getSimpleTypeIdMap().get( "anyType" ); + =09 + decl.setTypeDefinition( type ); + handler =3D new ElementHandlerImpl( decl, parent, this ); + } + } + =20 if (handler !=3D null) { //add the handler to teh list of children parent.addChildHandler( handler ); |