cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
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 GMT
Author: reinhard
Date: Sun Jan  4 04:57:33 2009
New Revision: 731247

URL: http://svn.apache.org/viewvc?rev=731247&view=rev
Log:
<action dev="reinhard" type="add">
  [cocoon-servlet] Add org.apache.cocoon.servlet.util.ServletServiceUtils to use a Servlet-Service
servlet 
  by reference and get an InputStream of a resource.
</action>

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 @@
 
   <body>
     <release version="3.0.0-alpha-2" date="2008-00-00" description="unreleased">
+      <action dev="reinhard" type="add">
+        [cocoon-servlet] Add org.apache.cocoon.servlet.util.ServletServiceUtils to use a
Servlet-Service servlet 
+        by reference and get an InputStream of a resource.
+      </action>
       <action dev="reinhard" type="update">
         [cocoon-sitemap] Update the WildcardMatcherHelper to the latest version of Cocoon
2.2.
       </action>

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



Mime
View raw message