Author: dpfister Date: Mon Jan 26 13:30:03 2009 New Revision: 737690 URL: http://svn.apache.org/viewvc?rev=737690&view=rev Log: JCRCMIS - add a query page and implementation in the server Added: jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.html jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.jsp Modified: jackrabbit/sandbox/jcr-cmis/api/src/main/java/org/apache/jackrabbit/cmis/Repository.java jackrabbit/sandbox/jcr-cmis/cmis2jcr/src/main/java/org/apache/jackrabbit/cmis/jcr/JCRRepository.java jackrabbit/sandbox/jcr-cmis/server/atompub/src/test/java/org/apache/jackrabbit/cmis/SimpleRepository.java Modified: jackrabbit/sandbox/jcr-cmis/api/src/main/java/org/apache/jackrabbit/cmis/Repository.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcr-cmis/api/src/main/java/org/apache/jackrabbit/cmis/Repository.java?rev=737690&r1=737689&r2=737690&view=diff ============================================================================== --- jackrabbit/sandbox/jcr-cmis/api/src/main/java/org/apache/jackrabbit/cmis/Repository.java (original) +++ jackrabbit/sandbox/jcr-cmis/api/src/main/java/org/apache/jackrabbit/cmis/Repository.java Mon Jan 26 13:30:03 2009 @@ -100,4 +100,12 @@ * @return entry */ public Entry getEntry(String id); + + /** + * Query elements, given a query string. + * + * @param query query string + * @return list of items + */ + public Iterable query(String query); } Added: jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.html URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.html?rev=737690&view=auto ============================================================================== --- jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.html (added) +++ jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.html Mon Jan 26 13:30:03 2009 @@ -0,0 +1,26 @@ + + +CMIS v0.5+ implementation: query + + + + + + +
+

Discovery Services: query

+
+ + + + +
Query
  +
+
+

+ +

+ +
+ + \ No newline at end of file Added: jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.jsp URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.jsp?rev=737690&view=auto ============================================================================== --- jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.jsp (added) +++ jackrabbit/sandbox/jcr-cmis/client/src/main/webapp/query.jsp Mon Jan 26 13:30:03 2009 @@ -0,0 +1,63 @@ +<%@ page session="false" %><% +%><%@ page import="org.apache.jackrabbit.cmis.*, + org.apache.jackrabbit.cmis.client.JCRRepositoryLocator, + java.util.Iterator" %><% + + response.setContentType("application/atom+xml;type=feed"); + response.setCharacterEncoding("UTF-8"); + + String contextPath = request.getContextPath(); + String query = (String) request.getParameter("query"); + + Repository repository = JCRRepositoryLocator.getRepository(application); + String authorName = "admin"; + +%> + + <%= authorName %> + + + + Query result for <%= query %><% + + for (Entry child : repository.query(query)) { + + %> + <% + String childId = child.getId(); + String childUrl = contextPath + "/" + childId; + %> + <%= authorName %> + <%= childId %> + urn:uuid:<%= childId %> + + + + + + + + + + <%= child.getLastModificationDate().getTime() %> + Summary for <%= child.getName() %> + Title for <%= child.getName() %> + <%= child.getLastModifiedBy() %> + + + <%= child.getObjectId() %> + <%= child.getObjectTypeId() %> + <%= child.getCreatedBy() %> + <%= child.getCreationDate().getTime() %> + <%= child.getLastModifiedBy() %> + <%= child.getLastModificationDate().getTime() %> + <%= child.getName() %> + <%= child.getParentId() %> + + + + <%= child.getLastModifiedBy() %> + + + <% } %> + Modified: jackrabbit/sandbox/jcr-cmis/cmis2jcr/src/main/java/org/apache/jackrabbit/cmis/jcr/JCRRepository.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcr-cmis/cmis2jcr/src/main/java/org/apache/jackrabbit/cmis/jcr/JCRRepository.java?rev=737690&r1=737689&r2=737690&view=diff ============================================================================== --- jackrabbit/sandbox/jcr-cmis/cmis2jcr/src/main/java/org/apache/jackrabbit/cmis/jcr/JCRRepository.java (original) +++ jackrabbit/sandbox/jcr-cmis/cmis2jcr/src/main/java/org/apache/jackrabbit/cmis/jcr/JCRRepository.java Mon Jan 26 13:30:03 2009 @@ -17,7 +17,11 @@ package org.apache.jackrabbit.cmis.jcr; import java.net.URI; +import java.util.Iterator; +import javax.jcr.query.Query; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; import javax.jcr.RepositoryException; import org.slf4j.Logger; @@ -83,8 +87,11 @@ } public Entry getEntry(String id) { + javax.jcr.Session session = null; + try { - javax.jcr.Node node = repository.login(workspace).getRootNode(); + session = repository.login(workspace); + javax.jcr.Node node = session.getRootNode(); if (!id.equals("")) { node = node.getNode(id); } @@ -92,6 +99,47 @@ } catch (RepositoryException e) { log.warn("Unable to retrieve node " + id, e); return null; + } finally { + /* + if (session != null) { + session.logout(); + } + */ + } + } + + public Iterable query(String s) { + javax.jcr.Session session = null; + + if (!s.startsWith("select ") && !s.startsWith("SELECT ")) { + s = "SELECT * FROM nt:base WHERE contains(*, '" + s + "')"; + } + + try { + session = repository.login(workspace); + QueryManager qm = session.getWorkspace().getQueryManager(); + Query query = qm.createQuery(s, Query.SQL); + final QueryResult result = query.execute(); + + return new Iterable() { + public Iterator iterator() { + try { + return new JCREntryIterator(result.getNodes()); + } catch (RepositoryException e) { + log.warn("Unable to retrieve result nodes", e); + return null; + } + } + }; + } catch (RepositoryException e) { + log.warn("Unable to execute query: " + s, e); + return null; + } finally { + /* + if (session != null) { + session.logout(); + } + */ } } Modified: jackrabbit/sandbox/jcr-cmis/server/atompub/src/test/java/org/apache/jackrabbit/cmis/SimpleRepository.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcr-cmis/server/atompub/src/test/java/org/apache/jackrabbit/cmis/SimpleRepository.java?rev=737690&r1=737689&r2=737690&view=diff ============================================================================== --- jackrabbit/sandbox/jcr-cmis/server/atompub/src/test/java/org/apache/jackrabbit/cmis/SimpleRepository.java (original) +++ jackrabbit/sandbox/jcr-cmis/server/atompub/src/test/java/org/apache/jackrabbit/cmis/SimpleRepository.java Mon Jan 26 13:30:03 2009 @@ -151,7 +151,12 @@ } public Entry getEntry(String id) { - // TODO implement + // TODO Auto-generated method stub return null; } + + public Iterable query(String query) { + // TODO Auto-generated method stub + return null; + } }