KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > controlx > search > RepositorySearchListModel


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.controlx.search;
14
15 import info.magnolia.cms.core.search.Query;
16 import info.magnolia.cms.core.search.QueryResult;
17 import info.magnolia.cms.gui.query.SearchQuery;
18 import info.magnolia.context.MgnlContext;
19
20 import java.util.Collection JavaDoc;
21
22 import javax.jcr.RepositoryException;
23 import javax.jcr.query.InvalidQueryException;
24
25 import org.apache.log4j.Logger;
26
27
28 /**
29  * @author Sameer Charles $Id:RepositorySearchListModel.java 2544 2006-04-04 12:47:32Z philipp $
30  */

31 public class RepositorySearchListModel extends AbstractSearchableListModel {
32
33     /**
34      * Logger
35      */

36     private static Logger log = Logger.getLogger(RepositorySearchListModel.class);
37
38     /**
39      * repository id
40      */

41     private String JavaDoc repositoryId;
42
43     /**
44      * workspace Id, if no workspace is defined - default is used which has the same name as repository name
45      */

46     private String JavaDoc workspaceId;
47
48     /**
49      * select from node type (optional)
50      */

51     private String JavaDoc nodeType = "nt:base";
52
53     private String JavaDoc resultNodeType = "mgnl:content";
54     
55     /**
56      * search path (optional)
57      */

58     private String JavaDoc searchPath;
59
60     /**
61      * search query to be used by sub implementation
62      */

63     protected SearchQuery query;
64
65     /**
66      * default constructor
67      */

68     public RepositorySearchListModel(String JavaDoc repositoryId) {
69         this.repositoryId = repositoryId;
70     }
71
72     /**
73      * Returns the jcr query statement used by the model.
74      */

75     protected String JavaDoc buildQuery() {
76         QueryBuilder builder = new QueryBuilder(this);
77         return builder.getSQLStatement();
78     }
79
80     /**
81      * Executes the query statement and returns the QueryResult.
82      */

83     protected QueryResult getResult(String JavaDoc statement) throws InvalidQueryException, RepositoryException {
84         Query q = MgnlContext.getQueryManager(this.repositoryId).createQuery(statement, Query.SQL);
85         QueryResult result = q.execute();
86         return result;
87     }
88
89     /**
90      * Creates the jcr query and executes it.
91      */

92     protected Collection JavaDoc getResult() throws Exception JavaDoc {
93         String JavaDoc query = buildQuery();
94         if(log.isDebugEnabled()){
95             log.debug("query: " + query);
96         }
97         QueryResult result = this.getResult(query);
98         Collection JavaDoc items = getResult(result);
99         return items;
100     }
101
102     /**
103      * Gets the items from the query (possibility to post filter)
104      */

105     protected Collection JavaDoc getResult(QueryResult result) {
106         Collection JavaDoc items = result.getContent(this.getResultNodeType());
107         return items;
108     }
109
110     /**
111      * get repository Id
112      * @return repository id
113      */

114     public String JavaDoc getRepositoryId() {
115         return repositoryId;
116     }
117
118     /**
119      * set repository id
120      * @param repositoryId
121      */

122     public void setRepositoryId(String JavaDoc repositoryId) {
123         this.repositoryId = repositoryId;
124     }
125
126     /**
127      * get workspace Id
128      * @return workspace id
129      */

130     public String JavaDoc getWorkspaceId() {
131         return workspaceId;
132     }
133
134     /**
135      * set workspace Id
136      * @param workspaceId
137      */

138     public void setWorkspaceId(String JavaDoc workspaceId) {
139         this.workspaceId = workspaceId;
140     }
141
142     /**
143      * get select node type, query will be executed only on these if set
144      * @return nodeType name
145      */

146     public String JavaDoc getNodeType() {
147         return nodeType;
148     }
149
150     /**
151      * set select node type value, query will be executed only on these if set
152      * @param nodeType
153      */

154     public void setNodeType(String JavaDoc selectNodeType) {
155         this.nodeType = selectNodeType;
156     }
157
158     /**
159      * get jcr path, under which search will be executed
160      * @return path
161      */

162     public String JavaDoc getSearchPath() {
163         return searchPath;
164     }
165
166     /**
167      * set jcr path, under which search will be executed
168      * @param searchPath
169      */

170     public void setSearchPath(String JavaDoc searchPath) {
171         this.searchPath = searchPath;
172     }
173
174     /**
175      * set Query
176      * @param query
177      */

178     public void setQuery(SearchQuery query) {
179         this.query = query;
180     }
181
182     /**
183      * get query
184      * @return query
185      */

186     public SearchQuery getQuery() {
187         return this.query;
188     }
189
190     public void setResultNodeType(String JavaDoc resultNodeType) {
191         this.resultNodeType = resultNodeType;
192     }
193
194     public String JavaDoc getResultNodeType() {
195         return resultNodeType;
196     }
197
198 }
199
Popular Tags