Example usage for org.dom4j Element getQName

List of usage examples for org.dom4j Element getQName

Introduction

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

Prototype

QName getQName();

Source Link

Document

Returns the QName of this element which represents the local name, the qualified name and the Namespace.

Usage

From source file:org.jboss.as.quickstart.xml.DOM4JXMLParser.java

License:Apache License

@Override
public List<Book> parseInternal(InputStream is) throws Exception {

    Document document = this.dom4jReader.read(is);

    List<Book> catalog = new ArrayList<Book>();
    Element root = document.getRootElement();
    if (!root.getQName().getName().equals("catalog")) {
        throw new RuntimeException("Wrong element: " + root.getQName());
    }//from  w  ww  . j a  va 2 s.c o m

    Iterator children = root.elementIterator();
    while (children.hasNext()) {
        Node n = (Node) children.next();
        String childName = n.getName();
        if (childName == null)
            continue;

        if (childName.equals("book")) {
            Book b = parseBook((Element) n);
            catalog.add(b);
        }
    }

    return catalog;

}

From source file:org.jboss.seam.init.Initialization.java

License:LGPL

@SuppressWarnings("unchecked")
private void installComponentFromXmlElement(Element component, String name, String className,
        Properties replacements) throws ClassNotFoundException {
    String installText = component.attributeValue("installed");
    boolean installed = false;
    if (installText == null || "true".equals(replace(installText, replacements))) {
        installed = true;/*  w  w w. java  2  s  . c o  m*/
    }

    String scopeName = component.attributeValue("scope");
    String jndiName = component.attributeValue("jndi-name");
    String precedenceString = component.attributeValue("precedence");
    int precedence = precedenceString == null ? Install.APPLICATION : Integer.valueOf(precedenceString);
    ScopeType scope = scopeName == null ? null : ScopeType.valueOf(scopeName.toUpperCase());
    String autocreateAttribute = component.attributeValue("auto-create");
    Boolean autoCreate = autocreateAttribute == null ? null : "true".equals(autocreateAttribute);
    String startupAttribute = component.attributeValue("startup");
    Boolean startup = startupAttribute == null ? null : "true".equals(startupAttribute);
    String startupDependsAttribute = component.attributeValue("startupDepends");
    String[] startupDepends = startupDependsAttribute == null ? new String[0]
            : startupDependsAttribute.split(" ");

    if (className != null) {
        Class<?> clazz = getClassUsingImports(className);

        if (name == null) {
            if (!clazz.isAnnotationPresent(Name.class)) {
                throw new IllegalArgumentException(
                        "Component class must have @Name annotation or name must be specified in components.xml: "
                                + clazz.getName());
            }

            name = clazz.getAnnotation(Name.class).value();
        }

        ComponentDescriptor descriptor = new ComponentDescriptor(name, clazz, scope, autoCreate, startup,
                startupDepends, jndiName, installed, precedence);
        addComponentDescriptor(descriptor);
        installedComponentClasses.add(clazz);
    } else if (name == null) {
        throw new IllegalArgumentException("must specify either class or name in <component/> declaration");
    }

    for (Element prop : (List<Element>) component.elements()) {
        String propName = prop.attributeValue("name");
        if (propName == null) {
            propName = prop.getQName().getName();
        }
        String qualifiedPropName = name + '.' + toCamelCase(propName, false);
        properties.put(qualifiedPropName, getPropertyValue(prop, qualifiedPropName, replacements));
    }

    for (Attribute prop : (List<Attribute>) component.attributes()) {
        String attributeName = prop.getName();
        if (isProperty(prop.getNamespaceURI(), attributeName)) {
            String qualifiedPropName = name + '.' + toCamelCase(prop.getQName().getName(), false);
            Conversions.PropertyValue propValue = null;
            try {
                propValue = getPropertyValue(prop, replacements);
                properties.put(qualifiedPropName, propValue);
            } catch (Exception ex) {
                throw new IllegalArgumentException(String.format(
                        "Exception setting property %s on component %s.  Expression %s evaluated to %s.",
                        qualifiedPropName, name, prop.getValue(), propValue), ex);

            }
        }
    }
}

From source file:org.jetbrains.kotlin.projectsextensions.maven.buildextender.PomXmlModifier.java

License:Apache License

private Element createDependenciesElement(Element root) {
    QName qname = new QName("dependencies", root.getQName().getNamespace());
    DefaultElement dependenciesElement = new DefaultElement(qname);

    root.content().add(dependenciesElement);

    return root.element("dependencies");
}

From source file:org.jetbrains.kotlin.projectsextensions.maven.buildextender.PomXmlModifier.java

License:Apache License

private Element createBuildElement(Element root) {
    QName qname = new QName("build", root.getQName().getNamespace());
    DefaultElement buildElement = new DefaultElement(qname);

    root.content().add(buildElement);//from w w w .j ava2  s. c om

    return root.element("build");
}

From source file:org.jetbrains.kotlin.projectsextensions.maven.buildextender.PomXmlModifier.java

License:Apache License

private Element createPluginsElement(Element root) {
    QName qname = new QName("plugins", root.getQName().getNamespace());
    DefaultElement pluginsElement = new DefaultElement(qname);

    root.content().add(pluginsElement);/*from  w ww .  j ava  2  s.co m*/

    return root.element("plugins");
}

From source file:org.jetbrains.kotlin.projectsextensions.maven.buildextender.PomXmlModifier.java

License:Apache License

