List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportOutput(XMLStreamWriter writer, ProcessletOutputImpl output, RequestedOutput requestedOutput) throws XMLStreamException { // "wps:Output" element writer.writeStartElement(WPS_NS, "Output"); ProcessletOutputDefinition outputType = output.getDefinition(); // "ows:Identifier" (minOccurs="1", maxOccurs="1") writer.writeStartElement(OWS_NS, "Identifier"); if (outputType.getIdentifier().getCodeSpace() != null) { writer.writeAttribute("codeSpace", outputType.getIdentifier().getCodeSpace()); }/*from w ww . ja v a 2s. c o m*/ writer.writeCharacters(outputType.getIdentifier().getValue()); writer.writeEndElement(); // "ows:Title" (minOccurs="1", maxOccurs="1") if (outputType.getTitle() != null) { writer.writeStartElement(OWS_NS, "Title"); if (outputType.getTitle().getLang() != null) { writer.writeAttribute("xml:lang", outputType.getTitle().getLang()); } writer.writeCharacters(outputType.getTitle().getValue()); writer.writeEndElement(); } // "ows:Abstract" (minOccurs="0", maxOccurs="1") if (outputType.getAbstract() != null) { writer.writeStartElement(OWS_NS, "Abstract"); if (outputType.getAbstract().getLang() != null) { writer.writeAttribute("xml:lang", outputType.getAbstract().getLang()); } writer.writeCharacters(outputType.getAbstract().getValue()); writer.writeEndElement(); } // "ows:Metadata" (minOccurs="0", maxOccurs="unbounded") if (outputType.getMetadata() != null) { for (ProcessletOutputDefinition.Metadata metadata : outputType.getMetadata()) { writer.writeStartElement(OWS_NS, "Metadata"); if (metadata.getAbout() != null) { writer.writeAttribute("about", metadata.getAbout()); } if (metadata.getHref() != null) { writer.writeAttribute(XLN_NS, "href", metadata.getHref()); } writer.writeEndElement(); } } // choice: "wps:Reference" or "wps:Data" (minOccurs="1", maxOccurs="1") // (ignore asReference for Literal or BoundingBoxOutput) if (!requestedOutput.getAsReference() || output instanceof BoundingBoxOutputImpl || output instanceof LiteralOutputImpl) { writer.writeStartElement(WPS_NS, "Data"); if (output instanceof BoundingBoxOutputImpl) { exportBoundingBoxOutput(writer, (BoundingBoxOutputImpl) output); } else if (output instanceof LiteralOutputImpl) { exportLiteralOutput(writer, (LiteralOutputImpl) output); } else if (output instanceof ComplexOutputImpl) { exportComplexOutput(writer, (ComplexOutputImpl) output); } writer.writeEndElement(); } else { writer.writeStartElement(WPS_NS, "Reference"); String href = null; String mimeType = null; if (output instanceof ComplexOutputImpl) { ComplexOutputImpl complexOutput = (ComplexOutputImpl) output; href = complexOutput.getWebURL(); mimeType = complexOutput.getRequestedMimeType(); } if (mimeType == null) { LOG.warn("No mime type info available -> text/xml"); mimeType = "text/xml"; } writer.writeAttribute("href", "" + href); writer.writeAttribute("mimeType", mimeType); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportBoundingBoxOutput(XMLStreamWriter writer, BoundingBoxOutputImpl output) throws XMLStreamException { // "wps:BoundingBoxData" element writer.writeStartElement(WPS_NS, "BoundingBoxData"); OWSCommonXMLAdapter.exportBoundingBoxType(writer, output.getValue()); writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportLiteralOutput(XMLStreamWriter writer, LiteralOutputImpl output) throws XMLStreamException { // "wps:LiteralData" element writer.writeStartElement(WPS_NS, "LiteralData"); // "dataType" attribute (optional) if (output.getDataType() != null) { writer.writeAttribute("dataType", output.getDataType()); }//from w w w . j a va 2s. com // "uom" attribute (optional) if (output.getRequestedUOM() != null) { writer.writeAttribute("uom", output.getRequestedUOM()); } writer.writeCharacters(output.getValue()); writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportXMLOutput(XMLStreamWriter writer, ComplexOutputImpl output) throws XMLStreamException { // "wps:ComplexData" element writer.writeStartElement(WPS_NS, "ComplexData"); String mimeType = output.getRequestedMimeType(); if (mimeType != null) { writer.writeAttribute("mimeType", mimeType); }/* w w w . ja v a2s . c o m*/ String schema = output.getRequestedSchema(); if (schema != null) { writer.writeAttribute("schema", schema); } // NOTE: Providing the encoding attribute doesn't make any sense for inline XML output (always defined by the // surrounding document) XMLStreamReader reader = output.getStreamReader(); // skip start document event // apadberg: the following line was necessary when Axiom 1.2.8 is used, // it is commented out because of revised behavior in Axiom 1.2.9 if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT) { reader.next(); } if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) { XMLAdapter.writeElement(writer, reader); } else { LOG.warn("No element in XMLOutput found, skipping it in response document."); } writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportBinaryOutput(XMLStreamWriter writer, ComplexOutputImpl output) throws XMLStreamException { // "wps:ComplexData" element writer.writeStartElement(WPS_NS, "ComplexData"); String mimeType = output.getRequestedMimeType(); if (mimeType != null) { writer.writeAttribute("mimeType", mimeType); }// w w w . j a v a 2s. com LOG.warn("TODO Handle other encodings. Using fixed encoding: base64."); writer.writeAttribute("encoding", "base64"); ByteArrayOutputStream os = new ByteArrayOutputStream(); InputStream is = output.getInputStream(); byte[] buffer = new byte[1024]; int bytesRead = 0; try { while ((bytesRead = is.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } os.flush(); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } byte[] binary = os.toByteArray(); String base64 = Base64.encodeBase64String(binary); writer.writeCharacters(base64); writer.writeEndElement(); }
From source file:org.deegree.tools.services.wms.FeatureTypesToLayerTree.java
private static void writeLayer(HashSet<FeatureType> visited, XMLStreamWriter out, FeatureType ft, String storeId) throws XMLStreamException { if (visited.contains(ft) || ft == null) { return;/*from w w w .jav a 2s. com*/ } visited.add(ft); out.writeCharacters("\n"); out.writeStartElement(ns, "RequestableLayer"); XMLAdapter.writeElement(out, ns, "Name", ft.getName().getLocalPart()); XMLAdapter.writeElement(out, ns, "Title", ft.getName().getLocalPart()); for (FeatureType sub : ft.getSchema().getDirectSubtypes(ft)) { writeLayer(visited, out, sub, storeId); } XMLAdapter.writeElement(out, ns, "FeatureStoreId", storeId); out.writeEndElement(); out.writeCharacters("\n"); }
From source file:org.deegree.tools.services.wms.FeatureTypesToLayerTree.java
/** * @param args//from www.ja v a2 s .co 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); } } } }
From source file:org.dita.dost.module.GenMapAndTopicListModule.java
private void writeExportAnchors() throws DITAOTException { if (INDEX_TYPE_ECLIPSEHELP.equals(transtype)) { // Output plugin id final File pluginIdFile = new File(job.tempDir, FILE_NAME_PLUGIN_XML); final DelayConrefUtils delayConrefUtils = new DelayConrefUtils(); delayConrefUtils.writeMapToXML(exportAnchorsFilter.getPluginMap(), pluginIdFile); XMLStreamWriter export = null; try (OutputStream exportStream = new FileOutputStream(new File(job.tempDir, FILE_NAME_EXPORT_XML))) { export = XMLOutputFactory.newInstance().createXMLStreamWriter(exportStream, "UTF-8"); export.writeStartDocument(); export.writeStartElement("stub"); for (final ExportAnchor e : exportAnchorsFilter.getExportAnchors()) { export.writeStartElement("file"); export.writeAttribute("name", tempFileNameScheme.generateTempFileName(toFile(e.file).toURI()).toString()); for (final String t : sort(e.topicids)) { export.writeStartElement("topicid"); export.writeAttribute("name", t); export.writeEndElement(); }/*from www. ja v a2 s. c om*/ for (final String i : sort(e.ids)) { export.writeStartElement("id"); export.writeAttribute("name", i); export.writeEndElement(); } for (final String k : sort(e.keys)) { export.writeStartElement("keyref"); export.writeAttribute("name", k); export.writeEndElement(); } export.writeEndElement(); } export.writeEndElement(); export.writeEndDocument(); } catch (final IOException e) { throw new DITAOTException("Failed to write export anchor file: " + e.getMessage(), e); } catch (final XMLStreamException e) { throw new DITAOTException("Failed to serialize export anchor file: " + e.getMessage(), e); } finally { if (export != null) { try { export.close(); } catch (final XMLStreamException e) { logger.error("Failed to close export anchor file: " + e.getMessage(), e); } } } } }
From source file:org.dita.dost.reader.ChunkMapReader.java
/** * Create the new topic stump./*from ww w. j a va 2 s .c o m*/ */ private void createTopicStump(final File newFile) { OutputStream newFileWriter = null; try { newFileWriter = new FileOutputStream(newFile); final XMLStreamWriter o = XMLOutputFactory.newInstance().createXMLStreamWriter(newFileWriter, UTF8); o.writeStartDocument(); o.writeProcessingInstruction(PI_WORKDIR_TARGET, UNIX_SEPARATOR + newFile.getParentFile().getAbsolutePath()); o.writeProcessingInstruction(PI_WORKDIR_TARGET_URI, newFile.getParentFile().toURI().toString()); o.writeStartElement(ELEMENT_NAME_DITA); o.writeEndElement(); o.writeEndDocument(); o.close(); newFileWriter.flush(); } catch (final RuntimeException e) { throw e; } catch (final Exception e) { logger.error(e.getMessage(), e); } finally { try { if (newFileWriter != null) { newFileWriter.close(); } } catch (final Exception e) { logger.error(e.getMessage(), e); } } }
From source file:org.eclipse.gyrex.logback.config.model.Appender.java
@Override public void toXml(final XMLStreamWriter writer) throws XMLStreamException { final boolean wrapIntoSiftingAppender = canSift() && isSeparateLogOutputsPerMdcProperty(); writer.writeStartElement("appender"); writer.writeAttribute("name", getName()); if (wrapIntoSiftingAppender) { writer.writeAttribute("class", SiftingAppender.class.getName()); } else {/*from www .j ava 2 s.com*/ writer.writeAttribute("class", getAppenderClassName()); } final Level threshold = getThreshold(); if (null != threshold) { writer.writeStartElement("filter"); writer.writeAttribute("class", ThresholdFilter.class.getName()); writer.writeStartElement("level"); writer.writeCharacters(threshold.toString()); writer.writeEndElement(); writer.writeEndElement(); } if (wrapIntoSiftingAppender) { // start discriminator and wrap regular appender into <sift><appender> writer.writeStartElement("discriminator"); writer.writeAttribute("class", MDCBasedDiscriminator.class.getName()); writer.writeStartElement("key"); writer.writeCharacters(getSiftingMdcPropertyName()); writer.writeEndElement(); writer.writeStartElement("defaultValue"); writer.writeCharacters(getSiftingMdcPropertyDefaultValue()); writer.writeEndElement(); writer.writeEndElement(); writer.writeStartElement("sift"); writer.writeStartElement("appender"); writer.writeAttribute("name", String.format("%s-${%s}", getName(), getSiftingMdcPropertyName())); } writeAppenderContent(writer); writeEncoder(writer); if (wrapIntoSiftingAppender) { // finish <sift><appender> writer.writeEndElement(); writer.writeEndElement(); } writer.writeEndElement(); }