Example usage for org.jdom2 Namespace XML_NAMESPACE

List of usage examples for org.jdom2 Namespace XML_NAMESPACE

Introduction

In this page you can find the example usage for org.jdom2 Namespace XML_NAMESPACE.

Prototype

Namespace XML_NAMESPACE

To view the source code for org.jdom2 Namespace XML_NAMESPACE.

Click Source Link

Document

Define a Namespace for the standard xml prefix.

Usage

From source file:com.rometools.modules.opensearch.impl.OpenSearchModuleParser.java

License:Apache License

/**
 * Use xml:base attributes at feed and entry level to resolve relative links
 *///  w ww  .  j a v a2s .  co  m
private static String resolveURI(final URL baseURI, final Parent parent, String url) {
    url = url.equals(".") || url.equals("./") ? "" : url;
    if (isRelativeURI(url) && parent != null && parent instanceof Element) {
        final Attribute baseAtt = ((Element) parent).getAttribute("base", Namespace.XML_NAMESPACE);
        String xmlBase = baseAtt == null ? "" : baseAtt.getValue();
        if (!isRelativeURI(xmlBase) && !xmlBase.endsWith("/")) {
            xmlBase = xmlBase.substring(0, xmlBase.lastIndexOf("/") + 1);
        }
        return resolveURI(baseURI, parent.getParent(), xmlBase + url);
    } else if (isRelativeURI(url) && parent == null) {
        return baseURI + url;
    } else if (baseURI != null && url.startsWith("/")) {
        String hostURI = baseURI.getProtocol() + "://" + baseURI.getHost();
        if (baseURI.getPort() != baseURI.getDefaultPort()) {
            hostURI = hostURI + ":" + baseURI.getPort();
        }
        return hostURI + url;
    }
    return url;
}

From source file:com.rometools.modules.sle.types.DateValue.java

License:Apache License

public void setNamespace(final Namespace namespace) {
    this.namespace = namespace == null ? Namespace.XML_NAMESPACE : namespace;
}

From source file:com.rometools.modules.sle.types.Group.java

License:Apache License

/**
 * Creates a new instance of Group/*ww  w  .  ja  v a2 s  .  c o  m*/
 *
 * @param namespace Namespace of the element
 * @param element Name of the element
 * @param label Label for the grouping.
 */
public Group(final Namespace namespace, final String element, final String label) {
    this.namespace = namespace == null ? Namespace.XML_NAMESPACE : namespace;
    this.element = element;
    this.label = label;
}

From source file:com.rometools.modules.sle.types.Sort.java

License:Apache License

/**
 * Creates a new instance of Sort/*ww w.jav a 2 s .c o m*/
 *
 * @param namespace Namespace of the element
 * @param element Name of the element
 * @param dataType data-type of the element
 * @param label Label for the sort
 * @param defaultOrder indicates if this is the defaul order of the feed.
 */
public Sort(final Namespace namespace, final String element, final String dataType, final String label,
        final boolean defaultOrder) {
    super();
    this.namespace = namespace == null ? Namespace.XML_NAMESPACE : namespace;
    this.element = element;
    this.dataType = dataType;
    this.label = label;
    this.defaultOrder = defaultOrder;
}

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

License:Open Source License

protected Element createRootElement(final Feed feed) {

    final Element root = new Element("feed", getFeedNamespace());

    root.addNamespaceDeclaration(getFeedNamespace());

    // Attribute version = new Attribute("version", getVersion());
    // root.setAttribute(version);

    final String xmlBase = feed.getXmlBase();
    if (xmlBase != null) {
        root.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE);
    }/*from   w  ww . j  a v  a  2  s. c  o m*/

    generateModuleNamespaceDefs(root);

    return root;

}

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

License:Open Source License

