cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ovi...@apache.org
Subject cvs commit: xml-cocoon2/scratchpad/schecoon/webapp/WEB-INF web.xml
Date Mon, 10 Dec 2001 08:45:17 GMT
ovidiu      01/12/10 00:45:17

  Added:       scratchpad/schecoon build.xml
               scratchpad/schecoon/emacs README sisc-servlet.bat.in
                        sisc-servlet.in siscscheme.el
               scratchpad/schecoon/lib servlet_2_2.jar sisc.heap sisc.jar
               scratchpad/schecoon/scheme test.scm
               scratchpad/schecoon/src/org/apache/cocoon/scheme/servlet
                        REPLEvalServlet.java REPLGenericServlet.java
                        REPLServlet.java
               scratchpad/schecoon/src/org/apache/cocoon/scheme/util
                        SchemeServletCmdLine.java
               scratchpad/schecoon/webapp/WEB-INF web.xml
  Log:
  The initial  import.
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/scratchpad/schecoon/build.xml
  
  Index: build.xml
  ===================================================================
  <project default="build" basedir=".">
  
    <!--
      Give user a chance to override without editing this file
      (and without typing -D each time he compiles it)
    -->
    <property file=".ant.properties"/>
    <property file="${user.home}/.ant.properties"/>
  
    <!--
      these are here only for those who use jikes compiler. For other
      developers this part makes no difference.
    -->
    <property name="build.compiler.emacs" value="on"/>
    <property name="build.compiler.warnings" value="true"/>
    <property name="build.compiler.pedantic" value="false"/>
    <property name="build.compiler.depend" value="true"/>
    <property name="build.compiler.fulldepend" value="true"/>
  
    <!-- =================================================================== -->
    <!-- Initialization target                                               -->
    <!-- =================================================================== -->
    <target name="init">
      <tstamp/>
  
      <!-- Define at least fullname, name, and description. They will be
      placed in webapp/WEB-INF/web.xml -->
      <property name="fullname" value="Schecoon"/>
      <property name="description" value="Schecoon"/>
      <property name="name"     value="schecoon"/>
      <property name="version"  value="${DSTAMP}"/>
      <property name="short.version" value="${DSTAMP}"/>
      <property name="release"  value="1st"/>
      <property name="year"     value="2001"/>
  
      <echo message="------------------- ${fullname} ${version} [${year}] ----------------"/>
  
      <property name="debug"          value="on"/>
      <property name="optimize"       value="off"/>
      <property name="deprecation"    value="off"/>
      <property name="build.compiler" value="classic"/>
      <property name="target.vm"      value="1.2"/>
  
      <property name="src.dir"      value="./src"/>
      <property name="lib.dir"      value="./lib"/>
      <property name="bin.dir"      value="./bin"/>
      <property name="webapp.dir"   value="./webapp"/>
      <property name="scheme.dir"     value="./scheme"/>
      <property name="emacs.dir"     value="./emacs"/>
  
      <property name="build.root"     value="./build"/>
      <property name="build.dir"      value="${build.root}"/>
      <property name="build.dest"     value="${build.dir}/webapp/WEB-INF/classes"/>
      <property name="build.docs"     value="${build.dir}/docs"/>
      <property name="build.war"      value="${build.dir}/webapp"/>
      <property name="build.javadocs" value="${build.dir}/javadocs"/>
  
      <property name="dist.root"   value="./dist"/>
      <property name="dist.dir"    value="${dist.root}/${name}-${version}"/>
      <property name="dist.target" value="${dist.root}"/>
  
      <!-- 
      The location of tools.jar, relative to the JAVA_HOME home. 
      -->
      <property name="tools.jar" value="${java.home}/lib/tools.jar"/>
  
      <filter token="name"    value="${fullname}"/>
      <filter token="year"    value="${year}"/>
      <filter token="version" value="${version}"/>
      <filter token="date"    value="${TODAY}"/>
      <filter token="log"     value="true"/>
      <filter token="verbose" value="true"/>
    </target>
  
    <!-- =================================================================== -->
    <!-- Indentify Classpath                                                 -->
    <!-- =================================================================== -->
    <path id="classpath">
      <fileset dir="./lib">
        <include name="*.jar"/>
        <include name="${src.dir}"/>
      </fileset>
    </path>
  
    <!-- Add filters for loading database information from
         database.properties file
    -->
    <!-- =================================================================== -->
    <!-- Prepares the build directory                                        -->
    <!-- =================================================================== -->
    <target name="prepare" depends="init">
      <mkdir dir="${build.dir}"/>
      <mkdir dir="${build.dest}"/>
      <mkdir dir="${build.war}"/>
    </target>
  
    <!-- =================================================================== -->
    <!-- Compiles the source directory                                       -->
    <!-- =================================================================== -->
    <target name="compile" depends="prepare"
            description="Compiles the source code">
      <javac srcdir="${src.dir}"
             destdir="${build.dest}"
             debug="${debug}"
             optimize="${optimize}"
             deprecation="${deprecation}"
             target="${target.vm}">
        <classpath refid="classpath"/>
      </javac>
    </target>
  
    <!-- =================================================================== -->
    <!-- Prepares the webapp directories                                     -->
    <!-- =================================================================== -->
    <target name="prepare-webapp" depends="prepare">
      <copy todir="${build.war}" filtering="off">
        <fileset dir="${webapp.dir}" excludes="**/*.in"/>
      </copy>
  
      <copy todir="${build.war}" filtering="off">
        <fileset dir="${lib.dir}">
          <include name="*.heap"/>
        </fileset>
      </copy>
  
    </target>
  
    <!-- =================================================================== -->
    <!-- Prepares the libraries for the war package                          -->
    <!-- =================================================================== -->
    <target name="prepare-webapp-libs" depends="prepare">
      <copy todir="${build.war}/WEB-INF/lib">
        <fileset dir="${lib.dir}">
          <include name="*.jar"/>
        </fileset>
      </copy>
    </target>
  
    <!-- =================================================================== -->
    <!-- Generate the heap from the Scheme files                             -->
    <!-- =================================================================== -->
    <target name="prepare-heap" depends="init, prepare">
      <java classname="sisc.boot.GenerateHeap">
        <classpath refid="classpath"/>
        <arg line="${build.war}/${name}.heap"/>
        <arg line="${scheme.dir}/test.scm"/>
      </java>
    </target>
  
    <!-- =================================================================== -->
    <!-- Creates the jar file                                                -->
    <!-- =================================================================== -->
    <target name="package" depends="compile"
  	  description="Generates the jar package">
      <jar jarfile="${build.dir}/${name}.jar">
        <fileset dir="${build.dest}" includes="org/**"/>
      </jar>
    </target>
  
    <!-- =================================================================== -->
    <!-- Setup the script files                                              -->
    <!-- =================================================================== -->
    <target name="scripts">
      <copy todir="${emacs.dir}">
        <fileset dir="${emacs.dir}">
          <include name="*.in"/>
        </fileset>
        <filterset>
          <filter token="top" value="${basedir}"/>
        </filterset>
        <mapper type="glob" from="*.in" to="*"/>
      </copy>
      <chmod perm="a+x">
        <fileset dir="${emacs.dir}" includes="sisc-servlet"/>
      </chmod>
    </target>
  
    <!-- =================================================================== -->
    <!-- Prepares everything to be run in place                              -->
    <!-- =================================================================== -->
    <target name="build" depends="prepare-webapp, prepare-webapp-libs,
  	                        compile, prepare-heap, package, scripts"
  	  description="Prepares everything to be run in place"/>
  
    <!-- =================================================================== -->
    <!-- Creates the war file                                                -->
    <!-- =================================================================== -->
    <target name="webapp" depends="build, package"
  	  description="Generates the war package">
      <jar jarfile="${build.dir}/${name}.war" basedir="${build.war}" includes="**"/>
    </target>
  
    <!-- =================================================================== -->
    <!-- Set a variable if javadoc is already up-to-date.                    -->
    <!-- =================================================================== -->
    <target name="javadocs_check">
      <uptodate property="javadocs.notrequired" targetfile="${build.javadocs}/packages.html"
