org.dom4j.io.SAXReader Java Examples

The following examples show how to use org.dom4j.io.SAXReader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VersionProperty.java    From jfinal-api-scaffold with MIT License 6 votes vote down vote up
/**
 * Builds the document XML model up based the given reader of XML data.
 * @param in the input stream used to build the xml document
 * @throws java.io.IOException thrown when an error occurs reading the input stream.
 */
private void buildDoc(Reader in) throws IOException {
    try {
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        document = xmlReader.read(in);
        buildNowVersion();
    }
    catch (Exception e) {
        Log.error("Error reading XML properties", e);
        throw new IOException(e.getMessage());
    }
    finally {
        if (in != null) {
            in.close();
        }
    }
}
 
Example #2
Source File: AlipaySubmit.java    From jframe with Apache License 2.0 6 votes vote down vote up
/**
    * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
    * 注意:远程解析XML出错,与服务器是否支持SSL等配置有关
    * @return 时间戳字符串
    * @throws Exception 
    * @throws UnsupportedEncodingException 
    * @throws IOException
    * @throws DocumentException
    * @throws MalformedURLException
    */
public static Map<String,String> parseRespose(String reponse) throws Exception {
	Map<String,String> respMap = new HashMap<String,String>();
	
	try {
		SAXReader reader = new SAXReader();
		Document doc = reader.read(new ByteArrayInputStream(reponse.getBytes("GBK")));
		Node isSuccessNode = doc.selectSingleNode("//alipay/is_success");
		if (isSuccessNode.getText().equals("T")) {
		    // 判断是否有成功标示
		    Node tradeStatusNode = doc.selectSingleNode("//response/trade/trade_status");
		    respMap.put("trade_status", tradeStatusNode.getText());
		}
		respMap.put("is_success", isSuccessNode.getText());
	} catch (Exception e) {
		LOG.error(e.getMessage(),reponse);
	}
	
	return respMap;
   }
 
Example #3
Source File: ComponentFinder.java    From Whack with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the value of an element selected via an xpath expression from
 * a component's component.xml file.
 *
 * @param component the component.
 * @param xpath the xpath expression.
 * @return the value of the element selected by the xpath expression.
 */
private String getElementValue(Component component, String xpath) {
    File componentDir = componentDirs.get(component);
    if (componentDir == null) {
        return null;
    }
    try {
        File componentConfig = new File(componentDir, "component.xml");
        if (componentConfig.exists()) {
            SAXReader saxReader = new SAXReader();
            Document componentXML = saxReader.read(componentConfig);
            Element element = (Element)componentXML.selectSingleNode(xpath);
            if (element != null) {
                return element.getTextTrim();
            }
        }
    }
    catch (Exception e) {
        manager.getLog().error(e);
    }
    return null;
}
 
Example #4
Source File: XmlUtil.java    From weChatRobot with MIT License 6 votes vote down vote up
/**
 * 解析xml
 */
@SuppressWarnings("unchecked")
public static Map<String, String> parseXml(InputStream inputStream) throws Exception {

    Map<String, String> map = Maps.newHashMap();
    SAXReader reader = new SAXReader();
    Document document = reader.read(inputStream);
    //得到xml根元素
    Element root = document.getRootElement();
    //得到根元素的所有子节点
    List<Element> elementList = root.elements();
    //遍历所有子节点
    for (Element e : elementList) {
        map.put(e.getName(), e.getText());
    }
    //关闭流
    inputStream.close();

    return map;
}
 
Example #5
Source File: CheckboxTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void collectionOfPetsAsStringNotSelected() throws Exception {
	this.tag.setPath("pets");
	this.tag.setValue("Santa's Little Helper");

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("pets", checkboxElement.attribute("name").getValue());
	assertNull(checkboxElement.attribute("checked"));
}
 
Example #6
Source File: CheckboxTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void withSingleValueNull() throws Exception {
	this.bean.setName(null);
	this.tag.setPath("name");
	this.tag.setValue("Rob Harrop");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("name", checkboxElement.attribute("name").getValue());
	assertNull(checkboxElement.attribute("checked"));
	assertEquals("Rob Harrop", checkboxElement.attribute("value").getValue());
}
 
