You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompileDefaultTheme.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.vaadin.buildhelpers;
  2. import java.io.BufferedReader;
  3. import java.io.BufferedWriter;
  4. import java.io.DataInputStream;
  5. import java.io.File;
  6. import java.io.FileInputStream;
  7. import java.io.FileWriter;
  8. import java.io.IOException;
  9. import java.io.InputStreamReader;
  10. import java.util.Arrays;
  11. import java.util.Comparator;
  12. /**
  13. * Helper to combine css diveded into separate per component dirs into one to
  14. * optimize http requests.
  15. *
  16. */
  17. public class CompileDefaultTheme {
  18. private static final String THEME_DIR = "./WebContent/ITMILL/themes/";
  19. private static final String BASE = "base";
  20. private static final String DEFAULT = "default";
  21. private static final String REINDEER = "reindeer";
  22. /**
  23. * @param args
  24. * @throws IOException
  25. */
  26. public static void main(String[] args) throws IOException {
  27. combineTheme(new String[] { BASE });
  28. combineTheme(new String[] { BASE, DEFAULT });
  29. combineTheme(new String[] { BASE, REINDEER });
  30. }
  31. /**
  32. *
  33. * @param themeNames
  34. * All themes that should be combined together (to include
  35. * inheritance). The order is the same in which the styles are
  36. * catenated. The resulted file is placed in the last specified
  37. * theme folder.
  38. * @throws IOException
  39. */
  40. private static void combineTheme(String[] themeNames) throws IOException {
  41. StringBuffer combinedCss = new StringBuffer();
  42. for (int j = 0; j < themeNames.length; j++) {
  43. File f = new File(THEME_DIR + themeNames[j]);
  44. combinedCss
  45. .append("/* Automatically compiled css file from subdirectories. */\n");
  46. File[] subdir = f.listFiles();
  47. Arrays.sort(subdir, new Comparator() {
  48. public int compare(Object arg0, Object arg1) {
  49. return ((File) arg0).compareTo((File) arg1);
  50. }
  51. });
  52. for (int i = 0; i < subdir.length; i++) {
  53. File dir = subdir[i];
  54. String name = dir.getName();
  55. String filename = dir.getPath() + "/" + name + ".css";
  56. File cssFile = new File(filename);
  57. if (cssFile.isFile()) {
  58. combinedCss.append("\n");
  59. combinedCss.append("/* " + filename.replaceAll("\\\\", "/")
  60. + " */");
  61. combinedCss.append("\n");
  62. FileInputStream fstream = new FileInputStream(cssFile);
  63. // Get the object of DataInputStream
  64. DataInputStream in = new DataInputStream(fstream);
  65. BufferedReader br = new BufferedReader(
  66. new InputStreamReader(in));
  67. String strLine;
  68. while ((strLine = br.readLine()) != null) {
  69. // Define image url prefix
  70. String urlPrefix = "";
  71. if (j < themeNames.length - 1) {
  72. urlPrefix = "../" + themeNames[j] + "/";
  73. }
  74. if (strLine.indexOf("url(../") > 0) {
  75. strLine = strLine.replaceAll("url\\(../",
  76. ("url\\(" + urlPrefix));
  77. } else {
  78. strLine = strLine.replaceAll("url\\(", ("url\\("
  79. + urlPrefix + name + "/"));
  80. }
  81. combinedCss.append(strLine);
  82. combinedCss.append("\n");
  83. }
  84. // Close the input stream
  85. in.close();
  86. }
  87. }
  88. }
  89. BufferedWriter out = new BufferedWriter(new FileWriter(THEME_DIR
  90. + themeNames[themeNames.length - 1] + "/styles.css"));
  91. out.write(combinedCss.toString());
  92. out.close();
  93. System.out.println("Compiled CSS to " + THEME_DIR
  94. + themeNames[themeNames.length - 1] + "/styles.css ("
  95. + combinedCss.toString().length() + " bytes)");
  96. }
  97. }