List of usage examples for org.apache.commons.lang3 StringUtils startsWith
public static boolean startsWith(final CharSequence str, final CharSequence prefix)
Check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:org.apache.sling.contextaware.config.impl.ConfigurationBuilderImpl.java
/** * Check the name.//from w w w . j ava 2s. c om * A name must not be null and relative. * @param name The name * @return {@code true} if it is valid */ private boolean isNameValid(final String name) { return !StringUtils.isBlank(name) && !StringUtils.startsWith(name, "/") && !StringUtils.contains(name, "../"); }
From source file:org.apache.sling.contextaware.config.impl.def.DefaultConfigurationPersistenceStrategy.java
private void replaceProperties(Resource resource, Map<String, Object> properties) { ModifiableValueMap modValueMap = resource.adaptTo(ModifiableValueMap.class); // remove all existing properties that do not have jcr: or sling: namespace for (String propertyName : new HashSet<>(modValueMap.keySet())) { if (StringUtils.startsWith(propertyName, "jcr:") || StringUtils.startsWith(propertyName, "sling:")) { continue; }//from w w w. j a v a 2 s . c o m modValueMap.remove(propertyName); } modValueMap.putAll(properties); }
From source file:org.apache.sling.nosql.couchbase.client.CouchbaseKeyTest.java
@Test public void testLongKey() { String key = CouchbaseKey.build("/long/key/" + StringUtils.repeat("/aaa", 500), PREFIX); assertTrue(StringUtils.startsWith(key, PREFIX + "/long/key/")); assertEquals(CouchbaseKey.MAX_KEY_LENGTH, key.length()); }
From source file:org.apache.sling.testing.mock.jcr.AbstractItem.java
protected String makeAbsolutePath(final String relativePath) throws RepositoryException { String absolutePath = relativePath; // ensure the path is absolute and normalized if (!StringUtils.startsWith(absolutePath, "/")) { absolutePath = getPath() + "/" + absolutePath; // NOPMD }/* w w w . j a v a 2 s. c o m*/ return ResourceUtil.normalize(absolutePath); }
From source file:org.apache.struts2.convention.DefaultResultMapBuilder.java
/** * Creates any result types from the resources available in the web application. This scans the * web application resources using the servlet context. * * @param actionClass The action class the results are being built for. * @param results The results map to put the result configs created into. * @param resultPath The calculated path to the resources. * @param resultPrefix The prefix for the result. This is usually <code>/resultPath/actionName</code>. * @param actionName The action name which is used only for logging in this implementation. * @param packageConfig The package configuration which is passed along in order to determine * @param resultsByExtension The map of extensions to result type configuration instances. */// ww w . ja v a2 s . c o m protected void createFromResources(Class<?> actionClass, Map<String, ResultConfig> results, final String resultPath, final String resultPrefix, final String actionName, PackageConfig packageConfig, Map<String, ResultTypeConfig> resultsByExtension) { if (LOG.isTraceEnabled()) { LOG.trace("Searching for results in the Servlet container at [#0]" + " with result prefix of [#1]", resultPath, resultPrefix); } // Build from web application using the ServletContext @SuppressWarnings("unchecked") Set<String> paths = servletContext.getResourcePaths(flatResultLayout ? resultPath : resultPrefix); if (paths != null) { for (String path : paths) { if (LOG.isTraceEnabled()) { LOG.trace("Processing resource path [#0]", path); } String fileName = StringUtils.substringAfterLast(path, "/"); if (StringUtils.isBlank(fileName) || StringUtils.startsWith(fileName, ".")) { if (LOG.isTraceEnabled()) LOG.trace("Ignoring file without name [#0]", path); continue; } else if (fileName.lastIndexOf(".") > 0) { String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); if (conventionsService.getResultTypesByExtension(packageConfig).get(suffix) == null) { if (LOG.isDebugEnabled()) LOG.debug("No result type defined for file suffix : [#0]. Ignoring file #1", suffix, fileName); continue; } } makeResults(actionClass, path, resultPrefix, results, packageConfig, resultsByExtension); } } // Building from the classpath String classPathLocation = resultPath.startsWith("/") ? resultPath.substring(1, resultPath.length()) : resultPath; if (LOG.isTraceEnabled()) { LOG.trace( "Searching for results in the class path at [#0]" + " with a result prefix of [#1] and action name [#2]", classPathLocation, resultPrefix, actionName); } ResourceFinder finder = new ResourceFinder(classPathLocation, getClassLoaderInterface()); try { Map<String, URL> matches = finder.getResourcesMap(""); if (matches != null) { Test<URL> resourceTest = getResourceTest(resultPath, actionName); for (Map.Entry<String, URL> entry : matches.entrySet()) { if (resourceTest.test(entry.getValue())) { if (LOG.isTraceEnabled()) { LOG.trace("Processing URL [#0]", entry.getKey()); } String urlStr = entry.getValue().toString(); int index = urlStr.lastIndexOf(resultPrefix); String path = urlStr.substring(index); makeResults(actionClass, path, resultPrefix, results, packageConfig, resultsByExtension); } } } } catch (IOException ex) { if (LOG.isErrorEnabled()) LOG.error("Unable to scan directory [#0] for results", ex, classPathLocation); } }
From source file:org.apache.unomi.plugins.baseplugin.conditions.PropertyConditionEvaluator.java
@Override public boolean eval(Condition condition, Item item, Map<String, Object> context, ConditionEvaluatorDispatcher dispatcher) { String op = (String) condition.getParameter("comparisonOperator"); String name = (String) condition.getParameter("propertyName"); String expectedValue = ConditionContextHelper.foldToASCII((String) condition.getParameter("propertyValue")); Object expectedValueInteger = condition.getParameter("propertyValueInteger"); Object expectedValueDate = condition.getParameter("propertyValueDate"); Object expectedValueDateExpr = condition.getParameter("propertyValueDateExpr"); Object actualValue;/*from w w w .j a v a2s . c o m*/ if (item instanceof Event && "eventType".equals(name)) { actualValue = ((Event) item).getEventType(); } else { try { long time = System.nanoTime(); //actualValue = beanUtilsBean.getPropertyUtils().getProperty(item, name); actualValue = getPropertyValue(item, name); time = System.nanoTime() - time; if (time > 5000000L) { logger.info("eval took {} ms for {} {}", time / 1000000L, item.getClass().getName(), name); } } catch (NullPointerException e) { // property not found actualValue = null; } catch (Exception e) { if (!(e instanceof OgnlException) || (!StringUtils.startsWith(e.getMessage(), "source is null for getProperty(null"))) { logger.warn("Error evaluating value for " + item.getClass().getName() + " " + name, e); } actualValue = null; } } if (actualValue instanceof String) { actualValue = ConditionContextHelper.foldToASCII((String) actualValue); } if (op == null) { return false; } else if (actualValue == null) { return op.equals("missing"); } else if (op.equals("exists")) { return true; } else if (op.equals("equals")) { if (actualValue instanceof Collection) { for (Object o : ((Collection<?>) actualValue)) { if (o instanceof String) { o = ConditionContextHelper.foldToASCII((String) o); } if (compare(o, expectedValue, expectedValueDate, expectedValueInteger, expectedValueDateExpr) == 0) { return true; } } return false; } return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger, expectedValueDateExpr) == 0; } else if (op.equals("notEquals")) { return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger, expectedValueDateExpr) != 0; } else if (op.equals("greaterThan")) { return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger, expectedValueDateExpr) > 0; } else if (op.equals("greaterThanOrEqualTo")) { return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger, expectedValueDateExpr) >= 0; } else if (op.equals("lessThan")) { return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger, expectedValueDateExpr) < 0; } else if (op.equals("lessThanOrEqualTo")) { return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger, expectedValueDateExpr) <= 0; } else if (op.equals("between")) { List<?> expectedValuesInteger = (List<?>) condition.getParameter("propertyValuesInteger"); List<?> expectedValuesDate = (List<?>) condition.getParameter("propertyValuesDate"); List<?> expectedValuesDateExpr = (List<?>) condition.getParameter("propertyValuesDateExpr"); return compare(actualValue, null, (expectedValuesDate != null && expectedValuesDate.size() >= 1) ? getDate(expectedValuesDate.get(0)) : null, (expectedValuesInteger != null && expectedValuesInteger.size() >= 1) ? (Integer) expectedValuesInteger.get(0) : null, (expectedValuesDateExpr != null && expectedValuesDateExpr.size() >= 1) ? (String) expectedValuesDateExpr.get(0) : null) >= 0 && compare(actualValue, null, (expectedValuesDate != null && expectedValuesDate.size() >= 2) ? getDate(expectedValuesDate.get(1)) : null, (expectedValuesInteger != null && expectedValuesInteger.size() >= 2) ? (Integer) expectedValuesInteger.get(1) : null, (expectedValuesDateExpr != null && expectedValuesDateExpr.size() >= 2) ? (String) expectedValuesDateExpr.get(1) : null) <= 0; } else if (op.equals("contains")) { return actualValue.toString().contains(expectedValue); } else if (op.equals("startsWith")) { return actualValue.toString().startsWith(expectedValue); } else if (op.equals("endsWith")) { return actualValue.toString().endsWith(expectedValue); } else if (op.equals("matchesRegex")) { return expectedValue != null && Pattern.compile(expectedValue).matcher(actualValue.toString()).matches(); } else if (op.equals("in") || op.equals("notIn") || op.equals("all")) { List<?> expectedValues = ConditionContextHelper .foldToASCII((List<?>) condition.getParameter("propertyValues")); List<?> expectedValuesInteger = (List<?>) condition.getParameter("propertyValuesInteger"); List<?> expectedValuesDate = (List<?>) condition.getParameter("propertyValuesDate"); List<?> expectedValuesDateExpr = (List<?>) condition.getParameter("propertyValuesDateExpr"); return compareMultivalue(actualValue, expectedValues, expectedValuesDate, expectedValuesInteger, expectedValuesDateExpr, op); } else if (op.equals("isDay") && expectedValueDate != null) { return yearMonthDayDateFormat.format(getDate(actualValue)) .equals(yearMonthDayDateFormat.format(getDate(expectedValueDate))); } else if (op.equals("isNotDay") && expectedValueDate != null) { return !yearMonthDayDateFormat.format(getDate(actualValue)) .equals(yearMonthDayDateFormat.format(getDate(expectedValueDate))); } return false; }
From source file:org.asqatasun.rules.domelement.DomElement.java
/** * /*from www. j a va 2 s .c o m*/ * @return the current element raw background color */ public String getBgColor() { String bgColor = getProperty(BG_COLOR_KEY); if (StringUtils.startsWith(bgColor, ALPHA_COLOR_KEY)) { float alpha = getAlpha(bgColor); if (alpha == 0f) { return "rgb(255; 255; 255)"; } else if (alpha == 1f) { return StringUtils.replace(bgColor, ", 0)", ")"); } } return bgColor; }
From source file:org.asqatasun.rules.domelement.DomElement.java
public String getDisplayableBgColor() { if (StringUtils.startsWith(getBgColor(), BACKGROUND_IMAGE_KEY)) { return StringUtils.substring(getBgColor(), getBgColor().indexOf(":") + 1, getBgColor().length()); }// w w w .ja v a 2s . c om return getBgColor(); }
From source file:org.asqatasun.rules.elementchecker.contrast.helper.ContrastHelper.java
/** * //from w w w . ja v a 2 s .co m * @param color * @return whether the color is testable, i.e defined as a rgb color */ public static boolean isColorTestable(final String color) { return !StringUtils.contains(color, BACKGROUND_IMAGE_KEY) && !StringUtils.contains(color, GRADIENT_KEY) && !StringUtils.contains(color, ALPHA_COLOR_KEY) && !StringUtils.equalsIgnoreCase(color, TRANSPARENT_KEY) && StringUtils.startsWith(color, RGB_COLOR_KEY); }
From source file:org.asqatasun.sebuilder.interpreter.TgStore.java
@Override public boolean run(TestRun ctx) { if (ctx instanceof TgTestRun && StringUtils.startsWith(ctx.string("variable"), ASQATASUN_GET_PAGE_VARIABLE)) { ctx.getLog().debug("Fire New Page From a Store"); ((TgTestRun) ctx).fireNewPage(ctx.string("variable")); return true; }//from w ww.j a v a 2 s.c o m return super.run(ctx); }