1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.surf.util;
20
21 import javax.servlet.http.HttpServletRequest;
22
23 import org.springframework.extensions.surf.RequestContext;
24 import org.springframework.extensions.surf.ThreadLocalPreviewContext;
25 import org.springframework.extensions.surf.WebFrameworkConstants;
26
27
28
29
30 public class WebStudioUtil
31 {
32
33 public static String getContentEditURL(RequestContext context,
34 String endpointId, String itemRelativePath)
35 {
36 return null;
37 }
38
39 public static Object getCachedObject(HttpServletRequest request, String key)
40 {
41 return (Object) request.getSession().getAttribute(
42 "CACHED_RESOURCE_" + key);
43 }
44
45 public static void setCachedObject(HttpServletRequest request, String key,
46 Object object)
47 {
48 request.getSession().setAttribute("CACHED_RESOURCE_" + key, object);
49 }
50
51 public static String getCurrentUserId(HttpServletRequest request)
52 {
53 return (String) getCachedObject(request, "CurrentUserId");
54 }
55
56 public static void setCurrentUserId(HttpServletRequest request,
57 String currentUserId)
58 {
59 setCachedObject(request, "CurrentUserId", currentUserId);
60 }
61
62 public static String getCurrentWebProjectId(HttpServletRequest request)
63 {
64 return (String) getCachedObject(request, "CurrentWebProject");
65 }
66
67 public static void setCurrentWebProjectId(HttpServletRequest request,
68 String webProjectId)
69 {
70 setCachedObject(request, "CurrentWebProject", webProjectId);
71 }
72
73 public static String getCurrentSandboxId()
74 {
75 return getCurrentStoreId();
76 }
77
78 public static void setCurrentSandboxId(HttpServletRequest request, String sandboxId)
79 {
80 setCurrentStoreId(request, sandboxId);
81 }
82
83 public static String getCurrentStoreId()
84 {
85 String storeId = null;
86
87 if (ThreadLocalPreviewContext.getSandboxContext() != null)
88 {
89 storeId = ThreadLocalPreviewContext.getSandboxContext().getStoreId();
90 }
91
92 if ("".equals(storeId))
93 {
94 storeId = null;
95 }
96
97 return storeId;
98 }
99
100 public static void setCurrentStoreId(HttpServletRequest request, String storeId)
101 {
102 request.getSession(true).setAttribute(WebFrameworkConstants.STORE_ID_SESSION_ATTRIBUTE_NAME, storeId);
103
104 ThreadLocalPreviewContext sandboxContext = new ThreadLocalPreviewContext(storeId, getCurrentWebappId());
105 }
106
107 public static String getCurrentWebappId()
108 {
109 String webappId = null;
110
111 if (ThreadLocalPreviewContext.getSandboxContext() != null)
112 {
113 webappId = ThreadLocalPreviewContext.getSandboxContext().getWebappId();
114 }
115
116 if ("".equals(webappId))
117 {
118 webappId = null;
119 }
120
121 return webappId;
122 }
123
124 public static void setCurrentWebappId(HttpServletRequest request, String webappId)
125 {
126 request.getSession(true).setAttribute(WebFrameworkConstants.WEBAPP_ID_SESSION_ATTRIBUTE_NAME, webappId);
127
128 ThreadLocalPreviewContext sandboxContext = new ThreadLocalPreviewContext(getCurrentStoreId(), webappId);
129 }
130
131 public static void setOverlayEnabled(HttpServletRequest request,
132 boolean enabled)
133 {
134 request.getSession().setAttribute("OverlayState",
135 (enabled ? "enabled" : "disabled"));
136 }
137
138 public static boolean isOverlayEnabled(HttpServletRequest request)
139 {
140 boolean enabled = true;
141
142 String result = (String) request.getSession().getAttribute(
143 "OverlayState");
144 if ("disabled".equals(result))
145 {
146 enabled = false;
147 }
148
149 return enabled;
150 }
151 }