Example usage for javax.xml.stream XMLStreamWriter writeAttribute

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

Introduction

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

Prototype

public void writeAttribute(String localName, String value) throws XMLStreamException;

Source Link

Document

Writes an attribute to the output stream without a prefix.

Usage

From source file:com.norconex.collector.http.sitemap.impl.DefaultSitemapResolver.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/*  w  w w. j  a  v  a  2  s .  c o  m*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("sitemap");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeAttribute("lenient", Boolean.toString(lenient));
        if (sitemapLocations != null) {
            for (String location : sitemapLocations) {
                writer.writeStartElement("location");
                writer.writeCharacters(location);
                writer.writeEndElement();
            }
        }
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

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

protected void toJXMLString_1(XMLStreamWriter writer, boolean writeCDataSections)
        throws XMLStreamException, FioranoException {
    if (writeCDataSections)
        writeCDATAElement(writer, ELEM_JMS_SCRIPT, jmsScript);
    else {/*from  www .j a va  2 s  .  c o m*/
        if (jmsScriptFile != null) {
            writer.writeStartElement(ELEM_JMS_SCRIPT_FILE);
            writer.writeAttribute(ATTR_NAME, jmsScriptFile);
            writer.writeEndElement();
        }
    }
}

From source file:com.github.fritaly.graphml4j.ShapeStyle.java

private void writeDropShadow(XMLStreamWriter writer) throws XMLStreamException {
    Validate.notNull(writer, "The given stream writer is null");

    if ((shadowColor == null) || ((shadowOffsetX == 0) && (shadowOffsetY == 0))) {
        // Nothing to render
        return;/* www  .ja  v  a 2s  .c  o  m*/
    }

    // y:DropShadow
    writer.writeEmptyElement("y:DropShadow");
    writer.writeAttribute("color", Utils.encode(shadowColor));
    writer.writeAttribute("offsetX", Integer.toString(shadowOffsetX));
    writer.writeAttribute("offsetY", Integer.toString(shadowOffsetY));
}

From source file:com.github.fritaly.graphml4j.GeneralStyle.java

private void writeGeometry(XMLStreamWriter writer, float x, float y) throws XMLStreamException {
    Validate.notNull(writer, "The given stream writer is null");

    // y:Geometry (the x & y attributes are computed when laying out the graph in yEd)
    writer.writeEmptyElement("y:Geometry");
    writer.writeAttribute("height", String.format("%.1f", height));
    writer.writeAttribute("width", String.format("%.1f", width));
    writer.writeAttribute("x", String.format("%.1f", x));
    writer.writeAttribute("y", String.format("%.1f", y));
}

From source file:com.fiorano.openesb.application.common.Param.java

public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException {
    //Start Param
    writer.writeStartElement("Param");
    writer.writeAttribute("name", m_paramName);
    writer.writeCharacters(m_paramValue);
    //End Param/*from   w  w w .jav  a  2  s . c  om*/
    writer.writeEndElement();
}

From source file:org.xmlsh.internal.commands.http.java

private void writeHeaders(String outv, StatusLine statusLine, Header[] allHeaders)
        throws XMLStreamException, SaxonApiException, CoreException, IOException {
    OutputPort out = mShell.getEnv().getOutputPort(outv);

    XMLStreamWriter sw = out.asXMLStreamWriter(getSerializeOpts());
    sw.writeStartDocument();//from   w w w .j  a  v a2 s.  c  o m
    sw.writeStartElement("status");
    sw.writeAttribute("status-code", String.valueOf(statusLine.getStatusCode()));
    sw.writeAttribute("reason", statusLine.getReasonPhrase());
    sw.writeAttribute("protocol-version", statusLine.getProtocolVersion().toString());

    sw.writeEndElement();

    sw.writeStartElement("headers");
    for (Header header : allHeaders) {
        sw.writeStartElement("header");
        sw.writeAttribute("name", header.getName());
        sw.writeAttribute("value", header.getValue());
        sw.writeEndElement();
    }
    sw.writeEndElement();
    sw.writeEndDocument();
    sw.close();

}

From source file:com.github.fritaly.graphml4j.EdgeStyle.java

void writeTo(XMLStreamWriter writer) throws XMLStreamException {
    Validate.notNull(writer, "The given stream writer is null");

    // What is the path used for ?
    // TODO Create properties for sx, sy, tx and ty

    // y:Path// w w  w. j  a va 2s. co  m
    writer.writeEmptyElement("y:Path");
    writer.writeAttribute("sx", String.format("%.1f", 0.0f));
    writer.writeAttribute("sy", String.format("%.1f", 0.0f));
    writer.writeAttribute("tx", String.format("%.1f", 0.0f));
    writer.writeAttribute("ty", String.format("%.1f", 0.0f));

    // y:LineStyle
    writer.writeEmptyElement("y:LineStyle");
    writer.writeAttribute("color", Utils.encode(color));
    writer.writeAttribute("type", type.getValue());
    writer.writeAttribute("width", String.format("%.1f", width));

    // y:Arrows
    writer.writeEmptyElement("y:Arrows");
    writer.writeAttribute("source", sourceArrow.getValue());
    writer.writeAttribute("target", targetArrow.getValue());

    // y:BendStyle
    writer.writeEmptyElement("y:BendStyle");
    writer.writeAttribute("smoothed", Boolean.toString(smoothed));
}

From source file:org.maodian.flyingcat.xmpp.extensions.xep0030.QueryInfoCodec.java

@Override
public void encode(Object object, XMLStreamWriter xmlsw) throws XMLStreamException {
    xmlsw.writeStartElement("", "query", ServiceDiscovery.INFORMATION);
    xmlsw.writeDefaultNamespace(ServiceDiscovery.INFORMATION);

    QueryInfo qi = (QueryInfo) object;//from   www. j  a  v a2  s. c  om
    List<Identity> identityList = qi.getIdentityList();
    for (Identity identity : identityList) {
        xmlsw.writeEmptyElement("", "identity", ServiceDiscovery.INFORMATION);
        xmlsw.writeAttribute("category", identity.getCategory());
        xmlsw.writeAttribute("type", identity.getType());
    }

    List<Feature> featureList = qi.getFeatureList();
    for (Feature feature : featureList) {
        xmlsw.writeEmptyElement(ServiceDiscovery.INFORMATION, "feature");
        xmlsw.writeAttribute("var", feature.getVar());
    }
}

From source file:XMLWriteTest.java

/**
 * Writers an SVG document of the current drawing.
 * @param writer the document destination
 *///from ww w  .  j a va2 s .c o m
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:com.concursive.connect.web.modules.api.services.BackupService.java

private void save(XMLStreamWriter writer, DataRecord record, String recordId, Object object,
        PacketContext context) throws Exception {
    // Data record
    writer.writeCharacters("  ");
    writer.writeStartElement("dataRecord");
    writer.writeAttribute("name", record.getName());
    writer.writeAttribute("id", recordId);
    writer.writeCharacters(System.getProperty("line.separator"));
    // Data fields
    for (DataField thisField : record) {
        writer.writeCharacters("    ");
        writer.writeStartElement(thisField.getName());
        if (thisField.getValue() != null) {
            if (StringUtils.countLines(thisField.getValue()) > 1) {
                writer.writeCData(thisField.getValue());
            } else {
                writer.writeCharacters(thisField.getValue());
            }//from   w  ww. j ava  2  s .co  m
        } else {
            writer.writeCharacters(DataRecord.NULL);
        }
        writer.writeEndElement();
        writer.writeCharacters(System.getProperty("line.separator"));
    }

    // If this is a file, stream it too
    if (object instanceof FileItem) {
        // Find the file in the filesystem
        File file = new File(context.getBaseFilePath()
                + DateUtils.getDatePath(record.getValueAsTimestamp("modified")) + record.getValue("filename"));
        if (!file.exists()) {
            LOG.error("File not found: " + file.getAbsolutePath());
        } else {
            // If there is a fileAttachment, then attach it as base64
            writer.writeCharacters("    ");
            writer.writeStartElement("fileAttachment");
            // Convert to base64 and append
            writer.writeCData(new String(Base64.encodeBase64(FileUtils.getBytesFromFile(file), true)));
            // Close the element
            writer.writeEndElement();
            writer.writeCharacters(System.getProperty("line.separator"));
        }
    }

    // Close the record
    writer.writeCharacters("  ");
    writer.writeEndElement();
    writer.writeCharacters(System.getProperty("line.separator"));
}