Example usage for org.dom4j QName QName

List of usage examples for org.dom4j QName QName

Introduction

In this page you can find the example usage for org.dom4j QName QName.

Prototype

public QName(String name, Namespace namespace) 

Source Link

Usage

From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JInputStreamInterpreter.java

License:Open Source License

private void setMessageContentItem(TResponseInfoContent responseInfoContent, Document document) {
    // Analyze the message state
    Element re = document.getRootElement();
    // Obtain the list of message elements.
    List messageList = re.elements(new QName(TInoNamespace.MESSAGE.getName(), inoNamespace));
    Iterator messageIter = messageList.iterator();
    // Iterate thru the list of messages.
    while (messageIter.hasNext()) {
        Element message = (Element) messageIter.next();
        // Obtain the messages returnValue.
        QName qname = new QName(TInoNamespace.RETURN_VALUE.getName(), inoNamespace);
        String returnValue = message.attributeValue(qname);
        TMessageLineContentItem[] messageLineContentArray = null;
        // Obtain the list of message lists within the message.
        qname = new QName(TInoNamespace.MESSAGE_LINE.getName(), inoNamespace);
        List messageLineList = message.elements(qname);
        // Go thru the list of message lines and retrieve for each the subject and text content.
        if (messageLineList.size() > 0) {
            messageLineContentArray = new TMessageLineContentItem[messageLineList.size()];
            int index = 0;
            Iterator messageLineIter = messageLineList.iterator();
            while (messageLineIter.hasNext()) {
                Element messageLine = (Element) messageLineIter.next();
                qname = new QName(TInoNamespace.SUBJECT.getName(), inoNamespace);
                String subject = messageLine.attributeValue(qname);
                qname = new QName(TInoNamespace.UNIT.getName(), inoNamespace);
                String unit = messageLine.attributeValue(qname);
                String text = messageLine.getText();
                // Instantiate the message line content item.
                TMessageLineContentItem messageLineContentItem = responseContentItemFactory
                        .newMessageLineContentItem(subject, text);
                if (unit != null && !unit.equals("")) {
                    messageLineContentItem.addAttribute(TInoNamespace.UNIT.getQualifiedName(), unit);
                }//from  w w w . j  av  a 2s  . c om
                messageLineContentArray[index++] = messageLineContentItem;

            }
        }
        TMessageTextContentItem messageTextContent = null;
        // Obtain the message text if given.
        qname = new QName(TInoNamespace.MESSAGE_TEXT.getName(), inoNamespace);
        Element messageText = message.element(qname);
        if (messageText != null) {
            qname = new QName(TInoNamespace.CODE.getName(), inoNamespace);
            String code = messageText.attributeValue(qname);
            String text = messageText.getText();
            // Instantiate the message text content item for code and text content.
            messageTextContent = responseContentItemFactory.newMessageTextContentItem(code, text);
        }
        // Finally instantiate the message content with returnValue, message lines and message text.
        TMessageContentItem messageContent = responseContentItemFactory.newMessageContentItem(returnValue,
                messageLineContentArray, messageTextContent);
        // Put the message content into the info content.
        responseInfoContent.putItem(TMessageContentItem.SPECIFIER, messageContent);
    }
}

From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JInputStreamInterpreter.java

License:Open Source License

private void setQueryContentItem(TResponseInfoContent responseInfoContent, Document document) {
    Element re = document.getRootElement();
    QName qnameXQuery = new QName(TXQNamespace.XQUERY.getName(), xqNamespace);
    Element xqueryElement = re.element(qnameXQuery);
    if (xqueryElement != null) {
        TXQueryContentItem xqueryContentItem = responseContentItemFactory
                .newXQueryContentItem(xqueryElement.getText());
        responseInfoContent.putItem(TQueryContentItem.SPECIFIER, xqueryContentItem);
    } else {// w  ww  .ja va  2s.c om
        QName qnameQuery = new QName(TXQLNamespace.QUERY.getName(), xqlNamespace);
        Element queryElement = re.element(qnameQuery);
        if (queryElement != null) {
            TQueryContentItem queryContentItem = responseContentItemFactory
                    .newQueryContentItem(queryElement.getText());
            responseInfoContent.putItem(TQueryContentItem.SPECIFIER, queryContentItem);
        }
    }
}

From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JInputStreamInterpreter.java

License:Open Source License

private void setSessionContentItem(TResponseInfoContent responseInfoContent, Document document) {
    // Set the session state if one is given within the ino:response root tag
    Element re = document.getRootElement();
    QName qname = new QName(TInoNamespace.SESSION_ID.getName(), inoNamespace);
    String sessionId = re.attributeValue(qname);
    qname = new QName(TInoNamespace.SESSION_KEY.getName(), inoNamespace);
    String sessionKey = re.attributeValue(qname);
    if (sessionId != null && sessionKey != null) {
        TSessionContentItem sessionContentItem = responseContentItemFactory.newSessionContentItem(sessionId,
                sessionKey);//from  w  ww .  j av a 2 s.c om
        responseInfoContent.putItem(TSessionContentItem.SPECIFIER, sessionContentItem);
        // This is the place where the mode listener has to be called!!
        //transactionModeListener.sessionStateChanged( sessionId, sessionKey );
    }
}

From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JInputStreamInterpreter.java

License:Open Source License

private void setObjectContentItem(TResponseInfoContent responseInfoContent, Document document) {
    // Set the object state (only relevant for insert or update) if one is given within ino:object child element beneath root element
    Element re = document.getRootElement();
    QName qname = new QName(TInoNamespace.OBJECT.getName(), inoNamespace);
    Element obj = re.element(qname);
    if (obj != null) {
        qname = new QName(TInoNamespace.COLLECTION.getName(), inoNamespace);
        String collection = obj.attributeValue(qname);
        qname = new QName(TInoNamespace.DOCTYPE.getName(), inoNamespace);
        String doctype = obj.attributeValue(qname);
        qname = new QName(TInoNamespace.ID.getName(), inoNamespace);
        String id = obj.attributeValue(qname);
        TObjectContentItem objectContentItem = responseContentItemFactory.newObjectContentItem(collection,
                doctype, id);//from  w w w . j a  va  2 s  . c o  m
        responseInfoContent.putItem(TObjectContentItem.SPECIFIER, objectContentItem);
    }
}

From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JInputStreamInterpreter.java

License:Open Source License

private void setCursorContentItem(TResponseInfoContent responseInfoContent, Document document) {
    QName qname = new QName(TInoNamespace.CURSOR.getName(), inoNamespace);
    // Set the cursor state if one is given within ino:cursor element beneath root element
    Element re = document.getRootElement();
    Element ce = re.element(qname);
    if (ce != null) {
        // Get the cursor handle attribute of the cursor element
        qname = new QName(TInoNamespace.HANDLE.getName(), inoNamespace);
        String handleValue = ce.attributeValue(qname);
        // Get the count attribute of the cursor element if available
        qname = new QName(TInoNamespace.COUNT.getName(), inoNamespace);
        String countValue = ce.attributeValue(qname);
        // Get the current, next and previous attribute values of cursor structure
        qname = new QName(TInoNamespace.CURRENT.getName(), inoNamespace);
        Element current = ce.element(qname);
        qname = new QName(TInoNamespace.NEXT.getName(), inoNamespace);
        Element next = ce.element(qname);
        qname = new QName(TInoNamespace.PREVIOUS.getName(), inoNamespace);
        Element prev = ce.element(qname);
        // Get the concrete attribute values
        qname = new QName(TInoNamespace.POSITION.getName(), inoNamespace);
        String currentValue = (current != null) ? current.attributeValue(qname) : null;
        qname = new QName(TInoNamespace.QUANTITY.getName(), inoNamespace);
        String quantityValue = (current != null) ? current.attributeValue(qname) : null;
        qname = new QName(TInoNamespace.POSITION.getName(), inoNamespace);
        String nextValue = (next != null) ? next.attributeValue(qname) : null;
        String prevValue = (prev != null) ? prev.attributeValue(qname) : null;
        // Instantiate the cursor instance
        TCursorContentItem cursorContentItem = responseContentItemFactory.newCursorContentItem(handleValue,
                currentValue, quantityValue, nextValue, prevValue, countValue);
        responseInfoContent.putItem(TCursorContentItem.SPECIFIER, cursorContentItem);
    }/*from   w w  w.ja  v  a2  s  .  c om*/
}

From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JInputStreamInterpreter.java

License:Open Source License

private void setResponseQueryContent(Document document, String collection, String doctype) {
    // Get all the Elements returned from Tamino
    Element re = document.getRootElement();
    // Get the xql/xq:result element as the container for the querried XML instances.
    QName qname = new QName(TXQNamespace.RESULT.getName(), xqNamespace);
    Element qc = re.element(qname);
    if (qc == null) {
        qname = new QName(TXQLNamespace.RESULT.getName(), xqlNamespace);
        qc = re.element(qname);/*from  www  .  j a  va2  s  .co m*/
    }

    if (qc != null) {
        // Get the list of all result DOM4J element instances referring to the XML instances. Currently getMixedContent is used, will be changed later.
        //List list  = qc.elements();
        List list = qc.content();
        if (list.size() != 0) {
            // Obtain the response query content.
            TResponseQueryContent responseQueryContent = getResponseQueryContent();
            Iterator iter = list.iterator();
            while (iter.hasNext()) {
                Object item = iter.next();
                // Well, if the item happens to be a string then there is either mixed content or only text content.
                if (item instanceof String) {
                    responseQueryContent.setText(item.toString());
                } else if (item instanceof DefaultText) {
                    responseQueryContent.setText(((DefaultText) item).getText());
                } else if (item instanceof Element) {
                    Element element = (Element) item;
                    // Create the appropiate Tamino XML object with the given ino:id, collection and schema information.
                    TXMLObject xmlObject = TXMLObject.newInstance(element);
                    xmlObject.setCollection(collection);
                    xmlObject.setDoctype(doctype);
                    // Add the obtained TXMLObject to the result set.
                    responseQueryContent.add(xmlObject);
                }
            }
        }
    }
}

From source file:org.orbeon.oxf.transformer.xupdate.VariableContextImpl.java

License:Open Source License

public Object getVariableValue(String namespaceURI, String prefix, String localName)
        throws UnresolvableException {
    if (this.qname == null) {
        throw new UnresolvableException(
                "Variable '" + Utils.qualifiedName(prefix, localName) + "' is not defined");
    } else {//w w  w  .  ja v a 2  s. c  om
        QName qname = new QName(localName, new Namespace(prefix, namespaceURI));
        return this.qname.equals(qname) ? value
                : parentContext.getVariableValue(namespaceURI, prefix, localName);
    }
}

From source file:org.orbeon.oxf.xforms.control.controls.XFormsInputControl.java

License:Open Source License

public XFormsInputControl(XBLContainer container, XFormsControl parent, Element element, String id) {
    super(container, parent, element, id);
    if (element != null) { // can be null in some unit tests only
        this.format = element.attributeValue(new QName("format", XFormsConstants.XXFORMS_NAMESPACE));
        this.unformat = element.attributeValue(new QName("unformat", XFormsConstants.XXFORMS_NAMESPACE));
    } else {/*from w w w.j a v  a2  s .  co  m*/
        this.format = this.unformat = null;
    }
}

From source file:org.orbeon.oxf.xforms.control.controls.XMLCleaner.java

License:Open Source License

public static org.dom4j.Document cleanXML(org.dom4j.Document doc, String stylesheetURL) {
    try {//from   w  ww .ja  v  a  2 s  . c  om
        final org.dom4j.Element element = doc.getRootElement();
        final String systemId = Dom4jUtils.makeSystemId(element);
        // The date to clean
        final DOMGenerator dataToClean = new DOMGenerator(doc, "clean xml", DOMGenerator.ZeroValidity,
                systemId);
        // The stylesheet
        final URLGenerator stylesheetGenerator = new URLGenerator(stylesheetURL);
        // The transformation
        // Define the name of the processor (this is a QName)
        final QName processorName = new QName("xslt", XMLConstants.OXF_PROCESSORS_NAMESPACE);
        // Get a factory for this processor
        final ProcessorFactory processorFactory = ProcessorFactoryRegistry.lookup(processorName);
        if (processorFactory == null)
            throw new OXFException("Cannot find processor factory with name '"
                    + processorName.getNamespacePrefix() + ":" + processorName.getName() + "'");

        // Create processor
        final Processor xsltProcessor = processorFactory.createInstance();
        // Where the result goes
        final DOMSerializer transformationOutput = new DOMSerializer();

        // Connect
        PipelineUtils.connect(stylesheetGenerator, "data", xsltProcessor, "config");
        PipelineUtils.connect(dataToClean, "data", xsltProcessor, "data");
        PipelineUtils.connect(xsltProcessor, "data", transformationOutput, "data");

        // Run the pipeline
        // Candidate for Scala withPipelineContext
        final PipelineContext pipelineContext = new PipelineContext();
        boolean success = false;
        try {
            final org.dom4j.Document result = transformationOutput.runGetDocument(pipelineContext);
            success = true;
            return result;
        } finally {
            pipelineContext.destroy(success);
        }
    } catch (Exception e) {
        throw new OXFException(e);
    }
}

From source file:org.orbeon.oxf.xforms.function.xxforms.XXFormsCallXPL.java

License:Open Source License

public SequenceIterator iterate(XPathContext xpathContext) throws XPathException {

    try {//from w  ww.  j a  v  a  2s .  com
        // Get XPL URL
        final URL xplURL;
        {
            Expression xplURIExpression = argument[0];
            //xplURL = new URL(((AnyURIValue) xplURIExpression.evaluateItem(xpathContext)).getStringValue());
            if (getSystemId() == null)
                xplURL = URLFactory.createURL(xplURIExpression.evaluateAsString(xpathContext).toString());
            else
                xplURL = URLFactory.createURL(getSystemId(),
                        xplURIExpression.evaluateAsString(xpathContext).toString());
        }

        // Get list of input names
        final List<String> inputNames = new ArrayList<String>();
        {
            final Expression inputNamesExpression = argument[1];
            final SequenceIterator i = inputNamesExpression.iterate(xpathContext);

            Item currentItem;
            while ((currentItem = i.next()) != null) {
                inputNames.add(currentItem.getStringValue());
            }
        }

        // Get list of input documents
        final List<Item> inputNodeInfos = new ArrayList<Item>();
        {
            final Expression inputDocumentsExpression = argument[2];
            final SequenceIterator i = inputDocumentsExpression.iterate(xpathContext);

            Item currentItem;
            while ((currentItem = i.next()) != null) {
                inputNodeInfos.add(currentItem);
            }
        }

        if (inputNames.size() != inputNodeInfos.size())
            throw new OXFException("The length of sequence of input names (" + inputNames.size()
                    + ") must be equal to the length of the sequence of input nodes (" + inputNodeInfos.size()
                    + ").");//getDisplayName()

        // Get list of output names
        final List<String> outputNames = new ArrayList<String>();
        {
            final Expression inputNamesExpression = argument[3];
            final SequenceIterator i = inputNamesExpression.iterate(xpathContext);

            Item currentItem;
            while ((currentItem = i.next()) != null) {
                outputNames.add(currentItem.getStringValue());
            }
        }

        // Create processor definition and processor
        Processor processor;
        {
            ProcessorDefinition processorDefinition = new ProcessorDefinition();
            {
                processorDefinition.setName(new QName("pipeline", XMLConstants.OXF_PROCESSORS_NAMESPACE));
                processorDefinition.addInput("config", xplURL.toExternalForm());

                Iterator inputNodesIterator = inputNodeInfos.iterator();
                for (final String inputName : inputNames) {
                    final NodeInfo inputNodeInfo = (NodeInfo) inputNodesIterator.next();

                    if (!(inputNodeInfo.getNodeKind() == org.w3c.dom.Node.ELEMENT_NODE
                            || inputNodeInfo.getNodeKind() == org.w3c.dom.Node.DOCUMENT_NODE))
                        throw new OXFException(
                                "Input node must be a document or element for input name: " + inputName);

                    // TODO: We should be able to just pass inputNodeInfo to addInput() and avoid the conversions, but that doesn't work!

                    if (inputNodeInfo instanceof VirtualNode) {
                        // Get reference to dom4j node

                        final Element inputElement;
                        final Node inputNode = (Node) ((VirtualNode) inputNodeInfo).getUnderlyingNode();

                        if (inputNode instanceof Document)
                            inputElement = ((Document) inputNode).getRootElement();
                        else if (inputNode instanceof Element && inputNode.getParent() == null)
                            inputElement = (Element) inputNode;
                        else if (inputNode instanceof Element)
                            inputElement = Dom4jUtils.createDocumentCopyParentNamespaces((Element) inputNode)
                                    .getRootElement();
                        else
                            throw new OXFException(
                                    "Input node must be a document or element for input name: " + inputName);

                        processorDefinition.addInput(inputName, inputElement);
                    } else {
                        // Copy to dom4j

                        //                            final DocumentInfo inputDocumentInfo = TransformerUtils.readTinyTree(inputNodeInfo);
                        //                            processorDefinition.addInput(inputName, inputDocumentInfo);

                        final Document inputDocument = TransformerUtils.tinyTreeToDom4j(inputNodeInfo);
                        processorDefinition.addInput(inputName, inputDocument.getRootElement());
                    }
                }
            }
            processor = InitUtils.createProcessor(processorDefinition);
        }

        final PipelineContext pipelineContext = PipelineContext.get();
        processor.reset(pipelineContext);

        if (outputNames.size() == 0) {
            // Just run the processor
            processor.start(pipelineContext);
            return EmptyIterator.getInstance();
        } else {
            // Create all outputs to read
            List<ProcessorOutput> outputs = new ArrayList<ProcessorOutput>(outputNames.size());
            for (String outputName : outputNames) {
                ProcessorOutput output = processor.createOutput(outputName);
                outputs.add(output);
            }

            // Connect all DOM serializers
            List<DOMSerializer> domSerializers = new ArrayList<DOMSerializer>(outputNames.size());
            for (ProcessorOutput output : outputs) {
                DOMSerializer domSerializer = new DOMSerializer();
                PipelineUtils.connect(processor, output.getName(), domSerializer, "data");
                domSerializers.add(domSerializer);
            }

            // Read all outputs in sequence
            List<DocumentWrapper> results = new ArrayList<DocumentWrapper>(outputNames.size());
            for (DOMSerializer domSerializer : domSerializers) {
                results.add(new DocumentWrapper(
                        (Document) Dom4jUtils.normalizeTextNodes(domSerializer.runGetDocument(pipelineContext)),
                        null, xpathContext.getConfiguration()));
            }
            return new ListIterator(results);
        }
    } catch (XPathException e) {
        throw e;
    } catch (Exception e) {
        throw new OXFException(e);
    }
}