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/04/09 16:38:29 UTC
svn commit: r160685 - in lenya/trunk/src: java/org/apache/lenya/cms/ant/
java/org/apache/lenya/cms/cocoon/source/
java/org/apache/lenya/cms/publication/
java/org/apache/lenya/cms/publication/util/ java/org/apache/lenya/cms/site/
java/org/apache/lenya/cms/site/topicmap/ java/org/apache/lenya/cms/site/tree/
java/org/apache/lenya/cms/site/usecases/
webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/
Author: andreas
Date: Sat Apr 9 07:38:27 2005
New Revision: 160685
URL: http://svn.apache.org/viewcvs?view=rev&rev=160685
Log:
refactored site management, fixed delete usecase problems
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/ant/ComputeNewDocumentId.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/util/DocumentSet.java
lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java
lenya/trunk/src/java/org/apache/lenya/cms/site/topicmap/TopicMapSiteManager.java
lenya/trunk/src/java/org/apache/lenya/cms/site/tree/TreeSiteManager.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java
lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java
lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/ComputeNewDocumentId.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/ComputeNewDocumentId.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/ComputeNewDocumentId.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/ComputeNewDocumentId.java Sat Apr 9 07:38:27 2005
@@ -19,32 +19,33 @@
package org.apache.lenya.cms.ant;
+import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.site.SiteManager;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
-
/**
* <p>
- * Ant task to set the property "newdocumentid" in the project with the
- * value of computed unique document id, needed for the destination file
- * Overriden for copy/move/rename.
+ * Ant task to set the property "newdocumentid" in the project with the value of computed unique
+ * document id, needed for the destination file Overriden for copy/move/rename.
+ * </p>
+ * <p>
+ * Parameters:
* </p>
- * <p>Parameters:</p>
* <ul>
* <li>area - The area in which is the sitetree.</li>
* <li>firstdocumentid - The document id of the source</li>
- * <li>secdocumentid - The document id of the parent of the destination
- or in case of rename the new name</li>
+ * <li>secdocumentid - The document id of the parent of the destination or in case of rename the
+ * new name</li>
* </ul>
*/
public class ComputeNewDocumentId extends PublicationTask {
-
- private String area;
- private String firstdocumentid;
- private String secdocumentid;
+
+ private String area;
+ private String firstdocumentid;
+ private String secdocumentid;
/**
* Creates a new instance of ComputeNewDocumentId
@@ -53,23 +54,23 @@
super();
}
- /**
- * @return string The area in which is the sitetree.
- */
- public String getArea() {
- return this.area;
- }
-
- /**
- * set the value of the area in which is the sitetree
- * @param string The area of the sitetree.
- */
- public void setArea(String string) {
- this.area = string;
- }
+ /**
+ * @return string The area in which is the sitetree.
+ */
+ public String getArea() {
+ return this.area;
+ }
/**
- * @return string The document id of the source
+ * set the value of the area in which is the sitetree
+ * @param string The area of the sitetree.
+ */
+ public void setArea(String string) {
+ this.area = string;
+ }
+
+ /**
+ * @return string The document id of the source
*/
protected String getFirstdocumentid() {
return this.firstdocumentid;
@@ -84,80 +85,84 @@
}
/**
- * @return string The document id of the parent of the destination
- * or the new name in case of rename
+ * @return string The document id of the parent of the destination or the new name in case of
+ * rename
*/
protected String getSecdocumentid() {
return this.secdocumentid;
}
/**
- * @param string The document id of the parent of the destination
- * or the new name in case of rename
+ * @param string The document id of the parent of the destination or the new name in case of
+ * rename
*/
public void setSecdocumentid(String string) {
this.secdocumentid = string;
}
- /**
- * Method to be overriden to compute the document id of the destination.
- * @param _firstdocumentid The document id of the source.
- * @param _secdocumentid Some string to characterize the destination (ex
- * document id of parent, new name).
- * @return string. The new document id
- */
- protected String compute(String _firstdocumentid, String _secdocumentid) {
- return _secdocumentid;
- }
+ /**
+ * Method to be overriden to compute the document id of the destination.
+ * @param _firstdocumentid The document id of the source.
+ * @param _secdocumentid Some string to characterize the destination (ex document id of parent,
+ * new name).
+ * @return string. The new document id
+ */
+ protected String compute(String _firstdocumentid, String _secdocumentid) {
+ return _secdocumentid;
+ }
/**
- * Compute the unique document id: append a "_version number" to the id,
- * if there is already a node in the sitetree with this id.
- * @param documentid The document id.
+ * Compute the unique document id: append a "_version number" to the id, if there is already a
+ * node in the sitetree with this id.
+ * @param documentid The document id.
* @param _area The area in which is the sitetree.
- * @return newdocumentid The unique document id.
+ * @return newdocumentid The unique document id.
*/
- protected String computeUniqueId(String documentid, String _area) {
+ protected String computeUniqueId(String documentid, String _area) {
- DocumentManager docManager = null;
+ SiteManager siteManager = null;
+ ServiceSelector selector = null;
try {
- docManager = (DocumentManager) getServiceManager().lookup(DocumentManager.ROLE);
+ selector = (ServiceSelector) getServiceManager().lookup(SiteManager.ROLE + "Selector");
+ siteManager = (SiteManager) selector.select(getPublication().getSiteManagerHint());
Document document = getIdentityMap().get(getPublication(), _area, documentid);
- document = docManager.getAvailableDocument(document);
+ document = siteManager.getAvailableDocument(document);
return document.getId();
} catch (Exception e) {
throw new RuntimeException(e);
- }
- finally {
- if (docManager != null) {
- getServiceManager().release(docManager);
+ } finally {
+ if (selector != null) {
+ if (siteManager != null) {
+ selector.release(siteManager);
+ }
+ getServiceManager().release(selector);
}
}
}
- /**
- * Set the property node.newdocumentid for the project
- * @param documentid The new document id.
- */
- protected void setNewProperty(String documentid) {
- Target _target = getOwningTarget();
- Project _project = _target.getProject();
- _project.setProperty("node.newdocumentid", documentid);
- }
+ /**
+ * Set the property node.newdocumentid for the project
+ * @param documentid The new document id.
+ */
+ protected void setNewProperty(String documentid) {
+ Target _target = getOwningTarget();
+ Project _project = _target.getProject();
+ _project.setProperty("node.newdocumentid", documentid);
+ }
/**
* @see org.apache.tools.ant.Task#execute()
- **/
+ */
public void execute() throws BuildException {
try {
log("document id of the source" + getFirstdocumentid());
log("document id of the destination" + getSecdocumentid());
log("area: " + getArea());
String documentId = compute(getFirstdocumentid(), getSecdocumentid());
- String uniqueId = computeUniqueId(documentId, getArea());
+ String uniqueId = computeUniqueId(documentId, getArea());
setNewProperty(uniqueId);
} catch (Exception e) {
throw new BuildException(e);
}
}
-}
+}
\ No newline at end of file
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java Sat Apr 9 07:38:27 2005
@@ -401,7 +401,7 @@
* @param sourceUri The source URI.
* @param manager The service manager.
*/
- public static void registerDirty(String sourceUri, ServiceManager manager) {
+ public static void registerDirty(String sourceUri, ServiceManager manager) {
SourceResolver resolver = null;
RepositorySource source = null;
try {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java Sat Apr 9 07:38:27 2005
@@ -81,6 +81,26 @@
void move(Document sourceDocument, Document destinationDocument) throws PublicationException;
/**
+ * Moves a document set from one location to another. A source is moved to the destination of
+ * the same position in the set.
+ * @param sources The source documents.
+ * @param destinations The destination documents.
+ * @throws PublicationException if a document which the destination document depends on does not
+ * exist.
+ */
+ void move(DocumentSet sources, DocumentSet destinations) throws PublicationException;
+
+ /**
+ * Copies a document set from one location to another. A source is copied to the destination of
+ * the same position in the set.
+ * @param sources The source documents.
+ * @param destinations The destination documents.
+ * @throws PublicationException if a document which the destination document depends on does not
+ * exist.
+ */
+ void copy(DocumentSet sources, DocumentSet destinations) throws PublicationException;
+
+ /**
* Checks if a document can be created. This is the case if the document ID is valid and the
* document does not yet exist.
* @param identityMap The identity map to use.
@@ -97,15 +117,6 @@
String[] canCreate(DocumentIdentityMap identityMap, Publication publication, String area,
Document parent, String nodeId, String language) throws DocumentBuildException,
DocumentException;
-
- /**
- * Checks if the document does already exist. If it does, returns a non-existing document with a
- * similar document ID. If it does not, the original document is returned.
- * @param document The document.
- * @return A document.
- * @throws DocumentBuildException if the new document could not be built.
- */
- Document getAvailableDocument(Document document) throws DocumentBuildException;
/**
* Moves a document to another location, incl. all requiring documents. If a sitetree is used,
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java Sat Apr 9 07:38:27 2005
@@ -17,7 +17,9 @@
package org.apache.lenya.cms.publication;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
@@ -34,9 +36,7 @@
import org.apache.lenya.cms.publication.util.DocumentSet;
import org.apache.lenya.cms.publication.util.DocumentVisitor;
import org.apache.lenya.cms.site.SiteManager;
-import org.apache.lenya.cms.site.tree.SiteTree;
-import org.apache.lenya.cms.site.tree.SiteTreeNode;
-import org.apache.lenya.cms.site.tree.TreeSiteManager;
+import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.workflow.WorkflowManager;
/**
@@ -266,83 +266,6 @@
}
/**
- * @see org.apache.lenya.cms.publication.DocumentManager#getAvailableDocument(org.apache.lenya.cms.publication.Document)
- */
- public Document getAvailableDocument(Document document) throws DocumentBuildException {
- String availableDocumentId = computeUniqueDocumentId(document);
- Document availableDocument = document.getIdentityMap().get(document.getPublication(),
- document.getArea(),
- availableDocumentId,
- document.getLanguage());
- return availableDocument;
- }
-
- /**
- * compute an unique document id
- * @param document The document.
- * @return the unique documentid
- */
- protected String computeUniqueDocumentId(Document document) {
- String documentId = document.getId();
-
- SiteManager siteManager = null;
- ServiceSelector selector = null;
- try {
- Publication pub = document.getPublication();
- selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
- siteManager = (SiteManager) selector.select(pub.getSiteManagerHint());
-
- if (!(siteManager instanceof TreeSiteManager)) {
- throw new RuntimeException("Only supported for site trees!");
- }
- DocumentIdentityMap map = document.getIdentityMap();
- SiteTree tree = ((TreeSiteManager) siteManager).getTree(map, pub, document.getArea());
-
- SiteTreeNode node = tree.getNode(documentId);
- String suffix = null;
- int version = 0;
- String idwithoutsuffix = null;
-
- if (node != null) {
- int n = documentId.lastIndexOf("/");
- String lastToken = "";
- String substring = documentId;
- if ((n < documentId.length()) && (n > 0)) {
- lastToken = documentId.substring(n);
- substring = documentId.substring(0, n);
- }
-
- int l = lastToken.length();
- int index = lastToken.lastIndexOf("-");
- if (0 < index && index < l) {
- suffix = lastToken.substring(index + 1);
- idwithoutsuffix = substring + lastToken.substring(0, index);
- version = Integer.parseInt(suffix);
- } else {
- idwithoutsuffix = substring + lastToken;
- }
-
- while (node != null) {
- version = version + 1;
- documentId = idwithoutsuffix + "-" + version;
- node = tree.getNode(documentId);
- }
- }
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage(), e);
- } finally {
- if (selector != null) {
- if (siteManager != null) {
- selector.release(siteManager);
- }
- this.manager.release(selector);
- }
- }
-
- return documentId;
- }
-
- /**
* @see org.apache.lenya.cms.publication.DocumentManager#moveAll(org.apache.lenya.cms.publication.Document,
* org.apache.lenya.cms.publication.Document)
*/
@@ -622,5 +545,55 @@
}
}
+ }
+
+ /**
+ * @see org.apache.lenya.cms.publication.DocumentManager#move(org.apache.lenya.cms.publication.util.DocumentSet, org.apache.lenya.cms.publication.util.DocumentSet)
+ */
+ public void move(DocumentSet sources, DocumentSet destinations) throws PublicationException {
+ Document[] sourceDocs = sources.getDocuments();
+ Document[] targetDocs = destinations.getDocuments();
+
+ if (sourceDocs.length != targetDocs.length) {
+ throw new PublicationException("The number of source and destination documents must be equal!");
+ }
+
+ Map source2target = new HashMap();
+ for (int i = 0; i < sourceDocs.length; i++) {
+ source2target.put(sourceDocs[i], targetDocs[i]);
+ }
+
+ DocumentSet sortedSources = new DocumentSet(sourceDocs);
+ SiteUtil.sortAscending(this.manager, sortedSources);
+ Document[] sortedSourceDocs = sortedSources.getDocuments();
+
+ for (int i = 0; i < sortedSourceDocs.length; i++) {
+ move(sortedSourceDocs[i], (Document) source2target.get(sortedSourceDocs[i]));
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.publication.DocumentManager#copy(org.apache.lenya.cms.publication.util.DocumentSet, org.apache.lenya.cms.publication.util.DocumentSet)
+ */
+ public void copy(DocumentSet sources, DocumentSet destinations) throws PublicationException {
+ Document[] sourceDocs = sources.getDocuments();
+ Document[] targetDocs = destinations.getDocuments();
+
+ if (sourceDocs.length != targetDocs.length) {
+ throw new PublicationException("The number of source and destination documents must be equal!");
+ }
+
+ Map source2target = new HashMap();
+ for (int i = 0; i < sourceDocs.length; i++) {
+ source2target.put(sourceDocs[i], targetDocs[i]);
+ }
+
+ DocumentSet sortedSources = new DocumentSet(sourceDocs);
+ SiteUtil.sortAscending(this.manager, sortedSources);
+ Document[] sortedSourceDocs = sortedSources.getDocuments();
+
+ for (int i = 0; i < sortedSourceDocs.length; i++) {
+ copy(sortedSourceDocs[i], (Document) source2target.get(sortedSourceDocs[i]));
+ }
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/util/DocumentSet.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/util/DocumentSet.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/util/DocumentSet.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/util/DocumentSet.java Sat Apr 9 07:38:27 2005
@@ -25,6 +25,7 @@
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.transaction.TransactionException;
/**
* An ordered set of documents without duplicates.
@@ -120,6 +121,17 @@
*/
public void reverse() {
Collections.reverse(getList());
+ }
+
+ /**
+ * Locks all contained documents.
+ * @throws TransactionException if an error occurs.
+ */
+ public void lock() throws TransactionException {
+ Document[] docs = getDocuments();
+ for (int i = 0; i < docs.length; i++) {
+ docs[i].lock();
+ }
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java Sat Apr 9 07:38:27 2005
@@ -153,4 +153,14 @@
*/
SiteStructure getSiteStructure(DocumentIdentityMap map, Publication publiation, String area)
throws SiteException;
+
+ /**
+ * Checks if the document does already exist. If it does, returns a non-existing document with a
+ * similar document ID. If it does not, the original document is returned.
+ * @param document The document.
+ * @return A document.
+ * @throws SiteException if the new document could not be built.
+ */
+ Document getAvailableDocument(Document document) throws SiteException;
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/topicmap/TopicMapSiteManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/topicmap/TopicMapSiteManager.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/topicmap/TopicMapSiteManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/topicmap/TopicMapSiteManager.java Sat Apr 9 07:38:27 2005
@@ -130,4 +130,11 @@
return null;
}
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#getAvailableDocument(org.apache.lenya.cms.publication.Document)
+ */
+ public Document getAvailableDocument(Document document) throws SiteException {
+ return document;
+ }
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/tree/TreeSiteManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/tree/TreeSiteManager.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/tree/TreeSiteManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/tree/TreeSiteManager.java Sat Apr 9 07:38:27 2005
@@ -29,6 +29,7 @@
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.util.DocumentSet;
import org.apache.lenya.cms.site.AbstractSiteManager;
import org.apache.lenya.cms.site.Label;
import org.apache.lenya.cms.site.SiteException;
@@ -125,7 +126,7 @@
getLogger().debug("Obtaining requiring resources of [" + resource + "]");
}
- Document[] resources;
+ DocumentSet resources = new DocumentSet();
SiteTree tree = getTree(resource);
SiteTreeNode node = tree.getNode(resource.getId());
@@ -135,16 +136,19 @@
// remove original resource (does not require itself)
preOrder.remove(0);
- resources = new Document[preOrder.size()];
-
try {
- for (int i = 0; i < resources.length; i++) {
+ for (int i = 0; i < preOrder.size(); i++) {
SiteTreeNode descendant = (SiteTreeNode) preOrder.get(i);
- resources[i] = resource.getIdentityMap().get(resource.getPublication(),
- resource.getArea(),
- descendant.getAbsoluteId());
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(" Descendant: [" + resources[i] + "]");
+ Label[] labels = descendant.getLabels();
+ for (int j = 0; j < labels.length; j++) {
+ Document version = resource.getIdentityMap().get(resource.getPublication(),
+ resource.getArea(),
+ descendant.getAbsoluteId(),
+ labels[i].getLanguage());
+ resources.add(version);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" Descendant: [" + version + "]");
+ }
}
}
} catch (PublicationException e) {
@@ -154,11 +158,9 @@
if (getLogger().isDebugEnabled()) {
getLogger().debug("Obtaining requiring resources completed.");
}
- } else {
- resources = new Document[0];
}
- return resources;
+ return resources.getDocuments();
}
/**
@@ -393,4 +395,65 @@
return getTree(map, publiation, area);
}
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#getAvailableDocument(org.apache.lenya.cms.publication.Document)
+ */
+ public Document getAvailableDocument(Document document) throws SiteException {
+ String availableDocumentId = computeUniqueDocumentId(document);
+ Document availableDocument;
+ try {
+ availableDocument = document.getIdentityMap().get(document.getPublication(),
+ document.getArea(),
+ availableDocumentId,
+ document.getLanguage());
+ } catch (DocumentBuildException e) {
+ throw new SiteException(e);
+ }
+ return availableDocument;
+ }
+
+ /**
+ * compute an unique document id
+ * @param document The document.
+ * @return the unique documentid
+ * @throws SiteException if an error occurs.
+ */
+ protected String computeUniqueDocumentId(Document document) throws SiteException {
+ String documentId = document.getId();
+
+ SiteTree tree = getTree(document);
+
+ SiteTreeNode node = tree.getNode(documentId);
+ String suffix = null;
+ int version = 0;
+ String idwithoutsuffix = null;
+
+ if (node != null) {
+ int n = documentId.lastIndexOf("/");
+ String lastToken = "";
+ String substring = documentId;
+ if ((n < documentId.length()) && (n > 0)) {
+ lastToken = documentId.substring(n);
+ substring = documentId.substring(0, n);
+ }
+
+ int l = lastToken.length();
+ int index = lastToken.lastIndexOf("-");
+ if (0 < index && index < l) {
+ suffix = lastToken.substring(index + 1);
+ idwithoutsuffix = substring + lastToken.substring(0, index);
+ version = Integer.parseInt(suffix);
+ } else {
+ idwithoutsuffix = substring + lastToken;
+ }
+
+ while (node != null) {
+ version = version + 1;
+ documentId = idwithoutsuffix + "-" + version;
+ node = tree.getNode(documentId);
+ }
+ }
+
+ return documentId;
+ }
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java Sat Apr 9 07:38:27 2005
@@ -16,14 +16,14 @@
*/
package org.apache.lenya.cms.site.usecases;
-import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.DocumentManager;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.util.DocumentSet;
-import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
/**
* Delete a document and all its descendants, including all language versions. The documents are
@@ -49,28 +49,10 @@
Document document = getSourceDocument();
DocumentIdentityMap identityMap = getDocumentIdentityMap();
- ServiceSelector selector = null;
- SiteManager siteManager = null;
- DocumentSet set;
- try {
- selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
- siteManager = (SiteManager) selector.select(document.getPublication()
- .getSiteManagerHint());
- set = new DocumentSet(siteManager.getRequiringResources(document));
- } finally {
- if (selector != null) {
- if (siteManager != null) {
- selector.release(siteManager);
- }
- this.manager.release(selector);
- }
- }
-
- set.add(document);
+ DocumentSet set = SiteUtil.getSubSite(this.manager, document);
Document[] documents = set.getDocuments();
for (int i = 0; i < documents.length; i++) {
- Document liveVersion = identityMap.getAreaVersion(documents[i],
- Publication.LIVE_AREA);
+ Document liveVersion = identityMap.getAreaVersion(documents[i], Publication.LIVE_AREA);
if (liveVersion.exists()) {
addErrorMessage("Cannot delete because document [" + liveVersion + "] is live!");
}
@@ -78,21 +60,57 @@
}
/**
+ * Lock the following objects:
+ * <ul>
+ * <li>all involved documents in the document's area</li>
+ * <li>the trash versions of these documents</li>
+ * <li>the document area's site structure</li>
+ * <li>the trash site structure</li>
+ * </ul>
+ * @see org.apache.lenya.cms.usecase.Usecase#lockInvolvedObjects()
+ */
+ public void lockInvolvedObjects() throws UsecaseException {
+ super.lockInvolvedObjects();
+
+ Document doc = getSourceDocument();
+ try {
+ DocumentSet sources = SiteUtil.getSubSite(this.manager, doc);
+ sources.lock();
+
+ DocumentSet targets = SiteUtil.getTransferedSubSite(this.manager,
+ doc,
+ Publication.TRASH_AREA,
+ SiteUtil.MODE_CHANGE_ID);
+ targets.lock();
+
+ SiteUtil.getSiteStructure(this.manager, doc).lock();
+ SiteUtil.getSiteStructure(this.manager, targets.getDocuments()[0]).lock();
+ } catch (Exception e) {
+ throw new UsecaseException(e);
+ }
+ }
+
+ /**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
*/
protected void doExecute() throws Exception {
super.doExecute();
- Document source = getSourceDocument();
- DocumentIdentityMap identityMap = source.getIdentityMap();
+ Document doc = getSourceDocument();
+ Document target = doc.getIdentityMap().getAreaVersion(doc, Publication.TRASH_AREA);
+ target = SiteUtil.getAvailableDocument(this.manager, target);
DocumentManager documentManager = null;
- Document target;
try {
documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
- target = identityMap.getAreaVersion(source, Publication.TRASH_AREA);
- target = documentManager.getAvailableDocument(target);
- documentManager.moveAll(source, target);
+
+ DocumentSet sources = SiteUtil.getSubSite(this.manager, doc);
+ DocumentSet targets = SiteUtil.getTransferedSubSite(this.manager,
+ doc,
+ Publication.TRASH_AREA,
+ SiteUtil.MODE_CHANGE_ID);
+
+ documentManager.move(sources, targets);
} finally {
if (documentManager != null) {
this.manager.release(documentManager);
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Paste.java Sat Apr 9 07:38:27 2005
@@ -20,6 +20,7 @@
import org.apache.lenya.cms.publication.DocumentBuildException;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.usecase.DocumentUsecase;
/**
@@ -85,7 +86,7 @@
DocumentManager documentManager = null;
try {
documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
- Document availableDocument = documentManager.getAvailableDocument(potentialDocument);
+ Document availableDocument = SiteUtil.getAvailableDocument(this.manager, potentialDocument);
if (clipboard.getMethod() == Clipboard.METHOD_COPY) {
documentManager.copyAll(clippedDocument, availableDocument);
Modified: lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java Sat Apr 9 07:38:27 2005
@@ -26,6 +26,7 @@
import org.apache.lenya.cms.publication.util.DocumentSet;
import org.apache.lenya.cms.publication.util.DocumentVisitor;
import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.usecase.DocumentUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.cms.workflow.WorkflowManager;
@@ -89,8 +90,6 @@
public void lockInvolvedObjects() throws UsecaseException {
super.lockInvolvedObjects();
- ServiceSelector selector = null;
- SiteManager siteManager = null;
try {
Document doc = getSourceDocument();
Document liveVersion = doc.getIdentityMap().getAreaVersion(doc, Publication.LIVE_AREA);
@@ -100,21 +99,12 @@
documents[i].lock();
}
- selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
- siteManager = (SiteManager) selector.select(doc.getPublication().getSiteManagerHint());
- siteManager.getSiteStructure(doc.getIdentityMap(),
+ SiteUtil.getSiteStructure(this.manager, doc.getIdentityMap(),
doc.getPublication(),
Publication.LIVE_AREA).lock();
} catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (selector != null) {
- if (siteManager != null) {
- selector.release(siteManager);
- }
- this.manager.release(selector);
- }
+ throw new UsecaseException(e);
}
}
Modified: lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java?view=diff&r1=160684&r2=160685
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java Sat Apr 9 07:38:27 2005
@@ -33,6 +33,7 @@
import org.apache.lenya.cms.publication.util.DocumentVisitor;
import org.apache.lenya.cms.publication.util.DocumentSet;
import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.usecase.DocumentUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.cms.usecase.scheduling.UsecaseScheduler;
@@ -69,8 +70,6 @@
public void lockInvolvedObjects() throws UsecaseException {
super.lockInvolvedObjects();
- ServiceSelector selector = null;
- SiteManager siteManager = null;
try {
Document doc = getSourceDocument();
DocumentSet set = getInvolvedDocuments(doc);
@@ -81,21 +80,13 @@
liveVersion.lock();
}
- selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
- siteManager = (SiteManager) selector.select(doc.getPublication().getSiteManagerHint());
- siteManager.getSiteStructure(doc.getIdentityMap(),
+ SiteUtil.getSiteStructure(this.manager,
+ doc.getIdentityMap(),
doc.getPublication(),
Publication.LIVE_AREA).lock();
} catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (selector != null) {
- if (siteManager != null) {
- selector.release(siteManager);
- }
- this.manager.release(selector);
- }
+ throw new UsecaseException(e);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org