List of usage examples for org.w3c.dom Node hasAttributes
public boolean hasAttributes();
From source file:org.hyperic.hq.plugin.jboss.JBossConfig.java
private boolean findJnpPortBinding(Document doc) { boolean foundPort = false; NodeList servers = doc.getDocumentElement().getElementsByTagName("server"); for (int i = 0; i < servers.getLength(); i++) { Node server = servers.item(i); if (!server.hasAttributes()) { continue; }/* ww w .jav a2 s. com*/ String name = getAttribute(server, "name"); if (!name.equals(this.serverBinding)) { continue; } NodeList configs = server.getChildNodes(); for (int j = 0; j < configs.getLength(); j++) { Node config = configs.item(j); if (!config.hasAttributes()) { continue; } if (!"service-config".equals(config.getNodeName())) { continue; } name = getAttribute(config, "name"); boolean isNaming = false, isWebserver = false; if (!((isNaming = name.equals(NAMING_MBEAN)) || (isWebserver = name.equals(WEBSERVER_MBEAN)))) { continue; } NodeList bindings = config.getChildNodes(); for (int k = 0; k < bindings.getLength(); k++) { Node binding = bindings.item(k); if (!"binding".equals(binding.getNodeName())) { continue; } if (binding.hasAttributes()) { String val = getAttribute(binding, "port"); log.debug(this.serverBinding + " " + name + "=" + val); if (hasValue(val)) { if (isNaming) { this.jnpPortBinding = val; foundPort = true; } else if (isWebserver) { this.httpPort = val; } } val = getAttribute(binding, "host"); if (hasValue(val)) { if (isNaming) { this.jnpAddressBinding = val; } } } break; } } } return foundPort; }
From source file:org.hyperic.hq.plugin.jboss.JBossConfig.java
private boolean findJnpPortBinding(Node mbean) throws IOException { NodeList attrs = mbean.getChildNodes(); for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); if (!attr.hasAttributes()) { continue; }/*from www. ja v a 2s. c o m*/ String attrName = getAttribute(attr, "name"); if ("ServerName".equals(attrName)) { this.serverBinding = getText(attr); log.debug("ServerName=" + this.serverBinding); } else if ("StoreURL".equals(attrName)) { String url = getText(attr); File home = getJBossHome(); if (home != null) { log.debug("jboss.home.url=" + home); url = StringUtil.replace(url, "${jboss.home.url}", home.toString()); } url = StringUtil.replace(url, "${jboss.server.config.url}", this.serviceXML.getParentFile().toString()); File bindings = new File(url); boolean exists = bindings.exists(); log.debug("StoreURL exists=" + exists + " (" + url + ")"); if (exists) { this.bindingXML = bindings; this.lastModifiedBinding = bindings.lastModified(); Document bindingDoc; try { bindingDoc = parse(bindings); return findJnpPortBinding(bindingDoc); } finally { bindingDoc = null; } } } } return false; }
From source file:org.hyperic.hq.plugin.jboss.JBossConfig.java
private boolean findJnpPort(Node mbean) { NodeList attrs = mbean.getChildNodes(); boolean foundPort = false; for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); if (!attr.hasAttributes()) { continue; }/*from w ww . j a v a 2 s . com*/ String attrName = getAttribute(attr, "name"); if ("Port".equals(attrName)) { String val = getText(attr); if (hasValue(val)) { this.jnpPort = val; foundPort = true; } } else if ("BindAddress".equals(attrName)) { String val = getText(attr); if (hasValue(val)) { this.jnpAddress = val; } } } return foundPort; }
From source file:org.hyperic.hq.plugin.jboss.JBossConfig.java
private void findJnpPort(Document doc) throws IOException { NodeList mbeans = doc.getDocumentElement().getElementsByTagName("mbean"); for (int i = 0; i < mbeans.getLength(); i++) { Node mbean = mbeans.item(i); if (!mbean.hasAttributes()) { continue; }/* www .j a v a 2s . c o m*/ String name = getAttribute(mbean, "name"); if (NAMING_MBEAN.equals(name)) { findJnpPort(mbean); log.debug(NAMING_MBEAN + " port=" + this.jnpPort + ", host=" + this.jnpAddress); } else if (BINDING_MBEAN.equals(name)) { findJnpPortBinding(mbean); log.debug(BINDING_MBEAN + " port=" + this.jnpPortBinding + ", host=" + this.jnpAddressBinding); } } log.debug("JNP port=" + getJnpPort()); }
From source file:org.jboss.dashboard.displayer.AbstractDataDisplayerXMLFormat.java
public DataDisplayer parse(NodeList xmlNodes, ImportResults results) throws Exception { for (int i = 0; i < xmlNodes.getLength(); i++) { Node item = xmlNodes.item(i); if (item.getNodeName().equals("displayer") && item.hasAttributes() && item.hasChildNodes()) { String typeUid = item.getAttributes().getNamedItem("type").getNodeValue(); DataDisplayerType type = DataDisplayerServices.lookup().getDataDisplayerManager() .getDisplayerTypeByUid(typeUid); DataDisplayerRenderer renderer = null; Node rendererNode = item.getAttributes().getNamedItem("renderer"); if (rendererNode != null) { String rendUid = rendererNode.getNodeValue(); renderer = DataDisplayerServices.lookup().getDataDisplayerManager() .getDisplayerRendererByUid(rendUid); }/* w ww. j av a 2 s .c om*/ DataDisplayer displayer = type.createDataDisplayer(); displayer.setDataDisplayerRenderer(renderer); parseDisplayer(displayer, item.getChildNodes(), results); return displayer; } } throw new IllegalArgumentException("Missing <displayer> tag."); }
From source file:org.jboss.dashboard.export.ImportManagerImpl.java
protected void parseKPIs(NodeList xmlNodes, ImportResults results) throws Exception { for (int i = 0; i < xmlNodes.getLength(); i++) { Node item = xmlNodes.item(i); if (item.getNodeName().equals("kpi")) { try { KPI kpi = DataDisplayerServices.lookup().getKPIManager().createKPI(); Node codeNode = item.getAttributes().getNamedItem("code"); if (codeNode != null) kpi.setCode(StringEscapeUtils.unescapeXml(codeNode.getNodeValue())); NodeList subNodes = item.getChildNodes(); for (int j = 0; j < subNodes.getLength(); j++) { item = subNodes.item(j); // Description if (item.getNodeName().equals("description") && item.hasChildNodes()) { String description = item.getFirstChild().getNodeValue(); Locale locale = LocaleManager.currentLocale(); Node languageNode = item.getAttributes().getNamedItem("language"); if (languageNode != null) locale = new Locale(languageNode.getNodeValue()); kpi.setDescription(StringEscapeUtils.unescapeXml(description), locale); }// w w w . j av a 2 s.c om // Provider if (item.getNodeName().equals("provider") && item.hasAttributes()) { String providerCode = item.getAttributes().getNamedItem("code").getNodeValue(); DataProvider provider = results.getDataProviderByCode(providerCode); if (provider == null) provider = DataDisplayerServices.lookup().getDataProviderManager() .getDataProviderByCode(providerCode); if (provider == null) { results.getMessages() .add(new ImportExportMessage(ImportExportMessage.PROVIDER_CODE_NOT_FOUND, new Object[] { providerCode })); throw new RuntimeException("Continue with the next KPI..."); } kpi.setDataProvider(provider); } // Displayer if (item.getNodeName().equals("displayer") && item.hasAttributes() && item.hasChildNodes()) { String typeUid = item.getAttributes().getNamedItem("type").getNodeValue(); DataDisplayerType type = dataDisplayerManager.getDisplayerTypeByUid(typeUid); if (type == null) { results.getMessages().add(new ImportExportMessage( ImportExportMessage.DISPLAYER_TYPE_NOT_FOUND, new Object[] { typeUid })); throw new RuntimeException("Continue with the next KPI..."); } DataDisplayerRenderer renderer = null; Node rendererNode = item.getAttributes().getNamedItem("renderer"); if (rendererNode != null) { String rendUid = rendererNode.getNodeValue(); renderer = dataDisplayerManager.getDisplayerRendererByUid(rendUid); if (renderer == null) { results.getMessages() .add(new ImportExportMessage( ImportExportMessage.DISPLAYER_RENDERER_NOT_FOUND, new Object[] { rendUid })); throw new RuntimeException("Continue with the next KPI..."); } } DataDisplayer displayer = type.getXmlFormat().parse(subNodes, results); if (results.getMessages().hasErrors()) { throw new Exception(results.getMessages().get(0).toString()); } displayer.setDataDisplayerType(type); displayer.setDataDisplayerRenderer(renderer); kpi.setDataDisplayer(displayer); } } results.addKPI(kpi); } catch (Exception e) { log.error("Error parsing KPI", e); // Continue with the next KPI... } } } }
From source file:org.jmingo.parser.xml.dom.util.DomUtil.java
/** * Transform node attributes to map.//from w ww. jav a2s . c om * * @param node the node {@link Node} * @return map : key - attribute name; value - attribute value */ public static Map<String, String> getAttributes(Node node) { Map<String, String> attributes = ImmutableMap.of(); if (node.hasAttributes()) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); // get attributes names and values NamedNodeMap nodeMap = node.getAttributes(); for (int i = 0; i < nodeMap.getLength(); i++) { Node currentNode = nodeMap.item(i); builder.put(currentNode.getNodeName(), currentNode.getNodeValue()); } attributes = builder.build(); } return attributes; }
From source file:org.jmingo.parser.xml.dom.util.DomUtil.java
/** * Gets attribute by name.// ww w. jav a 2 s .c o m * * @param node {@link Node} * @param attributeName attribute name * @return attribute value with type 'string' */ public static String getAttributeString(Node node, String attributeName, String deffVal) { Validate.notNull(node, "getAttributeString::node cannot be null"); String value; Map<String, String> attrs; if (node.hasAttributes() && (attrs = getAttributes(node)).containsKey(attributeName)) { value = attrs.get(attributeName); } else { value = deffVal; } return value; }
From source file:org.jmingo.parser.xml.dom.util.DomUtil.java
/** * Gets attribute by name.//from w ww . ja v a2 s . c o m * * @param node {@link Node} * @param attributeName attribute name * @return attribute value with type 'int' */ public static int getAttributeInt(Node node, String attributeName, int deffVal) { Validate.notNull(node, "getAttributeInt::node cannot be null"); int value; Map<String, String> attrs; if (node.hasAttributes() && (attrs = getAttributes(node)).containsKey(attributeName)) { value = Integer.parseInt(attrs.get(attributeName)); } else { value = deffVal; } return value; }
From source file:org.kepler.moml.KeplerMetadataExtractor.java
/** Get the metadata from an input stream optionally printing output if a parsing error occurs. * @param actorStream the input stream// w ww . java2 s.c om * @param printError if true, print a stack trace and error message if a parsing error occurs. */ public static KeplerActorMetadata extractActorMetadata(InputStream actorStream, boolean printError) throws Exception { //if (isTracing) //log.trace("ActorCacheObject(" + actorStream.getClass().getName() //+ ")"); KeplerActorMetadata kam = new KeplerActorMetadata(); ByteArrayOutputStream byteout; try { // Copy 1024 bytes from actorStream to byteout byteout = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int numread = actorStream.read(b, 0, 1024); while (numread != -1) { byteout.write(b, 0, numread); numread = actorStream.read(b, 0, 1024); } kam.setActorString(byteout.toString()); // need to get actor name and id from the string // thus build a DOM representation String nameStr = null; try { //if (isTracing) log.trace(kam.getActorString()); StringReader strR = new StringReader(kam.getActorString()); InputSource xmlIn = new InputSource(strR); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (MOML_PUBLIC_ID_1.equals(publicId)) { return new InputSource(MoMLParser.class.getResourceAsStream("MoML_1.dtd")); } else { return null; } } }); // TODO // this causes http://bugzilla.ecoinformatics.org/show_bug.cgi?id=4671 // when File => Save Archive w/ wf w/ actor w/ < in the name: Document doc = builder.parse(xmlIn); //if (isTracing) log.trace(doc.toString()); Element rootNode = doc.getDocumentElement(); kam.setRootName(rootNode.getNodeName()); // Get the value of the name attribute of the root node NamedNodeMap nnm = rootNode.getAttributes(); Node namenode = nnm.getNamedItem("name"); nameStr = namenode.getNodeValue(); kam.setName(nameStr); boolean emptyKeplerDocumentation = true; boolean foundKeplerDocumentation = false; boolean foundUserLevelDocumentation = false; boolean foundAuthor = false; // Cycle through the children of the root node NodeList probNodes = rootNode.getChildNodes(); for (int i = 0; i < probNodes.getLength(); i++) { Node child = probNodes.item(i); if (child.hasAttributes()) { NamedNodeMap childAttrs = child.getAttributes(); Node idNode = childAttrs.getNamedItem("name"); if (idNode != null) { // the entityId String nameval = idNode.getNodeValue(); if (nameval.equals(NamedObjId.NAME)) { Node idNode1 = childAttrs.getNamedItem("value"); String idval = idNode1.getNodeValue(); kam.setLsid(new KeplerLSID(idval)); } // the class name if (nameval.equals("class")) { Node idNode3 = childAttrs.getNamedItem("value"); String classname = idNode3.getNodeValue(); kam.setClassName(classname); } // the semantic types if (nameval.startsWith("semanticType")) { Node idNode2 = childAttrs.getNamedItem("value"); String semtype = idNode2.getNodeValue(); kam.addSemanticType(semtype); } // userLevelDocumentation must be contained in KeplerDocumentation if (nameval.equals("userLevelDocumentation")) { log.warn(nameStr + " userLevelDocumentation property should be contained in a KeplerDocumentation property."); } else if (nameval.equals("KeplerDocumentation")) { foundKeplerDocumentation = true; final NodeList keplerDocNodeList = child.getChildNodes(); if (keplerDocNodeList.getLength() > 0) { emptyKeplerDocumentation = false; for (int j = 0; j < keplerDocNodeList.getLength(); j++) { final Node docChildNode = keplerDocNodeList.item(j); final NamedNodeMap docChildNamedNodeMap = docChildNode.getAttributes(); if (docChildNamedNodeMap != null) { final Node docChildChildName = docChildNamedNodeMap .getNamedItem("name"); if (docChildChildName != null) { final String docChildChildNameValue = docChildChildName .getNodeValue(); if (docChildChildNameValue.equals("userLevelDocumentation")) { foundUserLevelDocumentation = true; final String text = docChildNode.getTextContent(); if (text == null || text.trim().isEmpty()) { log.debug(nameStr + " has empty userLevelDocumentation."); } } else if (docChildChildNameValue.equals("author")) { foundAuthor = true; final String text = docChildNode.getTextContent(); if (text == null || text.trim().isEmpty()) { log.debug(nameStr + " has empty author documentation."); } } } } } } } if (nameval.startsWith(COPY_ATTRIBUTE_PREFIX)) { String value = childAttrs.getNamedItem("value").getNodeValue(); kam.addAttribute(nameval, value); } } } } // check documentation if (!foundKeplerDocumentation) { log.debug(nameStr + " is missing KeplerDocumentation."); } else if (emptyKeplerDocumentation) { log.debug(nameStr + " KeplerDocumentation is empty."); } else if (!foundUserLevelDocumentation && !foundAuthor) { log.debug(nameStr + " is missing userLevelDocumentation and author documentation."); } else if (!foundUserLevelDocumentation) { log.debug(nameStr + " is missing userLevelDocumentation."); } else if (!foundAuthor) { log.debug(nameStr + " is missing author documentation."); } } catch (Exception e) { if (printError) { e.printStackTrace(); System.out.println("Error parsing Actor KAR DOM \"" + ((nameStr == null) ? byteout.toString().substring(0, 300) + "..." : nameStr) + "\": " + e.getMessage()); } kam = null; } finally { actorStream.close(); byteout.close(); } } catch (Exception e) { kam = null; throw new Exception("Error extracting Actor Metadata: " + e.getMessage()); } return kam; }