larryi      01/12/05 03:20:52

  Modified:    src/share/org/apache/tomcat/modules/config
                        ContextXmlReader.java
  Log:
  For consistency with server.xml handling, added support for
  <Property ... /> and ant-style variable substitution in Context definitions
  
  Revision  Changes    Path
  1.12      +69 -2     
jakarta-tomcat/src/share/org/apache/tomcat/modules/config/ContextXmlReader.java
  
  Index: ContextXmlReader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/config/ContextXmlReader.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ContextXmlReader.java     2001/10/20 02:52:12     1.11
  +++ ContextXmlReader.java     2001/12/05 11:20:52     1.12
  @@ -68,6 +68,7 @@
   import org.apache.tomcat.util.xml.*;
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.modules.server.*;
  +import org.apache.tomcat.util.IntrospectionUtils;
   import org.apache.tomcat.util.log.Log;
   import org.xml.sax.*;
   
  @@ -110,6 +111,7 @@
        // use the same tags for context-local modules
        addTagRules(cm, xh);
        setContextRules( xh );
  +        setPropertiesRules( cm, xh );
        setBackward( xh );
   
        // load the config file(s)
  @@ -144,7 +146,58 @@
   
       // -------------------- Xml reading details --------------------
   
  -    // rules for reading teh context config
  +    static class ContextPropertySource
  +        implements IntrospectionUtils.PropertySource
  +    {
  +        ContextManager cm;
  +        Context ctx=null;
  +     
  +        ContextPropertySource( ContextManager cm ) {
  +            this.cm=cm;
  +        }
  +
  +        public void setContext(Context ctx) {
  +            this.ctx=ctx;
  +        }
  +     
  +        public String getProperty( String key ) {
  +            // XXX add other "predefined" properties
  +            String s=null;
  +            if( ctx != null )
  +                s=ctx.getProperty( key );              
  +            if( s == null )
  +                s=cm.getProperty( key );
  +            if( s == null )
  +             s=System.getProperty( key );
  +            return s;
  +        }
  +    }
  +
  +    public static void setPropertiesRules( ContextManager cm, XmlMapper xh )
  +     throws TomcatException
  +    {
  +     ContextPropertySource propS=new ContextPropertySource( cm );
  +     xh.setPropertySource( propS );
  +     
  +     xh.addRule( "Context/Property", new XmlAction() {
  +             public void start(SaxContext ctx ) throws Exception {
  +                 AttributeList attributes = ctx.getCurrentAttributes();
  +                 String name=attributes.getValue("name");
  +                 String value=attributes.getValue("value");
  +                 if( name==null || value==null ) return;
  +                 XmlMapper xm=ctx.getMapper();
  +                 
  +                 Context context=(Context)ctx.currentObject();
  +                 // replace ${foo} in value
  +                 value=xm.replaceProperties( value );
  +                 if( context.getDebug() > 0 )
  +                     context.log("Setting " + name + "=" + value);
  +                 context.setProperty( name, value );
  +             }
  +         });
  +    }
  +
  +    // rules for reading the context config
       public static void setContextRules( XmlMapper xh ) {
        // Default host
        xh.addRule( "Context",
  @@ -172,9 +225,23 @@
                }
            });
   
  +        xh.addRule( "Context", new XmlAction() {
  +                public void start( SaxContext xctx) throws Exception {
  +                    Context tcCtx=(Context)xctx.currentObject();
  +                    XmlMapper xm=xctx.getMapper();
  +                    ContextPropertySource propS = 
(ContextPropertySource)xm.getPropertySource();
  +                    if( propS != null )
  +                        propS.setContext(tcCtx);
  +                }
  +            });
  +
        xh.addRule( "Context", new XmlAction() {
                public void end( SaxContext xctx) throws Exception {
                    Context tcCtx=(Context)xctx.currentObject();
  +                    XmlMapper xm=xctx.getMapper();
  +                    ContextPropertySource propS = 
(ContextPropertySource)xm.getPropertySource();
  +                    if( propS != null )
  +                        propS.setContext(null);
                    String host=(String)xctx.getVariable("current_host");
                    String address=(String)xctx.getVariable("current_address");
                    Vector aliases=(Vector)xctx.getVariable( "host_aliases" );
  @@ -199,7 +266,7 @@
                    xh.addChild("addContext",
                                "org.apache.tomcat.core.Context") );
       }
  -    
  +
       // -------------------- Backward compatibility -------------------- 
   
       // Read old configuration formats
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to