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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsp.java;
030:
031: import com.caucho.jsp.JspContentHandler;
032: import com.caucho.jsp.JspParseException;
033: import com.caucho.jsp.Namespace;
034: import com.caucho.jsp.ParseState;
035: import com.caucho.util.L10N;
036: import com.caucho.vfs.Path;
037: import com.caucho.vfs.WriteStream;
038: import com.caucho.xml.QName;
039: import com.caucho.xml.Xml;
040:
041: import org.xml.sax.SAXException;
042:
043: import java.io.IOException;
044:
045: public class JspDirectiveInclude extends JspNode {
046: static L10N L = new L10N(JspDirectiveInclude.class);
047:
048: static private final QName FILE = new QName("file");
049:
050: private String _file;
051:
052: /**
053: * Adds an attribute.
054: *
055: * @param name the attribute name
056: * @param value the attribute value
057: */
058: public void addAttribute(QName name, String value)
059: throws JspParseException {
060: if (FILE.equals(name))
061: _file = value;
062: else {
063: throw error(L
064: .l(
065: "'{0}' is an unknown JSP include directive attributes. Compile-time includes need a 'file' attribute.",
066: name.getName()));
067: }
068: }
069:
070: /**
071: * When the element completes.
072: */
073: public void endElement() throws JspParseException {
074: if (_file == null)
075: throw error(L.l("<{0}> needs a 'file' attribute.",
076: getTagName()));
077:
078: try {
079: ParseState parseState = _gen.getParseState();
080:
081: if (parseState.isXml()) {
082: Xml xml = new Xml();
083: xml.setContentHandler(new JspContentHandler(parseState
084: .getBuilder()));
085: Path path = resolvePath(_file, parseState);
086:
087: path.setUserPath(_file);
088: xml.setNamespaceAware(true);
089:
090: for (Namespace ns = parseState.getNamespaces(); ns != null; ns = ns
091: .getNext()) {
092: xml.pushNamespace(ns.getPrefix(), ns.getURI());
093: }
094:
095: xml.parse(path);
096: } else
097: _gen.getJspParser().pushInclude(_file);
098: } catch (SAXException e) {
099: throw error(e);
100: } catch (IOException e) {
101: throw error(e);
102: }
103: }
104:
105: private Path resolvePath(String value, ParseState parseState) {
106: Path include;
107: if (value.length() > 0 && value.charAt(0) == '/')
108: include = parseState.resolvePath(value);
109: else
110: include = parseState.resolvePath(parseState.getUriPwd()
111: + value);
112:
113: return include;
114: /*
115: String newUrl = _uriPwd;
116:
117: if (value.startsWith("/"))
118: newUrl = value;
119: else
120: newUrl = _uriPwd + value;
121:
122: include.set
123:
124: return newUrl;
125: */
126: }
127:
128: /**
129: * Generates the XML text representation for the tag validation.
130: *
131: * @param os write stream to the generated XML.
132: */
133: public void printXml(WriteStream os) throws IOException {
134: // jsp/0354
135: // os.print("<jsp:directive.include file=\"" + _file + "\"/>");
136: }
137:
138: /**
139: * Generates the code for the tag
140: *
141: * @param out the output writer for the generated java.
142: */
143: public void generate(JspJavaWriter out) throws Exception {
144: }
145: }
|