Modified: lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/java/org/apache/lenya/cms/repository/SourceNodeRevision.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/java/org/apache/lenya/cms/repository/SourceNodeRevision.java?rev=741384&r1=741383&r2=741384&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/java/org/apache/lenya/cms/repository/SourceNodeRevision.java (original)
+++ lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/java/org/apache/lenya/cms/repository/SourceNodeRevision.java Fri Feb 6 03:16:59 2009
@@ -21,7 +21,6 @@
import java.util.Iterator;
import java.util.Vector;
-import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.util.AbstractLogEnabled;
import org.apache.commons.logging.Log;
import org.apache.excalibur.source.Source;
@@ -40,20 +39,19 @@
private SourceNode node;
private int number;
- private ServiceManager manager;
private long time = -1;
private String userId;
+ private SourceResolver sourceResolver;
/**
* @param node The node.
* @param number The revision number.
- * @param manager The service manager.
* @param logger The logger.
*/
- public SourceNodeRevision(SourceNode node, int number, ServiceManager manager, Log logger) {
+ public SourceNodeRevision(SourceNode node, int number, SourceResolver resolver, Log logger) {
this.node = node;
this.number = number;
- this.manager = manager;
+ this.sourceResolver = resolver;
}
public long getTime() {
@@ -86,11 +84,9 @@
public InputStream getInputStream() {
Source source = null;
- SourceResolver resolver = null;
try {
String sourceUri = getSourceURI();
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- source = resolver.resolveURI(sourceUri);
+ source = getSourceResolver().resolveURI(sourceUri);
if (source.exists()) {
return source.getInputStream();
} else {
@@ -101,13 +97,6 @@
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
- } finally {
- if (resolver != null) {
- if (source != null) {
- resolver.release(source);
- }
- this.manager.release(resolver);
- }
}
}
@@ -129,13 +118,13 @@
protected SourceNodeMetaDataHandler getMetaDataHandler() {
if (this.metaDataHandler == null) {
- this.metaDataHandler = new SourceNodeMetaDataHandler(this.manager, getMetaSourceUri(), this);
+ this.metaDataHandler = new SourceNodeMetaDataHandler(getMetaSourceUri(), this, getSourceResolver());
}
return this.metaDataHandler;
}
protected String getMetaSourceUri() {
- String realSourceUri = SourceWrapper.computeRealSourceUri(this.manager, this.node.getSession(),
+ String realSourceUri = SourceWrapper.computeRealSourceUri(getSourceResolver(), this.node.getSession(),
this.node.getSourceURI(), getLogger());
return realSourceUri + ".meta." + getTime() + ".bak";
}
@@ -146,7 +135,7 @@
public boolean exists() throws RepositoryException {
try {
- return SourceUtil.exists(getSourceURI(), this.manager);
+ return SourceUtil.exists(getSourceURI(), getSourceResolver());
} catch (Exception e) {
throw new RepositoryException(e);
}
@@ -154,7 +143,7 @@
public long getContentLength() throws RepositoryException {
try {
- return SourceUtil.getContentLength(getSourceURI(), this.manager);
+ return SourceUtil.getContentLength(getSourceURI(), getSourceResolver());
} catch (Exception e) {
throw new RepositoryException(e);
}
@@ -162,7 +151,7 @@
public long getLastModified() throws RepositoryException {
try {
- return SourceUtil.getLastModified(getSourceURI(), this.manager);
+ return SourceUtil.getLastModified(getSourceURI(), getSourceResolver());
} catch (Exception e) {
throw new RepositoryException(e);
}
@@ -170,7 +159,7 @@
public String getMimeType() throws RepositoryException {
try {
- return SourceUtil.getMimeType(getSourceURI(), this.manager);
+ return SourceUtil.getMimeType(getSourceURI(), getSourceResolver());
} catch (Exception e) {
throw new RepositoryException(e);
}
@@ -181,4 +170,8 @@
return this.userId;
}
+ protected SourceResolver getSourceResolver() {
+ return sourceResolver;
+ }
+
}
Modified: lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/java/org/apache/lenya/cms/repository/SourceWrapper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/java/org/apache/lenya/cms/repository/SourceWrapper.java?rev=741384&r1=741383&r2=741384&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/java/org/apache/lenya/cms/repository/SourceWrapper.java (original)
+++ lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/java/org/apache/lenya/cms/repository/SourceWrapper.java Fri Feb 6 03:16:59 2009
@@ -28,7 +28,7 @@
import java.util.WeakHashMap;
import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
import org.apache.cocoon.util.AbstractLogEnabled;
import org.apache.commons.logging.Log;
import org.apache.excalibur.source.ModifiableSource;
@@ -36,7 +36,7 @@
import org.apache.excalibur.source.TraversableSource;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.publication.DocumentFactory;
-import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.DocumentFactoryBuilder;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.util.Assert;
@@ -47,16 +47,15 @@
private SourceNode node;
private String sourceUri;
- protected ServiceManager manager;
+ private SourceResolver sourceResolver;
/**
* Ctor.
* @param node
* @param sourceUri
- * @param manager
* @param logger
*/
- public SourceWrapper(SourceNode node, String sourceUri, ServiceManager manager, Log logger) {
+ public SourceWrapper(SourceNode node, String sourceUri, SourceResolver resolver, Log logger) {
Assert.notNull("node", node);
this.node = node;
@@ -64,9 +63,8 @@
Assert.notNull("source URI", sourceUri);
this.sourceUri = sourceUri;
- Assert.notNull("service manager", manager);
- this.manager = manager;
-
+ Assert.notNull("source resolver", resolver);
+ this.sourceResolver = resolver;
}
protected static final String FILE_PREFIX = "file:/";
@@ -85,14 +83,14 @@
*/
protected String getRealSourceUri() {
if (this.realSourceUri == null) {
- this.realSourceUri = computeRealSourceUri(this.manager, getNode().getSession(),
+ this.realSourceUri = computeRealSourceUri(getSourceResolver(), getNode().getSession(),
this.sourceUri, getLogger());
}
return this.realSourceUri;
}
- protected static final String computeRealSourceUri(ServiceManager manager, Session session,
- String sourceUri, Log logger) {
+ protected static final String computeRealSourceUri(SourceResolver sourceResolver,
+ Session session, String sourceUri, Log logger) {
String contentDir = null;
String publicationId = null;
try {
@@ -100,7 +98,9 @@
String publicationsPath = sourceUri.substring(pubBase.length());
int firstSlashIndex = publicationsPath.indexOf("/");
publicationId = publicationsPath.substring(0, firstSlashIndex);
- DocumentFactory factory = DocumentUtil.createDocumentFactory(manager, session);
+ DocumentFactoryBuilder builder = (DocumentFactoryBuilder) WebAppContextUtils.getCurrentWebApplicationContext()
+ .getBean(DocumentFactoryBuilder.class.getName());
+ DocumentFactory factory = builder.createDocumentFactory(session);
Publication pub = factory.getPublication(publicationId);
contentDir = pub.getContentDir();
} catch (Exception e) {
@@ -130,7 +130,7 @@
if (logger.isDebugEnabled()) {
try {
- if (!SourceUtil.exists(contentBaseUri, manager)) {
+ if (!SourceUtil.exists(contentBaseUri, sourceResolver)) {
logger.debug("The content directory [" + contentBaseUri + "] does not exist. "
+ "It will be created as soon as documents are added.");
}
@@ -158,7 +158,7 @@
+ "]: not checked out!");
} else {
this.data = null;
- SourceUtil.delete(getRealSourceUri(), this.manager);
+ SourceUtil.delete(getRealSourceUri(), getSourceResolver());
}
} catch (Exception e) {
throw new RepositoryException(e);
@@ -192,7 +192,7 @@
return true;
} else {
try {
- return SourceUtil.exists(getRealSourceUri(), this.manager);
+ return SourceUtil.exists(getRealSourceUri(), getSourceResolver());
} catch (Exception e) {
throw new RepositoryException(e);
}
@@ -219,11 +219,9 @@
ByteArrayOutputStream out = null;
InputStream in = null;
- SourceResolver resolver = null;
TraversableSource source = null;
try {
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- source = (TraversableSource) resolver.resolveURI(getRealSourceUri());
+ source = (TraversableSource) getSourceResolver().resolveURI(getRealSourceUri());
if (source.exists() && !source.isCollection()) {
byte[] buf = new byte[4096];
@@ -250,12 +248,8 @@
} catch (Exception e) {
throw new RepositoryException(e);
}
-
- if (resolver != null) {
- if (source != null) {
- resolver.release(source);
- }
- this.manager.release(resolver);
+ if (source != null) {
+ getSourceResolver().release(source);
}
}
this.loadRevision = this.node.getCurrentRevisionNumber();
@@ -291,14 +285,12 @@
}
protected void saveTransactionable(String realSourceUri) throws RepositoryException {
- SourceResolver resolver = null;
ModifiableSource source = null;
InputStream in = null;
OutputStream out = null;
try {
- resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
- source = (ModifiableSource) resolver.resolveURI(realSourceUri);
+ source = (ModifiableSource) getSourceResolver().resolveURI(realSourceUri);
out = source.getOutputStream();
@@ -325,12 +317,8 @@
} catch (Throwable t) {
throw new RuntimeException("Could not close streams: ", t);
}
-
- if (resolver != null) {
- if (source != null) {
- resolver.release(source);
- }
- manager.release(resolver);
+ if (source != null) {
+ getSourceResolver().release(source);
}
}
}
@@ -393,9 +381,13 @@
loadData();
return new NodeOutputStream();
}
-
+
protected int getLoadRevision() {
return this.loadRevision;
}
+ protected SourceResolver getSourceResolver() {
+ return sourceResolver;
+ }
+
}
Added: lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/resources/META-INF/cocoon/spring/lenya-module-sourcerepository-components.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/resources/META-INF/cocoon/spring/lenya-module-sourcerepository-components.xml?rev=741384&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/resources/META-INF/cocoon/spring/lenya-module-sourcerepository-components.xml (added)
+++ lenya/trunk/org.apache.lenya.module.sourcerepository/src/main/resources/META-INF/cocoon/spring/lenya-module-sourcerepository-components.xml Fri Feb 6 03:16:59 2009
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
+ xmlns="http://www.springframework.org/schema/beans">
+ <bean name="org.apache.lenya.cms.repository.NodeFactory"
+ class="org.apache.lenya.cms.repository.SourceNodeFactory">
+ <property name="sourceResolver" ref="org.apache.excalibur.source.SourceResolver"/>
+ </bean>
+</beans>
Modified: lenya/trunk/org.apache.lenya.welcome/pom.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.welcome/pom.xml?rev=741384&r1=741383&r2=741384&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.welcome/pom.xml (original)
+++ lenya/trunk/org.apache.lenya.welcome/pom.xml Fri Feb 6 03:16:59 2009
@@ -100,5 +100,9 @@
<groupId>org.apache.lenya</groupId>
<artifactId>lenya-core-usecase</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.lenya</groupId>
+ <artifactId>lenya-module-sourcerepository</artifactId>
+ </dependency>
</dependencies>
</project>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.