Rev 1357 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1355 | jmachado | 1 | package pt.estgp.estgweb.web.controllers.paginaseseccoes; |
75 | jmachado | 2 | |
1355 | jmachado | 3 | import org.apache.log4j.Logger; |
4 | import org.apache.struts.action.ActionErrors; |
||
5 | import org.apache.struts.upload.FormFile; |
||
6 | import pt.estgp.estgweb.domain.Pagina; |
||
7 | import pt.estgp.estgweb.domain.Seccao; |
||
1356 | jmachado | 8 | import pt.estgp.estgweb.utils.DynamicArrayList; |
1355 | jmachado | 9 | import pt.estgp.estgweb.web.form.ApplicationForm; |
75 | jmachado | 10 | |
11 | /** |
||
12 | * @author Jorge Machado |
||
13 | * @date 21/Abr/2008 |
||
14 | * @time 14:28:59 |
||
90 | jmachado | 15 | * @see pt.estgp.estgweb.web.form.blogs |
75 | jmachado | 16 | */ |
1355 | jmachado | 17 | public class PaginasSeccoesForm extends ApplicationForm |
75 | jmachado | 18 | { |
1355 | jmachado | 19 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(PaginasSeccoesForm.class); |
202 | jmachado | 20 | |
1355 | jmachado | 21 | Pagina pagina; |
22 | Seccao seccao; |
||
75 | jmachado | 23 | |
1374 | jmachado | 24 | FormFile ficheiro; |
187 | jmachado | 25 | |
1374 | jmachado | 26 | public FormFile getFicheiro() { |
27 | return ficheiro; |
||
28 | } |
||
29 | |||
30 | public void setFicheiro(FormFile ficheiro) { |
||
31 | this.ficheiro = ficheiro; |
||
32 | } |
||
33 | |||
1355 | jmachado | 34 | public Pagina getPagina() |
202 | jmachado | 35 | { |
1355 | jmachado | 36 | if(pagina == null) |
1356 | jmachado | 37 | { |
1355 | jmachado | 38 | pagina = new Pagina(); |
1357 | jmachado | 39 | pagina.setSeccoes(new DynamicArrayList<Seccao>(Seccao.class)); |
1356 | jmachado | 40 | } |
1355 | jmachado | 41 | return pagina; |
75 | jmachado | 42 | } |
43 | |||
1355 | jmachado | 44 | public void setPagina(Pagina pagina) { |
45 | this.pagina = pagina; |
||
75 | jmachado | 46 | } |
47 | |||
1355 | jmachado | 48 | public Seccao getSeccao() { |
49 | if(seccao == null) |
||
50 | seccao = new Seccao(); |
||
51 | return seccao; |
||
75 | jmachado | 52 | } |
53 | |||
1355 | jmachado | 54 | public void setSeccao(Seccao seccao) { |
55 | this.seccao = seccao; |
||
75 | jmachado | 56 | } |
202 | jmachado | 57 | |
178 | jmachado | 58 | public ActionErrors validate(org.apache.struts.action.ActionMapping actionMapping, javax.servlet.http.HttpServletRequest httpServletRequest) |
59 | { |
||
1355 | jmachado | 60 | /* |
202 | jmachado | 61 | if (httpServletRequest.getParameter("dispatch").equals("save")) |
178 | jmachado | 62 | { |
373 | jmachado | 63 | UserSessionImpl userSession; |
178 | jmachado | 64 | try |
65 | { |
||
66 | userSession = (UserSessionImpl) UserSessionProxy.loadUserSessionFromRequest(httpServletRequest); |
||
67 | List<String> roles = (List<String>) userSession.get(TARGET_ROLES_KEY); |
||
202 | jmachado | 68 | if (roles == null || roles.size() == 0) |
178 | jmachado | 69 | { |
70 | roles = new ArrayList<String>(); |
||
71 | roles.add(targetRolesStr); |
||
72 | } |
||
73 | blogView.setTargetRoles(roles); |
||
74 | } |
||
75 | catch (Throwable throwable) |
||
76 | { |
||
202 | jmachado | 77 | logger.error(throwable, throwable); |
178 | jmachado | 78 | } |
79 | } |
||
202 | jmachado | 80 | if (httpServletRequest.getParameter("dispatch").equals("addRole") || httpServletRequest.getParameter("dispatch").equals("removeRole")) |
178 | jmachado | 81 | return null; |
82 | ActionErrors errors = new ActionErrors(); |
||
202 | jmachado | 83 | if (image.getFileSize() != 0 && image.getFileSize() > (Globals.MAX_BIGMAGE_FILE_SIZE_BYTES)) |
84 | addMessage(errors, httpServletRequest, "blog.exceed.image.max.size"); |
||
85 | if (blogView.getTitle() == null || blogView.getTitle().trim().length() == 0) |
||
86 | addMessageWithKeys(errors, httpServletRequest, "errors.required", "blog.title"); |
||
87 | if (blogView.getDescription() == null || blogView.getDescription().trim().length() == 0) |
||
88 | addMessageWithKeys(errors, httpServletRequest, "errors.required", "blog.description"); |
||
89 | if(blogView.getName()!=null) |
||
90 | blogView.setName(blogView.getName().trim()); |
||
485 | jmachado | 91 | if(blogView.getName() != null && blogView.getName().trim().length() > 0 && !StringsUtils.checkLetters09AZazHiffenUnderScore(blogView.getName())) |
202 | jmachado | 92 | addMessage(errors, httpServletRequest, "blog.bad.name"); |
485 | jmachado | 93 | else if(blogView.getName() != null && blogView.getName().trim().length() > 0) |
202 | jmachado | 94 | { |
95 | IServiceManager sm; |
||
96 | try |
||
97 | { |
||
98 | sm = ServiceManager.getInstance(); |
||
99 | String[] names = new String[]{"serializable"}; |
||
100 | Object[] args = new Object[]{blogView.getName(),blogView.getId()}; |
||
101 | Boolean b = (Boolean) sm.execute(null, "CheckBlogName", args, names); |
||
102 | if (!b) |
||
103 | addMessage(errors, httpServletRequest, "blog.name.already.exist"); |
||
104 | } |
||
105 | catch (Throwable e) |
||
106 | { |
||
107 | logger.error(e,e); |
||
108 | addMessage(errors, httpServletRequest, "error.500"); |
||
109 | } |
||
187 | jmachado | 110 | |
485 | jmachado | 111 | }else if(blogView.getName() != null && blogView.getName().trim().length() == 0) |
112 | blogView.setName(null); |
||
178 | jmachado | 113 | return errors; |
1355 | jmachado | 114 | */ |
115 | return null; |
||
178 | jmachado | 116 | } |
187 | jmachado | 117 | |
75 | jmachado | 118 | } |