List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:com.beetle.framework.util.file.XMLReader.java
License:Apache License
public static String getTagContent(String xmlFileName, String TagPath) { String a = ""; SAXReader reader = new SAXReader(); Document doc = null;//from w w w. j a v a2s . com try { doc = reader.read(new File(xmlFileName)); Node node = doc.selectSingleNode(convertPath(TagPath)); if (node != null) { a = node.getText(); } } catch (Exception e) { e.printStackTrace(); } finally { if (doc != null) { doc.clearContent(); } reader = null; } return a; }
From source file:com.beetle.framework.util.file.XMLReader.java
License:Apache License
/** * ???????//from w w w . j a v a 2s .co m * * * @param xmlFileInputStream * @param TagPath * @return */ public static String getTagContent(InputStream xmlFileInputStream, String TagPath) { String a = ""; if (xmlFileInputStream == null) { // System.out.println("WARN:the resource do not exist"); return a; } SAXReader reader = new SAXReader(); Document doc = null; try { doc = reader.read(xmlFileInputStream); Node node = doc.selectSingleNode(convertPath(TagPath)); if (node != null) { a = node.getText(); } } catch (Exception e) { e.printStackTrace(); } finally { if (doc != null) { doc.clearContent(); } reader = null; } return a; }
From source file:com.boyuanitsm.pay.alipay.util.AlipaySubmit.java
License:Apache License
/** * ?query_timestamp???/*from ww w .j a v a 2 s. c o m*/ * ??XML???SSL? * @return * @throws IOException * @throws DocumentException * @throws MalformedURLException */ public static String query_timestamp() throws MalformedURLException, DocumentException, IOException { //query_timestamp?URL String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" + AlipayConfig.input_charset; StringBuffer result = new StringBuffer(); SAXReader reader = new SAXReader(); Document doc = reader.read(new URL(strUrl).openStream()); List<Node> nodeList = doc.selectNodes("//alipay/*"); for (Node node : nodeList) { // ????? if (node.getName().equals("is_success") && node.getText().equals("T")) { // ?? List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*"); for (Node node1 : nodeList1) { result.append(node1.getText()); } } } return result.toString(); }
From source file:com.chinarewards.license.util.XmlUtil_dom4j.java
public static String getTextByNode(Document paramDocument, String paramString) { String text = ""; Node localNode = paramDocument.selectSingleNode(paramString); if (localNode != null) { text = localNode.getText(); }/* w ww . j a va 2s . c o m*/ return text; }
From source file:com.chingo247.settlercraft.structure.plan.PlanMenuManager.java
License:Open Source License
/** * Loads the PlanMenu from the menu.xml. If menu.xml doesn't exist, the menu.xml from the jar * will be written to the FileSystem./*from ww w. j a va2s. c o m*/ * * @throws DocumentException When XML is invalid * @throws StructureAPIException When XML contains invalid data */ public final void init() throws DocumentException, StructureAPIException { File file = new File(PLUGIN_FOLDER, "menu.xml"); if (!file.exists()) { InputStream input = PlanMenuManager.class.getClassLoader() .getResourceAsStream(RESOURCE_FOLDER + "/menu.xml"); FileUtil.write(input, file); } Document d = new SAXReader().read(file); List<Node> rows = d.selectNodes("Menu/SlotRow"); if (rows.size() > 2) { throw new StructureAPIException("Max rows is 2 for menu.xml"); } planMenu = MenuAPI.createMenu(SettlerCraft.getInstance(), PLANSHOP_NAME, 54); boolean hasRow2 = false; for (int row = 0; row < rows.size(); row++) { Node rowNode = rows.get(row); List<Node> slotNodes = rowNode.selectNodes("Slot"); // Slot #1 is reserved for all category if (row == 0 && slotNodes.size() > 8) { throw new StructureAPIException(" 'SlotRow#1' has max 8 slots to customize"); } else if (slotNodes.size() > 9) { throw new StructureAPIException(" 'SlotRow#" + (row + 2) + "' has max 9 slots to customize"); } int count = 0; for (Node categorySlotNode : slotNodes) { if (!categorySlotNode.hasContent()) { count++; continue; } Node mId = categorySlotNode.selectSingleNode("MaterialID"); Node cat = categorySlotNode.selectSingleNode("Category"); Node ali = categorySlotNode.selectSingleNode("Aliases"); if (mId == null) { throw new StructureAPIException("Missing 'MaterialID' element in 'SlotRow#" + (row + 1) + "' 'Slot#" + (count + 1) + "'"); } if (cat == null) { throw new StructureAPIException( "Missing 'Category' element in 'SlotRow#" + (row + 1) + "' 'Slot#" + (count + 1) + "'"); } int id; try { id = Integer.parseInt(mId.getText()); } catch (NumberFormatException nfe) { throw new StructureAPIException("Invalid number for 'MaterialID' element in 'SlotRow#" + (row + 1) + "' 'Slot#" + (count + 1) + "'"); } String category = cat.getText(); if (category.isEmpty()) { Element catEl = (Element) cat; category = catEl.attributeValue("value"); } if (category.trim().isEmpty()) { throw new StructureAPIException("Empty 'Category' element in 'SlotRow#" + (row + 1) + "' and 'Slot#" + (count + 1) + "'"); } category = category.replaceAll(" AND ", "&"); String[] aliases; if (ali == null) { aliases = new String[0]; } else { List<Node> aliasNodes = ali.selectNodes("Alias"); aliases = new String[aliasNodes.size()]; for (int j = 0; j < aliasNodes.size(); j++) { String alias = aliasNodes.get(j).getText(); if (alias.isEmpty()) { Element aliasEl = (Element) cat; alias = aliasEl.attributeValue("value"); } if (alias.trim().isEmpty()) { throw new StructureAPIException("Empty 'Alias' element in 'SlotRow#" + (row + 1) + "' and 'Slot#" + (count + 1) + "' and 'Alias#" + (j + 1) + "'"); } aliases[j] = aliasNodes.get(j).getText(); } } int slot = count; if (row == 0) { slot += 1; // slot 0 is reserved... } else { hasRow2 = true; } planMenu.putCategorySlot((row * 9) + slot, category, Material.getMaterial(id), aliases); count++; } // fill remaining if (count < 8 && row == 0) { for (int i = count; i < 8; i++) { planMenu.putLocked(i); } } else if (row > 0 && count < 9) { for (int i = count; i < 9; i++) { planMenu.putLocked((row * 9) + i); } } } if (hasRow2) { planMenu.putLocked(19, 20, 21, 22, 23, 24, 25); planMenu.putActionSlot(18, "Previous", Material.COAL_BLOCK); planMenu.putActionSlot(26, "Next", Material.COAL_BLOCK); } else { planMenu.putLocked(10, 11, 12, 13, 14, 15, 16); planMenu.putActionSlot(9, "Previous", Material.COAL_BLOCK); planMenu.putActionSlot(17, "Next", Material.COAL_BLOCK); } }
From source file:com.chingo247.structureapi.menus.plans.StructurePlanMenuReader.java
License:Open Source License
public CategoryMenu read(File file) throws DocumentException, SettlerCraftException { Preconditions.checkArgument(file.exists(), "File '" + file.getAbsolutePath() + "' does not exist!"); Document d = new SAXReader().read(file); CategoryMenu menu = new DefaultCategoryMenu("Buy & Build"); List<Node> rows = d.selectNodes("Menu/SlotRow"); if (rows.size() > 2) { throw new SettlerCraftException("Max rows is 2 for menu.xml"); }/* w w w .j a va 2 s . c o m*/ boolean hasRow2 = false; for (int row = 0; row < rows.size(); row++) { Node rowNode = rows.get(row); List<Node> slotNodes = rowNode.selectNodes("Slot"); // Slot #1 is reserved for all category if (row == 0 && slotNodes.size() > 8) { throw new SettlerCraftException(" 'SlotRow#1' has max 8 slots to customize"); } else if (slotNodes.size() > 9) { throw new SettlerCraftException(" 'SlotRow#" + (row + 2) + "' has max 9 slots to customize"); } int count = 0; for (Node categorySlotNode : slotNodes) { if (!categorySlotNode.hasContent()) { count++; continue; } Node mId = categorySlotNode.selectSingleNode("MaterialID"); Node cat = categorySlotNode.selectSingleNode("Category"); // Node ali = categorySlotNode.selectSingleNode("Aliases"); if (mId == null) { throw new SettlerCraftException("Missing 'MaterialID' element in 'SlotRow#" + (row + 1) + "' 'Slot#" + (count + 1) + "'"); } if (cat == null) { throw new SettlerCraftException( "Missing 'Category' element in 'SlotRow#" + (row + 1) + "' 'Slot#" + (count + 1) + "'"); } int id; try { id = Integer.parseInt(mId.getText()); } catch (NumberFormatException nfe) { throw new SettlerCraftException("Invalid number for 'MaterialID' element in 'SlotRow#" + (row + 1) + "' 'Slot#" + (count + 1) + "'"); } Node catNameNode = cat.selectSingleNode("Name"); if (catNameNode == null) { throw new SettlerCraftException( "Missing 'Name' element in 'SlotRow#" + (row + 1) + "' 'Slot#" + (count + 1) + "'"); } String category = catNameNode.getText(); if (category.isEmpty()) { Element catEl = (Element) cat; category = catEl.attributeValue("value"); } if (category.trim().isEmpty()) { throw new SettlerCraftException("Empty 'Category' element in 'SlotRow#" + (row + 1) + "' and 'Slot#" + (count + 1) + "'"); } category = category.replaceAll(" AND ", "&"); Node synonymsNode = cat.selectSingleNode("Synonyms"); // Set aliases String[] synonyms; if (synonymsNode == null) { synonyms = new String[0]; } else { List<Node> synonymNodes = synonymsNode.selectNodes("Synonym"); synonyms = new String[synonymNodes.size()]; for (int j = 0; j < synonymNodes.size(); j++) { String synonym = synonymNodes.get(j).getText(); if (synonym.isEmpty()) { Element synoEl = (Element) cat; synonym = synoEl.attributeValue("value"); } if (synonym.trim().isEmpty()) { throw new SettlerCraftException("Empty 'Synonym' element in 'SlotRow#" + (row + 1) + "' and 'Slot#" + (count + 1) + "' and 'Synonym#" + (j + 1) + "'"); } synonyms[j] = synonymNodes.get(j).getText(); } } int slot = count; if (row == 0) { slot += 1; // slot 0 is reserved... } else { hasRow2 = true; } CategorySlot categorySlot = SlotFactory.getInstance().createCategorySlot(category, id); categorySlot.addSynonyms(synonyms); menu.setCategorySlot((row * 9) + slot, categorySlot); count++; } // fill remaining if (count < 8 && row == 0) { for (int i = count; i < 8; i++) { menu.setLocked(i); } } else if (row > 0 && count < 9) { for (int i = count; i < 9; i++) { menu.setLocked((row * 9) + i); } } } if (hasRow2) { menu.setLocked(19, 20, 21, 22, 23, 24, 25); menu.setActionSlot(18, "Previous", 173); // block of coal menu.setActionSlot(26, "Next", 173); } else { menu.setLocked(10, 11, 12, 13, 14, 15, 16); menu.setActionSlot(9, "Previous", 173); menu.setActionSlot(17, "Next", 173); } return menu; }
From source file:com.chingo247.structureapi.plan.document.DocumentPluginElement.java
public String getStringValue(String xPath) { Node n = pluginElement.selectSingleNode(xPath); if (n == null || n.getText().trim().isEmpty()) { return null; }// w w w . j a va 2s. co m return n.getText(); }
From source file:com.chingo247.structureapi.plan.document.DocumentPluginElement.java
/** * Gets the double value from the xPath expression, may return null if xPath expression returned null * @param xPath The xPath/*from www.j a v a 2 s . c o m*/ * @return The value * @throws NumberFormatException if string wasn't a number value */ public Double getDoubleValue(String xPath) { Node n = pluginElement.selectSingleNode(xPath); if (n == null) { return null; } else { return Double.parseDouble(n.getText()); } }
From source file:com.chingo247.structureapi.plan.document.DocumentPluginElement.java
/** * Gets the float value from the xPath expression, may return null if xPath expression returned null * @param xPath The xPath/*from w w w .j a v a2 s . c o m*/ * @return The value * @throws NumberFormatException if string wasn't a number value */ public Float getFloatValue(String xPath) { Node n = pluginElement.selectSingleNode(xPath); if (n == null) { return null; } else { return Float.parseFloat(n.getText()); } }
From source file:com.chingo247.structureapi.plan.document.DocumentPluginElement.java
/** * Gets the int value from the xPath expression, may return null if xPath expression returned null * @param xPath The xPath//ww w .j ava 2 s. co m * @return The value * @throws NumberFormatException if string wasn't a number value */ public Integer getIntegerValue(String xPath) { Node n = pluginElement.selectSingleNode(xPath); if (n == null) { return null; } else { return Integer.parseInt(n.getText()); } }