List of usage examples for org.dom4j DocumentHelper parseText
public static Document parseText(String text) throws DocumentException
parseText
parses the given text as an XML document and returns the newly created Document.
From source file:com.gtrj.docdeal.ui.GalleryFileActivity.java
License:Open Source License
private String parseXml(String xml) { try {//from ww w .j av a2 s.c o m File file = new File(ContextString.FilePath + File.separator + "xml.txt"); FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(xml.getBytes()); Document document = DocumentHelper.parseText(xml); Element root = document.getRootElement(); Element totalPageElement = root.element(""); Element currentPageElement = root.element("?"); Element pictureElement = root.element(""); totalPage = Integer.parseInt(totalPageElement.getText()); String pageNum = currentPageElement.getText(); String path = Base64Util.decoderBase64FileWithFileName(pictureElement.getText(), pageNum + ".jpg", this); return path; } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.haier.wxpt.yqfw.util.MiniTemplator.java
License:Open Source License
public Document generateOutputXml() throws Exception { try {//from w w w. j av a 2 s. co m String output = generateOutput(); //System.out.println(output); return DocumentHelper.parseText(output); } catch (Exception ex) { throw ex; } }
From source file:com.haulmont.cuba.core.app.EntitySnapshotManager.java
License:Apache License
protected String processSnapshotXml(String snapshotXml, Map<Class, Class> classMapping) { if (!isXml(snapshotXml)) { return snapshotXml; }/*from w w w . jav a 2s. c om*/ Document document; try { document = DocumentHelper.parseText(snapshotXml); } catch (DocumentException e) { throw new RuntimeException("Couldn't parse snapshot xml content", e); } replaceClasses(document.getRootElement(), classMapping); replaceInXmlTree(document.getRootElement(), classMapping); return document.asXML(); }
From source file:com.haulmont.cuba.gui.components.filter.UserSetHelper.java
License:Apache License
public static String removeEntities(String filterXml, Collection ids) { Document document;//from w w w. j a v a 2 s . c om 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(); }
From source file:com.haulmont.cuba.gui.components.filter.UserSetHelper.java
License:Apache License
public static String addEntities(String filterXml, Collection ids) { Document document;/*from w ww . j a v a2 s . c o m*/ 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(); }
From source file:com.hazzard.gui.PiNet.java
public void parse(String text) throws DocumentException { Document document = DocumentHelper.parseText(text.trim()); System.out.println(text);/*from w w w . ja v a 2 s . c o m*/ if (document.getRootElement().getName().equals("syncData")) { List data; data = document.selectNodes("/syncData/*"); Iterator<Element> iterator = data.iterator(); while (iterator.hasNext()) { Element current = iterator.next(); if (current.getName().equals("RaceInfo")) { raceInfo.time = Integer .parseInt(document.selectSingleNode("/syncData/RaceInfo/Time").getText()); raceInfo.laps = Integer .parseInt(document.selectSingleNode("/syncData/RaceInfo/Laps").getText()); raceInfo.joinedPlayers = Integer .parseInt(document.selectSingleNode("/syncData/RaceInfo/JoinedPlayers").getText()); } else if (current.getName().equals("PlayerInfo1")) { playerInfo1.currentLap = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo1/CurrentLap").getText()); playerInfo1.relativeTime = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo1/RelativeTime").getText()); playerInfo1.speed = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo1/Speed").getText()); playerInfo1.turn = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo1/Turn").getText()); playerInfo1.position = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo1/Position").getText()); playerInfo1.finished = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo1/Finished").getText()); } else if (current.getName().equals("PlayerInfo2")) { playerInfo2.currentLap = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo2/CurrentLap").getText()); playerInfo2.relativeTime = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo2/RelativeTime").getText()); playerInfo2.speed = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo2/speed").getText()); playerInfo2.turn = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo2/Turn").getText()); playerInfo2.position = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo2/Position").getText()); playerInfo2.finished = Integer .parseInt(document.selectSingleNode("/syncData/PlayerInfo2/Finished").getText()); } } } }
From source file:com.heren.turtle.entry.command.AbstractCommand.java
License:Open Source License
@Override public void startAll(String args) throws Exception { Document document = DocumentHelper.parseText(args); Element root = document.getRootElement(); List elements = root.elements(); List<Map<String, String>> eachElement = XmlUtils.getEachElement(elements); for (Map<String, String> map : eachElement) { String eleName = map.get("eleName"); String name = map.get("name"); String ip = map.get("ip"); String port = map.get("port"); String nameSuffix = map.get("nameSuffix"); String status = map.get("status"); String needToFilter = map.get("needToFilter"); String method = map.get("method"); String methodType = map.get("methodType"); Class<?> aClass = Class.forName(name); if (Boolean.valueOf(status) && eleName.equals("Soap")) { Command command = new SoapCommand(aClass, Boolean.valueOf(needToFilter), Integer.parseInt(port), ip, nameSuffix);//w w w .j ava 2s.co m command.start(); } else if (Boolean.valueOf(status) && eleName.equals("Rest")) { Command command = new RestCommand(aClass, Boolean.valueOf(needToFilter), Integer.parseInt(port), ip, nameSuffix); command.start(); } else if (Boolean.valueOf(status) && eleName.equals("Netty")) { Command command = new NettyCommand(aClass, Boolean.valueOf(needToFilter), Integer.parseInt(port), method, methodType); command.start(); } } }
From source file:com.heren.turtle.gear.meta.AbstractService.java
License:Open Source License
protected Map<String, Object> getMessage(String message) throws DocumentException { Document document = DocumentHelper.parseText(message); Element rootElement = document.getRootElement(); List elements = rootElement.elements(); Map<String, Object> result = new HashMap<String, Object>(); for (Iterator it = elements.iterator(); it.hasNext();) { Element subElement = (Element) it.next(); if (subElement.isTextOnly()) { result.put(subElement.getName(), subElement.getTextTrim()); } else {//from w w w. ja v a 2s.c o m List<String> subList = new ArrayList<String>(); List subEle = subElement.elements(); for (Iterator iterator = subEle.iterator(); iterator.hasNext();) { Element itemElements = (Element) iterator.next(); subList.add(itemElements.getTextTrim()); } result.put(subElement.getName(), subList); } } return result; }
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
/** * is xml//from w w w.j ava 2 s .c o m * * @param value * @return */ public static boolean isXml(String value) { try { DocumentHelper.parseText(replaceWrongPart(value)); } catch (DocumentException e) { return false; } return true; }
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
/** * delete the label of xml that is not use * * @param message/*from w ww . ja v a2 s . c om*/ * @return */ public static Map<String, Object> getMessage(String message) throws DocumentException { message = replaceWrongPart(message); Document document = DocumentHelper.parseText(message); Element rootElement = document.getRootElement(); Element request = rootElement.element("request"); List elements = request.elements(); Map<String, Object> result = new HashMap<>(); for (Object element : elements) { Element subElement = (Element) element; if (subElement.isTextOnly()) { result.put(subElement.getName(), subElement.getTextTrim()); } else { List<String> subList = new ArrayList<>(); List subEle = subElement.elements(); for (Object aSubEle : subEle) { Element itemElements = (Element) aSubEle; subList.add(itemElements.getTextTrim()); } result.put(subElement.getName(), subList); } } return result; }