Java Code Examples for org.dom4j.io.SAXReader#read()
The following examples show how to use
org.dom4j.io.SAXReader#read() .
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: DOM4JSerializer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public static DOM4JSettingsNode readSettingsFile(ImportInteraction importInteraction, FileFilter fileFilter) { File file = importInteraction.promptForFile(fileFilter); if (file == null) { return null; } if (!file.exists()) { importInteraction.reportError("File does not exist: " + file.getAbsolutePath()); return null; //we should really sit in a loop until they cancel or give us a valid file. } try { SAXReader reader = new SAXReader(); Document document = reader.read(file); return new DOM4JSettingsNode(document.getRootElement()); } catch (Throwable t) { LOGGER.error("Unable to read file: " + file.getAbsolutePath(), t); importInteraction.reportError("Unable to read file: " + file.getAbsolutePath()); return null; } }
Example 2
Source File: WordTableCellContentOleObject.java From sun-wordtable-read with Apache License 2.0 | 6 votes |
/** * 由单元格内容xml构建Document * * @param xml * @return */ private Document buildDocument(String xml) { // dom4j解析器的初始化 SAXReader reader = new SAXReader(new DocumentFactory()); Map<String, String> map = new HashMap<String, String>(); map.put("o", "urn:schemas-microsoft-com:office:office"); map.put("v", "urn:schemas-microsoft-com:vml"); map.put("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); map.put("a", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); map.put("xdr", "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"); map.put("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"); map.put("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); reader.getDocumentFactory().setXPathNamespaceURIs(map); // xml文档的namespace设置 InputSource source = new InputSource(new StringReader(xml)); source.setEncoding("utf-8"); try { Document doc = reader.read(source); return doc; } catch (DocumentException e) { logger.error(e.getMessage(), e); } return null; }
Example 3
Source File: Parser.java From ParsePDM with Apache License 2.0 | 6 votes |
public PDM pdmParser(String pdmFileName) throws Exception { SAXReader reader = new SAXReader(); Document doc = reader.read(pdmFileName); Node model = doc.selectSingleNode("//c:Children/o:Model"); pdm.setId(((Element) model).attributeValue("Id")); pdm.setName(model.selectSingleNode("a:Name").getText()); pdm.setCode(model.selectSingleNode("a:Code").getText()); Node dbms = model.selectSingleNode("//o:Shortcut"); pdm.setDBMSCode(dbms.selectSingleNode("a:Code").getText()); pdm.setDBMSName(dbms.selectSingleNode("a:Name").getText()); System.out.println("解析PDM为:" + pdm.getCode() + "(" + pdm.getName() + ") DBMS为:" + pdm.getDBMSCode() + "(" + pdm.getDBMSName() + ")"); pdm.setUsers(pdmUserParser(model)); pdm.setTables(pdmTableParser(model)); pdm.setPhysicalDiagrams(pdmPhysicalDiagramParser(model)); pdm.setReferences(pdmReferenceParser(model)); return pdm; }
Example 4
Source File: CheckboxTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void collectionOfPetsAsStringNotSelected() throws Exception { this.tag.setPath("pets"); this.tag.setValue("Santa's Little Helper"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("pets", checkboxElement.attribute("name").getValue()); assertNull(checkboxElement.attribute("checked")); }
Example 5
Source File: CheckboxTagTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void hiddenElementOmittedOnDisabled() throws Exception { this.tag.setPath("someBoolean"); this.tag.setDisabled(true); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals("Both tag and hidden element rendered incorrectly", 1, rootElement.elements().size()); Element checkboxElement = (Element) rootElement.elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("someBoolean", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals("true", checkboxElement.attribute("value").getValue()); }
Example 6
Source File: WorkerResource.java From DataLink with Apache License 2.0 | 6 votes |
@POST @Path("/toEditLogback/{workerId}") public Map<String, String> toEditLogback(@PathParam("workerId") String workerId) throws Throwable { logger.info("Receive a request to edit logback.xml, with workerId " + workerId); String path = System.getProperty("logback.configurationFile"); SAXReader reader = new SAXReader(); Map<String, String> result = new HashMap<>(); try { Document document = reader.read(new File(path)); result.put("content", document.asXML()); return result; } catch (DocumentException e) { logger.info("reading logback.xml error:", e); result.put("content", e.getMessage()); } return result; }
Example 7
Source File: OptionsTagTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void withoutItemsEnumParent() throws Exception { BeanWithEnum testBean = new BeanWithEnum(); testBean.setTestEnum(TestEnum.VALUE_2); getPageContext().getRequest().setAttribute("testBean", testBean); this.selectTag.setPath("testBean.testEnum"); this.selectTag.doStartTag(); int result = this.tag.doStartTag(); assertEquals(BodyTag.SKIP_BODY, result); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); this.selectTag.doEndTag(); String output = getWriter().toString(); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Node value1 = rootElement.selectSingleNode("option[@value = 'VALUE_1']"); Node value2 = rootElement.selectSingleNode("option[@value = 'VALUE_2']"); assertEquals("TestEnum: VALUE_1", value1.getText()); assertEquals("TestEnum: VALUE_2", value2.getText()); assertEquals(value2, rootElement.selectSingleNode("option[@selected]")); }
Example 8
Source File: GMLMapFormat.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Read a GMLMap from a Reader. @param reader The Reader to read. @return A new GMLMap. @throws DocumentException If there is a problem parsing the XML. @throws MapException If there is a problem reading the map. */ public GMLMap read(Reader reader) throws DocumentException, MapException { Logger.debug("Parsing GML"); SAXReader saxReader = new SAXReader(); Document doc = saxReader.read(reader); Logger.debug("Building map"); return read(doc); }
Example 9
Source File: SelectTagTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void multipleExplicitlyTrue() throws Exception { this.tag.setPath("name"); this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); this.tag.setMultiple("true"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Element selectElement = rootElement.element("select"); assertEquals("select", selectElement.getName()); assertEquals("name", selectElement.attribute("name").getValue()); assertEquals("multiple", selectElement.attribute("multiple").getValue()); List children = selectElement.elements(); assertEquals("Incorrect number of children", 4, children.size()); Element inputElement = rootElement.element("input"); assertNotNull(inputElement); }
Example 10
Source File: OptionsTagTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void withCollectionAndDynamicAttributes() throws Exception { String dynamicAttribute1 = "attr1"; String dynamicAttribute2 = "attr2"; getPageContext().setAttribute( SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false)); this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); this.tag.setId("myOption"); this.tag.setCssClass("myClass"); this.tag.setOnclick("CLICK"); this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1); this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); List children = rootElement.elements(); assertEquals("Incorrect number of children", 4, children.size()); Element element = (Element) rootElement.selectSingleNode("option[@value = 'UK']"); assertEquals("UK node not selected", "selected", element.attribute("selected").getValue()); assertEquals("myOption3", element.attribute("id").getValue()); assertEquals("myClass", element.attribute("class").getValue()); assertEquals("CLICK", element.attribute("onclick").getValue()); assertEquals(dynamicAttribute1, element.attribute(dynamicAttribute1).getValue()); assertEquals(dynamicAttribute2, element.attribute(dynamicAttribute2).getValue()); }
Example 11
Source File: TestReport.java From PatatiumAppUi with GNU General Public License v2.0 | 5 votes |
private String getTestngParametersValue(String path,String ParametersName) throws DocumentException, IOException { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } String value=null; SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(); i.hasNext();) { Element page = (Element) i.next(); if(page.attributeCount()>0) { if (page.attribute(0).getValue().equalsIgnoreCase(ParametersName)) { value=page.attribute(1).getValue(); //System.out.println(page.attribute(1).getValue()); } continue; } //continue; } return value; }
Example 12
Source File: SelectTagTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void multipleForCollection() throws Exception { this.bean.setSomeList(new ArrayList()); this.tag.setPath("someList"); this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Element selectElement = rootElement.element("select"); assertEquals("select", selectElement.getName()); assertEquals("someList", selectElement.attribute("name").getValue()); assertEquals("multiple", selectElement.attribute("multiple").getValue()); List children = selectElement.elements(); assertEquals("Incorrect number of children", 4, children.size()); Element inputElement = rootElement.element("input"); assertNotNull(inputElement); }
Example 13
Source File: BpmnParseHandlerImpl.java From FoxBPM with Apache License 2.0 | 5 votes |
private BpmnModel loadBpmnModel(String processId, InputStream is) { BpmnXMLConverter converter = new BpmnXMLConverter(); SAXReader reader = new SAXReader(); BpmnModel bpmnModel = null; try { Document doc = reader.read(is); bpmnModel = converter.convertToBpmnModel(doc); } catch (Exception ex) { ex.printStackTrace(); } return bpmnModel; }
Example 14
Source File: CheckboxesTagTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void withMultiValueWithReverseEditor() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"FOO", "BAR", "BAZ"}); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME); MyLowerCaseEditor editor = new MyLowerCaseEditor(); bindingResult.getPropertyEditorRegistry().registerCustomEditor(String.class, editor); getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element spanElement1 = (Element) document.getRootElement().elements().get(0); Element checkboxElement1 = (Element) spanElement1.elements().get(0); assertEquals("input", checkboxElement1.getName()); assertEquals("checkbox", checkboxElement1.attribute("type").getValue()); assertEquals("stringArray", checkboxElement1.attribute("name").getValue()); assertEquals("checked", checkboxElement1.attribute("checked").getValue()); assertEquals("FOO", checkboxElement1.attribute("value").getValue()); Element spanElement2 = (Element) document.getRootElement().elements().get(1); Element checkboxElement2 = (Element) spanElement2.elements().get(0); assertEquals("input", checkboxElement2.getName()); assertEquals("checkbox", checkboxElement2.attribute("type").getValue()); assertEquals("stringArray", checkboxElement2.attribute("name").getValue()); assertEquals("checked", checkboxElement2.attribute("checked").getValue()); assertEquals("BAR", checkboxElement2.attribute("value").getValue()); Element spanElement3 = (Element) document.getRootElement().elements().get(2); Element checkboxElement3 = (Element) spanElement3.elements().get(0); assertEquals("input", checkboxElement3.getName()); assertEquals("checkbox", checkboxElement3.attribute("type").getValue()); assertEquals("stringArray", checkboxElement3.attribute("name").getValue()); assertNull("not checked", checkboxElement3.attribute("checked")); assertEquals("BAZ", checkboxElement3.attribute("value").getValue()); }
Example 15
Source File: CheckboxesTagTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void withMultiValueArrayWithDelimiter() throws Exception { this.tag.setDelimiter("<br/>"); this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element spanElement1 = (Element) document.getRootElement().elements().get(0); Element delimiterElement1 = spanElement1.element("br"); assertNull(delimiterElement1); Element checkboxElement1 = (Element) spanElement1.elements().get(0); assertEquals("input", checkboxElement1.getName()); assertEquals("checkbox", checkboxElement1.attribute("type").getValue()); assertEquals("stringArray", checkboxElement1.attribute("name").getValue()); assertEquals("checked", checkboxElement1.attribute("checked").getValue()); assertEquals("foo", checkboxElement1.attribute("value").getValue()); assertEquals("foo", spanElement1.getStringValue()); Element spanElement2 = (Element) document.getRootElement().elements().get(1); Element delimiterElement2 = (Element) spanElement2.elements().get(0); assertEquals("br", delimiterElement2.getName()); Element checkboxElement2 = (Element) spanElement2.elements().get(1); assertEquals("input", checkboxElement2.getName()); assertEquals("checkbox", checkboxElement2.attribute("type").getValue()); assertEquals("stringArray", checkboxElement2.attribute("name").getValue()); assertEquals("checked", checkboxElement2.attribute("checked").getValue()); assertEquals("bar", checkboxElement2.attribute("value").getValue()); assertEquals("bar", spanElement2.getStringValue()); Element spanElement3 = (Element) document.getRootElement().elements().get(2); Element delimiterElement3 = (Element) spanElement3.elements().get(0); assertEquals("br", delimiterElement3.getName()); Element checkboxElement3 = (Element) spanElement3.elements().get(1); assertEquals("input", checkboxElement3.getName()); assertEquals("checkbox", checkboxElement3.attribute("type").getValue()); assertEquals("stringArray", checkboxElement3.attribute("name").getValue()); assertNull("not checked", checkboxElement3.attribute("checked")); assertEquals("baz", checkboxElement3.attribute("value").getValue()); assertEquals("baz", spanElement3.getStringValue()); }
Example 16
Source File: CheckboxesTagTests.java From spring-analysis-note with MIT License | 4 votes |
/** * Test case where items toString() doesn't fit the item ID */ @Test public void collectionOfItemPets() throws Exception { this.tag.setPath("someSet"); List allPets = new ArrayList(); allPets.add(new ItemPet("PET1")); allPets.add(new ItemPet("PET2")); allPets.add(new ItemPet("PET3")); this.tag.setItems(allPets); this.tag.setItemValue("name"); this.tag.setItemLabel("label"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element spanElement1 = (Element) document.getRootElement().elements().get(0); Element checkboxElement1 = (Element) spanElement1.elements().get(0); assertEquals("input", checkboxElement1.getName()); assertEquals("checkbox", checkboxElement1.attribute("type").getValue()); assertEquals("someSet", checkboxElement1.attribute("name").getValue()); assertNotNull("should be checked", checkboxElement1.attribute("checked")); assertEquals("checked", checkboxElement1.attribute("checked").getValue()); assertEquals("PET1", checkboxElement1.attribute("value").getValue()); assertEquals("PET1", spanElement1.getStringValue()); Element spanElement2 = (Element) document.getRootElement().elements().get(1); Element checkboxElement2 = (Element) spanElement2.elements().get(0); assertEquals("input", checkboxElement2.getName()); assertEquals("checkbox", checkboxElement2.attribute("type").getValue()); assertEquals("someSet", checkboxElement2.attribute("name").getValue()); assertNotNull("should be checked", checkboxElement2.attribute("checked")); assertEquals("checked", checkboxElement2.attribute("checked").getValue()); assertEquals("PET2", checkboxElement2.attribute("value").getValue()); assertEquals("PET2", spanElement2.getStringValue()); Element spanElement3 = (Element) document.getRootElement().elements().get(2); Element checkboxElement3 = (Element) spanElement3.elements().get(0); assertEquals("input", checkboxElement3.getName()); assertEquals("checkbox", checkboxElement3.attribute("type").getValue()); assertEquals("someSet", checkboxElement3.attribute("name").getValue()); assertNull("not checked", checkboxElement3.attribute("checked")); assertEquals("PET3", checkboxElement3.attribute("value").getValue()); assertEquals("PET3", spanElement3.getStringValue()); }
Example 17
Source File: PageObjectAutoCodeForYaml.java From PatatiumAppUi with GNU General Public License v2.0 | 4 votes |
public static void autoCode2() throws Exception { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } SAXReader reader = new SAXReader(); Document document = reader.read(file); //对象库xml文件根节点 Element root = document.getRootElement(); //遍历根节点下的第一个节点(page节点) for(Iterator<?> i=root.elementIterator();i.hasNext();) { Element page=(Element)i.next(); //获取page节点的name属性值 String pageName=page.attribute(0).getValue(); System.out.println(pageName); //将pageName存储为数组 String[] pageNameArray=pageName.split("\\."); System.out.println(pageNameArray); System.out.println(pageNameArray[0]); //获取要写入的page所属的类名 String pageClassName=pageNameArray[4].toString(); //获取对象库包名 String packageName=pageNameArray[0].toString()+"."+pageNameArray[1].toString()+"."+pageNameArray[2].toString()+"."+pageNameArray[3].toString(); //--自动编写对象库代码(XXPage.java)开始-- StringBuffer sb=new StringBuffer("package "+packageName+";\n"); sb.append("import java.io.IOException;\n"); sb.append("import java.io.InputStream;\n"); sb.append("import org.webdriver.patatiumappui.utils.BaseAction;\n"); sb.append("import org.webdriver.patatiumappui.utils.Locator;\n"); sb.append("import org.webdriver.patatiumappui.pageObjectConfig.PageObjectAutoCode;"); sb.append("//"+page.attribute(2).getValue()+"_对象库类\n"); sb.append("public class "+ pageClassName+" extends BaseAction {\n"); sb.append("//用于eclipse工程内运行查找对象库文件路径\n"); sb.append("private String path=\"src/main/java/org/webdriver/patatiumappui/pageObjectConfig/UILibrary.xml\";\n"); //sb.append("//用户打包成jar后查找对象库文件路径\n"); //sb.append("private InputStream pathInputStream=PageObjectAutoCode.class.getClassLoader().getResourceAsStream(\"net/hk515/pageObjectConfig/UILibrary.xml\"); \n"); sb.append(" public " + pageClassName + "() {\n"); sb.append("//工程内读取对象库文件\n "); sb.append("setXmlObjectPath(path);\n"); sb.append("getLocatorMap();"); sb.append("\n}"); //sb.append("\n private String path=PageObjectAutoCode.class.getClassLoader().getResource(\"net/hk515/pageObjectConfig/UILibrary.xml\").getPath();"); //遍历Page节点下的Locator节点 for(Iterator<?> j=page.elementIterator();j.hasNext();) { //获取locaror节点 Element locator =(Element)j.next(); String locatorName=locator.getTextTrim(); if(locator.attributeCount()>3) {sb.append("\n/***\n" + "* "+locator.attribute(3).getValue()+"\n" + "* @return\n" + "* @throws IOException\n" + "*/\n"); } else { sb.append("\n"); } sb.append("public Locator "+locatorName+"() throws IOException\n {\n"); //sb.append(" setXmlObjectPath(path);\n"); sb.append(" Locator locator=getLocator(\""+locatorName+"\");\n"); sb.append(" return locator;\n }\n"); } sb.append("}"); //将自动生成的PageObject代码写入文件 File pageObjectFile=new File("src/main/java/org/webdriver/patatiumappui/pageObject/"+pageClassName+".java"); if(pageObjectFile.exists()) { pageObjectFile.delete();; } try { FileWriter fileWriter=new FileWriter(pageObjectFile, false); BufferedWriter output = new BufferedWriter(fileWriter); output.write(sb.toString()); output.flush(); output.close(); } catch (IOException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } System.out.println(sb); Log log=new Log(PageObjectAutoCodeForYaml.class); log.info("自动生成对象库java代码成功"); } }
Example 18
Source File: Config.java From PatatiumWebUi with Apache License 2.0 | 4 votes |
public static void SetXML(String Base_Url,String UserName,String PassWord,String driver,String nodeURL,String Recipients,String ReportUrl,String LogUrl) throws IOException, DocumentException { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(); i.hasNext();) { Element page = (Element) i.next(); if(page.attributeCount()>0) { if (page.attribute(0).getValue().equalsIgnoreCase("Base_Url")) { page.attribute(1).setValue(Base_Url); //System.out.println(page.attribute(1).getValue()); } if (page.attribute(0).getValue().equalsIgnoreCase("UserName")) { page.attribute(1).setValue(UserName); } if (page.attribute(0).getValue().equalsIgnoreCase("PassWord")) { page.attribute(1).setValue(PassWord); } if (page.attribute(0).getValue().equalsIgnoreCase("driver")) { page.attribute(1).setValue(driver); } if (page.attribute(0).getValue().equalsIgnoreCase("nodeURL")) { page.attribute(1).setValue("http://"+nodeURL+"/wd/hub"); } if (page.attribute(0).getValue().equalsIgnoreCase("Recipients")) { page.attribute(1).setValue(Recipients); } if (page.attribute(0).getValue().equalsIgnoreCase("ReportUrl")) { page.attribute(1).setValue(ReportUrl); } if (page.attribute(0).getValue().equalsIgnoreCase("LogUrl")) { page.attribute(1).setValue(LogUrl); } continue; } //continue; } if (driver.equalsIgnoreCase("FirefoxDriver")) { driver="火狐浏览器"; } else if (driver.equalsIgnoreCase("ChormeDriver")) { driver="谷歌浏览器"; } else if(driver.equalsIgnoreCase("InternetExplorerDriver-8")) { driver="IE8浏览器"; } else if(driver.equalsIgnoreCase("InternetExplorerDriver-9")) { driver="IE9浏览器"; } else { driver="火狐浏览器"; } try{ /** 格式化输出,类型IE浏览一样 */ OutputFormat format = OutputFormat.createPrettyPrint(); /** 指定XML编码 */ format.setEncoding("gb2312"); /** 将document中的内容写入文件中 */ XMLWriter writer = new XMLWriter(new FileWriter(new File(path)),format); writer.write(document); writer.close(); /** 执行成功,需返回1 */ int returnValue = 1; System.out.println("设置配置环境:"+Base_Url + ";用户名:"+UserName + "密码:" + PassWord +"浏览器:" +driver +"成功!"); System.out.println("设置报表url:"+ReportUrl); System.out.println("设置报表日志:"+LogUrl); System.out.println("设置收件人地址:"+Recipients); }catch(Exception ex){ ex.printStackTrace(); System.out.println("设置配置环境:"+Base_Url + ";用户名:"+UserName + "密码:" + PassWord +"浏览器:" +driver +"失败!"); } }
Example 19
Source File: XmlUtil.java From minimybatis with MIT License | 4 votes |
/** * readMapperXml * * @param fileName * @param mappedStatements * @see */ @SuppressWarnings("rawtypes") public static void readMapperXml(File fileName, Configuration configuration) { try { // 创建一个读取器 SAXReader saxReader = new SAXReader(); saxReader.setEncoding(Constant.CHARSET_UTF8); // 读取文件内容 Document document = saxReader.read(fileName); // 获取xml中的根元素 Element rootElement = document.getRootElement(); // 不是beans根元素的,文件不对 if (!Constant.XML_ROOT_LABEL.equals(rootElement.getName())) { System.err.println("mapper xml文件根元素不是mapper"); return; } String namespace = rootElement.attributeValue(Constant.XML_SELECT_NAMESPACE); List<MappedStatement> statements = new ArrayList<>(); for (Iterator iterator = rootElement.elementIterator(); iterator.hasNext();) { Element element = (Element)iterator.next(); String eleName = element.getName(); MappedStatement statement = new MappedStatement(); if (SqlType.SELECT.value().equals(eleName)) { String resultType = element.attributeValue(Constant.XML_SELECT_RESULTTYPE); statement.setResultType(resultType); statement.setSqlCommandType(SqlType.SELECT); } else if (SqlType.UPDATE.value().equals(eleName)) { statement.setSqlCommandType(SqlType.UPDATE); } else { // 其他标签自己实现 System.err.println("不支持此xml标签解析:" + eleName); statement.setSqlCommandType(SqlType.DEFAULT); } //设置SQL的唯一ID String sqlId = namespace + "." + element.attributeValue(Constant.XML_ELEMENT_ID); statement.setSqlId(sqlId); statement.setNamespace(namespace); statement.setSql(CommonUtis.stringTrim(element.getStringValue())); statements.add(statement); System.out.println(statement); configuration.addMappedStatement(sqlId, statement); //这里其实是在MapperRegistry中生产一个mapper对应的代理工厂 configuration.addMapper(Class.forName(namespace)); } } catch (Exception e) { e.printStackTrace(); } }
Example 20
Source File: RadioButtonsTagTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void withMultiValueMapWithDelimiter() throws Exception { String delimiter = " | "; this.tag.setDelimiter(delimiter); this.tag.setPath("stringArray"); Map m = new LinkedHashMap(); m.put("foo", "FOO"); m.put("bar", "BAR"); m.put("baz", "BAZ"); this.tag.setItems(m); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element spanElement1 = (Element) document.getRootElement().elements().get(0); Element radioButtonElement1 = (Element) spanElement1.elements().get(0); assertEquals("input", radioButtonElement1.getName()); assertEquals("radio", radioButtonElement1.attribute("type").getValue()); assertEquals("stringArray", radioButtonElement1.attribute("name").getValue()); assertEquals("checked", radioButtonElement1.attribute("checked").getValue()); assertEquals("foo", radioButtonElement1.attribute("value").getValue()); assertEquals("FOO", spanElement1.getStringValue()); Element spanElement2 = (Element) document.getRootElement().elements().get(1); Element radioButtonElement2 = (Element) spanElement2.elements().get(0); assertEquals("input", radioButtonElement2.getName()); assertEquals("radio", radioButtonElement2.attribute("type").getValue()); assertEquals("stringArray", radioButtonElement2.attribute("name").getValue()); assertEquals("checked", radioButtonElement2.attribute("checked").getValue()); assertEquals("bar", radioButtonElement2.attribute("value").getValue()); assertEquals(delimiter + "BAR", spanElement2.getStringValue()); Element spanElement3 = (Element) document.getRootElement().elements().get(2); Element radioButtonElement3 = (Element) spanElement3.elements().get(0); assertEquals("input", radioButtonElement3.getName()); assertEquals("radio", radioButtonElement3.attribute("type").getValue()); assertEquals("stringArray", radioButtonElement3.attribute("name").getValue()); assertNull("not checked", radioButtonElement3.attribute("checked")); assertEquals("baz", radioButtonElement3.attribute("value").getValue()); assertEquals(delimiter + "BAZ", spanElement3.getStringValue()); }