KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > pages > setup > PageDefinition


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2007
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * flx
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.pages.setup;
25
26 import java.util.Date JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Locale JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Properties JavaDoc;
33
34 import org.riotfamily.common.util.FormatUtils;
35 import org.riotfamily.pages.Page;
36 import org.riotfamily.pages.PageNode;
37 import org.riotfamily.pages.dao.PageDao;
38
39 /**
40  * @author flx
41  * @since 6.5
42  */

43 public class PageDefinition {
44
45     private String JavaDoc pathComponent;
46
47     private String JavaDoc handlerName;
48
49     private String JavaDoc childHandlerName;
50
51     private List JavaDoc definitions;
52
53     private boolean hidden;
54
55     private boolean published = true;
56
57     private boolean systemNode = true;
58
59     private boolean folder;
60
61     private Properties JavaDoc globalProps;
62
63     private HashMap JavaDoc localizedProps;
64
65     public void setPathComponent(String JavaDoc pathComponent) {
66         this.pathComponent = pathComponent;
67     }
68
69     public String JavaDoc getPathComponent() {
70         return pathComponent != null
71                 ? pathComponent
72                 : FormatUtils.camelToXmlCase(handlerName);
73     }
74
75     public void setHandlerName(String JavaDoc handlerName) {
76         this.handlerName = handlerName;
77     }
78
79     public void setChildHandlerName(String JavaDoc childHandlerName) {
80         this.childHandlerName = childHandlerName;
81     }
82
83     public void setHidden(boolean hidden) {
84         this.hidden = hidden;
85     }
86
87     public void setPublished(boolean published) {
88         this.published = published;
89     }
90
91     public void setSystemNode(boolean systemNode) {
92         this.systemNode = systemNode;
93     }
94
95     public void setFolder(boolean folder) {
96         this.folder = folder;
97     }
98
99     public void setGlobalProps(Properties JavaDoc globalProps) {
100         this.globalProps = globalProps;
101     }
102
103     public void setLocalizedProps(HashMap JavaDoc localizedProps) {
104         this.localizedProps = localizedProps;
105     }
106
107     public List JavaDoc getDefinitions() {
108         return this.definitions;
109     }
110
111     public void setDefinitions(List JavaDoc definitions) {
112         this.definitions = definitions;
113     }
114
115     public PageNode createNode(PageNode parent, PageDao pageDao) {
116         PageNode node = new PageNode();
117         node.setParent(parent);
118         node.setSite(parent.getSite());
119         node.setHandlerName(handlerName);
120         node.setSystemNode(systemNode);
121         node.setChildHandlerName(childHandlerName);
122         node.setHidden(hidden);
123         createPages(node, pageDao);
124         if (definitions != null) {
125             Iterator JavaDoc it = definitions.iterator();
126             while (it.hasNext()) {
127                 PageDefinition childDefinition = (PageDefinition) it.next();
128                 PageNode childNode = childDefinition.createNode(node, pageDao);
129                 node.addChildNode(childNode);
130             }
131         }
132         pageDao.saveNode(node);
133         return node;
134     }
135
136     private void createPages(PageNode node, PageDao pageDao) {
137         Iterator JavaDoc it = pageDao.getLocales().iterator();
138         while (it.hasNext()) {
139             Locale JavaDoc locale = (Locale JavaDoc) it.next();
140             Page page = new Page(getPathComponent(), locale);
141             page.setNode(node);
142             page.setPublished(published);
143             page.setFolder(folder);
144             page.setCreationDate(new Date JavaDoc());
145             addPageProps(page, locale);
146             node.addPage(page);
147         }
148     }
149
150     private void addPageProps(Page page, Locale JavaDoc locale) {
151         HashMap JavaDoc newProps = new HashMap JavaDoc();
152         if (globalProps != null) {
153             newProps.putAll(globalProps);
154         }
155         if (localizedProps != null) {
156             Map JavaDoc localizedMap = (Map JavaDoc) localizedProps.get(locale.toString());
157             if(localizedMap != null) {
158                 newProps.putAll(localizedMap);
159             }
160         }
161         page.getProperties(false).putAll(newProps);
162     }
163
164
165 }
166
Popular Tags