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 2006/10/03 10:02:40 UTC
svn commit: r452335 - in /cocoon/trunk:
blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/
blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/
blocks/c...
Author: cziegeler
Date: Tue Oct 3 01:02:39 2006
New Revision: 452335
URL: http://svn.apache.org/viewvc?view=rev&rev=452335
Log:
Add loading of flow scripts from default location
Added:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java (with props)
Modified:
cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java
cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java
Modified: cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java?view=diff&rev=452335&r1=452334&r2=452335
==============================================================================
--- cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java (original)
+++ cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java Tue Oct 3 01:02:39 2006
@@ -34,6 +34,7 @@
import org.apache.cocoon.components.flow.apples.DefaultAppleRequest;
import org.apache.cocoon.components.flow.apples.DefaultAppleResponse;
import org.apache.cocoon.components.flow.apples.StatelessAppleController;
+import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Response;
@@ -45,6 +46,7 @@
* @version $Id$
*/
public class ApplesProcessor extends AbstractInterpreter implements ContinuationsDisposer {
+
public void callFunction(String className, List params, Redirector redirector) throws Exception {
AppleController app = instantiateController(className);
@@ -99,9 +101,9 @@
private void processApple(List params, Redirector redirector, AppleController app, WebContinuation wk)
throws Exception {
- Request cocoonRequest = ContextHelper.getRequest(this.avalonContext);
+ Request cocoonRequest = ObjectModelHelper.getRequest(this.processInfoProvider.getObjectModel());
AppleRequest req = new DefaultAppleRequest(params, cocoonRequest);
- Response cocoonResponse = ContextHelper.getResponse(this.avalonContext);
+ Response cocoonResponse = ObjectModelHelper.getResponse(this.processInfoProvider.getObjectModel());
DefaultAppleResponse res = new DefaultAppleResponse(cocoonResponse);
try {
Modified: cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java?view=diff&rev=452335&r1=452334&r2=452335
==============================================================================
--- cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java (original)
+++ cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java Tue Oct 3 01:02:39 2006
@@ -36,8 +36,7 @@
private Location location;
private StringBuffer message;
- public JSErrorReporter(Logger logger)
- {
+ public JSErrorReporter(Logger logger) {
this.logger = logger;
}
Modified: cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java?view=diff&rev=452335&r1=452334&r2=452335
==============================================================================
--- cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java (original)
+++ cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java Tue Oct 3 01:02:39 2006
@@ -203,7 +203,7 @@
*/
private ThreadScope getSessionScope() throws Exception {
final String scopeID = USER_GLOBAL_SCOPE + getInterpreterID();
- final Request request = ContextHelper.getRequest(this.avalonContext);
+ final Request request = ObjectModelHelper.getRequest(this.processInfoProvider.getObjectModel());
ThreadScope scope = null;
@@ -234,7 +234,7 @@
private void setSessionScope(ThreadScope scope) throws Exception {
if (scope.useSession) {
final String scopeID = USER_GLOBAL_SCOPE + getInterpreterID();
- final Request request = ContextHelper.getRequest(this.avalonContext);
+ final Request request = ObjectModelHelper.getRequest(this.processInfoProvider.getObjectModel());
// FIXME: Where "session scope" should go when session is invalidated?
// Attach the scope to the current context
@@ -733,7 +733,7 @@
}
private void setupView(Scriptable scope, FOM_Cocoon cocoon, FOM_WebContinuation kont) {
- Map objectModel = ContextHelper.getObjectModel(this.avalonContext);
+ final Map objectModel = this.processInfoProvider.getObjectModel();
// Make the JS live-connect objects available to the view layer
FOM_JavaScriptFlowHelper.setPackages(objectModel,
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java?view=diff&rev=452335&r1=452334&r2=452335
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java Tue Oct 3 01:02:39 2006
@@ -30,11 +30,9 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.SingleThreaded;
-import org.apache.cocoon.Constants;
-import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.environment.Context;
import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.processing.ProcessInfoProvider;
import org.apache.excalibur.source.SourceUtil;
/**
@@ -62,15 +60,14 @@
private String instanceID;
protected org.apache.avalon.framework.context.Context avalonContext;
-
/**
* List of source locations that need to be resolved.
*/
protected ArrayList needResolve = new ArrayList();
- protected org.apache.cocoon.environment.Context context;
protected ServiceManager manager;
protected ContinuationsManager continuationsMgr;
+ protected ProcessInfoProvider processInfoProvider;
/** The settings of Cocoon. */
protected Settings settings;
@@ -120,15 +117,15 @@
this.manager = sm;
this.continuationsMgr = (ContinuationsManager)sm.lookup(ContinuationsManager.ROLE);
this.settings = (Settings)this.manager.lookup(Settings.ROLE);
+ this.processInfoProvider = (ProcessInfoProvider)this.manager.lookup(ProcessInfoProvider.ROLE);
}
/**
* @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
*/
- public void contextualize(org.apache.avalon.framework.context.Context context)
+ public void contextualize(org.apache.avalon.framework.context.Context aContext)
throws ContextException{
- this.avalonContext = context;
- this.context = (Context)context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
+ this.avalonContext = aContext;
}
/**
@@ -137,9 +134,12 @@
public void dispose() {
if ( this.manager != null ) {
this.manager.release( this.continuationsMgr );
+ this.manager.release( this.settings );
+ this.manager.release( this.processInfoProvider );
this.continuationsMgr = null;
- this.manager = null;
this.settings = null;
+ this.processInfoProvider = null;
+ this.manager = null;
}
}
@@ -185,7 +185,7 @@
throws Exception {
if (SourceUtil.indexOfSchemeColon(uri) == -1) {
uri = "cocoon:/" + uri;
- Map objectModel = ContextHelper.getObjectModel(this.avalonContext);
+ final Map objectModel = this.processInfoProvider.getObjectModel();
FlowHelper.setWebContinuation(objectModel, continuation);
FlowHelper.setContextObject(objectModel, bizData);
if (redirector.hasRedirected()) {
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java?view=diff&rev=452335&r1=452334&r2=452335
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java Tue Oct 3 01:02:39 2006
@@ -18,10 +18,13 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.cocoon.components.flow.AbstractInterpreter;
import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.core.container.spring.ResourceUtils;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
/**
@@ -52,19 +55,23 @@
// since 2.2 we add by default all flow scripts located in the ./flow directory
// The default location can be overwritten by specifying the location attribute.
// we only include the scripts if the language is javascript
- /*
- if ( "javascript".equals(language) && node.getInterpreter() instanceof AbstractInterpreter ) {
- // FIXME we need the resource loader
- final String scriptLocation = config.getAttribute("location", DEFAULT_FLOW_SCRIPT_LOCATION);
- PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
- final Resource[] resources = resolver.getResources(scriptLocation + "/*.js");
- if ( resources != null ) {
- for(int i=0; i < resources.length; i++) {
- ((AbstractInterpreter)node.getInterpreter()).register(resources[i].getURL().toExternalForm());
+ if ( "javascript".equals(language) ) {
+ final BeanFactory beanFactory = this.treeBuilder.getContainer().getBeanFactory();
+ if ( beanFactory instanceof ApplicationContext ) {
+ final ResourceLoader resourceLoader = (ApplicationContext)beanFactory;
+ final String scriptLocation = config.getAttribute("location", DEFAULT_FLOW_SCRIPT_LOCATION);
+ if ( resourceLoader.getResource(scriptLocation).exists() ) {
+ final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
+ final Resource[] resources = resolver.getResources(scriptLocation + "/*.js");
+ if ( resources != null ) {
+ for(int i=0; i < resources.length; i++) {
+ node.getInterpreter().register(ResourceUtils.getUri(resources[i]));
+ }
+ }
}
}
}
- */
+
// now process child nodes
buildChildNodesList(config);
Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java?view=auto&rev=452335
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java Tue Oct 3 01:02:39 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.cocoon.core.container.spring;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.springframework.core.io.Resource;
+
+/**
+ * Utility class for Spring resource handling
+ * @version $Id$
+ */
+public class ResourceUtils {
+
+ /**
+ * Get the uri of a resource.
+ * This method corrects the uri in the case of the file protocol
+ * on windows.
+ * @param resource The resource.
+ * @return The uri.
+ * @throws IOException
+ */
+ public static String getUri(Resource resource)
+ throws IOException {
+ if ( resource == null ) {
+ return null;
+ }
+ return correctUri(resource.getURL().toExternalForm());
+ }
+
+ protected static String correctUri(String uri) {
+ // if it is a file we have to recreate the url,
+ // otherwise we get problems under windows with some file
+ // references starting with "/DRIVELETTER" and some
+ // just with "DRIVELETTER"
+ if ( uri.startsWith("file:") ) {
+ final File f = new File(uri.substring(5));
+ return "file://" + f.getAbsolutePath();
+ }
+ return uri;
+ }
+}
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java?view=diff&rev=452335&r1=452334&r2=452335
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java Tue Oct 3 01:02:39 2006
@@ -34,6 +34,7 @@
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.cocoon.Constants;
import org.apache.cocoon.core.container.spring.AbstractSettingsBeanFactoryPostProcessor;
+import org.apache.cocoon.core.container.spring.ResourceUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
@@ -486,15 +487,7 @@
final Configuration includeStatement)
throws ConfigurationException, IOException {
// If already loaded: do nothing
- String uri = src.getURL().toExternalForm();
- // if it is a file we have to recreate the url,
- // otherwise we get problems under windows with some file
- // references starting with "/DRIVELETTER" and some
- // just with "DRIVELETTER"
- if ( uri.startsWith("file:") ) {
- final File f = new File(uri.substring(5));
- uri = "file://" + f.getAbsolutePath();
- }
+ final String uri = ResourceUtils.getUri(src);
if (!loadedURIs.contains(uri)) {
if ( this.logger.isDebugEnabled() ) {
this.logger.debug("Loading configuration: " + uri);