List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException;
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); }/*from www. jav a 2 s . 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 ww w.j a v a2 s . c o m } 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 w w w.ja v a2 s . com */ 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.eclipse.smila.datamodel.record.stax.RecordWriter.java
/** * start an element with the tag name and the default namespace. * * @param staxWriter//from w w w. j a v a 2s . com * target XML stream * @param tagName * tag name * @throws XMLStreamException * StAX error */ private void writeStartElement(final XMLStreamWriter staxWriter, final String tagName) throws XMLStreamException { staxWriter.writeStartElement(RecordBuilder.NAMESPACE_RECORD, tagName); }
From source file:org.eclipse.smila.datamodel.xml.StaxRecordWriter.java
/** * start an element with the tag name and the default namespace. * /* ww w .jav a2 s. co m*/ * @param staxWriter * target XML stream * @param tagName * tag name * @throws XMLStreamException * StAX error */ private void writeStartElement(final XMLStreamWriter staxWriter, final String tagName) throws XMLStreamException { staxWriter.writeStartElement(XmlConstants.NAMESPACE_RECORD, tagName); }