X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Foutput%2FTemplate.java;h=0b0fe3ba4067a7e0de5efbb63243c633d3ae774a;hp=c7e90674c0370d4e46f0c78f92173630ea48d238;hb=862eaa5913c657d2760337635de517471f0424cf;hpb=15284bd894484c5d692b3a84faefcf34bac89bde diff --git a/src/org/cacert/gigi/output/Template.java b/src/org/cacert/gigi/output/Template.java index c7e90674..0b0fe3ba 100644 --- a/src/org/cacert/gigi/output/Template.java +++ b/src/org/cacert/gigi/output/Template.java @@ -1,26 +1,38 @@ package org.cacert.gigi.output; import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.Reader; +import java.net.URISyntaxException; import java.net.URL; import java.util.LinkedList; import java.util.Map; +import org.cacert.gigi.DevelLauncher; import org.cacert.gigi.Language; public class Template implements Outputable { String[] contents; Outputable[] vars; - URL source; + long lastLoaded; + File source; public Template(URL u) { try { - source = u; Reader r = new InputStreamReader(u.openStream(), "UTF-8"); + try { + if (u.getProtocol().equals("file") && DevelLauncher.DEVEL) { + source = new File(u.toURI()); + lastLoaded = source.lastModified() + 1000; + } + } catch (URISyntaxException e) { + e.printStackTrace(); + } parse(r); } catch (IOException e) { throw new Error(e); @@ -122,6 +134,17 @@ public class Template implements Outputable { } public void output(PrintWriter out, Language l, Map vars) { + if (source != null && DevelLauncher.DEVEL) { + if (lastLoaded < source.lastModified()) { + try { + System.out.println("Reloading template.... " + source); + parse(new InputStreamReader(new FileInputStream(source), "UTF-8")); + lastLoaded = source.lastModified() + 1000; + } catch (IOException e) { + e.printStackTrace(); + } + } + } for (int i = 0; i < contents.length; i++) { out.print(contents[i]); if (i < this.vars.length) {