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.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java

License:Apache License

private String loadVersion(Document xmlDoc) {
    Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_VERSION, namespaceCP));
    if (el == null) {
        return null;
    }//  ww  w. j  av a  2 s.c o  m
    return el.getStringValue();
}

From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java

License:Apache License

/**
 * Check the element for the following OPC compliance rules:
 * <p>//  www  .java 2  s. co m
 * Rule M4.2: A format consumer shall consider the use of the Markup
 * Compatibility namespace to be an error.
 * </p><p>
 * Rule M4.3: Producers shall not create a document element that contains
 * refinements to the Dublin Core elements, except for the two specified in
 * the schema: <dcterms:created> and <dcterms:modified> Consumers shall
 * consider a document element that violates this constraint to be an error.
 * </p><p>
 * Rule M4.4: Producers shall not create a document element that contains
 * the xml:lang attribute. Consumers shall consider a document element that
 * violates this constraint to be an error.
 *  </p><p>
 * Rule M4.5: Producers shall not create a document element that contains
 * the xsi:type attribute, except for a <dcterms:created> or
 * <dcterms:modified> element where the xsi:type attribute shall be present
 * and shall hold the value dcterms:W3CDTF, where dcterms is the namespace
 * prefix of the Dublin Core namespace. Consumers shall consider a document
 * element that violates this constraint to be an error.
 * </p>
 */
public void checkElementForOPCCompliance(Element el) throws InvalidFormatException {
    // Check the current element
    @SuppressWarnings("unchecked")
    List<Namespace> declaredNamespaces = el.declaredNamespaces();
    Iterator<Namespace> itNS = declaredNamespaces.iterator();
    while (itNS.hasNext()) {
        Namespace ns = itNS.next();

        // Rule M4.2
        if (ns.getURI().equals(PackageNamespaces.MARKUP_COMPATIBILITY))
            throw new InvalidFormatException(
                    "OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.");
    }

    // Rule M4.3
    if (el.getNamespace().getURI().equals(PackageProperties.NAMESPACE_DCTERMS)
            && !(el.getName().equals(KEYWORD_CREATED) || el.getName().equals(KEYWORD_MODIFIED)))
        throw new InvalidFormatException(
                "OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.");

    // Rule M4.4
    if (el.attribute(new QName("lang", namespaceXML)) != null)
        throw new InvalidFormatException(
                "OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.");

    // Rule M4.5
    if (el.getNamespace().getURI().equals(PackageProperties.NAMESPACE_DCTERMS)) {
        // DCTerms namespace only use with 'created' and 'modified' elements
        String elName = el.getName();
        if (!(elName.equals(KEYWORD_CREATED) || elName.equals(KEYWORD_MODIFIED)))
            throw new InvalidFormatException("Namespace error : " + elName
                    + " shouldn't have the following naemspace -> " + PackageProperties.NAMESPACE_DCTERMS);

        // Check for the 'xsi:type' attribute
        Attribute typeAtt = el.attribute(new QName("type", namespaceXSI));
        if (typeAtt == null)
            throw new InvalidFormatException("The element '" + elName + "' must have the '"
                    + namespaceXSI.getPrefix() + ":type' attribute present !");

        // Check for the attribute value => 'dcterms:W3CDTF'
        if (!typeAtt.getValue().equals("dcterms:W3CDTF"))
            throw new InvalidFormatException("The element '" + elName + "' must have the '"
                    + namespaceXSI.getPrefix() + ":type' attribute with the value 'dcterms:W3CDTF' !");
    }

    // Check its children
    @SuppressWarnings("unchecked")
    Iterator<Element> itChildren = el.elementIterator();
    while (itChildren.hasNext())
        checkElementForOPCCompliance(itChildren.next());
}

From source file:org.apereo.portal.layout.dlm.FragmentDefinition.java

License:Apache License

