List of usage examples for org.dom4j.io SAXReader read
public Document read(InputSource in) throws DocumentException
Reads a Document from the given InputSource
using SAX
From source file:com.beetle.framework.util.file.XMLReader.java
License:Apache License
public static void setProperties(String xmlFileName, String itemPath, String ElementName, String keyName, String valueName, String key, String value) { // ? ??????//from w w w. j a v a2 s . c o m // ???? synchronized (writeLock) { SAXReader reader = new SAXReader(); XMLWriter writer = null; try { Document doc = reader.read(new File(xmlFileName)); Node node = doc.selectSingleNode(convertPath(itemPath)); if (node != null) { Iterator<?> it = node.selectNodes(ElementName).iterator(); while (it.hasNext()) { Element e = (Element) it.next(); if (e.attributeValue(keyName).equals(key)) { e.addAttribute(valueName, value); break; } } } writer = new XMLWriter(new FileWriter(xmlFileName)); writer.write(doc); } catch (Exception e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (IOException ex) { ex.printStackTrace(); } } reader = null; } } }
From source file:com.beetle.framework.web.cache.imp.CacheConfig.java
License:Apache License
public synchronized void readCacheURLs(InputStream xmlIs) { url_cacheAttr.clear();/*from w w w . j ava2 s . c o m*/ if (xmlIs == null) { return; } SAXReader reader = new SAXReader(); Document doc = null; try { doc = reader.read(xmlIs); Node node = doc.selectSingleNode(convertPath("mappings.caches")); if (node != null) { config.setDiskStorePath(node.valueOf("@diskStorePath")); config.setMaxElementsInMemory(toInt(node.valueOf("@maxElementsInMemory"))); config.setMemoryStoreEvictionPolicy(node.valueOf("memoryStoreEvictionPolicy")); Iterator<?> it = node.selectNodes("cItem").iterator(); while (it.hasNext()) { CacheAttr attr = new CacheAttr(); Element e = (Element) it.next(); attr.setUrl(e.valueOf("@name")); attr.setScope(e.valueOf("@scope")); attr.setTime(toInt(e.valueOf("@time"))); url_cacheAttr.put(attr.getUrl(), attr); } } } catch (Exception de) { de.printStackTrace(); } finally { if (doc != null) { doc.clearContent(); } reader = null; } }
From source file:com.beyondb.io.DBConfig.java
/** *??//from w ww.j a v a 2 s .co m * @param path * @return */ public static DataSource readDBConfig(String path) { DataSource ds = null; try { SAXReader reader = new SAXReader(); File file = new File(path); if (file.exists()) { Document doc = reader.read(file); Element datasource = doc.getRootElement(); Element dbElement = datasource.element(Node_database); if (dbElement != null) { String id = dbElement.attribute(Attribute_id).getValue(); String username = dbElement.attribute(Attribute_username).getValue(); String password = dbElement.attribute(Attribute_password).getValue(); String virtualNode = dbElement.attribute(Attribute_virtualNode).getValue(); String url = dbElement.elementText(Attribute_jdbcurl); ds = new BydDataSource(url, username, password); ds.setVirtualNode(virtualNode); ds.setID(id); } } } catch (DocumentException ex) { Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, "???", ex); } return ds; }
From source file:com.beyondb.io.DBConfig.java
/** *??//from w ww . j a v a 2 s. co m * @param path * @return */ public static ArrayList<DataSource> readDBConfig1(String path) { ArrayList<DataSource> dslist = new ArrayList<>(); try { SAXReader reader = new SAXReader(); File file = new File(path); if (file.exists()) { Document doc = reader.read(file); Element datasource = doc.getRootElement(); Iterator it = datasource.elementIterator(Node_database); while (it.hasNext()) { Element dbElement = (Element) it.next(); String id = dbElement.attribute(Attribute_id).getValue(); String username = dbElement.attribute(Attribute_username).getValue(); String password = dbElement.attribute(Attribute_password).getValue(); String virtualNode = dbElement.attribute(Attribute_virtualNode).getValue(); String url = dbElement.elementText(Attribute_jdbcurl); DataSource ds = new BydDataSource(url, username, password); ds.setVirtualNode(virtualNode); ds.setID(id); dslist.add(ds); } } } catch (DocumentException ex) { Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, "???", ex); } return dslist; }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * ReaderDocument encodingStrnull""GB2312 * * @param in// ww w .j a v a 2 s . com * Reader * @param encoding * * @return documment * @throws XMLDocException * @throws BaseException */ public static Document fromXML(Reader in, String encoding) throws BaseException { try { if (encoding == null || encoding.equals("")) { encoding = DEFAULT_ENCODING; } SAXReader reader = new SAXReader(); InputSource source = new InputSource(in); source.setEncoding(encoding); Document document = reader.read(source); document.setXMLEncoding(encoding); return document; } catch (Exception ex) { throw new BaseException("UTIL-0001", ex); } }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * XMLDocument encodingStrnull""GB2312//from w w w.ja v a 2 s .c o m * * @param inputSource * * @param encoding * * @return document * @throws XMLDocException * @throws BaseException */ public static Document fromXML(InputStream inputSource, String encoding) throws BaseException { try { if (encoding == null || encoding.equals("")) { encoding = DEFAULT_ENCODING; } SAXReader reader = new SAXReader(); Document document = reader.read(inputSource); document.setXMLEncoding(encoding); return document; } catch (Exception ex) { throw new BaseException("UTIL-0001", ex); } }
From source file:com.boyuanitsm.pay.alipay.util.AlipaySubmit.java
License:Apache License
/** * ?query_timestamp???/* w ww. 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.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;/*from w ww . j a v a 2s .c o m*/ 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 w w .ja va 2 s . co m*/ 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(); }