KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > util > Search


1 package info.magnolia.cms.util;
2
3 import info.magnolia.cms.core.Content;
4 import info.magnolia.cms.core.search.Query;
5 import info.magnolia.cms.core.search.QueryManager;
6 import info.magnolia.cms.core.search.QueryResult;
7
8 import java.util.Iterator JavaDoc;
9
10 import javax.jcr.RepositoryException;
11
12 import org.apache.log4j.Logger;
13
14
15 /**
16  * This is a temporary class to search for content object based on mgnl:UUID property it will be replaced later by
17  * HierarchyManager.getContentByUUID(String)
18  * @author Sameer Charles
19  * @version $Revision $ ($Author $)
20  */

21 public final class Search {
22
23     /**
24      * Logger
25      */

26     private static Logger log = Logger.getLogger(Search.class);
27
28     /**
29      * don't instantiate.
30      */

31     private Search() {
32         // unused
33
}
34
35     /**
36      * Using JCR search to get content object associated with the given UUID
37      * @param queryManager
38      * @param uuid
39      */

40     public static Content getContentByUUID(QueryManager queryManager, String JavaDoc uuid) {
41         try {
42             String JavaDoc statement = "SELECT * FROM nt:base where mgnl:uuid like '" + uuid + "'"; //$NON-NLS-1$ //$NON-NLS-2$
43
Query q = queryManager.createQuery(statement, Query.SQL);
44             QueryResult result = q.execute();
45             Iterator JavaDoc it = result.getContent().iterator();
46             while (it.hasNext()) {
47                 Content foundObject = (Content) it.next();
48                 return foundObject;
49             }
50         }
51         catch (RepositoryException e) {
52             log.error(e);
53         }
54         return null;
55     }
56
57 }
58
Popular Tags