Example usage for org.dom4j Namespace Namespace

List of usage examples for org.dom4j Namespace Namespace

Introduction

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

Prototype

public Namespace(String prefix, String uri) 

Source Link

Document

DOCUMENT ME!

Usage

From source file:org.jinglenodes.relay.RelayRedirectIQ.java

License:Open Source License

public Element getChildElement() {

    final Element element = DocumentHelper.createElement(new QName(ELEMENT_NAME, new Namespace("", NAMESPACE)));

    if (host != null) {
        element.addAttribute("host", host);
    }/*  ww w  .ja v  a  2  s  . co m*/

    element.addAttribute("port", port);

    if (channelId != null) {
        element.addAttribute("id", channelId);
    }
    return element;

}

From source file:org.jivesoftware.multiplexer.net.http.HttpSession.java

License:Open Source License

/**
 * Returns the stream features which are available for this session.
 *
 * @return the stream features which are available for this session.
 *//*from  ww  w . ja v  a  2s  .  co  m*/
public Collection<Element> getAvailableStreamFeaturesElements() {
    List<Element> elements = new ArrayList<Element>();

    Element sasl = connectionManager.getServerSurrogate().getSASLMechanismsElement(this);
    if (sasl != null) {
        elements.add(sasl);
    }

    Element bind = DocumentHelper
            .createElement(new QName("bind", new Namespace("", "urn:ietf:params:xml:ns:xmpp-bind")));
    elements.add(bind);

    Element session = DocumentHelper
            .createElement(new QName("session", new Namespace("", "urn:ietf:params:xml:ns:xmpp-session")));
    elements.add(session);
    return elements;
}

From source file:org.jivesoftware.openfire.http.HttpSession.java

License:Open Source License

/**
 * Returns the stream features which are available for this session.
 *
 * @return the stream features which are available for this session.
 *///from   w ww.  j  ava2  s . com
public Collection<Element> getAvailableStreamFeaturesElements() {
    List<Element> elements = new ArrayList<Element>();

    if (getAuthToken() == null) {
        Element sasl = SASLAuthentication.getSASLMechanismsElement(this);
        if (sasl != null) {
            elements.add(sasl);
        }
    }

    if (XMPPServer.getInstance().getIQRegisterHandler().isInbandRegEnabled()) {
        elements.add(DocumentHelper.createElement(
                new QName("register", new Namespace("", "http://jabber.org/features/iq-register"))));
    }
    Element bind = DocumentHelper
            .createElement(new QName("bind", new Namespace("", "urn:ietf:params:xml:ns:xmpp-bind")));
    elements.add(bind);

    Element session = DocumentHelper
            .createElement(new QName("session", new Namespace("", "urn:ietf:params:xml:ns:xmpp-session")));
    session.addElement("optional");
    elements.add(session);
    return elements;
}

From source file:org.jivesoftware.openfire.net.SASLAuthentication.java

License:Open Source License

public static Element getSASLMechanismsElement(Session session) {
    if (!(session instanceof ClientSession) && !(session instanceof IncomingServerSession)) {
        return null;
    }/*from   w  w w .  j a  v a  2  s .  com*/

    Element mechs = DocumentHelper
            .createElement(new QName("mechanisms", new Namespace("", "urn:ietf:params:xml:ns:xmpp-sasl")));
    if (session instanceof LocalIncomingServerSession) {
        // Server connections don't follow the same rules as clients
        if (session.isSecure()) {
            boolean haveTrustedCertificate = false;
            try {
                LocalIncomingServerSession svr = (LocalIncomingServerSession) session;
                X509Certificate trusted = CertificateManager.getEndEntityCertificate(
                        svr.getConnection().getPeerCertificates(), SSLConfig.getKeyStore(),
                        SSLConfig.gets2sTrustStore());
                haveTrustedCertificate = trusted != null;
                if (trusted != null && svr.getDefaultIdentity() != null) {
                    haveTrustedCertificate = verifyCertificate(trusted, svr.getDefaultIdentity());
                }
            } catch (IOException ex) {
                Log.warn(
                        "Exception occurred while trying to determine whether remote certificate is trusted. Treating as untrusted.",
                        ex);
            }
            if (haveTrustedCertificate) {
                // Offer SASL EXTERNAL only if TLS has already been negotiated and the peer has a trusted cert.
                Element mechanism = mechs.addElement("mechanism");
                mechanism.setText("EXTERNAL");
            }
        }
    } else {
        for (String mech : getSupportedMechanisms()) {
            Element mechanism = mechs.addElement("mechanism");
            mechanism.setText(mech);
        }
    }
    return mechs;
}

