Java Code Examples for org.dom4j.Element#elementText()
The following examples show how to use
org.dom4j.Element#elementText() .
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: InMsgParser.java From jfinal-weixin with Apache License 2.0 | 6 votes |
/** * 消息类型 * 1:text 文本消息 * 2:image 图片消息 * 3:voice 语音消息 * 4:video 视频消息 * shortvideo 小视频消息 * 5:location 地址位置消息 * 6:link 链接消息 * 7:event 事件 */ private static InMsg doParse(String xml) throws DocumentException { Document doc = DocumentHelper.parseText(xml); Element root = doc.getRootElement(); String toUserName = root.elementText("ToUserName"); String fromUserName = root.elementText("FromUserName"); Integer createTime = Integer.parseInt(root.elementText("CreateTime")); String msgType = root.elementText("MsgType"); if ("text".equals(msgType)) return parseInTextMsg(root, toUserName, fromUserName, createTime, msgType); if ("image".equals(msgType)) return parseInImageMsg(root, toUserName, fromUserName, createTime, msgType); if ("voice".equals(msgType)) return parseInVoiceMsgAndInSpeechRecognitionResults(root, toUserName, fromUserName, createTime, msgType); if ("video".equals(msgType)) return parseInVideoMsg(root, toUserName, fromUserName, createTime, msgType); if ("shortvideo".equals(msgType)) //支持小视频 return parseInShortVideoMsg(root, toUserName, fromUserName, createTime, msgType); if ("location".equals(msgType)) return parseInLocationMsg(root, toUserName, fromUserName, createTime, msgType); if ("link".equals(msgType)) return parseInLinkMsg(root, toUserName, fromUserName, createTime, msgType); if ("event".equals(msgType)) return parseInEvent(root, toUserName, fromUserName, createTime, msgType); throw new RuntimeException("无法识别的消息类型 " + msgType + ",请查阅微信公众平台开发文档"); }
Example 2
Source File: QQInMsgParser.java From seed with Apache License 2.0 | 6 votes |
private static QQInMsg doParse(String xml) throws DocumentException { Document doc = DocumentHelper.parseText(xml); Element root = doc.getRootElement(); String toUserName = root.elementText("ToUserName"); String fromUserName = root.elementText("FromUserName"); long createTime = Long.parseLong(root.elementText("CreateTime")); String msgType = root.elementText("MsgType"); if("text".equals(msgType)){ return parseInTextMsg(root, toUserName, fromUserName, createTime, msgType); } if("image".equals(msgType)){ return parseInImageMsg(root, toUserName, fromUserName, createTime, msgType); } if("location".equals(msgType)){ return parseInLocationMsg(root, toUserName, fromUserName, createTime, msgType); } if("event".equals(msgType)){ return parseInEventMsg(root, toUserName, fromUserName, createTime, msgType); } throw new RuntimeException("未知的消息类型" + msgType + ", 请查阅QQ公众平台开发者文档http://mp.qq.com/"); }
Example 3
Source File: OpenwxController.java From jeewx with Apache License 2.0 | 6 votes |
@RequestMapping(value = "{appid}/callback") public void acceptMessageAndEvent(HttpServletRequest request, HttpServletResponse response) throws IOException, AesException, DocumentException { String msgSignature = request.getParameter("msg_signature"); //LogUtil.info("第三方平台全网发布-------------{appid}/callback-----------验证开始。。。。msg_signature="+msgSignature); if (!StringUtils.isNotBlank(msgSignature)) return;// 微信推送给第三方开放平台的消息一定是加过密的,无消息加密无法解密消息 StringBuilder sb = new StringBuilder(); BufferedReader in = request.getReader(); String line; while ((line = in.readLine()) != null) { sb.append(line); } in.close(); String xml = sb.toString(); Document doc = DocumentHelper.parseText(xml); Element rootElt = doc.getRootElement(); String toUserName = rootElt.elementText("ToUserName"); //微信全网测试账号 // if (StringUtils.equalsIgnoreCase(toUserName, APPID)) { // LogUtil.info("全网发布接入检测消息反馈开始---------------APPID="+ APPID +"------------------------toUserName="+toUserName); checkWeixinAllNetworkCheck(request,response,xml); // } }
Example 4
Source File: JenrlInfo.java From unitime with Apache License 2.0 | 5 votes |
public void load(Element root) { int version = Integer.parseInt(root.attributeValue("version")); if (version==1) { iJenrl = Double.parseDouble(root.elementText("jenrl")); iIsSatisfied = Boolean.valueOf(root.elementText("satisfied")).booleanValue(); iIsDistance = Boolean.valueOf(root.elementText("dist")).booleanValue(); iIsFixed = Boolean.valueOf(root.elementText("fixed")).booleanValue(); iIsHard = Boolean.valueOf(root.elementText("hard")).booleanValue(); iIsWorkDay = Boolean.valueOf(root.elementText("workday")).booleanValue(); if (root.elementText("distance")!=null) iDistance = Double.parseDouble(root.elementText("distance")); if (root.elementText("commited")==null) { iIsCommited = false; } else { iIsCommited = Boolean.valueOf(root.elementText("commited")).booleanValue(); } if (root.elementText("important")==null) { iIsImportant = false; } else { iIsImportant = Boolean.valueOf(root.elementText("important")).booleanValue(); } if (root.elementText("instructor")==null) { iIsInstructor = false; } else { iIsInstructor = Boolean.valueOf(root.elementText("instructor")).booleanValue(); } } }
Example 5
Source File: OpenwxController.java From jeewx with Apache License 2.0 | 5 votes |
/** * 获取授权的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 6
Source File: ConfigParser.java From cherry with Apache License 2.0 | 5 votes |
private Param parseInitParam(Element foo, Map<String, String> props){ Param param = new Param(); param.setName(foo.elementText("param-name")); String value = foo.elementText("param-value"); if(value!=null && value.startsWith(PLACEHOLDER_PREFIX) && value.endsWith(PLACEHOLDER_SUFFIX)){ String key = value.substring(2, value.length()-1); if(!props.containsKey(key)){ throw new IllegalArgumentException("unknown param:"+param.getName()+" value:"+value); } value = props.get(key); } param.setValue(value); return param; }
Example 7
Source File: LinksPortlet.java From olat with Apache License 2.0 | 5 votes |
private void init() { private static final Logger log = LoggerHelper.getLogger(); if (log.isDebugEnabled()) { log.debug("START: Loading remote portlets content."); } final File configurationFile = new File(WebappHelper.getContextRoot() + CONFIG_FILE); // this map contains the whole data final HashMap<String, PortletInstitution> portletMap = new HashMap<String, PortletInstitution>(); final SAXReader reader = new SAXReader(); try { final Document doc = reader.read(configurationFile); final Element rootElement = doc.getRootElement(); final List<Element> lstInst = rootElement.elements(ELEM_INSTITUTION); for (final Element instElem : lstInst) { final String inst = instElem.attributeValue(ATTR_INSTITUTION_NAME); final List<Element> lstTmpLinks = instElem.elements(ELEM_LINK); final List<PortletLink> lstLinks = new ArrayList<PortletLink>(lstTmpLinks.size()); for (final Element linkElem : lstTmpLinks) { final String title = linkElem.elementText(ELEM_LINK_TITLE); final String url = linkElem.elementText(ELEM_LINK_URL); final String target = linkElem.elementText(ELEM_LINK_TARGET); final String lang = linkElem.elementText(ELEM_LINK_LANG); final String desc = linkElem.elementText(ELEM_LINK_DESC); lstLinks.add(new PortletLink(title, url, target, lang, desc)); } portletMap.put(inst, new PortletInstitution(inst, lstLinks)); } } catch (final Exception e) { log.error("Error reading configuration file", e); } finally { content = portletMap; } }
Example 8
Source File: SocketReadingMode.java From Openfire with Apache License 2.0 | 4 votes |
/** * Start using compression but first check if the connection can and should use compression. * The connection will be closed if the requested method is not supported, if the connection * is already using compression or if client requested to use compression but this feature * is disabled. * * @param doc the element sent by the client requesting compression. Compression method is * included. * @return true if it was possible to use compression. * @throws IOException if an error occurs while starting using compression. */ protected boolean compressClient(Element doc) throws IOException, XmlPullParserException { String error = null; if (socketReader.connection.getCompressionPolicy() == Connection.CompressionPolicy.disabled) { // Client requested compression but this feature is disabled error = "<failure xmlns='http://jabber.org/protocol/compress'><setup-failed/></failure>"; // Log a warning so that admins can track this case from the server side Log.warn("Client requested compression while compression is disabled. Closing " + "connection : " + socketReader.connection); } else if (socketReader.connection.isCompressed()) { // Client requested compression but connection is already compressed error = "<failure xmlns='http://jabber.org/protocol/compress'><setup-failed/></failure>"; // Log a warning so that admins can track this case from the server side Log.warn("Client requested compression and connection is already compressed. Closing " + "connection : " + socketReader.connection); } else { // Check that the requested method is supported String method = doc.elementText("method"); if (!"zlib".equals(method)) { error = "<failure xmlns='http://jabber.org/protocol/compress'><unsupported-method/></failure>"; // Log a warning so that admins can track this case from the server side Log.warn("Requested compression method is not supported: " + method + ". Closing connection : " + socketReader.connection); } } if (error != null) { // Deliver stanza socketReader.connection.deliverRawText(error); return false; } else { // Start using compression for incoming traffic socketReader.connection.addCompression(); // Indicate client that he can proceed and compress the socket socketReader.connection.deliverRawText("<compressed xmlns='http://jabber.org/protocol/compress'/>"); // Start using compression for outgoing traffic socketReader.connection.startCompression(); return true; } }
Example 9
Source File: OpenWxController.java From jeewx-boot with Apache License 2.0 | 4 votes |
/** * 保存Ticket * @param xml */ void processAuthorizationEvent(String xml){ Document doc; try { doc = DocumentHelper.parseText(xml); Element rootElt = doc.getRootElement(); String ticket = rootElt.elementText("ComponentVerifyTicket"); if(StringUtils.isNotEmpty(ticket)){ WeixinOpenAccount entity = getWeixinOpenAccount(CommonWeixinProperties.component_appid); if(entity==null){ entity=new WeixinOpenAccount(); entity.setTicket(ticket); entity.setAppid(CommonWeixinProperties.component_appid); entity.setGetTicketTime(new Date()); weixinOpenAccountService.doAdd(entity); log.info("微信第三方添加TICKET成功!TICKET={}.",new Object[]{ticket}); }else{ entity.setTicket(ticket); entity.setAppid(CommonWeixinProperties.component_appid); entity.setGetTicketTime(new Date()); log.info("===================={}=======================",new Object[]{entity}); weixinOpenAccountService.doEdit(entity); log.info("微信第三方重置TICKET成功!TICKET={}.",new Object[]{ticket}); } } //----------取消公众号授权事件接收处理-------------------------- if("unauthorized".equals(rootElt.elementText("InfoType"))){ String appid = rootElt.elementText("AuthorizerAppid"); MyJwWebJwid myJwWebJwid = myJwWebJwidService.queryByAppid(appid); if(myJwWebJwid != null){ //公众号取消授权,设置相应的状态标志 myJwWebJwid.setAuthorizationStatus("2"); myJwWebJwidService.doEdit(myJwWebJwid); log.info("微信第三方接收公众号取消授权消息,更新公众号成功!名称={}.appid={}",new Object[]{myJwWebJwid.getName(),appid}); } } //----------取消公众号授权事件接收处理-------------------------- } catch (DocumentException e) { e.printStackTrace(); log.error("微信第三方重置TICKET失败!"); e.printStackTrace(); } }
Example 10
Source File: Installer.java From MesquiteCore with GNU Lesser General Public License v3.0 | 4 votes |
void readReceipts(String path){ String receiptsContents = null; try{ receiptsContents = MesquiteFile.getFileContentsAsString(path, 2000000, 100, false); } catch (Exception e) { return; } if (StringUtil.blank(receiptsContents)) return; Element root = XMLUtil.getRootXMLElementFromString("mesquite",receiptsContents); if (root==null) return; List receipts = root.elements("installationReceipt"); boolean stillInstalled = true; for (Iterator iter = receipts.iterator(); iter.hasNext();) { // this is going through all of the notices Element messageElement = (Element) iter.next(); ListableVector v = new ListableVector(); v.addElement(new MesquiteString("identity", messageElement.elementText("identity")), false); v.addElement(new MesquiteString("updateVersion", messageElement.elementText("updateVersion")), false); List locs = messageElement.elements("location"); for (Iterator locsIter = locs.iterator(); locsIter.hasNext();) { // this is going through all of the notices Element locElement = (Element) locsIter.next(); String p = locElement.elementText("path"); if (!MesquiteFile.fileOrDirectoryExists(MesquiteTrunk.getRootPath() + p)) stillInstalled = false; v.addElement(new MesquiteString("location", locElement.elementText("path")), false); } v.addElement(new MesquiteString("explanation", messageElement.elementText("explanation")), false); v.addElement(new MesquiteString("packageName", messageElement.elementText("packageName")), false); v.addElement(new MesquiteString("uniqueLocation", messageElement.elementText("uniqueLocation")), false); Element elup = messageElement.element("updateXML"); if (elup != null) v.addElement(new MesquiteString("updateXML", clean(XMLUtil.getElementAsXMLString(elup, "UTF-8", true)) ), false); // v.addElement(new MesquiteString("updateXML", "<updateXML>\n" + XMLUtil.getElementAsXMLString(elup, "UTF-8", true) + "</updateXML>" ), false); if (!PhoneHomeUtil.alreadyInReceipts(v)){ if (stillInstalled) PhoneHomeUtil.installedReceipts.addElement(v); } } writeReceipts(); //rewrite into central }
Example 11
Source File: MeSHParser.java From AML-Project with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Vector<String> concepts = new Vector<String>(); MediatorLexicon med = new MediatorLexicon(); SAXReader reader = new SAXReader(); File f = new File("store/knowledge/mesh.xml"); Document doc = reader.read(f); Element root = doc.getRootElement(); Iterator<?> records = root.elementIterator("DescriptorRecord"); int index = 0; while(records.hasNext()) { Element concList = ((Element)records.next()).element("ConceptList"); Iterator<?> conc = concList.elementIterator("Concept"); while(conc.hasNext()) { Element c = (Element)conc.next(); String conceptName = c.element("ConceptName").elementText("String"); concepts.add(conceptName); med.add(index, conceptName, 0.90); String casN1Name = c.elementText("CASN1Name"); if(casN1Name != null) med.add(index, casN1Name, 0.85); Element termList = c.element("TermList"); Iterator<?> terms = termList.elementIterator("Term"); while(terms.hasNext()) { Element t = (Element)terms.next(); String termName = t.elementText("String"); if(!conceptName.equals(termName)) med.add(index, termName, 0.85); } index++; } } med.save("store/knowledge/mesh.lexicon"); }
Example 12
Source File: StanzaHandler.java From Openfire with Apache License 2.0 | 4 votes |
/** * Start using compression but first check if the connection can and should use compression. * The connection will be closed if the requested method is not supported, if the connection * is already using compression or if client requested to use compression but this feature * is disabled. * * @param doc the element sent by the client requesting compression. Compression method is * included. * @return true if it was possible to use compression. */ private boolean compressClient(Element doc) { String error = null; if (connection.getCompressionPolicy() == Connection.CompressionPolicy.disabled) { // Client requested compression but this feature is disabled error = "<failure xmlns='http://jabber.org/protocol/compress'><setup-failed/></failure>"; // Log a warning so that admins can track this case from the server side Log.warn("Client requested compression while compression is disabled. Closing " + "connection : " + connection); } else if (connection.isCompressed()) { // Client requested compression but connection is already compressed error = "<failure xmlns='http://jabber.org/protocol/compress'><setup-failed/></failure>"; // Log a warning so that admins can track this case from the server side Log.warn("Client requested compression and connection is already compressed. Closing " + "connection : " + connection); } else { // Check that the requested method is supported String method = doc.elementText("method"); if (!"zlib".equals(method)) { error = "<failure xmlns='http://jabber.org/protocol/compress'><unsupported-method/></failure>"; // Log a warning so that admins can track this case from the server side Log.warn("Requested compression method is not supported: " + method + ". Closing connection : " + connection); } } if (error != null) { // Deliver stanza connection.deliverRawText(error); return false; } else { // Start using compression for incoming traffic connection.addCompression(); // Indicate client that he can proceed and compress the socket connection.deliverRawText("<compressed xmlns='http://jabber.org/protocol/compress'/>"); // Start using compression for outgoing traffic connection.startCompression(); return true; } }
Example 13
Source File: ScormCPManifestTreeModel.java From olat with Apache License 2.0 | 4 votes |
private GenericTreeNode buildNode(final Element item) { final GenericTreeNode treeNode = new GenericTreeNode(); // extract title String title = item.elementText("title"); if (title == null) { title = item.attributeValue("identifier"); } treeNode.setAltText(title); treeNode.setTitle(title); if (item.getName().equals("organization")) { treeNode.setIconCssClass("o_scorm_org"); treeNode.setAccessible(false); } else if (item.getName().equals("item")) { scormIdToNode.put(new Integer(nodeId).toString(), treeNode); nodeToId.put(treeNode, new Integer(nodeId)); // set node images according to scorm sco status final String itemStatusDesc = (String) itemStatus.get(Integer.toString(nodeId)); treeNode.setIconCssClass("o_scorm_item"); if (itemStatusDesc != null) { // add icon decorator for current status treeNode.setIconDecorator1CssClass("o_scorm_" + itemStatusDesc); } nodeId++; // set resolved file path directly final String identifierref = item.attributeValue("identifierref"); final XPath meta = rootElement.createXPath("//ns:resource[@identifier='" + identifierref + "']"); meta.setNamespaceURIs(nsuris); final String href = (String) resources.get(identifierref); if (href != null) { treeNode.setUserObject(href); // allow lookup of a treenode given a href so we can quickly adjust the menu if the user clicks on hyperlinks within the text hrefToTreeNode.put(href, treeNode); } else { treeNode.setAccessible(false); } } final List chds = item.elements("item"); final int childcnt = chds.size(); for (int i = 0; i < childcnt; i++) { final Element childitem = (Element) chds.get(i); final GenericTreeNode gtnchild = buildNode(childitem); treeNode.addChild(gtnchild); } return treeNode; }
Example 14
Source File: PaymentApiTest.java From jfinal-weixin with Apache License 2.0 | 4 votes |
public static void testCreate() throws DocumentException { //商户相关资料 String openId = ""; String notify_url = ""; Map<String, String> params = new HashMap<String, String>(); params.put("appid", appid); params.put("mch_id", partner); params.put("body", "JFinal2.0技术开发"); params.put("out_trade_no", "97777368"); params.put("total_fee", "1"); params.put("spbill_create_ip", "60.12.33.121"); params.put("trade_type", TradeType.JSAPI.name()); params.put("nonce_str", System.currentTimeMillis() / 1000 + ""); params.put("notify_url", notify_url); params.put("openid", openId); String sign = PaymentKit.createSign(params, paternerKey); params.put("sign", sign); String xmlResult = PaymentApi.pushOrder(params); System.out.println(xmlResult); Document doc = DocumentHelper.parseText(xmlResult); Element root = doc.getRootElement(); String return_code = root.elementText("return_code"); String result_code = root.elementText("result_code"); String return_msg = root.elementText("return_msg"); String prepay_id = root.elementText("prepay_id"); Map<String, String> packageParams = new HashMap<String, String>(); packageParams.put("appId", appid); packageParams.put("timeStamp", System.currentTimeMillis() / 1000 + ""); packageParams.put("nonceStr", System.currentTimeMillis() + ""); packageParams.put("package", "prepay_id=" + prepay_id); packageParams.put("signType", "MD5"); String packageSign = PaymentKit.createSign(packageParams, paternerKey); packageParams.put("paySign", packageSign); String jsonStr = JsonUtils.toJson(packageParams); System.out.println(jsonStr); }
Example 15
Source File: XmlLoader.java From crawler4j with Apache License 2.0 | 4 votes |
/** * Load and parse the crawler4j.xml to get all crawlers. * @return WebCrawler instance list; * @throws Exception */ @SuppressWarnings("unchecked") public List<WebCrawler> load() { List<WebCrawler> crawlers = new ArrayList<WebCrawler>(); SAXReader reader = new SAXReader(); try { InputStream is = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_CONFIG_FILE); document = reader.read(is); Element root = document.getRootElement(); for (Iterator<Element> i = root.elementIterator(); i.hasNext();) { Element taskElement = i.next(); String name = taskElement.elementText("name"); long delay = Long.parseLong(taskElement.elementText("delay")); String url = taskElement.elementText("url"); String parserName = taskElement.elementText("parser").trim(); String defaultCharset = taskElement.elementText("charset"); String pageNoStr = taskElement.elementText("max_page"); String crawlerName = taskElement.elementText("crawler"); String nextPageRegex = taskElement.elementText("next_page_key"); String extractLinksElementId = taskElement.elementText("extract_links_elementId"); Class<Parser> c = (Class<Parser>)Class.forName(parserName); Parser parser = c.newInstance(); if (parser == null) { throw new IllegalArgumentException("parser must not be null!"); } int maxPageNo = 1; if (StringUtils.isNotEmpty(pageNoStr)) { maxPageNo = Integer.parseInt(pageNoStr); } CrawlerConfig config = new CrawlerConfig(name, defaultCharset, url, delay, maxPageNo, nextPageRegex, extractLinksElementId, parserName, crawlerName, parser); WebCrawler crawler = null; //get WebCrawler instance throw reflection if (StringUtils.isBlank(crawlerName)) { crawler = new DefaultWebCrawler(config); } else { crawler = (WebCrawler)Reflections.constructorNewInstance(crawlerName, new Class[] { CrawlerConfig.class }, new CrawlerConfig[] { config }); } crawlers.add(crawler); } } catch (Throwable e) { logger.error(e.getMessage(),e); } return crawlers; }
Example 16
Source File: AssignmentPreferenceInfo.java From unitime with Apache License 2.0 | 4 votes |
public void load(Element root) { int version = Integer.parseInt(root.attributeValue("version")); if (version==sVersion) { iNormalizedTimePreference = Double.parseDouble(root.elementText("normTimePref")); iBestNormalizedTimePreference = Double.parseDouble(root.elementText("bestNormTimePref")); iTimePreference = Integer.parseInt(root.elementText("timePref")); for (Iterator i=root.elementIterator("roomPref");i.hasNext();) { Element e = (Element)i.next(); iRoomPreference.put(Long.valueOf(e.attributeValue("id")),Integer.valueOf(e.getText())); } iBestRoomPreference = Integer.parseInt(root.elementText("bestRoomPref")); iNrStudentConflicts = Integer.parseInt(root.elementText("nrStudentConf")); iNrHardStudentConflicts = Integer.parseInt(root.elementText("nrHardStudentConf")); iNrDistanceStudentConflicts = Integer.parseInt(root.elementText("nrDistanceStudentConf")); iNrCommitedStudentConflicts = Integer.parseInt(root.elementText("nrCommitedStudentConf")); iNrTimeLocations = Integer.parseInt(root.elementText("nrTimeLoc")); iNrRoomLocations = Integer.parseInt(root.elementText("nrRoomLoc")); iNrSameRoomPlacementsNoConf = Integer.parseInt(root.elementText("nrSameRoomPlacNoConf")); iNrSameTimePlacementsNoConf = Integer.parseInt(root.elementText("nrSameTimePlacNoConf")); iNrPlacementsNoConf = Integer.parseInt(root.elementText("nrPlacNoConf")); iBtbInstructorPreference = Integer.parseInt(root.elementText("btbInstrPref")); iIsInitial = Boolean.valueOf(root.elementText("isInitial")).booleanValue(); iInitialAssignment = root.elementText("iniAssign"); iHasInitialSameTime = Boolean.valueOf(root.elementText("hasIniSameTime")).booleanValue(); iHasInitialSameRoom = Boolean.valueOf(root.elementText("hasIniSameRoom")).booleanValue(); iPerturbationPenalty = Double.parseDouble(root.elementText("pertPenalty")); iTooBigRoomPreference = Integer.parseInt(root.elementText("tooBig")); iMinRoomSize = Long.parseLong(root.elementText("minSize")); iUselessHalfHours = Integer.parseInt(root.elementText("uselessHalfHours")); iDeptBalancPenalty = Double.parseDouble(root.elementText("deptBalanc")); iGroupConstraintPref = Integer.parseInt(root.elementText("groupConstr")); if (root.elementText("spread")!=null) iSpreadPenalty = Double.parseDouble(root.elementText("spread")); if (root.elementText("maxSpread")!=null) iMaxSpreadPenalty = Double.parseDouble(root.elementText("maxSpread")); else iMaxSpreadPenalty = iSpreadPenalty; if (root.elementText("maxDeptBalanc")!=null) iMaxDeptBalancPenalty = Integer.parseInt(root.elementText("maxDeptBalanc")); else iMaxDeptBalancPenalty = (int)iDeptBalancPenalty; if (root.elementText("datePref") != null) iDatePatternPref = Integer.parseInt(root.elementText("datePref")); if (root.elementText("studentGroupPercent") != null) iStudentGroupPercent = Integer.valueOf(root.elementText("studentGroupPercent")); iStudentGroupComment = root.elementText("studentGroupComment"); } }
Example 17
Source File: SQLStoreImpl.java From anyline with Apache License 2.0 | 4 votes |
/** * 解析sql.xml文件 * * @param file file * @return return */ private static Hashtable<String, SQL> parseSQLFile(File file) { Hashtable<String, SQL> result = new Hashtable<String, SQL>(); String fileName = file.getPath(); String dirName = ""; if (sqlDir.contains(ConfigTable.getWebRoot())) { dirName = sqlDir + FileUtil.getFileSeparator(); } else { dirName = new File(ConfigTable.getWebRoot(), sqlDir).getPath() + FileUtil.getFileSeparator(); } fileName = fileName.substring(fileName.indexOf("sql") + 4, fileName.indexOf(".xml")).replace("/", ".").replace("\\", ".").replace("..", "."); Document document = createDocument(file); if (null == document) { return result; } Element root = document.getRootElement(); //全局条件分组 Map<String, List<Condition>> gloableConditions = new HashMap<String, List<Condition>>(); for (Iterator<?> itrCons = root.elementIterator("conditions"); itrCons.hasNext(); ) { Element conditionGroupElement = (Element) itrCons.next(); String groupId = conditionGroupElement.attributeValue("id"); List<Condition> conditions = new ArrayList<Condition>(); gloableConditions.put(groupId, conditions); for (Iterator<?> itrParam = conditionGroupElement.elementIterator("condition"); itrParam.hasNext(); ) { conditions.add(parseCondition(null, null, (Element) itrParam.next())); } } for (Iterator<?> itrSql = root.elementIterator("sql"); itrSql.hasNext(); ) { Element sqlElement = (Element) itrSql.next(); String sqlId = fileName + ":" + sqlElement.attributeValue("id"); //SQL 主键 boolean strict = BasicUtil.parseBoolean(sqlElement.attributeValue("strict"), false); //是否严格格式 true:java中不允许添加XML定义之外的临时条件 String sqlText = sqlElement.elementText("text"); //SQL 文本 SQL sql = new XMLSQLImpl(); sql.setDataSource(fileName + ":" + sqlId); sql.setText(sqlText); sql.setStrict(strict); for (Iterator<?> itrParam = sqlElement.elementIterator("condition"); itrParam.hasNext(); ) { parseCondition(sql, gloableConditions, (Element) itrParam.next()); } String group = sqlElement.elementText("group"); String order = sqlElement.elementText("order"); sql.group(group); sql.order(order); if (ConfigTable.isSQLDebug()) { log.warn("[解析SQL][id:{}]\n[text:{}]", sqlId, sqlText); } result.put(sqlId, sql); } return result; }
Example 18
Source File: CaseResult.java From junit-plugin with MIT License | 4 votes |
private static String getError(Element testCase) { String msg = testCase.elementText("error"); if(msg!=null) return msg; return testCase.elementText("failure"); }
Example 19
Source File: ScormCPManifestTreeModel.java From olat with Apache License 2.0 | 4 votes |
private GenericTreeNode buildNode(final Element item) { final GenericTreeNode treeNode = new GenericTreeNode(); // extract title String title = item.elementText("title"); if (title == null) { title = item.attributeValue("identifier"); } treeNode.setAltText(title); treeNode.setTitle(title); if (item.getName().equals("organization")) { treeNode.setIconCssClass("o_scorm_org"); treeNode.setAccessible(false); } else if (item.getName().equals("item")) { scormIdToNode.put(new Integer(nodeId).toString(), treeNode); nodeToId.put(treeNode, new Integer(nodeId)); // set node images according to scorm sco status final String itemStatusDesc = (String) itemStatus.get(Integer.toString(nodeId)); treeNode.setIconCssClass("o_scorm_item"); if (itemStatusDesc != null) { // add icon decorator for current status treeNode.setIconDecorator1CssClass("o_scorm_" + itemStatusDesc); } nodeId++; // set resolved file path directly final String identifierref = item.attributeValue("identifierref"); final XPath meta = rootElement.createXPath("//ns:resource[@identifier='" + identifierref + "']"); meta.setNamespaceURIs(nsuris); final String href = (String) resources.get(identifierref); if (href != null) { treeNode.setUserObject(href); // allow lookup of a treenode given a href so we can quickly adjust the menu if the user clicks on hyperlinks within the text hrefToTreeNode.put(href, treeNode); } else { treeNode.setAccessible(false); } } final List chds = item.elements("item"); final int childcnt = chds.size(); for (int i = 0; i < childcnt; i++) { final Element childitem = (Element) chds.get(i); final GenericTreeNode gtnchild = buildNode(childitem); treeNode.addChild(gtnchild); } return treeNode; }
Example 20
Source File: WxXmlUtil.java From WeixinMultiPlatform with Apache License 2.0 | 3 votes |
/** * <code> * <xml><br /> * <ToUserName><![CDATA[toUser]]></ToUserName><br /> * <FromUserName><![CDATA[FromUser]]></FromUserName><br /> * <CreateTime>123456789</CreateTime><br /> * <MsgType><![CDATA[event]]></MsgType><br /> * <Event><![CDATA[EVENT]]></Event><br /> * <EventKey><![CDATA[EVENTKEY]]></EventKey><br /> * </xml> * </code> * * @param xmlstr * @return * @throws DocumentException */ public static WxMsgEventEntity getMsgEvent(Element ele) throws DocumentException { WxMsgEventEntity result = msgEntityFactory(WxMsgEventEntity.class, ele); result.setEvent(strVal(ele, "Event")); if (ele.elementText("EventKey") != null) { result.setEventKey(strVal(ele, "EventKey")); } if (ele.elementText("Ticket") != null) { result.setEventKey(strVal(ele, "Ticket")); } return result; }