Example usage for org.dom4j QName getNamespaceURI

List of usage examples for org.dom4j QName getNamespaceURI

Introduction

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

Prototype

public String getNamespaceURI() 

Source Link

Document

DOCUMENT ME!

Usage

From source file:at.jabberwocky.impl.core.io.PacketReader.java

private Document parseDocument() throws DocumentException, IOException, XmlPullParserException {
    DocumentFactory df = docFactory;// www .ja  va 2  s  . c  o m
    Document document = df.createDocument();
    Element parent = null;
    XmlPullParser pp = parser;
    int count = 0;
    while (true) {
        int type = -1;
        type = pp.nextToken();
        switch (type) {
        case XmlPullParser.PROCESSING_INSTRUCTION: {
            String text = pp.getText();
            int loc = text.indexOf(" ");
            if (loc >= 0) {
                document.addProcessingInstruction(text.substring(0, loc), text.substring(loc + 1));
            } else {
                document.addProcessingInstruction(text, "");
            }
            break;
        }
        case XmlPullParser.COMMENT: {
            if (parent != null) {
                parent.addComment(pp.getText());
            } else {
                document.addComment(pp.getText());
            }
            break;
        }
        case XmlPullParser.CDSECT: {
            String text = pp.getText();
            if (parent != null) {
                parent.addCDATA(text);
            } else {
                if (text.trim().length() > 0) {
                    throw new DocumentException("Cannot have text content outside of the root document");
                }
            }
            break;

        }
        case XmlPullParser.ENTITY_REF: {
            String text = pp.getText();
            if (parent != null) {
                parent.addText(text);
            } else {
                if (text.trim().length() > 0) {
                    throw new DocumentException("Cannot have an entityref outside of the root document");
                }
            }
            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 = null;
            // Do not include the namespace if this is the start tag of a new packet
            // This avoids including "jabber:client", "jabber:server" or
            // "jabber:component:accept"
            if ("jabber:client".equals(qname.getNamespaceURI())
                    || "jabber:server".equals(qname.getNamespaceURI())
                    || "jabber:component:accept".equals(qname.getNamespaceURI())
                    || "http://jabber.org/protocol/httpbind".equals(qname.getNamespaceURI())) {
                newElement = df.createElement(pp.getName());
            } else {
                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));
            }
            if (parent != null) {
                parent.add(newElement);
            } else {
                document.add(newElement);
            }
            parent = newElement;
            count++;
            break;
        }
        case XmlPullParser.END_TAG: {
            if (parent != null) {
                parent = parent.getParent();
            }
            count--;
            if (count < 1) {
                return document;
            }
            break;
        }
        case XmlPullParser.TEXT: {
            String text = pp.getText();
            if (parent != null) {
                parent.addText(text);
            } else {
                if (text.trim().length() > 0) {
                    throw new DocumentException("Cannot have text content outside of the root document");
                }
            }
            break;
        }
        default:
        }
    }
}

From source file:com.bluexml.side.Framework.alfresco.dataGenerator.serialization.mapping.XMLForACPMappingHelper.java

License:Open Source License

/**
 * create and fill the xml's elements corresponding to target of given generated arc
 * @param assoc/*  w ww.  j  av a 2  s .co m*/
 * @param arc
 */
public void createTargetAssociation(Element assoc, IArc arc) {
    org.alfresco.service.namespace.QName arcQName = ((AlfrescoArc) arc).getTypeAssociation().getName();
    Element definedAssoc = assoc.addElement(arcQName.toPrefixString(), arcQName.getNamespaceURI());

    createAssociation(definedAssoc, ((AlfrescoArc) arc).getTarget());
}

From source file:com.liferay.util.xml.XMLConverter.java

License:Open Source License

public static javax.xml.namespace.QName toJavaxQName(org.dom4j.QName dom4jQName) {

    javax.xml.namespace.QName javaxQName = new javax.xml.namespace.QName(dom4jQName.getNamespaceURI(),
            dom4jQName.getName(), dom4jQName.getNamespacePrefix());

    return javaxQName;
}

From source file:com.rdvmedecin.proprietes.Properties.java

public Properties() throws DocumentException {
    File fichier = new File("configuration.xml");
    SAXReader reader = new SAXReader();
    Document doc = reader.read(fichier);
    Element root = doc.getRootElement();
    List attributes = root.attributes();
    List elements = root.elements();
    QName qName = root.getQName();
    String nom = qName.getName();
    // lecture du nom de l'espace de noms
    String nomEspaceDeNoms = qName.getNamespaceURI();
    // lecture du prfixe utilis pour cet espace de nom 
    String nomPrefix = qName.getNamespacePrefix();
    String texte = root.getText();
    Attribute attribute = (Attribute) attributes.iterator().next();
    QName attributeQName = attribute.getQName();
    String value = attribute.getValue();
    String nomAttribut = attribute.getName();
}

From source file:com.zimbra.cs.dav.caldav.Filter.java

License:Open Source License

protected void parse(Element elem) {
    for (Object o : elem.elements()) {
        if (o instanceof Element) {
            Element e = (Element) o;
            QName name = e.getQName();
            if (canHaveCompFilter() && name.equals(DavElements.E_COMP_FILTER))
                mComps.add(new CompFilter(e));
            else if (canHavePropFilter() && name.equals(DavElements.E_PROP_FILTER))
                mProps.add(new PropFilter(e));
            else if (canHaveParamFilter() && name.equals(DavElements.E_PARAM_FILTER))
                mParams.add(new ParamFilter(e));
            else if (name.equals(DavElements.E_TEXT_MATCH))
                mTextMatches.add(new TextMatch(e));
            else if (name.equals(DavElements.E_TIME_RANGE))
                mTimeRange = new TimeRange(e);
            else if (name.equals(DavElements.E_IS_NOT_DEFINED))
                mIsNotDefinedSet = true;
            else/*  w w w .j  av a2 s  . c  o  m*/
                ZimbraLog.dav.info("unrecognized filter " + name.getNamespaceURI() + ":" + name.getName());
        }
    }
}

From source file:com.zimbra.cs.dav.carddav.Filter.java

License:Open Source License

protected void parse(Element elem) {
    for (Object o : elem.elements()) {
        if (o instanceof Element) {
            Element e = (Element) o;
            QName name = e.getQName();
            if (canHavePropFilter() && name.equals(DavElements.CardDav.E_PROP_FILTER))
                mProps.add(new PropFilter(e));
            else if (canHaveParamFilter() && name.equals(DavElements.CardDav.E_PARAM_FILTER))
                mParams.add(new ParamFilter(e, this));
            else if (name.equals(DavElements.CardDav.E_TEXT_MATCH))
                mTextMatch = new TextMatch(e, this);
            else if (name.equals(DavElements.CardDav.E_IS_NOT_DEFINED))
                mIsNotDefinedSet = true;
            else//from www .  j  a  v  a2  s  .c  om
                ZimbraLog.dav.info("unrecognized filter " + name.getNamespaceURI() + ":" + name.getName());
        }
    }
}

From source file:com.zimbra.soap.DocumentDispatcher.java

License:Open Source License

public void registerHandler(QName qname, DocumentHandler handler) {
    if (handler instanceof AdminDocumentHandler) {
        if (!(includeList == null) && !includeList.isEmpty() && !includeList
                .contains(String.format("%s::%s", qname.getNamespaceURI(), qname.getQualifiedName()))) {
            ZimbraLog.soap.debug("skipping %s::%s", qname.getNamespaceURI(), qname.getQualifiedName());
            return;
        }/*  w w w  .  j av a2s. c  om*/
        ZimbraLog.soap.debug("Registering %s::%s", qname.getNamespaceURI(), qname.getQualifiedName());
    }

    handlers.put(qname, handler);
    QName respQName = responses.get(qname);
    if (respQName == null) {
        String reqName = qname.getName();
        String respName;
        if (reqName.endsWith(REQUEST_SUFFIX)) {
            respName = reqName.substring(0, reqName.length() - REQUEST_SUFFIX.length()) + RESPONSE_SUFFIX;
        } else {
            respName = reqName + RESPONSE_SUFFIX;
        }
        respQName = new QName(respName, qname.getNamespace());
        responses.put(qname, respQName);
    }
    handler.setResponseQName(respQName);
}