@Override
public void toElement(org.dom4j.Element parent) {

    // Assertions.
    if (parent == null) {
        String msg = "Argument 'parent' cannot be null.";
        throw new IllegalArgumentException(msg);
    }/*from  www . j  a v  a2s  .  c o m*/

    QName q = new QName("fragment", FragmentDefinition.NAMESPACE);
    org.dom4j.Element rslt = DocumentHelper.createElement(q);
    rslt.addAttribute("name", this.getName());
    rslt.addAttribute("ownerID", this.getOwnerId());
    rslt.addAttribute("precedence", Double.toString(this.getPrecedence()));
    rslt.addAttribute("description", this.getDescription());

    // Serialize our children...
    for (Evaluator v : this.evaluators) {
        v.toElement(rslt);
    }

    parent.add(rslt);
}

From source file:org.apereo.portal.layout.dlm.providers.AllUsersEvaluatorFactory.java

License:Apache License

@Override
public void toElement(Element parent) {

    // Assertions.
    if (parent == null) {
        String msg = "Argument 'parent' cannot be null.";
        throw new IllegalArgumentException(msg);
    }// w w  w .ja  v  a 2  s. c o m

    Element rslt = null;
    QName q = new QName("audience", FragmentDefinition.NAMESPACE);
    rslt = DocumentHelper.createElement(q);
    rslt.addAttribute("evaluatorFactory", this.getFactoryClass().getName());
    parent.add(rslt);
}

From source file:org.apereo.portal.layout.dlm.providers.Paren.java

License:Apache License

@Override
public void toElement(Element parent) {

    // Assertions.
    if (parent == null) {
        String msg = "Argument 'parent' cannot be null.";
        throw new IllegalArgumentException(msg);
    }/*  w  ww . j a v  a  2  s. c om*/

    // NB:  This method behaves vastly different depending on whether
    // the parent of this Paren is an instance of FragmentDefinition.
    Element rslt = null;
    if (parent.getName().equals("fragment")) {

        // The parent is a fragment, so we render as a <dlm:audience> element...
        QName q = new QName("audience", FragmentDefinition.NAMESPACE);
        rslt = DocumentHelper.createElement(q);

        // Discover the EvaluatorFactory class...
        rslt.addAttribute("evaluatorFactory", this.getFactoryClass().getName());

    } else {

        // The parent is *not* a fragment, so we render as a <paren> element...
        rslt = DocumentHelper.createElement("paren");
        rslt.addAttribute("mode", this.type.toString());
    }

    // Serialize our children...
    for (Evaluator v : this.evaluators) {
        v.toElement(rslt);
    }

    // Append ourself...
    parent.add(rslt);
}

From source file:org.apereo.portal.layout.dlm.providers.SubscribedTabEvaluator.java

License:Apache License

@Override
public void toElement(Element parent) {
    // Assertions.
    if (parent == null) {
        String msg = "Argument 'parent' cannot be null.";
        throw new IllegalArgumentException(msg);
    }/*from  w  ww.  j ava 2s.  c om*/

    Element rslt = null;
    QName q = new QName("audience", FragmentDefinition.NAMESPACE);
    rslt = DocumentHelper.createElement(q);
    rslt.addAttribute("evaluatorFactory", this.getFactoryClass().getName());
    parent.add(rslt);
}

From source file:org.b5chat.crossfire.core.net.sasl.SASLAuthentication.java

License:Open Source License

public static Element getSASLMechanismsElement(ISession session) {
    if (!(session instanceof IClientSession)) {
        return null;
    }/*from w w  w  .j a va  2 s. c om*/

    Element mechs = DocumentHelper
            .createElement(new QName("mechanisms", new Namespace("", "urn:ietf:params:xml:ns:xmpp-sasl")));
    for (String mech : getSupportedMechanisms()) {
        Element mechanism = mechs.addElement("mechanism");
        mechanism.setText(mech);
    }
    return mechs;
}

From source file:org.b5chat.crossfire.xmpp.disco.IQDiscoInfoHandler.java

License:Open Source License

