@SuppressWarnings("deprecation") private String getStr(Que que, Collection queEntrys, int i) { // 拼接XML样式,逐个拼接 // 拼接标题 doc = DocumentHelper.createDocument(); root = doc.addElement("div"); root.setAttributeValue("value", que.getId().toString()); eleH1 = root.addElement("h1"); eleH1.setText(i + 1 + ". " + que.getQueDesc().toString()); eleH1.setAttributeValue("value", que.getId().toString()); // 拼接明细 eleDiv = root.addElement("div"); eleDiv.addAttribute("data-role", "controlgroup"); int k = 0; for (Iterator iter = queEntrys.iterator(); iter.hasNext(); k++) { queEntry = (Queentry) iter.next(); str = que.getId() + "|" + queEntry.getId(); eleLab = eleDiv.addElement("label"); eleLab.setText(String.valueOf((char) (charL + k)) + "." + queEntry.getDesc()); eleLab.addAttribute("for", str); eleInput = eleDiv.addElement("input"); eleInput.addAttribute("id", str); eleInput.addAttribute("type", "radio"); eleInput.addAttribute("name", "put" + i); eleInput.addAttribute("value", queEntry.getId().toString()); } return doc.getRootElement().asXML(); }
/** 配置xml文件的 方案名称、用户信息、剧情 */ @SuppressWarnings("deprecation") public static Document configXmlHead(ArrayList<String> a, String path) { doc = loadxml(path); Element famcEle = doc.getRootElement().element("方案名称"); famcEle.setAttributeValue("方案", a.get(0)); Element yhxxEle = doc.getRootElement().element("用户信息"); yhxxEle.setAttributeValue("名称", a.get(1)); Element jqEle = doc.getRootElement().element("剧情"); jqEle.setAttributeValue("想定名称", a.get(2)); return doc; // writeXml(doc,path); // System.out.println("成功配置 "+path+" xml文件的头部信息"); }
/** * 方法名: </br> 详述: </br>修改版本号和package 开发人员:谭明</br> 创建时间:Apr 1, 2014</br> * * @param pageName * @param project_path * @throws Exception */ public static void update_AndroidManifest_xml( String project_path, String enterpriseId, String appId, String appKey) throws Exception { File file = new File(project_path + File.separator + "AndroidManifest.xml"); String pageName = "app" + enterpriseId; String package_value = "com.cndatacom." + pageName; if (!file.exists()) { throw new Exception("项目AndroidManifest.xml文件不存在!"); } Document doc = null; try { doc = new SAXReader().read(file); Element root = doc.getRootElement(); root.setAttributeValue("package", package_value); logger.info("修改后的AndroidManifest.xml文件::" + doc.asXML()); List<Element> elementList = root.element("application").elements("meta-data"); for (Element childElement : elementList) { List<Attribute> aList = childElement.attributes(); String name = ""; Attribute a = null; for (Attribute attribute : aList) { String attributeName = attribute.getName(); if ("value".equals(attributeName)) { a = attribute; } else if ("name".equals(attributeName)) { name = attribute.getValue(); } } childElement.remove(a); if ("app_info".equals(name)) childElement.setAttributeValue("android:value", appId); else if ("app_key".equals(name)) childElement.setAttributeValue("android:value", appKey); } } catch (DocumentException e) { e.printStackTrace(); throw new Exception("读取项目AndroidManifest.xml文件出错!"); } try { XMLWriter writer = new XMLWriter(new FileOutputStream(file)); writer.write(doc); writer.close(); } catch (Exception e) { throw new Exception("输出项目AndroidManifest.xml文件出错!"); } }
private String checkAnwer(String strAn) { // TODO Auto-generated method stub a = strAn.split(";"); // 拼接XML 3列 doc = DocumentHelper.createDocument(); root = doc.addElement("table"); root.addAttribute("data-role", "table"); root.addAttribute("data-mode", "columntoggle"); root.addAttribute("class", "ui-responsive table-stripe"); ele = root.addElement("thead"); ele = ele.addElement("tr"); ele.addAttribute("class", "ui-bar-c"); // 列标题 ele.addElement("th").setText("题目"); eleH1 = ele.addElement("th"); eleH1.setText("选择"); eleH1.setAttributeValue("data-priority", "1"); eleH1 = ele.addElement("th"); eleH1.setText("正确答案"); eleH1.setAttributeValue("data-priority", "1"); ele = root.addElement("tbody"); // 增加信息行 for (String strA : a) { aS = strA.split("\\|"); // 注意 “|”的转义 ele = ele.addElement("tr"); que = queDao.findBystrId(aS[0]); // 题目 queEntry = queEntryDao.findBystrId(aS[1]); // 选择 // 判断回答是否正确 // if (queEntry.getId().equals(que.getAnswer())) { ele.addElement("td").setText(que.getQueDesc()); ele.addElement("td").setText(queEntry.getDesc()); ele.addElement("td").setText(queEntryDao.findBystrId(que.getAnswer()).getDesc()); // } else { // System.out.println("error"); // } } return doc.getRootElement().asXML(); }
/** * 方法名: </br> 详述: </br>修改生成apk的名称 开发人员:谭明</br> 创建时间:Apr 1, 2014</br> * * @param apkName * @param project_path * @throws Exception */ public static void updata_build_xml(String project_path, String apkName) throws Exception { Document doc = null; File file = new File(project_path + File.separator + "build.xml"); logger.info("project_path+File.separator:::" + project_path + File.separator + "build.xml"); if (!file.exists()) { throw new Exception("项目build.xml文件不存在!"); } try { doc = new SAXReader().read(file); } catch (DocumentException e) { throw new Exception("读取项目build.xml文件出错!"); } Element root = doc.getRootElement(); // 修改build 内容 root.setAttributeValue("name", apkName); logger.info("修改后的build.xml文件::" + doc.asXML()); try { XMLWriter writer = new XMLWriter(new FileOutputStream(file)); writer.write(doc); writer.close(); } catch (Exception e) { throw new Exception("输出项目build.xml文件出错!"); } }