KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.pages.setup;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.riotfamily.pages.PageNode;
30 import org.riotfamily.pages.Site;
31 import org.riotfamily.pages.dao.PageDao;
32 import org.springframework.beans.factory.InitializingBean;
33 import org.springframework.transaction.PlatformTransactionManager;
34 import org.springframework.transaction.TransactionStatus;
35 import org.springframework.transaction.support.TransactionCallbackWithoutResult;
36 import org.springframework.transaction.support.TransactionTemplate;
37
38 /**
39  * @author Felix Gnass [fgnass at neteye dot de]
40  * @since 6.5
41  */

42 public class PageSetupBean implements InitializingBean {
43
44     private String JavaDoc siteName = null;
45
46     private List JavaDoc definitions;
47
48     private PageDao pageDao;
49
50     private PlatformTransactionManager transactionManager;
51
52     public void setPageDao(PageDao pageDao) {
53         this.pageDao = pageDao;
54     }
55
56     public void setTransactionManager(PlatformTransactionManager transactionManager) {
57         this.transactionManager = transactionManager;
58     }
59
60     public void setDefinitions(List JavaDoc definitions) {
61         this.definitions = definitions;
62     }
63
64     public void afterPropertiesSet() throws Exception JavaDoc {
65         new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() {
66             protected void doInTransactionWithoutResult(TransactionStatus status) {
67                 createNodes();
68             }
69         });
70     }
71
72     protected void createNodes() {
73         if (pageDao.listSites().isEmpty()) {
74             Site site = pageDao.getSite(siteName);
75             PageNode rootNode = pageDao.findRootNode(site);
76             Iterator JavaDoc it = definitions.iterator();
77             while (it.hasNext()) {
78                 PageDefinition definition = (PageDefinition) it.next();
79                 PageNode childNode = definition.createNode(rootNode, pageDao);
80                 rootNode.addChildNode(childNode);
81             }
82             pageDao.updateNode(rootNode);
83         }
84     }
85
86
87 }
88
Popular Tags