Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 54694 invoked from network); 14 Apr 2008 14:28:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Apr 2008 14:28:45 -0000 Received: (qmail 95232 invoked by uid 500); 14 Apr 2008 14:28:46 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 95176 invoked by uid 500); 14 Apr 2008 14:28:46 -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 95165 invoked by uid 99); 14 Apr 2008 14:28:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Apr 2008 07:28:45 -0700 X-ASF-Spam-Status: No, hits=-1999.3 required=10.0 tests=ALL_TRUSTED,FRT_LEVITRA 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; Mon, 14 Apr 2008 14:28:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EB51F1A9832; Mon, 14 Apr 2008 07:28:17 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r647814 - in /cocoon/whiteboard/corona/trunk/corona-servlet: ./ src/main/java/org/apache/cocoon/corona/servlet/ src/main/java/org/apache/cocoon/corona/servlet/component/ src/main/java/org/apache/cocoon/corona/servlet/node/ src/main/resource... Date: Mon, 14 Apr 2008 14:28:10 -0000 To: cvs@cocoon.apache.org From: reinhard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080414142817.EB51F1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: reinhard Date: Mon Apr 14 07:28:00 2008 New Revision: 647814 URL: http://svn.apache.org/viewvc?rev=647814&view=rev Log: COCOON-2195 . support controllers in sitemaps . add mime-type handling (using AOP) . support for the servlet protocol . experimental sitemap delegator stuff . adding more samples Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLConnection.java (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandler.java (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandlerFactory.java (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapDelegator.java (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/Controller.java (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/DefaultControllerComponent.java (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/MimeTypeCollector.java (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/sax-pipeline/simple.xslt (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/main.xslt (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-file.xslt (with props) cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-servlet.xslt (with props) Modified: cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RequestParametersGenerator.java cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java Modified: cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml?rev=647814&r1=647813&r2=647814&view=diff ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml (original) +++ cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml Mon Apr 14 07:28:00 2008 @@ -42,6 +42,13 @@ corona-sitemap + + org.apache.cocoon cocoon-servlet-service-impl Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLConnection.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLConnection.java?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLConnection.java (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLConnection.java Mon Apr 14 07:28:00 2008 @@ -0,0 +1,90 @@ +/* + * 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.corona.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; + +import javax.servlet.ServletException; + +import org.apache.cocoon.servletservice.AbsoluteServletConnection; +import org.apache.cocoon.servletservice.Absolutizable; +import org.apache.cocoon.servletservice.CallStackHelper; + +public class ServletURLConnection extends URLConnection { + + private AbsoluteServletConnection connection; + + public ServletURLConnection(URL url) { + super(url); + } + + @Override + public void connect() throws IOException { + if (this.connected) { + return; + } + + // get the referenced servlet and find out if it is an absolute or relative connection + URI locationUri; + try { + locationUri = new URI(this.url.getPath()); + } catch (URISyntaxException e) { + throw new IOException(e.toString()); + } + + final String servletReference = locationUri.getScheme(); + final Absolutizable absolutizable = (Absolutizable) CallStackHelper.getCurrentServletContext(); + final String servletName; + + // find out the type of the reference and create a service name + if (servletReference == null) { + // self-reference + servletName = absolutizable.getServiceName(); + } else if (servletReference.endsWith(AbsoluteServletConnection.ABSOLUTE_SERVLET_SOURCE_POSTFIX)) { + // absolute reference + servletName = servletReference.substring(0, servletReference.length() - 1); + } else { + // relative reference + servletName = absolutizable.getServiceName(servletReference); + } + + this.connection = new AbsoluteServletConnection(servletName, locationUri.getRawPath(), locationUri.getRawQuery()); + try { + this.connection.connect(); + } catch (ServletException e) { + throw new IOException(e.toString()); + } + + this.connected = true; + } + + @Override + public InputStream getInputStream() throws IOException { + this.connect(); + + try { + return this.connection.getInputStream(); + } catch (ServletException e) { + throw new IOException(e.toString()); + } + } +} Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLConnection.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLConnection.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLConnection.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandler.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandler.java?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandler.java (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandler.java Mon Apr 14 07:28:00 2008 @@ -0,0 +1,35 @@ +/* + * 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.corona.servlet; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; + +public class ServletURLStreamHandler extends URLStreamHandler { + + /** + * {@inheritDoc} + * + * @see java.net.URLStreamHandler#openConnection(java.net.URL) + */ + @Override + protected URLConnection openConnection(URL url) throws IOException { + return new ServletURLConnection(url); + } +} Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandler.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandler.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandlerFactory.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandlerFactory.java?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandlerFactory.java (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandlerFactory.java Mon Apr 14 07:28:00 2008 @@ -0,0 +1,37 @@ +/* + * 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.corona.servlet; + +import java.net.URLStreamHandler; +import java.net.URLStreamHandlerFactory; + +final class ServletURLStreamHandlerFactory implements URLStreamHandlerFactory { + + /** + * {@inheritDoc} + * + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(java.lang.String) + */ + public URLStreamHandler createURLStreamHandler(String protocol) { + if ("servlet".equalsIgnoreCase(protocol)) { + System.out.println("ServletURLStreamHandlerFactory creating ServletURLStreamHandler"); + return new ServletURLStreamHandler(); + } + + return null; + } +} Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandlerFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandlerFactory.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ServletURLStreamHandlerFactory.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapDelegator.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapDelegator.java?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapDelegator.java (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapDelegator.java Mon Apr 14 07:28:00 2008 @@ -0,0 +1,43 @@ +/* + * 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.corona.servlet; + +import java.io.OutputStream; +import java.util.Map; + +public class SitemapDelegator { + + private static final ThreadLocal SITEMAP_SERVLET = new ThreadLocal(); + + public static void delegate(String requestURI, Map parameters, OutputStream outputStream) throws Exception { + SitemapServlet sitemapServlet = SITEMAP_SERVLET.get(); + + if (sitemapServlet == null) { + throw new IllegalStateException("No current SitemapServlet."); + } + + sitemapServlet.invoke(requestURI, parameters, outputStream); + } + + public static final void removeSitemapServlet() { + SITEMAP_SERVLET.set(null); + } + + public static final void setSitemapServlet(SitemapServlet sitemapServlet) { + SITEMAP_SERVLET.set(sitemapServlet); + } +} Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapDelegator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapDelegator.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapDelegator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java?rev=647814&r1=647813&r2=647814&view=diff ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java (original) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java Mon Apr 14 07:28:00 2008 @@ -19,6 +19,7 @@ package org.apache.cocoon.corona.servlet; import java.io.IOException; +import java.io.OutputStream; import java.io.PrintWriter; import java.net.URL; import java.util.Enumeration; @@ -31,12 +32,15 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.cocoon.corona.servlet.node.MimeTypeCollector; import org.apache.cocoon.corona.servlet.node.StatusCodeCollector; import org.apache.cocoon.corona.servlet.util.HttpContextHelper; import org.apache.cocoon.corona.sitemap.Invocation; import org.apache.cocoon.corona.sitemap.InvocationImpl; import org.apache.cocoon.corona.sitemap.SitemapBuilder; import org.apache.cocoon.corona.sitemap.node.Sitemap; +import org.apache.excalibur.sourceresolve.jnet.DynamicURLStreamHandlerFactory; +import org.apache.excalibur.sourceresolve.jnet.URLStreamHandlerFactoryInstaller; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -45,11 +49,8 @@ private static final long serialVersionUID = 1L; - private Sitemap sitemap; - private BeanFactory beanFactory; - - private StatusCodeCollector statusCodeCollector; + private Sitemap sitemap; @Override public void init(ServletConfig servletConfig) throws ServletException { @@ -59,33 +60,51 @@ SitemapBuilder sitemapBuilder = (SitemapBuilder) this.beanFactory.getBean(SitemapBuilder.class.getName()); URL url = servletConfig.getServletContext().getResource("/sitemap.xmap"); this.sitemap = sitemapBuilder.build(url); - this.statusCodeCollector = (StatusCodeCollector) beanFactory.getBean(StatusCodeCollector.class.getName()); + + URLStreamHandlerFactoryInstaller.setURLStreamHandlerFactory(new DynamicURLStreamHandlerFactory()); } catch (Exception e) { throw new ServletException(e); } } + public void invoke(String requestURI, Map parameters, OutputStream outputStream) { + InvocationImpl invocation = (InvocationImpl) this.beanFactory.getBean(Invocation.class.getName()); + + System.out.println("Starting invocation for RequestURI " + requestURI); + invocation.setRequestURI(requestURI); + invocation.setParameters(parameters); + invocation.setOutputStream(outputStream); + + this.sitemap.invoke(invocation); + } + + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } + @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { - InvocationImpl invocation = (InvocationImpl) this.beanFactory.getBean(Invocation.class.getName()); - // parameters - invocation.setParameters(this.getInvocationParameters(request)); - HttpContextHelper.storeRequest(request, invocation.getParameters()); - HttpContextHelper.storeResponse(response, invocation.getParameters()); - - // request - invocation.setRequestURI(request.getRequestURI()); - // output stream - invocation.setOutputStream(response.getOutputStream()); - - this.sitemap.invoke(invocation); + DynamicURLStreamHandlerFactory.push(new ServletURLStreamHandlerFactory()); + SitemapDelegator.setSitemapServlet(this); - response.setStatus(this.statusCodeCollector.getStatusCode()); + // assemble parameters + Map parameters = this.getInvocationParameters(request); + HttpContextHelper.storeRequest(request, parameters); + HttpContextHelper.storeResponse(response, parameters); + + this.invoke(request.getRequestURI(), parameters, response.getOutputStream()); + + response.setStatus(StatusCodeCollector.getStatusCode()); + response.setContentType(MimeTypeCollector.getMimeType()); + response.setContentType("text/html;charset=UTF-8"); } catch (Exception e) { PrintWriter writer = new PrintWriter(response.getOutputStream()); e.printStackTrace(writer); writer.close(); + } finally { + SitemapDelegator.removeSitemapServlet(); + DynamicURLStreamHandlerFactory.pop(); } } @@ -99,9 +118,5 @@ } return invocationParameters; - } - - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.beanFactory = beanFactory; } } Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/Controller.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/Controller.java?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/Controller.java (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/Controller.java Mon Apr 14 07:28:00 2008 @@ -0,0 +1,25 @@ +/* + * 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.corona.servlet.component; + +import java.io.OutputStream; +import java.util.Map; + +public interface Controller { + + void invoke(String function, Map parameters, OutputStream outputStream); +} Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/Controller.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/Controller.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/Controller.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/DefaultControllerComponent.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/DefaultControllerComponent.java?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/DefaultControllerComponent.java (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/DefaultControllerComponent.java Mon Apr 14 07:28:00 2008 @@ -0,0 +1,63 @@ +/* + * 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.corona.servlet.component; + +import java.io.OutputStream; +import java.util.Map; + +import org.apache.cocoon.corona.pipeline.component.Finisher; +import org.apache.cocoon.corona.pipeline.component.Starter; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +public class DefaultControllerComponent implements Starter, Finisher, ApplicationContextAware { + + private ApplicationContext applicationContext; + private Map configuration; + private String controllerName; + private String functionName; + private OutputStream outputStream; + private Map parameters; + + public void execute() { + Controller controller = (Controller) this.applicationContext.getBean(this.controllerName, Controller.class); + controller.invoke(this.functionName, this.parameters, this.outputStream); + } + + public String getContentType() { + return null; + } + + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + public void setConfiguration(Map configuration) { + this.functionName = (String) configuration.get("function"); + this.controllerName = (String) configuration.get("controller"); + this.configuration = configuration; + } + + public void setInputParameters(Map parameters) { + this.parameters = parameters; + } + + public void setOutputStream(OutputStream outputStream) { + this.outputStream = outputStream; + } +} Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/DefaultControllerComponent.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/DefaultControllerComponent.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/DefaultControllerComponent.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java?rev=647814&r1=647813&r2=647814&view=diff ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java (original) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java Mon Apr 14 07:28:00 2008 @@ -30,15 +30,16 @@ public class RedirectorComponent implements Starter, Finisher { + private Map parameters; private String uri; /** * {@inheritDoc} - * - * @see org.apache.cocoon.corona.pipeline.component.Starter#execute(Map) + * + * @see org.apache.cocoon.corona.pipeline.component.Starter#execute() */ - public void execute(Map parameters) { - HttpServletResponse response = HttpContextHelper.getResponse(parameters); + public void execute() { + HttpServletResponse response = HttpContextHelper.getResponse(this.parameters); try { String location = response.encodeRedirectURL(this.uri); @@ -48,26 +49,34 @@ } } + public String getContentType() { + return null; + } + /** * {@inheritDoc} - * - * @see org.apache.cocoon.corona.pipeline.component.Finisher#setOutputStream(java.io.OutputStream) + * + * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map) */ - public void setOutputStream(OutputStream outputStream) { + public void setConfiguration(Map configuration) { + this.uri = (String) configuration.get("uri"); + } + + public void setInputParameters(Map parameters) { + this.parameters = parameters; } /** * {@inheritDoc} - * - * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setParameters(java.util.Map) + * + * @see org.apache.cocoon.corona.pipeline.component.Finisher#setOutputStream(java.io.OutputStream) */ - public void setParameters(Map parameters) { - this.uri = (String) parameters.get("uri"); + public void setOutputStream(OutputStream outputStream) { } /** * {@inheritDoc} - * + * * @see java.lang.Object#toString() */ @Override Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RequestParametersGenerator.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RequestParametersGenerator.java?rev=647814&r1=647813&r2=647814&view=diff ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RequestParametersGenerator.java (original) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RequestParametersGenerator.java Mon Apr 14 07:28:00 2008 @@ -32,14 +32,16 @@ public class RequestParametersGenerator extends AbstractXMLProducer implements Starter { + private Map parameters; + /** * {@inheritDoc} - * - * @see org.apache.cocoon.corona.pipeline.component.Starter#execute(Map) + * + * @see org.apache.cocoon.corona.pipeline.component.Starter#execute() */ @SuppressWarnings("unchecked") - public void execute(Map parameters) { - HttpServletRequest request = HttpContextHelper.getRequest(parameters); + public void execute() { + HttpServletRequest request = HttpContextHelper.getRequest(this.parameters); Enumeration parameterNames = request.getParameterNames(); try { @@ -59,5 +61,10 @@ } catch (SAXException e) { throw new InvocationException(e); } + } + + @Override + public void setInputParameters(Map parameters) { + this.parameters = parameters; } } Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/MimeTypeCollector.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/MimeTypeCollector.java?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/MimeTypeCollector.java (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/MimeTypeCollector.java Mon Apr 14 07:28:00 2008 @@ -0,0 +1,49 @@ +/* + * 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.corona.servlet.node; + +import org.apache.cocoon.corona.pipeline.Pipeline; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; + +@Aspect +public class MimeTypeCollector { + + private static final ThreadLocal THREAD_LOCAL = new ThreadLocal(); + + @Around("execution(* org.apache.cocoon.corona.pipeline.Pipeline.execute(..))") + public Object interceptInvoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { + System.out.println("Executing MimeTypeCollector"); + Object result = proceedingJoinPoint.proceed(); + + Pipeline pipeline = (Pipeline) proceedingJoinPoint.getTarget(); + THREAD_LOCAL.set(pipeline.getContentType()); + + return result; + } + + public static String getMimeType() { + String mimeType = THREAD_LOCAL.get(); + + return mimeType; + } + + public static void setMimeType(String mimeType) { + THREAD_LOCAL.set(mimeType); + } +} Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/MimeTypeCollector.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/MimeTypeCollector.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/MimeTypeCollector.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java?rev=647814&r1=647813&r2=647814&view=diff ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java (original) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java Mon Apr 14 07:28:00 2008 @@ -45,7 +45,7 @@ return invocationResult; } - public int getStatusCode() { + public static int getStatusCode() { Integer integer = threadLocal.get(); if (integer == null) { @@ -53,5 +53,9 @@ } return integer.intValue(); + } + + public static void setStatusCode(int statusCode) { + threadLocal.set(statusCode); } } Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml?rev=647814&r1=647813&r2=647814&view=diff ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml (original) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml Mon Apr 14 07:28:00 2008 @@ -26,4 +26,6 @@ + + Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml?rev=647814&r1=647813&r2=647814&view=diff ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml (original) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml Mon Apr 14 07:28:00 2008 @@ -28,4 +28,6 @@ + + Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/sax-pipeline/simple.xslt URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/sax-pipeline/simple.xslt?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/sax-pipeline/simple.xslt (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/sax-pipeline/simple.xslt Mon Apr 14 07:28:00 2008 @@ -0,0 +1,35 @@ + + + + + + + + + + Simple Pipeline + + + +

