KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > forms > StylesForm


1 /*
2  * $$Id: StylesForm.java,v 1.3 2005/06/07 12:32:17 bel70 Exp $$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitry Belov <bel@jresearch.org>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on Jan 11, 2004
27  *
28  */

29 package org.jresearch.gossip.forms;
30
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Set JavaDoc;
35
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37
38 import org.apache.oro.text.perl.Perl5Util;
39 import org.apache.struts.action.ActionError;
40 import org.apache.struts.action.ActionErrors;
41 import org.apache.struts.action.ActionMapping;
42 import org.apache.struts.validator.ValidatorForm;
43
44 /**
45  * DOCUMENT ME!
46  *
47  * @author Bel
48  */

49 public class StylesForm extends ValidatorForm {
50     private final Map JavaDoc values = new HashMap JavaDoc();
51
52     private String JavaDoc skinid;
53
54     /**
55      * Reset all properties to their default values.
56      *
57      * @param mapping
58      * The mapping used to select this instance
59      * @param request
60      * The servlet request we are processing
61      */

62     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
63         this.skinid = null;
64         this.values.clear();
65     }
66
67     /**
68      * DOCUMENT ME!
69      *
70      * @param mapping
71      * DOCUMENT ME!
72      * @param request
73      * DOCUMENT ME!
74      *
75      * @return DOCUMENT ME!
76      */

77     public ActionErrors validate(ActionMapping mapping,
78             HttpServletRequest JavaDoc request) {
79         // Perform validator framework validations
80
ActionErrors errors = super.validate(mapping, request);
81         Iterator JavaDoc it = getKeys().iterator();
82         Perl5Util util = new Perl5Util();
83         while (it.hasNext()) {
84             String JavaDoc key = (String JavaDoc) it.next();
85             if (!util.match("/^[a-fA-F0-9]{6}$/", (String JavaDoc) getValue(key))) {
86                 errors.add(key, new ActionError("errors.color", key));
87             }
88         }
89
90         return errors;
91     }
92
93     /**
94      * DOCUMENT ME!
95      *
96      * @param key
97      * DOCUMENT ME!
98      * @param value
99      * DOCUMENT ME!
100      */

101     public void setValue(String JavaDoc key, Object JavaDoc value) {
102         values.put(key, value);
103     }
104
105     /**
106      * DOCUMENT ME!
107      *
108      * @param key
109      * DOCUMENT ME!
110      *
111      * @return DOCUMENT ME!
112      */

113     public Object JavaDoc getValue(String JavaDoc key) {
114         return values.get(key);
115     }
116
117     /**
118      * DOCUMENT ME!
119      *
120      * @return DOCUMENT ME!
121      */

122     public Set JavaDoc getKeys() {
123         return values.keySet();
124     }
125
126     /**
127      * DOCUMENT ME!
128      *
129      * @return
130      */

131     public String JavaDoc getSkinid() {
132         return skinid;
133     }
134
135     /**
136      * DOCUMENT ME!
137      *
138      * @param i
139      */

140     public void setSkinid(String JavaDoc i) {
141         skinid = i;
142     }
143 }
144
Popular Tags