Example usage for javax.xml.stream XMLStreamWriter writeEmptyElement

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

Introduction

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

Prototype

public void writeEmptyElement(String localName) throws XMLStreamException;

Source Link

Document

Writes an empty element tag to the output

Usage

From source file:de.shadowhunt.subversion.internal.MergeOperation.java

@Override
protected HttpUriRequest createRequest() {
    final DavTemplateRequest request = new DavTemplateRequest("MERGE", repository);
    request.addHeader("X-SVN-Options", "release-locks");

    final Writer body = new StringBuilderWriter();
    try {//  www .j  ava2s.co m
        final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body);
        writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0);
        writer.writeStartElement("merge");
        writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE);
        writer.writeStartElement("source");
        writer.writeStartElement("href");
        writer.writeCData(repository.getPath() + resource.getValue());
        writer.writeEndElement(); // href
        writer.writeEndElement(); // source
        writer.writeEmptyElement("no-auto-merge");
        writer.writeEmptyElement("no-checkout");
        writer.writeStartElement("prop");
        writer.writeEmptyElement("checked-in");
        writer.writeEmptyElement("version-name");
        writer.writeEmptyElement("resourcetype");
        writer.writeEmptyElement("creationdate");
        writer.writeEmptyElement("creator-displayname");
        writer.writeEndElement(); // prop
        if (!infoSet.isEmpty()) {
            writer.setPrefix(XmlConstants.SVN_PREFIX, XmlConstants.SVN_NAMESPACE);
            writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-token-list");
            writer.writeNamespace(XmlConstants.SVN_PREFIX, XmlConstants.SVN_NAMESPACE);
            for (final Info info : infoSet) {
                final String lockToken = info.getLockToken();
                assert (lockToken != null) : "must not be null";
                final Resource infoResource = info.getResource();

                writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock");
                writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-path");
                writer.writeCData(infoResource.getValueWithoutLeadingSeparator());
                writer.writeEndElement(); // lock-path
                writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-token");
                writer.writeCharacters(lockToken);
                writer.writeEndElement(); // lock-token
                writer.writeEndElement(); // lock
            }
            writer.writeEndElement(); // lock-token-list
        }
        writer.writeEndElement(); // merge
        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.shadowhunt.subversion.internal.httpv1.CheckoutOperation.java

@Override
protected HttpUriRequest createRequest() {
    final Writer body = new StringBuilderWriter();
    try {//w w w.j a  v  a2 s.c om
        final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body);
        writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0);
        writer.writeStartElement("checkout");
        writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE);
        writer.writeStartElement("activity-set");
        writer.writeStartElement("href");
        final URI transactionURI = URIUtils.createURI(repository, transaction);
        writer.writeCData(transactionURI.toString());
        writer.writeEndElement(); // href
        writer.writeEndElement(); // activity-set
        writer.writeEmptyElement("apply-to-version");
        writer.writeEndElement(); //checkout
        writer.writeEndDocument();
        writer.close();
    } catch (final XMLStreamException e) {
        throw new SubversionException("could not create request body", e);
    }

    final URI uri = URIUtils.createURI(repository, resource);
    final DavTemplateRequest request = new DavTemplateRequest("CHECKOUT", uri);
    request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML));
    return request;
}

From source file:de.qucosa.webapi.v1.RelationResource.java

private void writeRelationElement(List<Tuple<String>> tuples, XMLStreamWriter w, String name, String type)
        throws XMLStreamException {
    for (Tuple<String> t : tuples) {
        w.writeStartElement(name);//from w  ww  . ja  v  a 2s . co  m

        w.writeStartElement("DocumentId");
        w.writeCharacters(t.get(0));
        w.writeEndElement();

        w.writeStartElement("Value");
        w.writeCharacters(t.get(1));
        w.writeEndElement();

        w.writeStartElement("Relation");
        w.writeCharacters(type);
        w.writeEndElement();

        w.writeStartElement("TitleMain");
        w.writeCharacters(t.get(2));
        w.writeEndElement();

        w.writeEmptyElement("Label");
        w.writeEmptyElement("SortOrder");
        w.writeEmptyElement("Issue");

        w.writeEndElement();
    }
}

From source file:XMLWriteTest.java

/**
 * Writers an SVG document of the current drawing.
 * @param writer the document destination
 *//* w  ww . j a v  a 2  s  . c  om*/
