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.java;
031:
032: import com.caucho.jsp.JspParseException;
033: import com.caucho.util.L10N;
034: import com.caucho.vfs.WriteStream;
035: import com.caucho.xml.QName;
036:
037: import java.io.IOException;
038:
039: public class JspDirectiveTaglib extends JspNode {
040: final static L10N L = new L10N(JspDirectiveTaglib.class);
041:
042: private static final QName PREFIX = new QName("prefix");
043: private static final QName URI = new QName("uri");
044: private static final QName TAGDIR = new QName("tagdir");
045:
046: private String _prefix;
047: private String _uri;
048: private String _tagDir;
049:
050: /**
051: * Adds an attribute.
052: *
053: * @param name the attribute name
054: * @param value the attribute value
055: */
056: public void addAttribute(QName name, String value)
057: throws JspParseException {
058: if (PREFIX.equals(name))
059: _prefix = value;
060: else if (URI.equals(name))
061: _uri = value;
062: else if (TAGDIR.equals(name))
063: _tagDir = value;
064: else {
065: throw error(L
066: .l(
067: "`{0}' is an unknown JSP taglib directive attributes. See the JSP documentation for a complete list of page directive attributes.",
068: name.getName()));
069: }
070: }
071:
072: /**
073: * When the element complets.
074: */
075: public void endElement() throws JspParseException {
076: if (_prefix == null)
077: throw error(L.l("<{0}> needs a `prefix' attribute.",
078: getTagName()));
079:
080: if (_uri == null && _tagDir == null)
081: throw error(L.l(
082: "<{0}> needs a `uri' or `tagdir' attribute.",
083: getTagName()));
084:
085: if (_uri != null && _tagDir != null)
086: throw error(L
087: .l(
088: "<{0}> can't have both a `uri' an a `tagdir' attribute.",
089: getTagName()));
090:
091: if (_uri != null) {
092: _gen.addTaglib(_prefix, _uri);
093: addNamespace(_prefix, _uri);
094: } else {
095: _gen.addTaglibDir(_prefix, _tagDir);
096: addNamespace(_prefix, "urn:jsptld:" + _tagDir);
097: }
098: }
099:
100: /**
101: * Return true if the node only has static text.
102: */
103: public boolean isStatic() {
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) throws IOException {
113: /*
114: os.print("<jsp:directive.taglib prefix=\"" + _prefix + "\"");
115:
116: if (_uri != null)
117: os.print(" uri=\"" + _uri + "\"/>");
118: else
119: os.print(" tagdir=\"" + _tagDir + "\"/>");
120: */
121: }
122:
123: /**
124: * Generates the code for the tag
125: *
126: * @param out the output writer for the generated java.
127: */
128: public void generate(JspJavaWriter out) throws Exception {
129: }
130: }
|