List of usage examples for org.apache.commons.lang StringUtils trimToEmpty
public static String trimToEmpty(String str)
Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null
.
From source file:edu.lafayette.metadb.model.dataman.DataExporter.java
/** * Export a project's attributes./*from w w w . ja va2 s . c o m*/ * @param projectName The project name. * @param delimiter The delimiter to use. * @param encoder The character encoding to use. * @param technical A flag indicating whether to include technical attributes. * @return A String[] representing headers for the export file. */ public static String[] exportAttributes(String projectName, char delimiter, String encoder, boolean technical) { ArrayList attrList = null; attrList = AdminDescAttributesDAO.getAdminDescAttributes(projectName, Global.MD_TYPE_DESC); attrList.addAll(AdminDescAttributesDAO.getAdminDescAttributes(projectName, Global.MD_TYPE_ADMIN)); if (technical) attrList.addAll(TechAttributesDAO.getTechAttributes(projectName)); String[] out = new String[attrList.size()]; for (int i = 0; i < out.length; i++) try { String label = ((Attribute) attrList.get(i)).getLabel(); out[i] = StringUtils.trimToEmpty(new String( (((Attribute) attrList.get(i)).getElement() + (label.equals("") ? "" : "." + label)) .getBytes("UTF-8"), encoder).replace('\t', ' ')); } catch (UnsupportedEncodingException e) { MetaDbHelper.logEvent(e); out[i] = ((Attribute) attrList.get(i)).getElement() + "." + ((Attribute) attrList.get(i)).getLabel(); } return out; }
From source file:com.egt.ejb.toolkit.ToolKitUtils.java
public static String getenv(String name) { String var = EAB.ENTERPRISE_APPLICATION_CODE.toUpperCase() + "_" + name; return StringUtils.trimToEmpty(System.getenv(var)); }
From source file:com.hangum.tadpole.rdb.core.dialog.dbconnect.composite.AltibaseLoginComposite.java
@Override public boolean makeUserDBDao(boolean isTest) { if (!isValidateInput(isTest)) return false; String dbUrl = ""; String selectLocale = StringUtils.trimToEmpty(comboLocale.getText()); if (selectLocale.equals("") || DBLocaleUtils.NONE_TXT.equals(selectLocale)) { dbUrl = String.format(getSelectDB().getDB_URL_INFO(), StringUtils.trimToEmpty(textHost.getText()), StringUtils.trimToEmpty(textPort.getText()), StringUtils.trimToEmpty(textDatabase.getText())); if (!"".equals(textJDBCOptions.getText())) { dbUrl += "?" + textJDBCOptions.getText(); }//w ww. j a va 2 s . c om } else { dbUrl = String.format(getSelectDB().getDB_URL_INFO(), StringUtils.trimToEmpty(textHost.getText()), StringUtils.trimToEmpty(textPort.getText()), StringUtils.trimToEmpty(textDatabase.getText())) + "?charset=" + selectLocale; if (!"".equals(textJDBCOptions.getText())) { dbUrl += "&" + textJDBCOptions.getText(); } } userDB = new UserDBDAO(); userDB.setDbms_type(getSelectDB().getDBToString()); userDB.setUrl(dbUrl); userDB.setUrl_user_parameter(textJDBCOptions.getText()); userDB.setDb(StringUtils.trimToEmpty(textDatabase.getText())); userDB.setGroup_name(StringUtils.trimToEmpty(preDBInfo.getComboGroup().getText())); userDB.setDisplay_name(StringUtils.trimToEmpty(preDBInfo.getTextDisplayName().getText())); String dbOpType = PublicTadpoleDefine.DBOperationType .getNameToType(preDBInfo.getComboOperationType().getText()).name(); userDB.setOperation_type(dbOpType); if (dbOpType.equals(PublicTadpoleDefine.DBOperationType.PRODUCTION.name()) || dbOpType.equals(PublicTadpoleDefine.DBOperationType.BACKUP.name())) { userDB.setIs_lock(PublicTadpoleDefine.YES_NO.YES.name()); } userDB.setHost(StringUtils.trimToEmpty(textHost.getText())); userDB.setPort(StringUtils.trimToEmpty(textPort.getText())); userDB.setUsers(StringUtils.trimToEmpty(textUser.getText())); userDB.setPasswd(StringUtils.trimToEmpty(textPassword.getText())); userDB.setLocale(StringUtils.trimToEmpty(comboLocale.getText())); // ? ?? ? . userDB.setRole_id(PublicTadpoleDefine.USER_ROLE_TYPE.ADMIN.toString()); // others connection . setOtherConnectionInfo(); return true; }
From source file:com.enonic.cms.web.portal.services.UserServicesAccessManagerImpl.java
private void parseAndAddRules(String accessRules, AccessPermission accessPermission, ConcurrentMap<String, AccessPermission> siteRules, SiteKey site) { accessRules = StringUtils.trimToEmpty(accessRules); String[] ruleItems = accessRules.split(","); for (String ruleItem : ruleItems) { ruleItem = ruleItem.trim();//from w ww .j a v a 2 s . com if (ruleItem.isEmpty()) { continue; } if (siteRules.containsKey(ruleItem)) { throw new IllegalArgumentException( "Duplicated value for http service access rule '" + ruleItem + "' on site " + site); } siteRules.put(ruleItem, accessPermission); } }
From source file:com.mothsoft.alexis.web.ListDocumentsBackingBean.java
public SortOrder getSortOrder() { final FacesContext facesContext = FacesContext.getCurrentInstance(); final String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("order"); if (StringUtils.trimToEmpty(paramValue).equalsIgnoreCase("date")) { return SortOrder.DATE_DESC; } else {/*from w w w . ja va 2 s . co m*/ return SortOrder.RELEVANCE; } }
From source file:com.eucalyptus.blockstorage.BlockDeviceResource.java
@Override public Long getSize() throws UnknownSizeException { Long size = 0L;// w ww. ja v a 2s.c o m try { CommandOutput result = SystemUtil.runWithRawOutput(new String[] { StorageProperties.EUCA_ROOT_WRAPPER, "blockdev", "--getsize64", this.getPath() }); size = Long.parseLong(StringUtils.trimToEmpty(result.output)); return size; } catch (Exception e) { throw new UnknownSizeException( "Failed to determine size for " + this.getId() + " mounted at " + this.getPath(), e); } }
From source file:com.edgenius.wiki.Shell.java
/** * @return//from w w w. j a v a 2s . c o m * @throws IOException */ public static void load() { Shell.enabled = false; log.info("Loading shell.properties ..."); String root = DataRoot.getDataRoot(); if (!FileUtil.exist(root + Shell.FILE)) { try { //copy from defaultExternalResource FileOutputStream dest = FileUtil.getFileOutputStream(root + Shell.FILE); IOUtils.copy(FileUtil.getFileInputStream(FILE_DEFAULT), dest); IOUtils.closeQuietly(dest); } catch (IOException e) { log.error("Copy default shell.properties file failed", e); } } try { filelock.readLock().lock(); Properties props = FileUtil.loadProperties(root + Shell.FILE); Shell.enabled = BooleanUtils.toBoolean(props.getProperty("shell.enabled")); Shell.autoEnabled = BooleanUtils.toBoolean(props.getProperty("shell.auto.enable.at.space.creating")); Shell.rootUrl = StringUtils.trimToEmpty(props.getProperty("shell.url")); Shell.timeout = NumberUtils.toInt(props.getProperty("connection.timeout"), DEFAULT_TIMEOUT); //default 20s Shell.key = StringUtils.trimToEmpty(props.getProperty("shell.key")); //fix to add end slash if (!Shell.rootUrl.endsWith("/")) Shell.rootUrl += "/"; updateUrl(); } catch (IOException e) { log.error("Load shell.properties failed", e); } finally { filelock.readLock().unlock(); } }
From source file:com.edgenius.core.Server.java
public void syncTo(Properties prop) { prop.setProperty("server.db.type", StringUtils.trimToEmpty(dbType)); prop.setProperty("server.db.connect.type", StringUtils.trimToEmpty(dbConnectType)); prop.setProperty("server.db.driver.class.name", StringUtils.trimToEmpty(dbDriverClass)); prop.setProperty("server.db.url", StringUtils.trimToEmpty(dbUrl)); prop.setProperty("server.db.schema", StringUtils.trimToEmpty(dbSchema)); prop.setProperty("server.db.username", StringUtils.trimToEmpty(dbUsername)); prop.setProperty("server.db.password", StringUtils.trimToEmpty(dbPassword)); prop.setProperty("server.db.jndi", StringUtils.trimToEmpty(dbJNDI)); prop.setProperty("mail.smtp.host", StringUtils.trimToEmpty(mailHost)); prop.setProperty("mail.smtp.port", StringUtils.trimToEmpty(mailHostPort)); prop.setProperty("mail.smtp.username", StringUtils.trimToEmpty(mailUsername)); prop.setProperty("mail.smtp.password", StringUtils.trimToEmpty(mailPassword)); prop.setProperty("mail.smtp.properties", StringUtils.trimToEmpty(mailProperties)); prop.setProperty("mail.smtp.jndi", StringUtils.trimToEmpty(mailJndi)); prop.setProperty("mq.server.embedded", StringUtils.trimToEmpty(mqServerEmbedded)); prop.setProperty("mq.server.url", StringUtils.trimToEmpty(mqServerUrl)); prop.setProperty("quartz.jobstore.driver", StringUtils.trimToEmpty(quartzJobstoreDriver)); }
From source file:datacite.oai.provider.service.MDSSearchServiceSolrImpl.java
static SolrQuery constructSolrQuery(Date updateDateFrom, Date updateDateTo, String setspec, int offset, int length) throws ServiceException { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setRows(length);/*from w ww. j a va 2s. c om*/ query.setStart(offset); query.setSortField("updated", ORDER.asc); setspec = StringUtils.trimToEmpty(setspec); if (setspec.contains(Constants.Set.BASE64_PART_DELIMITER)) { String split[] = setspec.split(Constants.Set.BASE64_PART_DELIMITER, 2); setspec = split[0]; String base64 = split[1]; String solrfilter = new String(Base64.decodeBase64(base64)); logger.info("decoded base64 setspec: " + solrfilter); solrfilter = solrfilter.replaceAll("^[?&]+", ""); List<NameValuePair> params = URLEncodedUtils.parse(solrfilter, Charset.defaultCharset()); for (NameValuePair param : params) { String name = param.getName(); String value = param.getValue(); if (name.equals("q")) query.setQuery(value); else if (name.equals("fq")) query.addFilterQuery(value); else throw new ServiceException("parameter '" + name + "' is not supported"); } } if (setspec != null && setspec.trim().length() > 0) { setspec = setspec.trim().toUpperCase(); if (setspec.equalsIgnoreCase(Constants.Set.REF_QUALITY)) { query.addFilterQuery("refQuality:true"); } else { if (setspec.endsWith(Constants.Set.REF_QUALITY_SUFFIX)) { query.addFilterQuery("refQuality:true"); setspec = setspec.substring(0, setspec.lastIndexOf(Constants.Set.REF_QUALITY_SUFFIX)); } String field = setspec.contains(".") ? "datacentre_symbol" : "allocator_symbol"; query.addFilterQuery(field + ":" + setspec); } } String from = dateFormat.format(updateDateFrom); String to = dateFormat.format(updateDateTo); query.addFilterQuery("updated:[" + from + " TO " + to + "]"); query.setParam(CommonParams.QT, "/public/api"); return query; }
From source file:com.edgenius.wiki.search.service.AbstractSearchService.java
protected SearchResult commonSearch(final String keyword, final int currPageNumber, final int returnCount, final User user, final String... advance) throws SearchException { try {/*from ww w.j a va 2s .c o m*/ return (SearchResult) this.search(new SearcherCallback() { public Object doWithSearcher(IndexSearcher searcher) throws SearchException { try { if (StringUtils.trimToEmpty(keyword).length() > 0) { Query[] queries = createQuery(keyword, advance); Sort sort = createSort(advance); // Don't use Lucene default filter function to filter out no reading permission results // it is too slow - it will retrieve all documents in index - whatever it is matched or not //Filter filter = new SecurityFilter(user); TopDocs hits; if (sort == null) { hits = searcher.search(queries[0], LuceneConfig.MAX_RETURN); } else { hits = searcher.search(queries[0], LuceneConfig.MAX_RETURN, sort); } SearchResult rs = getResult(searcher, hits, keyword, currPageNumber, returnCount, user, queries[1]); return rs; } else { return emptyResult(keyword, currPageNumber); } } catch (Exception e) { throw new SearchException(e); } } }); } catch (Exception e) { log.error("Search failed ", e); throw new SearchException(e); } }