]> git.argeo.org Git - lgpl/argeo-commons.git/blob - CmsApplication.java
c428a0bf95e622056ffe4f97a978300f76b1871e
[lgpl/argeo-commons.git] / CmsApplication.java
1 package org.argeo.cms;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.argeo.cms.util.SimpleApp;
6
7 /**
8 * Configures an Argeo CMS RWT application.
9 *
10 * @deprecated Use {@link SimpleApp} instead (same method signatures)
11 */
12 @Deprecated
13 public class CmsApplication extends SimpleApp {
14 private final static Log log = LogFactory.getLog(CmsApplication.class);
15
16 public CmsApplication() {
17 super();
18 log.warn("org.argeo.cms.CmsApplication will be removed soon, use org.argeo.cms.util.SimpleApp");
19 }
20
21 //
22 // private Map<String, Map<String, String>> branding = new HashMap<String,
23 // Map<String, String>>();
24 // private Map<String, List<String>> styleSheets = new HashMap<String,
25 // List<String>>();
26 //
27 // private List<String> resources = new ArrayList<String>();
28 //
29 // private BundleContext bundleContext;
30 //
31 // private Repository repository;
32 // private String workspace = null;
33 // private String basePath = "/";
34 // private List<String> roPrincipals = Arrays.asList("anonymous",
35 // "everyone");
36 // private List<String> rwPrincipals = Arrays.asList("everyone");
37 //
38 // private CmsUiProvider header;
39 // private Map<String, CmsUiProvider> pages = new LinkedHashMap<String,
40 // CmsUiProvider>();
41 //
42 // private Integer headerHeight = 40;
43 //
44 // // Managers
45 // private CmsImageManager imageManager = new ImageManagerImpl();
46 //
47 // public void configure(Application application) {
48 // try {
49 // application.setOperationMode(OperationMode.SWT_COMPATIBILITY);
50 // application.setExceptionHandler(new CmsExceptionHandler());
51 //
52 // // TODO load all pics under icons
53 // // loading animated gif
54 // application.addResource(LOADING_IMAGE,
55 // createResourceLoader(LOADING_IMAGE));
56 // // empty image
57 // application.addResource(NO_IMAGE, createResourceLoader(NO_IMAGE));
58 //
59 // for (String resource : resources) {
60 // application.addResource(resource, new BundleResourceLoader(
61 // bundleContext));
62 // if (log.isDebugEnabled())
63 // log.debug("Registered resource " + resource);
64 // }
65 //
66 // Map<String, String> defaultBranding = null;
67 // if (branding.containsKey("*"))
68 // defaultBranding = branding.get("*");
69 //
70 // // entry points
71 // for (String page : pages.keySet()) {
72 // Map<String, String> properties = defaultBranding != null ? new
73 // HashMap<String, String>(
74 // defaultBranding) : new HashMap<String, String>();
75 // if (branding.containsKey(page)) {
76 // properties.putAll(branding.get(page));
77 // }
78 // // favicon
79 // if (properties.containsKey(WebClient.FAVICON)) {
80 // String faviconRelPath = properties.get(WebClient.FAVICON);
81 // application.addResource(faviconRelPath,
82 // new BundleResourceLoader(bundleContext));
83 // if (log.isTraceEnabled())
84 // log.trace("Registered favicon " + faviconRelPath);
85 //
86 // }
87 //
88 // // page title
89 // if (!properties.containsKey(WebClient.PAGE_TITLE))
90 // properties.put(
91 // WebClient.PAGE_TITLE,
92 // Character.toUpperCase(page.charAt(0))
93 // + page.substring(1));
94 //
95 // // default body HTML
96 // if (!properties.containsKey(WebClient.BODY_HTML))
97 // properties.put(WebClient.BODY_HTML, DEFAULT_LOADING_BODY);
98 //
99 // //
100 // // ADD ENTRY POINT
101 // //
102 // application.addEntryPoint("/" + page, new CmsEntryPointFactory(
103 // pages.get(page), repository, workspace, properties),
104 // properties);
105 // log.info("Registered entry point /" + page);
106 // }
107 //
108 // // stylesheets
109 // for (String themeId : styleSheets.keySet()) {
110 // List<String> cssLst = styleSheets.get(themeId);
111 // for (String css : cssLst) {
112 // application.addStyleSheet(themeId, css,
113 // new BundleResourceLoader(bundleContext));
114 // }
115 //
116 // }
117 // } catch (RuntimeException e) {
118 // // Easier access to initialisation errors
119 // log.error("Unexpected exception when configuring RWT application.",
120 // e);
121 // throw e;
122 // }
123 // }
124 //
125 // public void init() throws RepositoryException {
126 // Session session = null;
127 // try {
128 // session = JcrUtils.loginOrCreateWorkspace(repository, workspace);
129 // VersionManager vm = session.getWorkspace().getVersionManager();
130 // if (!vm.isCheckedOut("/"))
131 // vm.checkout("/");
132 // JcrUtils.mkdirs(session, basePath);
133 // for (String principal : rwPrincipals)
134 // JcrUtils.addPrivilege(session, basePath, principal,
135 // Privilege.JCR_WRITE);
136 // for (String principal : roPrincipals)
137 // JcrUtils.addPrivilege(session, basePath, principal,
138 // Privilege.JCR_READ);
139 //
140 // for (String pageName : pages.keySet()) {
141 // try {
142 // initPage(session, pages.get(pageName));
143 // session.save();
144 // } catch (Exception e) {
145 // throw new CmsException(
146 // "Cannot initialize page " + pageName, e);
147 // }
148 // }
149 //
150 // } finally {
151 // JcrUtils.logoutQuietly(session);
152 // }
153 // }
154 //
155 // protected void initPage(Session adminSession, CmsUiProvider page)
156 // throws RepositoryException {
157 // if (page instanceof LifeCycleUiProvider)
158 // ((LifeCycleUiProvider) page).init(adminSession);
159 // }
160 //
161 // public void destroy() {
162 // for (String pageName : pages.keySet()) {
163 // try {
164 // CmsUiProvider page = pages.get(pageName);
165 // if (page instanceof LifeCycleUiProvider)
166 // ((LifeCycleUiProvider) page).destroy();
167 // } catch (Exception e) {
168 // log.error("Cannot destroy page " + pageName, e);
169 // }
170 // }
171 // }
172 //
173 // public void setRepository(Repository repository) {
174 // this.repository = repository;
175 // }
176 //
177 // public void setWorkspace(String workspace) {
178 // this.workspace = workspace;
179 // }
180 //
181 // public void setCmsLogin(@SuppressWarnings("deprecation") CmsLogin
182 // cmsLogin) {
183 // // this.cmsLogin = cmsLogin;
184 // log.warn("cmsLogin"
185 // +
186 // " is deprecated and will be removed soon. Adapt your configuration ASAP.");
187 // }
188 //
189 // public void setHeader(CmsUiProvider header) {
190 // this.header = header;
191 // }
192 //
193 // public void setPages(Map<String, CmsUiProvider> pages) {
194 // this.pages = pages;
195 // }
196 //
197 // public void setBasePath(String basePath) {
198 // this.basePath = basePath;
199 // }
200 //
201 // public void setRoPrincipals(List<String> roPrincipals) {
202 // this.roPrincipals = roPrincipals;
203 // }
204 //
205 // public void setRwPrincipals(List<String> rwPrincipals) {
206 // this.rwPrincipals = rwPrincipals;
207 // }
208 //
209 // public void setHeaderHeight(Integer headerHeight) {
210 // this.headerHeight = headerHeight;
211 // }
212 //
213 // public void setBranding(Map<String, Map<String, String>> branding) {
214 // this.branding = branding;
215 // }
216 //
217 // public void setStyleSheets(Map<String, List<String>> styleSheets) {
218 // this.styleSheets = styleSheets;
219 // }
220 //
221 // public void setBundleContext(BundleContext bundleContext) {
222 // this.bundleContext = bundleContext;
223 // }
224 //
225 // public void setResources(List<String> resources) {
226 // this.resources = resources;
227 // }
228 //
229 // class CmsExceptionHandler implements ExceptionHandler {
230 //
231 // @Override
232 // public void handleException(Throwable throwable) {
233 // CmsSession.current.get().exception(throwable);
234 // }
235 //
236 // }
237 //
238 // private class CmsEntryPointFactory implements EntryPointFactory {
239 // private final CmsUiProvider page;
240 // private final Repository repository;
241 // private final String workspace;
242 // private final Map<String, String> properties;
243 //
244 // public CmsEntryPointFactory(CmsUiProvider page, Repository repository,
245 // String workspace, Map<String, String> properties) {
246 // this.page = page;
247 // this.repository = repository;
248 // this.workspace = workspace;
249 // this.properties = properties;
250 // }
251 //
252 // @Override
253 // public EntryPoint create() {
254 // CmsEntryPoint entryPoint = new CmsEntryPoint(repository, workspace,
255 // page, properties);
256 // entryPoint.setState("");
257 // CmsSession.current.set(entryPoint);
258 // return entryPoint;
259 // }
260 //
261 // }
262 //
263 // private class CmsEntryPoint extends AbstractCmsEntryPoint {
264 // private Composite headerArea;
265 // private Composite bodyArea;
266 // private final CmsUiProvider uiProvider;
267 //
268 // public CmsEntryPoint(Repository repository, String workspace,
269 // CmsUiProvider uiProvider, Map<String, String> factoryProperties) {
270 // super(repository, workspace, factoryProperties);
271 // this.uiProvider = uiProvider;
272 // }
273 //
274 // @Override
275 // protected void createContents(Composite parent) {
276 // try {
277 // getShell().getDisplay().setData(CmsSession.KEY, this);
278 //
279 // parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
280 // true));
281 // parent.setLayout(CmsUtils.noSpaceGridLayout());
282 //
283 // headerArea = new Composite(parent, SWT.NONE);
284 // headerArea.setLayout(new FillLayout());
285 // GridData headerData = new GridData(SWT.FILL, SWT.FILL, false,
286 // false);
287 // headerData.heightHint = headerHeight;
288 // headerArea.setLayoutData(headerData);
289 // refreshHeader();
290 //
291 // bodyArea = new Composite(parent, SWT.NONE);
292 // bodyArea.setData(RWT.CUSTOM_VARIANT, CmsStyles.CMS_BODY);
293 // bodyArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
294 // true));
295 // // Should not be set here: it then prevent all children
296 // // composite to define a background color via CSS
297 // // bodyArea.setBackgroundMode(SWT.INHERIT_DEFAULT);
298 // bodyArea.setLayout(CmsUtils.noSpaceGridLayout());
299 // refreshBody();
300 // } catch (Exception e) {
301 // throw new CmsException("Cannot create entrypoint contents", e);
302 // }
303 // }
304 //
305 // @Override
306 // protected void refreshHeader() {
307 // if (headerArea == null)
308 // return;
309 // for (Control child : headerArea.getChildren())
310 // child.dispose();
311 // try {
312 // header.createUi(headerArea, getNode());
313 // } catch (RepositoryException e) {
314 // throw new CmsException("Cannot refresh header", e);
315 // }
316 // headerArea.layout(true, true);
317 // }
318 //
319 // @Override
320 // protected void refreshBody() {
321 // if (bodyArea == null)
322 // return;
323 // // Exception
324 // Throwable exception = getException();
325 // if (exception != null) {
326 // // new Label(bodyArea, SWT.NONE).setText("Unreachable state : "
327 // // + getState());
328 // // if (getNode() != null)
329 // // new Label(bodyArea, SWT.NONE).setText("Context : "
330 // // + getNode());
331 // //
332 // // Text errorText = new Text(bodyArea, SWT.MULTI | SWT.H_SCROLL
333 // // | SWT.V_SCROLL);
334 // // errorText.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
335 // // true,
336 // // true));
337 // // StringWriter sw = new StringWriter();
338 // // exception.printStackTrace(new PrintWriter(sw));
339 // // errorText.setText(sw.toString());
340 // // IOUtils.closeQuietly(sw);
341 // SystemNotifications systemNotifications = new SystemNotifications(
342 // bodyArea);
343 // systemNotifications.notifyException(exception);
344 // resetException();
345 // return;
346 // // TODO report
347 // }
348 //
349 // // clear
350 // for (Control child : bodyArea.getChildren())
351 // child.dispose();
352 // bodyArea.setLayout(CmsUtils.noSpaceGridLayout());
353 //
354 // String state = getState();
355 // try {
356 // if (state == null)
357 // throw new CmsException("State cannot be null");
358 // uiProvider.createUi(bodyArea, getNode());
359 // } catch (RepositoryException e) {
360 // throw new CmsException("Cannot refresh body", e);
361 // }
362 //
363 // bodyArea.layout(true, true);
364 // }
365 //
366 // @Override
367 // protected Node getDefaultNode(Session session)
368 // throws RepositoryException {
369 // if (!session.hasPermission(basePath, "read")) {
370 // if (session.getUserID().equals("anonymous"))
371 // throw new LoginRequiredException();
372 // else
373 // throw new CmsException("Unauthorized");
374 // }
375 // return session.getNode(basePath);
376 // }
377 //
378 // @Override
379 // public CmsImageManager getImageManager() {
380 // return imageManager;
381 // }
382 //
383 // }
384 //
385 // private static ResourceLoader createResourceLoader(final String
386 // resourceName) {
387 // return new ResourceLoader() {
388 // public InputStream getResourceAsStream(String resourceName)
389 // throws IOException {
390 // return getClass().getClassLoader().getResourceAsStream(
391 // resourceName);
392 // }
393 // };
394 // }
395 //
396 // /*
397 // * TEXTS
398 // */
399 // private static String DEFAULT_LOADING_BODY = "<div"
400 // +
401 // " style=\"position: absolute; left: 50%; top: 50%; margin: -32px -32px; width: 64px; height:64px\">"
402 // +
403 // "<img src=\"./rwt-resources/icons/loading.gif\" width=\"32\" height=\"32\" style=\"margin: 16px 16px\"/>"
404 // + "</div>";
405 }