List of usage examples for org.apache.commons.lang3 StringEscapeUtils unescapeHtml4
public static final String unescapeHtml4(final String input)
Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes.
From source file:org.spdx.rdfparser.license.License.java
/** * @return the standardLicenseHeader//from w w w . java 2s. co m */ public String getStandardLicenseHeader() { if (this.resource != null && this.refreshOnGet) { this.standardLicenseHeader = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_NOTICE); if (this.standardLicenseHeader == null) { this.standardLicenseHeader = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_HEADER_VERSION_1); } if (this.standardLicenseHeader != null) { this.standardLicenseHeader = StringEscapeUtils.unescapeHtml4(this.standardLicenseHeader); } } return standardLicenseHeader; }
From source file:org.spdx.rdfparser.license.License.java
/** * @return standard license header template */// w w w .ja v a 2 s .co m public String getStandardLicenseHeaderTemplate() { if (this.resource != null && this.refreshOnGet) { standardLicenseHeaderTemplate = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_HEADER_TEMPLATE); if (standardLicenseHeaderTemplate != null) { standardLicenseHeaderTemplate = StringEscapeUtils.unescapeHtml4(standardLicenseHeaderTemplate); } } return standardLicenseHeaderTemplate; }
From source file:org.spdx.rdfparser.SPDXStandardLicense.java
/** * Constructs an SPDX License from the licenseNode * @param licenseNode RDF graph node representing the SPDX License * @throws InvalidSPDXAnalysisException *//* w w w . j a v a 2 s .c om*/ public SPDXStandardLicense(Model spdxModel, Node licenseNode) throws InvalidSPDXAnalysisException { super(spdxModel, licenseNode); // name this.name = null; Node p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_NAME) .asNode(); Triple m = Triple.createMatch(licenseNode, p, null); ExtendedIterator<Triple> tripleIter = model.getGraph().find(m); if (tripleIter.hasNext()) { Triple t = tripleIter.next(); this.name = t.getObject().toString(false); } else { // try the pre 1.1 name - for backwards compatibility p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_NAME_VERSION_1) .asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); if (tripleIter.hasNext()) { Triple t = tripleIter.next(); this.name = t.getObject().toString(false); } else { this.name = id; // No name hsa been found, default is the ID } } // text p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_TEXT).asNode(); m = Triple.createMatch(licenseInfoNode, p, null); tripleIter = model.getGraph().find(m); while (tripleIter.hasNext()) { Triple t = tripleIter.next(); this.text = t.getObject().toString(false); if (this.text.endsWith(XML_LITERAL)) { this.text = this.text.substring(0, this.text.length() - XML_LITERAL.length()); } if (this.textInHtml) { this.text = SpdxLicenseTemplateHelper.HtmlToText(this.text); } } // SourceUrl/seeAlso ArrayList<String> alsourceUrls = new ArrayList<String>(); p = model.getProperty(SpdxRdfConstants.RDFS_NAMESPACE, SpdxRdfConstants.RDFS_PROP_SEE_ALSO).asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); while (tripleIter.hasNext()) { Triple t = tripleIter.next(); alsourceUrls.add(t.getObject().toString(false)); } // The following is added for compatibility with earlier versions p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_URL_VERSION_1) .asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); while (tripleIter.hasNext()) { Triple t = tripleIter.next(); alsourceUrls.add(t.getObject().toString(false)); } this.sourceUrl = alsourceUrls.toArray(new String[alsourceUrls.size()]); // notes p = model.getProperty(SpdxRdfConstants.RDFS_NAMESPACE, SpdxRdfConstants.RDFS_PROP_COMMENT).asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); if (!tripleIter.hasNext()) { // check the old property name for compatibility with pre-1.1 generated RDF files p = model .getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_NOTES_VERSION_1) .asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); } if (tripleIter.hasNext()) { Triple t = tripleIter.next(); this.comments = t.getObject().toString(false); } else { this.comments = null; } // standardLicenseHeader p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_NOTICE).asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); if (tripleIter.hasNext()) { Triple t = tripleIter.next(); this.standardLicenseHeader = t.getObject().toString(false); } else { // try the 1.0 version name p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_HEADER_VERSION_1).asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); if (tripleIter.hasNext()) { Triple t = tripleIter.next(); this.standardLicenseHeader = t.getObject().toString(false); } else { this.standardLicenseHeader = null; } } if (this.standardLicenseHeader != null) { this.standardLicenseHeader = StringEscapeUtils.unescapeHtml4(this.standardLicenseHeader); } // template p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_TEMPLATE).asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); if (tripleIter.hasNext()) { Triple t = tripleIter.next(); this.template = t.getObject().toString(false); if (template.endsWith(XML_LITERAL)) { this.template = this.template.substring(0, this.template.length() - XML_LITERAL.length()); } if (this.templateInHtml) { this.template = SpdxLicenseTemplateHelper.HtmlToText(this.template); } } else { // try version 1 p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_TEMPLATE_VERSION_1).asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); if (tripleIter.hasNext()) { Triple t = tripleIter.next(); this.template = t.getObject().toString(false); if (template.endsWith(XML_LITERAL)) { this.template = this.template.substring(0, this.template.length() - XML_LITERAL.length()); } if (this.templateInHtml) { this.template = SpdxLicenseTemplateHelper.HtmlToText(this.template); } } else { this.template = null; } } // OSI Approved p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_OSI_APPROVED) .asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); if (!tripleIter.hasNext()) { // for compatibility, check the version 1 property name p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_OSI_APPROVED_VERSION_1).asNode(); m = Triple.createMatch(licenseNode, p, null); tripleIter = model.getGraph().find(m); } if (tripleIter.hasNext()) { Triple t = tripleIter.next(); String osiTextValue = t.getObject().toString(false); if (osiTextValue.equals("true") || osiTextValue.equals("1")) { this.osiApproved = true; } else if (osiTextValue.equals("false") || osiTextValue.equals("0")) { this.osiApproved = false; } else { throw (new InvalidSPDXAnalysisException( "Invalid value for OSI Approved - must be {true, false, 0, 1}")); } } else { this.osiApproved = false; } }
From source file:org.springframework.web.util.HtmlUtilsTest.java
/** * Test html utils./*from w w w.ja va 2 s .c o m*/ */ @Test public void testHtmlUtils() { String specialStr = "<div id=\"testDiv\">test1;test2</div>"; String str1 = HtmlUtils.htmlEscape(specialStr); // HTML HTML ? log.info(str1); String str2 = HtmlUtils.htmlEscapeDecimal(specialStr);// HTML # ???? log.info(str2); String str3 = HtmlUtils.htmlEscapeHex(specialStr);// HTML # ???? log.info(str3); // ?????? log.info(HtmlUtils.htmlUnescape(str1)); log.info(HtmlUtils.htmlUnescape(str2)); log.info(HtmlUtils.htmlUnescape(str3)); log.info(StringEscapeUtils.unescapeHtml4(str1)); log.info(StringEscapeUtils.unescapeHtml4(str2)); log.info(StringEscapeUtils.unescapeHtml4(str3)); log.info(org.apache.commons.lang.StringEscapeUtils.unescapeHtml(str1)); log.info(org.apache.commons.lang.StringEscapeUtils.unescapeHtml(str2)); log.info(org.apache.commons.lang.StringEscapeUtils.unescapeHtml(str3)); }
From source file:org.springframework.web.util.HtmlUtilsTest.java
/** * String escape utils. */ @Test public void stringEscapeUtils() { log.info(StringEscapeUtils.unescapeHtml4(a)); }
From source file:org.tinymediamanager.scraper.aebn.AebnMetadataProvider.java
/** * Search for movies at aebn.net.//from ww w . j a v a 2 s. c om * */ @Override public List<MediaSearchResult> search(MediaSearchOptions query) throws Exception { LOGGER.debug("AEBN: search() {}", query); List<MediaSearchResult> resultList = new ArrayList<MediaSearchResult>(); Elements movies = null; String searchString = ""; // Search for query if (StringUtils.isNotEmpty(query.get(MediaSearchOptions.SearchParam.QUERY))) { searchString = query.get(MediaSearchOptions.SearchParam.QUERY); } // Search String searchUrl = BASE_DATAURL + "/dispatcher/fts?userQuery=" + URLEncoder.encode(cleanSearchQuery(searchString), "UTF-8") + "&targetSearchMode=basic&isAdvancedSearch=true&isFlushAdvancedSearchCriteria=false" + "&count=" + SEARCH_COUNT.toString() + "&imageType=Large&sortType=Relevance"; try { LOGGER.info("========= BEGIN AEBN Scraper Search for: {}", searchString); Url url = new Url(searchUrl); InputStream in = url.getInputStream(); Document doc = Jsoup.parse(in, "UTF-8", ""); in.close(); // only look for movie links like // <a id="FTSMovieSearch_link_title_detail_30" ... </a> movies = doc.getElementsByAttributeValueMatching("id", "FTSMovieSearch_link_title_detail_\\d+"); LOGGER.debug("AEBN: found {} search results", movies.size()); } catch (Exception e) { LOGGER.error("AEBN: failed to search for {}: ", searchString, e); } if (movies == null || movies.isEmpty()) { LOGGER.debug("AEBN: no movie found"); return resultList; } // there are search results, so fill media data structure HashSet<String> foundResultUrls = new HashSet<String>(); for (Element anchor : movies) { try { String movieUrl = BASE_DATAURL + StrgUtils.substr(anchor.toString(), "href=\\\"(.*?)\\\""); String movieId = StrgUtils.substr(anchor.toString(), "movieId=(\\d+)"); String movieName = StringEscapeUtils.unescapeHtml4(anchor.text()); String posterUrl = BASE_IMGURL + "/Stream/Movie/Boxcovers/a" + movieId + "_160w.jpg"; LOGGER.debug("AEBN: found movie {} (id{})", movieName, movieId); // check if it is a valid AEBN id if (!isValidAebnId(Integer.parseInt(movieId))) { LOGGER.error("AEBN: id({}) is not a valid aebn id", movieId); } MediaSearchResult sr = new MediaSearchResult(providerInfo.getId()); sr.setId(movieId); sr.setIMDBId(""); sr.setTitle(movieName); sr.setOriginalTitle(movieName); // sr.setYear not possible, no data at this point sr.setYear(null); sr.setMediaType(MediaType.MOVIE); sr.setUrl(movieUrl); sr.setPosterUrl(posterUrl); // compare score based on names float score = MetadataUtil.calculateScore(searchString, movieName); if (posterUrl.isEmpty() || posterUrl.contains("nopicture")) { LOGGER.debug("AEBN: no poster - downgrading score by 0.01"); score = score - 0.01f; } sr.setScore(score); // check if result has at least a title and id if (StringUtils.isBlank(sr.getTitle()) || StringUtils.isBlank(sr.getId())) { LOGGER.warn("AEBN: no title nor id, skipping"); continue; } // check if the movie has been already added to the search results if (foundResultUrls.contains(sr.getUrl())) { continue; } foundResultUrls.add(sr.getUrl()); // populate extra arguments (deprecated) // MetadataUtil.copySearchQueryToSearchResult(query, sr); resultList.add(sr); } catch (Exception e) { LOGGER.warn("AEBN: error parsing search result: {}", e); } } Collections.sort(resultList); Collections.reverse(resultList); return resultList; }
From source file:org.tinymediamanager.scraper.ofdb.OfdbMetadataProvider.java
@Override public List<MediaSearchResult> search(MediaSearchOptions options) throws Exception { LOGGER.debug("search() " + options.toString()); if (options.getMediaType() != MediaType.MOVIE) { throw new UnsupportedMediaTypeException(options.getMediaType()); }//ww w .jav a 2 s .co m List<MediaSearchResult> resultList = new ArrayList<>(); String searchString = ""; String searchQuery = ""; String imdb = ""; Elements filme = null; int myear = options.getYear(); /* * Kat = All | Titel | Person | DTitel | OTitel | Regie | Darsteller | Song | Rolle | EAN| IMDb | Google * http://www.ofdb.de//view.php?page=suchergebnis &Kat=xxxxxxxxx&SText=yyyyyyyyyyy */ // 1. search with imdbId if (StringUtils.isNotEmpty(options.getImdbId()) && (filme == null || filme.isEmpty())) { try { imdb = options.getImdbId(); searchString = BASE_URL + "/view.php?page=suchergebnis&Kat=IMDb&SText=" + imdb; LOGGER.debug("search with imdbId: " + imdb); Url url = new Url(searchString); InputStream in = url.getInputStream(); Document doc = Jsoup.parse(in, "UTF-8", ""); in.close(); // only look for movie links filme = doc.getElementsByAttributeValueMatching("href", "film\\/\\d+,"); LOGGER.debug("found " + filme.size() + " search results"); } catch (Exception e) { LOGGER.error("failed to search for imdb Id " + imdb + ": " + e.getMessage()); } } // 2. search for search string if (StringUtils.isNotEmpty(options.getQuery()) && (filme == null || filme.isEmpty())) { try { String query = options.getQuery(); searchQuery = query; query = MetadataUtil.removeNonSearchCharacters(query); searchString = BASE_URL + "/view.php?page=suchergebnis&Kat=All&SText=" + URLEncoder.encode(cleanSearch(query), "UTF-8"); LOGGER.debug("search for everything: " + query); Url url = new Url(searchString); InputStream in = url.getInputStream(); Document doc = Jsoup.parse(in, "UTF-8", ""); in.close(); // only look for movie links filme = doc.getElementsByAttributeValueMatching("href", "film\\/\\d+,"); LOGGER.debug("found " + filme.size() + " search results"); } catch (Exception e) { LOGGER.error("failed to search for " + searchQuery + ": " + e.getMessage()); } } if (filme == null || filme.isEmpty()) { LOGGER.debug("nothing found :("); return resultList; } // <a href="film/22523,Die-Bourne-Identitt" // onmouseover="Tip('<img src="images/film/22/22523.jpg" // width="120" height="170">',SHADOW,true)">Bourne // Identitt, Die<font size="1"> / Bourne Identity, The</font> (2002)</a> HashSet<String> foundResultUrls = new HashSet<>(); for (Element a : filme) { try { MediaSearchResult sr = new MediaSearchResult(providerInfo.getId(), MediaType.MOVIE); if (StringUtils.isNotEmpty(imdb)) { sr.setIMDBId(imdb); } sr.setId(StrgUtils.substr(a.toString(), "film\\/(\\d+),")); // OFDB ID sr.setTitle(StringEscapeUtils.unescapeHtml4(StrgUtils .removeCommonSortableName(StrgUtils.substr(a.toString(), ".*>(.*?)(\\[.*?\\])?<font")))); LOGGER.debug("found movie " + sr.getTitle()); sr.setOriginalTitle(StringEscapeUtils.unescapeHtml4( StrgUtils.removeCommonSortableName(StrgUtils.substr(a.toString(), ".*> / (.*?)</font")))); try { sr.setYear(Integer.parseInt(StrgUtils.substr(a.toString(), "font> \\((.*?)\\)<\\/a"))); } catch (Exception ignored) { } sr.setUrl(BASE_URL + "/" + StrgUtils.substr(a.toString(), "href=\\\"(.*?)\\\"")); sr.setPosterUrl(BASE_URL + "/images" + StrgUtils.substr(a.toString(), "images(.*?)\\"")); // check if it has at least a title and url if (StringUtils.isBlank(sr.getTitle()) || StringUtils.isBlank(sr.getUrl())) { continue; } // OFDB could provide linke twice - check if that has been already added if (foundResultUrls.contains(sr.getUrl())) { continue; } foundResultUrls.add(sr.getUrl()); if (imdb.equals(sr.getIMDBId())) { // perfect match sr.setScore(1); } else { // compare score based on names float score = MetadataUtil.calculateScore(searchQuery, sr.getTitle()); if (yearDiffers(myear, sr.getYear())) { float diff = (float) Math.abs(myear - sr.getYear()) / 100; LOGGER.debug( "parsed year does not match search result year - downgrading score by " + diff); score -= diff; } sr.setScore(score); } resultList.add(sr); } catch (Exception e) { LOGGER.warn("error parsing movie result: " + e.getMessage()); } } Collections.sort(resultList); Collections.reverse(resultList); return resultList; }
From source file:org.tinymediamanager.ui.actions.DonateAction.java
@Override public void actionPerformed(ActionEvent e) { String url = StringEscapeUtils.unescapeHtml4("http://tinymediamanager.org/donate.php"); try {// ww w . ja v a2s.co m TmmUIHelper.browseUrl(url); } catch (Exception e1) { LOGGER.error("Donate", e1); MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, url, "message.erroropenurl", new String[] { ":", e1.getLocalizedMessage() })); } }
From source file:org.tinymediamanager.ui.actions.FaqAction.java
@Override public void actionPerformed(ActionEvent e) { String url = StringEscapeUtils .unescapeHtml4("https://github.com/tinyMediaManager/tinyMediaManager/wiki/FAQ"); try {/*ww w. j av a2 s .c om*/ TmmUIHelper.browseUrl(url); } catch (Exception e1) { LOGGER.error("FAQ", e1); MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, url, "message.erroropenurl", new String[] { ":", e1.getLocalizedMessage() })); } }
From source file:org.tinymediamanager.ui.actions.FeedbackAction.java
@Override public void actionPerformed(ActionEvent e) { String url = StringEscapeUtils.unescapeHtml4("http://forum.xbmc.org/forumdisplay.php?fid=204"); try {// w w w . ja va2 s. c om TmmUIHelper.browseUrl(url); } catch (Exception e1) { LOGGER.error("FAQ", e1); MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, url, "message.erroropenurl", new String[] { ":", e1.getLocalizedMessage() })); } }