2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.photos.wicket;
18 import javax.inject.Inject;
19 import javax.servlet.http.HttpServletRequest;
21 import org.apache.wicket.RedirectToUrlException;
22 import org.apache.wicket.markup.html.CSSPackageResource;
23 import org.apache.wicket.markup.html.WebPage;
24 import org.apache.wicket.markup.html.basic.Label;
25 import org.apache.wicket.markup.html.link.Link;
26 import org.apache.wicket.markup.html.panel.FeedbackPanel;
27 import org.apache.wicket.model.IModel;
28 import org.wamblee.wicket.behavior.TitleAttributeTooltipBehavior;
29 import org.wamblee.wicket.css.ResetCssBehavior;
30 import org.wamblee.wicket.page.ExpireBehavior;
31 import org.wamblee.wicket.page.WebApplicationBasePage;
33 public class BasePage extends WebApplicationBasePage {
36 private HttpServletRequest request;
38 private boolean isExpired = false;
44 public BasePage(IModel aModel) {
47 if (request.getUserPrincipal() == null) {
48 redirectToLoginPage();
51 add(new ResetCssBehavior());
52 add(new TitleAttributeTooltipBehavior());
53 add(CSSPackageResource.getHeaderContribution(BasePage.class, "photos.css"));
56 add(new FeedbackPanel("feedback"));
57 add(new Label("title", getTitle()));
59 addBehavior(new ExpireBehavior() {
61 protected boolean isExpired(WebPage aPage) {
66 add(new Link("logout") {
68 public void onClick() {
69 getRequestCycle().getSession().invalidate();
70 throw redirectToLoginPage();
75 private RedirectToUrlException redirectToLoginPage() {
76 return new RedirectToUrlException("login.jsp");
79 public void setExpired(boolean aExpired) {
83 private String getTitle() {
84 String name = getClass().getSimpleName();
85 name = name.replaceAll("([A-Z]+)([A-Z][a-z])", "$1 $2");
86 name = name.replaceAll("[A-Z]+", " $0");
87 name = name.replaceAll("^ ", "");
88 name = name.replaceAll(" ", " ");