Revision: 18471
Author: wko
Date: 2009-06-10 16:35:57 +0200 (Wed, 10 Jun 2009)
Log Message:
-----------
HSTTWO-627: Adding a basic JCR content browser example in Wicket.
Modified Paths:
--------------
ecm/site-toolkit/trunk/pom.xml
ecm/site-toolkit/trunk/testsuite/site/pom.xml
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/WicketContentBrowserApplication.java
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/WicketContentBrowserPage.java
ecm/site-toolkit/trunk/testsuite/site/src/main/resources/org/hippoecm/hst/wicketexamples/WicketContentBrowserPage.html
Added Paths:
-----------
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBean.java
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBeanFactory.java
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/NodeBean.java
Modified: ecm/site-toolkit/trunk/pom.xml
===================================================================
--- ecm/site-toolkit/trunk/pom.xml 2009-06-10 12:18:11 UTC (rev 18470)
+++ ecm/site-toolkit/trunk/pom.xml 2009-06-10 14:35:57 UTC (rev 18471)
@@ -86,8 +86,6 @@
<jackrabbit.version>1.5.0</jackrabbit.version>
<hippoecm.version>2.06.04</hippoecm.version>
-
- <wicket.version>1.4-rc4</wicket.version>
</properties>
@@ -544,20 +542,6 @@
<scope>test</scope>
</dependency>
- <!-- Wicket dependencies -->
-
- <dependency>
- <groupId>org.apache.wicket</groupId>
- <artifactId>wicket</artifactId>
- <version>${wicket.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.wicket</groupId>
- <artifactId>wicket-extensions</artifactId>
- <version>${wicket.version}</version>
- </dependency>
-
<!-- Hippo ECM Depedencies -->
<dependency>
Modified: ecm/site-toolkit/trunk/testsuite/site/pom.xml
===================================================================
--- ecm/site-toolkit/trunk/testsuite/site/pom.xml 2009-06-10 12:18:11 UTC
(rev 18470)
+++ ecm/site-toolkit/trunk/testsuite/site/pom.xml 2009-06-10 14:35:57 UTC
(rev 18471)
@@ -130,10 +130,12 @@
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket</artifactId>
+ <version>1.4-rc4</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
+ <version>1.4-rc4</version>
</dependency>
<dependency>
<groupId>org.onehippo.ecm.hst</groupId>
Added:
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBean.java
===================================================================
---
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBean.java
(rev 0)
+++
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBean.java
2009-06-10 14:35:57 UTC (rev 18471)
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2008 Hippo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hippoecm.hst.wicketexamples;
+
+import java.io.Serializable;
+
+public class ItemBean implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String name;
+ protected String path;
+ protected int depth;
+ protected boolean ismodified;
+ protected boolean isnew;
+ protected boolean isnode;
+
+ public ItemBean(String name, String path, int depth, boolean ismodified,
boolean isnew, boolean isnode) {
+ this.name = name;
+ this.path = path;
+ this.depth = depth;
+ this.ismodified = ismodified;
+ this.isnew = isnew;
+ this.isnode = isnode;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public int getDepth() {
+ return depth;
+ }
+
+ public boolean isModified() {
+ return ismodified;
+ }
+
+ public boolean isNew() {
+ return isnew;
+ }
+
+ public boolean isNode() {
+ return isnode;
+ }
+
+}
Property changes on:
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBean.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added:
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBeanFactory.java
===================================================================
---
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBeanFactory.java
(rev 0)
+++
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBeanFactory.java
2009-06-10 14:35:57 UTC (rev 18471)
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2008 Hippo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hippoecm.hst.wicketexamples;
+
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
+
+public class ItemBeanFactory {
+
+ public static ItemBean createItemBean(Item item) throws Exception {
+ ItemBean itemBean = null;
+
+ if (item.isNode()) {
+ Node node = (Node) item;
+ Map<String, Object[]> properties = getProperties(node);
+
+ itemBean = new NodeBean(node.getName(), node.getPath(),
node.getDepth(), node.isModified(), node.isNew(), node.isNode(),
+ node.getPrimaryNodeType().getName(),
+ (node.isNodeType("mix:referenceable") ? node.getUUID() :
null),
+ properties);
+ } else {
+ itemBean = new ItemBean(item.getName(), item.getPath(),
item.getDepth(), item.isModified(), item.isNew(),
+ item.isNode());
+ }
+
+ return itemBean;
+ }
+
+ public static Map<String, Object[]> getProperties(Node node) throws
Exception {
+ Map<String, Object[]> properties = new HashMap<String, Object[]>();
+
+ for (PropertyIterator it = node.getProperties(); it.hasNext(); ) {
+ Property p = it.nextProperty();
+ String name = p.getName();
+ properties.put(name, getPropertyValues(p, name));
+ }
+
+ return properties;
+ }
+
+ public static Object[] getPropertyValues(Property p, String name) throws
Exception {
+ Object[] propValues = null;
+
+ PropertyDefinition def = p.getDefinition();
+
+ switch (p.getType()) {
+ case PropertyType.BOOLEAN:
+ if (def.isMultiple()) {
+ Value[] values = p.getValues();
+ propValues = new Boolean[values.length];
+
+ for (int i = 0; i < values.length; i++) {
+ propValues[i] = (values[i].getBoolean() ? Boolean.TRUE :
Boolean.FALSE);
+ }
+ } else {
+ propValues = new Boolean[] { p.getBoolean() ? Boolean.TRUE :
Boolean.FALSE };
+ }
+ break;
+ case PropertyType.STRING:
+ if (def.isMultiple()) {
+ Value[] values = p.getValues();
+ propValues = new String[values.length];
+
+ for (int i = 0; i < propValues.length; i++) {
+ propValues[i] = values[i].getString();
+ }
+ } else {
+ propValues = new String[] { p.getString() };
+ }
+ break;
+ case PropertyType.LONG:
+ if (def.isMultiple()) {
+ Value[] values = p.getValues();
+ propValues = new Long[values.length];
+
+ for (int i = 0; i < values.length; i++) {
+ propValues[i] = new Long(values[i].getLong());
+ }
+ } else {
+ propValues = new Long[] { new Long(p.getLong()) };
+ }
+ break;
+ case PropertyType.DOUBLE:
+ if (def.isMultiple()) {
+ Value[] values = p.getValues();
+ propValues = new Double[values.length];
+
+ for (int i = 0; i < values.length; i++) {
+ propValues[i] = new Double(values[i].getDouble());
+ }
+ } else {
+ propValues = new Double[] { new Double(p.getDouble()) };
+ }
+ break;
+ case PropertyType.DATE:
+ if (def.isMultiple()) {
+ Value[] values = p.getValues();
+ propValues = new Calendar[values.length];
+
+ for (int i = 0; i < values.length; i++) {
+ propValues[i] = values[i].getDate();
+ }
+ } else {
+ propValues = new Calendar[] { p.getDate() };
+ }
+ break;
+ }
+
+ return propValues;
+ }
+
+}
Property changes on:
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/ItemBeanFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added:
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/NodeBean.java
===================================================================
---
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/NodeBean.java
(rev 0)
+++
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/NodeBean.java
2009-06-10 14:35:57 UTC (rev 18471)
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2008 Hippo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hippoecm.hst.wicketexamples;
+
+import java.util.Map;
+
+public class NodeBean extends ItemBean {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String primaryNodeTypeName;
+ protected String uuid;
+ protected Map<String, Object []> properties;
+
+ public NodeBean(String name, String path, int depth, boolean ismodified,
boolean isnew, boolean isnode,
+ String primaryNodeTypeName, String uuid, Map<String, Object []>
properties) {
+
+ super(name, path, depth, ismodified, isnew, isnode);
+
+ this.primaryNodeTypeName = primaryNodeTypeName;
+ this.uuid = uuid;
+ this.properties = properties;
+
+ }
+
+ public String getPrimaryNodeTypeName() {
+ return primaryNodeTypeName;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public Map<String, Object []> getProperties() {
+ return properties;
+ }
+
+ public Object [] getProperty(String name) {
+ return properties.get(name);
+ }
+
+}
Property changes on:
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/NodeBean.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified:
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/WicketContentBrowserApplication.java
===================================================================
---
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/WicketContentBrowserApplication.java
2009-06-10 12:18:11 UTC (rev 18470)
+++
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/WicketContentBrowserApplication.java
2009-06-10 14:35:57 UTC (rev 18471)
@@ -15,13 +15,69 @@
*/
package org.hippoecm.hst.wicketexamples;
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
import org.apache.wicket.protocol.http.WebApplication;
+import org.hippoecm.hst.site.HstServices;
public class WicketContentBrowserApplication extends WebApplication {
+ private Repository repository;
+ private Credentials credentials;
+ private boolean credentialsConfigured = true;
+ private String basePath;
+
@Override
public Class getHomePage() {
return WicketContentBrowserPage.class;
}
+ public Repository getDefaultRepository() throws Exception {
+ if (repository == null) {
+ String repositoryResourceReferenceName =
getInitParameter("repository-res-ref-name");
+
+ if (repositoryResourceReferenceName != null) {
+ Context initCtx = new InitialContext();
+ Context envCtx = (Context) initCtx.lookup("java:comp/env");
+ repository = (Repository)
envCtx.lookup(repositoryResourceReferenceName);
+ } else {
+ repository =
HstServices.getComponentManager().getComponent("javax.jcr.Repository");
+ }
+ }
+
+ return repository;
+ }
+
+ public Credentials getDefaultCredentials() {
+ if (credentials == null && credentialsConfigured) {
+ String user = getInitParameter("repository-user");
+ String password = getInitParameter("repository-password");
+
+ if (user != null && password != null) {
+ credentials = new SimpleCredentials(user,
password.toCharArray());
+ } else {
+ credentialsConfigured = false;
+ }
+ }
+
+ return credentials;
+ }
+
+ public String getBasePath() {
+ if (basePath == null) {
+ basePath = getInitParameter("base-path");
+
+ if (basePath == null) {
+ basePath = "/jcr:root";
+ }
+ }
+
+ return basePath;
+ }
+
}
Modified:
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/WicketContentBrowserPage.java
===================================================================
---
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/WicketContentBrowserPage.java
2009-06-10 12:18:11 UTC (rev 18470)
+++
ecm/site-toolkit/trunk/testsuite/site/src/main/java/org/hippoecm/hst/wicketexamples/WicketContentBrowserPage.java
2009-06-10 14:35:57 UTC (rev 18471)
@@ -15,12 +15,139 @@
*/
package org.hippoecm.hst.wicketexamples;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Credentials;
+import javax.jcr.NodeIterator;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+
import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
+import org.apache.wicket.markup.html.panel.FeedbackPanel;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.data.DataView;
+import org.apache.wicket.markup.repeater.data.ListDataProvider;
+import org.apache.wicket.model.PropertyModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class WicketContentBrowserPage extends WebPage {
+
+ private Logger logger =
LoggerFactory.getLogger(WicketContentBrowserPage.class);
+ protected String currentRelativePath = "";
+ protected List<ItemBean> currentItemBeans = new ArrayList<ItemBean>();
+
public WicketContentBrowserPage() {
+
+ refreshCurrentPathItemBeans();
+ Label currentRelativePathLabel = new Label("currentRelativePath", new
PropertyModel(this, "currentRelativePath"));
+ add(currentRelativePathLabel);
+
+ Link parentLink = new Link("parentLink") {
+ private static final long serialVersionUID = 1L;
+
+ public void onClick() {
+ if (currentRelativePath != null &&
!"".equals(currentRelativePath)) {
+ int offset = currentRelativePath.lastIndexOf('/');
+
+ if (offset >= 0) {
+ currentRelativePath = currentRelativePath.substring(0,
offset);
+ refreshCurrentPathItemBeans();
+ }
+ }
+ }
+ };
+
+ add(parentLink);
+
+ final DataView itemView = new DataView("itemView", new
ListDataProvider(currentItemBeans)) {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void populateItem(Item item) {
+ final ItemBean itemBean = (ItemBean) item.getModelObject();
+
+ final String name = itemBean.getName();
+ String primaryNodeTypeName = null;
+ String uuid = null;
+
+ if (itemBean instanceof NodeBean) {
+ NodeBean nodeBean = (NodeBean) itemBean;
+ primaryNodeTypeName = nodeBean.getPrimaryNodeTypeName();
+ uuid = nodeBean.getUuid();
+ }
+
+ Link nameLink = new Link("nameLink") {
+ private static final long serialVersionUID = 1L;
+
+ public void onClick() {
+ currentRelativePath += ("/" + name);
+ refreshCurrentPathItemBeans();
+ }
+ };
+
+ nameLink.add(new Label("name", name));
+ item.add(nameLink);
+ item.add(new Label("primaryNodeTypeName",
primaryNodeTypeName));
+ item.add(new Label("uuid", uuid));
+ }
+ };
+
+ itemView.setItemsPerPage(10);
+ add(itemView);
+ add(new PagingNavigator("itemNavigator", itemView));
+ FeedbackPanel feedback = new FeedbackPanel("feedback");
+ feedback.setEscapeModelStrings(false);
+ add(feedback);
+
}
+ public String getCurrentRelativePath() {
+ return currentRelativePath;
+ }
+
+ protected void refreshCurrentPathItemBeans() {
+ Repository repository = null;
+ Session session = null;
+
+ try {
+ WicketContentBrowserApplication app =
(WicketContentBrowserApplication) getApplication();
+ repository = app.getDefaultRepository();
+ Credentials credentials = app.getDefaultCredentials();
+ String basePath = app.getBasePath();
+
+ session = (credentials == null ? repository.login() :
repository.login(credentials));
+
+ String statement = basePath + currentRelativePath +
(currentRelativePath.endsWith("/") ? "*" : "/*");
+ Query query =
session.getWorkspace().getQueryManager().createQuery(statement, "xpath");
+ QueryResult result = query.execute();
+
+ currentItemBeans.clear();
+
+ for (NodeIterator it = result.getNodes(); it.hasNext(); ) {
+
currentItemBeans.add(ItemBeanFactory.createItemBean(it.nextNode()));
+ }
+ } catch (Exception e) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Failed to query.", e);
+ }
+ } finally {
+ if (session != null) {
+ try {
+ session.logout();
+ } catch (Exception ce) {
+ }
+ }
+ }
+ }
+
}
Modified:
ecm/site-toolkit/trunk/testsuite/site/src/main/resources/org/hippoecm/hst/wicketexamples/WicketContentBrowserPage.html
===================================================================
---
ecm/site-toolkit/trunk/testsuite/site/src/main/resources/org/hippoecm/hst/wicketexamples/WicketContentBrowserPage.html
2009-06-10 12:18:11 UTC (rev 18470)
+++
ecm/site-toolkit/trunk/testsuite/site/src/main/resources/org/hippoecm/hst/wicketexamples/WicketContentBrowserPage.html
2009-06-10 14:35:57 UTC (rev 18471)
@@ -18,12 +18,44 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.sourceforge.net/">
<head>
+<style>
+.content-browser {
+ text-align: left;
+}
+</style>
</head>
<body>
- <h1>Wicket Content Browser</h1>
- <hr/>
+
+<h1>Current path: <span wicket:id="currentRelativePath">Current Relative
Path</span></h1>
+
+<hr/>
+<div wicket:id="feedback"></div>
+
+<table class="content-browser">
+ <tr class="content-browser">
+ <th class="content-browser">Name</th>
+ <th class="content-browser">Primary Type</th>
+ <th class="content-browser">UUID</th>
+ </tr>
+ <tr class="content-browser">
+ <td class="content-browser" colspan="3"><em><a href='#'
wicket:id='parentLink'>.. (go to parent)</a></em></td>
+ </tr>
+ <tr wicket:id="itemView" class="content-browser">
+ <td class="content-browser"><a href='#'
wicket:id='nameLink'><span wicket:id="name"
class="content-browser">name</span></a></td>
+ <td class="content-browser"><span wicket:id="primaryNodeTypeName"
class="content-browser">primaryNodeTypeName</span></td>
+ <td class="content-browser"><span wicket:id="uuid"
class="content-browser">UUID</span></td>
+ </tr>
+ <tr class="content-browser">
+ <td class="content-browser"><span wicket:id="itemNavigator"
class="content-browser">Navigator</span></td>
+ </tr>
+</table>
+
+<hr/>
+
+<em>Wicket Content Browser Example</em>
+
</body>
</html>
\ No newline at end of file
_______________________________________________
Hippocms-svn mailing list
[email protected]
http://lists.hippo.nl/mailman/listinfo/hippocms-svn