List of usage examples for org.dom4j.io SAXReader SAXReader
public SAXReader()
From source file:com.boyuanitsm.pay.alipay.util.AlipaySubmit.java
License:Apache License
/** * ?query_timestamp???//from w ww . j av a 2s . co 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.bplow.netconn.base.net.Request.java
License:Open Source License
static Request parse(ByteBuffer bb) throws MalformedRequestException, UnsupportedEncodingException { byte[] requestMessage = bb.array(); String requestMsg = new String(requestMessage, "GBK"); System.out.println("??:" + requestMsg); String tradeType = null;// w ww. ja v a 2s . c om SAXReader reader = new SAXReader(); reader.setStripWhitespaceText(true); Document document; try { document = reader.read(new ByteArrayInputStream(requestMsg.trim().getBytes())); Iterator orderIt = document.selectNodes("/TX/TX_CODE").iterator(); while (orderIt.hasNext()) { Element elem = (Element) orderIt.next(); tradeType = elem.getText(); } } catch (DocumentException e) { e.printStackTrace(); } int i = 0; String outNo = ""; String jyteype = ""; /*42+2 22*/ byte[] type = new byte[2]; //bb.get(type, 44, 2); while (bb.hasRemaining()) { byte c = bb.get(); //int devIdInt = Integer.parseInt(devId); //String devIdString = Integer.toHexString(c); String hex = Integer.toHexString(c & 0xFF); if (hex.length() == 1) { hex = '0' + hex; } if (i >= 41 && i < 44) { outNo = outNo + hex; } if (i >= 44 && i < 46) { jyteype = jyteype + hex; } i++; System.out.print(hex.toUpperCase() + " "); } System.out.println(""); System.out.println("" + tradeType); System.out.println(outNo); //outOrderNo = outNo; /*CharBuffer cb = ascii.decode(bb); Matcher m = requestPattern.matcher(cb); if (!m.matches()) throw new MalformedRequestException(); Action a; try { a = Action.parse(m.group(1)); } catch (IllegalArgumentException x) { throw new MalformedRequestException(); } URI u; try { u = new URI("http://" + m.group(4) + m.group(2)); } catch (URISyntaxException x) { throw new MalformedRequestException(); } return new Request(a, m.group(3), u);*/ return new Request(outNo, tradeType); }
From source file:com.btmatthews.maven.plugins.ldap.dsml.DSMLFormatReader.java
License:Apache License
/** * Initialise the reader to read DSML entries from an underlying input stream. * * @param inputStream The underlying input stream. * @throws DocumentException If there was a problem parsing the DSML file. * @throws JaxenException If there was a problem creating the {@link XPath} expressions. * @throws IOException If there was a problem reading the DSML file. *///w ww .ja va 2 s .c om public DSMLFormatReader(final InputStream inputStream) throws DocumentException, IOException, JaxenException { final Map<String, String> map = new HashMap<String, String>(); map.put("dsml", "http://www.dsml.org/DSML"); namespaceContext = new SimpleNamespaceContext(map); final SAXReader reader = new SAXReader(); final Document document = reader.read(inputStream); final XPath xpath = createXPath( "/dsml[namespace-uri()='http://www.dsml.org/DSML']/dsml:directory-entries/dsml:entry"); objectClassXPath = createXPath("dsml:objectclass/dsml:oc-value"); attrXPath = createXPath("dsml:attr"); attrValueXPath = createXPath("dsml:value"); final List<Node> entries = (List<Node>) xpath.selectNodes(document); entryIterator = entries.iterator(); }
From source file:com.buddycloud.friendfinder.HttpUtils.java
License:Apache License
public static Element consumeXML(String URL) throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(new java.net.URL(URL)); return document.getRootElement(); }
From source file:com.cc.framework.util.SettingUtils.java
License:Open Source License
/** * ?//ww w. j a va 2 s .c o m * * @return */ public static Setting get() { Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); net.sf.ehcache.Element cacheElement = cache.get(Setting.CACHE_KEY); Setting setting; if (cacheElement != null) { setting = (Setting) cacheElement.getObjectValue(); } else { setting = new Setting(); try { File shopxxXmlFile = new ClassPathResource(CommonAttributes.SHOPXX_XML_PATH).getFile(); Document document = new SAXReader().read(shopxxXmlFile); List<Element> elements = document.selectNodes("/shopxx/setting"); for (Element element : elements) { String name = element.attributeValue("name"); String value = element.attributeValue("value"); try { beanUtils.setProperty(setting, name, value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } return setting; }
From source file:com.cc.framework.util.SettingUtils.java
License:Open Source License
/** * /*from ww w.j a va 2 s .c om*/ * * @param setting * */ public static void set(Setting setting) { try { File shopxxXmlFile = new ClassPathResource(CommonAttributes.SHOPXX_XML_PATH).getFile(); Document document = new SAXReader().read(shopxxXmlFile); List<Element> elements = document.selectNodes("/shopxx/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(shopxxXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.celexus.conniption.foreman.util.XMLHandler.java
License:Apache License
private Document getDocument(String response) throws UtilityException { SAXReader reader = new SAXReader(); Document document;/* w w w. j a v a 2s .c o m*/ try { document = reader.read(new ByteArrayInputStream(response.getBytes())); } catch (DocumentException e) { throw new UtilityException("Parse response failed", e); } return document; }
From source file:com.chinarewards.license.util.XmlUtil_dom4j.java
public static Document loadXml(String filename) { Document document = null;// w w w . j av a2 s .com try { SAXReader saxReader = new SAXReader(); document = saxReader.read(new File(filename)); } catch (Exception ex) { ex.printStackTrace(); } return document; }
From source file:com.chinarewards.license.util.XmlUtil_dom4j.java
public static Document readResult(StringBuffer paramStringBuffer) { Document localDocument = null; StringReader localStringReader = new StringReader(paramStringBuffer.toString()); SAXReader localSAXReader = new SAXReader(); try {// w ww . ja v a 2s.c o m localDocument = localSAXReader.read(localStringReader); } catch (DocumentException localDocumentException) { localDocumentException.printStackTrace(); System.out.println(localDocumentException.getMessage()); } return localDocument; }
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./*w w w . j a va 2s .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); } }