Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Package Attributes
ScriptFile Class Reference
Collaboration diagram for ScriptFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ScriptFile (Connection c, String req, PrintWriter stream)
 ScriptFile (String f)
void Parse () throws IOException

Static Public Member Functions

static void main (String args[])

Static Public Attributes

static final String URLMAP = new String("docs/urlmap")

Protected Member Functions

void WriteOutFile (String filename) throws IOException
void WriteDefaultResponse () throws IOException
void WriteSpecialResponse (String specialcase) throws IOException
void WriteHeadResponse ()

Package Attributes

String file = null
String request
PrintWriter out
Connection con

Detailed Description

Definition at line 46 of file ScriptFile.java.


Constructor & Destructor Documentation

ScriptFile.ScriptFile ( Connection  c,
String  req,
PrintWriter  stream 
) [inline]

Definition at line 50 of file ScriptFile.java.

                                                                        {
        con = c;
           request = req;
           out = stream;
           if (out == null)
               out = new PrintWriter(System.out);
           file = URLMAP;
           try {
               Parse();
           }
           catch (IOException e)
           {
               out.println("HTTP/1.1 500 Server Error\n\n");
               out.println("Failed with this exception-");
               out.println(e);
           }
           out.flush();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

ScriptFile.ScriptFile ( String  f) [inline]

Definition at line 69 of file ScriptFile.java.

                                   {
              file = f;
              out = new PrintWriter(System.out);
           try {
               Parse();
           }
           catch (FileNotFoundException e)
           {
               out.println("HTTP/1.1 404 File Not Found\n\n");
               out.println("File not found!");
               out.println(e);
           }
           catch (IOException e)
           {
               out.println("HTTP/1.1 500 Server Error\n\n");
               out.println("Failed with this exception-");
               out.println(e);
           }
           out.flush();
       }

Here is the call graph for this function:


Member Function Documentation

static void ScriptFile.main ( String  args[]) [inline, static]

Definition at line 200 of file ScriptFile.java.

                                              {
           if (args.length >= 1) {
            ScriptFile sf = new ScriptFile(args[0]);
            /* Detect change stuff;
            File f = new File(args[0]);
            long lastMod = f.lastModified();
            while (f.lastModified() == lastMod) {
            }
            sf.Parse();
            */
           }
       }

Here is the call graph for this function:

void ScriptFile.Parse ( ) throws IOException [inline]

Definition at line 90 of file ScriptFile.java.

                                               {

           if ((request == null) ||
                     (request.length() == 0) ||
                     request.startsWith("GET / ") || request.startsWith("get / "))
           {
               WriteDefaultResponse();
            return;
           }

              if (request.startsWith("GET /?") || request.startsWith("get /?"))
              {
                     WriteSpecialResponse(request.substring(request.indexOf('?')+1));
                     return;
              }

        if (request.startsWith("HEAD /") || request.startsWith("head /"))
        {
            WriteHeadResponse();
            return;
        }

        boolean outDirty = false;
           if (file != null)
           {
                       BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                                   new FileInputStream(file)));

              String s = new String();
              while((s = in.readLine())!= null)
              {
                s.trim();
                /* Skip comments */
                if ((s.length() == 0) || (s.charAt(0) == '#'))
                    continue;
                if (s.startsWith("START")) {
                    // Check to see if this was in the requested URL
                    String filename = new String ("GET " + s.substring(6));
                    String otherfilename = new String("POST " + s.substring(6));
                    if (request.startsWith(filename) || 
                            request.startsWith(otherfilename))
                    {
                        continue;
                    }
                    else// Else skipto past the END
                    {
                        while (!s.startsWith("END"))
                        {
                            s = in.readLine();
                            if (s != null)
                            {
                                s.trim();
                            }
                            else
                                break;
                        }
                    }
                }
                else if (s.startsWith("ECHO")) {
                    outDirty = true;
                    boolean parameter = false;
                    try {
                        String header = new String(s.substring(5));
                        String req= new String(con.request);
                        int t = req.indexOf(header);
                        if (t != -1) {
                            out.println(req.substring(
                                t, req.indexOf("\n", t)));
                            parameter = true;
                        }
                        else {
                            out.println("Error: " + header + 
                                    " not specified in request!");
                        }
                        
                    }
                    catch (StringIndexOutOfBoundsException e) {}
                    if (!parameter)
                        out.println(con.request);
                }
                else if (s.startsWith("INCLUDE")) {
                    outDirty = true;
                    WriteOutFile("docs/" + s.substring(8));
                }
                else if (s.startsWith("CRLF")) {
                    outDirty = true;
                    out.println();
                }
                else if (s.startsWith("END")) {
                    // ignore should never have appeared here though!
                    continue;
                }
                else {// Not a recognizable line... just print it as is...
                    outDirty = true;
                    out.println(s);
                }

              }
              in.close();

              if (outDirty)
              {
                out.flush();
              }
              else
                WriteDefaultResponse();
           }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void ScriptFile.WriteDefaultResponse ( ) throws IOException [inline, protected]

