List of usage examples for java.util.regex Matcher quoteReplacement
public static String quoteReplacement(String s)
From source file:org.rhq.plugins.jbossas5.script.ScriptComponent.java
private String replacePropertyPatterns(String envVars) { Pattern pattern = Pattern.compile("(%([^%]*)%)"); Matcher matcher = pattern.matcher(envVars); Configuration parentPluginConfig = this.resourceContext.getParentResourceComponent().getResourceContext() .getPluginConfiguration();// w ww . j ava 2s . c o m StringBuffer buffer = new StringBuffer(); while (matcher.find()) { String propName = matcher.group(2); PropertySimple prop = parentPluginConfig.getSimple(propName); String propPattern = matcher.group(1); String replacement = (prop != null) ? prop.getStringValue() : propPattern; matcher.appendReplacement(buffer, Matcher.quoteReplacement(replacement)); } matcher.appendTail(buffer); return buffer.toString(); }
From source file:org.entando.edo.builder.TestBuilderNoPlugin.java
@Test public void test_Widget_InternalServlet_Java() throws IOException { String commonPath = "src/main/java/com/myportal/aps/internalservlet/cat".replaceAll("/", Matcher.quoteReplacement(File.separator)); String actualPath = ACTUAL_BASE_FOLDER + commonPath; File actualDir = new File(actualPath); Assert.assertTrue(actualDir.exists()); List<File> actualFiles = this.searchFiles(actualDir, null); Assert.assertEquals(3, actualFiles.size()); this.compareFiles(actualFiles); }
From source file:org.wso2.carbon.esb.samples.test.util.ESBSampleIntegrationTest.java
/** * Load a synapse configuration given the relative path of the file that contains the synapse configuration. * * @param relativeFilePath the path of the file relative to the resources directory * @throws Exception if an error occurs while updating the synapse configuration. *///ww w .j ava 2 s. c o m protected void loadESBConfigurationFromClasspath(String relativeFilePath) throws Exception { relativeFilePath = relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator)); OMElement synapseConfig = esbUtils.loadResource(relativeFilePath); updateESBConfiguration(synapseConfig); }
From source file:dk.deck.resolver.ArtifactResolverRemote.java
private Metadata getSnapshptMetaData(String repo, Artifact artifact) throws IOException, DownloadException, SAXException { String artifactPath = artifact.getGroupId().replaceAll(Pattern.quote("."), Matcher.quoteReplacement("/")) + "/" + artifact.getArtifactId(); String artifactMetaData = artifactPath + "/" + artifact.getVersion() + "/maven-metadata.xml"; String getUrl = repo + "/" + artifactMetaData; return getMetadata(repo, artifact, getUrl); }
From source file:org.entando.edo.builder.TestBuilder.java
@Test public void test_Widget_InternalServlet_Java() throws IOException { String commonPath = "src/main/java/org/entando/entando/plugins/jppet/aps/internalservlet/cat" .replaceAll("/", Matcher.quoteReplacement(File.separator)); String actualPath = ACTUAL_BASE_FOLDER + commonPath; File actualDir = new File(actualPath); Assert.assertTrue(actualDir.exists()); List<File> actualFiles = this.searchFiles(actualDir, null); Assert.assertEquals(3, actualFiles.size()); this.compareFiles(actualFiles); }
From source file:org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.java
@SuppressWarnings({ "unchecked" }) private String createURLInternal(Map paramValues, String encoding, boolean includeContextPath) { if (encoding == null) encoding = "utf-8"; String contextPath = ""; if (includeContextPath) { GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.getRequestAttributes(); if (webRequest != null) { contextPath = webRequest.getAttributes().getApplicationUri(webRequest.getCurrentRequest()); }/*w w w.jav a 2s . c o m*/ } if (paramValues == null) paramValues = Collections.EMPTY_MAP; StringBuilder uri = new StringBuilder(contextPath); Set usedParams = new HashSet(); String[] tokens = urlData.getTokens(); int paramIndex = 0; for (int i = 0; i < tokens.length; i++) { String token = tokens[i]; if (i == tokens.length - 1 && urlData.hasOptionalExtension()) { token += UrlMapping.OPTIONAL_EXTENSION_WILDCARD; } Matcher m = OPTIONAL_EXTENSION_WILDCARD_PATTERN.matcher(token); if (m.find()) { if (token.startsWith(CAPTURED_WILDCARD)) { ConstrainedProperty prop = constraints[paramIndex++]; String propName = prop.getPropertyName(); Object value = paramValues.get(propName); usedParams.add(propName); if (value != null) { token = token.replaceFirst(DOUBLE_WILDCARD_PATTERN.pattern(), value.toString()); } else if (prop.isNullable()) { break; } } uri.append(SLASH); ConstrainedProperty prop = constraints[paramIndex++]; String propName = prop.getPropertyName(); Object value = paramValues.get(propName); usedParams.add(propName); if (value != null) { String ext = "." + value; uri.append(token.replace(OPTIONAL_EXTENSION_WILDCARD + '?', ext) .replace(OPTIONAL_EXTENSION_WILDCARD, ext)); } else { uri.append(token.replace(OPTIONAL_EXTENSION_WILDCARD + '?', "") .replace(OPTIONAL_EXTENSION_WILDCARD, "")); } continue; } if (token.endsWith("?")) { token = token.substring(0, token.length() - 1); } m = DOUBLE_WILDCARD_PATTERN.matcher(token); if (m.find()) { StringBuffer buf = new StringBuffer(); do { ConstrainedProperty prop = constraints[paramIndex++]; String propName = prop.getPropertyName(); Object value = paramValues.get(propName); usedParams.add(propName); if (value == null && !prop.isNullable()) { throw new UrlMappingException("Unable to create URL for mapping [" + this + "] and parameters [" + paramValues + "]. Parameter [" + prop.getPropertyName() + "] is required, but was not specified!"); } else if (value == null) { m.appendReplacement(buf, ""); } else { m.appendReplacement(buf, Matcher.quoteReplacement(value.toString())); } } while (m.find()); m.appendTail(buf); try { String v = buf.toString(); if (v.indexOf(SLASH) > -1 && CAPTURED_DOUBLE_WILDCARD.equals(token)) { // individually URL encode path segments if (v.startsWith(SLASH)) { // get rid of leading slash v = v.substring(SLASH.length()); } String[] segs = v.split(SLASH); for (String segment : segs) { uri.append(SLASH).append(encode(segment, encoding)); } } else if (v.length() > 0) { // original behavior uri.append(SLASH).append(encode(v, encoding)); } else { // Stop processing tokens once we hit an empty one. break; } } catch (UnsupportedEncodingException e) { throw new ControllerExecutionException("Error creating URL for parameters [" + paramValues + "], problem encoding URL part [" + buf + "]: " + e.getMessage(), e); } } else { uri.append(SLASH).append(token); } } populateParameterList(paramValues, encoding, uri, usedParams); if (LOG.isDebugEnabled()) { LOG.debug("Created reverse URL mapping [" + uri.toString() + "] for parameters [" + paramValues + "]"); } return uri.toString(); }
From source file:org.springframework.aop.interceptor.CustomizableTraceInterceptor.java
/** * Adds a comma-separated list of the short {@code Class} names of the * method argument types to the output. For example, if a method has signature * {@code put(java.lang.String, java.lang.Object)} then the value returned * will be {@code String, Object}.//from www . ja v a 2 s . com * @param methodInvocation the {@code MethodInvocation} being logged. * Arguments will be retrieved from the corresponding {@code Method}. * @param matcher the {@code Matcher} containing the state of the output * @param output the {@code StringBuffer} containing the output */ private void appendArgumentTypes(MethodInvocation methodInvocation, Matcher matcher, StringBuffer output) { Class<?>[] argumentTypes = methodInvocation.getMethod().getParameterTypes(); String[] argumentTypeShortNames = new String[argumentTypes.length]; for (int i = 0; i < argumentTypeShortNames.length; i++) { argumentTypeShortNames[i] = ClassUtils.getShortName(argumentTypes[i]); } matcher.appendReplacement(output, Matcher.quoteReplacement(StringUtils.arrayToCommaDelimitedString(argumentTypeShortNames))); }
From source file:org.entando.edo.builder.TestBuilderNoPlugin.java
@Test public void test_Widget_InternalServlet_Jsp() throws IOException { String commonPath = "src/main/webapp/WEB-INF/aps/jsp/internalservlet".replaceAll("/", Matcher.quoteReplacement(File.separator)); String actualPath = ACTUAL_BASE_FOLDER + commonPath; File actualDir = new File(actualPath); Assert.assertTrue(actualDir.exists()); List<File> actualFiles = this.searchFiles(actualDir, null); Assert.assertEquals(4, actualFiles.size()); this.compareFiles(actualFiles); }
From source file:dk.deck.resolver.ArtifactResolverRemote.java
private Metadata getArtifactMetaData(String repo, Artifact artifact) throws IOException, DownloadException, SAXException { String artifactPath = artifact.getGroupId().replaceAll(Pattern.quote("."), Matcher.quoteReplacement("/")) + "/" + artifact.getArtifactId(); String artifactMetaData = artifactPath + "/maven-metadata.xml"; String getUrl = repo + "/" + artifactMetaData; return getMetadata(repo, artifact, getUrl); }
From source file:io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder.java
protected void importMarkupStyle1(Pattern titlePattern, Markup titlePrefix, Reader markupText, MarkupLanguage markupLanguage, int levelOffset) { Validate.isTrue(levelOffset <= MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) > max levelOffset (%d)", levelOffset, MAX_TITLE_LEVEL)); Validate.isTrue(levelOffset >= -MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) < min levelOffset (%d)", levelOffset, -MAX_TITLE_LEVEL)); StringBuffer leveledText = new StringBuffer(); try (BufferedReader bufferedReader = new BufferedReader(markupText)) { String readLine;/*from w ww .j a v a2s . co m*/ while ((readLine = bufferedReader.readLine()) != null) { Matcher titleMatcher = titlePattern.matcher(readLine); while (titleMatcher.find()) { int titleLevel = titleMatcher.group(1).length() - 1; String title = titleMatcher.group(2); if (titleLevel + levelOffset > MAX_TITLE_LEVEL) throw new IllegalArgumentException(String.format( "Specified levelOffset (%d) set title '%s' level (%d) > max title level (%d)", levelOffset, title, titleLevel, MAX_TITLE_LEVEL)); if (titleLevel + levelOffset < 0) throw new IllegalArgumentException( String.format("Specified levelOffset (%d) set title '%s' level (%d) < 0", levelOffset, title, titleLevel)); else titleMatcher.appendReplacement(leveledText, Matcher.quoteReplacement(String.format("%s %s", StringUtils.repeat(titlePrefix.toString(), 1 + titleLevel + levelOffset), title))); } titleMatcher.appendTail(leveledText); leveledText.append(newLine); } } catch (IOException e) { throw new RuntimeException("Failed to import Markup", e); } if (!StringUtils.isBlank(leveledText)) { documentBuilder.append(newLine); documentBuilder.append(convert(leveledText.toString(), markupLanguage)); documentBuilder.append(newLine); } }