List of usage examples for org.jdom2 Element getText
public String getText()
From source file:com.rometools.rome.io.impl.RSS091UserlandParser.java
License:Open Source License
protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { final Description desc = new Description(); desc.setType("text/plain"); desc.setValue(eDesc.getText()); return desc;/*from www .j av a 2 s . c o m*/ }
From source file:com.rometools.rome.io.impl.RSS092Parser.java
License:Open Source License
@Override protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = super.parseItem(rssRoot, eItem, locale); final Element eSource = eItem.getChild("source", getRSSNamespace()); if (eSource != null) { final Source source = new Source(); // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String url = eSource.getAttributeValue("url"); source.setUrl(url);//from ww w. j ava 2 s . co m source.setValue(eSource.getText()); item.setSource(source); } // 0.92 allows one enclosure occurrence, 0.93 multiple just saving to write some code. // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final List<Element> eEnclosures = eItem.getChildren("enclosure"); if (!eEnclosures.isEmpty()) { final List<Enclosure> enclosures = new ArrayList<Enclosure>(); for (final Element eEnclosure : eEnclosures) { final Enclosure enclosure = new Enclosure(); // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String url = eEnclosure.getAttributeValue("url"); if (url != null) { enclosure.setUrl(url); } // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String length = eEnclosure.getAttributeValue("length"); enclosure.setLength(NumberParser.parseLong(length, 0L)); // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String type = eEnclosure.getAttributeValue("type"); if (type != null) { enclosure.setType(type); } enclosures.add(enclosure); } item.setEnclosures(enclosures); } // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final List<Element> categories = eItem.getChildren("category"); item.setCategories(parseCategories(categories)); return item; }
From source file:com.rometools.rome.io.impl.RSS092Parser.java
License:Open Source License
protected List<Category> parseCategories(final List<Element> eCats) { List<Category> cats = null; if (!eCats.isEmpty()) { cats = new ArrayList<Category>(); for (final Element eCat : eCats) { final Category cat = new Category(); // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String domain = eCat.getAttributeValue("domain"); if (domain != null) { cat.setDomain(domain);// w ww.j a v a 2s . c om } cat.setValue(eCat.getText()); cats.add(cat); } } return cats; }
From source file:com.rometools.rome.io.impl.RSS093Parser.java
License:Open Source License
@Override protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = super.parseItem(rssRoot, eItem, locale); final Element pubDate = eItem.getChild("pubDate", getRSSNamespace()); if (pubDate != null) { item.setPubDate(DateParser.parseDate(pubDate.getText(), locale)); }/*from w w w . j a v a 2 s. c o m*/ final Element expirationDate = eItem.getChild("expirationDate", getRSSNamespace()); if (expirationDate != null) { item.setExpirationDate(DateParser.parseDate(expirationDate.getText(), locale)); } final Element description = eItem.getChild("description", getRSSNamespace()); if (description != null) { final String type = description.getAttributeValue("type"); if (type != null) { item.getDescription().setType(type); } } return item; }
From source file:com.rometools.rome.io.impl.RSS094Parser.java
License:Open Source License
@Override protected WireFeed parseChannel(final Element rssRoot, final Locale locale) { final Channel channel = (Channel) super.parseChannel(rssRoot, locale); final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); final List<Element> categories = eChannel.getChildren("category", getRSSNamespace()); channel.setCategories(parseCategories(categories)); final Element ttl = eChannel.getChild("ttl", getRSSNamespace()); if (ttl != null && ttl.getText() != null) { final Integer ttlValue = NumberParser.parseInt(ttl.getText()); if (ttlValue != null) { channel.setTtl(ttlValue);/*from ww w . ja va2 s. co m*/ } } return channel; }
From source file:com.rometools.rome.io.impl.RSS094Parser.java
License:Open Source License
@Override public Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = super.parseItem(rssRoot, eItem, locale); item.setExpirationDate(null);/*w w w. j a v a 2s . c o m*/ final Element author = eItem.getChild("author", getRSSNamespace()); if (author != null) { item.setAuthor(author.getText()); } final Element eGuid = eItem.getChild("guid", getRSSNamespace()); if (eGuid != null) { final Guid guid = new Guid(); // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String att = eGuid.getAttributeValue("isPermaLink"); if (att != null) { guid.setPermaLink(att.equalsIgnoreCase("true")); } guid.setValue(eGuid.getText()); item.setGuid(guid); } final Element comments = eItem.getChild("comments", getRSSNamespace()); if (comments != null) { item.setComments(comments.getText()); } return item; }
From source file:com.rometools.rome.io.impl.RSS10Parser.java
License:Open Source License
/** * Parses an item element of an RSS document looking for item information. * <p/>// w w w .ja v a 2 s . c om * It first invokes super.parseItem and then parses and injects the description property if * present. * <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. */ @Override protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = super.parseItem(rssRoot, eItem, locale); final Element description = eItem.getChild("description", getRSSNamespace()); if (description != null) { item.setDescription(parseItemDescription(rssRoot, description)); } final Element encoded = eItem.getChild("encoded", getContentNamespace()); if (encoded != null) { final Content content = new Content(); content.setType(Content.HTML); content.setValue(encoded.getText()); item.setContent(content); } final String about = eItem.getAttributeValue("about", getRDFNamespace()); if (about != null) { item.setUri(about); } return item; }
From source file:com.rometools.rome.io.impl.SyModuleParser.java
License:Open Source License
@Override public Module parse(final Element syndRoot, final Locale locale) { boolean foundSomething = false; final SyModule sm = new SyModuleImpl(); final Element updatePeriod = syndRoot.getChild("updatePeriod", getDCNamespace()); if (updatePeriod != null) { foundSomething = true;/*from w w w . j a v a2s . c o m*/ sm.setUpdatePeriod(updatePeriod.getText().trim()); } final Element updateFrequency = syndRoot.getChild("updateFrequency", getDCNamespace()); if (updateFrequency != null) { foundSomething = true; sm.setUpdateFrequency(Integer.parseInt(updateFrequency.getText().trim())); } final Element updateBase = syndRoot.getChild("updateBase", getDCNamespace()); if (updateBase != null) { foundSomething = true; sm.setUpdateBase(DateParser.parseDate(updateBase.getText(), locale)); } if (foundSomething) { return sm; } else { return null; } }
From source file:com.s13g.themetools.keystyler.controller.ThemeLoader.java
License:Apache License
/** * Parses the ZIP file and the skins.xml therein to produce the final Theme model file. * * @param themeFile the file that contains the theme. * @param skinsXml the skinsXML stream that contains the skin specification. * @return The valid Theme model, if the file could be parses, null otherwise. * @throws JDOMException if the skins.xml cannot be parsed. * @throws IOException if the theme file could not be read, *///w w w . j a v a 2s. c o m private static Theme parse(File themeFile, InputStream skinsXml) throws JDOMException, IOException { Document document = sSaxBuilder.build(skinsXml); if (document == null) { System.err.println("Could not get document - " + themeFile.getAbsolutePath()); return null; } Element root = document.getRootElement(); if (root == null) { System.err.println("Could not get root element - " + themeFile.getAbsolutePath()); return null; } String name = root.getAttributeValue("name"); ThemeStyle style = new ThemeStyle(); Element background = root.getChild("background"); Element backgroundImage = background.getChild("image"); // NOTE: According to the example, background can also have two colors defined instead of an // image. This currently does not support such themes. So we simply don't supply a background; if (backgroundImage != null) { style.setItemName(Entry.BACKGROUND_IMAGE, backgroundImage.getText()); } else { System.err.println("Theme does not have background/image. Skipping."); } Element keyBackground = root.getChild("key-background"); style.setItemName(Entry.KEY_BACKGROUND_NORMAL, keyBackground.getChildText("normal")); style.setItemName(Entry.KEY_BACKGROUND_PRESSED, keyBackground.getChildText("pressed")); Element modKeyBackground = root.getChild("mod-key-background"); style.setItemName(Entry.MOD_KEY_BACKGROUND_NORMAL, modKeyBackground.getChildText("normal")); style.setItemName(Entry.MOD_KEY_BACKGROUND_PRESSED, modKeyBackground.getChildText("pressed")); style.setItemName(Entry.MOD_KEY_BACKGROUND_NORMAL_OFF, modKeyBackground.getChildText("normal-off")); style.setItemName(Entry.MOD_KEY_BACKGROUND_PRESSED_OFF, modKeyBackground.getChildText("pressed-off")); style.setItemName(Entry.MOD_KEY_BACKGROUND_NORMAL_ON, modKeyBackground.getChildText("normal-on")); style.setItemName(Entry.MOD_KEY_BACKGROUND_PRESSED_ON, modKeyBackground.getChildText("pressed-on")); Element symbols = root.getChild("symbols"); style.setItemName(Entry.SYMBOLS_DELETE, symbols.getChildText("delete")); style.setItemName(Entry.SYMBOLS_RETURN, symbols.getChildText("return")); style.setItemName(Entry.SYMBOLS_SEARCH, symbols.getChildText("search")); style.setItemName(Entry.SYMBOLS_SHIFT, symbols.getChildText("shift")); style.setItemName(Entry.SYMBOLS_SHIFT_LOCKED, symbols.getChildText("shift-locked")); style.setItemName(Entry.SYMBOLS_SPACE, symbols.getChildText("space")); style.setItemName(Entry.SYMBOLS_MIC, symbols.getChildText("mic")); Element colors = root.getChild("colors"); style.setItemName(Entry.COLORS_LABEL, colors.getChildText("label")); style.setItemName(Entry.COLORS_ALT_LABEL, colors.getChildText("alt-label")); style.setItemName(Entry.COLORS_MOD_LABEL, colors.getChildText("mod-label")); return new Theme(name, themeFile, style); }
From source file:com.sangupta.jerry.util.DomUtils.java
License:Apache License
/** * Returns the value of the element with the given tagName, where the * supplied attribute matches the supplied attribute value in the supplied * foreign markup values.//from w ww . j a v a 2 s. c o m * * @param tagName * the tag to search for * * @param attributeName * the attribute name to look for * * @param attributeValue * the attribute value to look for * * @param elements * the elements to search in * * @return all the values of the attributes which have matched * */ public static List<String> getTagValues(String tagName, String attributeName, String attributeValue, List<Element> elements) { List<String> values = new ArrayList<String>(); for (Element element : elements) { if (tagName.equals(element.getName())) { String value = element.getAttribute(attributeName).getValue(); if (attributeValue.equals(value)) { values.add(element.getText()); } } } return values; }