View Javadoc

1   package de.tivsource.page.reservation.actions;
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  
12  import de.tivsource.ejb3plugin.InjectEJB;
13  import de.tivsource.page.dao.location.LocationDaoLocal;
14  import de.tivsource.page.entity.location.Location;
15  
16  public class LocationAction extends EmptyAction {
17  
18      /**
19       * Serial Version UID.
20       */
21      private static final long serialVersionUID = 6236431708460575442L;
22  
23      /**
24       * Statischer Logger der Klasse.
25       */
26      private static final Logger LOGGER = LogManager.getLogger(LocationAction.class);
27  
28      @InjectEJB(name="LocationDao")
29      private LocationDaoLocal locationDaoLocal;
30  
31      /**
32       * Location Uuid im Pfad (Achtung kann duch den Benutzer manipuliert werden).
33       */
34      private String locationUuid;
35  
36      private Location location;
37  
38      public Location getLocation() {
39          return location;
40      }
41  
42      @Override
43      @Actions({
44          @Action(value = "*/index", results = {
45              @Result(name = "success", type = "tiles", location = "location"),
46              @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
47              @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
48          })
49      })
50      public String execute() throws Exception {
51          LOGGER.info("execute() aufgerufen.");
52  
53          // Hole Action Locale
54          this.getLanguageFromActionContext();
55  
56          locationUuid = ServletActionContext.getRequest().getServletPath();
57          LOGGER.info("LocationUuid: " + locationUuid);
58  
59          // /gallery/painting/index.html?page=1&request_locale=de
60          
61          
62          locationUuid = locationUuid.replaceAll("/index.html", "");
63          locationUuid = locationUuid.replaceAll("/", "");
64              
65          LOGGER.info("LocationUuid: " + locationUuid);
66  
67          
68          /*
69           * Wenn die Location Uuid keine nicht erlaubten Zeichen enthält und es
70           * die Location mit der Uuid gibt dann wird der Block ausgeführt.
71           */
72          if (isValid(locationUuid) && locationDaoLocal.isEventLocation(locationUuid)) {
73              LOGGER.info("gültige Location Uuid.");
74              location = locationDaoLocal.findByUuid(locationUuid);
75              return SUCCESS;
76          }
77  
78          /*
79           * Wenn es die Seite nicht gibt oder es einen Manipulationsversuch
80           * gab.
81           */
82           return ERROR;
83      }// Ende execute()
84  
85      private Boolean isValid(String input) {
86          if (Pattern.matches("[abcdef0-9-]*", input)) {
87              return true;
88          } else {
89              return false;
90          }
91      }
92  
93  }// Ende class