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 2007/02/15 13:15:34 UTC
svn commit: r507914 [3/3] - in /lenya/trunk/src:
impl/java/org/apache/lenya/cms/publication/
impl/java/org/apache/lenya/cms/repository/
impl/test/org/apache/lenya/ac/impl/
impl/test/org/apache/lenya/cms/publication/
impl/test/org/apache/lenya/cms/publi...
Modified: lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java (original)
+++ lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java Thu Feb 15 04:15:30 2007
@@ -23,7 +23,6 @@
import java.io.OutputStream;
import org.apache.cocoon.servlet.multipart.Part;
-import org.apache.excalibur.source.ModifiableSource;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.RepositorySource;
import org.apache.lenya.cms.publication.Document;
@@ -55,10 +54,6 @@
if (getLogger().isDebugEnabled())
getLogger().debug("ODT::uploadODT() called");
Document source = getSourceDocument();
- String destination = source.getSourceURI();
- if (source.getSourceExtension().equals("xml")) {
- destination = destination.substring(0, destination.lastIndexOf(".xml")) + ODT_EXTENSION;
- }
Part file = getPart("file");
String mimeType = file.getMimeType();
@@ -67,7 +62,7 @@
String[] params = { Integer.toString(file.getSize()) };
addErrorMessage("upload-size-exceeded", params);
} else if (ODT_MIME_TYPE.equals(mimeType)){
- saveResource(destination, file);
+ saveResource(source.getOutputStream(), file);
} else {
addErrorMessage("The mime type of the document you want to upload does not match the mime type: \""+ODT_MIME_TYPE+"\"");
}
@@ -77,31 +72,19 @@
/**
* Saves the resource to a file.
*
- * @param destination
+ * @param out
* The destination to write the file.
* @param part
* The part of the multipart request.
* @throws IOException
* if an error occurs.
*/
- protected void saveResource(String destination, Part part)
+ protected void saveResource(OutputStream out, Part part)
throws IOException {
- OutputStream out = null;
InputStream in = null;
- SourceResolver resolver = null;
- ModifiableSource source = null;
-
try {
- resolver = (SourceResolver) this.manager
- .lookup(SourceResolver.ROLE);
- source = (ModifiableSource) resolver.resolveURI(destination);
- // now that the source is determined, lock involved nodes
- Node node = getRepositoryNode(destination);
- node.lock();
-
byte[] buf = new byte[4096];
- out = source.getOutputStream();
in = part.getInputStream();
int read = in.read(buf);
@@ -125,13 +108,6 @@
if (out != null) {
out.flush();
out.close();
- }
-
- if (resolver != null) {
- if (source != null) {
- resolver.release(source);
- }
- this.manager.release(resolver);
}
}
}
Modified: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java (original)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java Thu Feb 15 04:15:30 2007
@@ -20,15 +20,12 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.MetaDataException;
-import org.apache.lenya.cms.observation.RepositoryListener;
import org.apache.lenya.cms.rc.RCML;
import org.apache.lenya.cms.repo.Translation;
import org.apache.lenya.cms.repository.History;
@@ -189,26 +186,16 @@
return null;
}
- private Set listeners = new HashSet();
-
- public void addListener(RepositoryListener listener) throws RepositoryException {
- if (this.listeners.contains(listener)) {
- throw new RepositoryException("The listener [" + listener
- + "] is already registered for node [" + this + "]!");
- }
- this.listeners.add(listener);
- }
-
- public boolean isListenerRegistered(RepositoryListener listener) {
- return this.listeners.contains(listener);
- }
-
public RCML getRcml() {
return null;
}
public History getHistory() {
return null;
+ }
+
+ public void delete() throws RepositoryException {
+ registerRemoved();
}
}
Modified: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java (original)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java Thu Feb 15 04:15:30 2007
@@ -102,4 +102,8 @@
this.manager = manager;
}
+ public boolean isSharable() {
+ return false;
+ }
+
}
Modified: lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java (original)
+++ lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java Thu Feb 15 04:15:30 2007
@@ -34,7 +34,6 @@
import org.apache.cocoon.servlet.multipart.Part;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.apache.excalibur.source.ModifiableSource;
import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.TraversableSource;
import org.apache.lenya.cms.metadata.MetaData;
@@ -137,16 +136,12 @@
MetaData mediaMeta = null;
- SourceResolver resolver = null;
- ModifiableSource source = null;
OutputStream destOutputStream = null;
try {
mediaMeta = document.getMetaData("http://apache.org/lenya/metadata/media/1.0");
addResourceMeta(fileName, mimeType, input, mediaMeta);
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- source = (ModifiableSource) resolver.resolveURI(document.getSourceURI());
- destOutputStream = source.getOutputStream();
+ destOutputStream = document.getOutputStream();
IOUtils.write(sourceBos.toByteArray(), destOutputStream);
document.setMimeType(mimeType);
Modified: lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/ResourceWrapperTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/ResourceWrapperTest.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/ResourceWrapperTest.java (original)
+++ lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/ResourceWrapperTest.java Thu Feb 15 04:15:30 2007
@@ -26,10 +26,10 @@
import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.TraversableSource;
+import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.impl.AbstractAccessControlTest;
import org.apache.lenya.cms.metadata.MetaDataException;
import org.apache.lenya.cms.repository.RepositoryException;
-import org.apache.lenya.cms.repository.RepositoryUtil;
import org.apache.lenya.cms.repository.Session;
/**
@@ -37,7 +37,7 @@
*/
public class ResourceWrapperTest extends AbstractAccessControlTest {
- public static final String IMAGE_URL = "context://lenya/resources/images/project-logo.png";
+ protected static final String IMAGE_URL = "context://lenya/resources/images/project-logo.png";
/**
* @throws RepositoryException
@@ -46,18 +46,19 @@
* @throws MetaDataException
* @throws IOException
* @throws MalformedURLException
+ * @throws AccessControlException
*/
public void testResourceWrapper() throws RepositoryException, PublicationException,
- ServiceException, MalformedURLException, IOException, MetaDataException {
+ ServiceException, MalformedURLException, IOException, MetaDataException, AccessControlException {
- String documentId = "/testResource";
+ String path = "/testResource";
- Session session = RepositoryUtil.getSession(getManager(), getRequest());
+ Session session = login("lenya");
DocumentFactory factory = DocumentUtil.createDocumentFactory(getManager(), session);
Publication pub = getPublication("test");
- Document doc = createResource(factory, pub, documentId, getManager(), getLogger());
+ Document doc = createResource(factory, pub, path, getManager(), getLogger());
SourceResolver resolver = null;
TraversableSource source = null;
@@ -112,8 +113,6 @@
try {
docManager = (DocumentManager) manager.lookup(DocumentManager.ROLE);
- DocumentLocator loc = DocumentLocator.getLocator(pub.getId(),
- Publication.AUTHORING_AREA, path, pub.getDefaultLanguage());
pub.getArea(Publication.AUTHORING_AREA).getSite().getRepositoryNode().lock();
Modified: lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/ResourceLinkRewriterTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/ResourceLinkRewriterTest.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/ResourceLinkRewriterTest.java (original)
+++ lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/ResourceLinkRewriterTest.java Thu Feb 15 04:15:30 2007
@@ -21,7 +21,6 @@
import org.apache.lenya.cms.publication.DocumentUtil;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.ResourceWrapperTest;
-import org.apache.lenya.cms.repository.RepositoryUtil;
import org.apache.lenya.cms.repository.Session;
/**
@@ -36,7 +35,7 @@
public void testResourceLinkRewriting() throws Exception {
String documentId = "/testResourceLinkRewriting";
- Session session = RepositoryUtil.getSession(getManager(), getRequest());
+ Session session = login("lenya");
DocumentFactory factory = DocumentUtil.createDocumentFactory(getManager(), session);
Publication pub = getPublication("test");
Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/DefaultSiteTree.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/DefaultSiteTree.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/DefaultSiteTree.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/DefaultSiteTree.java Thu Feb 15 04:15:30 2007
@@ -29,11 +29,11 @@
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.lenya.cms.cocoon.source.RepositorySource;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.repository.NodeFactory;
+import org.apache.lenya.cms.repository.Session;
import org.apache.lenya.cms.site.Link;
import org.apache.lenya.cms.site.SiteException;
import org.apache.lenya.cms.site.SiteNode;
@@ -73,6 +73,8 @@
private Document document;
private DocumentFactory factory;
+ private org.apache.lenya.cms.repository.Node repositoryNode;
+
/**
* Create a DefaultSiteTree
* @param factory The document factory.
@@ -94,8 +96,10 @@
this.area = _area;
this.manager = manager;
try {
- this.document = SourceUtil.readDOM(this.sourceUri, this.manager);
- if (this.document == null) {
+ if (getRepositoryNode().exists()) {
+ this.document = DocumentHelper.readDocument(getRepositoryNode().getInputStream());
+ }
+ else {
getLogger().info("Empty sitetree will be created/initialized!");
this.document = createDocument();
}
@@ -106,7 +110,7 @@
protected void saveDocument() throws SiteException {
try {
- SourceUtil.writeDOM(this.document, this.sourceUri, this.manager);
+ DocumentHelper.writeDocument(this.document, getRepositoryNode().getOutputStream());
} catch (Exception e) {
throw new SiteException(e);
}
@@ -478,22 +482,23 @@
* @see org.apache.lenya.cms.site.SiteStructure#getRepositoryNode()
*/
public org.apache.lenya.cms.repository.Node getRepositoryNode() {
- SourceResolver resolver = null;
- RepositorySource source = null;
- try {
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- source = (RepositorySource) resolver.resolveURI(this.sourceUri);
- return source.getNode();
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (resolver != null) {
- if (source != null) {
- resolver.release(source);
+ if (this.repositoryNode == null) {
+ Session session = this.getPublication().getFactory().getSession();
+ NodeFactory factory = null;
+ try {
+ factory = (NodeFactory) manager.lookup(NodeFactory.ROLE);
+ factory.setSession(session);
+ this.repositoryNode = (org.apache.lenya.cms.repository.Node)
+ session.getRepositoryItem(factory, this.sourceUri);
+ } catch (Exception e) {
+ throw new RuntimeException("Creating repository node failed: ", e);
+ } finally {
+ if (factory != null) {
+ manager.release(factory);
}
- this.manager.release(resolver);
}
}
+ return this.repositoryNode;
}
protected void save() throws SiteException {
Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeFactory.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeFactory.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeFactory.java Thu Feb 15 04:15:30 2007
@@ -24,7 +24,6 @@
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentUtil;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationUtil;
import org.apache.lenya.cms.repository.RepositoryException;
import org.apache.lenya.cms.repository.RepositoryItem;
import org.apache.lenya.cms.repository.RepositoryItemFactory;
@@ -66,6 +65,10 @@
public String getItemType() {
return SiteTree.IDENTIFIABLE_TYPE;
+ }
+
+ public boolean isSharable() {
+ return true;
}
}
Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeFactory.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeFactory.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeFactory.java Thu Feb 15 04:15:30 2007
@@ -70,4 +70,8 @@
return SiteTree.IDENTIFIABLE_TYPE;
}
+ public boolean isSharable() {
+ return true;
+ }
+
}
Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java Thu Feb 15 04:15:30 2007
@@ -18,6 +18,7 @@
package org.apache.lenya.cms.site.tree2;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -25,13 +26,15 @@
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.lenya.cms.cocoon.source.RepositorySource;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
import org.apache.lenya.cms.publication.Area;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.repository.NodeFactory;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
import org.apache.lenya.cms.site.Link;
import org.apache.lenya.cms.site.SiteException;
import org.apache.lenya.cms.site.SiteNode;
@@ -60,6 +63,10 @@
ContainerUtil.enableLogging(this, logger);
this.area = area;
this.manager = manager;
+ initRoot();
+ }
+
+ protected void initRoot() {
this.root = new RootNode(this, getLogger());
nodeAdded(root);
}
@@ -74,30 +81,47 @@
return this.sourceUri;
}
- private boolean loaded = false;
+ private long lastModified = -1;
+ private boolean loading = false;
protected static final String NAMESPACE = "http://apache.org/cocoon/lenya/sitetree/1.0";
private static final boolean DEFAULT_VISIBILITY = true;
- protected void load() {
+ protected synchronized void load() {
try {
- if (!loaded) {
- if (SourceUtil.exists(getSourceUri(), this.manager)) {
- org.w3c.dom.Document xml = SourceUtil.readDOM(getSourceUri(), this.manager);
- NamespaceHelper helper = new NamespaceHelper(NAMESPACE, "", xml);
- Assert.isTrue("document element is site", xml.getDocumentElement()
- .getLocalName().equals("site"));
- loadNodes(getRoot(), helper, xml.getDocumentElement());
- }
- loaded = true;
+ Node repoNode = getRepositoryNode();
+ if (repoNode.exists() && repoNode.getLastModified() > this.lastModified) {
+ long lastModified = repoNode.getLastModified();
+ org.w3c.dom.Document xml = DocumentHelper.readDocument(repoNode.getInputStream());
+ NamespaceHelper helper = new NamespaceHelper(NAMESPACE, "", xml);
+ Assert.isTrue("document element is site", xml.getDocumentElement().getLocalName()
+ .equals("site"));
+ this.loading = true;
+ reset();
+ loadNodes(this.root, helper, xml.getDocumentElement());
+ this.loading = false;
+ this.lastModified = lastModified;
+ }
+
+ if (!repoNode.exists() && this.lastModified > -1) {
+ reset();
+ this.lastModified = -1;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
+ checkInvariants();
+ }
+
+ protected void reset() {
+ this.path2node.clear();
+ this.uuidLanguage2link.clear();
+ initRoot();
}
protected RootNode getRoot() {
+ load();
return this.root;
}
@@ -130,13 +154,20 @@
}
protected void save() {
- if (!loaded) {
+ if (loading) {
return;
}
try {
+ Node repoNode = getRepositoryNode();
+ if (repoNode.exists() && repoNode.getLastModified() > this.lastModified) {
+ throw new RuntimeException("The sitetree repository node has been modified!");
+ }
NamespaceHelper helper = new NamespaceHelper(NAMESPACE, "", "site");
saveNodes(getRoot(), helper, helper.getDocument().getDocumentElement());
- SourceUtil.writeDOM(helper.getDocument(), getSourceUri(), this.manager);
+ helper.save(repoNode.getOutputStream());
+ this.lastModified = repoNode.getLastModified();
+ } catch (RuntimeException e) {
+ throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -231,7 +262,12 @@
private Map uuidLanguage2link = new HashMap();
protected void nodeAdded(SiteNode node) {
- this.path2node.put(node.getPath(), node);
+ String path = node.getPath();
+ Assert.notNull("path", path);
+ if (node != this.root) {
+ Assert.isTrue("path not empty", path.length() > 0);
+ }
+ this.path2node.put(path, node);
}
protected void linkAdded(Link link) {
@@ -306,6 +342,32 @@
return (Link) getUuidLanguage2Link().get(key);
}
+ protected void checkInvariants() {
+ if (true) {
+ return;
+ }
+ for (Iterator paths = this.path2node.keySet().iterator(); paths.hasNext();) {
+ String path = (String) paths.next();
+ SiteNode node = (SiteNode) this.path2node.get(path);
+ String uuid = node.getUuid();
+ if (uuid != null) {
+ String[] langs = node.getLanguages();
+ for (int i = 0; i < langs.length; i++) {
+ String key = getKey(uuid, langs[i]);
+ Assert.isTrue("contains link for [" + key + "]", this.uuidLanguage2link
+ .containsKey(key));
+ }
+ }
+ }
+ for (Iterator keys = this.uuidLanguage2link.keySet().iterator(); keys.hasNext();) {
+ String key = (String) keys.next();
+ Link link = (Link) this.uuidLanguage2link.get(key);
+ Assert.isTrue("contains path for [" + key + "]", this.path2node.containsKey(link
+ .getNode().getPath()));
+ }
+
+ }
+
public SiteNode getNode(String path) throws SiteException {
Assert.notNull("path", path);
if (!getPath2Node().containsKey(path)) {
@@ -321,29 +383,46 @@
public Publication getPublication() {
return this.area.getPublication();
}
-
- private Node repositoryNode;
-
- public Node getRepositoryNode() {
- if (this.repositoryNode == null) {
- SourceResolver resolver = null;
- RepositorySource source = null;
+
+ protected Session getSession() {
+ Session areaSession = this.area.getPublication().getFactory().getSession();
+
+ // if the session which the sitetree originates from is modifiable, we use this one
+ if (areaSession.isModifiable()) {
+ return areaSession;
+ }
+
+ // otherwise, we have to use the current request's session, not the SharedItemStore
+ else {
+ ContextUtility ctxUtil = null;
try {
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- source = (RepositorySource) resolver.resolveURI(getSourceUri());
- this.repositoryNode = source.getNode();
+ ctxUtil = (ContextUtility) this.manager.lookup(ContextUtility.ROLE);
+ Request req = ctxUtil.getRequest();
+ return RepositoryUtil.getSession(this.manager, req);
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new RuntimeException("Creating repository node failed: ", e);
} finally {
- if (resolver != null) {
- if (source != null) {
- resolver.release(source);
- }
- this.manager.release(resolver);
+ if (ctxUtil != null) {
+ this.manager.release(ctxUtil);
}
}
}
- return this.repositoryNode;
+ }
+
+ public Node getRepositoryNode() {
+ NodeFactory factory = null;
+ try {
+ Session session = getSession();
+ factory = (NodeFactory) manager.lookup(NodeFactory.ROLE);
+ factory.setSession(session);
+ return (Node) session.getRepositoryItem(factory, getSourceUri());
+ } catch (Exception e) {
+ throw new RuntimeException("Creating repository node failed: ", e);
+ } finally {
+ if (factory != null) {
+ manager.release(factory);
+ }
+ }
}
public SiteNode[] getTopLevelNodes() {
@@ -371,15 +450,31 @@
public void moveDown(String path) throws SiteException {
TreeNode node = getTreeNode(path);
- TreeNode parent = (TreeNode) node.getParent();
+ TreeNode parent = getParent(node);
parent.moveDown(node.getName());
-
+
}
public void moveUp(String path) throws SiteException {
TreeNode node = getTreeNode(path);
- TreeNode parent = (TreeNode) node.getParent();
+ TreeNode parent = getParent(node);
parent.moveUp(node.getName());
+ }
+
+ /**
+ * @param node A node.
+ * @return The parent of the node, which is the root node for top level nodes.
+ * @throws SiteException if an error occurs.
+ */
+ protected TreeNode getParent(TreeNode node) throws SiteException {
+ TreeNode parent;
+ if (node.isTopLevel()) {
+ parent = getRoot();
+ }
+ else {
+ parent = (TreeNode) node.getParent();;
+ }
+ return parent;
}
public boolean contains(String path, String language) {
Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/TreeNodeImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/TreeNodeImpl.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/TreeNodeImpl.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/TreeNodeImpl.java Thu Feb 15 04:15:30 2007
@@ -68,7 +68,24 @@
if (this.language2link.keySet().size() > 0) {
throw new RuntimeException("Can't set the UUID if the node has links.");
}
+
+ if (this.uuid != null) {
+ String[] languages = getLanguages();
+ for (int i = 0; i < languages.length; i++) {
+ getTree().linkRemoved(this.uuid, languages[i]);
+ }
+ }
+
this.uuid = uuid;
+
+ String[] languages = getLanguages();
+ for (int i = 0; i < languages.length; i++) {
+ try {
+ getTree().linkAdded(getLink(languages[i]));
+ } catch (SiteException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
public void delete() {
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java Thu Feb 15 04:15:30 2007
@@ -398,10 +398,7 @@
throw new RepositoryException("The node [" + this + "] does not exist!");
}
- long contentLastModified = 0;
- if (this.contentSource.exists()) {
- contentLastModified = this.contentSource.getLastModified();
- }
+ long contentLastModified = this.contentSource.getLastModified();
long metaLastModified = 0;
if (this.metaSource.exists()) {
metaLastModified = this.metaSource.getLastModified();
@@ -421,6 +418,10 @@
public void saveTransactionable() throws TransactionException {
this.contentSource.saveTransactionable();
this.metaSource.saveTransactionable();
+ }
+
+ public void delete() throws RepositoryException {
+ registerRemoved();
}
}
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeFactory.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeFactory.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeFactory.java Thu Feb 15 04:15:30 2007
@@ -66,4 +66,8 @@
this.manager = manager;
}
+ public boolean isSharable() {
+ return false;
+ }
+
}
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaDataHandler.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaDataHandler.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaDataHandler.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaDataHandler.java Thu Feb 15 04:15:30 2007
@@ -102,7 +102,7 @@
protected static final String ELEMENT_VALUE = "value";
protected static final String ATTRIBUTE_NAMESPACE = "namespace";
protected static final String ATTRIBUTE_KEY = "key";
-
+
protected void loadMetaData() throws MetaDataException {
if (this.namespace2metamap != null) {
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceWrapper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceWrapper.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceWrapper.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceWrapper.java Thu Feb 15 04:15:30 2007
@@ -187,7 +187,9 @@
* @see org.apache.lenya.cms.repository.Node#exists()
*/
public boolean exists() throws RepositoryException {
- loadData();
+ if (this.data == null) {
+ loadData();
+ }
return this.data != null;
}
@@ -197,6 +199,10 @@
* @throws RepositoryException if an error occurs.
*/
protected synchronized void loadData() throws RepositoryException {
+
+ if (this.data != null) {
+ return;
+ }
ByteArrayOutputStream out = null;
InputStream in = null;
Modified: lenya/trunk/src/modules/tinymce/java/src/org/apache/lenya/cms/editors/tinymce/TinyMce.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/tinymce/java/src/org/apache/lenya/cms/editors/tinymce/TinyMce.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/tinymce/java/src/org/apache/lenya/cms/editors/tinymce/TinyMce.java (original)
+++ lenya/trunk/src/modules/tinymce/java/src/org/apache/lenya/cms/editors/tinymce/TinyMce.java Thu Feb 15 04:15:30 2007
@@ -23,17 +23,15 @@
package org.apache.lenya.cms.editors.tinymce;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
+
import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.environment.Request;
-import org.apache.excalibur.source.ModifiableSource;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
-import org.apache.lenya.cms.metadata.dublincore.DublinCoreHelper;
import org.apache.lenya.cms.publication.ResourceType;
import org.apache.lenya.cms.usecase.DocumentUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
@@ -125,18 +123,16 @@
* @throws Exception if an error occurs.
*/
protected void saveDocument(String encoding, String content) throws Exception {
- ModifiableSource xmlSource = null;
SourceResolver resolver = null;
Source indexSource = null;
try {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- xmlSource = (ModifiableSource) resolver.resolveURI(getSourceDocument().getSourceURI());
- saveXMLFile(encoding, content, xmlSource);
+ saveXMLFile(encoding, content, getSourceDocument());
Document xmlDoc = null;
try {
- xmlDoc = DocumentHelper.readDocument(xmlSource.getInputStream());
+ xmlDoc = DocumentHelper.readDocument(getSourceDocument().getInputStream());
} catch (SAXException e) {
addErrorMessage("error-document-form", new String[] { e.getMessage() });
}
@@ -156,9 +152,6 @@
} finally {
if (resolver != null) {
- if (xmlSource != null) {
- resolver.release(xmlSource);
- }
if (indexSource != null) {
resolver.release(indexSource);
}
@@ -171,18 +164,19 @@
* Save the XML file
* @param encoding The encoding
* @param content The content
- * @param xmlSource The source
+ * @param document The source
* @throws FileNotFoundException if the file was not found
* @throws UnsupportedEncodingException if the encoding is not supported
* @throws IOException if an IO error occurs
*/
- private void saveXMLFile(String encoding, String content, ModifiableSource xmlSource)
+ private void saveXMLFile(String encoding, String content,
+ org.apache.lenya.cms.publication.Document document)
throws FileNotFoundException, UnsupportedEncodingException, IOException {
// FileOutputStream fileoutstream = null;
Writer writer = null;
try {
- writer = new OutputStreamWriter(xmlSource.getOutputStream(), encoding);
+ writer = new OutputStreamWriter(document.getOutputStream(), encoding);
writer.write(content, 0, content.length());
} catch (FileNotFoundException e) {
getLogger().error("File not found " + e.toString());
Modified: lenya/trunk/src/modules/usecasedocument/java/src/org/apache/lenya/cms/cocoon/components/modules/input/UsecaseDocumentModule.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/usecasedocument/java/src/org/apache/lenya/cms/cocoon/components/modules/input/UsecaseDocumentModule.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/usecasedocument/java/src/org/apache/lenya/cms/cocoon/components/modules/input/UsecaseDocumentModule.java (original)
+++ lenya/trunk/src/modules/usecasedocument/java/src/org/apache/lenya/cms/cocoon/components/modules/input/UsecaseDocumentModule.java Thu Feb 15 04:15:30 2007
@@ -27,10 +27,10 @@
import org.apache.cocoon.components.modules.input.AbstractInputModule;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentUtil;
import org.apache.lenya.cms.site.usecases.CreateUsecaseDocument;
+import org.apache.lenya.xml.DocumentHelper;
/**
* Module to retrieve information from a usecase resource type document.
@@ -47,7 +47,7 @@
if (name.equals(USECASE)) {
Request request = ObjectModelHelper.getRequest(objectModel);
Document doc = DocumentUtil.getCurrentDocument(this.manager, request);
- org.w3c.dom.Document xmlDoc = SourceUtil.readDOM(doc.getSourceURI(), this.manager);
+ org.w3c.dom.Document xmlDoc = DocumentHelper.readDocument(doc.getInputStream());
String usecaseName = xmlDoc.getDocumentElement().getAttribute(CreateUsecaseDocument.ATTRIBUTE_NAME);
value = usecaseName;
}
Modified: lenya/trunk/src/modules/usecasedocument/java/src/org/apache/lenya/cms/site/usecases/CreateUsecaseDocument.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/usecasedocument/java/src/org/apache/lenya/cms/site/usecases/CreateUsecaseDocument.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/usecasedocument/java/src/org/apache/lenya/cms/site/usecases/CreateUsecaseDocument.java (original)
+++ lenya/trunk/src/modules/usecasedocument/java/src/org/apache/lenya/cms/site/usecases/CreateUsecaseDocument.java Thu Feb 15 04:15:30 2007
@@ -19,8 +19,8 @@
import java.util.Arrays;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.usecase.UsecaseResolver;
+import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.NamespaceHelper;
import org.w3c.dom.Element;
@@ -86,7 +86,7 @@
NamespaceHelper helper = new NamespaceHelper(NAMESPACE, "", ELEMENT_USECASE);
Element usecaseElement = helper.getDocument().getDocumentElement();
usecaseElement.setAttribute(ATTRIBUTE_NAME, getParameterAsString(USECASE));
- SourceUtil.writeDOM(helper.getDocument(), getNewDocument().getSourceURI(), this.manager);
+ DocumentHelper.writeDocument(helper.getDocument(), getNewDocument().getOutputStream());
}
Modified: lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java (original)
+++ lenya/trunk/src/modules/webdav/java/src/org/apache/lenya/cms/usecases/webdav/Put.java Thu Feb 15 04:15:30 2007
@@ -31,7 +31,6 @@
import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.MetaDataException;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
-import org.apache.lenya.cms.metadata.dublincore.DublinCoreHelper;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentManager;
@@ -48,6 +47,7 @@
import org.apache.lenya.cms.usecase.xml.UsecaseErrorHandler;
import org.apache.lenya.cms.workflow.WorkflowUtil;
import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper;
+import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.Schema;
import org.apache.lenya.xml.ValidationUtil;
@@ -87,8 +87,6 @@
}
protected void doCheckExecutionConditions() throws Exception {
- super.doCheckExecutionConditions();
-
String event = getParameterAsString(EVENT);
if (event != null) {
Document doc = getSourceDocument();
@@ -154,7 +152,7 @@
if (!hasErrors()) {
try {
- SourceUtil.writeDOM(xmlDoc, doc.getSourceURI(), this.manager);
+ DocumentHelper.writeDocument(xmlDoc, doc.getOutputStream());
} catch (Exception e) {
addErrorMessage("invalid source xml. Full exception: " + e);
}
Added: lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/shared-item-store.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/shared-item-store.xconf?view=auto&rev=507914
==============================================================================
--- lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/shared-item-store.xconf (added)
+++ lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/shared-item-store.xconf Thu Feb 15 04:15:30 2007
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+ This file defines the publication specific use-cases
+-->
+
+ <xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.cms.repository.SharedItemStore']">
+ <component role="org.apache.lenya.cms.repository.SharedItemStore"
+ logger="lenya.cocoon.components"
+ class="org.apache.lenya.cms.repository.SharedItemStoreImpl"/>
+ </xconf>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org