1 28 29 package com.caucho.xsl.java; 30 31 import com.caucho.java.JavaWriter; 32 import com.caucho.xml.QName; 33 import com.caucho.xsl.XslParseException; 34 35 import java.util.ArrayList ; 36 import java.util.regex.Pattern ; 37 38 41 public class XslStylesheet extends XslNode { 42 private String _version; 43 private String _id; 44 private String _extensionElementPrefixes; 45 private String _excludeResultPrefixes; 46 private String _xpathDefaultNamespace; 47 private String _defaultValidation; 48 49 private boolean _isStyleScript; 50 private boolean _isDisableOutputEscaping; 51 52 private ArrayList <XslNode> _init = new ArrayList <XslNode>(); 53 54 private ArrayList <XslNode> _imports = new ArrayList <XslNode>(); 55 56 59 public String getTagName() 60 { 61 return "xsl:stylesheet"; 62 } 63 64 67 public void setDisableOutputEscaping(boolean disable) 68 { 69 _isDisableOutputEscaping = disable; 70 } 71 72 75 public void addImport(XslNode node) 76 { 77 _imports.add(node); 78 } 79 80 83 public void addAttribute(QName name, String value) 84 throws XslParseException 85 { 86 if (name.getName().equals("version")) 87 _version = value; 88 else if (name.getName().equals("extension-element-prefixes")) 89 _extensionElementPrefixes = value; 90 else if (name.getName().equals("exclude-result-prefixes")) 91 _excludeResultPrefixes = value; 92 else if (name.getName().equals("xpath-default-namespace")) 93 _xpathDefaultNamespace = value; 94 else if (name.getName().equals("default-validation")) 95 _defaultValidation = value; 96 else if (name.getName().equals("resin:stylescript")) 97 _gen.setStyleScript(true); 98 else 99 super.addAttribute(name, value); 100 } 101 102 105 public void endAttributes() 106 throws XslParseException 107 { 108 if (_excludeResultPrefixes != null) 109 addExcludeResultPrefixes(_excludeResultPrefixes); 110 117 } 118 119 122 public void addChild(XslNode node) 123 throws XslParseException 124 { 125 if (node instanceof XslVariable) { 126 ((XslVariable) node).setGlobal(true); 127 _gen.addInit(node); 128 } 129 else if (node instanceof XslParam) { 130 ((XslParam) node).setGlobal(true); 131 _gen.addInit(node); 132 } 133 else if (node instanceof TextNode) { 134 TextNode text = (TextNode) node; 135 136 if (! text.isWhitespace()) 137 throw error(L.l("text not allowed in the top level.")); 138 } 139 else if (node instanceof XslElementNode) { 140 } 141 else if (! (node instanceof XslTopNode)) { 142 throw error(L.l("<{0}> is not allowed in the top level.", 143 node.getTagName())); 144 } 145 else 146 super.addChild(node); 147 } 148 149 154 public void generate(JavaWriter out) 155 throws Exception 156 { 157 for (int i = 0; i < _imports.size(); i++) { 158 int oldMinImportance = _gen.getMinImportance(); 159 _gen.setMinImportance(_gen.getImportance()); 160 _imports.get(i).generate(out); 161 _gen.setMinImportance(oldMinImportance); 162 _gen.incrementImportance(); 163 } 164 165 generateChildren(out); 166 } 167 168 173 public void generateDeclaration(JavaWriter out) 174 throws Exception 175 { 176 for (int i = 0; i < _imports.size(); i++) 177 _imports.get(i).generateDeclaration(out); 178 179 super.generateDeclaration(out); 180 } 181 182 private void addExcludeResultPrefixes(String prefixes) 183 throws XslParseException 184 { 185 if (prefixes == null) 186 return; 187 188 Pattern regexp = Pattern.compile("[,\\s]+"); 189 String []strings = regexp.split(prefixes); 190 for (int i = 0; i < strings.length; i++) { 191 String prefix = strings[i]; 192 String ns = getNamespace(prefix); 193 if (ns == null) 194 throw error(L.l("`{0}' must be a namespace prefix", prefix)); 195 _gen.addExcludedNamespace(ns); 196 } 197 } 198 199 protected void printPopScope(JavaWriter out) 200 throws Exception 201 { 202 } 203 } 204 | Popular Tags |