From source file:org.mule.config.spring.SpringXmlConfigurationMuleArtifactFactory.java

License:Open Source License

private MuleArtifact doGetArtifact(org.w3c.dom.Element element, XmlConfigurationCallback callback,
        boolean embedInFlow) throws MuleArtifactFactoryException {
    ConfigResource config = null;//from   ww  w .j  a va2  s .  c o m
    Document document = DocumentHelper.createDocument();

    // the rootElement is the root of the document
    Element rootElement = document.addElement("mule", "http://www.mulesoft.org/schema/mule/core");

    // the parentElement is the parent of the element we are adding
    Element parentElement = rootElement;
    addSchemaLocation(rootElement, element, callback);
    String flowName = "flow-" + Integer.toString(element.hashCode());
    if (embedInFlow) {
        // Need to put the message processor in a valid flow. Our default flow is:
        //            "<flow name=\"CreateSingle\">"
        //          + "</flow>"
        parentElement = rootElement.addElement("flow", "http://www.mulesoft.org/schema/mule/core");
        parentElement.addAttribute("name", flowName);
    }
    try {
        parentElement.add(convert(element));
        for (int i = 0; i < element.getAttributes().getLength(); i++) {
            String attributeName = element.getAttributes().item(i).getLocalName();
            if (attributeName != null && attributeName.endsWith("-ref")) {
                org.w3c.dom.Element dependentElement = callback
                        .getGlobalElement(element.getAttributes().item(i).getNodeValue());
                if (dependentElement != null) {
                    // if the element is a spring bean, wrap the element in a top-level spring beans element
                    if ("http://www.springframework.org/schema/beans"
                            .equals(dependentElement.getNamespaceURI())) {
                        String namespaceUri = dependentElement.getNamespaceURI();
                        Namespace namespace = new Namespace(dependentElement.getPrefix(), namespaceUri);
                        Element beans = rootElement.element(new QName("beans", namespace));
                        if (beans == null) {
                            beans = rootElement.addElement("beans", namespaceUri);
                        }
                        beans.add(convert(dependentElement));
                    } else {
                        rootElement.add(convert(dependentElement));
                        addSchemaLocation(rootElement, dependentElement, callback);
                    }
                    addChildSchemaLocations(rootElement, dependentElement, callback);
                }
                // if missing a dependent element, try anyway because it might not be needed.
            }
        }

        config = new ConfigResource("", new StringBufferInputStream(document.asXML()));
    } catch (Exception e) {
        throw new MuleArtifactFactoryException("Error parsing XML", e);
    }
    MuleContext muleContext = null;
    SpringXmlConfigurationBuilder builder = null;
    try {
        MuleContextFactory factory = new DefaultMuleContextFactory();
        builder = new SpringXmlConfigurationBuilder(new ConfigResource[] { config });
        muleContext = factory.createMuleContext(builder);
        muleContext.start();

        MuleArtifact artifact = null;
        if (embedInFlow) {
            Pipeline pipeline = (Pipeline) muleContext.getRegistry().lookupFlowConstruct(flowName);
            artifact = new DefaultMuleArtifact(pipeline.getMessageProcessors().get(0));
        } else {
            artifact = new DefaultMuleArtifact(
                    muleContext.getRegistry().lookupObject(element.getAttribute("name")));
        }
        builders.put(artifact, builder);
        contexts.put(artifact, muleContext);
        return artifact;
    } catch (Exception e) {
        dispose(builder, muleContext);
        throw new MuleArtifactFactoryException("Error initializing", e);
    }
}