From source file:org.apereo.portal.tenants.TemplateDataTenantOperationsListener.java

License:Apache License

private boolean evaluatePortalDataKeyMatch(Document doc, PortalDataKey pdk) {
    // Matching is tougher because it's dom4j <> w3c...
    final QName qname = doc.getRootElement().getQName();
    if (!qname.getName().equals(pdk.getName().getLocalPart())
            || !qname.getNamespaceURI().equals(pdk.getName().getNamespaceURI())) {
        // Rule these out straight off...
        return false;
    }/*w w  w. j  av a2s.c om*/

    // If the PortalDataKey declares a script
    // (old method), the document must match it
    final Attribute s = doc.getRootElement().attribute(PortalDataKey.SCRIPT_ATTRIBUTE_NAME.getLocalPart());
    final String script = s != null ? s.getValue() : null;
    if (pdk.getScript() != null) {
        // If the pdk declares a script, the data document MUST match it...
        if (pdk.getScript().equals(script)) {
            /*
             * A data document that matches on script need not match on version
             * as well.  It appears that the pdk.version member is overloaded
             * with two purposes...
             *
             *   - A numeric version (e.g. 4.0) indicates a match IN THE ABSENCE
             *     OF a script attribute (newer method, below)
             *   - A word (e.g. 'GROUP' or 'MEMBERS') indicates the type of data
             *     the pdk handles, where more than one pdk applies to the data
             *     document
             */
            return true;
        } else {
            return false;
        }
    }

    // If the PortalDataKey declares a version BUT NOT a script (new
    // method), the document must match it
    final Attribute v = doc.getRootElement().attribute(PortalDataKey.VERSION_ATTRIBUTE_NAME.getLocalPart());
    final String version = v != null ? v.getValue() : null;
    if (pdk.getVersion() != null && pdk.getVersion().equals(version)) {
        return true;
    }

    // This pdk is not a match
    return false;
}

From source file:org.jasig.portal.tenants.TemplateDataTenantOperationsListener.java

License:Apache License

