Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 60024 invoked from network); 7 Jul 2005 06:19:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Jul 2005 06:19:04 -0000 Received: (qmail 50097 invoked by uid 500); 7 Jul 2005 06:19:03 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 50045 invoked by uid 500); 7 Jul 2005 06:19:03 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 50026 invoked by uid 99); 7 Jul 2005 06:19:02 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 06 Jul 2005 23:18:51 -0700 Received: (qmail 59968 invoked by uid 65534); 7 Jul 2005 06:18:49 -0000 Message-ID: <20050707061849.59966.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r209567 - in /cocoon: blocks/scratchpad/trunk/java/org/apache/cocoon/acting/ trunk/src/java/org/apache/cocoon/ trunk/src/java/org/apache/cocoon/components/blocks/ trunk/src/java/org/apache/cocoon/components/treeprocessor/ trunk/src/java/org... Date: Thu, 07 Jul 2005 06:18:45 -0000 To: cvs@cocoon.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.2 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: cziegeler Date: Wed Jul 6 23:18:44 2005 New Revision: 209567 URL: http://svn.apache.org/viewcvs?rev=209567&view=rev Log: Make sitemap interpreters available Modified: cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/acting/FlowAction.java cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java cocoon/trunk/src/java/org/apache/cocoon/Processor.java cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java cocoon/trunk/src/java/org/apache/cocoon/core/Core.java cocoon/trunk/src/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java cocoon/trunk/src/java/org/apache/cocoon/sitemap/Sitemap.java cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java Modified: cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/acting/FlowAction.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/acting/FlowAction.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/acting/FlowAction.java (original) +++ cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/acting/FlowAction.java Wed Jul 6 23:18:44 2005 @@ -19,15 +19,13 @@ import java.util.List; import java.util.Map; -import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; +import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.parameters.Parameters; -import org.apache.avalon.framework.service.ServiceSelector; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.components.flow.Interpreter; -import org.apache.cocoon.components.treeprocessor.sitemap.FlowNode; -import org.apache.cocoon.components.treeprocessor.sitemap.SitemapLanguage; +import org.apache.cocoon.core.Core; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.SourceResolver; @@ -35,19 +33,30 @@ * Action class which simply calls a function defined in the flow * script. * - * @version CVS $Id:$ + * @version CVS $Id$ */ public class FlowAction extends ServiceableAction - implements Contextualizable, ThreadSafe { + implements Disposable, ThreadSafe { - protected SitemapLanguage sitemapLanguage; + protected Core core; /** - * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) + * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) */ - public void contextualize(Context context) throws ContextException { - this.sitemapLanguage = (SitemapLanguage)context.get("sitemap-language"); + public void service(ServiceManager manager) throws ServiceException { + super.service(manager); + this.core = (Core)this.manager.lookup(Core.ROLE); + } + + /** + * @see org.apache.avalon.framework.activity.Disposable#dispose() + */ + public void dispose() { + if ( this.manager != null ) { + this.manager.release(this.core); + this.core = null; + } } /** @@ -62,15 +71,11 @@ final String language = param.getParameter("language", "javascript"); final String name = param.getParameter("function"); - FlowNode flowNode = (FlowNode)this.sitemapLanguage.getRegisteredNode("flow"); - if ( flowNode != null ) { - Interpreter interpreter = flowNode.getInterpreter(); - - // no arguments for now - final List args = Collections.EMPTY_LIST; + Interpreter interpreter = this.core.getCurrentSitemap().getInterpreter(language); + // no arguments for now + final List args = Collections.EMPTY_LIST; - interpreter.callFunction(name, args, redirector); - } + interpreter.callFunction(name, args, redirector); return EMPTY_MAP; } Modified: cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java Wed Jul 6 23:18:44 2005 @@ -58,6 +58,7 @@ import java.io.IOException; import java.net.URL; import java.util.Enumeration; +import java.util.HashMap; import java.util.Map; /** @@ -119,6 +120,9 @@ /** The Cocoon Core */ protected Core core; + /** Processor attributes */ + protected Map processorAttributes = new HashMap(); + /** * Creates a new Cocoon instance. */ @@ -598,4 +602,26 @@ public ServiceManager getServiceManager() { return this.serviceManager; } + + /** + * @see org.apache.cocoon.Processor#getAttribute(java.lang.String) + */ + public Object getAttribute(String name) { + return this.processorAttributes.get(name); + } + + /** + * @see org.apache.cocoon.Processor#removeAttribute(java.lang.String) + */ + public Object removeAttribute(String name) { + return this.processorAttributes.remove(name); + } + + /** + * @see org.apache.cocoon.Processor#setAttribute(java.lang.String, java.lang.Object) + */ + public void setAttribute(String name, Object value) { + this.processorAttributes.put(name, value); + } + } Modified: cocoon/trunk/src/java/org/apache/cocoon/Processor.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/Processor.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/Processor.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/Processor.java Wed Jul 6 23:18:44 2005 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -108,4 +108,22 @@ * @since 2.2 */ String getContext(); + + /** + * Sets an attribute + * @since 2.2 + */ + void setAttribute(String name, Object value); + + /** + * Gets an attribute + * @since 2.2 + */ + Object getAttribute(String name); + + /** + * Remove an attribute. + * @since 2.2 + */ + Object removeAttribute(String name); } Modified: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java Wed Jul 6 23:18:44 2005 @@ -74,6 +74,9 @@ private Map connections = new HashMap(); private Map properties = new HashMap(); + /** Processor attributes */ + protected Map processorAttributes = new HashMap(); + // Life cycle public void service(ServiceManager manager) throws ServiceException { @@ -396,5 +399,26 @@ public String getContext() { return this.environmentHelper.getContext(); + } + + /** + * @see org.apache.cocoon.Processor#getAttribute(java.lang.String) + */ + public Object getAttribute(String name) { + return this.processorAttributes.get(name); + } + + /** + * @see org.apache.cocoon.Processor#removeAttribute(java.lang.String) + */ + public Object removeAttribute(String name) { + return this.processorAttributes.remove(name); + } + + /** + * @see org.apache.cocoon.Processor#setAttribute(java.lang.String, java.lang.Object) + */ + public void setAttribute(String name, Object value) { + this.processorAttributes.put(name, value); } } Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java Wed Jul 6 23:18:44 2005 @@ -18,8 +18,10 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.configuration.Configuration; @@ -90,6 +92,9 @@ protected volatile boolean needsReload = false; protected boolean fresh = true; + /** Processor attributes */ + protected Map processorAttributes = new HashMap(); + public void onChangeDirectory( final File changeDirectory ) { if (!fresh) { if (getLogger().isDebugEnabled()) { @@ -501,5 +506,26 @@ public ServiceManager getServiceManager() { return this.manager; + } + + /** + * @see org.apache.cocoon.Processor#getAttribute(java.lang.String) + */ + public Object getAttribute(String name) { + return this.processorAttributes.get(name); + } + + /** + * @see org.apache.cocoon.Processor#removeAttribute(java.lang.String) + */ + public Object removeAttribute(String name) { + return this.processorAttributes.remove(name); + } + + /** + * @see org.apache.cocoon.Processor#setAttribute(java.lang.String, java.lang.Object) + */ + public void setAttribute(String name, Object value) { + this.processorAttributes.put(name, value); } } Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java Wed Jul 6 23:18:44 2005 @@ -16,6 +16,7 @@ package org.apache.cocoon.components.treeprocessor; import java.net.URL; + import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.configuration.Configurable; @@ -35,8 +36,10 @@ import org.apache.cocoon.Processor; import org.apache.cocoon.components.ContextHelper; import org.apache.cocoon.components.fam.SitemapMonitor; +import org.apache.cocoon.components.flow.Interpreter; import org.apache.cocoon.components.source.SourceUtil; import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper; +import org.apache.cocoon.components.treeprocessor.sitemap.FlowNode; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.internal.EnvironmentHelper; import org.apache.cocoon.sitemap.SitemapExecutor; @@ -429,6 +432,14 @@ if (getLogger().isDebugEnabled()) { getLogger().debug("ConcreteTreeProcessor ready"); } + + // Get the actual interpreter + FlowNode flowNode = (FlowNode)treeBuilder.getRegisteredNode("flow"); + if ( flowNode != null ) { + final Interpreter interpreter = flowNode.getInterpreter(); + newProcessor.setAttribute(Interpreter.ROLE, interpreter); + } + } finally { this.manager.release(treeBuilder); } @@ -483,4 +494,24 @@ this.manager = null; } } -} + + /** + * @see org.apache.cocoon.Processor#getAttribute(java.lang.String) + */ + public Object getAttribute(String name) { + return this.concreteProcessor.getAttribute(name); + } + + /** + * @see org.apache.cocoon.Processor#removeAttribute(java.lang.String) + */ + public Object removeAttribute(String name) { + return this.concreteProcessor.removeAttribute(name); + } + + /** + * @see org.apache.cocoon.Processor#setAttribute(java.lang.String, java.lang.Object) + */ + public void setAttribute(String name, Object value) { + this.concreteProcessor.setAttribute(name, value); + }} Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java Wed Jul 6 23:18:44 2005 @@ -209,8 +209,6 @@ newContext.put(Constants.CONTEXT_ENV_PREFIX, env.getURIPrefix()); // FIXME How to get rid of EnvironmentHelper? newContext.put(Constants.CONTEXT_ENV_HELPER, getProcessor().getWrappingProcessor().getEnvironmentHelper()); - // FIXME - find a better way to make the interpreter available - newContext.put("sitemap-language", this); return newContext; } Modified: cocoon/trunk/src/java/org/apache/cocoon/core/Core.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/Core.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/core/Core.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/core/Core.java Wed Jul 6 23:18:44 2005 @@ -29,6 +29,7 @@ import org.apache.cocoon.Constants; import org.apache.cocoon.Processor; import org.apache.cocoon.components.ContextHelper; +import org.apache.cocoon.components.flow.Interpreter; import org.apache.cocoon.core.container.ComponentLocatorWrapper; import org.apache.cocoon.environment.internal.EnvironmentHelper; import org.apache.cocoon.sitemap.ComponentLocator; @@ -217,10 +218,19 @@ } /** - * @see org.apache.cocoon.sitemap.Sitemap#getCurrentProcessor() + * @see org.apache.cocoon.sitemap.Sitemap#getProcessor() */ - public Processor getCurrentProcessor() { + public Processor getProcessor() { return EnvironmentHelper.getCurrentProcessor(); } + + /** + * @see org.apache.cocoon.sitemap.Sitemap#getInterpreter(java.lang.String) + */ + public Interpreter getInterpreter(String language) { + // TODO We ignore the language for now + return (Interpreter)this.getProcessor().getAttribute(Interpreter.ROLE); + } + } } Modified: cocoon/trunk/src/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java Wed Jul 6 23:18:44 2005 @@ -66,7 +66,6 @@ /** The last prefix, which is stripped off from the request uri */ protected String lastPrefix; - /** * Constructor * Modified: cocoon/trunk/src/java/org/apache/cocoon/sitemap/Sitemap.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/Sitemap.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/sitemap/Sitemap.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/Sitemap.java Wed Jul 6 23:18:44 2005 @@ -16,10 +16,10 @@ package org.apache.cocoon.sitemap; import org.apache.cocoon.Processor; +import org.apache.cocoon.components.flow.Interpreter; /** * TODO WORK IN PROGRESS!! - * TODO Add Interpreter(s) * * This interface describes the current sitemap. The current sitemap is available using * {@link org.apache.cocoon.core.Core#getCurrentSitemap()}. @@ -38,6 +38,13 @@ /** * Return the current processor */ - Processor getCurrentProcessor(); + Processor getProcessor(); + /** + * Return the Interpreter for the given language. If no + * interpreter is found null is returned. + * @param language The language or null for the default interpreter. + * @return The interpreter or null. + */ + Interpreter getInterpreter(String language); } Modified: cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java?rev=209567&r1=209566&r2=209567&view=diff ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java (original) +++ cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java Wed Jul 6 23:18:44 2005 @@ -67,4 +67,26 @@ public boolean process(Environment environment) throws Exception { return false; } + + /** + * @see org.apache.cocoon.Processor#getAttribute(java.lang.String) + */ + public Object getAttribute(String name) { + return null; + } + + /** + * @see org.apache.cocoon.Processor#removeAttribute(java.lang.String) + */ + public Object removeAttribute(String name) { + return null; + } + + /** + * @see org.apache.cocoon.Processor#setAttribute(java.lang.String, java.lang.Object) + */ + public void setAttribute(String name, Object value) { + // nothing to do + } + }