You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2005/03/18 19:27:56 UTC
svn commit: r158118 - in cocoon/blocks/spring-app/trunk:
java/org/apache/cocoon/spring/SpringComponentLocator.java samples/flow.js
samples/test.xml
Author: cziegeler
Date: Fri Mar 18 10:27:55 2005
New Revision: 158118
URL: http://svn.apache.org/viewcvs?view=rev&rev=158118
Log:
Make Cocoon core available to spring beans
Modified:
cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java
cocoon/blocks/spring-app/trunk/samples/flow.js
cocoon/blocks/spring-app/trunk/samples/test.xml
Modified: cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java?view=diff&r1=158117&r2=158118
==============================================================================
--- cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java (original)
+++ cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java Fri Mar 18 10:27:55 2005
@@ -31,6 +31,7 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.Constants;
+import org.apache.cocoon.core.Core;
import org.apache.cocoon.environment.internal.EnvironmentHelper;
import org.apache.cocoon.servlet.CocoonServlet;
import org.apache.cocoon.sitemap.ComponentLocator;
@@ -43,6 +44,7 @@
import org.springframework.context.ApplicationContextException;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
+import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.StringUtils;
import org.springframework.web.context.ConfigurableWebApplicationContext;
@@ -54,7 +56,7 @@
* TODO - we need to store the application context somewhere to use the context
* of a parent sitemap as the parent of a sub sitemap.
*
- * @version $Id:$
+ * @version $Id$
*/
public class SpringComponentLocator
extends AbstractLogEnabled
@@ -70,6 +72,7 @@
protected EnvironmentHelper environmentHelper;
protected ServiceManager manager;
protected SourceResolver resolver;
+ protected Core cocoon;
protected CocoonApplicationContext wac;
@@ -94,6 +97,7 @@
public void service(ServiceManager aManager) throws ServiceException {
this.manager = aManager;
this.resolver = (SourceResolver)this.manager.lookup(SourceResolver.ROLE);
+ this.cocoon = (Core)this.manager.lookup(Core.class.getName());
}
/**
@@ -121,6 +125,11 @@
// Determine parent for application context, if any.
ApplicationContext parent = this.loadParentContext();
+ // Make the core available as a bean, if not already done by a parent context
+ if ( parent == null || !parent.containsBean("cocoon-core") ) {
+ parent = this.createCocoonAppContext(parent);
+ }
+
this.wac = this.createWebApplicationContext(parent);
if (this.getLogger().isInfoEnabled()) {
@@ -157,6 +166,8 @@
if ( this.manager != null ) {
this.manager.release(this.resolver);
this.resolver = null;
+ this.manager.release(this.cocoon);
+ this.cocoon = null;
this.manager = null;
}
}
@@ -225,6 +236,20 @@
cwac.refresh();
return cwac;
+ }
+
+ /**
+ * Create an application context that contains Cocoon specific beans.
+ * @return
+ */
+ protected ApplicationContext createCocoonAppContext(ApplicationContext parent) {
+ GenericApplicationContext gac = new GenericApplicationContext();
+ gac.setParent(parent);
+ gac.refresh();
+ gac.getBeanFactory().registerSingleton("cocoon-core", this.cocoon);
+ gac.getBeanFactory().registerSingleton("cocoon-settings", this.cocoon.getSettings());
+
+ return gac;
}
/**
Modified: cocoon/blocks/spring-app/trunk/samples/flow.js
URL: http://svn.apache.org/viewcvs/cocoon/blocks/spring-app/trunk/samples/flow.js?view=diff&r1=158117&r2=158118
==============================================================================
--- cocoon/blocks/spring-app/trunk/samples/flow.js (original)
+++ cocoon/blocks/spring-app/trunk/samples/flow.js Fri Mar 18 10:27:55 2005
@@ -14,11 +14,14 @@
* limitations under the License.
*/
//
-// @version $Id:$
+// @version $Id$
//
function test() {
var component = cocoon.getComponent("spring-test");
- cocoon.sendPage("test", { "message" : component.getMessage()});
+ var core = cocoon.getComponent("cocoon-core");
+
+ cocoon.sendPage("test", { "message" : component.getMessage(),
+ "configuration" : core.getSettings().getConfiguration()});
}
Modified: cocoon/blocks/spring-app/trunk/samples/test.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/spring-app/trunk/samples/test.xml?view=diff&r1=158117&r2=158118
==============================================================================
--- cocoon/blocks/spring-app/trunk/samples/test.xml (original)
+++ cocoon/blocks/spring-app/trunk/samples/test.xml Fri Mar 18 10:27:55 2005
@@ -14,9 +14,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!-- SVN $Id:$ -->
+<!-- SVN $Id$ -->
<document xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
<p>This is a simple demo page</p>
<p>Messsage from a Spring Bean:</p>
<p>#{message}</p>
+ <p>Using the Cocoon core through Spring: This is the main configuration file location:</p>
+ <p>#{configuration}</p>
</document>