Example usage for javax.xml.stream XMLStreamWriter writeCharacters

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

Introduction

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

Prototype

public void writeCharacters(String text) throws XMLStreamException;

Source Link

Document

Write text to the output

Usage

From source file:Main.java

public static void writeIndent(XMLStreamWriter xmlsw, String indent) throws XMLStreamException {
    xmlsw.writeCharacters(indent);
}

From source file:Main.java

public static void writeValue(XMLStreamWriter writer, String name, String value) throws XMLStreamException {
    writer.writeStartElement(name);//from   w ww . j av a 2s  . co  m
    writer.writeCharacters(value);
    writer.writeEndElement();
}

From source file:Main.java

/**
 * write xml element start tag, data and end tag into XmlStreamWriter
 *
 * @param writer//  w  ww  .  j  a  va  2 s.  c  om
 * @param element
 * @param value
 * @throws XMLStreamException
 */
public static void writeSimpleDataElement(XMLStreamWriter writer, String element, String value)
        throws XMLStreamException {
    writer.writeStartElement(element);
    writer.writeCharacters(value);
    writer.writeEndElement();
}

From source file:Main.java

public static void writeElement(XMLStreamWriter writer, String elementName, String characterData)
        throws XMLStreamException {
    writer.writeStartElement(elementName);
    writer.writeCharacters(characterData);
    writer.writeEndElement();//ww  w  . j a  v a2s.com
}

From source file:Main.java

public static XMLStreamWriter CreateSimpleTagAndContent(XMLStreamWriter serializer, String tag, String content,
        boolean allow_empty) throws XMLStreamException {
    if (!allow_empty && content.equals(""))
        return serializer;
    serializer.writeStartElement(tag);/*from   w w w  . ja  v a2  s  . c  o  m*/
    serializer.writeCharacters(content);
    serializer.writeEndElement(); // end simple tag
    return serializer;
}

From source file:com.flexive.shared.FxXMLUtils.java

/**
 * Write a "simple" tag// w  ww  .  ja  va  2  s .c  om
 *
 * @param writer  xml writer
 * @param tag     tag name
 * @param value   value
 * @param asCData use CDData?
 * @throws javax.xml.stream.XMLStreamException
 *          on errors
 */
public static void writeSimpleTag(XMLStreamWriter writer, String tag, Object value, boolean asCData)
        throws XMLStreamException {
    writer.writeStartElement(tag);
    if (asCData)
        writer.writeCData(String.valueOf(value));
    else
        writer.writeCharacters(String.valueOf(value));
    writer.writeEndElement();
}

From source file:com.norconex.jefmon.model.ConfigurationDAO.java

public static void saveConfig(JEFMonConfig config) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Saving JEF config to: " + CONFIG_FILE);
    }//from   www .  j av  a2  s  .co m

    if (!CONFIG_FILE.exists()) {
        File configDir = new File(FilenameUtils.getFullPath(CONFIG_FILE.getAbsolutePath()));
        if (!configDir.exists()) {
            LOG.debug("Creating JEF Monitor config directory for: " + CONFIG_FILE);
            configDir.mkdirs();
        }
    }

    OutputStream out = new FileOutputStream(CONFIG_FILE);
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {
        XMLStreamWriter xml = factory.createXMLStreamWriter(out);
        xml.writeStartDocument();
        xml.writeStartElement("jefmon-config");

        xml.writeStartElement("instance-name");
        xml.writeCharacters(config.getInstanceName());
        xml.writeEndElement();

        xml.writeStartElement("default-refresh-interval");
        xml.writeCharacters(Integer.toString(config.getDefaultRefreshInterval()));
        xml.writeEndElement();

        saveRemoteUrls(xml, config.getRemoteInstanceUrls());
        saveMonitoredPaths(xml, config.getMonitoredPaths());
        saveJobActions(xml, config.getJobActions());

        xml.writeEndElement();
        xml.writeEndDocument();
        xml.flush();
        xml.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
    out.close();
}

From source file:com.norconex.jefmon.model.ConfigurationDAO.java

private static void saveRemoteUrls(XMLStreamWriter xml, String[] remoteUrls) throws XMLStreamException {
    if (remoteUrls == null) {
        return;//from   w  w w  .  j a  v  a  2  s . c  o m
    }
    xml.writeStartElement("remote-instances");
    for (String url : remoteUrls) {
        xml.writeStartElement("url");
        xml.writeCharacters(url);
        xml.writeEndElement();
    }
    xml.writeEndElement();
}

From source file:com.norconex.jefmon.model.ConfigurationDAO.java

private static void saveJobActions(XMLStreamWriter xml, IJobAction[] jobActions) throws XMLStreamException {
    if (jobActions == null) {
        return;//  www .jav  a2 s  .c  o  m
    }
    xml.writeStartElement("job-actions");
    for (IJobAction action : jobActions) {
        xml.writeStartElement("action");
        xml.writeCharacters(action.getClass().getName());
        xml.writeEndElement();
    }
    xml.writeEndElement();
}

From source file:com.norconex.jefmon.model.ConfigurationDAO.java

private static void saveMonitoredPaths(XMLStreamWriter xml, File[] monitoredPaths) throws XMLStreamException {
    if (monitoredPaths == null) {
        return;/*from   www .  java2s.co m*/
    }
    xml.writeStartElement("monitored-paths");
    for (File path : monitoredPaths) {
        xml.writeStartElement("path");
        xml.writeCharacters(path.getAbsolutePath());
        xml.writeEndElement();
    }
    xml.writeEndElement();
}