List of usage examples for org.dom4j.io SAXReader SAXReader
public SAXReader()
From source file:com.glaf.core.provider.ServicePropertiesProvider.java
License:Apache License
public Document getFormatXMLDocument() { if (formatXML == null) { File file = getFileFromDevelopmentPath("Format.xml"); if (file != null && file.exists() && file.isFile()) { try { SAXReader reader = new SAXReader(); formatXML = reader.read(new FileReader(file)); } catch (Exception ex) { throw new IllegalStateException(ex); }/* www .jav a2 s. c o m*/ } else { file = new File(SystemProperties.getConfigRootPath() + "/Format.xml"); try { SAXReader reader = new SAXReader(); formatXML = reader.read(new FileReader(file)); } catch (Exception ex) { throw new IllegalStateException(ex); } } } return formatXML; }
From source file:com.glaf.core.provider.ServicePropertiesProvider.java
License:Apache License
public void setFormatXML(InputStream is) { try {//from w w w. j a v a 2 s. c o m SAXReader reader = new SAXReader(); formatXML = reader.read(is); } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:com.glaf.core.provider.ServiceProviderConfigReader.java
License:Apache License
void read(String prefix, InputStream is) { try {// ww w .j a va2s.c o m final SAXReader reader = new SAXReader(); final Document doc = reader.read(is); process(prefix, doc); } catch (final Exception e) { throw new ServiceProviderException(e); } }
From source file:com.glaf.core.provider.ServiceProviderConfigReader.java
License:Apache License
void read(String prefix, String fileLocation) { try {//from w w w .jav a2 s . c o m final SAXReader reader = new SAXReader(); final Document doc = reader.read(new FileInputStream(fileLocation)); process(prefix, doc); } catch (final Exception ex) { ex.printStackTrace(); throw new ServiceProviderException(ex); } }
From source file:com.glaf.core.todo.util.TodoXmlReader.java
License:Apache License
public List<Todo> read(java.io.InputStream inputStream) { List<Todo> todos = new java.util.ArrayList<Todo>(); SAXReader xmlReader = new SAXReader(); int sortNo = 1; try {/*from ww w. j a v a2 s . c om*/ Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); List<?> rows = root.elements(); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); String id = element.attributeValue("id"); Map<String, Object> rowMap = new java.util.HashMap<String, Object>(); rowMap.put("id", id); List<?> properties = element.elements("property"); Iterator<?> iter = properties.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String propertyName = elem.attributeValue("name"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { rowMap.put(propertyName, propertyValue); } } Todo model = new Todo(); model.setSortNo(sortNo++); Tools.populate(model, rowMap); todos.add(model); } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex.getMessage()); } return todos; }
From source file:com.glaf.core.util.Dom4jUtils.java
License:Apache License
/** * ??/*from w w w. j a va 2s .com*/ * * @param inputStream * InputStream * @param xpath * String * @return Element * @throws Exception */ public static Element getElementCopy(InputStream inputStream, String xpath) throws Exception { if (xpath == null) { return toElement(inputStream); } SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element element = (Element) root.selectSingleNode(xpath); return element; }
From source file:com.glaf.core.util.Dom4jUtils.java
License:Apache License
/** * XML//from www. ja va 2 s . com * * @param filename * ?? * @return XML * @throws Exception */ public static Document loadDocument(String filename) throws Exception { SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(filename); return doc; }
From source file:com.glaf.core.util.Dom4jUtils.java
License:Apache License
/** * ???/*from w w w . ja va 2 s . co m*/ * * @param bytes * byte[] * @return Document * @throws Exception */ public static Document toDocument(byte[] bytes) { InputStream inputStream = null; try { inputStream = new ByteArrayInputStream(bytes); SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(inputStream); return doc; } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException ex) { } } }
From source file:com.glaf.core.util.Dom4jUtils.java
License:Apache License
/** * ???/* w w w.j a va2s . c o m*/ * * @param inputStream * * @return Document * @throws Exception */ public static Document toDocument(java.io.InputStream inputStream) { try { SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(inputStream); return doc; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.glaf.core.util.Dom4jUtils.java
License:Apache License
/** * ???/*from w w w.j av a2s . c o m*/ * * @param reader * * @return Document * @throws Exception */ public static Document toDocument(java.io.Reader reader) { try { SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(reader); return doc; } catch (Exception ex) { throw new RuntimeException(ex); } }