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