Author: mgrigorov
Date: Fri Jan 21 19:09:20 2011
New Revision: 1061971

URL: http://svn.apache.org/viewvc?rev=1061971&view=rev
Log:
Add a demo for mounting a resource reference.

Added:
    
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/MapperDemoResourceReference.java
   (with props)
Modified:
    
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java
    
wicket/trunk/wicket-examples/src/main/resources/org/apache/wicket/examples/requestmapper/RequestMapperHomePage.html

Added: 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/MapperDemoResourceReference.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/MapperDemoResourceReference.java?rev=1061971&view=auto
==============================================================================
--- 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/MapperDemoResourceReference.java
 (added)
+++ 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/MapperDemoResourceReference.java
 Fri Jan 21 19:09:20 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.requestmapper;
+
+import java.util.Locale;
+
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.request.resource.AbstractResource;
+import org.apache.wicket.request.resource.IResource;
+import org.apache.wicket.request.resource.ResourceReference;
+import org.apache.wicket.util.string.StringValue;
+
+/**
+ * A resource reference which shows how to serve a custom resource and use 
request parameters
+ */
+public class MapperDemoResourceReference extends ResourceReference
+{
+
+       private static final long serialVersionUID = 1L;
+
+       /**
+        * Constructor.
+        */
+       public MapperDemoResourceReference()
+       {
+               super(new Key(MapperDemoResourceReference.class.getName(), 
"demoResource", Locale.ENGLISH,
+                       null, null));
+       }
+
+       @Override
+       public IResource getResource()
+       {
+               return new AbstractResource()
+               {
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       protected ResourceResponse 
newResourceResponse(Attributes attributes)
+                       {
+                               ResourceResponse resourceResponse = new 
ResourceResponse();
+
+                               PageParameters parameters = 
attributes.getParameters();
+                               StringValue sheetParam = 
parameters.get("sheet");
+                               StringValue formatParam = 
parameters.get("format");
+                               final String responseText = String.format(
+                                       "You just printed sheet '%s' in format 
'%s'.\n\n\nPress browser's back button to go to the examples.",
+                                       sheetParam, formatParam);
+
+                               resourceResponse.setContentType("text/plain");
+                               
resourceResponse.setContentLength(responseText.length());
+                               resourceResponse.setWriteCallback(new 
WriteCallback()
+                               {
+
+                                       @Override
+                                       public void writeData(Attributes 
attributes)
+                                       {
+                                               
attributes.getResponse().write(responseText);
+                                       }
+                               });
+
+                               return resourceResponse;
+                       }
+
+               };
+       }
+
+}

Propchange: 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/MapperDemoResourceReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java?rev=1061971&r1=1061970&r2=1061971&view=diff
==============================================================================
--- 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java
 (original)
+++ 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java
 Fri Jan 21 19:09:20 2011
@@ -57,6 +57,8 @@ public class RequestMapperApplication ex
 
                mountPackage("pMount", PackageMountedPage.class);
 
+               mountResource("/print/${sheet}/${format}", new 
MapperDemoResourceReference());
+
                setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), 
new HttpsConfig()));
        }
 

Modified: 
wicket/trunk/wicket-examples/src/main/resources/org/apache/wicket/examples/requestmapper/RequestMapperHomePage.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-examples/src/main/resources/org/apache/wicket/examples/requestmapper/RequestMapperHomePage.html?rev=1061971&r1=1061970&r2=1061971&view=diff
==============================================================================
--- 
wicket/trunk/wicket-examples/src/main/resources/org/apache/wicket/examples/requestmapper/RequestMapperHomePage.html
 (original)
+++ 
wicket/trunk/wicket-examples/src/main/resources/org/apache/wicket/examples/requestmapper/RequestMapperHomePage.html
 Fri Jan 21 19:09:20 2011
@@ -44,6 +44,8 @@
            
            <p><wicket:link><a href="pMount/PackageMountedPage">A page mounted 
with PackageMapper</a></wicket:link></p>
            
+           <p><wicket:link><a href="print/sheet1/a4">A mounted resource that 
prints sheets in different formats</a></wicket:link></p>
+           
        </body>
 
 </html>
\ No newline at end of file


Reply via email to