List of usage examples for org.apache.commons.text 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:com.networknt.graphql.security.JwtVerifyHandlerTest.java
static RoutingHandler getTestHandler() { return Handlers.routing().add(Methods.GET, "/v2/pet/{petId}", exchange -> { Map<String, Object> examples = new HashMap<>(); examples.put("application/xml", StringEscapeUtils.unescapeHtml4( "<Pet> <id>123456</id> <name>doggie</name> <photoUrls> <photoUrls>string</photoUrls> </photoUrls> <tags> </tags> <status>string</status></Pet>")); examples.put("application/json", StringEscapeUtils.unescapeHtml4( "{ "photoUrls" : [ "aeiou" ], "name" : "doggie", "id" : 123456789, "category" : { "name" : "aeiou", "id" : 123456789 }, "tags" : [ { "name" : "aeiou", "id" : 123456789 } ], "status" : "aeiou"}")); if (examples.size() > 0) { exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json"); exchange.getResponseSender().send((String) examples.get("application/json")); } else {/*ww w .ja v a 2 s .com*/ exchange.endExchange(); } }).add(Methods.GET, "/v2/pet", exchange -> exchange.getResponseSender().send("get")); }
From source file:com.networknt.openapi.JwtVerifyHandlerTest.java
static RoutingHandler getTestHandler() { return Handlers.routing().add(Methods.GET, "/v1/pets/{petId}", exchange -> { Map<String, Object> examples = new HashMap<>(); examples.put("application/xml", StringEscapeUtils.unescapeHtml4( "<Pet> <id>123456</id> <name>doggie</name> <photoUrls> <photoUrls>string</photoUrls> </photoUrls> <tags> </tags> <status>string</status></Pet>")); examples.put("application/json", StringEscapeUtils.unescapeHtml4( "{ "photoUrls" : [ "aeiou" ], "name" : "doggie", "id" : 123456789, "category" : { "name" : "aeiou", "id" : 123456789 }, "tags" : [ { "name" : "aeiou", "id" : 123456789 } ], "status" : "aeiou"}")); if (examples.size() > 0) { exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json"); exchange.getResponseSender().send((String) examples.get("application/json")); } else {/* w w w . j a va 2 s . c o m*/ exchange.endExchange(); } }).add(Methods.GET, "/v1/pets", exchange -> exchange.getResponseSender().send("get")); }
From source file:br.bireme.ngrams.NGrams.java
public static boolean indexDocument(final NGIndex index, final IndexWriter writer, final NGSchema schema, final String pipedDoc, final boolean allowDocUpdate) throws IOException, ParseException { if (index == null) { throw new NullPointerException("index"); }/*w w w. ja v a2 s .c o m*/ if (writer == null) { throw new NullPointerException("writer"); } if (schema == null) { throw new NullPointerException("schema"); } if (pipedDoc == null) { throw new NullPointerException("pipedDoc"); } boolean ret = false; final String pipedDocT = pipedDoc.trim(); if (!isUtf8Encoding(pipedDocT)) { throw new IOException("Invalid encoded string"); } if (!pipedDocT.isEmpty()) { final Parameters parameters = schema.getParameters(); if (Tools.countOccurrences(pipedDoc, '|') < parameters.maxIdxFieldPos) { throw new IOException("invalid number of fields: [" + pipedDoc + "]"); } final String pipedDoc2 = StringEscapeUtils.unescapeHtml4(pipedDoc); final String[] split = pipedDoc2.replace(':', ' ').trim().split(" *\\| *", Integer.MAX_VALUE); final String id = split[parameters.id.pos]; if (id.isEmpty()) { throw new IOException("id"); } final String dbName = split[parameters.db.pos]; if (dbName.isEmpty()) { throw new IOException("dbName"); } final Map<String, br.bireme.ngrams.Field> flds = parameters.nameFields; final Document doc = createDocument(flds, split); if (doc != null) { if (allowDocUpdate) { writer.updateDocument(new Term("id", id), doc); writer.commit(); } else { writer.addDocument(doc); } ret = true; } } return ret; }
From source file:br.bireme.ngrams.NGrams.java
private static void searchRaw(final Parameters parameters, final IndexSearcher searcher, final NGAnalyzer analyzer, final NGramDistance ngDistance, final String text, final boolean useSimilarity, final Set<String> id_id, final Set<Result> results) throws IOException, ParseException { assert parameters != null; assert searcher != null; assert analyzer != null; assert ngDistance != null; assert id_id != null; assert results != null; if (text == null) { throw new NullPointerException("text"); }// w ww. ja va2s.c om final String text2 = StringEscapeUtils.unescapeHtml4(text); final String[] param = text2.trim().split(" *\\| *", Integer.MAX_VALUE); if (param.length != parameters.nameFields.size()) { throw new IOException(text); } final String fname = parameters.indexed.name; final QueryParser parser = new QueryParser(fname, analyzer); final String ntext = Tools .limitSize(Tools.normalize(param[parameters.indexed.pos], OCC_SEPARATOR), MAX_NG_TEXT_SIZE).trim(); final int MAX_RESULTS = 20; if (!ntext.isEmpty()) { final Query query = parser.parse(QueryParser.escape(ntext)); final TopDocs top = searcher.search(query, MAX_RESULTS); final float lower = parameters.scores.first().minValue; ScoreDoc[] scores = top.scoreDocs; int remaining = MAX_RESULTS; for (ScoreDoc sdoc : scores) { if (remaining-- <= 0) { break; // Only for performance } final Document doc = searcher.doc(sdoc.doc); if (useSimilarity) { final String dname = doc.get(fname); if (dname == null) { throw new IOException("dname"); } final float similarity = ngDistance.getDistance(ntext, doc.get(fname)); if (similarity < lower) { if (remaining > 3) { remaining = 3; //System.out.println("Atualizando tot=" + tot + " score=" + sdoc.score + " similarity=" + similarity+ " text=" + doc.get(fname)); } } else { final Result out = createResult(id_id, parameters, param, doc, ngDistance, similarity, sdoc.score); if (out != null) { results.add(out); } } } else { if (sdoc.score < 1.0) { System.out.println("Saindo score=" + sdoc.score); break; // Only for performance } final Result out = createResult(id_id, parameters, param, doc, ngDistance, 0, sdoc.score); if (out != null) { results.add(out); } } } } }
From source file:org.sakaiproject.commons.api.datamodel.Comment.java
public void setContent(String text, boolean modified) { if (!this.content.equals(text) && modified) { modifiedDate = Instant.now().toEpochMilli(); }/*from w w w . j a v a2 s . com*/ this.content = StringEscapeUtils.unescapeHtml4(text.trim()); }
From source file:ru.org.linux.topic.Topic.java
public String getTitleUnescaped() { return StringEscapeUtils.unescapeHtml4(title); }
From source file:ru.org.linux.user.EditRegisterController.java
@RequestMapping(method = RequestMethod.GET) public ModelAndView show(@ModelAttribute("form") EditRegisterRequest form, @PathVariable String nick, HttpServletRequest request, HttpServletResponse response) throws Exception { Template tmpl = Template.getTemplate(request); if (!tmpl.isSessionAuthorized()) { throw new AccessViolationException("Not authorized"); }/*from ww w .j av a2s .c o m*/ if (!tmpl.getNick().equals(nick)) { throw new AccessViolationException("Not authorized"); } User user = tmpl.getCurrentUser(); UserInfo userInfo = userDao.getUserInfoClass(user); ModelAndView mv = new ModelAndView("edit-reg"); form.setEmail(user.getEmail()); form.setUrl(userInfo.getUrl()); form.setTown(userInfo.getTown()); form.setName(user.getName()); form.setInfo(StringEscapeUtils.unescapeHtml4(userDao.getUserInfo(user))); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); return mv; }
From source file:ru.org.linux.user.ReplyFeedView.java
@Override protected void createFeed(SyndFeed feed, Map model) { @SuppressWarnings("unchecked") List<PreparedUserEvent> list = (List<PreparedUserEvent>) model.get("topicsList"); String s = " ? " + model.get("nick"); feed.setTitle(s);// w w w .java 2s.co m feed.setLink("http://www.linux.org.ru"); feed.setUri("http://www.linux.org.ru"); feed.setAuthor(""); feed.setDescription(s); Date lastModified; if (!list.isEmpty()) { lastModified = list.get(0).getEvent().getEventDate(); } else { lastModified = new Date(); } feed.setPublishedDate(lastModified); List<SyndEntry> entries = new ArrayList<>(); feed.setEntries(entries); for (PreparedUserEvent preparedUserEvent : list) { UserEvent item = preparedUserEvent.getEvent(); SyndEntry feedEntry = new SyndEntryImpl(); feedEntry.setPublishedDate(item.getEventDate()); feedEntry.setTitle(StringEscapeUtils.unescapeHtml4(item.getSubj())); String link; if (item.getCid() != 0) { feedEntry.setAuthor(preparedUserEvent.getAuthor().getNick()); link = String.format("http://www.linux.org.ru/jump-message.jsp?msgid=%s&cid=%s", String.valueOf(item.getTopicId()), String.valueOf(item.getCid())); } else { link = String.format("http://www.linux.org.ru/view-message.jsp?msgid=%s", String.valueOf(item.getTopicId())); } feedEntry.setLink(link); feedEntry.setUri(link); if (preparedUserEvent.getMessageText() != null) { SyndContent message = new SyndContentImpl(); message.setValue(StringUtil.removeInvalidXmlChars(preparedUserEvent.getMessageText())); message.setType("text/html"); feedEntry.setDescription(message); } entries.add(feedEntry); } }