Example usage for javax.xml.stream XMLOutputFactory createXMLStreamWriter

List of usage examples for javax.xml.stream XMLOutputFactory createXMLStreamWriter

Introduction

In this page you can find the example usage for javax.xml.stream XMLOutputFactory createXMLStreamWriter.

Prototype

public abstract XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException;

Source Link

Document

Create a new XMLStreamWriter that writes to a JAXP result.

Usage

From source file:org.apache.axiom.om.util.StAXUtils.java

public static XMLStreamWriter createXMLStreamWriter(StAXWriterConfiguration configuration, final Writer out)
        throws XMLStreamException {
    final XMLOutputFactory outputFactory = getXMLOutputFactory(configuration);
    try {//  www.ja  va2 s . c om
        XMLStreamWriter writer = (XMLStreamWriter) AccessController
                .doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return outputFactory.createXMLStreamWriter(out);
                    }
                });
        if (isDebugEnabled) {
            log.debug("XMLStreamWriter is " + writer.getClass().getName());
        }
        return writer;
    } catch (PrivilegedActionException pae) {
        throw (XMLStreamException) pae.getException();
    }
}

From source file:org.apache.flex.compiler.config.Configuration.java

/**
 * @return Metadata XML string./*from  www  .  j  a  va  2 s  . c om*/
 */
private final String generateMetadata() {
    final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    assert xmlOutputFactory != null : "Expect XMLOutputFactory implementation.";
    final StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlWriter = null;

    try {
        xmlWriter = new XMLFormatter(xmlOutputFactory.createXMLStreamWriter(stringWriter));
        xmlWriter.writeStartDocument();

        xmlWriter.writeStartElement("rdf", "RDF", RDF_URI);
        xmlWriter.setPrefix("rdf", RDF_URI);
        xmlWriter.writeNamespace("rdf", RDF_URI);

        // write rdf:Description
        xmlWriter.writeStartElement(RDF_URI, "Description");
        xmlWriter.setPrefix("dc", DC_URI);
        xmlWriter.setPrefix(VersionInfo.COMPILER_NAMESPACE_PREFIX, VersionInfo.COMPILER_NAMESPACE_URI);
        xmlWriter.writeNamespace("dc", DC_URI);
        xmlWriter.writeNamespace(VersionInfo.COMPILER_NAMESPACE_PREFIX, VersionInfo.COMPILER_NAMESPACE_URI);

        // write dc:format
        xmlWriter.writeStartElement(DC_URI, "format");
        xmlWriter.writeCharacters("application/x-shockwave-flash");
        xmlWriter.writeEndElement();

        if (isFlex()) {
            // write localizedTitles
            writeMap(xmlWriter, DC_URI, "description", localizedDescriptions);

            // write localizedDescription
            writeMap(xmlWriter, DC_URI, "title", localizedTitles);

            // write publisher
            writeCollection(xmlWriter, DC_URI, "publisher", publishers);

            // write creators
            writeCollection(xmlWriter, DC_URI, "creator", creators);

            // write contributor
            writeCollection(xmlWriter, DC_URI, "contributor", contributors);

            // write language
            writeCollection(xmlWriter, DC_URI, "language", langs);

            // write date
            writeDate(xmlWriter);
        }

        // write compiledBy
        writeCompiledBy(xmlWriter);

        // write
        xmlWriter.writeEndElement(); // Description
        xmlWriter.writeEndDocument();
    } catch (XMLStreamException e) {
        return "";
    }

    return stringWriter.toString();
}

From source file:org.apache.maven.dotnet.stylecop.StyleCopGenerator.java

/**
 * Generates the msbuild configuration for a project.
 * //from   www. j  a va  2  s . c  om
 * @param stream
 */
