1 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 ; 42 43 import java.io.IOException ; 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 _file; 51 52 58 public void addAttribute(QName name, String 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 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 e) { 101 throw error(e); 102 } catch (IOException e) { 103 throw error(e); 104 } 105 } 106 107 private Path resolvePath(String 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 128 } 129 130 135 public void printXml(WriteStream os) 136 throws IOException 137 { 138 } 141 142 147 public void generate(JspJavaWriter out) 148 throws Exception 149 { 150 } 151 } 152 | Popular Tags |