View Javadoc

1   package de.tivsource.page.user.actions.contact;
2   
3   import java.net.URL;
4   
5   import org.apache.logging.log4j.LogManager;
6   import org.apache.logging.log4j.Logger;
7   import org.apache.struts2.convention.annotation.Action;
8   import org.apache.struts2.convention.annotation.Actions;
9   import org.apache.struts2.convention.annotation.Result;
10  import org.apache.struts2.tiles.annotation.TilesDefinition;
11  import org.apache.struts2.tiles.annotation.TilesDefinitions;
12  import org.apache.struts2.tiles.annotation.TilesPutAttribute;
13  
14  import de.tivsource.ejb3plugin.InjectEJB;
15  import de.tivsource.page.common.captcha.Captcha;
16  import de.tivsource.page.dao.captcha.CaptchaDaoLocal;
17  import de.tivsource.page.dao.page.PageDaoLocal;
18  import de.tivsource.page.dao.property.PropertyDaoLocal;
19  import de.tivsource.page.entity.page.Page;
20  import de.tivsource.page.user.actions.EmptyAction;
21  
22  /**
23   * 
24   * @author Marc Michele
25   *
26   */
27  @TilesDefinitions({
28    @TilesDefinition(name="contactForm", extend = "userTemplate", putAttributes = {
29      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/contact/contact_form.jsp")
30    })
31  })
32  public class ContactAction extends EmptyAction {
33  
34      /**
35       * Serial Version UID.
36       */
37      private static final long serialVersionUID = 8491900732546714341L;
38  
39      /**
40  	 * Statischer Logger der Klasse.
41  	 */
42      private static final Logger LOGGER = LogManager.getLogger(ContactAction.class);
43  
44      @InjectEJB(name="CaptchaDao")
45      private CaptchaDaoLocal captchaDaoLocal;
46  
47      @InjectEJB(name="PageDao")
48      private PageDaoLocal pageDaoLocal;
49  
50      @InjectEJB(name="PropertyDao")
51      private PropertyDaoLocal propertyDaoLocal;
52  
53      private Page page;
54  
55      private Captcha captcha;
56  
57      @Override
58      public void prepare() {
59          // Lade die Kontaktseite aus der Datenbank
60          this.page = pageDaoLocal.findByTechnical("contact");
61          // Lade Zufälligen Captcha aus der Datenbank
62          captcha = captchaDaoLocal.random();
63      }
64  
65      @Override
66      @Actions({
67          @Action(
68          		value = "index", 
69          		results = {
70          		  @Result(name = "success", type="tiles", location = "contactForm"),
71          		  @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
72          		}
73          )
74      })
75      public String execute() throws Exception {
76      	LOGGER.info("execute() aufgerufen.");
77      	
78      	// Hole Action Locale
79      	this.getLanguageFromActionContext();
80  
81      	Boolean contactPageEnabled = propertyDaoLocal.findByKey("contact.page.enabled").getValue().equals("true") ? true : false;
82  
83      	if(contactPageEnabled) {
84      	    URL templatePath = new URL(propertyDaoLocal.findByKey("mail.template.path").getValue());
85              LOGGER.info("Pfad zur temp.xml Klasse: " + templatePath);
86              return SUCCESS;
87      	} else {
88      	    return ERROR;
89      	}
90  
91      }// Ende execute()
92  
93      @Override
94      public Page getPage() {
95      	return this.page;
96      }// Ende getPage()
97  
98      /**
99       * @return the captcha
100      */
101     public Captcha getCaptcha() {
102         return captcha;
103     }
104 
105 }// Ende class