You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/12/01 18:20:38 UTC
svn commit: r350280 - in /lenya/trunk/src: java/org/apache/lenya/cms/repo/
modules/jcr/java/src/org/apache/lenya/cms/jcr/
modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/
modules/jcr/java/test/org/apache/lenya/cms/jcr/
Author: andreas
Date: Thu Dec 1 09:20:21 2005
New Revision: 350280
URL: http://svn.apache.org/viewcvs?rev=350280&view=rev
Log:
Repo layer: added method Site.move()
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/ContentNodeProxy.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteNodeProxy.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteProxy.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/RepositoryFacade.java
lenya/trunk/src/modules/jcr/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java?rev=350280&r1=350279&r2=350280&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java Thu Dec 1 09:20:21 2005
@@ -55,23 +55,29 @@
* @throws RepositoryException if an error occurs.
*/
DocumentType getDocumentType() throws RepositoryException;
-
+
/**
* @return The ID of this node.
* @throws RepositoryException if an error occurs.
*/
String getNodeId() throws RepositoryException;
-
+
/**
* @return If the node should be visible in the navigation.
* @throws RepositoryException if an error occurs.
*/
boolean isVisibleInNav() throws RepositoryException;
-
+
/**
* @param visible If the node should be visible in the navigation.
* @throws RepositoryException if an error occurs.
*/
void setVisibleInNav(boolean visible) throws RepositoryException;
-
+
+ /**
+ * Removes the node and all its documents.
+ * @throws RepositoryException if the node is still referenced from the site structure.
+ */
+ void remove() throws RepositoryException;
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java?rev=350280&r1=350279&r2=350280&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java Thu Dec 1 09:20:21 2005
@@ -26,39 +26,48 @@
* @throws RepositoryException if an error occurs.
*/
SiteNode[] getChildren() throws RepositoryException;
-
+
/**
* @return The nodes of this site in preorder.
* @throws RepositoryException if an error occurs.
*/
SiteNode[] preOrder() throws RepositoryException;
-
+
/**
* @param name The name.
* @param contentNode The content node which the site node refers to.
* @return a site node.
- * @throws RepositoryException if a child with this name already exists.
+ * @throws RepositoryException if a node with this path already exists.
*/
SiteNode addChild(String name, ContentNode contentNode) throws RepositoryException;
-
+
/**
* @param name The name.
* @return a site node.
- * @throws RepositoryException if the child does not exist.
+ * @throws RepositoryException if the node does not exist.
*/
SiteNode getChild(String name) throws RepositoryException;
-
+
/**
* @param path The path of the node.
* @return A site node.
* @throws RepositoryException if the node does not exist.
*/
SiteNode getNode(String path) throws RepositoryException;
-
+
/**
* @return The area this site belongs to.
* @throws RepositoryException if an error occurs.
*/
Area getArea() throws RepositoryException;
-
+
+ /**
+ * Moves a subtree to another location.
+ * @param srcAbsPath The path of the node to move.
+ * @param destAbsPath The destination path.
+ * @throws RepositoryException if the destination node already exists or the destination parent
+ * does not exist.
+ */
+ void move(String srcAbsPath, String destAbsPath) throws RepositoryException;
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java?rev=350280&r1=350279&r2=350280&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java Thu Dec 1 09:20:21 2005
@@ -77,4 +77,10 @@
* @throws RepositoryException if an error occurs.
*/
Site getSite() throws RepositoryException;
+
+ /**
+ * Removes the node and all its child nodes.
+ * @throws RepositoryException if an error occurs.
+ */
+ void remove() throws RepositoryException;
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/ContentNodeProxy.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/ContentNodeProxy.java?rev=350280&r1=350279&r2=350280&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/ContentNodeProxy.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/ContentNodeProxy.java Thu Dec 1 09:20:21 2005
@@ -115,4 +115,8 @@
setProperty(DOCUMENT_TYPE_PROPERTY, documentType);
}
+ public void remove() throws RepositoryException {
+ getRepository().removeProxy(this);
+ }
+
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteNodeProxy.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteNodeProxy.java?rev=350280&r1=350279&r2=350280&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteNodeProxy.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteNodeProxy.java Thu Dec 1 09:20:21 2005
@@ -70,7 +70,7 @@
public String getPath() throws RepositoryException {
String sitePath = ((SiteProxy) getSite()).getAbsolutePath().toString();
- return getAbsolutePath().toString().substring(0, sitePath.length());
+ return getAbsolutePath().toString().substring(sitePath.length());
}
public Path getAbsolutePath() throws RepositoryException {
@@ -127,6 +127,10 @@
} catch (javax.jcr.RepositoryException e) {
throw new RepositoryException(e);
}
+ }
+
+ public void remove() throws RepositoryException {
+ getRepository().removeProxy(this);
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteProxy.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteProxy.java?rev=350280&r1=350279&r2=350280&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteProxy.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/SiteProxy.java Thu Dec 1 09:20:21 2005
@@ -20,6 +20,8 @@
import java.util.Arrays;
import java.util.List;
+import javax.jcr.Session;
+
import org.apache.lenya.cms.jcr.mapping.AbstractNodeProxy;
import org.apache.lenya.cms.jcr.mapping.NamePathElement;
import org.apache.lenya.cms.jcr.mapping.Path;
@@ -51,7 +53,7 @@
}
return (SiteNode[]) nodes.toArray(new SiteNode[nodes.size()]);
}
-
+
public SiteNode addChild(String name, ContentNode contentNode) throws RepositoryException {
SiteNodeProxy proxy = (SiteNodeProxy) getRepository().addByName(getAbsolutePath(),
SiteNodeProxy.NODE_TYPE,
@@ -79,7 +81,7 @@
public Path getAbsolutePath() throws RepositoryException {
return SiteProxy.getPath((AreaProxy) getParentProxy());
}
-
+
protected static Path getPath(AreaProxy area) throws RepositoryException {
return area.getAbsolutePath().append(getPathElement(NODE_NAME));
}
@@ -90,6 +92,17 @@
public PathElement getPathElement() throws RepositoryException {
return getPathElement(getName());
+ }
+
+ public void move(String srcAbsPath, String destAbsPath) throws RepositoryException {
+ try {
+ String srcPath = getNode().getPath() + srcAbsPath;
+ String destPath = getNode().getPath() + destAbsPath;
+ Session session = getNode().getSession();
+ session.move(srcPath, destPath);
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/RepositoryFacade.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/RepositoryFacade.java?rev=350280&r1=350279&r2=350280&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/RepositoryFacade.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/RepositoryFacade.java Thu Dec 1 09:20:21 2005
@@ -16,14 +16,9 @@
*/
package org.apache.lenya.cms.jcr.mapping;
-import java.util.HashMap;
-import java.util.Map;
-
import javax.jcr.Node;
import javax.jcr.NodeIterator;
-import javax.jcr.PathNotFoundException;
import javax.jcr.Session;
-import javax.jcr.ValueFormatException;
import javax.jcr.query.InvalidQueryException;
import org.apache.lenya.cms.jcr.util.Assertion;
@@ -49,7 +44,6 @@
this.metaDataRegistry = metaDataRegistry;
}
- private Map node2proxy = new HashMap();
private Session session;
private DocumentTypeRegistry doctypeRegistry;
@@ -72,7 +66,7 @@
Node[] nodes = getNodes(path);
NodeProxy[] proxies = new NodeProxy[nodes.length];
for (int i = 0; i < nodes.length; i++) {
- proxies[i] = (NodeProxy) this.node2proxy.get(nodes[i]);
+ proxies[i] = getProxy(nodes[i]);
if (proxies[i] == null) {
proxies[i] = createProxy(nodes[i]);
}
@@ -114,21 +108,26 @@
}
}
- protected NodeProxy createProxy(Node node) throws ValueFormatException,
- javax.jcr.RepositoryException, PathNotFoundException, ClassNotFoundException,
- InstantiationException, IllegalAccessException, RepositoryException {
- String className = node.getProperty(CLASS_PROPERTY).getString();
+ protected NodeProxy createProxy(Node node) throws RepositoryException {
+ String className;
+ try {
+ className = node.getProperty(CLASS_PROPERTY).getString();
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
NodeProxy proxy = createProxy(className);
proxy.setup(this, node);
- this.node2proxy.put(node, proxy);
return proxy;
}
- protected NodeProxy createProxy(String className) throws ClassNotFoundException,
- InstantiationException, IllegalAccessException {
+ protected NodeProxy createProxy(String className) throws RepositoryException {
NodeProxy proxy;
- Class clazz = Class.forName(className);
- proxy = (NodeProxy) clazz.newInstance();
+ try {
+ Class clazz = Class.forName(className);
+ proxy = (NodeProxy) clazz.newInstance();
+ } catch (Exception e) {
+ throw new RepositoryException(e);
+ }
return proxy;
}
@@ -196,14 +195,8 @@
}
- protected NodeProxy getProxy(Node parentNode) throws ValueFormatException,
- javax.jcr.RepositoryException, PathNotFoundException, ClassNotFoundException,
- InstantiationException, IllegalAccessException, RepositoryException {
- NodeProxy parentProxy = (NodeProxy) this.node2proxy.get(parentNode);
- if (parentProxy == null) {
- parentProxy = createProxy(parentNode);
- }
- return parentProxy;
+ protected NodeProxy getProxy(Node node) throws RepositoryException {
+ return createProxy(node);
}
public DocumentTypeRegistry getDocumentTypeRegistry() {
@@ -216,4 +209,19 @@
return this.metaDataRegistry;
}
+ public void removeProxy(NodeProxy proxy) throws RepositoryException {
+
+ try {
+ for (NodeIterator i = proxy.getNode().getNodes(); i.hasNext();) {
+ Node node = i.nextNode();
+ removeProxy(getProxy(node));
+ }
+
+ Node node = proxy.getNode();
+ node.remove();
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
+
+ }
}
Modified: lenya/trunk/src/modules/jcr/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java?rev=350280&r1=350279&r2=350280&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java (original)
+++ lenya/trunk/src/modules/jcr/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java Thu Dec 1 09:20:21 2005
@@ -21,6 +21,8 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
+import javax.jcr.ItemExistsException;
+
import junit.framework.TestCase;
import org.apache.cocoon.components.validation.Validator;
@@ -126,12 +128,33 @@
assertNotNull(node2);
SiteNode parent = site.addChild("parent", node1);
SiteNode child = parent.addChild("child", node2);
- assertSame(node2, child.getContentNode());
+ assertSame(node2.getNodeId(), child.getContentNode().getNodeId());
+
+ doTestSite(site, node1);
doTestDocument(node1);
}
+ protected void doTestSite(Site site, ContentNode contentNode) throws RepositoryException {
+ SiteNode foo = site.addChild("foo", contentNode);
+ SiteNode bar = site.addChild("bar", contentNode);
+
+
+ RepositoryException ex = null;
+ try {
+ site.move(foo.getPath(), bar.getPath());
+ } catch (RepositoryException e) {
+ ex = e;
+ }
+ assertTrue(ex.getCause() instanceof ItemExistsException);
+ site.move("/foo", "/bar/baz");
+
+ SiteNode barBaz = bar.getChild("baz");
+ assertSame(foo.getContentNode().getNodeId(), barBaz.getContentNode().getNodeId());
+
+ }
+
protected void doTestDocument(ContentNode node1) throws Exception {
Document doc = node1.addDocument("de", "hello");
@@ -172,7 +195,7 @@
meta.addValue(TestElementSet.MULTIPLE_ELEMENT, "hello");
meta.addValue(TestElementSet.MULTIPLE_ELEMENT, "world");
assertTrue(meta.getValues(TestElementSet.MULTIPLE_ELEMENT).length == 2);
-
+
try {
meta.addValue(TestElementSet.SINGLE_ELEMENT, "hello");
} catch (RepositoryException e) {
@@ -181,7 +204,7 @@
assertNotNull(ex);
meta.setValue(TestElementSet.SINGLE_ELEMENT, "hello");
assertEquals(meta.getValue(TestElementSet.SINGLE_ELEMENT), "hello");
-
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org