List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:com.prowidesoftware.swift.io.parser.MxParser.java
/** * Distinguished Name structure: cn=name,ou=payment,o=bank,o=swift * <br />//w w w .j av a 2s .c o m * Example: o=spxainjj,o=swift * * @param dn the DN element content * @return returns capitalized "bank", in the example SPXAINJJ */ public static String getBICFromDN(final String dn) { for (String s : StringUtils.split(dn, ",")) { if (StringUtils.startsWith(s, "o=") && !StringUtils.equals(s, "o=swift")) { return StringUtils.upperCase(StringUtils.substringAfter(s, "o=")); } /* else if (StringUtils.startsWith(s, "ou=") && !StringUtils.equals(s, "ou=swift")) { return StringUtils.upperCase(StringUtils.substringAfter(s, "ou=")); } */ } return null; }
From source file:com.prowidesoftware.swift.model.field.Field.java
/** * Returns the first component starting with the given prefix value or <code>null</code> if not found. * @param prefix//w w w. j av a2 s . c o m * @return s */ public String findComponentStartingWith(final String prefix) { for (int i = 0; i < this.components.size(); i++) { final String c = this.components.get(i); if (StringUtils.startsWith(c, prefix)) { return c; } } return null; }
From source file:com.sfs.whichdoctor.dao.onlineapplication.BasicTrainingOnlineApplicationHandler.java
/** * Load specialty details from the XML application. * * @param root the root of the XML application * @param onlineApplication the online application * @return the specialty bean//from w w w . j a va 2 s . co m */ private SpecialtyBean loadSpecialtyDetails(final Element root, final OnlineApplicationBean onlineApplication) { SpecialtyBean specialty = new SpecialtyBean(); String organisation = "RACP - Adult"; try { String div = root.getChild("masterrecord").getChildText("Division").trim(); if (StringUtils.startsWith(div, "P")) { organisation = "RACP - Paediatric"; } } catch (Exception e) { dataLogger.error("Error parsing Division: " + e.getMessage()); } Calendar date = Calendar.getInstance(); if (onlineApplication.getCreatedDate() != null) { date.setTime(onlineApplication.getCreatedDate()); } int year = date.get(Calendar.YEAR); // If December the curriculum year is the following year if (date.get(Calendar.MONTH) > 10) { year++; } specialty.setTrainingOrganisation(organisation); specialty.setTrainingProgram("Basic Training"); specialty.setStatus("In training"); specialty.setTrainingProgramYear(year); return specialty; }
From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java
private static void setCellValueTagNumberFormat(HSSFWorkbook wb, Cell cell, Object oneCellValue, String vendor) {/* ww w . j ava 2 s . c o m*/ if (oneCellValue == null) { cell.setCellValue(StringUtils.EMPTY); return; } String tagNum = StringUtils.trimToEmpty(oneCellValue.toString()); tagNum = tagNum.replaceAll("\u00a0", StringUtils.EMPTY); tagNum = StringUtils.stripStart(tagNum, "0"); if (StringUtils.contains(vendor, TOLL_COMPANY_SUN_PASS)) { if (StringUtils.startsWith(tagNum, "155")) { tagNum = StringUtils.stripEnd(tagNum, "0"); } } cell.setCellValue(tagNum); }
From source file:com.zb.app.web.controller.cms.CMSController.java
/** * ???/* www . ja v a 2s . com*/ * * @return */ @RequestMapping(value = "/queryCompanyByConditions.htm", produces = "application/json") @ResponseBody public JsonResult queryCompanyByConditions(TravelCompanyQuery query, Integer limit) { List<TravelCompanyDO> list = companyService.listQuery(query); List<Map<String, ?>> mapList = CollectionUtils.toMapList(list, "cId", "cName", "cSpell"); // StringBuilder sb = new StringBuilder(); String cond = query.getQ() == null ? StringUtils.EMPTY : query.getQ(); cond = cond.toLowerCase(); // String temp; int maxSize = getLimit(limit); int size = 0; List<Map<String, ?>> result = new LinkedList<Map<String, ?>>(); String property = cond.matches("[a-zA-Z]+") ? "cSpell" : "cName"; for (Map<String, ?> map : mapList) { Object cName = null; for (Entry<String, ?> entry : map.entrySet()) { if (StringUtils.equals(entry.getKey(), property)) { cName = entry.getValue(); } } if (cond.matches("[a-zA-Z]+") ? StringUtils.startsWith((String) cName, cond) : StringUtils.containsIgnoreCase((String) cName, cond)) { result.add(map); size++; if (size > maxSize) { break; } } } return JsonResultUtils.success(result); }
From source file:com.taobao.tdhs.jdbc.TDHSStatement.java
private void doInsert(com.taobao.tdhs.client.statement.Statement s, ParseSQL parseSQL, String tableName, String dbName) throws SQLException { Insert insert = s.insert().use(dbName).from(tableName); List<Entry<String, String>> insertEntries = parseSQL.getInsertEntries(); if (insertEntries == null || insertEntries.isEmpty()) { throw new TDHSSQLException("no value to insert!", parseSQL.getSql()); }//from w w w . j a v a 2 s . c om for (Entry<String, String> e : insertEntries) { if (StringUtils.isBlank(e.getKey()) || StringUtils.isBlank(e.getValue())) { throw new TDHSSQLException("insert column and values can't be empty!", parseSQL.getSql()); } String field = StringUtil.escapeField(StringUtils.trim(e.getKey())); if (field == null) { throw new TDHSSQLException("insert column is error!", parseSQL.getSql()); } String value = StringUtils.trim(e.getValue()); if (StringUtils.equalsIgnoreCase("null", value)) { insert.valueSetNull(field); } else if (StringUtils.equalsIgnoreCase("now()", value)) { insert.valueSetNow(field); } else { value = StringUtil.escapeValue(value); if (value == null) { throw new TDHSSQLException("insert value is error!", parseSQL.getSql()); } if (StringUtils.startsWith(value, BYTE_PARAMETER_PREFIX)) { int pidx = ConvertUtil .safeConvertInt(StringUtils.substring(value, BYTE_PARAMETER_PREFIX.length()), -1); if (byteParameters.containsKey(pidx)) { insert.value(field, byteParameters.get(pidx)); } else { insert.value(field, value); } } else { insert.value(field, value); } } } TDHSResponse response = null; try { response = insert.insert(); } catch (TDHSException e) { throw new SQLException(e); } processResponse(response, null, true, true); }
From source file:com.glaf.base.modules.sys.service.mybatis.SysApplicationServiceImpl.java
public JSONArray getUserMenu(long parent, String actorId) { JSONArray array = new JSONArray(); SysUser user = authorizeService.login(actorId); if (user != null) { List<SysTree> treeList = null; SysApplication app = this.findById(parent); SysTreeQuery query = new SysTreeQuery(); query.treeId(app.getNode().getTreeId()); query.treeIdLike(app.getNode().getTreeId() + "%"); if (!user.isSystemAdmin()) { List<String> actorIds = new java.util.ArrayList<String>(); List<Object> rows = entityService.getList("getAgents", actorId); if (rows != null && !rows.isEmpty()) { for (Object object : rows) { if (object instanceof Agent) { Agent agent = (Agent) object; if (!agent.isValid()) { continue; }//from www. jav a 2 s . co m switch (agent.getAgentType()) { case 0:// ? actorIds.add(agent.getAssignFrom()); break; default: break; } } } } if (!actorIds.isEmpty()) { actorIds.add(actorId); query.setActorIds(actorIds); } else { query.setActorId(actorId); } treeList = sysTreeMapper.getTreeListByUsers(query); } else { treeList = sysTreeMapper.getTreeList(query); } List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>(); for (SysTree tree : treeList) { if (StringUtils.isNotEmpty(tree.getUrl())) { if (StringUtils.startsWith(tree.getUrl(), "/")) { if (StringUtils.isNotEmpty(SystemConfig.getServiceUrl())) { String link = SystemConfig.getServiceUrl() + tree.getUrl(); tree.setUrl(link); } else { String link = ApplicationContext.getContextPath() + tree.getUrl(); tree.setUrl(link); } } } treeModels.add(tree); } TreeHelper treeHelper = new TreeHelper(); array = treeHelper.getTreeJSONArray(treeModels); // logger.debug(array.toString('\n')); } return array; }
From source file:ddf.catalog.resource.impl.URLResourceReader.java
private boolean validateFilePath(File resourceFilePath) throws IOException { String resourceCanonicalPath = resourceFilePath.getCanonicalPath(); LOGGER.debug("Converted resource path [{}] to its canonical path of [{}]", resourceFilePath.toString(), resourceCanonicalPath);//from w w w.j a va2 s . co m if (this.rootResourceDirectories != null) { for (String rootResourceDirectory : this.rootResourceDirectories) { String rootResouceDirectoryCanonicalPath = new File(rootResourceDirectory).getCanonicalPath(); LOGGER.debug("Converted root resource directory [{}] to its canonical path of [{}]", rootResourceDirectory, rootResouceDirectoryCanonicalPath); LOGGER.debug( "Determining if resource path [{}] starts with configured root resource directory [{}].", resourceCanonicalPath, rootResouceDirectoryCanonicalPath); if (StringUtils.startsWith(resourceCanonicalPath, rootResouceDirectoryCanonicalPath)) { LOGGER.debug( "Resource path [{}] starts with configured root resource directory [{}]. Resource is in a valid location for download by the {}", resourceCanonicalPath, rootResouceDirectoryCanonicalPath, URLResourceReader.class.getSimpleName()); return true; } else { LOGGER.debug("Resource path [{}] does not start with configured root resource directory [{}].", resourceCanonicalPath, rootResouceDirectoryCanonicalPath); } } LOGGER.debug( "Unable to find a root resource directory in the {}'s configuration for resource path [{}]. Unable to download resource.", URLResourceReader.class.getSimpleName(), resourceCanonicalPath); return false; } return false; }
From source file:com.prowidesoftware.swift.model.SwiftTagListBlock.java
/** * Similar to {@link #getTagsByName(String)} * <em>NOTE: supports 'a' wildcard. If 95a is given, all 95, 95K, 95J fields will be returned.</em>. * This is case sensitive.//from ww w . j av a 2 s. c o m * @throws IllegalArgumentException if name is null * @return an array of matched fields or an empty array if none found */ public Field[] getFieldsByName(final String name) { // sanity check Validate.notNull(name, "parameter 'name' cannot not be null"); final boolean wildcard; final String search; if (name.endsWith("a")) { wildcard = true; search = name.substring(0, name.length() - 1); } else { wildcard = false; search = name; } final List<Field> l = new ArrayList<Field>(); for (final Iterator<Tag> it = this.tags.iterator(); it.hasNext();) { final Tag t = (Tag) it.next(); if ((wildcard && StringUtils.startsWith(t.getName(), search)) || StringUtils.equals(t.getName(), name)) { final Field field = t.getField(); if (field == null) { log.warning("Could not create field instance of " + t); } else { l.add(field); } } } // returns correctly empty array - see test testEmptyArrayReturn return (Field[]) l.toArray(new Field[l.size()]); }
From source file:au.edu.anu.portal.portlets.basiclti.BasicLTIPortlet.java
/** * Processes the init params to get the adapter class map. This method iterates over every init-param, selects the appropriate adapter ones, * fetches the param value and then strips the 'adapter-class-' prefix from the param name for storage in the map. * @param config PortletConfig/*from w w w . ja v a 2 s. c o m*/ * @return Map of adapter names and classes */ private Map<String, String> initAdapters(PortletConfig config) { Map<String, String> m = new HashMap<String, String>(); String ADAPTER_CLASS_PREFIX = "adapter-class-"; //get it into a usable form List<String> paramNames = Collections.list((Enumeration<String>) config.getInitParameterNames()); //iterate over, select the appropriate ones, retrieve the param value then strip param name for storage. for (String paramName : paramNames) { if (StringUtils.startsWith(paramName, ADAPTER_CLASS_PREFIX)) { String adapterName = StringUtils.removeStart(paramName, ADAPTER_CLASS_PREFIX); String adapterClass = config.getInitParameter(paramName); m.put(adapterName, adapterClass); log.info("Registered adapter: " + adapterName + " with class: " + adapterClass); } } log.info("Autowired: " + m.size() + " adapters"); return m; }