Example #7
Source File: CheckboxTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void withSingleValueBooleanObjectChecked() throws Exception {
	this.tag.setPath("someBoolean");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);
	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();
	assertEquals("Both tag and hidden element not rendered", 2, rootElement.elements().size());
	Element checkboxElement = (Element) rootElement.elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("someBoolean1", checkboxElement.attribute("id").getValue());
	assertEquals("someBoolean", checkboxElement.attribute("name").getValue());
	assertEquals("checked", checkboxElement.attribute("checked").getValue());
	assertEquals("true", checkboxElement.attribute("value").getValue());
}
 
Example #8
Source File: CheckboxTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void collectionOfPets() throws Exception {
	this.tag.setPath("pets");
	this.tag.setValue(new Pet("Rudiger"));

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("pets", checkboxElement.attribute("name").getValue());
	assertEquals("Rudiger", checkboxElement.attribute("value").getValue());
	assertEquals("checked", checkboxElement.attribute("checked").getValue());
}
 
Example #9
Source File: CheckboxTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void collectionOfPetsAsStringNotSelected() throws Exception {
	this.tag.setPath("pets");
	this.tag.setValue("Santa's Little Helper");

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("pets", checkboxElement.attribute("name").getValue());
	assertNull(checkboxElement.attribute("checked"));
}
 
Example #10
Source File: OptionsTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void withoutItems() throws Exception {
	this.tag.setItemValue("isoCode");
	this.tag.setItemLabel("name");
	this.selectTag.setPath("testBean");

	this.selectTag.doStartTag();
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);
	this.tag.doEndTag();
	this.selectTag.doEndTag();

	String output = getOutput();
	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();

	List children = rootElement.elements();
	assertEquals("Incorrect number of children", 0, children.size());
}
 
Example #11
Source File: Identity.java    From hermes with Apache License 2.0 6 votes vote down vote up
private static Document creXmlDoc(String xmlStr) {
	if (Strings.empty(xmlStr)) {
		throw new RuntimeException("参数不能为空");
	}
	SAXReader saxReader = new SAXReader();
	Document document = null;
	try {
		document = saxReader.read(new ByteArrayInputStream(xmlStr.getBytes("UTF-8")));
		Element rootElement = document.getRootElement();
		String getXMLEncoding = document.getXMLEncoding();
		String rootname = rootElement.getName();
		System.out.println("getXMLEncoding>>>" + getXMLEncoding + ",rootname>>>" + rootname);
		OutputFormat format = OutputFormat.createPrettyPrint();
		/** 指定XML字符集编码 */
		format.setEncoding("UTF-8");
		Logger.info(xmlStr);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return document;
}
 
Example #12
Source File: Bilibili.java    From VideoHelper with MIT License 6 votes vote down vote up
/**
 * timeLength, fileSize, urls
 *
 * @param epReqApi
 * @throws IOException
 * @throws DocumentException
 */
private void parseEpApiResponse(String epReqApi) throws IOException, DocumentException {
    String response = HttpUtil.getResponseContent(epReqApi);

    SAXReader reader = new SAXReader();
    org.dom4j.Element rootElement = reader.read(new ByteArrayInputStream(response.getBytes("utf-8"))).getRootElement();

    timeLength = Integer.parseInt(rootElement.element("timelength").getText().trim());

    List<org.dom4j.Element> elements = rootElement.elements("durl");

    for (org.dom4j.Element ele : elements) {
        int curSize = Integer.parseInt(ele.element("size").getText());
        fileSize += curSize;

        String url = ele.element("url").getText();
        urls.add(url);
    }

    println(fileName + ": " + fileSize / 1024 / 1024 + "M");
}
 
Example #13
Source File: Dom4JReader.java    From liteFlow with Apache License 2.0 6 votes vote down vote up
public static Document getDocument(Reader reader) throws DocumentException, IOException {
    SAXReader saxReader = new SAXReader();

    Document document = null;
    try {
        document = saxReader.read(reader);
    } catch (DocumentException e) {
        throw e;
    } finally {
        if (reader != null) {
            reader.close();
        }
    }

    return document;
}
 
Example #14
Source File: RadioButtonsTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void hiddenElementOmittedOnDisabled() throws Exception {
	this.tag.setPath("stringArray");
	this.tag.setItems(new Object[] {"foo", "bar", "baz"});
	this.tag.setDisabled(true);
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);
	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();
	assertEquals("Both tag and hidden element rendered incorrectly", 3, rootElement.elements().size());
	Element spanElement = (Element) document.getRootElement().elements().get(0);
	Element radioButtonElement = (Element) spanElement.elements().get(0);
	assertEquals("input", radioButtonElement.getName());
	assertEquals("radio", radioButtonElement.attribute("type").getValue());
	assertEquals("stringArray", radioButtonElement.attribute("name").getValue());
	assertEquals("checked", radioButtonElement.attribute("checked").getValue());
	assertEquals("disabled", radioButtonElement.attribute("disabled").getValue());
	assertEquals("foo", radioButtonElement.attribute("value").getValue());
}
 
