1 package com.dotmarketing.portlets.categories.struts; 2 3 import javax.servlet.http.HttpServletRequest ; 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 20 public class CategoryForm extends ValidatorForm { 21 private static final long serialVersionUID = 1L; 22 private long inode; 23 private long parent; 24 private String description; 25 private String keywords; 26 private String key; 27 private String categoryName; 28 private boolean active; 29 private int sortOrder; 30 31 public String getKeywords() { 32 return this.keywords; 33 } 34 public void setKeywords(String keywords) { 35 this.keywords = keywords; 36 } 37 38 public CategoryForm(java.lang.String categoryName, int sortOrder) { 39 this.categoryName = categoryName; 40 this.sortOrder = sortOrder; 41 } 42 43 44 public CategoryForm() { 45 } 46 47 48 public CategoryForm(java.lang.String 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 getCategoryName() { 61 return this.categoryName; 62 } 63 64 public void setCategoryName(java.lang.String 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 toString() { 77 return new ToStringBuilder(this).append("inode", getInode()).toString(); 78 } 79 80 public boolean equals(Object 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 98 public long getParent() { 99 return parent; 100 } 101 102 106 public void setParent(long parent) { 107 this.parent = parent; 108 } 109 110 public ActionErrors validate(ActionMapping mapping, HttpServletRequest 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 136 public String getDescription() { 137 return description; 138 } 139 140 144 public void setDescription(String description) { 145 this.description = description; 146 } 147 148 151 public String getKey() { 152 return this.key; 153 } 154 155 158 public void setKey(String key) { 159 if(key!=null){ 160 key = key.replaceAll("/", "").replaceAll(" ", "_").toLowerCase(); 161 } 162 this.key = key; 163 } 164 165 168 public boolean isActive() { 169 return this.active; 170 } 171 172 175 public void setActive(boolean active) { 176 this.active = active; 177 } 178 } 179 | Popular Tags |