1 package org.astrogrid.portal.myspace.acting.framework;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.net.MalformedURLException;
6
7 import org.apache.avalon.framework.parameters.Parameters;
8 import org.apache.cocoon.environment.Request;
9 import org.apache.cocoon.environment.Session;
10 import org.apache.cocoon.servlet.multipart.Part;
11 import org.astrogrid.community.User;
12 import org.astrogrid.portal.common.user.UserHelper;
13 import org.astrogrid.portal.login.common.SessionKeys;
14 import org.astrogrid.portal.utils.acting.ActionUtils;
15 import org.astrogrid.store.Agsl;
16 import org.astrogrid.store.Ivorn;
17 import org.astrogrid.store.delegate.StoreClient;
18 import org.astrogrid.store.delegate.StoreFile;
19 import org.astrogrid.store.delegate.VoSpaceResolver;
20
21 /***
22 * Default implementation of <code>org.astrogrid.portal.myspace.acting.framework.ContextWrapper</code>.
23 *
24 * @author peter.shillan
25 * @see org.astrogrid.portal.myspace.acting.framework.ContextWrapper
26 */
27 public class ContextWrapperImpl implements ContextWrapper {
28 private ActionUtils utils;
29 private Parameters params;
30 private Request request;
31 private Session session;
32 private User user;
33 private Ivorn ivorn;
34 private Agsl agsl;
35 private StoreClient storeClient;
36
37 public static final String MYSPACE_CACHE = "myspace-cache";
38
39
40 public ContextWrapperImpl(ActionUtils utils, Parameters params, Request request, Session session)
41 throws MalformedURLException, IOException {
42 this.utils = utils;
43 this.params= params;
44 this.request = request;
45 this.session = session;
46
47 try {
48
49 user = UserHelper.getCurrentUser(params, request, session);
50
51
52 ivorn = (Ivorn) utils.getAnyParameterObject(
53 SessionKeys.IVORN,
54 params, request, session);
55
56 storeClient = VoSpaceResolver.resolveStore(user, ivorn);
57
58
59 agsl = storeClient.getEndpoint();
60 }
61 catch(Throwable t) {
62 throw new IOException("Could not create a valid context: " + t.getLocalizedMessage());
63 }
64 }
65
66 public String getParameter(String param) {
67 return utils.getAnyParameter(param, params, request, session);
68 }
69
70 public String getParameter(String param, String defaultValue) {
71 return utils.getAnyParameter(param, defaultValue, params, request, session);
72 }
73
74 public User getUser() {
75 return user;
76 }
77
78 public Agsl getAgsl() throws IOException {
79 return agsl;
80 }
81
82 public StoreClient getStoreClient() {
83 return storeClient;
84 }
85
86 public void setGlobalAttribute(String attribute, Object value) {
87 session.setAttribute(attribute, value);
88 }
89
90 public void setLocalAttribute(String attribute, Object value) {
91 request.setAttribute(attribute, value);
92 }
93
94 public InputStream getFileInputStream(String fileName) throws Exception {
95 InputStream result = null;
96
97 Part part = (Part) request.get(fileName);
98 if (part != null) {
99 result = part.getInputStream();
100 } else {
101
102 }
103
104 return result;
105 }
106
107 /***
108 * Return the cache of MySpace files for a user.
109 *
110 *
111 * @return <code>StoreFile</code> for a user
112 *n
113 */
114 public StoreFile getMySpaceCache() {
115
116 return (StoreFile)null ;
117
118 }
119
120
121 /***
122 * Set the cache of MySpace files for a user.
123 *
124 *
125 */
126 public void setMySpaceCache( StoreFile cache ) {
127
128
129 }
130
131 }