List of usage examples for org.apache.commons.lang.text StrBuilder replaceAll
public StrBuilder replaceAll(StrMatcher matcher, String replaceStr)
From source file:com.archivas.logging.FileHandler.java
protected static String buildPattern(String pattern) { String retval;/*from ww w . j a v a 2 s . c o m*/ if (pattern == null) { return null; } StrBuilder newPattern = new StrBuilder(pattern); String applicationHomeDir = System.getProperty("application_home_dir"); String userHomeDir = System.getProperty("user.home"); String tmpDir = System.getProperty("java.io.tmpdir"); if (tmpDir == null) { tmpDir = userHomeDir; } if (applicationHomeDir != null) { newPattern = newPattern.replaceAll("%a", applicationHomeDir); } retval = newPattern.toString(); // ensure that the log directory exists // Replace the known variables that are common in directories so we can create the dir. newPattern = newPattern.replaceAll("%t", tmpDir); newPattern = newPattern.replaceAll("%h", userHomeDir); String logPath = FileUtil.getPath(newPattern.toString()); FileUtil.mkdirs(logPath); return retval; }
From source file:com.opengamma.analytics.example.coupledfokkerplank.CoupledFokkerPlankExample.java
public static void runCoupledFokkerPlank(PrintStream out) throws FileNotFoundException, IOException { final ExtendedCoupledFiniteDifference solver = new ExtendedCoupledFiniteDifference(0.5); final int tNodes = 50; final int xNodes = 150; final MeshingFunction timeMesh = new ExponentialMeshing(0, T, tNodes, 5.0); final MeshingFunction spaceMesh = new HyperbolicMeshing(LOWER.getLevel(), UPPER.getLevel(), SPOT, xNodes, 0.01);/*from w w w .j a v a 2 s. co m*/ final double[] timeGrid = new double[tNodes]; for (int n = 0; n < tNodes; n++) { timeGrid[n] = timeMesh.evaluate(n); } final double[] spaceGrid = new double[xNodes]; for (int i = 0; i < xNodes; i++) { spaceGrid[i] = spaceMesh.evaluate(i); } final PDEGrid1D grid = new PDEGrid1D(timeGrid, spaceGrid); final PDEResults1D[] res = solver.solve(DATA1, DATA2, grid, LOWER, UPPER, LOWER, UPPER, null); final PDEFullResults1D res1 = (PDEFullResults1D) res[0]; final PDEFullResults1D res2 = (PDEFullResults1D) res[1]; // output in JSON format without using a JSON library to save dependencies StrBuilder buf = new StrBuilder(2048).append('{'); ByteArrayOutputStream state_1_stream = new ByteArrayOutputStream(); PrintStream state_1_out = new PrintStream(state_1_stream, true); PDEUtilityTools.printSurface("State 1 density", res1, state_1_out); state_1_out.close(); buf.append("\"state_1_data\":\"").append(state_1_stream.toString()).append("\","); ByteArrayOutputStream state_2_stream = new ByteArrayOutputStream(); PrintStream state_2_out = new PrintStream(state_2_stream, true); PDEUtilityTools.printSurface("State 2 density", res2, state_2_out); state_2_out.close(); buf.append("\"state_2_data\":\"").append(state_2_stream.toString()).append("\"}"); buf.replaceAll("\t", "\\t").replaceAll("\r\n", "\\r\\n").replaceAll("\n", "\\n"); out.print(buf.toString()); }
From source file:org.youtestit.core.controllers.createProject.AbstractCreateDocument.java
/** * Allow to generate path./*from w ww. j av a 2 s . c o m*/ * * @return path String representation */ protected String generatePath(final String title) { final StrBuilder result = new StrBuilder(); result.append(parentPath); if (!parentPath.endsWith(PATH_SPLIT)) { result.append(PATH_SPLIT); } final StrBuilder projectPath = new StrBuilder(); projectPath.append(Normalizer.normalize(title, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "")); projectPath.replaceAll(" ", "_"); for (String item : TO_REPLACE) { projectPath.replaceAll(item, "-"); } result.append(projectPath.toString()); return result.toString().trim(); }
From source file:tvbrowser.core.search.AbstractSearcher.java
/** * get the searchable text for all given program fields contained in this * program//from w w w . j a v a 2 s. com * * @param prog * @param fieldArr * @return concatenated string for use in regex search */ private String getProgramFieldsText(Program prog, ProgramFieldType[] fieldArr) { if (fieldArr.length == 1) { ProgramFieldType fieldType = fieldArr[0]; if (fieldType.getFormat() == ProgramFieldType.TEXT_FORMAT) { return prog.getTextField(fieldType); } else if (fieldType.getFormat() == ProgramFieldType.INT_FORMAT) { return prog.getIntFieldAsString(fieldType); } else if (fieldType.getFormat() == ProgramFieldType.TIME_FORMAT) { if (fieldType == ProgramFieldType.START_TIME_TYPE) { return prog.getTimeString(); } else if (fieldType == ProgramFieldType.END_TIME_TYPE) { return prog.getEndTimeString(); } else { return prog.getTimeFieldAsString(fieldType); } } } StrBuilder buffer = new StrBuilder(); for (ProgramFieldType fieldType : fieldArr) { // Get the field value as String String value = null; if (fieldType != null) { if (fieldType.getFormat() == ProgramFieldType.TEXT_FORMAT) { value = prog.getTextField(fieldType); } else if (fieldType.getFormat() == ProgramFieldType.INT_FORMAT) { value = prog.getIntFieldAsString(fieldType); } else if (fieldType.getFormat() == ProgramFieldType.TIME_FORMAT) { if (fieldType == ProgramFieldType.START_TIME_TYPE) { value = prog.getTimeString(); } else if (fieldType == ProgramFieldType.END_TIME_TYPE) { value = prog.getEndTimeString(); } else { value = prog.getTimeFieldAsString(fieldType); } } } if (value != null) { buffer.append(value).append(' '); } } /* Remove special characters */ if (mReplaceSpCh) { buffer.replaceAll("\\p{Punct}", ";"); } // remove line breaks buffer.replaceAll('\n', ' '); return buffer.trim().toString(); }