1 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 ; 21 22 import javax.jcr.RepositoryException; 23 import javax.jcr.query.InvalidQueryException; 24 25 import org.apache.log4j.Logger; 26 27 28 31 public class RepositorySearchListModel extends AbstractSearchableListModel { 32 33 36 private static Logger log = Logger.getLogger(RepositorySearchListModel.class); 37 38 41 private String repositoryId; 42 43 46 private String workspaceId; 47 48 51 private String nodeType = "nt:base"; 52 53 private String resultNodeType = "mgnl:content"; 54 55 58 private String searchPath; 59 60 63 protected SearchQuery query; 64 65 68 public RepositorySearchListModel(String repositoryId) { 69 this.repositoryId = repositoryId; 70 } 71 72 75 protected String buildQuery() { 76 QueryBuilder builder = new QueryBuilder(this); 77 return builder.getSQLStatement(); 78 } 79 80 83 protected QueryResult getResult(String 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 92 protected Collection getResult() throws Exception { 93 String query = buildQuery(); 94 if(log.isDebugEnabled()){ 95 log.debug("query: " + query); 96 } 97 QueryResult result = this.getResult(query); 98 Collection items = getResult(result); 99 return items; 100 } 101 102 105 protected Collection getResult(QueryResult result) { 106 Collection items = result.getContent(this.getResultNodeType()); 107 return items; 108 } 109 110 114 public String getRepositoryId() { 115 return repositoryId; 116 } 117 118 122 public void setRepositoryId(String repositoryId) { 123 this.repositoryId = repositoryId; 124 } 125 126 130 public String getWorkspaceId() { 131 return workspaceId; 132 } 133 134 138 public void setWorkspaceId(String workspaceId) { 139 this.workspaceId = workspaceId; 140 } 141 142 146 public String getNodeType() { 147 return nodeType; 148 } 149 150 154 public void setNodeType(String selectNodeType) { 155 this.nodeType = selectNodeType; 156 } 157 158 162 public String getSearchPath() { 163 return searchPath; 164 } 165 166 170 public void setSearchPath(String searchPath) { 171 this.searchPath = searchPath; 172 } 173 174 178 public void setQuery(SearchQuery query) { 179 this.query = query; 180 } 181 182 186 public SearchQuery getQuery() { 187 return this.query; 188 } 189 190 public void setResultNodeType(String resultNodeType) { 191 this.resultNodeType = resultNodeType; 192 } 193 194 public String getResultNodeType() { 195 return resultNodeType; 196 } 197 198 } 199 | Popular Tags |