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:Main.java
public static Element findElementWithAttribute(Node node, String tagName, String attrName) { Element result = null;/*w w w.j a va 2s .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 && element.hasAttribute(attrName)) { result = element; break; } } return result; }
From source file:Main.java
/** * /*from w w w.j a va 2 s. co m*/ * @param context * @param element */ public static void recursiveIdBrowse(DOMValidateContext context, Element element) { for (int i = 0; i < element.getChildNodes().getLength(); i++) { Node node = element.getChildNodes().item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element childEl = (Element) node; String ID_ATTRIBUTE_NAME = "Id"; if (childEl.hasAttribute(ID_ATTRIBUTE_NAME)) { context.setIdAttributeNS(childEl, null, ID_ATTRIBUTE_NAME); } recursiveIdBrowse(context, childEl); } } }
From source file:com.flipkart.phantom.runtime.impl.spring.utils.ConfigFileUtils.java
/** * Gets the task handler names from Config file * @param configFile job config file contents as a <code> ByteArrayResource </code> * @return List of task handler names, null if unable to find a TaskHandler name. *//*from w w w. jav a 2s . c o m*/ public static List<String> getHandlerNames(ByteArrayResource configFile) { List<String> jobNameList = new LinkedList<String>(); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document dom = db.parse(configFile.getInputStream()); Element docEle = dom.getDocumentElement(); //get a nodelist of nodes with the name "ConfigFileUtils.BATCH_JOB_TAG" NodeList nl = docEle.getElementsByTagName(ConfigFileUtils.BATCH_JOB_TAG); //Loop over all found nodes if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { //get the element Element el = (Element) nl.item(i); if (el.hasAttribute(ConfigFileUtils.ID_PROP)) { jobNameList.add(el.getAttribute(ConfigFileUtils.ID_PROP)); } } } } catch (Exception e) { LOGGER.error("Unable to get the job name from the given Spring Batch configuration file", e); throw new PlatformException(e); } return jobNameList; }
From source file:Main.java
public static Element getElementByAttr(NodeList elements, String attrName) throws Exception { Element element = null; for (int i = 0; i < elements.getLength(); i++) { element = (Element) elements.item(i); if (element.hasAttribute(attrName)) break; }/*from ww w . j a v a2 s . c om*/ return element; }
From source file:org.trpr.platform.batch.common.utils.ConfigFileUtils.java
/** * Gets the job names from Config file//w ww.ja v a2s .c om * @param configFile job config file contents as a <code> ByteArrayResource </code> * @return List of job names, null if unable to find a job name. */ public static List<String> getJobName(ByteArrayResource configFile) { List<String> jobNameList = new LinkedList<String>(); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document dom = db.parse(configFile.getInputStream()); Element docEle = dom.getDocumentElement(); //get a nodelist of nodes with the name "ConfigFileUtils.BATCH_JOB_TAG" NodeList nl = docEle.getElementsByTagName(ConfigFileUtils.BATCH_JOB_TAG); //Loop over all found nodes if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { //get the element Element el = (Element) nl.item(i); if (el.hasAttribute(ConfigFileUtils.ID_PROP)) { jobNameList.add(el.getAttribute(ConfigFileUtils.ID_PROP)); } } } } catch (Exception e) { LOGGER.error("Unable to get the job name from the given Spring Batch configuration file", e); throw new PlatformException(e); } return jobNameList; }
From source file:Main.java
License:asdf
public static void dom(Element element) { element.setAttribute("newAttrName", "attrValue"); element.setAttribute("newAttrName", "<>&\"'"); element.removeAttribute("value"); boolean has = element.hasAttribute("value"); // true System.out.println(has);/*www .j a va 2s . com*/ String attrValue = element.getAttribute("value"); // mydefault System.out.println(attrValue); }
From source file:Main.java
public static void copyAttr(Element from, Element to) { NamedNodeMap nnm = from.getAttributes(); for (int i = 0; i < nnm.getLength(); ++i) { String name = nnm.item(i).getNodeName(); if (!to.hasAttribute(name)) { String value = nnm.item(i).getNodeValue(); to.setAttribute(name, value); }/*from w w w .j a v a 2 s . c om*/ } }
From source file:org.jboss.windup.config.spring.namespace.java.SpringNamespaceHandlerUtil.java
public static void setNestedList(BeanDefinitionBuilder beanBuilder, Element bean, String nestedTagName, ParserContext context) {/*from ww w .jav a 2 s .c o m*/ BeanDefinition beanDef = beanBuilder.getRawBeanDefinition(); Element test = XmlElementUtil.getChildByTagName(bean, nestedTagName); if (test != null) { if (test.hasAttribute("ref")) { beanBuilder.addPropertyReference(nestedTagName, test.getAttribute("ref")); return; } } Element nestElement = XmlElementUtil.getChildByTagName(bean, nestedTagName); if (nestElement != null) { ManagedList<BeanDefinition> nested = SpringNamespaceHandlerUtil.parseManagedList(beanDef, XmlElementUtil.getChildElements(nestElement), context); beanBuilder.addPropertyValue(nestedTagName, nested); } }
From source file:biz.webgate.tools.urlfetcher.URLFetcher.java
public static void checkImage(PageAnalyse analyse, NodeList ndlImage, int maxPictureHeigh) { for (int nCounter = 0; nCounter < ndlImage.getLength(); nCounter++) { Element elCurrent = (Element) ndlImage.item(nCounter); if (elCurrent.hasAttribute("src")) { String strImage = calculateImageHeighBased(ndlImage, maxPictureHeigh, elCurrent); if (strImage != null) { analyse.addImageURL(strImage); }// w w w .java 2 s . c o m } } }
From source file:Main.java
/** * * @param element/*from www. j a v a2 s . c o m*/ * @param attributeName * @param matches */ private static void removeAttributeLoopElement(Element element, String attributeName, String... matches) { if (element.hasAttribute(attributeName)) { if (matches(element.getTagName(), matches)) { element.removeAttribute(attributeName); } } NodeList nodeList = element.getChildNodes(); int length = nodeList.getLength(); for (int seq = 0; seq < length; seq++) { Node node = nodeList.item(seq); if (node.getNodeType() == Node.ELEMENT_NODE) { if (element.hasAttribute(attributeName)) { if (matches(element.getTagName(), matches)) { removeAttributeLoopElement((Element) node, attributeName, matches); } } } } }