You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jb...@apache.org on 2007/09/07 12:04:22 UTC
svn commit: r573525 -
/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/
Author: jbq
Date: Fri Sep 7 03:04:15 2007
New Revision: 573525
URL: http://svn.apache.org/viewvc?rev=573525&view=rev
Log:
WICKET-795 Easy access to final rendered page source
Added:
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTarget.java (with props)
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTargetUrlCodingStrategy.java (with props)
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.html (with props)
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.java (with props)
Modified:
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java
Modified: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java?rev=573525&r1=573524&r2=573525&view=diff
==============================================================================
--- wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java (original)
+++ wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java Fri Sep 7 03:04:15 2007
@@ -17,21 +17,15 @@
package org.apache.wicket.examples.staticpages;
import org.apache.wicket.IRequestTarget;
-import org.apache.wicket.PageParameters;
-import org.apache.wicket.RequestCycle;
import org.apache.wicket.protocol.http.WebApplication;
-import org.apache.wicket.protocol.http.WebResponse;
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.component.BookmarkablePageRequestTarget;
import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
-import org.apache.wicket.response.StringResponse;
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;
-import org.apache.wicket.util.value.ValueMap;
/**
* Examples for serving static files
@@ -73,38 +67,8 @@
return new ResourceStreamRequestTarget(new XSLTResourceStream(xslStream, docStream));
}
});
-
- // Passing URI to a Wicket page
- mount(new URIRequestTargetUrlCodingStrategy("/pages")
- {
- @Override
- public IRequestTarget decode(RequestParameters requestParameters)
- {
- final ValueMap requestParams = decodeParameters(requestParameters);
- PageParameters params = new PageParameters();
- params.put("uri", requestParams.get(URI));
- return new BookmarkablePageRequestTarget(Page.class, params) {
- /**
- * @see org.apache.wicket.request.target.component.BookmarkablePageRequestTarget#respond(org.apache.wicket.RequestCycle)
- */
- @Override
- public void respond(RequestCycle requestCycle)
- {
- if (requestParams.getString("email") != null) {
- final StringResponse emailResponse = new StringResponse();
- final WebResponse originalResponse = (WebResponse)RequestCycle.get().getResponse();
- RequestCycle.get().setResponse(emailResponse);
- super.respond(requestCycle);
- // Here send the email instead of dumping it to stdout!
- System.out.println(emailResponse.toString());
- RequestCycle.get().setResponse(originalResponse);
- RequestCycle.get().setRequestTarget(new BookmarkablePageRequestTarget(Sent.class));
- } else {
- super.respond(requestCycle);
- }
- }
- };
- }
- });
+
+ // All requests to bookmarkable page "Page" will be captured, and the "Sent" page is shown instead
+ mount(new CapturingBookmarkablePageRequestTargetUrlCodingStrategy("/capturedpage", EmailPage.class, Sent.class));
}
}
Added: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTarget.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTarget.java?rev=573525&view=auto
==============================================================================
--- wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTarget.java (added)
+++ wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTarget.java Fri Sep 7 03:04:15 2007
@@ -0,0 +1,77 @@
+/*
+ * 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.PageParameters;
+import org.apache.wicket.RequestCycle;
+import org.apache.wicket.protocol.http.WebResponse;
+import org.apache.wicket.request.target.component.BookmarkablePageRequestTarget;
+import org.apache.wicket.response.StringResponse;
+
+/**
+ * @author <a href="mailto:jbq@apache.org">Jean-Baptiste Quenot</a>
+ */
+public abstract class CapturingBookmarkablePageRequestTarget extends BookmarkablePageRequestTarget
+{
+ Class displayedPageClass;
+
+ /**
+ * @see org.apache.wicket.request.target.component.BookmarkablePageRequestTarget#respond(org.apache.wicket.RequestCycle)
+ */
+ @Override
+ public void respond(RequestCycle requestCycle)
+ {
+ final StringResponse emailResponse = new StringResponse();
+ final WebResponse originalResponse = (WebResponse)RequestCycle.get().getResponse();
+ RequestCycle.get().setResponse(emailResponse);
+ super.respond(requestCycle);
+ onCapture(emailResponse);
+ RequestCycle.get().setResponse(originalResponse);
+ RequestCycle.get().setRequestTarget(new BookmarkablePageRequestTarget(displayedPageClass));
+ }
+
+ protected abstract void onCapture(StringResponse emailResponse);
+
+ /**
+ * Construct.
+ *
+ * @param capturedPageClass
+ * the bookmarkable page to capture for sending in email
+ * @param displayedPageClass
+ * the bookmarkable page to display in the browser
+ */
+ public CapturingBookmarkablePageRequestTarget(Class capturedPageClass, Class displayedPageClass,
+ PageParameters pageParameters)
+ {
+ super(capturedPageClass, pageParameters);
+ this.displayedPageClass = displayedPageClass;
+ }
+
+ /**
+ * Construct.
+ *
+ * @param capturedPageClass
+ * the bookmarkable page to capture for sending in email
+ * @param displayedPageClass
+ * the bookmarkable page to display in the browser
+ */
+ public CapturingBookmarkablePageRequestTarget(Class capturedPageClass, Class displayedPageClass)
+ {
+ super(capturedPageClass);
+ this.displayedPageClass = displayedPageClass;
+ }
+}
Propchange: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTarget.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTarget.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTargetUrlCodingStrategy.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTargetUrlCodingStrategy.java?rev=573525&view=auto
==============================================================================
--- wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTargetUrlCodingStrategy.java (added)
+++ wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTargetUrlCodingStrategy.java Fri Sep 7 03:04:15 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.request.RequestParameters;
+import org.apache.wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy;
+import org.apache.wicket.response.StringResponse;
+
+/**
+ * @author jbq
+ */
+public class CapturingBookmarkablePageRequestTargetUrlCodingStrategy
+ extends
+ BookmarkablePageRequestTargetUrlCodingStrategy
+{
+ Class capturedPageClass;
+ Class displayedPageClass;
+ /**
+ * Construct.
+ *
+ * @param mountPath
+ * @param bookmarkablePageClass
+ * @param pageMapName
+ */
+ public CapturingBookmarkablePageRequestTargetUrlCodingStrategy(String mountPath,
+ Class capturedPageClass, Class displayedPageClass)
+ {
+ super(mountPath, capturedPageClass, null);
+ this.displayedPageClass = displayedPageClass;
+ this.capturedPageClass = capturedPageClass;
+ }
+
+ @Override
+ public IRequestTarget decode(RequestParameters requestParameters)
+ {
+ return new CapturingBookmarkablePageRequestTarget(capturedPageClass, displayedPageClass)
+ {
+ /**
+ * @see org.apache.wicket.examples.staticpages.CapturingBookmarkablePageRequestTarget#onCapture(org.apache.wicket.response.StringResponse)
+ */
+ @Override
+ protected void onCapture(StringResponse emailResponse)
+ {
+ // Here send the email instead of dumping it to stdout!
+ System.out.println(emailResponse.toString());
+ }
+ };
+ }
+
+}
Propchange: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTargetUrlCodingStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/CapturingBookmarkablePageRequestTargetUrlCodingStrategy.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.html?rev=573525&view=auto
==============================================================================
--- wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.html (added)
+++ wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.html Fri Sep 7 03:04:15 2007
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>Wicket Examples - Static Pages</title>
+ </head>
+ <body>
+ <p>This is the captured page sent by email.</p>
+ </body>
+</html>
Propchange: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.java?rev=573525&view=auto
==============================================================================
--- wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.java (added)
+++ wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.java Fri Sep 7 03:04:15 2007
@@ -0,0 +1,30 @@
+/*
+ * 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.PageParameters;
+import org.apache.wicket.examples.WicketExamplePage;
+
+/**
+ * @author jbq
+ */
+public class EmailPage extends WicketExamplePage
+{
+ public EmailPage()
+ {
+ }
+}
Propchange: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/EmailPage.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java?rev=573525&r1=573524&r2=573525&view=diff
==============================================================================
--- wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java (original)
+++ wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Home.java Fri Sep 7 03:04:15 2007
@@ -19,6 +19,7 @@
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
@@ -45,8 +46,16 @@
add(new StaticLink("helloxslt", new Model("xsldocs/hello.html")));
// Passing URI to a Wicket page
add(new StaticLink("wicketpage", new Model("pages/path/to/hello.html")));
- // Sending a Wicket page by email
- add(new StaticLink("emailwicketpage", new Model("pages/path/to/hello.html?email=true")));
+ /*
+ * Sending a Wicket page by email: all requests to bookmarkable page
+ * "Page" will be captured, and the "Sent" page is shown instead, see
+ * the "/capture" mount in staticpages.Application. Unfortunately, you
+ * cannot use CapturingBookmarkablePageRequestTarget in an event
+ * listener like onClick() unless you change the application's
+ * IRequestCycleSettings to ONE_PASS_RENDER, thus we use mount() in the
+ * application
+ */
+ add(new BookmarkablePageLink("emailwicketpage", EmailPage.class));
}
private class StaticLink extends WebMarkupContainer