From source file:org.mule.module.cxf.MuleSoapHeaders.java

License:Open Source License

public Element createHeaders() throws Exception {
    Element muleHeader = null;//from   w ww .  ja  v a  2s. c  o m

    if (correlationId != null || replyTo != null) {
        muleHeader = new DOMElement(new QName(MULE_HEADER, new Namespace(MULE_NAMESPACE, MULE_10_ACTOR)));
    } else {
        return null;
    }

    if (correlationId != null) {
        Node e = muleHeader.appendChild(new DOMElement(new QName(MuleProperties.MULE_CORRELATION_ID_PROPERTY,
                new Namespace(MULE_NAMESPACE, MULE_10_ACTOR))));
        e.setNodeValue(correlationId);

        e = muleHeader.appendChild(new DOMElement(new QName(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY,
                new Namespace(MULE_NAMESPACE, MULE_10_ACTOR))));
        e.setNodeValue(correlationGroup);

        e = muleHeader.appendChild(new DOMElement(new QName(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY,
                new Namespace(MULE_NAMESPACE, MULE_10_ACTOR))));
        e.setNodeValue(correlationSequence);
    }
    if (replyTo != null) {

        Node e = muleHeader.appendChild(new DOMElement(new QName(MuleProperties.MULE_REPLY_TO_PROPERTY,
                new Namespace(MULE_NAMESPACE, MULE_10_ACTOR))));
        e.setNodeValue(replyTo);
    }
    return muleHeader;
}

From source file:org.nuxeo.ecm.core.io.impl.transformers.SchemaRenamer.java

License:Open Source License

@Override
public boolean transform(ExportedDocument xdoc) throws IOException {
    Element root = xdoc.getDocument().getRootElement();

    List<Object> schemas = root.elements("schema");
    Element src = null;/*w  w  w  .  j a  va  2 s . c  o m*/
    if (schemas != null) {
        for (Object s : schemas) {
            Element schema = (Element) s;
            String name = schema.attribute("name").getText();
            if (srcSchema.equalsIgnoreCase(name)) {
                Namespace ns = new Namespace(dstPrefix, "http://www.nuxeo.org/ecm/schemas/" + dstSchema);
                schema.add(ns);
                schema.setAttributeValue("name", dstSchema);
                List<Element> fields = schema.elements();
                for (Element field : fields) {
                    field.setQName(new QName(field.getName(), ns));
                    ;
                }
            }
        }
    }
    return true;
}

From source file:org.nuxeo.ecm.jsf2.migration.parser.NamespaceParser.java

License:Open Source License

@Override
public void migrate(Document input) throws Exception {
    Element root = input.getRootElement();
    for (String prefix : listPrefixToMigrate) {
        Namespace newNamespace = new Namespace(prefix, EnumPrefixes.getPrefix(prefix).getNamespace());
        Namespace oldNamespace = root.getNamespaceForPrefix(prefix);
        if (oldNamespace != null) {
            root.remove(oldNamespace);//from w w  w.  java 2 s  . com
        }
        root.add(newNamespace);

        // Change the name of every elements with the prefix
        StringBuilder prefixXpath = new StringBuilder("//");
        prefixXpath.append(prefix);
        prefixXpath.append(":*");
        // Create a new XPath expression, with the old namespace in order
        // to
        // get the elements matching the expression
        XPath xpath = new Dom4jXPath(prefixXpath.toString());
        SimpleNamespaceContext nc = new SimpleNamespaceContext();
        nc.addNamespace(prefix, oldNamespace.getURI());
        xpath.setNamespaceContext(nc);

        @SuppressWarnings("unchecked")
        List<Element> elementsToMigrate = xpath.selectNodes(input);
        for (Element element : elementsToMigrate) {
            // The namespace to change is not hold by the element but the
            // QName
            QName qname = element.getQName();
            QName newQName = new QName(qname.getName(), newNamespace, qname.getQualifiedName());
            element.setQName(newQName);
        }
    }
}

