Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 37370 invoked from network); 4 Jan 2009 12:57:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jan 2009 12:57:56 -0000 Received: (qmail 91250 invoked by uid 500); 4 Jan 2009 12:57:55 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 91197 invoked by uid 500); 4 Jan 2009 12:57:55 -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 91188 invoked by uid 99); 4 Jan 2009 12:57:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Jan 2009 04:57:55 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Jan 2009 12:57:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 718F623889A0; Sun, 4 Jan 2009 04:57:34 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r731247 - in /cocoon/cocoon3/trunk: cocoon-docs/src/changes/changes.xml cocoon-servlet/src/main/java/org/apache/cocoon/servlet/util/ServletServiceUtils.java Date: Sun, 04 Jan 2009 12:57:34 -0000 To: cvs@cocoon.apache.org From: reinhard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090104125734.718F623889A0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: reinhard Date: Sun Jan 4 04:57:33 2009 New Revision: 731247 URL: http://svn.apache.org/viewvc?rev=731247&view=rev Log: [cocoon-servlet] Add org.apache.cocoon.servlet.util.ServletServiceUtils to use a Servlet-Service servlet by reference and get an InputStream of a resource. Added: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/util/ServletServiceUtils.java (with props) Modified: cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml Modified: cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml?rev=731247&r1=731246&r2=731247&view=diff ============================================================================== --- cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml (original) +++ cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml Sun Jan 4 04:57:33 2009 @@ -27,6 +27,10 @@ + + [cocoon-servlet] Add org.apache.cocoon.servlet.util.ServletServiceUtils to use a Servlet-Service servlet + by reference and get an InputStream of a resource. + [cocoon-sitemap] Update the WildcardMatcherHelper to the latest version of Cocoon 2.2. Added: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/util/ServletServiceUtils.java URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/util/ServletServiceUtils.java?rev=731247&view=auto ============================================================================== --- cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/util/ServletServiceUtils.java (added) +++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/util/ServletServiceUtils.java Sun Jan 4 04:57:33 2009 @@ -0,0 +1,91 @@ +/* + * 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.servlet.util; + +import java.io.IOException; +import java.io.InputStream; + +import javax.servlet.Servlet; +import javax.servlet.ServletException; + +import org.apache.cocoon.servletservice.AbsoluteServletConnection; +import org.apache.cocoon.servletservice.Absolutizable; + +public class ServletServiceUtils { + + /** + * Get an {@link InputStream} of a Servlet that is a servlet-service as defined by the Cocoon Servlet-Service + * framework. + * + * @param servlet The Servlet-Service reference. + * @param resourcePath The absolute resource path. + * @return An InputStream of the resource. + * @throws ServletServiceException If any problem occurs, this unchecked exception is thrown. + */ + public static InputStream getServletServiceResource(Servlet servlet, String resourcePath) { + return getServletServiceResource(servlet, resourcePath, null); + } + + /** + * Get an {@link InputStream} of a Servlet that is a servlet-service as defined by the Cocoon Servlet-Service + * framework. + * + * @param servlet The Servlet-Service reference. + * @param resourcePath The absolute resource path. + * @param query The query string. + * @return An InputStream of the resource. + * @throws ServletServiceException If any problem occurs, this unchecked exception is thrown. + */ + public static InputStream getServletServiceResource(Servlet servlet, String resourcePath, String query) { + if (resourcePath.length() > 0 && !resourcePath.startsWith("/")) { + resourcePath = "/" + resourcePath; + } + + Absolutizable a; + try { + a = (Absolutizable) servlet.getServletConfig().getServletContext(); + } catch (ClassCastException cce) { + throw new ServletServiceException("The passed servlet isn't a servlet service because it can't be cast to " + + Absolutizable.class.getName() + ".", cce); + } + + AbsoluteServletConnection sc = new AbsoluteServletConnection(a.getServiceName(), resourcePath, null); + try { + return sc.getInputStream(); + } catch (IOException e) { + throw new ServletServiceException(e); + } catch (ServletException e) { + throw new ServletServiceException(e); + } + } + + /** + * A general purpose {@link RuntimeException} that is used to indicate any problem with accessing a servlet-service. + */ + public static class ServletServiceException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public ServletServiceException(String message, Throwable t) { + super(message, t); + } + + public ServletServiceException(Throwable t) { + super(t); + } + } +} Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/util/ServletServiceUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/util/ServletServiceUtils.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/util/ServletServiceUtils.java ------------------------------------------------------------------------------ svn:mime-type = text/plain