diff options
author | Henri Sara <henri.sara@itmill.com> | 2011-07-29 08:13:17 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2011-07-29 08:13:17 +0000 |
commit | 5c6aa674102a39af0388d6494c752c1cba4a11e1 (patch) | |
tree | 7bb338eda9f66527abce23da19eff151bf8feae4 /build/buildhelpers/com/vaadin | |
parent | e03ef4cc2db66d0904e323dfc660bd18eb450abb (diff) | |
download | vaadin-framework-5c6aa674102a39af0388d6494c752c1cba4a11e1.tar.gz vaadin-framework-5c6aa674102a39af0388d6494c752c1cba4a11e1.zip |
#4580 and #7053 theme compiler support for multi-level imports and relative URL processing (needed for Chameleon)
svn changeset:20018/svn branch:6.7
Diffstat (limited to 'build/buildhelpers/com/vaadin')
-rw-r--r-- | build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java b/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java index eab61315a1..dd4e1c75ac 100644 --- a/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java +++ b/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java @@ -144,13 +144,22 @@ public class CompileDefaultTheme { if (strLine.startsWith("@import")) { // All import statements must be exactly // @import "file-to-import.css"; - // No sub-directories are allowed in the url + // or + // @import "subdir1[/subdir2]*/file-to-import.css" + // ".." and other similar paths are not allowed in the url String importFilename = strLine.split("\"")[1]; File importFile = new File(THEME_DIR + themeName + "/" + folder + "/" + importFilename); if (importFile.isFile()) { - processCSSFile(importFile, folder, themeName, + String currentFolder = folder; + if (importFilename.contains("/")) { + currentFolder = currentFolder + + "/" + + importFilename.substring(0, + importFilename.lastIndexOf("/")); + } + processCSSFile(importFile, currentFolder, themeName, combinedCss, inheritedFile); } else { System.out @@ -163,23 +172,8 @@ public class CompileDefaultTheme { } } - // Define image url prefix - String urlPrefix = ""; - if (inheritedFile) { - urlPrefix = "../" + themeName + "/"; - } - - if (strLine.indexOf("url(/") > 0) { - // Do nothing for urls beginning with / - } else if (strLine.indexOf("url(../") > 0) { - strLine = strLine.replaceAll("url\\(../", - ("url\\(" + urlPrefix)); + strLine = updateUrls(folder, themeName, inheritedFile, strLine); - } else { - strLine = strLine.replaceAll("url\\(", ("url\\(" - + urlPrefix + folder + "/")); - - } if (!strLine.startsWith("@import")) { combinedCss.append(strLine); combinedCss.append("\n"); @@ -190,6 +184,41 @@ public class CompileDefaultTheme { } } + private static String updateUrls(String folder, String themeName, + boolean inheritedFile, String strLine) { + // Define image url prefix + String urlPrefix = ""; + if (inheritedFile) { + urlPrefix = "../" + themeName + "/"; + } + + if (strLine.indexOf("url(/") > 0) { + // Do nothing for urls beginning with / + } else if (strLine.indexOf("url(../") >= 0) { + // eliminate a path segment in the folder name for every + // "../" + String[] folderSegments = folder.split("/"); + int segmentCount = folderSegments.length; + while (segmentCount > 0 && strLine.indexOf("url(../") >= 0) { + segmentCount--; + strLine = strLine.replaceAll("url\\(../", ("url\\(")); + } + // add remaining path segments to urlPrefix + StringBuilder sb = new StringBuilder(urlPrefix); + for (int i = 0; i < segmentCount; i++) { + sb.append(folderSegments[i]); + sb.append("/"); + } + strLine = strLine.replaceAll("url\\(", ("url\\(" + sb.toString())); + + } else { + strLine = strLine.replaceAll("url\\(", ("url\\(" + urlPrefix + + folder + "/")); + + } + return strLine; + } + private static void createSprites(String themeName) throws FileNotFoundException, IOException { String[] parameters = new String[] { "--sprite-png-depth", "AUTO", |