Example usage for javax.xml.stream XMLStreamWriter writeProcessingInstruction

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

Introduction

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

Prototype

public void writeProcessingInstruction(String target, String data) throws XMLStreamException;

Source Link

Document

Writes a processing instruction

Usage

From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java

private static final void writeProcessingInstruction(final DmProcessingInstruction pi,
        final XMLStreamWriter xsw) throws XMLStreamException {
    xsw.writeProcessingInstruction(pi.getName().getLocalPart(), pi.getStringValue());
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java

private static final void writeMappingDocument(final XmiComparison documentElement, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeProcessingInstruction("xml-stylesheet", "type='text/xsl' href='xmi-mapping.xsl'");
    xsw.setPrefix("", XmiMappingConstants.NAMESPACE_URI);
    xsw.writeStartElement(XmiMappingConstants.DOCUMENT_ELEMENT.getLocalPart());
    xsw.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    xsw.writeAttribute("xsi", "http://www.w3.org/2001/XMLSchema-instance", "noNamespaceSchemaLocation",
            "xmi-mapping.xsd");
    try {/*w  w w  .j av a2  s  .c o m*/
        writeReference(documentElement.getLhsDef(), XmiMappingConstants.LHS_MODEL, xsw);
        writeReference(documentElement.getRhsDef(), XmiMappingConstants.RHS_MODEL, xsw);
        for (final XmiMapping mapping : documentElement.getMappings()) {
            writeMapping(mapping, xsw);
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.wso2.carbon.core.transports.util.AtomProcessor.java

public void process(HttpServletRequest request, HttpServletResponse response,
        ConfigurationContext configurationContext) throws Exception {
    try {/*from  w  ww . j a v  a  2 s  .c o  m*/
        response.setContentType("text/xml; charset=utf-8");
        AtomFeed atomFeed = FeedFactory.getAtomFeed(FeedConstants.WSO2WSAS_ATOM_FEED,
                configurationContext.getAxisConfiguration());
        if (atomFeed != null) {
            XMLStreamWriter writer = XMLOutputFactory.newInstance()
                    .createXMLStreamWriter(response.getOutputStream());
            writer.writeProcessingInstruction("xml-stylesheet",
                    "  type=\"text/xsl\" href=\"" + (configurationContext.getContextRoot().equals("/") ? ""
                            : configurationContext.getContextRoot()) + "/styles/atom.xsl\"");
            OMElement feedElement = atomFeed.getFeedElement(configurationContext.getServiceContextPath());
            feedElement.serialize(writer);
            writer.flush();
        }
    } catch (Exception e) {
        log.error("Could not process ATOM feed", e);
    }
}

From source file:org.wso2.carbon.core.transports.util.RequestProcessorUtil.java

/**
 * @param byteArrayOutStream//  w  w  w  .java  2s.  c o m
 * @param out
 * @param annotatedXsl
 * @param contextRoot
 * @param annotation         : If annotation is false PI would not be attached.
 */
public static void writeDocument(ByteArrayOutputStream byteArrayOutStream, OutputStream out,
        String annotatedXsl, String contextRoot, boolean annotation) {
    XMLStreamWriter writer;
    ByteArrayInputStream bais = null;
    XMLStreamReader reader = null;
    try {
        bais = new ByteArrayInputStream(byteArrayOutStream.toByteArray());
        reader = XMLInputFactory.newInstance().createXMLStreamReader(bais);
        StAXOMBuilder builder = new StAXOMBuilder(reader);
        OMElement docElem = builder.getDocumentElement();
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
        if (annotatedXsl != null && annotation) {
            writer.writeProcessingInstruction("xml-stylesheet", "  type=\"text/xsl\" href=\""
                    + (contextRoot.equals("/") ? "" : contextRoot) + "/styles/" + annotatedXsl + "\"");
        }
        docElem.serialize(writer);
        writer.flush();
    } catch (XMLStreamException e) {
        log.error("Error occurred while trying to write processing instruction for attaching "
                + "annotated style sheet", e);
    } finally {
        try {
            if (bais != null) {
                bais.close();
            }
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (XMLStreamException e) {
            log.error(e.getMessage(), e);
        }

    }
}

From source file:org.wso2.carbon.core.transports.util.RssProcessor.java

public void process(HttpServletRequest request, HttpServletResponse response,
        ConfigurationContext configurationContext) throws Exception {
    try {//from  ww  w.j a  v  a  2 s  .  c om
        response.setContentType("text/xml; charset=utf-8");
        RSSFeed rssFeed = FeedFactory.getRSSFeed(FeedConstants.WSO2WSAS_RSS_FEED,
                configurationContext.getAxisConfiguration());
        if (rssFeed != null) {
            XMLStreamWriter writer = XMLOutputFactory.newInstance()
                    .createXMLStreamWriter(response.getOutputStream());
            writer.writeProcessingInstruction("xml-stylesheet",
                    "  type=\"text/xsl\" href=\"" + (configurationContext.getContextRoot().equals("/") ? ""
                            : configurationContext.getContextRoot()) + "/styles/rss.xsl\"");
            OMElement feedElement = rssFeed.getFeedElement(configurationContext.getServiceContextPath());
            feedElement.serialize(writer);
            writer.flush();
        }
    } catch (Exception e) {
        log.error("Could not process RSS feed", e);
    }
}