KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > managementtool > actions > RebuildRegistryAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.applications.managementtool.actions;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.apache.log4j.Logger;
30 import org.exolab.castor.jdo.Database;
31 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
32 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService;
33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
34 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController;
35 import org.infoglue.cms.controllers.kernel.impl.simple.RegistryController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController;
37 import org.infoglue.cms.entities.content.Content;
38 import org.infoglue.cms.entities.content.ContentVersion;
39 import org.infoglue.cms.entities.structure.SiteNode;
40 import org.infoglue.cms.entities.structure.SiteNodeVersion;
41
42
43 /**
44  * This class handles Exporting of a repository to an XML-file.
45  *
46  * @author mattias
47  */

48
49 public class RebuildRegistryAction extends InfoGlueAbstractAction
50 {
51     private final static Logger logger = Logger.getLogger(RebuildRegistryAction.class.getName());
52
53     private Integer JavaDoc repositoryId = null;
54     
55     private String JavaDoc fileUrl = "";
56     private String JavaDoc fileName = "";
57
58     /**
59      * This shows the dialog before export.
60      * @return
61      * @throws Exception
62      */

63
64     public String JavaDoc doInput() throws Exception JavaDoc
65     {
66         return "input";
67     }
68     
69     /**
70      * This handles the actual exporting.
71      */

72     
73     protected String JavaDoc doExecute() throws Exception JavaDoc
74     {
75         RegistryController registryController = RegistryController.getController();
76         
77         Database db = CastorDatabaseService.getDatabase();
78         
79         try
80         {
81             db.begin();
82
83             
84             //Checks the relations from sitenodes
85
List JavaDoc siteNodes = SiteNodeController.getController().getRepositorySiteNodes(this.repositoryId, db);
86             
87             Iterator JavaDoc siteNodesIterator = siteNodes.iterator();
88             while(siteNodesIterator.hasNext())
89             {
90                 SiteNode siteNode = (SiteNode)siteNodesIterator.next();
91                 logger.info("Going to index all versions of " + siteNode.getName());
92                 
93                 Iterator JavaDoc siteNodeVersionsIterator = siteNode.getSiteNodeVersions().iterator();
94                 while(siteNodeVersionsIterator.hasNext())
95                 {
96                     SiteNodeVersion siteNodeVersion = (SiteNodeVersion)siteNodeVersionsIterator.next();
97                     registryController.updateSiteNodeVersion(siteNodeVersion, db);
98                 }
99             }
100
101             //Checks the relations from contents
102
List JavaDoc languages = LanguageController.getController().getLanguageList(this.repositoryId, db);
103             List JavaDoc contents = ContentController.getContentController().getRepositoryContents(this.repositoryId, db);
104             
105             Iterator JavaDoc iterator = contents.iterator();
106             while(iterator.hasNext())
107             {
108                 Content content = (Content)iterator.next();
109                 logger.info("Going to index all version of " + content.getName());
110                 
111                 Iterator JavaDoc versionsIterator = content.getContentVersions().iterator();
112                 while(versionsIterator.hasNext())
113                 {
114                     ContentVersion contentVersion = (ContentVersion)versionsIterator.next();
115                     registryController.updateContentVersion(contentVersion, db);
116                 }
117             }
118                         
119             db.commit();
120         }
121         catch (Exception JavaDoc e)
122         {
123             logger.error("An error was found rebuilding the registry: " + e.getMessage(), e);
124             db.rollback();
125         }
126         finally
127         {
128             db.close();
129         }
130         
131         return "success";
132     }
133
134
135     public void setRepositoryId(Integer JavaDoc repositoryId)
136     {
137         this.repositoryId = repositoryId;
138     }
139
140     public Integer JavaDoc getRepositoryId()
141     {
142         return repositoryId;
143     }
144
145 }
146
Popular Tags