01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.cms.search;
23:
24: import org.jboss.portal.cms.CMS;
25: import org.jboss.portal.cms.Command;
26: import org.jboss.portal.cms.model.File;
27: import org.jboss.portal.common.i18n.LocalizedString;
28: import org.jboss.portal.search.Query;
29: import org.jboss.portal.search.QueryConverter;
30: import org.jboss.portal.search.impl.AbstractFederatedSearcher;
31: import org.jboss.portal.search.impl.jcr.JCRQuery;
32: import org.jboss.portal.search.impl.jcr.JCRQueryConverter;
33: import org.jboss.portal.search.result.ResultSet;
34:
35: import java.util.Iterator;
36: import java.util.List;
37:
38: /**
39: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
40: * @version $Revision$
41: */
42: public class CMSFederatedSearch extends AbstractFederatedSearcher {
43: private CMS cms;
44: private String urlPrefix;
45: private JCRQueryConverter queryConverter;
46:
47: public CMSFederatedSearch(String id) {
48: setId(id);
49: setDisplayName(new LocalizedString("Content Management System"));
50: this .urlPrefix = "portal/content";
51: this .queryConverter = new JCRQueryConverter();
52: }
53:
54: public void setCMS(CMS cms) {
55: this .cms = cms;
56: }
57:
58: public ResultSet search(Query query) {
59: Command searchCommand = cms.getCommandFactory()
60: .createSearchCommand((JCRQuery) query);
61: List files = (List) cms.execute(searchCommand);
62: ResultSet results = new ResultSet(this );
63:
64: Iterator it = files.iterator();
65: while (it.hasNext()) {
66: File file = (File) it.next();
67: results.add(new CMSResult(file, urlPrefix));
68: }
69: return results;
70: }
71:
72: public QueryConverter getQueryConverter() {
73: return queryConverter;
74: }
75:
76: }
|