]> source.dussan.org Git - vaadin-framework.git/commitdiff
Modified theme build helper to support theme inheritance (to aid in #2269).
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Wed, 3 Dec 2008 06:59:37 +0000 (06:59 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Wed, 3 Dec 2008 06:59:37 +0000 (06:59 +0000)
svn changeset:6079/svn branch:trunk

build/buildhelpers/com/itmill/toolkit/buildhelpers/CompileDefaultTheme.java

index 779b85ec3fb882e6397cb33ca76462634e1e5c50..66c4b00bdd11ae12dc3b7b3cb3d5c27ad91f253e 100644 (file)
@@ -18,62 +18,94 @@ import java.util.Comparator;
  */
 public class CompileDefaultTheme {
 
-    private static final String SRCDIR = "./WebContent/ITMILL/themes/default";
+    private static final String THEME_DIR = "./WebContent/ITMILL/themes/";
+    private static final String BONES = "bones";
+    private static final String DEFAULT = "default";
 
     /**
      * @param args
      * @throws IOException
      */
     public static void main(String[] args) throws IOException {
-        File f = new File(SRCDIR);
+        // combineTheme(new String[] { BONES });
+        combineTheme(new String[] { DEFAULT });
+    }
+
+    /**
+     * 
+     * @param themeNames
+     *            All themes that should be combined together (to include
+     *            inheritance). The order is the same in which the styles are
+     *            catenated. The resulted file is placed in the last specified
+     *            theme folder.
+     * @throws IOException
+     */
+    private static void combineTheme(String[] themeNames) throws IOException {
 
         StringBuffer combinedCss = new StringBuffer();
-        combinedCss
-                .append("/* Automatically compiled css file from subdirectories. */\n");
 
-        File[] subdir = f.listFiles();
-        Arrays.sort(subdir, new Comparator() {
-            public int compare(Object arg0, Object arg1) {
-                return ((File) arg0).compareTo((File) arg1);
-            }
-        });
-
-        for (int i = 0; i < subdir.length; i++) {
-            File dir = subdir[i];
-            String name = dir.getName();
-
-            File cssFile = new File(dir.getPath() + "/" + name + ".css");
-            if (cssFile.isFile()) {
-                FileInputStream fstream = new FileInputStream(cssFile);
-                // Get the object of DataInputStream
-                DataInputStream in = new DataInputStream(fstream);
-                BufferedReader br = new BufferedReader(
-                        new InputStreamReader(in));
-                String strLine;
-                while ((strLine = br.readLine()) != null) {
-                    if (strLine.indexOf("url(../") > 0) {
-                        strLine = strLine.replaceAll("url\\(../", ("url\\("));
-
-                    } else {
-                        strLine = strLine.replaceAll("url\\(",
-                                ("url\\(" + name + "/"));
+        for (int j = 0; j < themeNames.length; j++) {
+            File f = new File(THEME_DIR + themeNames[j]);
+            combinedCss
+                    .append("/* Automatically compiled css file from subdirectories. */\n");
 
-                    }
-                    combinedCss.append(strLine);
+            File[] subdir = f.listFiles();
+            Arrays.sort(subdir, new Comparator() {
+                public int compare(Object arg0, Object arg1) {
+                    return ((File) arg0).compareTo((File) arg1);
+                }
+            });
+
+            for (int i = 0; i < subdir.length; i++) {
+                File dir = subdir[i];
+                String name = dir.getName();
+                String filename = dir.getPath() + "/" + name + ".css";
+
+                File cssFile = new File(filename);
+                if (cssFile.isFile()) {
+
+                    combinedCss.append("\n");
+                    combinedCss.append("/*" + filename + "*/");
                     combinedCss.append("\n");
+
+                    FileInputStream fstream = new FileInputStream(cssFile);
+                    // Get the object of DataInputStream
+                    DataInputStream in = new DataInputStream(fstream);
+                    BufferedReader br = new BufferedReader(
+                            new InputStreamReader(in));
+                    String strLine;
+                    while ((strLine = br.readLine()) != null) {
+                        // Define image url prefix
+                        String urlPrefix = "";
+                        if (j < themeNames.length - 1) {
+                            urlPrefix = "../" + themeNames[j] + "/";
+                        }
+
+                        if (strLine.indexOf("url(../") > 0) {
+                            strLine = strLine.replaceAll("url\\(../",
+                                    ("url\\(" + urlPrefix));
+
+                        } else {
+                            strLine = strLine.replaceAll("url\\(", ("url\\("
+                                    + urlPrefix + name + "/"));
+
+                        }
+                        combinedCss.append(strLine);
+                        combinedCss.append("\n");
+                    }
+                    // Close the input stream
+                    in.close();
                 }
-                // Close the input stream
-                in.close();
             }
         }
 
-        BufferedWriter out = new BufferedWriter(new FileWriter(SRCDIR
-                + "/styles.css"));
+        BufferedWriter out = new BufferedWriter(new FileWriter(THEME_DIR
+                + themeNames[themeNames.length - 1] + "/styles.css"));
         out.write(combinedCss.toString());
         out.close();
 
-        System.out.println("Compiled CSS to " + SRCDIR + "/styles.css ("
+        System.out.println("Compiled CSS to " + THEME_DIR
+                + themeNames[themeNames.length - 1] + "/styles.css ("
                 + combinedCss.toString().length() + " bytes)");
-
     }
 }