use of net.htmlparser.jericho.SourceFormatter in project jahia by Jahia.
the class JahiaContentManagementServiceImpl method drawPortletInstanceOutput.
@Override
public GWTJahiaPortletOutputBean drawPortletInstanceOutput(String windowID, String entryPointIDStr, String pathInfo, String queryString) {
GWTJahiaPortletOutputBean result = new GWTJahiaPortletOutputBean();
try {
int fieldId = Integer.parseInt(windowID);
String portletOutput = ServicesRegistry.getInstance().getApplicationsDispatchService().getAppOutput(fieldId, entryPointIDStr, getRemoteJahiaUser(), getRequest(), getResponse(), getServletContext(), getWorkspace());
try {
JCRNodeWrapper node = JCRSessionFactory.getInstance().getCurrentUserSession().getNodeByUUID(entryPointIDStr);
String nodeTypeName = node.getPrimaryNodeTypeName();
/**
* todo cleanup the hardcoded value here
*/
if ("jnt:htmlPortlet".equals(nodeTypeName)) {
result.setInIFrame(false);
}
if ("jnt:contentPortlet".equals(nodeTypeName) || "jnt:rssPortlet".equals(nodeTypeName)) {
result.setInContentPortlet(true);
}
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
}
result.setHtmlOutput(portletOutput);
// what we need to do now is to do special processing for <script> tags, and on the client side we will
// create them dynamically.
Source source = new Source(portletOutput);
source = new Source((new SourceFormatter(source)).toString());
List<StartTag> scriptTags = source.getAllStartTags(HTMLElementName.SCRIPT);
for (StartTag curScriptTag : scriptTags) {
if ((curScriptTag.getAttributeValue("src") != null) && (!curScriptTag.getAttributeValue("src").equals(""))) {
result.getScriptsWithSrc().add(curScriptTag.getAttributeValue("src"));
} else {
result.getScriptsWithCode().add(curScriptTag.getElement().getContent().toString());
}
}
} catch (JahiaException e) {
logger.error(e.getMessage(), e);
}
return result;
}
use of net.htmlparser.jericho.SourceFormatter in project jahia by Jahia.
the class SourceFormatterFilter method execute.
@Override
public String execute(String previousOut, RenderContext renderContext, Resource resource, RenderChain chain) throws Exception {
long timer = System.currentTimeMillis();
final SourceFormatter sourceFormatter = new SourceFormatter(new Source(previousOut));
sourceFormatter.setIndentString(" ");
String out = sourceFormatter.toString();
if (logger.isDebugEnabled()) {
logger.debug("Formatting took {} ms", System.currentTimeMillis() - timer);
}
return out;
}
use of net.htmlparser.jericho.SourceFormatter in project jahia by Jahia.
the class DiffHelper method getHighlighted.
public String getHighlighted(String original, String amendment) {
final StringWriter sw = new StringWriter();
try {
final SAXTransformerFactory transformerFactory = (SAXTransformerFactory) JahiaTransformerFactory.newInstance();
final TransformerHandler result = transformerFactory.newTransformerHandler();
result.setResult(new StreamResult(sw));
final XslFilter filter = new XslFilter();
// replace /live/ by /default/ in href and src attributes as it represents same image
if (original.contains("/files/" + Constants.EDIT_WORKSPACE + "/") || amendment.contains("/files/" + Constants.EDIT_WORKSPACE + "/")) {
original = LIVE_WS_PATTERN.matcher(original).replaceAll("/" + Constants.EDIT_WORKSPACE + "/");
amendment = LIVE_WS_PATTERN.matcher(amendment).replaceAll("/" + Constants.EDIT_WORKSPACE + "/");
}
original = new SourceFormatter(new Source(original)).toString();
amendment = new SourceFormatter(new Source(amendment)).toString();
final ContentHandler postProcess = filter.xsl(result, "jahiahtmlheader.xsl");
final Locale locale = Locale.ENGLISH;
final String prefix = "diff";
final HtmlCleaner cleaner = new HtmlCleaner();
final InputSource oldSource = new InputSource(new StringReader(original));
final InputSource newSource = new InputSource(new StringReader(amendment));
final DomTreeBuilder oldHandler = new DomTreeBuilder();
cleaner.cleanAndParse(oldSource, oldHandler);
final TextNodeComparator leftComparator = new TextNodeComparator(oldHandler, locale);
final DomTreeBuilder newHandler = new DomTreeBuilder();
cleaner.cleanAndParse(newSource, newHandler);
final TextNodeComparator rightComparator = new TextNodeComparator(newHandler, locale);
postProcess.startDocument();
postProcess.startElement("", "diffreport", "diffreport", new AttributesImpl());
addDiffCss(postProcess);
postProcess.startElement("", "diff", "diff", new AttributesImpl());
final HtmlSaxDiffOutput output = new HtmlSaxDiffOutput(postProcess, prefix);
final HTMLDiffer differ = new HTMLDiffer(output);
differ.diff(rightComparator, leftComparator);
postProcess.endElement("", "diff", "diff");
postProcess.endElement("", "diffreport", "diffreport");
postProcess.endDocument();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return sw.toString();
}
use of net.htmlparser.jericho.SourceFormatter in project ramus by Vitaliy-Yakovchuk.
the class HTMLView method setHTMLText.
public void setHTMLText(String htmlText) {
try {
this.text = htmlText;
if (formatt) {
Source segment = new Source(text);
segment.fullSequentialParse();
SourceFormatter formatter = new SourceFormatter(segment);
htmlText = formatter.toString();
}
editorPane.read(new StringReader(htmlText), null);
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations