List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:it.unibo.alchemist.language.EnvironmentBuilder.java
private <K> K buildK(final Node son, final Map<String, Object> env, final String defaultPackage) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {/*from w w w .jav a2 s . c o m*/ final NamedNodeMap attributes = son.getAttributes(); final Node typeNode = attributes.getNamedItem(TYPE); String type; if (typeNode == null) { type = ""; } else { type = typeNode.getNodeValue(); type = type.contains(".") ? type : defaultPackage + type; } return coreOperations(env, son, type, random); }
From source file:br.org.indt.ndg.common.SurveyParser.java
private SurveyXML processSurvey() throws ParserConfigurationException, SAXException, IOException { survey = new SurveyXML(); survey.setXmldoc(document);/* ww w . j a v a2s . c o m*/ logger.info("loading survey attributes"); NodeList nodeSurvey = document.getElementsByTagName("survey"); NamedNodeMap surveyAttr = nodeSurvey.item(0).getAttributes(); survey.setId(surveyAttr.getNamedItem("id").getNodeValue()); survey.setDisplay(surveyAttr.getNamedItem("display").getNodeValue()); if (surveyAttr.getNamedItem("title") != null) survey.setTitle(surveyAttr.getNamedItem("title").getNodeValue()); else survey.setTitle(nodeSurvey.item(0).getChildNodes().item(1).getTextContent()); if (surveyAttr.getNamedItem("deployed") != null) survey.setDeployed(surveyAttr.getNamedItem("deployed").getNodeValue()); if (surveyAttr.getNamedItem("checksum") != null) survey.setChecksum(surveyAttr.getNamedItem("checksum").getNodeValue()); logger.info("loading categories attributes"); categories = new TreeMap<Integer, Category>(); NodeList nodesCategory = document.getElementsByTagName("category"); int countCategory = nodesCategory.getLength(); for (int c = 0; c < countCategory; ++c) { Category category = new Category(); NamedNodeMap categoryAttr = nodesCategory.item(c).getAttributes(); category.setId(Integer.parseInt(categoryAttr.getNamedItem("id").getNodeValue())); category.setName(categoryAttr.getNamedItem("name").getNodeValue()); categories.put(category.getId(), category); } logger.info("loading fields attributes"); NodeList nodesQuestion = document.getElementsByTagName("question"); int countQuestions = nodesQuestion.getLength(); //logger.debug("countQuestions= "+ countQuestions); for (int a = 0; a < countQuestions; ++a) { NamedNodeMap questionAttr = nodesQuestion.item(a).getAttributes(); Field question = new Field(); String direction = ""; if (questionAttr.getNamedItem("direction") != null) direction = questionAttr.getNamedItem("direction").getNodeValue(); question.setDirection(direction); String questionId = questionAttr.getNamedItem("id").getNodeValue(); question.setId(Integer.parseInt(questionId)); String questionType = questionAttr.getNamedItem("type").getNodeValue(); question.setXmlType(questionType); String field = null; if (questionAttr.getNamedItem("field") != null) field = questionAttr.getNamedItem("field").getNodeValue(); else field = "" + fieldid++; question.setName(field); Node nquestion = nodesQuestion.item(a); Node nchild = nquestion.getChildNodes().item(1); String description = nchild.getTextContent(); question.setDescription(description); if (question.getXmlType().equals("_choice")) { NodeList questionChild = nodesQuestion.item(a).getChildNodes(); Choice choice = new Choice(); int index = 0; for (int i = 0; i < questionChild.getLength(); i++) { if (questionChild.item(i).getNodeName().equals("select")) { String select = questionChild.item(i).getTextContent(); choice.setChoiceType( (select.equals("exclusive") ? ChoiceType.EXCLUSIVE : ChoiceType.MULTIPLE)); } else if (questionChild.item(i).getNodeName().equals("item")) { NamedNodeMap itemAttr = questionChild.item(i).getAttributes(); String otr = itemAttr.getNamedItem("otr").getNodeValue(); String value = questionChild.item(i).getTextContent(); Item item = new Item(); item.setOtr(otr); item.setValue(value); item.setIndex(index++); choice.addItem(item); } else if (questionChild.item(i).getNodeName().equals("SkipLogic")) { //TODO: Skiplogic objects here; } } question.setChoice(choice); } String categoryName = nodesQuestion.item(a).getParentNode().getAttributes().getNamedItem("name") .getNodeValue(); int categoryId = Integer.parseInt( nodesQuestion.item(a).getParentNode().getAttributes().getNamedItem("id").getNodeValue()); //logger.debug(categoryName+" | "+questionId+ " | " + questionType); Category category = categories.get(categoryId); //logger.debug("category name: " + category.getName()); question.setCategoryId(categoryId); category.addField(question); categories.put(categoryId, category); ++keys; } survey.setCategories(categories); return survey; }
From source file:it.unibo.alchemist.language.EnvironmentBuilder.java
private Reaction<T> buildReaction(final Node rootReact, final Map<String, Object> env) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {// w w w . j a va 2 s . c o m final NamedNodeMap attributes = rootReact.getAttributes(); final Node nameNode = attributes.getNamedItem(NAME); final String name = nameNode == null ? "" : nameNode.getNodeValue(); String type = attributes.getNamedItem(TYPE).getNodeValue(); type = type.contains(".") ? type : REACTIONS_DEFAULT_PACKAGE + type; final Reaction<T> res = coreOperations(env, rootReact, type, random); if (!name.equals("")) { env.put(name, res); } env.put("REACTION", res); populateReaction(env, res, rootReact); return res; }
From source file:it.unibo.alchemist.language.EnvironmentBuilder.java
private Position buildPosition(final Node son, final Map<String, Object> env) throws InstantiationException, IllegalAccessException, InvocationTargetException { if (positionClass == null) { L.error("position class not yet defined."); } else {// ww w . j a v a 2s .com final NamedNodeMap attributes = son.getAttributes(); final Node posNode = attributes.getNamedItem("position"); if (posNode == null) { L.warn("a node has no position!"); } else { final String args = posNode.getNodeValue(); final StringTokenizer tk = new StringTokenizer(args, " ,;"); final ArrayList<String> arguments = new ArrayList<String>(); while (tk.hasMoreElements()) { arguments.add(tk.nextToken()); } arguments.trimToSize(); final List<Constructor<Position>> list = unsafeExtractConstructors(positionClass); return tryToBuild(list, arguments, env, random); } } return null; }
From source file:lineage2.gameserver.instancemanager.CursedWeaponsManager.java
/** * Method load.//from w ww.ja va 2 s . co m */ private void load() { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); File file = new File(Config.DATAPACK_ROOT, "data/xml/other/cursed_weapons.xml"); if (!file.exists()) { return; } Document doc = factory.newDocumentBuilder().parse(file); 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 ("item".equalsIgnoreCase(d.getNodeName())) { NamedNodeMap attrs = d.getAttributes(); int id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue()); int skillId = Integer.parseInt(attrs.getNamedItem("skillId").getNodeValue()); String name = "Unknown cursed weapon"; if (attrs.getNamedItem("name") != null) { name = attrs.getNamedItem("name").getNodeValue(); } else if (ItemHolder.getInstance().getTemplate(id) != null) { name = ItemHolder.getInstance().getTemplate(id).getName(); } if (id == 0) { continue; } CursedWeapon cw = new CursedWeapon(id, skillId, name); for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling()) { if ("dropRate".equalsIgnoreCase(cd.getNodeName())) { cw.setDropRate(Integer .parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("duration".equalsIgnoreCase(cd.getNodeName())) { attrs = cd.getAttributes(); cw.setDurationMin(Integer.parseInt(attrs.getNamedItem("min").getNodeValue())); cw.setDurationMax(Integer.parseInt(attrs.getNamedItem("max").getNodeValue())); } else if ("durationLost".equalsIgnoreCase(cd.getNodeName())) { cw.setDurationLost(Integer .parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("disapearChance".equalsIgnoreCase(cd.getNodeName())) { cw.setDisapearChance(Integer .parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("stageKills".equalsIgnoreCase(cd.getNodeName())) { cw.setStageKills(Integer .parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("transformationId".equalsIgnoreCase(cd.getNodeName())) { cw.setTransformationId(Integer .parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("transformationTemplateId".equalsIgnoreCase(cd.getNodeName())) { cw.setTransformationTemplateId(Integer .parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("transformationName".equalsIgnoreCase(cd.getNodeName())) { cw.setTransformationName(cd.getAttributes().getNamedItem("val").getNodeValue()); } } _cursedWeaponsMap.put(id, cw); } } } } _cursedWeapons = _cursedWeaponsMap.values(new CursedWeapon[_cursedWeaponsMap.size()]); } catch (Exception e) { _log.error("CursedWeaponsManager: Error parsing cursed_weapons file. " + e); } }
From source file:com.signavio.warehouse.business.util.jpdl4.Script.java
public Script(org.w3c.dom.Node script) { this.uuid = "oryx_" + UUID.randomUUID().toString(); NamedNodeMap attributes = script.getAttributes(); this.name = JpdlToJson.getAttribute(attributes, "name"); this.expression = JpdlToJson.getAttribute(attributes, "expr"); this.language = JpdlToJson.getAttribute(attributes, "lang"); this.variable = JpdlToJson.getAttribute(attributes, "var"); if (script.hasChildNodes()) for (org.w3c.dom.Node a = script.getFirstChild(); a != null; a = a.getNextSibling()) if (a.getNodeName().equals("text")) { this.text = a.getTextContent(); break; }//from w w w. j a v a 2s.c om this.bounds = JpdlToJson.getBounds(attributes.getNamedItem("g")); }
From source file:hoot.services.controllers.osm.ChangesetDbWriter.java
private long getOldElementId(NamedNodeMap nodeAttributes, EntityChangeType entityChangeType, List<Long> oldElementIds) { long oldElementId = Long.parseLong(nodeAttributes.getNamedItem("id").getNodeValue()); // make sure request has no duplicate IDs for new elements // This catches a duplicate create/delete error earlier. Technically, // updating the same node twice could be allowed (not sure if rails port does), but I'm // going to not allow that for now. if (oldElementIds.contains(oldElementId)) { throw new IllegalArgumentException( "Duplicate OSM element ID: " + oldElementId + " in changeset " + requestChangesetId); }/*from w ww.j a v a 2 s . c o m*/ if (entityChangeType == EntityChangeType.CREATE) { // by convention, new element IDs should have a negative value if (oldElementId >= 0) { throw new IllegalArgumentException("Invalid OSM element ID for create: " + oldElementId + " for " + "changeset: " + requestChangesetId + ". Use a negative ID value."); } } // Formerly, we had a setting called // "hootCoreServicesDatabaseWriterCompatibility" that would // have to be turned on to allow nodes with negative ID's to be written, // which was to accomodate the behavior of hoot --convert. If it wasn't turned on, a failure // would occur here. Now, by default the writing nodes with negative ID's is always allowed. oldElementIds.add(oldElementId); return oldElementId; }
From source file:net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.java
/** * *//* w ww . j a v a2 s. c o m*/ private Map<String, String> parseExportFonts(Node exportFontsNode) { Map<String, String> exportFonts = new HashMap<String, String>(); NodeList nodeList = exportFontsNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && NODE_export.equals(node.getNodeName())) { NamedNodeMap nodeAttrs = node.getAttributes(); if (nodeAttrs.getNamedItem(ATTRIBUTE_key) != null) { exportFonts.put(nodeAttrs.getNamedItem(ATTRIBUTE_key).getNodeValue(), node.getTextContent()); } } } return exportFonts; }
From source file:net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.java
private SimpleFontSet parseFontSet(Node fontSetNode) { SimpleFontSet fontSet = new SimpleFontSet(); NamedNodeMap nodeAttrs = fontSetNode.getAttributes(); if (nodeAttrs.getNamedItem(ATTRIBUTE_name) != null) { fontSet.setName(nodeAttrs.getNamedItem(ATTRIBUTE_name).getNodeValue()); }//from w ww . j a va 2 s .co m NodeList nodeList = fontSetNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (NODE_family.equals(node.getNodeName())) { SimpleFontSetFamily family = parsetFontSetFamily(node); fontSet.addFamily(family); } else if (NODE_exportFonts.equals(node.getNodeName())) { fontSet.setExportFonts(parseExportFonts(node)); } } } return fontSet; }
From source file:net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.java
private SimpleFontSetFamily parsetFontSetFamily(Node familyNode) { SimpleFontSetFamily family = new SimpleFontSetFamily(); NamedNodeMap nodeAttrs = familyNode.getAttributes(); if (nodeAttrs.getNamedItem(ATTRIBUTE_familyName) != null) { family.setFamilyName(nodeAttrs.getNamedItem(ATTRIBUTE_familyName).getNodeValue()); }/*from ww w.j a va 2 s .c om*/ if (nodeAttrs.getNamedItem(ATTRIBUTE_primary) != null) { family.setPrimary(Boolean.parseBoolean(nodeAttrs.getNamedItem(ATTRIBUTE_primary).getNodeValue())); } NodeList nodeList = familyNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (NODE_includedScript.equals(node.getNodeName())) { family.addIncludedScript(node.getTextContent()); } else if (NODE_excludedScript.equals(node.getNodeName())) { family.addExcludedScript(node.getTextContent()); } } } return family; }