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.pipeline.ast.ASTDocumentHandler.java

License:Open Source License

public void output(ASTOutput output) {
    Element outputElement = currentElement
            .addElement(new QName("output", PipelineProcessor.PIPELINE_NAMESPACE));
    outputElement.addAttribute("name", output.getName());
    if (output.getRef() != null)
        outputElement.addAttribute("ref", output.getRef());
    if (output.getId() != null)
        outputElement.addAttribute("id", output.getId());
}

From source file:org.orbeon.oxf.processor.pipeline.ast.ASTDocumentHandler.java

License:Open Source License

public boolean startChoose(ASTChoose choose) {
    href = new Stack();
    currentElement = currentElement.addElement(new QName("choose", PipelineProcessor.PIPELINE_NAMESPACE));
    return true;//  ww  w  . j  a v  a 2  s. c om
}

From source file:org.orbeon.oxf.processor.pipeline.ast.ASTDocumentHandler.java

License:Open Source License

public boolean startForEach(ASTForEach forEach) {
    href = new Stack();
    currentElement = currentElement.addElement(new QName("for-each", PipelineProcessor.PIPELINE_NAMESPACE));
    if (forEach.getId() != null)
        currentElement.addAttribute("id", forEach.getId());
    if (forEach.getRef() != null)
        currentElement.addAttribute("ref", forEach.getRef());
    currentElement.addAttribute("root", forEach.getRoot());
    return true;//from  w ww  . ja v a 2 s. co m
}

From source file:org.orbeon.oxf.processor.pipeline.ast.ASTDocumentHandler.java

License:Open Source License

public boolean startWhen(ASTWhen when) {
    if (currentElement.elements().isEmpty()) {
        currentElement.addAttribute("href", (String) href.pop());
    }/*  w  w w  . j a v a 2s  . c o  m*/
    if (when.getTest() == null) {
        currentElement = currentElement
                .addElement(new QName("otherwise", PipelineProcessor.PIPELINE_NAMESPACE));
    } else {
        currentElement = currentElement.addElement(new QName("when", PipelineProcessor.PIPELINE_NAMESPACE));
        currentElement.addAttribute("test", when.getTest());
    }
    return true;
}

From source file:org.orbeon.oxf.processor.serializer.BinaryTextXMLReceiver.java

License:Open Source License

public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) {
    if (elementLevel++ == 0) {
        // This is the root element

        // Get xsi:type attribute and determine whether the input is binary or text
        String xsiType = attributes.getValue(XMLConstants.XSI_TYPE_QNAME.getNamespaceURI(),
                XMLConstants.XSI_TYPE_QNAME.getName());

        if (xsiType == null)
            throw new OXFException("Root element must contain an xsi:type attribute");

        int colonIndex = xsiType.indexOf(':');
        if (colonIndex == -1)
            throw new OXFException("Type xs:string or xs:base64Binary must be specified");

        String typePrefix = xsiType.substring(0, colonIndex);
        String typeLocalName = xsiType.substring(colonIndex + 1);

        if (prefixMappings == null)
            throw new OXFException("Undeclared prefix in xsi:type: " + typePrefix);

        String typeNamespaceURI = prefixMappings.get(typePrefix);
        if (typeNamespaceURI == null)
            throw new OXFException("Undeclared prefix in xsi:type: " + typePrefix);

        QName typeQName = new QName(typeLocalName, new Namespace(typePrefix, typeNamespaceURI));
        boolean isBinaryInput;
        if (typeQName.equals(XMLConstants.XS_BASE64BINARY_QNAME)) {
            isBinaryInput = true;/*from   w w w  .ja  va 2  s. c o m*/
        } else if (typeQName.equals(XMLConstants.XS_STRING_QNAME)) {
            isBinaryInput = false;
        } else
            throw new OXFException("Type xs:string or xs:base64Binary must be specified");

        // Set last-modified if available
        final String validityAttribute = attributes.getValue("last-modified");
        if (StringUtils.isNotBlank(validityAttribute)) {
            // Override caching settings which may have taken place before
            if (response != null)
                response.setPageCaching(DateUtils.parseRFC1123(validityAttribute));
        }

        // Set filename if available
        final String fileName = attributes.getValue("filename");
        if (StringUtils.isNotBlank(fileName)) {
            if (response != null)
                response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        }

        // Set status code if available
        final String statusCode = attributes.getValue("status-code");
        if (StringUtils.isNotBlank(statusCode)) {
            if (response != null)
                response.setStatus(Integer.parseInt(statusCode));
        }

        // Set ContentHandler and headers depending on input type
        final String contentTypeAttribute = attributes.getValue("content-type");
        if (isBinaryInput) {
            // Get content-type
            final String contentType = getContentType(contentTypeAttribute, DEFAULT_BINARY_CONTENT_TYPE);

            if (response != null)
                response.setContentType(contentType);

            outputContentHandler = new Base64XMLReceiver(outputStream);
        } else {
            // Get content-type and encoding
            final String contentType = getContentType(contentTypeAttribute, DEFAULT_TEXT_CONTENT_TYPE);
            final String encoding = getEncoding(contentTypeAttribute, CachedSerializer.DEFAULT_ENCODING);

            // Always set the content type with a charset attribute
            if (response != null)
                response.setContentType(contentType + "; charset=" + encoding);

            try {
                writer = new OutputStreamWriter(outputStream, encoding);
            } catch (UnsupportedEncodingException e) {
                throw new OXFException(e);
            }
            outputContentHandler = new TextXMLReceiver(writer);
        }
    }
}

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

License:Open Source License

/**
 * Sets the ino:docname on this DOM4J specific TXMLObject.
 *
 * @param docname is the ino:docname attribute of the data object.
 *///from  ww  w. j  a va 2  s  .co  m
public void setDocname(String docname) {
    if (docname == null || docname.equals("")) {
        if (element == null)
            super.setDocname(null);
        else {
            QName qname = new QName(TInoNamespace.DOCNAME.getName(), inoNamespace);
            Attribute att = new FlyweightAttribute(qname);
            element.remove(att);
        }
    } else {
        if (element == null)
            super.setDocname(docname);
        else {
            QName qname = new QName(TInoNamespace.DOCNAME.getName(), inoNamespace);
            Attribute att = element.attribute(qname);
            if (att != null)
                att.setValue(docname);
            else {
                att = new FlyweightAttribute(TInoNamespace.DOCNAME.getName(), docname, inoNamespace);
                element.add(att);
            }
        }
    }
}

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

License:Open Source License

/**
 * Sets the ino:id for the XML instance.
 *//*  w ww.j  a v a2s .c  o m*/
public void setId(String inoId) {
    if (inoId == null || inoId.length() == 0) {
        if (element == null)
            super.setId(null);
        else {
            QName qtmpName = new QName(TInoNamespace.ID.getName(), inoNamespace);
            Attribute tmpAttribute = new FlyweightAttribute(qtmpName);
            element.remove(tmpAttribute);
        }
    } else {
        if (element == null)
            super.setId(inoId);
        else {
            QName qname = new QName(TInoNamespace.ID.getName(), inoNamespace);
            Attribute att = element.attribute(qname);
            if (att != null)
                att.setValue(inoId);
            else {
                att = new FlyweightAttribute(TInoNamespace.ID.getName(), inoId, inoNamespace);
                element.add(att);
            }
        }
    }
}

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

License:Open Source License

/**
 * Gets the ino:docname from this Tamino data object.
 *///from w  w  w  . j av  a2 s  .  c  o  m
public String getDocname() {
    if (element == null)
        return super.getDocname();
    QName qname = new QName(TInoNamespace.DOCNAME.getName(), inoNamespace);
    Attribute att = element.attribute(qname);
    return (att != null) ? att.getValue() : "";
}

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

License:Open Source License

/**
 * Gets the ino:id attribute for the underlying XML data.
 *///  w  w  w .  j a va  2  s . c  o  m
public String getId() {
    if (element == null)
        return super.getId();
    QName qname = new QName(TInoNamespace.ID.getName(), inoNamespace);
    Attribute att = element.attribute(qname);
    return (att != null) ? att.getValue() : "";
}

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

License:Open Source License

/**
 ** Interprets the a general inputStream in a generic fashion. As a consequence only the
 ** result state will be obtained.//from w w w. jav  a  2 s  .  com
 **
 ** @param inputStream is the InputStream for a response to a previous operation on Tamino.
 ** @exception TStreamInterpretException when interpreting errors occur.
 **/
protected void doInterpret(TInputStream inputStream) throws TStreamInterpretException {
    // please have a look at comment in the initialize method.
    try {
        // Create the DOM4J SAXReader with the DOM4J specific underlying SAX parser. This is a JAXP parser!
        SAXReader saxReader = (parserName == null || parserName.equals("")) ? new SAXReader()
                : new SAXReader(parserName);

        // Make sure the document and its children are thread safe by using our
        // document factory.
        final DocumentFactory factory = NonLazyUserDataDocumentFactory.getInstance();
        saxReader.setDocumentFactory(factory);

        // Invoke the parsing and obtain the Document instance
        document = saxReader.read(inputStream);
        TStreamHeader header = inputStream.getHeader();
        // Set the result state
        setResponseInfoContent(document);
        // Set the result set of querried XML objects only if result relates to a query
        if (document.getRootElement().element(new QName(TXQLNamespace.QUERY.getName(), xqlNamespace)) != null
                || document.getRootElement()
                        .element(new QName(TXQNamespace.XQUERY.getName(), xqNamespace)) != null) {
            setResponseQueryContent(document, (String) header.getValue(TStreamHeader.COLLECTION),
                    (String) header.getValue(TStreamHeader.DOCTYPE));
        }
    } catch (SAXException saxException) {
        throw new TStreamInterpretException("Interpreting the input stream for DOM4J failed!", saxException);
    } catch (Exception exception) {
        throw new TStreamInterpretException("Interpreting the input stream failed!", exception);
    }
}