1 package de.tivsource.page.user.actions.manual;
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 import org.apache.struts2.tiles.annotation.TilesDefinition;
12 import org.apache.struts2.tiles.annotation.TilesDefinitions;
13 import org.apache.struts2.tiles.annotation.TilesPutAttribute;
14
15 import de.tivsource.ejb3plugin.InjectEJB;
16 import de.tivsource.page.dao.manual.ManualDaoLocal;
17 import de.tivsource.page.dao.page.PageDaoLocal;
18 import de.tivsource.page.dao.property.PropertyDaoLocal;
19 import de.tivsource.page.entity.manual.Manual;
20 import de.tivsource.page.entity.page.Page;
21 import de.tivsource.page.user.actions.EmptyAction;
22
23
24
25
26
27
28 @TilesDefinitions({
29 @TilesDefinition(name="manual", extend = "userTemplate", putAttributes = {
30 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/manual.jsp"),
31 @TilesPutAttribute(name = "twitter", value = "/WEB-INF/tiles/active/twitter/manual.jsp"),
32 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/manual/manual.jsp")
33 })
34 })
35 public class ManualAction extends EmptyAction {
36
37
38
39
40 private static final long serialVersionUID = 6773842640719364262L;
41
42
43
44
45 private static final Logger LOGGER = LogManager.getLogger(ManualAction.class);
46
47 @InjectEJB(name = "PageDao")
48 private PageDaoLocal pageDaoLocal;
49
50 @InjectEJB(name="PropertyDao")
51 private PropertyDaoLocal propertyDaoLocal;
52
53 @InjectEJB(name="ManualDao")
54 private ManualDaoLocal manualDaoLocal;
55
56 private Manual manual;
57
58 private String manualUuid;
59
60 private Page page;
61
62 @Override
63 @Actions({
64 @Action(value = "*/index", results = {
65 @Result(name = "success", type = "tiles", location = "manual"),
66 @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
67 @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
68 })
69 })
70 public String execute() throws Exception {
71 LOGGER.info("execute() aufgerufen.");
72
73
74 boolean moduleEnabled = propertyDaoLocal.findByKey("module.manual").getValue().equals("true") ? true : false;
75
76
77 if(moduleEnabled) {
78
79 this.getLanguageFromActionContext();
80
81
82 manualUuid = ServletActionContext.getRequest().getServletPath();
83 LOGGER.info("ManualUuid: " + manualUuid);
84 manualUuid = manualUuid.replaceAll("/index.html", "");
85 manualUuid = manualUuid.replaceAll("/manual/", "");
86 LOGGER.info("ManualUuid: " + manualUuid);
87
88
89
90
91
92 if (isValid(manualUuid) && manualDaoLocal.isManualUuid(manualUuid)) {
93 LOGGER.info("gültige Manual Uuid.");
94
95 manual = manualDaoLocal.findByUuid(manualUuid);
96
97
98 setUpPage();
99
100 return SUCCESS;
101 }
102
103
104 return ERROR;
105 } else {
106
107 return ERROR;
108 }
109
110 }
111
112 @Override
113 public Page getPage() {
114 return page;
115 }
116
117 public Manual getManual() {
118 return manual;
119 }
120
121 private Boolean isValid(String input) {
122 if (Pattern.matches("[abcdef0-9-]*", input)) {
123 return true;
124 } else {
125 return false;
126 }
127 }
128
129 private void setUpPage() {
130 page = new Page();
131 page.setTechnical(manual.getTechnical());
132 page.setDescriptionMap(manual.getDescriptionMap());
133 page.setPicture(manual.getPicture());
134 page.setPictureOnPage(manual.getPictureOnPage());
135 page.setCssGroup(manual.getCssGroup());
136 }
137
138 }