List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:org.apache.zeppelin.socket.NotebookServer.java
private void restoreFolder(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException { String folderId = (String) fromMessage.get("id"); if (folderId == null) { return;//from w w w. ja v a 2 s . c o m } Folder folder = notebook.getFolder(folderId); if (folder != null && folder.isTrash()) { String restoreName = folder.getId().replaceFirst(Folder.TRASH_FOLDER_ID + "/", "").trim(); // if the folder had conflict when it had moved to trash before Pattern p = Pattern.compile("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$"); Matcher m = p.matcher(restoreName); restoreName = m.replaceAll("").trim(); fromMessage.put("name", restoreName); renameFolder(conn, userAndRoles, notebook, fromMessage, "restore"); } }
From source file:io.hops.hopsworks.api.zeppelin.socket.NotebookServerImpl.java
public void restoreFolder(Session conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage, Users user) throws SchedulerException, IOException { String folderId = (String) fromMessage.get("id"); if (folderId == null) { return;//from w ww . java 2s .com } Folder folder = notebook.getFolder(folderId); if (folder != null && folder.isTrash()) { String restoreName = folder.getId().replaceFirst(Folder.TRASH_FOLDER_ID + "/", "").trim(); // if the folder had conflict when it had moved to trash before Pattern p = Pattern.compile("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$"); Matcher m = p.matcher(restoreName); restoreName = m.replaceAll("").trim(); fromMessage.put("name", restoreName); renameFolder(conn, userAndRoles, notebook, fromMessage, "restore", user); } }
From source file:com.photon.phresco.framework.actions.applications.Quality.java
public String performanceTestResultAvail() { S_LOGGER.debug("Entering Method Quality.performanceTestResultAvail()"); try {//from ww w .j a va2 s . c o m ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator(); Project project = administrator.getProject(projectCode); FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); List<String> testResultsTypes = new ArrayList<String>(); testResultsTypes.add("server"); testResultsTypes.add("database"); testResultsTypes.add("webservices"); for (String perType : testResultsTypes) { StringBuilder sb = new StringBuilder(); sb.append(Utility.getProjectHome()); sb.append(project.getProjectInfo().getCode()); String performanceReportDir = frameworkUtil .getPerformanceReportDir(project.getProjectInfo().getTechnology().getId()); if (StringUtils.isNotEmpty(performanceReportDir) && StringUtils.isNotEmpty(perType)) { Pattern p = Pattern.compile("dir_type"); Matcher matcher = p.matcher(performanceReportDir); performanceReportDir = matcher.replaceAll(perType); sb.append(performanceReportDir); } File file = new File(sb.toString()); File[] children = file.listFiles(new XmlNameFileFilter(FILE_EXTENSION_XML)); if (children != null && children.length > 0) { isAtleastOneFileAvail = true; break; } } } catch (Exception e) { S_LOGGER.error("Entered into catch block of Quality.performanceTestResultAvail()" + FrameworkUtil.getStackTraceAsString(e)); } return "success"; }
From source file:com.photon.phresco.framework.actions.applications.Quality.java
@SuppressWarnings("static-access") public String performanceTestResultFiles() { S_LOGGER.debug("Entering Method Quality.performanceTestResultFiles()"); try {/* w w w. j a v a 2s . co m*/ ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator(); Project project = administrator.getProject(projectCode); FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); StringBuilder sb = new StringBuilder(); sb.append(Utility.getProjectHome()); sb.append(project.getProjectInfo().getCode()); String performanceReportDir = frameworkUtil .getPerformanceReportDir(project.getProjectInfo().getTechnology().getId()); S_LOGGER.debug("test type performance test Report directory " + performanceReportDir); if (StringUtils.isNotEmpty(performanceReportDir) && StringUtils.isNotEmpty(testResultsType)) { Pattern p = Pattern.compile("dir_type"); Matcher matcher = p.matcher(performanceReportDir); performanceReportDir = matcher.replaceAll(testResultsType); sb.append(performanceReportDir); } S_LOGGER.debug("test type performance test Report directory & Type " + sb.toString() + " Type " + testResultsType); File file = new File(sb.toString()); File[] children = file.listFiles(new XmlNameFileFilter(FILE_EXTENSION_XML)); QualityUtil util = new QualityUtil(); if (children != null) { util.sortResultFile(children); getHttpRequest().setAttribute(REQ_JMETER_REPORT_FILES, children); } else { getHttpRequest().setAttribute(REQ_ERROR_TESTSUITE, ERROR_TEST_SUITE); } testResultFiles = new ArrayList<String>(); for (File resultFile : children) { if (resultFile.isFile()) { testResultFiles.add(resultFile.getName()); } } } catch (Exception e) { S_LOGGER.error("Entered into catch block of Quality.performanceTestResultFiles()" + FrameworkUtil.getStackTraceAsString(e)); } return "success"; }
From source file:io.personium.core.bar.BarFileReadRunner.java
/** * ????????./*from www . j av a 2 s . c o m*/ * @param zae * @param entryName * @param maxSize * @param doneKeys * @return ???true? */ private boolean isValidFileStructure(ZipArchiveEntry zae, String entryName, long maxSize, List<String> doneKeys) { writeOutputStream(false, CODE_BAR_INSTALL_STARTED, entryName); // ??????? if (!barFileOrder.containsKey(entryName)) { log.info("[" + entryName + "] invalid file"); String message = PersoniumCoreMessageUtils.getMessage("PL-BI-2001"); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } // ????? Pattern formatPattern = Pattern.compile(".*/+([0-9][0-9])_.*"); Matcher formatMatcher = formatPattern.matcher(entryName); String entryIndex = formatMatcher.replaceAll("$1"); if (doneKeys.isEmpty()) { // ?????"00"????? if (!entryIndex.equals("00")) { log.info("bar/00_meta/00_manifest.json is not exsist"); String message = PersoniumCoreMessageUtils.getMessage("PL-BI-2001"); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } } else { String lastEntryName = doneKeys.get(doneKeys.size() - 1); formatMatcher = formatPattern.matcher(lastEntryName); String lastEntryIndex = formatMatcher.replaceAll("$1"); // ?????? if (entryIndex.compareTo(lastEntryIndex) < 0) { log.info("[" + entryName + "] invalid file"); String message = PersoniumCoreMessageUtils.getMessage("PL-BI-2001"); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } } // [400]bar/bar?????? if (zae.getSize() > (long) (maxSize * MB)) { log.info("Bar file entry size too large invalid file [" + entryName + "]"); String message = PersoniumCoreException.BarInstall.BAR_FILE_ENTRY_SIZE_TOO_LARGE .params(zae.getName(), String.valueOf(zae.getSize())).getMessage(); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } return true; }
From source file:io.personium.core.bar.BarFileReadRunner.java
/** * JSON???.//from ww w .j a v a 2 s . c o m * @param entryName ?? * @param inputStream * @return ????true */ private boolean registJsonEntry(String entryName, InputStream inputStream) { JsonParser jp = null; ObjectMapper mapper = new ObjectMapper(); JsonFactory f = new JsonFactory(); try { jp = f.createJsonParser(inputStream); JsonToken token = jp.nextToken(); // JSON?"{" Pattern formatPattern = Pattern.compile(".*/+(.*)"); Matcher formatMatcher = formatPattern.matcher(entryName); String jsonName = formatMatcher.replaceAll("$1"); if (token == JsonToken.START_OBJECT) { if (jsonName.equals(RELATION_JSON) || jsonName.equals(ROLE_JSON) || jsonName.equals(EXTROLE_JSON) || jsonName.equals(LINKS_JSON)) { registJsonEntityData(jp, mapper, jsonName); } else if (jsonName.equals(MANIFEST_JSON)) { manifestJsonValidate(jp, mapper); // Box????? } log.debug(jsonName); } else { throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName); } } catch (PersoniumCoreException e) { // JSON?? writeOutputStream(true, "PL-BI-1004", entryName, e.getMessage()); log.info("PersoniumCoreException" + e.getMessage(), e.fillInStackTrace()); return false; } catch (JsonParseException e) { // JSON?? String message = PersoniumCoreMessageUtils.getMessage("PL-BI-2002"); writeOutputStream(true, "PL-BI-1004", entryName, message); log.info("JsonParseException: " + e.getMessage(), e.fillInStackTrace()); return false; } catch (JsonMappingException e) { // JSON? String message = PersoniumCoreMessageUtils.getMessage("PL-BI-2003"); writeOutputStream(true, "PL-BI-1004", entryName, message); log.info("JsonMappingException: " + e.getMessage(), e.fillInStackTrace()); return false; } catch (Exception e) { String message = PersoniumCoreMessageUtils.getMessage("PL-BI-2000"); writeOutputStream(true, "PL-BI-1004", entryName, message); log.info("Exception: " + e.getMessage(), e.fillInStackTrace()); return false; } return true; }
From source file:com.photon.phresco.framework.actions.applications.Quality.java
public String tstResultFiles() { S_LOGGER.debug("Entering Method Quality.perTstResultFiles()"); try {/*ww w . j av a2 s . c om*/ String testDirPath = null; testResultFiles = new ArrayList<String>(); ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator(); Project project = administrator.getProject(projectCode); FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); StringBuilder sb = new StringBuilder(); sb.append(Utility.getProjectHome()); sb.append(project.getProjectInfo().getCode()); if (StringUtils.isEmpty(settingType)) { testDirPath = frameworkUtil.getLoadReportDir(project.getProjectInfo().getTechnology().getId()); sb.append(testDirPath); } else { testDirPath = frameworkUtil .getPerformanceReportDir(project.getProjectInfo().getTechnology().getId()); if (StringUtils.isNotEmpty(testDirPath) && StringUtils.isNotEmpty(settingType)) { Pattern p = Pattern.compile("dir_type"); Matcher matcher = p.matcher(testDirPath); if (WEBSERVICE.equals(settingType)) { testDirPath = matcher.replaceAll(WEBSERVICES_DIR); } else { testDirPath = matcher.replaceAll(settingType); } sb.append(testDirPath); } } File file = new File(sb.toString()); File[] children = file.listFiles(new XmlNameFileFilter(FILE_EXTENSION_XML)); if (children != null && children.length > 0) { for (File resultFile : children) { if (resultFile.isFile()) { testResultFiles.add(resultFile.getName()); } } } } catch (Exception e) { S_LOGGER.error("Entered into catch block of Quality.perTstResultFiles" + FrameworkUtil.getStackTraceAsString(e)); } return "success"; }
From source file:com.fujitsu.dc.core.bar.BarFileReadRunner.java
/** * ????????./*from w w w.j a v a2s . c om*/ * @param zae * @param entryName * @param maxSize * @param doneKeys * @return ???true? */ private boolean isValidFileStructure(ZipArchiveEntry zae, String entryName, long maxSize, List<String> doneKeys) { writeOutputStream(false, CODE_BAR_INSTALL_STARTED, entryName); // ??????? if (!barFileOrder.containsKey(entryName)) { log.info("[" + entryName + "] invalid file"); String message = DcCoreMessageUtils.getMessage("PL-BI-2001"); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } // ????? Pattern formatPattern = Pattern.compile(".*/+([0-9][0-9])_.*"); Matcher formatMatcher = formatPattern.matcher(entryName); String entryIndex = formatMatcher.replaceAll("$1"); if (doneKeys.isEmpty()) { // ?????"00"????? if (!entryIndex.equals("00")) { log.info("bar/00_meta/00_manifest.json is not exsist"); String message = DcCoreMessageUtils.getMessage("PL-BI-2001"); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } } else { String lastEntryName = doneKeys.get(doneKeys.size() - 1); formatMatcher = formatPattern.matcher(lastEntryName); String lastEntryIndex = formatMatcher.replaceAll("$1"); // ?????? if (entryIndex.compareTo(lastEntryIndex) < 0) { log.info("[" + entryName + "] invalid file"); String message = DcCoreMessageUtils.getMessage("PL-BI-2001"); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } } // [400]bar/bar?????? if (zae.getSize() > (long) (maxSize * MB)) { log.info("Bar file entry size too large invalid file [" + entryName + "]"); String message = DcCoreException.BarInstall.BAR_FILE_ENTRY_SIZE_TOO_LARGE .params(zae.getName(), String.valueOf(zae.getSize())).getMessage(); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } return true; }
From source file:com.fujitsu.dc.core.bar.BarFileReadRunner.java
/** * JSON???./*from www . j a va 2 s . c om*/ * @param entryName ?? * @param inputStream * @return ????true */ private boolean registJsonEntry(String entryName, InputStream inputStream) { JsonParser jp = null; ObjectMapper mapper = new ObjectMapper(); JsonFactory f = new JsonFactory(); try { jp = f.createJsonParser(inputStream); JsonToken token = jp.nextToken(); // JSON?"{" Pattern formatPattern = Pattern.compile(".*/+(.*)"); Matcher formatMatcher = formatPattern.matcher(entryName); String jsonName = formatMatcher.replaceAll("$1"); if (token == JsonToken.START_OBJECT) { if (jsonName.equals(RELATION_JSON) || jsonName.equals(ROLE_JSON) || jsonName.equals(EXTROLE_JSON) || jsonName.equals(LINKS_JSON)) { registJsonEntityData(jp, mapper, jsonName); } else if (jsonName.equals(MANIFEST_JSON)) { manifestJsonValidate(jp, mapper); // Box????? } log.debug(jsonName); } else { throw DcCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName); } } catch (DcCoreException e) { // JSON?? writeOutputStream(true, "PL-BI-1004", entryName, e.getMessage()); log.info("DcCoreException" + e.getMessage(), e.fillInStackTrace()); return false; } catch (JsonParseException e) { // JSON?? String message = DcCoreMessageUtils.getMessage("PL-BI-2002"); writeOutputStream(true, "PL-BI-1004", entryName, message); log.info("JsonParseException: " + e.getMessage(), e.fillInStackTrace()); return false; } catch (JsonMappingException e) { // JSON? String message = DcCoreMessageUtils.getMessage("PL-BI-2003"); writeOutputStream(true, "PL-BI-1004", entryName, message); log.info("JsonMappingException: " + e.getMessage(), e.fillInStackTrace()); return false; } catch (Exception e) { String message = DcCoreMessageUtils.getMessage("PL-BI-2000"); writeOutputStream(true, "PL-BI-1004", entryName, message); log.info("Exception: " + e.getMessage(), e.fillInStackTrace()); return false; } return true; }
From source file:io.personium.core.bar.BarFileReadRunner.java
/** * bar/90_contents/{OdataCol_name}?????????????. * @param entryName ??(??)/* w ww. jav a 2 s .c o m*/ * @param colMap ?Map * @param doneKeys ???OData * @return ?? */ protected boolean isValidODataContents(String entryName, Map<String, DavCmp> colMap, List<String> doneKeys) { String odataColPath = ""; for (Map.Entry<String, DavCmp> 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 = PersoniumCoreMessageUtils.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 = PersoniumCoreMessageUtils.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 = PersoniumCoreMessageUtils.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 = PersoniumCoreMessageUtils.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 = PersoniumCoreMessageUtils.getMessage("PL-BI-2001"); log.info(message + "entryName: " + entryName); writeOutputStream(true, "PL-BI-1004", entryName, message); return false; } } return true; }