Example #15
Source File: RadioButtonsTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void spanElementCustomizable() throws Exception {
	this.tag.setPath("stringArray");
	this.tag.setItems(new Object[] {"foo", "bar", "baz"});
	this.tag.setElement("element");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);
	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element spanElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("element", spanElement.getName());
}
 
Example #16
Source File: BlobRoomAvailabilityService.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected Document receiveResponse() throws IOException, DocumentException {
    try {
        SessionImplementor session = (SessionImplementor)new _RootDAO().getSession();
        Connection connection = session.getJdbcConnectionAccess().obtainConnection();
        String response = null;
        try {
            CallableStatement call = connection.prepareCall(iResponseSql);
            call.registerOutParameter(1, java.sql.Types.CLOB);
            call.execute();
            response = call.getString(1);
            call.close();
        } finally {
        	session.getJdbcConnectionAccess().releaseConnection(connection);
        }
        if (response==null || response.length()==0) return null;
        StringReader reader = new StringReader(response);
        Document document = (new SAXReader()).read(reader);
        reader.close();
        return document;
    } catch (Exception e) {
        sLog.error("Unable to receive response: "+e.getMessage(),e);
        return null;
    } finally {
        _RootDAO.closeCurrentThreadSessions();
    }
}
 
Example #17
Source File: DOM4JSerializer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static DOM4JSettingsNode readSettingsFile(ImportInteraction importInteraction, FileFilter fileFilter) {
    File file = importInteraction.promptForFile(fileFilter);
    if (file == null) {
        return null;
    }

    if (!file.exists()) {
        importInteraction.reportError("File does not exist: " + file.getAbsolutePath());
        return null;  //we should really sit in a loop until they cancel or give us a valid file.
    }

    try {
        SAXReader reader = new SAXReader();
        Document document = reader.read(file);

        return new DOM4JSettingsNode(document.getRootElement());
    } catch (Throwable t) {
        LOGGER.error("Unable to read file: " + file.getAbsolutePath(), t);
        importInteraction.reportError("Unable to read file: " + file.getAbsolutePath());
        return null;
    }
}
 
Example #18
Source File: XmlUtils.java    From nbp with Apache License 2.0 6 votes vote down vote up
public Document load(String filename) {
    Document document = null;
    Reader xmlReader = null;
    InputStream stream = null;
    try {
        SAXReader saxReader = new SAXReader();
        stream = getClass().getClassLoader().getResourceAsStream(filename);
        xmlReader = new InputStreamReader(stream, "UTF-8");
        document = saxReader.read(xmlReader);
    }
    catch (Exception ex) {
        _logger.error(String.format("the filename of document is %s, error [%s]" , filename
                ,ex.getMessage()));
        document = DocumentHelper.createDocument();
        document.addElement("ROOT");
    } finally {
        closeStream(xmlReader);
        closeStream(stream);
    }
    return document;
}
 
