KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > webapp > CacheMapping


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  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.server.webapp;
30
31 import com.caucho.config.types.Period;
32 import com.caucho.util.L10N;
33
34 import javax.annotation.PostConstruct;
35 import javax.servlet.ServletException JavaDoc;
36
37 /**
38  * Configuration for a cache-mapping.
39  */

40 public class CacheMapping {
41   static L10N L = new L10N(CacheMapping.class);
42
43   // The path-mapping pattern
44
private String JavaDoc _urlPattern;
45   private String JavaDoc _urlRegexp;
46   
47   // The period
48
private long _maxAge = Long.MIN_VALUE;
49   private long _sMaxAge = Long.MIN_VALUE;
50
51   /**
52    * Creates the path mapping.
53    */

54   public CacheMapping()
55   {
56   }
57
58   /**
59    * Sets the urlPattern
60    */

61   public void setUrlPattern(String JavaDoc urlPattern)
62   {
63     _urlPattern = urlPattern;
64   }
65
66   /**
67    * Gets the urlPattern.
68    */

69   public String JavaDoc getUrlPattern()
70   {
71     return _urlPattern;
72   }
73
74   /**
75    * Sets the urlRegexp
76    */

77   public void setUrlRegexp(String JavaDoc urlRegexp)
78   {
79     _urlRegexp = urlRegexp;
80   }
81
82   /**
83    * Sets the urlRegexp
84    */

85   public String JavaDoc getUrlRegexp()
86   {
87     return _urlRegexp;
88   }
89
90   /**
91    * Sets the period
92    */

93   public void setExpires(Period period)
94   {
95     setMaxAge(period);
96   }
97
98   /**
99    * Sets the period
100    */

101   public void setMaxAge(Period period)
102   {
103     _maxAge = period.getPeriod();
104   }
105
106   /**
107    * Gets the expires period.
108    */

109   public long getMaxAge()
110   {
111     return _maxAge;
112   }
113
114   /**
115    * Sets the period
116    */

117   public void setSMaxAge(Period period)
118   {
119     _sMaxAge = period.getPeriod();
120   }
121
122   /**
123    * Gets the expires period.
124    */

125   public long getSMaxAge()
126   {
127     return _sMaxAge;
128   }
129
130   /**
131    * Init
132    */

133   @PostConstruct
134   public void init()
135     throws ServletException JavaDoc
136   {
137     if (_urlPattern == null && _urlRegexp == null)
138       throw new ServletException JavaDoc(L.l("cache-mapping needs 'url-pattern' attribute."));
139     if (_maxAge == Long.MIN_VALUE && _sMaxAge == Long.MIN_VALUE)
140       throw new ServletException JavaDoc(L.l("cache-mapping needs 'max-age' attribute."));
141   }
142 }
143
Popular Tags