List of usage examples for java.util.regex Matcher quoteReplacement
public static String quoteReplacement(String s)
From source file:com.mongosqlmigrator.harsha.sql.DocBuilder.java
public Map<String, Object> getFields(Map<String, Object> firstRow, ResultSet rs, Entity entity, Map<String, Object> entityMap, Map<String, Object> rootEntityMap) throws SQLException { entityMap = new HashMap<String, Object>(); if (entity.allAttributes.get(MULTI_VALUED) != null && entity.allAttributes.get(MULTI_VALUED).equalsIgnoreCase("true")) { getMultiValuedEntity(rs, entity, rootEntityMap); } else if (firstRow != null) { getSingleValuedEntity(firstRow, rs, entity, entityMap); }// w w w . j a v a 2 s .c o m if (entity.entities != null) { Entity subEntity = null; String query = "", aparam = ""; for (Iterator<Entity> iterator = entity.entities.iterator(); iterator.hasNext();) { subEntity = (Entity) iterator.next(); subLevel = subConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); query = subEntity.allAttributes.get("query"); m = p.matcher(query); aparam = ""; try { log.info("Parameter Map is: " + params); while (m.find()) { aparam = query.substring(m.start() + 2, m.end() - 1); query = query.replaceAll("(\\$\\{" + aparam + "\\})", Matcher.quoteReplacement(StringEscapeUtils.escapeSql(params.get(aparam)))); m = p.matcher(query); } } catch (Exception e) { e.printStackTrace(); } resultSet = subLevel.executeQuery(query); if (resultSet.next()) { subEntityData = getFields(processor.toMap(resultSet), resultSet, subEntity, null, entityMap); if (subEntityData.size() > 0) entityMap.put(subEntity.name, subEntityData); } resultSet.close(); subLevel.close(); } } return entityMap; }
From source file:org.springframework.integration.dsl.test.ftp.FtpTests.java
@Test @SuppressWarnings("unchecked") public void testFtpMgetFlow() { String dir = "ftpSource/"; this.ftpMgetInputChannel.send(new GenericMessage<>(dir + "*")); Message<?> result = this.remoteFileOutputChannel.receive(1000); assertNotNull(result);/*w w w . ja va2s . c om*/ List<File> localFiles = (List<File>) result.getPayload(); // should have filtered ftpSource2.txt assertEquals(2, localFiles.size()); for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), Matchers.containsString(dir)); } assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), Matchers.containsString(dir + "subFtpSource")); }
From source file:org.ops4j.effluence.xar.XarExporter.java
private String buildPageTitle(String spaceKey, Page page) { String title = page.getTitle(); title = title.replaceAll("\\.", Matcher.quoteReplacement("\\.")); return String.format("%s.%s", spaceKey, title); }
From source file:orange.save.export.sql.DocBuilder.java
public Map<String, Object> getFields(Map<String, Object> firstRow, ResultSet resultSet, Entity entity, Map<String, Object> entityMap, Map<String, Object> rootEntityMap) throws SQLException { entityMap = new HashMap<String, Object>(); if (entity.allAttributes.get(MULTI_VALUED) != null && entity.allAttributes.get(MULTI_VALUED).equalsIgnoreCase("true")) { getMultiValuedEntity(resultSet, entity, rootEntityMap); } else if (firstRow != null) { getSingleValuedEntity(firstRow, resultSet, entity, entityMap); }/*from w ww.j ava 2 s. c om*/ if (entity.entities != null) { Entity subEntity = null; String query = ""; String aparam = ""; for (Iterator<Entity> iterator = entity.entities.iterator(); iterator.hasNext();) { subEntity = (Entity) iterator.next(); subLevel = subConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); query = subEntity.allAttributes.get("query"); matcher = pattern.matcher(query); aparam = ""; try { log.info("Parameter Map is: " + params); while (matcher.find()) { aparam = query.substring(matcher.start() + 2, matcher.end() - 1); query = query.replaceAll("(\\$\\{" + aparam + "\\})", Matcher.quoteReplacement(StringEscapeUtils.escapeSql(params.get(aparam)))); matcher = pattern.matcher(query); } } catch (Exception e) { e.printStackTrace(); } this.resultSet = subLevel.executeQuery(query); if (this.resultSet.next()) { subEntityData = getFields(processor.toMap(this.resultSet), this.resultSet, subEntity, null, entityMap); if (subEntityData.size() > 0) entityMap.put(subEntity.name, subEntityData); } this.resultSet.close(); subLevel.close(); } } return entityMap; }
From source file:org.entando.edo.builder.TestBuilderNoPlugin.java
@Test public void test_Service_Api_Xml() throws IOException { String commonPath = "src/main/resources/api/sandbox".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(1, actualFiles.size()); this.compareFiles(actualFiles); }
From source file:org.flowerplatform.codesync.code.javascript.adapter.JavaScriptFileModelAdapter.java
/** * Loads children templates as well, because we can't allow overlapping edits. * @author Mariana Gheorghe//from w w w. j ava 2 s.c om * @author Cristina Constantinescu */ private String loadTemplate(RegExAstNode node) { String template = null; // first find the template to use try { URL url = CodeSyncCodeJavascriptPlugin.getInstance().getBundleContext().getBundle() .getResource("templates/" + node.getType() + ".tpl"); File file = new File(FileLocator.resolve(url).toURI()); template = FileUtils.readFileToString(file); } catch (IOException | URISyntaxException e) { throw new RuntimeException("Template does not exist", e); } // replace the parameters with their values from the node for (RegExAstNodeParameter parameter : node.getParameters()) { template = template.replaceAll("@" + parameter.getName(), Matcher.quoteReplacement(parameter.getValue())); } // load children templates Map<String, Boolean> firstChild = new HashMap<String, Boolean>(); for (RegExAstNode child : getChildrenWithTemplate(node, new ArrayList<RegExAstNode>())) { String childTemplate = loadTemplate(child); String childType = getChildType(child); if (childType != null) { int childInsertPoint = template.indexOf("<!-- children-insert-point " + childType + " -->"); if (childInsertPoint == -1) { childInsertPoint = template.indexOf("// children-insert-point " + childType); } if (childInsertPoint == -1) { throw new RuntimeException("RegExAstNode " + getKeyFeatureValue(node) + " of type " + node.getType() + " does not accept children of type " + childType); } boolean isFirstChildAdded = firstChild.get(childType) == null; childTemplate = getIndentTemplate(template, childInsertPoint, childTemplate, isFirstChildAdded); if (!isFirstChildAdded) { String codeSyncType = child.getType(); CodeSyncElementDescriptor descriptor = CodeSyncPlugin.getInstance() .getCodeSyncElementDescriptor(codeSyncType); childTemplate = (descriptor.getNextSiblingSeparator() != null ? descriptor.getNextSiblingSeparator() : "") + '\n' + childTemplate; } template = template.substring(0, childInsertPoint) + childTemplate + template.substring(childInsertPoint); firstChild.put(childType, false); } } return template; }
From source file:com.arrow.acn.client.api.DeviceApi.java
/** * Sends GET request to obtain parameters of device specified by its * {@code hid}// w w w. ja va 2 s. c o m * * @param hid * {@link String} representing specific device * * @return {@link DeviceModel} containing device parameters * * @throws AcnClientException * if request failed */ public DeviceModel findByHid(String hid) { String method = "findByHid"; try { URI uri = buildUri(PATTERN.matcher(FIND_BY_HID_URL).replaceAll(Matcher.quoteReplacement(hid))); DeviceModel result = execute(new HttpGet(uri), DeviceModel.class); log(method, result); return result; } catch (Throwable e) { logError(method, e); throw new AcnClientException(method, e); } }
From source file:org.nuxeo.theme.html.servlets.Resources.java
protected void doProcess(final HttpServletRequest request, final HttpServletResponse response) throws IOException { final String pathInfo = request.getPathInfo(); if (pathInfo == null) { return;/*from w w w .ja va2 s. com*/ } final Matcher m = pathPattern.matcher(pathInfo); if (!m.matches()) { log.error(String.format("Invalid resource path: %s", pathInfo)); return; } final TypeRegistry typeRegistry = Manager.getTypeRegistry(); final ThemeManager themeManager = Manager.getThemeManager(); String contentType = null; String resourceSuffix = null; final List<String> resourceNames = Arrays.asList(m.group(1).split(",")); for (String resourceName : resourceNames) { String previousContentType = contentType; if (resourceName.endsWith(".js")) { contentType = "text/javascript"; resourceSuffix = ".js"; } else if (resourceName.endsWith(".css")) { contentType = "text/css"; resourceSuffix = ".css"; } else if (resourceName.endsWith(".json")) { contentType = "text/json"; resourceSuffix = ".json"; } if (contentType == null) { log.error("Resource names must end with .js, .css or .json: " + pathInfo); return; } if (previousContentType != null && !contentType.equals(previousContentType)) { log.error("Combined resources must be of the same type: " + pathInfo); return; } } response.addHeader("content-type", contentType); // cache control final String applicationPath = request.getParameter("path"); if (applicationPath != null) { ApplicationType application = (ApplicationType) Manager.getTypeRegistry().lookup(TypeFamily.APPLICATION, applicationPath); if (application != null) { Utils.setCacheHeaders(response, application.getResourceCaching()); } } StringBuilder text = new StringBuilder(); String basePath = request.getParameter("basepath"); // plug additional resources for this page List<String> allResourceNames = new ArrayList<String>(); allResourceNames.addAll(themeManager.getOrderedResourcesAndDeps(resourceNames)); for (String resourceName : allResourceNames) { if (!resourceName.endsWith(resourceSuffix)) { continue; } final OutputStream out = new ByteArrayOutputStream(); String source = themeManager.getResource(resourceName); if (source == null) { ResourceType resource = (ResourceType) typeRegistry.lookup(TypeFamily.RESOURCE, resourceName); if (resource == null) { log.error(String.format("Resource not registered %s.", resourceName)); continue; } writeResource(resource, out); source = out.toString(); if (resourceName.endsWith(".js")) { // do not shrink the script when Dev mode is enabled if (resource.isShrinkable() && !Framework.isDevModeSet()) { try { source = JSUtils.compressSource(source); } catch (ThemeException e) { log.warn("failed to compress javascript source: " + resourceName); } } } else if (resourceName.endsWith(".css")) { // fix CSS url(...) declarations; String cssContextPath = resource.getContextPath(); if (cssContextPath != null) { source = CSSUtils.expandPartialUrls(source, cssContextPath); } // expands system variables source = Framework.expandVars(source); // expand ${basePath} source = source.replaceAll("\\$\\{basePath\\}", Matcher.quoteReplacement(basePath)); // also expand ${org.nuxeo.ecm.contextPath} source = source.replaceAll("\\$\\{org.nuxeo.ecm.contextPath\\}", Matcher.quoteReplacement(basePath)); // do not shrink the CSS when Dev mode is enabled if (resource.isShrinkable() && !Framework.isDevModeSet()) { try { source = CSSUtils.compressSource(source); } catch (ThemeException e) { log.warn("failed to compress CSS source: " + resourceName); } } } // do not cache the resource when Dev mode is enabled if (!Framework.isDevModeSet()) { themeManager.setResource(resourceName, source); } } text.append(source); if (out != null) { out.close(); } } boolean supportsGzip = Utils.supportsGzip(request); OutputStream os = response.getOutputStream(); BufferingServletOutputStream.stopBuffering(os); if (supportsGzip) { response.setHeader("Content-Encoding", "gzip"); // Needed by proxy servers response.setHeader("Vary", "Accept-Encoding"); os = new GZIPOutputStream(os); } try { os.write(text.toString().getBytes()); os.close(); } catch (IOException e) { Throwable cause = e.getCause(); if (cause != null && "Broken pipe".equals(cause.getMessage())) { log.debug("Swallowing: " + e); } else { throw e; } } log.debug( String.format("Served resource(s): %s %s", pathInfo, supportsGzip ? "with gzip compression" : "")); }
From source file:org.demo.workflow.integration.Helper.java
public static String replaceTokensInURL(String url, String token, String value) { return url.replaceFirst("\\{" + token + "\\}", Matcher.quoteReplacement(value)); }
From source file:org.archive.modules.CrawlMetadata.java
public String getUserAgent() { String userAgent = getUserAgentTemplate(); String contactURL = getOperatorContactUrl(); userAgent = userAgent.replaceFirst("@OPERATOR_CONTACT_URL@", contactURL); userAgent = userAgent.replaceFirst("@VERSION@", Matcher.quoteReplacement(ArchiveUtils.VERSION)); return userAgent; }