@Override
public void onCreate(final ITenant tenant) {

    final StandardEvaluationContext ctx = new StandardEvaluationContext();
    ctx.setRootObject(new RootObjectImpl(tenant));

    /*/*  w  w  w.  jav a 2s .com*/
     * First load dom4j Documents and sort the entity files into the proper order 
     */
    final Map<PortalDataKey, Set<Document>> importQueue = new HashMap<PortalDataKey, Set<Document>>();
    Resource rsc = null;
    try {
        for (Resource r : templateResources) {
            rsc = r;
            if (log.isDebugEnabled()) {
                log.debug("Loading template resource file for tenant " + "'" + tenant.getFname() + "':  "
                        + rsc.getFilename());
            }
            final Document doc = reader.read(rsc.getInputStream());
            final QName qname = doc.getRootElement().getQName();
            PortalDataKey atLeastOneMatchingDataKey = null;
            for (PortalDataKey pdk : dataKeyImportOrder) {
                // Matching is tougher because it's dom4j <> w3c...
                boolean matches = qname.getName().equals(pdk.getName().getLocalPart())
                        && qname.getNamespaceURI().equals(pdk.getName().getNamespaceURI());
                if (matches) {
                    // Found the right bucket...
                    atLeastOneMatchingDataKey = pdk;
                    Set<Document> bucket = importQueue.get(atLeastOneMatchingDataKey);
                    if (bucket == null) {
                        // First of these we've seen;  create the bucket;
                        bucket = new HashSet<Document>();
                        importQueue.put(atLeastOneMatchingDataKey, bucket);
                    }
                    bucket.add(doc);
                    /*
                     * At this point, we would normally add a break;
                     * statement, but group_membership.xml files need to
                     * match more than one PortalDataKey.
                     */
                }
            }
            if (atLeastOneMatchingDataKey == null) {
                // We can't proceed
                throw new RuntimeException(
                        "No PortalDataKey found for QName:  " + doc.getRootElement().getQName());
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(
                "Failed to process the specified template:  " + (rsc != null ? rsc.getFilename() : ""), e);
    }

    log.trace("Ready to import data entity templates for new tenant '{}';  importQueue={}", tenant.getName(),
            importQueue);

    /*
     * Now import the identified entities each bucket in turn 
     */
    Document doc = null;
    org.w3c.dom.Document w3c = null;
    try {
        for (PortalDataKey pdk : dataKeyImportOrder) {
            Set<Document> bucket = importQueue.get(pdk);
            if (bucket != null) {
                log.debug("Importing the specified PortalDataKey tenant '{}':  {}", tenant.getName(),
                        pdk.getName());
                for (Document d : bucket) {
                    doc = d;
                    log.trace("Importing document XML={}", doc.asXML());
                    for (String xpath : XPATH_EXPRESSIONS) {
                        @SuppressWarnings("unchecked")
                        List<Node> nodes = doc.selectNodes(xpath);
                        for (Node n : nodes) {
                            String inpt, otpt;
                            switch (n.getNodeType()) {
                            case org.w3c.dom.Node.ATTRIBUTE_NODE:
                                Attribute a = (Attribute) n;
                                inpt = a.getValue();
                                otpt = processText(inpt, ctx);
                                if (!otpt.equals(inpt)) {
                                    a.setValue(otpt);
                                }
                                break;
                            case org.w3c.dom.Node.TEXT_NODE:
                                Text t = (Text) n;
                                inpt = t.getText();
                                otpt = processText(inpt, ctx);
                                if (!otpt.equals(inpt)) {
                                    t.setText(otpt);
                                }
                                break;
                            default:
                                String msg = "Unsupported node type:  " + n.getNodeTypeName();
                                throw new RuntimeException(msg);
                            }
                        }
                    }
                    w3c = writer.write(doc, domImpl);
                    Source source = new DOMSource(w3c);
                    source.setSystemId(rsc.getFilename()); // must be set, else import chokes
                    dataHandlerService.importData(source, pdk);
                }
            }
        }

    } catch (Exception e) {
        log.warn("w3c DOM=" + this.nodeToString(w3c));
        throw new RuntimeException(
                "Failed to process the specified template document:  " + (doc != null ? doc.asXML() : ""), e);
    }

}

From source file:org.orbeon.oxf.processor.sql.interpreters.AttributeInterpreter.java

License:Open Source License

public void end(String uri, String localname, String qName) throws SAXException {

    // Restore output
    getInterpreterContext().setOutput(savedOutput);

    // Normalize/* w w  w  . j  a va 2 s  .  c om*/
    final String contentString;
    if (content == null)
        contentString = "";
    else
        contentString = content.toString().trim();

    // Output attribute
    final QName attributeQName = getQName(getDocumentLocator(), attributeName,
            getInterpreterContext().getPrefixesMap());
    getInterpreterContext().getOutput().startPrefixMapping(attributeQName.getName(),
            attributeQName.getNamespaceURI());// NOTE: we may have to check that the mapping does not exist yet
    getInterpreterContext().getOutput().addAttribute(attributeQName.getNamespaceURI(), attributeQName.getName(),
            attributeName, contentString);

    // Clear state
    savedOutput = null;
    attributeName = null;
    content = null;
}