private void createStdlibDependency(Element dependencies) {
    QName dependencyQname = new QName("dependency", dependencies.getQName().getNamespace());
    DefaultElement dependency = new DefaultElement(dependencyQname);

    QName groupIdQname = new QName("groupId", dependencies.getQName().getNamespace());
    DefaultElement groupId = new DefaultElement(groupIdQname);
    groupId.addText(groupIdName);//www . j  a  v  a2s . com

    QName artifactIdQname = new QName("artifactId", dependencies.getQName().getNamespace());
    DefaultElement artifactId = new DefaultElement(artifactIdQname);
    artifactId.addText("kotlin-stdlib");

    QName versionQname = new QName("version", dependencies.getQName().getNamespace());
    DefaultElement version = new DefaultElement(versionQname);
    version.addText(kotlinVersion);

    dependency.add(groupId);
    dependency.add(artifactId);
    dependency.add(version);

    dependencies.content().add(dependency);
}

From source file:org.jetbrains.kotlin.projectsextensions.maven.buildextender.PomXmlModifier.java

License:Apache License

private void addExecution(Element executions, String id, String phase, String goal) {
    QName executionQname1 = new QName("execution", executions.getQName().getNamespace());
    DefaultElement execution = new DefaultElement(executionQname1);

    QName idQname1 = new QName("id", executions.getQName().getNamespace());
    DefaultElement id1 = new DefaultElement(idQname1);
    id1.addText(id);/*from w  ww  .j  a  v a  2  s .c om*/
    QName phaseQname1 = new QName("phase", executions.getQName().getNamespace());
    DefaultElement phase1 = new DefaultElement(phaseQname1);
    phase1.addText(phase);
    QName goalsQname1 = new QName("goals", executions.getQName().getNamespace());
    DefaultElement goals1 = new DefaultElement(goalsQname1);
    QName goalQname1 = new QName("goal", executions.getQName().getNamespace());
    DefaultElement goal1 = new DefaultElement(goalQname1);
    goal1.addText(goal);

    goals1.add(goal1);

    execution.add(id1);
    execution.add(phase1);
    execution.add(goals1);

    executions.add(execution);
}

From source file:org.jetbrains.kotlin.projectsextensions.maven.buildextender.PomXmlModifier.java

License:Apache License

private void addExecutions(Element plugin) {
    QName executionsQname = new QName("executions", plugin.getQName().getNamespace());
    DefaultElement executions = new DefaultElement(executionsQname);

    addExecution(executions, "compile", "process-sources", "compile");
    addExecution(executions, "test-compile", "process-test-sources", "test-compile");

    plugin.add(executions);//from   www .j a  v  a2 s .  c om
}

From source file:org.jetbrains.kotlin.projectsextensions.maven.buildextender.PomXmlModifier.java

License:Apache License

private void createPluginElement(Element plugins) {
    QName pluginQname = new QName("plugin", plugins.getQName().getNamespace());
    DefaultElement plugin = new DefaultElement(pluginQname);

    QName groupIdQname = new QName("groupId", plugins.getQName().getNamespace());
    DefaultElement groupId = new DefaultElement(groupIdQname);
    groupId.addText(groupIdName);/*  w w w  . j  av  a 2  s.  c  o  m*/

    QName artifactIdQname = new QName("artifactId", plugins.getQName().getNamespace());
    DefaultElement artifactId = new DefaultElement(artifactIdQname);
    artifactId.addText("kotlin-maven-plugin");

    QName versionQname = new QName("version", plugins.getQName().getNamespace());
    DefaultElement version = new DefaultElement(versionQname);
    version.addText(kotlinVersion);

    plugin.add(groupId);
    plugin.add(artifactId);
    plugin.add(version);

    addExecutions(plugin);

    plugins.add(plugin);
}

From source file:org.jivesoftware.openfire.OfflineMessageStore.java

License:Open Source License

/**
 * Decide whether a message should be stored offline according to XEP-0160 and XEP-0334.
 *
 * @param message//from   ww w .j  a va 2 s  . com
 * @return <code>true</code> if the message should be stored offline, <code>false</code> otherwise.
 */
static boolean shouldStoreMessage(final Message message) {
    // XEP-0334: Implement the <no-store/> hint to override offline storage
    if (message.getChildElement("no-store", "urn:xmpp:hints") != null) {
        return false;
    }

    switch (message.getType()) {
    case chat:
        // XEP-0160: Messages with a 'type' attribute whose value is "chat" SHOULD be stored offline, with the exception of messages that contain only Chat State Notifications (XEP-0085) [7] content

        // Iterate through the child elements to see if we can find anything that's not a chat state notification or
        // real time text notification
        Iterator<?> it = message.getElement().elementIterator();

        while (it.hasNext()) {
            Object item = it.next();

            if (item instanceof Element) {
                Element el = (Element) item;

                if (!el.getNamespaceURI().equals("http://jabber.org/protocol/chatstates")
                        && !(el.getQName().equals(QName.get("rtt", "urn:xmpp:rtt:0")))) {
                    return true;
                }
            }
        }

        return false;

    case groupchat:
    case headline:
        // XEP-0160: "groupchat" message types SHOULD NOT be stored offline
        // XEP-0160: "headline" message types SHOULD NOT be stored offline
        return false;

    case error:
        // XEP-0160: "error" message types SHOULD NOT be stored offline,
        // although a server MAY store advanced message processing errors offline
        if (message.getChildElement("amp", "http://jabber.org/protocol/amp") == null) {
            return false;
        }
        break;

    default:
        // XEP-0160: Messages with a 'type' attribute whose value is "normal" (or messages with no 'type' attribute) SHOULD be stored offline.
        break;
    }
    return true;
}