Author: seade Date: Sun May 6 03:59:43 2007 New Revision: 535597 URL: http://svn.apache.org/viewvc?view=rev&rev=535597 Log: UITool.getSkinNames() was broken. Added a test aces for this and one to test retrieval of properties.
Added: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myotherskin/ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myotherskin/skin.props jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myskin/ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myskin/skin.props Modified: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/TurbineResources.properties jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/ui/TurbineUIService.java jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/tools/UIToolTest.java jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java Modified: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/TurbineResources.properties URL: http://svn.apache.org/viewvc/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/TurbineResources.properties?view=diff&rev=535597&r1=535596&r2=535597 ============================================================================== --- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/TurbineResources.properties (original) +++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/TurbineResources.properties Sun May 6 03:59:43 2007 @@ -363,7 +363,7 @@ # on each request (request tools aren't ever, because they're # instantiated for the request only anyway). services.PullService.tools.per.request.refresh=true -services.PullService.tools.resources.dir = /turbine-resources/ +services.PullService.tools.resources.dir = /conf/test/turbine-resources/ # These are tools that are placed in the context by the service # These tools will be made available to all your @@ -416,7 +416,7 @@ # stored in the user's temporary hashtable. Tool should be # threadsafe. # -# persistent: tool is instantitated once for each use session, and +# persistent: tool is instantiated once for each use session, and # is stored in the user's permanent hashtable. This means # for a logged in user the tool will be persisted in the # user's objectdata. Tool should be threadsafe and @@ -432,7 +432,7 @@ ## The following is the old deprecated version. It is being added as uimanager ## so that it can still be tested. tool.global.uimanager = org.apache.turbine.services.pull.util.UIManager - +## These properties apply to both the old UIManager and the newer UIService tool.ui.dir.skin = /turbine-skins/ tool.ui.dir.image = /turbine-images/ tool.ui.skin = myskin Added: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myotherskin/skin.props URL: http://svn.apache.org/viewvc/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myotherskin/skin.props?view=auto&rev=535597 ============================================================================== --- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myotherskin/skin.props (added) +++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myotherskin/skin.props Sun May 6 03:59:43 2007 @@ -0,0 +1 @@ +skin_property_1 = skin_property_1_my_other_skin \ No newline at end of file Added: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myskin/skin.props URL: http://svn.apache.org/viewvc/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myskin/skin.props?view=auto&rev=535597 ============================================================================== --- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myskin/skin.props (added) +++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/turbine-resources/turbine-skins/myskin/skin.props Sun May 6 03:59:43 2007 @@ -0,0 +1 @@ +skin_property_1 = skin_property_1_my_skin \ No newline at end of file Modified: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/ui/TurbineUIService.java URL: http://svn.apache.org/viewvc/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/ui/TurbineUIService.java?view=diff&rev=535597&r1=535596&r2=535597 ============================================================================== --- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/ui/TurbineUIService.java (original) +++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/ui/TurbineUIService.java Sun May 6 03:59:43 2007 @@ -21,11 +21,13 @@ import java.io.File; import java.io.FilenameFilter; +import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Properties; import org.apache.commons.configuration.Configuration; +import org.apache.commons.io.filefilter.DirectoryFileFilter; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -57,23 +59,7 @@ extends TurbineBaseService implements UIService { - /** - * A FilenameFilter that returns only directories. - * TODO Replace with commons-io DirectoryFileFilter - */ - private class DirectoryFileFilter implements FilenameFilter - { - public boolean accept(File dir, String fileName) - { - File file = new File(dir, fileName); - if (file.isDirectory()) - { - return true; - } - return false; - } - } - + /** Logging. */ private static Log log = LogFactory.getLog(TurbineUIService.class); /** @@ -123,13 +109,15 @@ public static final String SKIN_PROPERTY_DEFAULT = "default"; /** - * The skins directory. + * The skins directory, qualified by the resources directory (which is + * relative to the webapp context). This is used for constructing URIs and + * for retrieving skin files. */ private String skinsDirectory; /** - * The file within the skin directory that actually contains the name/value - * pairs for the skin. + * The file within the skin directory that contains the name/value pairs for + * the skin. */ private static final String SKIN_PROPS_FILE = "skin.props"; @@ -139,13 +127,19 @@ private static final String DEFAULT_SKIN_CSS_FILE = "skin.css"; /** - * This the resources directory relative to the webapp context. Used for - * constructing correct URIs for retrieving skin files. + * The directory within the skin directory that contains the skin images. */ - private String resourcesDirectory; private String imagesDirectory; + + /** + * The name of the css file within the skin directory. + */ private String cssFile; + /** + * The flag that determines if the links that are returned are are absolute + * or relative. + */ private boolean wantRelative = false; /** @@ -235,7 +229,7 @@ public String[] getSkinNames() { File skinsDir = new File(skinsDirectory); - return skinsDir.list(new DirectoryFileFilter()); + return skinsDir.list(DirectoryFileFilter.INSTANCE); } /** @@ -291,7 +285,6 @@ Properties skinProperties = new Properties(defaultSkinProperties); StringBuffer sb = new StringBuffer(); - sb.append('/').append(resourcesDirectory); sb.append('/').append(skinsDirectory); sb.append('/').append(skinName); sb.append('/').append(SKIN_PROPS_FILE); @@ -302,6 +295,8 @@ try { + // This will NPE if the directory associated with the skin does not + // exist, but it is habdled correctly below. InputStream is = TurbineServlet.getResourceAsStream(sb.toString()); skinProperties.load(is); @@ -480,8 +475,7 @@ private String getSkinResource(ServerData serverData, String skinName, String subDir, String resourceName) { - StringBuffer sb = new StringBuffer(resourcesDirectory); - sb.append("/").append(skinsDirectory); + StringBuffer sb = new StringBuffer(skinsDirectory); sb.append("/").append(skinName); if (subDir != null) { @@ -505,10 +499,15 @@ // Get the resources directory that is specified in the TR.props or // default to "resources", relative to the webapp. - resourcesDirectory = stripSlashes(TurbinePull.getResourcesDirectory()); + StringBuffer sb = new StringBuffer(); + sb.append(stripSlashes(TurbinePull.getResourcesDirectory())); + sb.append("/"); + sb.append(stripSlashes( + cfg.getString(SKINDIR_PROPERTY, SKINS_DIRECTORY))); + skinsDirectory = sb.toString(); - skinsDirectory = stripSlashes(cfg.getString(SKINDIR_PROPERTY, SKINS_DIRECTORY)); - imagesDirectory = stripSlashes(cfg.getString(IMAGEDIR_PROPERTY, IMAGES_DIRECTORY)); + imagesDirectory = stripSlashes( + cfg.getString(IMAGEDIR_PROPERTY, IMAGES_DIRECTORY)); cssFile = cfg.getString(CSS_PROPERTY, DEFAULT_SKIN_CSS_FILE); wantRelative = cfg.getBoolean(RELATIVE_PROPERTY, false); Modified: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/tools/UIToolTest.java URL: http://svn.apache.org/viewvc/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/tools/UIToolTest.java?view=diff&rev=535597&r1=535596&r2=535597 ============================================================================== --- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/tools/UIToolTest.java (original) +++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/tools/UIToolTest.java Sun May 6 03:59:43 2007 @@ -64,7 +64,7 @@ UITool ui = getTool(); String cssUrl = ui.getStylecss(); - assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/skins.css", cssUrl); + assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/skins.css", cssUrl); } public void testImageSlashes() @@ -74,17 +74,17 @@ String img = "myimage.gif"; String imgUrl = ui.image(img); - assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl); + assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl); String img2 = "foo/myimage.gif"; String imgUrl2 = ui.image(img2); - assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2); + assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2); String img3 = "/foo/myimage.gif"; String imgUrl3 = ui.image(img3); - assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3); + assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3); } public void testPathologicalCases() @@ -93,14 +93,39 @@ String img = ""; String imgUrl = ui.image(img); - assertEquals("Could not strip empty String", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); + assertEquals("Could not strip empty String", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); img = "/"; imgUrl = ui.image(img); - assertEquals("Could not strip single Slash", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); + assertEquals("Could not strip single Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); img = "//"; imgUrl = ui.image(img); - assertEquals("Could not strip double Slash", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); + assertEquals("Could not strip double Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); + } + + public void testGetSkinNames() + { + UITool ui = getTool(); + + String[] skinNames = ui.getSkinNames(); + assertEquals(2, skinNames.length); + + // Not completely sure this will always be in the same order. + assertEquals("myotherskin", skinNames[0]); + assertEquals("myskin", skinNames[1]); + } + + public void testSkinValues() + { + UITool ui = getTool(); + + // Default skin + //skin_property_1 = skin_property_1_my_skin + assertEquals("skin_property_1_my_skin", ui.get("skin_property_1")); + + ui.setSkin("myotherskin"); + //skin_property_1 = skin_property_1_my_other_skin + assertEquals("skin_property_1_my_other_skin", ui.get("skin_property_1")); } } Modified: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java URL: http://svn.apache.org/viewvc/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java?view=diff&rev=535597&r1=535596&r2=535597 ============================================================================== --- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java (original) +++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java Sun May 6 03:59:43 2007 @@ -64,7 +64,7 @@ UIManager ui = getTool(); String cssUrl = ui.getStylecss(); - assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/skins.css", cssUrl); + assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/skins.css", cssUrl); } public void testImageSlashes() @@ -74,17 +74,17 @@ String img = "myimage.gif"; String imgUrl = ui.image(img); - assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl); + assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl); String img2 = "foo/myimage.gif"; String imgUrl2 = ui.image(img2); - assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2); + assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2); String img3 = "/foo/myimage.gif"; String imgUrl3 = ui.image(img3); - assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3); + assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3); } public void testPathologicalCases() @@ -93,14 +93,14 @@ String img = ""; String imgUrl = ui.image(img); - assertEquals("Could not strip empty String", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); + assertEquals("Could not strip empty String", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); img = "/"; imgUrl = ui.image(img); - assertEquals("Could not strip single Slash", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); + assertEquals("Could not strip single Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); img = "//"; imgUrl = ui.image(img); - assertEquals("Could not strip double Slash", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); + assertEquals("Could not strip double Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]