site

(djk)
2011-04-09: Added style dir as a first step towards getting css out of .java

Added style dir as a first step towards getting css out of .java files.

diff --git a/build.xml b/build.xml
--- a/build.xml
+++ b/build.xml
@@ -5,6 +5,7 @@
   <property name="classes" value="./build/classes" />
   <property name="doc" value="./doc" />
   <property name="templates" value="./templates" />
+  <property name="style" value="./style" />
   <property name="jars" value="./build/jar" />
 
   <target name="clean">
@@ -50,6 +51,8 @@
       </manifest>
       <fileset dir="${doc}" includes="quickstart.txt"/>
       <fileset dir="${templates}" includes="*.html"/>
+      <!-- A place to stash snippets of .css -->
+      <fileset dir="${style}" includes="*.css"/>
     </jar>
   </target>
 
diff --git a/src/fniki/wiki/WikiApp.java b/src/fniki/wiki/WikiApp.java
--- a/src/fniki/wiki/WikiApp.java
+++ b/src/fniki/wiki/WikiApp.java
@@ -334,7 +334,7 @@ public class WikiApp implements ChildCon
         } else if (keyName.equals("form_password") && mFormPassword != null) {
             return mFormPassword;
         } else if (keyName.equals("default_wikitext")) {
-            return getDefaultWikiText();
+            return getString("/quickstart.txt", "Couldn't load default wikitext from jar???");
         } else if (keyName.equals("wikiname")) {
             if (mArchiveManager.getBissName() != null) {
                 return mArchiveManager.getBissName();
@@ -343,6 +343,13 @@ public class WikiApp implements ChildCon
             if (mArchiveManager.getFmsGroup() != null) {
                 return mArchiveManager.getFmsGroup();
             }
+        } else if (keyName.startsWith("/")) {
+            // Assume any name starting with a "/" is a UTF-8 encoded file in the jar.
+            try {
+                return IOUtil.readUtf8StringAndClose(WikiApp.class.getResourceAsStream(keyName));
+            } catch (IOException ioe) {
+                /* NOP: Caller gets default */
+            }
         }
 
         return defaultValue;
@@ -481,12 +488,4 @@ public class WikiApp implements ChildCon
         }
         mRequest = request;
     }
-
-    private static String getDefaultWikiText() {
-        try {
-            return IOUtil.readUtf8StringAndClose(WikiApp.class.getResourceAsStream("/quickstart.txt"));
-        } catch (IOException ioe) {
-            return "Couldn't load default wikitext from jar???";
-        }
-    }
 }
diff --git a/src/fniki/wiki/child/WikiContainer.java b/src/fniki/wiki/child/WikiContainer.java
--- a/src/fniki/wiki/child/WikiContainer.java
+++ b/src/fniki/wiki/child/WikiContainer.java
@@ -147,7 +147,7 @@ public class WikiContainer implements Ch
 
     private String getPageHtml(WikiContext context, String name) throws IOException {
         StringBuilder buffer = new StringBuilder();
-        addHeader(name, buffer);
+        addHeader(context, name, buffer);
         if (context.getStorage().hasPage(name)) {
             buffer.append(renderXHTML(context, context.getStorage().getPage(name)));
         } else {
@@ -166,7 +166,7 @@ public class WikiContainer implements Ch
         return buffer.toString();
     }
 
-    private void addHeader(String name, StringBuilder buffer) throws IOException {
+    private void addHeader(WikiContext context, String name, StringBuilder buffer) throws IOException {
         buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
         buffer.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " +
                       "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
@@ -174,10 +174,11 @@ public class WikiContainer implements Ch
         buffer.append("<head><title>\n");
         buffer.append(escapeHTML(unescapedTitleFromName(name)));
         buffer.append("</title>\n");
-        buffer.append("<style type=\"text/css\">div.indent{margin-left:20px;} " +
-                      "div.center{text-align:center;} " +
-                      "blockquote{margin-left:20px;background-color:#e0e0e0;} " +
-                      "span.underline{text-decoration:underline;}</style>\n");
+        buffer.append("<style type=\"text/css\">\n");
+        // CAREFUL: MUST audit .css files built into .jar to make sure they are safe.
+        // Load .css snippet from jar. Names can only have 1 '/' and must be globally unique.
+        buffer.append(context.getString("/add_header.css", ""));
+        buffer.append("</style>\n");
         buffer.append("</head>\n");
         buffer.append("<body>\n");
         buffer.append("<h1>\n");
diff --git a/style/add_header.css b/style/add_header.css
new file mode 100644
--- /dev/null
+++ b/style/add_header.css
@@ -0,0 +1,6 @@
+div.indent{margin-left:20px;}
+div.center{text-align:center;}
+blockquote{margin-left:20px;background-color:#e0e0e0;}
+span.underline{text-decoration:underline;}
+body { background-color: #FFFFFF; color: #000000 }
+a { color: #1f6b9e }