Author: sascharodekamp
Date: Tue Nov 15 12:32:45 2011 New Revision: 1202158 URL: http://svn.apache.org/viewvc?rev=1202158&view=rev Log: UPDATE: It is now possible to search the content repository by using SQL2 / JQOM query language Modified: ofbiz/branches/jackrabbit20100709/.classpath ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java Modified: ofbiz/branches/jackrabbit20100709/.classpath URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/.classpath?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/.classpath (original) +++ ofbiz/branches/jackrabbit20100709/.classpath Tue Nov 15 12:32:45 2011 @@ -141,17 +141,16 @@ <classpathentry kind="lib" path="framework/guiapp/lib/XuiCoreSwing-v3.2rc2b.jar"/> <classpathentry kind="lib" path="framework/guiapp/lib/XuiOptional-v3.2rc2b.jar"/> <classpathentry kind="lib" path="framework/jcr/lib/concurrent-1.3.4.jar"/> - <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-api-2.2.8.jar"/> - <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-core-2.2.8.jar"/> - <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-jca-2.2.8.jar"/> - <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-jcr-commons-2.2.8.jar"/> - <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-2.2.8.jar"/> - <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-commons-2.2.8.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-api-2.3.2.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-core-2.3.2.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-jca-2.3.2.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-jcr-commons-2.3.2.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-2.3.2.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-commons-2.3.2.jar"/> <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-ocm-2.0.jar" sourcepath="/ocm"/> <classpathentry kind="lib" path="framework/jcr/lib/jcr-2.0.jar"/> - <classpathentry kind="lib" path="framework/jcr/lib/pdfbox-1.3.1.jar"/> - <classpathentry kind="lib" path="framework/jcr/lib/slf4j-api-1.5.11.jar"/> - <classpathentry kind="lib" path="framework/jcr/lib/slf4j-log4j12-1.5.11.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/pdfbox-1.6.0.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/slf4j-api-1.6.1.jar"/> <classpathentry kind="lib" path="framework/jetty/lib/jasper-compiler-5.5.15.jar"/> <classpathentry kind="lib" path="framework/jetty/lib/jasper-runtime-5.5.15.jar"/> <classpathentry kind="lib" path="framework/jetty/lib/jetty-6.1.11.jar"/> Modified: ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml Tue Nov 15 12:32:45 2011 @@ -865,5 +865,9 @@ <value xml:lang="de">Content Schnellauswahl - Content Node auswählen und Sprache bestimmen.</value> <value xml:lang="en">Content quick select - Choose your content node and select a language.</value> </property> + <property key="ExampleJackrabbitQueryForContent"> + <value xml:lang="de">Das Repository kann mit Hilfe der SQL2 oder JQOM Query Language durchsucht werden: z.B. SELECT * FROM [nt:unstructured] gibt alle nodes vom Typ nt:unstructured zurück.</value> + <value xml:lang="en">You can search the repository by using SQL2 or JQOM query syntax: i.e. SELECT * FROM [nt:unstructured] gives all nodes with the typ nt:unstructured.</value> + </property> </resource> Modified: ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java Tue Nov 15 12:32:45 2011 @@ -317,19 +317,19 @@ public class JackrabbitEvents { } try { - for (String path : contentList) { - Node parent = session.getNode(path); - NodeIterator ni = parent.getNodes(); - List<String> language = new ArrayList<String>(); - while (ni.hasNext()) { - Node t = ni.nextNode(); + for (String path : contentList) { + Node parent = session.getNode(path); + NodeIterator ni = parent.getNodes(); + List<String> language = new ArrayList<String>(); + while (ni.hasNext()) { + Node t = ni.nextNode(); if (t.hasProperty("localized") && t.getProperty("localized").getBoolean()) { String l = t.getPath(); language.add(l.substring(l.lastIndexOf("/") + 1)); } + } + languageList.put(path, language); } - languageList.put(path, language); - } } catch (ValueFormatException e) { Debug.logError(e, module); } catch (PathNotFoundException e) { @@ -408,6 +408,24 @@ public class JackrabbitEvents { return "success"; } + public static String queryRepositoryData(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + + String searchQuery = request.getParameter("queryData"); + + JcrContentHelper helper = new JcrContentHelper(userLogin); + + try { + request.setAttribute("queryResult", helper.queryData(searchQuery)); + } catch (RepositoryException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); + return "error"; + } + + return "success"; + } + private static void getContentList(Node startNode, List<String> contentList) throws RepositoryException { NodeIterator ni = startNode.getNodes(); while (ni.hasNext()) { Modified: ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml Tue Nov 15 12:32:45 2011 @@ -318,6 +318,12 @@ under the License. <response name="success" type="view" value="ExampleJackrabbitOpenFileInformation"/> <response name="error" type="view" value="ExampleJackrabbitShowUploadedFiles"/> </request-map> + <request-map uri="QueryRepositoryData"> + <security auth="true" https="true" /> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="queryRepositoryData"/> + <response name="success" type="view" value="ExampleJackrabbitShowQueryResult"/> + <response name="error" type="request" value="ExampleJackrabbitShowContentData"/> + </request-map> <!-- View Mappings --> <view-map name="main" type="screen" page="component://example/widget/example/CommonScreens.xml#main"/> @@ -372,6 +378,7 @@ under the License. <view-map name="ExampleJackrabbitShowUploadedFiles" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ExampleJackrabbitShowUploadedFiles" type="screen" /> <view-map name="ExampleJackrabbitShowContentData" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ExampleJackrabbitShowContentData" type="screen" /> <view-map name="ExampleJackrabbitOpenFileInformation" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ExampleJackrabbitShowFileInformation" type="screen" /> + <view-map name="ExampleJackrabbitShowQueryResult" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ExampleJackrabbitShowQueryResult" type="screen" /> <!-- Supported Content Types --> Modified: ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml Tue Nov 15 12:32:45 2011 @@ -48,7 +48,7 @@ under the License. <field name="contentDropDown" position="1"> <drop-down ><list-options key-name="contentList" description="${contentList}" list-name="parameters.contentList" list-entry-name="contentList"/></drop-down> </field> - + <!-- <field name="languageDropDown" position="2" title=""> <drop-down><list-options key-name="languageList" list-name="parameters.languageList"/></drop-down> @@ -154,4 +154,14 @@ under the License. <display /> </field> </form> + + <form name="QueryRepositoryDataForm" type="single" target="QueryRepositoryData"> + <field name="queryData" ><text /></field> + <field name="submit"><submit/></field> + </form> + + <form name="ExampleJackrabbitShowQueryResults" type="list" target="EditRepositoryContent" list-name="queryResult" separate-columns="true" odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar"> + <field name="path" title="${uiLabelMap.ExampleRepositoryNode}" ><hyperlink target="EditRepositoryContent" description="${path}"><parameter param-name="path"/></hyperlink></field> + <field name="score" ><display /></field> + </form> </forms> \ No newline at end of file Modified: ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml Tue Nov 15 12:32:45 2011 @@ -57,6 +57,10 @@ under the License. </platform-specific> </container> <container> + <label>${uiLabelMap.ExampleJackrabbitQueryForContent}</label> + <include-form location="component://example/widget/example/ExampleJackrabbitForms.xml" name="QueryRepositoryDataForm" /> + </container> + <container> <label>${uiLabelMap.ExampleJackrabbitTryRightClick}</label> <platform-specific> <html><html-template location="component://example/webapp/example/jackrabbit/JackrabbitDataTree.ftl"/></html> @@ -187,4 +191,23 @@ under the License. </section> </screen> + <screen name="ExampleJackrabbitShowQueryResult"> + <section> + <actions> + <set field="titleProperty" value="PageTitleExampleJackrabbit" /> + <set field="tabButtonItem" value="ExampleJackrabbitShowContentData" /> + <set field="queryResult" from-field="parameters.queryResult"/> + </actions> + <widgets> + <decorator-screen name="CommonExampleJackrabbitDecorator" location="${parameters.mainDecoratorLocation}"> + <decorator-section name="body"> + <container> + <include-form location="component://example/widget/example/ExampleJackrabbitForms.xml" name="ExampleJackrabbitShowQueryResults" /> + </container> + </decorator-section> + </decorator-screen> + </widgets> + </section> + </screen> + </screens> \ No newline at end of file Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java Tue Nov 15 12:32:45 2011 @@ -1,6 +1,7 @@ package org.ofbiz.jcr.access; import javax.jcr.RepositoryException; +import javax.jcr.query.QueryResult; import net.sf.json.JSONArray; @@ -45,4 +46,14 @@ public interface ContentReader { * @throws RepositoryException */ JSONArray getJsonFileTree() throws RepositoryException; + + /** + * Query for Data in the JCR Repository using the SQL2 or JQOM Query + * language. Returns the Query Result. + * + * @param query + * either a SQL2 or JQOM statement. + * @return + */ + QueryResult queryRepositoryData(String query) throws RepositoryException; } Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java Tue Nov 15 12:32:45 2011 @@ -4,6 +4,7 @@ import java.util.List; import javax.jcr.ItemExistsException; import javax.jcr.RepositoryException; +import javax.jcr.query.QueryResult; import net.sf.json.JSONArray; @@ -110,4 +111,14 @@ public interface RepositoryAccess { * @return */ public String getRootVersion(String nodePath); + + /** + * Query for Data in the JCR Repository using the SQL2 or JQOM Query + * language. Returns the Query result. + * + * @param query + * either a SQL2 or JQOM statement. + * @return + */ + public QueryResult queryForRepositoryData(String query) throws RepositoryException; } Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java Tue Nov 15 12:32:45 2011 @@ -3,6 +3,9 @@ package org.ofbiz.jcr.access.jackrabbit; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; +import javax.jcr.query.Query; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; import javax.jcr.version.VersionException; import net.sf.json.JSONArray; @@ -83,6 +86,17 @@ public class ContentReaderJackrabbit imp return getJsonFileChildNodes(ocm.getSession().getRootNode()); } + /* + * (non-Javadoc) + * + * @see + * org.ofbiz.jcr.access.ContentReader#queryRepositoryData(java.lang.String) + */ + @Override + public QueryResult queryRepositoryData(String query) throws RepositoryException { + return executeQuery(query); + } + /** * Returns a JSON Array with the repository folder structure. The JSON array * is directly build for the jsTree jQuery plugin. @@ -167,4 +181,25 @@ public class ContentReaderJackrabbit imp return folderStrucutre; } + + /** + * Executes the query specified by <code>statement</code> and returns the + * query result. + * + * @param statement + * either a SQL2 or JQOM statement. + * @return the query result. + * @throws RepositoryException + * if an error occurs. + */ + protected QueryResult executeQuery(String statement) throws RepositoryException { + // TODO create a query manager which uses the OCM Layer. + QueryManager qm = ocm.getSession().getWorkspace().getQueryManager(); + + if (statement.trim().toLowerCase().startsWith("select")) { + return qm.createQuery(statement, Query.JCR_SQL2).execute(); + } else { + return qm.createQuery(statement, Query.JCR_JQOM).execute(); + } + } } Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java Tue Nov 15 12:32:45 2011 @@ -5,6 +5,7 @@ import java.util.List; import javax.jcr.ItemExistsException; import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.query.QueryResult; import net.sf.json.JSONArray; @@ -213,4 +214,14 @@ public class RepositoryAccessJackrabbit ContentReader contentReader = new ContentReaderJackrabbit(this.ocm); return contentReader.getJsonFileTree(); } + + /* + * (non-Javadoc) + * @see org.ofbiz.jcr.access.RepositoryAccess#queryForRepositoryData(java.lang.String) + */ + @Override + public QueryResult queryForRepositoryData(String query) throws RepositoryException{ + ContentReader contentReader = new ContentReaderJackrabbit(this.ocm); + return contentReader.queryRepositoryData(query); + } } Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java?rev=1202158&r1=1202157&r2=1202158&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java Tue Nov 15 12:32:45 2011 @@ -1,5 +1,17 @@ package org.ofbiz.jcr.api; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.jcr.RepositoryException; +import javax.jcr.query.QueryResult; +import javax.jcr.query.Row; +import javax.jcr.query.RowIterator; + +import javolution.util.FastMap; + +import org.ofbiz.base.util.Debug; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; @@ -15,14 +27,37 @@ import org.ofbiz.jcr.access.jackrabbit.R * in the Framework. * */ -public class JcrContentHelper extends AbstractJcrHelper{ +public class JcrContentHelper extends AbstractJcrHelper { + + private static String module = JcrContentHelper.class.getName(); /** * Create a default content helper object. * * @param userLogin */ - public JcrContentHelper (GenericValue userLogin) { + public JcrContentHelper(GenericValue userLogin) { access = new RepositoryAccessJackrabbit(userLogin); } + + public List<Map<String, String>> queryData(String query) throws RepositoryException { + QueryResult qr = access.queryForRepositoryData(query); + + List<Map<String, String>> resultNodePaths = new ArrayList<Map<String, String>>(); + RowIterator rows = qr.getRows(); + while (rows.hasNext()) { + Row row = rows.nextRow(); + Map<String, String> content = FastMap.newInstance(); + content.put("path", row.getPath()); + content.put("score", String.valueOf(row.getScore())); + + resultNodePaths.add(content); + if (Debug.isOn(Debug.INFO)) { + Debug.logInfo("For query: " + query + " found node with path: " + row.getPath(), module); + } + + } + + return resultNodePaths; + } } |
Free forum by Nabble | Edit this page |