Java Code Examples for org.dom4j.DocumentException#printStackTrace()

The following examples show how to use org.dom4j.DocumentException#printStackTrace() . 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: BeanUtil.java    From anyline with Apache License 2.0 6 votes vote down vote up
public static Map<String,Object> xml2map(String xml){ 
	Map<String,Object> map = new HashMap<String,Object>(); 
	Document document; 
	try { 
		document =  DocumentHelper.parseText(xml);  
		Element root = document.getRootElement(); 
		for(Iterator<Element> itrProperty=root.elementIterator(); itrProperty.hasNext();){ 
			Element element = itrProperty.next(); 
			String key = element.getName(); 
			String value = element.getTextTrim(); 
			map.put(key, value); 
		} 
	} catch (DocumentException e) { 
		e.printStackTrace(); 
	} 
	return map; 
}
 
Example 2
Source File: XmlMapper.java    From frpMgr with MIT License 6 votes vote down vote up
/**
 * xml转map 带属性
 * @param xmlStr
 * @param needRootKey 是否需要在返回的map里加根节点键
 * @return
 * @throws DocumentException
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> xmlToMapWithAttr(String xmlStr, boolean needRootKey) {
	try {
		Document doc = DocumentHelper.parseText(xmlStr);
		Element root = doc.getRootElement();
		Map<String, Object> map = (Map<String, Object>) xmlToMapWithAttr(root);
		if (root.elements().size() == 0 && root.attributes().size() == 0) {
			return map; //根节点只有一个文本内容
		}
		if (needRootKey) {
			//在返回的map里加根节点键(如果需要)
			Map<String, Object> rootMap = new HashMap<String, Object>();
			rootMap.put(root.getName(), map);
			return rootMap;
		}
		return map;
	} catch (DocumentException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 3
Source File: TaskTest.java    From bulbasaur with Apache License 2.0 6 votes vote down vote up
@Test
public void testdeployDefinition() {
    // 初始化

    SAXReader reader = new SAXReader();
    // 拿不到信息
    //URL url = this.getClass().getResource("/multipleTask.xml");
    URL url = this.getClass().getResource("/singleTask.xml");
    Document document = null;
    try {
        document = reader.read(url);
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String definitionContent = document.asXML();
    // deploy first time
    DefinitionHelper.getInstance().deployDefinition("singleTask", "测试单人任务流程", definitionContent, true);
    //DefinitionHelper.getInstance().deployDefinition("multipleTask", "测试多人任务流程", definitionContent, true);
}
 
Example 4
Source File: PersistDefinationTest.java    From bulbasaur with Apache License 2.0 6 votes vote down vote up
@Test
public void testdeployDefinition() {
    // 初始化

    SAXReader reader = new SAXReader();
    // 拿不到信息
    URL url = this.getClass().getResource("/process12.xml");
    Document document = null;
    try {
        document = reader.read(url);
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String definitionContent = document.asXML();
    // deploy first time
    DefinitionHelper.getInstance().deployDefinition("process", "测试流程", definitionContent, true);
}
 
Example 5
Source File: OpenwxController.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
   * 保存Ticket
   * @param xml
   */
  void processAuthorizationEvent(String xml){
  	Document doc;
try {
	doc = DocumentHelper.parseText(xml);
	Element rootElt = doc.getRootElement();
	String ticket = rootElt.elementText("ComponentVerifyTicket");
	if(oConvertUtils.isNotEmpty(ticket)){
		LogUtil.info("8、推送component_verify_ticket协议-----------ticket = "+ticket);
		WeixinOpenAccountEntity  entity = getWeixinOpenAccount(APPID);
		entity = entity==null?new WeixinOpenAccountEntity():entity;
		entity.setTicket(ticket);
		entity.setAppid(APPID);
		entity.setGetTicketTime(new Date());
		systemService.saveOrUpdate(entity);
	}
} catch (DocumentException e) {
	e.printStackTrace();
}
  }
 
