X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Foutput%2Ftemplate%2FTemplate.java;h=b345a059f36873a53b8d2eb5eb3e87763aac71cf;hb=8d98e8c550a5fc426d7efbd57436dcb61bd41243;hp=dca6568b7432847f4db4cca56f9840e9bc9cab41;hpb=7e1a029d9df4c731a2087e58f774e6d8737aace3;p=gigi.git diff --git a/src/org/cacert/gigi/output/template/Template.java b/src/org/cacert/gigi/output/template/Template.java index dca6568b..b345a059 100644 --- a/src/org/cacert/gigi/output/template/Template.java +++ b/src/org/cacert/gigi/output/template/Template.java @@ -16,11 +16,37 @@ import java.util.regex.Pattern; import org.cacert.gigi.DevelLauncher; import org.cacert.gigi.localisation.Language; -import org.cacert.gigi.output.Outputable; import org.cacert.gigi.util.HTMLEncoder; public class Template implements Outputable { + class ParseResult { + + TemplateBlock block; + + String endType; + + public ParseResult(TemplateBlock block, String endType) { + this.block = block; + this.endType = endType; + } + + public String getEndType() { + return endType; + } + + public TemplateBlock getBlock(String reqType) { + if (endType == null && reqType == null) + return block; + if (endType == null || reqType == null) { + throw new Error("Invalid block type: " + endType); + } + if (endType.equals(reqType)) + return block; + throw new Error("Invalid block type: " + endType); + } + } + private TemplateBlock data; private long lastLoaded; @@ -29,6 +55,8 @@ public class Template implements Outputable { private static final Pattern CONTROL_PATTERN = Pattern.compile(" ?([a-z]+)\\(\\$([^)]+)\\) ?\\{ ?"); + private static final Pattern ELSE_PATTERN = Pattern.compile(" ?\\} ?else ?\\{ ?"); + public Template(URL u) { try { Reader r = new InputStreamReader(u.openStream(), "UTF-8"); @@ -40,7 +68,7 @@ public class Template implements Outputable { } catch (URISyntaxException e) { e.printStackTrace(); } - data = parse(r); + data = parse(r).getBlock(null); r.close(); } catch (IOException e) { throw new Error(e); @@ -49,17 +77,18 @@ public class Template implements Outputable { public Template(Reader r) { try { - data = parse(r); + data = parse(r).getBlock(null); r.close(); } catch (IOException e) { throw new Error(e); } } - private TemplateBlock parse(Reader r) throws IOException { + private ParseResult parse(Reader r) throws IOException { LinkedList splitted = new LinkedList(); LinkedList commands = new LinkedList(); StringBuffer buf = new StringBuffer(); + String blockType = null; outer: while (true) { while ( !endsWith(buf, "