larryi 01/12/05 03:26:57 Modified: src/share/org/apache/tomcat/modules/config LoaderInterceptor11.java Log: Updates so jaxpJars can include absolute paths. Added a "jarSeparator" attribute to allow changing the separator from the default ':' so Windows absolute paths can be used. Implemented "additionalJars" attribute and support for an additionalJars context property to add a list of jars to the web application classloader. This avoids trying to use jaxpJars to perform this feature.. Revision Changes Path 1.23 +75 -10 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/LoaderInterceptor11.java Index: LoaderInterceptor11.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/config/LoaderInterceptor11.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- LoaderInterceptor11.java 2001/10/09 17:42:27 1.22 +++ LoaderInterceptor11.java 2001/12/05 11:26:57 1.23 @@ -89,8 +89,12 @@ private int attributeInfo; String loader=null; Vector jaxpJars=new Vector(); - String jaxpJarsS="jaxp.jar:crimson.jar:xalan.jar:xerces.jar"; + String jaxpJarsSDefault="jaxp.jar:crimson.jar:xalan.jar:xerces.jar"; + String jaxpJarsS=null; String jaxpDir=null; + Vector additionalJars=new Vector(); + String additionalJarsS=null; + String jarSeparator=":"; public LoaderInterceptor11() { } @@ -125,6 +129,31 @@ jaxpJarsS=jars; } + /** List of additional jars to add to each web application. + */ + public void setAdditionalJars(String jars ) { + additionalJarsS=jars; + } + + /** Character to use to separate jars in the jaxpJars list. + It also applies to the additionalJars context property + list. + */ + public void setJarSeparator(String sep) { + if( sep != null && sep.length() > 0 ) { + if( sep.length() > 1 ) + sep = sep.substring(0,1); + + char oldSep[]=new char[1]; + char newSep[]=new char[1]; + jarSeparator.getChars(0,1,oldSep,0 ); + sep.getChars(0,1,newSep,0); + jaxpJarsSDefault=jaxpJarsSDefault.replace(oldSep[0],newSep[0]); + + jarSeparator=sep; + } + } + /** Check if the webapp contains jaxp , and add one if not. This allow apps to include their own parser if they want, while using the normal delegation model. @@ -146,6 +175,7 @@ attributeInfo=cm.getNoteId(ContextManager.REQUEST_NOTE, "req.attribute"); initJaxpJars(); + initAdditionalJars(); } @@ -228,11 +258,30 @@ * */ public void prepareClassLoader(Context context) throws TomcatException { + String list = context.getProperty("additionalJars"); + if( list != null ) { + Vector urls=new Vector(); + getUrls( null, list, urls ); + Enumeration en=urls.elements(); + while( en.hasMoreElements() ) { + URL url=(URL)en.nextElement(); + if( debug > 0 ) log(context + " adding: " + url); + context.addClassPath( url ); + } + } + + Enumeration en=additionalJars.elements(); + while( en.hasMoreElements() ) { + URL url=(URL)en.nextElement(); + if( debug > 0 ) log(context + " adding: " + url); + context.addClassPath( url ); + } + ClassLoader loader=constructLoader( context ); if( addJaxp ) { boolean hasJaxp=checkJaxp( loader, context ); if( ! hasJaxp ) { - Enumeration en=jaxpJars.elements(); + en=jaxpJars.elements(); while( en.hasMoreElements() ) { URL url=(URL)en.nextElement(); if( debug > 0 ) log(context + " adding jaxp: " + url); @@ -241,6 +290,7 @@ loader=constructLoader( context ); } } + if( debug>5 ) { URL classP[]=context.getClassPath(); log(" Context classpath URLs:"); @@ -267,7 +317,7 @@ if( debug > 0 ) log( "Using no parent loader "); parent=null; } else if( useAppsL && !context.isTrusted() ) { - if( debug > 0 ) log( "Using webapp loader " + context.isTrusted()); + if( debug > 0 ) log( "Using webapp loader "); parent=cm.getAppsLoader(); } else { if( debug > 0 ) log( "Using container loader "); @@ -284,22 +334,37 @@ } private void initJaxpJars() { - if( jaxpDir==null ) jaxpDir=cm.getInstallDir() + "/lib/container"; - File base=new File( jaxpDir ); - StringTokenizer st=new StringTokenizer( jaxpJarsS, ":" ); + if( jaxpJarsS == null ) + jaxpJarsS=jaxpJarsSDefault; + getUrls( jaxpDir, jaxpJarsS, jaxpJars ); + } + + private void initAdditionalJars() { + if( additionalJarsS != null ) + getUrls( null, additionalJarsS, additionalJars ); + } + + private void getUrls( String dir, String jarList, Vector jars ) { + if( dir == null ) dir=cm.getInstallDir() + "/lib/container"; + File base=new File( dir ); + if( debug > 5 ) log( "Scanning \"" + jarList + "\" with base directory " + base); + StringTokenizer st=new StringTokenizer( jarList, jarSeparator ); while( st.hasMoreElements() ) { String s=(String)st.nextElement(); - File f=new File( base,s); - if( ! f.exists()) continue; + File f=new File( s ); + if( ! f.isAbsolute() ) + f=new File( base, s); + if( ! f.exists() ) continue; try { URL url=new URL( "file", null, f.getAbsolutePath().replace('\\','/')); - jaxpJars.addElement( url ); - if( debug > 0 ) log( "Adding " + url ); + jars.addElement( url ); + if( debug > 5 ) log( "Adding " + url ); } catch( MalformedURLException ex ) { } } } + private boolean checkJaxp( ClassLoader loader, Context context ) { try { loader.loadClass("javax.xml.parsers.SAXParserFactory");
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>