List of usage examples for org.apache.commons.lang StringUtils strip
public static String strip(String str, String stripChars)
Strips any of a set of characters from the start and end of a String.
From source file:com.vmware.thinapp.manualmode.server.RequestFactory.java
/** * Create an input mounter.//from w w w . j ava 2 s . c o m * * @param inDS an input datastore instance. * @param inputUncPath UNC path to the input datastore. * @return a new Mounter instance. */ protected Mounter createInputMounter(Datastore inDS, String inputUncPath, DriveLetter driveLetter) { if (inDS == null) { throw new IllegalArgumentException("Input datastore is null"); } // Strip all leading path elements so that joining them doesn't // result in multiple separators which confuses Windows. String server = StringUtils.strip(inDS.getServer(), "/\\"); String share = null; if (StringUtils.isNotEmpty(inDS.getShare())) { share = StringUtils.strip(inDS.getShare(), "/\\"); } String path = null; if (inputUncPath != null) { path = StringUtils.strip(inputUncPath, "/\\"); } String inputUnc = AfUtil.toUNC(server, share, path); log.debug("Input datastore is: {} [UNC:{}]", inDS, inputUnc); return new Mounter(inputUnc, inDS.getUsername(), inDS.getPassword(), driveLetter.driveString()); }
From source file:com.zjy.mongo.util.MongoConfigUtil.java
public static List<MongoClientURI> getMongoURIs(final Configuration conf, final String key) { String raw = conf.get(key);//from w w w .ja v a 2s . c om List<MongoClientURI> result = new LinkedList<MongoClientURI>(); if (raw != null && !raw.trim().isEmpty()) { for (String connectionString : raw.split("mongodb://")) { // Try to be forgiving with formatting. connectionString = StringUtils.strip(connectionString, ", "); if (!connectionString.isEmpty()) { result.add(new MongoClientURI("mongodb://" + connectionString)); } } } return result; }
From source file:com.tesora.dve.sql.parser.InvokeParser.java
private static ParseResult parameterizeAndParse(SchemaContext pc, ParserOptions options, byte[] line, Charset cs) throws ParserException { String singleByteEncoded = PECharsetUtils.getString(line, PECharsetUtils.latin1, false); logParse(pc, singleByteEncoded, null); ListOfPairs<Statement, List<Object>> parameterized = buildParameterizedCommands(singleByteEncoded, cs, pc); ArrayList<Statement> out = new ArrayList<Statement>(); for (Pair<Statement, List<Object>> p : parameterized) { DMLStatement dmls = (DMLStatement) p.getFirst(); String msql = dmls.getSQL(pc, false, true); List<Object> params = p.getSecond(); byte[] modstmt = msql.getBytes(PECharsetUtils.latin1); String orig = PECharsetUtils.getString(modstmt, cs, true); if (orig == null) throw new ParserException(Pass.FIRST, "Unable to parameterize SQL statement to handle characters invalid for character set " + cs.name()); orig = StringUtils.strip(orig, new String(Character.toString(Character.MIN_VALUE))); out.addAll(parse(buildInputState(orig, pc), DEFAULT_PARSER_RULE, options, pc, params, TranslatorInitCallback.INSTANCE).getStatements()); }//www . ja v a 2s . co m return new ParseResult(out, null); }
From source file:com.hpe.application.automation.tools.octane.executor.UFTTestDetectionService.java
private static String getRelativePath(FilePath root, FilePath path) { String testPath = path.getRemote(); String rootPath = root.getRemote(); String relativePath = testPath.replace(rootPath, ""); relativePath = StringUtils.strip(relativePath, windowsPathSplitter + linuxPathSplitter); //we want all paths will be in windows style, because tests are run in windows, therefore we replace all linux splitters (/) by windows one (\) //http://stackoverflow.com/questions/23869613/how-to-replace-one-or-more-in-string-with-just relativePath = relativePath.replaceAll(linuxPathSplitter, windowsPathSplitter + windowsPathSplitter);//str.replaceAll("/", "\\\\"); return relativePath; }
From source file:jos.parser.Parser.java
private Declaration processDeclaration(final boolean isProtocol, String line, final boolean isOptional) { /*// w w w . j a va 2 s . co m * boolean debug = false; if (line.indexOf("6_0") != -1) { debug = true; * } */ if (limit != null) { if (!hasLimitKeyword(line)) { return null; } if (line.indexOf(limit) == -1) { return null; } } final boolean appearance = (line.indexOf("UI_APPEARANCE_SELECTOR") != -1); line = cleanDeclaration(line); if (line.length() == 0) { return null; } final boolean isAbstract = isProtocol && !isOptional; if (line.startsWith("@property")) { if (isAbstract) { gencs.println("\t@Abstract"); } processProperty(line, appearance); return null; } log("PROCESSING: %s", line); boolean isStatic = line.startsWith("+"); int p, q; p = line.indexOf('('); if (p == -1) { return null; } q = line.indexOf(')'); log("->%s\np=%d q-p=%d", line, p, q - p); String retval = null; try { retval = remapType(line.substring(p + 1, p + 1 + q - p - 1)); } catch (StringIndexOutOfBoundsException e) { e.printStackTrace(); } p = line.indexOf(';'); String signature = null; try { signature = StringUtils.strip(line.substring(q + 1, q + 1 + p - q), " ;"); } catch (StringIndexOutOfBoundsException e) { e.printStackTrace(); } log("SIG: %s %d", line, p); final String selector = makeSelector(signature); final String parameters = makeParameters(signature); log("signature: %s", signature); log("selector: %s", selector); return new Declaration(selector, retval, parameters, isAbstract, isStatic, appearance); }
From source file:jos.parser.Parser.java
private void processInterface(final String iface) throws IOException { boolean need_close = iface.indexOf("{") != -1; String[] cols = iface.split("\\s+"); String line;/*from ww w . j a v a 2 s . c o m*/ log("**** %s ", iface); types.add(cols[1]); if (extraAnnotation != null) { gencs.println("/**"); gencs.printf(" * @%s", extraAnnotation); gencs.println(); gencs.println(" */"); } final List<String> baseTypes = new ArrayList<String>(); for (int i = 3; i < cols.length; i++) { final String clazz = StringUtils.strip(cols[i], " ,<>{}"); if (!clazz.isEmpty() && !clazz.equals("NSObject")) { baseTypes.add(clazz); } } if (baseTypes.size() > 0) { gencs.printf("@BaseType("); if (baseTypes.size() > 1) gencs.printf("{"); for (int i = 0; i < baseTypes.size(); i++) { gencs.printf("%s.class", baseTypes.get(i)); if (i != baseTypes.size() - 1) gencs.printf(", "); } if (baseTypes.size() > 1) gencs.printf("}"); gencs.println(")"); } gencs.println("@Register(isWrapper = true)"); gencs.printf("public class %s", cols[1]); if (baseTypes.size() > 0) { gencs.printf(" extends"); for (int i = 0; i < baseTypes.size(); i++) { gencs.printf(" %s", baseTypes.get(i)); if (i != baseTypes.size() - 1) gencs.printf(","); } } gencs.println(" {"); /* * while ((line = r.readLine()) != null && (need_close && * !line.startsWith ("}"))) { if (line.equals("{")) { need_close = true; * } } */ line = r.readLine(); if ("{".equals(line)) { need_close = true; } while (line != null && (need_close && !line.equals("}"))) { line = r.readLine(); } Declarations decl = new Declarations(gencs); while ((line = r.readLine()) != null && !line.startsWith("@end")) { String full = line; while ((line = r.readLine()) != null && !line.startsWith("@end")) { full += line; if (full.indexOf(';') != -1) { full = full.replace('\n', ' '); decl.add(processDeclaration(false, full, false)); full = ""; } } break; } decl.generate(extraAnnotation); gencs.println("}"); gencs.println(); }
From source file:com.tesora.dve.sql.parser.InvokeParser.java
public static PlanningResult buildPlan(SchemaContext pc, byte[] line, Charset cs, String pstmtID) throws PEException { boolean isPrepare = (pstmtID != null); if (pc != null) SchemaContext.threadContext.set(pc); preparse(pc);/*w ww .j a v a2s . com*/ ParserOptions options = ParserOptions.NONE.setDebugLog(true).setResolve().setFailEarly(); if (isPrepare) options = options.setPrepare().setActualLiterals(); PlanningResult result = null; String lineStr = PECharsetUtils.getString(line, cs, true); if (lineStr == null) { // bad characters - not a candidate for caching // if we get this for a prepared stmt, just give up for now if (isPrepare) throw new PEException("Invalid prepare request: bad characters"); ParseResult pr = parameterizeAndParse(pc, options, line, cs); List<Statement> stmts = pr.getStatements(); List<ExecutionPlan> plans = new ArrayList<ExecutionPlan>(); ConnectionValuesMap cvm = new ConnectionValuesMap(); for (Statement s : stmts) { PlanningResult epr = Statement.getExecutionPlan(pc, s, pc.getBehaviorConfiguration(), lineStr, pr.getInputState()); plans.addAll(epr.getPlans()); cvm.take(epr.getValues()); } result = new PlanningResult(plans, cvm, pr.getInputState(), lineStr); } else { lineStr = StringUtils.strip(lineStr, new String(Character.toString(Character.MIN_VALUE))); logParse(pc, lineStr, pstmtID); InputState input = buildInputState(lineStr, pc); if (isPrepare) { if (input.getCommand() == null) throw new PEException( "Prepare stmt is too long (greater than " + input.getThreshold() + " characters)"); result = preparePlan(pc, input, options, pstmtID); } else result = buildPlan(pc, input, options, null); } for (ExecutionPlan ep : result.getPlans()) if (ep.isRoot()) { SqlStatistics.incrementCounter(((RootExecutionPlan) ep).getStatementType()); } return result; }
From source file:jos.parser.Parser.java
private void processProtocol(final String proto) throws IOException { final String[] d = proto.split("[ <>]", -1); String line;// w w w. j a v a 2 s . c om types.add(d[1]); if (extraAnnotation != null) { gencs.println("/**"); gencs.printf(" * @%s", extraAnnotation); gencs.println(); gencs.println(" */"); } final List<String> baseTypes = new ArrayList<String>(); for (int i = 2; i < d.length; i++) { final String clazz = StringUtils.strip(d[i], " ,"); if (!clazz.isEmpty() && !clazz.equals("NSObject")) { baseTypes.add(clazz); } } if (baseTypes.size() > 0) { gencs.printf("@BaseType("); if (baseTypes.size() > 1) gencs.printf("{"); for (int i = 0; i < baseTypes.size(); i++) { gencs.printf("%s.class", baseTypes.get(i)); if (i != baseTypes.size() - 1) gencs.printf(", "); } if (baseTypes.size() > 1) gencs.printf("}"); gencs.println(")"); } gencs.println("@Model"); gencs.println("@Register(isWrapper = true)"); gencs.printf("public class %s extends NSObject", d[1]); if (baseTypes.size() > 0) { for (int i = 0; i < baseTypes.size(); i++) { gencs.printf(", %s", baseTypes.get(i)); } } gencs.println(" {"); boolean optional = false; Declarations decl = new Declarations(gencs); while ((line = r.readLine()) != null && !line.startsWith("@end")) { if (line.startsWith("@optional")) { optional = true; } String full = line; while ((line = r.readLine()) != null && !line.startsWith("@end")) { full += line; if (full.indexOf(';') != -1) { full = full.replace('\n', ' '); decl.add(processDeclaration(true, full, optional)); full = ""; } } if (line.startsWith("@end")) { break; } } decl.generate(extraAnnotation); gencs.println("}"); gencs.println(); }
From source file:eu.europeana.portal2.web.presentation.model.FullDocPage.java
/** * Returns the title of the page/*from ww w. j av a 2 s . c o m*/ * * @return page title */ @Override public String getPageTitle() { StringBuilder title = new StringBuilder(getBaseTitle()); String creator = getShortcutFirstValue("DcCreator"); if (creator != null) { // clean up creator first (..), [..], <..>, {..} creator = creator.replaceAll("[\\<({\\[].*?[})\\>\\]]", ""); // strip , from begin or end creator = StringUtils.strip(creator, ","); // strip spaces creator = StringUtils.trim(creator); if (StringUtils.isNotBlank(creator)) { title.append(" | ").append(creator); } } return StringUtils.left(title.toString(), 250); }
From source file:jos.parser.Parser.java
private void processEnum(String line) { final String[] types = line.split(","); if (types.length < 2) { throw new IllegalStateException(); }/*from ww w.j av a2s . co m*/ final String name = StringUtils.strip(types[1], "){ "); gencs.printf("public enum %s {", name); gencs.println(); try { boolean first = true; while ((line = r.readLine()) != null) { if (line.indexOf("};") != -1) { gencs.println(";"); break; } else if (!first) { gencs.println(","); } else { first = false; } String enumValue = line.split("//")[0]; enumValue = enumValue.split(",")[0].trim(); enumValue = enumValue.split("=")[0].trim(); if (enumValue.startsWith(name)) { enumValue = "@Bind(\"" + enumValue + "\") " + enumValue.substring(name.length()); } gencs.printf("\t%s", enumValue); } } catch (IOException e) { System.err.println("Error parsing '" + line + "': " + e.getMessage()); } gencs.println("}"); gencs.println(); }