Search in sources :

Example 1 with XhtmlParser

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);
    }
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument)

Example 2 with XhtmlParser

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);
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 3 with XhtmlParser

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);
    }
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FileInputStream(java.io.FileInputStream) FileNotFoundException(java.io.FileNotFoundException) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument)

Example 4 with XhtmlParser

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);
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 5 with XhtmlParser

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();
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) CompartmentDefinitionResourceComponent(org.hl7.fhir.dstu2016may.model.CompartmentDefinition.CompartmentDefinitionResourceComponent) StringType(org.hl7.fhir.dstu2016may.model.StringType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)40 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)25 FHIRException (org.hl7.fhir.exceptions.FHIRException)19 IOException (java.io.IOException)14 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)10 FileNotFoundException (java.io.FileNotFoundException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 XhtmlDocument (org.hl7.fhir.utilities.xhtml.XhtmlDocument)6 TransformerException (javax.xml.transform.TransformerException)5 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)5 CDANarrativeFormat (org.hl7.fhir.utilities.xhtml.CDANarrativeFormat)5 Node (org.w3c.dom.Node)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 MarkDownProcessor (org.hl7.fhir.utilities.MarkDownProcessor)4 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3