use of org.hl7.fhir.utilities.xhtml.XhtmlParser in project kindling by HL7.
the class Publisher method cachePage.
private void cachePage(String filename, String source, String title, boolean includeInBook) throws Exception {
try {
// page.log("parse "+filename);
XhtmlDocument src = new XhtmlParser().parse(source, "html");
scanForFragments(filename, src);
// book.getPages().put(filename, src);
page.getHTMLChecker().registerFile(filename, title, HTMLLinkChecker.XHTML_TYPE, includeInBook);
} catch (Exception e) {
throw new Exception("error parsing page " + filename + ": " + e.getMessage() + " in source\r\n" + source, e);
}
}
use of org.hl7.fhir.utilities.xhtml.XhtmlParser in project kindling by HL7.
the class BookMaker method produceBookForm.
private void produceBookForm() throws FileNotFoundException, Exception {
target = page.getFolders().dstDir;
target = target + File.separator;
checkCrossLinks();
String src = TextFile.fileToString(page.getFolders().srcDir + "book.html");
src = page.processPageIncludes(page.getFolders().srcDir + "book.html", src, "book", null, null, null, "Book", null, null, null);
XhtmlDocument doc = new XhtmlParser().parse(src, "html");
XhtmlNode body = doc.getElement("html").getElement("body");
addTOC(body);
addContent(body);
addReferenceIds(body);
new XhtmlComposer(XhtmlComposer.HTML).compose(new FileOutputStream(target + "fhir-book.html"), doc);
}
use of org.hl7.fhir.utilities.xhtml.XhtmlParser in project kindling by HL7.
the class HTMLLinkChecker method check.
private void check(Entry e) throws Exception {
if (new File(Utilities.path(page.getFolders().dstDir, e.filename)).exists()) {
e.checked = true;
checkNormativeStatus(e.filename);
XhtmlDocument doc;
try {
doc = new XhtmlParser().parse(new FileInputStream(Utilities.path(page.getFolders().dstDir, e.filename)), "html");
checkAnchors(doc, e);
checkLinks(doc, e);
stripDivs(doc);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
new XhtmlComposer(XhtmlComposer.HTML).compose(stream, doc);
e.bytes = stream.toByteArray();
if (e.bytes == null || e.bytes.length == 0)
throw new Exception("File is empty");
} catch (Exception e1) {
throw new Exception("Error parsing " + Utilities.path(page.getFolders().dstDir, e.filename), e1);
}
} else {
reportError(e.filename, "Unable to find file " + e.filename);
}
}
use of org.hl7.fhir.utilities.xhtml.XhtmlParser in project kindling by HL7.
the class Publisher method fixExampleReferences.
private String fixExampleReferences(String path, String narrative) throws Exception {
if (narrative == null)
return "";
XhtmlNode node = new XhtmlParser().parseFragment(narrative);
checkExampleLinks(path, node);
return new XhtmlComposer(XhtmlComposer.HTML).compose(node);
}
use of org.hl7.fhir.utilities.xhtml.XhtmlParser in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generate.
public void generate(CompartmentDefinition cpd) {
StringBuilder in = new StringBuilder();
StringBuilder out = new StringBuilder();
for (CompartmentDefinitionResourceComponent cc : cpd.getResource()) {
CommaSeparatedStringBuilder rules = new CommaSeparatedStringBuilder();
if (!cc.hasParam()) {
out.append(" <li><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></li>\r\n");
} else if (!rules.equals("{def}")) {
for (StringType p : cc.getParam()) rules.append(p.asStringValue());
in.append(" <tr><td><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></td><td>").append(rules.toString()).append("</td></tr>\r\n");
}
}
XhtmlNode x;
try {
x = new XhtmlParser().parseFragment("<div><p>\r\nThe following resources may be in this compartment:\r\n</p>\r\n" + "<table class=\"grid\">\r\n" + " <tr><td><b>Resource</b></td><td><b>Inclusion Criteria</b></td></tr>\r\n" + in.toString() + "</table>\r\n" + "<p>\r\nA resource is in this compartment if the nominated search parameter (or chain) refers to the patient resource that defines the compartment.\r\n</p>\r\n" + "<p>\r\n\r\n</p>\r\n" + "<p>\r\nThe following resources are never in this compartment:\r\n</p>\r\n" + "<ul>\r\n" + out.toString() + "</ul></div>\r\n");
inject(cpd, x, NarrativeStatus.GENERATED);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations