List of usage examples for org.apache.commons.lang StringUtils contains
public static boolean contains(String str, String searchStr)
Checks if String contains a search String, handling null
.
From source file:com.device.storefront.filters.cms.CMSSiteFilter.java
/** * Processing preview request (i.e. request with additional parameters like {@link CMSFilter#PREVIEW_TOKEN} requested * from cmscockpit) )/*from w ww .ja v a 2s .co m*/ * <p/> * <b>Note:</b> Processing preview data in order to generate target URL, and load necessary information in user * session * <ul> * <li>Initialize information (Active CMSSite, Catalog versions,Current catalog version ) information getting from * valid Preview Data</li> * <li>Load all fake information (like: User, User group, Language, Time ...) * <li>Generating target URL according to Preview Data * </ul> * * @param httpRequest * current request * @return target URL */ protected String processPreviewRequest(final HttpServletRequest httpRequest, final CmsPageRequestContextData cmsPageRequestContextData) { final PreviewDataModel previewDataModel = cmsPageRequestContextData.getPreviewData(); processPreviewData(httpRequest, previewDataModel); //generate destination URL final String destinationURL = generatePreviewUrl(httpRequest, previewDataModel); // persist changes previewDataModel.setResourcePath(destinationURL); getContextInformationLoader().storePreviewData(previewDataModel); final CMSPreviewTicketModel ticket = getCmsPreviewService().createPreviewTicket(previewDataModel); String parameterDelimiter = "?"; if (StringUtils.contains(destinationURL, "?")) { parameterDelimiter = "&"; } return destinationURL + parameterDelimiter + PREVIEW_TICKET_ID_PARAM + "=" + ticket.getId(); }
From source file:edu.ku.brc.specify.toycode.mexconabio.MexConvToSQLNew.java
public void convert(final String tableName, final String fileName) { String str = ""; int fldLen = 0; int inx = 0;/*from w w w. j a v a 2 s .c o m*/ Connection conn = null; Statement stmt = null; try { conn = DriverManager.getConnection( "jdbc:mysql://localhost/mex?characterEncoding=UTF-8&autoReconnect=true", "root", "root"); stmt = conn.createStatement(); int[] fieldLengths = null; BasicSQLUtils.deleteAllRecordsFromTable(conn, tableName, SERVERTYPE.MySQL); Vector<Integer> types = new Vector<Integer>(); Vector<String> names = new Vector<String>(); String selectStr = null; String prepareStr = null; try { prepareStr = FileUtils.readFileToString(new File("prepare_stmt.txt")); selectStr = FileUtils.readFileToString(new File("select.txt")); } catch (IOException e) { e.printStackTrace(); } int idInx = selectStr.indexOf("ID,"); if (idInx == 0) { selectStr = selectStr.substring(3); } File file = new File("/Users/rods/Documents/" + fileName); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); //SimpleDateFormat stf = new SimpleDateFormat("k:mm:ss"); int rowCnt = 0; try { System.out.println(prepareStr); PreparedStatement pStmt = conn.prepareStatement(prepareStr); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8")); str = in.readLine(); String[] fieldNames = StringUtils.split(str, ","); //String[] fieldNamesDB = StringUtils.split(selectStr, ","); String sql = "SELECT " + selectStr + " FROM " + tableName; System.out.println(sql); ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); fieldLengths = new int[rsmd.getColumnCount()]; for (int i = 1; i <= rsmd.getColumnCount(); i++) { fieldLengths[i - 1] = rsmd.getPrecision(i); types.add(rsmd.getColumnType(i)); names.add(rsmd.getColumnName(i)); System.out.println((i > 1 ? fieldNames[i - 2] : "ID") + " / " + rsmd.getColumnName(i) + " - " + rsmd.getPrecision(i)); } int numCols = rsmd.getColumnCount(); rs.close(); System.out.println("Number of Fields: " + numCols); str = in.readLine(); while (str != null) { //System.err.println(str); str = StringUtils.replace(str.substring(1, str.length() - 1), "\",\"", "|"); Vector<String> fields = split(str); if (fields.size() != numCols) { System.out.println("numCols: " + numCols + " != " + fields.size() + "fields.size()"); continue; } int col = 1; inx = 0; for (String fld : fields) { String field = fld.trim(); //if (field.length() > 1) //{ // field = field.substring(1, field.length()-1); //} //if (inx > 204) break; fldLen = field.length(); pStmt.setObject(col, null); switch (types.get(inx)) { case java.sql.Types.LONGVARCHAR: case java.sql.Types.VARCHAR: case java.sql.Types.LONGNVARCHAR: { if (field.length() > 0) { if (field.length() <= fieldLengths[inx]) { pStmt.setString(col, field); } else { System.err.println(String.format("The data for `%s` (%d) is too big %d f[%s]", names.get(inx), fieldLengths[inx], field.length(), field)); pStmt.setString(col, null); } } else { pStmt.setString(col, null); } } break; case java.sql.Types.DOUBLE: case java.sql.Types.FLOAT: { if (StringUtils.isNotEmpty(field)) { if (StringUtils.isNumeric(field)) { pStmt.setDouble(col, field.length() > 0 ? Double.parseDouble(field) : null); } else { System.err.println(col + " Bad Number[" + field + "] "); pStmt.setDate(col, null); } } else { pStmt.setDate(col, null); } } break; case java.sql.Types.INTEGER: { if (StringUtils.isNotEmpty(field)) { if (StringUtils.isNumeric(field)) { pStmt.setInt(col, field.length() > 0 ? Integer.parseInt(field) : null); } else { System.err.println(col + " Bad Number[" + field + "] "); pStmt.setDate(col, null); } } else { pStmt.setDate(col, null); } } break; case java.sql.Types.TIME: { Time time = null; try { time = Time.valueOf(field); } catch (Exception ex) { } pStmt.setTime(col, time); } break; case java.sql.Types.DATE: { try { if (StringUtils.isNotEmpty(field)) { if (StringUtils.contains(field, "/")) { field = StringUtils.replace(field, "/", "-"); } else if (StringUtils.contains(field, " ")) { field = StringUtils.replace(field, " ", "-"); } pStmt.setDate(col, field.length() > 0 ? new java.sql.Date(sdf.parse(field).getTime()) : null); } else { pStmt.setDate(col, null); } } catch (Exception ex) { System.err.println(col + " Bad Date[" + field + "]\n" + str); pStmt.setDate(col, null); } } break; default: { System.err.println("Error - " + types.get(inx)); } } inx++; col++; } pStmt.execute(); str = in.readLine(); rowCnt++; } in.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { System.err.println("Row: " + rowCnt); System.err.println(str); System.err.println(inx + " " + fieldLengths[inx] + " - Field Len: " + fldLen); e.printStackTrace(); } /*BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); while (bis.available() > 0) { int bytesRead = bis.read(bytes); if (bytesRead > 0) { System.arraycopy(bytes, bytesRead, buffer, bufEndInx, bytesRead); bufEndInx += bytesRead; int inx = 0; while (inx < bufEndInx) { if (buffer[inx] != '\n') { String line = } inx++; } } }*/ } catch (Exception ex) { ex.printStackTrace(); } finally { try { stmt.close(); conn.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:com.hangum.tadpole.rdb.core.dialog.dbconnect.composite.MSSQLLoginComposite.java
/** * ip? instance ping.// w ww . ja v a 2 s .c o m */ public boolean isPing(String strHost, String port) { if (StringUtils.contains(strHost, "\\")) { String strIp = StringUtils.substringBefore(strHost, "\\"); return ValidChecker.isPing(strIp, port); } else if (StringUtils.contains(strHost, "/")) { String strIp = StringUtils.substringBefore(strHost, "/"); return ValidChecker.isPing(strIp, port); } else { return ValidChecker.isPing(strHost, port); } }
From source file:edu.ku.brc.specify.datamodel.busrules.SpecifyUserBusRules.java
/** * NOTE: This is being called when editing an existing person. * @param id//from ww w. ja v a2 s. c o m * @param keyName * @param isPwd * @return */ private boolean isFieldOK(final String id, final String keyName, final boolean isPwd) { JTextField tf = null; Component comp = formViewObj.getCompById(id); if (comp instanceof EditViewCompSwitcherPanel) { tf = (JTextField) ((EditViewCompSwitcherPanel) comp).getCurrentComp(); } else { tf = (JTextField) comp; } String value = tf.getText().trim(); if (StringUtils.contains(value, ' ') || (!isPwd && StringUtils.contains(value, ','))) { UIRegistry.showLocalizedError(keyName); return false; } return true; }
From source file:gemlite.core.webapp.tools.ClusterController.java
private boolean checkThreadStatus(String ip, String username, String psw, String cmd, String thread) throws Exception { String rs = CmdUtils.exeCmd(ip, username, psw, cmd); if (StringUtils.contains(rs, thread)) { LogUtil.getCoreLog().warn("{} : {} is running {}", ip, thread, rs); return true; }//ww w .j a v a 2s . c om return false; }
From source file:edu.ku.brc.specify.toycode.BugParse.java
/** * @param fileName//from w ww. ja va2 s . com */ @SuppressWarnings("unchecked") protected void parse(final String fileName) { try { List<String> lines = FileUtils.readLines(new File("/Users/rod/Downloads/" + fileName)); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (StringUtils.contains(line, "show_bug.cgi?id")) { String line2 = lines.get(++i); String[] tokens1 = StringUtils.split(line); String[] tokens2 = StringUtils.split(line2); int number = Integer.parseInt(tokens1[0]); Bug bug = new Bug(number, tokens1[2], tokens1[3], tokens2[0], tokens1[4], tokens1[5]); bug.setClosed(!(tokens2[1].equals("ASSI") || tokens2[1].equals("NEW"))); bugHash.put(number, bug); } } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BugParse.class, ex); ex.printStackTrace(); } }
From source file:com.hangum.tadpole.sql.util.sqlscripts.scripts.OracleDDLScript.java
@Override public String getProcedureScript(ProcedureFunctionDAO procedureDAO) throws Exception { SqlMapClient client = TadpoleSQLManager.getInstance(userDB); logger.debug("\n Procedure DDL Generation..."); StringBuilder result = new StringBuilder(""); String objType = (String) client.queryForObject("getSourceObjectType", procedureDAO.getName()); List<String> srcScriptList = null; if (StringUtils.contains(objType, "PROCEDURE")) { result.append("/* DROP PROCEDURE " + procedureDAO.getName() + "; */ \n\n"); result.append("CREATE OR REPLACE "); srcScriptList = client.queryForList("getProcedureScript", procedureDAO.getName()); for (int i = 0; i < srcScriptList.size(); i++) { result.append(srcScriptList.get(i)); }/*from w w w. j a v a 2 s. c o m*/ } else if (StringUtils.contains(objType, "PACKAGE")) { result.append("/* DROP PACKAGE BODY " + procedureDAO.getName() + "; */ \n\n"); result.append("/* DROP PACKAGE " + procedureDAO.getName() + "; */ \n\n"); result.append("CREATE OR REPLACE "); srcScriptList = client.queryForList("getPackageScript.head", procedureDAO.getName()); for (int i = 0; i < srcScriptList.size(); i++) { result.append(srcScriptList.get(i)); } result.append("/ \n\n "); result.append("CREATE OR REPLACE "); srcScriptList = client.queryForList("getPackageScript.body", procedureDAO.getName()); for (int i = 0; i < srcScriptList.size(); i++) { result.append(srcScriptList.get(i)); } result.append("/ \n\n "); } return result.toString(); }
From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java
private static String getCommonTollCompanyName(String tollCompanyName) { String commonTollCompanyName = StringUtils.EMPTY; if (StringUtils.contains(tollCompanyName, TOLL_COMPANY_EZ_PASS_NY)) { commonTollCompanyName = TOLL_COMPANY_EZ_PASS_NY; } else if (StringUtils.contains(tollCompanyName, TOLL_COMPANY_EZ_PASS_PA)) { commonTollCompanyName = TOLL_COMPANY_EZ_PASS_PA; } else if (StringUtils.contains(tollCompanyName, TOLL_COMPANY_IPASS)) { commonTollCompanyName = TOLL_COMPANY_IPASS; } else if (StringUtils.contains(tollCompanyName, TOLL_COMPANY_SUN_PASS)) { commonTollCompanyName = TOLL_COMPANY_SUN_PASS; }// www .ja v a2s. c om return commonTollCompanyName; }
From source file:edu.ku.brc.af.ui.weblink.WebLinkEditorDlg.java
/** * /*from www.ja v a 2s. c om*/ */ protected void parseForFields() { if (isParsingError) { //baseUrlTF.setForeground(txtFGColor); baseUrlTF.setBackground(txtBGColor); isParsingError = false; enableUI(); } boolean wasIncomplete = isParsingIncomplete; fields.clear(); args.clear(); model.fire(); String baseStr = baseUrlTF.getText(); Pattern pattern = Pattern.compile("<.*?>"); Matcher matcher = pattern.matcher(baseStr); while (matcher.find()) { String token = matcher.group(0); if (token.length() > 2) { token = token.substring(1, token.length() - 1); if (StringUtils.contains(token, ">") || StringUtils.contains(token, "<")) { setURLToError(); return; } if (tableInfo == null || fieldInfoHash.get(token) != null) { if (tableInfo != null && token.equals("this")) { setURLToError(); return; } fields.put(token, token); String titleStr = titleHash.get(token); if (StringUtils.isEmpty(titleStr) && fieldInfoHash == null) { titleStr = StringUtils.capitalize(token); } model.addItem(token, titleStr, !token.equals("this")); } else { String titleStr = StringUtils.capitalize(token); model.addItem(token, titleStr, !token.equals("this")); } } } if (wasIncomplete != isParsingIncomplete) { enableUI(); } adjustAvailableJList(); format = baseStr; }
From source file:com.ctc.storefront.filters.cms.CMSSiteFilter.java
/** * Processing preview request (i.e. request with additional parameters like {@link CMSFilter#PREVIEW_TOKEN} requested * from cmscockpit) )// w ww . j av a 2 s. c om * <p/> * <b>Note:</b> Processing preview data in order to generate target URL, and load necessary information in user * session * <ul> * <li>Initialize information (Active CMSSite, Catalog versions,Current catalog version ) information getting from * valid Preview Data</li> * <li>Load all fake information (like: User, User group, Language, Time ...) * <li>Generating target URL according to Preview Data * </ul> * * @param httpRequest * current request * @return target URL */ protected String processPreviewRequest(final HttpServletRequest httpRequest, final CmsPageRequestContextData cmsPageRequestContextData) { final PreviewDataModel previewDataModel = cmsPageRequestContextData.getPreviewData(); final BaseSiteModel currentBaseSite = getBaseSiteService().getCurrentBaseSite(); if (currentBaseSite != null && !currentBaseSite.equals(previewDataModel.getActiveSite())) { httpRequest.getSession(false).invalidate(); return httpRequest.getRequestURL() + "?" + httpRequest.getQueryString(); } processPreviewData(httpRequest, previewDataModel); //generate destination URL final String destinationURL = generatePreviewUrl(httpRequest, previewDataModel); // persist changes previewDataModel.setResourcePath(destinationURL); getContextInformationLoader().storePreviewData(previewDataModel); final CMSPreviewTicketModel ticket = getCmsPreviewService().createPreviewTicket(previewDataModel); String parameterDelimiter = "?"; if (StringUtils.contains(destinationURL, "?")) { parameterDelimiter = "&"; } return destinationURL + parameterDelimiter + PREVIEW_TICKET_ID_PARAM + "=" + ticket.getId(); }