KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsp > cfg > JspPropertyGroup


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free SoftwareFoundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jsp.cfg;
31
32 import com.caucho.config.ConfigException;
33 import com.caucho.config.types.FileSetType;
34 import com.caucho.config.types.Period;
35 import com.caucho.jsp.JspServlet;
36 import com.caucho.jsp.JspXmlServlet;
37 import com.caucho.server.dispatch.ServletMapping;
38 import com.caucho.server.dispatch.UrlMap;
39 import com.caucho.server.webapp.WebApp;
40 import com.caucho.util.L10N;
41 import com.caucho.vfs.Path;
42
43 import javax.annotation.PostConstruct;
44 import javax.servlet.ServletException JavaDoc;
45 import java.util.ArrayList JavaDoc;
46 import java.util.regex.Pattern JavaDoc;
47
48 /**
49  * Configuration for the jsp-property-group.
50  */

51 public class JspPropertyGroup {
52   private static final L10N L = new L10N(JspPropertyGroup.class);
53
54   private static int _gId;
55
56   private WebApp _webApp;
57   
58   private String JavaDoc _id;
59   private ArrayList JavaDoc<String JavaDoc> _urlPatterns = new ArrayList JavaDoc<String JavaDoc>();
60   private String JavaDoc _pageEncoding;
61   private Boolean JavaDoc _isELIgnored;
62   private boolean _isScriptingInvalid = false;
63   private Boolean JavaDoc _isXml = null;
64   private ArrayList JavaDoc<String JavaDoc> _includePrelude = new ArrayList JavaDoc<String JavaDoc>();
65   private ArrayList JavaDoc<String JavaDoc> _includeCoda = new ArrayList JavaDoc<String JavaDoc>();
66
67   // Resin config
68
private boolean _precompile = true;
69   private boolean _fastJstl = true;
70   private boolean _ideHack = false;
71   private boolean _velocity = false;
72   private boolean _session = true;
73   private boolean _staticEncoding = true;
74   private boolean _recycleTags = true;
75   private boolean _autoCompile = true;
76   private boolean _requireSource = false;
77   private boolean _ignoreELException = true;
78   private boolean _isValidateTaglibSchema = true;
79   private boolean _isPrintNullAsBlank = false;
80
81   private int _jspMax = 0;
82   private boolean _disableLog = true;
83   private long _dependencyCheckInterval = Long.MIN_VALUE;
84   private boolean _staticPageGeneratesClass = true;
85
86   private boolean _recompileOnError = false;
87   private FileSetType _tldFileSet;
88
89   private boolean _isTrimWhitespace = false;
90   private boolean _isDeferredSyntaxAllowedAsLiteral = false;
91
92   public JspPropertyGroup()
93   {
94   }
95
96   public JspPropertyGroup(WebApp webApp)
97   {
98     _webApp = webApp;
99   }
100   
101   /**
102    * Returns the group's identifier.
103    */

104   public String JavaDoc getId()
105   {
106     return _id;
107   }
108
109   /**
110    * Sets the group's identifier.
111    */

112   public void setId(String JavaDoc id)
113   {
114     _id = id;
115   }
116
117   /**
118    * Sets the group's description
119    */

120   public void setDescription(String JavaDoc description)
121   {
122   }
123
124   /**
125    * Sets the group's display name
126    */

127   public void setDisplayName(String JavaDoc displayName)
128   {
129   }
130
131   /**
132    * Adds a URL pattern.
133    */

134   public void addURLPattern(String JavaDoc urlPattern)
135   {
136     _urlPatterns.add(urlPattern);
137   }
138
139   /**
140    * Sets the default page encoding.
141    */

142   public void setPageEncoding(String JavaDoc pageEncoding)
143   {
144     _pageEncoding = pageEncoding;
145   }
146
147   /**
148    * Returns the default page encoding.
149    */

150   public String JavaDoc getPageEncoding()
151   {
152     return _pageEncoding;
153   }
154
155   /**
156    * Set true if EL expressions are ignored for the JSP page.
157    */

158   public void setELIgnored(boolean isELIgnored)
159   {
160     _isELIgnored = isELIgnored ? Boolean.TRUE : Boolean.FALSE;;
161   }
162
163   /**
164    * Return true if EL expressions are ignored for the JSP page.
165    */

166   public Boolean JavaDoc isELIgnored()
167   {
168     return _isELIgnored;
169   }
170
171   /**
172    * Sets the dependency check interval.
173    */

174   public void setDependencyCheckInterval(Period period)
175   {
176     _dependencyCheckInterval = period.getPeriod();
177   }
178
179   /**
180    * Gets the dependency check interval.
181    */

182   public long getDependencyCheckInterval()
183   {
184     return _dependencyCheckInterval;
185   }
186
187   /**
188    * Set true if scripting is invalid for the JSP page.
189    */

190   public void setScriptingInvalid(boolean isScriptingInvalid)
191   {
192     _isScriptingInvalid = isScriptingInvalid;
193   }
194
195   /**
196    * Return true if scripting expressions are invalid for the JSP page.
197    */

198   public boolean isScriptingInvalid()
199   {
200     return _isScriptingInvalid;
201   }
202
203   /**
204    * Return true if the JSP uses XML format.
205    */

206   public void setIsXml(boolean isXml)
207   {
208     _isXml = isXml ? Boolean.TRUE : Boolean.FALSE;
209   }
210
211   /**
212    * Return true if the JSP uses XML format.
213    */

214   public Boolean JavaDoc isXml()
215   {
216     return _isXml;
217   }
218
219   /**
220    * Adds a new prelude inclusion.
221    */

222   public void addIncludePrelude(String JavaDoc url)
223   {
224     _includePrelude.add(url);
225   }
226
227   /**
228    * Returns the prelude inclusion.
229    */

230   public ArrayList JavaDoc<String JavaDoc> getIncludePreludeList()
231   {
232     return _includePrelude;
233   }
234
235   /**
236    * Adds a new coda inclusion.
237    */

238   public void addIncludeCoda(String JavaDoc url)
239   {
240     _includeCoda.add(url);
241   }
242
243   /**
244    * Returns the coda inclusion.
245    */

246   public ArrayList JavaDoc<String JavaDoc> getIncludeCodaList()
247   {
248     return _includeCoda;
249   }
250
251   // Resin config
252

253   /**
254    * Set if precompilation is allowed.
255    */

256   public void setPrecompile(boolean precompile)
257   {
258     _precompile = precompile;
259   }
260
261   /**
262    * Return true if precompilation is allowed.
263    */

264   public boolean getPrecompile()
265   {
266     return _precompile;
267   }
268
269   /**
270    * Return true if auto-compilation is allowed.
271    */

272   public boolean isAutoCompile()
273   {
274     return _autoCompile;
275   }
276
277   /**
278    * Set if auto-compile is allowed.
279    */

280   public void setAutoCompile(boolean compile)
281   {
282     _autoCompile = compile;
283   }
284
285   /**
286    * Set if the *.jsp source is required.
287    */

288   public void setRequireSource(boolean requireSource)
289   {
290     _requireSource = requireSource;
291   }
292
293   /**
294    * Set if the *.jsp source is required.
295    */

296   public boolean getRequireSource()
297   {
298     return _requireSource;
299   }
300
301   /**
302    * Set if nulls are printed as space
303    */

304   public void setPrintNullAsBlank(boolean enable)
305   {
306     _isPrintNullAsBlank = enable;
307   }
308
309   /**
310    * Set if nulls are printed as space
311    */

312   public boolean isPrintNullAsBlank()
313   {
314     return _isPrintNullAsBlank;
315   }
316
317   /**
318    * Set true if EL exceptions should be ignored.
319    */

320   public boolean isIgnoreELException()
321   {
322     return _ignoreELException;
323   }
324
325   /**
326    * Set true if EL exceptions should be ignored.
327    */

328   public void setIgnoreELException(boolean ignore)
329   {
330     _ignoreELException = ignore;
331   }
332
333   /**
334    * Set if fast jstl is allowed.
335    */

336   public void setFastJstl(boolean fastJstl)
337   {
338     _fastJstl = fastJstl;
339   }
340
341   /**
342    * Return true if fast jstl is allowed.
343    */

344   public boolean isFastJstl()
345   {
346     return _fastJstl;
347   }
348
349   /**
350    * Set if velocity-style syntax is allowed.
351    */

352   public void setVelocityEnabled(boolean velocity)
353   {
354     _velocity = velocity;
355   }
356
357   /**
358    * Return true if velocity is allowed.
359    */

360   public boolean isVelocityEnabled()
361   {
362     return _velocity;
363   }
364
365   /**
366    * Set if sessions are enabled by default
367    */

368   public void setSession(boolean session)
369   {
370     _session = session;
371   }
372
373   /**
374    * Return true if sessions are enabled by default.
375    */

376   public boolean isSession()
377   {
378     return _session;
379   }
380
381   /**
382    * Set if static encoding is enabled.
383    */

384   public void setStaticEncoding(boolean staticEncoding)
385   {
386     _staticEncoding = staticEncoding;
387   }
388
389   /**
390    * Return true if static encoding is enabled
391    */

392   public boolean isStaticEncoding()
393   {
394     return _staticEncoding;
395   }
396
397   /**
398    * Set if recycle tags is enabled.
399    */

400   public void setRecycleTags(boolean recycleTags)
401   {
402     _recycleTags = recycleTags;
403   }
404
405   /**
406    * Return true if recycle tags is enabled
407    */

408   public boolean isRecycleTags()
409   {
410     return _recycleTags;
411   }
412
413   /**
414    * Sets true for the ide-hack
415    */

416   public void setIdeHack(boolean ideHack)
417   {
418     _ideHack = ideHack;
419   }
420
421   /**
422    * Gets the value of the ide-hack
423    */

424   public boolean getIdeHack()
425   {
426     return _ideHack;
427   }
428
429   /**
430    * Sets the jsp-max
431    */

432   public void setJspMax(int max)
433     throws ConfigException
434   {
435     if (max <= 0)
436       throw new ConfigException(L.l("`{0}' is too small a value for jsp-max",
437                     max));
438
439     _jspMax = max;
440   }
441
442   /**
443    * Gets the value of the jsp-max
444    */

445   public int getJspMax()
446   {
447     return _jspMax;
448   }
449
450   /**
451    * Returns true if JSP logging should be disabled.
452    */

453   public boolean isDisableLog()
454   {
455     return _disableLog;
456   }
457
458   /**
459    * Sets the deferred-syntax.
460    */

461   public void setDeferredSyntaxAllowedAsLiteral(boolean isAllowed)
462   {
463     _isDeferredSyntaxAllowedAsLiteral = isAllowed;
464   }
465
466   /**
467    * Sets the deferred-syntax.
468    */

469   public boolean isDeferredSyntaxAllowedAsLiteral()
470   {
471     return _isDeferredSyntaxAllowedAsLiteral;
472   }
473
474   /**
475    * Sets the recompile-on-errrkReturns true if JSP logging should be disabled.
476    */

477   public void setRecompileOnError(boolean recompile)
478   {
479     _recompileOnError = recompile;
480   }
481
482   /**
483    * Sets the recompile-on-errrkReturns true if JSP logging should be disabled.
484    */

485   public boolean isRecompileOnError()
486   {
487     return _recompileOnError;
488   }
489
490   /**
491    * Set true if the taglibs should have the schema validated
492    */

493   public void setValidateTaglibSchema(boolean isValidate)
494   {
495     _isValidateTaglibSchema = isValidate;
496   }
497
498   /**
499    * Set true if the taglibs should have the schema validated
500    */

501   public boolean isValidateTaglibSchema()
502   {
503     return _isValidateTaglibSchema;
504   }
505
506   /**
507    * Sets the tld fileset.
508    */

509   public void setTldFileSet(FileSetType fileSet)
510   {
511     _tldFileSet = fileSet;
512   }
513
514   /**
515    * Gets the tld fileset.
516    */

517   public FileSetType getTldFileSet()
518   {
519     return _tldFileSet;
520   }
521
522   /**
523    * Sets a restriction of the tld dir.
524    */

525   public void setTldDir(Path tldDir)
526   {
527     _tldFileSet = new FileSetType();
528     _tldFileSet.setDir(tldDir);
529   }
530
531   /**
532    * Set true if static pages should generate a class
533    */

534   public void setStaticPageGeneratesClass(boolean generate)
535   {
536     _staticPageGeneratesClass = generate;
537   }
538
539   /**
540    * Set true if static pages should generate a class
541    */

542   public boolean getStaticPageGeneratesClass()
543   {
544     return _staticPageGeneratesClass;
545   }
546
547   /**
548    * True if whitespace is trimmed.
549    */

550   public boolean isTrimDirectiveWhitespaces()
551   {
552     return _isTrimWhitespace;
553   }
554
555   /**
556    * Set if whitespace is trimmed.
557    */

558   public void setTrimDirectiveWhitespaces(boolean isTrim)
559   {
560     _isTrimWhitespace = isTrim;
561   }
562
563   @PostConstruct
564   public void init()
565     throws ServletException JavaDoc
566   {
567     if (_webApp != null) {
568       ServletMapping mapping = new ServletMapping();
569       mapping.setServletName("jsp-property-group-" + _gId++);
570       
571       if (Boolean.TRUE.equals(_isXml))
572     mapping.setServletClass(JspXmlServlet.class.getName());
573       else
574     mapping.setServletClass(JspServlet.class.getName());
575
576       for (int i = 0; i < _urlPatterns.size(); i++) {
577     mapping.addURLPattern(_urlPatterns.get(i));
578       }
579
580       _webApp.addServletMapping(mapping);
581     }
582   }
583
584   /**
585    * Returns true if the property group matches the URL.
586    */

587   public boolean match(String JavaDoc url)
588   {
589     if (_urlPatterns.size() == 0)
590       return true;
591
592     for (int i = 0; i < _urlPatterns.size(); i++) {
593       String JavaDoc urlPattern = _urlPatterns.get(i);
594       String JavaDoc regexpPattern = UrlMap.urlPatternToRegexpPattern(urlPattern);
595
596       if (Pattern.compile(regexpPattern).matcher(url).find()) {
597     return true;
598       }
599     }
600
601     return false;
602   }
603 }
604
Popular Tags