Example usage for org.dom4j QName getName

List of usage examples for org.dom4j QName getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

DOCUMENT ME!

Usage

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));

    /*/*from  w  w  w.j  a  v a2  s  .  co m*/
     * 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.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 2s  . c  o m
        }
        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.openzal.zal.soap.InternalDocumentService.java

License:Open Source License

@Override
public void registerHandlers(DocumentDispatcher dispatcher) {
    mHandlerMapPublisher.receivedHandlerMap(dispatcher.getHandlers());

    Map<QName, ? extends SoapHandler> services = mSoapService.getServices();
    for (Map.Entry<QName, ? extends SoapHandler> entry : services.entrySet()) {
        QName qName = entry.getKey();
        org.dom4j.QName zimbraQName = new org.dom4j.QName(qName.getName(), Namespace.get(qName.getNamespace()));

        dispatcher.registerHandler(zimbraQName, wrapHandler(entry.getValue()));
    }/*from  ww w.j  a va  2s  . com*/
}

From source file:org.openzal.zal.soap.InternalOverrideDocumentServiceImpl.java

License:Open Source License

@Override
public void registerHandlers(DocumentDispatcher dispatcher) {
    // these are latest original handlers, they may be already overriden
    Map<org.dom4j.QName, DocumentHandler> oringinalHandlers = dispatcher.getHandlers();
    mHandlerMapPublisher.receivedHandlerMap(oringinalHandlers);

    Map<QName, OverridenSoapHandler> services = mSoapService.getServices();
    for (Map.Entry<QName, OverridenSoapHandler> entry : services.entrySet()) {
        QName qName = entry.getKey();
        org.dom4j.QName zimbraQName = new org.dom4j.QName(qName.getName(), Namespace.get(qName.getNamespace()));

        DocumentHandler originalDocumentHandler = null;
        if (mOriginalHandlers.containsKey(zimbraQName)) {
            originalDocumentHandler = mOriginalHandlers.get(zimbraQName);
            entry.getValue().setOriginalHandler(unWrapHandler(originalDocumentHandler));
        }//from  ww  w .java  2  s  .  c  om

        if (originalDocumentHandler != null) {
            dispatcher.registerHandler(zimbraQName, wrapHandler(entry.getValue(), originalDocumentHandler));
        } else {
            ZimbraLog.extensions.warn("Unable to proxy SOAP Request: " + zimbraQName.toString());
        }
    }
}

From source file:org.openzal.zal.soap.InternalRestoreDocumentService.java

License:Open Source License

@Override
public void registerHandlers(@NotNull DocumentDispatcher dispatcher) {
    Map<QName, ? extends SoapHandler> services = mSoapService.getServices();
    for (QName qName : services.keySet()) {
        org.dom4j.QName zimbraQName = new org.dom4j.QName(qName.getName(), Namespace.get(qName.getNamespace()));

        dispatcher.unRegisterHandler(zimbraQName);

        if (mOriginalHandlersMap.containsKey(zimbraQName)) {
            dispatcher.registerHandler(zimbraQName, mOriginalHandlersMap.get(zimbraQName));
        }//from  w  w  w .ja  v  a2 s .com
    }
}

From source file:org.openzal.zal.soap.InternalUnregisterDocumentService.java

License:Open Source License

@Override
public void registerHandlers(@NotNull DocumentDispatcher dispatcher) {
    Map<QName, ? extends SoapHandler> services = mSoapService.getServices();
    for (QName qName : services.keySet()) {
        org.dom4j.QName zimbraQName = new org.dom4j.QName(qName.getName(), Namespace.get(qName.getNamespace()));

        dispatcher.unRegisterHandler(zimbraQName);
    }//from   w  w w  . j av a2  s  .  c  o m
}

From source file:org.orbeon.oxf.processor.ProcessorUtils.java

License:Open Source License

public static Processor createProcessorWithInputs(Element testNode, boolean saxDebug) {
    // Create processor
    QName processorName = XMLProcessorRegistry.extractProcessorQName(testNode);
    ProcessorFactory processorFactory = ProcessorFactoryRegistry.lookup(processorName);
    if (processorFactory == null)
        throw new OXFException("Cannot find processor factory with name '" + processorName.getNamespacePrefix()
                + ":" + processorName.getName() + "'");

    Processor processor = processorFactory.createInstance();

    // Connect inputs
    for (Iterator j = XPathUtils.selectIterator(testNode, "input"); j.hasNext();) {
        Element inputElement = (Element) j.next();
        String name = XPathUtils.selectStringValue(inputElement, "@name");
        if (XPathUtils.selectStringValue(inputElement, "@href") == null) {
            // Case of embedded XML
            Element originalElement = (Element) ((Element) inputElement).elementIterator().next();
            if (originalElement == null)
                throw new OXFException("Input content is mandatory");
            Element copiedElement = Dom4jUtils.copyElementCopyParentNamespaces(originalElement);
            final String sid = Dom4jUtils.makeSystemId(originalElement);
            final DOMGenerator domGenerator = new DOMGenerator(copiedElement, "input from pipeline utils",
                    DOMGenerator.ZeroValidity, sid);

            if (saxDebug) {
                final SAXLoggerProcessor loggerProcessor = new SAXLoggerProcessor();
                PipelineUtils.connect(domGenerator, "data", loggerProcessor, "data");
                PipelineUtils.connect(loggerProcessor, "data", processor, name);
            } else {
                PipelineUtils.connect(domGenerator, "data", processor, name);
            }/*  ww w.  j ava2s .  co  m*/
        } else {
            // Href
            LocationData locationData = (LocationData) inputElement.getData();
            URL fullURL = createRelativeURL(locationData, XPathUtils.selectStringValue(inputElement, "@href"));

            URLGenerator urlGenerator = new URLGenerator(fullURL);
            urlGenerator.setLocationData(locationData);
            PipelineUtils.connect(urlGenerator, "data", processor, name);
        }
    }
    return processor;
}

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/*from w  w w .  ja  v a  2  s.  co  m*/
    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;
}

