List of usage examples for org.jdom2 Element getName
public String getName()
From source file:com.sun.syndication.io.impl.RSS090Generator.java
License:Open Source License
protected void checkLength(Element parent, String childName, int minLen, int maxLen) throws FeedException { Element child = parent.getChild(childName, getFeedNamespace()); if (child != null) { if (minLen > 0 && child.getText().length() < minLen) { throw new FeedException("Invalid " + getType() + " feed, " + parent.getName() + " " + childName + "short of " + minLen + " length"); }/* w ww . j a v a2 s . c o m*/ if (maxLen > -1 && child.getText().length() > maxLen) { throw new FeedException("Invalid " + getType() + " feed, " + parent.getName() + " " + childName + "exceeds " + maxLen + " length"); } } }
From source file:com.sun.syndication.io.impl.RSS090Parser.java
License:Open Source License
/** * Parses an item element of an RSS document looking for item information. * <p/>/*from w ww . java 2 s.c o m*/ * It reads title and link out of the 'item' element. * <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. */ protected Item parseItem(Element rssRoot, Element eItem) { Item item = new Item(); Element e = eItem.getChild("title", getRSSNamespace()); if (e != null) { item.setTitle(e.getText()); } e = eItem.getChild("link", getRSSNamespace()); if (e != null) { item.setLink(e.getText()); item.setUri(e.getText()); } item.setModules(parseItemModules(eItem)); List foreignMarkup = extractForeignMarkup(eItem, item, getRSSNamespace()); //content:encoded elements are treated special, without a module, they have to be removed from the foreign //markup to avoid duplication in case of read/write. Note that this fix will break if a content module is //used Iterator iterator = foreignMarkup.iterator(); while (iterator.hasNext()) { Element ie = (Element) iterator.next(); if (getContentNamespace().equals(ie.getNamespace()) && ie.getName().equals("encoded")) { iterator.remove(); } } if (foreignMarkup.size() > 0) { item.setForeignMarkup(foreignMarkup); } return item; }
From source file:com.sun.syndication.io.impl.RSS091NetscapeParser.java
License:Open Source License
public boolean isMyType(Document document) { boolean ok = false; Element rssRoot = document.getRootElement(); ok = rssRoot.getName().equals("rss"); if (ok) {/*from w w w . j a v a 2 s . c o m*/ ok = false; Attribute version = rssRoot.getAttribute("version"); if (version != null) { ok = version.getValue().equals(getRSSVersion()); if (ok) { ok = false; DocType docType = document.getDocType(); if (docType != null) { ok = ELEMENT_NAME.equals(docType.getElementName()); ok = ok && PUBLIC_ID.equals(docType.getPublicID()); ok = ok && SYSTEM_ID.equals(docType.getSystemID()); } } } } return ok; }
From source file:com.sun.syndication.io.impl.RSS091UserlandParser.java
License:Open Source License
public boolean isMyType(Document document) { boolean ok;/*from w w w. j a v a 2s . c o m*/ Element rssRoot = document.getRootElement(); ok = rssRoot.getName().equals("rss"); if (ok) { ok = false; Attribute version = rssRoot.getAttribute("version"); if (version != null) { ok = version.getValue().equals(getRSSVersion()); } } return ok; }
From source file:com.sun.syndication.io.impl.RSS20Parser.java
License:Open Source License
public boolean isMyType(Document document) { boolean ok;// w w w .j a va 2 s. com Element rssRoot = document.getRootElement(); ok = rssRoot.getName().equals("rss"); if (ok) { ok = false; Attribute version = rssRoot.getAttribute("version"); if (version != null) { // At this point, 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. ok = version.getValue().startsWith(getRSSVersion()); } } return ok; }
From source file:com.swordlord.gozer.builder.Parser.java
License:Open Source License
@SuppressWarnings("unchecked") private void parseElement(Element element, ObjectBase parent) { if (!_objectTags.containsKey(element.getName())) { String msg = MessageFormat.format("Element {0} unknown, parsing aborted.", element.getName()); LOG.error(msg);// www .j a v a2s . c o m return; } ObjectBase ob = instantiateClass(_objectTags.get(element.getName())); if (ob == null) { String msg = MessageFormat.format("Class for {0} could not be instantiated, parsing aborted.", element); LOG.error(msg); return; } if (element.getText() != null) { ob.setContent(element.getText()); } List attributes = element.getAttributes(); Iterator itAttributes = attributes.iterator(); while (itAttributes.hasNext()) { Attribute attr = (Attribute) itAttributes.next(); ob.putAttribute(attr.getName(), attr.getValue()); } if (parent != null) { ob.inheritParent(parent); parent.putChild(ob); } else { _objectTree.setRoot(ob); } List children = element.getChildren(); Iterator itChildren = children.iterator(); while (itChildren.hasNext()) { parseElement((Element) itChildren.next(), ob); } }
From source file:com.tactfactory.harmony.utils.XMLUtils.java
License:Open Source License
/** * Find a node in the given node./*from w ww .j a v a2 s. co m*/ * @param baseNode The node in whom to search. * @param newNode The node to search. * @param id The attribute name used for the comparison * @return The found node or null if the node doesn't exists */ public static Element findNode(final Element baseNode, final Element newNode, final String id) { Element result = null; final List<Element> nodes = baseNode.getChildren(newNode.getName()); // Look in the children nodes if one node // has the corresponding key/value couple for (final Element node : nodes) { if (node.hasAttributes() && node.getAttributeValue(id).equals(newNode.getAttributeValue(id))) { result = node; } } return result; }
From source file:com.thoughtworks.go.config.GoConfigFieldWriter.java
License:Apache License
@SuppressWarnings("unchecked") private Collection parseCollection(Element e, Class<?> collectionType) { ConfigCollection collection = collectionType.getAnnotation(ConfigCollection.class); Class<?> type = collection.value(); Object o = newInstance(collectionType); bombUnless(o instanceof Collection, "Must be some sort of list. Was: " + collectionType.getName()); Collection baseCollection = (Collection) o; for (Element childElement : (List<Element>) e.getChildren()) { if (isInCollection(childElement, type)) { baseCollection.add(parseType(childElement, type)); }/*w w w . ja v a2 s .c om*/ } bombIf(baseCollection.size() < collection.minimum(), "Required at least " + collection.minimum() + " subelements to '" + e.getName() + "'. " + "Found " + baseCollection.size() + "."); return baseCollection; }
From source file:com.thoughtworks.go.config.GoConfigFieldWriter.java
License:Apache License
private boolean isInCollection(Element e, Class<?> type) { if (type.isInterface() && type.isAnnotationPresent(ConfigInterface.class)) { for (Class<?> implementation : registry.implementersOf(type)) { if (configTag(implementation).equals(e.getName())) { return true; }/* w w w .j av a 2s. c o m*/ } } return configTag(type).equals(e.getName()); }
From source file:com.thoughtworks.go.config.GoConfigFieldWriter.java
License:Apache License
private Class<?> typeToGenerate(Element e, Class<?> type) { if (type.isInterface() && type.isAnnotationPresent(ConfigInterface.class)) { for (Class<?> implementation : registry.implementersOf(type)) { if (configTag(implementation).equals(e.getName())) { return implementation; }// w w w .j a v a2 s .c om } } else { if (configTag(type).equals(e.getName())) { return type; } } throw bomb("Unable to determine type to generate.\n" + "Type: " + type.getName() + "\n" + "Element: " + configUtil.elementOutput(e)); }