@Override
public IQ handleIQ(IQ packet) {
    // Create a copy of the sent pack that will be used as the reply
    // we only need to add the requested info to the reply if any otherwise add 
    // a not found error
    IQ reply = IQ.createResultIQ(packet);

    // Look for a IDiscoInfoProvider associated with the requested entity.
    // We consider the host of the recipient JID of the packet as the entity. It's the 
    // IDiscoInfoProvider responsibility to provide information about the JID's name together 
    // with any possible requested node.  
    IDiscoInfoProvider infoProvider = getProvider(
            packet.getTo() == null ? XmppServer.getInstance().getServerInfo().getXMPPDomain()
                    : packet.getTo().getDomain());
    if (infoProvider != null) {
        // Get the JID's name
        String name = packet.getTo() == null ? null : packet.getTo().getNode();
        if (name == null || name.trim().length() == 0) {
            name = null;//  ww w . j ava  2s  .  c o  m
        }
        // Get the requested node
        Element iq = packet.getChildElement();
        String node = iq.attributeValue("node");
        //String node = metaData.getProperty("query:node");

        // Check if we have information about the requested name and node
        if (infoProvider.hasInfo(name, node, packet.getFrom())) {
            reply.setChildElement(iq.createCopy());
            Element queryElement = reply.getChildElement();

            // Add to the reply all the identities provided by the IDiscoInfoProvider
            Element identity;
            Iterator<Element> identities = infoProvider.getIdentities(name, node, packet.getFrom());
            while (identities.hasNext()) {
                identity = identities.next();
                identity.setQName(new QName(identity.getName(), queryElement.getNamespace()));
                queryElement.add((Element) identity.clone());
            }

            // Add to the reply all the features provided by the IDiscoInfoProvider
            Iterator<String> features = infoProvider.getFeatures(name, node, packet.getFrom());
            boolean hasDiscoInfoFeature = false;
            boolean hasDiscoItemsFeature = false;
            boolean hasResultSetManagementFeature = false;

            while (features.hasNext()) {
                final String feature = features.next();
                queryElement.addElement("feature").addAttribute("var", feature);
                if (feature.equals(NAMESPACE_DISCO_INFO)) {
                    hasDiscoInfoFeature = true;
                } else if (feature.equals("http://jabber.org/protocol/disco#items")) {
                    hasDiscoItemsFeature = true;
                } else if (feature.equals(ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)) {
                    hasResultSetManagementFeature = true;
                }
            }

            if (hasDiscoItemsFeature && !hasResultSetManagementFeature) {
                // IQDiscoItemsHandler provides result set management
                // support.
                queryElement.addElement("feature").addAttribute("var",
                        ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT);
            }

            if (!hasDiscoInfoFeature) {
                // XEP-0030 requires that every entity that supports service
                // discovery broadcasts the disco#info feature.
                queryElement.addElement("feature").addAttribute("var", NAMESPACE_DISCO_INFO);
            }

            // Add to the reply the extended info (XDataForm) provided by the IDiscoInfoProvider
            DataForm dataForm = infoProvider.getExtendedInfo(name, node, packet.getFrom());
            if (dataForm != null) {
                queryElement.add(dataForm.getElement());
            }
        } else {
            // If the IDiscoInfoProvider has no information for the requested name and node 
            // then answer a not found error
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.item_not_found);
        }
    } else {
        // If we didn't find a IDiscoInfoProvider then answer a not found error
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.item_not_found);
    }

    return reply;
}

From source file:org.b5chat.crossfire.xmpp.disco.IQDiscoItemsHandler.java

License:Open Source License

@Override
public IQ handleIQ(IQ packet) {
    // Create a copy of the sent pack that will be used as the reply
    // we only need to add the requested items to the reply if any otherwise add 
    // a not found error
    IQ reply = IQ.createResultIQ(packet);

    // TODO Implement publishing client items
    if (IQ.Type.set == packet.getType()) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.feature_not_implemented);
        return reply;
    }//from  w ww.j av a 2  s  .  c o  m

    // Look for a IDiscoItemsProvider associated with the requested entity.
    // We consider the host of the recipient JID of the packet as the entity. It's the 
    // IDiscoItemsProvider responsibility to provide the items associated with the JID's name  
    // together with any possible requested node.
    IDiscoItemsProvider itemsProvider = getProvider(
            packet.getTo() == null ? XmppServer.getInstance().getServerInfo().getXMPPDomain()
                    : packet.getTo().getDomain());
    if (itemsProvider != null) {
        // Get the JID's name
        String name = packet.getTo() == null ? null : packet.getTo().getNode();
        if (name == null || name.trim().length() == 0) {
            name = null;
        }
        // Get the requested node
        Element iq = packet.getChildElement();
        String node = iq.attributeValue("node");

        // Check if we have items associated with the requested name and node
        Iterator<DiscoItem> itemsItr = itemsProvider.getItems(name, node, packet.getFrom());
        if (itemsItr != null) {
            reply.setChildElement(iq.createCopy());
            Element queryElement = reply.getChildElement();

            // See if the requesting entity would like to apply 'result set
            // management'
            final Element rsmElement = packet.getChildElement()
                    .element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT));

            // apply RSM only if the element exists, and the (total) results
            // set is not empty.
            final boolean applyRSM = rsmElement != null && itemsItr.hasNext();

            if (applyRSM) {
                if (!ResultSet.isValidRSMRequest(rsmElement)) {
                    reply.setError(PacketError.Condition.bad_request);
                    return reply;
                }

                // Calculate which results to include.
                final List<DiscoItem> rsmResults;
                final List<DiscoItem> allItems = new ArrayList<DiscoItem>();
                while (itemsItr.hasNext()) {
                    allItems.add(itemsItr.next());
                }
                final ResultSet<DiscoItem> rs = new ResultSetImpl<DiscoItem>(allItems);
                try {
                    rsmResults = rs.applyRSMDirectives(rsmElement);
                } catch (NullPointerException e) {
                    final IQ itemNotFound = IQ.createResultIQ(packet);
                    itemNotFound.setError(PacketError.Condition.item_not_found);
                    return itemNotFound;
                }

                // add the applicable results to the IQ-result
                for (DiscoItem item : rsmResults) {
                    final Element resultElement = item.getElement();
                    resultElement.setQName(new QName(resultElement.getName(), queryElement.getNamespace()));
                    queryElement.add(resultElement.createCopy());
                }

                // overwrite the 'set' element.
                queryElement.remove(
                        queryElement.element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)));
                queryElement.add(rs.generateSetElementFromResults(rsmResults));
            } else {
                // don't apply RSM:
                // Add to the reply all the items provided by the IDiscoItemsProvider
                Element item;
                while (itemsItr.hasNext()) {
                    item = itemsItr.next().getElement();
                    item.setQName(new QName(item.getName(), queryElement.getNamespace()));
                    queryElement.add(item.createCopy());
                }
            }
        } else {
            // If the IDiscoItemsProvider has no items for the requested name and node 
            // then answer a not found error
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.item_not_found);
        }
    } else {
        // If we didn't find a IDiscoItemsProvider then answer a not found error
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.item_not_found);
    }

    return reply;
}

From source file:org.codehaus.cargo.container.weblogic.WebLogic9x10x103x12xConfigXmlInstalledLocalDeployer.java

License:Apache License

/**
 * create the config.xml element representing the Deployable. In WebLogic 9x, this is the
 * element app-deployment./*from w  w  w. j  ava 2 s. com*/
 * 
 * @param deployable to configure
 * @param domain root element of the config.xml file
 * @return app-deployment element
 */
protected Element createElementForDeployableInDomain(Deployable deployable, Element domain) {
    QName appDeploymentQName = new QName("app-deployment", new Namespace("", namespace));
    Element appDeployment = domain.addElement(appDeploymentQName);
    String id = createIdForDeployable(deployable);
    // the name element is a unique identifier in the config.xml file. that's why this is being
    // named id as opposed to name
    Element appId = appDeployment.addElement("name");
    appId.setText(id);
    Element target = appDeployment.addElement("target");
    target.setText(getServerName());
    Element sourcePath = appDeployment.addElement("source-path");
    sourcePath.setText(getAbsolutePath(deployable));
    return appDeployment;
}