From source file:org.nuxeo.ecm.platform.webdav.helpers.DavResponseXMLHelper.java

License:Open Source License

public void addResourcePropertiesToResponse(String schemaURI, Map<String, String> props,
        Map<String, Element> propsNodes) {
    // get prefix for schemaURI
    String prefix = NameSpaceHelper.getNameSpacePrefix(schemaURI);

    // add NS alias
    Namespace ns = new Namespace(prefix, schemaURI);
    for (Element propsNode : propsNodes.values()) {
        propsNode.add(ns);/*from   www. ja  v a 2s . c om*/
    }

    // get prop node
    Element prop = propsNodes.get(String.valueOf(WebDavConst.SC_OK)).element(propTag);
    Element prop404 = propsNodes.get(String.valueOf(WebDavConst.SC_NOT_FOUND)).element(propTag);

    for (String propName : props.keySet()) {
        QName qn = DocumentFactory.getInstance().createQName(propName, prefix, schemaURI);

        String propValue = props.get(propName);
        if (propName.equals("supportedlock")) {
            // hard coded Lock config !!!

            Element tag = prop.addElement(qn);

            QName stqn = DocumentFactory.getInstance().createQName("lockentry", prefix, schemaURI);
            Element lentry = tag.addElement(stqn);

            QName stqn2 = DocumentFactory.getInstance().createQName("lockscope", prefix, schemaURI);
            Element lscope = lentry.addElement(stqn2);

            QName stqn3 = DocumentFactory.getInstance().createQName("exclusive", prefix, schemaURI);
            lscope.addElement(stqn3);

            QName stqn4 = DocumentFactory.getInstance().createQName("locktype", prefix, schemaURI);
            Element ltype = lentry.addElement(stqn4);

            QName stqn5 = DocumentFactory.getInstance().createQName("write", prefix, schemaURI);
            ltype.addElement(stqn5);

            continue;
        }

        if (propValue != null) {
            Element tag = prop.addElement(qn);
            if (propValue.startsWith(MappingHelper.PROP_AS_TAG_PREFIX)) {
                String subTagName = propValue.split(":")[1];
                QName stqn = DocumentFactory.getInstance().createQName(subTagName, prefix, schemaURI);
                tag.addElement(stqn);
            } else {
                // if (propName.equals(WebDavConst.DAV_PROP_DISPLAYNAME))
                if (propValue.contains("<") || propValue.contains(">")) {
                    tag.add(new DOMCDATA(propValue));
                } else {
                    tag.setText(propValue);
                }
            }
        } else {
            prop404.addElement(qn);
        }
    }
}

From source file:org.nuxeo.ecm.platform.webdav.helpers.DavResponseXMLHelper.java

License:Open Source License

public void addResourceMissingPropertiesToResponse(String schemaURI, Map<String, String> props,
        Element propsNode) {//www  .j  a  v a2  s  . com
    // get prefix for schemaURI
    String prefix = NameSpaceHelper.getNameSpacePrefix(schemaURI);

    // add NS alias
    Namespace ns = new Namespace(prefix, schemaURI);
    propsNode.add(ns);

    // get prop node
    Element prop = propsNode.element(propTag);

    for (String propName : props.keySet()) {
        QName qn = DocumentFactory.getInstance().createQName(propName, prefix, schemaURI);
        String propValue = props.get(propName);

        if (propValue == null) {
            Element tag = prop.addElement(qn);
        }
    }
}