You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2003/12/27 23:09:02 UTC

cvs commit: ws-jaxme .classpath

jochen      2003/12/27 14:09:02

  Modified:    prerequisites README
               .        .classpath
  Added:       src/webapp web.xml build.xml compile.jsp index.jsp
               src/webapp/java/org/apache/ws/jaxme/webapp BaseServlet.java
                        InitServlet.java JaxMeServlet.java
               prerequisites servlet.jar LICENSE-tomcat.txt
  Log:
  Added the "JaxMe Online" web application.
  
  Revision  Changes    Path
  1.1                  ws-jaxme/src/webapp/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!DOCTYPE web-app 
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
      "http://java.sun.com/dtd/web-app_2_3.dtd">
  
  <web-app>
  	<display-name>JaxMe Online</display-name>
      <description>
  	  This small web application allows access to run the
  	  JaxMe compiler on a remote schema. It returns a ZIP
  	  file with the generated sources.
      </description>
  
      <context-param>
        <param-name>work.dir</param-name>
        <param-value>C:/Prg/Tomcat4.1/work</param-value>
        <description>
          This parameter specifies the location of
      	the "work" directory. If such a location is
      	not set, the value ${java.io.tmpdir}
      	will be used.
  
          In either case, a subdirectory "jaxme" will be
          created, which is the actual working directory.
          The directory will be created or cleaned on
          startup by the InitServlet.
        </description>
      </context-param>
  
  	<context-param>
  		<param-name>http.proxyHost</param-name>
  		<param-value>httpprox.software-ag.de</param-value>
  		<description>
  			This parameter, if present and nonempty, contains the name of a proxy
  			host to use for connecting to remote URL's. If you set this parameter,
  			you must also set the "http.proxyPort" parameter.
  		</description>
  	</context-param>
  
  	<context-param>
  		<param-name>http.proxyPort</param-name>
  		<param-value>8080</param-value>
  		<description>
  			This parameter, if present and nonempty, contains the name of a proxy
  			host to use for connecting to remote URL's. If you set this parameter,
  			you must also set the "http.proxyPort" parameter.
  		</description>
  	</context-param>
  
      <servlet>
        <servlet-name>InitServlet</servlet-name>
        <description>
        	Loaded on startup to initialize the application. In particular,
        	it creates or cleans the working directory.
        </description>
        <servlet-class>org.apache.ws.jaxme.webapp.InitServlet</servlet-class>
        <!-- Load this servlet at server startup time -->
        <load-on-startup>1</load-on-startup>
      </servlet>
  
      <servlet>
        <servlet-name>JaxMeServlet</servlet-name>
        <description>
        	Invokes the JaxMe binding compiler.
        </description>
        <servlet-class>org.apache.ws.jaxme.webapp.JaxMeServlet</servlet-class>
      </servlet>
  
  	<servlet-mapping>
        <servlet-name>JaxMeServlet</servlet-name>
        <url-pattern>/jaxme</url-pattern>
      </servlet-mapping>
  </web-app>
  
  
  
  1.1                  ws-jaxme/src/webapp/build.xml
  
  Index: build.xml
  ===================================================================
  <project name="webapp" default="all">
    <!-- Make sure, that *all* targets (except those on which init depends)
         depend on init. Would be nice, if Ant could do that for us.
         All the properties below could as well be set in
         ${user.home}/.jaxme.properties or ${basedir}/jaxme.properties -->
    <target name="init">
  	<property name="jaxme.properties.location.1" location="${user.home}/.jaxme.properties"/>
  	<property name="jaxme.properties.location.2" location="${basedir}/jaxme.properties"/>
      <available file="${jaxme.properties.location.1}" property="jaxme.properties.location" value="${jaxme.properties.location.1}"/>
      <property name="jaxme.properties.location" location="${basedir}/jaxme.properties"/>
      <echo>Loading custom properties from ${jaxme.properties.location}</echo>
      <property file="${jaxme.properties.location}"/>
  
      <property name="build" location="${basedir}/../../build/webapp"/>
      <property name="build.classes" location="${build}/classes"/>
      <property name="preqs" location="${basedir}/../../prerequisites"/>
      <property name="dist" location="${basedir}/../../dist"/>
      <property name="debug" value="true"/>
      <property name="optimize" value="false"/>
      <property name="force" value="false"/>
      <property name="logLevel" value="warn"/>
      <property name="src" location="${basedir}/java"/>
  
  	<path id="jaxme.webapp.class.path">
  	  <pathelement location="${dist}/jaxmeapi.jar"/>
  	  <pathelement location="${dist}/jaxmexs.jar"/>
  	  <pathelement location="${dist}/jaxmejs.jar"/>
  	  <pathelement location="${dist}/jaxme2.jar"/>
  	  <pathelement location="${preqs}/servlet.jar"/>
  	</path>
    </target>
  
    <target name="clean" depends="init">
      <delete dir="${build}"/>
      <delete dir="${dist}/jaxme.war"/>
    </target>
  
    <target name="compile" depends="init">
      <mkdir dir="${build.classes}"/>
      <javac destdir="${build.classes}" srcdir="${src}" debug="${debug}"
             optimize="${optimize}" classpathref="jaxme.webapp.class.path"/>
    </target>
  
    <target name="check.tomcat.home" depends="init" unless="tomcat.home">
      <echo>You have not set the property tomcat.home in your jaxme.properties.</echo>
      <echo>The property indicates the directory, where your Tomcat is installed.</echo>
      <echo>The property may be set in ${jaxme.properties.location.1} or</echo>
      <echo>${jaxme.properties.location.2}.</echo>
      <fail>Missing tomcat.home property, terminating</fail>
    </target>
  
    <target name="all" depends="compile">
    </target>
  
    <target name="fastinstall" depends="all,check.tomcat.home">
      <mkdir dir="${tomcat.home}/webapps/jaxme/WEB-INF/classes"/>
      <copy todir="${tomcat.home}/webapps/jaxme/WEB-INF/classes">
        <fileset dir="${build.classes}"/>
      </copy>
      <copy todir="${tomcat.home}/webapps/jaxme">
        <fileset dir="${basedir}" includes="*.jsp"/>
      </copy>
      <copy todir="${tomcat.home}/webapps/jaxme/WEB-INF/lib">
        <fileset dir="${dist}" includes="jaxme*.jar"/>
      </copy>
      <copy todir="${tomcat.home}/webapps/jaxme/WEB-INF" overwrite="true">
        <fileset dir="${basedir}" includes="web.xml"/>
      </copy>
    </target>
  </project>
  
  
  
  1.1                  ws-jaxme/src/webapp/compile.jsp
  
  Index: compile.jsp
  ===================================================================
  <%
  	java.util.List errors = new java.util.ArrayList();
  	boolean isValidating = Boolean.valueOf(request.getParameter("isValidating")).booleanValue();
  	String url = request.getParameter("url");
  	if (url == null  ||  url.length() == 0) {
  		errors.add("The schema URL must not be empty.");
  	} else {
  		try {
  			new java.net.URL(url);
  		} catch (java.net.MalformedURLException e) {
  			errors.add("The schema URL " + url + " is invalid.");
  		}
  	}
  	String what = request.getParameter("what");
  	if (!"compile".equals(what)  &&  !"validate".equals(what)) {
  		errors.add("You must choose a proper action: Either 'compile' or 'validate'");
  	}
  		
  
  	if (errors.size() == 0) {
  		request.getRequestDispatcher("jaxme").forward(request, response);
  	} else {
  		%>
  			<html><head><title>JaxMe Online - Error Message</title></head>
  				<body><h1>JaxMe Online - Error Message</h1>
  					<p>Sorry, but we are unable to process your request, due to the
  						following problems:<ul>
  						<% for (java.util.Iterator iter = errors.iterator();  iter.hasNext();  ) { %>
  							<li><%= iter.next() %></li>
  						<% } %></ul>
  					<p>Please return to the <a href="javascript:history.back()">calling page</a>
  						and fix your input.</p>
  				</body>
  			</html>
  		<%
  	}
  %>
  
  
  
  1.1                  ws-jaxme/src/webapp/index.jsp
  
  Index: index.jsp
  ===================================================================
  <%
  	String url = request.getParameter("url");
  	if (url == null) {
  		url = "";
  	}
  
  	Boolean success = (Boolean) request.getAttribute("success");
  	boolean isValidating = Boolean.valueOf(request.getParameter("isValidating")).booleanValue();
  	ServletException e = (ServletException) request.getAttribute("error");
  
  	String what = request.getParameter("what");
  	boolean compiling = what == null  ||  "compile".equals(what);
  %>
  <html><head><title>JaxMe Online</title></head>
  	<body><h1>JaxMe Online</h1>
  		<p>This small web application allows you to run JaxMe online.
  			By entering a schema URL, the JaxMe compiler is invoked
  			and returns a ZIP file with the generated sources.</p>
  	    <form method="get" action="compile.jsp">
  	    	<table>
  	    		<tr><th align="right">URL:</th>
  	    	        <td><input type="text" name="url" value="<%= url %>"></input></td></tr>
  				<tr><th align="right">Action:</th>
  					<td><select name="what">
  						  <option value="compile">Compile using JaxMe</option>
  						  <option value="validate" <%= compiling ? "" : "\"selected\"" %>>Validate using JaxMeXS</option>
  						</select></td></tr>
  				<tr><th align="right">Validating parser:</th>
  					<td><select name="isValidating">
  						  <option value="false">No</option>
  						  <option value="true" <%= isValidating ? "\"selected\"" : ""%>>Yes</option>
  						</select></td></tr>
  	    	    <tr><td></td>
  	    	    	<td><input type="submit" value="Compile"></input></td></tr>
  	    	</table>
  	    </form>
  <%
  	if (success != null) {
  		if (success.booleanValue()) {
  			%><h3>Schema validation result</h3><p>The schema was validated successful.</p><%
  		} else {
  			%><h3>Schema validation result</h3><p>The schema was found to contain errors.</p><%
  		}
  	}
  	if (e != null) {
  		%><h3>Error Details</h3><pre><%
  		    Throwable t = e.getRootCause() == null ? e : e.getRootCause();
  		    t.printStackTrace(new java.io.PrintWriter(out));
  		%></pre><%
  	}
  %>
  	</body>
  </html>
  
  
  
  1.1                  ws-jaxme/src/webapp/java/org/apache/ws/jaxme/webapp/BaseServlet.java
  
  Index: BaseServlet.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   */
  package org.apache.ws.jaxme.webapp;
  
  import java.io.File;
  
  import javax.servlet.ServletException;
  import javax.servlet.UnavailableException;
  import javax.servlet.http.HttpServlet;
  
  
  public abstract class BaseServlet extends HttpServlet {
  	private static File workDir;
  	
  	public File getWorkDir() {
  		return workDir;
  	}
  
  	public void cleanDirectory(File pDirectory) throws ServletException {
  		File[] files = pDirectory.listFiles();
  		for (int i = 0;  i < files.length;  i++) {
  			File f = files[i];
  			if (f.isFile()) {
  				if (!f.delete()) {
  					throw new UnavailableException("Unable to delete file " + f.getAbsolutePath());
  				}
  			} else if (f.isDirectory()) {
  				cleanDirectory(f);
  				if (!f.delete()) {
  					throw new UnavailableException("Unable to delete directory " + f.getAbsolutePath());
  				}
  			} else {
  				throw new UnavailableException("Unable to determine how to remove " + f.getAbsolutePath());
  			}
  		}
  	}
  
  	public void createDirectory(File pDirectory) throws ServletException {
  		if (!pDirectory.mkdir()) {
  			throw new UnavailableException("Unable to create working directory " + pDirectory);
  		}
  	}
  
  	public void init() throws ServletException {
  		synchronized (BaseServlet.class) {
  			if (workDir == null) {
  				String p = getServletContext().getInitParameter("http.proxyHost");
  				if (p != null  &&  p.length() > 0) {
  					String v = getServletContext().getInitParameter("http.proxyPort");
  					if (v != null  &&  v.length() > 0) {
  						log("http.proxyHost parameter detected, setting host=" + p + ", port=" + v);
  						System.setProperty("http.proxyHost", p);
  						System.setProperty("http.proxyPort", v);
  					} else {
  						throw new UnavailableException("The http.proxyHost parameter is set, but the http.proxyPort parameter is not set.");
  					}
  				} else {
  					log("http.proxyHost parameter is not set");
  				}
  				String s = getServletContext().getInitParameter("work.dir");
  				File f;
  				if (s == null  ||  s.length() == 0) {
  					s = System.getProperty("java.io.tmpdir");
  					if (s == null  ||  s.length() == 0) {
  						throw new UnavailableException("Neither the servlet context parameter work.dir nor the system property java.io.tmpdir are set.");
  					}
  					f = new File(s);
  					if (!f.isDirectory()) {
  						throw new UnavailableException("The directory " + s + " (specified by the system property java.io.tmpdir) does not exist.");
  					}
  				} else {
  					f = new File(s);
  					if (!f.isDirectory()) {
  						throw new UnavailableException("The directory " + s + " (specified by the servlet context parameter work.dir) does not exist.");
  					}
  				}
  
  				File g = new File(f, "jaxme");
  				if (g.isDirectory()) {
  					cleanDirectory(g);
  				} else {
  					createDirectory(g);
  				}
  				workDir = g;
  			}
  		}
  	}
  }
  
  
  
  1.1                  ws-jaxme/src/webapp/java/org/apache/ws/jaxme/webapp/InitServlet.java
  
  Index: InitServlet.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   */
  package org.apache.ws.jaxme.webapp;
  
  
  /** <p>Initializes the "JaxMe online" application by creating and/or
   * cleaning the working directory.</p>
   */
  public class InitServlet extends BaseServlet {
  }
  
  
  
  1.1                  ws-jaxme/src/webapp/java/org/apache/ws/jaxme/webapp/JaxMeServlet.java
  
  Index: JaxMeServlet.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   */
  package org.apache.ws.jaxme.webapp;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipOutputStream;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.ws.jaxme.generator.Generator;
  import org.apache.ws.jaxme.generator.impl.GeneratorImpl;
  import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader;
  import org.apache.ws.jaxme.xs.XSParser;
  import org.xml.sax.EntityResolver;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  
  /** <p>This class invokes the JaxMe compiler.</p>
   */
  public class JaxMeServlet extends BaseServlet {
  	private class StoringEntityResolver implements EntityResolver {
  		private final File schemaDir;
  		private final Map urlMap = new HashMap();
  		public StoringEntityResolver(File pSchemaDir) {
  			schemaDir = pSchemaDir;
  		}
  		
  		public InputSource resolveEntity(String pPublicId, String pSystemId) throws SAXException, IOException {
  			try {
  				URL url = new URL(pSystemId);
  				String fileName = (String) urlMap.get(url);
  				if (fileName != null) {
  					FileInputStream istream = new FileInputStream(new File(schemaDir, fileName));
  					InputSource isource = new InputSource(istream);
  					isource.setSystemId(url.toString());
  					return isource;
  				}
  				
  				String file = url.getFile();
  				if (file == null) {
  					file = "";
  				} else {
  					int offset = file.lastIndexOf('/');
  					if (offset >= 0) {
  						file = file.substring(offset+1);
  					}
  				}
  				if ("".equals(file)) {
  					file = "schema.xsd";
  				}
  				int offset = file.lastIndexOf('.');
  				String prefix;
  				String suffix;
  				String numAsStr = "";
  				if (offset > 0  &&  offset < file.length()) {
  					prefix = file.substring(0, offset);
  					suffix = file.substring(offset);
  				} else {
  					prefix = file;
  					suffix = ".xsd";
  				}
  				File f;
  				for (int num = 1;  ;  ++num) {
  					f = new File(schemaDir, prefix + numAsStr + suffix);
  					if (f.exists()) {
  						numAsStr = "_" + num;
  					} else {
  						break;
  					}
  				}
  
  				InputStream istream = url.openStream();
  				schemaDir.mkdirs();
  				FileOutputStream fos = new FileOutputStream(f);
  				try {
  					byte[] buffer = new byte[1024];
  					for (;;) {
  						int res = istream.read(buffer);
  						if (res == -1) {
  							break;
  						} else if (res > 0) {
  							fos.write(buffer, 0, res);
  						}
  					}
  					istream.close();
  					fos.close();
  					fos = null;
  				} finally {
  					if (fos != null) { try { f.delete(); } catch (Throwable ignore) {} }
  				}
  
  				urlMap.put(url, f.getName());
  				InputSource isource = new InputSource(new FileInputStream(f));
  				isource.setSystemId(url.toString());
  				return isource;
  			} catch (Exception e) {
  				JaxMeServlet.this.log("Failed to resolve URL " + pSystemId, e);
  			}
  			return null;
  		}
  	}
  
  	public File createTempDir() throws IOException, ServletException {
  		File f = File.createTempFile("jaxme", ".tmp", getWorkDir());
  		f.delete();
  		if (!f.mkdir()) {
  			throw new ServletException("Unable to create temporary directory " + f.getAbsolutePath());
  		}
  		return f;
  	}
  
  	public void addContents(ZipOutputStream pZipFile, File pDirectory, String pDirName) throws IOException {
  		File[] files = pDirectory.listFiles();
  		for (int i = 0;  i < files.length;  i++) {
  			File f = files[i];
  			String name = pDirName.length() == 0 ? f.getName() : pDirName + "/" + f.getName();
  			if (f.isDirectory()) {
  				addContents(pZipFile, f, name);
  			} else if (f.isFile()) {
  				FileInputStream istream = new FileInputStream(f);
  				try {
  					ZipEntry zipEntry = new ZipEntry(name);
  					pZipFile.putNextEntry(zipEntry);
  					byte[] buffer = new byte[1024];
  					for (;;) {
  						int res = istream.read(buffer);
  						if (res == -1) {
  							break;
  						} else if (res > 0) {
  							pZipFile.write(buffer, 0, res);
  						}
  					}
  					pZipFile.closeEntry();
  					istream.close();
  					istream = null;
  				} finally {
  					if (istream != null) { try { istream.close(); } catch (Throwable ignore) {} }
  				}
  			}
  		}
  	}
  
  	public void removeDirectory(File pDirectory) throws ServletException {
  		cleanDirectory(pDirectory);
  		pDirectory.delete();
  	}
  
  	protected void doCompile(boolean pValidating, File pTempDir, URL pURL, HttpServletResponse pResponse)
  			throws ServletException, IOException {
  		Generator gen = new GeneratorImpl();
  		gen.setTargetDirectory(new File(pTempDir, "src"));
  		gen.setValidating(pValidating);
  		gen.setSchemaReader(new JAXBSchemaReader());
  		gen.setEntityResolver(new StoringEntityResolver(new File(pTempDir, "schema")));
  		try {
  			gen.generate(pURL);
  		} catch (Exception e) {
  			throw new ServletException(e);
  		}
  		
  		pResponse.setContentType("application/zip");
  		pResponse.setHeader("Content-Disposition", "attachment; filename=\"jaxmeGeneratedSrc.zip\"");
  		ZipOutputStream zipOutputStream = new ZipOutputStream(pResponse.getOutputStream());
  		addContents(zipOutputStream, pTempDir, "");
  		zipOutputStream.close();
  		removeDirectory(pTempDir);
  		pTempDir = null;
  	}
  
  	protected void doValidate(boolean pValidating, File pTempDir, URL pURL, HttpServletResponse pResponse)
  			throws ServletException, IOException {
  		XSParser parser = new XSParser();
  		parser.setValidating(pValidating);
  		InputSource isource = new InputSource(pURL.toString());
  		try {
  			parser.parse(isource);
  		} catch (Exception e) {
  			throw new ServletException(e);
  		}
  	}
  
  	public void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse)
  	    	throws ServletException, IOException {
  		String s = pRequest.getParameter("url");
  		if (s == null  ||  s.length() == 0) {
  			throw new ServletException("Missing or empty request parameter: " + s);
  		}
  		URL url;
  		try {
  			url = new URL(s);
  		} catch (MalformedURLException e) {
  			throw new ServletException("Malformed URL: " + s);
  		}
  		
  		boolean isValidating = Boolean.valueOf(pRequest.getParameter("isValidating")).booleanValue();
  		File f = createTempDir();
  
  		String what = pRequest.getParameter("what");
  
  		boolean forward = false;
  		try {
  			if ("compile".equals(what)) {
  				try {
  					doCompile(isValidating, f, url, pResponse);
  				} catch (ServletException e) {
  					pRequest.setAttribute("error", e);
  					forward = true;
  				}
  			} else if ("validate".equals(what)) {
  				doValidate(isValidating, f, url, pResponse);
  				pRequest.setAttribute("success", Boolean.TRUE);
  				forward = true;
  			} else {
  				throw new ServletException("You must choose a proper action: Either 'compile' or 'validate'.");
  			}
  
  			f = null;
  		} finally {
  			if (f != null) { try { removeDirectory(f); } catch (Throwable ignore) {} }
  		}
  
  		if (forward) {
  			pRequest.getRequestDispatcher("index.jsp").forward(pRequest, pResponse);
  		}
  	}
  
  	public void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse)
  			throws ServletException, IOException {
  		// No actual difference between GET and POST ...
  		doGet(pRequest, pResponse);
  	}
  }
  
  
  
  1.2       +2 -0      ws-jaxme/prerequisites/README
  
  Index: README
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/prerequisites/README,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- README	8 Oct 2003 08:43:39 -0000	1.1
  +++ README	27 Dec 2003 22:09:02 -0000	1.2
  @@ -36,3 +36,5 @@
   xmldb-api-sdk-20021118.jar
   		 This is the XML:DB API, as distributed with Xindice
   		 1.1b1. See http://xml.apache.org/xindice for details.
  +servlet.jar	 This file contains the servlet API, required to build
  +                 a web archive, as distributed with Tomcat 4.1.29.
  
  
  
  1.1                  ws-jaxme/prerequisites/servlet.jar
  
  	<<Binary file>>
  
  
  1.1                  ws-jaxme/prerequisites/LICENSE-tomcat.txt
  
  Index: LICENSE-tomcat.txt
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  The Apache Software Foundation.         *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "Tomcat",  and  "Apache  Software *
   *    Foundation"  must not be used  to endorse or promote  products derived *
   *    from this  software without  prior  written  permission.  For  written *
   *    permission, please contact <ap...@apache.org>.                        *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
   * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
   * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  /* CVS information: $Revision: 1.1 $ $Date: 2003/12/27 22:09:02 $
   * $Source: /home/cvs/ws-jaxme/prerequisites/LICENSE-tomcat.txt,v $
   * $Author: jochen $
   */
  
  
  
  1.5       +18 -16    ws-jaxme/.classpath
  
  Index: .classpath
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/.classpath,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- .classpath	20 Oct 2003 20:32:43 -0000	1.4
  +++ .classpath	27 Dec 2003 22:09:02 -0000	1.5
  @@ -1,19 +1,21 @@
   <?xml version="1.0" encoding="UTF-8"?>
   <classpath>
  -    <classpathentry kind="src" path="src/api"/>
  -    <classpathentry kind="src" path="src/js"/>
  -    <classpathentry kind="src" path="src/xs"/>
  -    <classpathentry kind="src" path="src/jaxme"/>
  -    <classpathentry kind="src" path="src/pm"/>
  -    <classpathentry kind="src" path="build/js/src"/>
  -    <classpathentry kind="src" path="build/jm/src"/>
  -    <classpathentry kind="src" path="build/jm/test/jaxme/src"/>
  -    <classpathentry kind="src" path="build/pm/test/src"/>
  -    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  -    <classpathentry kind="lib" path="prerequisites/xml-apis.jar"/>
  -    <classpathentry kind="lib" path="prerequisites/junit.jar"/>
  -    <classpathentry kind="lib" path="prerequisites/ant-1.5.4.jar"/>
  -    <classpathentry kind="lib" path="prerequisites/log4j-1.2.8.jar"/>
  -    <classpathentry kind="lib" path="prerequisites/xmldb-api-20021118.jar"/>
  -    <classpathentry kind="output" path="build/classes"/>
  +	<classpathentry kind="src" path="src/api"/>
  +	<classpathentry kind="src" path="src/js"/>
  +	<classpathentry kind="src" path="src/xs"/>
  +	<classpathentry kind="src" path="src/jaxme"/>
  +	<classpathentry kind="src" path="src/pm"/>
  +	<classpathentry kind="src" path="build/js/src"/>
  +	<classpathentry kind="src" path="build/jm/src"/>
  +	<classpathentry kind="src" path="build/jm/test/jaxme/src"/>
  +	<classpathentry kind="src" path="build/pm/test/src"/>
  +	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  +	<classpathentry kind="lib" path="prerequisites/xml-apis.jar"/>
  +	<classpathentry kind="lib" path="prerequisites/junit.jar"/>
  +	<classpathentry kind="lib" path="prerequisites/ant-1.5.4.jar"/>
  +	<classpathentry kind="lib" path="prerequisites/log4j-1.2.8.jar"/>
  +	<classpathentry kind="lib" path="prerequisites/xmldb-api-20021118.jar"/>
  +	<classpathentry kind="src" path="src/webapp/java"/>
  +	<classpathentry kind="lib" path="prerequisites/servlet.jar"/>
  +	<classpathentry kind="output" path="build/classes"/>
   </classpath>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org