List of usage examples for org.dom4j Element getText
String getText();
From source file:cn.com.sunjiesh.wechat.service.AbstractWechatMessageReceiveService.java
/** * ??// w w w. j av a 2 s .co m * * @param doc4j ??Dom * @param toUserName ?? * @param fromUserName ????OpenID * @param eventKey KEY??? * @return ? * @throws ServiceException ServiceException */ protected Document scanCodeEventReceive(Document doc4j, String toUserName, String fromUserName, String eventKey) throws ServiceException { Document respDoc4j; Node eventNode = doc4j.selectSingleNode("/xml/Event"); Element scanCodeInfoNode = (Element) doc4j.selectSingleNode("/xml/ScanCodeInfo"); Element scanTypeNode = scanCodeInfoNode.element("ScanType"); Element scanResultNode = scanCodeInfoNode.element("ScanResult"); String event = eventNode == null ? "" : eventNode.getText(); String scanType = scanTypeNode.getText(); String scanResult = scanResultNode.getText(); WechatEventScancodeCommonMessageRequest scanCodePushMessage = new WechatEventScancodeCommonMessageRequest( toUserName, fromUserName, event, eventKey); scanCodePushMessage.new ScanCodeInfo(scanType, scanResult); //TODO return messageReceive(scanCodePushMessage); return null; }
From source file:cn.myloveqian.utils.XmlUtils.java
License:Open Source License
/** * @param elements//from ww w . j ava2s . c o m * @return * @throws DocumentException */ public static List<Map<String, String>> getEachElement(List elements) throws DocumentException { List<Map<String, String>> resultList = new ArrayList<>(); if (elements.size() > 0) { for (Iterator it = elements.iterator(); it.hasNext();) { Map<String, String> resultMap = new HashMap<>(); Element subElement = (Element) it.next(); List subElements = subElement.elements(); for (Iterator subIt = subElements.iterator(); subIt.hasNext();) { Element son = (Element) subIt.next(); String name = son.getName(); String text = son.getText(); resultMap.put(name, text); } resultList.add(resultMap); } } else { throw new DocumentException("this element is disappeared"); } return resultList; }
From source file:com.ah.be.parameter.BeParaModuleDefImpl.java
private void changeOsVersionFile() { String fingerprints = ImportTextFileAction.OS_VERSION_FILE_PATH + ImportTextFileAction.OS_VERSION_FILE_NAME; String fingerprintsChg = ImportTextFileAction.OS_VERSION_FILE_PATH + ImportTextFileAction.OS_VERSION_FILE_NAME_CHG; FileWriter fWriter = null;//from w ww .ja v a 2 s . c o m try { if (new File(fingerprints).exists() && new File(fingerprintsChg).exists()) { List<String> lines = NmsUtil.readFileByLines(fingerprints); List<String> replaceOsName = new ArrayList<>(); List<String> replaceOption55 = new ArrayList<>(); String preHmVer = NmsUtil.getHiveOSVersion(NmsUtil .getVersionInfo(BeAdminCentOSTools.ahBackupdir + File.separatorChar + "hivemanager.ver")); // parse os_dhcp_fingerprints_changes.xml SAXReader reader = new SAXReader(); Document document = reader.read(new File(fingerprintsChg)); Element root = document.getRootElement(); List<?> fingerprintElems = root.elements(); for (Object obj : fingerprintElems) { Element fingerprintElem = (Element) obj; String osName = fingerprintElem.attributeValue("osname"); for (Iterator<?> iterator = fingerprintElem.elementIterator(); iterator.hasNext();) { Element option55Elem = (Element) iterator.next(); String node_option55_text = option55Elem.getText(); Attribute version = option55Elem.attribute("version"); String version_text = version.getText(); if (NmsUtil.compareSoftwareVersion(preHmVer, version_text) <= 0) { if (!replaceOption55.contains(node_option55_text)) { replaceOsName.add(osName); replaceOption55.add(node_option55_text); } } } } if (replaceOption55.isEmpty()) { log.debug("No need to modify os_dhcp_fingerprints.txt."); FileUtils.deleteQuietly(new File(fingerprintsChg)); return; } for (String option55 : replaceOption55) { int size = lines.size(); boolean remove = false; for (int i = size - 1; i >= 0; i--) { if (remove) { lines.remove(i); remove = false; } else { if (option55.equals(lines.get(i))) { if (i < size - 1 && i > 0 && lines.get(i - 1).startsWith(ImportTextFileAction.OS_STR) && lines.get(i + 1).equals(ImportTextFileAction.END_STR)) { lines.remove(i + 1); lines.remove(i); remove = true; } else { lines.remove(i); } } } } } //insert for (int i = 0; i < replaceOption55.size(); i++) { String option55 = replaceOption55.get(i); String osName = ImportTextFileAction.OS_STR + replaceOsName.get(i); if (!lines.contains(option55)) { if (lines.contains(osName)) { List<String> temp = lines.subList(lines.indexOf(osName), lines.size()); int index = lines.indexOf(osName) + temp.indexOf(ImportTextFileAction.END_STR); lines.add(index, option55); } else { lines.add(osName); lines.add(option55); lines.add(ImportTextFileAction.END_STR); } } } fWriter = new FileWriter(fingerprints, false); for (String line : lines) { if (line != null && line.startsWith(ImportTextFileAction.VERSION_STR)) { String version = line.substring(line.indexOf(ImportTextFileAction.VERSION_STR) + ImportTextFileAction.VERSION_STR.length()); BigDecimal b1 = new BigDecimal(version); BigDecimal b2 = new BigDecimal("0.1"); float fVer = b1.add(b2).floatValue(); String versionStr = ImportTextFileAction.VERSION_STR + String.valueOf(fVer) + "\r\n"; fWriter.write(versionStr); } else { fWriter.write(line + "\r\n"); } } fWriter.close(); //compress file String strCmd = ""; StringBuffer strCmdBuf = new StringBuffer(); strCmdBuf.append("tar zcvf "); strCmdBuf.append( ImportTextFileAction.OS_VERSION_FILE_PATH + ImportTextFileAction.OS_VERSION_FILE_NAME_TAR); strCmdBuf.append(" -C "); strCmdBuf.append(ImportTextFileAction.OS_VERSION_FILE_PATH); strCmdBuf.append(" " + ImportTextFileAction.OS_VERSION_FILE_NAME); strCmd = strCmdBuf.toString(); boolean compressResult = BeAdminCentOSTools.exeSysCmd(strCmd); if (!compressResult) { log.error("compress os_dhcp_fingerprints.txt error."); return; } FileUtils.deleteQuietly(new File(fingerprintsChg)); } else { if (new File(fingerprintsChg).exists()) { FileUtils.deleteQuietly(new File(fingerprintsChg)); } } } catch (Exception e) { setDebugMessage("change OsVersionFile error: ", e); } finally { if (fWriter != null) { try { fWriter.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.alibaba.citrus.dev.handler.util.DomUtil.java
License:Open Source License
private static Element copy(org.dom4j.Element dom4jElement, ElementFilter filter) throws Exception { dom4jElement = filter.filter(dom4jElement); if (dom4jElement == null) { return null; }/* ww w. j a v a 2 s .c om*/ Element element = new Element(dom4jElement.getQualifiedName(), dom4jElement.getNamespaceURI()); for (Object attr : dom4jElement.attributes()) { String name = ((Attribute) attr).getQualifiedName(); String value = ((Attribute) attr).getValue(); element.addAttribute(name, value); } for (Object ns : dom4jElement.declaredNamespaces()) { String name = ((Namespace) ns).getPrefix(); String value = ((Namespace) ns).getURI(); if (isEmpty(name)) { name = "xmlns"; } else { name = "xmlns:" + name; } element.addAttribute(name, value); } for (Object e : dom4jElement.elements()) { Element subElement = copy((org.dom4j.Element) e, filter); if (subElement != null) { element.addSubElement(subElement); } } if (dom4jElement.elements().isEmpty()) { String text = trimToNull(dom4jElement.getText()); if (text != null) { element.setText(text); } } return element; }
From source file:com.allinfinance.common.grid.GridConfigUtil.java
License:Open Source License
/** * ??/*from w w w .j av a 2s. co m*/ * @param context * @throws Exception */ @SuppressWarnings("unchecked") public static void initGirdConfig(ServletContext context) throws Exception { SAXReader reader = new SAXReader(); Document document = null; document = reader.read(context.getResourceAsStream(Constants.GRID_CONFIG_CONTEXTPATH)); Element root = document.getRootElement(); List<Element> gridInfoList = root.elements(GridConfigConstants.NODE_GRID); for (Element gridNode : gridInfoList) { String gridId = gridNode.attributeValue(GridConfigConstants.GRID_ID); String gridConfigType = gridNode.attributeValue(GridConfigConstants.GRID_TYPE); //? GridModel gridModel = new GridModel(); gridModel.setId(gridId); gridModel.setType(gridConfigType); gridModel.setColumns(gridNode.elementText(GridConfigConstants.COLUMNS).trim()); if (GridConfigConstants.TYPE_SQL.equals(gridConfigType)) { SqlMode sqlMode = new SqlMode(); //SQL? Element sqlModeNode = gridNode.element(GridConfigConstants.TYPE_SQLMODE); //? Element wheresNode = sqlModeNode.element(GridConfigConstants.WHERES); List<Element> whereList = wheresNode.elements(GridConfigConstants.WHERE); sqlMode.setSql(sqlModeNode.elementText(GridConfigConstants.SQL).trim()); sqlMode.setDao(sqlModeNode.elementText(GridConfigConstants.QUERY_DAO).trim()); //? if (whereList != null && whereList.size() > 0) { WheresModel wheresModel = new WheresModel(); List<WhereModel> whereModelList = new ArrayList<WhereModel>(); for (Element whereNode : whereList) { WhereModel whereModel = new WhereModel(); whereModel.setType(whereNode.attributeValue(GridConfigConstants.WHERE_TYPE)); whereModel.setOperator(whereNode.attributeValue(GridConfigConstants.WHERE_OPERATOR)); whereModel.setLogic(whereNode.attributeValue(GridConfigConstants.WHERE_LOGIC)); whereModel.setDataBaseColumn( whereNode.elementText(GridConfigConstants.WHERE_DATABASE_COLUMN).trim()); whereModel.setQueryColumn( whereNode.elementText(GridConfigConstants.WHERE_QUERY_COLUMN).trim()); whereModelList.add(whereModel); } wheresModel.setWhereModelList(whereModelList); sqlMode.setWheresModel(wheresModel); } // ??? if (sqlModeNode.element(GridConfigConstants.ORDERS) != null) { OrdersModel ordersModel = new OrdersModel(); Element orderModels = sqlModeNode.element(GridConfigConstants.ORDERS); ordersModel.setSort(orderModels.attributeValue("sort")); List<Element> orderList = orderModels.elements(GridConfigConstants.ORDER); for (Element element : orderList) { ordersModel.getOrders().add(element.getText()); } sqlMode.setOrdersModel(ordersModel); } gridModel.setSqlMode(sqlMode); } else if (GridConfigConstants.TYPE_SYNC.equals(gridConfigType)) { SyncMode syncMode = new SyncMode(); Element syncModeNode = gridNode.element(GridConfigConstants.TYPE_SYNCMODE); Element methodNode = syncModeNode.element(GridConfigConstants.SYNC_METHOD); syncMode.setMethod(methodNode.attributeValue(GridConfigConstants.SYNC_METHOD_VALUE)); gridModel.setSyncMode(syncMode); } else { throw new Exception("???[ id:" + gridId + " ]"); } gridConfigMap.put(gridId, gridModel); } }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void checkUpAllCategoryForModel(TreeParent model) { if (model.getServerRoot() == null) { return;/*w w w.j ava 2 s . c o m*/ } String xpath = "//" + model.getServerRoot().getUser().getUsername() + "/" //$NON-NLS-1$//$NON-NLS-2$ + filterOutBlank(model.getDisplayName()) + "//child::*[text() = '" + TreeObject.CATEGORY_FOLDER + "' and @Url='" //$NON-NLS-1$//$NON-NLS-2$ + getURLFromTreeObject(model) + "']";//$NON-NLS-1$ Document doc = credentials.get(UnifyUrl(model.getServerRoot().getWsKey().toString())).doc; String xpathForModel = getXPathForTreeObject(model); List<Element> elems = doc.selectNodes(xpathForModel); Element modelElem = elems.get(0); elems = doc.selectNodes(xpath); for (Element elem : elems) { Element spec = elem; ArrayList<Element> hierarchicalList = new ArrayList<Element>(); while (spec != modelElem) { hierarchicalList.add(spec); spec = spec.getParent(); } Collections.reverse(hierarchicalList); TreeParent modelCpy = model; while (!hierarchicalList.isEmpty()) { spec = hierarchicalList.remove(0); String elemName = spec.getName(); if (spec.attributeValue(REALNAME) != null) { elemName = spec.attributeValue(REALNAME); } TreeObject to = findObject(modelCpy, Integer.parseInt(spec.getText().trim()), elemName); if (to == null) { TreeParent catalog = new TreeParent(elemName, modelCpy.getServerRoot(), TreeObject.CATEGORY_FOLDER, null, null); boolean cpyInternalCheck = internalCheck; internalCheck = true; modelCpy.addChild(catalog); internalCheck = cpyInternalCheck; modelCpy = catalog; } else { modelCpy = (TreeParent) to; } } } }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private ArrayList<String> checkUpCatalogRepositoryForTreeObject(TreeObject theObj, TreeObject folder) { if (theObj.getType() == 0 || theObj.getType() == TreeObject.CATEGORY_FOLDER) { return null; }//from w w w . ja v a 2 s .c o m try { String modelName = getXPathForTreeObject(folder); String url = getURLFromTreeObject(theObj); String xpath = modelName + "//child::*[text() = '" + TreeObject.CATEGORY_FOLDER + "' and @Url='" + url //$NON-NLS-1$//$NON-NLS-2$ + "']//child::*";//$NON-NLS-1$ Document doc = credentials.get(getURLFromTreeObject(folder)).doc; List<Element> elems = doc.selectNodes(xpath); for (Element elem : elems) { String xpathElem = getXPathForElem(elem); String xpathObj = getXPathForTreeObject(theObj); int squarebk = xpathObj.indexOf("[");//$NON-NLS-1$ if (squarebk != -1) { xpathObj = xpathObj.substring(0, squarebk); } if (elem.getName().equals(filterOutBlank(theObj.getDisplayName())) && elem.getData().toString().equals(theObj.getType() + "")) {//$NON-NLS-1$ ArrayList<String> path = new ArrayList<String>(); HashMap<Integer, String> slice = new HashMap<Integer, String>(); while (isAEXtentisObjects(elem, theObj) > XTENTIS_LEVEL) { String elemName = elem.getParent().getName(); if (elem.getParent().attributeValue(REALNAME) != null) { elemName = elem.getParent().attributeValue(REALNAME); } if (elem.getText() != null && StringUtils.trim(elem.getParent().getText()) .equals(TreeObject.CATEGORY_FOLDER + "")) {//$NON-NLS-1$ path.add(elem.getParent().getName()); if (elem.getParent().attributeValue(REALNAME) != null) { slice.put(path.size() - 1, elem.getParent().attributeValue(REALNAME)); } } elem = elem.getParent(); } ArrayList<String> pathCpy = new ArrayList<String>(path); Collections.reverse(path); if (!isEqualString(xpathElem, xpathObj, path)) { path = null; } if (path != null) { for (int i = 0; i < pathCpy.size(); i++) { if (slice.get(i) != null) { pathCpy.set(i, slice.get(i)); } } Collections.reverse(pathCpy); path = pathCpy; } return path; } } } catch (Exception ex) { return null; } return null; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public int receiveUnCertainTreeObjectType(TreeObject xobj) { String path = this.getXPathForTreeObject(xobj); int level = XTENTIS_LEVEL; if (path.startsWith("/category/admin/EventManagement")) {//$NON-NLS-1$ level = XTENTIS_LEVEL + 1;/* ww w .j av a 2 s . c o m*/ } Document doc = credentials.get(UnifyUrl(xobj.getServerRoot().getWsKey().toString())).doc; List<Element> elems = doc.selectNodes(path); if (!elems.isEmpty()) { Element elem = elems.get(0); while (isAEXtentisObjects(elem, xobj) >= level) { elem = elem.getParent(); } return Integer.parseInt(elem.getText().trim()); } else { return -1; } }
From source file:com.amalto.workbench.utils.MDMServerHelper.java
License:Open Source License
private static Element getServerElement(Element rootElement, String matchingName) { List<?> properties = rootElement.elements(MDMServerHelper.PROPERTIES); for (Iterator<?> iterator = properties.iterator(); iterator.hasNext();) { Element serverElement = (Element) iterator.next(); Element nameElement = serverElement.element(MDMServerHelper.NAME); if (nameElement != null) { String name = nameElement.getText(); if (matchingName.equals(name)) { return serverElement; }/* ww w. ja v a2 s . c o m*/ } } return null; }
From source file:com.apicloud.commons.model.Config.java
License:Open Source License
private static void parseGenral(Element rootElement, Config config) { Element nameElement = rootElement.element("name"); String name = nameElement.getText(); config.setName(name);// w ww. j a v a 2s . co m Element descriptionElement = rootElement.element("description"); String description = descriptionElement.getText(); config.setDesc(description); Element authorElement = rootElement.element("author"); String authorName = authorElement.getText(); String authorEmail = authorElement.attributeValue("email"); String authorHref = authorElement.attributeValue("href"); config.setAuthorHref(authorHref); config.setAuthorEmail(authorEmail); config.setAuthorName(authorName); Element contentElement = rootElement.element("content"); String content = contentElement.attributeValue("src"); config.setContentSrc(content); }