List of usage examples for org.jdom2 Element getName
public String getName()
From source file:com.rometools.rome.io.impl.RSS090Generator.java
License:Open Source License
protected void checkLength(final Element parent, final String childName, final int minLen, final int maxLen) throws FeedException { final 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"); }// ww w . j a va 2s .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.rometools.rome.io.impl.RSS090Parser.java
License:Open Source License
/** * Parses an item element of an RSS document looking for item information. * <p/>//from ww w . jav a 2s.co 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(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = new Item(); final Element title = eItem.getChild("title", getRSSNamespace()); if (title != null) { item.setTitle(title.getText()); } final Element link = eItem.getChild("link", getRSSNamespace()); if (link != null) { item.setLink(link.getText()); item.setUri(link.getText()); } item.setModules(parseItemModules(eItem, locale)); final List<Element> 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 final Iterator<Element> iterator = foreignMarkup.iterator(); while (iterator.hasNext()) { final Element element = iterator.next(); final Namespace eNamespace = element.getNamespace(); final String eName = element.getName(); if (getContentNamespace().equals(eNamespace) && eName.equals("encoded")) { iterator.remove(); } } if (!foreignMarkup.isEmpty()) { item.setForeignMarkup(foreignMarkup); } return item; }
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.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()); }
From source file:com.sangupta.jerry.util.DomUtils.java
License:Apache License
/** * Returns the value of a given attribute for the given tagName amongst the * supplied foreign markup values./*w w w . j a v a2 s . c o m*/ * * @param tagName * the tag name to find * * @param attributeName * the attribute name to extract * * @param elements * list of elements to search in * * @return the value of the attribute if found, <code>null</code> otherwise */ public static String getTagAttribute(String tagName, String attributeName, List<Element> elements) { for (Element element : elements) { if (tagName.equals(element.getName())) { Attribute attribute = element.getAttribute(attributeName); if (attribute != null) { return attribute.getValue(); } } } return null; }
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 w w.j av a 2s . com * * @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; }
From source file:com.sangupta.jerry.util.DomUtils.java
License:Apache License
/** * Returns the value of the element with the given tagName amongst the * supplied foreign markup values./* ww w . ja v a2 s .c o m*/ * * @param tagName * the tag name to look for * * @param elements * the elements to search in * * @return list of all values that match the tag name * */ public static List<String> getTagValues(String tagName, List<Element> elements) { List<String> values = new ArrayList<String>(); for (Element element : elements) { if (tagName.equals(element.getName())) { values.add(element.getText()); } } return values; }
From source file:com.seleniumtests.util.squashta.TaScriptGenerator.java
License:Apache License
/** * Search for tests in TestNG files// w w w .j a v a 2s. com * @param path * @param application * @return */ public List<SquashTaTestDef> parseTestNgXml() { // look for feature file into data folder File dir = Paths.get(srcPath, "data", application, "testng").toFile(); if (!dir.exists()) { return new ArrayList<>(); } File[] testngFiles = dir.listFiles((d, filename) -> filename.endsWith(".xml")); List<SquashTaTestDef> testDefs = new ArrayList<>(); for (File testngFile : testngFiles) { Document doc; SAXBuilder sxb = new SAXBuilder(); sxb.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); try { doc = sxb.build(testngFile); } catch (Exception e) { logger.error(String.format("Fichier %s illisible: %s", testngFile, e.getMessage())); return testDefs; } Element suite = doc.getRootElement(); if (!"suite".equalsIgnoreCase(suite.getName())) { continue; } for (Element test : suite.getChildren("test")) { readTestTag(test, testDefs, testngFile); } } return testDefs; }
From source file:com.sun.syndication.io.impl.RSS090Generator.java
License:Open Source License
protected void checkNotNullAndLength(Element parent, String childName, int minLen, int maxLen) throws FeedException { Element child = parent.getChild(childName, getFeedNamespace()); if (child == null) { throw new FeedException( "Invalid " + getType() + " feed, missing " + parent.getName() + " " + childName); }//from w ww . ja v a 2 s . c o m checkLength(parent, childName, minLen, maxLen); }