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 namespaceURI, String localName) throws XMLStreamException;

Source Link

Document

Writes a start tag to the output

Usage

From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java

public static void main(String[] args) {

    logger.info("Starting application [ rtd ] ...");

    try {/*from w ww. j  a v a 2  s.  c  o m*/

        config.addConfiguration(
                new XMLConfiguration(RetrieveTestData.class.getClassLoader().getResource(CONFIG_FILENAME)));

        HierarchicalConfiguration appConfig = config.configurationAt(APPLICATION_CONFIG_ROOT);

        EodDataProvider eodDataProvider = null;

        OutputStream out = new FileOutputStream(OUTPUT_FILENAME);
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);

        eodDataProvider = EodDataProviderFactory.create(appConfig, EODDATA_PROVIDER_NAME);

        writer.writeStartDocument("utf-8", "1.0");
        writer.writeCharacters(NEWLINE);
        writer.writeComment("Test data for running DataScraper unit tests against");
        writer.writeCharacters(NEWLINE);

        writer.setPrefix(XML_PREFIX, XML_NAMESPACE_URI);

        writer.writeStartElement(XML_NAMESPACE_URI, TESTDATA_LOCALNAME);
        writer.writeNamespace(XML_PREFIX, XML_NAMESPACE_URI);
        writer.writeCharacters(NEWLINE);

        serializeExchanges(eodDataProvider, writer);
        serializeSymbols(eodDataProvider, writer);
        serializeQuotes(eodDataProvider, writer);

        writer.writeEndElement();
        writer.writeCharacters(NEWLINE);
        writer.writeEndDocument();
        writer.flush();
        writer.close();

    } catch (ConfigurationException ce) {

        logger.error(ce.toString());
        ce.printStackTrace();

    } catch (Exception e) {

        logger.error(e.toString());
        logger.error(e);

    }

    logger.info("Exiting application [ rtd ] ...");

}

From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java

private static void serializeExchanges(EodDataProvider eodDataProvider, XMLStreamWriter writer) {

    try {//from   ww  w .  j  a v a  2  s . co  m
        writer.writeStartElement(XML_NAMESPACE_URI, EXCHANGES_LOCALNAME);
        writer.writeCharacters(NEWLINE);
        serialize(eodDataProvider.getExchanges(), EXCHANGE_QNAME, writer);
        writer.writeEndElement();
        writer.writeCharacters(NEWLINE);
    } catch (XMLStreamException xse) {
        logger.error(xse.toString());
        logger.error(xse);
    } catch (EodDataProviderException edpe) {

        logger.error(edpe.toString());
        logger.error(edpe);

    } finally {

        if (eodDataProvider != null) {

            // eodDataProvider.close();

        }

    }

}

From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java

private static void serializeSymbols(EodDataProvider eodDataProvider, XMLStreamWriter writer) {

    try {//from   w  w  w  .j  av  a 2 s .com
        writer.writeStartElement(XML_NAMESPACE_URI, SYMBOLS_LOCALNAME);
        writer.writeAttribute(XML_NAMESPACE_URI, TESTEXCHANGE_ATTRNAME, TEST_EXCHANGE);
        writer.writeCharacters(NEWLINE);
        serialize(eodDataProvider.getSymbols(TEST_EXCHANGE), SYMBOL_QNAME, writer);
        writer.writeEndElement();
        writer.writeCharacters(NEWLINE);
    } catch (XMLStreamException xse) {
        logger.error(xse.toString());
        logger.error(xse);
    } catch (EodDataProviderException edpe) {

        logger.error(edpe.toString());
        logger.error(edpe);

    } finally {

        if (eodDataProvider != null) {

            // eodDataProvider.close();

        }

    }

}

From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java

private static void serializeQuotes(EodDataProvider eodDataProvider, XMLStreamWriter writer) {

    try {//from  ww  w  .j  a  v  a  2s .  c  o  m
        writer.writeStartElement(XML_NAMESPACE_URI, QUOTES_LOCALNAME);
        writer.writeAttribute(XML_NAMESPACE_URI, TESTEXCHANGE_ATTRNAME, TEST_EXCHANGE);
        writer.writeAttribute(XML_NAMESPACE_URI, TESTSYMBOL_ATTRNAME, TEST_SYMBOL);
        writer.writeCharacters(NEWLINE);

        Calendar startCalendar = Calendar.getInstance();
        startCalendar.add(Calendar.YEAR, HISTORY_YEAR_OFFSET);
        //    startCalendar.add(Calendar.MONTH, HISTORY_MONTH_OFFSET);

        Calendar endCalendar = Calendar.getInstance();

        serialize(eodDataProvider.getQuotes(TEST_EXCHANGE, TEST_SYMBOL, startCalendar, endCalendar,
                DEFAULT_FREQUENCY), QUOTE_QNAME, writer);
        writer.writeEndElement();
        writer.writeCharacters(NEWLINE);
    } catch (XMLStreamException xse) {
        logger.error(xse.toString());
        logger.error(xse);
    } catch (EodDataProviderException edpe) {

        logger.error(edpe.toString());
        logger.error(edpe);

    } finally {

        if (eodDataProvider != null) {

            // eodDataProvider.close();

        }

    }

}

