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