use of net.htmlparser.jericho.OutputDocument in project vue-gwt by Axellience.
the class TemplateParser method parseHtmlTemplate.
/**
* Parse a given HTML template and return the a result object containing the expressions
* and a transformed HTML.
* @param htmlTemplate The HTML template to process, as a String
* @param context Context of the Component we are currently processing
* @param messager Used to report errors in template during Annotation Processing
* @return A {@link TemplateParserResult} containing the processed template and expressions
*/
public TemplateParserResult parseHtmlTemplate(String htmlTemplate, TemplateParserContext context, Messager messager) {
this.context = context;
this.logger = new TemplateParserLogger(context, messager);
initJerichoConfig(this.logger);
Source source = new Source(htmlTemplate);
outputDocument = new OutputDocument(source);
result = new TemplateParserResult(context);
processImports(source);
source.getChildElements().forEach(this::processElement);
result.setProcessedTemplate(outputDocument.toString());
return result;
}
use of net.htmlparser.jericho.OutputDocument in project liferay-ide by liferay.
the class AdminUtil method getKBArticleDiff.
public static String getKBArticleDiff(long resourcePrimKey, int sourceVersion, int targetVersion, String param) throws Exception {
if (sourceVersion < KBArticleConstants.DEFAULT_VERSION) {
sourceVersion = KBArticleConstants.DEFAULT_VERSION;
}
if (sourceVersion == targetVersion) {
KBArticle kbArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, targetVersion);
return BeanPropertiesUtil.getString(kbArticle, param);
}
KBArticle sourceKBArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, sourceVersion);
KBArticle targetKBArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, targetVersion);
String sourceHtml = BeanPropertiesUtil.getString(sourceKBArticle, param);
String targetHtml = BeanPropertiesUtil.getString(targetKBArticle, param);
String diff = DiffHtmlUtil.diff(new UnsyncStringReader(sourceHtml), new UnsyncStringReader(targetHtml));
Source source = new Source(diff);
OutputDocument outputDocument = new OutputDocument(source);
for (Element element : source.getAllElements()) {
StringBundler sb = new StringBundler(4);
Attributes attributes = element.getAttributes();
if (attributes == null) {
continue;
}
Attribute changeTypeAttribute = attributes.get("changeType");
if (changeTypeAttribute != null) {
String changeTypeValue = changeTypeAttribute.getValue();
if (changeTypeValue.contains("diff-added-image")) {
sb.append("border: 10px solid #CFC; ");
} else if (changeTypeValue.contains("diff-changed-image")) {
sb.append("border: 10px solid #C6C6FD; ");
} else if (changeTypeValue.contains("diff-removed-image")) {
sb.append("border: 10px solid #FDC6C6; ");
}
}
Attribute classAttribute = attributes.get("class");
if (classAttribute != null) {
String classValue = classAttribute.getValue();
if (classValue.contains("diff-html-added")) {
sb.append("background-color: #CFC; ");
} else if (classValue.contains("diff-html-changed")) {
sb.append("background-color: #C6C6FD; ");
} else if (classValue.contains("diff-html-removed")) {
sb.append("background-color: #FDC6C6; ");
sb.append("text-decoration: line-through; ");
}
}
if (Validator.isNull(sb.toString())) {
continue;
}
Attribute styleAttribute = attributes.get("style");
if (styleAttribute != null) {
sb.append(GetterUtil.getString(styleAttribute.getValue()));
}
Map<String, String> map = outputDocument.replace(attributes, false);
map.put("style", sb.toString());
}
return outputDocument.toString();
}
Aggregations