>
        <srcfiles dir= "${build.src}" includes="**/*.java"/>
      </uptodate>
    </target>
  
    <!-- =================================================================== -->
    <!-- If javadoc is already up-to-date, print a message saying so.        -->
    <!-- =================================================================== -->
    <target name="javadocs_done" if="javadocs.notrequired">
      <echo message="-------------------------------------------------------------"/>
      <echo message="Not rebuilding Javadocs, as they are up-to-date:"/>
      <echo message="  ${build.javadocs}/packages.html is more recent than"/>
      <echo message="  ${build.src}/**/*.java"/>
      <echo message="-------------------------------------------------------------"/>
    </target>
  
    <!-- =================================================================== -->
    <!-- Creates the API documentation                                       -->
    <!-- =================================================================== -->
    <target name="javadocs" depends="javadocs_check, javadocs_done"
        unless="javadocs.notrequired"
        description="Generates the API documentation">
      <mkdir dir="${build.javadocs}"/>
      <javadoc packagenames="${packages}"
               sourcepath="${build.src}"
               destdir="${build.javadocs}"
               author="true"
               version="true"
               use="false"
               noindex="true"
               windowtitle="${name} API"
               doctitle="${name}"
               bottom="Copyright &#169; ${year} Hewlett Packard Company. All Rights Reserved."
               stylesheetfile="${resource.dir}/javadoc.css">
        <classpath refid="classpath"/>
      </javadoc>
    </target>
  
    <!-- =================================================================== -->
    <!-- Clean targets                                                       -->
    <!-- =================================================================== -->
    <target name="clean" depends="init" description="* Cleans the build directories">
      <delete dir="${build.dir}"/>
      <delete>
        <fileset dir="${emacs.dir}" includes="sisc-servlet.bat"/>
        <fileset dir="${emacs.dir}" includes="sisc-servlet"/>
      </delete>
    </target>
  
    <target name="distclean" depends="clean" description="* Cleans everything to the original