public void writeDocument(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartDocument();
    writer.writeDTD("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20000802//EN\" "
            + "\"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd\">");
    writer.writeStartElement("svg");
    writer.writeAttribute("width", "" + getWidth());
    writer.writeAttribute("height", "" + getHeight());
    for (int i = 0; i < rects.size(); i++) {
        Color c = colors.get(i);
        Rectangle2D r = rects.get(i);
        writer.writeEmptyElement("rect");
        writer.writeAttribute("x", "" + r.getX());
        writer.writeAttribute("y", "" + r.getY());
        writer.writeAttribute("width", "" + r.getWidth());
        writer.writeAttribute("height", "" + r.getHeight());
        writer.writeAttribute("fill", colorToString(c));
    }
    writer.writeEndDocument(); // closes svg element
}

From source file:de.shadowhunt.subversion.internal.LogOperation.java

@Override
protected HttpUriRequest createRequest() {
    final Writer body = new StringBuilderWriter();
    try {//from w  w  w.j a  v  a  2s .c  o  m
        final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body);
        writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0);
        writer.writeStartElement("log-report");
        writer.writeDefaultNamespace(XmlConstants.SVN_NAMESPACE);
        writer.writeStartElement("start-revision");
        writer.writeCharacters(start.toString());
        writer.writeEndElement(); // start-revision
        writer.writeStartElement("end-revision");
        writer.writeCharacters(end.toString());
        writer.writeEndElement(); // end-revision
        if (limit > 0) {
            writer.writeStartElement("limit");
            writer.writeCharacters(Integer.toString(limit));
            writer.writeEndElement(); // limit
        }
        writer.writeEmptyElement("discover-changed-paths");
        writer.writeEmptyElement("all-revprops");
        writer.writeEmptyElement("path");
        writer.writeEndElement(); // log-report
        writer.writeEndDocument();
        writer.close();
    } catch (final XMLStreamException e) {
        throw new SubversionException("could not create request body", e);
    }

    final URI uri = URIUtils.createURI(repository, resource);
    final DavTemplateRequest request = new DavTemplateRequest("REPORT", uri);
    request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML));
    return request;
}

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");
    }/*from w w w .  j a  v a2s.c o m*/
    w.writeEndElement();
    w.writeEndElement();
    w.writeEndDocument();
    w.flush();

    return new ResponseEntity<>(sw.toString(), HttpStatus.OK);
}

From source file:com.flexive.core.IMParser.java

/**
 * Parse an identify stdOut result (from in) and convert it to an XML content
 *
 * @param in identify response/*from  ww  w .j a va2s  . c o m*/
 * @return XML content
 * @throws XMLStreamException on errors
 * @throws IOException        on errors
 */
public static String parse(InputStream in) throws XMLStreamException, IOException {
    StringWriter sw = new StringWriter(2000);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
    writer.writeStartDocument();

    int lastLevel = 0, level, lastNonValueLevel = 1;
    boolean valueEntry;
    String curr = null;
    String[] entry;
    try {
        while ((curr = br.readLine()) != null) {
            if (curr.indexOf(':') == -1 || curr.trim().length() == 0) {
                System.out.println("skipping: [" + curr + "]");
                continue; //ignore lines without ':'
            }
            level = getLevel(curr);
            curr = curr.trim();
            if (level == 0 && curr.startsWith("Image:")) {
                writer.writeStartElement("Image");
                entry = curr.split(": ");
                if (entry.length >= 2)
                    writer.writeAttribute("source", entry[1]);
                lastLevel = level;
                continue;
            }
            if (!(valueEntry = pNumeric.matcher(curr).matches())) {
                while (level < lastLevel--)
                    writer.writeEndElement();
                lastNonValueLevel = level;
            } else
                level = lastNonValueLevel + 1;
            if (curr.endsWith(":")) {
                writer.writeStartElement(cleanElement(curr.substring(0, curr.lastIndexOf(':'))));
                lastLevel = level + 1;
                continue;
            } else if (pColormap.matcher(curr).matches()) {
                writer.writeStartElement(cleanElement(curr.substring(0, curr.lastIndexOf(':'))));
                writer.writeAttribute("colors", curr.split(": ")[1].trim());
                lastLevel = level + 1;
                continue;
            }
            entry = curr.split(": ");
            if (entry.length == 2) {
                if (!valueEntry) {
                    writer.writeStartElement(cleanElement(entry[0]));
                    writer.writeCharacters(entry[1]);
                    writer.writeEndElement();
                } else {
                    writer.writeEmptyElement("value");
                    writer.writeAttribute("key", cleanElement(entry[0]));
                    writer.writeAttribute("data", entry[1]);
                    //                        writer.writeEndElement();
                }
            } else {
                //                    System.out.println("unknown line: "+curr);
            }
            lastLevel = level;
        }
    } catch (Exception e) {
        System.err.println("Error at [" + curr + "]:" + e.getMessage());
        e.printStackTrace();
    }

    writer.writeEndDocument();
    writer.flush();
    writer.close();
    return sw.getBuffer().toString();
}