public void generate(OutputStream stream) {
    Project project = new Project();

    // Properties used
    PropertyGroup propGroup = new PropertyGroup();
    propGroup.setProjectRoot(toWindowsPath(projectRoot));
    propGroup.setStyleCopRoot(toWindowsPath(styleCopRoot));

    // StyleCop task definition
    UsingTask usingTask = new UsingTask();
    usingTask.setAssemblyFile("$(StyleCopRoot)\\Microsoft.StyleCop.dll");
    usingTask.setTaskName("StyleCopTask");

    // StyleCop execution target
    Target target = new Target();
    target.setName("CheckStyle");
    StyleCopTask task = new StyleCopTask();
    task.setFullPath(toWindowsPath(visualSolution));
    task.setOutputFile(toWindowsPath(output));
    task.setSettingsFile(toWindowsPath(settings));
    task.setSourceFiles("@(SourceAnalysisFiles);@(CSFile)");

    // Builds the creation item
    CreateItem createItem = new CreateItem();
    createItem.setInclude("%(Project.RootDir)%(Project.Directory)**\\*.cs");
    ItemOutput itemOutput = new ItemOutput();
    itemOutput.setTaskParameter("Include");
    itemOutput.setItemName("SourceAnalysisFiles");
    createItem.setOutput(itemOutput);

    //
    ItemGroup group = new ItemGroup();
    // Adds all the projects files
    for (File visualProject : visualProjects) {
        if (visualProject.isDirectory()) {
            group.addCsFiles(visualProject + "\\**\\*.cs");
        } else {
            group.addProject(toWindowsPath(visualProject));
        }
    }

    // Populates the task
    target.setItem(createItem);
    target.setStyleCopTask(task);

    // Finishes the project
    project.setUsingTask(usingTask);
    project.setPropertyGroup(propGroup);
    project.setDefaultTargets("CheckStyle");
    project.setToolsVersion("3.5");
    project.addItem(group);
    project.addTarget(target);

    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    StringWriter writer = new StringWriter();
    XMLStreamWriter xtw = null;
    try {
        // Gets control of the generated namespaces
        xtw = xof.createXMLStreamWriter(writer);
        xtw.setNamespaceContext(new NamespaceContext() {

            @Override
            public Iterator getPrefixes(String arg0) {
                return null;
            }

            @Override
            public String getPrefix(String arg0) {
                if (STYLE_COP_NAMESPACE.equals(arg0)) {
                    return "stylecop";
                }
                return null;
            }

            @Override
            public String getNamespaceURI(String arg0) {
                return null;
            }
        });
        // Establish a jaxb context
        JAXBContext jc = JAXBContext.newInstance(Project.class);

        // Get a marshaller
        Marshaller m = jc.createMarshaller();

        // Enable formatted xml output
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        // Marshal to system output: java to xml
        m.marshal(project, xtw);
    } catch (Exception e) {
        log.debug("Generation error", e);
    }
    String xmlContent = writer.toString();

    // Due to a bug of missing feature in JAXB, I could not generate an XML file
    // having the default XML namespace
    // of stylecop (it defines the objects in a namespace that is not the
    // default).
    // The problem is that MSBuild is non fully XML compliant and requires the
    // stylecop namespace as being explicitely
    // the default one for the file. This is achived by hand-made replacement in
    // hte generated file, hoping for something
    // more robust later.
    String temp = StringUtils.replace(xmlContent, "xmlns=\"\"", "xmlns=\"" + STYLE_COP_NAMESPACE + "\"");
    String result = StringUtils.replace(temp, "stylecop:Project", "Project");
    PrintWriter outputWriter = new PrintWriter(stream);
    outputWriter.print(result);
    outputWriter.flush();
}

From source file:org.asimba.wa.integrationtest.saml2.model.AuthnRequest.java

/**
 * Get String with the SAML2 AuthnRequest message
 * @param format -1=plain, 1=base64/*from   ww  w .  j  ava2  s .  c  o  m*/
 * @return
 * @throws XMLStreamException
 * @throws IOException
 */
