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.npower.dm.setup.task.TacItemParser.java
private String trim(String s) { return StringUtils.trim(StringUtils.strip(s, "\"';")); }
From source file:net.bible.android.control.link.UriAnalyzer.java
public boolean analyze(String uri) { // check for urls like gdef:01234 String protocol;/*from ww w . ja v a 2 s.co m*/ String ref; // split the prefix from the book if (!uri.contains(":")) { protocol = Constants.BIBLE_PROTOCOL; ref = uri; } else { String[] uriTokens = uri.split(":"); protocol = uriTokens[0]; ref = uriTokens[1]; } // Doc type if (Constants.SWORD_PROTOCOL.equals(protocol)) { docType = DocType.SPECIFIC_DOC; } else if (Constants.BIBLE_PROTOCOL.equals(protocol)) { docType = DocType.BIBLE; } else if (Constants.GREEK_DEF_PROTOCOL.equals(protocol)) { docType = DocType.GREEK_DIC; } else if (Constants.HEBREW_DEF_PROTOCOL.equals(protocol)) { docType = DocType.HEBREW_DIC; } else if (Constants.ROBINSON_GREEK_MORPH_PROTOCOL.equals(protocol)) { docType = DocType.ROBINSON; } else if (Constants.ALL_GREEK_OCCURRENCES_PROTOCOL.equals(protocol)) { docType = DocType.ALL_GREEK; } else if (Constants.ALL_HEBREW_OCCURRENCES_PROTOCOL.equals(protocol)) { docType = DocType.ALL_HEBREW; } else { // not a valid Strongs Uri return false; } // Document if (StringUtils.isEmpty(ref)) { return false; } // remove the first 2 slashes from the url e.g. //module/key ref = StringUtils.strip(ref, "/"); if (!ref.contains("/")) { key = ref; } else { int firstSlash = ref.indexOf("/"); book = ref.substring(0, firstSlash); // handle uri like sword://Bible/John.17.11 found in Calvin's commentary avoiding any attempt to find a book named Bible that will fail if (Constants.BIBLE_PROTOCOL.equalsIgnoreCase(book)) { docType = DocType.BIBLE; } // safe to grab after slash because slash can't be on end due to above strip("/") key = ref.substring(firstSlash + 1); } // handled this url (or at least attempted to) return true; }
From source file:de.shadowhunt.maven.plugins.packageinfo.PackageInfoPlugin.java
static String path2PackageName(final String path) { final String strip = StringUtils.strip(path, File.separator); return strip.replace(File.separatorChar, '.'); }
From source file:cz.muni.fi.lessappcache.parser.modules.FilterModule.java
private List<String> loadFilter(String line, Path context) throws FilterException, FilterExecutionException { List<String> output = new ArrayList<>(); String[] split = line.split("\\s+"); for (int i = 0; i < split.length; i++) { split[i] = StringUtils.strip(split[i], "\"\'"); }//ww w .j av a 2s . co m //singleton FilterFactory to ensure that each filter has only one instance to support variables and so on in the future Filter filterInstance = FilterFactory.getFilterInstance(split[0]); output.addAll(filterInstance.execute(split, context)); return output; }
From source file:au.com.permeance.liferay.portlet.patchingtoolinfo.util.StringHelper.java
/** * Strips chars from input List of String lines and returns new List of String lines. * // w ww . jav a2s. c o m * @param lines input List of String lines * @param stripChars chars to strip * @return List of String lines with mathing chars stripped * * @see StringUtils#strip(String,String) */ public static List<String> stripStringLineList(List<String> lines, String stripChars) { List<String> newLines = new ArrayList<String>(); if (lines != null) { for (String line : lines) { String newLine = StringUtils.strip(line, stripChars); newLines.add(newLine); } } return newLines; }
From source file:com.pinterest.secor.uploader.Uploader.java
private void uploadFiles(TopicPartition topicPartition) throws Exception { long committedOffsetCount = mOffsetTracker.getTrueCommittedOffsetCount(topicPartition); long lastSeenOffset = mOffsetTracker.getLastSeenOffset(topicPartition); String stripped = StringUtils.strip(mConfig.getZookeeperPath(), "/"); final String lockPath = Joiner.on("/").skipNulls().join("", stripped.isEmpty() ? null : stripped, "secor", "locks", topicPartition.getTopic(), topicPartition.getPartition()); mZookeeperConnector.lock(lockPath);// w w w. j av a 2s .c om try { // Check if the committed offset has changed. long zookeeperComittedOffsetCount = mZookeeperConnector.getCommittedOffsetCount(topicPartition); if (zookeeperComittedOffsetCount == committedOffsetCount) { LOG.info("uploading topic {} partition {}", topicPartition.getTopic(), topicPartition.getPartition()); // Deleting writers closes their streams flushing all pending data to the disk. mFileRegistry.deleteWriters(topicPartition); Collection<LogFilePath> paths = mFileRegistry.getPaths(topicPartition); List<Handle<?>> uploadHandles = new ArrayList<Handle<?>>(); for (LogFilePath path : paths) { uploadHandles.add(mUploadManager.upload(path)); } for (Handle<?> uploadHandle : uploadHandles) { uploadHandle.get(); } mFileRegistry.deleteTopicPartition(topicPartition); mZookeeperConnector.setCommittedOffsetCount(topicPartition, lastSeenOffset + 1); mOffsetTracker.setCommittedOffsetCount(topicPartition, lastSeenOffset + 1); } } finally { mZookeeperConnector.unlock(lockPath); } }
From source file:com.yolodata.tbana.hadoop.mapred.util.CSVReader.java
protected void foundDelimiter(StringBuffer sb, List<Text> values, boolean takeDelimiterOut) throws UnsupportedEncodingException { Text text = new Text(); String val = (takeDelimiterOut) ? sb.substring(0, sb.length() - separator.length()) : sb.toString(); val = StringUtils.strip(val, "\n"); val = StringUtils.strip(val, delimiter); text.set(val); values.add(text);//w ww. ja v a 2s .c o m sb.setLength(0); }
From source file:com.jaspersoft.jasperserver.war.action.GenericActionModelBuilder.java
/** * Same as GenericActionModelSupport.getClientActionModelDocument but removes leasing '{' and trailing '}' and escapes the string for JavaScript, * so that it could be used as part of complicated menu-generation sequence like in DefaultJasperViewerState.jsp * @return//w w w.jav a2 s. c om * @throws Exception */ public static String getEmbeddableActionModelDocument(String modelName) throws Exception { GenericActionModelSupport support = new GenericActionModelSupport(modelName, GenericActionModelBuilder.actionModelBuilder.messages); String data = support.getClientActionModelDocument(); if (StringUtils.isEmpty(data)) return data; data = StringUtils.strip(data, "{}"); return data; }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.AuthorizationFileParser.java
private Principal parsePrincipal() throws AuthorizationSyntaxParseException, IOException { String principal = ats.nextUsefulToken(); String className = ats.nextUsefulToken(); String roleName = ats.nextUsefulToken(); if (principal == null || !principal.toLowerCase().equals("principal")) { throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", principal syntax error"); }/*from w ww . j av a 2 s .c o m*/ if (className == null) { throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", className is null"); } if (roleName == null) { throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", roleName is null"); } else { roleName = StringUtils.strip(roleName, "\""); roleName = roleName.replace("*", "All"); } try { Class<?> clazz = Class.forName(className); return ((Principal) clazz.getDeclaredConstructor(String.class).newInstance(roleName)); } catch (ClassNotFoundException e) { throw new AuthorizationSyntaxParseException( "Line " + ats.getLineNum() + ", ClassNotFoundException, " + e.getMessage()); } catch (Exception e) { throw new AuthorizationSyntaxParseException( "Line " + ats.getLineNum() + ", Exception happens, " + e.getMessage()); } }
From source file:com.pinterest.secor.common.ZookeeperConnector.java
protected String getCommittedOffsetGroupPath() { if (Strings.isNullOrEmpty(mCommittedOffsetGroupPath)) { String stripped = StringUtils.strip(mConfig.getKafkaZookeeperPath(), "/"); mCommittedOffsetGroupPath = Joiner.on("/").skipNulls().join("", stripped.equals("") ? null : stripped, "consumers", mConfig.getKafkaGroup(), "offsets"); }//from w w w . j a v a 2 s . co m return mCommittedOffsetGroupPath; }