Search in sources :

Example 11 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.

the class BookMaker method checkCrossLinks.

private void checkCrossLinks(String name, XhtmlNode node) {
    if (node.getNodeType() == NodeType.Element && node.getName().equals("a")) {
        String href = node.getAttribute("href");
        if (href != null) {
            if (!pages.containsKey(href)) {
                boolean found = false;
                if (href.endsWith(".xsd") || href.endsWith(".xml") || href.endsWith(".xml.html") || href.endsWith(".json") || href.endsWith(".zip"))
                    found = true;
                else if (pages.containsKey(href))
                    found = true;
                else if (href.startsWith("http:") || href.startsWith("https:") || href.startsWith("mailto:") || href.startsWith("ftp:"))
                    found = true;
                else if (href.startsWith("v2/") || href.startsWith("v3/") || href.startsWith("../")) {
                    found = true;
                    node.setAttribute("href", "http://hl7.org/fhir" + href);
                }
                if (!found && href.contains("#")) {
                    String[] parts = href.split("#");
                    if (parts == null || parts.length == 0) {
                        parts = new String[] { name };
                    } else if (parts[0].equals(""))
                        parts[0] = name;
                    found = pages.containsKey(parts[0]);
                    if (found && parts[1] != null && !parts[1].equals("")) {
                        found = findTarget(pages.get(parts[0]), parts[1]);
                        if (!found)
                            try {
                                if (new File("c:\\temp\\source.html").exists())
                                    new XhtmlComposer(XhtmlComposer.HTML).compose(new FileOutputStream("c:\\temp\\source.html"), pages.get(parts[0]));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                    }
                }
                if (!found && !new File(page.getFolders().dstDir + href).exists() && !href.equals("qa.html")) {
                    issues.add(new ValidationMessage(Source.Publisher, IssueType.INFORMATIONAL, -1, -1, name, "broken link in " + name + ": <a href=\"" + href + "\">" + node.allText() + "</a>", IssueSeverity.ERROR));
                }
            }
        }
    } else {
        if (!(node.getNodeType() == NodeType.Element && "div".equals(node.getName()) && "index-only-no-book".equals(node.getAttribute("class"))))
            for (XhtmlNode c : node.getChildNodes()) checkCrossLinks(name, c);
    }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FileNotFoundException(java.io.FileNotFoundException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 12 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer 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 13 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.

the class LogicalModelProcessor method genLogicalModelTable.

private String genLogicalModelTable(StructureDefinition sd, String prefix) throws Exception {
    ProfileUtilities pu = new ProfileUtilities(page.getWorkerContext(), null, this);
    XhtmlNode x = pu.generateTable(sd.getId() + "-definitions.html", sd, sd.hasSnapshot() ? false : true, page.getFolders().dstDir, false, sd.getId(), true, prefix, prefix, true, false, null, true, false);
    return new XhtmlComposer(XhtmlComposer.HTML).compose(x);
}
Also used : ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 14 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.

the class SourceParser method loadConformancePackage.

private void loadConformancePackage(Profile ap, List<ValidationMessage> issues, WorkGroup wg) throws FileNotFoundException, IOException, Exception {
    if (ap.getSourceType() == ConformancePackageSourceType.Spreadsheet) {
        OldSpreadsheetParser sparser = new OldSpreadsheetParser(ap.getCategory(), new CSFileInputStream(ap.getSource()), Utilities.noString(ap.getId()) ? ap.getSource() : ap.getId(), ap.getSource(), definitions, srcDir, logger, registry, version, context, genDate, false, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
        sparser.setFolder(Utilities.getDirectoryForFile(ap.getSource()));
        sparser.parseConformancePackage(ap, definitions, Utilities.getDirectoryForFile(ap.getSource()), ap.getCategory(), issues, wg);
        errors.addAll(sparser.getErrors());
    } else if (ap.getSourceType() == ConformancePackageSourceType.StructureDefinition) {
        Resource rf;
        try {
            rf = new XmlParser().parse(new CSFileInputStream(ap.getSource()));
        } catch (Exception e) {
            throw new Exception("Error parsing " + ap.getSource() + ": " + e.getMessage(), e);
        }
        if (!(rf instanceof StructureDefinition))
            throw new Exception("Error parsing Profile: not a structure definition");
        StructureDefinition sd = (StructureDefinition) rf;
        sd.setVersion(version.toCode());
        ap.putMetadata("id", sd.getId() + "-pack");
        ap.putMetadata("date", sd.getDateElement().asStringValue());
        ap.putMetadata("title", sd.getTitle());
        ap.putMetadata("status", sd.getStatus().toCode());
        ap.putMetadata("description", new XhtmlComposer(XhtmlComposer.HTML).compose(sd.getText().getDiv()));
        if (ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg")) {
            wg = definitions.getWorkgroups().get(ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg"));
            ap.putMetadata("workgroup", wg.getCode());
        }
        ap.setTitle(sd.getTitle());
        new ProfileUtilities(page.getWorkerContext(), null, null).setIds(sd, false);
        ap.getProfiles().add(new ConstraintStructure(sd, definitions.getUsageIG(ap.getCategory(), "Parsing " + ap.getSource()), wg == null ? wg(sd) : wg, fmm(sd), sd.getExperimental()));
    } else if (ap.getSource() != null) {
        parseConformanceDocument(ap, ap.getId(), new CSFile(ap.getSource()), ap.getCategory(), wg);
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) Resource(org.hl7.fhir.r5.model.Resource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) CSFile(org.hl7.fhir.utilities.CSFile) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 15 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer 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)

Aggregations

XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)78 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)31 FHIRException (org.hl7.fhir.exceptions.FHIRException)15 IOException (java.io.IOException)14 FileOutputStream (java.io.FileOutputStream)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)11 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)11 File (java.io.File)10 FileNotFoundException (java.io.FileNotFoundException)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)10 RenderingContext (org.hl7.fhir.r5.renderers.utils.RenderingContext)10 FileInputStream (java.io.FileInputStream)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 HashMap (java.util.HashMap)7 TransformerException (javax.xml.transform.TransformerException)7 XmlParser (org.hl7.fhir.r5.formats.XmlParser)7 ValueSet (org.hl7.fhir.r5.model.ValueSet)7 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)6 URISyntaxException (java.net.URISyntaxException)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5