List of usage examples for org.apache.commons.lang3 StringUtils replace
public static String replace(final String text, final String searchString, final String replacement)
Replaces all occurrences of a String within another String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("any", null, *) = "any" StringUtils.replace("any", *, null) = "any" StringUtils.replace("any", "", *) = "any" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "b" StringUtils.replace("aba", "a", "z") = "zbz"
From source file:com.dreambox.web.logger.LoggingFilter.java
@Override protected void logResponse(HttpServletRequest request, HttpServletResponse response) { if (!(response instanceof HttpServletResponseLoggingWrapper) || !isJson(response)) { return;/*from w w w .ja va2 s . c o m*/ } String uri = request.getRequestURI(); if (isExcludeUri(uri)) { return; } if (isIgnoreUri(uri)) { return; } long startTime = (long) request.getAttribute(REQUEST_START_TIME); long endTime = System.currentTimeMillis(); long elapse = endTime - startTime; String id = (String) request.getAttribute(REQUEST_ID_ATTR); String status = ""; String message = ""; String respData = ""; try { ServletOutputStream output = response.getOutputStream(); if (output instanceof CopyResponseStreamWrapper) { String copy = ((CopyResponseStreamWrapper) output).getCopy(); if (StringUtils.isNotBlank(copy)) { try { ApiRespWrapper<?> apiRespWrapper = GsonUtils.fromJsonStr(copy, ApiRespWrapper.class); status = String.valueOf(apiRespWrapper.getStatus()); message = apiRespWrapper.getMessage(); if (needLogResponse(uri)) { Object d = apiRespWrapper.getData(); respData = d == null ? "" : d.toString(); } } catch (Exception e) { } } } } catch (IOException e) { } Map<String, String> commonPara = threadLocalMap.get(); String ip = commonPara == null ? IPUtil.getClientIP(request) : commonPara.get("ip"); String method = commonPara == null ? request.getMethod() : commonPara.get("method"); String queryStr = commonPara == null ? request.getQueryString() : commonPara.get("queryStr"); queryStr = StringUtils.replace(queryStr, "\r\n", ""); queryStr = StringUtils.replace(queryStr, "\n", ""); String parameter = commonPara == null ? getRequestParams(request) : commonPara.get("parameter"); parameter = StringUtils.replace(parameter, "\r\n", ""); parameter = StringUtils.replace(parameter, "\n", ""); String logInfo = now() + "\tId:" + id + "\ttype:response\tUri:" + uri + "\tIp:" + ip + "\tMethod:" + method + "\tQueryStr:" + queryStr + "\tParameter:" + parameter + "\tHttpStatus:" + response.getStatus() + "\tStatus:" + status + "\tMessage:" + message + "\telapseTime:" + elapse + "\tData:" + respData; requestLogger.info(logInfo); threadLocalMap.remove(); }
From source file:de.micromata.genome.gwiki.utils.CommaListParser.java
/** * Quote.//from w w w .j av a2 s .c o m * * @param s the s * @return the string */ public static String quote(String s) { s = StringUtils.replace(s, "\\", "\\\\"); s = StringUtils.replace(s, "\"", "\\\""); return "\"" + s + "\""; }
From source file:com.sk89q.craftbook.sponge.mechanics.BounceBlocks.java
private void doAction(Entity entity, String positionString, Vector3d rotation) { if (entity instanceof Player) { if (!usePermissions.hasPermission((Subject) entity)) { return; }//from w w w . j av a 2s . c om } double x = 0; double y; double z = 0; boolean straight = positionString.startsWith("!"); String[] bits = RegexUtil.COMMA_PATTERN.split(StringUtils.replace(positionString, "!", "")); if (bits.length == 0) { y = 0.5; } else if (bits.length == 1) { try { y = Double.parseDouble(bits[0]); } catch (NumberFormatException e) { y = 0.5; } } else { x = Double.parseDouble(bits[0]); y = Double.parseDouble(bits[1]); z = Double.parseDouble(bits[2]); } if (!straight) { double pitch = ((rotation.getX() + 90d) * Math.PI) / 180d; double yaw = ((rotation.getY() + 90d) * Math.PI) / 180d; x *= Math.sin(pitch) * Math.cos(yaw); z *= Math.sin(pitch) * Math.sin(yaw); } entity.setVelocity(new Vector3d(x, y, z)); entity.offer(Keys.FALL_DISTANCE, -20f); }
From source file:com.thoughtworks.go.server.service.AccessTokenServiceIntegrationTest.java
@Test public void shouldFailToGetAccessTokenWhenProvidedTokenHashEqualityFails() { String tokenDescription = "This is my first Token"; AccessToken.AccessTokenWithDisplayValue createdToken = accessTokenService.create(tokenDescription, "bob", authConfigId);/* w ww .j a v a2s . co m*/ String accessTokenInString = createdToken.getDisplayValue(); //replace last 5 characters to make the current token invalid String invalidAccessToken = StringUtils.replace(accessTokenInString, accessTokenInString.substring(35), "abcde"); InvalidAccessTokenException exception = assertThrows(InvalidAccessTokenException.class, () -> accessTokenService.findByAccessToken(invalidAccessToken)); assertThat("Invalid Personal Access Token.").isEqualTo(exception.getMessage()); }
From source file:net.ontopia.topicmaps.nav2.plugins.PluginContentHandler.java
/** * INTERNAL: Process specified URI string and replace placeholder * (<code>"${" + NavigatorApplicationIF.PLUGINS_ROOTDIR_KEY + * "}"</code>) with actual plugins root directory. *///w w w .j av a 2 s .c o m private String processURI(String orig_uri) { String uri = orig_uri; if (uri.indexOf(PLUGINS_ROOTDIR_PLACEHOLDER) >= 0) { uri = StringUtils.replace(uri, PLUGINS_ROOTDIR_PLACEHOLDER, pluginsRootURI); } return uri; }
From source file:com.alibaba.rocketmq.filtersrv.filter.DynaCode.java
private String[] uploadSrcFile() throws Exception { List<String> srcFileAbsolutePaths = new ArrayList<String>(codeStrs.size()); for (String code : codeStrs) { if (StringUtils.isNotBlank(code)) { String packageName = getPackageName(code); String className = getClassName(code); if (StringUtils.isNotBlank(className)) { File srcFile = null; BufferedWriter bufferWriter = null; try { if (StringUtils.isBlank(packageName)) { File pathFile = new File(sourcePath); if (!pathFile.exists()) { if (!pathFile.mkdirs()) { throw new RuntimeException("create PathFile Error!"); }//from w w w .j av a 2s .co m } srcFile = new File(sourcePath + FILE_SP + className + ".java"); } else { String srcPath = StringUtils.replace(packageName, ".", FILE_SP); File pathFile = new File(sourcePath + FILE_SP + srcPath); if (!pathFile.exists()) { if (!pathFile.mkdirs()) { throw new RuntimeException("create PathFile Error!"); } } srcFile = new File(pathFile.getAbsolutePath() + FILE_SP + className + ".java"); } synchronized (loadClass) { loadClass.put(getFullClassName(code), null); } if (null != srcFile) { logger.warn("Dyna Create Java Source File:---->" + srcFile.getAbsolutePath()); srcFileAbsolutePaths.add(srcFile.getAbsolutePath()); srcFile.deleteOnExit(); } OutputStreamWriter outputStreamWriter = new OutputStreamWriter( new FileOutputStream(srcFile), encoding); bufferWriter = new BufferedWriter(outputStreamWriter); for (String lineCode : code.split(LINE_SP)) { bufferWriter.write(lineCode); bufferWriter.newLine(); } bufferWriter.flush(); } finally { if (null != bufferWriter) { bufferWriter.close(); } } } } } return srcFileAbsolutePaths.toArray(new String[srcFileAbsolutePaths.size()]); }
From source file:io.wcm.handler.mediasource.dam.markup.DamVideoMediaMarkupBuilder.java
/** * Build flash player element//www . j av a 2 s .c o m * @param media Media metadata * @param dimension Dimension * @return Media element */ protected HtmlElement getFlashPlayerElement(Media media, Dimension dimension) { Asset asset = getDamAsset(media); if (asset == null) { return null; } com.day.cq.dam.api.Rendition rendition = asset .getRendition(new PrefixRenditionPicker(VideoConstants.RENDITION_PREFIX + H264_PROFILE)); if (rendition == null) { return null; } String playerUrl = urlHandler.get("/etc/clientlibs/foundation/video/swf/StrobeMediaPlayback.swf") .buildExternalResourceUrl(); // strobe specialty: path must be relative to swf file String renditionUrl = "../../../../.." + rendition.getPath(); // manually apply jcr_content namespace mangling renditionUrl = StringUtils.replace(renditionUrl, JcrConstants.JCR_CONTENT, "_jcr_content"); HtmlElement object = new HtmlElement("object"); object.setAttribute("type", ContentType.SWF); object.setAttribute("data", playerUrl); object.setAttribute("width", Long.toString(dimension.getWidth())); object.setAttribute("height", Long.toString(dimension.getHeight())); // get flashvars Map<String, String> flashvars = new HashMap<String, String>(); flashvars.put("src", renditionUrl); flashvars.putAll(getAdditionalFlashPlayerFlashVars(media, dimension)); // get flash parameters Map<String, String> parameters = new HashMap<String, String>(); parameters.put("movie", playerUrl); parameters.put("flashvars", buildFlashVarsString(flashvars)); parameters.putAll(getAdditionalFlashPlayerParameters(media, dimension)); // set parameters on object element for (Map.Entry<String, String> entry : parameters.entrySet()) { HtmlElement param = object.create("param"); param.setAttribute("name", entry.getKey()); param.setAttribute("value", entry.getValue()); } return object; }
From source file:de.blizzy.documentr.markdown.MarkdownProcessor.java
private String markdownToHtml(RootNode rootNode, String projectName, String branchName, String path, Authentication authentication, boolean nonCacheableMacros, String contextPath) { HtmlSerializerContext context = new HtmlSerializerContext(projectName, branchName, path, this, authentication, pageStore, systemSettingsStore, contextPath); HtmlSerializer serializer = new HtmlSerializer(context); String html = serializer.toHtml(rootNode); List<MacroInvocation> macroInvocations = context.getMacroInvocations(); int nonCacheableMacroIdx = 1; for (MacroInvocation invocation : macroInvocations) { IMacro macro = macroFactory.get(invocation.getMacroName()); if (macro == null) { macro = new UnknownMacroMacro(); }// ww w. j a va2 s . com IMacroDescriptor macroDescriptor = macro.getDescriptor(); String startMarker = invocation.getStartMarker(); String endMarker = invocation.getEndMarker(); String body = StringUtils.substringBetween(html, startMarker, endMarker); if (macroDescriptor.isCacheable()) { MacroContext macroContext = MacroContext.create(invocation.getMacroName(), invocation.getParameters(), body, context, beanFactory); IMacroRunnable macroRunnable = macro.createRunnable(); String macroHtml = StringUtils.defaultString(macroRunnable.getHtml(macroContext)); html = StringUtils.replace(html, startMarker + body + endMarker, macroHtml); } else if (nonCacheableMacros) { String macroName = invocation.getMacroName(); String params = invocation.getParameters(); String idx = String.valueOf(nonCacheableMacroIdx++); html = StringUtils.replace(html, startMarker + body + endMarker, "__" + NON_CACHEABLE_MACRO_MARKER + "_" + idx + "__" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ macroName + " " + StringUtils.defaultString(params) + //$NON-NLS-1$ "__" + NON_CACHEABLE_MACRO_BODY_MARKER + "__" + //$NON-NLS-1$ //$NON-NLS-2$ body + "__/" + NON_CACHEABLE_MACRO_MARKER + "_" + idx + "__"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } else { html = StringUtils.replace(html, startMarker + body + endMarker, StringUtils.EMPTY); } } html = cleanupHtml(html, macroInvocations, true); return html; }
From source file:io.stallion.tools.ExportToHtml.java
public Set<String> findAssetsInHtml(String html) { HashSet<String> assets = new HashSet<>(); Jerry jerry = Jerry.jerry(html);/*from w w w .j a v a 2s . c om*/ for (Jerry j : jerry.find("script")) { String src = j.attr("src"); Log.info("SCRIPT TAG HTML {0} {1}", j.htmlAll(true), src); if (empty(src)) { continue; } Log.info("Add asset {0}", src); assets.add(src); } for (Jerry j : jerry.find("link")) { Log.info("LINK TAG HTML {0}", j.htmlAll(true)); if (!"stylesheet".equals(j.attr("rel"))) { continue; } String src = j.attr("href"); if (empty(src)) { continue; } assets.add(src); } for (Jerry j : jerry.find("img")) { String src = j.attr("src"); if (empty(src)) { continue; } assets.add(src); } HashSet<String> filteredAssets = new HashSet<>(); Log.info("CDN URL {0}", Settings.instance().getCdnUrl()); Log.info("Site URL {0}", Settings.instance().getSiteUrl()); for (String src : assets) { if (src.startsWith(Settings.instance().getCdnUrl())) { src = StringUtils.replace(src, Settings.instance().getCdnUrl(), ""); if (!src.startsWith("/")) { src = "/" + src; } } if (src.startsWith(Settings.instance().getSiteUrl())) { src = StringUtils.replace(src, Settings.instance().getSiteUrl(), ""); } if (src.startsWith("/")) { filteredAssets.add(src); } } Log.info("Asset count {0}", filteredAssets.size()); return filteredAssets; }
From source file:de.tuberlin.uebb.jbop.optimizer.utils.ClassNodeBuilderTextifier.java
/** * Prints a disassembled view of the given annotation. * //from w w w . j a va 2s . c o m * @param desc * the class descriptor of the annotation class. * @param visible * <tt>true</tt> if the annotation is visible at runtime. * @return a visitor to visit the annotation values. */ @Override public Textifier visitAnnotation(final String desc, final boolean visible) { buf.setLength(0); buf.append("withAnnotation("); buf.append(StringUtils.replace(StringUtils.removeEnd(StringUtils.removeStart(desc, "L"), ";"), "/", ".")); buf.append(".class"); text.add(buf.toString()); text.add(").//\n"); return createTextifier(); }