Author: henning
Date: Mon Aug 29 04:11:49 2005
New Revision: 264108
URL: http://svn.apache.org/viewcvs?rev=264108&view=rev
Log:
- Change UIManager to allow customization of directories and default values.
- Get rid of File() in UIManager.
- Allow UIManager to return relative links if configured.
Patches contributed by Thomas Vandahl.
Modified:
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/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=264108&r1=264107&r2=264108&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 Aug 29 04:11:49 2005
@@ -16,17 +16,17 @@
* limitations under the License.
*/
-import java.io.FileInputStream;
-
+import java.io.InputStream;
import java.util.Properties;
+import org.apache.commons.configuration.Configuration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.turbine.Turbine;
import org.apache.turbine.om.security.User;
import org.apache.turbine.services.pull.ApplicationTool;
import org.apache.turbine.services.pull.TurbinePull;
+import org.apache.turbine.services.servlet.TurbineServlet;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.ServerData;
import org.apache.turbine.util.uri.DataURI;
@@ -73,6 +73,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">James Coltman</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
+ * @author <a href="[EMAIL PROTECTED]">Thomas Vandahl</a>
* @version $Id$
*/
public class UIManager implements ApplicationTool
@@ -93,12 +94,36 @@
private static final String IMAGES_DIRECTORY = "/images";
/**
- * Property tag for the skin that is to be
+ * Property tag for the default skin that is to be
* used for the web application.
*/
private static final String SKIN_PROPERTY = "tool.ui.skin";
/**
+ * Property tag for the image directory inside the skin that is to be
+ * used for the web application.
+ */
+ private static final String IMAGEDIR_PROPERTY = "tool.ui.dir.image";
+
+ /**
+ * Property tag for the skin directory that is to be
+ * used for the web application.
+ */
+ private static final String SKINDIR_PROPERTY = "tool.ui.dir.skin";
+
+ /**
+ * Property tag for the css file that is to be
+ * used for the web application.
+ */
+ private static final String CSS_PROPERTY = "tool.ui.css";
+
+ /**
+ * Property tag for the css file that is to be
+ * used for the web application.
+ */
+ private static final String RELATIVE_PROPERTY = "tool.ui.want.relative";
+
+ /**
* Default skin name. This name actually represents
* a directory in the WEBAPP/resources/ui/skins
* directory. There is a file called skin.props
@@ -110,7 +135,7 @@
* Attribute name of skinName value in User's temp hashmap.
*/
private static final String SKIN_ATTRIBUTE =
- UIManager.class.getName()+ ".skin";
+ UIManager.class.getName()+ ".skin";
/**
* The actual skin being used for the webapp.
@@ -131,7 +156,7 @@
/**
* The file name for the skin style sheet.
*/
- private static final String SKIN_CSS_FILE = "skin.css";
+ private static final String DEFAULT_SKIN_CSS_FILE = "skin.css";
/**
* This the resources directory relative to the
@@ -139,6 +164,10 @@
* URIs for retrieving images in image().
*/
private String resourcesDirectory;
+ private String imagesDirectory;
+ private String cssFile;
+
+ private boolean wantRelative = false;
/**
* Properties to hold the name/value pairs
@@ -156,8 +185,18 @@
/**
* 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);
+ }
+
if (data == null)
{
log.debug("UI Manager scope is global");
@@ -174,8 +213,31 @@
setSkin((User) data);
}
- skinsDirectory =
- TurbinePull.getAbsolutePathToResourcesDirectory() +
SKINS_DIRECTORY;
+ skinsDirectory = cfg.getString(SKINDIR_PROPERTY, SKINS_DIRECTORY);
+ if (skinsDirectory.charAt(skinsDirectory.length() - 1) == '/')
+ {
+ skinsDirectory = skinsDirectory.substring(0,
skinsDirectory.length() - 2);
+ }
+
+ if (skinsDirectory.charAt(0) == '/')
+ {
+ skinsDirectory = skinsDirectory.substring(1);
+ }
+
+ imagesDirectory = cfg.getString(IMAGEDIR_PROPERTY, IMAGES_DIRECTORY);
+ if (imagesDirectory.charAt(imagesDirectory.length() - 1) == '/')
+ {
+ imagesDirectory = imagesDirectory.substring(0,
imagesDirectory.length() - 2);
+ }
+
+ if (imagesDirectory.charAt(0) == '/')
+ {
+ imagesDirectory = imagesDirectory.substring(1);
+ }
+
+ cssFile = cfg.getString(CSS_PROPERTY, DEFAULT_SKIN_CSS_FILE);
+
+ wantRelative = cfg.getBoolean(RELATIVE_PROPERTY, false);
loadSkin();
}
@@ -232,15 +294,18 @@
StringBuffer sb = new StringBuffer();
sb.append(resourcesDirectory).
- append(SKINS_DIRECTORY).
- append("/").
+ append('/').
+ append(skinsDirectory).
+ append('/').
append(getSkin()).
- append(IMAGES_DIRECTORY).
- append("/").
+ append('/').
+ append(imagesDirectory).
+ append('/').
append(imageId);
du.setScriptName(sb.toString());
- return du.getAbsoluteLink();
+
+ return wantRelative ? du.getRelativeLink() : du.getAbsoluteLink();
}
/**
@@ -257,15 +322,17 @@
StringBuffer sb = new StringBuffer();
sb.append(resourcesDirectory).
- append(SKINS_DIRECTORY).
- append("/").
- append(getSkin()).
- append(IMAGES_DIRECTORY).
- append("/").
- append(imageId);
+ append('/').
+ append(skinsDirectory).
+ append('/').
+ append(getSkin()).
+ append('/').
+ append(imagesDirectory).
+ append('/').
+ append(imageId);
du.setScriptName(sb.toString());
- return du.getAbsoluteLink();
+ return wantRelative ? du.getRelativeLink() : du.getAbsoluteLink();
}
/**
@@ -284,27 +351,49 @@
*/
public String getStylecss(RunData data)
{
+ return getScript(cssFile, data);
+ }
+
+ /**
+ * Retrieve the URL for the style sheet that is part
+ * of a skin. The style is stored in the
+ * WEBAPP/resources/ui/skins/<SKIN> directory with the
+ * filename skin.css
+ */
+ public String getStylecss()
+ {
+ return getScript(cssFile);
+ }
+
+ /**
+ * Retrieve the URL for a given script that is part
+ * of a skin. The script is stored in the
+ * WEBAPP/resources/ui/skins/<SKIN> directory
+ */
+ public String getScript(String filename, RunData data)
+ {
DataURI du = new DataURI(data);
+
StringBuffer sb = new StringBuffer();
sb.append(resourcesDirectory).
- append(SKINS_DIRECTORY).
- append("/").
+ append('/').
+ append(skinsDirectory).
+ append('/').
append(getSkin()).
- append("/").
- append(SKIN_CSS_FILE);
+ append('/').
+ append(filename);
du.setScriptName(sb.toString());
- return du.getAbsoluteLink();
+ return wantRelative ? du.getRelativeLink() : du.getAbsoluteLink();
}
/**
- * Retrieve the URL for the style sheet that is part
- * of a skin. The style is stored in the
- * WEBAPP/resources/ui/skins/<SKIN> directory with the
- * filename skin.css
+ * Retrieve the URL for a given script that is part
+ * of a skin. The script is stored in the
+ * WEBAPP/resources/ui/skins/<SKIN> directory
*/
- public String getStylecss()
+ public String getScript(String filename)
{
ServerData sd = Turbine.getDefaultServerData();
DataURI du = new DataURI(sd);
@@ -312,14 +401,15 @@
StringBuffer sb = new StringBuffer();
sb.append(resourcesDirectory).
- append(SKINS_DIRECTORY).
- append("/").
- append(getSkin()).
- append("/").
- append(SKIN_CSS_FILE);
+ append('/').
+ append(skinsDirectory).
+ append('/').
+ append(getSkin()).
+ append('/').
+ append(filename);
du.setScriptName(sb.toString());
- return du.getAbsoluteLink();
+ return wantRelative ? du.getRelativeLink() : du.getAbsoluteLink();
}
/**
@@ -333,8 +423,7 @@
try
{
- FileInputStream is = new FileInputStream(
- skinsDirectory + "/" + getSkin() + "/" + SKIN_PROPS_FILE);
+ InputStream is =
TurbineServlet.getResourceAsStream(getScript(SKIN_PROPS_FILE));
skinProperties.load(is);
}
@@ -353,7 +442,7 @@
{
this.skinName = Turbine.getConfiguration()
.getString(SKIN_PROPERTY,
- SKIN_PROPERTY_DEFAULT);
+ SKIN_PROPERTY_DEFAULT);
}
/**
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=264108&r1=264107&r2=264108&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 Aug
29 04:11:49 2005
@@ -28,6 +28,12 @@
<body>
<release version="2.3.2-dev" date="in CVS">
<action type="update" dev="henning">
+ Change UIManager to allow customization of directories and default
values.
+ Get rid of File() in UIManager.
+ Allow UIManager to return relative links if configured.
+ Patches contributed by Thomas Vandahl.
+ </action>
+ <action type="update" dev="henning">
Bump javamail to version 1.3.2<br/>
Build with commons-email 1.0-RC6.
</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]