protected void addEntry(final Entry entry, final Element parent) throws FeedException {

    final Element eEntry = new Element("entry", getFeedNamespace());

    final String xmlBase = entry.getXmlBase();
    if (xmlBase != null) {
        eEntry.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE);
    }/*from  ww w. j  a v a2  s  . co  m*/

    populateEntry(entry, eEntry);
    generateForeignMarkup(eEntry, entry.getForeignMarkup());
    checkEntryConstraints(eEntry);
    generateItemModules(entry.getModules(), eEntry);
    parent.addContent(eEntry);

}

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

License:Open Source License

protected WireFeed parseFeed(final Element eFeed, final Locale locale) throws FeedException {

    String baseURI = null;//  w w  w  .j a  va 2 s  .  c  o m
    try {
        baseURI = findBaseURI(eFeed);
    } catch (final Exception e) {
        throw new FeedException("ERROR while finding base URI of feed", e);
    }

    final Feed feed = parseFeedMetadata(baseURI, eFeed, locale);
    feed.setStyleSheet(getStyleSheet(eFeed.getDocument()));

    final String xmlBase = eFeed.getAttributeValue("base", Namespace.XML_NAMESPACE);
    if (xmlBase != null) {
        feed.setXmlBase(xmlBase);
    }

    feed.setModules(parseFeedModules(eFeed, locale));

    final List<Element> eList = eFeed.getChildren("entry", getAtomNamespace());
    if (!eList.isEmpty()) {
        feed.setEntries(parseEntries(feed, baseURI, eList, locale));
    }

    final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
    if (!foreignMarkup.isEmpty()) {
        feed.setForeignMarkup(foreignMarkup);
    }
    return feed;
}

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

License:Open Source License

protected Entry parseEntry(final Feed feed, final Element eEntry, final String baseURI, final Locale locale) {

    final Entry entry = new Entry();

    final String xmlBase = eEntry.getAttributeValue("base", Namespace.XML_NAMESPACE);
    if (xmlBase != null) {
        entry.setXmlBase(xmlBase);/* w  w w.  j a v  a  2s . c o  m*/
    }

    final Element title = eEntry.getChild("title", getAtomNamespace());
    if (title != null) {
        final Content c = new Content();
        c.setValue(parseTextConstructToString(title));
        c.setType(getAttributeValue(title, "type"));
        entry.setTitleEx(c);
    }

    final List<Element> links = eEntry.getChildren("link", getAtomNamespace());
    entry.setAlternateLinks(parseAlternateLinks(feed, entry, baseURI, links));
    entry.setOtherLinks(parseOtherLinks(feed, entry, baseURI, links));

    final List<Element> authors = eEntry.getChildren("author", getAtomNamespace());
    if (!authors.isEmpty()) {
        entry.setAuthors(parsePersons(baseURI, authors, locale));
    }

    final List<Element> contributors = eEntry.getChildren("contributor", getAtomNamespace());
    if (!contributors.isEmpty()) {
        entry.setContributors(parsePersons(baseURI, contributors, locale));
    }

    final Element id = eEntry.getChild("id", getAtomNamespace());
    if (id != null) {
        entry.setId(id.getText());
    }

    final Element updated = eEntry.getChild("updated", getAtomNamespace());
    if (updated != null) {
        entry.setUpdated(DateParser.parseDate(updated.getText(), locale));
    }

    final Element published = eEntry.getChild("published", getAtomNamespace());
    if (published != null) {
        entry.setPublished(DateParser.parseDate(published.getText(), locale));
    }

    final Element summary = eEntry.getChild("summary", getAtomNamespace());
    if (summary != null) {
        entry.setSummary(parseContent(summary));
    }

    final Element content = eEntry.getChild("content", getAtomNamespace());
    if (content != null) {
        final List<Content> contents = new ArrayList<Content>();
        contents.add(parseContent(content));
        entry.setContents(contents);
    }

    final Element rights = eEntry.getChild("rights", getAtomNamespace());
    if (rights != null) {
        entry.setRights(rights.getText());
    }

    final List<Element> categories = eEntry.getChildren("category", getAtomNamespace());
    entry.setCategories(parseCategories(baseURI, categories));

    // TODO: SHOULD handle Atom entry source element
    final Element source = eEntry.getChild("source", getAtomNamespace());
    if (source != null) {
        entry.setSource(parseFeedMetadata(baseURI, source, locale));
    }

    entry.setModules(parseItemModules(eEntry, locale));

    final List<Element> foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace());
    if (!foreignMarkup.isEmpty()) {
        entry.setForeignMarkup(foreignMarkup);
    }

    return entry;
}

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

