Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 39123 invoked from network); 14 Jan 2007 11:32:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Jan 2007 11:32:20 -0000 Received: (qmail 71104 invoked by uid 500); 14 Jan 2007 11:32:26 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 71056 invoked by uid 500); 14 Jan 2007 11:32:26 -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 71044 invoked by uid 99); 14 Jan 2007 11:32:26 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Jan 2007 03:32:26 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Jan 2007 03:32:17 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 011861A981A; Sun, 14 Jan 2007 03:31:14 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r496063 - in /cocoon/trunk/core/cocoon-servlet-service: cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/blocks/ cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/servletservice/ cocoon-servlet-service-demo1/src/main/... Date: Sun, 14 Jan 2007 11:31:14 -0000 To: cvs@cocoon.apache.org From: danielf@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070114113115.011861A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: danielf Date: Sun Jan 14 03:31:10 2007 New Revision: 496063 URL: http://svn.apache.org/viewvc?view=rev&rev=496063 Log: Name changes. Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/servletservice/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/servletservice/demo1/ - copied from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/blocks/demo1/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo1-servletService.xml - copied, changed from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo1-blockServlet.xml cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/java/org/apache/cocoon/servletservice/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/java/org/apache/cocoon/servletservice/demo2/ - copied from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/java/org/apache/cocoon/blocks/demo2/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo2-servletService.xml - copied, changed from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo2-blockServlet.xml cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java - copied, changed from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/DispatcherServlet.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DynamicProxyRequestHandler.java - copied, changed from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/DynamicProxyRequestHandler.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/ - copied from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/components/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ - copied from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/shielding/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ - copied from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/util/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-path-module.xconf - copied, changed from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-path-module.xconf cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-property-module.xconf - copied, changed from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-property-module.xconf cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-servlet-source-factory.xconf - copied, changed from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-source-factory.xconf Removed: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/blocks/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo1-blockServlet.xml cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/java/org/apache/cocoon/blocks/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo2-blockServlet.xml cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-path-module.xconf cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-property-module.xconf cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-source-factory.xconf cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/org/ Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/servletservice/demo1/DemoServlet.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/java/org/apache/cocoon/servletservice/demo2/DemoServlet.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSource.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSourceFactory.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldedGroupClassLoaderManager.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingBlockServlet.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingClassLoaderInterceptor.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletResponse.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/RequestParameters.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletConfigurationWrapper.java cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletContextWrapper.java Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/servletservice/demo1/DemoServlet.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/servletservice/demo1/DemoServlet.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/servletservice/demo1/DemoServlet.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/java/org/apache/cocoon/servletservice/demo1/DemoServlet.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.demo1; +package org.apache.cocoon.servletservice.demo1; import java.io.IOException; import java.io.InputStream; Copied: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo1-servletService.xml (from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo1-blockServlet.xml) URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo1-servletService.xml?view=diff&rev=496063&p1=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo1-blockServlet.xml&r1=496060&p2=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo1-servletService.xml&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo1-blockServlet.xml (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo1/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo1-servletService.xml Sun Jan 14 03:31:10 2007 @@ -20,9 +20,9 @@ - + - + @@ -30,7 +30,7 @@ - + Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/java/org/apache/cocoon/servletservice/demo2/DemoServlet.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/java/org/apache/cocoon/servletservice/demo2/DemoServlet.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/java/org/apache/cocoon/servletservice/demo2/DemoServlet.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/java/org/apache/cocoon/servletservice/demo2/DemoServlet.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.demo2; +package org.apache.cocoon.servletservice.demo2; import java.io.IOException; import java.io.PrintWriter; Copied: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo2-servletService.xml (from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo2-blockServlet.xml) URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo2-servletService.xml?view=diff&rev=496063&p1=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo2-blockServlet.xml&r1=496060&p2=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo2-servletService.xml&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-blocks-fw-demo2-blockServlet.xml (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-demo2/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-demo2-servletService.xml Sun Jan 14 03:31:10 2007 @@ -20,8 +20,8 @@ - + - + Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java?view=auto&rev=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java (added) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java Sun Jan 14 03:31:10 2007 @@ -0,0 +1,126 @@ +/* + * 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.servletservice; + +import java.util.Stack; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + +/** + * Stack used for geting hold on the current block servlet + * + * @version $Id: BlockCallStack.java 496060 2007-01-14 11:03:06Z danielf $ + * @since 2.2 + */ +public class CallStack { + + /** The block stack */ + private static final ThreadLocal blockStack = new ThreadLocal(); + + /** Keep track on if it is an ordinary or a super call */ + private static class BlockCallStackInfo { + public BlockCallStackInfo(ServletContext servletContext, boolean superCall) { + this.servletContext = servletContext; + this.superCall = superCall; + } + public ServletContext servletContext; + public boolean superCall; + }; + + /** + * This hook must be called each time a block is entered. + * + *

