Java Code Examples for org.apache.commons.text.StringEscapeUtils#unescapeHtml4()

The following examples show how to use org.apache.commons.text.StringEscapeUtils#unescapeHtml4() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImgurAPI.java    From RedReader with GNU General Public License v3.0 6 votes vote down vote up
public static AlbumInfo parseV3(final String id, final JsonBufferedObject object)
		throws IOException, InterruptedException {

	String title = object.getString("title");
	String description = object.getString("description");

	if(title != null) {
		title = StringEscapeUtils.unescapeHtml4(title);
	}

	if(description != null) {
		description = StringEscapeUtils.unescapeHtml4(description);
	}

	final JsonBufferedArray imagesJson = object.getArray("images");
	final ArrayList<ImageInfo> images = new ArrayList<>();

	for(final JsonValue imageJson : imagesJson) {
		images.add(ImageInfo.parseImgurV3(imageJson.asObject()));
	}

	return new AlbumInfo(id, title, description, images);
}
 
Example 2
Source File: HttpUtils.java    From drftpd with GNU General Public License v2.0 6 votes vote down vote up
public static String htmlToString(String input) {
    String str = input.replaceAll("\n", "");
    str = StringEscapeUtils.unescapeHtml4(str);
    str = Normalizer.normalize(str, Normalizer.Form.NFD);
    str = str.replaceAll("\\P{InBasic_Latin}", "");
    while (str.contains("<")) {
        int startPos = str.indexOf("<");
        int endPos = str.indexOf(">", startPos);
        if (endPos > startPos) {
            String beforeTag = str.substring(0, startPos);
            String afterTag = str.substring(endPos + 1);
            str = beforeTag + afterTag;
        }
    }
    return str;
}
 
Example 3
Source File: YouTubeChannel.java    From youtube-comment-suite with MIT License 5 votes vote down vote up
/**
 * Comment objects usually have enough detail about the poster to create our object.
 */
public YouTubeChannel(Comment item) {
    this(getChannelIdFromObject(item.getSnippet().getAuthorChannelId()),
            StringEscapeUtils.unescapeHtml4(item.getSnippet().getAuthorDisplayName()),
            item.getSnippet().getAuthorProfileImageUrl());
    setTypeId(YType.CHANNEL);
}
 
Example 4
Source File: RedditSubreddit.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
public String getSidebarHtml(boolean nightMode) {
	final String unescaped = StringEscapeUtils.unescapeHtml4(description_html);

	final StringBuilder result = new StringBuilder(unescaped.length() + 512);

	result.append("<html>");

	result.append("<head>");
	result.append("<meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\">");

	if(nightMode) {
		result.append("<style>");
		result.append("body {color: white; background-color: black;}");
		result.append("a {color: #3399FF; background-color: 000033;}");
		result.append("</style>");
	}

	result.append("</head>");

	result.append("<body>");
	result.append(unescaped);
	result.append("</body>");

	result.append("</html>");

	return result.toString();
}
 
Example 5
Source File: GradebookServiceHelperImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Add a published assessment to gradebook.
 * @param publishedAssessment the published assessment
 * @param g  the Gradebook Service
 * @return false: cannot add to gradebook
 * @throws java.lang.Exception
 */
public boolean addToGradebook(PublishedAssessmentData publishedAssessment, Long categoryId, 
  GradebookExternalAssessmentService g) throws
  Exception
{
  boolean added = false;
  String gradebookUId = GradebookFacade.getGradebookUId();
  if (gradebookUId == null)
  {
    return false;
  }

  if (g.isGradebookDefined(gradebookUId))
  {
    String title = StringEscapeUtils.unescapeHtml4(publishedAssessment.getTitle());
    if(!g.isAssignmentDefined(gradebookUId, title))
    {
        g.addExternalAssessment(gradebookUId,
                publishedAssessment.getPublishedAssessmentId().toString(),
                null,
                title,
                publishedAssessment.getTotalScore(),
                publishedAssessment.getAssessmentAccessControl().getDueDate(),
                getAppName(), // Use the app name from sakai
                null,
                false,
                categoryId);
      added = true;
    }
  }
  return added;
}
 
