Example usage for org.dom4j DocumentFactory createElement

List of usage examples for org.dom4j DocumentFactory createElement

Introduction

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

Prototype

public Element createElement(String name) 

Source Link

Usage

From source file:org.olat.ims.qti.render.ResultsBuilder.java

License:Apache License

private static void addStaticsPath(final Element el_in, final AssessmentInstance ai) {
    Element el_staticspath = (Element) el_in.selectSingleNode(STATICS_PATH);
    if (el_staticspath == null) {
        final DocumentFactory df = DocumentFactory.getInstance();
        el_staticspath = df.createElement(STATICS_PATH);
        final Resolver resolver = ai.getResolver();
        el_staticspath.addAttribute("ident", resolver.getStaticsBaseURI());
        el_in.add(el_staticspath);//from w ww .j av  a 2 s. c  o  m
    }
}

From source file:org.onosproject.xmpp.core.ctl.handlers.XmppDecoder.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, Object object, List out) throws Exception {
    if (object instanceof Element) {
        Element root = (Element) object;

        try {/*w w  w. j av  a  2s.c  om*/
            Packet packet = recognizeAndReturnXmppPacket(root);
            validate(packet);
            out.add(packet);
        } catch (UnsupportedStanzaTypeException e) {
            throw e;
        } catch (Exception e) {
            throw new XmppValidationException(false);
        }

    } else if (object instanceof XMLEvent) {

        XMLEvent event = (XMLEvent) object;
        if (event.isStartElement()) {
            final StartElement element = event.asStartElement();

            if (element.getName().getLocalPart().equals(XmppConstants.STREAM_QNAME)) {
                DocumentFactory df = DocumentFactory.getInstance();
                QName qname = (element.getName().getPrefix() == null)
                        ? df.createQName(element.getName().getLocalPart(), element.getName().getNamespaceURI())
                        : df.createQName(element.getName().getLocalPart(), element.getName().getPrefix(),
                                element.getName().getNamespaceURI());

                Element newElement = df.createElement(qname);

                Iterator nsIt = element.getNamespaces();
                // add all relevant XML namespaces to Element
                while (nsIt.hasNext()) {
                    Namespace ns = (Namespace) nsIt.next();
                    newElement.addNamespace(ns.getPrefix(), ns.getNamespaceURI());
                }

                Iterator attrIt = element.getAttributes();
                // add all attributes to Element
                while (attrIt.hasNext()) {
                    Attribute attr = (Attribute) attrIt.next();
                    newElement.addAttribute(attr.getName().getLocalPart(), attr.getValue());
                }
                XmppStreamOpen xmppStreamOpen = new XmppStreamOpen(newElement);
                validator.validateStream(xmppStreamOpen);
                out.add(xmppStreamOpen);
            }
        } else if (event.isEndElement()) {
            out.add(new XmppStreamClose());
        }
    }

}

From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java

License:Open Source License

public static Element createElement(final String name) {
    final DocumentFactory factory = NonLazyUserDataDocumentFactory.getInstance();
    return factory.createElement(name);
}

From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java

License:Open Source License

public static Element createElement(final QName qName) {
    final DocumentFactory factory = NonLazyUserDataDocumentFactory.getInstance();
    return factory.createElement(qName);
}

From source file:org.orbeon.oxf.xml.dom4j.NonLazyUserDataElement.java

License:Open Source License

protected org.dom4j.Element createElement(final org.dom4j.QName qName) {
    final DocumentFactory factory = NonLazyUserDataDocumentFactory.getInstance();
    final org.dom4j.Element ret = factory.createElement(qName);
    final Object dta = getCopyOfUserData();
    ret.setData(dta);/*from w  w w . j ava2 s. c  om*/
    return ret;
}

From source file:org.talend.updates.runtime.nexus.component.ComponentIndexManager.java

License:Open Source License

public boolean createIndexFile(File indexFile, List<ComponentIndexBean> newIndexList) throws IOException {
    if (newIndexList == null || newIndexList.isEmpty() || indexFile == null) {
        return false;
    }//from   ww  w.  ja  v  a 2  s. com

    XMLWriter xmlWriter = null;
    boolean created = false;
    try {
        // write to index
        final DocumentFactory docFactory = DocumentFactory.getInstance();
        final Element components = docFactory.createElement(ELEM_COMPONENTS);
        Document newDoc = docFactory.createDocument(components);
        for (ComponentIndexBean b : newIndexList) {
            final Element elem = createXmlElement(b);
            if (elem != null) {
                components.add(elem);
            }
        }

        // 4 spaces
        OutputFormat format = new OutputFormat();
        format.setEncoding("UTF-8"); //$NON-NLS-1$
        format.setIndentSize(4);
        format.setNewlines(true);
        xmlWriter = new XMLWriter(new FileOutputStream(indexFile), format);

        xmlWriter.write(newDoc);

        created = true;
        return true;
    } finally {
        if (xmlWriter != null) {
            try {
                xmlWriter.close();
            } catch (IOException e) {
                //
            }
        }
        if (!created && indexFile.exists()) {
            indexFile.delete(); // remove the wrong file.
        }
    }
}

From source file:org.talend.updates.runtime.nexus.component.ComponentIndexManager.java

License:Open Source License

Element createXmlElement(ComponentIndexBean indexBean) {

    if (indexBean == null) {
        return null;
    }//from  w  ww  . j a  va  2 s . c  o m
    if (!indexBean.validRequired()) {
        return null; // no valid
    }
    final DocumentFactory docFactory = DocumentFactory.getInstance();
    final Element component = docFactory.createElement(ComponentIndexManager.ELEM_COMPONENT);
    for (ComponentIndexNames in : ComponentIndexNames.values()) {
        final String value = indexBean.getValue(in);
        if (StringUtils.isBlank(value)) {
            continue; // not value
        }
        switch (in) {
        case name:
        case bundle_id:
        case version:
        case mvn_uri:
        case license_uri:
        case product:
        case image_mvn_uri:
        case types:
        case categories:
        case degradable:
        case compatibleStudioVersion:
        default:
            // attribute
            component.add(docFactory.createAttribute(component, in.getName(), value));
            break;
        case description:
        case license:
            // child element
            final Element child = docFactory.createElement(in.getName());
            child.setText(value);
            component.add(child);
            break;
        }
    }
    return component;
}