Example usage for org.jdom2 Element getNamespace

List of usage examples for org.jdom2 Element getNamespace

Introduction

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

Prototype

public Namespace getNamespace() 

Source Link

Document

Returns the element's Namespace .

Usage

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

License:Open Source License

private boolean hasElementsFrom(Element root, Namespace namespace) {
    boolean hasElements = false;
    //        boolean hasElements = namespace.equals(root.getNamespace());

    if (!hasElements) {
        List children = root.getChildren();
        for (int i = 0; !hasElements && i < children.size(); i++) {
            Element child = (Element) children.get(i);
            hasElements = namespace.equals(child.getNamespace());
        }//  w w w  .  j  a  v  a 2 s  . co m
    }
    return hasElements;
}

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 www .j  a  va  2 s . c  om*/
        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.RSS090Parser.java

License:Open Source License

/**
 * Parses an item element of an RSS document looking for item information.
 * <p/>//from ww  w.  jav  a 2s. c  o  m
 * It reads title and link out of the 'item' element.
 * <p/>
 *
 * @param rssRoot the root element of the RSS document in case it's needed for context.
 * @param eItem the item element to parse.
 * @return the parsed RSSItem bean.
 */
protected Item parseItem(Element rssRoot, Element eItem) {
    Item item = new Item();
    Element e = eItem.getChild("title", getRSSNamespace());
    if (e != null) {
        item.setTitle(e.getText());
    }
    e = eItem.getChild("link", getRSSNamespace());
    if (e != null) {
        item.setLink(e.getText());
        item.setUri(e.getText());
    }

    item.setModules(parseItemModules(eItem));

    List foreignMarkup = extractForeignMarkup(eItem, item, getRSSNamespace());
    //content:encoded elements are treated special, without a module, they have to be removed from the foreign
    //markup to avoid duplication in case of read/write. Note that this fix will break if a content module is
    //used
    Iterator iterator = foreignMarkup.iterator();
    while (iterator.hasNext()) {
        Element ie = (Element) iterator.next();
        if (getContentNamespace().equals(ie.getNamespace()) && ie.getName().equals("encoded")) {
            iterator.remove();
        }
    }
    if (foreignMarkup.size() > 0) {
        item.setForeignMarkup(foreignMarkup);
    }
    return item;
}

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  . ja v  a 2s. co 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:com.sun.syndication.io.impl.RSS20wNSParser.java

License:Open Source License

public boolean isMyType(Document document) {
    Element rssRoot = document.getRootElement();
    Namespace defaultNS = rssRoot.getNamespace();
    boolean ok = defaultNS != null && defaultNS.equals(getRSSNamespace());
    if (ok) {// www  .j  a v a  2s  . c  o m
        ok = super.isMyType(document);
    }
    return ok;
}

From source file:com.thoughtworks.go.config.parser.GoConfigClassLoader.java

License:Apache License

public static boolean compare(Element e, Class<?> implementation, ConfigCache configCache) {
    final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(implementation,
            AttributeAwareConfigTag.class);

    if (attributeAwareConfigTag != null) {
        return compareAttributeAwareConfigTag(e, attributeAwareConfigTag);
    }//from  ww  w.ja  v a  2s.c  o m

    ConfigTag configTag = configTag(implementation, configCache);
    return configTag.value().equals(e.getName()) && e.getNamespace().getURI().equals(configTag.namespaceURI());
}

From source file:com.thoughtworks.go.config.parser.GoConfigClassLoader.java

License:Apache License

private static boolean compareAttributeAwareConfigTag(Element e,
        AttributeAwareConfigTag attributeAwareConfigTag) {
    return attributeAwareConfigTag.value().equals(e.getName())
            && attributeAwareConfigTag.attributeValue()
                    .equals(e.getAttributeValue(attributeAwareConfigTag.attribute()))
            && e.getNamespace().getURI().equals(attributeAwareConfigTag.namespaceURI());
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MfencedReplacer.java

License:Apache License

private void replaceMfenced(final Element mfencedElement) {
    assert mfencedElement != null;
    final char[] separators = getSeparators(mfencedElement);
    final Namespace ns = mfencedElement.getNamespace();
    final List<Element> children = mfencedElement.getChildren();
    final int nChildren = children.size();
    final int last = Math.min(separators.length - 1, nChildren - 2);

    Element insideFence = null;//  w  w  w . j a v a  2 s.  c  o  m
    if (nChildren == 1 && children.get(0).getName().equals(ROW)) {
        // we do not want to add another mrow
        insideFence = children.get(0).detach();
    } else if (nChildren != 0) {
        insideFence = new Element(ROW, ns);
        for (int i = 0; i < nChildren; i++) {
            // add separator
            if (i > 0 && last >= 0) { // not before first or when blank separators
                char separatorChar = separators[(i - 1 > last) ? last : i - 1];
                String separatorStr = Character.toString(separatorChar);
                insideFence.addContent(new Element(OPERATOR, ns).setText(separatorStr));
            }
            // add original child
            insideFence.addContent(children.get(0).detach());
        }
    }
    replaceMfenced(mfencedElement, insideFence);
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MfencedReplacer.java

License:Apache License

private void replaceMfenced(final Element mfencedElement, final Element insideContent) {
    assert mfencedElement != null; // but insideContent can be null
    final Namespace ns = mfencedElement.getNamespace();
    Element replacement = new Element(ROW, ns);
    String openStr = getProperty(DEFAULT_OPEN);
    String closeStr = getProperty(DEFAULT_CLOSE);
    if (openStr.isEmpty() || closeStr.isEmpty()) {
        LOGGER.warning("Default open or close fence not set");
    }/*from w  w w.  j av  a 2 s . co m*/

    if (!isEnabled(FORCE_DEFAULT_OPEN)) {
        openStr = mfencedElement.getAttributeValue(OPEN_FENCE, openStr);
    }
    if (!isEnabled(FORCE_DEFAULT_CLOSE)) {
        closeStr = mfencedElement.getAttributeValue(CLOSE_FENCE, closeStr);
    }

    replacement.addContent(new Element(OPERATOR, ns).setText(openStr));
    if (insideContent != null) {
        if (isEnabled(ADD_INNER_ROW)) {
            replacement.addContent(insideContent);
        } else {
            replacement.addContent(insideContent.removeContent());
        }
    }
    replacement.addContent(new Element(OPERATOR, ns).setText(closeStr));

    final Element parent = mfencedElement.getParentElement();
    final int index = parent.indexOf(mfencedElement);
    parent.removeContent(index);
    if (isEnabled(ADD_OUTER_ROW)) {
        parent.addContent(index, replacement);
    } else {
        parent.addContent(index, replacement.removeContent());
    }
    LOGGER.fine("Mfenced element converted");
}

From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java

License:Apache License

private void propagateNamespace(Element element) {
    List children = element.getChildren();
    for (Object o : children) {
        Element child = (Element) o;
        if (child.getName().equals("raise")) {
            child.setNamespace(Namespace.getNamespace("ca", "http://www.dfki.de/mmds/scxml/customaction"));
        } else {/*w  w  w . ja  v a2s  . co m*/
            child.setNamespace(element.getNamespace());
        }
        propagateNamespace(child);
    }
}