List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:net.solarnetwork.web.support.SimpleXmlHttpMessageConverter.java
private void writeElement(String name, Map<?, ?> props, XMLStreamWriter writer, boolean close) throws IOException, XMLStreamException { writer.writeStartElement(name);/* ww w. j a v a 2 s . co m*/ Map<String, Object> nested = null; if (props != null) { for (Map.Entry<?, ?> me : props.entrySet()) { String key = me.getKey().toString(); Object val = me.getValue(); if (propertySerializerRegistrar != null) { val = propertySerializerRegistrar.serializeProperty(name, val.getClass(), props, val); } if (val instanceof Date) { SimpleDateFormat sdf = SDF.get(); Date date = (Date) val; val = sdf.format(date); } else if (val instanceof Collection) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (val instanceof Map<?, ?>) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (classNamesAllowedForNesting != null && !(val instanceof Enum<?>)) { for (String prefix : classNamesAllowedForNesting) { if (val.getClass().getName().startsWith(prefix)) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; break; } } } if (val != null) { writer.writeAttribute(key, val.toString()); } } } if (nested != null) { for (Map.Entry<String, Object> me : nested.entrySet()) { outputObject(me.getValue(), me.getKey(), writer); } } if (close) { writer.writeEndElement(); } }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the representation of one comment. * //w w w . j ava2 s. co m * @param writer * {@link XMLStreamWriter} of the current XMI file * @param comment * {@link Comment} which should be represented * @param id * {@link String} the id of the created <code>ownedComment</code> * tag, which represents <code>comment</code> * @param annotatedElement * {@link String} qualified name of the {@link NamedElement} * which is commented * @throws XMLStreamException */ private void createComment(XMLStreamWriter writer, Comment comment, String id, String annotatedElement) throws XMLStreamException { // start ownedComment writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_OWNEDCOMMENT); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.OWNEDCOMMENT_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDCOMMENT_ATTRIBUTE_ANNOTATEDELEMENT, annotatedElement); // start body writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_BODY); // write content writer.writeCharacters(XMIConstants4SchemaGraph2XMI.COMMENT_START + comment.get_text().replaceAll(Pattern.quote("\n"), XMIConstants4SchemaGraph2XMI.COMMENT_NEWLINE) + XMIConstants4SchemaGraph2XMI.COMMENT_END); // end body writer.writeEndElement(); // end ownedComment writer.writeEndElement(); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the <code>Model</code> tag and its content consisting of * <ul>//from w w w .j av a2 s . com * <li>the {@link GraphClass},</li> * <li>the defaultPackage and its content,</li> * <li>the representation of the domains in * {@link SchemaGraph2XMI#typesToBeDeclaredAtTheEnd} and</li> * <li>and the profile application</li> * </ul> * by calling the corresponding methods. * * @param writer * {@link XMLStreamWriter} of the current XMI file * @param schemaGraph * {@link SchemaGraph} to be converted into an XMI * @throws XMLStreamException */ private void createModelElement(XMLStreamWriter writer, SchemaGraph schemaGraph) throws XMLStreamException { de.uni_koblenz.jgralab.grumlschema.structure.Schema schema = schemaGraph.getFirstSchema(); // start model writer.writeStartElement(XMIConstants4SchemaGraph2XMI.NAMESPACE_UML, XMIConstants4SchemaGraph2XMI.UML_TAG_MODEL); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, schema.get_packagePrefix() + "." + schema.get_name()); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, schema.get_packagePrefix() + "." + schema.get_name()); // convert graph class createAttributedElementClass(writer, schemaGraph.getFirstGraphClass()); createPackage(writer, (Package) schemaGraph.getFirstSchema().getFirstContainsDefaultPackageIncidence().getThat()); // create Types if (!typesToBeDeclaredAtTheEnd.isEmpty()) { createTypes(writer); } // create profileApplication createProfileApplication(writer); // end model writer.writeEndElement(); }
From source file:edu.stanford.cfuller.colocalization3d.correction.Correction.java
protected String writeToXML() { StringWriter sw = new StringWriter(); try {// w w w .j ava 2 s . c o m XMLStreamWriter xsw = XMLOutputFactory.newFactory().createXMLStreamWriter(sw); xsw.writeStartDocument(); xsw.writeCharacters("\n"); xsw.writeStartElement("root"); xsw.writeCharacters("\n"); xsw.writeStartElement(CORRECTION_ELEMENT); xsw.writeAttribute(N_POINTS_ATTR, Integer.toString(this.distanceCutoffs.getDimension())); xsw.writeAttribute(REF_CHANNEL_ATTR, Integer.toString(this.referenceChannel)); xsw.writeAttribute(CORR_CHANNEL_ATTR, Integer.toString(this.correctionChannel)); xsw.writeCharacters("\n"); for (int i = 0; i < this.distanceCutoffs.getDimension(); i++) { xsw.writeStartElement(CORRECTION_POINT_ELEMENT); xsw.writeAttribute(X_POS_ATTR, Double.toString(this.positionsForCorrection.getEntry(i, 0))); xsw.writeAttribute(Y_POS_ATTR, Double.toString(this.positionsForCorrection.getEntry(i, 1))); xsw.writeAttribute(Z_POS_ATTR, Double.toString(this.positionsForCorrection.getEntry(i, 2))); xsw.writeCharacters("\n"); String x_param_string = ""; String y_param_string = ""; String z_param_string = ""; for (int j = 0; j < this.correctionX.getColumnDimension(); j++) { String commaString = ""; if (j != 0) commaString = ", "; x_param_string += commaString + this.correctionX.getEntry(i, j); y_param_string += commaString + this.correctionY.getEntry(i, j); z_param_string += commaString + this.correctionZ.getEntry(i, j); } x_param_string = x_param_string.trim() + "\n"; y_param_string = y_param_string.trim() + "\n"; z_param_string = z_param_string.trim() + "\n"; xsw.writeStartElement(X_PARAM_ELEMENT); xsw.writeCharacters(x_param_string); xsw.writeEndElement(); xsw.writeCharacters("\n"); xsw.writeStartElement(Y_PARAM_ELEMENT); xsw.writeCharacters(y_param_string); xsw.writeEndElement(); xsw.writeCharacters("\n"); xsw.writeStartElement(Z_PARAM_ELEMENT); xsw.writeCharacters(z_param_string); xsw.writeEndElement(); xsw.writeCharacters("\n"); xsw.writeEndElement(); xsw.writeCharacters("\n"); } xsw.writeStartElement(BINARY_DATA_ELEMENT); xsw.writeAttribute(ENCODING_ATTR, ENCODING_NAME); ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(bytesOutput); oos.writeObject(this); } catch (java.io.IOException e) { java.util.logging.Logger.getLogger(LOG_NAME) .severe("Exception encountered while serializing correction: " + e.getMessage()); } HexBinaryAdapter adapter = new HexBinaryAdapter(); xsw.writeCharacters(adapter.marshal(bytesOutput.toByteArray())); xsw.writeEndElement(); xsw.writeCharacters("\n"); xsw.writeEndElement(); xsw.writeCharacters("\n"); xsw.writeEndElement(); xsw.writeCharacters("\n"); xsw.writeEndDocument(); } catch (XMLStreamException e) { java.util.logging.Logger.getLogger(LOG_NAME) .severe("Exception encountered while writing XML correction output: " + e.getMessage()); } return sw.toString(); }
From source file:com.smartbear.jenkins.plugins.testcomplete.TcLogParser.java
private void processProject(ZipFile logArchive, Node rootOwnerNode, Node rootOwnerNodeInfoSummary, XMLStreamWriter writer) throws ParsingException, XMLStreamException { String totalTests = NodeUtils.getTextProperty( NodeUtils.findNamedNode(rootOwnerNodeInfoSummary.getChildNodes(), "total"), "total (sum)"); String failedTests = NodeUtils.getTextProperty( NodeUtils.findNamedNode(rootOwnerNodeInfoSummary.getChildNodes(), "failed"), "total (sum)"); long startDate = Utils.safeConvertDate(NodeUtils.getTextProperty(rootOwnerNodeInfoSummary, "start date")); long stopDate = Utils.safeConvertDate(NodeUtils.getTextProperty(rootOwnerNodeInfoSummary, "stop date")); long projectDuration = stopDate - startDate > 0 ? stopDate - startDate : 0; String projectName = NodeUtils.getTextProperty(rootOwnerNodeInfoSummary, "test"); Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(startDate);// w w w . ja va 2s . co m String timestamp = DatatypeConverter.printDateTime(cal); String rootOwnerNodeFileName = NodeUtils.getTextProperty(rootOwnerNode, "filename"); if (rootOwnerNodeFileName == null || rootOwnerNodeFileName.isEmpty()) { throw new ParsingException("Unable to obtain filename for project node."); } List<Pair<String, Node>> items = null; try { items = NodeUtils.findChildNodesRecursively(logArchive, rootOwnerNode, rootOwnerNode.getParentNode().getChildNodes(), ""); } catch (Exception e) { items = new ArrayList<Pair<String, Node>>(); } writer.writeStartElement("testsuite"); writer.writeAttribute("name", projectName); writer.writeAttribute("failures", failedTests); writer.writeAttribute("tests", totalTests); writer.writeAttribute("time", Double.toString(projectDuration / 1000f)); writer.writeAttribute("timestamp", timestamp); for (Pair<String, Node> pair : items) { processItem(logArchive, pair.getValue(), projectName, writer, pair.getKey()); } writer.writeEndElement(); //testcase }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the profileApplication tag at the end of the model tag. * /*from w w w . ja va 2 s . co m*/ * @param writer * {@link XMLStreamWriter} of the current XMI file * @throws XMLStreamException */ private void createProfileApplication(XMLStreamWriter writer) throws XMLStreamException { // start profileApplication writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_PROFILEAPPLICATION); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.PROFILEAPPLICATION_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, XMIConstants4SchemaGraph2XMI.TAG_PROFILEAPPLICATION + System.currentTimeMillis()); // create content createExtension(writer, null, null); // create appliedProfile writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_APPLIEDPROFILE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.APPLIEDPROFILE_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF, XMIConstants4SchemaGraph2XMI.APPLIEDPROFILE_HREF_VALUE); // end profileApplication writer.writeEndElement(); }
From source file:com.fiorano.openesb.application.aps.Route.java
public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException { //Start Route writer.writeStartElement("Route"); //Add Route Attributes writer.writeAttribute("isP2PRoute", "" + m_isP2PRoute); writer.writeAttribute("isPersistant", "" + m_isPersitant); writer.writeAttribute("isDurable", "" + m_isDurable); writer.writeAttribute("applyTransformationAtSrc", "" + m_applyTransformationAtSrc); //Name//from www . jav a 2 s . com FioranoStackSerializer.writeElement("Name", m_routeName, writer); //RouteGuid FioranoStackSerializer.writeElement("RouteGUID", m_routeGUID, writer); //TimeToLive FioranoStackSerializer.writeElement("TimeToLive", "" + m_iTimeToLive, writer); //SrcServiceInstance FioranoStackSerializer.writeElement("SrcServiceInstance", m_srcServInst, writer); //SrcPort FioranoStackSerializer.writeElement("SrcPort", m_srcPortName, writer); //TransformationXSL if (m_transformationXSL != null) { writer.writeStartElement("TransformationXSL"); writer.writeCData(m_transformationXSL); writer.writeEndElement(); } //Selectors if (m_selectors != null) { Iterator itr = m_selectors.keySet().iterator(); while (itr.hasNext()) { writer.writeStartElement("Selector"); String type = (String) itr.next(); writer.writeAttribute("type", type); Object val = m_selectors.get(type); String value = null; if (val instanceof String) { value = (String) m_selectors.get(type); } else if (val instanceof XPathDmi) { value = ((XPathDmi) val).getXPath(); HashMap map = ((XPathDmi) val).getNameSpace(); if (map != null) { Set keys = map.keySet(); Iterator iter = keys.iterator(); while (iter.hasNext()) { String key = (String) iter.next(); String keyval = (String) map.get(key); writer.writeAttribute("esb_" + key, keyval); } } } writer.writeCharacters(value); //End Selector writer.writeEndElement(); } } //TgtServiceInstance FioranoStackSerializer.writeElement("TgtServiceInstance", m_trgtServInst, writer); //TgtPort FioranoStackSerializer.writeElement("TgtPort", m_trgtPortName, writer); //LongDescription if (!StringUtils.isEmpty(m_longDescription)) { FioranoStackSerializer.writeElement("LongDescription", m_longDescription, writer); } //ShortDescription if (!StringUtils.isEmpty(m_shortDescription)) { FioranoStackSerializer.writeElement("ShortDescription", m_shortDescription, writer); } if (m_altDestination != null) { m_altDestination.toJXMLString(writer); } if (m_params != null && m_params.size() > 0) { Enumeration enums = m_params.elements(); while (enums.hasMoreElements()) { Param param = (Param) enums.nextElement(); if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue())) param.toJXMLString(writer); } } //End Route writer.writeEndElement(); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the representation of the {@link RecordDomain} * <code>recordDomain</code>. This representation consists of an UML class * with stereotype <code><<record>></code>. The components of * <code>recordDomain</code> are represented as attributes of the generated * UML class. Further more all {@link Comment}s attached to * <code>recordDomain</code> are created. * /* w w w .j a va2s . c o m*/ * @param writer * {@link XMLStreamWriter} of the current XMI file * @param recordDomain * {@link RecordDomain} the current {@link RecordDomain} * @throws XMLStreamException */ private void createRecordDomain(XMLStreamWriter writer, RecordDomain recordDomain) throws XMLStreamException { // start packagedElement writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_CLASS); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, recordDomain.get_qualifiedName()); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, extractSimpleName(recordDomain.get_qualifiedName())); // create stereotype <<record>> createExtension(writer, recordDomain, "record"); // create comments createComments(writer, recordDomain); // create attributes for (HasRecordDomainComponent hrdc : recordDomain .getHasRecordDomainComponentIncidences(EdgeDirection.OUT)) { createAttribute(writer, hrdc.get_name(), null, (Domain) hrdc.getThat(), recordDomain.get_qualifiedName() + "_" + hrdc.get_name()); } // end packagededElement writer.writeEndElement(); }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private void handleContainerLocation(HttpServletResponse response, BlobStore blobStore, String containerName) throws IOException { try (Writer writer = response.getWriter()) { XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(writer); xml.writeStartDocument();//from w w w. ja va 2 s . c o m // TODO: using us-standard semantics but could emit actual location xml.writeStartElement("LocationConstraint"); xml.writeDefaultNamespace(AWS_XMLNS); xml.writeEndElement(); xml.flush(); } catch (XMLStreamException xse) { throw new IOException(xse); } }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates an constraint with the content <code>constraintContent</code>. * /*from www . j a va2 s . c om*/ * @param writer * {@link XMLStreamWriter} of the current XMI file * @param constraintContent * {@link String} the content of the constraint which will be * created * @param id * {@link String} the id of the created <code>ownedRule</code> * tag, which represents <code>constraint</code> * @param constrainedElement * {@link String} qualified name of the * {@link AttributedElementClass} which is constrained * @throws XMLStreamException */ private void createConstraint(XMLStreamWriter writer, String constraintContent, String id, String constrainedElement) throws XMLStreamException { // start ownedRule writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_OWNEDRULE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.OWNEDRULE_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDRULE_ATTRIBUTE_CONSTRAINEDELEMENT, constrainedElement); // start specification writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_SPECIFICATION); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.TYPE_VALUE_OPAQUEEXPRESSION); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id + "_" + XMIConstants4SchemaGraph2XMI.TAG_SPECIFICATION); // start and end language writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_LANGUAGE); writer.writeEndElement(); // start body writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_BODY); writer.writeCharacters(constraintContent); // end body writer.writeEndElement(); // end specification writer.writeEndElement(); // end ownedRule writer.writeEndElement(); }