View Javadoc

1   package de.tivsource.page.user.actions.appointmentarchive;
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.appointment.AppointmentDaoLocal;
17  import de.tivsource.page.dao.page.PageDaoLocal;
18  import de.tivsource.page.dao.property.PropertyDaoLocal;
19  import de.tivsource.page.entity.appointment.Appointment;
20  import de.tivsource.page.entity.page.Page;
21  import de.tivsource.page.user.actions.EmptyAction;
22  
23  @TilesDefinitions({
24    @TilesDefinition(name="appointment", extend = "userTemplate", putAttributes = {
25      @TilesPutAttribute(name = "meta",       value = "/WEB-INF/tiles/active/meta/appointment.jsp"),
26      @TilesPutAttribute(name = "twitter",    value = "/WEB-INF/tiles/active/twitter/content.jsp"),
27      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/appointmentarchive/appointment.jsp")
28    })
29  })
30  public class AppointmentAction extends EmptyAction {
31  
32      /**
33       * Serial Version UID.
34       */
35      private static final long serialVersionUID = 2449929224384587137L;
36  
37      /**
38       * Statischer Logger der Klasse.
39       */
40      private static final Logger LOGGER = LogManager.getLogger(AppointmentAction.class);
41  
42      @InjectEJB(name = "PageDao")
43      private PageDaoLocal pageDaoLocal;
44  
45      @InjectEJB(name="PropertyDao")
46      private PropertyDaoLocal propertyDaoLocal;
47  
48      @InjectEJB(name="AppointmentDao")
49      private AppointmentDaoLocal appointmentDaoLocal;
50  
51      private Appointment appointment;
52  
53      private String appointmentUuid;
54      
55      private Page page;
56  
57      @Override
58      @Actions({
59          @Action(value = "*/index", results = {
60              @Result(name = "success", type = "tiles", location = "appointment"),
61              @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
62              @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
63          })
64      })
65      public String execute() throws Exception {
66          LOGGER.info("execute() aufgerufen.");
67  
68          // Hole Action Locale
69          this.getLanguageFromActionContext();
70  
71          appointmentUuid = ServletActionContext.getRequest().getServletPath();
72          LOGGER.info("Appointment Uuid: " + appointmentUuid);
73  
74          // /gallery/painting/index.html?page=1&request_locale=de
75          
76          
77          appointmentUuid = appointmentUuid.replaceAll("/index.html", "");
78          appointmentUuid = appointmentUuid.replaceAll("/appointmentarchive/", "");
79              
80          LOGGER.info("Appointment Uuid: " + appointmentUuid);
81  
82          /*
83           * Wenn die Manual Uuid keine nicht erlaubten Zeichen enthält und es
84           * das Manual mit der Uuid gibt dann wird der Block ausgeführt.
85           */
86          if (isValid(appointmentUuid) && appointmentDaoLocal.isAppointmentUuid(appointmentUuid)) {
87              LOGGER.info("gültige Appointment Uuid.");
88  
89              appointment = appointmentDaoLocal.findByUuid(appointmentUuid);
90  
91              // Setze Daten in ein Page Objekt
92              setUpPage();
93  
94              return SUCCESS;
95          }
96  
97          /*
98           * Wenn es die Seite nicht gibt oder es einen Manipulationsversuch
99           * gab.
100          */
101          return ERROR;
102     }// Ende execute()
103 
104     @Override
105     public Page getPage() {
106         return page;
107     }
108 
109     public Appointment getAppointment() {
110         return appointment;
111     }
112 
113     private Boolean isValid(String input) {
114         if (Pattern.matches("[abcdef0-9-]*", input)) {
115             return true;
116         } else {
117             return false;
118         }
119     }
120 
121     private void setUpPage() {
122         page = new Page();
123         page.setDescriptionMap(appointment.getDescriptionMap());
124         page.setPicture(appointment.getPicture());
125         page.setPictureOnPage(appointment.getPictureOnPage());
126         page.setCssGroup(appointment.getCssGroup());
127     }
128 
129 }// Ende class