View Javadoc

1   /*
2    * Copyright 2000-2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.jetspeed.modules.actions.portlets;
18  
19  // Java APIs
20  import java.util.Iterator;
21  import java.util.Collection;
22  import java.util.ArrayList;
23  
24  // Turbine Modules
25  import org.apache.turbine.util.RunData;
26  import org.apache.jetspeed.services.search.Search;
27  
28  // Jetspeed Stuff
29  import org.apache.jetspeed.om.registry.PortletEntry;
30  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
31  import org.apache.jetspeed.services.logging.JetspeedLogger;
32  import org.apache.jetspeed.services.Registry;
33  import org.apache.jetspeed.portal.Portlet;
34  
35  
36  /***
37   * This class is responsible for indexing the registry.
38   * 
39   * @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>
40   * @version $Id: IndexPortletRegistry.java,v 1.6 2004/03/31 04:49:10 morciuch Exp $
41   */
42  public class IndexPortletRegistry extends SecureGenericMVCAction
43  {
44  
45      /***
46       * Static initialization of the logger for this class
47       */    
48      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(IndexPortletRegistry.class.getName());     
49      
50      /***
51       * Build the normal state content for this portlet.
52       *
53       * @param portlet The jsp-based portlet that is being built.
54       * @param rundata The turbine rundata context for this request.
55       */
56      protected void buildNormalContext(Portlet portlet, RunData rundata)
57      {
58          // Do nothing
59      }
60  
61      /***
62       * Continue event handler.
63       *
64       * @param portlet The jsp-based portlet that is being built.
65       * @param rundata The turbine rundata context for this request.
66       */
67      public void doIndex(RunData rundata, Portlet portlet)
68      {
69          if (portlet == null)
70          {
71              return;
72          }
73  
74          Collection c = new ArrayList();
75  
76          for (Iterator i = Registry.get(Registry.PORTLET).listEntryNames(); i.hasNext();)
77          {
78              PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, (String) i.next());
79              if (!entry.getType().equals(PortletEntry.TYPE_ABSTRACT) && !entry.isHidden())
80              {
81                  c.add(entry);
82                  //System.out.println("Will index [" + entry.getTitle() + "]");
83              }
84          }
85  
86          try
87          {
88              // Delete all entries from index
89              Search.remove(c);
90          }
91          catch (Throwable e)
92          {
93              logger.error("Throwable", e);
94          }
95  
96          try
97          {
98              // Add all entries to index
99              Search.add(c);
100         }
101         catch (Throwable e)
102         {
103             logger.error("Throwable", e);
104         }
105     }
106 
107 }