1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.webscripts;
20
21 import java.io.Serializable;
22 import java.util.Map;
23
24 import javax.servlet.http.HttpServletRequest;
25
26 import org.springframework.extensions.surf.FrameworkUtil;
27 import org.springframework.extensions.surf.RequestContext;
28 import org.springframework.extensions.surf.UserFactory;
29 import org.springframework.extensions.surf.WebFrameworkConstants;
30 import org.springframework.extensions.surf.site.AuthenticationUtil;
31 import org.springframework.extensions.surf.studio.WebStudioService;
32 import org.springframework.extensions.surf.util.WebStudioUtil;
33
34
35
36
37 public final class ScriptWebStudio implements Serializable
38 {
39 protected RequestContext context = null;
40
41 public ScriptWebStudio(RequestContext context)
42 {
43 this.context = context;
44 }
45
46 protected WebStudioService getWebStudioService()
47 {
48 return WebStudioService.getInstance();
49 }
50
51 protected HttpServletRequest getHttpServletRequest()
52 {
53 return context.getRequest();
54 }
55
56 public String getCurrentWebProjectId()
57 {
58 return WebStudioUtil.getCurrentWebProjectId(getHttpServletRequest());
59 }
60
61 public void setCurrentWebProjectId(String webProjectId)
62 {
63 WebStudioUtil.setCurrentWebProjectId(getHttpServletRequest(),
64 webProjectId);
65
66
67 }
68
69
70 public String getCurrentSandboxId()
71 {
72 return WebStudioUtil.getCurrentSandboxId();
73 }
74
75
76 public void setCurrentSandboxId(String sandboxId)
77 {
78 WebStudioUtil.setCurrentSandboxId(getHttpServletRequest(), sandboxId);
79 }
80
81 public String getCurrentStoreId()
82 {
83 return WebStudioUtil.getCurrentStoreId();
84 }
85
86 public void setCurrentStoreId(String storeId)
87 {
88 WebStudioUtil.setCurrentStoreId(getHttpServletRequest(), storeId);
89
90
91
92
93
94
95
96
97 String webappId = getCurrentWebappId();
98 if (webappId == null)
99 {
100 setCurrentWebappId("ROOT");
101 }
102 }
103
104 public String getCurrentWebappId()
105 {
106 return WebStudioUtil.getCurrentWebappId();
107 }
108
109 public void setCurrentWebappId(String webappId)
110 {
111 WebStudioUtil.setCurrentWebappId(getHttpServletRequest(), webappId);
112
113
114 getHttpServletRequest().getSession(true).setAttribute(
115 WebFrameworkConstants.WEBAPP_ID_SESSION_ATTRIBUTE_NAME,
116 webappId);
117 }
118
119 public String getCurrentUserId()
120 {
121 return WebStudioUtil.getCurrentUserId(getHttpServletRequest());
122 }
123
124 public void setCurrentUserId(String currentUserId)
125 {
126 WebStudioUtil.setCurrentUserId(getHttpServletRequest(), currentUserId);
127 }
128
129 public void setModel(Map<String, Object> model)
130 {
131 this.model = model;
132 }
133
134 public Map<String, Object> getModel()
135 {
136 return this.model;
137 }
138
139 protected Map<String, Object> model;
140
141 public boolean login(String username, String password) throws Exception
142 {
143 boolean success = false;
144
145 HttpServletRequest request = this.getHttpServletRequest();
146
147 UserFactory userFactory = FrameworkUtil.getServiceRegistry().getUserFactory();
148
149
150 boolean authenticated = userFactory.authenticate(request, username,
151 password);
152 if (authenticated)
153 {
154
155 RequestContext context = FrameworkUtil.getCurrentRequestContext();
156 AuthenticationUtil.login(request, username);
157
158
159 setCurrentUserId(username);
160
161
162 success = true;
163 }
164
165 return success;
166 }
167
168 public ScriptImporter getImporter()
169 {
170 return new ScriptImporter(context);
171 }
172 }