List of usage examples for java.util.regex Matcher quoteReplacement
public static String quoteReplacement(String s)
From source file:org.wso2.am.integration.test.utils.base.APIMIntegrationBaseTest.java
/** * @param relativeFilePath - file path to load config * @throws APIManagerIntegrationTestException - Throws if load synapse configuration from file path * fails */// ww w .j av a 2 s .co m protected void loadSynapseConfigurationFromClasspath(String relativeFilePath, AutomationContext automationContext, String sessionCookie) throws APIManagerIntegrationTestException { relativeFilePath = relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator)); OMElement synapseConfig; try { synapseConfig = APIMTestCaseUtils.loadResource(relativeFilePath); updateSynapseConfiguration(synapseConfig, automationContext, sessionCookie); } catch (FileNotFoundException e) { log.error("synapse config loading issue", e); throw new APIManagerIntegrationTestException("synapse config loading issue", e); } catch (XMLStreamException e) { log.error("synapse config loading issue", e); throw new APIManagerIntegrationTestException("synapse config loading issue", e); } }
From source file:org.entando.edo.builder.TestBuilder.java
@Test public void test_Controller_Jsp_Model() throws IOException { String commonPath = "src/main/webapp/WEB-INF/plugins/jppet/apsadmin/jsp/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 w w w .j ava 2s . com commonPath = "src/main/webapp/WEB-INF/plugins/jppet/apsadmin/jsp/common/layouts".replaceAll("/", Matcher.quoteReplacement(File.separator)); actualPath = ACTUAL_BASE_FOLDER + commonPath; actualDir = new File(actualPath); Assert.assertTrue(actualDir.exists()); FileFilter excludeSubfolders = new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.isDirectory() && !pathname.getName().equals("layouts")) return false; return true; } }; actualFiles = this.searchFiles(actualDir, excludeSubfolders); Assert.assertEquals(1, actualFiles.size()); this.compareFiles(actualFiles); }
From source file:org.dataconservancy.packaging.tool.impl.generator.DomainObjectResourceBuilder.java
private static void remap(String oldBaseURI, String newBaseURI, TreeMap<String, Resource> resources, Map<String, String> renameMap) { Map<String, Resource> toReplace = new HashMap<>(); /* Consider the the URI plus any hash fragments */ toReplace.putAll(resources.subMap(oldBaseURI, true, oldBaseURI, true)); toReplace.putAll(resources.subMap(oldBaseURI + "#", oldBaseURI + "#" + Character.MAX_VALUE)); /* Swap out the base URI for each matching resource */ toReplace.entrySet().forEach(res -> { String newURI = res.getKey().replaceFirst(oldBaseURI, Matcher.quoteReplacement(newBaseURI)); renameMap.put(res.getValue().toString(), newURI); ResourceUtils.renameResource(res.getValue(), newURI); });//from w w w .ja v a 2 s. co m }
From source file:org.bonitasoft.platform.setup.command.configure.BundleConfigurator.java
protected static String getDatabaseConnectionUrlForXmlFile(DatabaseConfiguration configuration) { return escapeXmlCharacters(Matcher.quoteReplacement(getDatabaseConnectionUrl(configuration))); }
From source file:org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.java
private static File getFileFromNotRunningPlatform(String filename, Class<?> clazz) throws UnsupportedEncodingException, IOException { URL localURL = clazz.getResource(""); String path = URLDecoder.decode(localURL.getFile(), Charset.defaultCharset().name()); int i = path.indexOf("!"); if (i != -1) { int j = path.lastIndexOf(File.separatorChar, i); if (j != -1) { path = path.substring(0, j) + File.separator; } else {//from w ww .j ava 2 s. c o m throw new AssertionFailedError( "Unable to determine location for '" + filename + "' at '" + path + "'"); } // class file is nested in jar, use jar path as base if (path.startsWith("file:")) { path = path.substring(5); } return new File(path + filename); } else { // remove all package segments from name String directory = clazz.getName().replaceAll("[^.]", ""); directory = directory.replaceAll(".", "../"); if (path.contains("/bin/")) { // account for bin/ when running from Eclipse workspace directory += "../"; } else if (path.contains("/target/classes/")) { // account for bin/ when running from Eclipse workspace directory += "../../"; } filename = path + (directory + filename).replaceAll("/", Matcher.quoteReplacement(File.separator)); return new File(filename).getCanonicalFile(); } }
From source file:org.apache.sqoop.connector.idf.CSVIntermediateDataFormat.java
private String unescapeStrings(String orig) { //Remove the trailing and starting quotes. orig = orig.substring(1, orig.length() - 1); int j = 0;//from www .java 2 s .c o m try { for (j = 0; j < replacements.length; j++) { orig = orig.replaceAll(getRegExp(replacements[j]), Matcher.quoteReplacement(String.valueOf(originals[j]))); } } catch (Exception e) { throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0003, orig + " " + String.valueOf(j) + e.getMessage()); } return orig; }
From source file:com.cisco.dvbu.ps.common.scriptutil.ScriptUtil.java
/** * Create the Composite Studio Enable VCS property file. The property file name is of the format <composite_user>.<domain>.<composite_server_host>.properties. * @param vcsIncludeResourceSecurity - the value is either "true" or "false" * @param vcsWorkspacePathOverride - this is a way of overriding the vcs workspace path. The vcsWorkspacePath is derived from the studio.properties file properties: * VCS_WORKSPACE_DIR+"/"+VCS_PROJECT_ROOT. It will use the substitute drive by default. * @param vcsScriptBinFolderOverride - this is the bin folder name only for PDTool Studio. Since PDTool Studio can now support multiple hosts via multiple /bin folders, * it is optional to pass in the /bin folder location. e.g. bin_host1, bin_host2. The default will be bin if the input is null or blank. * @param studioPropertyName - the name of the PDTool configuration property file. The default is studio.properties * @param PDToolHomeDir - the directory of the PDToolStudio home directory * @param propertyFilePath - this is the full path to the output file. For windows 7 the location will be in %USERPROFILE%\.compositesw * // www . ja va 2s. c om * usage createStudioEnableVCSPropertyFile true studio.properties D/:/CompositeSoftware/CIS6.2.0/conf/studio/PDToolStudio62 C:/Users/mike/.compositesw/admin.composite.localhost.properties */ public static void createStudioEnableVCSPropertyFile(String vcsIncludeResourceSecurity, String vcsWorkspacePathOverride, String vcsScriptBinFolderOverride, String studioPropertyName, String PDToolHomeDir, String propertyFilePath) { String prefix = "createStudioEnableVCSPropertyFile"; // Set the global suppress and debug properties used throughout this class String validOptions = "true,false"; // Get the property from the property file String debug = CommonUtils.getFileOrSystemPropertyValue(studioPropertyName, "DEBUG1"); boolean debug1 = false; if (debug != null && validOptions.contains(debug)) { debug1 = Boolean.valueOf(debug); } if (!vcsIncludeResourceSecurity.equals("true") && !vcsIncludeResourceSecurity.equals("false")) { throw new ApplicationException( "The variable vcsIncludeResourceSecurity may only be set to \"true\" or \"false\""); } if (vcsWorkspacePathOverride != null) vcsWorkspacePathOverride = vcsWorkspacePathOverride.trim(); if (vcsScriptBinFolderOverride != null) vcsScriptBinFolderOverride = vcsScriptBinFolderOverride.trim(); CommonUtils.writeOutput("", prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput("--- INPUT PARAMETERS ----", prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput("", prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput(" vcsIncludeResourceSecurity=" + vcsIncludeResourceSecurity, prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput(" vcsWorkspacePathOverride=[" + vcsWorkspacePathOverride + "] len=" + vcsWorkspacePathOverride.length(), prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput(" vcsScriptFolderOverride=[" + vcsScriptBinFolderOverride + "] len=" + vcsScriptBinFolderOverride.length(), prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput(" studioPropertyName=" + studioPropertyName, prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput(" PDToolHomeDir=" + PDToolHomeDir, prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput(" propertyFilePath=" + propertyFilePath, prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput("", prefix, "-debug1", logger, debug1, false, false); StringBuffer sb = new StringBuffer(); try { Format formatter; Date date = new Date(); formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); String dt = formatter.format(date); String VCS_WORKSPACE_DIR = CommonUtils.extractVariable("", CommonUtils.getFileOrSystemPropertyValue(studioPropertyName, "VCS_WORKSPACE_DIR"), "studio.properties", true); File absFile = new File(VCS_WORKSPACE_DIR); String VCS_WORKSPACE_DIR_ABS = CommonUtils.setCanonicalPath(absFile.getCanonicalPath()); String VCS_PROJECT_ROOT = CommonUtils.extractVariable("", CommonUtils.getFileOrSystemPropertyValue(studioPropertyName, "VCS_PROJECT_ROOT"), "studio.properties", true); // Set the workspace path to the workspace override String vcsWorkspacePath = vcsWorkspacePathOverride; // If the vcs workspace path override is null then derive the path from the studio.properties. if (vcsWorkspacePath == null || vcsWorkspacePath.length() == 0) { vcsWorkspacePath = (VCS_WORKSPACE_DIR_ABS + "/" + VCS_PROJECT_ROOT); System.out.println("VCS_WORKSPACE_DIR=" + VCS_WORKSPACE_DIR_ABS); System.out.println("VCS_PROJECT_ROOT=" + VCS_PROJECT_ROOT); System.out.println("vcsWorkspacePath=[" + vcsWorkspacePath + "]"); } CommonUtils.writeOutput("--- INTERNAL WORKING PARAMETERS ----", prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput("", prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput("VCS_WORKSPACE_DIR=" + VCS_WORKSPACE_DIR_ABS, prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput("VCS_PROJECT_ROOT=" + VCS_PROJECT_ROOT, prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput("pre-mod: vcsWorkspacePath=[" + vcsWorkspacePath + "]", prefix, "-debug1", logger, debug1, false, false); // Change all backslash to forward slashes to normalize the path vcsWorkspacePath = vcsWorkspacePath.replaceAll(Matcher.quoteReplacement("\\\\"), Matcher.quoteReplacement("/")); // System.out.println("vcsWorkspacePath="+vcsWorkspacePath); // Change all backslash to forward slashes to normalize the path vcsWorkspacePath = vcsWorkspacePath.replaceAll(Matcher.quoteReplacement("\\"), Matcher.quoteReplacement("/")); // System.out.println("vcsWorkspacePath="+vcsWorkspacePath); // Create a double backslash for paths vcsWorkspacePath = vcsWorkspacePath.replaceAll(Matcher.quoteReplacement("/"), Matcher.quoteReplacement("\\\\")); // System.out.println("vcsWorkspacePath="+vcsWorkspacePath); // Add \ in front of the C: so it will be C\: if (!vcsWorkspacePath.contains("\\:")) vcsWorkspacePath = vcsWorkspacePath.replaceAll(Matcher.quoteReplacement(":"), Matcher.quoteReplacement("\\:")); // System.out.println("vcsWorkspacePath="+vcsWorkspacePath); // Change C\\: to C\: if (vcsWorkspacePath.contains("\\\\:")) vcsWorkspacePath = vcsWorkspacePath.replaceAll(Matcher.quoteReplacement("\\\\:"), Matcher.quoteReplacement("\\:")); // System.out.println("vcsWorkspacePath="+vcsWorkspacePath); // System.out.println("vcsWorkspacePath=["+vcsWorkspacePath+"]"); CommonUtils.writeOutput("post-mod: vcsWorkspacePath=[" + vcsWorkspacePath + "]", prefix, "-debug1", logger, debug1, false, false); // If the vcs script bin folder name override is null then derive the path from the default /bin location. String vcsScriptFolder = (PDToolHomeDir + "/bin"); if (vcsScriptBinFolderOverride != null && vcsScriptBinFolderOverride.length() > 0) vcsScriptFolder = (PDToolHomeDir + "/" + vcsScriptBinFolderOverride); CommonUtils.writeOutput("pre-mod: vcsScriptFolder=[" + vcsScriptFolder + "]", prefix, "-debug1", logger, debug1, false, false); // System.out.println("vcsScriptFolder="+vcsScriptFolder); // Change all backslash to forward slashes to normalize the path vcsScriptFolder = vcsScriptFolder.replaceAll(Matcher.quoteReplacement("\\\\"), Matcher.quoteReplacement("/")); // System.out.println("vcsScriptFolder="+vcsScriptFolder); // Change all backslash to forward slashes to normalize the path vcsScriptFolder = vcsScriptFolder.replaceAll(Matcher.quoteReplacement("\\"), Matcher.quoteReplacement("/")); // System.out.println("vcsScriptFolder="+vcsScriptFolder); // Create a double backslash for paths vcsScriptFolder = vcsScriptFolder.replaceAll(Matcher.quoteReplacement("/"), Matcher.quoteReplacement("\\\\")); // Add \ in front of the C: so it will be C\: if (!vcsScriptFolder.contains("\\:")) vcsScriptFolder = vcsScriptFolder.replaceAll(Matcher.quoteReplacement(":"), Matcher.quoteReplacement("\\:")); // System.out.println("vcsScriptFolder="+vcsScriptFolder); // Change C\\: to C\: if (vcsScriptFolder.contains("\\\\:")) vcsScriptFolder = vcsScriptFolder.replaceAll(Matcher.quoteReplacement("\\\\:"), Matcher.quoteReplacement("\\:")); // System.out.println("vcsScriptFolder="+vcsScriptFolder); // System.out.println("vcsScriptFolder=["+vcsScriptFolder+"]"); CommonUtils.writeOutput("post-mod: vcsScriptFolder=[" + vcsScriptFolder + "]", prefix, "-debug1", logger, debug1, false, false); sb.append("# Generated by ExecutePDToolStudio.bat\n"); sb.append("# " + dt + "\n"); sb.append("vcsIncludeResourceSecurity=" + vcsIncludeResourceSecurity + "\n"); sb.append("vcsScriptFolder=" + vcsScriptFolder + "\n"); sb.append("vcsWorkspacePath=" + vcsWorkspacePath + "\n"); sb.append("enableVCS=true" + "\n"); } catch (Exception e) { throw new ValidationException(e.getMessage(), e); } try { Writer out = new OutputStreamWriter(new FileOutputStream(propertyFilePath)); out.write(sb.toString()); out.flush(); String fileContents = CommonUtils.getFileAsString(propertyFilePath); System.out.println(""); System.out.println(""); System.out.println( "-----------------------------------------------------------------------------------------------------"); System.out.println("Property File Contents For [" + propertyFilePath + "]"); System.out.println( "-----------------------------------------------------------------------------------------------------"); System.out.println(fileContents); System.out.println(""); CommonUtils.writeOutput("Property File Contents For [" + propertyFilePath + "]", prefix, "-debug1", logger, debug1, false, false); CommonUtils.writeOutput(fileContents, prefix, "-debug1", logger, debug1, false, false); } catch (FileNotFoundException e) { logger.error("Could not wirte to property file " + propertyFilePath, e); throw new ValidationException(e.getMessage(), e); } catch (IOException e) { logger.error("Could not wirte to property file " + propertyFilePath, e); throw new ValidationException(e.getMessage(), e); } }
From source file:org.springframework.integration.sftp.outbound.SftpServerOutboundTests.java
@Test @SuppressWarnings("unchecked") public void testInt3172LocalDirectoryExpressionMGETRecursiveFiltered() { String dir = "sftpSource/"; this.inboundMGetRecursiveFiltered.send(new GenericMessage<Object>(dir + "*")); Message<?> result = this.output.receive(1000); assertNotNull(result);/*from www . j a va 2 s . c om*/ List<File> localFiles = (List<File>) result.getPayload(); // should have filtered sftpSource2.txt assertEquals(2, localFiles.size()); for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir)); } assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir + "subSftpSource")); }
From source file:org.bonitasoft.platform.setup.command.configure.BundleConfigurator.java
protected static String getDatabaseConnectionUrlForPropertiesFile(DatabaseConfiguration configuration) { String url = getDatabaseConnectionUrl(configuration); if (H2.equals(configuration.getDbVendor())) { url = StringEscapeUtils.escapeJava(url); }//from w w w .j a v a 2s . c o m return Matcher.quoteReplacement(url); }