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:Main.java

public static void writeElement(XMLStreamWriter writer, String elementName, String characterData)
        throws XMLStreamException {
    writer.writeStartElement(elementName);
    writer.writeCharacters(characterData);
    writer.writeEndElement();//from ww  w  .ja  va 2s.  c  o m
}

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);
    serializer.writeCharacters(content);
    serializer.writeEndElement(); // end simple tag
    return serializer;
}

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

/**
 * Write a "simple" tag//www  .  j  a  va  2 s . co  m
 *
 * @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:Main.java

public static void writeTag(XMLStreamWriter xmlWriter, String tag, Object value) throws XMLStreamException {
    if (value == null) {
        xmlWriter.writeEmptyElement(tag);
    } else {//from   ww  w . j  av  a 2  s.co  m
        xmlWriter.writeStartElement(tag);
        xmlWriter.writeCData(value.toString());
        xmlWriter.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);
    }//w  w  w.ja  va2s  .  c  om

    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 ww  w .ja v  a 2 s. c  om
    }
    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;// ww  w  . j  a  v  a  2s . c om
    }
    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   w  ww  .j a  v a 2 s .  co  m
    }
    xml.writeStartElement("monitored-paths");
    for (File path : monitoredPaths) {
        xml.writeStartElement("path");
        xml.writeCharacters(path.getAbsolutePath());
        xml.writeEndElement();
    }
    xml.writeEndElement();
}

From source file:gdv.xport.util.HtmlFormatter.java

private static void writeTagTo(final XMLStreamWriter xmlStreamWriter, final String tag, final String content)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement(tag);
    xmlStreamWriter.writeCharacters(content);
    xmlStreamWriter.writeEndElement();/*from   w w  w. ja  v a2s  . co m*/
}

From source file:gdv.xport.util.HtmlFormatter.java

private static void writeDetailsTo(final XMLStreamWriter xmlStreamWriter, final Satz satz, final int zeile)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("h3");
    xmlStreamWriter//from   www .  j ava 2s.  c  o  m
            .writeCharacters("Satzart " + satz.getSatzart() + " (" + satz.getClass().getSimpleName() + ")");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    int n = zeile;
    for (Iterator<Teildatensatz> iterator = satz.getTeildatensaetze().iterator(); iterator.hasNext();) {
        Teildatensatz teildatensatz = iterator.next();
        writeDetailsTo(xmlStreamWriter, teildatensatz, n);
        n++;
    }
    xmlStreamWriter.flush();
}