This method should never raise an exception, except when the + * parameters are not set!

+ * + * @throws ServletException if block is null + */ + public static void enterBlock(ServletContext context) + throws ServletException { + enterBlock(context, false); + } + + /** + * This hook must be called each time a super block is entered. + * + *

This method should never raise an exception, except when the + * parameters are not set!

+ * + * @throws ServletException if block is null + */ + public static void enterSuperBlock(ServletContext context) + throws ServletException { + enterBlock(context, true); + } + + private static void enterBlock(ServletContext context, boolean superCall) + throws ServletException { + if (null == context) { + throw new ServletException("Block is not set."); + } + + Stack stack = (Stack)blockStack.get(); + if (stack == null) { + stack = new Stack(); + blockStack.set(stack); + } + BlockCallStackInfo info = new BlockCallStackInfo(context, superCall); + stack.push(info); + } + + /** + * This hook must be called each time a block is left. + * + *

It's the counterpart to the {@link #enterBlock(Block)} + * method.

+ */ + public static void leaveBlock() { + final Stack stack = (Stack)blockStack.get(); + stack.pop(); + } + + /** + * Use this method for getting the context that should be used for + * resolving a polymorphic block protocol call + * @return a servlet context + */ + public static ServletContext getBaseBlockContext() { + final Stack stack = (Stack)blockStack.get(); + if (stack != null) { + for(int i = stack.size() - 1; i >= 0; i--) { + BlockCallStackInfo info = (BlockCallStackInfo) stack.elementAt(i); + if (!info.superCall) + return info.servletContext; + } + } + return null; + } + + /** + * Use this method for getting the context that should be used for + * resolving a block protocol call to a super block + * @return a servlet context + */ + public static ServletContext getCurrentBlockContext() { + final Stack stack = (Stack)blockStack.get(); + if (stack != null && !stack.isEmpty()) { + return ((BlockCallStackInfo)stack.peek()).servletContext; + } + return null; + } +} Copied: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java (from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/DispatcherServlet.java) URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java?view=diff&rev=496063&p1=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/DispatcherServlet.java&r1=496060&p2=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/DispatcherServlet.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks; +package org.apache.cocoon.servletservice; import java.io.IOException; import java.lang.reflect.Proxy; Copied: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DynamicProxyRequestHandler.java (from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/DynamicProxyRequestHandler.java) URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DynamicProxyRequestHandler.java?view=diff&rev=496063&p1=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/DynamicProxyRequestHandler.java&r1=496060&p2=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DynamicProxyRequestHandler.java&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/blocks/DynamicProxyRequestHandler.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DynamicProxyRequestHandler.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks; +package org.apache.cocoon.servletservice; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java?view=auto&rev=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java (added) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java Sun Jan 14 03:31:10 2007 @@ -0,0 +1,156 @@ +/* + * 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.servletservice; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLConnection; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + +import org.apache.avalon.framework.logger.Logger; +import org.apache.cocoon.CascadingIOException; +import org.apache.cocoon.servletservice.util.BlockCallHttpServletRequest; +import org.apache.cocoon.servletservice.util.BlockCallHttpServletResponse; + +/** + * Implementation of a {@link URLConnection} that gets its content by + * invoking the Block. + * + * TODO Plenty of work left to have a meaningfull implementation of all methods + * + * @version $Id: BlockConnection.java 496060 2007-01-14 11:03:06Z danielf $ + */ +public final class ServletConnection { + + /** Wrapped request */ + private BlockCallHttpServletRequest request; + + /** Wrapped response */ + private BlockCallHttpServletResponse response; + + /** The name of the called block */ + private String blockName; + + /** The current block context */ + private final ServletContext context; + + private String systemId; + + private Logger logger; + + /** + * Construct a new object + */ + public ServletConnection(String url, Logger logger) + throws MalformedURLException { + + this.logger = logger; + + URI blockURI = null; + try { + blockURI = parseBlockURI(new URI(url.toString())); + } catch (URISyntaxException e) { + throw new MalformedURLException("Malformed URI in block source " + + e.getMessage()); + } + + // Super calls are resolved relative the current context and ordinary + // calls relative the last non super call in the call chain + if (ServletServiceContext.SUPER.equals(this.blockName)) + this.context = CallStack.getCurrentBlockContext(); + else + this.context = CallStack.getBaseBlockContext(); + + if (this.context == null) + throw new MalformedURLException("Must be used in a block context " + url); + + this.request = new BlockCallHttpServletRequest(blockURI); + this.response = new BlockCallHttpServletResponse(); + } + + public void connect() throws IOException {} + + /** + * Return an InputStream object to read from the source. + */ + public InputStream getInputStream() throws IOException { + + ByteArrayOutputStream os = new ByteArrayOutputStream(); + this.response.setOutputStream(os); + RequestDispatcher dispatcher = null; + + try { + if (this.blockName == null) { + // FIXME Should be called with path + queryString, + // but the argument is ignored so it doesn't matter + dispatcher = this.context.getRequestDispatcher(this.systemId); + } else { + dispatcher = this.context.getNamedDispatcher(this.blockName); + } + if (dispatcher == null) + throw new ServletException("No dispatcher for " + this.systemId); + dispatcher.forward(this.request, this.response); + this.response.flushBuffer(); + + byte[] out = os.toByteArray(); + + return new ByteArrayInputStream(out); + } catch (ServletException e) { + throw new CascadingIOException("BlockConnection " + e.getMessage(), e); + } finally { + os.close(); + } + } + + protected final Logger getLogger() { + return this.logger; + } + + // Parse the block protocol. + private URI parseBlockURI(URI uri) throws URISyntaxException { + // Can't happen + if (!uri.isAbsolute()) { + throw new URISyntaxException(uri.toString(), + "Only absolute URIs are allowed for the block protocol."); + } + String scheme = uri.getScheme(); + + this.logger.debug("BlockSource: resolving " + uri.toString() + " with scheme " + + uri.getScheme() + " and ssp " + uri.getRawSchemeSpecificPart()); + uri = new URI(uri.getRawSchemeSpecificPart()); + this.logger.debug("BlockSource: resolved to " + uri.toString()); + + this.blockName = uri.getScheme(); + String path = uri.getPath(); + // All URIs, also relative are resolved and processed from the block manager + String queryString = uri.getQuery(); + + // FIXME: This will not be a system global id, as the blockName is block local. + String ssp = (new URI(this.blockName, null, path, queryString, null)).toString(); + this.systemId = (new URI(scheme, ssp, null)).toString(); + + return new URI(scheme, null, path, queryString, null); + } +} Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java?view=auto&rev=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java (added) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java Sun Jan 14 03:31:10 2007 @@ -0,0 +1,205 @@ +/* + * 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.servletservice; + +import java.io.IOException; +import java.util.Enumeration; +import java.util.Map; + +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.cocoon.servletservice.util.ServletConfigurationWrapper; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanNameAware; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.web.context.ServletContextAware; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.GenericWebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * @version $Id: BlockServlet.java 496060 2007-01-14 11:03:06Z danielf $ + */ +public class ServletService extends HttpServlet + implements ApplicationContextAware, ServletContextAware, BeanNameAware, InitializingBean, DisposableBean { + + private ServletServiceContext blockContext; + private String embeddedServletClass; + private Servlet embeddedServlet; + private ServletContext servletContext; + private String beanName; + private ApplicationContext parentContainer; + + public ServletService() { + this.blockContext = new ServletServiceContext(); + } + + /* (non-Javadoc) + * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) + */ + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + this.blockContext.setServletContext(servletConfig.getServletContext()); + + // create a sub container that resolves paths relative to the block + // context rather than the parent context and make it available in + // a context attribute + if (this.parentContainer == null) + this.parentContainer = + WebApplicationContextUtils.getRequiredWebApplicationContext(servletConfig.getServletContext()); + GenericWebApplicationContext container = new GenericWebApplicationContext(); + container.setParent(this.parentContainer); + container.setServletContext(this.blockContext); + container.refresh(); + this.blockContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, container); + + // create a servlet config based on the block servlet context + ServletConfig blockServletConfig = + new ServletConfigurationWrapper(servletConfig, this.blockContext) { + + // FIXME: The context should get the init parameters from the + // config rather than the oposite way around. + public String getInitParameter(String name) { + return super.getServletContext().getInitParameter(name); + } + + public Enumeration getInitParameterNames() { + return super.getServletContext().getInitParameterNames(); + } + }; + + // create and initialize the embeded servlet + this.embeddedServlet = createEmbeddedServlet(this.embeddedServletClass, blockServletConfig); + this.embeddedServlet.init(blockServletConfig); + this.blockContext.setServlet(this.embeddedServlet); + } + + /** + * Creates and initializes the embedded servlet + * @param string + * @throws ServletException + */ + protected Servlet createEmbeddedServlet(String embeddedServletClassName, ServletConfig servletConfig) + throws ServletException { + try { + return (Servlet) this.getClass().getClassLoader().loadClass(embeddedServletClassName).newInstance(); + } catch (Exception e) { + throw new ServletException("Loading class for embedded servlet failed " + embeddedServletClassName, e); + } + } + + /* (non-Javadoc) + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + protected void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + RequestDispatcher dispatcher = + this.blockContext.getRequestDispatcher(request.getPathInfo()); + dispatcher.forward(request, response); + } + + public void destroy() { + this.embeddedServlet.destroy(); + super.destroy(); + } + + /** + * @return the blockContext + */ + public ServletServiceContext getBlockContext() { + return this.blockContext; + } + + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.parentContainer = applicationContext; + } + + public void setServletContext(ServletContext servletContext) { + this.servletContext = servletContext; + } + + public void setBeanName(String beanName) { + this.beanName = beanName; + } + + public void setMountPath(String mountPath) { + this.blockContext.setMountPath(mountPath); + } + + public String getMountPath() { + return this.blockContext.getMountPath(); + } + + /** + * The path to the blocks resources relative to the servlet context URL, + * must start with an '/'. + * @param blockContextURL + */ + // FIXME: would like to throw an exeption if the form of the url is faulty, + // what is the prefered way of handling faulty properties in Spring? + public void setBlockContextURL(String blockContextURL) { + this.blockContext.setBlockContextURL(blockContextURL); + } + + public void setServletClass(String servletClass) { + this.embeddedServletClass = servletClass; + } + + public void setProperties(Map properties) { + this.blockContext.setProperties(properties); + } + + public void setConnections(Map connections) { + this.blockContext.setConnections(connections); + } + + public void afterPropertiesSet() throws Exception { + + // Create a servlet config object based on the servlet context + // from the webapp container + ServletConfig servletConfig = new ServletConfig() { + + public String getInitParameter(String parameter) { + return ServletService.this.servletContext.getInitParameter(parameter); + } + + public Enumeration getInitParameterNames() { + return ServletService.this.servletContext.getInitParameterNames(); + } + + public ServletContext getServletContext() { + return ServletService.this.servletContext; + } + + public String getServletName() { + return ServletService.this.beanName; + } + + }; + this.init(servletConfig); + } +} Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java?view=auto&rev=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java (added) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java Sun Jan 14 03:31:10 2007 @@ -0,0 +1,542 @@ +/* + * 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.servletservice; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; +import java.util.Vector; + +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; + +import org.apache.cocoon.servletservice.util.ServletContextWrapper; +import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.SourceResolver; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * @version $Id: BlockContext.java 496060 2007-01-14 11:03:06Z danielf $ + */ +public class ServletServiceContext extends ServletContextWrapper { + + public static final String SUPER = "super"; + + private Hashtable attributes = new Hashtable(); + private Servlet servlet; + private String mountPath; + private String blockContextURL; + private Map properties; + private Map connections; + + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getAttribute(java.lang.String) + */ + /* + * TODO ineritance of attributes from the parent context is only + * partly implemented: removeAttribute and getAttributeNames + * doesn't respect inheritance yet. + */ + public Object getAttribute(String name) { + Object value = this.attributes.get(name); + return value != null ? value : super.getAttribute(name); + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#setAttribute(java.lang.String, + * java.lang.Object) + */ + public void setAttribute(String name, Object value) { + this.attributes.put(name, value); + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#removeAttribute(java.lang.String) + */ + public void removeAttribute(String name) { + this.attributes.remove(name); + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getAttributeNames() + */ + public Enumeration getAttributeNames() { + return this.attributes.keys(); + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getResource(java.lang.String) + */ + public URL getResource(String path) throws MalformedURLException { + // hack for getting a file protocol or other protocols that can be used as context + // path in the getResource method in the servlet context + if (!(blockContextURL.startsWith("file:") || blockContextURL.startsWith("/") + || blockContextURL.indexOf(':') == -1)) { + SourceResolver resolver = null; + Source source = null; + try { + BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(this); + resolver = (SourceResolver) factory.getBean(SourceResolver.ROLE); + source = resolver.resolveURI(blockContextURL); + blockContextURL = source.getURI(); + } catch (IOException e) { + throw new MalformedURLException("Could not resolve " + blockContextURL); + } finally { + if (resolver != null) + resolver.release(source); + } + } + + // HACK: allow file:/ URLs for reloading of sitemaps during development + if (this.blockContextURL.startsWith("file:")) { + return new URL("file", null, this.blockContextURL.substring("file:".length()) + path); + } else { + if (this.blockContextURL.length() != 0 && this.blockContextURL.charAt(0) != '/') + throw new MalformedURLException("The blockContextURL must be empty or start with '/' " + + this.blockContextURL); + + // prefix the path with the block context resolve and resolve in the embeding + // servlet context + return super.getResource(this.blockContextURL + path); + } + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getRealPath(java.lang.String) + */ + public String getRealPath(String path) { + // We better don't assume that blocks are unpacked + return null; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getInitParameter(java.lang.String) + */ + // FIXME, this should be defined in the config instead + public String getInitParameter(String name) { + if (this.properties == null) + return null; + String value = (String) this.properties.get(name); + // Ask the super block for the property + if (value == null) { + ServletContext superContext = this.getNamedContext(SUPER); + if (superContext != null) + value = superContext.getInitParameter(name); + } + // Ask the parent context + if (value == null) { + super.getInitParameter(name); + } + return value; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getInitParameterNames() + */ + public Enumeration getInitParameterNames() { + Vector names = new Vector(); + + // add all names of the parent servlet context + Enumeration enumeration = super.getInitParameterNames(); + while (enumeration.hasMoreElements()) { + names.add(enumeration.nextElement()); + } + + // add names of the super block + ServletContext superContext = this.getNamedContext(SUPER); + if (superContext != null) { + enumeration = superContext.getInitParameterNames(); + while (enumeration.hasMoreElements()) { + names.add(enumeration.nextElement()); + } + } + + // add property names of this block + if (this.properties != null) { + names.addAll(this.properties.keySet()); + } + + return names.elements(); + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String) + */ + public InputStream getResourceAsStream(String path) { + try { + return this.getResource(path).openStream(); + } catch (IOException e) { + // FIXME Error handling + e.printStackTrace(); + return null; + } + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getContext(java.lang.String) + */ + public ServletContext getContext(String uripath) { + return null; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getMajorVersion() + */ + public int getMajorVersion() { + return 2; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getMinorVersion() + */ + public int getMinorVersion() { + return 3; + } + + private Collection getDirectoryList(File file, String pathPrefix) { + ArrayList filenames = new ArrayList(); + + if (!file.isDirectory()) { + filenames.add("/" + file.toString().substring(pathPrefix.length()-1)); + return filenames; + } + + File[] files = file.listFiles(); + + for (int i = 0; i < files.length; i++) { + File subfile = files[i]; + filenames.addAll(getDirectoryList(subfile, pathPrefix)); + } + + return filenames; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String) + */ + public Set getResourcePaths(String path) { + String pathPrefix; + if (this.blockContextURL.startsWith("file:")) { + pathPrefix = this.blockContextURL.substring("file:".length()); + } else { + pathPrefix = this.blockContextURL; + } + + path = pathPrefix + path; + + if (path == null) { + return Collections.EMPTY_SET; + } + + File file = new File(path); + + if (!file.exists()) { + return Collections.EMPTY_SET; + } + + HashSet set = new HashSet(); + set.addAll(getDirectoryList(file, pathPrefix)); + + return set; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String) + */ + public RequestDispatcher getRequestDispatcher(String path) { + PathDispatcher dispatcher = new PathDispatcher(path); + return dispatcher.exists() ? dispatcher : null; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String) + */ + public RequestDispatcher getNamedDispatcher(String name) { + NamedDispatcher dispatcher = new NamedDispatcher(name); + return dispatcher.exists() ? dispatcher : null; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getServerInfo() + */ + public String getServerInfo() { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.ServletContext#getServletContextName() + */ + public String getServletContextName() { + // TODO Auto-generated method stub + return null; + } + + // Block specific methods + + /** + * Set the servlet of the block + * @param servlet + */ + public void setServlet(Servlet servlet) { + this.servlet = servlet; + } + + /** + * Takes the scheme specific part of a block URI (the scheme is the + * responsibilty of the BlockSource) and resolve it with respect to the + * blocks mount point. + */ + public URI absolutizeURI(URI uri) throws URISyntaxException { + String blockName = uri.getScheme(); + ServletServiceContext blockContext; + if (blockName == null) { + // this block + blockContext = this; + } else { + // another block + blockContext = (ServletServiceContext) this.getNamedContext(blockName); + if (blockContext == null) + throw new URISyntaxException(uri.toString(), "Unknown block name"); + } + + String mountPath = blockContext.getMountPath(); + if (mountPath == null) + throw new URISyntaxException(uri.toString(), + "No mount point for this URI"); + if (mountPath.endsWith("/")) + mountPath = mountPath.substring(0, mountPath.length() - 1); + String absoluteURI = mountPath + uri.getSchemeSpecificPart(); + log("Resolving " + uri.toString() + " to " + absoluteURI); + return new URI(absoluteURI); + } + + /** + * Get the context of a block with a given name. + */ + // FIXME implement NPE handling + public ServletContext getNamedContext(String name) { + if (this.connections == null) { + return null; + } + + ServletService blockServlet = + (ServletService) this.connections.get(name); + return blockServlet != null ? blockServlet.getBlockContext() : null; + } + + /** + * @param mountPath The mountPath to set. + */ + public void setMountPath(String mountPath) { + this.mountPath = mountPath; + } + + /** + * Get the mount path of the block context + */ + public String getMountPath() { + return this.mountPath; + } + + /** + * @param blockContextURL the blockContextURL to set + */ + public void setBlockContextURL(String blockContextURL) { + this.blockContextURL = blockContextURL; + } + + /** + * @param properties The properties to set. + */ + public void setProperties(Map properties) { + this.properties = properties; + } + + /** + * @param connections the connections to set + */ + public void setConnections(Map connections) { + this.connections = connections; + } + + protected class NamedDispatcher implements RequestDispatcher { + + private String blockName; + private boolean superCall = false; + private ServletContext context; + + public NamedDispatcher(String blockName) { + this.blockName = blockName; + this.superCall = SUPER.equals(this.blockName); + + // Call to a named block that exists in the current context + this.context = ServletServiceContext.this.getNamedContext(this.blockName); + if (this.context == null) { + // If there is a super block, the connection might + // be defined there instead. + ServletServiceContext superContext = + (ServletServiceContext) ServletServiceContext.this.getNamedContext(SUPER); + if (superContext != null) { + this.context = superContext.getNamedContext(this.blockName); + this.superCall = true; + } + } + } + + protected boolean exists() { + return this.context != null; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, + * javax.servlet.ServletResponse) + */ + public void forward(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + // Call to named block + + ServletServiceContext.this.log("Enter processing in block " + this.blockName); + RequestDispatcher dispatcher = + this.context.getRequestDispatcher(((HttpServletRequest)request).getPathInfo()); + if (dispatcher != null && dispatcher instanceof PathDispatcher) { + ((PathDispatcher)dispatcher).forward(request, response, this.superCall); + } else { + // Cannot happen + throw new IllegalStateException(); + } + ServletServiceContext.this.log("Leaving processing in block " + this.blockName); + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, + * javax.servlet.ServletResponse) + */ + public void include(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + throw new UnsupportedOperationException(); + } + } + + /** + * Limited functionality, assumes that there is at most one servlet in the block + */ + private class PathDispatcher implements RequestDispatcher { + + // Ignores path, as the assumed only servlet within the block is + // implicitly mounted on '/*' + private PathDispatcher(String path) { + } + + private boolean exists() { + return ServletServiceContext.this.servlet != null; + } + + /* (non-Javadoc) + * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse) + */ + public void forward(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + this.forward(request, response, false); + } + + protected void forward(ServletRequest request, ServletResponse response, boolean superCall) + throws ServletException, IOException { + try { + if (!superCall) { + // It is important to set the current block each time + // a new block is entered, this is used for the block + // protocol + CallStack.enterBlock(ServletServiceContext.this); + } else { + // A super block should be called in the context of + // the called block to get polymorphic calls resolved + // in the right way. We still need to register the + // current context for resolving super calls relative it. + CallStack.enterSuperBlock(ServletServiceContext.this); + } + ServletServiceContext.this.servlet.service(request, response); + } finally { + CallStack.leaveBlock(); + } + } + + /* (non-Javadoc) + * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse) + */ + public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException { + throw new UnsupportedOperationException(); + } + } +} Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java Sun Jan 14 03:31:10 2007 @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.cocoon.blocks.components; +package org.apache.cocoon.servletservice.components; import java.net.URI; import java.net.URISyntaxException; @@ -25,11 +25,11 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.thread.ThreadSafe; -import org.apache.cocoon.blocks.BlockContext; import org.apache.cocoon.environment.Environment; -import org.apache.cocoon.blocks.BlockCallStack; import org.apache.cocoon.components.modules.input.InputModule; import org.apache.cocoon.environment.internal.EnvironmentHelper; +import org.apache.cocoon.servletservice.CallStack; +import org.apache.cocoon.servletservice.ServletServiceContext; /** * BlockPathModule returns the absolute path of a block protocol path. @@ -41,7 +41,7 @@ public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException { Environment env = EnvironmentHelper.getCurrentEnvironment(); - BlockContext blockContext = (BlockContext) BlockCallStack.getBaseBlockContext(); + ServletServiceContext blockContext = (ServletServiceContext) CallStack.getBaseBlockContext(); String absoluteURI = null; /* No relative block paths yet String baseURI = env.getURIPrefix(); Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java Sun Jan 14 03:31:10 2007 @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.cocoon.blocks.components; +package org.apache.cocoon.servletservice.components; import java.util.Iterator; import java.util.Map; @@ -23,8 +23,8 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.thread.ThreadSafe; -import org.apache.cocoon.blocks.BlockCallStack; import org.apache.cocoon.components.modules.input.InputModule; +import org.apache.cocoon.servletservice.CallStack; /** * BlockPropertyModule provides access to the properties of the current block. @@ -35,7 +35,7 @@ public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException { - return BlockCallStack.getBaseBlockContext().getInitParameter(name); + return CallStack.getBaseBlockContext().getInitParameter(name); } public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel) Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSource.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSource.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSource.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSource.java Sun Jan 14 03:31:10 2007 @@ -14,13 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.components; +package org.apache.cocoon.servletservice.components; import java.io.IOException; import java.io.InputStream; import org.apache.avalon.framework.logger.Logger; -import org.apache.cocoon.blocks.BlockConnection; +import org.apache.cocoon.servletservice.ServletConnection; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.impl.AbstractSource; @@ -33,14 +33,14 @@ */ public class BlockSource extends AbstractSource { - private BlockConnection blockConnection; + private ServletConnection blockConnection; public BlockSource(String location, Logger logger) throws IOException { // the systemId (returned by getURI()) is by default null // using the block uri is a little bit questionable as it only is valid // whithin the current block, not globally setSystemId(location); - this.blockConnection = new BlockConnection(location, logger); + this.blockConnection = new ServletConnection(location, logger); this.blockConnection.connect(); } Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSourceFactory.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSourceFactory.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSourceFactory.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/components/BlockSourceFactory.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.components; +package org.apache.cocoon.servletservice.components; import java.io.IOException; import java.net.MalformedURLException; Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldedGroupClassLoaderManager.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldedGroupClassLoaderManager.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldedGroupClassLoaderManager.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldedGroupClassLoaderManager.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.shielding; +package org.apache.cocoon.servletservice.shielding; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingBlockServlet.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingBlockServlet.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingBlockServlet.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingBlockServlet.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.shielding; +package org.apache.cocoon.servletservice.shielding; import java.util.HashMap; import java.util.Map; @@ -23,14 +23,14 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletException; -import org.apache.cocoon.blocks.BlockServlet; +import org.apache.cocoon.servletservice.ServletService; import org.springframework.aop.framework.ProxyFactory; /** * A servlet for use in cocoon blocks that adds shielded classloading support. */ -public class ShieldingBlockServlet extends BlockServlet { +public class ShieldingBlockServlet extends ServletService { /** * Spring property, name of the group that will get the same classloader. Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingClassLoaderInterceptor.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingClassLoaderInterceptor.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingClassLoaderInterceptor.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/shielding/ShieldingClassLoaderInterceptor.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.shielding; +package org.apache.cocoon.servletservice.shielding; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.util; +package org.apache.cocoon.servletservice.util; import java.io.BufferedReader; import java.io.IOException; Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletResponse.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletResponse.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletResponse.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletResponse.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.util; +package org.apache.cocoon.servletservice.util; import java.io.IOException; import java.io.OutputStream; Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/RequestParameters.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/RequestParameters.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/RequestParameters.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/RequestParameters.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.util; +package org.apache.cocoon.servletservice.util; import java.io.Serializable; import java.util.ArrayList; Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletConfigurationWrapper.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletConfigurationWrapper.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletConfigurationWrapper.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletConfigurationWrapper.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.util; +package org.apache.cocoon.servletservice.util; import java.util.Enumeration; Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletContextWrapper.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletContextWrapper.java?view=diff&rev=496063&r1=496060&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletContextWrapper.java (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/ServletContextWrapper.java Sun Jan 14 03:31:10 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cocoon.blocks.util; +package org.apache.cocoon.servletservice.util; import java.io.InputStream; import java.net.MalformedURLException; Copied: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-path-module.xconf (from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-path-module.xconf) URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-path-module.xconf?view=diff&rev=496063&p1=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-path-module.xconf&r1=496060&p2=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-path-module.xconf&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-path-module.xconf (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-path-module.xconf Sun Jan 14 03:31:10 2007 @@ -19,7 +19,7 @@ - + Copied: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-property-module.xconf (from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-property-module.xconf) URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-property-module.xconf?view=diff&rev=496063&p1=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-property-module.xconf&r1=496060&p2=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-property-module.xconf&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-property-module.xconf (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-block-property-module.xconf Sun Jan 14 03:31:10 2007 @@ -19,7 +19,7 @@ - + Copied: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-servlet-source-factory.xconf (from r496060, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-source-factory.xconf) URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-servlet-source-factory.xconf?view=diff&rev=496063&p1=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-source-factory.xconf&r1=496060&p2=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-servlet-source-factory.xconf&r2=496063 ============================================================================== --- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-blocks-fw-block-source-factory.xconf (original) +++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-servlet-service-servlet-source-factory.xconf Sun Jan 14 03:31:10 2007 @@ -24,7 +24,7 @@ | Each source factory adds a special uri schemes to the system. +--> - +