From source file:org.apache.chemistry.opencmis.server.impl.atompub.AtomDocumentBase.java

/**
 * Writes a simple tag./*from w w w  .j a va 2 s  .  c  o m*/
 */
public void writeSimpleTag(String namespace, String name, String value) throws XMLStreamException {
    if (value == null) {
        return;
    }

    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(namespace, name);
    xsw.writeCharacters(value);
    xsw.writeEndElement();
}

From source file:org.apache.chemistry.opencmis.server.impl.atompub.AtomDocumentBase.java

/**
 * Writes an Atom author tag.//from  ww w  .  j a  v a  2  s  .  c  o m
 */
public void writeAuthor(String author) throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(Constants.NAMESPACE_ATOM, "author");
    writeSimpleTag(Constants.NAMESPACE_ATOM, "name", author);
    xsw.writeEndElement();
}

From source file:org.apache.chemistry.opencmis.server.impl.atompub.AtomDocumentBase.java

/**
 * Writes an Atom collection./*  w  w w . j  a  va2  s. com*/
 */
public void writeCollection(String href, String collectionType, String text, String... accept)
        throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(Constants.NAMESPACE_APP, "collection");
    xsw.writeAttribute("href", href);

    if (collectionType != null) {
        xsw.writeStartElement(Constants.NAMESPACE_RESTATOM, "collectionType");
        xsw.writeCharacters(collectionType);
        xsw.writeEndElement();
    }

    xsw.writeStartElement(Constants.NAMESPACE_ATOM, "title");
    xsw.writeAttribute("type", "text");
    xsw.writeCharacters(text);
    xsw.writeEndElement();

    for (String ct : accept) {
        xsw.writeStartElement(Constants.NAMESPACE_APP, "accept");
        xsw.writeCharacters(ct);
        xsw.writeEndElement();
    }

    xsw.writeEndElement();
}

From source file:org.apache.chemistry.opencmis.server.impl.atompub.AtomDocumentBase.java

/**
 * Writes a link.//from  w  ww. java 2s  .  c om
 */
public void writeLink(String rel, String href, String type, String id) throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(Constants.NAMESPACE_ATOM, "link");

    xsw.writeAttribute("rel", rel);
    xsw.writeAttribute("href", href);

    if (type != null) {
        xsw.writeAttribute("type", type);
    }

    if (id != null) {
        xsw.writeAttribute(Constants.NAMESPACE_RESTATOM, "id", id);
    }

    xsw.writeEndElement();
}

From source file:org.apache.chemistry.opencmis.server.impl.atompub.AtomDocumentBase.java

public void writeAlternateLink(String href, String type, String kind, String title, BigInteger length)
        throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(Constants.NAMESPACE_ATOM, "link");

    xsw.writeAttribute("rel", Constants.REL_ALTERNATE);
    xsw.writeAttribute("href", href);

    if (type != null) {
        xsw.writeAttribute("type", type);
    }//w w  w.j av a 2 s  .c  om

    if (kind != null) {
        xsw.writeAttribute(Constants.NAMESPACE_RESTATOM, "renditionKind", kind);
    }

    if (title != null) {
        xsw.writeAttribute("title", title);
    }

    if (length != null) {
        xsw.writeAttribute("length", length.toString());
    }

    xsw.writeEndElement();
}

From source file:org.apache.flex.compiler.config.Configuration.java

/**
 * Write the data to rdf/xml/*from  w w  w.  ja v  a  2  s .co  m*/
 * 
 * @param writer
 * @throws XMLStreamException
 */
private void writeDate(XMLStreamWriter writer) throws XMLStreamException {
    if (date == null) {
        date = DateFormat.getDateInstance().format(new Date());
    }

    writer.writeStartElement(DC_URI, "date");
    writer.writeCharacters(date);
    writer.writeEndElement();
}