Example #19
Source File: RadioButtonsTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void withoutItemsEnumBindTargetWithExplicitLabelsAndValues() throws Exception {
	BeanWithEnum testBean = new BeanWithEnum();
	testBean.setTestEnum(TestEnum.VALUE_2);
	getPageContext().getRequest().setAttribute("testBean", testBean);

	this.tag.setPath("testEnum");
	this.tag.setItemLabel("enumLabel");
	this.tag.setItemValue("enumValue");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = "<div>" + getOutput() + "</div>";
	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();

	assertEquals(2, rootElement.elements().size());
	Node value1 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_1']");
	Node value2 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_2']");
	assertEquals("Label: VALUE_1", rootElement.selectSingleNode("//label[@for = '" + value1.valueOf("@id") + "']").getText());
	assertEquals("Label: VALUE_2", rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText());
	assertEquals(value2, rootElement.selectSingleNode("//input[@checked]"));
}
 
Example #20
Source File: RadioButtonsTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void withoutItemsEnumBindTarget() throws Exception {
	BeanWithEnum testBean = new BeanWithEnum();
	testBean.setTestEnum(TestEnum.VALUE_2);
	getPageContext().getRequest().setAttribute("testBean", testBean);

	this.tag.setPath("testEnum");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = "<div>" + getOutput() + "</div>";
	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();

	assertEquals(2, rootElement.elements().size());
	Node value1 = rootElement.selectSingleNode("//input[@value = 'VALUE_1']");
	Node value2 = rootElement.selectSingleNode("//input[@value = 'VALUE_2']");
	assertEquals("TestEnum: VALUE_1", rootElement.selectSingleNode("//label[@for = '" + value1.valueOf("@id") + "']").getText());
	assertEquals("TestEnum: VALUE_2", rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText());
	assertEquals(value2, rootElement.selectSingleNode("//input[@checked]"));
}
 
Example #21
Source File: PageAccessFilter.java    From unitime with Apache License 2.0 6 votes vote down vote up
public void init(FilterConfig cfg) throws ServletException {
	iContext = cfg.getServletContext();
	try {
		Document config = (new SAXReader()).read(cfg.getServletContext().getResource(cfg.getInitParameter("config")));
		for (Iterator i=config.getRootElement().element("action-mappings").elementIterator("action"); i.hasNext();) {
			Element action = (Element)i.next();
			String path = action.attributeValue("path");
			String input = action.attributeValue("input");
			if (path!=null && input!=null) {
				iPath2Tile.put(path+".do", input);
			}
		}
	} catch (Exception e) {
		sLog.error("Unable to read config "+cfg.getInitParameter("config")+", reason: "+e.getMessage());
	}
	if (cfg.getInitParameter("debug-time")!=null) {
		debugTime = Long.parseLong(cfg.getInitParameter("debug-time"));
	}
	if (cfg.getInitParameter("dump-time")!=null) {
		dumpTime = Long.parseLong(cfg.getInitParameter("dump-time"));
	}
	if (cfg.getInitParameter("session-attributes")!=null) {
		dumpSessionAttribues = Boolean.parseBoolean(cfg.getInitParameter("session-attributes"));
	}
}
 
Example #22
Source File: CheckboxesTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void hiddenElementOmittedOnDisabled() throws Exception {
	this.tag.setPath("stringArray");
	this.tag.setItems(new Object[] {"foo", "bar", "baz"});
	this.tag.setDisabled(true);
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);
	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();
	assertEquals("Both tag and hidden element rendered incorrectly", 3, rootElement.elements().size());
	Element spanElement = (Element) document.getRootElement().elements().get(0);
	Element checkboxElement = (Element) spanElement.elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("stringArray", checkboxElement.attribute("name").getValue());
	assertEquals("checked", checkboxElement.attribute("checked").getValue());
	assertEquals("disabled", checkboxElement.attribute("disabled").getValue());
	assertEquals("foo", checkboxElement.attribute("value").getValue());
}
 
Example #23
Source File: SelectTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void multipleExplicitlyFalse() throws Exception {
	this.tag.setPath("name");
	this.tag.setItems(Country.getCountries());
	this.tag.setItemValue("isoCode");
	this.tag.setMultiple("false");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();
	assertEquals(1, rootElement.elements().size());

	Element selectElement = rootElement.element("select");
	assertEquals("select", selectElement.getName());
	assertEquals("name", selectElement.attribute("name").getValue());
	assertNull(selectElement.attribute("multiple"));

	List children = selectElement.elements();
	assertEquals("Incorrect number of children", 4, children.size());
}
 
