List of usage examples for javax.xml.stream XMLStreamWriter writeDefaultNamespace
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException;
From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java
private void link(final Writer outWriter, final Link link) throws XMLStreamException { final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter); writer.writeStartDocument();//from w ww . j av a 2 s. co m writer.writeStartElement(Constants.ELEM_LINKS); writer.writeDefaultNamespace(namespaceData); writer.writeStartElement(Constants.ELEM_URI); writer.writeCharacters(link.getHref()); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); }
From source file:org.apache.olingo.commons.core.data.AtomSerializer.java
private void link(final Writer outWriter, final Link link) throws XMLStreamException { final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter); writer.writeStartDocument();/*from w w w . ja va 2 s . c om*/ writer.writeStartElement(Constants.ELEM_LINKS); writer.writeDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); writer.writeStartElement(Constants.ELEM_URI); writer.writeCharacters(link.getHref()); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); }
From source file:org.deegree.tools.services.wms.FeatureTypesToLayerTree.java
/** * @param args//from w ww. j a 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.eclipse.smila.datamodel.record.stax.RecordWriter.java
/** * Append a rec:RecordList element describing the given record list to the given XML stream. The element contains a * namespace declaration for xmlns:rec.//from www. j ava 2 s.co m * * @param staxWriter * target XML stream * @param records * the record list to transform. * @throws XMLStreamException * StAX error * */ public void writeRecordList(final XMLStreamWriter staxWriter, final Iterable<Record> records) throws XMLStreamException { staxWriter.setDefaultNamespace(RecordBuilder.NAMESPACE_RECORD); writeStartElement(staxWriter, RecordBuilder.TAG_RECORDLIST); staxWriter.writeDefaultNamespace(RecordBuilder.NAMESPACE_RECORD); newline(staxWriter); for (final Record record : records) { writeRecord(staxWriter, record, false); } writeEndElement(staxWriter); }
From source file:org.eclipse.smila.datamodel.record.stax.RecordWriter.java
/** * write a record to an XML stream./*from w ww. ja va2s . c om*/ * * @param staxWriter * target XML stream * @param record * the record to write * @param addNamespace * add xmlns attribute * @throws XMLStreamException * StAX error */ private void writeRecord(final XMLStreamWriter staxWriter, final Record record, final boolean addNamespace) throws XMLStreamException { staxWriter.setDefaultNamespace(RecordBuilder.NAMESPACE_RECORD); writeStartElement(staxWriter, RecordBuilder.TAG_RECORD); if (addNamespace) { staxWriter.writeDefaultNamespace(RecordBuilder.NAMESPACE_RECORD); } staxWriter.writeAttribute(RecordBuilder.ATTRIBUTE_VERSION, RecordBuilder.SCHEMA_VERSION_RECORD); newline(staxWriter); if (record.getId() != null) { _idWriter.writeId(staxWriter, record.getId()); staxWriter.setDefaultNamespace(RecordBuilder.NAMESPACE_RECORD); } if (record.getMetadata() != null) { writeMetadata(staxWriter, record.getMetadata()); } if (record.hasAttachments()) { final Iterator<String> attachmentNames = record.getAttachmentNames(); while (attachmentNames.hasNext()) { final String attachmentName = attachmentNames.next(); writeTextElement(staxWriter, RecordBuilder.TAG_ATTACHMENT, attachmentName); } } writeEndElement(staxWriter); }
From source file:org.eclipse.smila.datamodel.xml.StaxRecordWriter.java
/** * Append a rec:RecordList element describing the given record list to the given XML stream. The element contains a * namespace declaration for xmlns:rec./*from w w w . ja v a 2 s .c o m*/ * * @param staxWriter * target XML stream * @param records * the record list to transform. * @throws XMLStreamException * StAX error * */ public void writeRecordList(final XMLStreamWriter staxWriter, final Iterable<Record> records) throws XMLStreamException { staxWriter.setDefaultNamespace(XmlConstants.NAMESPACE_RECORD); writeStartElement(staxWriter, XmlConstants.TAG_RECORDLIST); staxWriter.writeDefaultNamespace(XmlConstants.NAMESPACE_RECORD); newline(staxWriter); for (final Record record : records) { writeRecord(staxWriter, record, false); } writeEndElement(staxWriter); }
From source file:org.eclipse.smila.datamodel.xml.StaxRecordWriter.java
/** * write a record to an XML stream.//w w w.jav a2s. co m * * @param staxWriter * target XML stream * @param record * the record to write * @param addNamespace * add xmlns attribute * @throws XMLStreamException * StAX error */ private void writeRecord(final XMLStreamWriter staxWriter, final Record record, final boolean addNamespace) throws XMLStreamException { staxWriter.setDefaultNamespace(XmlConstants.NAMESPACE_RECORD); newline(staxWriter); writeStartElement(staxWriter, XmlConstants.TAG_RECORD); if (addNamespace) { staxWriter.writeDefaultNamespace(XmlConstants.NAMESPACE_RECORD); } staxWriter.writeAttribute(XmlConstants.ATTRIBUTE_VERSION, XmlConstants.SCHEMA_VERSION_RECORD); newline(staxWriter); if (record.getId() != null) { staxWriter.setDefaultNamespace(XmlConstants.NAMESPACE_RECORD); } if (record.getMetadata() != null) { writeMetadata(staxWriter, record.getMetadata()); } if (record.hasAttachments()) { final Iterator<String> attachmentNames = record.getAttachmentNames(); while (attachmentNames.hasNext()) { final String attachmentName = attachmentNames.next(); writeTextElement(staxWriter, XmlConstants.TAG_ATTACHMENT, attachmentName); } } writeEndElement(staxWriter); }
From source file:org.flowable.bpmn.converter.export.DefinitionsRootExport.java
@SuppressWarnings("unchecked") public static void writeRootElement(BpmnModel model, XMLStreamWriter xtw, String encoding) throws Exception { xtw.writeStartDocument(encoding, "1.0"); // start definitions root element xtw.writeStartElement(ELEMENT_DEFINITIONS); xtw.setDefaultNamespace(BPMN2_NAMESPACE); xtw.writeDefaultNamespace(BPMN2_NAMESPACE); xtw.writeNamespace(XSI_PREFIX, XSI_NAMESPACE); xtw.writeNamespace(XSD_PREFIX, SCHEMA_NAMESPACE); xtw.writeNamespace(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE); xtw.writeNamespace(BPMNDI_PREFIX, BPMNDI_NAMESPACE); xtw.writeNamespace(OMGDC_PREFIX, OMGDC_NAMESPACE); xtw.writeNamespace(OMGDI_PREFIX, OMGDI_NAMESPACE); for (String prefix : model.getNamespaces().keySet()) { if (!defaultNamespaces.contains(prefix) && StringUtils.isNotEmpty(prefix)) xtw.writeNamespace(prefix, model.getNamespaces().get(prefix)); }/* w w w . j a v a2s.c om*/ xtw.writeAttribute(TYPE_LANGUAGE_ATTRIBUTE, SCHEMA_NAMESPACE); xtw.writeAttribute(EXPRESSION_LANGUAGE_ATTRIBUTE, XPATH_NAMESPACE); if (StringUtils.isNotEmpty(model.getTargetNamespace())) { xtw.writeAttribute(TARGET_NAMESPACE_ATTRIBUTE, model.getTargetNamespace()); } else { xtw.writeAttribute(TARGET_NAMESPACE_ATTRIBUTE, PROCESS_NAMESPACE); } BpmnXMLUtil.writeCustomAttributes(model.getDefinitionsAttributes().values(), xtw, model.getNamespaces(), defaultAttributes); }
From source file:org.flowable.cmmn.converter.export.DefinitionsRootExport.java
public static void writeRootElement(CmmnModel model, XMLStreamWriter xtw, String encoding) throws Exception { xtw.writeStartDocument(encoding, "1.0"); // start definitions root element xtw.writeStartElement(ELEMENT_DEFINITIONS); xtw.setDefaultNamespace(CMMN_NAMESPACE); xtw.writeDefaultNamespace(CMMN_NAMESPACE); xtw.writeNamespace(XSI_PREFIX, XSI_NAMESPACE); xtw.writeNamespace(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE); xtw.writeNamespace(CMMNDI_PREFIX, CMMNDI_NAMESPACE); xtw.writeNamespace(OMGDC_PREFIX, OMGDC_NAMESPACE); xtw.writeNamespace(OMGDI_PREFIX, OMGDI_NAMESPACE); for (String prefix : model.getNamespaces().keySet()) { if (!defaultNamespaces.contains(prefix) && StringUtils.isNotEmpty(prefix)) xtw.writeNamespace(prefix, model.getNamespaces().get(prefix)); }// www . j a va2 s .c o m if (StringUtils.isNotEmpty(model.getTargetNamespace())) { xtw.writeAttribute(ATTRIBUTE_TARGET_NAMESPACE, model.getTargetNamespace()); } else { xtw.writeAttribute(ATTRIBUTE_TARGET_NAMESPACE, CASE_NAMESPACE); } }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private void handleBlobList(HttpServletRequest request, HttpServletResponse response, BlobStore blobStore, String containerName) throws IOException, S3Exception { String blobStoreType = getBlobStoreType(blobStore); ListContainerOptions options = new ListContainerOptions(); String encodingType = request.getParameter("encoding-type"); String delimiter = request.getParameter("delimiter"); if (delimiter != null) { options.delimiter(delimiter);//from w w w. jav a2 s. c o m } else { options.recursive(); } String prefix = request.getParameter("prefix"); if (prefix != null && !prefix.isEmpty()) { options.prefix(prefix); } String marker = request.getParameter("marker"); if (marker != null) { if (Quirks.OPAQUE_MARKERS.contains(blobStoreType)) { String realMarker = lastKeyToMarker.getIfPresent(Maps.immutableEntry(containerName, marker)); if (realMarker != null) { marker = realMarker; } } options.afterMarker(marker); } int maxKeys = 1000; String maxKeysString = request.getParameter("max-keys"); if (maxKeysString != null) { try { maxKeys = Integer.parseInt(maxKeysString); } catch (NumberFormatException nfe) { throw new S3Exception(S3ErrorCode.INVALID_ARGUMENT, nfe); } if (maxKeys > 1000) { maxKeys = 1000; } } options.maxResults(maxKeys); response.setCharacterEncoding("UTF-8"); PageSet<? extends StorageMetadata> set = blobStore.list(containerName, options); try (Writer writer = response.getWriter()) { response.setStatus(HttpServletResponse.SC_OK); XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(writer); xml.writeStartDocument(); xml.writeStartElement("ListBucketResult"); xml.writeDefaultNamespace(AWS_XMLNS); writeSimpleElement(xml, "Name", containerName); if (prefix == null) { xml.writeEmptyElement("Prefix"); } else { writeSimpleElement(xml, "Prefix", encodeBlob(encodingType, prefix)); } writeSimpleElement(xml, "MaxKeys", String.valueOf(maxKeys)); if (marker == null) { xml.writeEmptyElement("Marker"); } else { writeSimpleElement(xml, "Marker", encodeBlob(encodingType, marker)); } if (delimiter != null) { writeSimpleElement(xml, "Delimiter", encodeBlob(encodingType, delimiter)); } if (encodingType != null && encodingType.equals("url")) { writeSimpleElement(xml, "EncodingType", encodingType); } String nextMarker = set.getNextMarker(); if (nextMarker != null) { writeSimpleElement(xml, "IsTruncated", "true"); writeSimpleElement(xml, "NextMarker", encodeBlob(encodingType, nextMarker)); if (Quirks.OPAQUE_MARKERS.contains(blobStoreType)) { lastKeyToMarker.put(Maps.immutableEntry(containerName, Iterables.getLast(set).getName()), nextMarker); } } else { writeSimpleElement(xml, "IsTruncated", "false"); } Set<String> commonPrefixes = new TreeSet<>(); for (StorageMetadata metadata : set) { switch (metadata.getType()) { case FOLDER: continue; case RELATIVE_PATH: commonPrefixes.add(metadata.getName()); continue; default: break; } xml.writeStartElement("Contents"); writeSimpleElement(xml, "Key", encodeBlob(encodingType, metadata.getName())); Date lastModified = metadata.getLastModified(); if (lastModified != null) { writeSimpleElement(xml, "LastModified", formatDate(lastModified)); } String eTag = metadata.getETag(); if (eTag != null) { writeSimpleElement(xml, "ETag", maybeQuoteETag(eTag)); } writeSimpleElement(xml, "Size", String.valueOf(metadata.getSize())); writeSimpleElement(xml, "StorageClass", "STANDARD"); writeOwnerStanza(xml); xml.writeEndElement(); } for (String commonPrefix : commonPrefixes) { xml.writeStartElement("CommonPrefixes"); writeSimpleElement(xml, "Prefix", encodeBlob(encodingType, commonPrefix)); xml.writeEndElement(); } xml.writeEndElement(); xml.flush(); } catch (XMLStreamException xse) { throw new IOException(xse); } }