Example 6
Source File: AnimeCmds.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
private void characterData(GuildMessageReceivedEvent event, I18nContext lang, CharacterData character) {
    try {
        final CharacterData.Attributes attributes = character.getAttributes();

        final String japName = attributes.getNames().getJa_jp();
        final String charName = attributes.getName();
        final String imageUrl = attributes.getImage().getOriginal();

        final String characterDescription = StringEscapeUtils.unescapeHtml4(attributes.getDescription().replace("<br>", "\n").replaceAll("\\<.*?>", "")); //This is silly.

        final String charDescription = attributes.getDescription() == null || attributes.getDescription().isEmpty() ? lang.get("commands.character.no_info")
                : StringUtils.limit(characterDescription, 1016);

        Player p = MantaroData.db().getPlayer(event.getAuthor());
        Badge badge = APIUtils.getHushBadge(charName.replace(japName, "").trim(), Utils.HushType.CHARACTER);

        if (badge != null) {
            p.getData().addBadgeIfAbsent(badge);
            p.save();
        }

        EmbedBuilder embed = new EmbedBuilder();
        embed.setColor(Color.LIGHT_GRAY)
                .setThumbnail(imageUrl)
                .setAuthor(String.format(lang.get("commands.character.information_header"), charName), null, imageUrl)
                .addField(lang.get("commands.character.information"), charDescription, true)
                .setFooter(lang.get("commands.anime.information_notice"), null);

        event.getChannel().sendMessage(embed.build()).queue(success -> {
        }, failure -> failure.printStackTrace());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: ThreadSearhDomain.java    From domain_hunter with MIT License 5 votes vote down vote up
public static Set<String> grepDomain(String httpResponse) {
	Set<String> domains = new HashSet<>();
	//"^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$"
	final String DOMAIN_NAME_PATTERN = "([A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}";
	int counter =0;
	while (httpResponse.contains("&#x") && counter<3) {// &#x html编码的特征
		httpResponse = StringEscapeUtils.unescapeHtml4(httpResponse);
		counter++;
	}
	
	counter = 0;
	while (httpResponse.contains("%") && counter<3) {// %对应的URL编码
		httpResponse = URLDecoder.decode(httpResponse);
		counter++;
	}
	
	counter = 0;
	while (httpResponse.contains("\\u00") && counter<3) {//unicode解码
		httpResponse = StringEscapeUtils.unescapeJava(httpResponse);
		counter++;
	}
	
	Pattern pDomainNameOnly = Pattern.compile(DOMAIN_NAME_PATTERN);
	Matcher matcher = pDomainNameOnly.matcher(httpResponse);
	while (matcher.find()) {//多次查找
		domains.add(matcher.group());
	}
	return domains;
}
 
Example 8
Source File: GradebookServiceHelperImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Add a published assessment to gradebook.
 * @param publishedAssessment the published assessment
 * @param g  the Gradebook Service
 * @return false: cannot add to gradebook
 * @throws java.lang.Exception
 */
public boolean addToGradebook(PublishedAssessmentData publishedAssessment, Long categoryId, 
  GradebookExternalAssessmentService g) throws
  Exception
{
  boolean added = false;
  String gradebookUId = GradebookFacade.getGradebookUId();
  if (gradebookUId == null)
  {
    return false;
  }

  if (g.isGradebookDefined(gradebookUId))
  {
    String title = StringEscapeUtils.unescapeHtml4(publishedAssessment.getTitle());
    if(!g.isAssignmentDefined(gradebookUId, title))
    {
        g.addExternalAssessment(gradebookUId,
                publishedAssessment.getPublishedAssessmentId().toString(),
                null,
                title,
                publishedAssessment.getTotalScore(),
                publishedAssessment.getAssessmentAccessControl().getDueDate(),
                getAppName(), // Use the app name from sakai
                null,
                false,
                categoryId);
      added = true;
    }
  }
  return added;
}
 
Example 9
Source File: HtmlCleaner.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * Removes HTML preformatting (if any).
 * @param value value (possibly pre-formatted)
 * @return value without HTML preformatting.
 */
public String cleanupPreFormatted(String value) {
    String result = value;
    if (value != null) {
        Matcher matcher = PRE_FORMATTED_PATTERN.matcher(value);
        if (matcher.matches()) {
            String escapedBody = matcher.group(1);
            result = StringEscapeUtils.unescapeHtml4(escapedBody);
        }
    }
    return result;
}
 
Example 10
Source File: RedditParsedPost.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
public RedditParsedPost(
		@NonNull final AppCompatActivity activity,
		final RedditPost src,
		final boolean parseSelfText) {

	this.mSrc = src;

	if(src.title == null) {
		mTitle = "[null]";
	} else {
		mTitle = StringEscapeUtils.unescapeHtml4(src.title.replace('\n', ' ')).trim();
	}

	mUrl = StringEscapeUtils.unescapeHtml4(src.getUrl());
	mPermalink = StringEscapeUtils.unescapeHtml4(src.permalink);

	if(parseSelfText && src.is_self && src.selftext_html != null && src.selftext.trim().length() > 0) {
		mSelfText = HtmlReader.parse(StringEscapeUtils.unescapeHtml4(src.selftext_html), activity);
	} else {
		mSelfText = null;
	}

	if(src.link_flair_text != null && src.link_flair_text.length() > 0) {
		mFlairText = StringEscapeUtils.unescapeHtml4(src.link_flair_text);
	} else {
		mFlairText = null;
	}
}
 
Example 11
Source File: AnswerHTMLConverter.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
	String text = (String)arg2;
	if (text == null) return null;

	return StringEscapeUtils.unescapeHtml4(text);
}
 
Example 12
Source File: TemplateFtlUtil.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
/**
 * Compiles a progress success action.
 * <p>
 * Currently the link handling is similar to org.ofbiz.widget.WidgetWorker.buildHyperlinkUrl.
 */
public static String compileProgressSuccessAction(String progressSuccessAction, HttpServletRequest request,
        HttpServletResponse response) {
    if (progressSuccessAction.startsWith("redirect;")) {
        String newAction = "none";
        String[] parts = progressSuccessAction.split(";", 3);
        if (parts.length == 3) {
            Boolean fullPath = null;
            Boolean secure = null;
            Boolean encode = null;
            String[] options = parts[1].split("\\s*,\\s*");
            for(String pair : options) {
                if (pair.length() > 0) {
                    String[] elems = pair.split("\\s*=\\s*", 2);
                    if (elems.length == 2) {
                        Boolean val = null;
                        if ("true".equals(elems[1])) {
                            val = true;
                        } else if ("false".equals(elems[1])) {
                            val = false;
                        }
                        if (val != null) {
                            if ("fullPath".equalsIgnoreCase(elems[0])) {
                                fullPath = val;
                            } else if ("secure".equalsIgnoreCase(elems[0])) {
                                secure = val;
                            } else if ("encode".equalsIgnoreCase(elems[0])) {
                                encode = val;
                            } else {
                                Debug.logError("Scipio: progress success action value has invalid option name: [" + pair + "] in " + progressSuccessAction, module);
                            }
                        } else {
                            Debug.logError("Scipio: progress success action value has invalid option value: [" + pair + "] in " + progressSuccessAction, module);
                        }
                    } else {
                        Debug.logError("Scipio: progress success action value has invalid option: [" + pair + "] in " + progressSuccessAction, module);
                    }
                }
            }
            String target = parts[2].replaceAll("&", "&amp;");
            StringBuilder sb = new StringBuilder();
            sb.append("redirect;");
            // we don't have access to WidgetWorker, but don't need anyway
            //try {
            //    WidgetWorker.buildHyperlinkUrl(sb, target, "intra-app", null, null, fullPath, secure, encode, request, response, context);
            //} catch (IOException e) {
            //    Debug.logError("Scipio: progress success action value has invalid format in " + progressSuccessAction, module);
            //}
            String localRequestName = StringEscapeUtils.unescapeHtml4(target);
            localRequestName = UtilHttp.encodeAmpersands(localRequestName);
            if (request != null && response != null) {
                // FIXME: this does not support inter-webapp links or any new parameters
                sb.append(RequestHandler.makeUrl(request, response, localRequestName, fullPath, secure, encode));
            } else {
                sb.append(localRequestName);
            }
            newAction = sb.toString();
        } else {
            Debug.logError("Scipio: progress success action value has invalid format in " + progressSuccessAction, module);
        }
        progressSuccessAction = newAction;
    }
    return progressSuccessAction;
}
 
Example 13
Source File: WikiPage.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected String doInBackground(Object[] params) {
    return StringEscapeUtils.unescapeHtml4(
            ((WikiManager) params[0]).get((String) params[1], (String) params[2]).getDataNode().get("content_html").asText());
}
 
Example 14
Source File: PageSteps.java    From vividus with Apache License 2.0 4 votes vote down vote up
private String decodeUrl(String url)
{
    return StringEscapeUtils.unescapeHtml4(URLDecoder.decode(url, StandardCharsets.UTF_8));
}
 
Example 15
Source File: ImageLoaderUtils.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options,
        ImageSize targetSize, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
    String newUri = StringEscapeUtils.unescapeHtml4(uri);
    super.displayImage(newUri, imageAware, options, targetSize, listener, progressListener);
}
 
