LayoutView.java
3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package fi.codecrew.moya.web.helper;
import java.io.ByteArrayInputStream;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.enums.apps.ContentPermission;
import fi.codecrew.moya.model.LanEventProperty;
import fi.codecrew.moya.model.LanEventPropertyKey;
@Named
@RequestScoped
public class LayoutView {
@Inject
private FacesContext context;
private ResourceBundle rb;
private String pagename;
@EJB
private EventBeanLocal eventbean;
@EJB
private PermissionBeanLocal permbean;
private StreamedContent headerimage;
private String headertext;
private static final Logger logger = LoggerFactory.getLogger(LayoutView.class);
public void init() {
logger.info("Initialized layoutView");
}
public boolean isManageContent()
{
return permbean.hasPermission(ContentPermission.MANAGE_PAGES);
}
public String getPagepath() {
if (pagename == null) {
HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
String[] splitted = req.getServletPath().split("\\.");
if (splitted.length > 0) {
pagename = splitted[0];
}
}
return pagename;
}
private String localize(String key) {
String value = null;
try {
value = getResourcebundle().getString(key);
} catch (MissingResourceException e) {
value = null;
}
if (key == null) {
value = "########";
} else if (value == null) {
value = "???" + key + "???";
}
return value;
}
private ResourceBundle getResourcebundle() {
if (rb == null) {
rb = context.getApplication().getResourceBundle(context, "i18n");
}
return rb;
}
public String getHeader() {
return new StringBuilder().append(eventbean.getCurrentEvent().getName()).append(" - ")
.append(localize(new StringBuilder("submenu").append(getPagepath().replace('/', '.')).toString())).toString();
}
// public String header() {
// logger.info("Context {}", context);
// UIViewRoot root = context.getViewRoot();
// Map<String, Object> viewmap = root.getViewMap(false);
// if (viewmap != null) {
// for (Entry<String, Object> entry : viewmap.entrySet()) {
// logger.info("Got entry {}: {}", entry.getKey(), entry.getValue());
// }
// }
// logger.info("Attrmap");
// if (context.getAttributes() != null) {
// for (Entry<Object, Object> e : context.getAttributes().entrySet()) {
// logger.info("Got attr {}: {}", e.getKey(), e.getValue());
// }
// }
// return "";
// }
public StreamedContent getHeaderimage() {
if (headertext == null && headerimage == null)
{
LanEventProperty logo = eventbean.getProperty(LanEventPropertyKey.EVENT_LOGO);
if (logo != null)
{
if (logo.getByteMime() == null)
{
headertext = logo.getTextvalue();
} else {
headerimage = new DefaultStreamedContent(new ByteArrayInputStream(logo.getByteValue()), logo.getByteMime());
}
}
}
return headerimage;
}
public void setHeaderimage(StreamedContent headerimage) {
this.headerimage = headerimage;
}
public String getHeadertext() {
return headertext;
}
public void setHeadertext(String headertext) {
this.headertext = headertext;
}
}