You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2005/09/05 21:25:05 UTC
svn commit: r278819 - in /jakarta/turbine/core/branches/TURBINE_2_3_BRANCH:
conf/test/ src/java/org/apache/turbine/services/pull/util/
src/test/org/apache/turbine/services/pull/util/ xdocs/
Author: henning
Date: Mon Sep 5 12:24:56 2005
New Revision: 278819
URL: http://svn.apache.org/viewcvs?rev=278819&view=rev
Log:
Update Thomas' patch for UIManager, fixing TTWS16
Added:
jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java (with 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/pull/util/UIManager.java
jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/xdocs/changes.xml
Modified: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/TurbineResources.properties
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/conf/test/TurbineResources.properties?rev=278819&r1=278818&r2=278819&view=diff
==============================================================================
--- 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 Mon Sep 5 12:24:56 2005
@@ -360,6 +360,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/
# These are tools that are placed in the context by the service
# These tools will be made available to all your
@@ -423,6 +424,13 @@
tool.request.link=org.apache.turbine.services.pull.tools.TemplateLink
tool.request.page=org.apache.turbine.util.template.HtmlPageAttributes
tool.request.content=org.apache.turbine.services.pull.tools.ContentTool
+
+tool.global.ui = org.apache.turbine.services.pull.util.UIManager
+
+tool.ui.dir.skin = /turbine-skins/
+tool.ui.dir.image = /turbine-images/
+tool.ui.skin = myskin
+tool.ui.css = skins.css
# This pull tool is to allow for easy formatting of Date object into Strings
tool.request.dateFormatter=org.apache.turbine.services.pull.util.DateFormatter
Modified: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/pull/util/UIManager.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/pull/util/UIManager.java?rev=278819&r1=278818&r2=278819&view=diff
==============================================================================
--- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/pull/util/UIManager.java (original)
+++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/pull/util/UIManager.java Mon Sep 5 12:24:56 2005
@@ -20,6 +20,7 @@
import java.util.Properties;
import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.turbine.Turbine;
@@ -186,16 +187,8 @@
* Store the resources directory for use in image().
*/
Configuration cfg = Turbine.getConfiguration();
- resourcesDirectory = TurbinePull.getResourcesDirectory();
- if (resourcesDirectory.charAt(resourcesDirectory.length() -1) == '/')
- {
- resourcesDirectory = resourcesDirectory.substring(0, resourcesDirectory.length() - 2);
- }
- if (resourcesDirectory.charAt(0) == '/')
- {
- resourcesDirectory = resourcesDirectory.substring(1);
- }
+ resourcesDirectory = stripSlashes(TurbinePull.getResourcesDirectory());
if (data == null)
{
@@ -213,33 +206,38 @@
setSkin((User) data);
}
- skinsDirectory = cfg.getString(SKINDIR_PROPERTY, SKINS_DIRECTORY);
- if (skinsDirectory.charAt(skinsDirectory.length() - 1) == '/')
- {
- skinsDirectory = skinsDirectory.substring(0, skinsDirectory.length() - 2);
- }
+ skinsDirectory = stripSlashes(cfg.getString(SKINDIR_PROPERTY, SKINS_DIRECTORY));
+
+ imagesDirectory = stripSlashes(cfg.getString(IMAGEDIR_PROPERTY, IMAGES_DIRECTORY));
+
+ cssFile = cfg.getString(CSS_PROPERTY, DEFAULT_SKIN_CSS_FILE);
+
+ wantRelative = cfg.getBoolean(RELATIVE_PROPERTY, false);
- if (skinsDirectory.charAt(0) == '/')
+ loadSkin();
+ }
+
+ private String stripSlashes(final String path)
+ {
+ if (StringUtils.isEmpty(path))
{
- skinsDirectory = skinsDirectory.substring(1);
+ return "";
}
- imagesDirectory = cfg.getString(IMAGEDIR_PROPERTY, IMAGES_DIRECTORY);
- if (imagesDirectory.charAt(imagesDirectory.length() - 1) == '/')
+ String ret = path;
+ int len = ret.length() - 1;
+
+ if (ret.charAt(len) == '/')
{
- imagesDirectory = imagesDirectory.substring(0, imagesDirectory.length() - 2);
+ ret = ret.substring(0, len);
}
- if (imagesDirectory.charAt(0) == '/')
+ if (len > 0 && ret.charAt(0) == '/')
{
- imagesDirectory = imagesDirectory.substring(1);
+ ret = ret.substring(1);
}
- cssFile = cfg.getString(CSS_PROPERTY, DEFAULT_SKIN_CSS_FILE);
-
- wantRelative = cfg.getBoolean(RELATIVE_PROPERTY, false);
-
- loadSkin();
+ return ret;
}
/**
@@ -301,7 +299,7 @@
append('/').
append(imagesDirectory).
append('/').
- append(imageId);
+ append(stripSlashes(imageId));
du.setScriptName(sb.toString());
@@ -329,7 +327,7 @@
append('/').
append(imagesDirectory).
append('/').
- append(imageId);
+ append(stripSlashes(imageId));
du.setScriptName(sb.toString());
return wantRelative ? du.getRelativeLink() : du.getAbsoluteLink();
@@ -382,7 +380,7 @@
append('/').
append(getSkin()).
append('/').
- append(filename);
+ append(stripSlashes(filename));
du.setScriptName(sb.toString());
return wantRelative ? du.getRelativeLink() : du.getAbsoluteLink();
@@ -406,7 +404,7 @@
append('/').
append(getSkin()).
append('/').
- append(filename);
+ append(stripSlashes(filename));
du.setScriptName(sb.toString());
return wantRelative ? du.getRelativeLink() : du.getAbsoluteLink();
Added: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java?rev=278819&view=auto
==============================================================================
--- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java (added)
+++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java Mon Sep 5 12:24:56 2005
@@ -0,0 +1,103 @@
+package org.apache.turbine.services.pull.util;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.turbine.services.pull.ApplicationTool;
+import org.apache.turbine.services.pull.PullService;
+import org.apache.turbine.services.pull.TurbinePull;
+import org.apache.turbine.test.BaseTurbineTest;
+import org.apache.velocity.context.Context;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class UIManagerTest
+ extends BaseTurbineTest
+{
+ public UIManagerTest(String name)
+ throws Exception
+ {
+ super(name, "conf/test/TurbineResources.properties");
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(UIManagerTest.class);
+ }
+
+ private UIManager getTool()
+ {
+ PullService pullService = TurbinePull.getService();
+ assertNotNull(pullService);
+
+ Context globalContext = pullService.getGlobalContext();
+ assertNotNull(globalContext);
+
+ return (UIManager) globalContext.get("ui");
+ }
+
+ public void testTool()
+ {
+ UIManager ui = getTool();
+ assertNotNull(ui);
+ }
+
+ public void testCssSlashes()
+ {
+ UIManager ui = getTool();
+
+ String cssUrl = ui.getStylecss();
+ assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/skins.css", cssUrl);
+ }
+
+ public void testImageSlashes()
+ {
+ UIManager ui = getTool();
+
+ 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);
+
+ 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);
+
+ 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);
+ }
+
+ public void testPathologicalCases()
+ {
+ UIManager ui = getTool();
+
+ String img = "";
+ String imgUrl = ui.image(img);
+ assertEquals("Could not strip empty String", "http:///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);
+
+ img = "//";
+ imgUrl = ui.image(img);
+ assertEquals("Could not strip double Slash", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
+ }
+}
Propchange: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/test/org/apache/turbine/services/pull/util/UIManagerTest.java
------------------------------------------------------------------------------
svn:keywords = Id Author
Modified: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/xdocs/changes.xml?rev=278819&r1=278818&r2=278819&view=diff
==============================================================================
--- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/xdocs/changes.xml (original)
+++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/xdocs/changes.xml Mon Sep 5 12:24:56 2005
@@ -25,6 +25,10 @@
<body>
<release version="2.3.2-dev" date="in CVS">
+ <action type="fix" dev="henning" issue="TTWS16">
+ Make sure that UIManager strips leading and trailing
+ slashes from referenced objects and configured pathes.
+ </action>
<action type="update" dev="henning">
Add a maven goal to generate SQL with Torque. Removed old SQL files
from src/sql. Add some documentation on how to build the SQL files.
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org