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:DataCrawler.OpenAIRE.XMLGenerator.java
public static void main(String[] args) { String text = ""; try {//from www .ja v a 2 s .c om if (args.length < 4) { System.out.println("<command> template_file csv_file output_dir log_file [start_id]"); } // InputStream fis = new FileInputStream("E:/Downloads/result-r-00000"); InputStream fis = new FileInputStream(args[1]); BufferedReader br = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8"))); // String content = new String(Files.readAllBytes(Paths.get("publications_template.xml"))); String content = new String(Files.readAllBytes(Paths.get(args[0]))); Document doc = Jsoup.parse(content, "UTF-8", Parser.xmlParser()); // String outputDirectory = "G:/"; String outputDirectory = args[2]; // PrintWriter logWriter = new PrintWriter(new FileOutputStream("publication.log",false)); PrintWriter logWriter = new PrintWriter(new FileOutputStream(args[3], false)); Element objectId = null, title = null, publisher = null, dateofacceptance = null, bestlicense = null, resulttype = null, originalId = null, originalId2 = null; boolean start = true; // String startID = "dedup_wf_001::207a098867b64f3b5af505fa3aeecd24"; String startID = ""; if (args.length >= 5) { start = false; startID = args[4]; } String previousText = ""; while ((text = br.readLine()) != null) { /* For publications: 0. dri:objIdentifier context 9. title context 12. publisher context 18. dateofacceptance 19. bestlicense @classname 21. resulttype @classname 26. originalId context (Notice that the prefix is null and will use space to separate two different "originalId") */ if (!previousText.isEmpty()) { text = previousText + text; start = true; previousText = ""; } String[] items = text.split("!"); for (int i = 0; i < items.length; ++i) { items[i] = StringUtils.strip(items[i], "#"); } if (objectId == null) objectId = doc.getElementsByTag("dri:objIdentifier").first(); objectId.text(items[0]); if (!start && items[0].equals(startID)) { start = true; } if (title == null) title = doc.getElementsByTag("title").first(); title.text(items[9]); if (publisher == null) publisher = doc.getElementsByTag("publisher").first(); if (items.length < 12) { previousText = text; continue; } publisher.text(items[12]); if (dateofacceptance == null) dateofacceptance = doc.getElementsByTag("dateofacceptance").first(); dateofacceptance.text(items[18]); if (bestlicense == null) bestlicense = doc.getElementsByTag("bestlicense").first(); bestlicense.attr("classname", items[19]); if (resulttype == null) resulttype = doc.getElementsByTag("resulttype").first(); resulttype.attr("classname", items[21]); if (originalId == null || originalId2 == null) { Elements elements = doc.getElementsByTag("originalId"); String[] context = items[26].split(" "); if (elements.size() > 0) { if (elements.size() >= 1) { originalId = elements.get(0); if (context.length >= 1) { int indexOfnull = context[0].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[0].trim().length() >= (indexOfnull + 5)) value = context[0].trim().substring(indexOfnull + 5); } else { value = context[0].trim(); } originalId.text(value); } } if (elements.size() >= 2) { originalId2 = elements.get(1); if (context.length >= 2) { int indexOfnull = context[1].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[1].trim().length() >= (indexOfnull + 5)) value = context[1].trim().substring(indexOfnull + 5); } else { value = context[1].trim(); } originalId2.text(value); } } } } else { String[] context = items[26].split(" "); if (context.length >= 1) { int indexOfnull = context[0].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[0].trim().length() >= (indexOfnull + 5)) value = context[0].trim().substring(indexOfnull + 5); } else { value = context[0].trim(); } originalId.text(value); } if (context.length >= 2) { int indexOfnull = context[1].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[1].trim().length() >= (indexOfnull + 5)) value = context[1].trim().substring(indexOfnull + 5); } else { value = context[1].trim(); } originalId2.text(value); } } if (start) { String filePath = outputDirectory + items[0].replace(":", "#") + ".xml"; PrintWriter writer = new PrintWriter(new FileOutputStream(filePath, false)); logWriter.write(filePath + " > Start" + System.lineSeparator()); writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + System.lineSeparator()); writer.write(doc.getElementsByTag("response").first().toString()); writer.close(); logWriter.write(filePath + " > OK" + System.lineSeparator()); logWriter.flush(); } } logWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.livinglogic.ul4.BoundStringMethodStrip.java
public static String call(String object, String chars) { return StringUtils.strip(object, chars); }
From source file:com.agapsys.utils.console.args.ActionParserTest.java
private static String[] __getArgs(String cmd) { cmd = cmd.trim();/*www .j av a 2s . com*/ if (cmd.isEmpty()) return new String[] {}; String[] args = cmd.split("\\s+(?=([^\"]*\"[^\"]*\")*[^\"]*$)"); for (int i = 0; i < args.length; i++) { args[i] = StringUtils.strip(args[i], " \""); } return args; }
From source file:it.biztech.btable.util.Utils.java
public static IBasicFile getFile(String filePath, String basePath) { if (StringUtils.isEmpty(filePath)) { return null; }//from w w w .j a v a 2s. c o m IContentAccessFactory factory = PentahoPluginEnvironment.getInstance().getContentAccessFactory(); String res = StringUtils.strip(filePath.toLowerCase(), "/"); if (res.startsWith(BTableConstants.SYSTEM_DIR + "/")) { res = StringUtils.strip(res, BTableConstants.SYSTEM_DIR + "/"); if (res.startsWith(BTableConstants.PLUGIN_SYSTEM_DIR.toLowerCase() + "/")) { filePath = filePath.replaceFirst( BTableConstants.SYSTEM_DIR + "/" + BTableConstants.PLUGIN_SYSTEM_DIR + "/", ""); return factory.getPluginSystemReader(basePath).fetchFile(filePath); } else { String pluginId = res.substring(0, filePath.indexOf("/")); filePath = filePath.replaceFirst(BTableConstants.SYSTEM_DIR + "/" + pluginId + "/", ""); return factory.getOtherPluginSystemReader(pluginId, basePath).fetchFile(filePath); } } else if (res.startsWith(BTableConstants.PLUGIN_REPOSITORY_DIR.toLowerCase() + "/")) { filePath = filePath.replaceFirst(BTableConstants.PLUGIN_REPOSITORY_DIR + "/", ""); return factory.getPluginRepositoryReader(basePath).fetchFile(filePath); } else { if (factory.getPluginSystemReader(basePath).fileExists(filePath)) { return factory.getPluginSystemReader(basePath).fetchFile(filePath); } else if (factory.getUserContentAccess(basePath).fileExists(filePath)) { return factory.getUserContentAccess(basePath).fetchFile(filePath); } } return null; }
From source file:com.shigengyu.hyperion.server.ControllerMethod.java
public ControllerMethod(String httpMethod, String controller, String method) { this.httpMethod = httpMethod; controller = "/" + StringUtils.strip(controller, "/"); this.controller = controller; method = "/" + StringUtils.strip(method, "/"); this.method = method; }
From source file:net.bible.android.view.util.widget.BookmarkStyleAdapterHelper.java
public void styleView(TextView view, BookmarkStyle bookmarkStyle, Context context, boolean overrideText, boolean centreText) { // prepare text to be shown String baseText;// www .j av a2 s . c om if (overrideText) { baseText = sampleText; } else { baseText = view.getText().toString(); // avoid multiple *'s if (baseText.startsWith("*")) { StringUtils.strip(baseText, "*"); } } int backgroundColor = Color.WHITE; switch (bookmarkStyle) { case YELLOW_STAR: backgroundColor = UiUtils.getThemeBackgroundColour(context); view.setTextColor(UiUtils.getThemeTextColour(context)); CharSequence imgText = addImageAtStart("* " + baseText, R.drawable.goldstar16x16, context); view.setText(imgText, TextView.BufferType.SPANNABLE); break; case RED_HIGHLIGHT: backgroundColor = BookmarkStyle.RED_HIGHLIGHT.getBackgroundColor(); view.setText(baseText); break; case YELLOW_HIGHLIGHT: backgroundColor = BookmarkStyle.YELLOW_HIGHLIGHT.getBackgroundColor(); view.setText(baseText); break; case GREEN_HIGHLIGHT: backgroundColor = BookmarkStyle.GREEN_HIGHLIGHT.getBackgroundColor(); view.setText(baseText); break; case BLUE_HIGHLIGHT: backgroundColor = BookmarkStyle.BLUE_HIGHLIGHT.getBackgroundColor(); view.setText(baseText); break; } view.setBackgroundColor(backgroundColor); view.setHeight(CommonUtils.convertDipsToPx(30)); if (centreText) { view.setGravity(Gravity.CENTER); } }
From source file:com.qualogy.qafe.bind.core.pattern.WildCardPattern.java
public String stripWildCards() { if (strippedPattern == null) strippedPattern = StringUtils.strip(pattern, "" + WILDCARD); return strippedPattern; }
From source file:cz.muni.fi.lessappcache.parser.modules.ImportModule.java
@Override public ModuleOutput parse(String line, ParsingContext pc) throws ModuleException { ModuleOutput output = new ModuleOutput(); if (line.startsWith("@import")) { output.setControl(ModuleControl.STOP); String url = line.replaceAll("(?i)^@import\\s+(.*)$", "$1"); //TODO: regex should be more aggresive url = StringUtils.strip(url, "\'\""); Path base = PathUtils.isAbsoluteOrRemote(url) ? Paths.get("") : pc.getContext(); Path file = base.resolve(Paths.get(url)); if (Importer.isImported(file)) { logger.warn("File " + file + " already imported. Skipping..."); return output; }/*ww w . j av a2 s .com*/ ManifestParser mp = new ManifestParser(file); try { mp.getLoadedResources().putAll(pc.getLoadedResources()); mp.setMode(pc.getMode()); output.getOutput().addAll(mp.processFile()); output.setLoadedResources(mp.getLoadedResources()); output.setMode(mp.getMode()); } catch (IOException ex) { logger.error("File " + file + " not found."); throw new ModuleException(ex); } } return output; }
From source file:de.hu_berlin.german.korpling.saltnpepper.pepperModules.ridgesModules.SOrderRelationAdderProperties.java
public Set<String> getSegmentations() { if (segmentations == null) { segmentations = new HashSet<String>(); String segs = (String) this.getProperty(PROP_SEGMENTATION_LAYERS).getValue(); segs = StringUtils.strip(segs, "{}"); for (String seg : segs.split("\\s*,\\s*")) { segmentations.add(seg.trim()); }/*from w ww . jav a2 s . c o m*/ } return (segmentations); }
From source file:com.kalessil.phpStorm.phpInspectionsEA.inspectors.security.rsaStrategies.OpensslRsaOraclePaddingStrategy.java
static private boolean isTargetCall(@NotNull FunctionReference reference) { boolean result = false; if (reference.getNameNode() == null) { final PsiElement name = reference.getFirstPsiChild(); if (name != null) { final Set<PsiElement> nameVariants = PossibleValuesDiscoveryUtil.discover(name); if (!nameVariants.isEmpty()) { for (final PsiElement variant : nameVariants) { if (variant instanceof StringLiteralExpression) { final String content = ((StringLiteralExpression) variant).getContents(); if (functions.contains(StringUtils.strip(content, "\\"))) { result = true; break; }/* w ww. j a va 2 s . c o m*/ } } nameVariants.clear(); } } } else { result = functions.contains(reference.getName()); } return result; }