1 16 19 package org.apache.xalan.extensions; 20 21 import java.util.Vector ; 22 23 import org.apache.xalan.templates.Constants; 24 25 31 public class ExtensionNamespacesManager 32 { 33 36 private Vector m_extensions = new Vector (); 37 41 private Vector m_predefExtensions = new Vector (7); 42 46 private Vector m_unregisteredExtensions = new Vector (); 47 48 53 public ExtensionNamespacesManager() 54 { 55 setPredefinedNamespaces(); 56 } 57 58 68 public void registerExtension(String namespace) 69 { 70 if (namespaceIndex(namespace, m_extensions) == -1) 71 { 72 int predef = namespaceIndex(namespace, m_predefExtensions); 73 if (predef !=-1) 74 m_extensions.addElement(m_predefExtensions.elementAt(predef)); 75 else if (!(m_unregisteredExtensions.contains(namespace))) 76 m_unregisteredExtensions.addElement(namespace); 77 } 78 } 79 80 85 public void registerExtension(ExtensionNamespaceSupport extNsSpt) 86 { 87 String namespace = extNsSpt.getNamespace(); 88 if (namespaceIndex(namespace, m_extensions) == -1) 89 { 90 m_extensions.addElement(extNsSpt); 91 if (m_unregisteredExtensions.contains(namespace)) 92 m_unregisteredExtensions.removeElement(namespace); 93 } 94 95 } 96 97 101 public int namespaceIndex(String namespace, Vector extensions) 102 { 103 for (int i = 0; i < extensions.size(); i++) 104 { 105 if (((ExtensionNamespaceSupport)extensions.elementAt(i)).getNamespace().equals(namespace)) 106 return i; 107 } 108 return -1; 109 } 110 111 112 117 public Vector getExtensions() 118 { 119 return m_extensions; 120 } 121 122 125 public void registerUnregisteredNamespaces() 126 { 127 for (int i = 0; i < m_unregisteredExtensions.size(); i++) 128 { 129 String ns = (String )m_unregisteredExtensions.elementAt(i); 130 ExtensionNamespaceSupport extNsSpt = defineJavaNamespace(ns); 131 if (extNsSpt != null) 132 m_extensions.addElement(extNsSpt); 133 } 134 } 135 136 153 public ExtensionNamespaceSupport defineJavaNamespace(String ns) 154 { 155 return defineJavaNamespace(ns, ns); 156 } 157 public ExtensionNamespaceSupport defineJavaNamespace(String ns, String classOrPackage) 158 { 159 if(null == ns || ns.trim().length() == 0) return null; 161 162 String className = classOrPackage; 166 if (className.startsWith("class:")) 167 className = className.substring(6); 168 169 int lastSlash = className.lastIndexOf("/"); 170 if (-1 != lastSlash) 171 className = className.substring(lastSlash + 1); 172 173 if(null == className || className.trim().length() == 0) 176 return null; 177 178 try 179 { 180 ExtensionHandler.getClassForName(className); 181 return new ExtensionNamespaceSupport( 182 ns, 183 "org.apache.xalan.extensions.ExtensionHandlerJavaClass", 184 new Object []{ns, "javaclass", className}); 185 } 186 catch (ClassNotFoundException e) 187 { 188 return new ExtensionNamespaceSupport( 189 ns, 190 "org.apache.xalan.extensions.ExtensionHandlerJavaPackage", 191 new Object []{ns, "javapackage", className + "."}); 192 } 193 } 194 195 201 202 203 206 private void setPredefinedNamespaces() 207 { 208 String uri = Constants.S_EXTENSIONS_JAVA_URL; 209 String handlerClassName = "org.apache.xalan.extensions.ExtensionHandlerJavaPackage"; 210 String lang = "javapackage"; 211 String lib = ""; 212 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 213 new Object []{uri, lang, lib})); 214 215 uri = Constants.S_EXTENSIONS_OLD_JAVA_URL; 216 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 217 new Object []{uri, lang, lib})); 218 219 uri = Constants.S_EXTENSIONS_LOTUSXSL_JAVA_URL; 220 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 221 new Object []{uri, lang, lib})); 222 223 uri = Constants.S_BUILTIN_EXTENSIONS_URL; 224 handlerClassName = "org.apache.xalan.extensions.ExtensionHandlerJavaClass"; 225 lang = "javaclass"; lib = "org.apache.xalan.lib.Extensions"; 227 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 228 new Object []{uri, lang, lib})); 229 230 uri = Constants.S_BUILTIN_OLD_EXTENSIONS_URL; 231 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 232 new Object []{uri, lang, lib})); 233 234 uri = Constants.S_EXTENSIONS_REDIRECT_URL; 236 lib = "org.apache.xalan.lib.Redirect"; 237 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 238 new Object []{uri, lang, lib})); 239 240 uri = Constants.S_EXTENSIONS_PIPE_URL; 241 lib = "org.apache.xalan.lib.PipeDocument"; 242 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 243 new Object []{uri, lang, lib})); 244 245 uri = Constants.S_EXTENSIONS_SQL_URL; 246 lib = "org.apache.xalan.lib.sql.XConnection"; 247 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 248 new Object []{uri, lang, lib})); 249 250 251 uri = Constants.S_EXSLT_COMMON_URL; 254 lib = "org.apache.xalan.lib.ExsltCommon"; 255 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 256 new Object []{uri, lang, lib})); 257 258 uri = Constants.S_EXSLT_MATH_URL; 259 lib = "org.apache.xalan.lib.ExsltMath"; 260 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 261 new Object []{uri, lang, lib})); 262 263 uri = Constants.S_EXSLT_SETS_URL; 264 lib = "org.apache.xalan.lib.ExsltSets"; 265 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 266 new Object []{uri, lang, lib})); 267 268 uri = Constants.S_EXSLT_DATETIME_URL; 269 lib = "org.apache.xalan.lib.ExsltDatetime"; 270 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 271 new Object []{uri, lang, lib})); 272 273 uri = Constants.S_EXSLT_DYNAMIC_URL; 274 lib = "org.apache.xalan.lib.ExsltDynamic"; 275 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 276 new Object []{uri, lang, lib})); 277 278 uri = Constants.S_EXSLT_STRINGS_URL; 279 lib = "org.apache.xalan.lib.ExsltStrings"; 280 m_predefExtensions.addElement(new ExtensionNamespaceSupport(uri, handlerClassName, 281 new Object []{uri, lang, lib})); 282 } 283 284 } 285 | Popular Tags |