]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/template/Template.java
add: let a user revoke his certificates.
[gigi.git] / src / org / cacert / gigi / output / template / Template.java
index b345a059f36873a53b8d2eb5eb3e87763aac71cf..8bcbc8f24ebe156a98d5cdd38918e494e94c004d 100644 (file)
@@ -14,7 +14,6 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.cacert.gigi.DevelLauncher;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.util.HTMLEncoder;
 
@@ -36,13 +35,15 @@ public class Template implements Outputable {
         }
 
         public TemplateBlock getBlock(String reqType) {
-            if (endType == null && reqType == null)
+            if (endType == null && reqType == null) {
                 return block;
+            }
             if (endType == null || reqType == null) {
                 throw new Error("Invalid block type: " + endType);
             }
-            if (endType.equals(reqType))
+            if (endType.equals(reqType)) {
                 return block;
+            }
             throw new Error("Invalid block type: " + endType);
         }
     }
@@ -53,7 +54,7 @@ public class Template implements Outputable {
 
     private File source;
 
-    private static final Pattern CONTROL_PATTERN = Pattern.compile(" ?([a-z]+)\\(\\$([^)]+)\\) ?\\{ ?");
+    private static final Pattern CONTROL_PATTERN = Pattern.compile(" ?([a-zA-Z]+)\\(\\$([^)]+)\\) ?\\{ ?");
 
     private static final Pattern ELSE_PATTERN = Pattern.compile(" ?\\} ?else ?\\{ ?");
 
@@ -61,7 +62,7 @@ public class Template implements Outputable {
         try {
             Reader r = new InputStreamReader(u.openStream(), "UTF-8");
             try {
-                if (u.getProtocol().equals("file") && DevelLauncher.DEVEL) {
+                if (u.getProtocol().equals("file")) {
                     source = new File(u.toURI());
                     lastLoaded = source.lastModified() + 1000;
                 }
@@ -149,45 +150,30 @@ public class Template implements Outputable {
     private Outputable parseCommand(String s2) {
         if (s2.startsWith("=_")) {
             final String raw = s2.substring(2);
-            return new TranslateCommand(raw);
+            if ( !s2.contains("$") && !s2.contains("!'")) {
+                return new TranslateCommand(raw);
+            } else {
+                return new SprintfCommand(raw);
+            }
         } else if (s2.startsWith("=$")) {
             final String raw = s2.substring(2);
             return new OutputVariableCommand(raw);
-        } else if (s2.startsWith("=s,")) {
-            String command = s2.substring(3);
-            final LinkedList<String> store = new LinkedList<String>();
-            while (command.startsWith("$") || command.startsWith("\"") || command.startsWith("!\"")) {
-                int idx;
-                if (command.startsWith("\"") || command.startsWith("!\"")) {
-                    idx = command.indexOf("\"", command.charAt(0) == '!' ? 2 : 1) + 1;
-                    store.add(command.substring(0, idx - 1));
-                } else {
-                    idx = command.indexOf(",");
-                    store.add(command.substring(0, idx));
-                }
-                command = command.substring(idx + 1);
-            }
-            final String text = command;
-            return new SprintfCommand(text, store);
         } else {
-            System.out.println("Unknown processing instruction: " + s2);
+            throw new Error("Unknown processing instruction: " + s2);
         }
-        return null;
     }
 
     @Override
     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
-        if (source != null && DevelLauncher.DEVEL) {
-            if (lastLoaded < source.lastModified()) {
-                try {
-                    System.out.println("Reloading template.... " + source);
-                    InputStreamReader r = new InputStreamReader(new FileInputStream(source), "UTF-8");
-                    data = parse(r).getBlock(null);
-                    r.close();
-                    lastLoaded = source.lastModified() + 1000;
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
+        if (source != null && lastLoaded < source.lastModified()) {
+            try {
+                System.out.println("Reloading template.... " + source);
+                InputStreamReader r = new InputStreamReader(new FileInputStream(source), "UTF-8");
+                data = parse(r).getBlock(null);
+                r.close();
+                lastLoaded = source.lastModified() + 1000;
+            } catch (IOException e) {
+                e.printStackTrace();
             }
         }
         data.output(out, l, vars);