Example usage for org.jdom2 Element getAdditionalNamespaces

List of usage examples for org.jdom2 Element getAdditionalNamespaces

Introduction

In this page you can find the example usage for org.jdom2 Element getAdditionalNamespaces.

Prototype

public List<Namespace> getAdditionalNamespaces() 

Source Link

Document

Returns a list of the additional namespace declarations on this element.

Usage

From source file:com.rometools.modules.content.io.ContentModuleParser.java

License:Open Source License

@Override
public com.rometools.rome.feed.module.Module parse(final Element element, final Locale locale) {
    boolean foundSomething = false;
    final ContentModule cm = new ContentModuleImpl();
    final List<Element> encodeds = element.getChildren("encoded", CONTENT_NS);
    final ArrayList<String> contentStrings = new ArrayList<String>();
    final ArrayList<String> encodedStrings = new ArrayList<String>();

    if (!encodeds.isEmpty()) {
        foundSomething = true;//from  www . j  av  a 2  s.  c o  m

        for (int i = 0; i < encodeds.size(); i++) {
            final Element encodedElement = encodeds.get(i);
            encodedStrings.add(encodedElement.getText());
            contentStrings.add(encodedElement.getText());
        }
    }

    final ArrayList<ContentItem> contentItems = new ArrayList<ContentItem>();
    final List<Element> items = element.getChildren("items", CONTENT_NS);

    for (int i = 0; i < items.size(); i++) {
        foundSomething = true;

        final List<Element> lis = items.get(i).getChild("Bag", RDF_NS).getChildren("li", RDF_NS);

        for (int j = 0; j < lis.size(); j++) {
            final ContentItem ci = new ContentItem();
            final Element li = lis.get(j);
            final Element item = li.getChild("item", CONTENT_NS);
            final Element format = item.getChild("format", CONTENT_NS);
            final Element encoding = item.getChild("encoding", CONTENT_NS);
            final Element value = item.getChild("value", RDF_NS);

            if (value != null) {
                if (value.getAttributeValue("parseType", RDF_NS) != null) {
                    ci.setContentValueParseType(value.getAttributeValue("parseType", RDF_NS));
                }

                if (ci.getContentValueParseType() != null && ci.getContentValueParseType().equals("Literal")) {
                    ci.setContentValue(getXmlInnerText(value));
                    contentStrings.add(getXmlInnerText(value));
                    ci.setContentValueNamespaces(value.getAdditionalNamespaces());
                } else {
                    ci.setContentValue(value.getText());
                    contentStrings.add(value.getText());
                }

                ci.setContentValueDOM(value.clone().getContent());
            }

            if (format != null) {
                ci.setContentFormat(format.getAttribute("resource", RDF_NS).getValue());
            }

            if (encoding != null) {
                ci.setContentEncoding(encoding.getAttribute("resource", RDF_NS).getValue());
            }

            if (item != null) {
                final Attribute about = item.getAttribute("about", RDF_NS);

                if (about != null) {
                    ci.setContentAbout(about.getValue());
                }
            }

            contentItems.add(ci);
        }
    }

    cm.setEncodeds(encodedStrings);
    cm.setContentItems(contentItems);
    cm.setContents(contentStrings);

    return foundSomething ? cm : null;
}

From source file:com.rometools.rome.io.impl.RSS090Parser.java

License:Open Source License

@Override
public boolean isMyType(final Document document) {

    final Element rssRoot = document.getRootElement();
    final Namespace defaultNS = rssRoot.getNamespace();
    final List<Namespace> additionalNSs = rssRoot.getAdditionalNamespaces();

    boolean myType = false;
    if (defaultNS != null && defaultNS.equals(getRDFNamespace()) && additionalNSs != null) {
        for (final Namespace namespace : additionalNSs) {
            if (getRSSNamespace().equals(namespace)) {
                myType = true;/*from  w  w  w  .  j a v a2  s.com*/
                break;
            }
        }
    }
    return myType;

}

From source file:com.sun.syndication.io.impl.RSS090Parser.java

License:Open Source License

public boolean isMyType(Document document) {
    boolean ok = false;

    Element rssRoot = document.getRootElement();
    Namespace defaultNS = rssRoot.getNamespace();
    List additionalNSs = rssRoot.getAdditionalNamespaces();

    ok = defaultNS != null && defaultNS.equals(getRDFNamespace());
    if (ok) {/*from w  ww .  j a  va 2s.  com*/
        if (additionalNSs == null) {
            ok = false;
        } else {
            ok = false;
            for (int i = 0; !ok && i < additionalNSs.size(); i++) {
                ok = getRSSNamespace().equals(additionalNSs.get(i));
            }
        }
    }
    return ok;
}

From source file:com.sun.syndication.io.impl.RSS10Parser.java

License:Open Source License

/**
 * Indicates if a JDom document is an RSS instance that can be parsed with the parser.
 * <p/>// ww  w.j a  va  2s . c o  m
 * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and
 * RSS ("http://purl.org/rss/1.0/") namespaces being defined in the root element.
 *
 * @param document document to check if it can be parsed with this parser implementation.
 * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise.
 */
