List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String localName) throws XMLStreamException;
From source file:com.fiorano.openesb.application.application.Application.java
protected void toJXMLString_1(XMLStreamWriter writer, boolean writeManageableProperties) throws XMLStreamException, FioranoException { MapThreadLocale.getInstance().getMap().put("ERROR_XSD", CommonSchemas.ERROR_XSD); try {//from w w w . ja v a 2 s. c om if (applicationContext != null) applicationContext.toJXMLString(writer, writeManageableProperties); if (serviceInstances.size() > 0 || remoteServiceInstances.size() > 0) { writer.writeStartElement(ELEM_SERVICE_INSTANCES); { writeCollection(writer, serviceInstances, null, writeManageableProperties); writeCollection(writer, remoteServiceInstances, null); } writer.writeEndElement(); } writeCollection(writer, routes, ELEM_ROUTES, writeManageableProperties); writeCDATAElement(writer, ELEM_LAYOUT, layout); } finally { MapThreadLocale.getInstance().getMap().clear(); } }
From source file:com.fiorano.openesb.application.application.ApplicationReference.java
protected void toJXMLString(XMLStreamWriter writer, boolean writeManageableProperties) throws XMLStreamException, FioranoException { writer.writeStartElement(ELEM_APPLICATION); {// w w w.ja va 2 s . c o m writer.writeAttribute(ATTR_GUID, guid); writer.writeAttribute(ATTR_VERSION, String.valueOf(version)); writer.writeStartElement(ELEM_DISPLAY); { writer.writeAttribute(ATTR_DISPLAY_NAME, displayName); writeAttribute(writer, ATTR_CATEGORIES, categories); } writer.writeEndElement(); writer.writeStartElement(ELEM_SERVER_VERSION); { writer.writeAttribute(ATTR_SERVER_VERSION, serverVersion); writer.writeAttribute(ATTR_SERVER_CATEGORY, serverCategory); writer.writeAttribute(ATTR_BUILD_NO, buildNo); writer.writeAttribute(ATTR_USER_NAME, userName); } writer.writeEndElement(); writer.writeStartElement(ELEM_CREATION); { writeAttribute(writer, ATTR_CREATION_DATE, creationDate); writeAttribute(writer, ATTR_AUTHORS, authors); writeAttribute(writer, ATTR_SCHEMA_VERSION, schemaVersion); } writer.writeEndElement(); if (typeName != null) { writer.writeStartElement(ELEM_TYPE); { writeAttribute(writer, ATTR_TYPE_NAME, getTypeName()); if (subType != null) writeAttribute(writer, ATTR_SUB_TYPE, getSubType()); } writer.writeEndElement(); } writeElement(writer, ELEM_SHORT_DESCRIPTION, shortDescription); writeElement(writer, ELEM_LONG_DESCRIPTION, longDescription); writer.writeStartElement(ELEM_DEPLOYMENT); { writer.writeAttribute(ATTR_LABEL, label); if (!componentCached) writer.writeAttribute(ATTR_COMPONENT_CACHED, String.valueOf(componentCached)); } writer.writeEndElement(); writer.writeStartElement(ELEM_DL_DST); { writer.writeAttribute(String.valueOf(ATTR_DL_DST), String.valueOf(deleteDestination)); } writer.writeEndElement(); //write App RouteDurability writer.writeStartElement(ELEM_DURABLE_ROUTE); { writer.writeAttribute(ATTR_DURABLE_ROUTE_VALUE, String.valueOf(appRouteDurability)); } writer.writeEndElement(); if (componentLaunchOrderEnabled) { writer.writeStartElement(ELEM_COMPONENT_LAUNCH_ORDER); { writer.writeAttribute(ATTR_COMPONENT_LAUNCH_ORDER_ENABLED, String.valueOf(componentLaunchOrderEnabled)); } writer.writeEndElement(); } if (componentStopOrderEnabled) { writer.writeStartElement(ELEM_COMPONENT_STOP_ORDER); { writer.writeAttribute(ATTR_COMPONENT_STOP_ORDER_ENABLED, String.valueOf(componentStopOrderEnabled)); writer.writeAttribute(ATTR_USE_REVERSE_ORDER_OF_COMPONENT_LAUNCH_ORDER, String.valueOf(reverseComponentLaunchOrder)); } writer.writeEndElement(); } if (exposedWebInterfaces != WEB_INTERFACES_NONE) { writer.writeStartElement(ELEM_WEB); { writeAttribute(writer, ATTR_EXPOSED_INTERFACES, exposedWebInterfaces); } writer.writeEndElement(); } toJXMLString_1(writer, writeManageableProperties); } writer.writeEndElement(); }
From source file:de.codesourcery.eve.skills.dao.impl.FileShoppingListDAO.java
protected void writeToFile() { XMLStreamWriter writer = null; try {//from w ww. j a v a 2s . co 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.smartbear.jenkins.plugins.testcomplete.TcLogParser.java
private void processItem(ZipFile logArchive, Node node, String projectName, XMLStreamWriter writer, String name) throws ParsingException, XMLStreamException { Node nodeInfo = NodeUtils.getRootDocumentNodeFromArchive(logArchive, NodeUtils.getTextProperty(node, "filename")); if (nodeInfo == null) { throw new ParsingException("Unable to obtain item node info."); }//from w w w.ja v a2 s . c o m Node logDataRowNode = NodeUtils.findNamedNode(NodeUtils.findNamedNode(nodeInfo, "log data"), "row0"); if (logDataRowNode == null) { throw new ParsingException("Unable to obtain log data->row0 node for item with name '" + name + "'."); } writer.writeStartElement("testcase"); writer.writeAttribute("name", name); writer.writeAttribute("classname", suite + "." + projectName); long startTime = Utils.safeConvertDate(NodeUtils.getTextProperty(logDataRowNode, "start time")); long endTime = Utils.safeConvertDate(NodeUtils.getTextProperty(logDataRowNode, "end time")); long duration = endTime - startTime > 0 ? endTime - startTime : 0; writer.writeAttribute("time", Double.toString(duration / 1000f)); if (checkFail(NodeUtils.getTextProperty(node, "status"))) { Node testDetailsNode = NodeUtils.getRootDocumentNodeFromArchive(logArchive, NodeUtils.getTextProperty(logDataRowNode, "details")); writer.writeStartElement("failure"); List<String> messages = NodeUtils.getErrorMessages(testDetailsNode); if (errorOnWarnings) { messages.addAll(NodeUtils.getWarningMessages(testDetailsNode)); } writer.writeAttribute("message", StringUtils.join(messages, "\n\n")); writer.writeEndElement(); //failure } writer.writeEndElement(); //testcase }
From source file:ca.uhn.fhir.parser.XmlParser.java
@Override public void encodeTagListToWriter(TagList theTagList, Writer theWriter) throws IOException { try {/*from w w w . j av a 2 s . co m*/ XMLStreamWriter eventWriter = createXmlWriter(theWriter); eventWriter.writeStartElement(TagList.ELEMENT_NAME_LC); eventWriter.writeDefaultNamespace(FHIR_NS); for (Tag next : theTagList) { eventWriter.writeStartElement(TagList.ATTR_CATEGORY); if (isNotBlank(next.getTerm())) { eventWriter.writeAttribute(Tag.ATTR_TERM, next.getTerm()); } if (isNotBlank(next.getLabel())) { eventWriter.writeAttribute(Tag.ATTR_LABEL, next.getLabel()); } if (isNotBlank(next.getScheme())) { eventWriter.writeAttribute(Tag.ATTR_SCHEME, next.getScheme()); } eventWriter.writeEndElement(); } eventWriter.writeEndElement(); eventWriter.close(); } catch (XMLStreamException e) { throw new ConfigurationException("Failed to initialize STaX event factory", e); } }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeTagWithTextNode(XMLStreamWriter theEventWriter, String theElementName, IdDt theIdDt) throws XMLStreamException { theEventWriter.writeStartElement(theElementName); if (StringUtils.isNotBlank(theIdDt.getValue())) { theEventWriter.writeCharacters(theIdDt.getValue()); }/*from ww w . j av a2 s . c om*/ theEventWriter.writeEndElement(); }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeTagWithTextNode(XMLStreamWriter theEventWriter, String theElementName, StringDt theStringDt) throws XMLStreamException { theEventWriter.writeStartElement(theElementName); if (StringUtils.isNotBlank(theStringDt.getValue())) { theEventWriter.writeCharacters(theStringDt.getValue()); }//from w ww . j a v a 2 s . co m theEventWriter.writeEndElement(); }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void encodeBundleToWriterDstu2(Bundle theBundle, XMLStreamWriter theEventWriter) throws XMLStreamException { theEventWriter.writeStartElement("Bundle"); theEventWriter.writeDefaultNamespace(FHIR_NS); writeOptionalTagWithValue(theEventWriter, "id", theBundle.getId().getIdPart()); InstantDt updated = (InstantDt) theBundle.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED); IdDt bundleId = theBundle.getId();//from w w w. j a va 2s . c o m if (bundleId != null && isNotBlank(bundleId.getVersionIdPart()) || (updated != null && !updated.isEmpty())) { theEventWriter.writeStartElement("meta"); writeOptionalTagWithValue(theEventWriter, "versionId", bundleId.getVersionIdPart()); if (updated != null) { writeOptionalTagWithValue(theEventWriter, "lastUpdated", updated.getValueAsString()); } theEventWriter.writeEndElement(); } writeOptionalTagWithValue(theEventWriter, "type", theBundle.getType().getValue()); writeOptionalTagWithValue(theEventWriter, "total", theBundle.getTotalResults().getValueAsString()); writeBundleResourceLink(theEventWriter, "first", theBundle.getLinkFirst()); writeBundleResourceLink(theEventWriter, "previous", theBundle.getLinkPrevious()); writeBundleResourceLink(theEventWriter, "next", theBundle.getLinkNext()); writeBundleResourceLink(theEventWriter, "last", theBundle.getLinkLast()); writeBundleResourceLink(theEventWriter, "self", theBundle.getLinkSelf()); for (BundleEntry nextEntry : theBundle.getEntries()) { theEventWriter.writeStartElement("entry"); boolean deleted = false; if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) { deleted = true; } writeBundleResourceLink(theEventWriter, "alternate", nextEntry.getLinkAlternate()); if (nextEntry.getResource() != null && nextEntry.getResource().getId().getBaseUrl() != null) { writeOptionalTagWithValue(theEventWriter, "fullUrl", nextEntry.getResource().getId().getValue()); } IResource resource = nextEntry.getResource(); if (resource != null && !resource.isEmpty() && !deleted) { theEventWriter.writeStartElement("resource"); encodeResourceToXmlStreamWriter(resource, theEventWriter, false, true); theEventWriter.writeEndElement(); // content } else { ourLog.debug("Bundle entry contains null resource"); } if (nextEntry.getSearchMode().isEmpty() == false || nextEntry.getScore().isEmpty() == false) { theEventWriter.writeStartElement("search"); writeOptionalTagWithValue(theEventWriter, "mode", nextEntry.getSearchMode().getValueAsString()); writeOptionalTagWithValue(theEventWriter, "score", nextEntry.getScore().getValueAsString()); theEventWriter.writeEndElement(); // IResource nextResource = nextEntry.getResource(); } if (nextEntry.getTransactionMethod().isEmpty() == false || nextEntry.getLinkSearch().isEmpty() == false) { theEventWriter.writeStartElement("request"); writeOptionalTagWithValue(theEventWriter, "method", nextEntry.getTransactionMethod().getValue()); writeOptionalTagWithValue(theEventWriter, "url", nextEntry.getLinkSearch().getValue()); theEventWriter.writeEndElement(); } if (deleted) { theEventWriter.writeStartElement("deleted"); writeOptionalTagWithValue(theEventWriter, "type", nextEntry.getId().getResourceType()); writeOptionalTagWithValue(theEventWriter, "id", nextEntry.getId().getIdPart()); writeOptionalTagWithValue(theEventWriter, "versionId", nextEntry.getId().getVersionIdPart()); writeOptionalTagWithValue(theEventWriter, "instant", nextEntry.getDeletedAt().getValueAsString()); theEventWriter.writeEndElement(); } theEventWriter.writeEndElement(); // entry } theEventWriter.writeEndElement(); theEventWriter.close(); }
From source file:com.liferay.portal.util.LocalizationImpl.java
private void _copyNonExempt(XMLStreamReader xmlStreamReader, XMLStreamWriter xmlStreamWriter, String exemptLanguageId, String defaultLanguageId, boolean cdata) throws XMLStreamException { while (xmlStreamReader.hasNext()) { int event = xmlStreamReader.next(); if (event == XMLStreamConstants.START_ELEMENT) { String languageId = xmlStreamReader.getAttributeValue(null, _LANGUAGE_ID); if (Validator.isNull(languageId)) { languageId = defaultLanguageId; }//from w w w. j av a 2 s.c o m if (!languageId.equals(exemptLanguageId)) { xmlStreamWriter.writeStartElement(xmlStreamReader.getLocalName()); xmlStreamWriter.writeAttribute(_LANGUAGE_ID, languageId); while (xmlStreamReader.hasNext()) { event = xmlStreamReader.next(); if ((event == XMLStreamConstants.CHARACTERS) || (event == XMLStreamConstants.CDATA)) { String text = xmlStreamReader.getText(); if (cdata) { xmlStreamWriter.writeCData(text); } else { xmlStreamWriter.writeCharacters(xmlStreamReader.getText()); } break; } else if (event == XMLStreamConstants.END_ELEMENT) { break; } } xmlStreamWriter.writeEndElement(); } } else if (event == XMLStreamConstants.END_DOCUMENT) { break; } } }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeBundleResourceLink(XMLStreamWriter theEventWriter, String theRel, StringDt theUrl) throws XMLStreamException { if (theUrl.isEmpty() == false) { theEventWriter.writeStartElement("link"); theEventWriter.writeStartElement("relation"); theEventWriter.writeAttribute("value", theRel); theEventWriter.writeEndElement(); theEventWriter.writeStartElement("url"); theEventWriter.writeAttribute("value", theUrl.getValue()); theEventWriter.writeEndElement(); theEventWriter.writeEndElement(); }//from w w w.j av a2s . c o m }