GMLAppSchemaWriter { public static void export( XMLStreamWriter writer, GMLSchemaInfoSet xsModel, String targetNs, URITranslator translator ) throws XMLStreamException, IOException { Set<String> schemaLocations = new HashSet<>(); List<Pair<String, String>> nsImports = new ArrayList<Pair<String, String>>(); for ( String ns : xsModel.getAppNamespaces() ) { List<String> locations = xsModel.getComponentLocations( ns ); for ( String location : locations ) { if ( !location.startsWith( "http" ) ) schemaLocations.add( location ); String translated = translator.translate( location ); nsImports.add( new Pair<String, String>( ns, translated ) ); } } if ( schemaLocations.size() == 1 ) { try { copyOriginalSchema( writer, schemaLocations ); } catch ( URISyntaxException e ) { writeWrapperDoc( writer, targetNs, nsImports ); } } else { writeWrapperDoc( writer, targetNs, nsImports ); } } GMLAppSchemaWriter( GMLVersion version, String targetNamespace, Map<String, String> importURLs,
                               Map<String, String> prefixToNs ); static void export( XMLStreamWriter writer, GMLSchemaInfoSet xsModel, String targetNs,
                               URITranslator translator ); void export( XMLStreamWriter writer, AppSchema schema ); void export( XMLStreamWriter writer, List<FeatureType> fts ); static final String GML_2_DEFAULT_INCLUDE; static final String GML_30_DEFAULT_INCLUDE; static final String GML_31_DEFAULT_INCLUDE; static final String GML_32_DEFAULT_INCLUDE; }
@Test public void testReexportCiteSF1() throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException, XMLStreamException, FactoryConfigurationError, IOException { String schemaURL = this.getClass().getResource( "../cite/schema/cite-gmlsf1.xsd" ).toString(); GMLAppSchemaReader adapter = new GMLAppSchemaReader( GMLVersion.GML_31, null, schemaURL ); AppSchema schema = adapter.extractAppSchema(); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty( XMLOutputFactory.IS_REPAIRING_NAMESPACES, true ); OutputStream os = new FileOutputStream( System.getProperty( "java.io.tmpdir" ) + File.separatorChar + "out.xml" ); XMLStreamWriter writer = new IndentingXMLStreamWriter( outputFactory.createXMLStreamWriter( os ) ); GMLAppSchemaWriter encoder = new GMLAppSchemaWriter( GMLVersion.GML_31, "http: null, schema.getNamespaceBindings() ); encoder.export( writer, schema ); writer.close(); }
@Test public void testExportSchemaWrappped() throws Exception { String schemaURL = this.getClass().getResource( "../cite/schema/cite-gmlsf1.xsd" ).toURI().toString(); GMLSchemaInfoSet gmlSchemaInfoSet = new GMLSchemaInfoSet( null, schemaURL ); GMLAppSchemaReader adapter = new GMLAppSchemaReader( GMLVersion.GML_31, null, schemaURL ); AppSchema schema = adapter.extractAppSchema(); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty( XMLOutputFactory.IS_REPAIRING_NAMESPACES, true ); ByteArrayOutputStream os = new ByteArrayOutputStream(); XMLStreamWriter writer = new IndentingXMLStreamWriter( outputFactory.createXMLStreamWriter( os ) ); GMLAppSchemaWriter encoder = new GMLAppSchemaWriter( GMLVersion.GML_31, "http: null, schema.getNamespaceBindings() ); encoder.export( writer, gmlSchemaInfoSet, "http: writer.close(); assertThat( the( os.toString() ), hasXPath( "count(/xs:schema/xs:include)", nsContext(), returningANumber(), is( 2.0 ) ) ); }
@Test public void testExportSchema() throws Exception { String schemaURL = this.getClass().getResource( "../cite/schema/cite-gmlsf0.xsd" ).toURI().toString(); GMLSchemaInfoSet gmlSchemaInfoSet = new GMLSchemaInfoSet( null, schemaURL ); GMLAppSchemaReader adapter = new GMLAppSchemaReader( GMLVersion.GML_31, null, schemaURL ); AppSchema schema = adapter.extractAppSchema(); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty( XMLOutputFactory.IS_REPAIRING_NAMESPACES, true ); ByteArrayOutputStream os = new ByteArrayOutputStream(); XMLStreamWriter writer = new IndentingXMLStreamWriter( outputFactory.createXMLStreamWriter( os ) ); GMLAppSchemaWriter encoder = new GMLAppSchemaWriter( GMLVersion.GML_31, "http: null, schema.getNamespaceBindings() ); encoder.export( writer, gmlSchemaInfoSet, "http: writer.close(); System.out.println( os.toString() ); }