001: package com.sun.portal.app.filesharing.util;
002:
003: import com.sun.portal.log.common.PortalLogger;
004:
005: import javax.servlet.ServletContextListener;
006: import javax.servlet.ServletContextEvent;
007: import javax.servlet.http.HttpServletRequest;
008: import javax.portlet.PortletRequest;
009: import javax.faces.context.FacesContext;
010: import java.util.logging.Logger;
011: import javax.servlet.http.HttpServletResponse;
012:
013: import com.sun.portal.community.CommunityFactory;
014: import com.sun.portal.community.CommunityUser;
015: import com.sun.portal.community.RoleId;
016: import com.sun.portal.community.CommunityId;
017:
018: import com.sun.portal.app.filesharing.repo.RepoFactory;
019:
020: /**
021: * @author Alejandro Abdelnur
022: */
023: public class WebAppInitializer implements ServletContextListener {
024:
025: private static final String MODE_INIT_PARAM = "app.mode";
026: private static final String DELETE_ON_UNPROVISION_INIT_PARAM = "delete.on.unprovision";
027:
028: public void contextInitialized(ServletContextEvent event) {
029: String mode = event.getServletContext().getInitParameter(
030: MODE_INIT_PARAM);
031: String s = event.getServletContext().getInitParameter(
032: DELETE_ON_UNPROVISION_INIT_PARAM);
033: boolean unprovision = (s == null) ? false : "true"
034: .equalsIgnoreCase(s.trim());
035:
036: if (mode == null || mode.equals("sunps")) {
037: LogUtils.setInstance(new PSLogUtils());
038: InfoResolverFactory
039: .setInstance(new CommunityInfoResolverFactory(
040: unprovision));
041: } else if (mode.equals("pluto")) {
042: LogUtils.setInstance(new JdkLogUtils());
043: InfoResolverFactory
044: .setInstance(new DummyInfoResolverFactory(
045: unprovision));
046: } else if (mode.equals("tomcat")) {
047: LogUtils.setInstance(new JdkLogUtils());
048: InfoResolverFactory
049: .setInstance(new DummyInfoResolverFactory(
050: unprovision));
051: } else {
052: throw new RuntimeException("Invalid application mode : "
053: + mode);
054: }
055: }
056:
057: public void contextDestroyed(ServletContextEvent event) {
058: LogUtils.setInstance(null);
059: }
060:
061: static class JdkLogUtils extends LogUtils {
062:
063: public Logger getLogger(String name) {
064: return Logger.getLogger(name);
065: }
066:
067: public Logger getLogger(Class klass) {
068: return Logger.getLogger(klass.getName());
069: }
070:
071: }
072:
073: private static class PSLogUtils extends LogUtils {
074:
075: public Logger getLogger(String name) {
076: return PortalLogger.getLogger(name);
077: }
078:
079: public Logger getLogger(Class klass) {
080: return PortalLogger.getLogger(klass);
081: }
082:
083: }
084:
085: private static class DummyInfoResolverFactory extends
086: InfoResolverFactory implements InfoResolver {
087: private boolean _unprovision;
088:
089: private DummyInfoResolverFactory(boolean unprovision) {
090: _unprovision = unprovision;
091: }
092:
093: public InfoResolver getInfoResolver(PortletRequest req)
094: throws SecurityException {
095: return this ;
096: }
097:
098: public InfoResolver getInfoResolver(HttpServletRequest req)
099: throws SecurityException {
100: return this ;
101: }
102:
103: public InfoResolver getInfoResolver(HttpServletRequest req,
104: HttpServletResponse res) throws SecurityException {
105: return this ;
106: }
107:
108: public InfoResolver getInfoResolver(FacesContext context)
109: throws SecurityException {
110: return this ;
111: }
112:
113: public String getUserId() {
114: return "dummyUser";
115: }
116:
117: public String getSessionId() {
118: return null;
119: }
120:
121: public boolean getUnprovision() {
122: return _unprovision;
123: }
124:
125: public String getSearchServerURL() {
126: return "dummySearchServerURL";
127: }
128:
129: public String getSearchDatabase() {
130: return "dummySearchDatabase";
131: }
132:
133: public String getPreference(String name) {
134: return "dummy" + name;
135: }
136:
137: public String getRepositoryId() {
138: return "dummyRepository";
139: }
140:
141: public boolean isRepositoryOwner() {
142: return true;
143: }
144:
145: public boolean isDownloadAllow() {
146: return true;
147: }
148:
149: }
150:
151: private class CommunityInfoResolverFactory extends
152: InfoResolverFactory {
153: private boolean _unprovision;
154:
155: private CommunityInfoResolverFactory(boolean unprovision) {
156: _unprovision = unprovision;
157: }
158:
159: private InfoResolver getInfoResolver(Object req)
160: throws SecurityException {
161: InfoResolver resolver = new CommunityInfoResolver(req,
162: _unprovision);
163: return resolver;
164: }
165:
166: public InfoResolver getInfoResolver(HttpServletRequest req,
167: HttpServletResponse res) throws SecurityException {
168: InfoResolver resolver = new CommunityInfoResolver(req, res,
169: _unprovision);
170: return resolver;
171: }
172:
173: public InfoResolver getInfoResolver(PortletRequest req)
174: throws SecurityException {
175: return getInfoResolver((Object) req);
176: }
177:
178: public InfoResolver getInfoResolver(HttpServletRequest req)
179: throws SecurityException {
180: return getInfoResolver((Object) req);
181:
182: }
183:
184: public InfoResolver getInfoResolver(FacesContext context) {
185: return getInfoResolver(context.getExternalContext()
186: .getRequest());
187: }
188: }
189:
190: }
|