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:com.nestof.paraweather.utils.LocationConverter.java
/** * Returns the Decimal Degrees that corresponds to the DMS values entered. * Requires values in Degrees, Minutes, Seconds, and Direction * * @return String//from w w w . j a va 2 s .c o m */ public String toDecimalDegrees(String location) { degrees = StringUtils.substringBefore(location, "").trim(); minutes = StringUtils.substringBetween(location, "", "'").trim(); seconds = StringUtils.substringBetween(location, "'", "\"").trim(); direction = StringUtils.substringAfter(location, "\"").trim(); String returnString = null; Double dblDegree; Double dblMinutes; Double dblSeconds; Double decDegrees; String CompassDirection; dblDegree = Double.parseDouble(getDegrees()); dblMinutes = Double.parseDouble(getMinutes()); dblSeconds = Double.parseDouble(getSeconds()); CompassDirection = getDirection(); decDegrees = dblDegree + (dblMinutes / 60) + (dblSeconds / 3600); if (CompassDirection.equalsIgnoreCase("S")) decDegrees = decDegrees * -1; if (CompassDirection.equalsIgnoreCase("W")) decDegrees = decDegrees * -1; returnString = decDegrees.toString() + direction; return returnString; }
From source file:com.iorga.iraj.json.ObjectContextCaller.java
public ObjectContextCaller(final Class<?> currentClass, final String currentContextPath) throws SecurityException { final String firstContextPathPart = StringUtils.substringBefore(currentContextPath, "."); try {//from ww w.j av a 2 s .co m getter = currentClass.getMethod("get" + StringUtils.capitalize(firstContextPathPart)); } catch (final NoSuchMethodException e) { try { getter = currentClass.getMethod("is" + StringUtils.capitalize(firstContextPathPart)); } catch (final NoSuchMethodException e1) { throw new IllegalArgumentException("No getter for " + firstContextPathPart + " on " + currentClass); } } if (!firstContextPathPart.equals(currentContextPath)) { // the path is not finished to handle nextContextCaller = new ObjectContextCaller(getter.getReturnType(), StringUtils.substringAfter(currentContextPath, ".")); } else { nextContextCaller = null; } }
From source file:com.beto.test.securityinterceptor.security.UserPageRoleServiceImpl.java
@Override public List<SecPageRoleDef> findUrlByUrl(String url) throws Exception { List<SecPageRoleDef> pageRoles = null; try {/*from w w w . j ava 2 s.c o m*/ url = StringUtils.substringBefore(url, "?"); logger.debug("findUrlByUrl method is called..." + url); TypedQuery<SecPageDef> createQuery = em.createNamedQuery("SecPageDef.findByViewId", SecPageDef.class); createQuery.setParameter("viewId", url); pageRoles = createQuery.getSingleResult().getSecPageRoleDefList(); for (SecPageRoleDef pageRole : pageRoles) { logger.debug(pageRole.toString()); } } catch (NoResultException e) { // TODO: handle exception } return pageRoles; }
From source file:com.iorga.iraj.json.ContextParamsContextCaller.java
public ContextParamsContextCaller(final String elementName, final AnnotatedElement annotatedElement, final Class<?> declaringClass, final ContextParams contextParamsAnnotation) { final ContextPath contextPathAnnotation = annotatedElement.getAnnotation(ContextPath.class); // First we have to know what is the first context path part of the target annotated member final String nextPath; if (contextPathAnnotation != null) { // the context path is not null, let's take the first element as a key for the context map final String contextPath = contextPathAnnotation.value(); contextMapKey = StringUtils.substringBefore(contextPath, "."); nextPath = StringUtils.substringAfter(contextPath, "."); } else {/*w w w. j a va2 s . c o m*/ // No @ContextPath, let's take the elementName contextMapKey = elementName; nextPath = null; } // Now search the @ContextParam corresponding to the targetAnnotatedMember ContextCaller nextContextCaller = null; Type returnType = null; for (final ContextParam contextParam : contextParamsAnnotation.value()) { String contextName = contextParam.name(); final Class<?> contextClass = contextParam.value(); if (StringUtils.isBlank(contextName)) { contextName = StringUtils.uncapitalize(contextClass.getSimpleName()); } if (contextMapKey.equals(contextName)) { // we have our @ContextParam now let's try to know if there is a "nextContextCaller" if (StringUtils.isEmpty(nextPath)) { // finished to handle the path, there is no other caller nextContextCaller = null; returnType = TemplateUtils.getGenericType(contextParam); } else { nextContextCaller = new ObjectContextCaller(contextClass, nextPath); returnType = nextContextCaller.getReturnType(); } break; } } if (returnType == null) { throw new IllegalArgumentException( "Couln't find the @ContextParam corresponding to " + contextMapKey + " in " + declaringClass); } else { this.nextContextCaller = nextContextCaller; this.returnType = returnType; } }
From source file:com.ctrip.infosec.rule.converter.Ip2ProvinceCityConverter.java
@Override public void convert(PreActionEnums preAction, Map fieldMapping, RiskFact fact, String resultWrapper, boolean isAsync) throws Exception { PreActionParam[] fields = preAction.getFields(); String ipFieldName = (String) fieldMapping.get(fields[0].getParamName()); String ipFieldValue = valueAsString(fact.eventBody, ipFieldName); // prefix default value if (Strings.isNullOrEmpty(resultWrapper)) { resultWrapper = ipFieldName + "_IpArea"; }// ww w. j ava 2 s.co m // if (fact.eventBody.containsKey(resultWrapper)) { return; } // "8.8.8.8:80" ipFieldValue = StringUtils.trimToEmpty(ipFieldValue); ipFieldValue = StringUtils.removeStart(ipFieldValue, "\""); ipFieldValue = StringUtils.removeEnd(ipFieldValue, "\""); ipFieldValue = StringUtils.substringBefore(ipFieldValue, ":"); if (StringUtils.isNotBlank(ipFieldValue) && !"127.0.0.1".equals(ipFieldValue)) { // PropertyUtils.setNestedProperty(fact.eventBody, ipFieldName, ipFieldValue); Map params = ImmutableMap.of("ip", ipFieldValue); Map result = DataProxy.queryForMap(serviceName, operationName, params); if (result != null && !result.isEmpty()) { fact.eventBody.put(resultWrapper, result); } else { TraceLogger.traceLog("?. ip=" + ipFieldValue); } } }
From source file:de.blizzy.documentr.markdown.DocumentrLinkRenderer.java
@Override public Rendering render(WikiLinkNode node) { String text = node.getText(); String uri;/*from w ww . ja va 2s . co m*/ boolean noFollow = false; if (text.startsWith("#")) { //$NON-NLS-1$ text = text.substring(1).trim(); uri = "#" + Util.simplifyForUrl(text); //$NON-NLS-1$ } else { uri = StringUtils.substringBefore(text, " ").trim(); //$NON-NLS-1$ text = StringUtils.substringAfter(text, " "); //$NON-NLS-1$ String params = StringUtils.substringAfter(text, "|").trim(); //$NON-NLS-1$ text = StringUtils.substringBefore(text, "|"); //$NON-NLS-1$ if (uri.startsWith("=")) { //$NON-NLS-1$ if (StringUtils.isBlank(text)) { text = uri.substring(1); } uri = context.getAttachmentUri(uri.substring(1)); } else { if (StringUtils.isBlank(text)) { text = uri; } } text = text.trim(); if (params.equalsIgnoreCase("nofollow")) { //$NON-NLS-1$ noFollow = true; } } Rendering rendering = new Rendering(uri, text); if (noFollow) { rendering.withAttribute(Attribute.NO_FOLLOW); } return rendering; }
From source file:eu.chocolatejar.eclipse.plugin.cleaner.model.Artifact.java
/** * This constructor is not intendet to be used * /*from w w w. ja v a 2 s .c o m*/ * @param location * @param bundleSymbolicName * @param bundleVersion */ public Artifact(File location, String bundleSymbolicName, String bundleVersion) { this.location = location; this.bundleSymbolicName = StringUtils.substringBefore(bundleSymbolicName, ";"); this.bundleVersion = new Version(bundleVersion); if (StringUtils.isBlank(bundleSymbolicName)) { throw new IllegalArgumentException("Invalid bundle name for: " + location); } }
From source file:common.util.PropertyFilter.java
/** * @param filterName//from w w w .ja v a 2 s . c o m * @param value */ public PropertyFilter(final String filterName, final String value) { String matchTypeStr; String matchPattenCode = LikeMatchPatten.ALL.toString(); String matchTypeCode; String propertyTypeCode; if (filterName.contains("LIKE") && filterName.charAt(0) != 'L') { matchTypeStr = StringUtils.substringBefore(filterName, PARAM_PREFIX); matchPattenCode = StringUtils.substring(matchTypeStr, 0, 1); matchTypeCode = StringUtils.substring(matchTypeStr, 1, matchTypeStr.length() - 1); propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); } else { matchTypeStr = StringUtils.substringBefore(filterName, PARAM_PREFIX); matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); } try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); likeMatchPatten = Enum.valueOf(LikeMatchPatten.class, matchPattenCode); } catch (RuntimeException e) { throw new IllegalArgumentException("filter name: " + filterName + "Not prepared in accordance with rules, not get more types of property.", e); } try { propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException("filter name: " + filterName + "Not prepared in accordance with the rules, attribute value types can not be.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, PARAM_PREFIX); propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR); Validate.isTrue(propertyNames.length > 0, "filter name: " + filterName + "Not prepared in accordance with the rules, property names can not be."); this.propertyValue = ConvertUtils.convert(value, propertyType); }
From source file:com.snowstore.mercury.core.indicator.impl.CompositeHealthIndicator.java
public CompositeHealthIndicator(Set<HealthIndicator> indicators) { Map<String, HealthIndicator> indicatorMap = new LinkedHashMap<String, HealthIndicator>(); for (HealthIndicator healthIndicator : indicators) { indicatorMap.put(//from w w w.j a va 2s. c om StringUtils.substringBefore(healthIndicator.getClass().getSimpleName(), "Health").toLowerCase(), healthIndicator); } this.indicators = indicatorMap; }
From source file:com.neatresults.mgnltweaks.ui.field.TemplateIdConverter.java
@Override public String convertToModel(String path, Class<? extends String> targetType, Locale locale) throws ConversionException { // Null is required for the property to be removed if path is empty String res = null;/* w ww . j a v a 2 s. c om*/ if (StringUtils.isBlank(path)) { return res; } String id = StringUtils.substringBefore(StringUtils.removeStart(path, "/modules/"), "/"); String template = StringUtils.substringAfter(path, "/templates/"); res = id + ":" + template; return res; }