List of usage examples for org.dom4j Element getText
String getText();
From source file:com.sharksharding.sql.SQLTemplate.java
License:Apache License
/** * dom4j?xml/* w ww .j a v a 2s . co m*/ * * @author gaoxianglong * * @param in * ? * * @exception XmlResolveException * * @return void */ @SuppressWarnings("unchecked") private void resolveXml(InputStream in) { if (null == in) return; Document document = null; SAXReader saxReader = new SAXReader(); try { document = saxReader.read(in); } catch (DocumentException e) { throw new XmlResolveException("xml resolve fail"); } Element root = document.getRootElement(); List<Element> elements = root.selectNodes(xpathExpression); if (!elements.isEmpty()) { for (Element element : elements) { final String sql = element.attribute(name).getValue(); sqlMap.put(sql, element.getText()); } } else { throw new XmlResolveException("element <sql/> not found"); } }
From source file:com.tedi.engine.XMLOutput.java
License:Open Source License
/** * Clean the element.//from w ww .j a v a 2 s . co m * * @param ele * The element. */ private void cleanElement(Element ele) { if (logger.isDebugEnabled()) { logger.debug("Cleaning the element " + ele); } // Attribute check shouldn't be necessary since only trying to write // populated attributes // but leave for now just in case for (Iterator i = ele.attributes().iterator(); i.hasNext();) { Attribute a = (Attribute) i.next(); if (!mapFile.isSuppressAttribIfEmpty() || a.getText().length() > 0) continue; if (!mapFile.isSuppressAttribIfHasOnlyWhitespace() || a.getText().trim().length() > 0) continue; ele.remove(a); } for (Iterator i = ele.elements().iterator(); i.hasNext();) { cleanElement((Element) i.next()); } if (!mapFile.isSuppressElementIfHasNoChildren() || ele.elements().size() > 0) return; if (!mapFile.isSuppressElementIfHasOnlyEmptyAttribs() || ele.attributes().size() > 0) return; if (!mapFile.isSuppressElementIfEmpty() || ele.getText().length() > 0) return; if (!mapFile.isSuppressElementIfHasOnlyWhitespace() || ele.getTextTrim().length() > 0) return; ele.getParent().remove(ele); }
From source file:com.testmax.framework.ConfigLoader.java
License:CDDL license
private void loadSqlLibDataFile(File sqlLibDataFile) { try {//w ww . ja v a 2 s.c o m List<Element> elms = scanSqlLibDataFiles(sqlLibDataFile); for (Element element : elms) { String elementName = element.getName(); if (!elementName.isEmpty()) { String value = element.getText(); String sqlLibFieldName = "sqllib:" + this.sqlLibName + "." + elementName; this.sqlLibDataMap.put(sqlLibFieldName.toLowerCase(), value); } } } catch (Exception e) { String error = ">>>Exception:<<<" + this.getClass().getName() + ">>> Failed in reading file " + sqlLibDataFile.getAbsolutePath() + " Message:" + e.getMessage(); WmLog.getCoreLogger().info(error); System.out.println(error); } }
From source file:com.testmax.framework.URLConfig.java
License:CDDL license
private void setUpElement(Element element) { if (element.attributeValue("type") != null && !element.attributeValue("type").equalsIgnoreCase("API") || element.attributeValue("method") != null) { List<Element> elmlist = element.elements(); for (Element elm : elmlist) { if (elm.getName().equalsIgnoreCase("url")) { if (!elm.getText().contains("http") && ConfigLoader.getConfig("WEB_SERVICE_URL") != null) { this.url = (ConfigLoader.getConfig("WEB_SERVICE_URL").replace("[env]", ConfigLoader.getConfig("QA_TEST_ENV"))) + elm.getText(); } else { String vurl = elm.getText(); if (vurl != null && vurl.contains("[env]")) { this.url = vurl.replace("[env]", ConfigLoader.getConfig("QA_TEST_ENV")); } else { this.url = elm.getText(); }//www . j av a 2s . c o m } } else if (elm.getName().equalsIgnoreCase("param")) { if (elm.hasContent() && elm.elements().size() > 0) { Element elParam = (Element) elm.elements().get(0); addUrlParam(elm.attributeValue("name"), elParam.asXML()); } else { addUrlParam(elm.attributeValue("name"), elm.getText()); } } else if (elm.getName().equalsIgnoreCase("assert")) { addUrlAseert(elm.attributeValue("name"), elm); } else if (elm.getName().equalsIgnoreCase("items")) { this.itemListElm.add(elm); } } } }
From source file:com.testmax.handler.ActionHandler.java
License:CDDL license
public void init() { //add report db connection for database=qa_sc if (ConfigLoader.getConfig("REPORT_SUMMARY").equalsIgnoreCase("ON")) { changeDbConnection(ConfigLoader.getConfig("REPORT_DB")); this.page.setDbConnection(this.dbConn); }// w ww .ja va 2 s . co m //this.page.setDbConnection(this.dbConn); String dbName = this.actionItem.attributeValue("dbName"); String dbHost = ConfigLoader.getDbProperty("DB_RAC"); String dbService = ConfigLoader.getDbProperty("DB_SERVICE"); String dbUser = ConfigLoader.getDbProperty("DB_USER"); String dbPass = ConfigLoader.getDbProperty("DB_PASSWORD"); String dbPort = ConfigLoader.getDbProperty("DB_PORT"); String url = null; Element dbEnv = null; if (dbName != null && !dbName.isEmpty()) { dbEnv = ConfigLoader.getDatabaseEnv(dbName); if (dbEnv != null) { List<Element> elmlist = dbEnv.elements(); for (Element elm : elmlist) { if (elm.getName().equalsIgnoreCase("user")) { dbUser = elm.getText(); } else if (elm.getName().equalsIgnoreCase("pwd")) { dbPass = elm.getText(); } else if (elm.getName().equalsIgnoreCase("host") && !elm.getText().isEmpty()) { dbHost = elm.getText(); } else if (elm.getName().equalsIgnoreCase("service")) { dbService = elm.getText(); } else if (elm.getName().equalsIgnoreCase("rac") && !elm.getText().isEmpty()) { dbHost = elm.getText(); } else if (elm.getName().equalsIgnoreCase("url") && !elm.getText().isEmpty()) { url = elm.getText(); } else if (elm.getName().equalsIgnoreCase("port") && !elm.getText().isEmpty()) { dbPort = elm.getText(); } else if (elm.getName().equalsIgnoreCase("db") && !elm.getText().isEmpty()) { this.dbProvider = elm.getText(); } else if (elm.getName().equalsIgnoreCase("driver") && !elm.getText().isEmpty()) { this.dbDriver = elm.getText(); } } } if (url == null) { url = getConnectionStr(dbHost, dbService, dbPort); } if (this.isUnitTest) { Connection con = this.dbManager.get(dbName); if (con == null) { con = makeDbConnection(url, dbUser, dbPass); this.dbManager.put(dbName, con); } this.dbConn = con; } else { this.dbConn = makeDbConnection(url, dbUser, dbPass); } setupCallableStatement(); } this.setupData(this.actionItem.elements()); //for setup system time in mili and conversion to oracle date this.setupTime(); }
From source file:com.testmax.handler.ActionHandler.java
License:CDDL license
public void changeDbConnection(String dbName) { Connection con = null;//from w ww .j a va 2 s . c o m String dbHost = null; String dbService = null; String dbUser = null; String dbPass = null; String dbPort = (ConfigLoader.getDbProperty("DB_PORT") == null ? "1521" : ConfigLoader.getDbProperty("DB_PORT")); Element dbEnv = null; String url = null; if (dbName != null && !dbName.isEmpty()) { dbEnv = ConfigLoader.getDatabaseEnv(dbName); if (dbEnv != null) { List<Element> elmlist = dbEnv.elements(); for (Element elm : elmlist) { if (elm.getName().equalsIgnoreCase("user")) { dbUser = elm.getText(); } else if (elm.getName().equalsIgnoreCase("pwd")) { dbPass = elm.getText(); } else if (elm.getName().equalsIgnoreCase("host") && !elm.getText().isEmpty()) { dbHost = elm.getText(); } else if (elm.getName().equalsIgnoreCase("service")) { dbService = elm.getText(); } else if (elm.getName().equalsIgnoreCase("rac") && !elm.getText().isEmpty()) { dbHost = elm.getText(); } else if (elm.getName().equalsIgnoreCase("url") && !elm.getText().isEmpty()) { url = elm.getText(); } else if (elm.getName().equalsIgnoreCase("port") && !elm.getText().isEmpty()) { dbPort = elm.getText(); } else if (elm.getName().equalsIgnoreCase("db") && !elm.getText().isEmpty()) { this.dbProvider = elm.getText(); } } } } if (url == null) { url = getConnectionStr(dbHost, dbService, dbPort); } if (this.isUnitTest) { con = this.dbManager.get(dbName); if (con == null && url != null && dbUser != null && dbPass != null) { con = makeDbConnection(url, dbUser, dbPass); this.dbManager.put(dbName, con); } this.dbConn = con; } else { if (url != null && dbUser != null && dbPass != null) { this.dbConn = makeDbConnection(url, dbUser, dbPass); } else { WmLog.getCoreLogger().info( ">>WARNING: Can not create database connection using url=" + url + " and dbUser=" + dbUser); System.out.println( ">>WARNING: Can not create database connection using url=" + url + " and dbUser=" + dbUser); } } }
From source file:com.testmax.handler.ActionHandler.java
License:CDDL license
private void setupInput(Element elm, int index) { try {//from w w w. ja va2 s. c o m String descriptor = elm.attributeValue("descriptor"); String arrayDesciptor = elm.attributeValue("arraydescriptor"); /* if(elm.attributeValue("type")!=null && elm.attributeValue("type").equalsIgnoreCase("table")){ if(elm.attributeValue("randomelement")==null || elm.attributeValue("randomelement")==""){ List<Element> rows=elm.elements(); //Structure StructDescriptor structDesc = StructDescriptor.createDescriptor(descriptor, this.dbConn); ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor(arrayDesciptor, this.dbConn); STRUCT[] arrayOfRecords = new STRUCT[rows.size()]; int i = 0; for (Element row: rows) { int attrCount= row.attributeCount(); Object[] temp = new Object[attrCount]; for(int k=0; k<attrCount; k++){ String val=row.attribute(k).getValue(); if(val!=null &&val.equalsIgnoreCase("null")){ val=null; } temp[k]=val; } STRUCT javaSqlObject = new STRUCT(structDesc, dbConn, temp); arrayOfRecords[i] = javaSqlObject; i++; } ARRAY arr = new ARRAY(arrayDesc, dbConn, arrayOfRecords); this.cs.setArray(index, arr); }else{ this.structDescList.add(StructDescriptor.createDescriptor(descriptor, this.dbConn)); this.arrayDescList.add(ArrayDescriptor.createDescriptor(arrayDesciptor, this.dbConn)); this.randomElmIndex.add(index); this.randomElm.add(elm); } }else */ if (elm.attributeValue("type") == null || elm.attributeValue("type") == "") { String value = elm.getText(); String lookuprow = elm.attributeValue("lookuprow"); ArrayList<ArrayList<Object>> rsData = null; if (value.indexOf("global") < 0 && value.contains(".")) { String prm = value.split("\\.")[0]; String field = value.split("\\.")[1]; String rsType = this.resultParamSet.get(prm); if (rsType.equalsIgnoreCase("cursor") || rsType.equalsIgnoreCase("query")) { rsData = (ArrayList<ArrayList<Object>>) this.resultDataSet.get(prm); int row = 0; if (rsData != null) { if (lookuprow.isEmpty()) { row = rsData.size() - 1; } else { row = Integer.valueOf(lookuprow); } value = this.getColumnValue(rsData, row, field); this.cs.setObject(index, value); } } } if (value.indexOf("global:") >= 0) { value = ConfigLoader.getGlobalDataFieldValue(value); } /* if(rsData==null){ if(descriptor.equalsIgnoreCase("NUMBER")){ if(value.equalsIgnoreCase("NULL")|| value.isEmpty()){ this.cs.setNull(index, OracleTypes.NUMBER); }else{ this.cs.setLong(index, Long.valueOf(value)); } }else if(descriptor.equalsIgnoreCase("VARCHAR")||descriptor.equalsIgnoreCase("CHAR")){ if(value.equalsIgnoreCase("NULL")|| value.isEmpty()){ this.cs.setNull(index, OracleTypes.VARCHAR); }else{ this.cs.setString(index, value); } }else if(descriptor.equalsIgnoreCase("DATE")){ if(value.equalsIgnoreCase("NULL") || value.isEmpty()){ this.cs.setNull(index, OracleTypes.DATE); }else{ if(value.equalsIgnoreCase("sysdate")){ java.util.Date today = new java.util.Date(); this.cs.setDate(index, new java.sql.Date (today.getTime())); }else{ SimpleDateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy"); java.sql.Date fromdate=(java.sql.Date) dateFormat.parse(value); this.cs.setObject(index, fromdate); } } } } */ } } catch (Exception x) { x.printStackTrace(); } }
From source file:com.testmax.handler.ActionHandler.java
License:CDDL license
private void setupQueryInput(PreparedStatement ps, Element elm, int index) { try {/* w w w . j a v a 2 s . c o m*/ String descriptor = elm.attributeValue("descriptor"); /* if(elm.attributeValue("type")!=null && elm.attributeValue("type").equalsIgnoreCase("table")){ String arrayDesciptor=elm.attributeValue("arraydescriptor"); List<Element> rows=elm.elements(); //Structure StructDescriptor structDesc = StructDescriptor.createDescriptor(descriptor, this.dbConn); ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor(arrayDesciptor, this.dbConn); STRUCT[] arrayOfRecords = new STRUCT[rows.size()]; int i = 0; for (Element row: rows) { int attrCount= row.attributeCount(); Object[] temp = new Object[attrCount]; for(int k=0; k<attrCount; k++){ temp[k]=row.attribute(k).getValue(); } STRUCT javaSqlObject = new STRUCT(structDesc, dbConn, temp); arrayOfRecords[i] = javaSqlObject; i++; } ARRAY arr = new ARRAY(arrayDesc, dbConn, arrayOfRecords); ps.setArray(index, arr); }else */ if (elm.attributeValue("type") == null || elm.attributeValue("type") == "") { String value = elm.getText(); String lookuprow = elm.attributeValue("lookuprow"); ArrayList<ArrayList<Object>> rsData = null; if (value.indexOf("global") < 0 && value.contains(".")) { String prm = value.split("\\.")[0]; String field = value.split("\\.")[1]; String rsType = this.resultParamSet.get(prm); if (rsType.equalsIgnoreCase("cursor") || rsType.equalsIgnoreCase("query")) { rsData = (ArrayList<ArrayList<Object>>) this.resultDataSet.get(prm); int row = 0; if (rsData != null) { if (lookuprow == null || lookuprow.isEmpty()) { row = rsData.size() - 1; } else { row = Integer.valueOf(lookuprow); } value = this.getColumnValue(rsData, row, field); ps.setObject(index, value); WmLog.getCoreLogger().info(" Set value for " + field + "=" + value); System.out.println(" Set value for " + field + "=" + value); } } } if (value.indexOf("global:") >= 0) { String param = value; value = new ItemUtility().getRamdomGlobalTagValue(value); WmLog.getCoreLogger().info("Set value for " + param + "=" + value); System.out.println("Set value for " + param + "=" + value); } /* if(rsData==null){ if(descriptor.equalsIgnoreCase("NUMBER")){ if(value.equalsIgnoreCase("NULL")){ ps.setNull(index, OracleTypes.NUMBER); }else{ ps.setLong(index, Long.valueOf(value)); } }else if(descriptor.equalsIgnoreCase("VARCHAR")||descriptor.equalsIgnoreCase("CHAR")){ if(value.equalsIgnoreCase("NULL")){ ps.setNull(index, OracleTypes.VARCHAR); }else{ ps.setString(index, value); } } } */ } } catch (Exception x) { x.printStackTrace(); } }
From source file:com.testmax.handler.ActionHandler.java
License:CDDL license
private void executeCommand(List<Element> vCommand) { String path = ConfigLoader.getWmRoot(); String logpath = ConfigLoader.getWmOutputLogPath(); FileUtility.deleteFile(path + "/executecmd.sh"); for (Element vCmd : vCommand) { String name = vCmd.attributeValue("name"); String description = vCmd.attributeValue("description"); String logfolder = vCmd.attributeValue("logfolder"); String fileextension = vCmd.attributeValue("fileextension"); String os = System.getProperty("os.name").toLowerCase(); String cmd = " "; //HashMap cmdparams= new HashMap<String, String>(); //Item setup using global item List<Element> cmdElms = vCmd.elements(); for (Element jcmdProp : cmdElms) { String key = jcmdProp.getName(); String value = jcmdProp.getText(); if (os.contains(key)) { cmd += value + "\n " + "cd " + path; //CmdExecutor.executeCommand(value); }//w ww .j a v a2 s. com //cmdparams.put(key, value); if (jcmdProp.getName().equalsIgnoreCase("execute")) { //CmdExecutor.executeCommand(value); cmd += "\n " + value; } } try { FileUtility.createTextFile(path + "/executecmd.sh", cmd); //Thread.sleep(500); CmdExecutor.executeCommand("chmod 777 " + path.replace("/.", "") + "/executecmd.sh"); Thread.sleep(100); CmdExecutor.executeCommand(path + "/executecmd.sh"); Thread.sleep(5000); File source = new File(path.replace(".", "") + logfolder); File dest = new File(logpath); if (source.isDirectory()) { String files[] = source.list(); for (String temp : files) { //construct the file structure File fileRead = new File(source, temp); //DomUtil du = new DomUtil(); //du.parseXmlFile(fileRead); if (fileRead.getAbsolutePath().toLowerCase().contains(".xml")) { String xml = FileUtility.read(fileRead.getAbsolutePath()); this.resultDataSet.put((String) "ws:" + name, xml); this.wsName = name; } } } FileUtility.copyFolder(source, dest); FileUtility.delete(source); //add XML //Files.move(source.toPath(), dest.toPath(),StandardCopyOption.REPLACE_EXISTING); } catch (InterruptedException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.testmax.handler.ActionHandler.java
License:CDDL license
private void executeSetup(List<Element> vSetup) { // Validate Setup for (Element vSetelm : vSetup) { if (vSetelm != null) { isItemSetup = true;//from w w w.j a v a 2 s.c o m String sql = vSetelm.getText(); if (sql != null && !sql.isEmpty()) { this.executeSetupQuery(vSetelm); } } } }