List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:babel.content.pages.PageVersion.java
/** * To be called by ObjectWriter only./*from w w w. ja va 2 s.co m*/ * @throws XMLStreamException */ public void persist(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement(XML_TAG_PAGEVERSION); if (m_verProps.numKeys() > 0) { m_verProps.persist(writer); } if (m_parseMeta.numKeys() > 0) { m_parseMeta.persist(writer); } if (m_contentMeta.numKeys() > 0) { m_contentMeta.persist(writer); } if (m_outLinks != null) { String anchor; writer.writeStartElement(XML_TAG_OUT_LINKS); for (Outlink outlink : m_outLinks) { writer.writeStartElement(XML_TAG_LINK); anchor = outlink.getAnchor(); if ((anchor != null) && (anchor.length() != 0)) { writer.writeAttribute(XML_ATTRIB_ANCHOR, anchor); } writer.writeCharacters(outlink.getToUrl()); writer.writeEndElement(); } writer.writeEndElement(); } if (m_content.length() > 0) { writer.writeStartElement(XML_TAG_CONTENT); writer.writeCharacters(new String(Base64.encodeBase64(m_content.getBytes()))); //writer.writeCharacters(m_content); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:com.norconex.collector.http.client.impl.GenericHttpClientFactory.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/*from w w w.j a va2 s.com*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("httpClientFactory"); writer.writeAttribute("class", getClass().getCanonicalName()); writeBoolElement(writer, "cookiesDisabled", cookiesDisabled); writeStringElement(writer, "authMethod", authMethod); writeStringElement(writer, "authUsername", authUsername); writeStringElement(writer, "authPassword", authPassword); writeStringElement(writer, "authUsernameField", authUsernameField); writeStringElement(writer, "authPasswordField", authPasswordField); writeStringElement(writer, "authURL", authURL); writeStringElement(writer, "authHostname", authHostname); writeIntElement(writer, "authPort", authPort); writeStringElement(writer, "authFormCharset", authFormCharset); writeStringElement(writer, "authWorkstation", authWorkstation); writeStringElement(writer, "authDomain", authDomain); writeStringElement(writer, "authRealm", authRealm); writeStringElement(writer, "proxyHost", proxyHost); writeIntElement(writer, "proxyPort", proxyPort); writeStringElement(writer, "proxyScheme", proxyScheme); writeStringElement(writer, "proxyUsername", proxyUsername); writeStringElement(writer, "proxyPassword", proxyPassword); writeStringElement(writer, "proxyRealm", proxyRealm); writer.writeEndElement(); writeIntElement(writer, "connectionTimeout", connectionTimeout); writeIntElement(writer, "socketTimeout", socketTimeout); writeIntElement(writer, "connectionRequestTimeout", connectionRequestTimeout); writeStringElement(writer, "connectionCharset", connectionCharset); writeBoolElement(writer, "expectContinueEnabled", expectContinueEnabled); writeIntElement(writer, "maxRedirects", maxRedirects); writeStringElement(writer, "localAddress", localAddress); writeBoolElement(writer, "staleConnectionCheckDisabled", staleConnectionCheckDisabled); writeIntElement(writer, "maxConnections", maxConnections); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:de.qucosa.webapi.v1.DocumentResource.java
@RequestMapping(value = "/document", method = RequestMethod.GET) public ResponseEntity<String> listAll() throws IOException, FedoraClientException, XMLStreamException { List<String> pids = fedoraRepository.getPIDsByPattern("^qucosa:"); StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); w.writeAttribute("version", "2.0"); w.writeStartElement("DocumentList"); w.writeNamespace("xlink", "http://www.w3.org/1999/xlink"); for (String pid : pids) { String nr = pid.substring(pid.lastIndexOf(':') + 1); String href = getHrefLink(nr); w.writeEmptyElement("Document"); w.writeAttribute("xlink:href", href); w.writeAttribute("xlink:nr", nr); w.writeAttribute("xlink:type", "simple"); }/*www . j av a 2 s .c o m*/ w.writeEndElement(); w.writeEndElement(); w.writeEndDocument(); w.flush(); return new ResponseEntity<>(sw.toString(), HttpStatus.OK); }
From source file:de.qucosa.webapi.v1.DocumentResource.java
private ResponseEntity<String> errorResponse(String message, HttpStatus status) throws XMLStreamException { StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); w.writeStartElement("Error"); w.writeAttribute("message", message); w.writeEndElement();//from www .ja va 2s .c o m w.writeEndElement(); w.writeEndDocument(); w.flush(); return new ResponseEntity<>(sw.toString(), status); }
From source file:com.fiorano.openesb.application.application.Application.java
/** * Writes manageable properties file with the specified label * @param applicationFolderName event process folder * @param label environment label//from www. j a v a2 s . c o m * @throws FioranoException FioranoException * @throws XMLStreamException XMLStreamException */ public void writeManageableProperties(File applicationFolderName, Label label) throws FioranoException, XMLStreamException { File manageablePropertiesFile = getManageablePropertiesFile(applicationFolderName, label); if (!manageablePropertiesFile.exists()) manageablePropertiesFile.getParentFile().mkdirs(); XMLOutputFactory outputFactory = XMLUtils.getStaxOutputFactory(); // System.out.println(".....:"+outputFactory); //outputFactory.setProperty(XMLOutputFactory.INDENTATION, "/t"); XMLStreamWriter writer = null; FileOutputStream fos = null; try { fos = new FileOutputStream(manageablePropertiesFile); writer = outputFactory.createXMLStreamWriter(fos); writer.writeStartDocument(); { writer.writeStartElement(ELEM_TARGET, ELEM_TARGET, Namespaces.URI_TARGET); writer.writeAttribute(XMLNS_TARGET, Namespaces.URI_TARGET); writer.writeAttribute(XMLNS_XSI, Namespaces.URI_XSI); writer.writeAttribute(XSI_LOCATION, Namespaces.URI_ENV_XSD); { for (ServiceInstance instance : getServiceInstances()) { instance.writeManageableProperties(writer); } } writer.writeEndElement(); } writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new FioranoException(e); } catch (IOException e) { throw new FioranoException(e); } finally { try { if (writer != null) writer.close(); } catch (XMLStreamException e) { // Ignore } try { if (fos != null) fos.close(); } catch (IOException e) { // Ignore } } }
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.j a va 2s.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: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 v a 2s .com 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: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 www . ja v a 2 s .c om*/ 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:com.microsoft.windowsazure.storage.table.TableParser.java
/** * Reserved for internal use. Writes an entity to the stream as an AtomPub Entry Resource, leaving the stream open * for additional writing./* w w w . j a va 2s . com*/ * * @param entity * The instance implementing {@link TableEntity} to write to the output stream. * @param isTableEntry * A flag indicating the entity is a reference to a table at the top level of the storage service when * <code>true<code> and a reference to an entity within a table when <code>false</code>. * @param xmlw * The <code>XMLStreamWriter</code> to write the entity to. * @param opContext * An {@link OperationContext} object used to track the execution of the operation. * * @throws XMLStreamException * if an error occurs accessing the stream. * @throws StorageException * if a Storage service error occurs. */ private static void writeAtomEntity(final TableEntity entity, final boolean isTableEntry, final XMLStreamWriter xmlw, final OperationContext opContext) throws XMLStreamException, StorageException { HashMap<String, EntityProperty> properties = entity.writeEntity(opContext); if (properties == null) { properties = new HashMap<String, EntityProperty>(); } if (!isTableEntry) { Utility.assertNotNull(TableConstants.PARTITION_KEY, entity.getPartitionKey()); Utility.assertNotNull(TableConstants.ROW_KEY, entity.getRowKey()); Utility.assertNotNull(TableConstants.TIMESTAMP, entity.getTimestamp()); } // Begin entry xmlw.writeStartElement("entry"); xmlw.writeNamespace("d", ODataConstants.DATA_SERVICES_NS); xmlw.writeNamespace("m", ODataConstants.DATA_SERVICES_METADATA_NS); // default namespace xmlw.writeNamespace(null, ODataConstants.ATOM_NS); // Content xmlw.writeStartElement(ODataConstants.CONTENT); xmlw.writeAttribute(ODataConstants.TYPE, ODataConstants.ODATA_CONTENT_TYPE); // m:properties xmlw.writeStartElement("m", ODataConstants.PROPERTIES, ODataConstants.DATA_SERVICES_METADATA_NS); if (!isTableEntry) { // d:PartitionKey xmlw.writeStartElement("d", TableConstants.PARTITION_KEY, ODataConstants.DATA_SERVICES_NS); xmlw.writeAttribute("xml", "xml", "space", "preserve"); xmlw.writeCharacters(entity.getPartitionKey()); xmlw.writeEndElement(); // d:RowKey xmlw.writeStartElement("d", TableConstants.ROW_KEY, ODataConstants.DATA_SERVICES_NS); xmlw.writeAttribute("xml", "xml", "space", "preserve"); xmlw.writeCharacters(entity.getRowKey()); xmlw.writeEndElement(); // d:Timestamp if (entity.getTimestamp() == null) { entity.setTimestamp(new Date()); } xmlw.writeStartElement("d", TableConstants.TIMESTAMP, ODataConstants.DATA_SERVICES_NS); xmlw.writeAttribute("m", ODataConstants.DATA_SERVICES_METADATA_NS, ODataConstants.TYPE, EdmType.DATE_TIME.toString()); xmlw.writeCharacters(Utility.getTimeByZoneAndFormat(entity.getTimestamp(), Utility.UTC_ZONE, Utility.ISO8061_LONG_PATTERN)); xmlw.writeEndElement(); } for (final Entry<String, EntityProperty> ent : properties.entrySet()) { if (ent.getKey().equals(TableConstants.PARTITION_KEY) || ent.getKey().equals(TableConstants.ROW_KEY) || ent.getKey().equals(TableConstants.TIMESTAMP) || ent.getKey().equals("Etag")) { continue; } EntityProperty currProp = ent.getValue(); // d:PropName xmlw.writeStartElement("d", ent.getKey(), ODataConstants.DATA_SERVICES_NS); if (currProp.getEdmType() == EdmType.STRING) { xmlw.writeAttribute("xml", "xml", "space", "preserve"); } else if (currProp.getEdmType().toString().length() != 0) { String edmTypeString = currProp.getEdmType().toString(); if (edmTypeString.length() != 0) { xmlw.writeAttribute("m", ODataConstants.DATA_SERVICES_METADATA_NS, ODataConstants.TYPE, edmTypeString); } } if (currProp.getIsNull()) { xmlw.writeAttribute("m", ODataConstants.DATA_SERVICES_METADATA_NS, ODataConstants.NULL, Constants.TRUE); } // Write Value xmlw.writeCharacters(currProp.getValueAsString()); // End d:PropName xmlw.writeEndElement(); } // End m:properties xmlw.writeEndElement(); // End content xmlw.writeEndElement(); // End entry xmlw.writeEndElement(); }
From source file:com.norconex.committer.idol.IdolCommitter.java
protected void buildCfsXmlDocument(XMLStreamWriter writer, InputStream is, Properties properties) throws XMLStreamException, IOException { try {/* w w w . j ava 2 s . c o m*/ writer.writeStartElement("add"); writer.writeStartElement("document"); // Create a database key for the idol XML document String targetIdField = getTargetReferenceField(); if (DEFAULT_IDOL_REFERENCE_FIELD.equalsIgnoreCase(targetIdField)) { writer.writeStartElement("reference"); writer.writeCharacters(properties.getString(targetIdField)); writer.writeEndElement(); } else { writer.writeStartElement("metadata"); writer.writeAttribute("name", targetIdField); writer.writeAttribute("value", properties.getString(targetIdField)); writer.writeEndElement(); } // Loop thru the list of properties and create XML fields // accordingly. for (Entry<String, List<String>> entry : properties.entrySet()) { if (!EqualsUtil.equalsAny(entry.getKey(), getTargetReferenceField(), getTargetContentField())) { for (String value : entry.getValue()) { writer.writeStartElement("metadata"); writer.writeAttribute("name", entry.getKey()); writer.writeAttribute("value", value); writer.writeEndElement(); } } } // Store content at specified location String targetCtntField = getTargetContentField(); String targetCtntValue = properties.getString(targetCtntField); writer.writeEndElement(); writer.writeStartElement("source"); writer.writeAttribute("content", Base64.encodeBase64String(targetCtntValue.getBytes(CharEncoding.UTF_8))); writer.writeEndElement(); writer.writeEndElement(); } finally { IOUtils.closeQuietly(is); } }