List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:eu.planets_project.tb.impl.model.benchmark.BenchmarkGoalsHandlerImpl.java
private void parseBenchmarkGoals(String sCategoryName) { NodeList categories = root.getElementsByTagName("category"); for (int k = 0; k < categories.getLength(); k++) { Node category = categories.item(k); NodeList items = category.getChildNodes(); //now check if this is the category we're looking for NamedNodeMap catattributes = category.getAttributes(); String sCategory = catattributes.getNamedItem("name").getNodeValue(); if (sCategory.equals(sCategoryName)) { //now parse items for (int i = 0; i < items.getLength(); i++) { BenchmarkGoalImpl bmGoal = new BenchmarkGoalImpl(); Node item = items.item(i); if (item.getNodeName().equals("item") && item.getNodeType() == Node.ELEMENT_NODE) { //Now within an item (=benchmarkGoal) NamedNodeMap attributes = item.getAttributes(); bmGoal.setCategory(sCategoryName); bmGoal.setID(attributes.getNamedItem("id").getNodeValue()); bmGoal.setType(attributes.getNamedItem("type").getNodeValue()); bmGoal.setScale(attributes.getNamedItem("scale").getNodeValue()); bmGoal.setVersion(attributes.getNamedItem("version").getNodeValue()); //now get childNodesw: definition and description NodeList itemchilds = item.getChildNodes(); for (int j = 0; j < itemchilds.getLength(); j++) { if (itemchilds.item(j).getNodeType() == Node.ELEMENT_NODE) { if (itemchilds.item(j).getNodeName().equals("definition")) { bmGoal.setDefinition(itemchilds.item(j).getTextContent()); }//from w w w .j av a 2s .c om if (itemchilds.item(j).getNodeName().equals("description")) { bmGoal.setDescription(itemchilds.item(j).getTextContent()); } if (itemchilds.item(j).getNodeName().equals("name")) { bmGoal.setName(itemchilds.item(j).getTextContent()); } } } if (this.hmBmGoals.containsKey(bmGoal.getID())) this.hmBmGoals.remove(bmGoal.getID()); this.hmBmGoals.put(bmGoal.getID(), bmGoal); } } } //End Check if correct category name } }
From source file:com.collabnet.ccf.core.recovery.HospitalArtifactReplayer.java
private void removeProcessors(Node mapNode) { NodeList entryNodes = ((Element) mapNode).getElementsByTagName("entry"); String sourceComponent = entry.getSourceComponent(); int nodeLength = entryNodes.getLength(); for (int i = 0; i < nodeLength; i++) { Node entryNode = entryNodes.item(i); NamedNodeMap attributes = entryNode.getAttributes(); Node keyRefNode = attributes.getNamedItem("key-ref"); String keyRef = keyRefNode.getNodeValue(); if (keyRef.equals(sourceComponent)) { Node valueRefNode = attributes.getNamedItem("value-ref"); String valueRef = valueRefNode.getNodeValue(); sourceComponent = valueRef;//from w w w . ja v a 2 s . co m } else { nodeLength--; i--; mapNode.removeChild(entryNode); } } }
From source file:fedora.server.security.servletfilters.pubcookie.FilterPubcookie.java
private final String getAction(Node parent, String pubcookieLoginpageFormName) { String method = "getAction()"; if (log.isDebugEnabled()) { log.debug(enter(method));/*from w ww . ja va2 s. c om*/ } String action = ""; NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String tag = child.getNodeName(); if ("form".equalsIgnoreCase(tag)) { NamedNodeMap attributes = child.getAttributes(); Node nameNode = attributes.getNamedItem("name"); String name = nameNode.getNodeValue(); Node actionNode = attributes.getNamedItem("action"); if (pubcookieLoginpageFormName.equalsIgnoreCase(name) && actionNode != null) { action = actionNode.getNodeValue(); break; } } action = getAction(child, pubcookieLoginpageFormName); if (!"".equals(action)) { break; } } if (log.isDebugEnabled()) { log.debug(exit(method)); } return action; }
From source file:com.sparkred.mdex.metrics.publish.EndecaMDEXAgent.java
/** * Takes in the XML doc returned on the stats page and parses it out into a * list of MdexStatsEntry items//from w ww. j av a 2 s . c o m * * @param pDoc * - the xml doc to pull data from * @param pRootNode * - the name of the node from which metrics should be pulled * @return - the list of items with the relevant metrics * @throws IOException * @throws ClientProtocolException */ private List<MdexStatsEntry> fetchMDEXStatsByType(Document pDoc, String pRootNode) throws IOException, ClientProtocolException { List<MdexStatsEntry> stats_entries = new ArrayList<MdexStatsEntry>(); NodeList server_stats = pDoc.getElementsByTagName(pRootNode); NodeList statsList = server_stats.item(0).getChildNodes(); for (int i = 0; i < statsList.getLength(); i++) { Node node = statsList.item(i); if (node.getNodeName().equals(MdexStatsEntry.STAT_NODE_NAME)) { NamedNodeMap attr = node.getAttributes(); MdexStatsEntry entry = new MdexStatsEntry( attr.getNamedItem(MdexStatsEntry.METRIC_NODE_NAME).getNodeValue(), attr.getNamedItem(MdexStatsEntry.METRIC_NODE_UNITS).getNodeValue(), attr.getNamedItem(MdexStatsEntry.METRIC_NODE_COUNT).getNodeValue(), attr.getNamedItem(MdexStatsEntry.METRIC_NODE_AVG).getNodeValue(), attr.getNamedItem(MdexStatsEntry.METRIC_NODE_STDDEV).getNodeValue(), attr.getNamedItem(MdexStatsEntry.METRIC_NODE_MIN).getNodeValue(), attr.getNamedItem(MdexStatsEntry.METRIC_NODE_MAX).getNodeValue(), attr.getNamedItem(MdexStatsEntry.METRIC_NODE_TOTAL).getNodeValue()); stats_entries.add(entry); } } return stats_entries; }
From source file:fedora.server.security.servletfilters.pubcookie.FilterPubcookie.java
private final void getFormFields(Node parent, Map formfields) { String method = "getFormFields(Node parent, Map formfields)"; if (log.isDebugEnabled()) { log.debug(enter(method));/*from w ww . ja v a2 s.c o m*/ } NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String tag = child.getNodeName(); if ("input".equalsIgnoreCase(tag)) { NamedNodeMap attributes = child.getAttributes(); Node typeNode = attributes.getNamedItem("type"); String type = typeNode.getNodeValue(); Node nameNode = attributes.getNamedItem("name"); String name = nameNode.getNodeValue(); Node valueNode = attributes.getNamedItem("value"); String value = ""; if (valueNode != null) { value = valueNode.getNodeValue(); } if ("hidden".equalsIgnoreCase(type) && value != null) { if (log.isDebugEnabled()) { log.debug(format("capturing hidden fields", name, value)); } formfields.put(name, value); } } getFormFields(child, formfields); } if (log.isDebugEnabled()) { log.debug(exit(method)); } }
From source file:com.jaspersoft.jasperserver.ws.xml.Unmarshaller.java
private Argument readArgument(Node argumentNode) { Argument argument = new Argument(); NamedNodeMap nodeAttributes = argumentNode.getAttributes(); if (nodeAttributes.getNamedItem("name") != null) argument.setName(nodeAttributes.getNamedItem("name").getNodeValue()); argument.setValue(readPCDATA(argumentNode)); return argument; }
From source file:com.jaspersoft.jasperserver.ws.xml.Unmarshaller.java
private Request readRequest(Node requestNode) { Request request = new Request(); NamedNodeMap nodeAttributes = requestNode.getAttributes(); if (nodeAttributes.getNamedItem("operationName") != null) request.setOperationName(nodeAttributes.getNamedItem("operationName").getNodeValue()); if (nodeAttributes.getNamedItem("locale") != null) request.setLocale(nodeAttributes.getNamedItem("locale").getNodeValue()); NodeList childsOfChild = requestNode.getChildNodes(); for (int c_count = 0; c_count < childsOfChild.getLength(); c_count++) { Node child_child = (Node) childsOfChild.item(c_count); if (child_child.getNodeType() == Node.ELEMENT_NODE && child_child.getNodeName().equals("argument")) { request.getArguments().add(readArgument(child_child)); }/*from www . j a v a2s .c o m*/ if (child_child.getNodeType() == Node.ELEMENT_NODE && child_child.getNodeName().equals("resourceDescriptor")) { request.setResourceDescriptor(readResourceDescriptor((Element) child_child)); } } return request; }
From source file:org.opencastproject.loadtest.impl.IngestJob.java
/** * Parse and change the manifest.xml's id to match the mediapackage id we will be ingesting. * /* w ww. ja v a2s . co m*/ * @param filepath * The path to the manifest.xml file. */ private void changeManifestID(String filepath) { try { logger.info("Filepath for changing the manifest id is " + filepath); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse(filepath); // Get the mediapackage XPath xPath = XPathFactory.newInstance().newXPath(); Node mediapackage = ((NodeList) xPath.evaluate("//*[local-name() = 'mediapackage']", doc, XPathConstants.NODESET)).item(0); // update mediapackage attribute NamedNodeMap attr = mediapackage.getAttributes(); Node nodeAttr = attr.getNamedItem("id"); nodeAttr.setTextContent(id); // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(filepath)); transformer.transform(source, result); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (TransformerException tfe) { tfe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (SAXException sae) { sae.printStackTrace(); } catch (XPathExpressionException xpe) { xpe.printStackTrace(); } }
From source file:com.l2jfree.gameserver.datatables.EnchantHPBonusData.java
private EnchantHPBonusData() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);// ww w .j a va 2 s .c om factory.setIgnoringComments(true); File file = new File(Config.DATAPACK_ROOT, "data/enchantHPBonus.xml"); Document doc = null; try { doc = factory.newDocumentBuilder().parse(file); } catch (Exception e) { _log.warn("", e); return; } for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) { if ("list".equalsIgnoreCase(n.getNodeName())) { for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) { if ("enchantHP".equalsIgnoreCase(d.getNodeName())) { NamedNodeMap attrs = d.getAttributes(); Node att; boolean fullArmor; att = attrs.getNamedItem("grade"); if (att == null) { _log.warn("[EnchantHPBonusData] Missing grade, skipping"); continue; } int grade = Integer.parseInt(att.getNodeValue()); att = attrs.getNamedItem("fullArmor"); if (att == null) { _log.warn("[EnchantHPBonusData] Missing fullArmor, skipping"); continue; } fullArmor = Boolean.valueOf(att.getNodeValue()); att = attrs.getNamedItem("values"); if (att == null) { _log.warn("[EnchantHPBonusData] Missing bonus id: " + grade + ", skipping"); continue; } StringTokenizer st = new StringTokenizer(att.getNodeValue(), ","); int tokenCount = st.countTokens(); Integer[] bonus = new Integer[tokenCount]; for (int i = 0; i < tokenCount; i++) { Integer value = Integer.decode(st.nextToken().trim()); if (value == null) { _log.warn("[EnchantHPBonusData] Bad Hp value!! grade: " + grade + " FullArmor? " + fullArmor + " token: " + i); value = 0; } bonus[i] = value; } if (fullArmor) _fullArmorHPBonus.set(grade, bonus); else _singleArmorHPBonus.set(grade, bonus); } } } } if (_fullArmorHPBonus.isEmpty() && _singleArmorHPBonus.isEmpty()) return; int count = 0; for (L2Item item0 : ItemTable.getInstance().getAllTemplates()) { if (!(item0 instanceof L2Equip)) continue; final L2Equip item = (L2Equip) item0; if (item.getCrystalType() == L2Item.CRYSTAL_NONE) continue; boolean shouldAdd = false; // normally for armors if (item instanceof L2Armor) { switch (item.getBodyPart()) { case L2Item.SLOT_CHEST: case L2Item.SLOT_FEET: case L2Item.SLOT_GLOVES: case L2Item.SLOT_HEAD: case L2Item.SLOT_LEGS: case L2Item.SLOT_BACK: case L2Item.SLOT_FULL_ARMOR: case L2Item.SLOT_UNDERWEAR: case L2Item.SLOT_L_HAND: shouldAdd = true; break; } } // shields in the weapons table else if (item instanceof L2Weapon) { switch (item.getBodyPart()) { case L2Item.SLOT_L_HAND: shouldAdd = true; break; } } if (shouldAdd) { count++; item.attach(new FuncTemplate(null, "EnchantHp", Stats.MAX_HP, 0x60, 0)); } } _log.info("Enchant HP Bonus registered for " + count + " items!"); }
From source file:com.collabnet.ccf.core.recovery.HospitalArtifactReplayer.java
private void addGAImportComponents(Document document, Element routerElement) { NodeList propertyNodes = routerElement.getElementsByTagName("map"); Element mapElement = (Element) propertyNodes.item(0); Element fileReaderEntry = document.createElement("entry"); fileReaderEntry.setAttribute("key-ref", "FileReader"); fileReaderEntry.setAttribute("value-ref", "GenericArtifactMultiLineParser"); Element gaParserEntry = document.createElement("entry"); gaParserEntry.setAttribute("key-ref", "GenericArtifactMultiLineParser"); gaParserEntry.setAttribute("value-ref", entry.getSourceComponent()); mapElement.appendChild(fileReaderEntry); mapElement.appendChild(gaParserEntry); Element documentElement = document.getDocumentElement(); Element fileReaderElement = document.createElement("bean"); fileReaderElement.setAttribute("id", "FileReader"); fileReaderElement.setAttribute("class", "org.openadaptor.auxil.connector.iostream.reader.FileReadConnector"); Element fileProperty = document.createElement("property"); fileProperty.setAttribute("name", "filename"); fileProperty.setAttribute("value", entry.getDataFile().getAbsolutePath()); fileReaderElement.appendChild(fileProperty); documentElement.appendChild(fileReaderElement); Element gaParserElement = document.createElement("bean"); gaParserElement.setAttribute("id", "GenericArtifactMultiLineParser"); gaParserElement.setAttribute("class", "com.collabnet.ccf.core.utils.GenericArtifactMultiLineParser"); documentElement.appendChild(gaParserElement); NodeList allBeans = document.getElementsByTagName("bean"); String exceptionProcessorComponentName = null; for (int i = 0; i < allBeans.getLength(); i++) { Node beanNode = allBeans.item(i); NamedNodeMap atts = beanNode.getAttributes(); Node beanIdNode = atts.getNamedItem("id"); String beanId = beanIdNode.getNodeValue(); // FIXME What happens if the router component is not called router if (beanId.equals("Router")) { NodeList routerPropertyNodes = ((Element) beanNode).getElementsByTagName("property"); for (int j = 0; j < routerPropertyNodes.getLength(); j++) { Node propNode = routerPropertyNodes.item(j); NamedNodeMap routerPropAtts = propNode.getAttributes(); Node nameNode = routerPropAtts.getNamedItem("name"); String routerProperty = nameNode.getNodeValue(); if (routerProperty.equals("exceptionProcessor")) { Node expProcessorNode = routerPropAtts.getNamedItem("ref"); exceptionProcessorComponentName = expProcessorNode.getNodeValue(); }//from w w w . ja v a2 s .c o m } } else if (beanId.equals(exceptionProcessorComponentName)) { NodeList exceptionPropertyNodes = ((Element) beanNode).getElementsByTagName("property"); for (int j = 0; j < exceptionPropertyNodes.getLength(); j++) { Node propertyNode = exceptionPropertyNodes.item(j); NamedNodeMap excepPropAtts = propertyNode.getAttributes(); Node nameNode = excepPropAtts.getNamedItem("name"); String propertyName = nameNode.getNodeValue(); if (propertyName.equals("hospitalFileName")) { Node valueNode = excepPropAtts.getNamedItem("value"); valueNode.setNodeValue(replayWorkDir.getAbsolutePath() + File.separator + "hospital.txt"); } else if (propertyName.equals("artifactsDirectory")) { Node valueNode = excepPropAtts.getNamedItem("value"); valueNode.setNodeValue(replayWorkDir.getAbsolutePath() + File.separator + "artifacts"); } } } } }