List of usage examples for org.apache.commons.lang3 StringUtils removeStart
public static String removeStart(final String str, final String remove)
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null .
From source file:org.apache.sling.resourcemerger.impl.MergedResourceProvider.java
/** * Gets the relative path out of merge root path * * @param path Absolute path/* w w w.ja v a2 s.co m*/ * @return Relative path */ private String getRelativePath(String path) { return StringUtils.removeStart(path, mergeRootPath); }
From source file:org.apache.struts.beanvalidation.validation.interceptor.BeanValidationInterceptor.java
protected ValidationError buildBeanValidationError(ConstraintViolation<Object> violation, String message) { if (violation.getPropertyPath().iterator().next().getName() != null) { String fieldName = violation.getPropertyPath().toString(); String finalMessage = StringUtils.removeStart(message, fieldName + ValidatorConstants.FIELD_SEPERATOR); return new ValidationError(fieldName, finalMessage); }//from www. j a v a2 s . c o m return null; }
From source file:org.apache.struts2.convention.DefaultClassFinder.java
private List<String> jar(JarInputStream jarStream) throws IOException { List<String> classNames = new ArrayList<>(); JarEntry entry;//from w w w .j a v a2 s .co m while ((entry = jarStream.getNextJarEntry()) != null) { if (entry.isDirectory() || !entry.getName().endsWith(".class")) { continue; } String className = entry.getName(); className = className.replaceFirst(".class$", ""); //war files are treated as .jar files, so takeout WEB-INF/classes className = StringUtils.removeStart(className, "WEB-INF/classes/"); className = className.replace('/', '.'); classNames.add(className); } return classNames; }
From source file:org.apache.struts2.EmbeddedJSPResult.java
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { JSPRuntime.handle(StringUtils.removeStart(finalLocation, "/")); }
From source file:org.apache.struts2.jasper.JspCompilationContext.java
/** * Gets a resource as a stream, relative to the meanings of this * context's implementation./* w w w. j a v a 2s . c om*/ * @return a null if the resource cannot be found or represented * as an InputStream. */ public java.io.InputStream getResourceAsStream(String res) { try { return classLoaderInterface.getResourceAsStream(canonicalURI(StringUtils.removeStart(res, "/"))); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.apache.struts2.jasper.JspCompilationContext.java
public URL getResource(String res) throws MalformedURLException { return classLoaderInterface.getResource(canonicalURI(StringUtils.removeStart(res, "/"))); }
From source file:org.apache.struts2.oval.interceptor.OValValidationInterceptor.java
/** * Get field name and message, used to add the validation error to fieldErrors *///from w w w. j a va 2s . co m protected ValidationError buildValidationError(ConstraintViolation violation, String message) { OValContext context = violation.getContext(); if (context instanceof FieldContext) { Field field = ((FieldContext) context).getField(); String className = field.getDeclaringClass().getName(); //the default OVal message shows the field name as ActionClass.fieldName String finalMessage = StringUtils.removeStart(message, className + "."); return new ValidationError(field.getName(), finalMessage); } else if (context instanceof MethodReturnValueContext) { Method method = ((MethodReturnValueContext) context).getMethod(); String className = method.getDeclaringClass().getName(); String methodName = method.getName(); //the default OVal message shows the field name as ActionClass.fieldName String finalMessage = StringUtils.removeStart(message, className + "."); String fieldName = null; if (methodName.startsWith("get")) { fieldName = StringUtils.uncapitalize(StringUtils.removeStart(methodName, "get")); } else if (methodName.startsWith("is")) { fieldName = StringUtils.uncapitalize(StringUtils.removeStart(methodName, "is")); } //the result will have the full method name, like "getName()", replace it by "name" (obnly if it is a field) if (fieldName != null) finalMessage = finalMessage.replaceAll(methodName + "\\(.*?\\)", fieldName); return new ValidationError(StringUtils.defaultString(fieldName, methodName), finalMessage); } return new ValidationError(violation.getCheckName(), message); }
From source file:org.awesomeagile.webapp.controller.HackpadControllerTest.java
@Test public void testCreateNewHackpadSuccess() throws Exception { User user = createUser().setPrimaryEmail("user@domain.com"); CreatedDocument document = controller.createNewHackpad(new AwesomeAgileSocialUser(user, ImmutableSet.of()), DocumentType.DEFINITION_OF_DONE.name()); assertNotNull(document);/* w ww. j ava2 s.c o m*/ String padId = StringUtils.removeStart(document.getUrl(), BASE_URL); String content = hackpadClient.getContentByPadId().get(new PadIdentity(padId)); assertNotNull(content); assertEquals(content, "<html><body>New and shiny document</body></html>"); Document expectedDocument = new Document().setUrl(document.getUrl()) .setDocumentType(DocumentType.DEFINITION_OF_DONE).setUser(user); verify(documentRepository).save(expectedDocument); }
From source file:org.awesomeagile.webapp.controller.HackpadControllerTest.java
@Test public void testCreateNewHackpadExistingDocument() throws Exception { User user = createUser().setPrimaryEmail("user@domain.com"); // Pre-create a document of the type 'Definition of ready' PadIdentity originalPadIdentity = hackpadClient.createHackpad("title"); when(documentRepository.findAllByUserId(user.getId())) .thenReturn(ImmutableList.of(new Document().setDocumentType(DocumentType.DEFINITION_OF_DONE) .setUrl(hackpadClient.fullUrl(originalPadIdentity.getPadId())))); CreatedDocument document = controller.createNewHackpad(new AwesomeAgileSocialUser(user, ImmutableSet.of()), DocumentType.DEFINITION_OF_DONE.name()); assertNotNull(document);//from ww w .j a v a2 s. co m assertEquals(2, hackpadClient.getContentByPadId().size()); String returnedPadId = StringUtils.removeStart(document.getUrl(), BASE_URL); assertEquals(originalPadIdentity.getPadId(), returnedPadId); verify(documentRepository, never()).save(any(Document.class)); }
From source file:org.blockartistry.mod.Restructured.assets.Assets.java
private static void processEntry(final ConfigCategory p, final ConfigCategory cc, final List<ChestGenHooks> list) { String chestHookName = null;//from w ww.jav a 2 s.c o m if (p == null || cc.getName().startsWith("^")) chestHookName = StringUtils.removeStart(cc.getName(), "^"); else chestHookName = p.getName() + "." + cc.getName(); for (final Entry<String, Property> item : cc.getValues().entrySet()) { final ItemStack stack = ItemStackHelper.getItemStack(item.getKey()); if (stack == null || stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { ModLog.warn("Invalid item: %s", item.getKey()); continue; } try { final String values = item.getValue().getString(); final String[] parms = values.split(","); if (parms.length == 3) { final int min = Integer.valueOf(parms[0]); final int max = Integer.valueOf(parms[1]); final int weight = Integer.valueOf(parms[2]); ChestGenHooks.addItem(chestHookName, new WeightedRandomChestContent(stack, min, max, weight)); } else { ModLog.warn("Invalid number of values in parameter string: %s", values); } } catch (final Exception e) { ModLog.error("Unable to parse chest entry", e); } } list.add(ChestGenHooks.getInfo(chestHookName)); ModLog.info("Loaded chest loot table '%s'", chestHookName); }