List of usage examples for java.util.regex Matcher quoteReplacement
public static String quoteReplacement(String s)
From source file:com.arrow.acn.client.api.DeviceApi.java
/** * Sends PUT request to update specific existing device according to * {@code model} passed/* w w w .j ava2 s .com*/ * * @param hid * {@link String} representing {@code hid} of device to be * updated * @param model * {@link DeviceRegistrationModel} representing device parameters * to be updated * * @return {@link HidModel} containing {@code hid} of device updated * * @throws AcnClientException * if request failed */ public HidModel updateExistingDevice(String hid, DeviceRegistrationModel model) { String method = "updateExistingDevice"; try { URI uri = buildUri(PATTERN.matcher(UPDATE_EXISTING_URL).replaceAll(Matcher.quoteReplacement(hid))); HidModel result = execute(new HttpPut(uri), JsonUtils.toJson(model), HidModel.class); log(method, result); return result; } catch (Throwable e) { logError(method, e); throw new AcnClientException(method, e); } }
From source file:edworld.pdfreader4humans.PDFReader.java
protected String output(Component component, int indentLevel) { String componentTemplate = template("pdfreader4humans-" + component.getType() + ".xml", indentLevel); String content = ""; for (Component child : component.getChildren()) content += output(child, indentLevel + 1); return component.output(componentTemplate).replaceAll("\\$\\{content\\}", Matcher.quoteReplacement(content)); }
From source file:org.apache.kylin.engine.mr.CubingJob.java
@Override protected Pair<String, String> formatNotifications(ExecutableContext context, ExecutableState state) { CubeInstance cubeInstance = CubeManager.getInstance(context.getConfig()) .getCube(CubingExecutableUtil.getCubeName(this.getParams())); final Output output = getManager().getOutput(getId()); String logMsg;//from w w w.j a v a 2 s. co m state = output.getState(); if (state != ExecutableState.ERROR && !cubeInstance.getDescriptor().getStatusNeedNotify().contains(state.toString())) { logger.info("state:" + state + " no need to notify users"); return null; } switch (state) { case ERROR: logMsg = output.getVerboseMsg(); break; case DISCARDED: logMsg = "job has been discarded"; break; case SUCCEED: logMsg = "job has succeeded"; break; default: return null; } String content = ExecutableConstants.NOTIFY_EMAIL_TEMPLATE; content = content.replaceAll("\\$\\{job_name\\}", getName()); content = content.replaceAll("\\$\\{result\\}", state.toString()); content = content.replaceAll("\\$\\{env_name\\}", getDeployEnvName()); content = content.replaceAll("\\$\\{project_name\\}", getProjectName()); content = content.replaceAll("\\$\\{cube_name\\}", CubingExecutableUtil.getCubeName(this.getParams())); content = content.replaceAll("\\$\\{source_records_count\\}", String.valueOf(findSourceRecordCount())); content = content.replaceAll("\\$\\{start_time\\}", new Date(getStartTime()).toString()); content = content.replaceAll("\\$\\{duration\\}", getDuration() / 60000 + "mins"); content = content.replaceAll("\\$\\{mr_waiting\\}", getMapReduceWaitTime() / 60000 + "mins"); content = content.replaceAll("\\$\\{last_update_time\\}", new Date(getLastModified()).toString()); content = content.replaceAll("\\$\\{submitter\\}", StringUtil.noBlank(getSubmitter(), "missing submitter")); content = content.replaceAll("\\$\\{error_log\\}", Matcher.quoteReplacement(StringUtil.noBlank(logMsg, "no error message"))); try { InetAddress inetAddress = InetAddress.getLocalHost(); content = content.replaceAll("\\$\\{job_engine\\}", inetAddress.getCanonicalHostName()); } catch (UnknownHostException e) { logger.warn(e.getLocalizedMessage(), e); } String title = "[" + state.toString() + "] - [" + getDeployEnvName() + "] - [" + getProjectName() + "] - " + CubingExecutableUtil.getCubeName(this.getParams()); return Pair.of(title, content); }
From source file:org.entando.edo.builder.TestBuilder.java
@Test public void test_Controller_GlobalMassages() throws IOException { String commonPath = "src/main/java/org/entando/entando/plugins/jppet/apsadmin".replaceAll("/", Matcher.quoteReplacement(File.separator)); String actualPath = ACTUAL_BASE_FOLDER + commonPath; File actualDir = new File(actualPath); Assert.assertTrue(actualDir.exists()); FileFilter excludeSubfolders = new FileFilter() { @Override//from ww w.j a v a 2s . co m public boolean accept(File pathname) { if (pathname.isDirectory() && !pathname.getName().equals("apsadmin")) return false; return true; } }; List<File> actualFiles = this.searchFiles(actualDir, excludeSubfolders); Assert.assertEquals(2, actualFiles.size()); this.compareFiles(actualFiles); }
From source file:mobi.jenkinsci.net.UrlPath.java
/** * * @param __path The path to compare with this path I.e. if this.path = * res1/res2/res3 and current node path is res1/res2 : the method * should return true if this.path = res1/res2/res3 and current node * path is re ss1/res4 : the method should return false * @return True if the given path is part of this path *///from www. j a v a 2 s . c o m public boolean isFollowingPath(String currentNodePath) { if (currentNodePath == null) { return false; } if (!currentNodePath.endsWith("/")) { currentNodePath = currentNodePath + "/"; } if (!path.endsWith("/")) { path = path + "/"; } final String currentNodePathPattern = "/?" + Matcher.quoteReplacement(currentNodePath) + ".*"; return Pattern.matches(currentNodePathPattern, path); }
From source file:org.kuali.rice.krad.theme.postprocessor.ThemeCssFilesProcessor.java
/** * Performs URL rewriting within the given CSS contents * * <p>//from w w w . j av a 2 s .c o m * The given merge file (where the merge contents come from) and the merged file (where they are going to) * is used to determine the path difference. Once that path difference is found, the contents are then matched * to find any URLs. For each relative URL (absolute URLs are not modified), the path is adjusted and * replaced into the contents. * * ex. suppose the merged file is /plugins/foo/plugin.css, and the merged file is * /themes/mytheme/stylesheets/merged.css, the path difference will then be '../../../plugins/foo/'. So a URL * in the CSS contents of 'images/image.png' will get rewritten to '../../../plugins/foo/images/image.png' * </p> * * @param css contents to adjust URLs for * @param mergeFile file that provided the merge contents * @param mergedFile file the contents will be going to * @return css contents, with possible adjusted URLs * @throws IOException */ protected String rewriteCssUrls(String css, File mergeFile, File mergedFile) throws IOException { String urlAdjustment = ThemeBuilderUtils.calculatePathToFile(mergedFile, mergeFile); if (StringUtils.isBlank(urlAdjustment)) { // no adjustment needed return css; } // match all URLs in css string and then adjust each one Pattern urlPattern = Pattern.compile(ThemeBuilderConstants.Patterns.CSS_URL_PATTERN); Matcher matcher = urlPattern.matcher(css); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String cssStatement = matcher.group(); String cssUrl = null; if (matcher.group(1) != null) { cssUrl = matcher.group(1); } else { cssUrl = matcher.group(2); } if (cssUrl != null) { // only adjust URL if it is relative String modifiedUrl = cssUrl; if (!cssUrl.startsWith("/")) { modifiedUrl = urlAdjustment + cssUrl; } String modifiedStatement = Matcher.quoteReplacement(cssStatement.replace(cssUrl, modifiedUrl)); matcher.appendReplacement(sb, modifiedStatement); } } matcher.appendTail(sb); return sb.toString(); }
From source file:server.Wso2EventServer.java
public List<StreamDefinition> loadStreamDefinitions() { String relativeFilePath = "src/main/java/files/streamDefinitions/"; String directoryPath = relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator)); String FILE_STREAM_DEFINITION_EXT = ".json"; GenericExtFilter filter = new GenericExtFilter(FILE_STREAM_DEFINITION_EXT); File directory = new File(directoryPath); List<StreamDefinition> streamDefinitions = new ArrayList<StreamDefinition>(); if (!directory.exists()) { log.error(// ww w . ja v a 2 s . co m "Cannot load stream definitions from " + directory.getAbsolutePath() + " directory not exist"); return streamDefinitions; } if (!directory.isDirectory()) { log.error("Cannot load stream definitions from " + directory.getAbsolutePath() + " not a directory"); return streamDefinitions; } // List out all the file names and filter by the extension. String[] listStreamDefinitionFiles = directory.list(filter); if (listStreamDefinitionFiles != null) { for (final String fileEntry : listStreamDefinitionFiles) { BufferedReader bufferedReader = null; StringBuilder stringBuilder = new StringBuilder(); String fullPathToStreamDefinitionFile = directoryPath + File.separator + fileEntry; try { bufferedReader = new BufferedReader(new FileReader(fullPathToStreamDefinitionFile)); String line; while ((line = bufferedReader.readLine()) != null) { stringBuilder.append(line).append("\n"); } StreamDefinition streamDefinition = EventDefinitionConverterUtils .convertFromJson(stringBuilder.toString().trim()); streamDefinitions.add(streamDefinition); } catch (IOException e) { log.error("Error in reading file : " + fullPathToStreamDefinitionFile, e); } catch (MalformedStreamDefinitionException e) { log.error("Error in converting Stream definition : " + e.getMessage(), e); } finally { try { if (bufferedReader != null) { bufferedReader.close(); } } catch (IOException e) { log.error("Error occurred when reading the file : " + e.getMessage(), e); } } } } return streamDefinitions; }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test @SuppressWarnings("unchecked") public void testInt2866LocalDirectoryExpressionMGET() { String dir = "ftpSource/"; long modified = setModifiedOnSource1(); this.inboundMGet.send(new GenericMessage<Object>(dir + "*.txt")); Message<?> result = this.output.receive(1000); assertNotNull(result);//w w w . j a va 2 s.com List<File> localFiles = (List<File>) result.getPayload(); assertThat(localFiles.size(), Matchers.greaterThan(0)); boolean assertedModified = false; for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir)); if (file.getPath().contains("localTarget1")) { assertedModified = assertPreserved(modified, file); } } assertTrue(assertedModified); dir = "ftpSource/subFtpSource/"; this.inboundMGet.send(new GenericMessage<Object>(dir + "*.txt")); result = this.output.receive(1000); assertNotNull(result); localFiles = (List<File>) result.getPayload(); assertThat(localFiles.size(), Matchers.greaterThan(0)); for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir)); } }
From source file:org.apache.marmotta.ldclient.provider.freebase.FreebaseProvider.java
/** * Fixes Freebase deficiencies on Turtle serialization, doing * some dirty things they may be semantically wrong. * * @param is stream with the raw data//from ww w . j av a 2s.c o m * @return fixed stream */ private InputStream fix(InputStream is, String encoding) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); String line; while ((line = br.readLine()) != null) { Matcher literalMatcher = FREEBASE_LITERAL_PATTERN.matcher(line); if (literalMatcher.matches()) { //literal found try { final String literal = literalMatcher.group(2); final String fixed = fixLiteral(literal); log.debug("literal: --{}--{}", literal, fixed); String triple = literalMatcher.group(1) + " \"" + fixed + "\""; if (literalMatcher.group(3) != null) { triple += literalMatcher.group(3); } log.debug("new triple: {}", triple); sb.append(" " + triple + literalMatcher.group(5)); sb.append(("\n")); } catch (Exception e) { log.debug("Error fixing line, so triple ignored: {}", e.getMessage()); log.trace("error on line: {}", line); warrantyClosing(sb, line); } } else { Matcher tripleMatcher = FREEBASE_TRIPLE_PATTERN.matcher(line); if (tripleMatcher.matches()) { String p = tripleMatcher.group(1); if (p.indexOf("..") >= 0) { log.debug("ignoring line due wrong property: {}", p); warrantyClosing(sb, line); } else { String o = tripleMatcher.group(2); if (o.charAt(0) == '<') { try { URI uri = URI.create(o.substring(1, o.length() - 1)); sb.append(" " + p + " <" + uri.toString() + ">" + tripleMatcher.group(3)); sb.append("\n"); } catch (RuntimeException e) { log.debug("Object uri not valid: {}", o.substring(1, o.length() - 1)); warrantyClosing(sb, line); } } else { if (o.contains("$")) { o = o.replaceAll(Pattern.quote("$"), Matcher.quoteReplacement("\\$")); } else if (o.contains("\\u")) { o = StringEscapeUtils.unescapeJava(o); } else if (o.contains("\\x")) { o = org.apache.marmotta.commons.util.StringUtils.fixLatin1(o); } sb.append(" " + p + " " + o + tripleMatcher.group(3)); sb.append("\n"); } } } else { log.debug("default fallback"); sb.append(line); sb.append("\n"); } } } //System.out.println(sb.toString()); return new ByteArrayInputStream(sb.toString().getBytes()); }
From source file:org.wso2.carbon.integration.test.client.JMSPublisherClient.java
/** * Construct the data file location using the testcase folder name and the file name * * @param testCaseFolderName Testcase folder name which is in the test artifacts folder * @param dataFileName data file name with the extension to be read * *///from www . ja v a 2s . c o m private static String getTestDataFileLocation(String testCaseFolderName, String dataFileName) { String relativeFilePath = FrameworkPathUtil.getSystemResourceLocation() + CEPIntegrationTestConstants.RELATIVE_PATH_TO_TEST_ARTIFACTS + testCaseFolderName + File.separator + dataFileName; relativeFilePath = relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator)); return relativeFilePath; }