You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by mi...@apache.org on 2005/04/11 23:54:48 UTC
svn commit: r160961 - in
lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication:
AbstractPublication.java JCRSiteTree.java
Author: michi
Date: Mon Apr 11 14:54:48 2005
New Revision: 160961
URL: http://svn.apache.org/viewcvs?view=rev&rev=160961
Log:
thanks to Felix archive, etc. has been implemented
Modified:
lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java
Modified: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/AbstractPublication.java?view=diff&r1=160960&r2=160961
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/AbstractPublication.java (original)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/AbstractPublication.java Mon Apr 11 14:54:48 2005
@@ -546,11 +546,11 @@
node.removeLabel(label);
- if (node.getLabels().length == 0) {
- tree.removeNode(document.getId());
- }
-
try {
+ if (node.getLabels().length == 0) {
+ tree.deleteNode(document.getId());
+ }
+
tree.save();
} catch (SiteTreeException e) {
throw new PublicationException(e);
Modified: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java?view=diff&r1=160960&r2=160961
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java (original)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java Mon Apr 11 14:54:48 2005
@@ -21,6 +21,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.StringTokenizer;
@@ -38,8 +39,12 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
import javax.jcr.version.VersionException;
import javax.naming.Context;
@@ -53,8 +58,11 @@
/**
* Sitetree implementation based on JSR-170.
*/
-public class JCRSiteTree implements SiteTree {
+public class JCRSiteTree implements SiteTree, LastModified, EventListener {
private static Logger log = Logger.getLogger(JCRSiteTree.class);
+
+ // Keeps the last modification time.
+ private long lastModified = 0;
// Repository user. "anonymous" gives a read-only session.
private final static String REPO_USER = "lenya";
@@ -80,7 +88,7 @@
private String prefixSys = null;
private String prefixUser = null;
- private Repository repository = null;
+ private static Repository repository = null;
private Session session = null;
private String workspace = null;
@@ -96,20 +104,30 @@
protected JCRSiteTree(File pubDir, String area) throws SiteTreeException {
this.workspace = area;
try {
- repository = getRepository(pubDir.getAbsolutePath() + File.separator + REPOSITORY_HOME);
+ Repository repo = getRepository(pubDir.getAbsolutePath() + File.separator + REPOSITORY_HOME);
String userId = REPO_USER;
char[] password = "".toCharArray();
- session = repository.login(new SimpleCredentials(userId, password), area);
+ session = repo.login(new SimpleCredentials(userId, password), area);
prefixUser = getNamespacePrefix(NS_URI_USER, NS_PREFIX_USER);
prefixSys = getNamespacePrefix(NS_URI_SYSTEM, NS_PREFIX_SYSTEM);
if (prefixUser == null || prefixSys == null) {
throw new SiteTreeException("Unable to get namespace prefixes");
}
+ Node siteNode = null;
// Add sitetree root node if it does not exist already
if (!session.getRootNode().hasNode(prefixSys + ":" + SITETREE_NAME)) {
- Node siteNode = session.getRootNode().addNode(prefixSys + ":" + SITETREE_NAME);
+ siteNode = session.getRootNode().addNode(prefixSys + ":" + SITETREE_NAME);
session.save();
+ } else {
+ siteNode = session.getRootNode().getNode(prefixSys + ":" + SITETREE_NAME);
}
+ // Stay informed about workspace changes.
+ int eventFilter = Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED |
+ Event.PROPERTY_REMOVED;
+ session.getWorkspace().getObservationManager().
+ addEventListener(this, eventFilter, siteNode.getPath(), true, null, null, false);
+ } catch (UnsupportedRepositoryOperationException e) {
+ throw new SiteTreeException("Could not register workspace event listener.", e);
} catch (RepositoryException e) {
throw new SiteTreeException("Repository exception", e);
} catch (Exception e) {
@@ -426,27 +444,27 @@
* @see org.apache.lenya.cms.publication.SiteTree#save()
*/
public synchronized void save() throws SiteTreeException {
- try {
- session.save();
- } catch (AccessDeniedException e) {
- log.error("JCRSiteTree.save() failed: access denied exception.", e);
- throw new SiteTreeException("Access denied when trying to save the site tree.", e);
- } catch (ConstraintViolationException e) {
- log.error("JCRSiteTree.save() failed: constraint violation.", e);
- throw new SiteTreeException("Constraint violation occured when saving the site tree.", e);
- } catch (InvalidItemStateException e) {
- log.error("JCRSiteTree.save() failed: invalid item state.", e);
- throw new SiteTreeException("Invalid item state when saving the site tree.", e);
- } catch (VersionException e) {
- log.error("JCRSiteTree.save() failed: version exception.", e);
- throw new SiteTreeException("Version issue when saving the site tree.", e);
- } catch (LockException e) {
- log.error("JCRSiteTree.save() failed: locking exception.", e);
- throw new SiteTreeException("Locking issue when saving the site tree.", e);
- } catch (RepositoryException e) {
- log.error("JCRSiteTree.save() failed: repository exception.", e);
- throw new SiteTreeException(e);
- }
+ try {
+ session.save();
+ } catch (AccessDeniedException e) {
+ log.error("JCRSiteTree.save() failed: access denied exception.", e);
+ throw new SiteTreeException("Access denied when trying to save the site tree.", e);
+ } catch (ConstraintViolationException e) {
+ log.error("JCRSiteTree.save() failed: constraint violation.", e);
+ throw new SiteTreeException("Constraint violation occured when saving the site tree.", e);
+ } catch (InvalidItemStateException e) {
+ log.error("JCRSiteTree.save() failed: invalid item state.", e);
+ throw new SiteTreeException("Invalid item state when saving the site tree.", e);
+ } catch (VersionException e) {
+ log.error("JCRSiteTree.save() failed: version exception.", e);
+ throw new SiteTreeException("Version issue when saving the site tree.", e);
+ } catch (LockException e) {
+ log.error("JCRSiteTree.save() failed: locking exception.", e);
+ throw new SiteTreeException("Locking issue when saving the site tree.", e);
+ } catch (RepositoryException e) {
+ log.error("JCRSiteTree.save() failed: repository exception.", e);
+ throw new SiteTreeException(e);
+ }
}
/**
@@ -540,28 +558,31 @@
* Get Repository
* @param repHomeDir Path to repository
*/
- private Repository getRepository(String repHomeDir) throws Exception {
- String configFile = repHomeDir + File.separator + "repository.xml";
-
- Hashtable env = new Hashtable();
- env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
- env.put(Context.PROVIDER_URL, "localhost");
- InitialContext ctx = new InitialContext(env);
-
- try {
- RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
- } catch (Exception e) {
- e.printStackTrace();
- throw e;
+ private static synchronized Repository getRepository(String repHomeDir) throws Exception {
+ if (repository == null) {
+ String configFile = repHomeDir + File.separator + "repository.xml";
+
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
+ env.put(Context.PROVIDER_URL, "localhost");
+ InitialContext ctx = new InitialContext(env);
+
+ try {
+ RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ repository = (Repository) ctx.lookup("repo");
}
- return (Repository) ctx.lookup("repo");
+ return repository;
}
public String getWorkspace() {
return workspace;
}
- /* (non-Javadoc)
+ /**
* @see org.apache.lenya.cms.publication.SiteTree#copy(org.apache.lenya.cms.publication.SiteTreeNode, org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String, java.lang.String)
*/
public void copy(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling)
@@ -574,8 +595,8 @@
JCRSiteTreeNodeImpl dstNode = (JCRSiteTreeNodeImpl)dst;
String dstPath = null;
- String srcWorkspace = srcNode.getJCRSiteTree().getWorkspace();
- String dstWorkspace = dstNode.getJCRSiteTree().getWorkspace();
+ String srcWorkspace = srcNode.getJCRSiteTree().getWorkspace();
+ String dstWorkspace = dstNode.getJCRSiteTree().getWorkspace();
try {
if (dstWorkspace != this.getWorkspace()) {
@@ -584,6 +605,7 @@
} else {
// Destination node is in this sitetree.
dstPath = dstNode.getJCRNode().getPath() + "/" + prefixUser + ":" + newId;
+
if (srcWorkspace == this.getWorkspace()) {
// Source node is in this sitetree.
session.getWorkspace().copy(srcNode.getJCRNode().getPath(), dstPath);
@@ -613,7 +635,7 @@
}
}
- /* (non-Javadoc)
+ /**
* @see org.apache.lenya.cms.publication.SiteTree#move(org.apache.lenya.cms.publication.SiteTreeNode, org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String, java.lang.String)
*/
public void move(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling) throws SiteTreeException {
@@ -641,7 +663,7 @@
} else {
// First, copy src node into this sitetree, then delete src node.
copy(src, dst, newId, followingSibling);
- srcNode.getJCRSiteTree().deleteNode(srcNode.getJCRNode().getPath());
+ srcNode.getJCRSiteTree().deleteNode(src.getAbsoluteId());
}
// TODO: Ordering of nodes
} catch (NoSuchWorkspaceException e) {
@@ -663,7 +685,7 @@
}
}
- /* (non-Javadoc)
+ /**
* @see org.apache.lenya.cms.publication.SiteTree#deleteNode(java.lang.String)
*/
public void deleteNode(String documentId) throws SiteTreeException {
@@ -678,6 +700,20 @@
} catch (RepositoryException e) {
throw new SiteTreeException("Repository exception.", e);
}
+ }
+
+ /**
+ * @see org.apache.lenya.cms.publication.LastModified#getLastModified()
+ */
+ public long getLastModified() {
+ return lastModified;
+ }
+
+ /**
+ * @see javax.jcr.observation.EventListener#onEvent(javax.jcr.observation.EventIterator)
+ */
+ public void onEvent(EventIterator events) {
+ lastModified = new Date().getTime();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org