public String getRequest(int format) throws XMLStreamException, IOException {
    _logger.info("For ID: " + this._id);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Deflater compresser = new Deflater(Deflater.BEST_COMPRESSION, true);
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(baos, compresser);
    StringWriter sw = new StringWriter();

    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = null;

    // ugly but effective:
    if (format == base64) {
        writer = factory.createXMLStreamWriter(deflaterOutputStream);
    } else {
        writer = factory.createXMLStreamWriter(sw);
    }

    writer.writeStartElement("samlp", "AuthnRequest", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");

    writer.writeAttribute("ID", _id);
    writer.writeAttribute("Version", "2.0");
    writer.writeAttribute("IssueInstant", this._issueInstant);
    writer.writeAttribute("ProtocolBinding", "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
    writer.writeAttribute("AssertionConsumerServiceURL", _acsUrl);

    writeIssuer(writer);

    writeNameIDPolicy(writer);

    writeRequestedAuthnContext(writer);

    writer.writeEndElement();
    writer.flush();

    if (format == base64) {
        deflaterOutputStream.close();
        byte[] bain = baos.toByteArray();
        byte[] encoded = Base64.encodeBase64(bain, false);
        String result = new String(encoded, Charset.forName("UTF-8"));

        return result;
    } else {
        return sw.toString();
    }

}

From source file:org.asimba.wa.integrationtest.saml2.model.Response.java

/**
 * Build response based on current state.<br/>
 * Only do Base64-encoding of the XML-document -- no deflating whatsoever may be done.
 * /*w w  w  .  j a v a 2s  .c o m*/
 * @return
 * @throws XMLStreamException 
 */
public String getResponse(int format) throws XMLStreamException {
    _logger.info("For ID: " + getId());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    StringWriter sw = new StringWriter();

    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = null;

    // ugly but effective:
    if (format == base64) {
        writer = factory.createXMLStreamWriter(baos);
    } else {
        writer = factory.createXMLStreamWriter(sw);
    }

    writer.writeStartElement("saml2p", "Response", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeNamespace("saml2p", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeNamespace("xs", "http://www.w3.org/2001/XMLSchema");

    writer.writeAttribute("Destination", _destination);
    writer.writeAttribute("ID", _id);
    writer.writeAttribute("InResponseTo", _inResponseTo);
    writer.writeAttribute("IssueInstant", _issueInstant);
    writer.writeAttribute("Version", "2.0");

    writeIssuer(writer);

    writeStatus(writer);

    _assertion.writeAssertion(writer);

    writer.writeEndElement(); // SAML2

    writer.flush();

    if (format == base64) {
        byte[] bain = baos.toByteArray();
        byte[] encoded = Base64.encodeBase64(bain, false);
        String result = new String(encoded, Charset.forName("UTF-8"));

        return result;
    } else {
        return sw.toString();
    }
}

From source file:org.corpus_tools.pepper.core.PepperJobImpl.java

/**
 * {@inheritDoc PepperJob#save(URI)}//  ww w . j a v a2  s.  com
 */
@Override
public URI save(URI uri) {
    if (uri == null) {
        throw new PepperException(
                "Cannot save Pepper job '" + getId() + "', because the passed uri is empty. ");
    }
    File file = null;
    if (PepperUtil.FILE_ENDING_PEPPER.equals(uri.fileExtension())) {
        // passed uri already points to a Pepper file
        file = new File(uri.toFileString());
    } else {
        // uri points to a directory
        String directory = uri.toFileString();
        if (!directory.endsWith("/")) {
            directory = directory + "/";
        }
        file = new File(directory + getId() + "." + PepperUtil.FILE_ENDING_PEPPER);
    }
    // create parent directory of file
    if (!file.getParentFile().exists()) {
        if (!file.getParentFile().mkdirs()) {
            if (!file.getParentFile().canWrite()) {
                throw new PepperModuleXMLResourceException(
                        "Cannot create folder '" + file.getParentFile().getAbsolutePath()
                                + "' to store Pepper workflow file, because of an access permission. ");
            } else {
                throw new PepperModuleXMLResourceException("Cannot create folder '"
                        + file.getParentFile().getAbsolutePath() + "' to store Pepper workflow file. ");
            }
        }
        ;
    }

    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    XMLStreamWriter xml;

    try {
        xml = new XMLStreamWriter(xof.createXMLStreamWriter(new FileWriter(file.getAbsolutePath())));
        xml.setPrettyPrint(true);
        xml.writeStartDocument();
        // <pepper>
        xml.writeStartElement(WorkflowDescriptionReader.TAG_PEPEPR_JOB);
        if (getId() != null) {
            xml.writeAttribute(WorkflowDescriptionReader.ATT_ID, getId());
        }
        xml.writeAttribute(WorkflowDescriptionReader.ATT_VERSION, "1.0");
        // <customization> ???
        List<StepDesc> importers = new ArrayList<>();
        List<StepDesc> manipulators = new ArrayList<>();
        List<StepDesc> exporters = new ArrayList<>();
        for (StepDesc step : getStepDescs()) {
            if (MODULE_TYPE.IMPORTER.equals(step.getModuleType())) {
                importers.add(step);
            } else if (MODULE_TYPE.MANIPULATOR.equals(step.getModuleType())) {
                manipulators.add(step);
            } else if (MODULE_TYPE.EXPORTER.equals(step.getModuleType())) {
                exporters.add(step);
            }
        }

        // <importer>
        for (StepDesc step : importers) {
            xml.writeStartElement(WorkflowDescriptionReader.TAG_IMPORTER);
            save_module(xml, step);
            xml.writeEndElement();
        }
        // <manipulator>
        for (StepDesc step : manipulators) {
            xml.writeStartElement(WorkflowDescriptionReader.TAG_MANIPULATOR);
            save_module(xml, step);
            xml.writeEndElement();
        }
        // <exporter>
        for (StepDesc step : exporters) {
            xml.writeStartElement(WorkflowDescriptionReader.TAG_EXPORTER);
            save_module(xml, step);
            xml.writeEndElement();
        }
        xml.writeEndElement();
        xml.writeEndDocument();
        xml.flush();
    } catch (XMLStreamException | IOException e) {
        throw new PepperException("Cannot store Pepper job '" + getId() + "' because of a nested exception. ",
                e);
    }
    return (URI.createFileURI(file.getAbsolutePath()));
}

From source file:org.deegree.geometry.wkbadapter.WKBReaderTest.java

@Test
public void testWKBToGML() throws Exception {
    ICRS crs = CRSManager.lookup("EPSG:4326");

    InputStream is = WKBReaderTest.class.getResourceAsStream(BASE_DIR + "Polygon.wkb");
    byte[] wkb = IOUtils.toByteArray(is);

    Polygon geom = (Polygon) WKBReader.read(wkb, crs);
    assertTrue(geom.getGeometryType() == GeometryType.PRIMITIVE_GEOMETRY);

    StringWriter sw = new StringWriter();
    XMLOutputFactory outFactory = XMLOutputFactory.newInstance();
    outFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);

    XMLStreamWriter writer = outFactory.createXMLStreamWriter(sw);
    writer.setDefaultNamespace(CommonNamespaces.GML3_2_NS);
    GMLStreamWriter gmlSw = GMLOutputFactory.createGMLStreamWriter(GMLVersion.GML_32, writer);
    gmlSw.write(geom);/*from   ww  w.j ava 2s .  c om*/
    writer.close();

    String s = "<gml:posList>5.148530 59.951879 5.134692 59.736522 5.561175 59.728897 5.577771 59.944188 5.148530 59.951879</gml:posList>";
    assertTrue(sw.toString().contains(s));
}

From source file:org.deegree.services.wcs.WCSController.java

private static XMLStreamWriter getXMLStreamWriter(Writer writer) throws XMLStreamException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    return new IndentingXMLStreamWriter(factory.createXMLStreamWriter(writer));
}

From source file:org.deegree.tools.alkis.BackReferenceFixer.java

public static void main(String[] args) {
    Options opts = initOptions();/*from   w  ww  .  j a v  a 2 s.  c  o m*/
    FileInputStream fis = null;
    FileOutputStream fos = null;
    try {
        CommandLine line = new PosixParser().parse(opts, args);
        String input = line.getOptionValue('i');
        String output = line.getOptionValue('o');
        String schema = line.getOptionValue('s');
        fis = new FileInputStream(input);
        fos = new FileOutputStream(output);
        XMLInputFactory xifac = XMLInputFactory.newInstance();
        XMLOutputFactory xofac = XMLOutputFactory.newInstance();
        XMLStreamReader xreader = xifac.createXMLStreamReader(input, fis);
        IndentingXMLStreamWriter xwriter = new IndentingXMLStreamWriter(xofac.createXMLStreamWriter(fos));
        GMLStreamReader reader = GMLInputFactory.createGMLStreamReader(GMLVersion.GML_32, xreader);

        AppSchema appSchema = new GMLAppSchemaReader(null, null, schema).extractAppSchema();
        reader.setApplicationSchema(appSchema);

        GMLStreamWriter writer = GMLOutputFactory.createGMLStreamWriter(GMLVersion.GML_32, xwriter);
        XlinkedObjectsHandler handler = new XlinkedObjectsHandler(true, null, new GmlXlinkOptions());
        writer.setReferenceResolveStrategy(handler);

        QName prop = new QName(ns601, "dientZurDarstellungVon");

        Map<String, List<String>> refs = new HashMap<String, List<String>>();
        Map<String, List<String>> types = new HashMap<String, List<String>>();
        Map<String, String> bindings = null;

        for (Feature f : reader.readFeatureCollectionStream()) {
            if (bindings == null) {
                bindings = f.getType().getSchema().getNamespaceBindings();
            }
            for (Property p : f.getProperties(prop)) {
                FeatureReference ref = (FeatureReference) p.getValue();
                List<String> list = refs.get(ref.getId());
                if (list == null) {
                    list = new ArrayList<String>();
                    refs.put(ref.getId(), list);
                }
                list.add(f.getId());
                list = types.get(ref.getId());
                if (list == null) {
                    list = new ArrayList<String>();
                    types.put(ref.getId(), list);
                }
                list.add("inversZu_dientZurDarstellungVon_" + f.getType().getName().getLocalPart());
            }
        }

        QName[] inversePropNames = new QName[] {
                new QName(ns601, "inversZu_dientZurDarstellungVon_AP_Darstellung"),
                new QName(ns601, "inversZu_dientZurDarstellungVon_AP_LTO"),
                new QName(ns601, "inversZu_dientZurDarstellungVon_AP_PTO"),
                new QName(ns601, "inversZu_dientZurDarstellungVon_AP_FPO"),
                new QName(ns601, "inversZu_dientZurDarstellungVon_AP_KPO_3D"),
                new QName(ns601, "inversZu_dientZurDarstellungVon_AP_LPO"),
                new QName(ns601, "inversZu_dientZurDarstellungVon_AP_PPO") };

        reader.close();
        fis.close();
        writer.setNamespaceBindings(bindings);

        fis = new FileInputStream(input);
        xreader = xifac.createXMLStreamReader(input, fis);
        reader = GMLInputFactory.createGMLStreamReader(GMLVersion.GML_32, xreader);
        reader.setApplicationSchema(appSchema);

        if (bindings != null) {
            for (Map.Entry<String, String> e : bindings.entrySet()) {
                if (!e.getKey().isEmpty()) {
                    xwriter.setPrefix(e.getValue(), e.getKey());
                }
            }
        }
        xwriter.writeStartDocument();
        xwriter.setPrefix("gml", "http://www.opengis.net/gml/3.2");
        xwriter.writeStartElement("http://www.opengis.net/gml/3.2", "FeatureCollection");
        xwriter.writeNamespace("gml", "http://www.opengis.net/gml/3.2");

        GmlDocumentIdContext ctx = new GmlDocumentIdContext(GMLVersion.GML_32);

        for (Feature f : reader.readFeatureCollectionStream()) {
            if (refs.containsKey(f.getId())) {
                List<Property> props = new ArrayList<Property>(f.getProperties());
                ListIterator<Property> iter = props.listIterator();
                String name = iter.next().getName().getLocalPart();
                while (name.equals("lebenszeitintervall") || name.equals("modellart") || name.equals("anlass")
                        || name.equals("zeigtAufExternes") || name.equals("istTeilVon")
                        || name.equals("identifier")) {
                    if (iter.hasNext()) {
                        name = iter.next().getName().getLocalPart();
                    } else {
                        break;
                    }
                }
                if (iter.hasPrevious()) {
                    iter.previous();
                }
                for (QName propName : inversePropNames) {
                    Iterator<String> idIter = refs.get(f.getId()).iterator();
                    Iterator<String> typeIter = types.get(f.getId()).iterator();
                    while (idIter.hasNext()) {
                        String id = idIter.next();
                        if (typeIter.next().equals(propName.getLocalPart())) {
                            PropertyType pt = f.getType().getPropertyDeclaration(propName);
                            Property p = new GenericProperty(pt, new FeatureReference(ctx, "#" + id, null));
                            iter.add(p);
                        }
                    }
                }
                f.setProperties(props);

            }
            xwriter.writeStartElement("http://www.opengis.net/gml/3.2", "featureMember");
            writer.write(f);
            xwriter.writeEndElement();
        }

        xwriter.writeEndElement();
        xwriter.close();
    } catch (Throwable e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(fis);
        IOUtils.closeQuietly(fos);
    }
}

From source file:org.deegree.tools.services.wms.FeatureTypesToLayerTree.java

/**
 * @param args/*from w  ww  .ja  v  a  2  s  .c o  m*/
 */
public static void main(String[] args) {
    Options options = initOptions();

    // for the moment, using the CLI API there is no way to respond to a help argument; see
    // https://issues.apache.org/jira/browse/CLI-179
    if (args.length == 0 || (args.length > 0 && (args[0].contains("help") || args[0].contains("?")))) {
        CommandUtils.printHelp(options, FeatureTypesToLayerTree.class.getSimpleName(), null, null);
    }

    XMLStreamWriter out = null;
    try {
        CommandLine line = new PosixParser().parse(options, args);

        String storeFile = line.getOptionValue("f");
        String nm = new File(storeFile).getName();
        String storeId = nm.substring(0, nm.length() - 4);

        FileOutputStream os = new FileOutputStream(line.getOptionValue("o"));
        XMLOutputFactory fac = XMLOutputFactory.newInstance();
        out = new IndentingXMLStreamWriter(fac.createXMLStreamWriter(os));
        out.setDefaultNamespace(ns);

        Workspace ws = new DefaultWorkspace(new File("nix"));
        ws.initAll();
        DefaultResourceIdentifier<FeatureStore> identifier = new DefaultResourceIdentifier<FeatureStore>(
                FeatureStoreProvider.class, "unknown");
        ws.add(new DefaultResourceLocation<FeatureStore>(new File(storeFile), identifier));
        ws.prepare(identifier);
        FeatureStore store = ws.init(identifier, null);

        AppSchema schema = store.getSchema();

        // prepare document
        out.writeStartDocument();
        out.writeStartElement(ns, "deegreeWMS");
        out.writeDefaultNamespace(ns);
        out.writeAttribute("configVersion", "0.5.0");
        out.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        out.writeAttribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation",
                "http://www.deegree.org/services/wms http://schemas.deegree.org/wms/0.5.0/wms_configuration.xsd");
        out.writeStartElement(ns, "ServiceConfiguration");

        HashSet<FeatureType> visited = new HashSet<FeatureType>();

        if (schema.getRootFeatureTypes().length == 1) {
            writeLayer(visited, out, schema.getRootFeatureTypes()[0], storeId);
        } else {
            out.writeCharacters("\n");
            out.writeStartElement(ns, "UnrequestableLayer");
            XMLAdapter.writeElement(out, ns, "Title", "Root Layer");
            for (FeatureType ft : schema.getRootFeatureTypes()) {
                writeLayer(visited, out, ft, storeId);
            }
            out.writeEndElement();
            out.writeCharacters("\n");
        }

        out.writeEndElement();
        out.writeEndElement();
        out.writeEndDocument();
    } catch (ParseException exp) {
        System.err.println(Messages.getMessage("TOOL_COMMANDLINE_ERROR", exp.getMessage()));
        CommandUtils.printHelp(options, FeatureTypesToLayerTree.class.getSimpleName(), null, null);
    } catch (ResourceInitException e) {
        LOG.info("The feature store could not be loaded: '{}'", e.getLocalizedMessage());
        LOG.trace("Stack trace:", e);
    } catch (FileNotFoundException e) {
        LOG.info("A file could not be found: '{}'", e.getLocalizedMessage());
        LOG.trace("Stack trace:", e);
    } catch (XMLStreamException e) {
        LOG.info("The XML output could not be written: '{}'", e.getLocalizedMessage());
        LOG.trace("Stack trace:", e);
    } catch (FactoryConfigurationError e) {
        LOG.info("The XML system could not be initialized: '{}'", e.getLocalizedMessage());
        LOG.trace("Stack trace:", e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (XMLStreamException e) {
                LOG.trace("Stack trace:", e);
            }
        }
    }

}