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:org.springside.modules.orm.PropertyFilter.java
/** * @param filterName ,???. /*from ww w . java 2s .c o m*/ * eg. LIKES_NAME_OR_LOGIN_NAME * @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).getValue(); } 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); propertyNames = propertyNameStr.split(PropertyFilter.OR_SEPARATOR); this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass); }
From source file:org.talend.repository.ui.wizards.metadata.connection.database.DatabaseForm.java
private String getUppercaseNetezzaUrl(String url) { if (StringUtils.isBlank(url)) { return url; }//from www . j av a2 s . c o m String uppcaseUrl = url; int lastIndexOf = StringUtils.lastIndexOf(url, "/"); //$NON-NLS-1$ if (lastIndexOf > 0 && lastIndexOf < url.length() - 1) { String part1 = StringUtils.substring(url, 0, lastIndexOf + 1); String part2 = StringUtils.substring(url, lastIndexOf + 1); if (!StringUtils.isEmpty(part2)) { int indexOf = StringUtils.indexOf(part2, "?"); //$NON-NLS-1$ if (indexOf > -1) { String sid = StringUtils.substring(part2, 0, indexOf); part2 = StringUtils.upperCase(sid) + StringUtils.substring(part2, indexOf, part2.length()); } else { part2 = StringUtils.upperCase(part2); } uppcaseUrl = part1 + part2; } } return uppcaseUrl; }
From source file:org.talend.repository.ui.wizards.metadata.connection.database.DatabaseWizard.java
/** * uppercase the sid and url of Netezza connection. * // w w w . ja v a 2s . c om * @param netezzaConnection */ private void uppercaseNetezzaSidUrl(DatabaseConnection netezzaConnection) { if (netezzaConnection == null) { return; } netezzaConnection.setSID(StringUtils.upperCase(netezzaConnection.getSID())); String url = netezzaConnection.getURL(); if (StringUtils.isBlank(url)) { return; } int lastIndexOf = StringUtils.lastIndexOf(url, "/"); //$NON-NLS-1$ if (lastIndexOf > 0 && lastIndexOf < url.length() - 1) { String part1 = StringUtils.substring(url, 0, lastIndexOf + 1); String part2 = StringUtils.substring(url, lastIndexOf + 1); if (!StringUtils.isEmpty(part2)) { int indexOf = StringUtils.indexOf(part2, "?"); //$NON-NLS-1$ if (indexOf > -1) { String sid = StringUtils.substring(part2, 0, indexOf); part2 = StringUtils.upperCase(sid) + StringUtils.substring(part2, indexOf, part2.length()); } else { part2 = StringUtils.upperCase(part2); } netezzaConnection.setURL(part1 + part2); } } }
From source file:org.telscenter.sail.webapp.presentation.web.controllers.student.brainstorm.BrainstormUtils.java
public static Map<String, String> parseChoices(String choiceList) { Map<String, String> choiceMap = new LinkedHashMap<String, String>(); while (choiceList != null && choiceList != "" && StringUtils.contains(choiceList, "simpleChoice")) { choiceList = StringUtils.removeStart(choiceList, IDENTIFIER); String key = StringUtils.substring(choiceList, 0, StringUtils.indexOf(choiceList, "\"")); choiceList = StringUtils.removeStart(choiceList, key); choiceList = StringUtils.removeStart(choiceList, BEFORECONTENT); String content = StringUtils.substring(choiceList, 0, StringUtils.indexOf(choiceList, AFTERCONTENT)); choiceList = StringUtils.removeStart(choiceList, content); choiceList = StringUtils.removeStart(choiceList, AFTERCONTENT); choiceMap.put(key, replaceTags(content)); }/*from w ww .ja v a 2 s . com*/ return choiceMap; }
From source file:org.tinygroup.config.util.ConfigurationUtil.java
/** * ???/* www. j a v a 2 s.c o m*/ * * @param value * @param proMap * @return */ public static String replace(String value, Map<String, String> proMap) { Pattern pattern = Pattern.compile("(\\{[^\\}]*\\})"); Matcher matcher = pattern.matcher(value); int curpos = 0; StringBuilder buf = new StringBuilder(); while (matcher.find()) { buf.append(value.substring(curpos, matcher.start())); curpos = matcher.end(); String var = value.substring(matcher.start(), curpos); buf.append(proMap.get(StringUtils.substring(var, 1, var.length() - 1))); continue; } buf.append(value.substring(curpos)); return buf.toString(); }
From source file:org.tinygroup.springmvc.coc.impl.AbstractConventionHandlerMethodResolver.java
public Set<String> resolve() { final Set<String> urlList = new HashSet<String>();// for this handler String className = handlerType.getName(); // /*w w w .j av a2s. c o m*/ final StringBuilder uri = new StringBuilder("/"); int lastpos = className.indexOf("." + conventionHelper.getHandlerStyle()); int startpos = className.indexOf("web."); startpos += 5; String path = StringUtils.EMPTY; if (startpos < lastpos) { path = StringUtils.substring(className, startpos, lastpos); path = path.replace(".", "/"); uri.append(path).append("/"); } // uri-prefix. => /namespace/ String resourcesName = conventionHelper.getHandlerName(getHandlerType()); uri.append(resourcesName); ReflectionUtils.doWithMethods(getHandlerType(), new ReflectionUtils.MethodCallback() { public void doWith(Method method) { if (!qualify(method)) { return; } // method should be public. if (!Modifier.isPublic(method.getModifiers())) { return; } if (method.isAnnotationPresent(RequestMapping.class)) { return; } else if (method.isAnnotationPresent(InitBinder.class)) { return; } else if (method.isAnnotationPresent(ModelAttribute.class)) { return; } else { List<String> urls = doResolve(uri.toString(), method); if (!CollectionUtil.isEmpty(urls)) { for (String url : urls) { urlList.add(url); } } } } }, new MethodFilter() { // ==object.class public boolean matches(Method method) { return method.getDeclaringClass() != Object.class; } }); return urlList; }
From source file:org.unitedinternet.cosmo.dao.hibernate.EventLogDaoImpl.java
private void updateDisplayName(HibEventLogEntry hibEntry, ItemEntry entry) { Item item = entry.getItem();//from w w w.j a v a2 s . c o m String displayName = item.getDisplayName(); // handle case of "missing" displayName if (displayName == null && item instanceof NoteItem) { NoteItem note = (NoteItem) item; if (note.getModifies() != null) { displayName = note.getModifies().getDisplayName(); } } // limit to 255 chars hibEntry.setStrval1(StringUtils.substring(displayName, 0, 255)); }
From source file:org.unitedinternet.cosmo.model.hibernate.EntityConverter.java
/** * Sets calendar attributes./*from w w w . j a va 2 s .c o m*/ * @param note The note item. * @param event The event. */ private void setCalendarAttributes(NoteItem note, VEvent event) { // UID (only set if master) if (event.getUid() != null && note.getModifies() == null) { note.setIcalUid(event.getUid().getValue()); } // for now displayName is limited to 1024 chars if (event.getSummary() != null) { note.setDisplayName(StringUtils.substring(event.getSummary().getValue(), 0, 1024)); } if (event.getDescription() != null) { note.setBody(event.getDescription().getValue()); } // look for DTSTAMP if (event.getDateStamp() != null) { note.setClientModifiedDate(event.getDateStamp().getDate()); } // look for absolute VALARM VAlarm va = ICalendarUtils.getDisplayAlarm(event); if (va != null && va.getTrigger() != null) { Trigger trigger = va.getTrigger(); Date reminderTime = trigger.getDateTime(); if (reminderTime != null) { note.setReminderTime(reminderTime); } } // calculate triage status based on start date java.util.Date now = java.util.Calendar.getInstance().getTime(); Date eventStartDate = event.getStartDate() != null && event.getStartDate().getDate() != null ? event.getStartDate().getDate() : new Date(); boolean later = eventStartDate.after(now); int code = later ? TriageStatus.CODE_LATER : TriageStatus.CODE_DONE; TriageStatus triageStatus = note.getTriageStatus(); // initialize TriageStatus if not present if (triageStatus == null) { triageStatus = TriageStatusUtil.initialize(entityFactory.createTriageStatus()); note.setTriageStatus(triageStatus); } triageStatus.setCode(code); // check for X-OSAF-STARRED if ("TRUE".equals(ICalendarUtils.getXProperty(X_OSAF_STARRED, event))) { TaskStamp ts = StampUtils.getTaskStamp(note); if (ts == null) { note.addStamp(entityFactory.createTaskStamp()); } } }
From source file:org.unitedinternet.cosmo.model.hibernate.EntityConverter.java
/** * Sets calendar attributes./* w w w . j a v a 2s.c om*/ * @param note The note item. * @param task The task vToDo. */ private void setCalendarAttributes(NoteItem note, VToDo task) { // UID if (task.getUid() != null) { note.setIcalUid(task.getUid().getValue()); } // for now displayName is limited to 1024 chars if (task.getSummary() != null) { note.setDisplayName(StringUtils.substring(task.getSummary().getValue(), 0, 1024)); } if (task.getDescription() != null) { note.setBody(task.getDescription().getValue()); } // look for DTSTAMP if (task.getDateStamp() != null) { note.setClientModifiedDate(task.getDateStamp().getDate()); } // look for absolute VALARM VAlarm va = ICalendarUtils.getDisplayAlarm(task); if (va != null && va.getTrigger() != null) { Trigger trigger = va.getTrigger(); Date reminderTime = trigger.getDateTime(); if (reminderTime != null) { note.setReminderTime(reminderTime); } } // look for COMPLETED or STATUS:COMPLETED Completed completed = task.getDateCompleted(); Status status = task.getStatus(); TriageStatus ts = note.getTriageStatus(); // Initialize TriageStatus if necessary if (completed != null || Status.VTODO_COMPLETED.equals(status)) { if (ts == null) { ts = TriageStatusUtil.initialize(entityFactory.createTriageStatus()); note.setTriageStatus(ts); } // TriageStatus.code will be DONE note.getTriageStatus().setCode(TriageStatus.CODE_DONE); // TriageStatus.rank will be the COMPLETED date if present // or currentTime if (completed != null) { note.getTriageStatus().setRank(TriageStatusUtil.getRank(completed.getDate().getTime())); } else { note.getTriageStatus().setRank(TriageStatusUtil.getRank(System.currentTimeMillis())); } } // check for X-OSAF-STARRED if ("TRUE".equals(ICalendarUtils.getXProperty(X_OSAF_STARRED, task))) { TaskStamp taskStamp = StampUtils.getTaskStamp(note); if (taskStamp == null) { note.addStamp(entityFactory.createTaskStamp()); } } }
From source file:org.unitedinternet.cosmo.model.hibernate.EntityConverter.java
/** * Sets calendar attributes.// w ww .j av a 2s.c om * @param note The note item. * @param journal The VJournal. */ private void setCalendarAttributes(NoteItem note, VJournal journal) { // UID if (journal.getUid() != null) { note.setIcalUid(journal.getUid().getValue()); } // for now displayName is limited to 1024 chars if (journal.getSummary() != null) { note.setDisplayName(StringUtils.substring(journal.getSummary().getValue(), 0, 1024)); } if (journal.getDescription() != null) { note.setBody(journal.getDescription().getValue()); } // look for DTSTAMP if (journal.getDateStamp() != null) { note.setClientModifiedDate(journal.getDateStamp().getDate()); } }