KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > search > handlers > PortletEntryToDocHandler


1 /*
2  * Copyright 2000-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 package org.apache.jetspeed.services.search.handlers;
17
18 // Java APIs
19
import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 // Jetspeed APIs
23
import org.apache.jetspeed.om.registry.PortletEntry;
24 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
25 import org.apache.jetspeed.services.logging.JetspeedLogger;
26 import org.apache.jetspeed.services.search.ParsedObject;
27 import org.apache.jetspeed.om.registry.Category;
28
29 /**
30  * This object handler deals with portlet registry entries
31  *
32  * @author <a HREF="mailto:caius1440@hotmail.com">Jeremy Ford</a>
33  * @version $Id: PortletEntryToDocHandler.java,v 1.5 2004/02/23 03:47:46 jford Exp $
34  */

35 public class PortletEntryToDocHandler extends RegistryEntryToDocHandler
36 {
37     private static final String JavaDoc PARENT = "parent";
38     private static final String JavaDoc TYPE = "type";
39     
40     {
41         fields.add(PARENT);
42         fields.add(TYPE);
43     }
44     
45     /**
46      * Static initialization of the logger for this class
47      */

48     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(PortletEntryToDocHandler.class.getName());
49     
50     /**
51      * Parses portlet entry object
52      *
53      * @param o
54      * @return
55      */

56     public ParsedObject parseObject(Object JavaDoc o)
57     {
58         ParsedObject result = super.parseObject(o);
59         
60         if ((o instanceof PortletEntry) == false)
61         {
62             logger.error("PortletEntryToDocHandler: invalid object type: " + o);
63             return null;
64         }
65
66         PortletEntry portletEntry = (PortletEntry) o;
67         
68         HashMap JavaDoc fields = new HashMap JavaDoc();
69         fields.put(PARENT, portletEntry.getParent());
70         fields.put(TYPE, portletEntry.getType());
71         
72         result.setFields(fields);
73
74         StringBuffer JavaDoc content = new StringBuffer JavaDoc();
75         String JavaDoc title = portletEntry.getTitle();
76         content.append(title == null ? portletEntry.getName() : title);
77         content.append(" ");
78         content.append(portletEntry.getDescription());
79         content.append(" ");
80         Iterator JavaDoc it = portletEntry.listCategories();
81         while (it.hasNext())
82         {
83             Category cat = (Category) it.next();
84             content.append(cat.getName());
85             content.append(" ");
86         }
87
88         result.setContent(content.toString());
89
90         result.setType(ParsedObject.OBJECT_TYPE_PORTLET);
91
92         // TODO: index the url for portlets defining one. A good candidate would be HTML, Webpage
93
// and IFrame portlets.
94

95         return result;
96     }
97 }
98
Popular Tags