List of usage examples for org.apache.commons.lang3 StringUtils substringBefore
public static String substringBefore(final String str, final String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.kuali.kra.iacuc.IacucProtocol.java
@Override public String getAmendedProtocolNumber() { if (isAmendment()) { return StringUtils.substringBefore(getProtocolNumber(), AMENDMENT_LETTER.toString()); } else if (isRenewal()) { return StringUtils.substringBefore(getProtocolNumber(), RENEWAL_LETTER.toString()); } else if (isContinuation()) { return StringUtils.substringBefore(getProtocolNumber(), CONTINUATION_LETTER.toString()); } else {//from ww w. jav a 2s. c om return null; } }
From source file:org.kuali.kra.protocol.ProtocolBase.java
/** * //from w ww . j ava 2s. c o m * If the protocol document is an amendment or renewal the parent protocol number is being returned. * (i.e. the protocol number of the protocol that is being amended or renewed). * * Null will be returned if the protocol is not an amendment or renewal. * * @return protocolNumber of the ProtocolBase that is being amended/renewed */ public String getAmendedProtocolNumber() { if (isAmendment()) { return StringUtils.substringBefore(getProtocolNumber(), AMENDMENT_LETTER.toString()); } else if (isRenewal()) { return StringUtils.substringBefore(getProtocolNumber(), RENEWAL_LETTER.toString()); } else { return null; } }
From source file:org.kuali.kra.protocol.specialreview.impl.ProtocolSpecialReviewServiceImplBase.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override// w w w .j av a2 s.c o m public void populateSpecialReview(SpecialReview specialReview) { String protocolNumber = specialReview.getProtocolNumber(); if (protocolNumber == null) { return; } String lastApprovedProtocolNumber = protocolNumber; if (StringUtils.contains(protocolNumber, AMENDMENT_KEY)) { lastApprovedProtocolNumber = StringUtils.substringBefore(protocolNumber, AMENDMENT_KEY); } else if (StringUtils.contains(protocolNumber, RENEWAL_KEY)) { lastApprovedProtocolNumber = StringUtils.substringBefore(protocolNumber, RENEWAL_KEY); } ProtocolBase protocol = getProtocolFinderDao().findCurrentProtocolByNumber(lastApprovedProtocolNumber); if (protocol != null) { setSpecialReviewApprovalTypeHook(specialReview); if (specialReview.getClass().equals(ProposalSpecialReview.class)) { ProposalSpecialReview psr = (ProposalSpecialReview) specialReview; DevelopmentProposal dp = getPropososalDevelopment(psr.getDevelopmentProposal().getProposalNumber()); if (dp != null && (StringUtils.equals(dp.getProposalStateTypeCode(), ProposalState.APPROVED_AND_SUBMITTED) || StringUtils.equals(dp.getProposalStateTypeCode(), ProposalState.DISAPPROVED) || StringUtils.equals(dp.getProposalStateTypeCode(), ProposalState.APPROVED_POST_SUBMISSION) || StringUtils.equals(dp.getProposalStateTypeCode(), ProposalState.DISAPPROVED_POST_SUBMISSION) || StringUtils.equals(dp.getProposalStateTypeCode(), ProposalState.APPROVAL_PENDING_SUBMITTED)) && specialReview.getProtocolStatus() != null) { // if the proposal is complete, do not get the fresh copy of the IRB status } else { specialReview.setProtocolStatus(protocol.getProtocolStatus().getDescription()); } } else { specialReview.setProtocolStatus(protocol.getProtocolStatus().getDescription()); } specialReview.setProtocolNumber(protocol.getProtocolNumber()); specialReview.setApplicationDate(protocol.getProtocolSubmission().getSubmissionDate()); specialReview.setApprovalDate(protocol.getLastApprovalDate() == null ? protocol.getApprovalDate() : protocol.getLastApprovalDate()); specialReview.setExpirationDate(protocol.getExpirationDate()); setProtocolExemptStudiesCheckListItemHook(protocol, specialReview); specialReview.setLinkedToProtocol(true); } }
From source file:org.languagetool.rules.spelling.morfologik.MorfologikMultiSpeller.java
private static List<byte[]> getLines(BufferedReader br) throws IOException { List<byte[]> lines = new ArrayList<>(); String line;//w w w . ja v a2 s . c o m while ((line = br.readLine()) != null) { if (!line.startsWith("#")) { lines.add(StringUtils.substringBefore(line, "#").trim().getBytes(UTF_8)); } } return lines; }
From source file:org.lazulite.boot.autoconfigure.core.utils.excel.ImportExcel.java
/** * ??//from w w w . j a va 2 s. co m * * @param cls * @param groups */ public <E> List<E> getDataList(Class<E> cls, int... groups) throws InstantiationException, IllegalAccessException { List<Object[]> annotationList = Lists.newArrayList(); // Get annotation field Field[] fs = cls.getDeclaredFields(); for (Field f : fs) { ExcelField ef = f.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, f }); break; } } } } else { annotationList.add(new Object[] { ef, f }); } } } // Get annotation method Method[] ms = cls.getDeclaredMethods(); for (Method m : ms) { ExcelField ef = m.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, m }); break; } } } } else { annotationList.add(new Object[] { ef, m }); } } } // Field sorting Collections.sort(annotationList, new Comparator<Object[]>() { public int compare(Object[] o1, Object[] o2) { return new Integer(((ExcelField) o1[0]).sort()).compareTo(new Integer(((ExcelField) o2[0]).sort())); } ; }); //log.debug("Import column count:"+annotationList.size()); // Get excel data List<E> dataList = Lists.newArrayList(); for (int i = this.getDataRowNum(); i < this.getLastDataRowNum(); i++) { E e = (E) cls.newInstance(); int column = 0; Row row = this.getRow(i); StringBuilder sb = new StringBuilder(); for (Object[] os : annotationList) { Object val = this.getCellValue(row, column++); if (val != null) { ExcelField ef = (ExcelField) os[0]; // Get param type and type cast Class<?> valType = Class.class; if (os[1] instanceof Field) { valType = ((Field) os[1]).getType(); } else if (os[1] instanceof Method) { Method method = ((Method) os[1]); if ("get".equals(method.getName().substring(0, 3))) { valType = method.getReturnType(); } else if ("set".equals(method.getName().substring(0, 3))) { valType = ((Method) os[1]).getParameterTypes()[0]; } } //log.debug("Import value type: ["+i+","+column+"] " + valType); try { if (valType == String.class) { String s = String.valueOf(val.toString()); if (StringUtils.endsWith(s, ".0")) { val = StringUtils.substringBefore(s, ".0"); } else { val = String.valueOf(val.toString()); } } else if (valType == Integer.class) { val = Double.valueOf(val.toString()).intValue(); } else if (valType == Long.class) { val = Double.valueOf(val.toString()).longValue(); } else if (valType == Double.class) { val = Double.valueOf(val.toString()); } else if (valType == Float.class) { val = Float.valueOf(val.toString()); } else if (valType == Date.class) { val = DateUtil.getJavaDate((Double) val); } else { if (ef.fieldType() != Class.class) { val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString()); } else { val = Class .forName(this.getClass().getName().replaceAll( this.getClass().getSimpleName(), "fieldtype." + valType.getSimpleName() + "Type")) .getMethod("getValue", String.class).invoke(null, val.toString()); } } } catch (Exception ex) { log.info("Get cell value [" + i + "," + column + "] error: " + ex.toString()); val = null; } // set entity value if (os[1] instanceof Field) { ReflectUtils.invokeSetter(e, ((Field) os[1]).getName(), val); } else if (os[1] instanceof Method) { String mthodName = ((Method) os[1]).getName(); if ("get".equals(mthodName.substring(0, 3))) { mthodName = "set" + StringUtils.substringAfter(mthodName, "get"); } ReflectUtils.invokeMethod(e, mthodName, new Class[] { valType }, new Object[] { val }); } } sb.append(val + ", "); } dataList.add(e); log.debug("Read success: [" + i + "] " + sb.toString()); } return dataList; }
From source file:org.lockss.plugin.FormUrlHelper.java
/** * convert from a unencoded string url This routine should almost never be * called because it is impossible to tell whether equal signs and ampersands * are part of the form parameters or being used as separators. Use * convertFromEncodedString instead./*from ww w . ja v a 2s . c o m*/ * * @param url * @return true if the url is valid */ public boolean convertFromString(String url) { // an invalid url if starts with ?, doesn't contain ? if (StringUtils.indexOf(url, "?") == -1 || StringUtils.indexOf(url, "?") == 0) { m_valid = false; return m_valid; } String prefix = StringUtils.substringBefore(url, "?"); setBaseUrl(prefix); String rest = StringUtils.substringAfter(url, "?"); String key; String value; if (logger.isDebug3()) logger.debug3("rest=" + rest); while (rest != null && rest.length() > 0) { if (logger.isDebug3()) logger.debug3("rest2=" + rest); if (StringUtils.indexOf(rest, "=") > 0) { key = StringUtils.substringBefore(rest, "="); rest = StringUtils.substringAfter(rest, "="); if (logger.isDebug3()) logger.debug3("rest3=" + rest); if (rest != null && StringUtils.indexOf(rest, "&") != -1) { value = StringUtils.substringBefore(rest, "&"); add(key, value); rest = StringUtils.substringAfter(rest, "&"); } else { // last value value = rest; add(key, value); rest = ""; } } else { //This indicates a form url missing the equals sign, // stop processing at this point m_valid = false; rest = ""; } } return m_valid; }
From source file:org.malaguna.cmdit.bbeans.SessionAbstractBean.java
@PostConstruct public void initUser() { login = getExternalContext().getRemoteUser(); if (login != null && !login.isEmpty()) { login = StringUtils.substringBefore(login, "@"); prepareUser();//from w w w . ja v a 2 s. c o m } }
From source file:org.mayocat.addons.EntityListAddonTransformer.java
public Optional<AddonFieldValueWebObject> toWebView(EntityData<?> entityData, AddonFieldDefinition definition, Object storedValue) {//w ww .j a v a 2 s.co m List<String> slugs = (List) storedValue; if (!definition.getProperties().containsKey("entityList.entityType")) { logger.warn("entityList.entityType property is mandatory for addon type entityList"); return Optional.absent(); } String type = (String) definition.getProperties().get("entityList.entityType"); if (!entityLoader.containsKey(type)) { logger.warn("No loader for entity type " + type); return Optional.absent(); } String builderHint = null; if (webContext.getTenant() == null) { builderHint = "global/" + type; } else { builderHint = type; } if (!getBuilders().containsKey(builderHint)) { logger.warn("No entity list addon web object buider for hint " + builderHint); return Optional.absent(); } EntityListAddonWebObjectBuilder builder = getBuilders().get(builderHint); EntityLoader loader = entityLoader.get(type); List<Entity> entities = Lists.newArrayList(); try { for (String slug : slugs) { Entity e; if (slug.indexOf('@') > 0 && webContext.getTenant() == null) { String tenantSlug = StringUtils.substringAfter(slug, "@"); String entitySlug = StringUtils.substringBefore(slug, "@"); e = loader.load(entitySlug, tenantSlug); } else { e = loader.load(slug); } entities.add(e); } List<EntityData<Entity>> data = dataLoader.load(entities, StandardOptions.LOCALIZE, AttachmentLoadingOptions.FEATURED_IMAGE_ONLY); List<Object> result = Lists.newArrayList(); for (EntityData<Entity> e : data) { result.add(builder.build(e)); } return Optional.of(new AddonFieldValueWebObject(result, buildDisplay(data))); } catch (Exception e) { logger.warn("Exception while trying to load entity", e.getMessage()); throw e; //return Optional.absent(); } }
From source file:org.mayocat.multitenancy.DefaultTenantResolver.java
@Override public Tenant resolve(String host, String path) { if (this.resolved.get() == null) { this.resolved.set(new HashMap<String, Tenant>()); }//from w w w.j av a 2 s .c om if (!this.resolved.get().containsKey(host)) { Tenant tenant = null; try { if (!this.configuration.isActivated()) { // Mono-tenant tenant = this.accountsService.findTenant(this.configuration.getDefaultTenantSlug()); if (tenant == null) { tenant = this.accountsService.createDefaultTenant(); } this.resolved.get().put(host, tenant); } else { // Multi-tenant if (path != null && path.startsWith("/tenant/")) { String tmp = StringUtils.substringAfter(path, "/tenant/"); String slug = StringUtils.substringBefore(tmp, "/"); tenant = this.accountsService.findTenant(slug); } if (tenant == null) { tenant = this.accountsService.findTenantByDefaultHost(host); if (tenant == null) { tenant = this.accountsService.findTenant(this.extractSlugFromHost(host)); if (tenant == null) { return null; } } } this.resolved.get().put(host, tenant); } } catch (EntityAlreadyExistsException e) { // Has been created in between ? this.logger.warn("Failed attempt at creating a tenant that already exists for host {}", host); } } logger.debug("Resolved tenant [{}] ", this.resolved.get().get(host)); return this.resolved.get().get(host); }
From source file:org.mayocat.multitenancy.DefaultTenantResolver.java
private String extractSlugFromHost(String host) { String rootDomain;// w ww . j a va 2s. co m String siteName = siteSettings.getWebDomainName().or(siteSettings.getDomainName()); if (Strings.emptyToNull(siteName) == null) { InternetDomainName domainName = InternetDomainName.from(host); if (domainName.hasPublicSuffix()) { // Domain is under a valid TLD, extract the TLD + first child rootDomain = domainName.topPrivateDomain().name(); } else if (host.indexOf(".") > 0 && host.indexOf(".") < host.length()) { // Otherwise, best guess : strip everything before the first dot. rootDomain = host.substring(host.indexOf(".") + 1); } else { rootDomain = host; } } else { rootDomain = StringUtils.substringBefore(siteSettings.getDomainName(), ":"); } if (host.indexOf("." + rootDomain) > 0) { return host.substring(0, host.indexOf("." + rootDomain)); } else { return host; } }