More robustness when wrong URLs are used.
*/
package org.wamblee.photos.wicket;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.wicket.RedirectToUrlException;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
public class BasePage extends WebApplicationBasePage {
+ @Inject
+ private HttpServletRequest request;
+
private boolean isExpired = false;
public BasePage() {
public BasePage(IModel aModel) {
super(aModel);
+
+ if (request.getUserPrincipal() == null) {
+ redirectToLoginPage();
+ }
+
add(new ResetCssBehavior());
add(new TitleAttributeTooltipBehavior());
- add(CSSPackageResource.getHeaderContribution(BasePage.class,
- "photos.css"));
+ add(CSSPackageResource.getHeaderContribution(BasePage.class, "photos.css"));
disableCaching();
add(new FeedbackPanel("feedback"));
@Override
public void onClick() {
getRequestCycle().getSession().invalidate();
+ throw redirectToLoginPage();
}
});
}
+ private RedirectToUrlException redirectToLoginPage() {
+ return new RedirectToUrlException("login.jsp");
+ }
+
public void setExpired(boolean aExpired) {
isExpired = aExpired;
}
<span wicket:id="message">Message here.</span>
- <div id="album">
- <table border=1>
+ <div id="photos">
+ <table>
<tr wicket:id="row">
- <td wicket:id="column">
+ <td wicket:id="column" id="photoentry">
<a href="#" wicket:id="thumbnail">
<table>
<tr>
- <td><img wicket:id="image" border="0"/></td>
+ <td><img wicket:id="image"/></td>
</tr>
<tr>
<td><span wicket:id="name">photo name</span></td>
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
+import java.util.logging.Logger;
import javax.inject.Inject;
import org.apache.wicket.PageParameters;
*/
public class HomePage extends BasePage {
+ private static final Logger LOGGER = Logger.getLogger(HomePage.class.getName());
+
private static final long serialVersionUID = 1L;
@Inject
@Override
public void onClick() {
System.out.println("Entry " + path + " was clicked");
+ PageParameters pars = new PageParameters();
+ pars.put("path", path);
+ setResponsePage(HomePage.class, pars);
}
}
+ private String path;
+
/**
* Constructor that is invoked when page is invoked without a session.
*
*/
public HomePage(final PageParameters parameters) throws Exception {
super();
+
+ path = parameters.getString("path", "/");
+ if (!path.startsWith("/")) {
+ info("Invalid album '" + path + "', showing root album instead");
+ path = "/";
+ }
+
add(new Label("message", "Hello world!"));
System.out.println("Currently logged in user: " + user);
System.out.println("Entry " + i + " " + entry.getId() + " " + entry.getPath());
}
+ PhotoEntry current = authorized.getEntry(path);
+
+ if (current instanceof Photo) {
+ throw new RuntimeException("Photo entry viewing not yet implemented");
+ }
+
+ Album album = (Album) current;
+
int ientry = 0;
int irow = 0;
RepeatingView row = new RepeatingView("row");
add(row);
- while (irow < 5 && ientry < authorized.size()) {
+ while (irow < 5 && ientry < album.size()) {
int icolumn = 0;
WebMarkupContainer columns = new WebMarkupContainer(row.newChildId());
row.add(columns);
RepeatingView column = new RepeatingView("column");
columns.add(column);
- while (icolumn < 5 && ientry < authorized.size()) {
+ while (icolumn < 5 && ientry < album.size()) {
WebMarkupContainer thumbnail = new WebMarkupContainer(column.newChildId());
column.add(thumbnail);
- final PhotoEntry entry = authorized.getEntry(ientry);
+ final PhotoEntry entry = album.getEntry(ientry);
Link link = new SerializableEntryLink("thumbnail", entry.getPath());
thumbnail.add(link);
ImageData data = getData(entry);
// TODO very inefficient. all data is loaded when generating the page.
link.add(new Image("image", new ByteArrayResource(data.getContentType(), data.getData())));
- link.add(new Label("name", authorized.getEntry(ientry).getId()));
+ link.add(new Label("name", album.getEntry(ientry).getId()));
icolumn++;
ientry++;
}
*/
package org.wamblee.photos.wicket;
-import javax.servlet.http.HttpServletRequest;
-
import org.apache.wicket.Request;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.Response;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequest;
-import org.apache.wicket.request.target.basic.RedirectRequestTarget;
+import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy;
import org.apache.wicket.settings.IApplicationSettings;
+import org.apache.wicket.settings.IExceptionSettings;
import org.wamblee.wicket.inject.ComponentInstantiationInjector;
import org.wamblee.wicket.transactions.OpenTransactionInViewRequestCycle;
/**
* Application object for your web application. If you want to run this
* application without deploying, run the Start class.
- *
+ *
* @see org.wamblee.Start#main(String[])
*/
public class WicketApplication extends WebApplication {
@Override
public RequestCycle newRequestCycle(Request aRequest, Response aResponse) {
- return new OpenTransactionInViewRequestCycle(this,
- (WebRequest) aRequest, aResponse);
+ return new OpenTransactionInViewRequestCycle(this, (WebRequest) aRequest, aResponse);
}
@Override
IApplicationSettings settings = getApplicationSettings();
settings.setInternalErrorPage(ErrorPage.class);
+ mount(new MixedParamUrlCodingStrategy("view", HomePage.class, new String[]{"path"}));
+
// Use the lines below to get the internal error page also when in
// development mode.
// IExceptionSettings exs = getExceptionSettings();
public Class<HomePage> getHomePage() {
return HomePage.class;
}
-
}
/* general */
body {
- font-family: Arial, Helvetica, sans-serif;
- list-style-type: square;
- font-size: 20px;
+ font-family: sans-serif;
}
/* menu styling */
font-size: 24px;
}
-#content table {
- text-align: left;
-}
-
-#content th, #content td {
+#photos th, #content td {
vertical-align: top;
padding: 10px;
}
-.entries a {
- display: block;
- float: left;
- font-size: 24px;
- margin-left: 10%;
- margin-right: 24px;
- line-height: 34px;
- width: 100%;
+#photos table {
+ font-size: small;
+ text-align: left;
+ border-collapse: collapse;
+ border-spacing: 0px;
}
-.entries .index {
- display: block;
- float: left;
- font-size: 30px;
- width: 100%;
- margin-top: 10px;
+#photoentry {
+ padding: 0.2em;
+ border: 1px;
+ border: 1px;
+ border-style: solid;
+ border-bottom-color: gray;
}
+#photos img {
+ display: block;
+}
-
+}
\ No newline at end of file
--- /dev/null
+<%@ page language="java" pageEncoding="UTF-8" session="true"%>
+
+
+
+<%
+ String path = request.getContextPath();
+ String basePath = request.getScheme() + "://" +
+ request.getServerName() + ":" + request.getServerPort() + path +
+ "/";
+%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+
+<head>
+<title wicket:id="title">Oops</title>
+
+<%
+ String cssUrl = request.getContextPath() + "/resources/org.wamblee.photos.wicket.BasePage/photos.css";
+%>
+
+<link rel="stylesheet" type="text/css" href="<%= cssUrl %>" />
+</head>
+
+<body>
+
+ <div id="banner">
+ <%
+ String logoUrl = request.getContextPath() + "/resources/org.wamblee.photos.wicket.BasePage/wamblee_logo.png";
+ %>
+ <img src="<%= logoUrl %>" />
+ <span class="title">wamblee photos</span>
+ </div>
+
+
+ <br/>
+ Oops, the requested URL could not be found.
+ <%
+ String loginUrl = request.getContextPath() + "/login.jsp";
+ %>
+ Please <a href="<%= loginUrl %>">login again</a>
+
+ <%
+ session.invalidate();
+ %>
+</body>
+</html>
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- version="3.0">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
- <display-name>cdi</display-name>
+ <display-name>cdi</display-name>
- <!--
- There are three means to configure Wickets configuration mode and they are
- tested in the order given.
- 1) A system property: -Dwicket.configuration
- 2) servlet specific <init-param>
- 3) context specific <context-param>
- The value might be either "development" (reloading when templates change)
- or "deployment". If no configuration is found, "development" is the default.
- -->
-
- <filter>
- <filter-name>authentication</filter-name>
- <filter-class>org.wamblee.photos.security.AuthenticationFilter</filter-class>
- <init-param>
- <param-name>loginpage</param-name>
- <param-value>/login.jsp</param-value>
- </init-param>
- <!-- each authenticated user is assigned to the gruop ALL in the security realm configuration -->
- <init-param>
- <param-name>role</param-name>
- <param-value>ALL</param-value>
- </init-param>
- <!-- defines the resource URLs for which no authentication is required -->
- <init-param>
- <param-name>resources</param-name>
- <param-value>/resources</param-value>
- </init-param>
- </filter>
+ <!--
+ There are three means to configure Wickets configuration mode and they are
+ tested in the order given.
+ 1) A system property: -Dwicket.configuration
+ 2) servlet specific <init-param>
+ 3) context specific <context-param>
+ The value might be either "development" (reloading when templates change)
+ or "deployment". If no configuration is found, "development" is the default.
+ -->
- <filter>
- <filter-name>photos</filter-name>
- <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
- <init-param>
- <param-name>applicationClassName</param-name>
- <param-value>org.wamblee.photos.wicket.WicketApplication</param-value>
- </init-param>
- <init-param>
- <param-name>configuration</param-name>
- <param-value>development</param-value>
- </init-param>
- </filter>
+ <filter>
+ <filter-name>authentication</filter-name>
+ <filter-class>org.wamblee.photos.security.AuthenticationFilter</filter-class>
+ <init-param>
+ <param-name>loginpage</param-name>
+ <param-value>/login.jsp</param-value>
+ </init-param>
+ <!-- each authenticated user is assigned to the gruop ALL in the security realm configuration -->
+ <init-param>
+ <param-name>role</param-name>
+ <param-value>ALL</param-value>
+ </init-param>
+ <!-- defines the resource URLs for which no authentication is required -->
+ <init-param>
+ <param-name>resources</param-name>
+ <param-value>/resources</param-value>
+ </init-param>
+ </filter>
+ <filter>
+ <filter-name>photos</filter-name>
+ <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+ <init-param>
+ <param-name>applicationClassName</param-name>
+ <param-value>org.wamblee.photos.wicket.WicketApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>configuration</param-name>
+ <param-value>development</param-value>
+ </init-param>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>authentication</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
<filter-mapping>
- <filter-name>authentication</filter-name>
- <url-pattern>/*</url-pattern>
+ <filter-name>photos</filter-name>
+ <url-pattern>/*</url-pattern>
</filter-mapping>
- <filter-mapping>
- <filter-name>photos</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
- <security-constraint>
- <web-resource-collection>
- <web-resource-name>resources</web-resource-name>
- <url-pattern>/resources/*</url-pattern>
- </web-resource-collection>
- </security-constraint>
- <security-constraint>
- <web-resource-collection>
- <web-resource-name>securedaccess</web-resource-name>
- <url-pattern>/*</url-pattern>
- </web-resource-collection>
- <auth-constraint>
- <role-name>ALL</role-name>
- <role-name>users</role-name>
- </auth-constraint>
- </security-constraint>
-
- <login-config>
- <auth-method>FORM</auth-method>
- <realm-name>PhotoXChangeRealm</realm-name>
- <form-login-config>
- <form-login-page>/login.jsp</form-login-page>
- <form-error-page>/loginError.jsp</form-error-page>
- </form-login-config>
- </login-config>
-
- <session-config>
- <session-timeout>10</session-timeout>
- </session-config>
-
- <welcome-file-list>
- <welcome-file>login.jsp</welcome-file>
- </welcome-file-list>
-
- <security-role>
- <role-name>ALL</role-name>
- </security-role>
-
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>resources</web-resource-name>
+ <url-pattern>/resources/*</url-pattern>
+ </web-resource-collection>
+ </security-constraint>
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>securedaccess</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>ALL</role-name>
+ <role-name>users</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <login-config>
+ <auth-method>FORM</auth-method>
+ <realm-name>PhotoXChangeRealm</realm-name>
+ <form-login-config>
+ <form-login-page>/login.jsp</form-login-page>
+ <form-error-page>/loginError.jsp</form-error-page>
+ </form-login-config>
+ </login-config>
+
+ <error-page>
+ <error-code>404</error-code>
+ <!-- view will redirect to login if the user is not logged in -->
+ <location>/404.jsp</location>
+ </error-page>
+
+ <session-config>
+ <session-timeout>10</session-timeout>
+ </session-config>
+
+ <welcome-file-list>
+ <welcome-file>login.jsp</welcome-file>
+ </welcome-file-list>
+
+ <security-role>
+ <role-name>ALL</role-name>
+ </security-role>
+
</web-app>
<head>
<title wicket:id="title">Home Page</title>
+<%
+ String cssUrl = request.getContextPath() + "/resources/org.wamblee.photos.wicket.BasePage/photos.css";
+%>
-<link rel="stylesheet" type="text/css"
- href="resources/org.wamblee.photos.wicket.BasePage/photos.css" />
+<link rel="stylesheet" type="text/css" href="<%= cssUrl %>" />
</head>
<body>
<div id="banner">
- <wicket:link>
- <img
- src="resources/org.wamblee.photos.wicket.BasePage/wamblee_logo.png" />
- </wicket:link>
+ <%
+ String logoUrl = request.getContextPath() + "/resources/org.wamblee.photos.wicket.BasePage/wamblee_logo.png";
+ %>
+ <img src="<%= logoUrl %>" />
<span class="title">wamblee photos</span>
</div>