1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.services.wcm.webcontent;
18
19 import javax.jcr.Node;
20 import javax.jcr.Session;
21
22 import org.exoplatform.services.jcr.ext.common.SessionProvider;
23 import org.exoplatform.services.wcm.core.BaseWebSchemaHandler;
24
25
26
27
28
29
30
31 public class WebContentSchemaHandler extends BaseWebSchemaHandler {
32
33 protected String getHandlerNodeType() { return "exo:webContent"; }
34 protected String getParentNodeType() { return "nt:unstructured"; }
35
36 public boolean matchHandler(SessionProvider sessionProvider, Node node) throws Exception {
37 String handlerNodeType = getHandlerNodeType();
38 String parentNodeType = getParentNodeType();
39 if(!node.isNodeType(handlerNodeType))
40 return false;
41 if(!node.getParent().isNodeType(parentNodeType))
42 return false;
43 return true;
44 }
45
46 public void onCreateNode(SessionProvider sessionProvider, final Node webContent) throws Exception {
47 createSchema(webContent);
48 webContent.getParent().save();
49 }
50
51 public Node getCSSFolder(final Node webContent) throws Exception {
52 return webContent.getNode("css");
53 }
54
55 public Node getJSFolder(final Node webContent) throws Exception {
56 return webContent.getNode("js");
57 }
58
59 public Node getImagesFolders(final Node webContent) throws Exception {
60 return webContent.getNode("medias/images");
61 }
62
63 public Node getIllustrationImage(final Node webContent) throws Exception {
64 return webContent.getNode("medias/images/illustration");
65 }
66
67 public Node getVideoFolder(final Node webContent) throws Exception {
68 return webContent.getNode("medias/videos");
69 }
70
71 public Node getDocumentFolder (final Node webContent) throws Exception {
72 return webContent.getNode("documents");
73 }
74
75 public void createDefaultSchema(Node webContent) throws Exception{
76 addMixin(webContent,"exo:owneable");
77 createSchema(webContent);
78 createDefautWebData(webContent);
79 }
80
81 protected void createSchema(final Node webContent) throws Exception {
82 if (!webContent.hasNode("js")) {
83 Node js = webContent.addNode("js","exo:jsFolder");
84 addMixin(js,"exo:owneable");
85 }
86 if (!webContent.hasNode("css")) {
87 Node css = webContent.addNode("css","exo:cssFolder");
88 addMixin(css,"exo:owneable");
89 }
90 if (!webContent.hasNode("medias")) {
91 Node multimedia = webContent.addNode("medias","exo:multimediaFolder");
92 addMixin(multimedia,"exo:owneable");
93 Node images = multimedia.addNode("images",NT_FOLDER);
94 addMixin(images, "exo:pictureFolder");
95 addMixin(images,"exo:owneable");
96 Node video = multimedia.addNode("videos",NT_FOLDER);
97 addMixin(video, "exo:videoFolder");
98 addMixin(video,"exo:owneable");
99 Node audio = multimedia.addNode("audio",NT_FOLDER);
100 addMixin(audio, "exo:musicFolder");
101 addMixin(audio,"exo:owneable");
102 }
103 if (!webContent.hasNode("documents")) {
104 Node document = webContent.addNode("documents",NT_UNSTRUCTURED);
105 addMixin(document, "exo:documentFolder");
106 addMixin(document,"exo:owneable");
107 }
108
109
110 webContent.setProperty("exo:title", webContent.getName());
111 }
112
113 public boolean isWebcontentChildNode(Node file) throws Exception{
114 Node parent = file.getParent();
115
116 if(parent.isNodeType("exo:webContent"))
117 return true;
118
119 if(parent.getPath().equals("/"))
120 return false;
121 Node grantParent = parent.getParent();
122 if(grantParent.isNodeType("exo:webContent"))
123 return true;
124
125 if(grantParent.getPath().equals("/"))
126 return false;
127 Node ansestor = grantParent.getParent();
128 if(ansestor.isNodeType("exo:webContent"))
129 return true;
130 return false;
131 }
132 }