List of usage examples for org.apache.commons.lang StringUtils strip
public static String strip(String str)
Strips whitespace from the start and end of a String.
From source file:com.netspective.axiom.sql.StoredProcedure.java
/** * NOTE: When using the batch update facility, a CallableStatement object can call only stored * procedures that take input parameters or no parameters at all. Further, the stored procedure * must return an update count. The CallableStatement.executeBatch method * (inherited from PreparedStatement) will throw a BatchUpdateException if the stored procedure * returns anything other than an update count or takes OUT or INOUT parameters. */// ww w . ja v a 2s . co m protected int[] batchExecute(ConnectionContext cc) throws SQLException, NamingException { // TODO: This method NEEDS to be tested! Connection conn; CallableStatement stmt; conn = cc.getConnection(); String sql = StringUtils.strip(getSqlText(cc)); stmt = conn.prepareCall(sql); // TODO: parameters must do addBatch() calles!!! if (parameters != null) parameters.apply(cc, stmt); return stmt.executeBatch(); }
From source file:com.hangum.tadpole.commons.admin.core.editors.sqlaudit.AdminSQLAuditEditor.java
/** * search/*from w w w . j av a 2s . com*/ */ private void search() { // ? ?? . clearGrid(); mapSQLHistory.clear(); String strEmail = "%" + StringUtils.trim(textEmail.getText()) + "%"; //$NON-NLS-1$ //$NON-NLS-2$ Calendar cal = Calendar.getInstance(); cal.set(dateTimeStart.getYear(), dateTimeStart.getMonth(), dateTimeStart.getDay(), 0, 0, 0); long startTime = cal.getTimeInMillis(); cal.set(dateTimeEnd.getYear(), dateTimeEnd.getMonth(), dateTimeEnd.getDay(), 23, 59, 59); long endTime = cal.getTimeInMillis(); int duringExecute = Integer.parseInt(textMillis.getText()); String strSearchTxt = "%" + StringUtils.trimToEmpty(textSearch.getText()) + "%"; //$NON-NLS-1$ //$NON-NLS-2$ try { List<RequestResultDAO> listSQLHistory = TadpoleSystem_ExecutedSQL.getAllExecuteQueryHistoryDetail( strEmail, comboTypes.getText(), startTime, endTime, duringExecute, strSearchTxt); for (int i = 0; i < listSQLHistory.size(); i++) { RequestResultDAO reqResultDAO = (RequestResultDAO) listSQLHistory.get(i); mapSQLHistory.put("" + i, reqResultDAO); //$NON-NLS-1$ GridItem item = new GridItem(gridHistory, SWT.V_SCROLL | SWT.H_SCROLL); String strSQL = StringUtils.strip(reqResultDAO.getStrSQLText()); int intLine = StringUtils.countMatches(strSQL, "\n"); //$NON-NLS-1$ if (intLine >= 1) { int height = (intLine + 1) * 24; if (height > 100) item.setHeight(100); else item.setHeight(height); } item.setText(0, "" + i); //$NON-NLS-1$ item.setText(1, reqResultDAO.getDbName()); item.setText(2, reqResultDAO.getUserName()); item.setText(3, Utils.dateToStr(reqResultDAO.getStartDateExecute())); item.setText(4, Utils.convLineToHtml(strSQL)); item.setToolTipText(4, strSQL); item.setText(5, "" + ((reqResultDAO.getEndDateExecute().getTime() //$NON-NLS-1$ - reqResultDAO.getStartDateExecute().getTime()) / 1000f)); item.setText(6, "" + reqResultDAO.getRows()); //$NON-NLS-1$ item.setText(7, reqResultDAO.getResult()); item.setText(8, Utils.convLineToHtml(reqResultDAO.getMesssage())); item.setToolTipText(8, reqResultDAO.getMesssage()); item.setText(9, reqResultDAO.getIpAddress()); if ("F".equals(reqResultDAO.getResult())) { //$NON-NLS-1$ item.setBackground(SWTResourceManager.getColor(240, 180, 167)); } } } catch (Exception ee) { logger.error("Executed SQL History call", ee); //$NON-NLS-1$ } }
From source file:com.netspective.axiom.sql.StoredProcedure.java
/** * Executes the stored procedure and records different statistics such as database connection times, * parameetr binding times, and procedure execution times. * * @param overrideIndexes parameter indexes to override * @param overrideValues parameter override values *//*from w ww .j a va 2 s .c om*/ protected QueryResultSet executeAndRecordStatistics(ConnectionContext cc, int[] overrideIndexes, Object[] overrideValues, boolean scrollable) throws NamingException, SQLException { if (log.isTraceEnabled()) trace(cc, overrideIndexes, overrideValues); QueryExecutionLogEntry logEntry = execLog.createNewEntry(cc, this.getQualifiedName()); Connection conn = null; CallableStatement stmt = null; boolean closeConnection = true; try { logEntry.registerGetConnectionBegin(); conn = cc.getConnection(); logEntry.registerGetConnectionEnd(conn); String sql = StringUtils.strip(getSqlText(cc)); if (scrollable) stmt = conn.prepareCall(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); else stmt = conn.prepareCall(sql); logEntry.registerBindParamsBegin(); if (parameters != null) { parameters.apply(cc, stmt, overrideIndexes, overrideValues); logEntry.registerBindParamsEnd(); logEntry.registerExecSqlBegin(); stmt.execute(); logEntry.registerExecSqlEndSuccess(); parameters.extract(cc, stmt); StoredProcedureParameter rsParameter = parameters.getResultSetParameter(); if (rsParameter != null) { closeConnection = false; Value val = rsParameter.getValue().getValue(cc.getDatabaseValueContext()); return (QueryResultSet) val.getValue(); } else return null; } else { logEntry.registerExecSqlBegin(); stmt.execute(); logEntry.registerExecSqlEndSuccess(); return null; } } catch (SQLException e) { logEntry.registerExecSqlEndFailed(); log.error(createExceptionMessage(cc, overrideIndexes, overrideValues), e); throw e; } }
From source file:com.atlassian.jira.web.action.admin.EditApplicationProperties.java
public void setBaseURL(String baseURL) { //JRA-13435: Strip trailing slash if there is one. this.baseURL = StringUtils.stripEnd(StringUtils.strip(baseURL), " /"); }
From source file:com.hangum.tadpole.manager.core.editor.executedsql.SQLAuditEditor.java
/** * search/*from w w w . ja va 2 s .co m*/ */ private void search() { // ? ?? . clearGrid(); mapSQLHistory.clear(); String strEmail = "%" + StringUtils.trim(textEmail.getText()) + "%"; //$NON-NLS-1$ //$NON-NLS-2$ // check all db String db_seq = ""; //$NON-NLS-1$ if (!comboDatabase.getText().equals("All")) { //$NON-NLS-1$ searchUserDBDAO = (UserDBDAO) comboDatabase.getData(comboDatabase.getText()); db_seq = "" + searchUserDBDAO.getSeq(); //$NON-NLS-1$ } else { searchUserDBDAO = null; for (int i = 0; i < listUserDBDAO.size(); i++) { UserDBDAO userDB = listUserDBDAO.get(i); if (i == (listUserDBDAO.size() - 1)) db_seq += ("" + userDB.getSeq()); //$NON-NLS-1$ else db_seq += userDB.getSeq() + ","; //$NON-NLS-1$ } } Calendar cal = Calendar.getInstance(); cal.set(dateTimeStart.getYear(), dateTimeStart.getMonth(), dateTimeStart.getDay(), 0, 0, 0); long startTime = cal.getTimeInMillis(); cal.set(dateTimeEnd.getYear(), dateTimeEnd.getMonth(), dateTimeEnd.getDay(), 23, 59, 59); long endTime = cal.getTimeInMillis(); int duringExecute = 0; try { duringExecute = Integer.parseInt(textMillis.getText()); } catch (Exception e) { // ignore exception } String strSearchTxt = "%" + StringUtils.trimToEmpty(textSearch.getText()) + "%"; //$NON-NLS-1$ //$NON-NLS-2$ try { List<RequestResultDAO> listSQLHistory = TadpoleSystem_ExecutedSQL.getExecuteQueryHistoryDetail(strEmail, comboTypes.getText(), db_seq, startTime, endTime, duringExecute, strSearchTxt); // for (RequestResultDAO reqResultDAO : listSQLHistory) { for (int i = 0; i < listSQLHistory.size(); i++) { RequestResultDAO reqResultDAO = (RequestResultDAO) listSQLHistory.get(i); mapSQLHistory.put("" + i, reqResultDAO); //$NON-NLS-1$ GridItem item = new GridItem(gridHistory, SWT.V_SCROLL | SWT.H_SCROLL); String strSQL = StringUtils.strip(reqResultDAO.getStrSQLText()); int intLine = StringUtils.countMatches(strSQL, "\n"); //$NON-NLS-1$ if (intLine >= 1) { int height = (intLine + 1) * 24; if (height > 100) item.setHeight(100); else item.setHeight(height); } item.setText(0, "" + i); //$NON-NLS-1$ item.setText(1, reqResultDAO.getDbName()); item.setText(2, reqResultDAO.getUserName()); item.setText(3, Utils.dateToStr(reqResultDAO.getStartDateExecute())); // logger.debug(Utils.convLineToHtml(strSQL)); item.setText(4, Utils.convLineToHtml(strSQL)); item.setToolTipText(4, strSQL); try { item.setText(5, "" + ((reqResultDAO.getEndDateExecute().getTime() //$NON-NLS-1$ - reqResultDAO.getStartDateExecute().getTime()))); } catch (Exception e) { item.setText(5, "-"); //$NON-NLS-1$ } item.setText(6, "" + reqResultDAO.getRows()); //$NON-NLS-1$ item.setText(7, reqResultDAO.getResult()); item.setText(8, Utils.convLineToHtml(reqResultDAO.getMesssage())); item.setToolTipText(8, reqResultDAO.getMesssage()); item.setText(9, reqResultDAO.getIpAddress()); if ("F".equals(reqResultDAO.getResult())) { //$NON-NLS-1$ item.setBackground(SWTResourceManager.getColor(240, 180, 167)); } } } catch (Exception ee) { logger.error("Executed SQL History call", ee); //$NON-NLS-1$ } }
From source file:com.circle.utils.XMLSerializer.java
private boolean checkChildElements(Element element, boolean isTopLevel) { int childCount = element.getChildCount(); Elements elements = element.getChildElements(); int elementCount = elements.size(); if (childCount == 1 && element.getChild(0) instanceof Text) { return isTopLevel; }/*from w w w . ja v a2 s . com*/ if (childCount == elementCount) { if (elementCount == 0) { return true; } if (elementCount == 1) { if (skipWhitespace || element.getChild(0) instanceof Text) { return true; } else { return false; } } } if (childCount > elementCount) { for (int i = 0; i < childCount; i++) { Node node = element.getChild(i); if (node instanceof Text) { Text text = (Text) node; if (StringUtils.isNotBlank(StringUtils.strip(text.getValue())) && !skipWhitespace) { return false; } } } } String childName = elements.get(0).getQualifiedName(); for (int i = 1; i < elementCount; i++) { if (childName.compareTo(elements.get(i).getQualifiedName()) != 0) { return false; } } return true; }
From source file:com.activecq.api.ActiveComponent.java
@SuppressWarnings("unchecked") private <T> T getPropertyGeneric(ValueMap valueMap, String key, Class<T> klass) { if (valueMap == null || klass == null) { return null; }//from www.ja v a2 s .co m if (!valueMap.containsKey(key)) { return null; } boolean isString = String.class.equals(klass); if (isString) { // Strip leading and trailing whitespace String strValue = StringUtils.strip((String) valueMap.get(key, klass)); return (T) strValue; } else { return valueMap.get(key, klass); } }
From source file:net.sf.json.xml.XMLSerializer.java
private boolean checkChildElements(Element element, boolean isTopLevel) { int childCount = element.getChildCount(); Elements elements = element.getChildElements(); int elementCount = elements.size(); if (childCount == 1 && element.getChild(0) instanceof Text) { return isTopLevel; }/*from w w w. j a va 2 s.c o m*/ if (childCount == elementCount) { if (elementCount == 0) { return true; } if (elementCount == 1) { if (skipWhitespace && element.getChild(0) instanceof Text) { return true; } else { return false; } } } if (childCount > elementCount) { for (int i = 0; i < childCount; i++) { Node node = element.getChild(i); if (node instanceof Text) { Text text = (Text) node; if (StringUtils.isNotBlank(StringUtils.strip(text.getValue())) && !skipWhitespace) { return false; } } } } String childName = elements.get(0).getQualifiedName(); for (int i = 1; i < elementCount; i++) { if (childName.compareTo(elements.get(i).getQualifiedName()) != 0) { return false; } } if (childName.equals(arrayName)) { return true; } return elementCount > 1; }
From source file:com.activecq.api.ActiveComponent.java
@SuppressWarnings("unchecked") private <T> T getPropertyGeneric(ValueMap valueMap, String key, T defaultValue) { if (valueMap == null) { return defaultValue; }/*from www.jav a 2s. c o m*/ if (!valueMap.containsKey(key)) { return defaultValue; } boolean isString = false; if (defaultValue != null) { isString = String.class.equals(defaultValue.getClass()); } if (isString) { // Strip leading and trailing whitespace String strValue = StringUtils.strip((String) valueMap.get(key, defaultValue)); return (T) strValue; } else { return valueMap.get(key, defaultValue); } }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.por.PORFileReader.java
private void decodeNumberOfVariables(BufferedReader reader) throws IOException { if (reader == null) { throw new IllegalArgumentException("decodeNumberOfVariables: reader == null!"); }/*from w w w .j av a 2 s. c om*/ String temp = null; char[] tmp = new char[1]; StringBuilder sb = new StringBuilder(); while (reader.read(tmp) > 0) { temp = Character.toString(tmp[0]); if (temp.equals("/")) { break; } else { sb.append(temp); } } String rawNumberOfVariables = sb.toString(); int rawLength = rawNumberOfVariables.length(); String numberOfVariables = StringUtils.stripStart((StringUtils.strip(rawNumberOfVariables)), "0"); if ((numberOfVariables.equals("")) && (numberOfVariables.length() == rawLength)) { numberOfVariables = "0"; } varQnty = Integer.valueOf(numberOfVariables, 30); smd.getFileInformation().put("varQnty", varQnty); }