List of usage examples for org.w3c.dom Element hasAttribute
public boolean hasAttribute(String name);
true
when an attribute with a given name is specified on this element or has a default value, false
otherwise. From source file:cz.incad.kramerius.rest.api.k5.client.utils.SOLRUtils.java
public static <T> List<T> array(final Element doc, final String attributeName, Class<T> clz) { synchronized (doc.getOwnerDocument()) { List<T> ret = new ArrayList<T>(); List<Element> elms = XMLUtils.getElements(doc, new XMLUtils.ElementsFilter() { @Override/*from w w w.j av a2 s . c om*/ public boolean acceptElement(Element element) { return (element.getNodeName().equals("arr") && element.hasAttribute("name") && element.getAttribute("name").equals(attributeName)); } }); for (Element e : elms) { ret.add(value(e.getTextContent(), clz)); } return ret; } }
From source file:cz.incad.kramerius.rest.api.k5.client.utils.SOLRUtils.java
public static <T> List<T> narray(final Element doc, final String attributeName, Class<T> clz) { synchronized (doc.getOwnerDocument()) { List<T> ret = new ArrayList<T>(); List<Element> elms = XMLUtils.getElements(doc, new XMLUtils.ElementsFilter() { @Override// ww w . java 2 s . c o m public boolean acceptElement(Element element) { return (element.getNodeName().equals("arr") && element.hasAttribute("name") && element.getAttribute("name").equals(attributeName)); } }); if (elms.size() >= 1) { Element parentE = elms.get(0); NodeList chnds = parentE.getChildNodes(); for (int i = 0, ll = chnds.getLength(); i < ll; i++) { Node n = chnds.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { ret.add(value(n.getTextContent(), clz)); } } } return ret; } }
From source file:com.evolveum.midpoint.util.UglyHacks.java
public static void unfortifyNamespaceDeclarationsSingleElement(Element element) { String fortifiedXmlnss = element.getAttribute(FORTIFIED_NAMESPACE_DECLARATIONS_ELEMENT_NAME); if (element.hasAttribute(FORTIFIED_NAMESPACE_DECLARATIONS_ELEMENT_NAME)) { element.removeAttribute(FORTIFIED_NAMESPACE_DECLARATIONS_ELEMENT_NAME); }//from w w w .j av a2s . c om if (StringUtils.isBlank(fortifiedXmlnss)) { return; } String[] xmlnss = StringUtils.split(fortifiedXmlnss, FORTIFIED_NAMESPACE_DECLARATIONS_SEPARATOR); for (String xmlns : xmlnss) { String[] prefixAndUrl = StringUtils.split(xmlns, "=", 2); String prefix = prefixAndUrl[0]; String url = prefixAndUrl[1]; if (!DOMUtil.hasNamespaceDeclarationForPrefix(element, prefix)) { DOMUtil.setNamespaceDeclaration(element, prefix, url); } } }
From source file:Main.java
public static Element findElementWithAttributes(Node node, String tagName, Collection<String> attrs) { Element result = null;/* w w w . j a v a2 s . c o m*/ NodeList nodeList = node.getChildNodes(); if (nodeList == null) { return result; } for (int i = 0; i < nodeList.getLength(); ++i) { Element element = checkIfElement(nodeList.item(i), tagName); if (element != null) { boolean match = true; for (String attrName : attrs) { if (!element.hasAttribute(attrName)) { match = false; break; } } if (match) { result = element; break; } } } return result; }
From source file:cz.incad.kramerius.rest.api.k5.client.utils.SOLRUtils.java
public static <T> T value(final Element doc, final String attributeName, Class<T> clz) { if (doc == null) { throw new IllegalArgumentException("element must not be null"); }/*from w w w. java2 s . com*/ synchronized (doc.getOwnerDocument()) { final String expectedTypeName = SOLR_TYPE_NAMES.get(clz); List<Element> elms = XMLUtils.getElements(doc, new XMLUtils.ElementsFilter() { @Override public boolean acceptElement(Element element) { return (element.getNodeName().equals(expectedTypeName) && element.hasAttribute("name") && element.getAttribute("name").equals(attributeName)); } }); Object obj = elms.isEmpty() ? null : elms.get(0).getTextContent(); if (obj != null) return value(obj.toString(), clz); else return null; } }
From source file:biz.webgate.tools.urlfetcher.URLFetcher.java
private static void check4OpenGraphTags(NodeList ndlMeta, PageAnalyse analyse) { for (int nCounter = 0; nCounter < ndlMeta.getLength(); nCounter++) { Element elMeta = (Element) ndlMeta.item(nCounter); // Test if property is available if (elMeta.hasAttribute("property")) { String strProperty = elMeta.getAttribute("property"); // CHECK if we have a OpenGraphProperty if (strProperty.toLowerCase().startsWith("og:")) { analyse.addOpenGraph(strProperty, elMeta.getAttribute("content")); }/*from w w w.j a v a2 s.c o m*/ if ("og:image".equalsIgnoreCase(strProperty)) { analyse.addImageURL(elMeta.getAttribute("content")); } if ("og:title".equalsIgnoreCase(strProperty)) { analyse.setTitle(elMeta.getAttribute("content")); } if ("og:description".equalsIgnoreCase(strProperty)) { analyse.setDescription(elMeta.getAttribute("content")); } } } }
From source file:biz.webgate.tools.urlfetcher.URLFetcher.java
private static String calculateImageHeighBased(NodeList ndlImage, int maxPictureHeigh, Element elCurrent) { String strImage = elCurrent.getAttribute("src"); if (ndlImage.getLength() > 20 && elCurrent.hasAttribute("height")) { String strHeight = elCurrent.getAttribute("height"); strHeight = strHeight.replace("px", ""); try {/*w w w. ja v a 2 s . co m*/ int nHeight = Integer.parseInt(strHeight); if (nHeight > maxPictureHeigh) { strImage = null; } } catch (Exception e) { // TODO:handle exception } } return strImage; }
From source file:org.apache.ftpserver.config.spring.SpringUtil.java
/** * Return the string value of an attribute, or null if the attribute is * missing//from ww w . j av a2 s. c o m * * @param parent * The element * @param attrName * The attribute name * @return The attribute string value */ public static String parseString(final Element parent, final String attrName) { if (parent.hasAttribute(attrName)) { return parent.getAttribute(attrName); } else { return null; } }
From source file:fll.xml.XMLUtils.java
/** * Get the winner criteria for a particular element. */// www. ja v a 2 s .c o m public static WinnerType getWinnerCriteria(final Element element) { if (element.hasAttribute("winner")) { final String str = element.getAttribute("winner"); final String sortStr; if (!str.isEmpty()) { sortStr = str.toUpperCase(); } else { sortStr = "HIGH"; } return Enum.valueOf(WinnerType.class, sortStr); } else { return WinnerType.HIGH; } }
From source file:fll.xml.XMLUtils.java
/** * Get the score type for a particular element. *///from ww w .j a va 2 s .com public static ScoreType getScoreType(final Element element) { if (element.hasAttribute("scoreType")) { final String str = element.getAttribute("scoreType"); final String sortStr; if (!str.isEmpty()) { sortStr = str.toUpperCase(); } else { sortStr = "INTEGER"; } return Enum.valueOf(ScoreType.class, sortStr); } else { return ScoreType.INTEGER; } }