List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private static void writeOwnerStanza(XMLStreamWriter xml) throws XMLStreamException { xml.writeStartElement("Owner"); writeSimpleElement(xml, "ID", FAKE_OWNER_ID); writeSimpleElement(xml, "DisplayName", FAKE_OWNER_DISPLAY_NAME); xml.writeEndElement();/*from ww w. j av a 2 s . co m*/ }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private static void writeInitiatorStanza(XMLStreamWriter xml) throws XMLStreamException { xml.writeStartElement("Initiator"); writeSimpleElement(xml, "ID", FAKE_INITIATOR_ID); writeSimpleElement(xml, "DisplayName", FAKE_INITIATOR_DISPLAY_NAME); xml.writeEndElement();//from w w w . j a va 2s .co m }
From source file:com.fiorano.openesb.application.application.Route.java
protected void toJXMLString(XMLStreamWriter writer, boolean writeCDataSections) throws XMLStreamException, FioranoException { writer.writeStartElement(ELEM_ROUTE); {/*from w w w . jav a2s . c o m*/ writer.writeAttribute(ATTR_NAME, name); if (ignoreAbsenceOfTransformation) {//write only if true writer.writeAttribute(ATTR_IGNORE_ABSENCE_TRANSFORMATION, String.valueOf(ignoreAbsenceOfTransformation)); } writer.writeStartElement(ELEM_SOURCE); { writer.writeAttribute(ATTR_SOURCE_SERVICE_INSTANCE, sourceServiceInstance); writer.writeAttribute(ATTR_SOURCE_PORT_INSTANCE, sourcePortInstance); } writer.writeEndElement(); writer.writeStartElement(ELEM_TARGET); { writer.writeAttribute(ATTR_TARGET_SERVICE_INSTANCE, targetServiceInstance); writer.writeAttribute(ATTR_TARGET_PORT_INSTANCE, targetPortInstance); } writer.writeEndElement(); writeElement(writer, ELEM_SHORT_DESCRIPTION, shortDescription); writeElement(writer, ELEM_LONG_DESCRIPTION, longDescription); if (messagingConfigName != null) { writer.writeStartElement(ELEM_MESSAGING_CONFIG_NAME); { writer.writeAttribute(ATTR_NAME, messagingConfigName); } writer.writeEndElement(); } else { writer.writeStartElement(ELEM_MESSAGES); { if (compressed) writer.writeAttribute(ATTR_COMPRESS, String.valueOf(true)); if (durable) writer.writeAttribute(ATTR_DURABLE, String.valueOf(true)); if (encrypted) writer.writeAttribute(ATTR_ENCRYPT, String.valueOf(true)); writer.writeAttribute(ATTR_ROUTE_DURABLE_PRIORITY, String.valueOf(durabilitySource)); } writer.writeEndElement(); } if (messageTransformation != null) messageTransformation.toJXMLString(writer, writeCDataSections); if (selectorConfigName != null) { writer.writeStartElement(ELEM_SELECTOR_CONFIG_NAME); { writer.writeAttribute(ATTR_NAME, selectorConfigName); } writer.writeEndElement(); } else if (selectors.size() > 0) { writer.writeStartElement(ELEM_SELECTORS); { Iterator iter = selectors.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); writer.writeStartElement(ELEM_SELECTOR); { writer.writeAttribute(ATTR_TYPE, (String) entry.getKey()); if (entry.getValue() instanceof XPathSelector) ((XPathSelector) entry.getValue()).toJXMLString(writer); else writer.writeCharacters((String) entry.getValue()); } writer.writeEndElement(); } } writer.writeEndElement(); } if (logManager != null) logManager.toJXMLString(writer); writeCollection(writer, logModules, ELEM_LOGMODULES); } writer.writeEndElement(); }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeCategories(XMLStreamWriter eventWriter, TagList categories) throws XMLStreamException { if (categories != null) { for (Tag next : categories) { eventWriter.writeStartElement("category"); eventWriter.writeAttribute("term", defaultString(next.getTerm())); eventWriter.writeAttribute("label", defaultString(next.getLabel())); eventWriter.writeAttribute("scheme", defaultString(next.getScheme())); eventWriter.writeEndElement(); }//from w w w . j a v a 2s . c om } }
From source file:de.shadowhunt.subversion.internal.AbstractPropfindOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("PROPFIND", uri); request.addHeader("Depth", depth.value); final Writer body = new StringBuilderWriter(); try {//from w w w .j a va 2s .co m final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("propfind"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); if (requestedProperties == null) { writer.writeEmptyElement("prop"); } else { if (requestedProperties.length == 0) { writer.writeEmptyElement("allprop"); } else { writer.writeStartElement("prop"); if (contains(XmlConstants.SUBVERSION_DAV_NAMESPACE)) { writer.writeNamespace(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); } if (contains(XmlConstants.SUBVERSION_SVN_NAMESPACE)) { writer.writeNamespace(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); } for (final ResourceProperty.Key requestedProperty : requestedProperties) { writer.writeEmptyElement(requestedProperty.getType().getPrefix(), requestedProperty.getName()); } writer.writeEndElement(); // prop } } writer.writeEndElement(); // propfind writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:de.escidoc.core.common.util.xml.XmlUtility.java
/** * Adds a new element to the provided {@code XMLStreamWriter} object containing a {@code String} value. * * @param writer The {@code XMLStreamWriter} object to add the element to. * @param elementName The name of the new element. * @param elementContent The {@code String} that shall be set as the value of the new element. * @param namespaceUri The namespace URI of the new element. * @param createEmpty Flag indicating if a an empty element shall be created if the provided data is * {@code null} ( {@code true} ), or if the element shall not be created ( * {@code false} ). * @throws XMLStreamException Thrown in case of an xml stream error. *///from www.j a v a 2s . c o m public static void addElement(final XMLStreamWriter writer, final String elementName, final String elementContent, final String namespaceUri, final boolean createEmpty) throws XMLStreamException { if (elementContent == null) { if (createEmpty) { writer.writeEmptyElement(namespaceUri, elementName); } } else { writer.writeStartElement(namespaceUri, elementName); writer.writeCharacters(elementContent); writer.writeEndElement(); } }
From source file:com.adobe.acs.commons.wcm.impl.SiteMapServlet.java
private void writeAsset(Asset asset, XMLStreamWriter stream, ResourceResolver resolver) throws XMLStreamException { stream.writeStartElement(NS, "url"); String loc = externalizer.externalLink(resolver, externalizerDomain, asset.getPath()); writeElement(stream, "loc", loc); if (includeLastModified) { long lastModified = asset.getLastModified(); if (lastModified > 0) { writeElement(stream, "lastmod", DATE_FORMAT.format(lastModified)); }/*w w w .jav a 2 s. c o m*/ } Resource contentResource = asset.adaptTo(Resource.class).getChild(JcrConstants.JCR_CONTENT); if (contentResource != null) { if (includeInheritValue) { HierarchyNodeInheritanceValueMap hierarchyNodeInheritanceValueMap = new HierarchyNodeInheritanceValueMap( contentResource); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, hierarchyNodeInheritanceValueMap); writeFirstPropertyValue(stream, "priority", priorityProperties, hierarchyNodeInheritanceValueMap); } else { ValueMap properties = contentResource.getValueMap(); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, properties); writeFirstPropertyValue(stream, "priority", priorityProperties, properties); } } stream.writeEndElement(); }
From source file:de.codesourcery.eve.skills.dao.impl.FileShoppingListDAO.java
protected void writeToFile() { XMLStreamWriter writer = null; try {//from ww w . ja v a 2 s. c o m if (!dataFile.exists()) { final File parent = dataFile.getParentFile(); if (parent != null && !parent.exists()) { if (!parent.mkdirs()) { log.error("writeToFile(): Failed to create parent directory " + parent.getAbsolutePath()); } else { log.info("writeToFile(): Created parent directory " + parent.getAbsolutePath()); } } } final XMLOutputFactory factory = XMLOutputFactory.newInstance(); log.info("writeToFile(): Writing to " + dataFile.getAbsolutePath()); final FileOutputStream outStream = new FileOutputStream(dataFile); writer = factory.createXMLStreamWriter(outStream, OUTPUT_ENCODING); writer.writeStartDocument(OUTPUT_ENCODING, "1.0"); writer.writeStartElement("shoppinglists"); // <shoppinglists> synchronized (this.entries) { for (ShoppingList list : this.entries) { writer.writeStartElement("shoppinglist"); writer.writeAttribute("title", list.getTitle()); if (!StringUtils.isBlank(list.getDescription())) { writer.writeStartElement("description"); writer.writeCharacters(list.getDescription()); writer.writeEndElement(); // </description> } writer.writeStartElement("entries"); for (ShoppingListEntry entry : list.getEntries()) { writer.writeStartElement("entry"); writer.writeAttribute("itemId", Long.toString(entry.getType().getId())); writer.writeAttribute("totalQuantity", Long.toString(entry.getQuantity())); writer.writeAttribute("purchasedQuantity", Long.toString(entry.getPurchasedQuantity())); writer.writeEndElement(); // </entry> } writer.writeEndElement(); // </entries> writer.writeEndElement(); // </shoppinglist> } } writer.writeEndElement(); // </shoppinglists> writer.writeEndDocument(); writer.flush(); writer.close(); } catch (FileNotFoundException e) { log.error("writeToFile(): Caught ", e); throw new RuntimeException("Unable to save shopping list to " + dataFile, e); } catch (XMLStreamException e) { log.error("writeToFile(): Caught ", e); throw new RuntimeException("Unable to save shopping list to " + dataFile, e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { log.error("writeToFile(): Caught ", e); } } } }
From source file:com.norconex.collector.http.delay.impl.DefaultDelayResolver.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {//from w w w .ja v a2 s .c om XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("delay"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeAttribute("default", Long.toString(defaultDelay)); writer.writeAttribute("scope", scope); writer.writeAttribute("ignoreRobotsCrawlDelay", Boolean.toString(ignoreRobotsCrawlDelay)); for (DelaySchedule schedule : schedules) { writer.writeStartElement("schedule"); if (schedule.getDayOfWeekRange() != null) { writer.writeAttribute("dayOfWeek", "from " + schedule.getDayOfWeekRange().getMinimum() + " to " + schedule.getDayOfWeekRange().getMaximum()); } if (schedule.getDayOfMonthRange() != null) { writer.writeAttribute("dayOfMonth", "from " + schedule.getDayOfMonthRange().getMinimum() + " to " + schedule.getDayOfMonthRange().getMaximum()); } if (schedule.getTimeRange() != null) { writer.writeAttribute("time", "from " + schedule.getTimeRange().getLeft().toString("HH:MM") + " to " + schedule.getTimeRange().getRight().toString("HH:MM")); } writer.writeEndElement(); } writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.norconex.collector.http.client.impl.DefaultHttpClientInitializer.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {//from w w w . ja v a2 s . co m XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("httpClientInitializer"); writer.writeAttribute("class", getClass().getCanonicalName()); writeSimpleElement(writer, "cookiesDisabled", Boolean.toString(cookiesDisabled)); writeSimpleElement(writer, "userAgent", userAgent); writeSimpleElement(writer, "authMethod", authMethod); writeSimpleElement(writer, "authUsername", authUsername); writeSimpleElement(writer, "authPassword", authPassword); writeSimpleElement(writer, "authUsernameField", authUsernameField); writeSimpleElement(writer, "authPasswordField", authPasswordField); writeSimpleElement(writer, "authURL", authURL); writeSimpleElement(writer, "authHostname", authHostname); writeSimpleElement(writer, "authPort", Integer.toString(authPort)); writeSimpleElement(writer, "authRealm", authRealm); writeSimpleElement(writer, "proxyHost", proxyHost); writeSimpleElement(writer, "proxyPort", Integer.toString(proxyPort)); writeSimpleElement(writer, "proxyUsername", proxyUsername); writeSimpleElement(writer, "proxyPassword", proxyPassword); writeSimpleElement(writer, "proxyRealm", proxyRealm); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }