Search in sources :

Example 6 with CSFile

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

the class Publisher method copyImage.

private void copyImage(String folder, String n) throws IOException {
    if (n.contains("*")) {
        final String filter = n.replace("?", ".?").replace("*", ".*?");
        File[] files = new File(folder).listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.matches(filter);
            }
        });
        for (File f : files) {
            Utilities.copyFile(f, new CSFile(page.getFolders().dstDir + f.getName()));
            page.getHTMLChecker().registerFile(f.getName(), "Support File", HTMLLinkChecker.determineType(n), true);
        }
    } else {
        Utilities.copyFile(new CSFile(Utilities.path(folder, n)), new CSFile(page.getFolders().dstDir + (n.contains("/") ? n.substring(n.lastIndexOf("/") + 1) : n)));
        page.getHTMLChecker().registerFile(n, "Support File", HTMLLinkChecker.determineType(n), true);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) CSFile(org.hl7.fhir.utilities.CSFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile)

Example 7 with CSFile

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

the class Publisher method produceArchive.

private void produceArchive() throws Exception {
    String target = page.getFolders().archiveDir + "v" + page.getVersion() + ".zip";
    File tf = new CSFile(target);
    if (tf.exists())
        tf.delete();
    ZipGenerator zip = new ZipGenerator(target);
    int c = 0;
    String[] files = new CSFile(page.getFolders().dstDir).list();
    for (String f : files) {
        File fn = new CSFile(page.getFolders().dstDir + f);
        if (!fn.isDirectory()) {
            if (f.endsWith(".html")) {
                String src = TextFile.fileToString(fn.getAbsolutePath());
                String srcn = src.replace("<!-- achive note -->", "This is an old version of FHIR retained for archive purposes. Do not use for anything else");
                if (!srcn.equals(src))
                    c++;
                srcn = srcn.replace("<body>", "<body><div class=\"watermark\"/>").replace("<body class=\"book\">", "<body class=\"book\"><div class=\"watermark\"/>");
                zip.addFileSource(f, srcn, false);
            // Utilities.stringToFile(srcn, target+File.separator+f);
            } else if (f.endsWith(".css")) {
                String src = TextFile.fileToString(fn.getAbsolutePath());
                src = src.replace("#fff", "lightcyan");
                zip.addFileSource(f, src, false);
            // Utilities.stringToFile(srcn, target+File.separator+f);
            } else
                zip.addFileName(f, fn.getAbsolutePath(), false);
        } else if (!fn.getAbsolutePath().endsWith("v2") && !fn.getAbsolutePath().endsWith("v3")) {
        // used to put stuff in sub-directories. clean them out if they
        // still exist
        // Utilities.clearDirectory(fn.getAbsolutePath());
        // fn.delete();
        }
    }
    if (c < 3)
        // so
        throw new Exception("header note replacement in archive failed");
    // check
    // the
    // syntax
    // of
    // the
    // string
    // constant
    // above
    zip.close();
}
Also used : CSFile(org.hl7.fhir.utilities.CSFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) ZipGenerator(org.hl7.fhir.utilities.ZipGenerator) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with CSFile

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

the class Publisher method cloneToXhtml.

private void cloneToXhtml(String n, String description, boolean adorn, String pageType, String crumbTitle, ImplementationGuideDefn igd, ResourceDefn rd, WorkGroup wg) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(new CSFile(page.getFolders().dstDir + n + ".xml")));
    XhtmlGenerator xhtml = new XhtmlGenerator(new ExampleAdorner(page.getDefinitions(), page.genlevel(Utilities.charCount(n, File.separatorChar))));
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    xhtml.generate(xdoc, b, n.toUpperCase().substring(0, 1) + n.substring(1), description, 0, adorn, n + ".xml.html");
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-example-xml.html").replace("<%example%>", b.toString());
    html = page.processPageIncludes(n + ".xml.html", html, pageType, null, n + ".xml.html", null, null, crumbTitle, (adorn && hasNarrative(xdoc)) ? new Boolean(true) : null, igd, rd, wg);
    TextFile.stringToFile(html, page.getFolders().dstDir + n + ".xml.html");
    // page.getEpub().registerFile(n + ".xml.html", description, EPubManager.XHTML_TYPE);
    page.getHTMLChecker().registerExternal(n + ".xml.html");
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) CSFile(org.hl7.fhir.utilities.CSFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) XhtmlGenerator(org.hl7.fhir.utilities.xml.XhtmlGenerator)

Example 9 with CSFile

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

the class Publisher method copyStaticContent.

private void copyStaticContent() throws IOException, Exception {
    if (page.getIni().getPropertyNames("support") != null)
        for (String n : page.getIni().getPropertyNames("support")) {
            Utilities.copyFile(new CSFile(page.getFolders().srcDir + n), new CSFile(page.getFolders().dstDir + n));
            page.getHTMLChecker().registerFile(n, "Support File", HTMLLinkChecker.determineType(n), true);
        }
    for (String n : page.getIni().getPropertyNames("images")) {
        copyImage(page.getFolders().imgDir, n);
    }
    for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
        for (String n : ig.getImageList()) {
            copyIgImage(ig, n);
        }
    }
    for (String n : page.getIni().getPropertyNames("files")) {
        Utilities.copyFile(new CSFile(page.getFolders().rootDir + n), new CSFile(page.getFolders().dstDir + page.getIni().getStringProperty("files", n)));
        page.getHTMLChecker().registerFile(page.getIni().getStringProperty("files", n), "Support File", HTMLLinkChecker.determineType(page.getIni().getStringProperty("files", n)), true);
    }
    page.log("Copy HTML templates", LogMessageType.Process);
    Utilities.copyDirectory(page.getFolders().rootDir + page.getIni().getStringProperty("html", "source"), page.getFolders().dstDir, page.getHTMLChecker());
    TextFile.stringToFile("\r\n[FHIR]\r\nFhirVersion=" + page.getVersion() + "-" + page.getBuildId() + "\r\nversion=" + page.getVersion().toCode() + "\r\nbuildId=" + page.getBuildId() + "\r\ndate=" + new SimpleDateFormat("yyyyMMddHHmmss").format(page.getGenDate().getTime()), Utilities.path(page.getFolders().dstDir, "version.info"), false);
    for (String n : page.getDefinitions().getDiagrams().keySet()) {
        page.log(" ...diagram " + n, LogMessageType.Process);
        page.getSvgs().put(n, TextFile.fileToString(page.getFolders().srcDir + page.getDefinitions().getDiagrams().get(n)));
    }
}
Also used : CSFile(org.hl7.fhir.utilities.CSFile) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) SimpleDateFormat(java.text.SimpleDateFormat)

Example 10 with CSFile

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

the class PageProcessor method cloneToXhtml.

private void cloneToXhtml(String src, String dst, String name, String description, int level, boolean adorn, String pageType, String crumbTitle, ImplementationGuideDefn ig, ResourceDefn rd, WorkGroup wg) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(new CSFile(src)));
    // XhtmlGenerator xhtml = new XhtmlGenerator(null);
    // xhtml.generate(xdoc, new CSFile(dst), name, description, level, adorn);
    String n = new File(dst).getName();
    n = n.substring(0, n.length() - 9);
    XhtmlGenerator xhtml = new XhtmlGenerator(new ExampleAdorner(definitions, genlevel(level)));
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    xhtml.generate(xdoc, b, name, description, level, adorn, n + ".xml.html");
    String html = ("<%setlevel " + Integer.toString(level) + "%>" + TextFile.fileToString(folders.srcDir + "template-example-xml.html")).replace("<%example%>", b.toString());
    html = processPageIncludes(n + ".xml.html", html, pageType, null, n + ".xml.html", null, null, crumbTitle, (adorn && hasNarrative(xdoc)) ? new Boolean(true) : null, ig, rd, wg);
    TextFile.stringToFile(html, dst);
    htmlchecker.registerExternal(dst);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) CSFile(org.hl7.fhir.utilities.CSFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) XhtmlGenerator(org.hl7.fhir.utilities.xml.XhtmlGenerator)

Aggregations

CSFile (org.hl7.fhir.utilities.CSFile)86 File (java.io.File)45 TextFile (org.hl7.fhir.utilities.TextFile)42 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)39 FHIRException (org.hl7.fhir.exceptions.FHIRException)37 FileOutputStream (java.io.FileOutputStream)36 ArrayList (java.util.ArrayList)29 FileInputStream (java.io.FileInputStream)27 XmlParser (org.hl7.fhir.r5.formats.XmlParser)21 IOException (java.io.IOException)16 IniFile (org.hl7.fhir.utilities.IniFile)16 JsonParser (org.hl7.fhir.r5.formats.JsonParser)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 FileNotFoundException (java.io.FileNotFoundException)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)9 Document (org.w3c.dom.Document)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7