License:Open Source License

/**
 * Resolve URI via base URL and parent element. Resolve URI based considering xml:base and
 * baseURI./*from  w  w w.  j  av a  2s  . co  m*/
 *
 * @param baseURI Base URI used to fetch the XML document
 * @param parent Parent element from which to consider xml:base
 * @param url URL to be resolved
 */
public static String resolveURI(final String baseURI, final Parent parent, String url) {

    if (!resolveURIs) {
        return url;
    }

    if (isRelativeURI(url)) {

        if (".".equals(url) || "./".equals(url)) {
            url = "";
        }

        if (url.startsWith("/") && baseURI != null) {
            String base = null;
            final int slashslash = baseURI.indexOf("//");
            final int nextslash = baseURI.indexOf("/", slashslash + 2);
            if (nextslash != -1) {
                base = baseURI.substring(0, nextslash);
            }
            return formURI(base, url);
        }

        // Relative URI with parent
        if (parent != null && parent instanceof Element) {

            // Do we have an xml:base?
            String xmlbase = ((Element) parent).getAttributeValue("base", Namespace.XML_NAMESPACE);
            if (xmlbase != null && xmlbase.trim().length() > 0) {
                if (isAbsoluteURI(xmlbase)) {
                    // Absolute xml:base, so form URI right now
                    if (url.startsWith("/")) {
                        // Host relative URI
                        final int slashslash = xmlbase.indexOf("//");
                        final int nextslash = xmlbase.indexOf("/", slashslash + 2);
                        if (nextslash != -1) {
                            xmlbase = xmlbase.substring(0, nextslash);
                        }
                        return formURI(xmlbase, url);
                    }
                    if (!xmlbase.endsWith("/")) {
                        // Base URI is filename, strip it off
                        xmlbase = xmlbase.substring(0, xmlbase.lastIndexOf("/"));
                    }
                    return formURI(xmlbase, url);
                } else {
                    // Relative xml:base, so walk up tree
                    return resolveURI(baseURI, parent.getParent(),
                            stripTrailingSlash(xmlbase) + "/" + stripStartingSlash(url));
                }
            }
            // No xml:base so walk up tree
            return resolveURI(baseURI, parent.getParent(), url);

            // Relative URI with no parent (i.e. top of tree), so form URI
            // right now
        } else if (parent == null || parent instanceof Document) {
            return formURI(baseURI, url);
        }
    }

    return url;

}

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

License:Open Source License

/**
 * Parse entry from reader./*from www .  j av  a2 s .  c o m*/
 */
public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale)
        throws JDOMException, IOException, IllegalArgumentException, FeedException {

    // Parse entry into JDOM tree
    final SAXBuilder builder = new SAXBuilder();
    final Document entryDoc = builder.build(rd);
    final Element fetchedEntryElement = entryDoc.getRootElement();
    fetchedEntryElement.detach();

    // Put entry into a JDOM document with 'feed' root so that Rome can
    // handle it
    final Feed feed = new Feed();
    feed.setFeedType("atom_1.0");
    final WireFeedOutput wireFeedOutput = new WireFeedOutput();
    final Document feedDoc = wireFeedOutput.outputJDom(feed);
    feedDoc.getRootElement().addContent(fetchedEntryElement);

    if (baseURI != null) {
        feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE);
    }

    final WireFeedInput input = new WireFeedInput(false, locale);
    final Feed parsedFeed = (Feed) input.build(feedDoc);
    return parsedFeed.getEntries().get(0);
}