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.quantumbadger.redreader.reddit.prepared.RedditPreparedMessage.java
public RedditPreparedMessage(final Context context, final RedditMessage message, final long timestamp) { this.src = message; // TODO custom time final int rrCommentHeaderBoldCol; final int rrCommentHeaderAuthorCol; {// w w w. j a va2 s . c om final TypedArray appearance = context.obtainStyledAttributes( new int[] { R.attr.rrCommentHeaderBoldCol, R.attr.rrCommentHeaderAuthorCol, }); rrCommentHeaderBoldCol = appearance.getColor(0, 255); rrCommentHeaderAuthorCol = appearance.getColor(1, 255); appearance.recycle(); } body = MarkdownParser.parse(StringEscapeUtils.unescapeHtml4(message.body).toCharArray()); idAndType = message.name; final BetterSSB sb = new BetterSSB(); if (src.author == null) { sb.append("[" + context.getString(R.string.general_unknown) + "]", BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f); } else { sb.append(src.author, BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f); } sb.append(" ", 0); sb.append(RRTime.formatDurationFrom(context, src.created_utc * 1000L), BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderBoldCol, 0, 1f); header = sb.get(); }
From source file:org.quantumbadger.redreader.reddit.prepared.RedditPreparedPost.java
public RedditPreparedPost(final Context context, final CacheManager cm, final int listId, final RedditPost post, final long timestamp, final boolean showSubreddit, final boolean updateNeeded, final boolean showThumbnails, final boolean precacheImages, final RedditAccount user, final boolean parseSelfText) { this.src = post; this.showSubreddit = showSubreddit; if (post.title == null) { title = "[null]"; } else {/* www .j a va 2 s. c om*/ title = StringEscapeUtils.unescapeHtml4(post.title.replace('\n', ' ')).trim(); } idAlone = post.id; idAndType = post.name; url = StringEscapeUtils.unescapeHtml4(post.url); mIsProbablyAnImage = LinkHandler.isProbablyAnImage(url); commentCount = post.num_comments; if (post.likes == null) { voteDirection = 0; } else { voteDirection = Boolean.TRUE.equals(post.likes) ? 1 : -1; } this.saved = post.saved; this.hidden = post.hidden; this.stickied = post.stickied; thumbnailUrl = post.thumbnail; hasThumbnail = showThumbnails && hasThumbnail(post); // TODO parameterise final int thumbnailWidth = General.dpToPixels(context, 64); if (hasThumbnail && hasThumbnail(post)) { downloadThumbnail(context, thumbnailWidth, cm, listId); } // TODO precache comments (respect settings) lastChange = timestamp; if (voteDirection != 0 || saved || hidden) { RedditChangeDataManager.getInstance(context).update("posts", user, this, true); } else if (updateNeeded) { RedditChangeDataManager.getInstance(context).update("posts", user, this, false); } rebuildSubtitle(context); if (parseSelfText && src.is_self && src.selftext != null && src.selftext.trim().length() > 0) { parsedSelfText = MarkdownParser.parse(StringEscapeUtils.unescapeHtml4(post.selftext).toCharArray()); } else { parsedSelfText = null; } }
From source file:org.quantumbadger.redreader.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final Activity activity, final Action action) { switch (action) { case UPVOTE://from www .j a v a2s . c om post.action(activity, RedditAPI.RedditAction.UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.RedditAction.DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.RedditAction.UNVOTE); break; case SAVE: post.action(activity, RedditAPI.RedditAction.SAVE); break; case UNSAVE: post.action(activity, RedditAPI.RedditAction.UNSAVE); break; case HIDE: post.action(activity, RedditAPI.RedditAction.HIDE); break; case UNHIDE: post.action(activity, RedditAPI.RedditAction.UNHIDE); break; case DELETE: new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm) .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.DELETE); } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case REPORT: new AlertDialog.Builder(activity).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.REPORT); // TODO update the view to show the result // TODO don't forget, this also hides } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case EXTERNAL: { final Intent intent = new Intent(Intent.ACTION_VIEW); String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl() : post.url; intent.setData(Uri.parse(url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.selftext)); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_self); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setItems(linksArr, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { final RedditAccount anon = RedditAccountManager.getAnon(); LinkHandler.getImageInfo(activity, post.url, Constants.Priority.IMAGE_VIEW, 0, new GetImageInfoListener() { @Override public void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { final RRError error = General.getGeneralErrorForFailure(activity, type, t, status, post.url); General.showResultDialog(activity, error); } @Override public void onSuccess(final ImgurAPI.ImageInfo info) { CacheManager.getInstance(activity) .makeRequest(new CacheRequest(General.uriFromString(info.urlOriginal), anon, null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, activity) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onDownloadNecessary() { General.quickToast(context, R.string.download_downloading); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, url.toString()); General.showResultDialog(activity, error); } @Override protected void onProgress(boolean authorizationInProgress, long bytesRead, long totalBytes) { } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { File dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), General.uriFromString(info.urlOriginal).getPath()); if (dst.exists()) { int count = 0; while (dst.exists()) { count++; dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), count + "_" + General.uriFromString(info.urlOriginal) .getPath().substring(1)); } } try { final InputStream cacheFileInputStream = cacheFile.getInputStream(); if (cacheFileInputStream == null) { notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image"); return; } General.copyFile(cacheFileInputStream, dst); } catch (IOException e) { notifyFailure(RequestFailureType.STORAGE, e, null, "Could not copy file"); return; } activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + dst.getAbsolutePath()))); General.quickToast(context, context.getString(R.string.action_save_image_success) + " " + dst.getAbsolutePath()); } }); } @Override public void onNotAnImage() { General.quickToast(activity, R.string.selected_link_is_not_image); } }); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.title); mailer.putExtra(Intent.EXTRA_TEXT, post.url); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.title); mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getUri(Constants.Reddit.PATH_COMMENTS + post.idAlone).toString()); activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.url); break; } case GOTO_SUBREDDIT: { try { final Intent intent = new Intent(activity, PostListingActivity.class); intent.setData(SubredditPostListURL.getSubreddit(post.src.subreddit).generateJsonUri()); activity.startActivityForResult(intent, 1); } catch (RedditSubreddit.InvalidSubredditNameException e) { Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show(); } break; } case USER_PROFILE: LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.author).toString()); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src).show(activity.getFragmentManager(), null); break; case COMMENTS: ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK: ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra("parentIdAndType", post.idAndType); activity.startActivity(intent); break; } }
From source file:org.quantumbadger.redreader.reddit.prepared.RedditPreparedPost.java
private void rebuildSubtitle(Context context) { // TODO customise display // TODO preference for the X days, X hours thing final TypedArray appearance = context .obtainStyledAttributes(new int[] { R.attr.rrPostSubtitleBoldCol, R.attr.rrPostSubtitleUpvoteCol, R.attr.rrPostSubtitleDownvoteCol, R.attr.rrFlairBackCol, R.attr.rrFlairTextCol }); final int boldCol = appearance.getColor(0, 255), rrPostSubtitleUpvoteCol = appearance.getColor(1, 255), rrPostSubtitleDownvoteCol = appearance.getColor(2, 255), rrFlairBackCol = appearance.getColor(3, 255), rrFlairTextCol = appearance.getColor(4, 255); appearance.recycle();// www . j ava 2 s . c o m final BetterSSB postListDescSb = new BetterSSB(); final int pointsCol; int score = src.score; if (Boolean.TRUE.equals(src.likes)) score--; if (Boolean.FALSE.equals(src.likes)) score++; if (isUpvoted()) { pointsCol = rrPostSubtitleUpvoteCol; score++; } else if (isDownvoted()) { pointsCol = rrPostSubtitleDownvoteCol; score--; } else { pointsCol = boldCol; } if (src.over_18) { postListDescSb.append(" NSFW ", BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR, Color.WHITE, Color.RED, 1f); // TODO color? postListDescSb.append(" ", 0); } if (src.link_flair_text != null && src.link_flair_text.length() > 0) { postListDescSb.append(" " + StringEscapeUtils.unescapeHtml4(src.link_flair_text) + " ", BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR, rrFlairTextCol, rrFlairBackCol, 1f); postListDescSb.append(" ", 0); } postListDescSb.append(String.valueOf(score), BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, pointsCol, 0, 1f); postListDescSb.append(" " + context.getString(R.string.subtitle_points) + " ", 0); postListDescSb.append(RRTime.formatDurationFrom(context, src.created_utc * 1000), BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f); postListDescSb.append(" " + context.getString(R.string.subtitle_by) + " ", 0); postListDescSb.append(src.author, BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f); if (showSubreddit) { postListDescSb.append(" " + context.getString(R.string.subtitle_to) + " ", 0); postListDescSb.append(src.subreddit, BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f); } postListDescSb.append(" (" + src.domain + ")", 0); postListDescription = postListDescSb.get(); }
From source file:org.seasar.robot.extractor.impl.AbstractXmlExtractor.java
public ExtractData getText(final InputStream in, final Map<String, String> params) { if (in == null) { throw new RobotSystemException("The inputstream is null."); }//from ww w . j a v a 2s . co m try { final BufferedInputStream bis = new BufferedInputStream(in); final String enc = getEncoding(bis); final String content = StringEscapeUtils.unescapeHtml4(new String(InputStreamUtil.getBytes(bis), enc)); return new ExtractData(extractString(content)); } catch (final Exception e) { throw new ExtractException(e); } }
From source file:org.silverpeas.core.util.EncodeHelper.java
/** * This method transforms a text with caracter specificly encoded for HTML by a text encoded in * according to the Java code./*ww w .j a v a 2s .c o m*/ * * @param text (String) a single text which contains a lot of forbidden caracters. This text must * not be null * @return Returns the transformed text without specific codes. */ public static String transformHtmlCode(String text) { return StringEscapeUtils.unescapeHtml4(text); }
From source file:org.silverpeas.core.util.WebEncodeHelper.java
/** * Convert a html string to a java string. Replace " * * @param htmlstring HTML string to encode * @return html string JAVA encoded/* ww w . ja v a 2s. c o m*/ */ public static String htmlStringToJavaString(String htmlstring) { if (!isDefined(htmlstring)) { return ""; } return StringEscapeUtils.unescapeHtml4(htmlstring); }
From source file:org.silverpeas.migration.publication.HtmlUnescaperTest.java
@Test public void unescapeSomeEncodedHtmlText() { String htmlText = "L'origine de ce livre est <celui-ci>"; String encodedText = Encode.forHtml(htmlText); String decodedText = StringEscapeUtils.unescapeHtml4(encodedText); assertThat(decodedText, is(htmlText)); }
From source file:org.sleuthkit.autopsy.coreutils.EscapeUtil.java
/** * Unescape html// www. j av a 2 s . c o m * @param toUnescape text (potentially escaped html) to unescape * @return html unescaped string */ public static String unEscapeHtml(String toUnescape) { return StringEscapeUtils.unescapeHtml4(toUnescape); }
From source file:org.spdx.rdfparser.license.License.java
@Override public void getPropertiesFromModel() throws InvalidSPDXAnalysisException { super.getPropertiesFromModel(); // text// w w w . ja va2s . co m licenseText = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_TEXT); if (licenseText != null && licenseText.endsWith(XML_LITERAL)) { this.licenseText = this.licenseText.substring(0, this.licenseText.length() - XML_LITERAL.length()); } if (licenseText != null && this.textInHtml) { this.licenseText = SpdxLicenseTemplateHelper.htmlToText(this.licenseText); } // standardLicenseHeader standardLicenseHeader = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_NOTICE); if (standardLicenseHeader == null) { standardLicenseHeader = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_HEADER_VERSION_1); } if (standardLicenseHeader != null) { standardLicenseHeader = StringEscapeUtils.unescapeHtml4(standardLicenseHeader); } standardLicenseHeaderTemplate = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_HEADER_TEMPLATE); if (standardLicenseHeaderTemplate != null) { standardLicenseHeaderTemplate = StringEscapeUtils.unescapeHtml4(standardLicenseHeaderTemplate); } // template this.standardLicenseTemplate = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_TEMPLATE); if (this.standardLicenseTemplate == null) { // try version 1 this.standardLicenseTemplate = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_TEMPLATE_VERSION_1); } if (standardLicenseTemplate != null && standardLicenseTemplate.endsWith(XML_LITERAL)) { this.standardLicenseTemplate = this.standardLicenseTemplate.substring(0, this.standardLicenseTemplate.length() - XML_LITERAL.length()); } if (standardLicenseTemplate != null && this.templateInHtml) { this.standardLicenseTemplate = SpdxLicenseTemplateHelper.htmlToText(this.standardLicenseTemplate); } // OSI Approved String osiTextValue = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_OSI_APPROVED); if (osiTextValue == null) { // for compatibility, check the version 1 property name osiTextValue = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_OSI_APPROVED_VERSION_1); } if (osiTextValue != null) { osiTextValue = osiTextValue.trim(); 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; } String fsfTextValue = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_STD_LICENSE_FSF_LIBRE); if (fsfTextValue != null) { fsfTextValue = fsfTextValue.trim(); if (fsfTextValue.equals("true") || fsfTextValue.equals("1")) { this.fsfLibre = true; } else if (fsfTextValue.equals("false") || fsfTextValue.equals("0")) { this.fsfLibre = false; } else { throw (new InvalidSPDXAnalysisException( "Invalid value for FSF Free - must be {true, false, 0, 1}")); } } else { fsfLibre = null; } // Deprecated String deprecatedValue = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LIC_ID_DEPRECATED); if (deprecatedValue != null) { deprecatedValue = deprecatedValue.trim(); if (deprecatedValue.equals("true") || deprecatedValue.equals("1")) { this.deprecated = true; } else if (deprecatedValue.equals("false") || deprecatedValue.equals("0")) { this.deprecated = false; } else { throw (new InvalidSPDXAnalysisException( "Invalid value for license deprecated - must be {true, false, 0, 1}")); } } }