You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2006/06/01 20:12:05 UTC
svn commit: r410906 -
/portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/file/FilePortlet.java
Author: taylor
Date: Thu Jun 1 11:12:04 2006
New Revision: 410906
URL: http://svn.apache.org/viewvc?rev=410906&view=rev
Log:
added alternate method of specifying target source file: if portlet init-param 'basepath' is non-empty,
check request parameters and request attributes for a property called 'filepath'
- resulting file path would be /WEB-INF/${basepath}/${filepath}
- this change should not affect any existing use of FilePortlet
(patch from Steve Milek)
Modified:
portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/file/FilePortlet.java
Modified: portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/file/FilePortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/file/FilePortlet.java?rev=410906&r1=410905&r2=410906&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/file/FilePortlet.java (original)
+++ portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/file/FilePortlet.java Thu Jun 1 11:12:04 2006
@@ -23,6 +23,7 @@
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.portlet.PortletConfig;
import javax.portlet.PortletPreferences;
import org.apache.jetspeed.PortalReservedParameters;
@@ -37,7 +38,41 @@
*/
public class FilePortlet extends GenericServletPortlet
{
-
+ /**
+ * Name of portlet preference for source file url
+ */
+ public static final String PARAM_SOURCE_FILE = "file";
+
+ /**
+ * Name of portlet preference for source file url
+ */
+ public static final String PARAM_SOURCE_BASE_PATH = "basepath";
+
+ /**
+ * Name of portlet preference for source file url
+ */
+ public static final String PARAM_SOURCE_FILE_PATH = "filepath";
+
+
+ /**
+ * Default URL for the source file
+ */
+ private String defaultSourceFile = null;
+
+ /**
+ * Default base URL for the source file
+ */
+ private String defaultSourceBasePath = null;
+
+ public void init(PortletConfig config)
+ throws PortletException
+ {
+ super.init(config);
+ this.defaultSourceFile = config.getInitParameter(PARAM_SOURCE_FILE);
+ this.defaultSourceBasePath = config.getInitParameter(PARAM_SOURCE_BASE_PATH);
+ }
+
+
public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{
@@ -46,14 +81,23 @@
if (null == path)
{
PortletPreferences prefs = request.getPreferences();
- path = prefs.getValue("file", null);
+ path = prefs.getValue(PARAM_SOURCE_FILE, this.defaultSourceFile);
}
- else
+
+ if (null == path && this.defaultSourceBasePath != null )
{
- // default to 'content' area
- File temp = new File(path);
- path = "/WEB-INF/" + temp.getPath();
+ String filepath = (String)request.getParameter(PARAM_SOURCE_FILE_PATH);
+ if (filepath == null)
+ {
+ filepath = (String)request.getAttribute(PARAM_SOURCE_FILE_PATH);
+ }
+
+ if (filepath != null)
+ {
+ path = ( ( this.defaultSourceBasePath.length() > 0 ) ? ( this.defaultSourceBasePath + "/" ) : "" ) + filepath;
+ }
}
+
if (null == path)
{
response.setContentType("text/html");
@@ -61,6 +105,10 @@
}
else
{
+ // default to 'content' area
+ File temp = new File(path);
+ path = "/WEB-INF/" + temp.getPath();
+
setContentType(path, response);
renderFile(response, path);
}
@@ -68,7 +116,7 @@
protected void setContentType(String path, RenderResponse response)
{
- // Note these content types need to be added to the portlet.xml
+ // Note these content types need to be added to the portlet.xml
if (path.endsWith(".html"))
{
response.setContentType("text/html");
@@ -84,7 +132,11 @@
else if (path.endsWith(".csv"))
{
response.setContentType("text/csv");
- }
+ }
+ else if (path.endsWith(".xml") || path.endsWith(".xsl"))
+ {
+ response.setContentType("text/xml");
+ }
else
{
response.setContentType("text/html");
@@ -131,4 +183,4 @@
}
-}
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org