List of usage examples for org.w3c.dom Attr getName
public String getName();
From source file:DomUtils.java
/** * Rename element.// w ww . j av a 2 s. c o m * @param element The element to be renamed. * @param replacementElement The tag name of the replacement element. * @param keepChildContent <code>true</code> if the target element's child content * is to be copied to the replacement element, false if not. Default <code>true</code>. * @param keepAttributes <code>true</code> if the target element's attributes * are to be copied to the replacement element, false if not. Default <code>true</code>. * @return The renamed element. */ public static Element renameElement(Element element, String replacementElement, boolean keepChildContent, boolean keepAttributes) { Element replacement = element.getOwnerDocument().createElement(replacementElement); if (keepChildContent) { DomUtils.copyChildNodes(element, replacement); } if (keepAttributes) { NamedNodeMap attributes = element.getAttributes(); int attributeCount = attributes.getLength(); for (int i = 0; i < attributeCount; i++) { Attr attribute = (Attr) attributes.item(i); replacement.setAttribute(attribute.getName(), attribute.getValue()); } } DomUtils.replaceNode(replacement, element); return replacement; }
From source file:org.jolokia.jvmagent.spring.config.ConfigBeanDefinitionParser.java
private Map<Object, Object> createConfigMap(NamedNodeMap attributes) { ManagedMap<Object, Object> map = new ManagedMap<Object, Object>(attributes.getLength()); map.setKeyTypeName("java.lang.String"); map.setValueTypeName("java.lang.String"); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); String name = attr.getName(); if (skipMap.contains(name)) { continue; }/* w ww .j a va 2 s. c om*/ Object key = new TypedStringValue(name, String.class); Object value = new TypedStringValue(attr.getValue(), String.class); map.put(key, value); } return map; }
From source file:net.di2e.ecdr.search.transform.atom.security.impl.XmlMetadataSecurityMarkingHandler.java
@Override public SecurityData getSecurityData(Metacard metacard) { String metadata = metacard.getMetadata(); if (StringUtils.isNotBlank(metadata)) { XPathHelper helper = new XPathHelper(metacard.getMetadata()); Document document = helper.getDocument(); NodeList nodeList = document.getElementsByTagNameNS("*", "security"); if (nodeList != null && nodeList.getLength() > 0) { Element element = (Element) nodeList.item(0); NamedNodeMap nodeNameMap = element.getAttributes(); int length = nodeNameMap.getLength(); Map<String, List<String>> securityProps = new HashMap<String, List<String>>(); String securityNamespace = null; for (int i = 0; i < length; i++) { Attr attr = (Attr) nodeNameMap.item(i); String value = attr.getValue(); if (!attr.getName().startsWith(XMLNS_PREFIX) && StringUtils.isNotBlank(value)) { securityProps.put(attr.getLocalName(), SecurityMarkingParser.getValues(value)); if (securityNamespace == null) { securityNamespace = attr.getNamespaceURI(); }/* www .j a v a 2 s . c o m*/ } } if (!securityProps.isEmpty()) { return new SecurityDataImpl(securityProps, securityNamespace); } } } return null; }
From source file:com.krawler.esp.utils.mime.MimeTypesReader.java
/** Read Element named magic. */ private void readMagic(Element element, MimeType mimeType) { // element.getValue(); String offset = null;// w w w .ja v a 2 s . c o m String content = null; String type = null; NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); if (attr.getName().equals("offset")) { offset = attr.getValue(); } else if (attr.getName().equals("type")) { type = attr.getValue(); } else if (attr.getName().equals("value")) { content = attr.getValue(); } } if ((offset != null) && (content != null)) { mimeType.addMagic(Integer.parseInt(offset), type, content); } }
From source file:edu.mayo.cts2.framework.core.xml.PatchedCastorMarshaller.java
protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException { Node node = domSource.getNode(); if (node != null && node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; Node parent = node.getParentNode(); while (parent != null) { NamedNodeMap atts = parent.getAttributes(); if (atts != null) { for (int i = 0, j = atts.getLength(); i < j; i++) { Attr att = (Attr) atts.item(i); if (XMLNS_NS.equals(att.getNamespaceURI())) { String name = att.getName(); String value = att.getValue(); if (!element.hasAttributeNS(XMLNS_NS, name)) { element.setAttributeNS(XMLNS_NS, name, value); }// ww w .ja v a 2 s .c o m } } } parent = parent.getParentNode(); } } return super.unmarshalDomSource(domSource); }
From source file:com.krawler.esp.utils.mime.MimeTypesReader.java
/** Read Element named mime-type. */ private MimeType readMimeType(Element element) { String name = null;/*from w ww . ja v a 2 s .c om*/ String description = null; MimeType type = null; NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); if (attr.getName().equals("name")) { name = attr.getValue(); } else if (attr.getName().equals("description")) { description = attr.getValue(); } } if ((name == null) || (name.trim().equals(""))) { return null; } try { type = new MimeType(name); } catch (MimeTypeException mte) { // Mime Type not valid... just ignore it if (logger.isInfoEnabled()) { logger.info(mte.toString() + " ... Ignoring!"); } return null; } type.setDescription(description); NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element nodeElement = (Element) node; if (nodeElement.getTagName().equals("ext")) { readExt(nodeElement, type); } else if (nodeElement.getTagName().equals("magic")) { readMagic(nodeElement, type); } } } return type; }
From source file:TreeDumper2.java
private void dumpAttributeNode(Attr node, String indent) { System.out.println(indent + "ATTRIBUTE " + node.getName() + "=\"" + node.getValue() + "\""); }
From source file:org.dozer.eclipse.plugin.sourcepage.hyperlink.DozerClassHyperlinkDetector.java
public boolean isLinkableAttr(Attr attr) { String attrName = attr.getName(); String ownerName = attr.getOwnerElement().getNodeName(); String parentName = attr.getOwnerElement().getParentNode().getNodeName(); if ("bean-factory".equals(attrName)) return true; else if ("field".equals(ownerName)) { if ("custom-converter".equals(attrName) || "custom-converter-id".equals(attrName)) return true; } else if ("field".equals(parentName)) { if ("set-method".equals(attrName) || "get-method".equals(attrName) || "map-set-method".equals(attrName) || "map-get-method".equals(attrName)) return true; }// w w w . j a v a 2 s. c om return false; }
From source file:com.cisco.dvbu.ps.common.adapters.config.AdapterConfig.java
private void parseAdapterCommon(Document doc) throws AdapterException { log.debug("Root element :" + doc.getDocumentElement().getNodeName()); XPath xpath = XPathFactory.newInstance().newXPath(); try {/*from w ww .j av a2 s . c om*/ Attr a = (Attr) xpath.evaluate(AdapterConstants.XPATH_CONFIG_VERSION, doc, XPathConstants.NODE); log.debug(a.getName() + ": " + a.getValue()); Element e = (Element) xpath.evaluate(AdapterConstants.XPATH_NAME, doc, XPathConstants.NODE); name = e.getTextContent(); log.debug(e.getNodeName() + ": " + e.getTextContent()); e = (Element) xpath.evaluate(AdapterConstants.XPATH_DESC, doc, XPathConstants.NODE); desc = e.getTextContent(); log.debug(e.getNodeName() + ": " + e.getTextContent()); e = (Element) xpath.evaluate(AdapterConstants.XPATH_CIS_VERSION, doc, XPathConstants.NODE); cisVersion = e.getTextContent(); log.debug(e.getNodeName() + ": " + e.getTextContent()); e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_RETRYATTMPTS, doc, XPathConstants.NODE); retryAttempts = (e != null && e.getTextContent() != null) ? Integer.parseInt(e.getTextContent()) : -1; log.debug("retryAttempts: " + retryAttempts); e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_MAXCLIENTS, doc, XPathConstants.NODE); maxClients = (e != null && e.getTextContent() != null) ? Integer.parseInt(e.getTextContent()) : -1; log.debug("maxclients: " + maxClients); e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_MINCLIENTS, doc, XPathConstants.NODE); minClients = (e != null && e.getTextContent() != null) ? Integer.parseInt(e.getTextContent()) : -1; log.debug("minclients: " + minClients); } catch (Exception e) { log.error("Configuration File Error! One or more mandatory configuration options are missing"); throw new AdapterException(302, "Configuration File Error! One or more mandatory configuration options are missing.", e); } }
From source file:jp.igapyon.selecrawler.SeleCrawlerWebContentAnalyzer.java
public void processFile(final File file, final String urlString) throws IOException { final List<String> anchorList = new ArrayList<String>(); final List<String> headList = new ArrayList<String>(); final List<String> scriptSrcList = new ArrayList<String>(); final String contents = FileUtils.readFileToString( new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_NORMAL), "UTF-8"); final Document document = SimpleMyXmlUtil.string2Document(contents); {//from w w w. j a va 2 s . c o m final String title = SimpleMyXmlUtil.getXPathString(document, "/html/head/title/text()"); if (title != null && title.trim().length() > 0) { headList.add("title: " + title); } } { final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "/html/head/meta"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleMeta = (Element) nodes.item(index); headList.add("meta:"); final NamedNodeMap nnm = eleMeta.getAttributes(); for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) { final Attr attr = (Attr) nnm.item(indexNnm); headList.add(" " + attr.getName() + " [" + attr.getValue() + "]"); } } } } { final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "/html/head/link"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleMeta = (Element) nodes.item(index); headList.add("link:"); final NamedNodeMap nnm = eleMeta.getAttributes(); for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) { final Attr attr = (Attr) nnm.item(indexNnm); headList.add(" " + attr.getName() + " [" + attr.getValue() + "]"); } } } } { // search anchor with href final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "//a"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleAnchor = (Element) nodes.item(index); String href = eleAnchor.getAttribute("href"); href = adjustAnchorUrl(href, urlString); if (href == null) { continue; } anchorList.add(href); } } } { // search script final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "//script"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleScript = (Element) nodes.item(index); String srcString = eleScript.getAttribute("src"); srcString = adjustAnchorUrl(srcString, urlString); if (srcString == null) { continue; } scriptSrcList.add(srcString); } } } { final File fileMetaAnchor = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_ANCHOR); FileUtils.writeLines(fileMetaAnchor, "UTF-8", anchorList); } { final File fileMetaHead = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_HEAD); FileUtils.writeLines(fileMetaHead, "UTF-8", headList); } { final File fileScriptSrc = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_SCRIPTSRC); FileUtils.writeLines(fileScriptSrc, "UTF-8", scriptSrcList); } }