001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jsp.cfg;
031:
032: import com.caucho.config.DependencyBean;
033: import com.caucho.server.webapp.Application;
034: import com.caucho.vfs.Path;
035: import com.caucho.vfs.PersistentDependency;
036:
037: import java.util.ArrayList;
038:
039: /**
040: * Configuration for the taglib in the .tld
041: */
042: public class TldTaglib implements DependencyBean {
043: private String _tlibVersion;
044: private String _jspVersion;
045: private String _shortName;
046: private String _uri;
047: private String _displayName;
048: private String _smallIcon;
049: private String _largeIcon;
050: private String _description;
051: private String _info;
052: private TldValidator _validator;
053: private ArrayList<TldListener> _listeners = new ArrayList<TldListener>();
054: private ArrayList<TldTag> _tags = new ArrayList<TldTag>();
055: private ArrayList<TldTagFile> _tagFiles = new ArrayList<TldTagFile>();
056: private ArrayList<TldFunction> _functionList = new ArrayList<TldFunction>();
057:
058: private Path _jarPath;
059: private Throwable _configException;
060:
061: private ArrayList<PersistentDependency> _dependList = new ArrayList<PersistentDependency>();
062:
063: private boolean _isInit;
064:
065: public TldTaglib() {
066: }
067:
068: /**
069: * Adds a dependency.
070: */
071: public void addDependency(PersistentDependency depend) {
072: _dependList.add(depend);
073: }
074:
075: /**
076: * Sets the tld version.
077: */
078: public void setVersion(String version) {
079: _jspVersion = version;
080: }
081:
082: /**
083: * Sets the schema location.
084: */
085: public void setSchemaLocation(String location) {
086: }
087:
088: /**
089: * Sets the icon.
090: */
091: public void setIcon(com.caucho.config.types.Icon icon) {
092: }
093:
094: /**
095: * Sets the taglib version.
096: */
097: public void setTlibVersion(String tlibVersion) {
098: _tlibVersion = tlibVersion;
099: }
100:
101: /**
102: * Sets the taglib version (backwards compat).
103: */
104: public void setTlibversion(String tlibVersion) {
105: setTlibVersion(tlibVersion);
106: }
107:
108: /**
109: * Gets the taglib version.
110: */
111: public String getTlibVersion() {
112: return _tlibVersion;
113: }
114:
115: /**
116: * Sets the JSP version.
117: */
118: public void setJspVersion(String jspVersion) {
119: _jspVersion = jspVersion;
120: }
121:
122: /**
123: * Sets the JSP version (backwards compat).
124: */
125: public void setJspversion(String jspVersion) {
126: setJspVersion(jspVersion);
127: }
128:
129: /**
130: * Gets the jsp version.
131: */
132: public String getJspVersion() {
133: return _jspVersion;
134: }
135:
136: /**
137: * Sets the info string
138: */
139: public void setInfo(String info) {
140: _info = info;
141: }
142:
143: /**
144: * Gets the info string.
145: */
146: public String getInfo() {
147: return _info;
148: }
149:
150: /**
151: * Sets the short name (prefix)
152: */
153: public void setShortName(String shortName) {
154: _shortName = shortName;
155: }
156:
157: /**
158: * Sets the short name (backwards compat)
159: */
160: public void setShortname(String shortName) {
161: setShortName(shortName);
162: }
163:
164: /**
165: * Gets the short name (prefix)
166: */
167: public String getShortName() {
168: return _shortName;
169: }
170:
171: /**
172: * Sets the uri
173: */
174: public void setURI(String uri) {
175: _uri = uri;
176: }
177:
178: /**
179: * Gets the uri
180: */
181: public String getURI() {
182: return _uri;
183: }
184:
185: /**
186: * Sets the display-name
187: */
188: public void setDisplayName(String displayName) {
189: _displayName = displayName;
190: }
191:
192: /**
193: * Gets the display-name
194: */
195: public String getDisplayName() {
196: return _displayName;
197: }
198:
199: /**
200: * Sets the small-icon
201: */
202: public void setSmallIcon(String smallIcon) {
203: _smallIcon = smallIcon;
204: }
205:
206: /**
207: * Gets the small-icon
208: */
209: public String getSmallIcon() {
210: return _smallIcon;
211: }
212:
213: /**
214: * Sets the large-icon
215: */
216: public void setLargeIcon(String largeIcon) {
217: _largeIcon = largeIcon;
218: }
219:
220: /**
221: * Gets the large-icon
222: */
223: public String getLargeIcon() {
224: return _largeIcon;
225: }
226:
227: /**
228: * Sets the description
229: */
230: public void setDescription(String description) {
231: _description = description;
232: }
233:
234: /**
235: * Gets the description
236: */
237: public String getDescription() {
238: return _description;
239: }
240:
241: /**
242: * Sets the validator
243: */
244: public void setValidator(TldValidator validator) {
245: _validator = validator;
246: }
247:
248: /**
249: * Gets the validator
250: */
251: public TldValidator getValidator() {
252: return _validator;
253: }
254:
255: /**
256: * Adds a listener
257: */
258: public void addListener(TldListener listener) {
259: _listeners.add(listener);
260: }
261:
262: /**
263: * Adds a tag
264: */
265: public void addTag(TldTag tag) {
266: _tags.add(tag);
267: }
268:
269: /**
270: * Returns the list of tags.
271: */
272: public ArrayList<TldTag> getTagList() {
273: return _tags;
274: }
275:
276: /**
277: * Adds a tag-file
278: */
279: public void addTagFile(TldTagFile tagFile) {
280: _tagFiles.add(tagFile);
281: }
282:
283: /**
284: * Returns the list of tag files.
285: */
286: public ArrayList<TldTagFile> getTagFileList() {
287: return _tagFiles;
288: }
289:
290: /**
291: * Adds a jsf tag.
292: */
293: public void addJsfTag(JsfTag tag) {
294: _tags.add(tag);
295: }
296:
297: /**
298: * Adds a function
299: */
300: public void addFunction(TldFunction function) {
301: _functionList.add(function);
302: }
303:
304: /**
305: * Returns the list of functions.
306: */
307: public ArrayList<TldFunction> getFunctionList() {
308: return _functionList;
309: }
310:
311: /**
312: * Sets the jar path.
313: */
314: public void setJarPath(Path path) {
315: _jarPath = path;
316: }
317:
318: /**
319: * Gets the jar path.
320: */
321: public Path getJarPath() {
322: return _jarPath;
323: }
324:
325: /**
326: * Sets any configuration exception
327: */
328: public void setConfigException(Throwable e) {
329: _configException = e;
330: }
331:
332: /**
333: * Gets any configuration exception
334: */
335: public Throwable getConfigException() {
336: return _configException;
337: }
338:
339: /**
340: * Applies the listeners.
341: */
342: public void initListeners(Application app)
343: throws InstantiationException, IllegalAccessException {
344: if (app == null)
345: return;
346:
347: for (int i = 0; i < _listeners.size(); i++) {
348: TldListener listener = _listeners.get(i);
349:
350: listener.register(app);
351: }
352: }
353:
354: public void mergeJsf(TldTaglib jsfTaglib) {
355: ArrayList<TldTag> jsfTags = jsfTaglib.getTagList();
356:
357: for (int i = 0; i < jsfTags.size(); i++) {
358: JsfTag jsfTag = (JsfTag) jsfTags.get(i);
359:
360: if (jsfTag.getBaseTag() != null)
361: continue;
362:
363: int p = _tags.indexOf(jsfTag);
364:
365: if (p >= 0) {
366: TldTag tag = _tags.remove(p);
367:
368: jsfTag.setBaseTag(tag);
369: } else
370: throw new IllegalStateException(
371: "No matching tag for : " + jsfTag);
372:
373: _tags.add(jsfTag);
374: }
375: }
376:
377: /**
378: * Checks for modification.
379: */
380: public boolean isModified() {
381: for (int i = 0; i < _dependList.size(); i++) {
382: if (_dependList.get(i).isModified())
383: return true;
384: }
385:
386: return false;
387: }
388: }
|