List of usage examples for org.apache.commons.lang StringUtils substring
public static String substring(String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.
From source file:com.justinmobile.core.dao.support.PropertyFilter.java
private void buildFilterName(String filterName) { // ????/*from www. j a v a2 s.com*/ String aliasPart = StringUtils.substringBefore(filterName, "_"); if (ALIAS.equals(aliasPart)) { String allPart = StringUtils.substringAfter(filterName, "_"); String firstPart = StringUtils.substringBefore(allPart, "_"); this.aliasName = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String joinTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); this.joinType = Enum.valueOf(JoinType.class, joinTypeCode).getValue(); filterName = StringUtils.substringAfter(allPart, "_"); } // ?????matchTypepropertyTypeCode String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } // ??OR String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); }
From source file:io.renren.modules.job.utils.ScheduleJob.java
@Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { ScheduleJobEntity scheduleJob = (ScheduleJobEntity) context.getMergedJobDataMap() .get(ScheduleJobEntity.JOB_PARAM_KEY); //?spring bean ScheduleJobLogService scheduleJobLogService = (ScheduleJobLogService) SpringContextUtils .getBean("scheduleJobLogService"); //??//w w w . j a v a 2 s . c o m ScheduleJobLogEntity log = new ScheduleJobLogEntity(); log.setJobId(scheduleJob.getJobId()); log.setBeanName(scheduleJob.getBeanName()); log.setMethodName(scheduleJob.getMethodName()); log.setParams(scheduleJob.getParams()); log.setCreateTime(new Date()); // long startTime = System.currentTimeMillis(); try { // logger.info("ID" + scheduleJob.getJobId()); ScheduleRunnable task = new ScheduleRunnable(scheduleJob.getBeanName(), scheduleJob.getMethodName(), scheduleJob.getParams()); Future<?> future = service.submit(task); future.get(); // long times = System.currentTimeMillis() - startTime; log.setTimes((int) times); //? 0? 1 log.setStatus(0); logger.info("ID" + scheduleJob.getJobId() + " " + times + ""); } catch (Exception e) { logger.error("ID" + scheduleJob.getJobId(), e); // long times = System.currentTimeMillis() - startTime; log.setTimes((int) times); //? 0? 1 log.setStatus(1); log.setError(StringUtils.substring(e.toString(), 0, 2000)); } finally { scheduleJobLogService.insert(log); } }
From source file:de.cosmocode.palava.salesforce.sync.DefaultAccountCopyFunction.java
@Override public Account apply(AccountBase from) { final Account to = Salesforce.FACTORY.createAccount(); LOG.debug("Copying {} into {}", from, to); String name = from.getName(); name = Strings.defaultIfBlank(name, "Empty Name"); name = StringUtils.substring(name, 0, 255); to.setName(Salesforce.FACTORY.createAccountName(name)); final String number = StringUtils.substring(Long.toString(from.getId()), 0, 40); to.setAccountNumber(Salesforce.FACTORY.createAccountAccountNumber(number)); final AddressBase address = from.getAddress(); final String phone = StringUtils.substring(address.getPhone(), 0, 40); to.setPhone(Salesforce.FACTORY.createAccountPhone(phone)); final String fax = StringUtils.substring(address.getFax(), 0, 40); to.setFax(Salesforce.FACTORY.createAccountFax(fax)); String website = address.getWebsite(); website = StringUtils.substring(website, 0, 255); website = URL_VALIDATOR.isValid(website) ? website : null; to.setWebsite(Salesforce.FACTORY.createAccountWebsite(website)); final String street = Strings.defaultIfBlank(address.getStreet(), ""); final String streetNumber = Strings.defaultIfBlank(address.getStreetNumber(), ""); final String additional = Strings.defaultIfBlank(address.getAdditional(), ""); final String formatted = String.format("%s %s\n%s", street, streetNumber, additional); final String trimmed = StringUtils.substring(formatted, 0, 255); to.setBillingStreet(Salesforce.FACTORY.createAccountBillingStreet(trimmed)); final String postalCode = StringUtils.substring(address.getPostalCode(), 0, 20); to.setBillingPostalCode(Salesforce.FACTORY.createAccountBillingPostalCode(postalCode)); final String city = StringUtils.substring(address.getCityName(), 0, 40); to.setBillingCity(Salesforce.FACTORY.createAccountBillingCity(city)); final String state = StringUtils.substring(address.getState(), 0, 20); to.setBillingState(Salesforce.FACTORY.createAccountBillingState(state)); final String country = StringUtils.substring(address.getCountryCode(), 0, 40); to.setBillingCountry(Salesforce.FACTORY.createAccountBillingCountry(country)); return to;/*from w w w . j a v a 2s .co m*/ }
From source file:com.bsi.summer.core.dao.PropertyFilter.java
/** * @param filterName ,???. //from w w w .jav a2 s . c o m * FILTER_LIKES_NAME_OR_LOGIN_NAME * * value "SYS_" ??? * * @param value . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); if (StringUtils.split(value, "-").length == 1) { this.matchValue = getValue(value); } else { this.matchValue = getValue(StringUtils.split(value, "-")[0]); this.matchBetweenValue = getValue(StringUtils.split(value, "-")[1]); } }
From source file:com.migo.utils.ScheduleJob.java
@Override protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException { ScheduleJobEntity scheduleJob = (ScheduleJobEntity) jobExecutionContext.getMergedJobDataMap() .get(ScheduleJobEntity.JOB_PARAM_KEY); //?spring bean ScheduleJobLogService scheduleJobLogService = (ScheduleJobLogService) SpringContextUtils .getBean("scheduleJobLogService"); //??/*from w w w .j a v a2 s. c om*/ ScheduleJobLogEntity log = new ScheduleJobLogEntity(); log.setJobId(scheduleJob.getJobId()); log.setBeanName(scheduleJob.getBeanName()); log.setMethodName(scheduleJob.getMethodName()); log.setParams(scheduleJob.getParams()); log.setCreateTime(new Date()); // long startTime = System.currentTimeMillis(); try { // logger.info("ID" + scheduleJob.getJobId()); ScheduleRunnable task = new ScheduleRunnable(scheduleJob.getBeanName(), scheduleJob.getMethodName(), scheduleJob.getParams()); Future<?> future = service.submit(task); future.get(); // long times = System.currentTimeMillis() - startTime; log.setTimes((int) times); //? 0? 1 log.setStatus(0); logger.info("ID" + scheduleJob.getJobId() + " " + times + ""); } catch (Exception e) { logger.error("ID" + scheduleJob.getJobId(), e); // long times = System.currentTimeMillis() - startTime; log.setTimes((int) times); //? 0? 1 log.setStatus(1); log.setError(StringUtils.substring(e.toString(), 0, 2000)); } finally { scheduleJobLogService.save(log); } }
From source file:gov.nih.nci.cabig.caaers2adeers.track.Tracker.java
public void process(Exchange exchange) throws Exception { try {//w w w .j a v a2 s . c o m //set the properties in the exchange log.debug("Logging with tracker, begin."); Map<String, Object> properties = exchange.getProperties(); String entity = (String) properties.get(ExchangePreProcessor.ENTITY_NAME); String operation = (String) properties.get(ExchangePreProcessor.OPERATION_NAME); String coorelationId = (String) properties.get(ExchangePreProcessor.CORRELATION_ID); Long begin = (Long) properties.get(ExchangePreProcessor.ENTRED_ON); long end = 0; String timeTookNotes = ""; if (coorelationId == null || stage == null || entity == null || operation == null) { throw new RuntimeException("Cannot log in database. Required fields are missing"); } if (begin != null && begin > 0) { end = System.currentTimeMillis() - begin; if (end > 1000) { timeTookNotes = "Took " + (end / 1000) + " seconds."; } else { timeTookNotes = "Took " + end + " milliseconds."; } } String status = ""; try { status = StringUtils .substring(XPathBuilder.xpath("//status/text()").evaluate(exchange, String.class), 0, 100); } catch (Exception ignore) { log.debug("Ignoring invalid status text from response XML", ignore); } String actualNotes = timeTookNotes + " " + notes + " " + status; IntegrationLog integrationLog = new IntegrationLog(coorelationId, stage, entity, operation, actualNotes); log.debug("creating new instance of IntegrationLog with [" + coorelationId + ", " + stage + ", " + entity + ", " + operation + ", " + actualNotes + "]"); IntegrationLogDao integrationLogDao = (IntegrationLogDao) exchange.getContext().getRegistry() .lookup("integrationLogDao"); captureLogDetails(exchange, integrationLog); captureLogMessage(exchange, integrationLog); integrationLogDao.save(integrationLog); if (log.isInfoEnabled() && StringUtils.isNotEmpty(timeTookNotes)) { log.info(coorelationId + " - " + entity + "#" + operation + " |" + stage + "|" + timeTookNotes); } } catch (Exception ex) { log.error("Error while tracking exchange", ex); } }
From source file:com.hangum.tadpole.sql.util.executer.ProcedureExecuterManager.java
/** * Is executed procedure?/*from w w w . j a va2s . c o m*/ * * @param procedureDAO * @param useDB * @return */ public boolean isExecuted(ProcedureFunctionDAO procedureDAO, UserDBDAO selectUseDB) { if (!isSupport()) { MessageDialog.openError(null, "Error", "Not Support database"); return false; } if (!procedureDAO.isValid()) { MessageDialog.openError(null, "Error", "Not valid this procedure."); return false; } if (DBDefine.getDBDefine(userDB) == DBDefine.MYSQL_DEFAULT) { double dbVersion = 0.0; try { SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB); DBInfoDAO dbInfo = (DBInfoDAO) sqlClient.queryForObject("findDBInfo"); //$NON-NLS-1$ dbVersion = Double.parseDouble(StringUtils.substring(dbInfo.getProductversion(), 0, 3)); if (dbVersion < 5.5) { MessageDialog.openError(null, "Error", "The current version does not support.\n\n5.5 or later is supported."); return false; } } catch (Exception e) { logger.error("find DB info", e); return false; } } try { ProcedureExecutor procedureExecutor = getExecuter(); procedureExecutor.getInParameters(); } catch (Exception e) { MessageDialog.openError(null, "Error", e.getMessage()); return false; } return true; }
From source file:com.cognifide.cq.cqsm.foundation.actions.allow.Allow.java
private ActionResult process(final Context context, boolean simulate) { ActionResult actionResult = new ActionResult(); try {/* www . j a va2 s . c o m*/ Authorizable authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); context.getSession().getNode(path); final PermissionActionHelper permissionActionHelper = new PermissionActionHelper( context.getValueFactory(), path, glob, permissions); LOGGER.info(String.format("Adding permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, StringUtils.isEmpty(glob) ? "" : ("glob = " + glob))); if (simulate) { permissionActionHelper.checkPermissions(context.getAccessControlManager()); } else { permissionActionHelper.applyPermissions(context.getAccessControlManager(), authorizable.getPrincipal(), true); } actionResult.logMessage("Added allow privilege for " + authorizable.getID() + " on " + path); if (permissions.contains("MODIFY")) { String preparedGlob = ""; if (!StringUtils.isBlank(glob)) { preparedGlob = glob; if (StringUtils.endsWith(glob, "*")) { preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*')); } } new Allow(path, preparedGlob + "*/jcr:content*", ignoreInexistingPaths, Collections.singletonList("MODIFY_PAGE")).process(context, simulate); } } catch (final PathNotFoundException e) { if (ignoreInexistingPaths) { actionResult.logWarning("Path " + path + " not found"); } else { actionResult.logError("Path " + path + " not found"); return actionResult; } } catch (RepositoryException | PermissionException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; }
From source file:com.haulmont.cuba.core.entity.SendingMessage.java
public void setCaption(String caption) { this.caption = StringUtils.substring(caption, 0, SendingMessage.CAPTION_LENGTH); }
From source file:de.cosmocode.palava.salesforce.sync.DefaultContactCopyFunction.java
@Override public Contact apply(ContactBase from) { final Contact to = Salesforce.FACTORY.createContact(); LOG.debug("Copying {} into {}", from, to); final String title = StringUtils.substring(from.getTitle(), 0, 40); to.setSalutation(Salesforce.FACTORY.createContactSalutation(title)); final String forename = StringUtils.substring(from.getForename(), 0, 40); to.setFirstName(Salesforce.FACTORY.createContactFirstName(forename)); String surname = from.getSurname(); surname = Strings.defaultIfBlank(surname, "Empty Surname"); surname = StringUtils.substring(surname, 0, 80); to.setLastName(Salesforce.FACTORY.createContactLastName(surname)); final AddressBase address = from.getAddress(); final String phone = StringUtils.substring(address.getPhone(), 0, 40); to.setPhone(Salesforce.FACTORY.createContactPhone(phone)); final String mobile = StringUtils.substring(address.getMobilePhone(), 0, 40); to.setPhone(Salesforce.FACTORY.createContactMobilePhone(mobile)); final String fax = StringUtils.substring(address.getFax(), 0, 40); to.setFax(Salesforce.FACTORY.createContactFax(fax)); String email = address.getEmail(); email = StringUtils.substring(email, 0, 80); email = EMAIL_VALIDATOR.isValid(email) ? email : null; to.setEmail(Salesforce.FACTORY.createContactEmail(email)); final String street = Strings.defaultIfBlank(address.getStreet(), ""); final String streetNumber = Strings.defaultIfBlank(address.getStreetNumber(), ""); final String additional = Strings.defaultIfBlank(address.getAdditional(), ""); final String formatted = String.format("%s %s\n%s", street, streetNumber, additional); final String trimmed = StringUtils.substring(formatted, 0, 255); to.setMailingStreet(Salesforce.FACTORY.createContactMailingStreet(trimmed)); final String postalCode = StringUtils.substring(address.getPostalCode(), 0, 20); to.setMailingPostalCode(Salesforce.FACTORY.createContactMailingPostalCode(postalCode)); final String city = StringUtils.substring(address.getCityName(), 0, 40); to.setMailingCity(Salesforce.FACTORY.createContactMailingCity(city)); final String state = StringUtils.substring(address.getState(), 0, 20); to.setMailingState(Salesforce.FACTORY.createContactMailingState(state)); final String country = StringUtils.substring(address.getCountryCode(), 0, 40); to.setMailingCountry(Salesforce.FACTORY.createContactMailingCountry(country)); return to;//from w w w. jav a 2 s . co m }