From source file:com.flexive.shared.media.impl.FxMediaImageMagickEngine.java

/**
 * Parse an identify stdOut result (from in) and convert it to an XML content
 *
 * @param in identify response/*  w w w . j  a  v  a2 s  .  c  o  m*/
 * @return XML content
 * @throws XMLStreamException on errors
 * @throws IOException        on errors
 */
public static String parse(InputStream in) throws XMLStreamException, IOException {
    StringWriter sw = new StringWriter(2000);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
    writer.writeStartDocument();

    int lastLevel = 0, level, lastNonValueLevel = 1;
    boolean valueEntry;
    String curr = null;
    String[] entry;
    try {
        while ((curr = br.readLine()) != null) {
            level = getLevel(curr);
            if (level == 0 && curr.startsWith("Image:")) {
                writer.writeStartElement("Image");
                entry = curr.split(": ");
                if (entry.length >= 2)
                    writer.writeAttribute("source", entry[1]);
                lastLevel = level;
                continue;
            }
            if (!(valueEntry = pNumeric.matcher(curr).matches())) {
                while (level < lastLevel--)
                    writer.writeEndElement();
                lastNonValueLevel = level;
            } else
                level = lastNonValueLevel + 1;
            if (curr.endsWith(":")) {
                writer.writeStartElement(
                        curr.substring(0, curr.lastIndexOf(':')).trim().replaceAll("[ :]", "-"));
                lastLevel = level + 1;
                continue;
            } else if (pColormap.matcher(curr).matches()) {
                writer.writeStartElement(
                        curr.substring(0, curr.lastIndexOf(':')).trim().replaceAll("[ :]", "-"));
                writer.writeAttribute("colors", curr.split(": ")[1].trim());
                lastLevel = level + 1;
                continue;
            }
            entry = curr.split(": ");
            if (entry.length == 2) {
                if (!valueEntry) {
                    writer.writeStartElement(entry[0].trim().replaceAll("[ :]", "-"));
                    writer.writeCharacters(entry[1]);
                    writer.writeEndElement();
                } else {
                    writer.writeEmptyElement("value");
                    writer.writeAttribute("key", entry[0].trim().replaceAll("[ :]", "-"));
                    writer.writeAttribute("data", entry[1]);
                    //                        writer.writeEndElement();
                }
            } else {
                //                    System.out.println("unknown line: "+curr);
            }
            lastLevel = level;
        }
    } catch (Exception e) {
        LOG.error("Error at [" + curr + "]:" + e.getMessage(), e);
    }
    writer.writeEndDocument();
    writer.flush();
    writer.close();
    return sw.getBuffer().toString();
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Creates the <code>type</code> tag used for attributes and default values.
 * //from  ww  w . j  a  va 2s  .c  o  m
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @param domain
 *            {@link Domain} the type of the current {@link Attribute}
 * @throws XMLStreamException
 */
private void createType(XMLStreamWriter writer, Domain domain) throws XMLStreamException {
    // create type
    writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_TYPE);
    if (domain instanceof BooleanDomain) {
        // BooleanDomain
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.TYPE_VALUE_PRIMITIVETYPE);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF,
                XMIConstants4SchemaGraph2XMI.TYPE_HREF_VALUE_BOOLEAN);
    } else if (domain instanceof IntegerDomain) {
        // IntegerDomain
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.TYPE_VALUE_PRIMITIVETYPE);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF,
                XMIConstants4SchemaGraph2XMI.TYPE_HREF_VALUE_INTEGER);
    } else {
        // StringDomain
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.TYPE_VALUE_PRIMITIVETYPE);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF,
                XMIConstants4SchemaGraph2XMI.TYPE_HREF_VALUE_STRING);
    }
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

private void createGeneralization(XMLStreamWriter writer, String id, String idOfSpecializedClass)
        throws XMLStreamException {
    // create generalization
    writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_GENERALIZATION);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.GENERALIZATION_TYPE_VALUE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.GENERALIZATION_ATTRIBUTE_GENERAL, idOfSpecializedClass);
}