state">
      <delete dir="${build.root}"/>
      <delete dir="${dist.root}"/>
    </target>
  
  </project>
  
  <!-- End of file -->
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/emacs/README
  
  Index: README
  ===================================================================
  These are instructions on how to setup the command line Scheme
  interaction program to be used from within Emacs. With this setup
  editing and evaluating expressions and definition in the Scheme
  servlet is a snap.
  
  Add the following in your ~/.emacs (change the location of
  sisc-servlet script to suit your needs):
  
  (require 'cl)
  (defvar sisc-location "~/src/schecoon/emacs")
  (pushnew sisc-location load-path)
  (require 'siscscheme)
  (setq sisc-program-name (concat sisc-location "/sisc-servlet"))
  
  Then visit a Scheme file. Type M-x run-sisc to start the inferior
  Scheme. Use the keys defined below to evaluate in the servlet the
  definitions you want.
  
  C-c e or M-C-x		evaluate the definition containing the point
  C-x C-e			evaluate the S-expression before point
  
  C-c C-e			evaluate the definition containing the point 
  			and select the scheme buffer after
  
  C-c r			evaluate the selected region
  
  C-c C-r			evaluate the selected region and select the
  			scheme buffer after
  
  C-c l			evaluate the current buffer
  
  The first time you evaluate something, you will be asked for a
  username and a password. Switch to the *scheme* buffer to enter them.
  
  This setup was tested with XEmacs 21.4.4, but it should work with
  other versions of XEmacs and GNU Emacs as well. Let me (Ovidiu) know
  if you have problems.
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/emacs/sisc-servlet.bat.in
  
  Index: sisc-servlet.bat.in
  ===================================================================
  ; FIXME: Somebody on Windows, can you please check if the syntax is right?
  
  set %LIBDIR%=@top@/build
  
  java -cp $LIBDIR/schecoon.jar org.apache.cocoon.scheme.util.SchemeServletCmdLine
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/emacs/sisc-servlet.in
  
  Index: sisc-servlet.in
  ===================================================================
  #! /bin/sh
  
  LIBDIR=@top@/build
  
  java -cp $LIBDIR/schecoon.jar org.apache.cocoon.scheme.util.SchemeServletCmdLine
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/emacs/siscscheme.el
  
  Index: siscscheme.el
  ===================================================================
  ;;; Mode to interact with the SISC Scheme command line tool.
  ;;;
  ;;; Author: Ovidiu Predescu <ovidiu@cup.hp.com>
  ;;; Date: December 9, 2001
  ;;;
  ;;; Adapted from cmuscheme48.el from the XEmacs distribution, which in
  ;;; turn was adapted from cmuscheme.el, which in turn was adapted from
  ;;; other things...
  ;;;
  ;;; Add the following in your ~/.emacs (change the location of
  ;;; sisc-servlet script to suit your needs):
  ;;;
  ;;; (require 'cl)
  ;;; (defvar sisc-location "~/src/schecoon/emacs")
  ;;; (pushnew sisc-location load-path)
  ;;; (require 'siscscheme)
  ;;; (setq sisc-program-name (concat sisc-location "/sisc-servlet"))
  ;;;
  ;;; Then visit a Scheme file. Type M-x run-sisc to start the inferior
  ;;; Scheme. Use the keys defined below to evaluate in the servlet the
  ;;; definitions you want.
  ;;;
  ;;; The first time you evaluate something, you will be asked for a
  ;;; username and a password. Switch to the *scheme* buffer to enter
  ;;; them.
  
  (provide 'siscscheme)
  (require 'cmuscheme)
  
  ;;;###autoload
  (defvar sisc-program-name "sisc-servlet"
    "The program name and arguments to be invoked for the `run-sisc'
  command.")
  
  ;;;###autoload
  (defun run-sisc (arg)
    "Run inferiour `sisc'.  See the documentation to `run-scheme' after
  `cmuscheme' has been `require'd."
    (interactive (list (if current-prefix-arg
  			 (read-string "Run Sisc: " sisc-program-name)
  		       sisc-program-name)))
    (run-scheme sisc-program-name))
  
  (define-key scheme-mode-map "\M-\C-x" 'sisc-send-definition);gnu convention
  (define-key scheme-mode-map "\C-x\C-e" 'sisc-send-last-sexp);gnu convention
  (define-key scheme-mode-map "\C-ce"    'sisc-send-definition)
  (define-key scheme-mode-map "\C-c\C-e" 'sisc-send-definition-and-go)
  (define-key scheme-mode-map "\C-cr"    'sisc-send-region)
  (define-key scheme-mode-map "\C-c\C-r" 'sisc-send-region-and-go)
  (define-key scheme-mode-map "\C-cl"    'sisc-load-file)
  
  (defun sisc-remove-newlines (start end)
    "Obtain from the current buffer the string between START and END,
  remove all the newlines and return it. Takes care of removing all the
  comments before removing the newlines."
    ;; FIXME: Ineficient, processes the string multiple times.
    (concat
     (replace-in-string
      (replace-in-string (buffer-substring start end) ";[^\n]*$" "")
      "\n" " " t)
     "\n"))
  
  (defun sisc-send-buffer-substring (start end)
    "Send to the inferior the buffer substring between START and END."
    (comint-send-string (scheme-proc) (sisc-remove-newlines start end)))
  
  (defun sisc-send-region (start end)
    "Send the current region to the inferior Scheme process."
    (interactive "r")
    (sisc-send-buffer-substring start end))
  
  (defun sisc-send-definition ()
    "Send the current definition to the inferior Sisc process."
    (interactive)
    (save-excursion
     (end-of-defun)
     (let ((end (point)))
       (beginning-of-defun)
       (sisc-send-buffer-substring (point) end))))
  
  (defun sisc-send-last-sexp ()
    "Send the previous sexp to the inferior Scheme process."
    (interactive)
    (sisc-send-buffer-substring (save-excursion (backward-sexp) (point))
  			      (point)))
  
  (defun sisc-send-region-and-go (start end)
    "Send the current region to the inferior Sisc process,
  and switch to the process buffer."
    (interactive "r")
    (sisc-send-region start end)
    (switch-to-scheme t))
  
  (defun sisc-send-definition-and-go ()
    "Send the current definition to the inferior Sisc,
  and switch to the process buffer."
    (interactive)
    (sisc-send-definition)
    (switch-to-scheme t))
  
  (defun sisc-load-file ()
    "Load a Scheme file into the inferior Sisc process."
    (interactive)
    (sisc-send-buffer-substring (save-excursion (beginning-of-buffer) (point))
  			      (save-excursion (end-of-buffer) (point))))
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/lib/servlet_2_2.jar
  
  	<<Binary file>>
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/lib/sisc.heap
  
  	<<Binary file>>
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/lib/sisc.jar
  
  	<<Binary file>>
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/scheme/test.scm
  
  Index: test.scm
  ===================================================================
  (define plus
     (lambda (a b)
        (+ a b)))
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/src/org/apache/cocoon/scheme/servlet/REPLEvalServlet.java
  
  Index: REPLEvalServlet.java
  ===================================================================
  package org.apache.cocoon.scheme.servlet;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.io.PrintStream;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import sisc.ContinuationException;
  import sisc.Interpreter;
  import sisc.data.Value;
  
  /**
   * Interactive Scheme evaluator. Use it only during development as it
   * is a big security risk.
   *
   * Receive the Scheme forms to evaluate via a POST message. Use the
   * Emacs minor mode to automatically submit a buffer or a region to
   * evaluate in the servlet.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since December  8, 2001
   */
  public class REPLEvalServlet extends REPLGenericServlet
  {
    protected boolean isEnabled = false;
    
    public void init(ServletConfig config)
      throws ServletException
    {
      super.init(config);
  
      String enabledString = config.getInitParameter("enabled");
      if (enabledString != null)
        isEnabled = enabledString.equalsIgnoreCase("true");
    }
  
    public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException
    {
      if (!isEnabled) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN,
                           "You're not authorized to access this URL!");
        return;
      }
  
      response.setContentType("text/plain");
  
      OutputStream os = response.getOutputStream();
      PrintStream out = new PrintStream(os);
      System.setErr(out);
  
      try {
        InputStream is = request.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        int size = 4096;
        int len;
        char[] buffer = new char[size];
        StringBuffer sbuf = new StringBuffer();
  
        while ((len = isr.read(buffer, 0, size)) > 0) {
          sbuf.append(buffer, 0, len);
        }
  
        System.out.println("executing '" + sbuf + "'");
        
        Value value = interpreter.eval(sbuf.toString());
        out.println(value.write());
      }
      catch (Exception ex) {
        out.println("ERROR: " + ex);
        throw new ServletException(ex);
      }
    }
  }
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/src/org/apache/cocoon/scheme/servlet/REPLGenericServlet.java
  
  Index: REPLGenericServlet.java
  ===================================================================
  package org.apache.cocoon.scheme.servlet;
  
  import java.io.BufferedInputStream;
  import java.io.DataInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.util.zip.GZIPInputStream;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.http.HttpServlet;
  import sisc.ContinuationException;
  import sisc.Interpreter;
  import sisc.data.Value;
  
  /**
   * Common functionality for REPL servlets. Reads the configuration
   * files and load the images specified in web.xml.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since December  8, 2001
   */
  public class REPLGenericServlet extends HttpServlet
  {
    protected Interpreter interpreter;
    protected ServletContext servletContext;
  
    public void init(ServletConfig config)
      throws ServletException
    {
      servletContext = config.getServletContext();
      interpreter = new Interpreter(System.in, System.out);
      interpreter.setEvaluator("eval");
      loadHeap(config.getInitParameter("sisc-heap"));
      loadHeap(config.getInitParameter("schecoon-heap"));
    }
  
    protected void loadHeap(String relativePath)
    {
      String realPath = servletContext.getRealPath("/");
      String heapFileName = realPath + relativePath;
      System.out.println("loading heap " + heapFileName);
      File heapFile = new File(heapFileName);
  
      try {
        FileInputStream fis = new FileInputStream(heapFileName);
        BufferedInputStream bis
          = new BufferedInputStream(fis, (int)heapFile.length());
        GZIPInputStream gzis = new GZIPInputStream(bis);
        DataInputStream dis = new DataInputStream(new BufferedInputStream(gzis));
        interpreter.loadEnv(dis);
        
      } catch (IOException e) {
        System.err.println("Error loading heap!");
        e.printStackTrace();
      }
    }
  }
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/src/org/apache/cocoon/scheme/servlet/REPLServlet.java
  
  Index: REPLServlet.java
  ===================================================================
  package org.apache.cocoon.scheme.servlet;
  
  import java.io.BufferedInputStream;
  import java.io.DataInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.util.zip.GZIPInputStream;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.http.HttpServlet;
  import sisc.ContinuationException;
  import sisc.Interpreter;
  import sisc.data.Value;
  
  /**
   * The entry point in the system. This servlet drives the processing
   * by executing the "service" Scheme function.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since December  8, 2001
   */
  public class REPLServlet extends REPLGenericServlet
  {
    public void service(ServletRequest request, ServletResponse response)
    {
      try {
        Value value = interpreter.eval("(plus 1 2)");
        System.out.println(value.write());
      }
      catch (Exception ex) {
        System.out.println("evaluation error: " + ex);
      }
    }
  }
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/src/org/apache/cocoon/scheme/util/SchemeServletCmdLine.java
  
  Index: SchemeServletCmdLine.java
  ===================================================================
  package org.apache.cocoon.scheme.util;
  
  import java.io.BufferedInputStream;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.io.OutputStreamWriter;
  import java.io.Writer;
  import java.net.Authenticator;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.PasswordAuthentication;
  import java.net.URL;
  import java.net.URLConnection;
  
  /**
   * REPL (Read Eval Print Loop) program that sends commands to a Scheme
   * interpreter running in a servlet. Assumes the URL uses basic
   * authentication.
   *
   * The best use of this REPL program is from within Emacs, as it will
   * have nice command history facilities.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since December  9, 2001
   */
  public class SchemeServletCmdLine
  {
    BufferedReader in;
    String url;
    
    public static void main(String[] args)
    {
      String url = "http://localhost:8080/schecoon/eval";
  
      if (args.length != 0) {
        if (args[0].indexOf("-h") != -1) {
          System.out.println("usage: SchemeServletCmdLine URL");
          System.exit(1);
        }
        else
          url = args[0];
      }
  
      new SchemeServletCmdLine(url).repl();
    }
  
    public SchemeServletCmdLine(String url)
    {
      Authenticator.setDefault(new CmdLineAuthenticator());
      in = new BufferedReader(new InputStreamReader(System.in));
      this.url = url;
    }
  
    public void repl()
    {
      while (true) {
        System.out.print("scheme> ");
  
        String evalString;
        try {
          evalString = in.readLine();
          if (evalString == null) {
            System.out.println("\nQuit.");
            return;
          }
        }
        catch (IOException ex) {
          System.out.println("Cannot read input line");
          continue;
        }
  
        try {
          URL schemeURL = new URL(url);
          HttpURLConnection conn = (HttpURLConnection)schemeURL.openConnection();
          conn.setDoOutput(true);
          conn.setDoInput(true);
          conn.setRequestMethod("POST");
  
          OutputStream out = conn.getOutputStream();
          Writer wout = new OutputStreamWriter(out, "UTF-8");
          wout.write(evalString);
          wout.flush();
          wout.close();
          
          InputStream is = conn.getInputStream();
          BufferedReader bin = new BufferedReader(new InputStreamReader(is));
          String line;
          while ((line = bin.readLine()) != null) {
            System.out.println(line);
          }
          is.close();
  
          conn.disconnect();
          
        } catch (MalformedURLException e) {
          System.out.println ("Invalid URL");
        } catch (IOException e) {
          System.out.println ("Error reading URL");
        }
      }
    }
  
    class CmdLineAuthenticator extends Authenticator
    {
      public CmdLineAuthenticator() {}
  
      protected PasswordAuthentication getPasswordAuthentication()
      {
        String username = null;
        String password = null;
  
        try {
          System.out.print("Username: ");
          username = in.readLine();
          System.out.print("Password: ");
          // FIXME: how to read the password securely? Java doesn't seem
          // to have a nice way to do it:
          // http://www.javaworld.com/javaworld/javaqa/2000-04/01-qa-0407-command.html
          password = in.readLine();
        }
        catch (IOException ex) {
          System.out.println("Caught exception " + ex);
          System.exit(1);
        }
  
        return new PasswordAuthentication(username, password.toCharArray());
      }
    }
  }
  
  
  
  1.1                  xml-cocoon2/scratchpad/schecoon/webapp/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
  
  <web-app>
    <display-name>Schecoon</display-name>
    <description>The Schecoon Web application</description>
    <servlet>
      <servlet-name>Schecoon</servlet-name>
      <display-name>Schecoon</display-name>
      <description>The main Schecoon servlet</description>
  
      <servlet-class>org.apache.cocoon.scheme.servlet.REPLServlet</servlet-class>
  
      <init-param>
        <param-name>sisc-heap</param-name>
        <param-value>sisc.heap</param-value>
      </init-param>
  
      <init-param>
        <param-name>schecoon-heap</param-name>
        <param-value>schecoon.heap</param-value>
      </init-param>
  
    </servlet>
  
    <servlet>
      <servlet-name>SchecoonEval</servlet-name>
      <display-name>Schecoon Interactive Evaluator</display-name>
      <description>The main Schecoon servlet</description>
  
      <servlet-class>org.apache.cocoon.scheme.servlet.REPLEvalServlet</servlet-class>
  
      <init-param>
        <param-name>enabled</param-name>
        <param-value>true</param-value>
      </init-param>
  
      <init-param>
        <param-name>sisc-heap</param-name>
        <param-value>sisc.heap</param-value>
      </init-param>
  
      <init-param>
        <param-name>schecoon-heap</param-name>
        <param-value>schecoon.heap</param-value>
      </init-param>
  
    </servlet>
  
    <servlet-mapping>
      <servlet-name>Schecoon</servlet-name>
      <url-pattern>/</url-pattern>
    </servlet-mapping>
  
    <servlet-mapping>
      <servlet-name>SchecoonEval</servlet-name>
      <url-pattern>/eval/*</url-pattern>
    </servlet-mapping>
  
    <security-constraint>
      <web-resource-collection>
        <web-resource-name>Protected Area</web-resource-name>
        <url-pattern>/eval/*</url-pattern>
        <http-method>POST</http-method>
      </web-resource-collection>
      <auth-constraint>
        <role-name>cocoon_admin</role-name>
      </auth-constraint>
    </security-constraint>
  
    <login-config>
      <auth-method>BASIC</auth-method>
      <realm-name>Admin</realm-name>
    </login-config>
  
  </web-app>
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message