KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsp > java > JspDirectiveTaglib


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 Software Foundation, 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.java;
31
32 import com.caucho.jsp.JspParseException;
33 import com.caucho.util.L10N;
34 import com.caucho.vfs.WriteStream;
35 import com.caucho.xml.QName;
36
37 import java.io.IOException JavaDoc;
38
39 public class JspDirectiveTaglib extends JspNode {
40   final static L10N L = new L10N(JspDirectiveTaglib.class);
41
42   private static final QName PREFIX = new QName("prefix");
43   private static final QName URI = new QName("uri");
44   private static final QName TAGDIR = new QName("tagdir");
45
46   private String JavaDoc _prefix;
47   private String JavaDoc _uri;
48   private String JavaDoc _tagDir;
49   
50   /**
51    * Adds an attribute.
52    *
53    * @param name the attribute name
54    * @param value the attribute value
55    */

56   public void addAttribute(QName name, String JavaDoc value)
57     throws JspParseException
58   {
59     if (PREFIX.equals(name))
60       _prefix = value;
61     else if (URI.equals(name))
62       _uri = value;
63     else if (TAGDIR.equals(name))
64       _tagDir = value;
65     else {
66       throw error(L.l("`{0}' is an unknown JSP taglib directive attributes. See the JSP documentation for a complete list of page directive attributes.",
67                       name.getName()));
68     }
69   }
70
71   /**
72    * When the element complets.
73    */

74   public void endElement()
75     throws JspParseException
76   {
77     if (_prefix == null)
78       throw error(L.l("<{0}> needs a `prefix' attribute.",
79                       getTagName()));
80     
81     if (_uri == null && _tagDir == null)
82       throw error(L.l("<{0}> needs a `uri' or `tagdir' attribute.",
83                       getTagName()));
84     
85     if (_uri != null && _tagDir != null)
86       throw error(L.l("<{0}> can't have both a `uri' an a `tagdir' attribute.",
87                       getTagName()));
88
89     if (_uri != null) {
90       _gen.addTaglib(_prefix, _uri);
91       addNamespace(_prefix, _uri);
92     }
93     else {
94       _gen.addTaglibDir(_prefix, _tagDir);
95       addNamespace(_prefix, "urn:jsptld:" + _tagDir);
96     }
97   }
98   
99   /**
100    * Return true if the node only has static text.
101    */

102   public boolean isStatic()
103   {
104     return true;
105   }
106
107   /**
108    * Generates the XML text representation for the tag validation.
109    *
110    * @param os write stream to the generated XML.
111    */

112   public void printXml(WriteStream os)
113     throws IOException JavaDoc
114   {
115     /*
116     os.print("<jsp:directive.taglib prefix=\"" + _prefix + "\"");
117     
118     if (_uri != null)
119       os.print(" uri=\"" + _uri + "\"/>");
120     else
121       os.print(" tagdir=\"" + _tagDir + "\"/>");
122     */

123   }
124
125   /**
126    * Generates the code for the tag
127    *
128    * @param out the output writer for the generated java.
129    */

130   public void generate(JspJavaWriter out)
131     throws Exception JavaDoc
132   {
133   }
134 }
135
Popular Tags