1 16 19 package org.apache.xalan.templates; 20 21 import javax.xml.transform.TransformerException ; 22 23 import org.apache.xalan.extensions.ExtensionNamespaceSupport; 24 import org.apache.xalan.extensions.ExtensionNamespacesManager; 25 import org.apache.xalan.res.XSLMessages; 26 import org.apache.xalan.res.XSLTErrorResources; 27 import org.apache.xalan.transformer.TransformerImpl; 28 import org.apache.xml.utils.StringVector; 29 30 34 public class ElemExtensionDecl extends ElemTemplateElement 35 { 36 37 41 public ElemExtensionDecl() 42 { 43 44 } 46 47 49 private String m_prefix = null; 50 51 57 public void setPrefix(String v) 58 { 59 m_prefix = v; 60 } 61 62 68 public String getPrefix() 69 { 70 return m_prefix; 71 } 72 73 75 private StringVector m_functions = new StringVector(); 76 77 83 public void setFunctions(StringVector v) 84 { 85 m_functions = v; 86 } 87 88 94 public StringVector getFunctions() 95 { 96 return m_functions; 97 } 98 99 109 public String getFunction(int i) throws ArrayIndexOutOfBoundsException 110 { 111 112 if (null == m_functions) 113 throw new ArrayIndexOutOfBoundsException (); 114 115 return (String ) m_functions.elementAt(i); 116 } 117 118 124 public int getFunctionCount() 125 { 126 return (null != m_functions) ? m_functions.size() : 0; 127 } 128 129 131 private StringVector m_elements = null; 132 133 139 public void setElements(StringVector v) 140 { 141 m_elements = v; 142 } 143 144 150 public StringVector getElements() 151 { 152 return m_elements; 153 } 154 155 165 public String getElement(int i) throws ArrayIndexOutOfBoundsException 166 { 167 168 if (null == m_elements) 169 throw new ArrayIndexOutOfBoundsException (); 170 171 return (String ) m_elements.elementAt(i); 172 } 173 174 180 public int getElementCount() 181 { 182 return (null != m_elements) ? m_elements.size() : 0; 183 } 184 185 191 public int getXSLToken() 192 { 193 return Constants.ELEMNAME_EXTENSIONDECL; 194 } 195 196 public void compose(StylesheetRoot sroot) throws TransformerException 197 { 198 super.compose(sroot); 199 String prefix = getPrefix(); 200 String declNamespace = getNamespaceForPrefix(prefix); 201 String lang = null; 202 String srcURL = null; 203 String scriptSrc = null; 204 if (null == declNamespace) 205 throw new TransformerException (XSLMessages.createMessage(XSLTErrorResources.ER_NO_NAMESPACE_DECL, new Object []{prefix})); 206 for (ElemTemplateElement child = getFirstChildElem(); child != null; 208 child = child.getNextSiblingElem()) 209 { 210 if (Constants.ELEMNAME_EXTENSIONSCRIPT == child.getXSLToken()) 211 { 212 ElemExtensionScript sdecl = (ElemExtensionScript) child; 213 lang = sdecl.getLang(); 214 srcURL = sdecl.getSrc(); 215 ElemTemplateElement childOfSDecl = sdecl.getFirstChildElem(); 216 if (null != childOfSDecl) 217 { 218 if (Constants.ELEMNAME_TEXTLITERALRESULT 219 == childOfSDecl.getXSLToken()) 220 { 221 ElemTextLiteral tl = (ElemTextLiteral) childOfSDecl; 222 char[] chars = tl.getChars(); 223 scriptSrc = new String (chars); 224 if (scriptSrc.trim().length() == 0) 225 scriptSrc = null; 226 } 227 } 228 } 229 } 230 if (null == lang) 231 lang = "javaclass"; 232 if (lang.equals("javaclass") && (scriptSrc != null)) 233 throw new TransformerException (XSLMessages.createMessage(XSLTErrorResources.ER_ELEM_CONTENT_NOT_ALLOWED, new Object []{scriptSrc})); 234 236 ExtensionNamespaceSupport extNsSpt = null; 238 ExtensionNamespacesManager extNsMgr = sroot.getExtensionNamespacesManager(); 239 if (extNsMgr.namespaceIndex(declNamespace, 240 extNsMgr.getExtensions()) == -1) 241 { 242 if (lang.equals("javaclass")) 243 { 244 if (null == srcURL) 245 { 246 extNsSpt = extNsMgr.defineJavaNamespace(declNamespace); 247 } 248 else if (extNsMgr.namespaceIndex(srcURL, 249 extNsMgr.getExtensions()) == -1) 250 { 251 extNsSpt = extNsMgr.defineJavaNamespace(declNamespace, srcURL); 252 } 253 } 254 else { 256 String handler = "org.apache.xalan.extensions.ExtensionHandlerGeneral"; 257 Object [] args = {declNamespace, this.m_elements, this.m_functions, 258 lang, srcURL, scriptSrc, getSystemId()}; 259 extNsSpt = new ExtensionNamespaceSupport(declNamespace, handler, args); 260 } 261 } 262 if (extNsSpt != null) 263 extNsMgr.registerExtension(extNsSpt); 264 } 265 266 267 275 public void runtimeInit(TransformerImpl transformer) throws TransformerException 276 { 277 365 } 366 } 367 | Popular Tags |