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 [2/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/java/org/apache/lenya/cms/repository/RepositoryUtil.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java Thu Feb 15 04:15:30 2007
@@ -35,12 +35,12 @@
*/
public static Session getSession(ServiceManager manager, Request request)
throws RepositoryException {
- org.apache.cocoon.environment.Session cocoonSession = request.getSession();
- Session session = (Session) cocoonSession.getAttribute(Session.class.getName());
+ Session session = (Session) request.getAttribute(Session.class.getName());
if (session == null) {
Identity identity = getIdentity(request);
- session = createSession(manager, identity);
- cocoonSession.setAttribute(Session.class.getName(), session);
+ // attach a read-only repository session to the HTTP request
+ session = createSession(manager, identity, false);
+ request.setAttribute(Session.class.getName(), session);
} else if (session.getIdentity() == null) {
Identity identity = getIdentity(request);
if (identity != null) {
@@ -60,16 +60,17 @@
* Creates a session.
* @param manager The service manager.
* @param identity The identity.
+ * @param modifiable Determines if the repository items in this session should be modifiable.
* @return a session.
* @throws RepositoryException if an error occurs.
*/
- public static Session createSession(ServiceManager manager, Identity identity)
+ public static Session createSession(ServiceManager manager, Identity identity, boolean modifiable)
throws RepositoryException {
RepositoryManager repoMgr = null;
Session session;
try {
repoMgr = (RepositoryManager) manager.lookup(RepositoryManager.ROLE);
- session = repoMgr.createSession(identity);
+ session = repoMgr.createSession(identity, modifiable);
} catch (Exception e) {
throw new RepositoryException(e);
} finally {
@@ -84,10 +85,13 @@
* @param request The current request.
*/
public static void removeSession(ServiceManager manager, Request request) {
+ request.removeAttribute(Session.class.getName());
+ /*
org.apache.cocoon.environment.Session session = request.getSession(false);
if (session != null) {
session.removeAttribute(Session.class.getName());
}
+ */
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repository/Session.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/Session.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/Session.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/Session.java Thu Feb 15 04:15:30 2007
@@ -70,5 +70,15 @@
* @param event The event to add to the queue.
*/
void enqueueEvent(RepositoryEvent event);
-
+
+ /**
+ * @param identity The identity.
+ */
+ void setIdentity(Identity identity);
+
+ /**
+ * @return if the repository items in this session can be modified.
+ */
+ boolean isModifiable();
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repository/SessionImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/SessionImpl.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/SessionImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/SessionImpl.java Thu Feb 15 04:15:30 2007
@@ -26,12 +26,14 @@
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.lenya.ac.Identity;
import org.apache.lenya.cms.observation.ObservationRegistry;
import org.apache.lenya.cms.observation.RepositoryEvent;
import org.apache.lenya.cms.observation.RepositoryListener;
import org.apache.lenya.transaction.IdentityMap;
+import org.apache.lenya.transaction.IdentityMapImpl;
import org.apache.lenya.transaction.Lock;
import org.apache.lenya.transaction.Lockable;
import org.apache.lenya.transaction.TransactionException;
@@ -46,47 +48,57 @@
public class SessionImpl extends AbstractLogEnabled implements Session {
private ServiceManager manager;
-
+ private Identity identity;
+
/**
* Ctor.
- * @param map The identity map.
* @param identity The identity.
+ * @param modifiable Determins if the repository items in this session can be modified.
* @param manager The service manager.
* @param logger The logger.
*/
- public SessionImpl(IdentityMap map, Identity identity, ServiceManager manager, Logger logger) {
-
- Assert.notNull("identity map", map);
-
- this.manager = manager;
- this.unitOfWork = new UnitOfWorkImpl(map, identity, logger);
- this.unitOfWork.setIdentity(identity);
+ public SessionImpl(Identity identity, boolean modifiable, ServiceManager manager, Logger logger) {
+
ContainerUtil.enableLogging(this, logger);
-
+
+ Assert.notNull("service manager", manager);
+ this.manager = manager;
+
+ this.identityMap = new IdentityMapImpl(logger);
+
+ this.identity = identity;
+
ObservationRegistry registry = null;
try {
registry = (ObservationRegistry) this.manager.lookup(ObservationRegistry.ROLE);
addListener(registry);
} catch (Exception e) {
throw new RuntimeException(e);
- }
- finally {
+ } finally {
if (registry != null) {
this.manager.release(registry);
}
}
+
+ if (modifiable) {
+ this.unitOfWork = new UnitOfWorkImpl(this.identityMap, this.identity, getLogger());
+ }
}
public Identity getIdentity() {
- return getUnitOfWork().getIdentity();
+ return this.identity;
}
private UnitOfWork unitOfWork;
+ private SharedItemStore sharedItemStore;
/**
* @return The unit of work.
*/
protected UnitOfWork getUnitOfWork() {
+ if (this.unitOfWork == null) {
+ throw new RuntimeException("This session is not modifiable!");
+ }
return this.unitOfWork;
}
@@ -95,16 +107,16 @@
* @throws RepositoryException if an error occurs.
*/
public void commit() throws RepositoryException {
-
+
try {
getUnitOfWork().commit();
} catch (TransactionException e) {
throw new RepositoryException(e);
}
-
- for (Iterator i = this.events.iterator(); i.hasNext(); ) {
+
+ for (Iterator i = this.events.iterator(); i.hasNext();) {
RepositoryEvent event = (RepositoryEvent) i.next();
- for (Iterator l = this.listeners.iterator(); l.hasNext(); ) {
+ for (Iterator l = this.listeners.iterator(); l.hasNext();) {
RepositoryListener listener = (RepositoryListener) l.next();
listener.eventFired(event);
}
@@ -124,6 +136,17 @@
}
this.events.clear();
}
+
+ protected SharedItemStore getSharedItemStore() {
+ if (this.sharedItemStore == null) {
+ try {
+ this.sharedItemStore = (SharedItemStore) this.manager.lookup(SharedItemStore.ROLE);
+ } catch (ServiceException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return this.sharedItemStore;
+ }
/**
* @see org.apache.lenya.cms.repository.Session#getRepositoryItem(org.apache.lenya.cms.repository.RepositoryItemFactory,
@@ -131,11 +154,16 @@
*/
public RepositoryItem getRepositoryItem(RepositoryItemFactory factory, String key)
throws RepositoryException {
- RepositoryItemFactoryWrapper wrapper = new RepositoryItemFactoryWrapper(factory, this);
- return (RepositoryItem) ((UnitOfWorkImpl) getUnitOfWork()).getIdentityMap().get(wrapper,
- key);
+
+ if (!isModifiable() && factory.isSharable()) {
+ return getSharedItemStore().getRepositoryItem(factory, key);
+ }
+ else {
+ RepositoryItemFactoryWrapper wrapper = new RepositoryItemFactoryWrapper(factory, this);
+ return (RepositoryItem) getIdentityMap().get(wrapper, key);
+ }
}
-
+
public void registerNew(Transactionable object) throws TransactionException {
getUnitOfWork().registerNew(object);
}
@@ -148,8 +176,11 @@
getUnitOfWork().registerRemoved(object);
}
+ /**
+ * @param identity The identity.
+ */
public void setIdentity(Identity identity) {
- getUnitOfWork().setIdentity(identity);
+ this.identity = identity;
}
public boolean isDirty(Transactionable transactionable) {
@@ -179,10 +210,22 @@
}
private List events = new ArrayList();
-
+ private IdentityMap identityMap;
+
public void enqueueEvent(RepositoryEvent event) {
+ if (!isModifiable()) {
+ throw new RuntimeException("Can't enqueue event in unmodifiable session!");
+ }
Assert.isTrue("event belongs to session", event.getSession() == this);
this.events.add(event);
+ }
+
+ protected IdentityMap getIdentityMap() {
+ return this.identityMap;
+ }
+
+ public boolean isModifiable() {
+ return this.unitOfWork != null;
}
}
Added: lenya/trunk/src/java/org/apache/lenya/cms/repository/SharedItemStore.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/SharedItemStore.java?view=auto&rev=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/SharedItemStore.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/SharedItemStore.java Thu Feb 15 04:15:30 2007
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.lenya.cms.repository;
+
+/**
+ * Store for read-only items which are shared by all sessions for performance reasons.
+ */
+public interface SharedItemStore extends Session {
+
+ /**
+ * The service role.
+ */
+ String ROLE = SharedItemStore.class.getName();
+
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java Thu Feb 15 04:15:30 2007
@@ -20,10 +20,8 @@
import java.util.HashSet;
import java.util.Set;
-import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceSelector;
-import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuilder;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentLocator;
@@ -119,7 +117,7 @@
Publication pub = factory.getPublication(info.getPublicationId());
if (pub.exists()) {
DocumentBuilder builder = pub.getDocumentBuilder();
- return builder.isDocument(webappUrl);
+ return builder.isDocument(factory, webappUrl);
}
return false;
} catch (SiteException e) {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java Thu Feb 15 04:15:30 2007
@@ -28,7 +28,6 @@
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuildException;
import org.apache.lenya.cms.publication.DocumentException;
@@ -134,7 +133,7 @@
*/
public boolean exists() throws DocumentException {
try {
- return SourceUtil.exists(getDelegate().getSourceURI(), this.manager);
+ return getDelegate().exists();
} catch (Exception e) {
throw new DocumentException(e);
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStoreFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStoreFactory.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStoreFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStoreFactory.java Thu Feb 15 04:15:30 2007
@@ -79,4 +79,8 @@
return store;
}
+ public boolean isSharable() {
+ return false;
+ }
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWork.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWork.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWork.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWork.java Thu Feb 15 04:15:30 2007
@@ -67,16 +67,6 @@
void rollback() throws TransactionException;
/**
- * @return The identity.
- */
- Identity getIdentity();
-
- /**
- * @param identity The identity.
- */
- void setIdentity(Identity identity);
-
- /**
* @param transactionable A transactionable.
* @return If the transactionable is registered as dirty.
*/
Modified: lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java Thu Feb 15 04:15:30 2007
@@ -61,24 +61,6 @@
return this.identityMap;
}
- private boolean isTransaction = false;
-
- /**
- * This starts the actual transaction. The unit of work starts to use a distinct identity map.
- */
- public void startTransaction() {
- this.identityMap = new IdentityMapImpl(getLogger());
- this.identityMap.setUnitOfWork(this);
- this.isTransaction = true;
- }
-
- /**
- * @return if the unit of work is in a transaction.
- */
- public boolean isTransaction() {
- return this.isTransaction;
- }
-
private Set newObjects = new HashSet();
private Set modifiedObjects = new HashSet();
private Set removedObjects = new HashSet();
@@ -165,26 +147,24 @@
}
}
}
+
+ resetTransaction();
}
+ protected void resetTransaction() {
+ this.modifiedObjects.clear();
+ this.newObjects.clear();
+ this.removedObjects.clear();
+ }
+
private Identity identity;
- /**
- * @see org.apache.lenya.transaction.UnitOfWork#getIdentity()
- */
- public Identity getIdentity() {
+ protected Identity getIdentity() {
return this.identity;
}
/**
- * @see org.apache.lenya.transaction.UnitOfWork#setIdentity(org.apache.lenya.ac.Identity)
- */
- public void setIdentity(Identity identity) {
- this.identity = identity;
- }
-
- /**
* @see org.apache.lenya.transaction.UnitOfWork#isDirty(org.apache.lenya.transaction.Transactionable)
*/
public boolean isDirty(Transactionable transactionable) {
@@ -212,6 +192,7 @@
}
}
}
+ resetTransaction();
}
private Map locks = new HashMap();
Modified: lenya/trunk/src/java/org/apache/lenya/xml/ValidationUtil.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/xml/ValidationUtil.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/xml/ValidationUtil.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/xml/ValidationUtil.java Thu Feb 15 04:15:30 2007
@@ -20,7 +20,6 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.components.validation.Validator;
import org.apache.cocoon.xml.dom.DOMStreamer;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.Document;
import org.xml.sax.ContentHandler;
import org.xml.sax.ErrorHandler;
@@ -39,7 +38,7 @@
public static void validate(ServiceManager manager, Document document, ErrorHandler handler)
throws Exception {
- org.w3c.dom.Document xmlDoc = SourceUtil.readDOM(document.getSourceURI(), manager);
+ org.w3c.dom.Document xmlDoc = DocumentHelper.readDocument(document.getInputStream());
validate(manager, xmlDoc, document.getResourceType().getSchema(), handler);
}
Modified: lenya/trunk/src/modules-core/ac/java/test/org/apache/lenya/ac/impl/IdentityTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac/java/test/org/apache/lenya/ac/impl/IdentityTest.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/ac/java/test/org/apache/lenya/ac/impl/IdentityTest.java (original)
+++ lenya/trunk/src/modules-core/ac/java/test/org/apache/lenya/ac/impl/IdentityTest.java Thu Feb 15 04:15:30 2007
@@ -50,9 +50,9 @@
* @throws Exception if an error occurs.
*/
public void testBelongsTo() throws Exception {
- AccreditableManager testMgr = getAccessController("test").getAccreditableManager();
- AccreditableManager defaultMgr = getAccessController("default").getAccreditableManager();
- AccreditableManager blogMgr = getAccessController("blog").getAccreditableManager();
+ AccreditableManager testMgr = getAccessController(getSession(), "test").getAccreditableManager();
+ AccreditableManager defaultMgr = getAccessController(getSession(), "default").getAccreditableManager();
+ AccreditableManager blogMgr = getAccessController(getSession(), "blog").getAccreditableManager();
String userId = "lenya";
User testUser = testMgr.getUserManager().getUser(userId);
Modified: lenya/trunk/src/modules-core/acusecases/test/canoo/test.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/acusecases/test/canoo/test.xml?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/acusecases/test/canoo/test.xml (original)
+++ lenya/trunk/src/modules-core/acusecases/test/canoo/test.xml Thu Feb 15 04:15:30 2007
@@ -21,8 +21,6 @@
<import file="${webtest.home}/lib/taskdef.xml"/>
<target name="main">
-
- <echo>Using WebTest home: ${webtest.home}</echo>
<webtest name="myTest">
<config
host="localhost"
Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/ContentLinkManager.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/ContentLinkManager.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/ContentLinkManager.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/ContentLinkManager.java Thu Feb 15 04:15:30 2007
@@ -24,8 +24,8 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.xml.DocumentHelper;
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
@@ -47,7 +47,7 @@
try {
String[] xPaths = source.getResourceType().getLinkAttributeXPaths();
if (xPaths.length > 0) {
- org.w3c.dom.Document xml = SourceUtil.readDOM(source.getSourceURI(), this.manager);
+ org.w3c.dom.Document xml = DocumentHelper.readDocument(source.getInputStream());
for (int i = 0; i < xPaths.length; i++) {
NodeIterator iter = XPathAPI.selectNodeIterator(xml, xPaths[i]);
Node node;
Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java Thu Feb 15 04:15:30 2007
@@ -21,11 +21,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.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.xml.DocumentHelper;
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
@@ -78,8 +78,7 @@
linkResolver = (LinkResolver) this.manager.lookup(LinkResolver.ROLE);
DocumentFactory factory = examinedDocument.getFactory();
- org.w3c.dom.Document xmlDocument = SourceUtil.readDOM(examinedDocument
- .getSourceURI(), this.manager);
+ org.w3c.dom.Document xmlDocument = DocumentHelper.readDocument(examinedDocument.getInputStream());
for (int xPathIndex = 0; xPathIndex < xPaths.length; xPathIndex++) {
if (getLogger().isDebugEnabled()) {
@@ -122,12 +121,11 @@
}
if (linksRewritten) {
- SourceUtil.writeDOM(xmlDocument, examinedDocument.getSourceURI(), this.manager);
+ DocumentHelper.writeDocument(xmlDocument, examinedDocument.getOutputStream());
}
}
} catch (Exception e) {
- throw new RuntimeException("Error rewriting document: [" + examinedDocument
- + "] - source URI: [" + examinedDocument.getSourceURI() + "]", e);
+ throw new RuntimeException("Error rewriting document: [" + examinedDocument + "]", e);
} finally {
if (linkResolver != null) {
this.manager.release(linkResolver);
Modified: lenya/trunk/src/modules-core/observation/java/test/org/apache/lenya/cms/observation/ObservationTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/observation/java/test/org/apache/lenya/cms/observation/ObservationTest.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/observation/java/test/org/apache/lenya/cms/observation/ObservationTest.java (original)
+++ lenya/trunk/src/modules-core/observation/java/test/org/apache/lenya/cms/observation/ObservationTest.java Thu Feb 15 04:15:30 2007
@@ -18,13 +18,11 @@
package org.apache.lenya.cms.observation;
import org.apache.lenya.ac.impl.AbstractAccessControlTest;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentManager;
import org.apache.lenya.cms.publication.DocumentUtil;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.repository.RepositoryUtil;
import org.apache.lenya.cms.repository.Session;
import org.apache.lenya.cms.site.SiteStructure;
import org.apache.lenya.xml.NamespaceHelper;
@@ -32,9 +30,6 @@
public class ObservationTest extends AbstractAccessControlTest {
public void testObservation() throws Exception {
- login("lenya");
- Session session = RepositoryUtil.getSession(getManager(), getRequest());
- DocumentFactory factory = DocumentUtil.createDocumentFactory(getManager(), session);
Publication publication = getPublication("test");
SiteStructure site = publication.getArea("authoring").getSite();
@@ -80,7 +75,7 @@
protected void testChanged(Document doc, TestListener listener) throws Exception {
listener.reset();
NamespaceHelper xml = new NamespaceHelper("http://apache.org/lenya/test", "", "test");
- SourceUtil.writeDOM(xml.getDocument(), doc.getSourceURI(), getManager());
+ xml.save(doc.getOutputStream());
assertFalse(listener.wasChanged());
doc.getRepositoryNode().getSession().commit();
Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/AbstractUsecase.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/AbstractUsecase.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/AbstractUsecase.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/AbstractUsecase.java Thu Feb 15 04:15:30 2007
@@ -55,24 +55,34 @@
public class AbstractUsecase extends AbstractLogEnabled implements Usecase, Configurable,
Contextualizable, Serviceable, Initializable {
- protected static final String PARAMETERS_INITIALIZED = "private.parametersInitialized";
+ protected static final StateMachine.Transition[] TRANSITIONS = {
+ new StateMachine.Transition("start", "preChecked", "checkPreconditions"),
+ new StateMachine.Transition("preChecked", "nodesLocked", "lockInvolvedObjects"),
+ new StateMachine.Transition("nodesLocked", "execChecked", "checkExecutionConditions"),
+ new StateMachine.Transition("execChecked", "execChecked", "checkExecutionConditions"),
+ new StateMachine.Transition("execChecked", "executed", "execute"),
+ new StateMachine.Transition("executed", "postChecked", "checkPostconditions") };
+
+ protected static final StateMachine.Model MODEL = new StateMachine.Model("start", TRANSITIONS);
+
+ protected static final String PARAMETER_STATE_MACHINE = "private.stateMachine";
+ protected static final String PARAMETER_SESSION = "private.session";
+ protected static final String PARAMETER_FACTORY = "private.factory";
- /**
- * Ctor.
- */
- public AbstractUsecase() {
- // do nothing
- }
+ protected static final String PARAMETERS_INITIALIZED = "private.parametersInitialized";
/**
* Override to initialize parameters.
*/
protected void initParameters() {
- // do nothing
+ }
+
+ protected void advanceState(String event) {
+ StateMachine machine = (StateMachine) getParameter(PARAMETER_STATE_MACHINE);
+ machine.invoke(event);
}
protected String SOURCE_URL = "private.sourceUrl";
- protected String FACTORY = "private.factory";
/**
* @see org.apache.lenya.cms.usecase.Usecase#getSourceURL()
@@ -90,8 +100,8 @@
}
/**
- * Determine if the usecase has error messages. Provides a way of checking for errors without
- * actually retrieving them.
+ * Determine if the usecase has error messages. Provides a way of checking
+ * for errors without actually retrieving them.
* @return true if the usecase resulted in error messages.
*/
public boolean hasErrors() {
@@ -106,8 +116,8 @@
}
/**
- * Determine if the usecase has info messages. Provides a way of checking for info messages
- * without actually retrieving them.
+ * Determine if the usecase has info messages. Provides a way of checking
+ * for info messages without actually retrieving them.
* @return true if the usecase resulted in info messages being generated.
*/
public boolean hasInfoMessages() {
@@ -118,8 +128,8 @@
}
/**
- * Checks if the operation can be executed and returns the error messages. Error messages
- * prevent the operation from being executed.
+ * Checks if the operation can be executed and returns the error messages.
+ * Error messages prevent the operation from being executed.
* @return A boolean value.
*/
public List getErrorMessages() {
@@ -128,7 +138,8 @@
/**
* Returns the information messages to show on the confirmation screen.
- * @return An array of strings. Info messages do not prevent the operation from being executed.
+ * @return An array of strings. Info messages do not prevent the operation
+ * from being executed.
*/
public List getInfoMessages() {
return Collections.unmodifiableList(new ArrayList(this.infoMessages));
@@ -197,6 +208,9 @@
throw new UsecaseException(e);
}
}
+ if (!hasErrors()) {
+ advanceState("checkExecutionConditions");
+ }
}
/**
@@ -215,7 +229,7 @@
clearErrorMessages();
clearInfoMessages();
doCheckPreconditions();
-
+
List _errorMessages = getErrorMessages();
for (int i = 0; i < _errorMessages.size(); i++) {
getLogger().info(_errorMessages.get(i).toString());
@@ -227,6 +241,9 @@
throw new UsecaseException(e);
}
}
+ if (!hasErrors()) {
+ advanceState("checkPreconditions");
+ }
}
/**
@@ -255,6 +272,7 @@
* @see org.apache.lenya.cms.usecase.Usecase#execute()
*/
public final void execute() throws UsecaseException {
+ advanceState("execute");
Exception exception = null;
try {
clearErrorMessages();
@@ -298,6 +316,7 @@
* @see org.apache.lenya.cms.usecase.Usecase#checkPostconditions()
*/
public void checkPostconditions() throws UsecaseException {
+ advanceState("checkPostconditions");
try {
clearErrorMessages();
clearInfoMessages();
@@ -331,7 +350,8 @@
private Map parameters = new HashMap();
/**
- * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String, java.lang.Object)
+ * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String,
+ * java.lang.Object)
*/
public void setParameter(String name, Object value) {
if (getLogger().isDebugEnabled()) {
@@ -356,7 +376,8 @@
}
/**
- * @see org.apache.lenya.cms.usecase.Usecase#getParameter(java.lang.String, java.lang.Object)
+ * @see org.apache.lenya.cms.usecase.Usecase#getParameter(java.lang.String,
+ * java.lang.Object)
*/
public Object getParameter(String name, Object defaultValue) {
Object value = getParameter(name);
@@ -379,7 +400,8 @@
}
/**
- * Returns a parameter as string. If the parameter does not exist, a default value is returned.
+ * Returns a parameter as string. If the parameter does not exist, a default
+ * value is returned.
* @param name The parameter name.
* @param defaultValue The default value.
* @return A string.
@@ -394,7 +416,8 @@
}
/**
- * Returns a parameter as integer. If the parameter does not exist, a default value is returned.
+ * Returns a parameter as integer. If the parameter does not exist, a
+ * default value is returned.
* @param name The parameter name.
* @param defaultValue The default value.
* @return An integer.
@@ -409,7 +432,8 @@
}
/**
- * Returns a parameter as boolean. If the parameter does not exist, a default value is returned.
+ * Returns a parameter as boolean. If the parameter does not exist, a
+ * default value is returned.
* @param name The parameter name.
* @param defaultValue The default value.
* @return A boolean value..
@@ -440,8 +464,8 @@
}
/**
- * Returns one of the strings "true" or "false" depending on whether the corresponding checkbox
- * was checked.
+ * Returns one of the strings "true" or "false" depending on whether the
+ * corresponding checkbox was checked.
* @param name The parameter name.
* @return A string.
*/
@@ -457,8 +481,8 @@
private String DEFAULT_TARGET_URL = "private.defaultTargetUrl";
/**
- * Sets the default target URL which should be used if no explicit target URL
- * is set.
+ * Sets the default target URL which should be used if no explicit target
+ * URL is set.
* @param url A URL string.
*/
protected void setDefaultTargetURL(String url) {
@@ -466,8 +490,8 @@
}
/**
- * If {@link #setDefaultTargetURL(String)}was not called, the source document (
- * {@link #getSourceURL()}) is returned.
+ * If {@link #setDefaultTargetURL(String)}was not called, the source
+ * document ( {@link #getSourceURL()}) is returned.
* @see org.apache.lenya.cms.usecase.Usecase#getTargetURL(boolean)
*/
public String getTargetURL(boolean success) {
@@ -491,7 +515,7 @@
if (value != null) {
className = value.getClass().getName();
}
- throw new RuntimeException("[" + name +"] = (" + className + ") [" + value
+ throw new RuntimeException("[" + name + "] = (" + className + ") [" + value
+ "] is not a part object. Maybe you have to enable uploads?");
}
setParameter(name, value);
@@ -504,13 +528,13 @@
return (Part) getParameter(name);
}
- private DocumentFactory documentFactory;
-
protected DocumentFactory getDocumentFactory() {
- if (this.documentFactory == null) {
- this.documentFactory = DocumentUtil.createDocumentFactory(this.manager, session);
+ DocumentFactory factory = (DocumentFactory) getParameter(PARAMETER_FACTORY);
+ if (factory == null || factory.getSession() != getSession()) {
+ factory = DocumentUtil.createDocumentFactory(this.manager, getSession());
+ setParameter(PARAMETER_FACTORY, factory);
}
- return this.documentFactory;
+ return factory;
}
/**
@@ -520,6 +544,7 @@
Request request = ContextHelper.getRequest(this.context);
Session session = RepositoryUtil.getSession(this.manager, request);
setSession(session);
+ setParameter(PARAMETER_STATE_MACHINE, new StateMachine(MODEL));
}
/**
@@ -580,7 +605,6 @@
*/
public void setSourceURL(String url) {
setParameter(SOURCE_URL, url);
- setParameter(FACTORY, getDocumentFactory());
}
private UsecaseView view;
@@ -606,8 +630,9 @@
private boolean isOptimistic = true;
/**
- * @return <code>true</code> if the transaction policy is optimistic offline lock,
- * <code>false</code> if it is pessimistic offline lock.
+ * @return <code>true</code> if the transaction policy is optimistic
+ * offline lock, <code>false</code> if it is pessimistic offline
+ * lock.
*/
protected boolean isOptimistic() {
return this.isOptimistic;
@@ -680,13 +705,26 @@
* @see org.apache.lenya.cms.usecase.Usecase#lockInvolvedObjects()
*/
public final void lockInvolvedObjects() throws UsecaseException {
+ advanceState("lockInvolvedObjects");
+ try {
+ startTransaction();
+ } catch (RepositoryException e) {
+ throw new UsecaseException(e);
+ }
lockInvolvedObjects(getNodesToLock());
}
+ protected void startTransaction() throws RepositoryException {
+ if (this.commitEnabled) {
+ setSession(RepositoryUtil.createSession(this.manager, getSession().getIdentity(), true));
+ }
+ }
+
/**
- * Lock the objects, for example when you need to change them (for example, delete). If you know
- * when entering the usecase what these objects are, you do not need to call this, the framework
- * will take of it if you implement getObjectsToLock(). If you do not know in advance what the
+ * Lock the objects, for example when you need to change them (for example,
+ * delete). If you know when entering the usecase what these objects are,
+ * you do not need to call this, the framework will take of it if you
+ * implement getObjectsToLock(). If you do not know in advance what the
* objects are, you can call this method explicitly when appropriate.
*
* @param objects the transactionable objects to lock
@@ -742,10 +780,12 @@
* @see org.apache.lenya.cms.usecase.Usecase#cancel()
*/
public void cancel() throws UsecaseException {
- try {
- getSession().rollback();
- } catch (Exception e) {
- throw new UsecaseException(e);
+ if (getSession().isModifiable()) {
+ try {
+ getSession().rollback();
+ } catch (Exception e) {
+ throw new UsecaseException(e);
+ }
}
}
@@ -784,12 +824,10 @@
return queryString;
}
- public org.apache.lenya.cms.repository.Session getSession() {
- return this.session;
+ public Session getSession() {
+ return (Session) getParameter(PARAMETER_SESSION);
}
- private org.apache.lenya.cms.repository.Session session;
-
protected Context context;
/**
@@ -806,15 +844,14 @@
}
protected void setSession(org.apache.lenya.cms.repository.Session session) {
- this.session = session;
- Request request = ContextHelper.getRequest(this.context);
- request.setAttribute(org.apache.lenya.cms.repository.Session.class.getName(), this.session);
+ setParameter(PARAMETER_SESSION, session);
}
private boolean commitEnabled = true;
- public void setCommitEnabled(boolean enabled) {
- this.commitEnabled = enabled;
+ public void setTestSession(Session session) {
+ this.commitEnabled = false;
+ setSession(session);
}
}
Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/DocumentUsecase.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/DocumentUsecase.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/DocumentUsecase.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/DocumentUsecase.java Thu Feb 15 04:15:30 2007
@@ -55,9 +55,19 @@
}
}
+ /*
+ public void setParameter(String name, Object value) {
+ if (name.equals(SOURCE_URL)) {
+ setSourceURL((String) value);
+ }
+ else {
+ super.setParameter(name, value);
+ }
+ }
+ */
+
/**
* @see org.apache.lenya.cms.usecase.Usecase#setSourceURL(java.lang.String)
- */
public void setSourceURL(String url) {
try {
DocumentFactory factory = getDocumentFactory();
@@ -68,17 +78,29 @@
} catch (Exception e) {
throw new RuntimeException(e);
}
- super.setSourceURL(url);
+ super.setParameter(SOURCE_URL, url);
}
+ */
/**
* Returns the source document.
* @return A document.
*/
protected Document getSourceDocument() {
- String url = super.getSourceURL();
- setSourceURL(url);
- return (Document) getParameter(DOCUMENT);
+ Document doc = (Document) getParameter(DOCUMENT);
+ if (doc == null || doc.getFactory().getSession() != getSession()) {
+ try {
+ DocumentFactory factory = getDocumentFactory();
+ String sourceUrl = getParameterAsString(SOURCE_URL);
+ if (factory.isDocument(sourceUrl)) {
+ doc = factory.getFromURL(sourceUrl);
+ setParameter(DOCUMENT, doc);
+ }
+ } catch (DocumentBuildException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return doc;
}
/**
@@ -143,10 +165,10 @@
/**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
protected void initParameters() {
super.initParameters();
setParameter(DOCUMENT, getSourceDocument());
}
+ */
}
Added: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/StateMachine.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/StateMachine.java?view=auto&rev=507914
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/StateMachine.java (added)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/StateMachine.java Thu Feb 15 04:15:30 2007
@@ -0,0 +1,139 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.lenya.cms.usecase;
+
+import org.apache.lenya.util.Assert;
+
+/**
+ * A simple state machine.
+ */
+public class StateMachine {
+
+ String currentState;
+ private Model model;
+
+ /**
+ * @param model The model to use.
+ */
+ public StateMachine(Model model) {
+ this.model = model;
+ this.currentState = model.getInitialState();
+ }
+
+ void invoke(String event) {
+ Assert.notNull("event", event);
+ Transition[] transitions = this.model.getTransitions();
+ Transition transition = null;
+ for (int i = 0; i < transitions.length; i++) {
+ Transition t = transitions[i];
+ if (canFire(t, event)) {
+ if (transition != null) {
+ throw new IllegalStateException("More than 1 transition for event [" + event
+ + "] in state [" + this.currentState + "]!");
+ }
+ transition = t;
+ }
+ }
+ if (transition == null) {
+ throw new IllegalStateException("No transition found for event [" + event
+ + "] in state [" + this.currentState + "]!");
+ }
+ this.currentState = transition.destination;
+ }
+
+ protected boolean canFire(Transition t, String event) {
+ return t.getSource().equals(this.currentState) && t.getEvent().equals(event);
+ }
+
+ /**
+ * A state machine model.
+ */
+ public static class Model {
+
+ private String initialState;
+
+ /**
+ * @param initialState The initial state.
+ * @param transitions The transitions.
+ */
+ public Model(String initialState, Transition[] transitions) {
+ this.transitions = transitions;
+ this.initialState = initialState;
+ }
+
+ /**
+ * @return The initial state.
+ */
+ public String getInitialState() {
+ return this.initialState;
+ }
+
+ private Transition[] transitions;
+
+ /**
+ * @return The transitions.
+ */
+ public Transition[] getTransitions() {
+ return this.transitions;
+ }
+ }
+
+ /**
+ * A transition switches from a source state to a destination state if an
+ * event is invoked.
+ */
+ public static class Transition {
+
+ /**
+ * @param source The source state.
+ * @param destination The destination state.
+ * @param event The event.
+ */
+ public Transition(String source, String destination, String event) {
+ this.source = source;
+ this.destination = destination;
+ this.event = event;
+ }
+
+ private String source;
+ private String destination;
+ private String event;
+
+ /**
+ * @return The destination state.
+ */
+ public String getDestination() {
+ return destination;
+ }
+
+ /**
+ * @return The event.
+ */
+ public String getEvent() {
+ return event;
+ }
+
+ /**
+ * @return The source state.
+ */
+ public String getSource() {
+ return source;
+ }
+ }
+
+}
Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java Thu Feb 15 04:15:30 2007
@@ -204,8 +204,11 @@
Session getSession();
/**
- * @param enabled if the transaction should be committed. Set to <code>false</code> for tests.
+ * If you invoke this method, the usecase won't use its own isolated session,
+ * but the passed test session. The session will not be committed when the usecase
+ * is invoked, so you can check it for modifications without modifying the repository.
+ * @param session The test session.
*/
- void setCommitEnabled(boolean enabled);
+ void setTestSession(Session session);
}
Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/UsecaseInvoker.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/UsecaseInvoker.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/UsecaseInvoker.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/UsecaseInvoker.java Thu Feb 15 04:15:30 2007
@@ -20,6 +20,8 @@
import java.util.List;
import java.util.Map;
+import org.apache.lenya.cms.repository.Session;
+
/**
* <p>
* This service allows to invoke a usecase in a convenient way. A typical usage
@@ -121,5 +123,10 @@
* yet.
*/
String getTargetUrl();
+
+ /**
+ * @param session The test session to use.
+ */
+ void setTestSession(Session session);
}
Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/impl/TestUsecaseInvoker.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/impl/TestUsecaseInvoker.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/impl/TestUsecaseInvoker.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/impl/TestUsecaseInvoker.java Thu Feb 15 04:15:30 2007
@@ -17,6 +17,7 @@
*/
package org.apache.lenya.cms.usecase.impl;
+
/**
* Invoker for test usecases. The transactions are not committed.
*/
@@ -26,9 +27,5 @@
* The Avalon role.
*/
public static final String ROLE = TestUsecaseInvoker.class.getName();
-
- protected boolean isCommitEnabled() {
- return false;
- }
}
Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/impl/UsecaseInvokerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/impl/UsecaseInvokerImpl.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/impl/UsecaseInvokerImpl.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/impl/UsecaseInvokerImpl.java Thu Feb 15 04:15:30 2007
@@ -27,6 +27,7 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
+import org.apache.lenya.cms.repository.Session;
import org.apache.lenya.cms.usecase.Usecase;
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.cms.usecase.UsecaseInvoker;
@@ -60,7 +61,10 @@
resolver = (UsecaseResolver) this.manager.lookup(UsecaseResolver.ROLE);
usecase = resolver.resolve(webappUrl, usecaseName);
- usecase.setCommitEnabled(isCommitEnabled());
+ Session testSession = getTestSession();
+ if (testSession != null) {
+ usecase.setTestSession(testSession);
+ }
usecase.setSourceURL(webappUrl);
usecase.setName(usecaseName);
@@ -101,8 +105,10 @@
}
}
- protected boolean isCommitEnabled() {
- return true;
+ private Session testSession = null;
+
+ protected Session getTestSession() {
+ return this.testSession;
}
protected boolean succeeded(int result, Usecase usecase) {
@@ -189,6 +195,10 @@
throw new IllegalStateException("The usecase has not been executed yet.");
}
return this.targetUrl;
+ }
+
+ public void setTestSession(Session session) {
+ this.testSession = session;
}
}
Modified: lenya/trunk/src/modules-optional/jcrsource/java/src/org/apache/lenya/cms/jcr/JCRNodeFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-optional/jcrsource/java/src/org/apache/lenya/cms/jcr/JCRNodeFactory.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-optional/jcrsource/java/src/org/apache/lenya/cms/jcr/JCRNodeFactory.java (original)
+++ lenya/trunk/src/modules-optional/jcrsource/java/src/org/apache/lenya/cms/jcr/JCRNodeFactory.java Thu Feb 15 04:15:30 2007
@@ -52,4 +52,8 @@
this.session = session;
}
+ public boolean isSharable() {
+ return false;
+ }
+
}
Modified: lenya/trunk/src/modules-optional/jcrsource/java/src/org/apache/lenya/cms/jcr/usecases/Import.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-optional/jcrsource/java/src/org/apache/lenya/cms/jcr/usecases/Import.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules-optional/jcrsource/java/src/org/apache/lenya/cms/jcr/usecases/Import.java (original)
+++ lenya/trunk/src/modules-optional/jcrsource/java/src/org/apache/lenya/cms/jcr/usecases/Import.java Thu Feb 15 04:15:30 2007
@@ -71,10 +71,10 @@
Document[] docs = siteManager.getDocuments(factory, pub, areas[i]);
for (int j = 0; j < docs.length; j++) {
nodes.add(docs[j].getRepositoryNode());
+ /*
final String lenyaUri = docs[j].getSourceURI();
final String sourcePath = lenyaUri.substring("lenya://".length());
final String contextUri = "context://" + sourcePath + ".meta";
- /*
* MetaDataManager meta = new MetaDataManager(contextUri, this.manager,
* getLogger()); uri2meta.put(docs[j].getSourceURI(), meta);
*/
Modified: lenya/trunk/src/modules/blog/java/src/org/apache/cocoon/generation/BlogOverviewGenerator.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/blog/java/src/org/apache/cocoon/generation/BlogOverviewGenerator.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/blog/java/src/org/apache/cocoon/generation/BlogOverviewGenerator.java (original)
+++ lenya/trunk/src/modules/blog/java/src/org/apache/cocoon/generation/BlogOverviewGenerator.java Thu Feb 15 04:15:30 2007
@@ -29,7 +29,6 @@
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.DocumentFactory;
@@ -395,7 +394,7 @@
PATH_ATTR_NAME, "CDATA", doc.getPath());
attributes.addAttribute("", URL_ATTR_NAME,
URL_ATTR_NAME, "CDATA", doc.getCanonicalWebappURL());
- org.w3c.dom.Document docDOM = SourceUtil.readDOM(doc.getSourceURI(), this.manager);
+ org.w3c.dom.Document docDOM = DocumentHelper.readDocument(doc.getInputStream());
Element parent = docDOM.getDocumentElement();
Element element = (Element) XPathAPI.selectSingleNode(parent,
"/*[local-name() = 'entry']/*[local-name() = 'title']");
Modified: lenya/trunk/src/modules/blog/java/src/org/apache/lenya/cms/site/usecases/CreateBlogEntry.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/blog/java/src/org/apache/lenya/cms/site/usecases/CreateBlogEntry.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/blog/java/src/org/apache/lenya/cms/site/usecases/CreateBlogEntry.java (original)
+++ lenya/trunk/src/modules/blog/java/src/org/apache/lenya/cms/site/usecases/CreateBlogEntry.java Thu Feb 15 04:15:30 2007
@@ -28,7 +28,6 @@
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.lenya.ac.Identity;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentException;
@@ -214,7 +213,7 @@
Identity identity = (Identity) session.getAttribute(Identity.class.getName());
String title = getParameterAsString(DublinCore.ELEMENT_TITLE);
- org.w3c.dom.Document xmlDoc = SourceUtil.readDOM(document.getSourceURI(), this.manager);
+ org.w3c.dom.Document xmlDoc = DocumentHelper.readDocument(document.getInputStream());
Element parent = xmlDoc.getDocumentElement();
@@ -278,6 +277,6 @@
"/*[local-name() = 'entry']/*[local-name() = 'modified']");
DocumentHelper.setSimpleElementText(element, datestr);
- SourceUtil.writeDOM(xmlDoc, document.getSourceURI(), this.manager);
+ DocumentHelper.writeDocument(xmlDoc, document.getOutputStream());
}
}
Modified: lenya/trunk/src/modules/blog/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/blog/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/blog/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java (original)
+++ lenya/trunk/src/modules/blog/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java Thu Feb 15 04:15:30 2007
@@ -23,8 +23,6 @@
import java.util.Date;
import java.util.List;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
-import org.apache.lenya.cms.metadata.dublincore.DublinCoreHelper;
import org.apache.lenya.cms.publication.Area;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentManager;
@@ -149,18 +147,18 @@
+ dateofs.substring(3, 5);
for (int i = 0; i < 2; i++) {
- doms[i] = SourceUtil.readDOM(docs[i].getSourceURI(), this.manager);
+ doms[i] = DocumentHelper.readDocument(docs[i].getInputStream());
Element parent = doms[i].getDocumentElement();
// set modified date on publish
Element element = (Element) XPathAPI.selectSingleNode(parent,
"/*[local-name() = 'feed']/*[local-name() = 'modified']");
DocumentHelper.setSimpleElementText(element, datestr);
- SourceUtil.writeDOM(doms[i], docs[i].getSourceURI(), this.manager);
+ DocumentHelper.writeDocument(doms[i], docs[i].getOutputStream());
}
}
protected void updateBlogEntry(Document doc) throws Exception {
- org.w3c.dom.Document dom = SourceUtil.readDOM(doc.getSourceURI(), this.manager);
+ org.w3c.dom.Document dom = DocumentHelper.readDocument(doc.getInputStream());
Element parent = dom.getDocumentElement();
DateFormat datefmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
@@ -193,7 +191,7 @@
DocumentHelper.setSimpleElementText(element, datestr);
}
- SourceUtil.writeDOM(dom, doc.getSourceURI(), this.manager);
+ DocumentHelper.writeDocument(dom, doc.getOutputStream());
}
/**
Modified: lenya/trunk/src/modules/cforms/java/src/org/apache/lenya/cms/editors/cforms/CForms.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/cforms/java/src/org/apache/lenya/cms/editors/cforms/CForms.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/cforms/java/src/org/apache/lenya/cms/editors/cforms/CForms.java (original)
+++ lenya/trunk/src/modules/cforms/java/src/org/apache/lenya/cms/editors/cforms/CForms.java Thu Feb 15 04:15:30 2007
@@ -62,7 +62,7 @@
private void doPreparation(ServiceManager manager) {
Request request = ContextHelper.getRequest(this.context);
Document doc = getSourceDocument();
- String sourceUri=doc.getSourceURI();
+ String sourceUri = doc.getSourceURI();
setParameter("sourceUri", sourceUri);
String pubId = doc.getPublication().getId();
setParameter("pubId", pubId);
Modified: lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java (original)
+++ lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/EditDocument.java Thu Feb 15 04:15:30 2007
@@ -83,7 +83,7 @@
ValidationUtil.validate(this.manager, xmlDoc, schema, new UsecaseErrorHandler(this));
if (!hasErrors()) {
- SourceUtil.writeDOM(xmlDoc, sourceDoc.getSourceURI(), this.manager);
+ SourceUtil.writeDOM(xmlDoc, sourceDoc.getOutputStream());
LinkConverter converter = new LinkConverter(this.manager, getLogger());
converter.convertUrlsToUuids(getSourceDocument());
Modified: lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/forms/FormsEditor.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/forms/FormsEditor.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/forms/FormsEditor.java (original)
+++ lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/forms/FormsEditor.java Thu Feb 15 04:15:30 2007
@@ -42,7 +42,6 @@
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.Request;
import org.apache.commons.lang.StringUtils;
import org.apache.excalibur.source.ModifiableSource;
@@ -130,7 +129,6 @@
String unnumberTagsXslUri = "fallback://lenya/modules/editors/usecases/forms/unnumberTags.xsl";
String numberTagsXslUri = "fallback://lenya/modules/editors/usecases/forms/numberTags.xsl";
- ModifiableSource xmlSource = null;
Source schemaSource = null;
Source unnumberTagsXslSource = null;
Source numberTagsXslSource = null;
@@ -139,8 +137,6 @@
try {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- xmlSource = (ModifiableSource) resolver.resolveURI(getSourceDocument().getSourceURI());
-
unnumberTagsXslSource = resolver.resolveURI(unnumberTagsXslUri);
numberTagsXslSource = resolver.resolveURI(numberTagsXslUri);
@@ -152,7 +148,7 @@
Request request = ContextHelper.getRequest(this.context);
String encoding = request.getCharacterEncoding();
- save(resolver, xmlSource, unnumberTagsXslSource, numberTagsXslSource, encoding);
+ save(resolver, getSourceDocument(), unnumberTagsXslSource, numberTagsXslSource, encoding);
if (hasErrors()) {
setParameter(VALIDATION_ERRORS, getErrorMessages());
@@ -170,9 +166,6 @@
throw new UsecaseException(e);
} finally {
if (resolver != null) {
- if (xmlSource != null) {
- resolver.release(xmlSource);
- }
if (schemaSource != null) {
resolver.release(schemaSource);
}
@@ -202,7 +195,7 @@
/**
* Save the Form
* @param resolver
- * @param xmlSource
+ * @param lenyaDocument
* @param unnumberTagsXslSource
* @param numberTagsXslSource
* @throws ProcessingException
@@ -216,16 +209,16 @@
* @throws TransformerConfigurationException
* @throws TransformerException
*/
- private void save(SourceResolver resolver, ModifiableSource xmlSource,
+ private void save(SourceResolver resolver, org.apache.lenya.cms.publication.Document lenyaDocument,
Source unnumberTagsXslSource, Source numberTagsXslSource,String encoding) throws ProcessingException,
FactoryConfigurationError, ParserConfigurationException, IOException, SAXException,
XPathQueryConfigurationException, Exception, MalformedURLException,
TransformerConfigurationException, TransformerException {
- if (!xmlSource.exists()) {
- throw new ProcessingException("The source [" + xmlSource.getURI() + "] does not exist.");
+ if (!lenyaDocument.exists()) {
+ throw new ProcessingException("The document [" + lenyaDocument + "] does not exist.");
}
if (getLogger().isDebugEnabled()) {
- getLogger().debug("Save modifications to [" + xmlSource.getURI() + "]");
+ getLogger().debug("Save modifications to [" + lenyaDocument + "]");
}
Document doc = null;
@@ -235,7 +228,7 @@
parserFactory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = parserFactory.newDocumentBuilder();
- InputSource xmlInputSource = SourceUtil.getInputSource(xmlSource);
+ InputSource xmlInputSource = new InputSource(lenyaDocument.getInputStream());
Document document = builder.parse(xmlInputSource);
Document renumberedDocument = renumberDocument(document, unnumberTagsXslSource,numberTagsXslSource);
@@ -251,11 +244,11 @@
Source unnumberTagsSource = null;
try {
- String validationUri = xmlSource.getURI() + ".validate";
+ String validationUri = lenyaDocument.getSourceURI() + ".validate";
validationSource = resolver.resolveURI(validationUri);
checkModifiability(validationSource);
- String unnumberTagsUri = xmlSource.getURI() + ".validate.unnumber";
+ String unnumberTagsUri = lenyaDocument.getSourceURI() + ".validate.unnumber";
unnumberTagsSource = resolver.resolveURI(unnumberTagsUri);
checkModifiability(unnumberTagsSource);
@@ -285,7 +278,7 @@
}
if (doc != null){
- writeDocument(doc, xmlSource, encoding);
+ writeDocument(doc, getSourceDocument().getOutputStream(), encoding);
}
}
@@ -423,15 +416,14 @@
/**
* Writes a document to a modifiable source.
* @param document The document.
- * @param source The source.
+ * @param oStream The source.
* @throws IOException if an error occurs.
* @throws TransformerConfigurationException if an error occurs.
* @throws TransformerException if an error occurs.
* @throws ProcessingException if an error occurs.
*/
- protected void writeDocument(Document document, ModifiableSource source, String encoding) throws IOException,
+ protected void writeDocument(Document document, OutputStream oStream, String encoding) throws IOException,
TransformerConfigurationException, TransformerException, ProcessingException {
- OutputStream oStream = source.getOutputStream();
Writer writer = new OutputStreamWriter(oStream, encoding);
DocumentHelper.writeDocument(document, writer);
if (oStream != null) {
@@ -444,9 +436,6 @@
}
throw new ProcessingException("Could not write document: ", t);
}
- }
- if (!source.exists()) {
- throw new ProcessingException("Could not write source [" + source.getURI() + "]");
}
}
Modified: lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/forms/OneFormEditor.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/forms/OneFormEditor.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/forms/OneFormEditor.java (original)
+++ lenya/trunk/src/modules/editors/java/src/org/apache/lenya/cms/editors/forms/OneFormEditor.java Thu Feb 15 04:15:30 2007
@@ -26,7 +26,6 @@
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.publication.ResourceType;
@@ -95,18 +94,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() });
}
@@ -128,9 +125,6 @@
} finally {
if (resolver != null) {
- if (xmlSource != null) {
- resolver.release(xmlSource);
- }
if (indexSource != null) {
resolver.release(indexSource);
}
@@ -143,18 +137,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/export/java/src/org/apache/lenya/cms/export/Importer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java (original)
+++ lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java Thu Feb 15 04:15:30 2007
@@ -139,7 +139,7 @@
Document doc = node.getLink(node.getLanguages()[0]).getDocument();
newDoc = docManager.addVersion(doc, area.getName(), language, true);
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- SourceUtil.copy(resolver, contentUri, newDoc.getSourceURI());
+ SourceUtil.copy(resolver, contentUri, newDoc.getOutputStream());
newDoc.getLink().setLabel(navigationTitle);
}
Modified: lenya/trunk/src/modules/export/java/test/org/apache/lenya/cms/export/ImportTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/java/test/org/apache/lenya/cms/export/ImportTest.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/export/java/test/org/apache/lenya/cms/export/ImportTest.java (original)
+++ lenya/trunk/src/modules/export/java/test/org/apache/lenya/cms/export/ImportTest.java Thu Feb 15 04:15:30 2007
@@ -19,9 +19,16 @@
import java.io.File;
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.lenya.ac.impl.AbstractAccessControlTest;
+import org.apache.lenya.cms.linking.Link;
+import org.apache.lenya.cms.linking.LinkManager;
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.publication.PublicationException;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.site.SiteStructure;
/**
* Import example content into test publication.
@@ -33,19 +40,46 @@
*/
public void testImport() throws Exception {
- login("lenya");
- Publication pub = getPublication("test");
+ Session session = login("lenya");
+
+ Publication pub = getPublication(session, "test");
Area area = pub.getArea("authoring");
if (area.getDocuments().length == 0) {
- Publication defaultPub = getPublication("default");
+ Publication defaultPub = getPublication(session, "default");
Area defaultArea = defaultPub.getArea("authoring");
String pubPath = defaultArea.getPublication().getDirectory().getAbsolutePath();
String path = pubPath.replace(File.separatorChar, '/') + "/example-content";
Importer importer = new Importer(getManager(), getLogger());
importer.importContent(defaultPub, area, path);
- getFactory().getSession().commit();
+ session.commit();
}
+
+ assertTrue(area.getSite().contains("/tutorial"));
+ checkLinks(area);
+
+ Session aliceSession = login("alice");
+ Publication alicePub = getPublication(aliceSession, "test");
+ assertTrue(alicePub.getArea("authoring").getSite().contains("/tutorial"));
+
+ }
+
+ protected void checkLinks(Area area) throws PublicationException, ServiceException {
+ SiteStructure site = area.getSite();
+ Document source = site.getNode("/index").getLink("en").getDocument();
+
+ LinkManager linkManager = null;
+ try {
+ linkManager = (LinkManager) getManager().lookup(LinkManager.ROLE);
+ Link[] links = linkManager.getLinksFrom(source);
+ assertTrue(links.length > 0);
+ }
+ finally {
+ if (linkManager != null) {
+ getManager().release(linkManager);
+ }
+ }
+
}
}
Modified: lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java (original)
+++ lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java Thu Feb 15 04:15:30 2007
@@ -20,6 +20,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -123,7 +124,6 @@
* @throws Exception if an error occurs.
*/
protected void saveDocument(String encoding, String content) throws Exception {
- ModifiableSource xmlSource = null;
SourceResolver resolver = null;
Source indexSource = null;
Source tidySource = null;
@@ -131,8 +131,7 @@
Properties properties = null;
try {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- xmlSource = (ModifiableSource) resolver.resolveURI(getSourceDocument().getSourceURI());
- saveXMLFile(encoding, content, xmlSource);
+ saveXMLFile(encoding, content, getSourceDocument().getOutputStream());
Document xmlDoc = null;
@@ -164,7 +163,7 @@
PrintWriter errorWriter = new PrintWriter(stringWriter);
tidy.setErrout(errorWriter);
- xmlDoc = tidy.parseDOM(xmlSource.getInputStream(), null);
+ xmlDoc = tidy.parseDOM(getSourceDocument().getInputStream(), null);
// FIXME: Jtidy doesn't warn or strip duplicate attributes in
// same
@@ -187,10 +186,10 @@
addErrorMessage(e.getMessage());
}
- saveXMLFile(encoding, content, xmlSource);
+ saveXMLFile(encoding, content, getSourceDocument().getOutputStream());
} else {
try {
- xmlDoc = DocumentHelper.readDocument(xmlSource.getInputStream());
+ xmlDoc = DocumentHelper.readDocument(getSourceDocument().getInputStream());
} catch (SAXException e) {
addErrorMessage("error-document-form", new String[] { e.getMessage() });
}
@@ -212,7 +211,7 @@
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty(OutputKeys.METHOD, "xml");
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
- xmlDoc = DocumentHelper.readDocument(xmlSource.getInputStream());
+ xmlDoc = DocumentHelper.readDocument(getSourceDocument().getInputStream());
t.transform(new DOMSource(xmlDoc.getDocumentElement()), strResult);
content = strResult.getWriter().toString();
@@ -220,10 +219,10 @@
addErrorMessage(e.getMessage());
}
- saveXMLFile(encoding, content, xmlSource);
+ saveXMLFile(encoding, content, getSourceDocument().getOutputStream());
}
- xmlDoc = DocumentHelper.readDocument(xmlSource.getInputStream());
+ xmlDoc = DocumentHelper.readDocument(getSourceDocument().getInputStream());
if (xmlDoc != null) {
ResourceType resourceType = getSourceDocument().getResourceType();
@@ -240,9 +239,6 @@
} finally {
if (resolver != null) {
- if (xmlSource != null) {
- resolver.release(xmlSource);
- }
if (indexSource != null) {
resolver.release(indexSource);
}
@@ -261,18 +257,18 @@
* Save the XML file
* @param encoding The encoding
* @param content The content
- * @param xmlSource The source
+ * @param out The stream to write to
* @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, OutputStream out)
throws FileNotFoundException, UnsupportedEncodingException, IOException {
FileOutputStream fileoutstream = null;
Writer writer = null;
try {
- writer = new OutputStreamWriter(xmlSource.getOutputStream(), encoding);
+ writer = new OutputStreamWriter(out, encoding);
writer.write(content, 0, content.length());
} catch (FileNotFoundException e) {
getLogger().error("File not found " + e.toString());
Modified: lenya/trunk/src/modules/lucene/java/test/org/apache/lenya/cms/lucene/IndexUpdaterTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/java/test/org/apache/lenya/cms/lucene/IndexUpdaterTest.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/lucene/java/test/org/apache/lenya/cms/lucene/IndexUpdaterTest.java (original)
+++ lenya/trunk/src/modules/lucene/java/test/org/apache/lenya/cms/lucene/IndexUpdaterTest.java Thu Feb 15 04:15:30 2007
@@ -17,14 +17,10 @@
*/
package org.apache.lenya.cms.lucene;
-import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.ac.impl.AbstractAccessControlTest;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentFactory;
-import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.DocumentManager;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.repository.RepositoryUtil;
import org.apache.lenya.cms.repository.Session;
import org.apache.lenya.cms.site.SiteNode;
import org.apache.lenya.cms.site.SiteStructure;
@@ -32,9 +28,9 @@
public class IndexUpdaterTest extends AbstractAccessControlTest {
public void testIndexUpdater() throws Exception {
- login("lenya");
+ Session session = login("lenya");
- Publication pub = getPublication("test");
+ Publication pub = getPublication(session, "test");
SiteStructure site = pub.getArea("authoring").getSite();
SiteNode sourceNode = site.getNode("/tutorial");
@@ -45,13 +41,13 @@
sourceDoc.getRepositoryNode().lock();
- SourceResolver resolver = null;
+ DocumentManager docMgr = null;
try {
- resolver = (SourceResolver) getManager().lookup(SourceResolver.ROLE);
- SourceUtil.copy(resolver, sourceDoc.getSourceURI(), destDoc.getSourceURI());
+ docMgr = (DocumentManager) getManager().lookup(DocumentManager.ROLE);
+ docMgr.copy(sourceDoc, destDoc.getLocator());
} finally {
- if (resolver != null) {
- getManager().release(resolver);
+ if (docMgr != null) {
+ getManager().release(docMgr);
}
}
checkSearchResults(pub, Publication.AUTHORING_AREA);
Modified: lenya/trunk/src/modules/migration/java/test/org/apache/lenya/cms/migration/MigrateUuidsTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/migration/java/test/org/apache/lenya/cms/migration/MigrateUuidsTest.java?view=diff&rev=507914&r1=507913&r2=507914
==============================================================================
--- lenya/trunk/src/modules/migration/java/test/org/apache/lenya/cms/migration/MigrateUuidsTest.java (original)
+++ lenya/trunk/src/modules/migration/java/test/org/apache/lenya/cms/migration/MigrateUuidsTest.java Thu Feb 15 04:15:30 2007
@@ -52,9 +52,7 @@
*/
public void testMigrateUuids() throws Exception {
- login("lenya");
-
- Session session = RepositoryUtil.getSession(getManager(), getRequest());
+ Session session = login("lenya");
DocumentFactory factory = DocumentUtil.createDocumentFactory(getManager(), session);
Publication[] pubs = factory.getPublications();
for (int i = 0; i < pubs.length; i++) {
@@ -138,7 +136,7 @@
}
Document newDoc;
-
+/*
String docId = doc.getUUID();
if (this.migratedDocs.containsKey(docId)) {
Document migratedDoc = (Document) this.migratedDocs.get(docId);
@@ -161,7 +159,7 @@
for (int i = 0; i < uris.length; i++) {
newDoc.getMetaData(uris[i]).replaceBy(doc.getMetaData(uris[i]));
}
-
+*/
doc.delete();
} finally {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org