Example 16
Source File: EncryptUtils.java    From platform with Apache License 2.0 4 votes vote down vote up
public static String unescapeHtml(String htmlEscaped) {
    return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 17
Source File: RedditParsedPost.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
public String getUnescapedSelfText() {
	return StringEscapeUtils.unescapeHtml4(mSrc.selftext);
}
 
Example 18
Source File: ImageInfo.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
public static ImageInfo parseDeviantArt(final JsonBufferedObject object)
		throws IOException, InterruptedException {

	String urlOriginal = null;
	String thumbnailUrl = null;
	String title = null;
	String tags = null;
	String type = null;
	Long width = null;
	Long height = null;
	Long size = (long) 0;

	if(object != null) {
		urlOriginal = object.getString("url");
		thumbnailUrl = object.getString("thumbnail_url");
		title = object.getString("title");
		tags = object.getString("tags");
		type = object.getString("imagetype");
		width = object.getLong("width");
		height = object.getLong("height");

	}

	if(title != null) {
		title = StringEscapeUtils.unescapeHtml4(title);
	}

	if(tags != null) {
		tags = StringEscapeUtils.unescapeHtml4(tags);
	}

	return new ImageInfo(
			urlOriginal,
			thumbnailUrl,
			title,
			tags,
			type,
			false,
			width,
			height,
			size,
			MediaType.IMAGE,
			HasAudio.NO_AUDIO);
}
 
Example 19
Source File: XmlUtility.java    From jstarcraft-core with Apache License 2.0 2 votes vote down vote up
/**
 * 对字符串执行HTML4.0解密
 * 
 * @param string
 * @return
 */
public static final String unescapeHtml4(String string) {
    return StringEscapeUtils.unescapeHtml4(string);
}
 
Example 20
Source File: HtmlFixture.java    From hsac-fitnesse-fixtures with Apache License 2.0 2 votes vote down vote up
/**
 * Unescapes supplied HTML content so it can be rendered inside a wiki page.
 * @param htmlSource HTML code to display (possibly surrounded by <pre></pre> tags).
 * @return unescaped content, enclosed in <div></div> so wiki will not escape it.
 */
public String html(String htmlSource) {
    String cleanSource = htmlCleaner.cleanupPreFormatted(htmlSource);
    return "<div>" + StringEscapeUtils.unescapeHtml4(cleanSource) + "</div>";
}