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.acc.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 o m final List<UrlEncoderData> urlEncodingAttributes = getUrlEncoderFacade().variablesForUrlEncoding(); if (urlEncodingAttributes != null && !urlEncodingAttributes.isEmpty()) { final HttpSession session = request.getSession(false); final UrlEncoderPatternData patternData = getUrlEncoderFacade().patternForUrlEncoding( request.getRequestURI().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", StringUtils.isBlank(request.getContextPath()) ? "/" : 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:com.broadwave.android.brut.androlib.res.data.ResResSpec.java
public String getName() { return StringUtils.replace(mName, "\"", "q"); }
From source file:com.prowidesoftware.swift.model.field.Field35BTest.java
@Test public void testGetValue() { Field35B f = new Field35B(); String v = "ISIN HELLO\nAAAA\nBBBB\nCCCC\nDDDD"; f = new Field35B(v); assertEquals(StringUtils.replace(v, "\n", FINWriterVisitor.SWIFT_EOL), f.getValue()); }
From source file:gov.nih.nci.caIMAGE.util.SafeHTMLUtil.java
public static String cleanWithSlash(String s) { String clean = Translate.decode(s).replace("<", "").replace(">", ""); clean = StringUtils.replace(clean, "script", ""); clean = StringUtils.replace(clean, "%27", ""); clean = StringUtils.replace(clean, "%", ""); clean = StringUtils.replace(clean, "#", ""); clean = StringUtils.replace(clean, ";", ""); clean = StringUtils.replace(clean, "'", ""); clean = StringUtils.replace(clean, "\"", ""); clean = StringUtils.replace(clean, "$", ""); clean = StringUtils.replace(clean, "&", ""); clean = StringUtils.replace(clean, "(", ""); clean = StringUtils.replace(clean, ")", ""); clean = StringUtils.replace(clean, "\\", ""); clean = StringUtils.replace(clean, "&", ""); clean = StringUtils.replace(clean, "=", ""); clean = StringUtils.replace(clean, "quot", ""); clean = StringUtils.replace(clean, "javascript", ""); clean = StringUtils.replace(clean, "alert", "cleaned"); clean = StringUtils.replace(clean, "CR", ""); clean = StringUtils.replace(clean, "LF", ""); clean = StringUtils.replace(clean, "<", ""); clean = StringUtils.replace(clean, ">", ""); if (clean.length() == 0) { clean = "empty"; }/*from w w w .j a va2 s. c om*/ return clean; }
From source file:com.cognifide.cq.cqsm.core.servlets.ScriptDownloadServlet.java
@Override protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { String fileName = request.getParameter("filename"); String filePath = request.getParameter("filepath"); String mode = request.getParameter("mode"); try {/* ww w. j a v a2s . c o m*/ final ResourceResolver resourceResolver = request.getResourceResolver(); final Session session = resourceResolver.adaptTo(Session.class); if (!("view").equals(mode)) { response.setContentType("application/octet-stream"); // Your content type response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8")); } String path = StringUtils.replace(filePath, "_jcr_content", "jcr:content"); Node jcrContent = session.getNode(path + "/jcr:content"); InputStream input = jcrContent.getProperty("jcr:data").getBinary().getStream(); session.save(); int read; byte[] bytes = new byte[BYTES_DOWNLOAD]; OutputStream os = response.getOutputStream(); while ((read = input.read(bytes)) != -1) { os.write(bytes, 0, read); } input.close(); os.flush(); os.close(); } catch (RepositoryException e) { LOGGER.error(e.getMessage(), e); response.sendRedirect("/etc/cqsm.html"); // response.sendError(500); } }
From source file:com.ewcms.publication.freemarker.directive.PositionDirectiveTest.java
@Test public void testLoopTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("position_loop.html")); Map<String, Object> params = new HashMap<String, Object>(); params.put(GlobalVariable.CHANNEL.toString(), initChannel()); String value = this.process(template, params); String expected = "<a href='http://www.jict.org/grand'>grand</a>>" + "<a href='http://www.jict.org/parent'>parent</a>>" + "<a href='http://www.jict.org/channel'>channel</a>"; value = StringUtils.replace(value, "\n", ""); Assert.assertEquals(expected, value); }
From source file:com.sun.socialsite.util.Utilities.java
/** * Escape, but do not replace HTML.// w w w . j a va2s . c om * @param escapeAmpersand Optionally escape * ampersands (&). */ public static String escapeHTML(String s, boolean escapeAmpersand) { // got to do amp's first so we don't double escape if (escapeAmpersand) { s = StringUtils.replace(s, "&", "&"); } s = StringUtils.replace(s, " ", " "); s = StringUtils.replace(s, "\"", """); s = StringUtils.replace(s, "<", "<"); s = StringUtils.replace(s, ">", ">"); return s; }
From source file:com.gst.portfolio.savings.DepositAccountType.java
@Override public String toString() { return StringUtils.replace(code, "_", SPACE); }
From source file:cn.vlabs.umt.common.mail.MessageFormatter.java
public String getFormattedMessage(Locale locale, String emailTemplateTarget, Properties prop) throws TemplateNotFound { String content = readTemplate(locale, emailTemplateTarget); if (prop != null) { Enumeration<Object> iter = prop.keys(); while (iter.hasMoreElements()) { String key = (String) iter.nextElement(); String value = prop.getProperty(key); if (value == null) { value = ""; }/* w w w. j a va2 s .co m*/ content = StringUtils.replace(content, "%" + key + "%", value); } } return CommonUtils.trim(content); }
From source file:com.flexive.faces.listener.FormRowMessageListener.java
@Override public void beforePhase(PhaseEvent event) { final FacesContext context = FacesContext.getCurrentInstance(); final Iterator<String> idsWithMessages = context.getClientIdsWithMessages(); while (idsWithMessages.hasNext()) { final String id = idsWithMessages.next(); // find the label component rendered by fx:formRow final UIComponent labelComponent = context.getViewRoot().findComponent(id + "Label"); if (labelComponent != null && labelComponent instanceof HtmlOutputLabel) { final Iterator<FacesMessage> messagesItr = context.getMessages(id); while (messagesItr.hasNext()) { final FacesMessage message = messagesItr.next(); // replace the component ID with the component label message.setSummary(StringUtils.replace(message.getSummary(), id, String.valueOf(((HtmlOutputLabel) labelComponent).getValue()))); }/*from w ww.jav a2 s .c o m*/ } } }