List of usage examples for org.dom4j Element getText
String getText();
From source file:com.testmax.handler.ActionHandler.java
License:CDDL license
private void executevQuery(List<Element> vQuery, List<Element> vInput, String validator) { String queryName = ""; String queryDesc = ""; String dbmsOutput = ""; for (Element vSql : vQuery) { //System.out.println(vSql.asXML()); queryName = vSql.attributeValue("name"); queryDesc = ">>>Executing Query=" + queryName + ": " + (vSql.attributeValue("description") == null ? "" : vSql.attributeValue("description")); String sql = vSql.getText().replaceAll("@Lt", "<"); String hasDbmsOutput = vSql.attributeValue("dbmsoutput"); dbmsOutputKey = vSql.attributeValue("dbmsoutputkey"); globaldataset = vSql.attributeValue("globaldataset"); String dbmsTableOutput = vSql.attributeValue("dbmstable"); String fileExtension = vSql.attributeValue("filetype"); //change database connection String dbName = vSql.attributeValue("dbname"); if (dbName != null && dbName.isEmpty()) { dbName = vSql.attributeValue("dbName"); }//ww w . j a v a2 s. c o m if (dbName != null && !dbName.isEmpty() && this.dbManager.get(dbName) == null) { this.changeDbConnection(dbName); } else if (dbName != null && !dbName.isEmpty()) { this.changeDbConnectionFromDbmanager(dbName); } /* //replace sql lib if included String includes=vSql.attributeValue("includes"); String replace=vSql.attributeValue("replace"); if(includes!=null &&includes.split(",").length>=0){ //String val=sql; for(Object key:includes.split(",")){ sql=sql.replace("@"+key, ConfigLoader.getSqlLibByKey(key.toString())); } System.out.println(sql); } */ if (hasDbmsOutput != null && hasDbmsOutput.equalsIgnoreCase("yes")) { dbmsOutput = this.executeWithDbmsOutput(sql); FileUtility.createDir(ConfigLoader.getWmOutputSqlPath()); this.printMessage(queryDesc + "\n" + sql); this.printMessage(this.printresult); /*WmLog.getCoreLogger().info(queryDesc+ "\n"+sql); System.out.println(queryDesc+ "\n"+sql); WmLog.getCoreLogger().info(ExecuteProc.class.getName()+">>>Output:\n"+this.printresult); System.out.println(this.printresult); */ FileUtility.writeToFile(ConfigLoader.getWmOutputSqlPath() + this.page.getURLConfig().getUrlElement().attributeValue("name") + "_" + queryName + "_input.sql", sql); FileUtility.writeToFile(ConfigLoader.getWmOutputSqlPath() + this.page.getURLConfig().getUrlElement().attributeValue("name") + "_" + queryName + "_output." + ((fileExtension == null || fileExtension == "") ? "txt" : fileExtension), ((fileExtension == null || fileExtension == "") ? printresult : dbmsOutput)); if (this.resultDataSet != null) { if (dbmsTableOutput != null && dbmsTableOutput.equalsIgnoreCase("yes")) { this.resultDataSet.put(queryName, this.setDbmsOutput2Array(dbmsOutput)); ConfigLoader.addGlobalField(queryName, dbmsOutput); //set for global dataset setDbmsOutput2XMLDataset(queryName, dbmsOutput); } else { this.resultDataSet.put(queryName, this.setDbmsOutput2String(dbmsOutput)); } this.resultParamSet.put(queryName, "QUERY"); } } else { try { WmLog.getCoreLogger().info(queryDesc + "\n" + sql); System.out.println(queryDesc + "\n" + sql); this.ps = this.makeSqlStatement(sql, vInput); ResultSet rs = this.executeSql(); if (rs != null) { this.resultDataSet.put(queryName, this.setResults2Array(rs, validator)); this.resultParamSet.put(queryName, "QUERY"); //set as global dataset this.setXMLDataset(queryName); } } catch (Exception e) { // TODO Auto-generated catch block System.out.print(e.getMessage()); e.printStackTrace(); } } } }
From source file:com.testmax.handler.ActionHandler.java
License:CDDL license
private void executeSetupQuery(Element vSql) { //System.out.println(vSql.asXML()); String dbmsOutput = ""; String queryName = vSql.attributeValue("name"); String queryDesc = ">>>Executing Query=" + queryName + ": " + (vSql.attributeValue("description") == null ? "" : vSql.attributeValue("description")); String sql = vSql.getText(); String hasDbmsOutput = vSql.attributeValue("dbmsoutput"); dbmsOutputKey = vSql.attributeValue("dbmsoutputkey"); //change database connection String dbName = vSql.attributeValue("dbname"); if (dbName != null && !dbName.isEmpty() && this.dbManager.get(dbName) == null) { this.changeDbConnection(dbName); } else if (dbName != null && !dbName.isEmpty()) { this.changeDbConnectionFromDbmanager(dbName); }// w w w. j a v a 2 s .c om if (hasDbmsOutput != null && hasDbmsOutput.equalsIgnoreCase("yes")) { dbmsOutput = this.executeWithDbmsOutput(sql); ConfigLoader.addGlobalField(queryName, dbmsOutput); this.setupDataSet.put(queryName, dbmsOutput); WmLog.getCoreLogger().info(queryDesc + "\n" + sql); System.out.println(queryDesc + "\n" + sql); WmLog.getCoreLogger().info(ActionHandler.class.getName() + ">>>Output:\n" + this.printresult); System.out.println(this.printresult); } }
From source file:com.testmax.util.CreateActionSpec.java
License:CDDL license
public static Connection getOracleConnection() throws Exception { String port = "1521"; String username = "Inventory"; String password = "inve3e"; String rac = "sdc-scan-r1"; String service = "wminve3_be.walmart.com"; Element dbEnv = null;/*w w w . j a v a2s. c o m*/ if (!dbname.isEmpty()) { dbEnv = getDatabaseEnv(dbname.toLowerCase()); if (dbEnv != null) { List<Element> elmlist = dbEnv.elements(); for (Element elm : elmlist) { if (elm.getName().equalsIgnoreCase("user")) { username = elm.getText(); } else if (elm.getName().equalsIgnoreCase("pwd")) { password = elm.getText(); } else if (elm.getName().equalsIgnoreCase("host") && !elm.getText().isEmpty()) { rac = elm.getText(); } else if (elm.getName().equalsIgnoreCase("service")) { service = elm.getText(); } else if (elm.getName().equalsIgnoreCase("rac") && !elm.getText().isEmpty()) { rac = elm.getText(); } } } } String url = "jdbc:oracle:thin:@(DESCRIPTION =" + "(ADDRESS_LIST =" + "(ADDRESS = (PROTOCOL = TCP)(HOST =" + rac + ")(PORT = 1521))" + ")" + "(CONNECT_DATA =" + "(SERVICE_NAME = " + service + ")" + ")" + ")"; DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection(url, username, password); return conn; }
From source file:com.testmax.util.DbUtil.java
License:CDDL license
public Connection getDbConnection(String dbName) { Connection con = null;//from w w w.ja v a 2s . co m String dbHost = null; String dbService = null; String dbUser = null; String dbPass = null; String dbPort = null; String provider = null; String driver = null; Element dbEnv = null; String url = null; if (dbManager.get(dbName) != null) { return dbManager.get(dbName); } 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()) { provider = elm.getText(); } else if (elm.getName().equalsIgnoreCase("driver") && !elm.getText().isEmpty()) { driver = elm.getText(); } } } } if (url == null) { url = getConnectionStr(provider, dbHost, dbService, dbPort); } con = makeDbConnection(provider, driver, url, dbUser, dbPass); dbManager.put(dbName, con); return con; }
From source file:com.testmax.util.DbUtil.java
License:CDDL license
public Connection getDbConnection(Element dbEnv, String dbName) { Connection con = null;// ww w .java 2 s. com String dbHost = null; String dbService = null; String dbUser = null; String dbPass = null; String dbPort = null; String provider = null; String driver = null; String url = null; if (dbManager.get(dbName) != null) { return dbManager.get(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()) { provider = elm.getText(); } else if (elm.getName().equalsIgnoreCase("driver") && !elm.getText().isEmpty()) { driver = elm.getText(); } } } if (url == null) { url = getConnectionStr(provider, dbHost, dbService, dbPort); } con = makeDbConnection(provider, driver, url, dbUser, dbPass); dbManager.put(dbName, con); return con; }
From source file:com.testmax.util.ItemUtility.java
License:CDDL license
public Element replaceTagLib(Element vTag) { Element elmNew = null;//from www . ja v a 2 s. com String prm = ""; //replace tag lib if included try { String includes = vTag.getText(); String xml = vTag.asXML(); if (includes != null && includes.split("@").length >= 0) { for (Object key : includes.split("@")) { prm = key.toString(); xml = xml.replace("@" + key, ConfigLoader.getTagLibByKey(key.toString()).asXML()); } //System.out.println(xml); } elmNew = new SAXReader().read(new StringReader(xml)).getRootElement(); } catch (DocumentException e) { WmLog.getCoreLogger().info( ">>>Exception:<<<" + this.getClass().getName() + ">>> Failed to replace parameter " + prm); System.out.println( ">>>Exception:<<<" + this.getClass().getName() + ">>> Failed to replace parameter " + prm); // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { WmLog.getCoreLogger().info( ">>>Exception:<<<" + this.getClass().getName() + ">>> Failed to replace parameter " + prm); System.out.println( ">>>Exception:<<<" + this.getClass().getName() + ">>> Failed to replace parameter " + prm); // TODO Auto-generated catch block e.printStackTrace(); } return (elmNew); }
From source file:com.thinkberg.moxo.dav.LockHandler.java
License:Apache License
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = getResourceManager().getFileObject(request.getPathInfo()); try {/*from ww w . jav a2 s .c o m*/ Lock lock = LockManager.getInstance().checkCondition(object, getIf(request)); if (lock != null) { sendLockAcquiredResponse(response, lock); return; } } catch (LockException e) { // handle locks below } try { SAXReader saxReader = new SAXReader(); Document lockInfo = saxReader.read(request.getInputStream()); //log(lockInfo); Element rootEl = lockInfo.getRootElement(); String lockScope = null, lockType = null; Object owner = null; Iterator elIt = rootEl.elementIterator(); while (elIt.hasNext()) { Element el = (Element) elIt.next(); if (TAG_LOCKSCOPE.equals(el.getName())) { lockScope = el.selectSingleNode("*").getName(); } else if (TAG_LOCKTYPE.equals(el.getName())) { lockType = el.selectSingleNode("*").getName(); } else if (TAG_OWNER.equals(el.getName())) { // TODO correctly handle owner Node subEl = el.selectSingleNode("*"); if (subEl != null && TAG_HREF.equals(subEl.getName())) { owner = new URL(el.selectSingleNode("*").getText()); } else { owner = el.getText(); } } } log("LOCK(" + lockType + ", " + lockScope + ", " + owner + ")"); Lock requestedLock = new Lock(object, lockType, lockScope, owner, getDepth(request), getTimeout(request)); try { LockManager.getInstance().acquireLock(requestedLock); sendLockAcquiredResponse(response, requestedLock); } catch (LockConflictException e) { response.sendError(SC_LOCKED); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); } } catch (DocumentException e) { e.printStackTrace(); response.sendError(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:com.thinkberg.webdav.LockHandler.java
License:Apache License
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = VFSBackend.resolveFile(request.getPathInfo()); try {/*from ww w . jav a 2s. co m*/ final LockManager manager = LockManager.getInstance(); final LockManager.EvaluationResult evaluation = manager.evaluateCondition(object, getIf(request)); if (!evaluation.result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } else { if (!evaluation.locks.isEmpty()) { LOG.debug(String.format("discovered locks: %s", evaluation.locks)); sendLockAcquiredResponse(response, evaluation.locks.get(0)); return; } } } catch (LockConflictException e) { List<Lock> locks = e.getLocks(); for (Lock lock : locks) { if (Lock.EXCLUSIVE.equals(lock.getType())) { response.sendError(SC_LOCKED); return; } } } catch (ParseException e) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } try { SAXReader saxReader = new SAXReader(); Document lockInfo = saxReader.read(request.getInputStream()); //log(lockInfo); Element rootEl = lockInfo.getRootElement(); String lockScope = null, lockType = null; Object owner = null; Iterator elIt = rootEl.elementIterator(); while (elIt.hasNext()) { Element el = (Element) elIt.next(); if (TAG_LOCKSCOPE.equals(el.getName())) { lockScope = el.selectSingleNode("*").getName(); } else if (TAG_LOCKTYPE.equals(el.getName())) { lockType = el.selectSingleNode("*").getName(); } else if (TAG_OWNER.equals(el.getName())) { // TODO correctly handle owner Node subEl = el.selectSingleNode("*"); if (subEl != null && TAG_HREF.equals(subEl.getName())) { owner = new URL(el.selectSingleNode("*").getText()); } else { owner = el.getText(); } } } LOG.debug("LOCK(" + lockType + ", " + lockScope + ", " + owner + ")"); Lock requestedLock = new Lock(object, lockType, lockScope, owner, getDepth(request), getTimeout(request)); try { LockManager.getInstance().acquireLock(requestedLock); sendLockAcquiredResponse(response, requestedLock); } catch (LockConflictException e) { response.sendError(SC_LOCKED); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); } } catch (DocumentException e) { e.printStackTrace(); response.sendError(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:com.thoughtworks.cruise.util.SvnLogXmlParser.java
License:Apache License
@SuppressWarnings("unchecked") private Revision parseLogEntry(Element logEntry, String path) throws ParseException { // TODO: we may need to add this information to the Revision in a potentially dark future of this probabilistic multiverse. // Date modifiedTime = convertDate(logEntry.elementText("date")); // String author = logEntry.elementText("author"); String comment = logEntry.elementText("msg"); String revisionNumber = logEntry.attributeValue("revision"); Revision revision = new Revision(revisionNumber, comment); Element logEntryPaths = (Element) logEntry.selectSingleNode("/paths"); if (logEntryPaths != null) { for (Element pathElement : (List<Element>) logEntryPaths.selectNodes("/path")) { if (underPath(path, pathElement.getText())) { addModificationToRevision(revision, pathElement); }//from w w w . j a v a2s . co m } } return revision; }
From source file:com.thoughtworks.cruise.util.SvnLogXmlParser.java
License:Apache License
private void addModificationToRevision(Revision revision, Element pathElement) { String action = pathElement.attributeValue("action"); if (action.equals("A")) { revision.addAddedFile(pathElement.getText()); }//from w w w. ja v a 2 s . c o m if (action.equals("M")) { revision.addModifiedFile(pathElement.getText()); } if (action.equals("D")) { revision.addDeletedFile(pathElement.getText()); } }