00deae94af9ddc38ce3e044c5d48a5af987ad3a3
[gpl/argeo-suite.git] / publishing / org.argeo.publishing.ui / src / org / argeo / publishing / ui / PublishingApp.java
1 package org.argeo.publishing.ui;
2
3 import java.util.HashSet;
4 import java.util.Map;
5 import java.util.Set;
6
7 import javax.jcr.Node;
8 import javax.jcr.RepositoryException;
9 import javax.jcr.Session;
10
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13 import org.argeo.api.NodeUtils;
14 import org.argeo.cms.ui.AbstractCmsApp;
15 import org.argeo.cms.ui.CmsApp;
16 import org.argeo.docbook.ui.DocBookTypes;
17 import org.argeo.docbook.ui.DocumentPage;
18 import org.argeo.jcr.Jcr;
19 import org.argeo.jcr.JcrUtils;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.osgi.framework.Constants;
24
25 /**
26  * A {@link CmsApp} dedicated to publishing, typically a public or internal web
27  * site.
28  */
29 public class PublishingApp extends AbstractCmsApp {
30         private final static Log log = LogFactory.getLog(PublishingApp.class);
31
32         private String pid;
33         private String defaultThemeId;
34
35         public void init(Map<String, String> properties) {
36                 defaultThemeId = properties.get("defaultThemeId");
37                 pid = properties.get(Constants.SERVICE_PID);
38                 if (log.isDebugEnabled())
39                         log.info("Publishing App " + pid + " started");
40         }
41
42         public void destroy(Map<String, String> properties) {
43                 if (log.isDebugEnabled())
44                         log.info("Publishing App " + pid + " stopped");
45
46         }
47
48         @Override
49         public Set<String> getUiNames() {
50                 Set<String> uiNames = new HashSet<>();
51                 uiNames.add("");
52                 return uiNames;
53         }
54
55         @Override
56         public Composite initUi(Composite parent) {
57                 Session adminSession = NodeUtils.openDataAdminSession(getRepository(), null);
58                 parent.setLayout(new GridLayout());
59                 Node indexNode;
60                 try {
61                         indexNode = JcrUtils.getOrAdd(Jcr.getRootNode(adminSession), DocumentPage.WWW, DocBookTypes.ARTICLE);
62                         adminSession.save();
63                 } catch (RepositoryException e) {
64                         throw new IllegalStateException(e);
65                 }
66                 Control page = new DocumentPage().createUiPart(parent, indexNode);
67                 return (Composite) page;
68         }
69
70         @Override
71         public void refreshUi(Composite parent, String state) {
72                 parent.setLayout(new GridLayout());
73                 new DocumentPage().createUiPart(parent, null);
74         }
75
76         @Override
77         public void setState(Composite parent, String state) {
78
79         }
80
81         @Override
82         protected String getThemeId(String uiName) {
83                 return defaultThemeId;
84         }
85 }