From: Erik Brakkee Date: Sat, 21 Sep 2013 22:58:09 +0000 (+0200) Subject: Same styling of photo albums as with tapestry based application. X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;ds=inline;h=6c8dd0362c097e5d3e40ca066b67ce6834e555df;hp=c64efa2d2002d15b22f458391cd44dfca44f8c96;p=photos Same styling of photo albums as with tapestry based application. More robustness when wrong URLs are used. --- diff --git a/src/main/java/org/wamblee/photos/wicket/BasePage.java b/src/main/java/org/wamblee/photos/wicket/BasePage.java index d4bdc11..f6c63d0 100644 --- a/src/main/java/org/wamblee/photos/wicket/BasePage.java +++ b/src/main/java/org/wamblee/photos/wicket/BasePage.java @@ -15,6 +15,10 @@ */ 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; @@ -28,6 +32,9 @@ import org.wamblee.wicket.page.WebApplicationBasePage; public class BasePage extends WebApplicationBasePage { + @Inject + private HttpServletRequest request; + private boolean isExpired = false; public BasePage() { @@ -36,10 +43,14 @@ public class BasePage extends WebApplicationBasePage { 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")); @@ -56,10 +67,15 @@ public class BasePage extends WebApplicationBasePage { @Override public void onClick() { getRequestCycle().getSession().invalidate(); + throw redirectToLoginPage(); } }); } + private RedirectToUrlException redirectToLoginPage() { + return new RedirectToUrlException("login.jsp"); + } + public void setExpired(boolean aExpired) { isExpired = aExpired; } diff --git a/src/main/java/org/wamblee/photos/wicket/HomePage.html b/src/main/java/org/wamblee/photos/wicket/HomePage.html index 705199a..26ac07e 100644 --- a/src/main/java/org/wamblee/photos/wicket/HomePage.html +++ b/src/main/java/org/wamblee/photos/wicket/HomePage.html @@ -12,16 +12,16 @@ Message here. -
- +
+
-
+ - + diff --git a/src/main/java/org/wamblee/photos/wicket/HomePage.java b/src/main/java/org/wamblee/photos/wicket/HomePage.java index 289f783..a7aa1a3 100644 --- a/src/main/java/org/wamblee/photos/wicket/HomePage.java +++ b/src/main/java/org/wamblee/photos/wicket/HomePage.java @@ -19,6 +19,7 @@ import java.io.ByteArrayOutputStream; 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; @@ -41,6 +42,8 @@ import org.wamblee.security.authentication.UserAdministration; */ public class HomePage extends BasePage { + private static final Logger LOGGER = Logger.getLogger(HomePage.class.getName()); + private static final long serialVersionUID = 1L; @Inject @@ -71,9 +74,14 @@ public class HomePage extends BasePage { @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. * @@ -81,6 +89,13 @@ public class HomePage extends BasePage { */ 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); @@ -103,21 +118,29 @@ public class HomePage extends BasePage { 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); @@ -125,7 +148,7 @@ public class HomePage extends BasePage { // 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++; } diff --git a/src/main/java/org/wamblee/photos/wicket/WicketApplication.java b/src/main/java/org/wamblee/photos/wicket/WicketApplication.java index 8339000..a1859a7 100644 --- a/src/main/java/org/wamblee/photos/wicket/WicketApplication.java +++ b/src/main/java/org/wamblee/photos/wicket/WicketApplication.java @@ -15,22 +15,21 @@ */ 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 { @@ -44,8 +43,7 @@ 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 @@ -56,6 +54,8 @@ public class WicketApplication extends WebApplication { 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(); @@ -68,5 +68,4 @@ public class WicketApplication extends WebApplication { public Class getHomePage() { return HomePage.class; } - } diff --git a/src/main/java/org/wamblee/photos/wicket/photos.css b/src/main/java/org/wamblee/photos/wicket/photos.css index eaa78ec..4c08bef 100644 --- a/src/main/java/org/wamblee/photos/wicket/photos.css +++ b/src/main/java/org/wamblee/photos/wicket/photos.css @@ -1,8 +1,6 @@ /* general */ body { - font-family: Arial, Helvetica, sans-serif; - list-style-type: square; - font-size: 20px; + font-family: sans-serif; } /* menu styling */ @@ -79,32 +77,28 @@ ul.feedbackPanel { 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 diff --git a/src/main/webapp/404.jsp b/src/main/webapp/404.jsp new file mode 100644 index 0000000..5f2d8eb --- /dev/null +++ b/src/main/webapp/404.jsp @@ -0,0 +1,47 @@ +<%@ page language="java" pageEncoding="UTF-8" session="true"%> + + + +<% + String path = request.getContextPath(); + String basePath = request.getScheme() + "://" + + request.getServerName() + ":" + request.getServerPort() + path + + "/"; +%> + + + + + +Oops + +<% + String cssUrl = request.getContextPath() + "/resources/org.wamblee.photos.wicket.BasePage/photos.css"; +%> + + + + + + + + + +
+ Oops, the requested URL could not be found. + <% + String loginUrl = request.getContextPath() + "/login.jsp"; + %> + Please login again + + <% + session.invalidate(); + %> + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 6762478..eaa1fd7 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -1,98 +1,104 @@ + 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"> - cdi + cdi - - - - authentication - org.wamblee.photos.security.AuthenticationFilter - - loginpage - /login.jsp - - - - role - ALL - - - - resources - /resources - - + - - photos - org.apache.wicket.protocol.http.WicketFilter - - applicationClassName - org.wamblee.photos.wicket.WicketApplication - - - configuration - development - - + + authentication + org.wamblee.photos.security.AuthenticationFilter + + loginpage + /login.jsp + + + + role + ALL + + + + resources + /resources + + + + photos + org.apache.wicket.protocol.http.WicketFilter + + applicationClassName + org.wamblee.photos.wicket.WicketApplication + + + configuration + development + + + + + authentication + /* + - authentication - /* + photos + /* - - photos - /* - - - - - resources - /resources/* - - - - - securedaccess - /* - - - ALL - users - - - - - FORM - PhotoXChangeRealm - - /login.jsp - /loginError.jsp - - - - - 10 - - - - login.jsp - - - - ALL - - + + + + resources + /resources/* + + + + + securedaccess + /* + + + ALL + users + + + + + FORM + PhotoXChangeRealm + + /login.jsp + /loginError.jsp + + + + + 404 + + /404.jsp + + + + 10 + + + + login.jsp + + + + ALL + + diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp index e3fbb11..88393b4 100644 --- a/src/main/webapp/login.jsp +++ b/src/main/webapp/login.jsp @@ -15,18 +15,20 @@ Home Page +<% + String cssUrl = request.getContextPath() + "/resources/org.wamblee.photos.wicket.BasePage/photos.css"; +%> - +
photo name