List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:cn.com.sunjiesh.wechat.service.AbstractWechatMessageReceiveService.java
/** * ???/* w ww . j av a 2 s . c o m*/ * * @param doc4j ??Dom * @param toUserName ?? * @param fromUserName ????OpenID * @param eventKey KEY??? * @return ? * @throws ServiceException ServiceException */ protected Document locationSelectEventReceive(Document doc4j, String toUserName, String fromUserName, String eventKey) throws ServiceException { Element sendLocationInfoEle = (Element) doc4j.selectSingleNode("/xml/SendLocationInfo"); Element locationXEle = sendLocationInfoEle.element("Location_X"); Element locationYEle = sendLocationInfoEle.element("Location_Y"); Element scaleEle = sendLocationInfoEle.element("Scale"); Element labelEle = sendLocationInfoEle.element("Label"); Element poinameEle = sendLocationInfoEle.element("Poiname"); BigDecimal locationX = new BigDecimal( StringUtils.isEmpty(locationXEle.getTextTrim()) ? "0" : locationXEle.getTextTrim()); BigDecimal locationY = new BigDecimal( StringUtils.isEmpty(locationYEle.getTextTrim()) ? "0" : locationYEle.getTextTrim()); BigDecimal scale = new BigDecimal( StringUtils.isEmpty(scaleEle.getTextTrim()) ? "0" : scaleEle.getTextTrim()); String label = labelEle.getTextTrim(); String poiname = poinameEle.getTextTrim(); WechatEventLocationSelectMessageRequest wechatMessage = new WechatEventLocationSelectMessageRequest( toUserName, fromUserName, WechatReceiveMessageEventEnum.LOCATION_SELECT.toString().toLowerCase(), eventKey); WechatEventLocationSelectMessageRequest.SendLocationInfo sendLocationInfo = wechatMessage.new SendLocationInfo(); sendLocationInfo.setLocationX(locationX); sendLocationInfo.setLocationY(locationY); sendLocationInfo.setScale(scale); sendLocationInfo.setLabel(label); sendLocationInfo.setPoiname(poiname); Document respDoc4j = messageReceive(wechatMessage); return respDoc4j; }
From source file:cn.com.sunjiesh.wechat.service.AbstractWechatMessageReceiveService.java
/** * ??/*from w w w .ja v a 2s .c o m*/ * * @param doc4j ??Dom * @param toUserName ?? * @param fromUserName ????OpenID * @param eventKey KEY??? * @param event event * @return ? */ protected WechatReceiveEventPicCommonMessage getWechatReceiveEventPicCommonMessage(Document doc4j, String toUserName, String fromUserName, String eventKey, String event) { Element sendPicsInfoEle = (Element) doc4j.selectSingleNode("/xml/SendPicsInfo"); Element countNode = sendPicsInfoEle.element("Count"); List<Element> picListNodeList = sendPicsInfoEle.elements("PicList"); Integer count = Integer.parseInt(countNode.getText()); WechatReceiveEventPicCommonMessage wechatMessage = new WechatReceiveEventPicCommonMessage(toUserName, fromUserName, event, eventKey); wechatMessage.setCount(count); picListNodeList.forEach(node -> { Element itemEle = node.element("item"); Element picMd5SumEle = itemEle.element("PicMd5Sum"); String picMd5Sum = picMd5SumEle.getTextTrim(); wechatMessage.getPicsInfoList().add(wechatMessage.new SendPicsInfo(picMd5Sum)); }); return wechatMessage; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public void makeUpDocWithImportCategory(String[] schemas, TreeParent serverRoot) { if (serverRoot.getServerRoot() == null) { return;/*from www . j a v a2 s . c o m*/ } Document orgDoc = credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc; // spareDoc is meant to show the category when import digloag is launched spareDoc = (Document) orgDoc.clone(); if (schemas != null) { for (String schema : schemas) { Element subRoot = parseElements(schema); String subRootXquery = "descendant::" + subRoot.getName() + "[text()='" + subRoot.getTextTrim() //$NON-NLS-1$//$NON-NLS-2$ + "']";//$NON-NLS-1$ Element division = pingElement(subRootXquery, spareDoc.getRootElement()); if (division == null || division.getParent() == null) { return; } Element divisionParent = division.getParent(); divisionParent.remove(division); divisionParent.add((Element) subRoot.clone()); } String url = getURLFromTreeObject(serverRoot); String urlXquery = "descendant::*[@Url != '" + url + "']";//$NON-NLS-1$//$NON-NLS-2$ List<Element> elems = spareDoc.selectNodes(urlXquery); for (Element elem : elems) { elem.addAttribute("Url", url);//$NON-NLS-1$ } } credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc = spareDoc; spareDoc = orgDoc; importCategories = schemas; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private Element drillUpForDevisionElement(Element elem) { Element parent = elem.getParent(); while (parent != null && !parent.getTextTrim().equals(elem.getTextTrim()) && !(parent.getTextTrim().equals("0"))) {//$NON-NLS-1$ parent = parent.getParent();//from ww w . j ava 2 s .c o m } return parent; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void transferElementsWithCategoryPath(String categoryXpath, Element srcElemRoot, Element targtElemRoot) {/* w w w . j a v a2s. c o m*/ categoryXpath += "[text()='" + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$//$NON-NLS-2$ // clear up the context of targtElemRoot firstly Element elemCategoryInTagt = pingElement(categoryXpath, targtElemRoot); List elems = elemCategoryInTagt.content(); List xobjects = new ArrayList(); for (Object obj : elems) { if (obj instanceof Element) { Element elem = (Element) obj; if (!elem.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) {//$NON-NLS-1$ Element division = drillUpForDevisionElement(elem); division.addElement(elem.getName()).setText(elem.getTextTrim()); xobjects.add(elem); } } } elemCategoryInTagt.content().removeAll(xobjects); Element elemCategoryInSrc = pingElement(categoryXpath, srcElemRoot); elems = elemCategoryInSrc.content(); for (Object obj : elems) { if (obj instanceof Element) { Element elem = (Element) obj; if (!elem.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) {//$NON-NLS-1$ String xpath = ".//descendant::" + elem.getName() + "[text()='" + elem.getTextTrim() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ List<Element> es = targtElemRoot.selectNodes(xpath); Element newElem = null; for (Element elemExist : es) { if (elemExist.getParent() != null && elemExist.getParent().getTextTrim().equals(TreeObject.EVENT_MANAGEMENT + "")) { continue; } if (elemExist != null) { Element parentExist = elemExist.getParent(); parentExist.remove(elemExist); } elemExist = pingElement(categoryXpath, targtElemRoot); newElem = elemExist.addElement(elem.getName()); newElem.setText(elem.getTextTrim()); } if (es.size() == 0 || (es.size() > 0 && newElem == null)) { Element elemExist = pingElement(categoryXpath, targtElemRoot); newElem = elemExist.addElement(elem.getName()); newElem.setText(elem.getTextTrim()); } } } } }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public void parseElementForOutput(TreeObject[] xobjs) { for (TreeObject xobj : xobjs) { TreeObject subParent = xobj;// ww w .ja v a2s . c o m while (subParent.getParent().getType() != 0) { subParent = subParent.getParent(); } Element modelElem = getParentElement(subParent); if (!outPutSchemas.containsKey(modelElem.getName())) { Element copyElem = (Element) modelElem.clone(); copyElem.clearContent(); copyElem.setText(modelElem.getTextTrim()); outPutSchemas.put(modelElem.getName(), copyElem); } subParent = xobj; TreeObject categorySubRoot = null; while (subParent.getParent().getType() == TreeObject.CATEGORY_FOLDER) { categorySubRoot = subParent.getParent(); subParent = subParent.getParent(); } Element divisionElem = null; Element copyModelElem = outPutSchemas.get(modelElem.getName()); Document doc = credentials.get(UnifyUrl(xobj.getServerRoot().getWsKey().toString())).doc; String division = xobj.getType() == TreeObject.TRANSFORMER ? "Process" : "Trigger";//$NON-NLS-1$//$NON-NLS-2$ String xpathForDivision = ".//child::" + division + "[text()='" + xobj.getType() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (categorySubRoot != null) { Element categoryElem = getParentElement(categorySubRoot); if (categoryElem.getParent() != modelElem) { divisionElem = pingElement(xpathForDivision, copyModelElem); if (divisionElem == null) { divisionElem = copyModelElem.addElement(categoryElem.getParent().getName()); divisionElem.setText(categoryElem.getParent().getTextTrim()); } } else { divisionElem = copyModelElem; } Element categoryElementClone = (Element) categoryElem.clone(); String xpath = "./child::" + categoryElem.getName() + "[text()='" + TreeObject.CATEGORY_FOLDER //$NON-NLS-1$//$NON-NLS-2$ + "']";//$NON-NLS-1$ if (divisionElem.selectNodes(xpath).size() == 0) { divisionElem.add(categoryElementClone); } } else { // individual xobject Element xobjElem = pingElement(getXPathForTreeObject(xobj), doc.getRootElement()); Element parentElem = xobjElem.getParent(); if (parentElem == modelElem) { parentElem = copyModelElem; } else { divisionElem = pingElement(xpathForDivision, copyModelElem); if (divisionElem == null) { divisionElem = copyModelElem.addElement(parentElem.getName()); divisionElem.setText(parentElem.getTextTrim()); } } String xpath = ".//child::" + xobjElem.getName() + "[text()='" + xobjElem.getTextTrim() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (divisionElem != null && pingElement(xpath, divisionElem) == null) { divisionElem.add((Element) xobjElem.clone()); } } } // filter those excluded from xobjects out of categorys String xpath = ".//descendant::*[text() ='" + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$//$NON-NLS-2$ Iterator<Element> iter = outPutSchemas.values().iterator(); while (iter.hasNext()) { Element divisionElement = iter.next(); List<Element> categorys = divisionElement.selectNodes(xpath); if (categorys != null) { for (Element categoryElems : categorys) { List objs = categoryElems.content(); List<Element> elemToDel = new ArrayList<Element>(); for (Object obj : objs) { if (obj instanceof Element) { Element categoryElement = (Element) obj; if (categoryElement.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) { continue; } boolean match = false; for (TreeObject xobj : xobjs) { if (filterOutBlank(xobj.getDisplayName()).equals(categoryElement.getName()) && categoryElement.getTextTrim().equals(xobj.getType() + "")) {//$NON-NLS-1$ match = true; break; } } if (!match) { elemToDel.add(categoryElement); } } } for (Element del : elemToDel) { categoryElems.remove(del); } } } } ArrayList<String> schemas = new ArrayList<String>(); Iterator<Element> iterd = outPutSchemas.values().iterator(); while (iterd.hasNext()) { schemas.add(iterd.next().asXML()); } }
From source file:com.arc.cdt.debug.seecode.core.launch.CMPDInfoFromVDKConfigReader.java
License:Open Source License
@SuppressWarnings("unchecked") private static void appendLaunchSwitches(List<String> switchList, List<String> startupCommands, Element launch) {// www. j av a 2 s. c o m List<Element> switches = launch.elements("SWITCH"); for (Element e : switches) { String data = e.getTextTrim(); if (data.startsWith("-multifiles=")) { // Do nothing } else if (data.equals("-OKN")) { // Do nothing } else if (data.startsWith("-cmd=")) { startupCommands.add(data.substring(5)); } else switchList.add(data); } }
From source file:com.arc.cdt.debug.seecode.core.launch.CMPDInfoFromVDKConfigReader.java
License:Open Source License
@SuppressWarnings("unchecked") private static ICMPDInfo.IProcess formProcess(Element e, File workingDir, final IProject project) throws DocumentException { List<Element> switches = e.elements("SWITCH"); final String name = e.attributeValue("name"); final List<String> args = new ArrayList<String>(switches.size()); ProcessIdList plist = null;/*from ww w. j a va 2 s . c om*/ boolean exeArgsPending = false; final List<String> exeCommand = new ArrayList<String>(); for (Element s : switches) { String arg = s.getTextTrim(); if (arg.startsWith("-pset=")) { try { plist = ProcessIdList.create(arg.substring(6)); } catch (NumberFormatException x) { throw new DocumentException("Bogus -pset value: " + arg.substring(6) + ": " + x.getMessage()); } } else if (arg.startsWith("-psetname=")) { // Do nothing; process name already known } else if (arg.equals("--") && exeCommand.size() == 1) { exeArgsPending = true; } else if (arg.startsWith("-") && !exeArgsPending) { args.add(arg); } else if (exeCommand.size() > 0 && !exeArgsPending) { throw new DocumentException("Multiple exe path specified: " + exeCommand.get(0) + " and " + arg); } else exeCommand.add(arg); } if (exeCommand.size() == 0) { throw new DocumentException("exe path missing for process " + name); } if (!new File(exeCommand.get(0)).isAbsolute() && workingDir != null) { String file = new File(workingDir, exeCommand.get(0)).toString(); exeCommand.set(0, file.replaceAll("\\\\", "/")); } if (new File(exeCommand.get(0)).isAbsolute() && project != null) { // Make absolute paths relative to project if possible. IPath exePath = new Path(exeCommand.get(0)); IPath projectPath = project.getLocation(); if (projectPath.isPrefixOf(exePath)) { exePath = exePath.setDevice(null).removeFirstSegments(projectPath.segmentCount()); exeCommand.set(0, exePath.toString()); } } List<Element> props = e.elements("property"); final Map<String, String> properties = new HashMap<String, String>(); if (props != null) { for (Element p : props) { String key = p.attributeValue("name"); String value = p.attributeValue("value"); if (key != null && value != null && key.length() > 0) { properties.put(key, value); } } } final ProcessIdList plistCopy = plist; return new ICMPDInfo.IProcess() { @Override public String[] getCommand() { return exeCommand.toArray(new String[exeCommand.size()]); } @Override public int getInstanceCount() { return plistCopy.getCount(); } @Override public ProcessIdList getIDList() { return plistCopy; } @Override public String getProcessName() { return name; } @Override public IProject getProject() { return project; } @Override public String[] getSwahiliArgs() { return args.toArray(new String[args.size()]); } @Override public Map<String, String> getGuihiliProperties() { return properties; } }; }
From source file:com.arc.intro.CompilerSamplesProvider.java
License:Open Source License
private String getProjectDescription(Element cat, File projectFile) { List<Element> projects = Cast.toType(cat.elements(PROJECT_TAG)); String projectName = projectFile.getName(); for (Element projectElement : projects) { if (projectName.equals(projectElement.attributeValue(NAME_ATTR, null))) { return projectElement.getTextTrim(); }//from w ww .j a v a2 s . c o m } File readmeFile = new File(projectFile, "README.txt"); if (readmeFile.exists()) { try { FileReader reader = new FileReader(readmeFile); BufferedReader input = new BufferedReader(reader); StringBuilder buf = new StringBuilder(); String line = input.readLine(); while (line != null) { buf.append(line); buf.append("\n"); line = input.readLine(); } return buf.toString(); } catch (IOException e) { //couldn't read the "README.txt" file. } } return ""; }
From source file:com.baidu.terminator.plugin.extractor.http.HttpXmlExtractor.java
License:Open Source License
/** * ??/*from w ww . j a v a 2 s.c o m*/ * * @param element */ @SuppressWarnings("unchecked") public void getElementList(Element element) { List<Element> elements = element.elements(); if (elements.size() == 0) { // ? String key = element.getName(); String value = element.getTextTrim(); RequestElement bodyElement = new RequestElement(); bodyElement.setKey(key); bodyElement.setValue(value); contentmap.add(bodyElement); } else { // ? for (Iterator<Element> it = elements.iterator(); it.hasNext();) { Element elem = (Element) it.next(); // ?? getElementList(elem); } } }