List of usage examples for org.jdom2 Element getName
public String getName()
From source file:com.rometools.modules.itunes.io.ITunesParser.java
License:Open Source License
@Override public com.rometools.rome.feed.module.Module parse(final Element element, final Locale locale) { AbstractITunesObject module = null;// w ww .j av a2 s . c o m if (element.getName().equals("channel")) { final FeedInformationImpl feedInfo = new FeedInformationImpl(); module = feedInfo; // Now I am going to get the channel specific tags final Element owner = element.getChild("owner", ns); if (owner != null) { final Element name = owner.getChild("name", ns); if (name != null) { feedInfo.setOwnerName(name.getValue().trim()); } final Element email = owner.getChild("email", ns); if (email != null) { feedInfo.setOwnerEmailAddress(email.getValue().trim()); } } final Element image = element.getChild("image", ns); if (image != null && image.getAttributeValue("href") != null) { try { final URL imageURL = new URL(image.getAttributeValue("href").trim()); feedInfo.setImage(imageURL); } catch (final MalformedURLException e) { LOG.debug("Malformed URL Exception reading itunes:image tag: {}", image.getAttributeValue("href")); } } final List<Element> categories = element.getChildren("category", ns); for (final Element element2 : categories) { final Element category = element2; if (category != null && category.getAttribute("text") != null) { final Category cat = new Category(); cat.setName(category.getAttribute("text").getValue().trim()); final Element subcategory = category.getChild("category", ns); if (subcategory != null && subcategory.getAttribute("text") != null) { final Subcategory subcat = new Subcategory(); subcat.setName(subcategory.getAttribute("text").getValue().trim()); cat.setSubcategory(subcat); } feedInfo.getCategories().add(cat); } } } else if (element.getName().equals("item")) { final EntryInformationImpl entryInfo = new EntryInformationImpl(); module = entryInfo; // Now I am going to get the item specific tags final Element duration = element.getChild("duration", ns); if (duration != null && duration.getValue() != null) { final Duration dur = new Duration(duration.getValue().trim()); entryInfo.setDuration(dur); } } if (module != null) { // All these are common to both Channel and Item final Element author = element.getChild("author", ns); if (author != null && author.getText() != null) { module.setAuthor(author.getText()); } final Element block = element.getChild("block", ns); if (block != null) { module.setBlock(true); } final Element explicit = element.getChild("explicit", ns); if (explicit != null && explicit.getValue() != null && explicit.getValue().trim().equalsIgnoreCase("yes")) { module.setExplicit(true); } final Element keywords = element.getChild("keywords", ns); if (keywords != null) { final StringTokenizer tok = new StringTokenizer(getXmlInnerText(keywords).trim(), ","); final String[] keywordsArray = new String[tok.countTokens()]; for (int i = 0; tok.hasMoreTokens(); i++) { keywordsArray[i] = tok.nextToken(); } module.setKeywords(keywordsArray); } final Element subtitle = element.getChild("subtitle", ns); if (subtitle != null) { module.setSubtitle(subtitle.getTextTrim()); } final Element summary = element.getChild("summary", ns); if (summary != null) { module.setSummary(summary.getTextTrim()); } } return module; }
From source file:com.rometools.modules.mediarss.io.MediaModuleParser.java
License:Open Source License
@Override public Module parse(final Element mmRoot, final Locale locale) { MediaModuleImpl mod = null;/*from w w w . ja v a 2s .co m*/ if (mmRoot.getName().equals("channel") || mmRoot.getName().equals("feed")) { mod = new MediaModuleImpl(); } else { mod = new MediaEntryModuleImpl(); } mod.setMetadata(parseMetadata(mmRoot)); mod.setPlayer(parsePlayer(mmRoot)); if (mod instanceof MediaEntryModuleImpl) { final MediaEntryModuleImpl m = (MediaEntryModuleImpl) mod; m.setMediaContents(parseContent(mmRoot)); m.setMediaGroups(parseGroup(mmRoot)); } return mod; }
From source file:com.rometools.modules.photocast.io.Generator.java
License:Open Source License
@Override public void generate(final Module module, final Element element) { if (!(module instanceof PhotocastModule)) { return;//from w w w . j a v a2s .co m } final PhotocastModule pm = (PhotocastModule) module; if (element.getName().equals("channel") || element.getName().equals("feed")) { element.addContent(generateSimpleElement("feedVersion", FEED_VERSION)); return; } element.addContent(generateSimpleElement("photoDate", Parser.PHOTO_DATE_FORMAT.format(pm.getPhotoDate()))); element.addContent(generateSimpleElement("cropDate", Parser.CROP_DATE_FORMAT.format(pm.getCropDate()))); element.addContent(generateSimpleElement("thumbnail", pm.getThumbnailUrl().toString())); element.addContent(generateSimpleElement("image", pm.getImageUrl().toString())); final Element e = new Element("metadata", NS); final Element pd = new Element("PhotoDate", ""); pd.addContent(pm.getMetadata().getPhotoDate().toString()); e.addContent(pd); final Element com = new Element("Comments", ""); com.addContent(pm.getMetadata().getComments()); e.addContent(com); element.addContent(e); }
From source file:com.rometools.modules.photocast.io.Parser.java
License:Open Source License
@Override public Module parse(final Element element, final Locale locale) { if (element.getName().equals("channel") || element.getName().equals("feed")) { return new PhotocastModuleImpl(); } else if (element.getChild("metadata", Parser.NS) == null && element.getChild("image", Parser.NS) == null) { return null; }// w w w. j a v a 2 s. c o m final PhotocastModule pm = new PhotocastModuleImpl(); final List<Element> children = element.getChildren(); final Iterator<Element> it = children.iterator(); while (it.hasNext()) { final Element e = it.next(); if (!e.getNamespace().equals(Parser.NS)) { continue; } if (e.getName().equals("photoDate")) { try { pm.setPhotoDate(Parser.PHOTO_DATE_FORMAT.parse(e.getText())); } catch (final Exception ex) { LOG.warn("Unable to parse photoDate: " + e.getText(), ex); } } else if (e.getName().equals("cropDate")) { try { pm.setCropDate(Parser.CROP_DATE_FORMAT.parse(e.getText())); } catch (final Exception ex) { LOG.warn("Unable to parse cropDate: " + e.getText(), ex); } } else if (e.getName().equals("thumbnail")) { try { pm.setThumbnailUrl(new URL(e.getText())); } catch (final Exception ex) { LOG.warn("Unable to parse thumnail: " + e.getText(), ex); } } else if (e.getName().equals("image")) { try { pm.setImageUrl(new URL(e.getText())); } catch (final Exception ex) { LOG.warn("Unable to parse image: " + e.getText(), ex); } } else if (e.getName().equals("metadata")) { String comments = ""; PhotoDate photoDate = null; if (e.getChildText("PhotoDate") != null) { try { photoDate = new PhotoDate(Double.parseDouble(e.getChildText("PhotoDate"))); } catch (final Exception ex) { LOG.warn("Unable to parse PhotoDate: " + e.getText(), ex); } } if (e.getChildText("Comments") != null) { comments = e.getChildText("Comments"); } pm.setMetadata(new Metadata(photoDate, comments)); } } return pm; }
From source file:com.rometools.opml.io.impl.OPML10Parser.java
License:Apache License
/** * Inspects an XML Document (JDOM) to check if it can parse it. * <p>/*w w w .j a va 2 s . c o m*/ * 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(); if (e.getName().equals("opml") && (e.getChild("head") == null || e.getChild("head").getChild("docs") == null) && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { return true; } return false; }
From source file:com.rometools.opml.io.impl.OPML10Parser.java
License:Apache License
protected Outline parseOutline(final Element e, final boolean validate, final Locale locale) throws FeedException { if (!e.getName().equals("outline")) { throw new RuntimeException("Not an outline element."); }/*from w w w. java 2s .co m*/ final Outline outline = new Outline(); outline.setText(e.getAttributeValue("text")); outline.setType(e.getAttributeValue("type")); outline.setTitle(e.getAttributeValue("title")); final List<org.jdom2.Attribute> jAttributes = e.getAttributes(); final ArrayList<Attribute> attributes = new ArrayList<Attribute>(); for (int i = 0; i < jAttributes.size(); i++) { final org.jdom2.Attribute a = jAttributes.get(i); if (!a.getName().equals("isBreakpoint") && !a.getName().equals("isComment") && !a.getName().equals("title") && !a.getName().equals("text") && !a.getName().equals("type")) { attributes.add(new Attribute(a.getName(), a.getValue())); } } outline.setAttributes(attributes); try { outline.setBreakpoint(readBoolean(e.getAttributeValue("isBreakpoint"))); } catch (final Exception ex) { LOG.warn("Unable to parse isBreakpoint value", ex); if (validate) { throw new FeedException("Unable to parse isBreakpoint value", ex); } } try { outline.setComment(readBoolean(e.getAttributeValue("isComment"))); } catch (final Exception ex) { LOG.warn("Unable to parse isComment value", ex); if (validate) { throw new FeedException("Unable to parse isComment value", ex); } } final List<Element> children = e.getChildren("outline"); outline.setModules(parseItemModules(e, locale)); outline.setChildren(parseOutlines(children, validate, locale)); return outline; }
From source file:com.rometools.opml.io.impl.OPML20Parser.java
License:Apache License
/** * Inspects an XML Document (JDOM) to check if it can parse it. * <p>/*from www .java 2 s . c o m*/ * 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(); if (e.getName().equals("opml") && (e.getChild("head") != null && e.getChild("head").getChild("docs") != null || e.getAttributeValue("version") != null && e.getAttributeValue("version").equals("2.0") || e.getChild("head") != null && e.getChild("head").getChild("ownerId") != null)) { return true; } return false; }
From source file:com.rometools.rome.io.impl.OPML10Parser.java
License:Apache License
protected Outline parseOutline(final Element e, final boolean validate, final Locale locale) throws FeedException { if (!e.getName().equals("outline")) { throw new RuntimeException("Not an outline element."); }//from w ww .j a v a 2s.c om final Outline outline = new Outline(); outline.setText(e.getAttributeValue("text")); outline.setType(e.getAttributeValue("type")); outline.setTitle(e.getAttributeValue("title")); final List<org.jdom2.Attribute> jAttributes = e.getAttributes(); final ArrayList<Attribute> attributes = new ArrayList<Attribute>(); for (int i = 0; i < jAttributes.size(); i++) { final org.jdom2.Attribute a = jAttributes.get(i); if (!a.getName().equals("isBreakpoint") && !a.getName().equals("isComment") && !a.getName().equals("title") && !a.getName().equals("text") && !a.getName().equals("type")) { attributes.add(new Attribute(a.getName(), a.getValue())); } } outline.setAttributes(attributes); try { outline.setBreakpoint(readBoolean(e.getAttributeValue("isBreakpoint"))); } catch (final Exception ex) { if (validate) { throw new FeedException("Unable to parse isBreakpoint value", ex); } } try { outline.setComment(readBoolean(e.getAttributeValue("isComment"))); } catch (final Exception ex) { if (validate) { throw new FeedException("Unable to parse isComment value", ex); } } final List<Element> children = e.getChildren("outline"); outline.setModules(parseItemModules(e, locale)); outline.setChildren(parseOutlines(children, validate, locale)); return outline; }
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>/*from w w w.ja va 2 s . com*/ * 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.RSS090Generator.java
License:Open Source License
protected void checkNotNullAndLength(final Element parent, final String childName, final int minLen, final int maxLen) throws FeedException { final Element child = parent.getChild(childName, getFeedNamespace()); if (child == null) { throw new FeedException( "Invalid " + getType() + " feed, missing " + parent.getName() + " " + childName); }/*w w w. j a v a 2 s .c o m*/ checkLength(parent, childName, minLen, maxLen); }