List of usage examples for org.apache.commons.lang3 StringUtils remove
public static String remove(final String str, final char remove)
Removes all occurrences of a character from within the source string.
A null source string will return null .
From source file:org.yamj.core.service.metadata.nfo.InfoReader.java
/** * Try and read a NFO file for information * * @param nfoFile/*from www.j a va 2 s.c o m*/ * @param nfoText * @param dto */ public void readNfoFile(StageFile stageFile, InfoDTO dto) { String nfoFilename = stageFile.getFileName(); File nfoFile = new File(stageFile.getFullPath()); String nfoContent = null; try { nfoContent = FileUtils.readFileToString(nfoFile, FileTools.DEFAULT_CHARSET); } catch (Exception e) { LOG.error("Unable to read NFO file: " + stageFile.getFullPath(), e); nfoFile = null; nfoContent = stageFile.getContent(); if (StringUtils.isBlank(nfoContent)) { LOG.warn("NFO file '{}' is not readable", nfoFilename); try { stageFile.setStatus(StatusType.INVALID); this.stagingService.updateStageFile(stageFile); } catch (Exception ignore) { // error can be ignored } // nothing to do for this stage file return; } LOG.warn("NFO file '{}' is not readable; try stage file content", nfoFilename); } boolean parsedNfo = Boolean.FALSE; // was the NFO XML parsed correctly or at all boolean hasXml = Boolean.FALSE; if (StringUtils.containsIgnoreCase(nfoContent, XML_START + DOMHelper.TYPE_MOVIE) || StringUtils.containsIgnoreCase(nfoContent, XML_START + DOMHelper.TYPE_TVSHOW) || StringUtils.containsIgnoreCase(nfoContent, XML_START + DOMHelper.TYPE_EPISODE)) { hasXml = Boolean.TRUE; } // If the file has XML tags in it, try reading it as a pure XML file if (hasXml) { parsedNfo = this.readXmlNfo(nfoFile, nfoContent, nfoFilename, dto); } // If it has XML in it, but didn't parse correctly, try splitting it out if (hasXml && !parsedNfo) { int posMovie = findPosition(nfoContent, DOMHelper.TYPE_MOVIE); int posTv = findPosition(nfoContent, DOMHelper.TYPE_TVSHOW); int posEp = findPosition(nfoContent, DOMHelper.TYPE_EPISODE); int start = Math.min(posMovie, Math.min(posTv, posEp)); posMovie = StringUtils.indexOf(nfoContent, XML_END + DOMHelper.TYPE_MOVIE); posTv = StringUtils.indexOf(nfoContent, XML_END + DOMHelper.TYPE_TVSHOW); posEp = StringUtils.indexOf(nfoContent, XML_END + DOMHelper.TYPE_EPISODE); int end = Math.max(posMovie, Math.max(posTv, posEp)); if ((end > -1) && (end > start)) { end = StringUtils.indexOf(nfoContent, '>', end) + 1; // Send text to be read String nfoTrimmed = StringUtils.substring(nfoContent, start, end); parsedNfo = readXmlNfo(null, nfoTrimmed, nfoFilename, dto); nfoTrimmed = StringUtils.remove(nfoContent, nfoTrimmed); if (parsedNfo && StringUtils.isNotBlank(nfoTrimmed)) { // we have some text left, so scan that with the text scanner readTextNfo(nfoTrimmed, dto); } } } // If the XML wasn't found or parsed correctly, then fall back to the old method if (parsedNfo) { LOG.debug("Successfully scanned {} as XML format", nfoFilename); } else { // If the XML wasn't found or parsed correctly, then fall back to the old method parsedNfo = readTextNfo(nfoContent, dto); if (parsedNfo) { LOG.debug("Successfully scanned {} as text format", nfoFilename); } else { LOG.warn("Failed to find any information in {}", nfoFilename); try { stageFile.setStatus(StatusType.INVALID); this.stagingService.updateStageFile(stageFile); } catch (Exception ignore) { // error can be ignored cause will be retried later } } } }
From source file:org.yamj.core.service.metadata.online.ImdbScanner.java
private static String parseOriginalTitle(String xml) { String originalTitle = HTMLTools.extractTag(xml, "<span class=\"title-extra\">", "</span>"); StringUtils.remove(originalTitle, "<i>(original title)</i>"); StringUtils.remove(originalTitle, "\""); return StringUtils.trimToNull(originalTitle); }
From source file:org.yamj.core.service.metadata.online.ImdbScanner.java
private static Date parseFirstAiredDate(String xml) { String date = HTMLTools.extractTag(xml, "<span class=\"nobr\">", "</span>"); date = StringUtils.remove(date, "("); date = StringUtils.remove(date, ")"); date = StringUtils.trimToNull(date); return MetadataTools.parseToDate(date); }
From source file:org.yamj.core.service.metadata.online.ImdbScanner.java
private static int parseYear(String xml) { String date = HTMLTools.extractTag(xml, "<span class=\"nobr\">", "</span>"); date = StringUtils.remove(date, "("); date = StringUtils.remove(date, ")"); date = StringUtils.trimToNull(date); return MetadataTools.extractYearAsInt(date); }
From source file:org.yamj.core.service.metadata.online.ImdbScanner.java
private static void parseYears(String xml, Series series) { String years = HTMLTools.extractTag(xml, "<span class=\"nobr\">", "</span>"); years = StringUtils.remove(years, "("); years = StringUtils.remove(years, ")"); years = StringUtils.trimToEmpty(years); String[] parts = years.split("-"); if (parts.length > 0) { series.setStartYear(MetadataTools.extractYearAsInt(parts[0]), SCANNER_ID); if (parts.length > 1) { series.setEndYear(MetadataTools.extractYearAsInt(parts[1]), SCANNER_ID); }//w w w .j a va2 s . c om } }
From source file:parser.esperanto.query.CommandBuilder.java
public static String getResult(String text) throws Exception { Query setSentence = new Query(buildCommand(text)); if (!setSentence.query()) { throw new Exception("Hibs mondat"); }/* ww w . j av a2s. com*/ Query query = new Query(getQuery()); if (!query.hasSolution()) { throw new Exception("Hibs adat"); } String word, partOfSpeech; List<String> rows = new ArrayList<>(); while (query.hasMoreSolutions()) { word = query.nextSolution().get(CommandBuilder.TERM1).toString(); partOfSpeech = StringUtils.remove(query.nextSolution().get(CommandBuilder.TERM2).toString(), "'"); rows.add(word + "\t" + partOfSpeech); } return join("\n", rows); }
From source file:qic.Main.java
public String downloadHtml(String terms, boolean sortOnly) throws Exception { long start = System.currentTimeMillis(); String regex = "([^\\s]*=\".*?\")"; List<String> customHttpKeyVals = Util.regexMatches(regex, terms, 1); String customHttpKeyVal = customHttpKeyVals.stream().map(s -> StringUtils.remove(s, '"')) .collect(Collectors.joining("&")); String query = terms.replaceAll(regex, " "); ParseResult sortParseResult = language.parseSortToken(query); String sort = sortParseResult.result; sort = sort == null ? "price_in_chaos" : sort; invalidSearchTerms.addAll(sortParseResult.invalidSearchTerms); if (!sortOnly) { logger.info("Query: " + query); ParseResult queryParseResult = language.parse(query); String payload = queryParseResult.result; invalidSearchTerms.addAll(queryParseResult.invalidSearchTerms); if (invalidSearchTerms.isEmpty()) { payload = asList(payload, customHttpKeyVal, "capquality=x").stream().filter(StringUtils::isNotBlank) .collect(joining("&")); logger.info("Unencoded payload: " + payload); payload = asList(payload.split("&")).stream().map(Util::encodeQueryParm).collect(joining("&")); String location = submitSearchForm(payload); String league = language.parseLeagueToken(query); sessProp.setLocation(location); sessProp.setLeague(league);//from ww w. j a v a 2 s .c o m sessProp.saveToFile(); } } String searchPage = null; if (invalidSearchTerms.isEmpty()) { logger.info("sort: " + sort); searchPage = ajaxSort(sort); } else { logger.info("invalidSearchTerms: " + invalidSearchTerms.toString()); } long end = System.currentTimeMillis(); long duration = end - start; logger.info("Took " + duration + " ms"); searchDuration = Long.valueOf(duration); return searchPage; }
From source file:rs.metropolitan.data_changer.lists.ToList.java
@Override public ArrayList<String> changeString(String data) { String left = "{"; String right = "}"; String doubleQuote = "\""; String seps = ","; if (StringUtils.startsWith(data, left) && StringUtils.endsWith(data, right)) { String cleaned = StringUtils.remove(data, left); cleaned = StringUtils.remove(cleaned, right); cleaned = StringUtils.remove(cleaned, doubleQuote); System.out.println(cleaned); StringTokenizer st = new StringTokenizer(cleaned, seps); while (st.hasMoreTokens()) { ArraylistString.add(st.nextToken()); }//from w w w. j ava2 s . com } return ArraylistString; }
From source file:syncthing.android.service.SyncthingUtils.java
public static String buildUrl(@NonNull String host, @NonNull String port, boolean tls) { host = stripHttp(StringUtils.trim(host).toLowerCase(Locale.US)); port = StringUtils.strip(StringUtils.trim(port), ":"); String path = ""; if (isDomainNameWithPath(host)) { path = Uri.parse("http://" + host).getPath(); host = StringUtils.remove(host, path); }/*from w w w .jav a 2 s .com*/ return (tls ? "https://" : "http://") + host + ":" + port + //without the trailing slash retrofit wont build the url correctly ((StringUtils.isEmpty(path) || StringUtils.endsWith(path, "/")) ? path : (path + "/")); }
From source file:syncthing.android.service.SyncthingUtils.java
private static String stripHttp(String uri) { if (StringUtils.startsWithAny(uri, "http://", "https://")) { uri = StringUtils.remove(uri, "http://"); uri = StringUtils.remove(uri, "https://"); }/*from w w w. j a v a 2 s. c o m*/ return uri; }