use of org.hl7.fhir.utilities.xhtml.XhtmlDocument 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.XhtmlDocument 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.XhtmlDocument in project kindling by HL7.
the class BookMaker method checkCrossLinks.
private void checkCrossLinks() {
for (String name : pages.keySet()) {
if (!"toc.html".equals(name)) {
XhtmlDocument d = pages.get(name);
checkCrossLinks(name, d);
}
}
}
use of org.hl7.fhir.utilities.xhtml.XhtmlDocument 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.XhtmlDocument in project org.hl7.fhir.core by hapifhir.
the class XhtmlParser method parse.
private XhtmlDocument parse(String entryName) throws FHIRFormatError, IOException {
XhtmlDocument result = new XhtmlDocument();
skipWhiteSpaceAndComments(result);
if (peekChar() != '<')
throw new FHIRFormatError("Unable to Parse HTML - does not start with tag. Found " + peekChar() + descLoc());
readChar();
markLocation();
QName n = new QName(readName().toLowerCase());
if ((entryName != null) && !n.getName().equals(entryName))
throw new FHIRFormatError("Unable to Parse HTML - starts with '" + n + "' not '" + entryName + "'" + descLoc());
XhtmlNode root = result.addTag(n.getName());
root.setLocation(markLocation());
parseAttributes(root);
markLocation();
NSMap nsm = checkNamespaces(n, root, null, true);
if (readChar() == '/') {
if (peekChar() != '>')
throw new FHIRFormatError("unexpected non-end of element " + n + " " + descLoc());
readChar();
} else {
unwindPoint = null;
List<XhtmlNode> p = new ArrayList<>();
parseElementInner(root, p, nsm, true);
}
return result;
}
Aggregations