001: package com.sun.portal.app.wiki;
002:
003: import javax.portlet.RenderRequest;
004: import javax.portlet.RenderResponse;
005: import javax.portlet.PortletSession;
006: import java.util.*;
007: import java.io.*;
008:
009: public class WikiPortletContext {
010:
011: static private ThreadLocal mapTL = new ThreadLocal();
012:
013: static final String RENDER_REQUEST_KEY = "renderRequestKey";
014: static final String RENDER_RESPONSE_KEY = "renderResponseKey";
015:
016: static Properties props = new Properties();
017:
018: static {
019: try {
020: Properties psprops = new Properties();
021: InputStream is = ClassLoader
022: .getSystemResourceAsStream("PSConfig.properties");
023: if (is != null)
024: psprops.load(is);
025:
026: String instanceid = System
027: .getProperty("com.sun.portal.instance.id");
028: String portalid = System
029: .getProperty("com.sun.portal.portal.id");
030: String datadir = psprops.getProperty("ps.data.location");
031: String portaldatadir = datadir + "/portals/" + portalid;
032:
033: String log4j_appender_FileLog_File = portaldatadir
034: + "/logs/" + instanceid + "/jspwiki.log";
035: String jspwiki_workDir = portaldatadir + "/wiki/work";
036: String jspwiki_fileSystemProvider_pageDir = portaldatadir
037: + "/wiki/repository";
038: String jspwiki_basicAttachmentProvider_storageDir = portaldatadir
039: + "/wiki/repository";
040:
041: props.setProperty("jspwiki.workDir", jspwiki_workDir);
042: props.setProperty("jspwiki.fileSystemProvider.pageDir",
043: jspwiki_fileSystemProvider_pageDir);
044: props.setProperty(
045: "jspwiki.basicAttachmentProvider.storageDir",
046: jspwiki_basicAttachmentProvider_storageDir);
047: props.setProperty("log4j.appender.FileLog.File",
048: log4j_appender_FileLog_File);
049:
050: } catch (Exception e) {
051: e.printStackTrace();
052: }
053: }
054:
055: static public void init(RenderRequest request,
056: RenderResponse response) {
057: mapTL.set(new HashMap());
058: put(RENDER_REQUEST_KEY, request);
059: put(RENDER_RESPONSE_KEY, response);
060: }
061:
062: static public void cleanup() {
063: mapTL.set(null);
064: }
065:
066: static public Map getMap() {
067: return (Map) mapTL.get();
068: }
069:
070: static public Properties getProperties() {
071: return props;
072: }
073:
074: // this indicates whether a portlet context is active or not
075: static public boolean isActive() {
076: return mapTL.get() != null;
077: }
078:
079: // XXX never throw exception - return null (in case not setup, eg, add atachment)
080: static public Object get(String key) {
081: Map m = (Map) mapTL.get();
082: if (m == null)
083: return null;
084: return m.get(key);
085: }
086:
087: static public void put(String key, Object value) {
088: Map m = (Map) mapTL.get();
089: if (m == null)
090: return;
091: ((Map) mapTL.get()).put(key, value);
092: }
093:
094: static public Object getPortletSessionAttribute(String name) {
095: RenderRequest rreq = (RenderRequest) get(RENDER_REQUEST_KEY);
096: if (rreq == null)
097: return null;
098: return rreq.getPortletSession().getAttribute(name);
099: }
100:
101: static public void setPortletSessionAttribute(String name,
102: Object value) {
103: RenderRequest rreq = (RenderRequest) get(RENDER_REQUEST_KEY);
104: if (rreq == null)
105: return;
106: rreq.getPortletSession().setAttribute(name, value);
107: }
108:
109: static public String getNamespace() {
110: RenderResponse response = getRenderResponse();
111: if (response != null)
112: return response.getNamespace();
113: else
114: return null;
115: }
116:
117: static public RenderRequest getRenderRequest() {
118: return (RenderRequest) get(RENDER_REQUEST_KEY);
119: }
120:
121: static public RenderResponse getRenderResponse() {
122: return (RenderResponse) get(RENDER_RESPONSE_KEY);
123: }
124:
125: }
|