Java Code Examples for org.dom4j.Document#asXML()
The following examples show how to use
org.dom4j.Document#asXML() .
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: RemoteArticleService.java From boubei-tss with Apache License 2.0 | 6 votes |
public String getArticleXML(Long articleId) { Article article = articleDao.getEntity(articleId); if(article == null || checkBrowsePermission(article.getChannel().getId() ) < 0 ) { return ""; // 如果文章不存在 或 对文章所在栏目没有浏览权限 } String pubUrl = article.getPubUrl(); Document articleDoc = XMLDocUtil.createDocByAbsolutePath2(pubUrl); Element articleElement = articleDoc.getRootElement(); Element hitRateNode = (Element) articleElement.selectSingleNode("//hitCount"); hitRateNode.setText(article.getHitCount().toString()); // 更新点击率 Document doc = org.dom4j.DocumentHelper.createDocument(); Element articleInfoElement = doc.addElement("Response").addElement("ArticleInfo"); articleInfoElement.addElement("rss").addAttribute("version", "2.0").add(articleElement); // 添加文章点击率; HitRateManager.getInstanse("cms_article").output(articleId); return doc.asXML(); }
Example 2
Source File: PersistDefinationTest.java From bulbasaur with Apache License 2.0 | 6 votes |
@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 3
Source File: TaskTest.java From bulbasaur with Apache License 2.0 | 6 votes |
@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: StatsGraphServlet.java From document-management-system with GNU General Public License v2.0 | 6 votes |
/** * Convert a piechartdata to xml * * @author [email protected] */ public String repoStatsXML(final String title, final DefaultPieDataset dataset) throws IOException, ServletException { Document document = DocumentHelper.createDocument(); Element root = document.addElement("RepoStats"); root.addElement("Title").addCDATA(title); Element dataSetElement = root.addElement("DataSet"); for (int i = 0; i < dataset.getItemCount(); i++) { Element itemElement = dataSetElement.addElement("Item"); itemElement.addElement("name").addCDATA(dataset.getKey(i).toString()); itemElement.addAttribute("percent", dataset.getValue(i).toString()); dataSetElement.add(itemElement); } return document.asXML(); }
Example 5
Source File: FavoritesMenu.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
public void storeAsUserPref() { if (CollectionUtils.isEmpty(menuEntries) == true) { UserPreferencesHelper.putEntry(USER_PREF_FAVORITES_MENU_ENTRIES_KEY, "", true); UserPreferencesHelper.removeEntry(USER_PREF_FAVORITES_MENU_KEY); return; } final Document document = DocumentHelper.createDocument(); final Element root = document.addElement("root"); for (final MenuEntry menuEntry : menuEntries) { buildElement(root.addElement("item"), menuEntry); } final String xml = document.asXML(); if (xml.length() > UserXmlPreferencesDO.MAX_SERIALIZED_LENGTH) { throw new UserException("menu.favorite.maxSizeExceeded"); } UserPreferencesHelper.putEntry(USER_PREF_FAVORITES_MENU_ENTRIES_KEY, xml, true); UserPreferencesHelper.putEntry(USER_PREF_FAVORITES_MENU_KEY, this, false); if (log.isDebugEnabled() == true) { log.debug("Favorites menu stored: " + xml); } log.info("Favorites menu stored: " + xml); }
Example 6
Source File: XmlUtil.java From das with Apache License 2.0 | 5 votes |
public static org.w3c.dom.Document parse(Document doc) throws Exception { if (doc == null) { return (null); } java.io.StringReader reader = new java.io.StringReader(doc.asXML()); org.xml.sax.InputSource source = new org.xml.sax.InputSource(reader); javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); javax.xml.parsers.DocumentBuilder documentBuilder = documentBuilderFactory. newDocumentBuilder(); return (documentBuilder.parse(source)); }
Example 7
Source File: AppiumNativePageSourceHandler.java From agent with MIT License | 5 votes |
public String handle(String pageSource) throws IOException, DocumentException { if (StringUtils.isEmpty(pageSource)) { throw new IllegalArgumentException("pageSource cannot be empty"); } try (InputStream in = new ByteArrayInputStream(pageSource.getBytes(Charset.forName("UTF-8")))) { SAXReader saxReader = new SAXReader(); saxReader.setEncoding("UTF-8"); Document document = saxReader.read(in); handleElement(document.getRootElement()); return document.asXML(); } }
Example 8
Source File: XmlUtil.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
public static String appendToNode(String xmlFileName, String nodeName, String value) throws DocumentException, IOException { SAXReader sr = new SAXReader(); // 需要导入jar包:dom4j // 关联xml Document document = sr.read(xmlFileName); // 获取根元素 Element root = document.getRootElement(); boolean append = appendToNode(root, nodeName, value); if (append) { String asXML = document.asXML(); // saveDocument(document, new File(xmlFileName)); return asXML; } return null; }
Example 9
Source File: XmlMapperTest.java From vjtools with Apache License 2.0 | 5 votes |
/** * 使用Dom4j生成测试用的XML文档字符串. */ private static String generateXmlByDom4j() { Document document = DocumentHelper.createDocument(); Element root = document.addElement("user").addAttribute("id", "1"); root.addElement("name").setText("calvin"); // List<String> Element interests = root.addElement("interests"); interests.addElement("interest").addText("movie"); interests.addElement("interest").addText("sports"); return document.asXML(); }
Example 10
Source File: BatchResponseDsml.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Converts this Batch Response to its XML representation in the DSMLv2 format. * * @param prettyPrint if true, formats the document for pretty printing * @return the XML representation in DSMLv2 format */ public String toDsml( boolean prettyPrint ) { Document document = DocumentHelper.createDocument(); Element element = document.addElement( "batchResponse" ); element.add( ParserUtils.DSML_NAMESPACE ); element.add( ParserUtils.XSD_NAMESPACE ); element.add( ParserUtils.XSI_NAMESPACE ); // RequestID if ( requestID != 0 ) { element.addAttribute( "requestID", Integer.toString( requestID ) ); } for ( DsmlDecorator<? extends Response> response : responses ) { response.toDsml( element ); } if ( prettyPrint ) { document = ParserUtils.styleDocument( document ); } return document.asXML(); }
Example 11
Source File: PersistParserTest.java From bulbasaur with Apache License 2.0 | 5 votes |
@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: PersistParserTest.java From bulbasaur with Apache License 2.0 | 5 votes |
@Test public void testMachineRunWithPersistParser() { 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(); int definitionVersion = DefinitionHelper.getInstance().deployDefinition("persist_definition","测试", definitionContent, true).getDefinitionVersion(); PersistMachine p = persistMachineFactory.newInstance(String.valueOf(System.currentTimeMillis()), "persist_definition"); Assert.assertEquals(definitionVersion, p.getProcessVersion()); Map m = new HashMap(); m.put("goto", 2); m.put("_i", 3); p.addContext(m); p.run(); Assert.assertEquals(6, p.getContext("_a")); }
Example 13
Source File: UserSetHelper.java From cuba with Apache License 2.0 | 5 votes |
public static String removeEntities(String filterXml, Collection ids) { Document document; try { document = DocumentHelper.parseText(filterXml); } catch (DocumentException e) { throw new RuntimeException(e); } Element param = document.getRootElement().element("and").element("c").element("param"); String currentIds = param.getTextTrim(); Set<String> set = parseSet(currentIds); String listOfIds = removeIds(set, ids); param.setText(listOfIds); return document.asXML(); }
Example 14
Source File: UserSetHelper.java From cuba with Apache License 2.0 | 5 votes |
public static String addEntities(String filterXml, Collection ids) { Document document; try { document = DocumentHelper.parseText(filterXml); } catch (DocumentException e) { throw new RuntimeException(e); } Element param = document.getRootElement().element("and").element("c").element("param"); String currentIds = param.getTextTrim(); Set<String> set = parseSet(currentIds); String listOfIds = createIdsString(set, ids); param.setText(listOfIds); return document.asXML(); }
Example 15
Source File: XmlUtil.java From mybatis-daoj with Apache License 2.0 | 2 votes |
/** * XML转字符串 * * @param document * @return * @throws org.dom4j.DocumentException */ public static String toText(Document document) { return document.asXML(); }