1 28 package net.sf.jasperreports.engine.design; 29 30 import java.beans.PropertyChangeListener ; 31 import java.beans.PropertyChangeSupport ; 32 import java.util.ArrayList ; 33 import java.util.List ; 34 import java.util.StringTokenizer ; 35 36 import net.sf.jasperreports.engine.JRConstants; 37 import net.sf.jasperreports.engine.JRQueryChunk; 38 import net.sf.jasperreports.engine.base.JRBaseQuery; 39 40 41 45 public class JRDesignQuery extends JRBaseQuery 46 { 47 48 private transient PropertyChangeSupport propSupport; 49 50 51 54 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 55 56 57 public static final String PROPERTY_LANGUAGE = "language"; 58 59 62 protected List chunks = new ArrayList (); 63 64 65 68 public JRQueryChunk[] getChunks() 69 { 70 JRQueryChunk[] chunkArray = null; 71 72 if (chunks != null && chunks.size() > 0) 73 { 74 chunkArray = new JRQueryChunk[chunks.size()]; 75 chunks.toArray(chunkArray); 76 } 77 78 return chunkArray; 79 } 80 81 84 public void setChunks(List chunks) 85 { 86 this.chunks = chunks; 87 } 88 89 92 public void addChunk(JRDesignQueryChunk chunk) 93 { 94 this.chunks.add(chunk); 95 } 96 97 100 public void addTextChunk(String text) 101 { 102 JRDesignQueryChunk chunk = new JRDesignQueryChunk(); 103 chunk.setType(JRQueryChunk.TYPE_TEXT); 104 chunk.setText(text); 105 106 this.chunks.add(chunk); 107 } 108 109 112 public void addParameterChunk(String text) 113 { 114 JRDesignQueryChunk chunk = new JRDesignQueryChunk(); 115 chunk.setType(JRQueryChunk.TYPE_PARAMETER); 116 chunk.setText(text); 117 118 this.chunks.add(chunk); 119 } 120 121 124 public void addParameterClauseChunk(String text) 125 { 126 JRDesignQueryChunk chunk = new JRDesignQueryChunk(); 127 chunk.setType(JRQueryChunk.TYPE_PARAMETER_CLAUSE); 128 chunk.setText(text); 129 130 this.chunks.add(chunk); 131 } 132 133 134 137 public void setText(String text) 138 { 139 chunks = new ArrayList (); 140 141 if (text != null) 142 { 143 int end = 0; 144 StringBuffer textChunk = new StringBuffer (); 145 String parameterChunk = null; 146 String parameterClauseChunk = null; 147 148 StringTokenizer tkzer = new StringTokenizer (text, "$", true); 149 String token = null; 150 boolean wasDelim = false; 151 while (tkzer.hasMoreTokens()) 152 { 153 token = tkzer.nextToken(); 154 155 if (token.equals("$")) 156 { 157 if (wasDelim) 158 { 159 textChunk.append("$"); 160 } 161 162 wasDelim = true; 163 } 164 else 165 { 166 if ( token.startsWith("P{") && wasDelim ) 167 { 168 end = token.indexOf('}'); 169 if (end > 0) 170 { 171 if (textChunk.length() > 0) 172 { 173 this.addTextChunk(textChunk.toString()); 174 } 175 parameterChunk = token.substring(2, end); 176 this.addParameterChunk(parameterChunk); 177 textChunk = new StringBuffer (token.substring(end + 1)); 178 } 179 else 180 { 181 if (wasDelim) 182 { 183 textChunk.append("$"); 184 } 185 textChunk.append(token); 186 } 187 } 188 else if ( token.startsWith("P!{") && wasDelim ) 189 { 190 end = token.indexOf('}'); 191 if (end > 0) 192 { 193 if (textChunk.length() > 0) 194 { 195 this.addTextChunk(textChunk.toString()); 196 } 197 parameterClauseChunk = token.substring(3, end); 198 this.addParameterClauseChunk(parameterClauseChunk); 199 textChunk = new StringBuffer (token.substring(end + 1)); 200 } 201 else 202 { 203 if (wasDelim) 204 { 205 textChunk.append("$"); 206 } 207 textChunk.append(token); 208 } 209 } 210 else 211 { 212 if (wasDelim) 213 { 214 textChunk.append("$"); 215 } 216 textChunk.append(token); 217 } 218 219 wasDelim = false; 220 } 221 } 222 if (wasDelim) 223 { 224 textChunk.append("$"); 225 } 226 if (textChunk.length() > 0) 227 { 228 this.addTextChunk(textChunk.toString()); 229 } 230 } 231 } 232 233 234 240 public void setLanguage(String language) 241 { 242 String oldValue = this.language; 243 this.language = language; 244 getPropertyChangeSupport().firePropertyChange(PROPERTY_LANGUAGE, oldValue, this.language); 245 } 246 247 248 255 protected PropertyChangeSupport getPropertyChangeSupport() 256 { 257 if (propSupport == null) 258 { 259 propSupport = new PropertyChangeSupport (this); 260 } 261 return propSupport; 262 } 263 264 269 public void addPropertyChangeListener(PropertyChangeListener l) 270 { 271 getPropertyChangeSupport().addPropertyChangeListener(l); 272 } 273 274 281 public void addPropertyChangeListener(String propName, PropertyChangeListener l) 282 { 283 getPropertyChangeSupport().addPropertyChangeListener(propName, l); 284 } 285 286 295 public void removePropertyChangeListener(PropertyChangeListener l) 296 { 297 getPropertyChangeSupport().removePropertyChangeListener(l); 298 } 299 300 306 public void removePropertyChangeListener(String propName, PropertyChangeListener l) 307 { 308 getPropertyChangeSupport().removePropertyChangeListener(propName, l); 309 } 310 } 311 | Popular Tags |