/** * Gets the diff HTML based on the selected display options.<p> * * @return the diff HTML to display * * @throws Exception if something goes wrong */ public String getDiffHtml() throws Exception { CmsDiffViewMode mode = "all".equals(m_diffMode) ? CmsDiffViewMode.ALL : CmsDiffViewMode.DIFF_ONLY; String text1 = m_text1; String text2 = m_text2; if ("text".equals(m_textMode)) { text1 = CmsHtml2TextConverter.html2text(text1, "UTF-8"); text2 = CmsHtml2TextConverter.html2text(text2, "UTF-8"); } CmsHtmlDifferenceConfiguration conf = new CmsHtmlDifferenceConfiguration( mode == CmsDiffViewMode.ALL ? -1 : 2, A_CmsUI.get().getLocale()); String diff = Diff.diffAsHtml(text1, text2, conf); String html = null; if (CmsStringUtil.isNotEmpty(diff)) { html = diff; } else { html = wrapLinesWithUnchangedStyle( CmsStringUtil.substitute(CmsStringUtil.escapeHtml(m_text1), "<br/>", "")); } return html; }
/** * Strips all HTML markup from the given input.<p> * * <ul> * <li>In case the input is an instance of {@link CmsJspContentAccessValueWrapper}, an optimized * method is used for the HTML stripping. * <li>Otherwise the input is converted to a String and this String is stripped. * </ul> * * @param input the input to Strip from HTML * * @return the given input with all HTML stripped. */ public static String stripHtml(Object input) { if (input instanceof CmsJspContentAccessValueWrapper) { CmsJspContentAccessValueWrapper wrapper = (CmsJspContentAccessValueWrapper)input; if (wrapper.getExists()) { return wrapper.obtainContentValue().getPlainText(wrapper.obtainCmsObject()); } else { return ""; } } try { return CmsHtml2TextConverter.html2text(String.valueOf(input), OpenCms.getSystemInfo().getDefaultEncoding()); } catch (Exception e) { return CmsMessages.formatUnknownKey(e.getMessage()); } }
/** * Strips all HTML markup from the given input.<p> * * <ul> * <li>In case the input is an instance of {@link CmsJspContentAccessValueWrapper}, an optimized * method is used for the HTML stripping. * <li>Otherwise the input is converted to a String and this String is stripped. * </ul> * * @param input the input to Strip from HTML * * @return the given input with all HTML stripped. */ public static String stripHtml(Object input) { if (input instanceof CmsJspContentAccessValueWrapper) { CmsJspContentAccessValueWrapper wrapper = (CmsJspContentAccessValueWrapper)input; if (wrapper.getExists()) { return wrapper.getContentValue().getPlainText(wrapper.obtainCmsObject()); } else { return ""; } } try { return CmsHtml2TextConverter.html2text(String.valueOf(input), OpenCms.getSystemInfo().getDefaultEncoding()); } catch (Exception e) { return CmsMessages.formatUnknownKey(e.getMessage()); } }