Example 6
Source File: XMLUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    Document document = testCreateXMLFile();
    String filePath = "d:/temp/test_create.xml";
    saveXml(filePath, document);

    document = testModifyXMLFile(filePath);
    String modifyPath = "d:/temp/test_modify.xml";
    saveXml(modifyPath, document);

    // 读取xml文档
    Document doc;
    try {
        doc = loadXmlFile(filePath);
        List<Element> listEl = doc.getRootElement().elements();

        print(listEl);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: Feature.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static List<Feature> loadXml2(File file) {
    if (!file.exists()) {
        return new ArrayList<Feature>();
    }
    Document document = null;
    try {
        document = XMLUtil.loadXmlFile(file);
    } catch (DocumentException e) {
    	e.printStackTrace();
    	return null;
    }
    Element rootElement = document.getRootElement();
    List<Element> featureElementList = rootElement.elements("feature");
    return parseFeature2(featureElementList);
}
 
Example 8
Source File: OpenwxController.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
    * 获取授权的Appid
    * @param xml
    * @return
    */
String getAuthorizerAppidFromXml(String xml) {
	Document doc;
	try {
		doc = DocumentHelper.parseText(xml);
		Element rootElt = doc.getRootElement();
		String toUserName = rootElt.elementText("ToUserName");
		return toUserName;
	} catch (DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
Example 9
Source File: Feature.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static List<Feature> loadXml(File file) {
    if (!file.exists()) {
        return new ArrayList<Feature>();
    }
    Document document = null;
    try {
        document = XMLUtil.loadXmlFile(file);
    } catch (DocumentException e) {
    	e.printStackTrace();
    	return null;
    }
    Element rootElement = document.getRootElement();
    List<Element> featureElementList = rootElement.elements("feature");
    return parseFeature(featureElementList);
}
 
Example 10
Source File: WTKTiledMap.java    From javafx-TKMapEditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 读取地图
 * 
 * @param is
 *            地图文件流
 */
public void readMap(InputStream is) {
	isLoadFinished = false;
	mapLayerList.clear();
	// 清空所有资源
	try {
		Document document = saxReader.read(is);
		readMap(document);
		isLoadFinished = true;
	} catch (DocumentException e) {
		WLog.logInFile("Load Map File Error:" + e.toString());
		e.printStackTrace();
	}
}
 
Example 11
Source File: PersistParserTest.java    From bulbasaur with Apache License 2.0 5 votes vote down vote up
@Test
public void testPersistParser() {

    // deploy 2 version of definition first

    SAXReader reader = new SAXReader();
    // 拿不到信息
    URL url = this.getClass().getResource("/persist_definition.xml");
    Document document = null;
    try {
        document = reader.read(url);
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String definitionContent = document.asXML();

    DefinitionHelper.getInstance().deployDefinition("persist_definition", "测试", definitionContent, true);
    DefinitionHelper.getInstance().deployDefinition("persist_definition", "测试", definitionContent, true);

    Definition definition = persistParser.parse("persist_definition", 0);
    Assert.assertEquals("persist_definition", definition.getName());
    Assert.assertEquals(2, definition.getVersion());
    Assert.assertNotNull(definition.getState("i'm start"));
    Definition definition1 = persistParser.parse("persist_definition", 1);
    Assert.assertEquals(1, definition1.getVersion());
}
 
Example 12
Source File: ConfigManager.java    From WeSync with MIT License 5 votes vote down vote up
/**
 * 读取xml,加载到dom
 */
public void reloadDom() {
    SAXReader reader = new SAXReader();
    try {
        document = reader.read(new File(ConstantsTools.PATH_CONFIG));
    } catch (DocumentException e) {
        e.printStackTrace();
        logger.error("Read config xml error:" + e.toString());
    }
}
 
Example 13
Source File: MapUtil.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 描述:遍历XML
 * 
 * @param filename
 *            XML文件位置
 * @param map
 *            存储数据的HashMap数组
 */
private static void iterateWholeXML(String filename,
		HashMap<String, String> map) {
	SAXReader saxReader = new SAXReader();
	try {
		org.jeecgframework.core.util.LogUtil.info("filename="+filename);
		Document document = saxReader.read(new File(filename));
		Element root = document.getRootElement();
		for (Iterator<?> iterProvince = root.elementIterator(); iterProvince
				.hasNext();) {
			Element province = (Element) iterProvince.next();
			for (Iterator<?> iterCity = province.elementIterator(); iterCity
					.hasNext();) {
				Element city = (Element) iterCity.next();
				for (Iterator<?> iterCountry = city.elementIterator(); iterCountry
						.hasNext();) {
					Element country = (Element) iterCountry.next();
					String name = country.attributeValue("name");
					String code = country.attributeValue("weatherCode");
					map.put(name, code);
				}
			}
		}
	} catch (DocumentException e) {
		e.printStackTrace();
	}
}
 
Example 14
Source File: Dom4JParser.java    From tutorials with MIT License 5 votes vote down vote up
public Node getElementsListByTitle(String name) {
    try {
        SAXReader reader = new SAXReader();
        Document document = reader.read(file);
        List<Node> elements = document.selectNodes("//tutorial[descendant::title[text()=" + "'" + name + "'" + "]]");
        return elements.get(0);
    } catch (DocumentException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 15
Source File: PluginServiceImpl.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public void getPluginXml(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	InputStream pluginStream = this.getClass().getClassLoader().getResourceAsStream("plugins.xml");
	Document document = null;  
	resp.setContentType("text/xml;charset=utf-8");   
	PrintWriter out = resp.getWriter();
	SAXReader reader = new SAXReader(); 
	try {
		document = reader.read(pluginStream);
		out.print(document.asXML());
	} catch (DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 16
Source File: DOM4JUtil.java    From TAC with MIT License 5 votes vote down vote up
public static Document xml2Dom4j(String filePath){
    SAXReader reader = new SAXReader();
    Document document = null;
    try {
        // 通过reader对象的read方法加载xml文件,获取docuemnt对象。
        document = reader.read(new File(filePath));
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    return document;
}
 
Example 17
Source File: Dom4JParser.java    From tutorials with MIT License 5 votes vote down vote up
public List<Element> getFirstElementList() {
    try {
        SAXReader reader = new SAXReader();
        Document document = reader.read(file);
        return document.getRootElement().elements();
    } catch (DocumentException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 18
Source File: Feature.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static List<Feature> loadXml3(File file) {
    if (!file.exists()) {
        return new ArrayList<Feature>();
    }
    Document document = null;
    try {
        document = XMLUtil.loadXmlFile(file);
    } catch (DocumentException e) {
    	e.printStackTrace();
    	return null;
    }
    Element rootElement = document.getRootElement();
    List<Element> featureElementList = rootElement.elements("feature");
    return parseFeature3(featureElementList);
}
 
Example 19
Source File: OpenWxController.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
    * 获取授权的Appid
    * @param xml
    * @return
    */
String getAuthorizerAppidFromXml(String xml) {
	Document doc;
	try {
		doc = DocumentHelper.parseText(xml);
		Element rootElt = doc.getRootElement();
		String toUserName = rootElt.elementText("ToUserName");
		return toUserName;
	} catch (DocumentException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 20
Source File: XMLUtil.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 修改XML文件
 * @param fileName
 * @param newFileName
 * @return
 */
private static Document testModifyXMLFile(String fileName) {
    SAXReader reader = new SAXReader();
    Document document = null;
    try {
        document = reader.read(new File(fileName));
        // 用xpath查找对象
        List<?> list = document.selectNodes("/catalog/journal/@title");
        Iterator<?> itr = list.iterator();
        while (itr.hasNext()) {
            Attribute attribute = (Attribute) itr.next();
            if (attribute.getValue().equals("XML Zone")) {
                attribute.setText("Modi XML");
            }
        }
        // 在journal元素中增加date元素
        list = document.selectNodes("/catalog/journal");
        itr = list.iterator();
        if (itr.hasNext()) {
            Element journalElement = (Element) itr.next();
            Element dateElement = journalElement.addElement("date");
            dateElement.setText("2006-07-10");
            dateElement.addAttribute("type", "Gregorian calendar");
        }
        // 删除title接点
        list = document.selectNodes("/catalog/journal/article");
        itr = list.iterator();
        while (itr.hasNext()) {
            Element articleElement = (Element) itr.next();
            Iterator<Element> iter = articleElement.elementIterator("title");
            while (iter.hasNext()) {
                Element titleElement = (Element) iter.next();
                if (titleElement.getText().equals("Dom4j Create XML Schema")) {
                    articleElement.remove(titleElement);
                }
            }
        }

    } catch (DocumentException e) {
        e.printStackTrace();
    }

    return document;

}