View Javadoc

1   package de.tivsource.page.user.actions;
2   
3   import java.math.BigDecimal;
4   import java.text.NumberFormat;
5   import java.util.List;
6   import java.util.Locale;
7   import java.util.Map;
8   
9   import javax.servlet.http.HttpServletRequest;
10  import javax.servlet.http.HttpServletResponse;
11  
12  import org.apache.logging.log4j.LogManager;
13  import org.apache.logging.log4j.Logger;
14  import org.apache.struts2.convention.annotation.Action;
15  import org.apache.struts2.convention.annotation.Actions;
16  import org.apache.struts2.convention.annotation.Result;
17  import org.apache.struts2.interceptor.ServletRequestAware;
18  import org.apache.struts2.interceptor.ServletResponseAware;
19  import org.apache.struts2.interceptor.SessionAware;
20  import org.apache.struts2.tiles.annotation.TilesDefinition;
21  import org.apache.struts2.tiles.annotation.TilesDefinitions;
22  
23  import com.opensymphony.xwork2.ActionContext;
24  import com.opensymphony.xwork2.ActionSupport;
25  import com.opensymphony.xwork2.Preparable;
26  
27  import de.tivsource.ejb3plugin.InjectEJB;
28  import de.tivsource.page.common.menuentry.MenuEntry;
29  import de.tivsource.page.dao.appointment.AppointmentDaoLocal;
30  import de.tivsource.page.dao.event.EventDaoLocal;
31  import de.tivsource.page.dao.menuentry.MenuEntryDaoLocal;
32  import de.tivsource.page.dao.page.PageDaoLocal;
33  import de.tivsource.page.dao.property.PropertyDaoLocal;
34  import de.tivsource.page.dao.slider.SliderDaoLocal;
35  import de.tivsource.page.entity.appointment.Appointment;
36  import de.tivsource.page.entity.event.Event;
37  import de.tivsource.page.entity.page.Page;
38  import de.tivsource.page.entity.slider.Slider;
39  
40  /**
41   * 
42   * @author Marc Michele
43   */
44  @TilesDefinitions({
45      @TilesDefinition(name="index",  extend = "userTemplate")
46  })
47  public class EmptyAction extends ActionSupport implements Preparable, ServletRequestAware,
48  		ServletResponseAware, SessionAware {
49  
50  	/**
51  	 * Serial Version UID.
52  	 */
53      private static final long serialVersionUID = 1294373943839660227L;
54  
55      /**
56  	 * Statischer Logger der Klasse.
57  	 */
58      private static final Logger LOGGER = LogManager.getLogger(EmptyAction.class);
59  
60  	/**
61  	 * Servlet-Request der die Post und Get Daten der Session enthält.
62  	 */
63  	private HttpServletRequest servletRequest;
64  
65  	private HttpServletResponse servletResponse;
66  
67  	private Map<String, Object> session;
68  
69      @InjectEJB(name="PropertyDao")
70      private PropertyDaoLocal propertyDaoLocal;
71  	
72      @InjectEJB(name="PageDao")
73  	private PageDaoLocal pageDaoLocal;
74  
75      @InjectEJB(name="MenuEntryDao")
76      private MenuEntryDaoLocal menuEntryDaoLocal;
77  
78      @InjectEJB(name="EventDao")
79      private EventDaoLocal eventDaoLocal;
80  
81      @InjectEJB(name="AppointmentDao")
82      private AppointmentDaoLocal appointmentDaoLocal;
83  
84      @InjectEJB(name="SliderDao")
85      private SliderDaoLocal sliderDaoLocal;
86      
87      private Event left;
88      private Event right;
89  
90      private Page page;
91      
92  	/**
93  	 * Attribut das die ausgelesene Sprache enthält.
94  	 */
95  	private String language = null;
96  
97  	public EmptyAction() {
98  		super();
99  	}
100 
101 	public static Logger getLogger() {
102 		return LOGGER;
103 	}
104 
105 	public HttpServletRequest getServletRequest() {
106 		return servletRequest;
107 	}
108 
109 	public void setServletRequest(HttpServletRequest httpServletRequest) {
110 		this.servletRequest = httpServletRequest;
111 	}
112 
113 	public HttpServletResponse getServletResponse() {
114 		return servletResponse;
115 	}
116 
117 	public void setServletResponse(HttpServletResponse servletResponse) {
118 		this.servletResponse = servletResponse;
119 	}
120 
121 	public Map<String, Object> getSession() {
122 		return session;
123 	}
124 
125 	public void setSession(Map<String, Object> session) {
126 		this.session = session;
127 	}
128 
129     @Override
130     public void prepare() {
131         // Lade die Startseite
132         page = pageDaoLocal.findByTechnical("home");
133     }
134 
135 	@Override
136 	@Actions({ 
137 		@Action(value = "index", results = { @Result(name = "success", type = "tiles", location = "index") })
138 		})
139 	public String execute() throws Exception {
140 		LOGGER.info("execute() aufgerufen.");
141 
142 		// Hole Action Locale
143 		this.getLanguageFromActionContext();
144 
145 		return SUCCESS;
146 	}
147 
148 	public String getActionName() {
149 		return ActionContext.getContext().getName();
150 	}
151 
152 	public List<MenuEntry> getTopNavigation() {
153 	    return menuEntryDaoLocal.findAllTopNavigation();
154 	}
155 
156     public List<MenuEntry> getNavigation() {
157         return menuEntryDaoLocal.findAllNavigation();
158     }
159 
160     public List<MenuEntry> getBottomNavigation() {
161         return menuEntryDaoLocal.findAllBottomNavigation();
162     }
163 
164     public List<MenuEntry> getResponsiveNavigation() {
165         return menuEntryDaoLocal.findAllResponsiveNavigation();
166     }
167 
168     public Page getPage() {
169         return this.page;
170     }
171 
172     public String getProperty(String key) {
173         return propertyDaoLocal.findByKey(key).getValue();
174     }
175 
176     public Event getLeftLocation() {
177         if(left == null) {
178             left = eventDaoLocal.findAll(propertyDaoLocal.findByKey("home.location.left").getValue(), 0, 1).get(0);
179         }
180         return left;
181     }
182 
183     public Event getRightLocation() {
184         if(right == null) {
185             right = eventDaoLocal.findAll(propertyDaoLocal.findByKey("home.location.right").getValue(), 0, 1).get(0);
186         }
187         return right;
188     }
189 
190     public List<Appointment> getSliderList() {
191         return appointmentDaoLocal.findAllVisible(0, Integer.parseInt(propertyDaoLocal.findByKey("home.appointment.slider.max.items").getValue()));
192     }
193 
194     public String getSliderWidth() {
195         BigDecimal sliderWidth = new BigDecimal(100).divide(new BigDecimal(getSliderList().size()), 3, BigDecimal.ROUND_HALF_UP);
196         NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); 
197         return numberFormat.format(sliderWidth);
198     }
199     
200     public List<Slider> getHomeSliderList() {
201         return sliderDaoLocal.findAllVisible(0, 7, "home");
202     }
203 
204     public String getHomeSliderWidth() {
205         BigDecimal sliderWidth = new BigDecimal(100).divide(new BigDecimal(getHomeSliderList().size()), 2, BigDecimal.ROUND_HALF_UP);
206         NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); 
207         return numberFormat.format(sliderWidth);
208     }
209 
210     
211 	/**
212 	 * Methode die die aktuelle Sprache aus dem Context holt.
213 	 */
214 	protected void getLanguageFromActionContext() {
215 		LOGGER.info("getLanguageFromSession() aufgerufen.");
216 		ActionContext actionContext = ActionContext.getContext();
217 		language = actionContext.getLocale().getLanguage();
218 		LOGGER.info("Action Locale: " + language);
219 	}
220 
221 }// Ende class