List of usage examples for org.apache.commons.lang StringUtils removeStart
public static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
From source file:com.egt.ejb.toolkit.ToolKitUtils.java
public static String getLowerCaseEnumOptionIdentifier(String string) { if (string == null) { return null; }//from w w w .j a v a2s .c om String s; s = STP.getIdentificadorSql(string); s = StringUtils.removeStart(s, "_"); s = StringUtils.removeEnd(s, "_"); return s.toLowerCase(); }
From source file:com.google.gdt.eclipse.designer.uibinder.model.util.EventHandlerProperty.java
/** * @return the existing or new {@link MethodDeclaration} for this event. *//*from ww w. ja v a 2 s .c o m*/ private MethodDeclaration createMethodDeclaration0() throws Exception { String name = NameSupport.ensureName(m_object); String eventTypeName = m_handler.getEventTypeName(); // prepare name of method String methodName; { String eventName = StringUtils.removeStart(m_handler.getMethodName(), "on"); String baseName = "on" + StringUtils.capitalize(name) + eventName; methodName = m_editor.getUniqueMethodName(baseName); } // add method String uiHandlerAnnotation = "@com.google.gwt.uibinder.client.UiHandler(\"" + name + "\")"; String header = "void " + methodName + "(" + eventTypeName + " event)"; MethodDeclaration method = m_editor.addMethodDeclaration(ImmutableList.<String>of(uiHandlerAnnotation), header, ImmutableList.<String>of(), new BodyDeclarationTarget(m_typeDeclaration, false)); // done return method; }
From source file:info.magnolia.module.admininterface.SaveHandlerImpl.java
/** * Update the links in a string returned by a rich text editor. If there are links to temporary files created due * the fckeditor upload mechanism those filese are written to the node. * @param node node saving to. used to save the files and fileinfod to * @param name the name of the field. used to make a subnode for the files * @param valueStr the value containing the links * @return the cleaned value/* w w w . j a v a2 s. co m*/ * @throws AccessDeniedException * @throws RepositoryException * @throws PathNotFoundException */ private String updateLinks(Content node, String name, String valueStr) throws AccessDeniedException, RepositoryException, PathNotFoundException { // process the images and uploaded files HierarchyManager hm = MgnlContext.getHierarchyManager(this.getRepository()); Pattern imagePattern = Pattern.compile("(<(a|img)[^>]+(href|src)[ ]*=[ ]*\")([^\"]*)(\"[^>]*>)"); Pattern uuidPattern = Pattern.compile(MgnlContext.getContextPath() + "/tmp/fckeditor/([^/]*)/[^\"]*"); Content filesNode = ContentUtil.getOrCreateContent(node, name + "_files", ItemType.CONTENTNODE); String pageName = StringUtils.substringAfterLast(this.getPath(), "/"); // adapt img urls Matcher srcMatcher = imagePattern.matcher(valueStr); StringBuffer res = new StringBuffer(); while (srcMatcher.find()) { String src = srcMatcher.group(4); // the editor creates relative links after moving an absolute path: ../../../ replace them src = StringUtils.replace(src, "../../../", MgnlContext.getContextPath() + "/"); String link = src; // process the tmporary uploaded files Matcher uuidMatcher = uuidPattern.matcher(src); if (uuidMatcher.find()) { String uuid = uuidMatcher.group(1); Document doc = FCKEditorTmpFiles.getDocument(uuid); String fileNodeName = Path.getUniqueLabel(hm, filesNode.getHandle(), "file"); SaveHandlerImpl.saveDocument(filesNode, doc, fileNodeName, "", ""); String subpath = StringUtils.removeStart(filesNode.getHandle(), this.getPath() + "/"); link = pageName + "/" + subpath + "/" + fileNodeName + "/" + doc.getFileNameWithExtension(); doc.delete(); try { FileUtils.deleteDirectory(new java.io.File(Path.getTempDirectory() + "/fckeditor/" + uuid)); } catch (IOException e) { log.error("can't delete tmp file [" + Path.getTempDirectory() + "/fckeditor/" + uuid + "]"); } } // make internal links relative else if (src.startsWith(MgnlContext.getContextPath())) { link = pageName + StringUtils.removeStart(src, MgnlContext.getContextPath() + this.getPath()); } // internal uuid links have a leading $ link = StringUtils.replace(link, "$", "\\$"); srcMatcher.appendReplacement(res, "$1" + link + "$5"); //$NON-NLS-1$ } srcMatcher.appendTail(res); valueStr = res.toString(); return valueStr; }
From source file:ips1ap101.web.fragments.FragmentoCabeza2.java
public String botonFavoritos2_action() { try {/*from w w w. j a v a 2 s. c o m*/ String requestContextPath = getFacesContext().getExternalContext().getRequestContextPath(); String aplicacion = StringUtils.removeStart(requestContextPath, "/"); AbstractPageBean paginaActual = ThreadContext.getPaginaActual(); String pagina = paginaActual.getClass().getSimpleName(); UsuarioAutenticado usuarioAutenticado = UsuarioAutenticadoCachingServiceLocator.getInstance(); Long usuario = usuarioAutenticado.getIdUsuario(); TLC.getAgenteSql().executeProcedure(DB.PAGINA_USUARIO_INSERT, new Object[] { aplicacion, pagina, usuario }); TLC.getBitacora() .info(ips1ap101.lib.base.bundle.BundleWebui.getString("favorito_agregado_exitosamente")); } catch (Exception ex) { TLC.getBitacora().error(ex); } return null; }
From source file:edu.mayo.cts2.framework.webapp.rest.controller.ValueSetDefinitionController.java
@RequestMapping(value = { PATH_VALUESETBYID + "/" + VALUE_SET_RESOLUTION_SHORT + "/" + ALL_WILDCARD, PATH_VALUESETBYID + "/" + VALUE_SET_RESOLUTION_SHORT }, method = RequestMethod.GET) public ModelAndView getValueSetDefinitionOfValueSetByTagRedirect(HttpServletRequest httpServletRequest, RestReadContext restReadContext, QueryControl queryControl, @PathVariable(VAR_VALUESETID) String valueSetName, @RequestParam(value = PARAM_TAG, defaultValue = DEFAULT_TAG) String tag, @RequestParam(value = "redirect", defaultValue = DEFAULT_REDIRECT) boolean redirect) { //TODO: Accept tag URIs here VersionTagReference tagReference = new VersionTagReference(tag); String valueSetDefinitionLocalId = this.tagResolver.getVersionNameFromTag( this.valueSetDefinitionReadService, ModelUtils.nameOrUriFromName(valueSetName), tagReference, this.resolveRestReadContext(restReadContext)); String contextPath = this.getUrlPathHelper().getContextPath(httpServletRequest); String requestUri = StringUtils.removeStart(this.getUrlPathHelper().getRequestUri(httpServletRequest), contextPath);//w w w . ja va 2 s .c o m requestUri = StringUtils.removeStart(requestUri, "/"); requestUri = StringUtils.replaceOnce(requestUri, VALUESET + "/" + valueSetName + "/", VALUESET + "/" + valueSetName + "/" + VALUESETDEFINITION_SHORT + "/" + valueSetDefinitionLocalId + "/"); if (redirect) { @SuppressWarnings("unchecked") Map<String, Object> parameters = new HashMap<String, Object>(httpServletRequest.getParameterMap()); parameters.remove(PARAM_REDIRECT); return new ModelAndView("redirect:" + "/" + requestUri + this.mapToQueryString(parameters)); } else { return new ModelAndView("forward:" + "/" + requestUri); } }
From source file:com.adobe.acs.commons.errorpagehandler.impl.ErrorPageHandlerImpl.java
/** * Find the JCR full path to the most appropriate Error Page. * * @param request/*from www. j ava2 s . c om*/ * @param errorResource * @return */ @Override @SuppressWarnings("squid:S3776") public String findErrorPage(SlingHttpServletRequest request, Resource errorResource) { if (!isEnabled()) { return null; } final String errorsPath = findErrorsPath(request, errorResource); Resource errorPage = null; if (StringUtils.isNotBlank(errorsPath)) { final ResourceResolver resourceResolver = errorResource.getResourceResolver(); final String errorPath = errorsPath + "/" + getErrorPageName(request); errorPage = getResource(resourceResolver, errorPath); if (errorPage == null && StringUtils.isNotBlank(errorsPath)) { log.trace( "No error-specific errorPage could be found, use the 'default' error errorPage for the Root content path"); errorPage = resourceResolver.resolve(errorsPath); } } String errorPagePath = null; if (errorPage == null || ResourceUtil.isNonExistingResource(errorPage)) { log.trace("no custom error page could be found"); if (this.hasSystemErrorPage()) { errorPagePath = this.getSystemErrorPagePath(); log.trace("using system error page [ {} ]", errorPagePath); } } else { errorPagePath = errorPage.getPath(); } if (errorImagesEnabled && this.isImageRequest(request)) { if (StringUtils.startsWith(this.errorImagePath, "/")) { // Absolute path return this.errorImagePath; } else if (StringUtils.isNotBlank(errorPagePath)) { // Selector or Relative path; compute path based off found error page if (StringUtils.startsWith(this.errorImagePath, ".")) { final String selectorErrorImagePath = errorPagePath + this.errorImagePath; log.debug("Using selector-based error image: {}", selectorErrorImagePath); return selectorErrorImagePath; } else { final String relativeErrorImagePath = errorPagePath + "/" + StringUtils.removeStart(this.errorImagePath, "/"); log.debug("Using relative path-based error image: {}", relativeErrorImagePath); return relativeErrorImagePath; } } else { log.warn("Error image path found, but no error page could be found so relative path cannot " + "be applied: {}", this.errorImagePath); } } else if (StringUtils.isNotBlank(errorPagePath)) { errorPagePath = StringUtils.stripToNull(applyExtension(errorPagePath)); log.debug("Using resolved error page: {}", errorPagePath); return errorPagePath; } else { log.debug("ACS AEM Commons Error Page Handler is enabled but mis-configured. A valid error image" + " handler nor a valid error page could be found."); } return null; }
From source file:edu.mayo.cts2.framework.webapp.rest.controller.AbstractMessageWrappingController.java
protected void setLocation(HttpServletResponse response, String location) { location = StringUtils.removeStart(location, "/"); response.setHeader("Location", location); }
From source file:com.sonicle.webtop.core.app.shiro.WTRealm.java
private String sanitizeImpersonateUsername(String username) { String s = StringUtils.removeStart(username, "admin!"); return StringUtils.removeStart(s, "admin$"); }
From source file:com.adobe.acs.tools.test_page_generator.impl.TestPageGeneratorServlet.java
private Object eval(final ScriptEngine scriptEngine, final Object value) { if (scriptEngine == null) { log.warn("ScriptEngine is null; cannot evaluate"); return value; } else if (value instanceof String[]) { final List<String> scripts = new ArrayList<String>(); final String[] values = (String[]) value; for (final String val : values) { scripts.add(String.valueOf(this.eval(scriptEngine, val))); }/*w w w .j a v a 2 s. com*/ return scripts.toArray(new String[scripts.size()]); } else if (!(value instanceof String)) { return value; } final String stringValue = StringUtils.stripToEmpty((String) value); String script; if (StringUtils.startsWith(stringValue, "{{") && StringUtils.endsWith(stringValue, "}}")) { script = StringUtils.removeStart(stringValue, "{{"); script = StringUtils.removeEnd(script, "}}"); script = StringUtils.stripToEmpty(script); try { return scriptEngine.eval(script); } catch (ScriptException e) { log.error("Could not evaluation the test page property ecma [ {} ]", script); } } return value; }
From source file:com.egt.ejb.toolkit.ToolKitUtils.java
public static String getCodigoFuncionAlterno(String codigoFuncion, String codigoDominio) { String alterno = StringUtils.trimToEmpty(codigoFuncion).toLowerCase(); String dominio = StringUtils.trimToEmpty(codigoDominio).toLowerCase(); alterno = StringUtils.removeStart(alterno, dominio); alterno = StringUtils.chomp(alterno, dominio); alterno = alterno.replace("_" + dominio + "_", "_"); alterno = StringUtils.removeStart(alterno, "_"); alterno = StringUtils.chomp(alterno, "_"); alterno = dominio + "_" + alterno; return alterno; }