Example #24
Source File: CheckboxTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void collectionOfPetsAsString() throws Exception {
	this.tag.setPath("pets");
	this.tag.setValue("Spot");

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("pets", checkboxElement.attribute("name").getValue());
	assertEquals("checked", checkboxElement.attribute("checked").getValue());
}
 
Example #25
Source File: DOM4JSerializer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static DOM4JSettingsNode readSettingsFile(ImportInteraction importInteraction, FileFilter fileFilter) {
    File file = importInteraction.promptForFile(fileFilter);
    if (file == null) {
        return null;
    }

    if (!file.exists()) {
        importInteraction.reportError("File does not exist: " + file.getAbsolutePath());
        return null;  //we should really sit in a loop until they cancel or give us a valid file.
    }

    try {
        SAXReader reader = new SAXReader();
        Document document = reader.read(file);

        return new DOM4JSettingsNode(document.getRootElement());
    } catch (Throwable t) {
        LOGGER.error("Unable to read file: " + file.getAbsolutePath(), t);
        importInteraction.reportError("Unable to read file: " + file.getAbsolutePath());
        return null;
    }
}
 
Example #26
Source File: VersionUpdater.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void getLastVersion(File controlpath){
	System.out.println("old version file path: " + controlpath.getAbsolutePath());
	String dayTag = "DayInPast";
	String versionTag = "LastDate";
	String name;
	
	/*
	this.setCvsControlPath(controlpath);
	*/
	SAXReader saxReader = new SAXReader();
	Document document = null;
	try{
		document = saxReader.read(this.cvsControlPath);
	}catch(org.dom4j.DocumentException dex){
		dex.printStackTrace();
	}
	Element rootElement = document.getRootElement();
	Iterator it = rootElement.elementIterator();
	while(it.hasNext()){
		Element element = (Element)it.next();
		name = element.getName();
		if ( name.equalsIgnoreCase(versionTag)){
			this.oldVersion = element.getText();
		}else if( name.equalsIgnoreCase(dayTag) ){
			this.daysInPast = Integer.valueOf(element.getText().trim()).intValue();

		}
	}
	
}
 
Example #27
Source File: PrivacyListProvider.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private PrivacyListProvider() {
    super();
    // Initialize the pool of sax readers
    for (int i=0; i<POOL_SIZE; i++) {
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        xmlReaders.add(xmlReader);
    }

    // Checks if the PrivacyLists database is empty. 
    // In that case, we can optimize away many database calls. 
    databaseContainsPrivacyLists = new AtomicBoolean(false);
    loadDatabaseContainsPrivacyLists();
}
 
Example #28
Source File: UpdateManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private void loadAvailablePluginsInfo() {
    Document xmlResponse;
    File file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf",
            "available-plugins.xml");
    if (!file.exists()) {
        return;
    }
    // Check read privs.
    if (!file.canRead()) {
        Log.warn("Cannot retrieve available plugins. File must be readable: " + file.getName());
        return;
    }
    try (FileReader reader = new FileReader(file)) {
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        xmlResponse = xmlReader.read(reader);
    } catch (Exception e) {
        Log.error("Error reading available-plugins.xml", e);
        return;
    }

    // Parse info and recreate available plugins
    Iterator it = xmlResponse.getRootElement().elementIterator("plugin");
    while (it.hasNext()) {
        Element plugin = (Element) it.next();
        final AvailablePlugin instance = AvailablePlugin.getInstance( plugin );
        // Add plugin to the list of available plugins at js.org
        availablePlugins.put(instance.getName(), instance);
    }
}
 
Example #29
Source File: DefaultVCardProvider.java    From Openfire with Apache License 2.0 5 votes vote down vote up
public DefaultVCardProvider() {
    super();
    // Initialize the pool of sax readers
    for (int i=0; i<POOL_SIZE; i++) {
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        xmlReaders.add(xmlReader);
    }
}
 
Example #30
Source File: XmlApiHelper.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public Document getRequest(Type requestType) throws IOException {
	Reader reader = iRequest.getReader();
	try {
		return new SAXReader().read(reader);
	} catch (DocumentException e) {
		throw new IOException(e.getMessage(), e);
	} finally {
		reader.close();
	}
}