List of usage examples for org.w3c.dom Attr getValue
public String getValue();
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 {/* w ww.j a v 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:com.doculibre.constellio.feedprotocol.parse.xml.FeedParser.java
private String getAttrValueIfPresent(Element elementName, String attributeName) { String value = null;/*from ww w .jav a2 s . c o m*/ Attr attr = elementName.getAttributeNode(attributeName); if (attr != null && attr.getSpecified()) { value = attr.getValue(); } return value; }
From source file:com.predic8.membrane.annot.parser.BlueprintElementParser.java
protected void setProperties(ParserContext context, String springPropertyName, Element element, MutableBeanMetadata mcm) {//from ww w . j ava2 s . c o m NamedNodeMap attributes = element.getAttributes(); HashMap<String, String> attrs = new HashMap<String, String>(); for (int i = 0; i < attributes.getLength(); i++) { Attr item = (Attr) attributes.item(i); if (item.getLocalName() != null) attrs.put(item.getLocalName(), item.getValue()); } MutablePassThroughMetadata pt = context.createMetadata(MutablePassThroughMetadata.class); pt.setObject(attrs); mcm.addProperty(springPropertyName, pt); }
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; }//from w w w . j av a2 s.c o m Object key = new TypedStringValue(name, String.class); Object value = new TypedStringValue(attr.getValue(), String.class); map.put(key, value); } return map; }
From source file:org.solmix.runtime.support.spring.AbstractBeanDefinitionParser.java
/**?Element,?Container*/ protected boolean parseAttributes(Element element, ParserContext ctx, BeanDefinitionBuilder bean) { NamedNodeMap atts = element.getAttributes(); boolean setBus = false; for (int i = 0; i < atts.getLength(); i++) { Attr node = (Attr) atts.item(i); String val = node.getValue(); String pre = node.getPrefix(); String name = node.getLocalName(); String prefix = node.getPrefix(); // Don't process namespaces if (isNamespace(name, prefix)) { continue; }/*from w w w .j av a 2 s . c o m*/ if ("createdFromAPI".equals(name)) { bean.setAbstract(true); } else if ("abstract".equals(name)) { bean.setAbstract(true); } else if ("depends-on".equals(name)) { bean.addDependsOn(val); } else if ("name".equals(name)) { parseNameAttribute(element, ctx, bean, val); } else if ("container".equals(name)) { setBus = parseContainerAttribute(element, ctx, bean, val); } else if ("id".equals(name)) { parseIdAttribute(bean, element, name, val, ctx); } else if (isAttribute(pre, name)) { parseAttribute(bean, element, name, val, ctx); } } return setBus; }
From source file:com.hazelcast.config.XmlConfigSchemaLocationTest.java
private String extractSchemaAttribute(InputStream documentStream) throws Exception { DocumentBuilder parser = documentBuilderFactory.newDocumentBuilder(); Document document = parser.parse(documentStream); Element item = document.getDocumentElement(); if (item == null) { return null; }/*from w w w. ja v a 2 s .c o m*/ Attr schemaAttr = item.getAttributeNodeNS(XML_SCHEMA_NAMESPACE, XML_SCHEMA_LOCATION_ATTRIBUTE); if (schemaAttr == null) { return null; } return schemaAttr.getValue(); }
From source file:com.mirth.connect.donkey.server.data.jdbc.XmlQuerySource.java
public void load(String xmlFile) throws XmlQuerySourceException { Document document = null;/*from ww w. ja v a 2 s. co m*/ try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = dbf.newDocumentBuilder(); InputStream is = ResourceUtil.getResourceStream(XmlQuerySource.class, xmlFile); document = documentBuilder.parse(is); IOUtils.closeQuietly(is); } catch (Exception e) { throw new XmlQuerySourceException("Failed to read query file: " + xmlFile, e); } NodeList queryNodes = document.getElementsByTagName("query"); int queryNodeCount = queryNodes.getLength(); for (int i = 0; i < queryNodeCount; i++) { Node node = queryNodes.item(i); if (node.hasAttributes()) { Attr attr = (Attr) node.getAttributes().getNamedItem("id"); if (attr != null) { String query = StringUtils.trim(node.getTextContent()); if (query.length() > 0) { queries.put(attr.getValue(), query); } } } } }
From source file:Main.java
private static Node copyNodeExceptNamespace(Document document, Node srcNode, Set<String> namespace, List<String> exceptNamespaces) { if (srcNode.getNodeType() == Node.ELEMENT_NODE) { String nodeName = srcNode.getNodeName(); nodeName = nodeName.substring(nodeName.indexOf(":") + 1); Element element = document.createElement(nodeName); for (int i = 0; i < srcNode.getAttributes().getLength(); i++) { Attr attr = (Attr) srcNode.getAttributes().item(i); String name = attr.getName(); if (name.startsWith("xmlns:")) { String suffix = name.substring(6); if (!exceptNamespaces.contains(suffix)) { namespace.add(suffix); }// w w w .ja va2s.co m continue; } } for (int i = 0; i < srcNode.getAttributes().getLength(); i++) { Attr attr = (Attr) srcNode.getAttributes().item(i); String name = attr.getName(); if (name.startsWith("xmlns:")) { continue; } int semi = name.indexOf(":"); if (semi > 0) { if (namespace.contains(name.substring(0, semi))) { name = name.substring(semi + 1); } } element.setAttribute(name, attr.getValue()); } NodeList nodeList = srcNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node childNode = nodeList.item(i); if (childNode.getNodeType() == Node.TEXT_NODE) { element.appendChild(document.createTextNode(childNode.getTextContent())); } else if (childNode.getNodeType() == Node.ELEMENT_NODE) { Node node = copyNodeExceptNamespace(document, childNode, namespace, exceptNamespaces); element.appendChild(node); } } return element; } if (srcNode.getNodeType() == Node.TEXT_NODE) { Text text = document.createTextNode(srcNode.getTextContent()); return text; } return null; }
From source file:de.fhg.iais.cortex.services.ingest.worker.BinaryResolutionWorker.java
private CortexModel replaceLocalUrisInEDM(CortexModel model, String itemId) { if ((model == null) || (model.getAny().size() < 1)) { return model; }//from ww w. j ava2s . c o m Element rdf = model.getAny().get(0); if (rdf != null) { //replace in edm model Element aggregation = (Element) rdf .getElementsByTagNameNS(GlobalConstants.ORE_NAMESPACE_URI, "Aggregation").item(0); if (aggregation != null) { Element thumbnail = (Element) aggregation .getElementsByTagNameNS(GlobalConstants.EDM_NAMESPACE_URI, "object").item(0); if (thumbnail != null) { if (thumbnail.getAttributeNS(GlobalConstants.RDF_NAMESPACE_URI, Parser.RESOURCE) != null) { Attr attr = thumbnail.getAttributeNodeNS(GlobalConstants.RDF_NAMESPACE_URI, Parser.RESOURCE); String href = attr.getValue(); String value = amendRelativeUris(itemId, href); attr.setNodeValue(value); } } } else { throw new DbcException( "Ingest failed: " + itemId + " has no ore:Aggregation. Please check your Mappings."); } } return model; }
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); } }