]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/CmsApplication.java
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.argeo
.cms
.util
.SimpleApp
;
8 * Configures an Argeo CMS RWT application.
10 * @deprecated Use {@link SimpleApp} instead (same method signatures)
13 public class CmsApplication
extends SimpleApp
{
14 private final static Log log
= LogFactory
.getLog(CmsApplication
.class);
16 public CmsApplication() {
18 log
.warn("org.argeo.cms.CmsApplication will be removed soon, use org.argeo.cms.util.SimpleApp");
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,
27 // private List<String> resources = new ArrayList<String>();
29 // private BundleContext bundleContext;
31 // private Repository repository;
32 // private String workspace = null;
33 // private String basePath = "/";
34 // private List<String> roPrincipals = Arrays.asList("anonymous",
36 // private List<String> rwPrincipals = Arrays.asList("everyone");
38 // private CmsUiProvider header;
39 // private Map<String, CmsUiProvider> pages = new LinkedHashMap<String,
42 // private Integer headerHeight = 40;
45 // private CmsImageManager imageManager = new ImageManagerImpl();
47 // public void configure(Application application) {
49 // application.setOperationMode(OperationMode.SWT_COMPATIBILITY);
50 // application.setExceptionHandler(new CmsExceptionHandler());
52 // // TODO load all pics under icons
53 // // loading animated gif
54 // application.addResource(LOADING_IMAGE,
55 // createResourceLoader(LOADING_IMAGE));
57 // application.addResource(NO_IMAGE, createResourceLoader(NO_IMAGE));
59 // for (String resource : resources) {
60 // application.addResource(resource, new BundleResourceLoader(
62 // if (log.isDebugEnabled())
63 // log.debug("Registered resource " + resource);
66 // Map<String, String> defaultBranding = null;
67 // if (branding.containsKey("*"))
68 // defaultBranding = branding.get("*");
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));
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);
89 // if (!properties.containsKey(WebClient.PAGE_TITLE))
91 // WebClient.PAGE_TITLE,
92 // Character.toUpperCase(page.charAt(0))
93 // + page.substring(1));
95 // // default body HTML
96 // if (!properties.containsKey(WebClient.BODY_HTML))
97 // properties.put(WebClient.BODY_HTML, DEFAULT_LOADING_BODY);
100 // // ADD ENTRY POINT
102 // application.addEntryPoint("/" + page, new CmsEntryPointFactory(
103 // pages.get(page), repository, workspace, properties),
105 // log.info("Registered entry point /" + page);
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));
117 // } catch (RuntimeException e) {
118 // // Easier access to initialisation errors
119 // log.error("Unexpected exception when configuring RWT application.",
125 // public void init() throws RepositoryException {
126 // Session session = null;
128 // session = JcrUtils.loginOrCreateWorkspace(repository, workspace);
129 // VersionManager vm = session.getWorkspace().getVersionManager();
130 // if (!vm.isCheckedOut("/"))
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);
140 // for (String pageName : pages.keySet()) {
142 // initPage(session, pages.get(pageName));
144 // } catch (Exception e) {
145 // throw new CmsException(
146 // "Cannot initialize page " + pageName, e);
151 // JcrUtils.logoutQuietly(session);
155 // protected void initPage(Session adminSession, CmsUiProvider page)
156 // throws RepositoryException {
157 // if (page instanceof LifeCycleUiProvider)
158 // ((LifeCycleUiProvider) page).init(adminSession);
161 // public void destroy() {
162 // for (String pageName : pages.keySet()) {
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);
173 // public void setRepository(Repository repository) {
174 // this.repository = repository;
177 // public void setWorkspace(String workspace) {
178 // this.workspace = workspace;
181 // public void setCmsLogin(@SuppressWarnings("deprecation") CmsLogin
183 // // this.cmsLogin = cmsLogin;
184 // log.warn("cmsLogin"
186 // " is deprecated and will be removed soon. Adapt your configuration ASAP.");
189 // public void setHeader(CmsUiProvider header) {
190 // this.header = header;
193 // public void setPages(Map<String, CmsUiProvider> pages) {
194 // this.pages = pages;
197 // public void setBasePath(String basePath) {
198 // this.basePath = basePath;
201 // public void setRoPrincipals(List<String> roPrincipals) {
202 // this.roPrincipals = roPrincipals;
205 // public void setRwPrincipals(List<String> rwPrincipals) {
206 // this.rwPrincipals = rwPrincipals;
209 // public void setHeaderHeight(Integer headerHeight) {
210 // this.headerHeight = headerHeight;
213 // public void setBranding(Map<String, Map<String, String>> branding) {
214 // this.branding = branding;
217 // public void setStyleSheets(Map<String, List<String>> styleSheets) {
218 // this.styleSheets = styleSheets;
221 // public void setBundleContext(BundleContext bundleContext) {
222 // this.bundleContext = bundleContext;
225 // public void setResources(List<String> resources) {
226 // this.resources = resources;
229 // class CmsExceptionHandler implements ExceptionHandler {
232 // public void handleException(Throwable throwable) {
233 // CmsSession.current.get().exception(throwable);
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;
244 // public CmsEntryPointFactory(CmsUiProvider page, Repository repository,
245 // String workspace, Map<String, String> properties) {
247 // this.repository = repository;
248 // this.workspace = workspace;
249 // this.properties = properties;
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;
263 // private class CmsEntryPoint extends AbstractCmsEntryPoint {
264 // private Composite headerArea;
265 // private Composite bodyArea;
266 // private final CmsUiProvider uiProvider;
268 // public CmsEntryPoint(Repository repository, String workspace,
269 // CmsUiProvider uiProvider, Map<String, String> factoryProperties) {
270 // super(repository, workspace, factoryProperties);
271 // this.uiProvider = uiProvider;
275 // protected void createContents(Composite parent) {
277 // getShell().getDisplay().setData(CmsSession.KEY, this);
279 // parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
281 // parent.setLayout(CmsUtils.noSpaceGridLayout());
283 // headerArea = new Composite(parent, SWT.NONE);
284 // headerArea.setLayout(new FillLayout());
285 // GridData headerData = new GridData(SWT.FILL, SWT.FILL, false,
287 // headerData.heightHint = headerHeight;
288 // headerArea.setLayoutData(headerData);
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,
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());
300 // } catch (Exception e) {
301 // throw new CmsException("Cannot create entrypoint contents", e);
306 // protected void refreshHeader() {
307 // if (headerArea == null)
309 // for (Control child : headerArea.getChildren())
312 // header.createUi(headerArea, getNode());
313 // } catch (RepositoryException e) {
314 // throw new CmsException("Cannot refresh header", e);
316 // headerArea.layout(true, true);
320 // protected void refreshBody() {
321 // if (bodyArea == null)
324 // Throwable exception = getException();
325 // if (exception != null) {
326 // // new Label(bodyArea, SWT.NONE).setText("Unreachable state : "
328 // // if (getNode() != null)
329 // // new Label(bodyArea, SWT.NONE).setText("Context : "
332 // // Text errorText = new Text(bodyArea, SWT.MULTI | SWT.H_SCROLL
333 // // | SWT.V_SCROLL);
334 // // errorText.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
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(
343 // systemNotifications.notifyException(exception);
350 // for (Control child : bodyArea.getChildren())
352 // bodyArea.setLayout(CmsUtils.noSpaceGridLayout());
354 // String state = getState();
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);
363 // bodyArea.layout(true, true);
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();
373 // throw new CmsException("Unauthorized");
375 // return session.getNode(basePath);
379 // public CmsImageManager getImageManager() {
380 // return imageManager;
385 // private static ResourceLoader createResourceLoader(final String
387 // return new ResourceLoader() {
388 // public InputStream getResourceAsStream(String resourceName)
389 // throws IOException {
390 // return getClass().getClassLoader().getResourceAsStream(
399 // private static String DEFAULT_LOADING_BODY = "<div"
401 // " style=\"position: absolute; left: 50%; top: 50%; margin: -32px -32px; width: 64px; height:64px\">"
403 // "<img src=\"./rwt-resources/icons/loading.gif\" width=\"32\" height=\"32\" style=\"margin: 16px 16px\"/>"