From source file:org.orbeon.oxf.xforms.action.actions.XFormsMessageAction.java

License:Open Source License

public void execute(XFormsActionInterpreter actionInterpreter, Element actionElement, Scope actionScope,
        boolean hasOverriddenContext, Item overriddenContext) {

    final XFormsContainingDocument containingDocument = actionInterpreter.containingDocument();

    {//w ww  .ja v a  2 s  . c  om
        final String levelAttribute;
        final QName levelQName;
        {
            final String tempLevelAttribute = actionElement.attributeValue(XFormsConstants.LEVEL_QNAME);
            if (tempLevelAttribute == null) {
                // "The default is "modal" if the attribute is not specified."
                levelQName = XFormsConstants.XFORMS_MODAL_LEVEL_QNAME;
                levelAttribute = levelQName.getName();
            } else {
                levelAttribute = tempLevelAttribute;
                levelQName = Dom4jUtils.extractAttributeValueQName(actionElement, XFormsConstants.LEVEL_QNAME);
            }
        }

        // Get message value
        final String messageValue;
        {
            final String elementValue = XFormsUtils.getElementValue(actionInterpreter.container(),
                    actionInterpreter.actionXPathContext(),
                    actionInterpreter.getSourceEffectiveId(actionElement), actionElement, false, false, null);

            // If we got a null consider the message to be an empty string
            messageValue = elementValue != null ? elementValue : "";
        }

        if (LOG_APPEARANCES.get(levelQName) != null) {
            // Special log appearance

            final IndentedLogger indentedLogger = containingDocument.indentedLogger();
            if (XFormsConstants.XXFORMS_LOG_DEBUG_LEVEL_QNAME.equals(levelQName)) {
                indentedLogger.logDebug("xf:message", messageValue);
            } else if (XFormsConstants.XXFORMS_LOG_INFO_DEBUG_LEVEL_QNAME.equals(levelQName)) {
                indentedLogger.logInfo("xf:message", messageValue);
            } else if (XFormsConstants.XXFORMS_LOG_WARN_DEBUG_LEVEL_QNAME.equals(levelQName)) {
                indentedLogger.logWarning("xf:message", messageValue);
            } else if (XFormsConstants.XXFORMS_LOG_ERROR_DEBUG_LEVEL_QNAME.equals(levelQName)) {
                indentedLogger.logError("xf:message", messageValue);
            }

        } else if (SUPPORTED_APPEARANCES.get(levelQName) != null) {
            // Any other supported appearance are sent to the client

            final String level;
            if (levelQName.getNamespacePrefix().equals("")) {
                level = levelAttribute;
            } else {
                level = "{" + levelQName.getNamespaceURI() + "}" + levelQName.getName();
            }

            // Store message for sending to client
            containingDocument.addMessageToRun(messageValue, level);

            // NOTE: In the future, we *may* want to save and resume the event state before and after
            // displaying a message, in order to possibly provide a behavior which is more consistent with what
            // users may expect regarding actions executed after xf:message.

        } else {
            // Unsupported appearance
            throw new OXFException(
                    "xf:message element's 'level' attribute must have value: 'ephemeral'|'modeless'|'modal'|'xxf:log-debug'|'xxf:log-info'|'xxf:log-warn'|'xxf:log-error'.");
        }
    }
}

From source file:org.orbeon.oxf.xforms.control.controls.XMLCleaner.java

License:Open Source License

public static org.dom4j.Document cleanXML(org.dom4j.Document doc, String stylesheetURL) {
    try {/*from   w  ww  . j av a  2  s  .co  m*/
        final org.dom4j.Element element = doc.getRootElement();
        final String systemId = Dom4jUtils.makeSystemId(element);
        // The date to clean
        final DOMGenerator dataToClean = new DOMGenerator(doc, "clean xml", DOMGenerator.ZeroValidity,
                systemId);
        // The stylesheet
        final URLGenerator stylesheetGenerator = new URLGenerator(stylesheetURL);
        // The transformation
        // Define the name of the processor (this is a QName)
        final QName processorName = new QName("xslt", XMLConstants.OXF_PROCESSORS_NAMESPACE);
        // Get a factory for this processor
        final ProcessorFactory processorFactory = ProcessorFactoryRegistry.lookup(processorName);
        if (processorFactory == null)
            throw new OXFException("Cannot find processor factory with name '"
                    + processorName.getNamespacePrefix() + ":" + processorName.getName() + "'");

        // Create processor
        final Processor xsltProcessor = processorFactory.createInstance();
        // Where the result goes
        final DOMSerializer transformationOutput = new DOMSerializer();

        // Connect
        PipelineUtils.connect(stylesheetGenerator, "data", xsltProcessor, "config");
        PipelineUtils.connect(dataToClean, "data", xsltProcessor, "data");
        PipelineUtils.connect(xsltProcessor, "data", transformationOutput, "data");

        // Run the pipeline
        // Candidate for Scala withPipelineContext
        final PipelineContext pipelineContext = new PipelineContext();
        boolean success = false;
        try {
            final org.dom4j.Document result = transformationOutput.runGetDocument(pipelineContext);
            success = true;
            return result;
        } finally {
            pipelineContext.destroy(success);
        }
    } catch (Exception e) {
        throw new OXFException(e);
    }
}