Annotation of java/classes/org/w3c/jigsaw/servlet/ServletDirectoryFrame.java, revision 1.9

1.1       bmahe       1: // ServletDirectoryFrame.java
1.9     ! bmahe       2: // $Id: ServletDirectoryFrame.java,v 1.8 1998/05/28 12:51:46 bmahe Exp $
1.1       bmahe       3: // (c) COPYRIGHT MIT and INRIA, 1996.
                      4: // Please first read the full copyright statement in file COPYRIGHT.html
                      5: 
                      6: package org.w3c.jigsaw.servlet;
                      7: 
                      8: import java.io.*;
                      9: import java.net.*;
                     10: import java.util.*;
                     11: 
                     12: import javax.servlet.*;
                     13: 
                     14: import org.w3c.tools.resources.store.*;
                     15: import org.w3c.tools.resources.*;
                     16: import org.w3c.jigsaw.frames.*;
                     17: 
                     18: /**
                     19:  *  @author Alexandre Rafalovitch <alex@access.com.au>
                     20:  *  @author Anselm Baird-Smith <abaird@w3.org>
1.3       bmahe      21:  *  @author Benoit Mahe <bmahe@w3.org>
1.1       bmahe      22:  */
                     23: 
1.3       bmahe      24: public class ServletDirectoryFrame extends HTTPFrame {
1.6       bmahe      25:     /**
                     26:      * Attribute index - The index for our servlet log file attribute.
                     27:      */
                     28:     protected static int ATTR_SERVLET_LOG_FILE = -1 ;
                     29: 
                     30:     /**
                     31:      * Name of the property indicating the servlet log file.
                     32:      * This property indicates the name of the servlet log file to use.
                     33:      * <p>This property defaults to the <code>servlets</code> file in 
                     34:      * the server log directory.
                     35:      */
                     36:     protected static String SERVLET_LOG_FILE_P = "servlet-log-file";
1.1       bmahe      37: 
1.6       bmahe      38:     protected JigsawServletContext servletContext = null;
                     39: 
                     40:     static {
                     41:        Attribute a   = null ;
                     42:        Class     cls = null ;
                     43:        // Get a pointer to our class.
                     44:        try {
                     45:            cls = 
                     46:                Class.forName("org.w3c.jigsaw.servlet.ServletDirectoryFrame") ;
                     47:        } catch (Exception ex) {
                     48:            ex.printStackTrace() ;
                     49:            System.exit(1) ;
                     50:        }
                     51:        // The servlet log file:
                     52:        a = new FileAttribute(SERVLET_LOG_FILE_P
                     53:                              , null
                     54:                              , Attribute.EDITABLE);
                     55:        ATTR_SERVLET_LOG_FILE = AttributeRegistry.registerAttribute(cls, a);
                     56:     }
                     57: 
                     58:     protected String logdir     = "logs" ;
                     59:     protected String deflogfile = "servlets";
                     60: 
                     61:     public File getServletLogFile() {
                     62:        File logfile = (File) getValue(ATTR_SERVLET_LOG_FILE, null);
1.8       bmahe      63:        if ((logfile != null) && (logfile.getPath().length() < 1))
1.7       bmahe      64:            logfile = null;
1.6       bmahe      65:        if (logfile == null) {
1.9     ! bmahe      66:            File root_dir = getServer().getRootDirectory();
1.6       bmahe      67:            if (root_dir == null) {
                     68:                throw new RuntimeException("unable to build a default "+
                     69:                                           "value for the servlet log file.");
                     70:            }
                     71:            logfile = new File(new File(root_dir, logdir), deflogfile);
                     72:        }
                     73:        return logfile;
                     74:     }
                     75: 
                     76:     /**
                     77:      * ServletContext implementation - Lookup a given servlet.
                     78:      */
                     79: 
                     80:     public Servlet getServlet(String name) {
                     81:        if (dresource != null) {
                     82:            ResourceReference rr = dresource.lookup(name);
                     83:            try {
                     84:                Resource resource = rr.lock();
                     85:                if (resource instanceof ServletWrapper)
                     86:                    return ((ServletWrapper) resource).getServlet();
                     87:            } catch (InvalidResourceException ex) {
                     88:                return null;
                     89:            } finally {
                     90:                rr.unlock();
                     91:            }
                     92:        }
1.1       bmahe      93:        return null;
1.6       bmahe      94:     }
                     95: 
                     96:     /**
                     97:      * ServletContext implementation - Enumerate all servlets within context.
                     98:      */
                     99: 
                    100:     public Enumeration getServlets() {
                    101:        if (dresource != null)
                    102:            return new ServletEnumeration(this, 
                    103:                                  dresource.enumerateResourceIdentifiers());
                    104:        else
                    105:            return new ServletEnumeration(this, null);
                    106:     }
1.5       bmahe     107: 
                    108:     /**
                    109:      * ServletContext implementation - Enumerate all servlets names
                    110:      * within context.
                    111:      */
                    112: 
                    113:     public Enumeration getServletNames() {
                    114:        if (dresource != null)
                    115:            return new ServletNamesEnumeration(this, 
                    116:                               dresource.enumerateResourceIdentifiers());
                    117:        else
                    118:            return new ServletNamesEnumeration(this, null);
                    119:     }
1.1       bmahe     120: 
1.6       bmahe     121:     /**
                    122:      * ServletContext implementation - Get server informations.
                    123:      */
                    124: 
                    125:     public String getServerInfo() {
                    126:        return resource.getServer().getSoftware();
                    127:     }
                    128: 
                    129:     /**
                    130:      * ServletContext implementation - Get an attribute value.
                    131:      * We map this into the ServletWrapper attributes, without
                    132:      * support for name clashes though.
                    133:      * @param name The attribute name.
                    134:      */
                    135: 
                    136:     public Object getAttribute(String name) {
                    137:        if ( definesAttribute(name) )
                    138:            return getValue(name, null);
                    139:        else if (resource.definesAttribute(name))
                    140:            return resource.getValue(name, null);
                    141:        return null;
                    142:     }
                    143: 
                    144:     /**
                    145:      * We add a <em>context</em> attribute to all our children.
                    146:      * The <em>context</em> attribute is any object implementing the
                    147:      * ServletContext interface.
                    148:      */
                    149: 
                    150:     protected void updateDefaultChildAttributes(Hashtable attrs) {
                    151:        if (servletContext == null)
                    152:            servletContext = new JigsawServletContext(getFrameReference());
                    153:        attrs.put("servlet-context", servletContext);
                    154:     }
1.1       bmahe     155: 
                    156: }

Webmaster