Definition at line 226 of file ScriptFile.java.

                                                             {
              WriteOutFile("docs/generic.res");
        out.println("Date: " + (new Date()).toString());
        if (file != null)
        {
            File f = new File(file);
            out.println("Last-modified: " + (new Date(f.lastModified())).toString());
        }
        out.println("\n"); // prints 2
        if (con != null)
        {
                     out.println("<HTML><BODY>");
            out.println("<H3>Rec'd. the following request-</H3>");
            out.println("<PRE>");
            out.println(con.request);
            out.println("</PRE>");
            out.println("From- " + con.client);
                     out.println("</BODY></HTML>");
         }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ScriptFile.WriteHeadResponse ( ) [inline, protected]

Definition at line 276 of file ScriptFile.java.

                                       {
        out.println("HTTP/1.1 200 OK");
        out.println("Server: HTTP Test Server/1.1");
        out.println("Content-Type: text/plain");
        out.println("Content-Length: 1000" ); // bogus 
        out.println("Date: " + (new Date()).toString());
        out.println(); // also test without it
        out.flush();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ScriptFile.WriteOutFile ( String  filename) throws IOException [inline, protected]

Definition at line 213 of file ScriptFile.java.

                                                                    {
                BufferedReader incl = new BufferedReader(
                     new InputStreamReader(
               new FileInputStream(filename)));
        // This doesn't have to be line wise... change later TODO
        String s;
        while ((s = incl.readLine()) != null)
        {
            out.println(s);
        }
        incl.close();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ScriptFile.WriteSpecialResponse ( String  specialcase) throws IOException [inline, protected]

Definition at line 247 of file ScriptFile.java.

                                                                                  {
        out.println("HTTP/1.1 200 OK");
        out.println("Server: HTTP Test Server/1.1");
        out.println("Content-Type: text/plain");

              StringTokenizer st = new StringTokenizer(specialcase, " &");
              while (st.hasMoreTokens()) {
                  String pair = st.nextToken();
              if (pair.startsWith("Length=") || pair.startsWith("length="))
              {

                int len = Integer.valueOf(pair.substring(
                            pair.indexOf('=')+1), 10).intValue();

                     out.println("Date: " + (new Date()).toString());
                     out.println("Content-Length: " + len);
                     out.println("\n");
                     for (int i = 0; i<len; i++) {
                    out.print ((char)i%10);
                    if ((i>0) && ((i+1)%80) == 0)
                             out.print('\n');
                         out.flush();
                     }
                     return;
              }
       }

       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 291 of file ScriptFile.java.

Definition at line 286 of file ScriptFile.java.

PrintWriter ScriptFile.out [package]

Definition at line 290 of file ScriptFile.java.

Definition at line 289 of file ScriptFile.java.

final String ScriptFile.URLMAP = new String("docs/urlmap") [static]

Definition at line 48 of file ScriptFile.java.


The documentation for this class was generated from the following file: