Package org.dom4j

Examples of org.dom4j.DocumentFactory


*/
public class Dom4jUnmarshallingEventHandler extends UnmarshallingEventHandlerAdaptor {
    private Element owner;
   
    public Dom4jUnmarshallingEventHandler(UnmarshallingContext _ctxt) throws SAXException {
        super(_ctxt, new SAXContentHandler(new DocumentFactory()));
    }
View Full Code Here


     * @param project
     */
    public void write(Writer writer, Model project)
        throws java.io.IOException
    {
        Document document = new DocumentFactory().createDocument();
        writeModel( project, "project", document );
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setLineSeparator( System.getProperty( "line.separator" ) );
        XMLWriter serializer = new XMLWriter( writer, format );
        serializer.write( document );
View Full Code Here

       
        if (DO_INTERN_QNAME) {
            elementQName = intern(elementQName);
        }

        DocumentFactory factory = elementQName.getDocumentFactory();
        if (factory instanceof DatatypeElementFactory) {
            result = (DatatypeElementFactory) factory;
        }
       
        return result;
View Full Code Here

        if (dataType != null) {
            return new DatatypeElement(qname, dataType);
        }

        DocumentFactory factory = qname.getDocumentFactory();

        if (factory instanceof DatatypeElementFactory) {
            DatatypeElementFactory dtFactory = (DatatypeElementFactory) factory;
            dataType = dtFactory.getChildElementXSDatatype(qname);
View Full Code Here

            NamespaceStack namespaceStack, boolean noNamespaceAttributes) {
        // now lets add all attribute values
        int size = attributes.getLength();

        if (size > 0) {
            DocumentFactory factory = getDocumentFactory();

            if (size == 1) {
                // allow lazy construction of the List of Attributes
                String name = attributes.getQName(0);

                if (noNamespaceAttributes || !name.startsWith("xmlns")) {
                    String attributeURI = attributes.getURI(0);

                    String attributeLocalName = attributes.getLocalName(0);

                    String attributeValue = attributes.getValue(0);

                    QName attributeQName = namespaceStack.getAttributeQName(
                            attributeURI, attributeLocalName, name);

                    add(factory.createAttribute(this, attributeQName,
                            attributeValue));
                }
            } else {
                List list = attributeList(size);

                list.clear();

                for (int i = 0; i < size; i++) {
                    // optimised to avoid the call to attribute(QName) to
                    // lookup an attribute for a given QName
                    String attributeName = attributes.getQName(i);

                    if (noNamespaceAttributes
                            || !attributeName.startsWith("xmlns")) {
                        String attributeURI = attributes.getURI(i);

                        String attributeLocalName = attributes.getLocalName(i);

                        String attributeValue = attributes.getValue(i);

                        QName attributeQName = namespaceStack
                                .getAttributeQName(attributeURI,
                                        attributeLocalName, attributeName);

                        Attribute attribute = factory.createAttribute(this,
                                attributeQName, attributeValue);

                        list.add(attribute);

                        childAdded(attribute);
View Full Code Here

        return this;
    }

    public Element addElement(String name) {
        DocumentFactory factory = getDocumentFactory();

        int index = name.indexOf(":");

        String prefix = "";

        String localName = name;

        Namespace namespace = null;

        if (index > 0) {
            prefix = name.substring(0, index);

            localName = name.substring(index + 1);

            namespace = getNamespaceForPrefix(prefix);

            if (namespace == null) {
                throw new IllegalAddException("No such namespace prefix: "
                        + prefix + " is in scope on: " + this
                        + " so cannot add element: " + name);
            }
        } else {
            namespace = getNamespaceForPrefix("");
        }

        Element node;

        if (namespace != null) {
            QName qname = factory.createQName(localName, namespace);

            node = factory.createElement(qname);
        } else {
            node = factory.createElement(name);
        }

        addNewNode(node);

        return node;
View Full Code Here

    protected DocumentFactory getDocumentFactory() {
        QName qName = getQName();

        // QName might be null as we might not have been constructed yet
        if (qName != null) {
            DocumentFactory factory = qName.getDocumentFactory();

            if (factory != null) {
                return factory;
            }
        }
View Full Code Here

    // Implementation methods
    // -------------------------------------------------------------------------
    protected Document parseDocument() throws DocumentException, IOException,
            XmlPullParserException {
        DocumentFactory df = getDocumentFactory();
        Document document = df.createDocument();
        Element parent = null;
        XmlPullParser pp = getXPPParser();
        pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

        while (true) {
            int type = pp.nextToken();

            switch (type) {
                case XmlPullParser.PROCESSING_INSTRUCTION: {
                    String text = pp.getText();
                    int loc = text.indexOf(" ");

                    if (loc >= 0) {
                        String target = text.substring(0, loc);
                        String txt = text.substring(loc + 1);
                        document.addProcessingInstruction(target, txt);
                    } else {
                        document.addProcessingInstruction(text, "");
                    }

                    break;
                }

                case XmlPullParser.COMMENT: {
                    if (parent != null) {
                        parent.addComment(pp.getText());
                    } else {
                        document.addComment(pp.getText());
                    }

                    break;
                }

                case XmlPullParser.CDSECT: {
                    if (parent != null) {
                        parent.addCDATA(pp.getText());
                    } else {
                        String msg = "Cannot have text content outside of the "
                                + "root document";
                        throw new DocumentException(msg);
                    }

                    break;
                }

                case XmlPullParser.ENTITY_REF:
                    break;

                case XmlPullParser.END_DOCUMENT:
                    return document;

                case XmlPullParser.START_TAG: {
                    QName qname = (pp.getPrefix() == null) ? df.createQName(pp
                            .getName(), pp.getNamespace()) : df.createQName(pp
                            .getName(), pp.getPrefix(), pp.getNamespace());
                    Element newElement = df.createElement(qname);
                    int nsStart = pp.getNamespaceCount(pp.getDepth() - 1);
                    int nsEnd = pp.getNamespaceCount(pp.getDepth());

                    for (int i = nsStart; i < nsEnd; i++) {
                        if (pp.getNamespacePrefix(i) != null) {
                            newElement.addNamespace(pp.getNamespacePrefix(i),
                                    pp.getNamespaceUri(i));
                        }
                    }

                    for (int i = 0; i < pp.getAttributeCount(); i++) {
                        QName qa = (pp.getAttributePrefix(i) == null) ? df
                                .createQName(pp.getAttributeName(i)) : df
                                .createQName(pp.getAttributeName(i), pp
                                        .getAttributePrefix(i), pp
                                        .getAttributeNamespace(i));
                        newElement.addAttribute(qa, pp.getAttributeValue(i));
                    }
View Full Code Here

            Element element = (Element) iterator.next();
            QName elementQName = getQNameOfSchemaElement(element);
            QName type = (QName) typedElementMap.get(element);

            if (complexTypeMap.containsKey(type)) {
                DocumentFactory factory = (DocumentFactory) complexTypeMap
                        .get(type);
                elementQName.setDocumentFactory(factory);
            } else if (simpleTypeMap.containsKey(type)) {
                XSDatatype datatype = (XSDatatype) simpleTypeMap.get(type);
                DocumentFactory factory = (DocumentFactory) elementFactoryMap
                        .get(element);

                if (factory instanceof DatatypeElementFactory) {
                    ((DatatypeElementFactory) factory)
                            .setChildElementXSDatatype(elementQName, datatype);
View Full Code Here

    }

    // Implementation methods
    // -------------------------------------------------------------------------
    protected DocumentFactory getDocumentFactory() {
        DocumentFactory factory = getQName().getDocumentFactory();

        return (factory != null) ? factory : DOCUMENT_FACTORY;
    }
View Full Code Here

TOP

Related Classes of org.dom4j.DocumentFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.