Simple Pipeline

+

+ + +
+ +
Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/sax-pipeline/simple.xslt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/sax-pipeline/simple.xslt ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/sax-pipeline/simple.xslt ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/main.xslt URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/main.xslt?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/main.xslt (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/main.xslt Mon Apr 14 07:28:00 2008 @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/main.xslt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/main.xslt ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/main.xslt ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-file.xslt URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-file.xslt?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-file.xslt (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-file.xslt Mon Apr 14 07:28:00 2008 @@ -0,0 +1,24 @@ + + + + + + file + + + Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-file.xslt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-file.xslt ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-file.xslt ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-servlet.xslt URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-servlet.xslt?rev=647814&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-servlet.xslt (added) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-servlet.xslt Mon Apr 14 07:28:00 2008 @@ -0,0 +1,24 @@ + + + + + + servlet + + + Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-servlet.xslt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-servlet.xslt ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/xslt/sub-servlet.xslt ------------------------------------------------------------------------------ svn:mime-type = text/xml Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java?rev=647814&r1=647813&r2=647814&view=diff ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java (original) +++ cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java Mon Apr 14 07:28:00 2008 @@ -39,7 +39,6 @@ private Sitemap sitemap; private SitemapBuilder sitemapBuilder; private ComponentProvider componentProvider; - private StatusCodeCollector statusCodeCollector; public void testErrorHandlingGlobal() { // TODO: currently this cannot work since some components for error @@ -69,7 +68,7 @@ assertTrue("Expected CustomException but received " + invocation.getThrowable(), invocation.getThrowable() instanceof CustomException); - assertEquals(501, this.statusCodeCollector.getStatusCode()); + assertEquals(501, StatusCodeCollector.getStatusCode()); } public void testGenerator() { @@ -83,7 +82,7 @@ // invocation should not be marked as error-invocation assertFalse(invocation.isErrorInvocation()); - assertEquals(401, this.statusCodeCollector.getStatusCode()); + assertEquals(401, StatusCodeCollector.getStatusCode()); } public void testNoMatchingPipeline() { @@ -96,6 +95,20 @@ invocation.getThrowable() instanceof NoMatchingPipelineException); } + public void testController() { + Invocation invocation = this.buildInvocation("controller/invoke"); + InvocationResult invocationResult = this.sitemap.invoke(invocation); + + assertNotNull(invocationResult); + } + + public void testXSLT() { + Invocation invocation = this.buildInvocation("xslt/main"); + InvocationResult invocationResult = this.sitemap.invoke(invocation); + + assertNotNull(invocationResult); + } + public void testObjectModelPipeline() { Invocation invocation = this.buildInvocation("object-model/request-parameters"); Map requestParameters = new HashMap(); @@ -176,8 +189,6 @@ "META-INF/cocoon/spring/corona-pipeline-component.xml", "META-INF/cocoon/spring/corona-pipeline.xml", "META-INF/cocoon/spring/corona-sitemap-node.xml", "META-INF/cocoon/spring/corona-expression-language.xml", "META-INF/cocoon/spring/corona-servlet-node.xml", "META-INF/cocoon/spring/corona-servlet-component.xml"}); - - this.statusCodeCollector = (StatusCodeCollector) applicationContext.getBean(StatusCodeCollector.class.getName()); this.componentProvider = (ComponentProvider) applicationContext.getBean("org.apache.cocoon.corona.sitemap.ComponentProvider");