List of usage examples for org.apache.commons.lang StringUtils replace
public static String replace(String text, String searchString, String replacement)
Replaces all occurrences of a String within another String.
From source file:com.cognifide.cq.cqsm.api.history.Entry.java
public String getExecutionResultFileName() { return EXECUTION + "-" + StringUtils.replace(fileName, ".cqsm", ".txt"); }
From source file:edu.mayo.cts2.framework.plugin.service.lexevs.naming.VersionNameConverter.java
public String unescapeVersion(String version) { return StringUtils.replace(version, SEPARATOR_ENCODE, SEPARATOR); }
From source file:gool.generator.android.AndroidCodePrinter.java
@Override public List<File> print(ClassDef pclass) throws FileNotFoundException { /*/* w w w . j a v a 2s . c o m*/ * As the implementation of Android necessitates that an additional file * "Activity" be created if the class contains the main method this * method is overridden to check for this */ String code = pclass.getCode(); List<File> result = new ArrayList<File>(); // file separator is just a slash in Unix // so the second argument to File() is just the directory // that corresponds to the package name // the first argument is the default output directory of the platform // so the directory name ends up being something like // GOOLOUPTUTTARGET/pack/age File dir = new File(getOutputDir().getAbsolutePath(), StringUtils.replace(pclass.getPackageName(), ".", File.separator)); // Typically the outputdir was created before, but not the package // subdirs dir.mkdirs(); // Create the file for the class, fill it in, close it File classFile = new File(dir, getFileName(pclass.getName())); PrintWriter writer = new PrintWriter(classFile); writer.println(code); writer.close(); /* * This part checks whether the class contains a main method/entry point * as well as creating the class that will be equivalent to sysOut. */ if (pclass.isMainClass()) { // Check if class contains main method and // if yes create activity class as well /** * As standard each .java file with a main method will have a * corresponding *Activity.java file */ File activityFile = new File(dir, getFileName(pclass.getName()).replace(".java", "Activity.java")); writer = new PrintWriter(activityFile); String activityClassCode = processTemplate("activity.vm", pclass); writer.println(activityClassCode); writer.close(); // Put the generated class into the result list result.add(activityFile); /* * After this it checks whether a PrintOut class has been made yet * and if not creates it. The reason why it is done here is because * most of the time there will only be one main class and this step * won't be repeated Unnecessarily */ File printOutFile = new File(dir, "PrintOut.java"); if (!printOutFile.exists()) { writer = new PrintWriter(printOutFile); String printOutFileCode = processTemplate("printout.vm", pclass); writer.println(printOutFileCode); writer.close(); // Put the generated class into the result list result.add(printOutFile); } } // Remember that you did the generation for this one abstract GOOL class printedClasses.add(pclass); // Put the generated class into the result list result.add(classFile); // Go through the dependencies // If they are abstract GOOL classes and have not been generated, do // that // And add the generated classes into the result list for (Dependency dependency : pclass.getDependencies()) { if (!printedClasses.contains(dependency) && dependency instanceof ClassDef) { result.addAll(print((ClassDef) dependency)); } } return result; }
From source file:com.vangent.hieos.authutil.ldap.LDAPAuthenticationHandler.java
/** * * @param creds// www. jav a2 s .c o m * @return * @throws AuthUtilException */ @Override public AuthenticationContext authenticate(Credentials creds) throws AuthUtilException { AuthenticationContext authnCtx = new AuthenticationContext(); this.configure(creds.getAuthDomainTypeKey()); LDAPClient ldapClient = null; try { ldapClient = new LDAPClient(this.ldapURL); } catch (NamingException e) { log.error("Error accessing LDAP.", e); throw new AuthUtilException("Error accessing LDAP." + e.getMessage()); } try { boolean status = false; String username = ""; if (creds != null) { username = creds.getUserId(); if (StringUtils.isNotBlank(this.userNameFormat)) { username = StringUtils.replace(this.userNameFormat, USERNAME_REPLACE_STRING, username); } // authenticate status = ldapClient.bind(username, creds.getPassword()); } if (status == true) { authnCtx.setStatus(AuthenticationContext.Status.SUCCESS); if (log.isInfoEnabled()) { log.info("LDAPAuthenticationHandler - User, " + username + ", authenticated."); } // get attributes from LDAP authnCtx.setUserProfile(getUserProfile(ldapClient, creds)); } else { authnCtx.setStatus(AuthenticationContext.Status.FAILURE); if (log.isInfoEnabled()) { log.info("LDAPAuthenticationHandler - User, " + username + ", could not be authenticated."); } } } finally { // disconnect, release resources!!!! if (ldapClient != null) { ldapClient.unbind(); } } return authnCtx; }
From source file:com.voa.weixin.task.Task.java
/** * ?access_token//from ww w . j av a 2s . c o m */ public void changeToken() { if (StringUtils.contains(url, "ACCESS_TOKEN")) { url = StringUtils.replace(url, "ACCESS_TOKEN", Carp.token); } else { String oldToken = StringUtils.substringAfter(url, "access_token="); if (StringUtils.contains(oldToken, "&")) { oldToken = StringUtils.substringBetween(url, "access_token=", "&"); } url = StringUtils.replace(url, oldToken, Carp.token); } }
From source file:ams.fwk.customtag.AmsUploadTag.java
/** * @return int//from w w w . j ava 2 s . com * @throws JspException */ public int doEndTag() throws JspException { try { List uploads = Collections.EMPTY_LIST; if (fileSeqNo != null && fileSeqNo.trim().length() > 0) { uploads = getUploads(); } JspWriter out = pageContext.getOut(); out.print(listOpen); int count = 0; for (Iterator all = uploads.iterator(); all.hasNext();) { Map each = (Map) all.next(); if ("N/A".equals(typeId) || typeId.equals(each.get("TYPE_ID"))) { String temp = StringUtils.replace(listItem, "$filename$", (String) each.get("FILE_NAME")); temp = StringUtils.replace(temp, "$max$", "" + max); temp = StringUtils.replace(temp, "$typeId$", typeId); temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID")); temp = StringUtils.replace(temp, "$filepath$", StringEscapeUtils.escapeJavaScript((String) each.get("FILE_PATH"))); out.print(temp); count++; } } if (max > count) { String requiredTemp = ""; String temp = ""; if ("Y".equals(isRequired)) { requiredTemp = StringUtils.replace(requiredTag, "$requiredMsg$", StringUtils.isEmpty(requiredMsg) ? "" : requiredMsg); temp = StringUtils.replace(fileItem, "$requiredTag$", "" + requiredTemp); } else { temp = StringUtils.replace(fileItem, "$requiredTag$", "" + ""); } temp = StringUtils.replace(temp, "$max$", "" + max); temp = StringUtils.replace(temp, "$typeId$", typeId); if ("Y".equals(eachSeqNoFlag)) { temp += StringUtils.replace(hiddenTag, "$id$", "eachSeqNoFlag"); temp = StringUtils.replace(temp, "$name$", "eachSeqNoFlag"); temp = StringUtils.replace(temp, "$value$", "" + "Y"); } out.print(temp); } out.print(listClose); return EVAL_PAGE; } catch (IOException e) { throw new JspException(e); } finally { fileSeqNo = null; typeId = "N/A"; max = 1; } }
From source file:com.hs.mail.imap.dao.AbstractDao.java
protected static String escape(String param) { return StringUtils.replace(StringUtils.replace(param, "_", "\\_"), "%", "\\%"); }
From source file:com.pedra.storefront.filters.UrlEncoderFilter.java
@Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { if (LOG.isDebugEnabled()) { LOG.debug(" The incoming URL : [" + request.getRequestURL().toString() + "]"); }/* w ww . j a v a 2s. c om*/ final List<UrlEncoderData> urlEncodingAttributes = getUrlEncoderFacade().variablesForUrlEncoding(); if (urlEncodingAttributes != null && !urlEncodingAttributes.isEmpty()) { final HttpSession session = request.getSession(false); final UrlEncoderPatternData patternData = getUrlEncoderFacade().patternForUrlEncoding( request.getRequestURL().toString(), request.getContextPath(), (session != null && session.isNew())); final String patternBeforeProcessing = getSessionService() .getAttribute(WebConstants.URL_ENCODING_ATTRIBUTES); final String pattern = "/" + patternData.getPattern(); if (!StringUtils.equalsIgnoreCase(patternBeforeProcessing, pattern)) { if (patternData.isRedirectRequired()) { String redirectUrl = StringUtils.replace(request.getRequestURL().toString(), patternBeforeProcessing, pattern); final String queryString = request.getQueryString(); if (StringUtils.isNotBlank(queryString)) { redirectUrl = redirectUrl + "?" + queryString; } response.sendRedirect(redirectUrl); } else { getUrlEncoderFacade().updateUrlEncodingData(); } } getSessionService().setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern); final UrlEncodeHttpRequestWrapper wrappedRequest = new UrlEncodeHttpRequestWrapper(request, patternData.getPattern()); wrappedRequest.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern); wrappedRequest.setAttribute("originalContextPath", request.getContextPath()); if (LOG.isDebugEnabled()) { LOG.debug("ContextPath=[" + wrappedRequest.getContextPath() + "]" + " Servlet Path= [" + wrappedRequest.getServletPath() + "]" + " Request Url= [" + wrappedRequest.getRequestURL() + "]"); } filterChain.doFilter(wrappedRequest, response); } else { if (LOG.isDebugEnabled()) { LOG.debug(" No URL attributes defined"); } request.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, ""); filterChain.doFilter(request, response); } }
From source file:de.minehattan.chatter.Chatter.java
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerJoin(PlayerJoinEvent event) { event.setJoinMessage(replaceColorCodes(StringUtils.replace( event.getPlayer().hasPlayedBefore() ? config.getString("messages.onJoin") : config.getString("messages.onFirstJoin"), "%player", event.getPlayer().getDisplayName()))); }
From source file:com.haulmont.cuba.web.gui.components.WebComponentsHelper.java
public static Resource getResource(String resURL) { if (StringUtils.isEmpty(resURL)) return null; if (resURL.startsWith("file:")) { return new FileResource(new File(resURL.substring("file:".length()))); } else if (resURL.startsWith("jar:")) { return new ClassResource(resURL.substring("jar:".length())); } else if (resURL.startsWith("theme:")) { String resourceId = resURL.substring("theme:".length()); Configuration configuration = AppBeans.get(Configuration.NAME); WebConfig webConfig = configuration.getConfig(WebConfig.class); if (webConfig.getUseFontIcons()) { String fontIcon;// w ww . j ava 2 s. c om ThemeConstants themeConstants = App.getInstance().getThemeConstants(); String iconKey = "cuba.web." + StringUtils.replace(resourceId, "/", "."); fontIcon = themeConstants.get(iconKey); try { Resource resource = getFontIconResource(fontIcon); if (resource != null) { return resource; } } catch (NoSuchFieldException | IllegalAccessException e) { LoggerFactory.getLogger(WebComponentsHelper.class).warn("Unable to use font icon " + fontIcon); } } return new VersionedThemeResource(resourceId); } else if (resURL.contains("icon:")) { try { return getFontIconResource(resURL); } catch (NoSuchFieldException | IllegalAccessException e) { LoggerFactory.getLogger(WebComponentsHelper.class).warn("Unable to use font icon " + resURL); } return null; } else { return new VersionedThemeResource(resURL); } }