Example usage for org.dom4j.tree DefaultProcessingInstruction getTarget

List of usage examples for org.dom4j.tree DefaultProcessingInstruction getTarget

Introduction

In this page you can find the example usage for org.dom4j.tree DefaultProcessingInstruction getTarget.

Prototype

public String getTarget() 

Source Link

Usage

From source file:org.orbeon.oxf.processor.transformer.XPathProcessor.java

License:Open Source License

public static void streamResult(PipelineContext context, XMLReceiver xmlReceiver, Object result,
        LocationData locationData) throws SAXException {

    String strVal = null;//from  ww w  .ja  va  2 s. c  o m
    if (result instanceof Element || result instanceof Document) {
        // If element or document, serialize it to content handler
        final Element element = result instanceof Element ? (Element) result
                : ((Document) result).getRootElement();
        final String systemId = Dom4jUtils.makeSystemId(element);
        // TODO: Should probably use Dom4jUtils.createDocumentCopyParentNamespaces() or equivalent to handle namespaces better
        // -> could maybe simply get the list of namespaces in scope on both sides, and output start/endPrefixMapping()
        final DOMGenerator domGenerator = new DOMGenerator(element, "xpath result doc",
                DOMGenerator.ZeroValidity, systemId);
        final ProcessorOutput domOutput = domGenerator.createOutput(OUTPUT_DATA);
        domOutput.read(context, new EmbeddedDocumentXMLReceiver(xmlReceiver));
    } else if (result instanceof NodeInfo) {
        final NodeInfo nodeInfo = (NodeInfo) result;
        TransformerUtils.writeTinyTree(nodeInfo, new EmbeddedDocumentXMLReceiver(xmlReceiver));
    } else if (result instanceof DefaultProcessingInstruction) {
        DefaultProcessingInstruction processingInstruction = (DefaultProcessingInstruction) result;
        xmlReceiver.processingInstruction(processingInstruction.getTarget(), processingInstruction.getText());
    } else if (result instanceof DefaultText) {
        strVal = ((DefaultText) result).getText();
    } else if (result instanceof String) {
        strVal = (String) result;
    } else if (result instanceof Long) {
        strVal = Long.toString((Long) result);
    } else if (result instanceof Double) {
        final double d = ((Double) result).doubleValue();
        strVal = XMLUtils.removeScientificNotation(d);
    } else if (result instanceof Boolean) {
        strVal = (result.toString());
    } else if (result instanceof StringBuilder) {
        strVal = result.toString();
    } else {
        String message = "Unsupported type returned by XPath expression: "
                + (result == null ? "null" : result.getClass().getName());
        throw new ValidationException(message, locationData);
    }

    // Send string representation of simple type to content handler
    if (strVal != null) {
        final char[] ch = strVal.toCharArray();
        final int len = strVal.length();
        xmlReceiver.characters(ch, 0, len);
    }
}