1 16 19 package org.apache.xalan.extensions; 20 21 import java.util.Hashtable ; 22 import java.util.Vector ; 23 24 import org.apache.xalan.res.XSLMessages; 25 import org.apache.xalan.res.XSLTErrorResources; 26 import org.apache.xalan.templates.StylesheetRoot; 27 import org.apache.xpath.XPathProcessorException; 28 import org.apache.xpath.functions.FuncExtFunction; 29 30 34 public class ExtensionsTable 35 { 36 42 public Hashtable m_extensionFunctionNamespaces = new Hashtable (); 43 44 47 private StylesheetRoot m_sroot; 48 49 55 public ExtensionsTable(StylesheetRoot sroot) 56 throws javax.xml.transform.TransformerException 57 { 58 m_sroot = sroot; 59 Vector extensions = m_sroot.getExtensions(); 60 for (int i = 0; i < extensions.size(); i++) 61 { 62 ExtensionNamespaceSupport extNamespaceSpt = 63 (ExtensionNamespaceSupport)extensions.elementAt(i); 64 ExtensionHandler extHandler = extNamespaceSpt.launch(); 65 if (extHandler != null) 66 addExtensionNamespace(extNamespaceSpt.getNamespace(), extHandler); 67 } 68 } 69 70 78 public ExtensionHandler get(String extns) 79 { 80 return (ExtensionHandler) m_extensionFunctionNamespaces.get(extns); 81 } 82 83 92 public void addExtensionNamespace(String uri, ExtensionHandler extNS) 93 { 94 m_extensionFunctionNamespaces.put(uri, extNS); 95 } 96 97 106 public boolean functionAvailable(String ns, String funcName) 107 throws javax.xml.transform.TransformerException 108 { 109 boolean isAvailable = false; 110 111 if (null != ns) 112 { 113 ExtensionHandler extNS = 114 (ExtensionHandler) m_extensionFunctionNamespaces.get(ns); 115 if (extNS != null) 116 isAvailable = extNS.isFunctionAvailable(funcName); 117 } 118 return isAvailable; 119 } 120 121 130 public boolean elementAvailable(String ns, String elemName) 131 throws javax.xml.transform.TransformerException 132 { 133 boolean isAvailable = false; 134 if (null != ns) 135 { 136 ExtensionHandler extNS = 137 (ExtensionHandler) m_extensionFunctionNamespaces.get(ns); 138 if (extNS != null) isAvailable = extNS.isElementAvailable(elemName); 140 } 141 return isAvailable; 142 } 143 144 159 public Object extFunction(String ns, String funcName, 160 Vector argVec, Object methodKey, 161 ExpressionContext exprContext) 162 throws javax.xml.transform.TransformerException 163 { 164 Object result = null; 165 if (null != ns) 166 { 167 ExtensionHandler extNS = 168 (ExtensionHandler) m_extensionFunctionNamespaces.get(ns); 169 if (null != extNS) 170 { 171 try 172 { 173 result = extNS.callFunction(funcName, argVec, methodKey, 174 exprContext); 175 } 176 catch (javax.xml.transform.TransformerException e) 177 { 178 throw e; 179 } 180 catch (Exception e) 181 { 182 throw new javax.xml.transform.TransformerException (e); 183 } 184 } 185 else 186 { 187 throw new XPathProcessorException(XSLMessages.createMessage(XSLTErrorResources.ER_EXTENSION_FUNC_UNKNOWN, new Object []{ns, funcName })); 188 } 190 } 191 return result; 192 } 193 194 206 public Object extFunction(FuncExtFunction extFunction, Vector argVec, 207 ExpressionContext exprContext) 208 throws javax.xml.transform.TransformerException 209 { 210 Object result = null; 211 String ns = extFunction.getNamespace(); 212 if (null != ns) 213 { 214 ExtensionHandler extNS = 215 (ExtensionHandler) m_extensionFunctionNamespaces.get(ns); 216 if (null != extNS) 217 { 218 try 219 { 220 result = extNS.callFunction(extFunction, argVec, exprContext); 221 } 222 catch (javax.xml.transform.TransformerException e) 223 { 224 throw e; 225 } 226 catch (Exception e) 227 { 228 throw new javax.xml.transform.TransformerException (e); 229 } 230 } 231 else 232 { 233 throw new XPathProcessorException(XSLMessages.createMessage(XSLTErrorResources.ER_EXTENSION_FUNC_UNKNOWN, 234 new Object []{ns, extFunction.getFunctionName()})); 235 } 236 } 237 return result; 238 } 239 } 240 | Popular Tags |