List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
@Override public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException { if (validate) { validateFeed(document);//from w w w. j ava 2 s . c om } final Element rssRoot = document.getRootElement(); return parseFeed(rssRoot, locale); }
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
/** * Parse entry from reader./*from w ww. ja va 2s . 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); }
From source file:com.rometools.rome.io.impl.OPML10Parser.java
License:Apache License
/** * Parses an XML document (JDOM Document) into a feed bean. * <p>/* ww w. j ava 2 s . c o m*/ * * @param document XML document (JDOM) to parse. * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). * @return the resulting feed bean. * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). */ @Override public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException { final Opml opml = new Opml(); opml.setFeedType("opml_1.0"); final Element root = document.getRootElement(); final Element head = root.getChild("head"); if (head != null) { opml.setTitle(head.getChildText("title")); if (head.getChildText("dateCreated") != null) { opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"), Locale.US)); } if (head.getChildText("dateModified") != null) { opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"), Locale.US)); } opml.setOwnerName(head.getChildTextTrim("ownerName")); opml.setOwnerEmail(head.getChildTextTrim("ownerEmail")); opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState"))); } try { opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); } catch (final NumberFormatException nfe) { if (validate) { throw new FeedException("Unable to parse windowBottom", nfe); } } try { opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); } catch (final NumberFormatException nfe) { } try { opml.setWindowRight(readInteger(head.getChildText("windowRight"))); } catch (final NumberFormatException nfe) { if (validate) { throw new FeedException("Unable to parse windowRight", nfe); } } try { opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); } catch (final NumberFormatException nfe) { if (validate) { throw new FeedException("Unable to parse windowLeft", nfe); } } try { opml.setWindowTop(readInteger(head.getChildText("windowTop"))); } catch (final NumberFormatException nfe) { if (validate) { throw new FeedException("Unable to parse windowTop", nfe); } } try { opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); } catch (final NumberFormatException nfe) { if (validate) { throw new FeedException("Unable to parse expansionState", nfe); } } opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale)); opml.setModules(parseFeedModules(root, locale)); return opml; }
From source file:com.rometools.rome.io.impl.OPML20Parser.java
License:Apache License
/** * Inspects an XML Document (JDOM) to check if it can parse it. * <p>// ww w .jav a 2 s .c om * It checks if the given document if the type of feeds the parser understands. * <p> * * @param document XML Document (JDOM) to check if it can be parsed by this parser. * @return <b>true</b> if the parser know how to parser this feed, <b>false</b> otherwise. */ @Override public boolean isMyType(final Document document) { final Element e = document.getRootElement(); String name = e.getName(); if (!"opml".equals(name)) { return false; } String version = e.getAttributeValue("version"); if ("2.0".equals(version)) { return true; } Element head = e.getChild("head"); if (head != null) { Element docs = head.getChild("docs"); if (docs != null) { return true; } Element ownerId = head.getChild("ownerId"); if (ownerId != null) { return true; } } return false; }
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;/* w w w. ja v a 2 s . com*/ break; } } } return myType; }
From source file:com.rometools.rome.io.impl.RSS090Parser.java
License:Open Source License
@Override public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException { if (validate) { validateFeed(document);//from w w w. j a va 2 s. c o m } final Element rssRoot = document.getRootElement(); return parseChannel(rssRoot, locale); }
From source file:com.rometools.rome.io.impl.RSS091NetscapeParser.java
License:Open Source License
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final String name = rssRoot.getName(); final Attribute version = rssRoot.getAttribute("version"); final DocType docType = document.getDocType(); return name.equals(ELEMENT_NAME) && version != null && version.getValue().equals(getRSSVersion()) && docType != null && ELEMENT_NAME.equals(docType.getElementName()) && PUBLIC_ID.equals(docType.getPublicID()) && SYSTEM_ID.equals(docType.getSystemID()); }
From source file:com.rometools.rome.io.impl.RSS091UserlandParser.java
License:Open Source License
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Attribute version = rssRoot.getAttribute("version"); return rssRoot.getName().equals("rss") && version != null && version.getValue().equals(getRSSVersion()); }
From source file:com.rometools.rome.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/>/*from w w w .j a va 2s . c o m*/ * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") namespace being defined in * the root element and for the RSS 1.0 ("http://purl.org/rss/1.0/") namespace in the channel * 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. */ @Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Namespace defaultNS = rssRoot.getNamespace(); return defaultNS != null && defaultNS.equals(getRDFNamespace()) && rssRoot.getChild("channel", getRSSNamespace()) != null; }
From source file:com.rometools.rome.io.impl.RSS20Parser.java
License:Open Source License
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Attribute version = rssRoot.getAttribute("version"); // as far ROME is concerned RSS 2.0, 2.00 and 2.0.X are all the same, so let's use // startsWith for leniency. return rssRoot.getName().equals("rss") && version != null && version.getValue().startsWith(getRSSVersion()); }