Author: ddewolf
Date: Mon Nov 20 08:17:30 2006
New Revision: 477233

URL: http://svn.apache.org/viewvc?view=rev&rev=477233
Log:
Adding local entity resolver; Fixing api pom to include jsp-api; Adding JSP out 
aware response warpper

Added:
    
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspWriterResponse.java
   (with props)
    
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/TilesEntityResolver.java
   (with props)
Modified:
    struts/sandbox/trunk/tiles/tiles-api/pom.xml
    
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspTilesRequestContext.java
    
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java

Modified: struts/sandbox/trunk/tiles/tiles-api/pom.xml
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-api/pom.xml?view=diff&rev=477233&r1=477232&r2=477233
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-api/pom.xml (original)
+++ struts/sandbox/trunk/tiles/tiles-api/pom.xml Mon Nov 20 08:17:30 2006
@@ -85,6 +85,13 @@
       </dependency>
 
       <dependency>
+         <groupId>javax.servlet</groupId>
+         <artifactId>jsp-api</artifactId>
+         <version>2.0</version>
+         <scope>provided</scope>
+      </dependency>
+
+      <dependency>
          <groupId>javax.portlet</groupId>
          <artifactId>portlet-api</artifactId>
          <version>1.0</version>

Modified: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspTilesRequestContext.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspTilesRequestContext.java?view=diff&rev=477233&r1=477232&r2=477233
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspTilesRequestContext.java
 (original)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspTilesRequestContext.java
 Mon Nov 20 08:17:30 2006
@@ -44,6 +44,7 @@
 
 
     private PageContext pageContext;
+    private JspWriterResponse response;
 
     public JspTilesRequestContext(ServletContext context, PageContext 
pageContext) {
         super(context,
@@ -63,6 +64,13 @@
             LOG.error("JSPException while including path '"+path+"'. ", e);
             throw new IOException("JSPException while including path 
'"+path+"'. "+e.getMessage());
         }
+    }
+
+    public HttpServletResponse getResponse() {
+        if(response == null) {
+            response = new JspWriterResponse(pageContext);
+        }
+        return response;
     }
 
 }

Added: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspWriterResponse.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspWriterResponse.java?view=auto&rev=477233
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspWriterResponse.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspWriterResponse.java
 Mon Nov 20 08:17:30 2006
@@ -0,0 +1,46 @@
+/*
+ * 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.tiles.context.jsp;
+
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
+import java.io.PrintWriter;
+import java.io.IOException;
+
+
+public class JspWriterResponse extends HttpServletResponseWrapper {
+
+    private PageContext context;
+    private PrintWriter writer;
+
+    public JspWriterResponse(PageContext pageContext) {
+        super((HttpServletResponse)pageContext.getResponse());
+        this.context = pageContext;
+    }
+
+
+    public PrintWriter getWriter() throws IOException {
+        if(writer == null) {
+            writer = new PrintWriter(context.getOut());
+        }
+        return writer;
+    }
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspWriterResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/context/jsp/JspWriterResponse.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Modified: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java?view=diff&rev=477233&r1=477232&r2=477233
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java
 (original)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java
 Mon Nov 20 08:17:30 2006
@@ -152,6 +152,7 @@
             // set first object in stack
             //digester.clear();
             digester.push(this);
+            digester.setEntityResolver(TilesEntityResolver.getInstance());
             // parse
             digester.parse(input);
 

Added: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/TilesEntityResolver.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/TilesEntityResolver.java?view=auto&rev=477233
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/TilesEntityResolver.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/TilesEntityResolver.java
 Mon Nov 20 08:17:30 2006
@@ -0,0 +1,72 @@
+/*
+ * 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.tiles.definition.digester;
+
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * Resource resolved used to provide local/classpath access
+ * to the tiles dtd.  DefinitionsReaders which validate xml
+ * should utilize this resolver to reduce requests to
+ * struts.apache.org.
+ *
+ * @since Tiles 2.0
+ * @version $Rev$
+ *
+ */
+class TilesEntityResolver implements EntityResolver {
+
+    public static final String SYSTEM_ID =
+        "http://struts.apache.org/dtds/tiles-config_2_0.dtd";;
+
+    public static final String PUBLIC_ID =
+        "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN";
+
+    private static TilesEntityResolver instance = new TilesEntityResolver();
+
+    public static TilesEntityResolver getInstance() {
+        return instance;
+    }
+
+    private URL tilesDtd;
+
+    public InputSource resolveEntity(String publicId, String systemId) throws 
SAXException, IOException {
+        if(PUBLIC_ID.equals(publicId) || SYSTEM_ID.equals(systemId)) {
+            InputSource source = new InputSource();
+            source.setSystemId(systemId);
+            source.setPublicId(publicId);
+            source.setByteStream(getTilesDTD().openStream());
+            return source;
+        }
+        return null;
+    }
+
+    public URL getTilesDTD() {
+        if(tilesDtd == null) {
+            tilesDtd = 
getClass().getResource("/org/apache/tiles/resources/tiles-config_2_0.dtd");
+        }
+        return tilesDtd;
+    }
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/TilesEntityResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/digester/TilesEntityResolver.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev


Reply via email to