List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:com.rometools.opml.io.impl.OPML20Parser.java
License:Apache License
@Override protected Outline parseOutline(final Element e, final boolean validate, final Locale locale) throws FeedException { Outline retValue;//from w w w .j a v a2 s.c o m retValue = super.parseOutline(e, validate, locale); if (e.getAttributeValue("created") != null) { retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"), locale)); } final List<Attribute> atts = retValue.getAttributes(); for (int i = 0; i < atts.size(); i++) { final Attribute a = atts.get(i); if (a.getName().equals("created")) { retValue.getAttributes().remove(a); break; } } return retValue; }
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."); }// ww w . ja va 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) { 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 . j ava 2s .co 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(); 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.RSS092Parser.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 Element eCloud = eChannel.getChild("cloud", getRSSNamespace()); if (eCloud != null) { final Cloud cloud = new Cloud(); final String domain = eCloud.getAttributeValue("domain"); if (domain != null) { cloud.setDomain(domain);//from w ww. java2 s . com } // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String port = eCloud.getAttributeValue("port"); if (port != null) { cloud.setPort(Integer.parseInt(port.trim())); } // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String path = eCloud.getAttributeValue("path"); if (path != null) { cloud.setPath(path); } // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String registerProcedure = eCloud.getAttributeValue("registerProcedure"); if (registerProcedure != null) { cloud.setRegisterProcedure(registerProcedure); } // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String protocol = eCloud.getAttributeValue("protocol"); if (protocol != null) { cloud.setProtocol(protocol); } channel.setCloud(cloud); } return channel; }
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 w w w . jav a 2 s .c o 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 w w . j a v a 2 s. com } cat.setValue(eCat.getText()); cats.add(cat); } } return cats; }
From source file:com.rometools.rome.io.impl.RSS092Parser.java
License:Open Source License
@Override protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { final Description desc = new Description(); final StringBuilder sb = new StringBuilder(); final XMLOutputter xmlOut = new XMLOutputter(); for (final Content c : eDesc.getContent()) { switch (c.getCType()) { case Text: case CDATA: sb.append(c.getValue());// w ww . j ava 2 s . com break; case EntityRef: LOG.debug("Entity: {}", c.getValue()); sb.append(c.getValue()); break; case Element: sb.append(xmlOut.outputString((Element) c)); break; default: // ignore break; } } desc.setValue(sb.toString()); String att = eDesc.getAttributeValue("type"); if (att == null) { att = "text/html"; } desc.setType(att); return desc; }
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)); }/* w w w . j a va2 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 public Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = super.parseItem(rssRoot, eItem, locale); item.setExpirationDate(null);// w ww . jav 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.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, *///from w w w .j a v a 2 s . com 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); }