1 package de.tivsource.page.user.actions.home;
2
3 import java.util.regex.Pattern;
4
5 import org.apache.logging.log4j.LogManager;
6 import org.apache.logging.log4j.Logger;
7 import org.apache.struts2.ServletActionContext;
8 import org.apache.struts2.convention.annotation.Action;
9 import org.apache.struts2.convention.annotation.Actions;
10 import org.apache.struts2.convention.annotation.Result;
11
12 import de.tivsource.ejb3plugin.InjectEJB;
13 import de.tivsource.page.dao.page.PageDaoLocal;
14 import de.tivsource.page.entity.page.Page;
15 import de.tivsource.page.user.actions.EmptyAction;
16
17 public class IndexAction extends EmptyAction {
18
19
20
21
22 private static final long serialVersionUID = 8289584958123232818L;
23
24
25
26
27 private static final Logger LOGGER = LogManager.getLogger(IndexAction.class);
28
29 @InjectEJB(name = "PageDao")
30 private PageDaoLocal pageDaoLocal;
31
32
33
34
35 private String pageName;
36
37 private Page page;
38
39 @Override
40 @Actions({
41 @Action(value = "*/*", results = {
42 @Result(name = "success", type = "tiles", location = "index"),
43 @Result(name = "error", type = "redirectAction", location = "index.html") })
44 })
45 public String execute() throws Exception {
46 LOGGER.info("execute() aufgerufen.");
47
48
49 this.getLanguageFromActionContext();
50
51 pageName = ServletActionContext.getRequest().getServletPath();
52 LOGGER.info("PageName: " + pageName);
53
54
55
56
57 pageName = pageName.replaceAll("/index.html", "");
58 pageName = pageName.replaceAll("/", "");
59
60 LOGGER.info("PageName: " + pageName);
61
62
63
64
65
66 if (isValid(pageName) && pageDaoLocal.isPageUrl(pageName)) {
67 page = pageDaoLocal.findByTechnical(pageName);
68 return SUCCESS;
69 }
70
71
72
73
74
75 return ERROR;
76 }
77
78 @Override
79 public Page getPage() {
80 return page;
81 }
82
83 private Boolean isValid(String input) {
84 if (Pattern.matches("[a-z]*", input)) {
85 return true;
86 } else {
87 return false;
88 }
89 }
90
91 }