KickJava   Java API By Example, From Geeks To Geeks.

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


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.jsp.java;
30
31 import com.caucho.jsp.JspContentHandler;
32 import com.caucho.jsp.JspParseException;
33 import com.caucho.jsp.Namespace;
34 import com.caucho.jsp.ParseState;
35 import com.caucho.util.L10N;
36 import com.caucho.vfs.Path;
37 import com.caucho.vfs.WriteStream;
38 import com.caucho.xml.QName;
39 import com.caucho.xml.Xml;
40
41 import org.xml.sax.SAXException JavaDoc;
42
43 import java.io.IOException JavaDoc;
44
45 public class JspDirectiveInclude extends JspNode {
46   static L10N L = new L10N(JspDirectiveInclude.class);
47
48   static private final QName FILE = new QName("file");
49
50   private String JavaDoc _file;
51   
52   /**
53    * Adds an attribute.
54    *
55    * @param name the attribute name
56    * @param value the attribute value
57    */

58   public void addAttribute(QName name, String JavaDoc value)
59     throws JspParseException
60   {
61     if (FILE.equals(name))
62       _file = value;
63     else {
64       throw error(L.l("'{0}' is an unknown JSP include directive attributes. Compile-time includes need a 'file' attribute.",
65                       name.getName()));
66     }
67   }
68
69   /**
70    * When the element completes.
71    */

72   public void endElement()
73     throws JspParseException
74   {
75     if (_file == null)
76       throw error(L.l("<{0}> needs a 'file' attribute.",
77                       getTagName()));
78
79     try {
80       ParseState parseState = _gen.getParseState();
81       
82       if (parseState.isXml()) {
83     Xml xml = new Xml();
84     xml.setContentHandler(new JspContentHandler(parseState.getBuilder()));
85     Path path = resolvePath(_file, parseState);
86     
87     path.setUserPath(_file);
88     xml.setNamespaceAware(true);
89
90     for (Namespace ns = parseState.getNamespaces();
91          ns != null;
92          ns = ns.getNext()) {
93       xml.pushNamespace(ns.getPrefix(), ns.getURI());
94     }
95     
96     xml.parse(path);
97       }
98       else
99     _gen.getJspParser().pushInclude(_file);
100     } catch (SAXException JavaDoc e) {
101       throw error(e);
102     } catch (IOException JavaDoc e) {
103       throw error(e);
104     }
105   }
106
107   private Path resolvePath(String JavaDoc value, ParseState parseState)
108   {
109     Path include;
110     if (value.length() > 0 && value.charAt(0) == '/')
111       include = parseState.resolvePath(value);
112     else
113       include = parseState.resolvePath(parseState.getUriPwd() + value);
114
115     return include;
116     /*
117     String newUrl = _uriPwd;
118
119     if (value.startsWith("/"))
120       newUrl = value;
121     else
122       newUrl = _uriPwd + value;
123
124     include.set
125
126     return newUrl;
127     */

128   }
129
130   /**
131    * Generates the XML text representation for the tag validation.
132    *
133    * @param os write stream to the generated XML.
134    */

135   public void printXml(WriteStream os)
136     throws IOException JavaDoc
137   {
138     // jsp/0354
139
// os.print("<jsp:directive.include file=\"" + _file + "\"/>");
140
}
141
142   /**
143    * Generates the code for the tag
144    *
145    * @param out the output writer for the generated java.
146    */

147   public void generate(JspJavaWriter out)
148     throws Exception JavaDoc
149   {
150   }
151 }
152
Popular Tags