Search in sources :

Example 1 with XhtmlDocument

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);
    }
}
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 XhtmlDocument

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);
}
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 XhtmlDocument

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

Example 4 with XhtmlDocument

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);
    }
}
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 5 with XhtmlDocument

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;
}
Also used : FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) ArrayList(java.util.ArrayList)

Aggregations

XhtmlDocument (org.hl7.fhir.utilities.xhtml.XhtmlDocument)8 FileNotFoundException (java.io.FileNotFoundException)5 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)5 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)5 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ArrayList (java.util.ArrayList)3 TransformerException (javax.xml.transform.TransformerException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 StringWriter (java.io.StringWriter)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ConceptMapValidator (org.hl7.fhir.definitions.validation.ConceptMapValidator)1 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)1