KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > examples > example2 > QuotationForm


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.examples.example2;
17
18 import javax.faces.model.SelectItem;
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  * DOCUMENT ME!
24  * @author Thomas Spiegl
25  */

26 public class QuotationForm
27 {
28     private String JavaDoc _text = "QuotationTest";
29     private String JavaDoc _quoteChar;
30     private String JavaDoc[] _selectManyValues;
31
32     private SelectItem[] _selectItems = null;
33     private List JavaDoc _selectManyItems = null;
34
35
36
37     public QuotationForm()
38     {
39     }
40
41
42     public String JavaDoc getText()
43     {
44         return _text;
45     }
46
47     public void setText(String JavaDoc text)
48     {
49         _text = text;
50     }
51
52     public String JavaDoc getQuoteChar()
53     {
54         return _quoteChar;
55     }
56
57     public void setQuoteChar(String JavaDoc value)
58     {
59         _quoteChar = value;
60     }
61
62     public SelectItem[] getSelectOneItems()
63     {
64         if (_selectItems == null)
65         {
66             _selectItems = new SelectItem[2];
67             _selectItems[0] = new SelectItem("*", "Asterisk");
68             _selectItems[1] = new SelectItem("+", "Plus");
69         }
70         return _selectItems;
71     }
72
73
74
75
76     public String JavaDoc[] getSelectManyValues()
77     {
78         return _selectManyValues;
79     }
80
81     public void setSelectManyValues(String JavaDoc[] value)
82     {
83         _selectManyValues = value;
84     }
85
86     public List JavaDoc getSelectManyItems()
87     {
88         if (_selectManyItems == null)
89         {
90             _selectManyItems = new ArrayList JavaDoc();
91             _selectManyItems.add(new SelectItem("\"", "Double"));
92             _selectManyItems.add(new SelectItem("'", "Single"));
93             _selectManyItems.add(new SelectItem("*", "Asterisk"));
94             _selectManyItems.add(new SelectItem("+", "Plus"));
95             _selectManyItems.add(new SelectItem("-", "Hyphen"));
96         }
97         return _selectManyItems;
98     }
99
100
101     public void quote()
102     {
103         if (_quoteChar != null)
104         {
105             _text = _quoteChar + _text + _quoteChar;
106         }
107     }
108
109     public void unquote()
110     {
111         if (_selectManyValues != null)
112         {
113             for (int i = 0; i < _selectManyValues.length; i++)
114             {
115                 unquote(_selectManyValues[i]);
116             }
117         }
118     }
119
120     private void unquote(String JavaDoc quoteChar)
121     {
122         if (quoteChar != null && quoteChar.length() > 0)
123         {
124             if (_text.startsWith(quoteChar))
125             {
126                 _text = _text.substring(1);
127             }
128
129             if (_text.endsWith(quoteChar))
130             {
131                 _text = _text.substring(0, _text.length() - 1);
132             }
133         }
134     }
135
136 }
137
138
Popular Tags