/** * @param mobile * @param content * @return 0——提交成功 1——账号无效 2——密码错误 3——msgid不唯一 4——存在无效手机号码 5——手机号码个数超过最大限制 6——短信内容超过最大限制 * 7——扩展子号码无效(验证格式和长度,不能超过20位) 8——发送时间格式无效 9——请求来源地址无效 10——内容包含敏感词 11——余额不足 97——接入方式错误 * 98——系统繁忙 99——消息格式错误 */ public static int sendSMS(String mobile, String content) { System.out.println("成功进入短信发送方法内部!"); mobile = mobile.replaceAll(",|;|;", ","); String url = "http://3tong.net/http/sms/Submit"; Map<String, String> params = new LinkedHashMap<String, String>(); String message = "<?xml version='1.0' encoding='UTF-8'?><message>" + "<account>" + account + "</account>" + "<password>" + md5(pwd) + "</password>" + "<msgid></msgid><phones>" + mobile + "</phones><content>" + content + "</content>" + "<subcode></subcode><sendtime></sendtime></message>"; params.put("message", message); String resp = doPost(url, params); Document doc = null; try { doc = DocumentHelper.parseText(resp); Element root = doc.getRootElement(); System.out.println(root); Element resultElement = root.element("result"); return Integer.parseInt(resultElement.getData().toString()); } catch (Exception e) { log.info("返回的resp有问题"); e.printStackTrace(); return -1; } }
private boolean authenticated(Document sentIndicators) { Element userElement = sentIndicators.getRootElement().element("user"); Element passwordElement = sentIndicators.getRootElement().element("drowssap"); if (userElement == null || passwordElement == null) { return false; } String user = (String) userElement.getData(); String password = (String) passwordElement.getData(); Login login = new Login(); login.setLoginName(user); login.setPassword(password); Login loginInfo = loginDAO.getValidateLogin(login); return loginInfo != null; }
/** * Reads location list (each location being specified by a doublet (longitude,latitude)) and * returns a {@link LocationList} */ private LocationList get2DLocList(Element posList) { LocationList locList = new LocationList(); String positionList = (String) posList.getData(); StringTokenizer st = new StringTokenizer(positionList); while (st.hasMoreTokens()) { double lon = Double.valueOf(st.nextToken()); double lat = Double.valueOf(st.nextToken()); locList.add(new Location(lat, lon)); } return locList; }
public static Element getWorkspace(Document doc, String workspaceName) { List<Element> workspaces = doc.getRootElement().elements("workspace"); Element workspace = null; if (workspaces.size() > 0) { for (Element wSpace : workspaces) { Element repoInfo = wSpace.element(CMISRA_REPO_INFO); Element repoId = repoInfo.element(CMIS_REPO_NAME); if (workspaceName.equals(repoId.getData())) { return workspace = wSpace; } } } else { workspace = null; } return workspace; }
/** * Reads incremental evenly discretized magnitude frequency distribution data and returns {@link * IncrementalMagFreqDist} */ private IncrementalMagFreqDist getEvenlyDiscretizedMagFreqDist( Element evenlyDiscretizedMagFreqDist) { IncrementalMagFreqDist magFreqDist; double binSize = Double.valueOf(evenlyDiscretizedMagFreqDist.attributeValue(BIN_SIZE)); double minVal = Double.valueOf(evenlyDiscretizedMagFreqDist.attributeValue(MIN_VAL)); StringTokenizer st = new StringTokenizer((String) evenlyDiscretizedMagFreqDist.getData()); magFreqDist = new IncrementalMagFreqDist(minVal, st.countTokens(), binSize); int index = 0; while (st.hasMoreTokens()) { magFreqDist.add(index, Double.valueOf(st.nextToken())); index++; } return magFreqDist; }
private void parseXML(URL url) { /* Here I am parsing from an XML File, using Dom4J framework. the file (test.xml) is setup so it holds info for the current game On parsing from the file I will populate the fields for: Teams, scores, goals scored and players who scored. Running tight on time, this will be fully implemented next week. This file will not be a local file, but a downloaded stream from server */ String team1G = "", team2G = ""; try { SAXReader reader = new SAXReader(); Document document = reader.read(url); Element rootElement = document.getRootElement(); System.out.println("Root Element: " + rootElement.getName()); for (Iterator i = rootElement.elementIterator(); i.hasNext(); ) { Element element = (Element) i.next(); System.out.println(element.getName()); for (Iterator i2 = element.elementIterator(); i2.hasNext(); ) { Element element2 = (Element) i2.next(); // Node is a game - parse game if ("isLive".equals(element2.getName())) { if ("false".equals((String) element2.getData())) { // If its not live dont show System.out.println("Game is not live, revert to Sim"); revertToSimulation(); break; } } if ("team1".equals(element2.getName())) { // Node is Team 1 - parse info for (Iterator team1Iterator = element2.elementIterator(); team1Iterator.hasNext(); ) { Element team1 = (Element) team1Iterator.next(); if ("name".equals((String) team1.getName())) { Team1Name.setText((String) team1.getData()); } if ("score".equals((String) team1.getName())) { teamOneScore.setText((String) team1.getData()); } if ("goals".equals((String) team1.getName())) { /* Parse the goals scored by this team */ for (Iterator team1GoalsIterator = team1.elementIterator(); team1GoalsIterator.hasNext(); ) { Element goals = (Element) team1GoalsIterator.next(); if ("goal".equals((String) goals.getName())) { for (Iterator t1gIgoalIterator = goals.elementIterator(); t1gIgoalIterator.hasNext(); ) { Element goal = (Element) t1gIgoalIterator.next(); if ("player".equals((String) goal.getName())) { // Parse the Player team1G = team1G + (String) goal.getData(); } if ("time".equals((String) goal.getName())) { // Parse the Time of Score team1G = team1G + " : " + (String) goal.getData() + "\n"; } } } } } } } if ("team2".equals(element2.getName())) { // Node is Team 2 - parse info for (Iterator team2Iterator = element2.elementIterator(); team2Iterator.hasNext(); ) { Element team2 = (Element) team2Iterator.next(); if ("name".equals((String) team2.getName())) { Team2Name.setText((String) team2.getData()); } if ("score".equals((String) team2.getName())) { teamTwoScore.setText((String) team2.getData()); } if ("goals".equals((String) team2.getName())) { /* Parse the goals scored by thie team */ for (Iterator team2GoalsIterator = team2.elementIterator(); team2GoalsIterator.hasNext(); ) { Element goals = (Element) team2GoalsIterator.next(); if ("goal".equals((String) goals.getName())) { /* Parse a Goal */ for (Iterator t2gIgoalIterator = goals.elementIterator(); t2gIgoalIterator.hasNext(); ) { Element goal = (Element) t2gIgoalIterator.next(); if ("player".equals((String) goal.getName())) { /* Parse the Player */ team2G = team2G + (String) goal.getData(); } if ("time".equals((String) goal.getName())) { /* Parse the time of score */ team2G = team2G + " : " + (String) goal.getData() + "\n"; } } } } } } } } } } catch (DocumentException e) { System.out.print(e.getMessage()); } team1GoalsArea.setText(team1G); team2GoalsArea.setText(team2G); }