KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > portlets > categories > struts > CategoryForm


1 package com.dotmarketing.portlets.categories.struts;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import org.apache.commons.lang.builder.EqualsBuilder;
5 import org.apache.commons.lang.builder.HashCodeBuilder;
6 import org.apache.commons.lang.builder.ToStringBuilder;
7 import org.apache.struts.action.ActionErrors;
8 import org.apache.struts.action.ActionMapping;
9 import org.apache.struts.action.ActionMessage;
10 import org.apache.struts.action.ActionMessages;
11 import org.apache.struts.validator.ValidatorForm;
12 import com.dotmarketing.portlets.categories.factories.CategoryFactory;
13 import com.dotmarketing.portlets.categories.model.Category;
14 import com.dotmarketing.util.Logger;
15 import com.dotmarketing.util.UtilMethods;
16 import com.liferay.portal.util.Constants;
17
18
19 /** @author Hibernate CodeGenerator */
20 public class CategoryForm extends ValidatorForm {
21     private static final long serialVersionUID = 1L;
22     private long inode;
23     private long parent;
24     private String JavaDoc description;
25     private String JavaDoc keywords;
26     private String JavaDoc key;
27     private String JavaDoc categoryName;
28     private boolean active;
29     private int sortOrder;
30
31     public String JavaDoc getKeywords() {
32         return this.keywords;
33     }
34     public void setKeywords(String JavaDoc keywords) {
35         this.keywords = keywords;
36     }
37     /** full constructor */
38     public CategoryForm(java.lang.String JavaDoc categoryName, int sortOrder) {
39         this.categoryName = categoryName;
40         this.sortOrder = sortOrder;
41     }
42
43     /** default constructor */
44     public CategoryForm() {
45     }
46
47     /** minimal constructor */
48     public CategoryForm(java.lang.String JavaDoc categoryName) {
49         this.categoryName = categoryName;
50     }
51
52     public long getInode() {
53         return this.inode;
54     }
55
56     public void setInode(long inode) {
57         this.inode = inode;
58     }
59
60     public java.lang.String JavaDoc getCategoryName() {
61         return this.categoryName;
62     }
63
64     public void setCategoryName(java.lang.String JavaDoc categoryName) {
65         this.categoryName = categoryName;
66     }
67
68     public int getSortOrder() {
69         return this.sortOrder;
70     }
71
72     public void setSortOrder(int sortOrder) {
73         this.sortOrder = sortOrder;
74     }
75
76     public String JavaDoc toString() {
77         return new ToStringBuilder(this).append("inode", getInode()).toString();
78     }
79
80     public boolean equals(Object JavaDoc other) {
81         if (!(other instanceof CategoryForm)) {
82             return false;
83         }
84
85         CategoryForm castOther = (CategoryForm) other;
86
87         return new EqualsBuilder().append(this.getInode(), castOther.getInode()).isEquals();
88     }
89
90     public int hashCode() {
91         return new HashCodeBuilder().append(getInode()).toHashCode();
92     }
93
94     /**
95      * Returns the parent.
96      * @return long
97      */

98     public long getParent() {
99         return parent;
100     }
101
102     /**
103      * Sets the parent.
104      * @param parent The parent to set
105      */

106     public void setParent(long parent) {
107         this.parent = parent;
108     }
109
110     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
111         
112         Logger.debug(this, "validating CategoryForm" + request.getParameter("cmd"));
113
114         if ((request.getParameter("cmd") != null) && request.getParameter("cmd").equals(Constants.ADD)) {
115             ActionErrors ae = super.validate(mapping, request);
116
117             Logger.debug(this, "action errors: " + ae);
118
119             if (UtilMethods.isSet(getKey())) {
120                 Category cat = CategoryFactory.getCategoryByKey(getKey());
121
122                 if ((cat.getInode() > 0) && (cat.getInode() != this.inode)) {
123                     ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.category.folder.taken"));
124                     return ae;
125                 }
126             }
127         }
128
129         return null;
130     }
131
132     /**
133      * Returns the description.
134      * @return String
135      */

136     public String JavaDoc getDescription() {
137         return description;
138     }
139
140     /**
141      * Sets the description.
142      * @param description The description to set
143      */

144     public void setDescription(String JavaDoc description) {
145         this.description = description;
146     }
147
148     /**
149      * @return Returns the key.
150      */

151     public String JavaDoc getKey() {
152         return this.key;
153     }
154
155     /**
156      * @param key The key to set.
157      */

158     public void setKey(String JavaDoc key) {
159         if(key!=null){
160             key = key.replaceAll("/", "").replaceAll(" ", "_").toLowerCase();
161         }
162         this.key = key;
163     }
164
165     /**
166      * @return Returns the active.
167      */

168     public boolean isActive() {
169         return this.active;
170     }
171
172     /**
173      * @param active The active to set.
174      */

175     public void setActive(boolean active) {
176         this.active = active;
177     }
178 }
179
Popular Tags