1 16 package org.apache.myfaces.examples.example2; 17 18 import javax.faces.model.SelectItem; 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 26 public class QuotationForm 27 { 28 private String _text = "QuotationTest"; 29 private String _quoteChar; 30 private String [] _selectManyValues; 31 32 private SelectItem[] _selectItems = null; 33 private List _selectManyItems = null; 34 35 36 37 public QuotationForm() 38 { 39 } 40 41 42 public String getText() 43 { 44 return _text; 45 } 46 47 public void setText(String text) 48 { 49 _text = text; 50 } 51 52 public String getQuoteChar() 53 { 54 return _quoteChar; 55 } 56 57 public void setQuoteChar(String 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 [] getSelectManyValues() 77 { 78 return _selectManyValues; 79 } 80 81 public void setSelectManyValues(String [] value) 82 { 83 _selectManyValues = value; 84 } 85 86 public List getSelectManyItems() 87 { 88 if (_selectManyItems == null) 89 { 90 _selectManyItems = new ArrayList (); 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 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 |