KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > treeservice > SiteNodeService


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.treeservice;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import javax.servlet.ServletConfig JavaDoc;
31 import javax.servlet.ServletException JavaDoc;
32
33 import org.apache.log4j.Logger;
34 import org.infoglue.cms.controllers.usecases.structuretool.ViewSiteNodeTreeUCC;
35 import org.infoglue.cms.controllers.usecases.structuretool.ViewSiteNodeTreeUCCFactory;
36 import org.infoglue.cms.entities.structure.SiteNodeVO;
37 import org.infoglue.cms.net.CommunicationEnvelope;
38 import org.infoglue.cms.net.Node;
39 import org.infoglue.cms.security.InfoGlueAuthenticationFilter;
40 import org.infoglue.cms.security.InfoGluePrincipal;
41
42
43 public class SiteNodeService extends JServiceBuilder
44 {
45     private final static Logger logger = Logger.getLogger(SiteNodeService.class.getName());
46
47     public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc
48     {
49         super.init(config);
50     }
51     
52
53     public CommunicationEnvelope execute(CommunicationEnvelope envelope)
54     {
55         CommunicationEnvelope responseEnvelope = new CommunicationEnvelope();
56         
57         try
58         {
59             String JavaDoc action = envelope.getAction();
60             logger.info("ACTION:" + action);
61             
62             if(action.equals("selectRootNode"))
63             {
64                 responseEnvelope = getRootSiteNode(envelope);
65             }
66             if(action.equals("selectNode"))
67             {
68                 responseEnvelope = getSiteNode(envelope);
69             }
70             else if(action.equals("selectChildNodes"))
71             {
72                 responseEnvelope = getChildSiteNodes(envelope);
73             }
74             /*
75             else if(action.equals("createSiteNode"))
76             {
77                 responseEnvelope = createSiteNode(envelope);
78             }
79             else if(action.equals("updateSiteNode"))
80             {
81                 responseEnvelope = updateSiteNode(envelope);
82             }
83             else if(action.equals("deleteSiteNode"))
84             {
85                 responseEnvelope = deleteSiteNode(envelope);
86             }
87             */

88             logger.info("Executing in SiteNodeService...");
89         }
90         catch (Exception JavaDoc e)
91         {
92             responseEnvelope.setStatus("1");
93             e.printStackTrace();
94         }
95         return responseEnvelope;
96     }
97
98     /**
99      * This method fetches the root SiteNode of this site
100      */

101     public CommunicationEnvelope getRootSiteNode(CommunicationEnvelope envelope)
102     {
103         CommunicationEnvelope responseEnvelope = new CommunicationEnvelope();
104         
105         try
106         {
107             List JavaDoc arguments = (List JavaDoc)envelope.getNodes();
108             Integer JavaDoc repositoryId = ((Node)arguments.get(0)).getId();
109             logger.info("repositoryId:" + repositoryId);
110             ViewSiteNodeTreeUCC viewSiteNodeTreeUCC = ViewSiteNodeTreeUCCFactory.newViewSiteNodeTreeUCC();
111             SiteNodeVO siteNodeVO = viewSiteNodeTreeUCC.getRootSiteNode(repositoryId, getInfoGluePrincipal());
112             logger.info("siteNodeVO:" + siteNodeVO.getSiteNodeId() + " " + siteNodeVO.getName());
113             Node node = new Node();
114             node.setId(siteNodeVO.getSiteNodeId());
115             node.setName(siteNodeVO.getName());
116             node.setIsBranch(siteNodeVO.getIsBranch());
117             
118             List JavaDoc nodes = new ArrayList JavaDoc();
119             nodes.add(node);
120             responseEnvelope.setNodes(nodes);
121         }
122         catch (Exception JavaDoc e)
123         {
124             responseEnvelope.setStatus("1");
125             e.printStackTrace();
126         }
127         return responseEnvelope;
128     }
129
130     /**
131      * This method fetches the SiteNode with the given id
132      */

133     public CommunicationEnvelope getSiteNode(CommunicationEnvelope envelope)
134     {
135         CommunicationEnvelope responseEnvelope = new CommunicationEnvelope();
136         
137         try
138         {
139             List JavaDoc arguments = (List JavaDoc)envelope.getNodes();
140             Integer JavaDoc siteNodeId = ((Node)arguments.get(0)).getId();
141             logger.info("siteNodeId:" + siteNodeId);
142             ViewSiteNodeTreeUCC viewSiteNodeTreeUCC = ViewSiteNodeTreeUCCFactory.newViewSiteNodeTreeUCC();
143             SiteNodeVO siteNodeVO = viewSiteNodeTreeUCC.getSiteNode(siteNodeId);
144             logger.info("siteNodeVO:" + siteNodeVO.getSiteNodeId() + " " + siteNodeVO.getName());
145             Node node = new Node();
146             node.setId(siteNodeVO.getSiteNodeId());
147             node.setName(siteNodeVO.getName());
148             node.setIsBranch(siteNodeVO.getIsBranch());
149             
150             List JavaDoc nodes = new ArrayList JavaDoc();
151             nodes.add(node);
152             responseEnvelope.setNodes(nodes);
153         }
154         catch (Exception JavaDoc e)
155         {
156             responseEnvelope.setStatus("1");
157             e.printStackTrace();
158         }
159         return responseEnvelope;
160     }
161
162
163     /**
164      * This method fetches the root SiteNode of this site
165      */

166     public CommunicationEnvelope getChildSiteNodes(CommunicationEnvelope envelope)
167     {
168         CommunicationEnvelope responseEnvelope = new CommunicationEnvelope();
169         
170         try
171         {
172             List JavaDoc arguments = (List JavaDoc)envelope.getNodes();
173             Integer JavaDoc siteNodeId = ((Node)arguments.get(0)).getId();
174             logger.info("siteNodeId:" + siteNodeId);
175             
176             ViewSiteNodeTreeUCC viewSiteNodeTreeUCC = ViewSiteNodeTreeUCCFactory.newViewSiteNodeTreeUCC();
177             List JavaDoc childSiteNodes = viewSiteNodeTreeUCC.getSiteNodeChildren(siteNodeId);
178             
179             List JavaDoc nodes = new ArrayList JavaDoc();
180             Iterator JavaDoc childIterator = childSiteNodes.iterator();
181             
182             while(childIterator.hasNext())
183             {
184                 SiteNodeVO siteNodeVO = (SiteNodeVO)childIterator.next();
185                 Node node = new Node();
186                 node.setId(siteNodeVO.getSiteNodeId());
187                 node.setName(siteNodeVO.getName());
188                 node.setIsBranch(siteNodeVO.getIsBranch());
189                 nodes.add(node);
190             }
191              
192             responseEnvelope.setNodes(nodes);
193         }
194         catch (Exception JavaDoc e)
195         {
196             responseEnvelope.setStatus("1");
197             e.printStackTrace();
198         }
199         return responseEnvelope;
200     }
201
202
203     /**
204       * This method returns a logged in principal if existing.
205       */

206
207      public InfoGluePrincipal getInfoGluePrincipal()
208      {
209          return (InfoGluePrincipal)this.request.getSession().getAttribute(InfoGlueAuthenticationFilter.INFOGLUE_FILTER_USER);
210      }
211
212 }
Popular Tags