Author: jbq
Date: Sat Apr 14 16:19:49 2007
New Revision: 528890
URL: http://svn.apache.org/viewvc?view=rev&rev=528890
Log:
WICKET-471 Static pages examples
Added:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java
(with props)
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.html
(with props)
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java
(with props)
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/layout.xsl
(with props)
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/another/
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/another/page.html
(with props)
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/hello.html
(with props)
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/index.html
Added:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java?view=auto&rev=528890
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java
(added)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java
Sat Apr 14 16:19:49 2007
@@ -0,0 +1,70 @@
+/*
+ * 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.wicket.examples.staticpages;
+
+import org.apache.wicket.IRequestTarget;
+import org.apache.wicket.protocol.http.WebApplication;
+import
org.apache.wicket.protocol.http.request.WebExternalResourceRequestTarget;
+import org.apache.wicket.request.RequestParameters;
+import
org.apache.wicket.request.target.basic.URIRequestTargetUrlCodingStrategy;
+import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.PackageResourceStream;
+import org.apache.wicket.util.resource.WebExternalResourceStream;
+import org.apache.wicket.util.resource.XSLTResourceStream;
+
+/**
+ * Examples for serving static files
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jean-Baptiste Quenot</a>
+ */
+public class Application extends WebApplication
+{
+ @Override
+ public Class getHomePage()
+ {
+ return Home.class;
+ }
+
+ @Override
+ protected void init()
+ {
+ // Hello World as a Static Page
+ mount("/docs", new URIRequestTargetUrlCodingStrategy("/docs")
+ {
+ @Override
+ public IRequestTarget decode(RequestParameters
requestParameters)
+ {
+ String path = "/staticpages/" +
getURI(requestParameters);
+ return new
WebExternalResourceRequestTarget(path);
+ }
+ });
+
+ // Hello World as a Static Page with XSLT layout
+ mount("/xsldocs", new
URIRequestTargetUrlCodingStrategy("/xsldocs")
+ {
+ @Override
+ public IRequestTarget decode(RequestParameters
requestParameters)
+ {
+ String path = "/staticpages/" +
getURI(requestParameters);
+ IResourceStream xslStream = new
PackageResourceStream(Application.class, "layout.xsl");
+ IResourceStream docStream = new
WebExternalResourceStream(path);
+ return new ResourceStreamRequestTarget(new
XSLTResourceStream(xslStream, docStream));
+ }
+ });
+ }
+}
Propchange:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.html?view=auto&rev=528890
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.html
(added)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.html
Sat Apr 14 16:19:49 2007
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml" >
+ <head>
+ <title>Wicket Examples - stockquote</title>
+ <link rel="stylesheet" type="text/css" href="style.css"/>
+ </head>
+ <body>
+ <span wicket:id="mainNavigation"/>
+ <h1>Static Pages</h1>
+ <div style="border: 2px dotted #fc0; padding: 5px;
margin-right: 25%;">
+ <p>These examples show how to serve files (or more
generally data
+ streams) by reusing the powerful Wicket concepts like
+ <tt>IResourceStream</tt>, <tt>IRequestTarget</tt> and
+ <tt>IRequestTargetUrlCodingStrategy</tt>.</p>
+
+ <p>Static pages are stateless pages that do
<b>not</b> make use of
+ Wicket Components, in fact those pages can be also
considered
+ dynamic if you take the example of an XSLT
transform.</p>
+
+ <p>Here is an overview of the relevant classes:</p>
+
+ <ul>
+ <li><tt>URIRequestTargetUrlCodingStrategy</tt>:
Request coding strategy
+ that uses a simple URI, and allows for
beautiful URLs. This is
+ configured in the application's init method
using
+ <tt>Application.mount()</tt>.</li>
+
+ <li><tt>XSLTResourceStream</tt>:
IResourceStream that applies XSLT on an
+ IResourceStream</li>
+
+ <li><tt>WebExternalResourceStream</tt>: An
IResourceStream that reads
+ data from a file in the web application</li>
+
+ <li><tt>PackageResourceStream</tt>: An
IResourceStream that reads data
+ from a resource in the classpath</li>
+
+ <li><tt>FileResourceStream</tt>: if you serve
files directly, be careful
+ to check that the requested file is below a
given base directory
+ comparing the <tt>File.getCanonicalPath()</tt>
of the requested file and
+ the base directory, otherwise your application
will give read access to
+ the whole disk, and it can be easily exploited
by malicious users who
+ forge the URL.</li>
+
+ <li>And all this made possible thanks to
+ <tt>ResourceStreamRequestTarget</tt> that is
returned in
+
<tt>IRequestTargetUrlCodingStrategy.decode()</tt></li>
+ </ul>
+ </div>
+ <p><a wicket:id="hellostream">Hello World as a Static
Page</a></p>
+ <p><a wicket:id="helloxslt">Hello World as a Static Page with
XSLT
+ layout</a></p>
+
+ <p>NOTE: it is possible to serve any kind of content using this
method, not
+ only HTML files.</p>
+ </body>
+</html>
Propchange:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.html
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java?view=auto&rev=528890
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java
(added)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java
Sat Apr 14 16:19:49 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.wicket.examples.staticpages;
+
+import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.examples.WicketExamplePage;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.parser.filter.PrependContextPathHandler;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+/**
+ * Examples for serving static files. XXX Notice the use of a
WebMarkupContainer
+ * to produce the static links, since with plain <tt>href</tt> attribute
+ * Wicket's [EMAIL PROTECTED] PrependContextPathHandler} would prepend the
servlet context
+ * path but without Wicket's filter path.
+ *
+ * TODO provide an example using a bookmarkable page
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jean-Baptiste Quenot</a>
+ */
+public class Home extends WicketExamplePage
+{
+ public Home()
+ {
+ // Hello World as a Static Page
+ add(new StaticLink("hellostream", new
Model("docs/hello.html")));
+ // Hello World as a Static Page with XSLT layout
+ add(new StaticLink("helloxslt", new
Model("xsldocs/hello.html")));
+ }
+
+ private class StaticLink extends WebMarkupContainer
+ {
+ public StaticLink(String id, IModel model)
+ {
+ super(id, model);
+ add(new AttributeModifier("href", true, model));
+ }
+ }
+}
Propchange:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/layout.xsl
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/layout.xsl?view=auto&rev=528890
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/layout.xsl
(added)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/layout.xsl
Sat Apr 14 16:19:49 2007
@@ -0,0 +1,14 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
+ <xsl:template match="/html/body">
+ <p><b>Passed through the XSL stylesheet!</b></p>
+ <div style="background-color: #D0D0D0; margin-left: 2em;
padding: 0 .5em">
+ <xsl:apply-templates/>
+ </div>
+ </xsl:template>
+
+ <xsl:template match='node()|@*'>
+ <xsl:copy>
+ <xsl:apply-templates select='node()|@*'/>
+ </xsl:copy>
+ </xsl:template>
+</xsl:stylesheet>
Propchange:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/layout.xsl
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml?view=diff&rev=528890&r1=528889&r2=528890
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml
Sat Apr 14 16:19:49 2007
@@ -326,6 +326,15 @@
</filter>
<filter>
+ <filter-name>StaticPagesApplication</filter-name>
+
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+ <init-param>
+ <param-name>applicationClassName</param-name>
+
<param-value>org.apache.wicket.examples.staticpages.Application</param-value>
+ </init-param>
+ </filter>
+
+ <filter>
<filter-name>RolesAuthApplication</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
@@ -500,6 +509,11 @@
<filter-mapping>
<filter-name>StatelessApplication</filter-name>
<url-pattern>/stateless/*</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>StaticPagesApplication</filter-name>
+ <url-pattern>/staticpages/*</url-pattern>
</filter-mapping>
<filter-mapping>
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/index.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/index.html?view=diff&rev=528890&r1=528889&r2=528890
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/index.html
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/index.html
Sat Apr 14 16:19:49 2007
@@ -45,6 +45,7 @@
<tr><td align="right"><a
href="breadcrumb">breadcrumb</a></td><td> - Don't get lost, use bread
crumbs</td></tr>
<tr><td align="right"><a
href="captcha">captcha</a></td><td> - Gotcha, captcha</td></tr>
<tr><td align="right"><a
href="stateless">stateless</a></td><td> - Demonstrates stateless
pages/sessions</td></tr>
+ <tr><td align="right"><a
href="staticpages">staticpages</a></td><td> - Examples for serving static
files</td></tr>
<tr><td align="right"><a
href="spring">spring</a></td><td> - Demonstrates integration options with the
Spring framework</td></tr>
<tr><td align="right"><a
href="authentication">authentication</a></td><td> - Demonstrates authentication
for pages</td></tr>
<tr><td align="right"><a
href="authorization">authorization</a></td><td> - Demonstrates authorization
for pages and components</td></tr>
@@ -52,4 +53,4 @@
</ul>
</p>
</body>
-</html>
\ No newline at end of file
+</html>
Added:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/another/page.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/another/page.html?view=auto&rev=528890
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/another/page.html
(added)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/another/page.html
Sat Apr 14 16:19:49 2007
@@ -0,0 +1,7 @@
+<html>
+ <body bgcolor="white">
+ <h1>Yet another page</h1>
+ <p>Notice the URL, you are reassured now, yes Wicket can
actually make use of beautiful URLs!</p>
+ <p><a href="../..">Back to the examples</a></p>
+ </body>
+</html>
Propchange:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/another/page.html
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/hello.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/hello.html?view=auto&rev=528890
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/hello.html
(added)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/hello.html
Sat Apr 14 16:19:49 2007
@@ -0,0 +1,6 @@
+<html>
+<body>
+<h1>Hello, World!</h1>
+<p><a href="another/page.html">Link to Another Page</a></p>
+</body>
+</html>
Propchange:
incubator/wicket/branches/wicket-1.x/jdk-1.5/wicket-examples/src/main/webapp/staticpages/hello.html
------------------------------------------------------------------------------
svn:eol-style = native