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:edu.ku.brc.specify.ui.AppBase.java
/** * Shows the About dialog./*from www .j a v a 2 s.c om*/ */ public void doAbout() { AppContextMgr acm = AppContextMgr.getInstance(); boolean hasContext = acm.hasContext(); int baseNumRows = 9; String serverName = AppPreferences.getLocalPrefs().get("login.servers_selected", null); if (serverName != null) { baseNumRows++; } CellConstraints cc = new CellConstraints(); PanelBuilder infoPB = new PanelBuilder(new FormLayout("p,6px,f:p:g", "p,4px,p,4px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", baseNumRows))); JLabel iconLabel = new JLabel(IconManager.getIcon("SpecifyLargeIcon"), SwingConstants.CENTER); //$NON-NLS-1$ PanelBuilder iconPB = new PanelBuilder(new FormLayout("p", "20px,t:p,f:p:g")); iconPB.add(iconLabel, cc.xy(1, 2)); if (hasContext) { DBTableIdMgr tableMgr = DBTableIdMgr.getInstance(); boolean hasReged = !RegisterSpecify.isAnonymous() && RegisterSpecify.hasInstitutionRegistered(); int y = 1; infoPB.addSeparator(getResourceString("Specify.SYS_INFO"), cc.xyw(1, y, 3)); y += 2; JLabel lbl = UIHelper.createLabel(databaseName); infoPB.add(UIHelper.createI18NFormLabel("Specify.DB"), cc.xy(1, y)); infoPB.add(lbl, cc.xy(3, y)); y += 2; lbl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { openLocalPrefs(); } } }); infoPB.add(UIHelper.createFormLabel(tableMgr.getTitleForId(Institution.getClassTableId())), cc.xy(1, y)); infoPB.add(lbl = UIHelper.createLabel(acm.getClassObject(Institution.class).getName()), cc.xy(3, y)); y += 2; lbl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { openRemotePrefs(); } } }); infoPB.add(UIHelper.createFormLabel(tableMgr.getTitleForId(Division.getClassTableId())), cc.xy(1, y)); infoPB.add(UIHelper.createLabel(acm.getClassObject(Division.class).getName()), cc.xy(3, y)); y += 2; infoPB.add(UIHelper.createFormLabel(tableMgr.getTitleForId(Discipline.getClassTableId())), cc.xy(1, y)); infoPB.add(UIHelper.createLabel(acm.getClassObject(Discipline.class).getName()), cc.xy(3, y)); y += 2; infoPB.add(UIHelper.createFormLabel(tableMgr.getTitleForId(Collection.getClassTableId())), cc.xy(1, y)); infoPB.add(UIHelper.createLabel(acm.getClassObject(Collection.class).getCollectionName()), cc.xy(3, y)); y += 2; infoPB.add(UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y)); infoPB.add(UIHelper.createLabel(appBuildVersion), cc.xy(3, y)); y += 2; infoPB.add(UIHelper.createI18NFormLabel("Specify.REG"), cc.xy(1, y)); infoPB.add(UIHelper.createI18NLabel(hasReged ? "Specify.HASREG" : "Specify.NOTREG"), cc.xy(3, y)); y += 2; String isaNumber = RegisterSpecify.getISANumber(); infoPB.add(UIHelper.createI18NFormLabel("Specify.ISANUM"), cc.xy(1, y)); infoPB.add(UIHelper.createLabel(StringUtils.isNotEmpty(isaNumber) ? isaNumber : ""), cc.xy(3, y)); y += 2; if (serverName != null) { infoPB.add(UIHelper.createI18NFormLabel("Specify.SERVER"), cc.xy(1, y)); infoPB.add(UIHelper.createLabel(StringUtils.isNotEmpty(serverName) ? serverName : ""), cc.xy(3, y)); y += 2; } if (StringUtils.contains(DBConnection.getInstance().getConnectionStr(), "mysql")) { Vector<Object[]> list = BasicSQLUtils.query("select version() as ve"); if (list != null && list.size() > 0) { infoPB.add(UIHelper.createFormLabel("MySQL Version"), cc.xy(1, y)); infoPB.add(UIHelper.createLabel(list.get(0)[0].toString()), cc.xy(3, y)); y += 2; } } infoPB.add(UIHelper.createFormLabel("Java Version"), cc.xy(1, y)); infoPB.add(UIHelper.createLabel(System.getProperty("java.version")), cc.xy(3, y)); y += 2; } String txt = getAboutText(appName, appVersion); JLabel txtLbl = createLabel(txt); txtLbl.setFont(UIRegistry.getDefaultFont()); final JEditorPane txtPane = new JEditorPane("text/html", txt); txtPane.setEditable(false); txtPane.setBackground(new JPanel().getBackground()); PanelBuilder pb = new PanelBuilder(new FormLayout("p,20px,f:min(400px;p):g,10px,8px,10px,p:g", "f:p:g")); pb.add(iconPB.getPanel(), cc.xy(1, 1)); pb.add(txtPane, cc.xy(3, 1)); Color bg = getBackground(); if (hasContext) { pb.add(new VerticalSeparator(bg.darker(), bg.brighter()), cc.xy(5, 1)); pb.add(infoPB.getPanel(), cc.xy(7, 1)); } pb.setDefaultDialogBorder(); String title = getResourceString("Specify.ABOUT");//$NON-NLS-1$ CustomDialog aboutDlg = new CustomDialog(topFrame, title + " " + appName, true, CustomDialog.OK_BTN, //$NON-NLS-1$ pb.getPanel()); String okLabel = getResourceString("Specify.CLOSE");//$NON-NLS-1$ aboutDlg.setOkLabel(okLabel); aboutDlg.createUI(); aboutDlg.pack(); // for some strange reason I can't get the dialog to size itself correctly Dimension size = aboutDlg.getSize(); size.height += 120; aboutDlg.setSize(size); txtPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { AttachmentUtils.openURI(event.getURL().toURI()); } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); } } } }); UIHelper.centerAndShow(aboutDlg); }
From source file:edu.ku.brc.af.ui.db.TextFieldWithQuery.java
/** * Builds the SQL to be used to do the search. * @param newEntryStr the string value to be searched * @param isForCount do query for count of returns * @return the full sql string./*w w w . j a v a2s . c o m*/ */ protected String buildSQL(final String newEntryStr, final boolean isForCount) { if (externalQueryProvider != null) { String fullSQLStr = externalQueryProvider.getFullSQL(newEntryStr, isForCount); if (StringUtils.isNotEmpty(fullSQLStr)) { return fullSQLStr; } } StringBuilder whereSB = new StringBuilder(); if (keyColumns.length > 1) { whereSB.append("("); //$NON-NLS-1$ } int cnt = 0; for (String keyCol : keyColumns) { String[] colParts = keyCol.split("\\."); String abbrev = colParts.length > 1 ? colParts[0] : tableInfo.getAbbrev(); String fld = colParts.length > 1 ? colParts[1] : keyCol; if (cnt > 0) whereSB.append(" OR "); //$NON-NLS-1$ whereSB.append(" LOWER("); //$NON-NLS-1$ whereSB.append(abbrev + "." + fld); whereSB.append(") LIKE '"); //$NON-NLS-1$ //The following condition is added specifically for catalog number lookups. Probably. if (uiFieldFormatter != null && uiFieldFormatter.isNumeric()) { whereSB.append("%"); //$NON-NLS-1$ } whereSB.append(newEntryStr.toLowerCase()); whereSB.append("%' "); //$NON-NLS-1$ cnt++; } if (keyColumns.length > 1) { whereSB.append(")"); //$NON-NLS-1$ } if (externalQueryProvider != null) { String extraWhereClause = externalQueryProvider.getExtraWhereClause(); if (StringUtils.isNotEmpty(extraWhereClause)) { whereSB.append(' '); whereSB.append(extraWhereClause); } } if (StringUtils.isNotEmpty(sqlTemplate)) { StringBuilder selectSB = new StringBuilder(); if (isForCount) { selectSB.append("count("); //$NON-NLS-1$ addTblAbbrev(tableInfo.getAbbrev(), tableInfo.getIdFieldName(), selectSB); selectSB.append(")"); //$NON-NLS-1$ } else { if (StringUtils.contains(displayColumns, ',')) { int fCnt = 0; for (String fld : StringUtils.split(displayColumns, ',')) { if (fCnt > 0) selectSB.append(", "); //$NON-NLS-1$ addTblAbbrev(tableInfo.getAbbrev(), fld, selectSB); fCnt++; } } else { addTblAbbrev(tableInfo.getAbbrev(), displayColumns, selectSB); } selectSB.append(", "); //$NON-NLS-1$ addTblAbbrev(tableInfo.getAbbrev(), tableInfo.getIdFieldName(), selectSB); } //System.err.println( selectSB.toString()); sql = StringUtils.replace(sqlTemplate, "%s1", selectSB.toString()); //$NON-NLS-1$ sql = StringUtils.replace(sql, "%s2", whereSB.toString()); //$NON-NLS-1$ if (doAdjustQuery) { sql = QueryAdjusterForDomain.getInstance().adjustSQL(sql); } //log.debug(sql); System.err.println(sql); return sql; } if (sql == null) { StringBuilder sb = new StringBuilder(); if (QueryAdjusterForDomain.getInstance().isUserInputNotInjectable(newEntryStr)) { sb.append("SELECT "); //$NON-NLS-1$ if (isForCount) { sb.append("count("); //$NON-NLS-1$ sb.append(tableInfo.getAbbrev() + "." + tableInfo.getIdFieldName()); sb.append(")"); //$NON-NLS-1$ } else { sb.append(tableInfo.getAbbrev() + "." + displayColumns); sb.append(","); //$NON-NLS-1$ sb.append(tableInfo.getAbbrev() + "." + tableInfo.getIdFieldName()); } sb.append(" FROM "); //$NON-NLS-1$ sb.append(tableInfo.getClassName()); sb.append(" as "); //$NON-NLS-1$ sb.append(tableInfo.getAbbrev()); String joinSnipet = doAdjustQuery ? QueryAdjusterForDomain.getInstance().getJoinClause(tableInfo, true, null, false) : null; //arg 2: false means SQL if (joinSnipet != null) { sb.append(' '); sb.append(joinSnipet); sb.append(' '); } sb.append(" WHERE "); //$NON-NLS-1$ //System.err.println(sb.toString()); String specialCols = doAdjustQuery ? QueryAdjusterForDomain.getInstance().getSpecialColumns(tableInfo, true) : null;//, false, isForCount ? null : tableInfo.getAbbrev()); if (StringUtils.isNotEmpty(specialCols)) { if (whereSB.length() > 0) whereSB.append(" AND "); //$NON-NLS-1$ whereSB.append(specialCols); //System.err.println(whereSB.toString()); } if (externalQueryProvider != null) { String extraWhereClause = externalQueryProvider.getExtraWhereClause(); if (StringUtils.isNotEmpty(extraWhereClause)) { whereSB.append(' '); whereSB.append(extraWhereClause); } } whereSB.append(" ORDER BY "); //$NON-NLS-1$ whereSB.append(displayColumns); //$NON-NLS-1$ whereSB.append(" ASC"); //$NON-NLS-1$ // cnt = 0; // for (String keyCol : keyColumns) // { // if (cnt > 0) whereSB.append(", "); //$NON-NLS-1$ // whereSB.append(keyCol); // whereSB.append(" ASC"); //$NON-NLS-1$ // cnt++; // } sb.append(whereSB.toString()); } //log.debug("* "+sql); return sb.toString(); } return sql; }
From source file:edu.ku.brc.specify.tasks.subpane.lm.LifeMapperPane.java
/** * @param searchStr// www . ja v a 2s. c o m * @param cbListener */ private void doSearchGenusSpecies(final String searchStr, final LMSearchCallbackListener cbListener) { UsageTracker.incrUsageCount("LM.GenSpSearch"); updateMyDataUIState(false); final SimpleGlassPane glassPane = writeSimpleGlassPaneMsg(getLocalizedMessage("LifeMapperTask.PROCESSING"), GLASS_FONT_SIZE); glassPane.setTextYPos((int) ((double) getSize().height * 0.25)); SwingWorker<String, String> worker = new SwingWorker<String, String>() { @Override protected String doInBackground() throws Exception { HttpClient httpClient = new HttpClient(); httpClient.getParams().setParameter("http.useragent", getClass().getName()); //$NON-NLS-1$ httpClient.getParams().setParameter("http.socket.timeout", 15000); String genusSpecies = StringUtils.replace(searchStr, " ", "%20"); String url = "http://www.lifemapper.org/hint/species/" + genusSpecies + "?maxReturned=1000&format=json"; //System.out.println(url); GetMethod getMethod = new GetMethod(url); try { httpClient.executeMethod(getMethod); return getMethod.getResponseBodyAsString(); } catch (java.net.UnknownHostException uex) { //log.error(uex.getMessage()); } catch (Exception e) { e.printStackTrace(); UsageTracker.incrUsageCount("LM.GenSpSearchErr"); } return null; } @SuppressWarnings("unchecked") @Override protected void done() { super.done(); ArrayList<OccurrenceSetIFace> items = null; String errMsgKey = "LifeMapperTask.PROC_ERR"; String responseString; try { responseString = get(); //System.out.println(responseString); if (responseString != null) { if (responseString.startsWith("None of the species")) { errMsgKey = "LM_NO_LM_DATA"; } else if (responseString.startsWith("Search too broad")) { errMsgKey = "LM_TOO_BROAD"; } else if (StringUtils.isNotEmpty(responseString) && StringUtils.contains(responseString.toLowerCase(), "{")) { JSONTokener tok = new JSONTokener(responseString); while (tok.more()) { JSONObject obj = (JSONObject) tok.nextValue(); JSONArray pointArray = (JSONArray) obj.get("columns"); Iterator<Object> iter = (Iterator<Object>) pointArray.iterator(); while (iter.hasNext()) { JSONArray arrayObj = (JSONArray) iter.next(); //System.out.println(arrayObj); Iterator<Object> iterInner = (Iterator<Object>) arrayObj.iterator(); while (iterInner.hasNext()) { JSONObject pObj = (JSONObject) iterInner.next(); String binomial = (String) pObj.get("binomial"); String gnSpName = (String) pObj.get("name"); String numPoints = (String) pObj.get("numPoints"); String occurrenceSet = (String) pObj.get("occurrenceSet"); if (StringUtils.isNotEmpty(gnSpName) && StringUtils.isNotEmpty(numPoints) && StringUtils.isNotEmpty(occurrenceSet)) { try { int numPnts = Integer.parseInt(numPoints); int occurId = Integer.parseInt(occurrenceSet); if (numPnts > 0 && occurId > 0) { if (items == null) { items = new ArrayList<OccurrenceSetIFace>(); } items.add(new GenusSpeciesDataItem( String.format("%s (%s)", gnSpName, numPoints), occurrenceSet, binomial)); } } catch (Exception ex) { // no op } errMsgKey = items == null || items.size() == 0 ? "LM_NO_LOCAL_DATA" : null; } } } } } } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } if (errMsgKey != null) { showErrorMsg(glassPane, errMsgKey); cbListener.noItems(); } else { //System.out.println("Num Genus/Species: "+items.size()); clearSimpleGlassPaneMsg(); cbListener.itemsFound(items); } } }; worker.execute(); }
From source file:com.cosmosource.app.personnel.service.UnitAdminManager.java
/** * @Description???/*from w ww. j av a 2 s .c o m*/ * @Authorhp * @Date2013-3-19 * @param xorText * @return **/ public static String getXorVerificationCode(String xorText) { char[] b = xorText.toCharArray(); int t = 0; int a = 0; int c = 0; String hexadecimal = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F"; for (int i = 0; i < b.length; i++) { if (StringUtils.contains(hexadecimal, b[i])) { if (i % 2 == 0) { t = Integer.parseInt(String.valueOf(b[i]), 16); a ^= t; } else { t = Integer.parseInt(String.valueOf(b[i]), 16); c ^= t; } } } String result = Integer.toHexString(a) + Integer.toHexString(c); return result.toUpperCase(); }
From source file:com.haulmont.cuba.gui.app.core.bulk.BulkEditorWindow.java
protected void ensureEmbeddedPropertyCreated(Entity item, String propertyPath) { if (!StringUtils.contains(propertyPath, ".")) { return;// w ww .ja va2s. c o m } MetaPropertyPath path = metaClass.getPropertyPath(propertyPath); if (path != null) { Entity currentItem = item; for (MetaProperty property : path.getMetaProperties()) { if (metadataTools.isEmbedded(property)) { Object currentItemValue = currentItem.getValue(property.getName()); if (currentItemValue == null) { Entity newItem = metadata.create(property.getRange().asClass()); currentItem.setValue(property.getName(), newItem); currentItem = newItem; } else { currentItem = (Entity) currentItemValue; } } else { break; } } } }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
/** * bucket list .//from w w w . j av a 2 s. c om * * @param userDB * @return * @throws Exception */ public static List<String> getGridFSBucketList(UserDBDAO userDB) throws Exception { List<String> listStr = new ArrayList<String>(); DB mongoDb = findDB(userDB); Set<String> colNames = mongoDb.getCollectionNames(); for (String name : colNames) { if (StringUtils.contains(name, ".chunks")) listStr.add(StringUtils.removeEnd(name, ".chunks")); } return listStr; }
From source file:com.adobe.acs.tools.csv_asset_importer.impl.CsvAssetImporterServlet.java
/** * Gets the ModifiableValueMap for the Asset's metadata node. * * @param asset the asset to get the properties for * @return the ModifiableValueMap for the Asset's metadata node *///from ww w .j a v a 2 s. c om private Node getMetadataProperties(final Asset asset, final String relPropertyPath) throws RepositoryException, CsvAssetImportException { String metadataResourcePath = JcrConstants.JCR_CONTENT + "/" + DamConstants.METADATA_FOLDER; Resource assetResource = asset.adaptTo(Resource.class); Resource metadataResource = assetResource.getChild(metadataResourcePath); if (metadataResource == null) { throw new CsvAssetImportException("Could not find metadata resource at [ " + assetResource.getPath() + "/" + metadataResourcePath + " ]. This is very strange. Skipping row as failure however some dam:Asset nodes for this asset may have been created."); } else if (!StringUtils.contains(relPropertyPath, "/")) { return metadataResource.adaptTo(Node.class); } else { ResourceResolver resourceResolver = assetResource.getResourceResolver(); String relPropertyPathPrefix = StringUtils.substringBeforeLast(relPropertyPath, "/"); String canonicalPath = com.day.text.Text .makeCanonicalPath(metadataResource.getPath() + "/" + relPropertyPathPrefix); Node node = JcrUtils.getOrCreateByPath(canonicalPath, JcrConstants.NT_UNSTRUCTURED, resourceResolver.adaptTo(Session.class)); Resource relativeResource = resourceResolver.getResource(node.getPath()); return relativeResource.adaptTo(Node.class); } }
From source file:edu.ku.brc.specify.config.init.DatabasePanel.java
/** * @param label/*from www. ja v a 2s .c o m*/ * @param text * @param badKeyArg * @param errKeyArg * @param isPwd * @return */ public static boolean checkForValidText(final JLabel label, final String text, final String badKeyArg, final String errKeyArg, final boolean isPwd) { String errKey = null; if (!isPwd && !text.isEmpty() && !StringUtils.isAlpha(text.substring(0, 1))) { errKey = badKeyArg; } else if (StringUtils.contains(text, ' ') || StringUtils.contains(text, ',')) { errKey = errKeyArg; } if (errKey != null) { label.setForeground(Color.RED); label.setText(getResourceString(errKeyArg)); label.setVisible(true); return false; } return true; }
From source file:com.vmware.veei.qe.devcenter.SampleExchangeTest.java
/** * Returns a list of URLs of the Sample Request links. *//*from w w w . jav a 2 s . c o m*/ @DataProvider public Object[][] getSampleRequestUrls() { List<Object[]> data = new ArrayList<Object[]>(); // #action : Navigates to main Sample Exchange pages. driver.get(baseUrl + SAMPLE_CODE_URL); selectTab("Requests"); // Gets all the links under Sample page span. List<WebElement> elements = driver .findElements(By.cssSelector("#search-results-list .title-list li .title")); // We have to put this in a temporaty list, since any further action on the Webdriver // will make the references to the WebElement unusable. for (WebElement element : elements) { if (StringUtils.contains(element.getAttribute("href"), "&id=")) { data.add(new Object[] { element.getAttribute("href").trim() }); } } return data.toArray(new Object[][] {}); }
From source file:com.atlassian.jira.web.action.JiraWebActionSupport.java
/** * The cancel links should not included the selectedIssueId, otherwise when returning to the issue navigator an * issue updated notification will be shown. * * @return the returnUrl with selectedIssueId parameter stripped out. *///from w ww.j av a 2 s . c om public String getReturnUrlForCancelLink() { if (StringUtils.contains(returnUrl, "selectedIssueId")) { return SELECTED_ISSUE_PATTERN.matcher(returnUrl).replaceFirst(""); } else { return returnUrl; } }