List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:com.photon.phresco.framework.actions.applications.Quality.java
private String getTestResultPath(Project project, String testResultFile) throws ParserConfigurationException, SAXException, IOException, TransformerException, PhrescoException { S_LOGGER.debug("Entering Method Quality.getTestDocument(Project project, String testResultFile)"); S_LOGGER.debug("getTestDocument() ProjectInfo = " + project.getProjectInfo()); S_LOGGER.debug("getTestDocument() TestResultFile = " + testResultFile); FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); StringBuilder sb = new StringBuilder(); sb.append(Utility.getProjectHome()); sb.append(project.getProjectInfo().getCode()); if (FUNCTIONAL.equals(testType)) { if (StringUtils.isNotEmpty(projectModule)) { sb.append(File.separatorChar); sb.append(projectModule);// w w w . ja va 2 s .c o m } sb.append(frameworkUtil.getFunctionalReportDir(project.getProjectInfo().getTechnology().getId())); } else if (UNIT.equals(testType)) { if (StringUtils.isNotEmpty(projectModule)) { sb.append(File.separatorChar); sb.append(projectModule); } StringBuilder tempsb = new StringBuilder(sb); if ("javascript".equals(techReport)) { tempsb.append(UNIT_TEST_QUNIT_REPORT_DIR); File file = new File(tempsb.toString()); if (file.isDirectory() && file.list().length > 0) { sb.append(UNIT_TEST_QUNIT_REPORT_DIR); } else { sb.append(UNIT_TEST_JASMINE_REPORT_DIR); } } else { sb.append(frameworkUtil.getUnitReportDir(project.getProjectInfo().getTechnology().getId())); } } else if (LOAD.equals(testType)) { sb.append(frameworkUtil.getLoadReportDir(project.getProjectInfo().getTechnology().getId())); sb.append(File.separator); sb.append(testResultFile); } else if (PERFORMACE.equals(testType)) { String performanceReportDir = frameworkUtil .getPerformanceReportDir(project.getProjectInfo().getTechnology().getId()); Pattern p = Pattern.compile(TEST_DIRECTORY); Matcher matcher = p.matcher(performanceReportDir); if (StringUtils.isNotEmpty(performanceReportDir) && matcher.find()) { performanceReportDir = matcher.replaceAll(testResultsType); } sb.append(performanceReportDir); sb.append(File.separator); sb.append(testResultFile); } // return getDocument(getTestResultFile(sb.toString())); return sb.toString(); }
From source file:com.fujitsu.dc.core.bar.BarFileReadRunner.java
/** * bar/90_contents/{OdataCol_name}?????????????. * @param entryName ??(??)//from w w w . j a va2s . c o m * @param colMap ?Map * @param doneKeys ???OData * @return ?? */ protected boolean isValidODataContents(String entryName, Map<String, DavCmpEsImpl> colMap, List<String> doneKeys) { String odataColPath = ""; for (Map.Entry<String, DavCmpEsImpl> entry : colMap.entrySet()) { if (entryName.startsWith(entry.getKey())) { odataColPath = entry.getKey(); break; } } // OData???? String odataPath = entryName.replaceAll(odataColPath, ""); // bar/90_contents/{OData_collection}??? if (USERDATA_LINKS_JSON.equals(odataPath)) { // 00_$metadata.xml???????? String meatadataPath = odataColPath + METADATA_XML; if (!doneKeys.contains(meatadataPath)) { String message = DcCoreMessageUtils.getMessage("PL-BI-2001"); log.info(message + "entryName: " + entryName); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } // 90_data/?????????? String userDataPath = odataColPath + USERDATA_DIR_NAME + "/"; if (doneKeys.contains(userDataPath)) { String message = DcCoreMessageUtils.getMessage("PL-BI-2001"); log.info(message + "entryName: " + entryName); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } } if (odataPath.startsWith(USERDATA_DIR_NAME + "/")) { // 00_$metadata.xml???????? String meatadataPath = odataColPath + METADATA_XML; if (!doneKeys.contains(meatadataPath)) { String message = DcCoreMessageUtils.getMessage("PL-BI-2001"); log.info(message + "entryName: " + entryName); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } } // bar/90_contents/{OData_collection}/{dirPath}/?? String dirPath = null; Pattern pattern = Pattern.compile("^([^/]+)/.*"); Matcher m = pattern.matcher(odataPath); if (m.matches()) { dirPath = m.replaceAll("$1"); } if (dirPath != null && !dirPath.equals(USERDATA_DIR_NAME)) { // bar/90_contents/{OData_collection}/{dir}/????? String message = DcCoreMessageUtils.getMessage("PL-BI-2001"); log.info(message + "entryName: " + entryName); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } // bar/90_contents/{OData_collection}/90_data/{entity}/{1.json}?? String fileName = null; pattern = Pattern.compile(".*/([^/]+)$"); m = pattern.matcher(odataPath); if (m.matches()) { fileName = m.replaceAll("$1"); } if (fileName != null) { pattern = Pattern.compile("^([0-9]+).json$"); m = pattern.matcher(fileName); if (!m.matches()) { // bar/90_contents/{OData_collection}/{dir}/????? String message = DcCoreMessageUtils.getMessage("PL-BI-2001"); log.info(message + "entryName: " + entryName); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } } return true; }
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * Post Processing single Label file /*from ww w . j a v a 2 s . c o m*/ * and write on OUTLABDIR * @param basename * @throws Exception */ private void convertSingleLabelFile(String basename) throws Exception { String line; String previous, current; String regexp = "\\spau|\\sssil"; //Compile regular expression Pattern pattern = Pattern.compile(regexp); File labDir = new File(getProp(OUTLABDIR)); if (!labDir.exists()) { labDir.mkdir(); } File labelFile = new File(getProp(HTDIR) + File.separator + "tmplab" + File.separator + basename + labExt); if (!labelFile.exists()) { System.err.println("WARNING: " + basename + " label file not created with HTK."); return; } BufferedReader labelIn = new BufferedReader(new InputStreamReader(new FileInputStream(labelFile))); PrintWriter labelOut = new PrintWriter(new FileOutputStream(new File(labDir + "/" + basename + labExt))); previous = labelIn.readLine(); while ((line = labelIn.readLine()) != null) { //Replace all occurrences of pattern in input Matcher matcher = pattern.matcher(line); current = matcher.replaceAll(" _"); if (previous.endsWith("_") && current.endsWith("_")) { previous = current; continue; } labelOut.println(previous); previous = current; } labelOut.println(previous); labelOut.flush(); labelOut.close(); labelIn.close(); }
From source file:org.agnitas.util.AgnUtils.java
public static String replaceHashTags(String hashTagString, Map<String, Object>... replacementMaps) { if (StringUtils.isBlank(hashTagString)) { return hashTagString; } else {/*from w w w. j a v a 2s . co m*/ String returnString = hashTagString; Pattern pattern = Pattern.compile("##([^#]+)##"); Matcher matcher = pattern.matcher(hashTagString); int currentPosition = 0; while (matcher.find(currentPosition)) { int matcherStart = matcher.start(); String tagNameString = matcher.group(1); String[] referenceKeys = tagNameString.split("/"); String replacementValue = null; if (replacementMaps != null) { for (String referenceKey : referenceKeys) { for (Map<String, Object> replacementMap : replacementMaps) { if (replacementMap != null) { Object replacementData = replacementMap.get(referenceKey); if (replacementData != null) { String replacementDataString = replacementData.toString(); if (StringUtils.isNotEmpty(replacementDataString)) { replacementValue = replacementData.toString(); break; } } } } if (replacementValue != null) { break; } } } if (replacementValue == null) { replacementValue = ""; } returnString = matcher.replaceAll(replacementValue); matcher = pattern.matcher(returnString); currentPosition += matcherStart + replacementValue.length(); } return returnString; } }
From source file:com.amalto.workbench.utils.Util.java
/** * Replace the source string by the parameters * /*from ww w .ja va 2 s . co m*/ * @param sourceString the source string with parameters,like : "This is {0} examples for {1}" * @param parameters the parameters used to do the replacement, the key is the index of the parameter, the value is * the content; * @return the string after replacement */ public static String replaceWithParameters(final String sourceString, Map<Integer, String> parameters) { String temp = sourceString; for (Entry<Integer, String> eachId2Content : parameters.entrySet()) { Pattern pattern = Pattern.compile("\\{" + eachId2Content.getKey() + "\\}");//$NON-NLS-1$//$NON-NLS-2$ Matcher matcher = pattern.matcher(temp); temp = matcher.replaceAll(eachId2Content.getValue()); } return temp; }
From source file:com.ichi2.anki.AbstractFlashcardViewer.java
/** * Clean up the correct answer text, so it can be used for the comparison with the typed text * * @param answer The content of the field the text typed by the user is compared to. * @return The correct answer text, with actual HTML and media references removed, and HTML entities unescaped. *///ww w . j a va 2s . com protected String cleanCorrectAnswer(String answer) { if (answer == null || answer.equals("")) { return ""; } answer = answer.trim(); Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(answer)); String answerText = matcher.replaceAll(""); matcher = sBrPattern.matcher(answerText); answerText = matcher.replaceAll("\n"); matcher = Sound.sSoundPattern.matcher(answerText); answerText = matcher.replaceAll(""); return HtmlUtil.nfcNormalized(answerText); }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
private String drawTextSanitizer(String string, int maxEventTextLen) { Matcher m = drawTextSanitizerFilter.matcher(string); string = m.replaceAll(","); int len = string.length(); if (maxEventTextLen <= 0) { string = ""; len = 0;/*from w ww .j av a2 s . c o m*/ } else if (len > maxEventTextLen) { string = string.substring(0, maxEventTextLen); len = maxEventTextLen; } return string.replace('\n', ' '); }
From source file:com.ikanow.infinit.e.api.knowledge.federated.SimpleFederatedQueryEngine.java
private String performImportPythonScript(String importScript, String entityValue, AdvancedQueryPojo query, Boolean isSrcAdmin, LinkedList<String> debugLog) { String modCode = importScript; try {/*www .j a v a 2 s . c o m*/ // Create a return value String fnName = "var" + new ObjectId(); // Pull all the imports, evaluate them outside the security manager Pattern importRegex = Pattern.compile("^\\s*(?:import|from)\\s[^\n]+", Pattern.MULTILINE); Matcher m = importRegex.matcher(importScript); StringBuffer sbImports = new StringBuffer(); while (m.find()) { sbImports.append(m.group()).append('\n'); } if (null != query) { _pyEngine.put("_query", query.toApi()); // full query } if (null != entityValue) { _pyEngine.put("_entityValue", entityValue); // allow either entityValue } _pyEngine.eval(sbImports.toString()); // Logging function if (null != debugLog) { String logName = "log" + new ObjectId(); _pyEngine.put(logName, debugLog); _pyEngine.eval("def ikanow_log(logmsg):\n " + logName + ".add(logmsg)\n\n"); } else { _pyEngine.eval("def ikanow_log(logmsg):\n pass\n\n"); } // Enable SSL everywhere (https://wiki.python.org/jython/NewSocketModule#SSLSupport) //http://tech.pedersen-live.com/2010/10/trusting-all-certificates-in-jython/ //didn't work: http://jython.xhaus.com/installing-an-all-trusting-security-provider-on-java-and-jython/ _pyEngine.eval(IOUtils .toString(SimpleFederatedQueryEngine.class.getResourceAsStream("JythonTrustManager.py"))); // Now run the script modCode = m.replaceAll(""); modCode = modCode.replaceAll("\n([^\n]+)$", "\n" + fnName + " = " + "$1"); if ((null == isSrcAdmin) || !isSrcAdmin) { _scriptingSecurityManager.eval(_pyEngine, modCode); } else { _pyEngine.eval(modCode); } // Get return value Object result = _pyEngine.get(fnName.toString()); //DEBUG if (_DEBUG) _logger.debug("DEB: T1: Return val from script: " + result); if (null == result) { throw new RuntimeException( "Null return from script - final line needs to evaluate expression to return, eg 'response.read()' or 'varname'"); } //TESTED (by hand) return result.toString(); } catch (Exception e) { throw new RuntimeException(e); } catch (Error ee) { throw new RuntimeException(ee); } }
From source file:org.apache.hadoop.hive.ql.QTestUtil.java
private void maskPatterns(Pattern[] patterns, String fname) throws Exception { String maskPattern = "#### A masked pattern was here ####"; String partialMaskPattern = "#### A PARTIAL masked pattern was here ####"; String line;//from ww w. j a va 2s . c o m BufferedReader in; BufferedWriter out; File file = new File(fname); File fileOrig = new File(fname + ".orig"); FileUtils.copyFile(file, fileOrig); in = new BufferedReader(new InputStreamReader(new FileInputStream(fileOrig), "UTF-8")); out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); boolean lastWasMasked = false; boolean partialMaskWasMatched = false; Matcher matcher; while (null != (line = in.readLine())) { if (fsType == FsType.encrypted_hdfs) { for (Pattern pattern : partialReservedPlanMask) { matcher = pattern.matcher(line); if (matcher.find()) { line = partialMaskPattern + " " + matcher.group(0); partialMaskWasMatched = true; break; } } } if (!partialMaskWasMatched) { for (Pair<Pattern, String> pair : patternsWithMaskComments) { Pattern pattern = pair.getLeft(); String maskComment = pair.getRight(); matcher = pattern.matcher(line); if (matcher.find()) { line = matcher.replaceAll(maskComment); partialMaskWasMatched = true; break; } } for (Pattern pattern : patterns) { line = pattern.matcher(line).replaceAll(maskPattern); } } if (line.equals(maskPattern)) { // We're folding multiple masked lines into one. if (!lastWasMasked) { out.write(line); out.write("\n"); lastWasMasked = true; partialMaskWasMatched = false; } } else { out.write(line); out.write("\n"); lastWasMasked = false; partialMaskWasMatched = false; } } in.close(); out.close(); }
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * Get phone sequence from a single feature file * @param basename/*from w w w . ja va2 s.com*/ * @return String * @throws Exception */ private String getLineFromXML(String basename, boolean spause, boolean vpause) throws Exception { String line; String phoneSeq; Matcher matcher; Pattern pattern; StringBuilder alignBuff = new StringBuilder(); //alignBuff.append(basename); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new File(getProp(PROMPTALLOPHONESDIR) + "/" + basename + xmlExt)); XPath xpath = XPathFactory.newInstance().newXPath(); NodeList tokens = (NodeList) xpath.evaluate("//t | //boundary", doc, XPathConstants.NODESET); alignBuff.append(collectTranscription(tokens)); phoneSeq = alignBuff.toString(); pattern = Pattern.compile("pau ssil "); matcher = pattern.matcher(phoneSeq); phoneSeq = matcher.replaceAll("sil "); pattern = Pattern.compile(" ssil pau$"); matcher = pattern.matcher(phoneSeq); phoneSeq = matcher.replaceAll(" sil"); if (!vpause) { /* TODO: Extra code need to write * to maintain minimum number of short sil. * or consider word boundaries as ssil. */ /* * virtual silence on word boundaries * are matched in sp */ pattern = Pattern.compile("vssil"); matcher = pattern.matcher(phoneSeq); phoneSeq = matcher.replaceAll(""); } else { /* * virtual silence on word boundaries * are matched in sp */ pattern = Pattern.compile("vssil"); matcher = pattern.matcher(phoneSeq); phoneSeq = matcher.replaceAll("sp"); } // checking if (!spause) { pattern = Pattern.compile("ssil"); matcher = pattern.matcher(phoneSeq); phoneSeq = matcher.replaceAll(""); } phoneSeq += " ."; pattern = Pattern.compile("\\s+"); matcher = pattern.matcher(phoneSeq); phoneSeq = matcher.replaceAll("\n"); //System.out.println(phoneSeq); return phoneSeq; }