public boolean isMyType(Document document) {
    boolean ok = false;

    Element rssRoot = document.getRootElement();
    Namespace defaultNS = rssRoot.getNamespace();
    List additionalNSs = rssRoot.getAdditionalNamespaces();

    ok = defaultNS != null && defaultNS.equals(getRDFNamespace());
    if (ok) {
        if (additionalNSs == null) {
            ok = false;
        } else {
            ok = false;
            for (int i = 0; !ok && i < additionalNSs.size(); i++) {
                ok = getRSSNamespace().equals(additionalNSs.get(i));
            }
        }
    }
    return ok;
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java

License:Apache License

private void adjustNamespaces(final Element element) {
    element.setNamespace(null);/*from  w ww . j  a va  2  s.c o  m*/
    final List<Namespace> namespaces = new ArrayList<Namespace>(element.getAdditionalNamespaces());
    for (final Namespace namespace : namespaces) {
        element.removeNamespaceDeclaration(namespace);
    }
    element.setNamespace(ModuleXmlBuilder.NS);
    for (final Element child : element.getChildren()) {
        adjustNamespaces(child);
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.util.XmlUtils.java

License:Apache License

public static void adjustNamespaces(final Element element, Namespace ns) {
    element.setNamespace(null);// w  w w . j  a  va2s .c  o  m
    final List<Namespace> namespaces = new ArrayList<Namespace>(element.getAdditionalNamespaces());
    for (final Namespace namespace : namespaces) {
        element.removeNamespaceDeclaration(namespace);
    }
    element.setNamespace(ns);
    for (final Element child : element.getChildren()) {
        adjustNamespaces(child, ns);
    }
}

From source file:org.artifactory.version.converter.NamespaceConverter.java

License:Open Source License

@Override
@SuppressWarnings({ "unchecked" })
public void convert(Document doc) {
    // change the xsd uri and schema location
    String currentXsdUri = ArtifactoryConfigVersion.getCurrent().getXsdUri();
    String currentXsdLocation = ArtifactoryConfigVersion.getCurrent().getXsdLocation();
    Namespace ns = Namespace.getNamespace(currentXsdUri);
    Element root = doc.getRootElement();
    // Check that schema instance namespace is there before adding schema location...
    Namespace schemaInstanceNS = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    List<Namespace> namespaces = root.getAdditionalNamespaces();
    boolean hasSchemaInstanceNS = false;
    for (Namespace namespace : namespaces) {
        // The equality is only on URI so hardcoded prefix does not impact
        if (namespace.equals(schemaInstanceNS)) {
            hasSchemaInstanceNS = true;//  w  w  w .  j  a  va2  s  .  c o  m
        }
    }
    if (!hasSchemaInstanceNS) {
        root.addNamespaceDeclaration(schemaInstanceNS);
    }
    root.setAttribute("schemaLocation", currentXsdUri + " " + currentXsdLocation, schemaInstanceNS);

    changeNameSpace(root, ns);
}

From source file:org.jahia.utils.osgi.parsers.AbstractXmlFileParser.java

License:Open Source License

public boolean hasNamespaceURI(Element element, String namespaceURI) {
    //getLog().debug("Main namespace URI=" + element.getNamespace().getURI());
    if (element.getNamespace().getURI().equals(namespaceURI)) {
        return true;
    }/*from w w w  .  ja v  a  2 s .  co m*/
    List<Namespace> additionalNamespaces = (List<Namespace>) element.getAdditionalNamespaces();
    for (Namespace additionalNamespace : additionalNamespaces) {
        //getLog().debug("Additional namespace URI=" + additionalNamespace.getURI());
        if (additionalNamespace.getURI().equals(namespaceURI)) {
            return true;
        }
    }
    return false;
}

From source file:org.jahia.utils.osgi.parsers.AbstractXmlFileParser.java

License:Open Source License

public Set<String> getMissingQueryPrefixes(Element root, String xPathQuery) {
    Set<String> xPathQueryPrefixes = getPrefixesInXPath(xPathQuery);
    Set<String> elementPrefixes = new HashSet<String>();
    for (Namespace additionalNamespaces : (List<Namespace>) root.getAdditionalNamespaces()) {
        elementPrefixes.add(additionalNamespaces.getPrefix());
    }/*from  w ww.j  a v  a 2  s.co  m*/
    elementPrefixes.add("beans");
    Set<String> missingPrefixes = new TreeSet<String>();
    for (String xPathQueryPrefix : xPathQueryPrefixes) {
        if (!elementPrefixes.contains(xPathQueryPrefix)) {
            missingPrefixes.add(xPathQueryPrefix);
        }
    }
    return missingPrefixes;
}

From source file:org.jahia.utils.osgi.parsers.AbstractXmlFileParser.java

License:Open Source License

public void dumpElementNamespaces(Element element) {
    Namespace mainNamespace = element.getNamespace();
    getLogger().debug("Main namespace prefix=[" + mainNamespace.getPrefix() + "] uri=[" + mainNamespace.getURI()
            + "] getNamespaceURI=[" + element.getNamespaceURI() + "]");
    for (Namespace additionalNamespace : (List<Namespace>) element.getAdditionalNamespaces()) {
        getLogger().debug("Additional namespace prefix=" + additionalNamespace.getPrefix() + " uri="
                + additionalNamespace.getURI());
    }//from  w  ww  .j  av a2 s  . c o m
}