Example usage for javax.xml.stream XMLEventWriter getNamespaceContext

List of usage examples for javax.xml.stream XMLEventWriter getNamespaceContext

Introduction

In this page you can find the example usage for javax.xml.stream XMLEventWriter getNamespaceContext.

Prototype

public NamespaceContext getNamespaceContext();

Source Link

Document

Returns the current namespace context.

Usage

From source file:sapience.injectors.stax.inject.ModelBasedStaxStreamInjector.java

/**
 * If the reference is more then a simple attribute, we have to add new XML (subtree) to the stream. We transform
 * the reference into an InputStream and invoke another SAX parsing process for it. But the parsed events are added
 * to the main XMLEventWriter. //  w ww  .  j a v  a2 s.c  om
 *
 * @param w
 * @param string
 * @throws XMLStreamException 
 * @throws XMLStreamException
 */
private void createEventsForElement(XMLEventWriter w, Reference ref) throws XMLStreamException {
    XMLEventReader r = null;
    try {
        StringBuilder target = new StringBuilder(ref.getTarget().toString());

        NamespaceContext c = w.getNamespaceContext();

        ByteArrayInputStream bais = new ByteArrayInputStream(target.toString().getBytes());
        getXMLInputFactory().setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
        r = getXMLInputFactory().createXMLEventReader(bais);

        while (r.hasNext()) {
            XMLEvent e = r.nextEvent();
            switch (e.getEventType()) {
            case XMLEvent.START_DOCUMENT:
                break;
            case XMLEvent.END_DOCUMENT:
                break;
            default:
                w.add(e);
                break;
            }
        }
    } finally {
        ;

        if (r != null)
            r.close();
    }

}

From source file:sapience.injectors.stax.inject.StringBasedStaxStreamInjector.java

/**
 * If the reference is more then a simple attribute, we have to add new XML (subtree) to the stream. We transform
 * the reference into an InputStream and invoke another SAX parsing process for it. But the parsed events are added
 * to the main XMLEventWriter. /*from  w w w . j  a v  a 2  s  . c o m*/
 *
 * @param w
 * @param string
 * @throws XMLStreamException 
 * @throws XMLStreamException
 */
private void createEventsForElement(XMLEventWriter w, Reference ref) throws XMLStreamException {
    XMLEventReader r = null;
    try {
        StringBuilder target = new StringBuilder(ref.getTarget().toString());

        NamespaceContext c = w.getNamespaceContext();

        // process namespaces
        //processNamespace(target, w.getNamespaceContext());

        ByteArrayInputStream bais = new ByteArrayInputStream(target.toString().getBytes());
        this.inFac.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
        r = this.inFac.createXMLEventReader(bais);
        // start a new line

        while (r.hasNext()) {
            XMLEvent e = r.nextEvent();
            switch (e.getEventType()) {
            case XMLEvent.START_DOCUMENT:
                break;
            case XMLEvent.END_DOCUMENT:
                break;
            default:
                w.add(e);
                break;
            }
        }
    } finally {
        ;

        if (r != null)
            r.close();
    }

}