Example usage for javax.xml.stream XMLStreamWriter writeStartElement

List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeStartElement.

Prototype

public void writeStartElement(String localName) throws XMLStreamException;

Source Link

Document

Writes a start tag to the output.

Usage

From source file:com.fiorano.openesb.application.application.OutputPortInstance.java

protected void toJXMLString_2(XMLStreamWriter writer, boolean writeSchema)
        throws XMLStreamException, FioranoException {
    if (writeSchema || publisherConfigName == null) { // We need to write port properties to stream when passing application launch packet to peer         //
        writer.writeStartElement(ELEM_PUBLISHER);
        {/*from   w w w .  j a  va2s .  c o  m*/
            writer.writeStartElement(ELEM_MESSAGES);
            {
                if (timeToLive != 0)
                    writer.writeAttribute(ATTR_TIME_TO_LIVE, String.valueOf(timeToLive));
                if (compressMessages)
                    writer.writeAttribute(ATTR_COMPRESS_MESSAGES, String.valueOf(compressMessages));
                if (priority != 4)
                    writer.writeAttribute(ATTR_PRIORITY, String.valueOf(priority));
                if (persistent)
                    writer.writeAttribute(ATTR_PERSISTENT, String.valueOf(persistent));
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
    } else {
        writer.writeStartElement(ELEM_PUBLISHER_CONFIG_NAME);
        {
            writer.writeAttribute(ATTR_NAME, publisherConfigName);
        }
        writer.writeEndElement();
    }
}

From source file:com.microsoft.tfs.core.memento.XMLMemento.java

/**
 * Saves this {@link Memento} as an XML Element in the given writer
 *
 * @param writer//www  .j  a va 2 s . c  o  m
 *        the writer (must not be <code>null</code>)
 */
private void writeAsElement(final XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement(name);

    /*
     * Write all attributes as XML attributes.
     */
    for (final Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) {
        final Entry entry = (Entry) iterator.next();
        writer.writeAttribute((String) entry.getKey(), (String) entry.getValue());
    }

    /*
     * Write the text node if there is one.
     */
    if (textData != null) {
        writer.writeCharacters(textData);
    }

    /*
     * Write all children as elements.
     */
    for (final Iterator iterator = children.iterator(); iterator.hasNext();) {
        final XMLMemento child = (XMLMemento) iterator.next();
        child.writeAsElement(writer);
    }

    /*
     * Done with the element.
     */
    writer.writeEndElement();
}

From source file:DDTReporter.java

private void writeStartElement(XMLStreamWriter writer, String name, String[] attributes, String[] values)
        throws XMLStreamException {
    writer.writeStartElement(name);
    for (int i = 0; i < attributes.length; i++) {
        writer.writeAttribute(attributes[i], values[i]);
    }/*from  w  ww .  ja  v  a 2 s  .com*/
    writer.writeCharacters("\n");
}

From source file:de.codesourcery.eve.skills.util.XMLMapper.java

public void write(Collection<?> beans, IFieldConverters converters, OutputStream outstream)
        throws XMLStreamException, IntrospectionException, IllegalArgumentException, IllegalAccessException {

    final XMLOutputFactory factory = XMLOutputFactory.newInstance();
    final XMLStreamWriter writer = factory.createXMLStreamWriter(outstream, OUTPUT_ENCODING);
    try {/*from w w  w.j a v  a 2  s. co m*/
        writer.writeStartDocument(OUTPUT_ENCODING, "1.0");
        writer.writeStartElement("rows");

        if (beans.isEmpty()) {
            writer.writeEndDocument();
            return;
        }

        final Class<?> beanClass = beans.iterator().next().getClass();

        final BeanDescription desc = createBeanDescription(beanClass);

        final Collection<Field> fields = desc.getFields();
        if (fields.isEmpty()) {
            writer.writeEndDocument();
            return;
        }

        for (Object bean : beans) {
            writer.writeStartElement("row");
            for (Field f : fields) {
                final Object fieldValue = f.get(bean);
                final String[] values = converters.getConverter(f).toString(fieldValue);

                final String attrName = this.propertyNameMappings.get(f.getName());
                if (values == null) {
                    writer.writeAttribute(f.getName(), NIL);
                } else if (attrName == null) {
                    writer.writeAttribute(f.getName(), toAttributeValue(values));
                } else {
                    writer.writeAttribute(attrName, toAttributeValue(values));
                }
            }
            writer.writeEndElement();
        }
        writer.writeEndDocument();
    } finally {
        writer.close();
    }
}

From source file:dk.statsbiblioteket.util.xml.XMLStepperTest.java

@SuppressWarnings("CallToPrintStackTrace")
private synchronized boolean writerIsCollapsing() {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {//from   ww  w.j a v  a2  s  .c o m
        XMLStreamWriter out = xmlOutFactory.createXMLStreamWriter(os);
        out.writeStartElement("foo");
        out.writeEndElement();
        out.flush();
        return "<foo />".equals(os.toString());
    } catch (XMLStreamException e) {
        throw new RuntimeException("Unable to determine if XMLStreamWriter collapses empty elements", e);
    }
}

From source file:jp.co.atware.solr.geta.GETAssocComponent.java

/**
 * GETAssoc??????//  w  w  w.  j  a v a 2  s.co m
 * 
 * @param params
 * @param queryValue
 * @param queryType
 * @return
 * @throws FactoryConfigurationError
 * @throws IOException
 */
protected String convertRequest(SolrParams params, String queryValue, QueryType queryType)
        throws FactoryConfigurationError, IOException {

    String req;
    try {
        CharArrayWriter output = new CharArrayWriter();
        XMLStreamWriter xml = XMLOutputFactory.newInstance().createXMLStreamWriter(output);
        xml.writeStartDocument();
        xml.writeStartElement("gss");
        if (config.settings.gss3version != null) {
            xml.writeAttribute("version", config.settings.gss3version);
        }
        xml.writeStartElement("assoc");
        String target = params.get(PARAM_TARGET, config.defaults.target);
        if (target != null) {
            xml.writeAttribute("target", target);
        }
        convertRequestWriteStage1Param(xml, params);
        convertRequestWriteStage2Param(xml, params);

        convReqWriteQuery(xml, params, queryValue, queryType);

        xml.writeEndElement();
        xml.writeEndElement();
        xml.writeEndDocument();
        xml.close();
        req = output.toString();
    } catch (XMLStreamException e) {
        throw new IOException(e);
    }
    LOG.debug(req);
    return req;
}

From source file:com.fiorano.openesb.application.aps.ApplicationContext.java

public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException {
    //Start Application Context
    writer.writeStartElement("ApplicationContext");

    //Write Structure
    if (!StringUtils.isEmpty(m_structure)) {
        writer.writeStartElement("Structure");
        writer.writeCData(m_structure);/*from  ww  w  .j  a v  a 2s.  c  o m*/
        writer.writeEndElement();

    }

    //Write Default Instance
    if (!StringUtils.isEmpty(m_defaultInstance)) {
        FioranoStackSerializer.writeElement("DefaultInstance", m_defaultInstance, writer);
    }

    //Write Root Element
    if (!StringUtils.isEmpty(m_rootElement)) {
        FioranoStackSerializer.writeElement("RootElement", m_rootElement, writer);

    }

    //Write Root Element Namespace
    if (!StringUtils.isEmpty(m_rootElementNamespace)) {
        FioranoStackSerializer.writeElement("RootElementNamespace", m_rootElementNamespace, writer);

    }

    //Write Structure Type
    FioranoStackSerializer.writeElement("StructureType", String.valueOf(m_structureType), writer);

    //End Application Context
    writer.writeEndElement();

}

From source file:com.basistech.bbhmp.RosapiBundleCollectorMojo.java

private void writeMetadata(Map<Integer, List<BundleSpec>> bundlesByLevel) throws MojoExecutionException {
    OutputStream os = null;//from   w  ww . j  ava 2  s  .  com
    File md = new File(outputDirectory, "bundles.xml");

    try {
        os = new FileOutputStream(md);
        XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(os);
        writer = new IndentingXMLStreamWriter(writer);
        writer.writeStartDocument("utf-8", "1.0");
        writer.writeStartElement("bundles");
        for (Integer level : bundlesByLevel.keySet()) {
            writer.writeStartElement("level");
            writer.writeAttribute("level", Integer.toString(level));
            for (BundleSpec spec : bundlesByLevel.get(level)) {
                writer.writeStartElement("bundle");
                writer.writeAttribute("start", Boolean.toString(spec.start));
                writer.writeCharacters(spec.filename);
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();

    } catch (IOException | XMLStreamException e) {
        throw new MojoExecutionException("Failed to write metadata file " + md.toString(), e);
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:edu.jhu.pha.vospace.node.Node.java

public String getXmlMetadata(Detail detail) {

    StringWriter jobWriter = new StringWriter();
    try {//from  w  w  w.  ja v a2s. c  om
        XMLStreamWriter xsw = XMLOutputFactory.newInstance().createXMLStreamWriter(jobWriter);
        xsw.writeStartDocument();

        xsw.setDefaultNamespace(VOS_NAMESPACE);

        xsw.writeStartElement("node");
        xsw.writeNamespace("xsi", XSI_NAMESPACE);
        xsw.writeNamespace(null, VOS_NAMESPACE);
        xsw.writeAttribute("xsi:type", this.getType().getTypeName());
        xsw.writeAttribute("uri", this.getUri().toString());

        if (detail == Detail.max) {
            xsw.writeStartElement("properties");
            Map<String, String> properties = this.getMetastore().getProperties(this.getUri());
            properties.put(LENGTH_PROPERTY, Long.toString(getNodeInfo().getSize()));
            properties.put(DATE_PROPERTY, dropboxDateFormat.format(getNodeInfo().getMtime()));
            if (this.getType() == NodeType.DATA_NODE || this.getType() == NodeType.STRUCTURED_DATA_NODE
                    || this.getType() == NodeType.UNSTRUCTURED_DATA_NODE) {
                properties.put(CONTENTTYPE_PROPERTY, getNodeInfo().getContentType());
            }

            for (String propUri : properties.keySet()) {
                xsw.writeStartElement("property");
                xsw.writeAttribute("uri", propUri);
                xsw.writeCharacters(properties.get(propUri));
                xsw.writeEndElement();
            }

            xsw.writeEndElement();

            xsw.writeStartElement("accepts");
            xsw.writeEndElement();

            xsw.writeStartElement("provides");
            xsw.writeEndElement();

            xsw.writeStartElement("capabilities");
            xsw.writeEndElement();

            if (this.getType() == NodeType.CONTAINER_NODE) {
                NodesList childrenList = ((ContainerNode) this).getDirectChildren(false, 0, -1);
                List<Node> children = childrenList.getNodesList();

                xsw.writeStartElement("nodes");
                for (Node childNode : children) {
                    xsw.writeStartElement("node");
                    xsw.writeAttribute("uri", childNode.getUri().getId().toString());
                    xsw.writeEndElement();
                }
                xsw.writeEndElement();

            }

        }

        xsw.writeEndElement();

        xsw.writeEndDocument();
        xsw.close();
    } catch (XMLStreamException e) {
        e.printStackTrace();
        throw new InternalServerErrorException(e);
    }
    return jobWriter.getBuffer().toString();
}

From source file:com.fiorano.openesb.application.application.InputPortInstance.java

protected void toJXMLString_2(XMLStreamWriter writer, boolean writeSchema)
        throws XMLStreamException, FioranoException {
    if (writeSchema || subscriberConfigName == null) { // We need to write port properties to stream when passing application launch packet to peer
        writer.writeStartElement(ELEM_SUBSCRIBER);
        {//from   w  w w .ja v a2 s . c om
            if (sessionCount != 1)
                writer.writeAttribute(ATTR_SESSION_COUNT, String.valueOf(sessionCount));
            if (acknowledgementMode != ACKNOWLEDGEMENT_MODE_DUPS_OK)
                writer.writeAttribute(ATTR_ACKNOWLEDGEMENT_MODE, String.valueOf(acknowledgementMode));
            if (!StringUtils.isEmpty(messageSelector))
                writer.writeAttribute(ATTR_MESSAGE_SELECTOR, String.valueOf(messageSelector));

            writer.writeStartElement(ELEM_TRANSACTION);
            {
                writer.writeAttribute(ATTR_TRANSACTED, String.valueOf(transacted));
                if (transactionSize != 0)
                    writer.writeAttribute(ATTR_TRANSACTION_SIZE, String.valueOf(transactionSize));
            }
            writer.writeEndElement();

            writer.writeStartElement(ELEM_SUBSCRIPTION);
            {
                writer.writeAttribute(ATTR_DURABLE_SUBSCRIPTION, String.valueOf(durableSubscription));
                if (!StringUtils.isEmpty(subscriptionName))
                    writer.writeAttribute(ATTR_SUBSCRIPTION_NAME, String.valueOf(subscriptionName));
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
    } else {
        writer.writeStartElement(ELEM_SUBSCRIBER_CONFIG_NAME);
        {
            writer.writeAttribute(ATTR_NAME, subscriberConfigName);
        }
        writer.writeEndElement();
    }
}