vmassol     2003/06/11 07:48:39

  Modified:    integration/eclipse/org.apache.cactus.eclipse.webapp
                        plugin.xml
  Added:       
integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/internal
                        Webapp.java WarBuilder.java
               
integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/internal/ui
                        WebAppConfigurationBlock.java
                        WebAppPropertyPage.java WebappMessages.properties
                        WebappMessages.java WebappPlugin.java
  Removed:     
integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/ui
                        WebappPlugin.java WebappMessages.java
                        WebAppPropertyPage.java WebappMessages.properties
                        WebAppConfigurationBlock.java
               
integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp
                        WarBuilder.java Webapp.java
  Log:
  Follow Eclipse "API Rules of Engagement" 
(http://www.eclipse.org/articles/Article-API%20use/eclipse-api-usage-rules.html) for 
non public APIs.
  
  Revision  Changes    Path
  1.1                  
jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/internal/Webapp.java
  
  Index: Webapp.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 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", "Cactus" 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 [EMAIL PROTECTED]
   *
   * 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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.webapp.internal;
  
  import java.io.File;
  import java.util.StringTokenizer;
  import java.util.Vector;
  
  import org.apache.cactus.eclipse.webapp.internal.ui.WebappPlugin;
  import org.eclipse.core.resources.IProject;
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IPath;
  import org.eclipse.core.runtime.Path;
  import org.eclipse.core.runtime.QualifiedName;
  import org.eclipse.jdt.core.IClasspathEntry;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.jdt.core.JavaCore;
  import org.eclipse.jdt.core.JavaModelException;
  
  /**
   * Represents a web application for a given project.
   * It knows how to load its values from project properties and
   * how to persist them.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
   * @version $Id: Webapp.java,v 1.1 2003/06/11 14:48:26 vmassol Exp $
   */
  public class Webapp
  {
      /**
       * Delimiter for classpaths entries in the String that will be used
       * for persisting the webapp settings. 
       */
      private static final String CLASSPATH_DELIMITER = ";";
  
      /**
       * Qualified name of the output war property. Used for persistence of 
       * project properties. 
       */
      private static final QualifiedName OUTPUT_QN =
          new QualifiedName(WebappPlugin.getPluginId(), "output");
  
      /**
       * Qualified name of the webapp directory property. Used for persistence 
       * of project properties. 
       */
      private static final QualifiedName DIR_QN =
          new QualifiedName(WebappPlugin.getPluginId(), "dir");
  
      /**
       * Qualified name of the classpath property. Used for persistence of 
       * project properties. 
       */
      private static final QualifiedName CLASSPATH_QN =
          new QualifiedName(WebappPlugin.getPluginId(), "webappClasspath");
  
      /**
       * Default path for the generated war 
       */
      private static final String DEFAULT_OUTPUT =
          System.getProperty("java.io.tmpdir") + "webapp.war";
  
      /**
       * Default directory of where the webapp is located. 
       */
      private static final String DEFAULT_DIR =
          "src" + File.separator + "webapp";
              
      /**
       * Full path to the webapp War.
       */
      private String output;
  
      /**
       * Directory of the webapp relative to the user's project. 
       */
      private String dir;
  
      /**
       * Paths to the webapp libraries
       */
      private IClasspathEntry[] classpath;
  
      /**
       * The current project to which this webapp refers.  
       */
      private IJavaProject javaProject;
  
      /**
       * @param theJavaProject the project this webapp is linked to
       */
      public Webapp(IJavaProject theJavaProject)
      {
          this.javaProject = theJavaProject;
      }
  
      /**
       * Initialize the web app properties with default values or stored values
       * if they exist. 
       * @return boolean true if we loaded the default values
       */
      public boolean init()
      {
          return loadValues();
      }
  
      /**
       * Loads this webapp from the project properties. If the persistent
       * properties cannot be loaded or if a value is not set, we load the 
       * default values.
       * 
       * @return true if the default values were loaded or false if the 
       *         persistent ones were loaded
       */
      public boolean loadValues()
      {
          boolean isDefaultValues;
  
          try
          {
              loadPersistentValues();
              isDefaultValues = false;
          }
          catch (CoreException ce)
          {
              loadDefaultValues();
              isDefaultValues = true;
          }
  
          if (output == null
              || dir == null
              || classpath == null)
          {
              loadDefaultValues();
              isDefaultValues = true;
          }
  
          return isDefaultValues;
      }
  
      /**
       * Loads the persistent properties for this webapp.
       * @throws CoreException if we fail to load a persistent property
       */
      public void loadPersistentValues() throws CoreException
      {
          IProject theProject = javaProject.getProject();
  
          this.output = theProject.getPersistentProperty(OUTPUT_QN);
          this.dir = theProject.getPersistentProperty(DIR_QN);
          this.classpath = toClasspathEntryArray(
              theProject.getPersistentProperty(CLASSPATH_QN));
      }
  
      /**
       *  Loads the default values of a webapp.
       */
      public void loadDefaultValues()
      {
          this.output = DEFAULT_OUTPUT;
          this.dir = DEFAULT_DIR;
  
          try
          {
              this.classpath = javaProject.getRawClasspath();
          }
          catch (JavaModelException e)
          {
              this.classpath = new IClasspathEntry[0];
          }
      }
  
      /**
       * Saves this webapp in the project's properties
       * @throws CoreException if an error occurs while saving 
       */
      public void persist() throws CoreException
      {
          IProject project = javaProject.getProject();
          project.setPersistentProperty(OUTPUT_QN, output);
          project.setPersistentProperty(DIR_QN, dir);
          project.setPersistentProperty(CLASSPATH_QN, toString(classpath));
      }
  
      /**
       * Converts a String classpath to an array of library classpath entries.
       * @param theClasspathEntriesString string of delimiter-separated 
       *        classpaths
       * @return an array of library entries
       */
      private IClasspathEntry[] toClasspathEntryArray(
          String theClasspathEntriesString)
      {
          if (theClasspathEntriesString == null)
          {
              return null;
          }
  
          Vector result = new Vector();
  
          StringTokenizer cpTokenizer =
              new StringTokenizer(theClasspathEntriesString, 
              CLASSPATH_DELIMITER);
              
          while (cpTokenizer.hasMoreElements())
          {
              String element = cpTokenizer.nextToken();
              try
              {
                  IClasspathEntry newEntry =
                      JavaCore.newLibraryEntry(new Path(element), null, null);
                  result.add(newEntry);
              }
              catch (Exception e)
              {
                  // Do not add the entry
              }
          }
  
          return (IClasspathEntry[]) result.toArray(
              new IClasspathEntry[result.size()]);
      }
  
      /**
       * Converts an array of library classpath entries to a String 
       * @param theClasspathEntries an array of library entries
       * @return String string of delimiter-separated classpaths
       */
      private String toString(IClasspathEntry[] theClasspathEntries)
      {
          StringBuffer result = new StringBuffer();
          for (int i = 0; i < theClasspathEntries.length; i++)
          {
              IClasspathEntry current = theClasspathEntries[i];
              result.append(current.getPath());
              result.append(CLASSPATH_DELIMITER);
          }
          return result.toString();
      }
  
      /**
       * Sets the classpath.
       * @param theClasspath The classpath to set
       */
      public void setClasspath(IClasspathEntry[] theClasspath)
      {
          this.classpath = theClasspath;
      }
  
      /**
       * Sets the dir.
       * @param theDir The dir to set
       */
      public void setDir(String theDir)
      {
          this.dir = theDir;
      }
  
      /**
       * Sets the output.
       * @param theOutput The output to set
       */
      public void setOutput(String theOutput)
      {
          this.output = theOutput;
      }
  
      /**
       * @return IClasspathEntry[] the array of jar entries for this webapp
       */
      public IClasspathEntry[] getClasspath()
      {
          return this.classpath;
      }
  
      /**
       * @return String directory of this webapp source files
       * relative to the project path 
       */
      public String getDir()
      {
          return this.dir;
      }
      
      /**
       * @return the absolute directory to this webapp source files
       */
      public File getAbsoluteDir()
      {
          File result = null;
  
          if (this.dir != null)
          {
              IPath projectPath = javaProject.getProject().getLocation();
              result = projectPath.append(this.dir).toFile();
          } 
          return result; 
      }
  
      /**
       * @return String location of the generated war
       */
      public String getOutput()
      {
          return this.output;
      }
  }
  
  
  
  1.1                  
jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/internal/WarBuilder.java
  
  Index: WarBuilder.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 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", "Cactus" 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 [EMAIL PROTECTED]
   *
   * 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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.webapp.internal;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.Vector;
  
  import org.apache.cactus.eclipse.webapp.internal.ui.WebappMessages;
  import org.apache.cactus.eclipse.webapp.internal.ui.WebappPlugin;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.taskdefs.Copy;
  import org.apache.tools.ant.taskdefs.War;
  import org.apache.tools.ant.taskdefs.Zip;
  import org.apache.tools.ant.types.FileSet;
  import org.apache.tools.ant.types.ZipFileSet;
  import org.eclipse.core.resources.IFile;
  import org.eclipse.core.resources.ResourcesPlugin;
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IPath;
  import org.eclipse.core.runtime.IProgressMonitor;
  import org.eclipse.core.runtime.IStatus;
  import org.eclipse.core.runtime.NullProgressMonitor;
  import org.eclipse.core.runtime.Path;
  import org.eclipse.core.runtime.Status;
  import org.eclipse.jdt.core.IClasspathEntry;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.jdt.core.JavaCore;
  import org.eclipse.jdt.core.JavaModelException;
  import org.eclipse.jdt.internal.core.JavaModel;
  
  /**
   * Helper class for creating War files.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
   * @version $Id: WarBuilder.java,v 1.1 2003/06/11 14:48:28 vmassol Exp $
   */
  public class WarBuilder
  {
      /**
       * The Java project to build the war from
       */
      private IJavaProject javaProject;
  
      /**
       * The Webapp object that stores webapp preferences 
       */
      private Webapp webapp;
  
      /**
       * Name of the WEB-INF directory
       */
      public static final String WEBINF = "WEB-INF";
  
      /**
       * Name of the lib directory
       */
      public static final String LIB = "lib";
  
      /**
       * Name of the web.xml file
       */
      public static final String WEBXML = "web.xml";
  
      /**
       * @param theJavaProject the Java project for which the webapp will be 
       *        created
       * @throws JavaModelException if we can't get the output location
       */
      public WarBuilder(IJavaProject theJavaProject) throws JavaModelException
      {
          this.javaProject = theJavaProject;
          this.webapp = new Webapp(theJavaProject);
      }
  
      /**
       * @param theWebFilesDir webapp directory to get the web.xml from
       * @return the web.xml file in the given webapp directory,
       *  or null if none
       */
      public File getWebXML(File theWebFilesDir)
      {
          if (theWebFilesDir == null)
          {
              return null;
          }
          else
          {
              String userWebXMLPath =
                  theWebFilesDir.getAbsolutePath()
                      + File.separator
                      + WEBINF
                      + File.separator
                      + WEBXML;
              return new File(userWebXMLPath);
          }
      }
      /**
       * For each IClasspathEntry transform the path in an absolute path.
       * @param theEntries array of IClasspathEntry to render asbolute
       * @return an array of absolute IClasspathEntries
       */
      private IClasspathEntry[] getAbsoluteEntries(IClasspathEntry[] theEntries)
      {
          if (theEntries == null)
          {
              return new IClasspathEntry[0];
          }
          Vector result = new Vector();
          for (int i = 0; i < theEntries.length; i++)
          {
              IClasspathEntry currentEntry = theEntries[i];
              if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
              {
                  IPath path = currentEntry.getPath();
                  Object target =
                      JavaModel.getTarget(
                          ResourcesPlugin.getWorkspace().getRoot(),
                          path,
                          true);
                  if (target instanceof IFile)
                  {
                      IFile file = (IFile) target;
                      IPath absolutePath = file.getLocation();
                      result.add(
                          JavaCore.newLibraryEntry(absolutePath, null, null));
                  }
                  else
                      if (target instanceof File)
                      {
                          File file = (File) target;
                          result.add(
                              JavaCore.newLibraryEntry(
                                  new Path(file.getAbsolutePath()),
                                  null,
                                  null));
                      }
              }
          }
          return (IClasspathEntry[]) result.toArray(
              new IClasspathEntry[result.size()]);
      }
  
      /**
       * @param theJavaProject the java project for which we want to get the
       *        absolute output path 
       * @return the absolute project output path
       * @throws JavaModelException if we fail to get the project relative 
       *         output location
       */
      private File getAbsoluteOutputLocation(IJavaProject theJavaProject)
          throws JavaModelException
      {
          IPath projectPath = theJavaProject.getProject().getLocation();
          IPath outputLocation = theJavaProject.getOutputLocation();
          IPath classFilesPath =
              projectPath.append(outputLocation.removeFirstSegments(1));
          return classFilesPath.toFile();
      }
  
      /**
       * Creates the war file.
       * @param thePM a monitor that reflects the overall progress,
       *  or null if none is to be used.
       * @return File the location where the war file was created
       * @throws CoreException if we can't create the file
       */
      public File createWar(IProgressMonitor thePM) throws CoreException
      {
          IProgressMonitor progressMonitor =
              (thePM != null) ? thePM : new NullProgressMonitor();
          progressMonitor.subTask(
              WebappMessages.getString("WarBuilder.message.createwar.monitor"));
          this.webapp.loadValues();
          File outputWar = getOutputWar();
          File userWebFilesDir = getUserWebFilesDir();
          File userWebXML = getWebXML(userWebFilesDir);
          IClasspathEntry[] jarEntries = getJarEntries();
          File userClassFilesDir = getAbsoluteOutputLocation(this.javaProject);
          
          outputWar.delete();
          War warTask = new War();
          progressMonitor.worked(1);
          Project antProject = new Project();
          antProject.init();
          warTask.setProject(antProject);
          warTask.setDestFile(outputWar);
          ZipFileSet classes = new ZipFileSet();
          classes.setDir(userClassFilesDir);
          warTask.addClasses(classes);
          classes = new ZipFileSet();
          classes.setDir(userClassFilesDir);
          classes.setIncludes("log4j.properties");
          warTask.addClasses(classes);
          if (userWebFilesDir != null && userWebFilesDir.exists())
          {
              FileSet webFiles = new FileSet();
              webFiles.setDir(userWebFilesDir);
              webFiles.setExcludes(WEBINF);
              warTask.addFileset(webFiles);
          }
          if (userWebXML != null && userWebXML.exists())
          {
              warTask.setWebxml(userWebXML);
          }
          else
          {
              // Without a webxml attribute the Ant war task
              // requires the update attribute set to true
              // That's why we actually need an existing war file.
              try
              {
                  // A file is needed for war creation
                  File voidFile = File.createTempFile("void", null);
                  createZipFile(outputWar, voidFile);
                  voidFile.delete();
              }
              catch (IOException e)
              {
                  throw new CoreException(
                      new Status(
                          IStatus.ERROR,
                          WebappPlugin.getPluginId(),
                          IStatus.OK,
                          WebappMessages.getString(
                              "WarBuilder.message.createwar.temp"),
                          e));
              }
  
              warTask.setUpdate(true);
          }
  
          ZipFileSet[] jarFS = getZipFileSets(jarEntries);
          for (int i = 0; i < jarFS.length; i++)
          {
              warTask.addLib(jarFS[i]);
          }
          warTask.execute();
          progressMonitor.worked(2);
          return outputWar;
      }
  
      /**
       * @param theJarEntries the jars to build ZipFileSets from
       * @return an array of ZipFileSet corresponding to the given jars
       */
      private ZipFileSet[] getZipFileSets(IClasspathEntry[] theJarEntries)
      {
          Vector result = new Vector();
          for (int i = 0; i < theJarEntries.length; i++)
          {
  
              IClasspathEntry currentEntry = theJarEntries[i];
              if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
              {
                  File currentJar = currentEntry.getPath().toFile();
                  ZipFileSet zipFS = new ZipFileSet();
                  zipFS.setFile(currentJar);
                  result.add(zipFS);
              }
          }
          return (ZipFileSet[]) result.toArray(new ZipFileSet[result.size()]);
      }
  
      /**
       * @return the web application folder situated in the user's project
       */
      private File getUserWebFilesDir()
      {
          // path to the web directory relative to the user's project
          String userWebFilesPath = webapp.getDir();
          if (userWebFilesPath == null || userWebFilesPath.equals(""))
          {
              return null;
          }
          else
          {
              IPath projectPath = this.javaProject.getProject().getLocation();
  
              // web application folder situated in the user's project
              return projectPath.append(userWebFilesPath).toFile();
          }
      }
  
      /**
       * @return the jar entries
       */
      private IClasspathEntry[] getJarEntries()
      {
          return getAbsoluteEntries(webapp.getClasspath());
      }
  
      /**
       * @return the output war file
       */
      private File getOutputWar()
      {
          return new File(webapp.getOutput());
      }
  
      /**
       * Copies a set of Jar files to the destination directory.
       * @param theEntries set of Jars
       * @param theDestination the destination directory 
       */
      private void copyJars(IClasspathEntry[] theEntries, File theDestination)
      {
          if (!theDestination.isDirectory())
          {
              return;
          }
          Project antProject = new Project();
          antProject.init();
          Copy jarCopy = new Copy();
          jarCopy.setProject(antProject);
          jarCopy.setTodir(theDestination);
          for (int i = 0; i < theEntries.length; i++)
          {
              IClasspathEntry currentEntry = theEntries[i];
              if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
              {
                  File currentJar = currentEntry.getPath().toFile();
                  FileSet fileSet = new FileSet();
                  fileSet.setFile(currentJar);
                  jarCopy.addFileset(fileSet);
              }
          }
          jarCopy.execute();
      }
  
      /**
       * Removes the specified file or directory, and all subdirectories
       * @param theFile the file or directory to delete
       */
      public static void delete(File theFile)
      {
          if (theFile.isDirectory())
          {
              File[] dir = theFile.listFiles();
              for (int i = 0; i < dir.length; i++)
              {
                  delete(dir[i]);
              }
              theFile.delete();
          }
          else
              if (theFile.exists())
              {
                  theFile.delete();
              }
      }
  
      /**
       * Creates a zip file containing the given existing file. 
       * @param theZipFile the zip file to create
       * @param theExistingFile the file to include in the zip
       */
      private void createZipFile(File theZipFile, File theExistingFile)
      {
          Project antProject = new Project();
          antProject.init();
          Zip zip = new Zip();
          zip.setProject(antProject);
          zip.setDestFile(theZipFile);
          FileSet existingFileSet = new FileSet();
          existingFileSet.setFile(theExistingFile);
          zip.addFileset(existingFileSet);
          zip.execute();
      }
  
  }
  
  
  
  1.1                  
jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/internal/ui/WebAppConfigurationBlock.java
  
  Index: WebAppConfigurationBlock.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 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", "Cactus" 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 [EMAIL PROTECTED]
   *
   * 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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.webapp.internal.ui;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Vector;
  
  import org.eclipse.core.resources.IWorkspaceRoot;
  import org.eclipse.jdt.core.IClasspathEntry;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.jdt.internal.ui.JavaPlugin;
  import org.eclipse.jdt.internal.ui.preferences.PreferencesMessages;
  import org.eclipse.jdt.internal.ui.util.PixelConverter;
  import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
  import org.eclipse.jdt.internal.ui.wizards.buildpaths.LibrariesWorkbookPage;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.CheckedListDialogField;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
  import org.eclipse.jface.viewers.LabelProvider;
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.layout.GridData;
  import org.eclipse.swt.layout.GridLayout;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Control;
  import org.eclipse.swt.widgets.FileDialog;
  import org.eclipse.swt.widgets.Shell;
  
  /**
   * UI block which shows a list of jar entries.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
   * @version $Id: WebAppConfigurationBlock.java,v 1.1 2003/06/11 14:48:29 vmassol Exp 
$
   */
  public class WebAppConfigurationBlock
  {
      /**
       * Field for the output war location. 
       */
      private StringButtonDialogField outputField;
  
      /**
       * Field for the webapp location. 
       */
      private StringDialogField webappDirField;
  
      /**
       * UI block that shows a list of jar entries. 
       */
      private LibrariesWorkbookPage libraryPage;
  
      /**
       * List of entries displayed by the libraryPage. 
       */
      private CheckedListDialogField classPathList;
  
      /**
       * Java project needed for the libraryPage initialization. 
       */
      private IJavaProject javaProject;
  
      /**
       * The shell used by dialog popups (directory and file choosers). 
       */
      private Shell shell;
  
      /**
       * Constructor.
       * @param theShell The shell used by dialog popups
       *     (directory and file choosers)
       * @param theJavaProject Java project needed for libraryPage initialization
       * @param theOutput initial output field value
       * @param theDir initial webapp directory value
       * @param theEntries initial list of entries
       */
      public WebAppConfigurationBlock(
          Shell theShell,
          IJavaProject theJavaProject,
          String theOutput,
          String theDir,
          IClasspathEntry[] theEntries)
      {
          shell = theShell;
          javaProject = theJavaProject;
          BuildPathAdapter adapter = new BuildPathAdapter();
  
          classPathList =
              new CheckedListDialogField(null, null, new LabelProvider());
          classPathList.setDialogFieldListener(adapter);
          IWorkspaceRoot root = JavaPlugin.getWorkspace().getRoot();
          libraryPage = new LibrariesWorkbookPage(root, classPathList);
          outputField = new StringButtonDialogField(adapter);
          outputField.setDialogFieldListener(adapter);
          outputField.setLabelText(
              WebappMessages.getString(
                  "WebAppConfigurationBlock.outputfield.label"));
          outputField.setButtonLabel(
              WebappMessages.getString(
                  "WebAppConfigurationBlock.outputfield.button.label"));
  
          webappDirField = new StringDialogField();
          webappDirField.setDialogFieldListener(adapter);
          webappDirField.setLabelText(
              WebappMessages.getString(
                  "WebAppConfigurationBlock.webappdirfield.label"));
          update(theOutput, theDir, theEntries);
      }
  
      /**
       * Adapter that displatches control events.
       */
      private class BuildPathAdapter
          implements IStringButtonAdapter, IDialogFieldListener
      {
  
          /**
           * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.
           *     IStringButtonAdapter#changeControlPressed(
           *     org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
           */
          public void changeControlPressed(DialogField theField)
          {
              webappChangeControlPressed(theField);
          }
  
          /**
           * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.
           *     IDialogFieldListener#dialogFieldChanged(
           *     org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
           */
          public void dialogFieldChanged(DialogField theField)
          {
              webappDialogFieldChanged(theField);
          }
      }
  
      /**
       * Adapter that dispatches events from Dialog fields.
       * Possible use : validation of an entry in a dialog field.
       * @param theField field that triggered an event.
       */
      private void webappDialogFieldChanged(DialogField theField)
      {
          // TODO: validate entries in dialogs
          // Do nothing.
      }
  
      /**
       * Adapter that dispatches events from StringButtonDialog fields.
       * @param theField field that triggered an event.
       */
      private void webappChangeControlPressed(DialogField theField)
      {
              if (theField == outputField)
              {
                  File output = chooseOutput();
                  if (output != null)
                  {
                      outputField.setText(output.getAbsolutePath());
                  }
              }
      }
  
      /**
       * Displays a file chooser dialog and returns the chosen file.
       * @return File the chosen file
       */
      private File chooseOutput()
      {
          File output = new File(outputField.getText());
          String initPath = "";
          String initFileName = "webapp.war";
  
          if (output != null)
          {
              if (!output.isDirectory())
              {
                  File dir = output.getParentFile();
                  if (dir != null)
                  {
                      initPath = dir.getPath();
                  }
                  initFileName = output.getName();
              }
              else
              {
                  initPath = output.getPath();
              }
          }
          FileDialog dialog = new FileDialog(shell);
          dialog.setText(
              PreferencesMessages.getString(
                  WebappMessages.getString(
                      "WebAppConfigurationBlock.outputchooser.label")));
          dialog.setFileName(initFileName);
          dialog.setFilterExtensions(new String[] {"*.war"});
          dialog.setFilterPath(initPath);
          String res = dialog.open();
          if (res != null)
          {
              return (new File(res));
          }
          return null;
      }
  
  
      /**
       * Returns the UI control for this block.
       * @param theParent the parent control.
       * @return Control the created control
       */
      public Control createContents(Composite theParent)
      {
          Composite topComp = new Composite(theParent, SWT.NONE);
  
          GridLayout topLayout = new GridLayout();
          topLayout.numColumns = 3;
          topLayout.marginWidth = 0;
          topLayout.marginHeight = 0;
          topComp.setLayout(topLayout);
  
          outputField.doFillIntoGrid(topComp, 3);
          webappDirField.doFillIntoGrid(topComp, 3);
  
          PixelConverter converter = new PixelConverter(topComp);
          LayoutUtil.setWidthHint(
              outputField.getTextControl(null),
              converter.convertWidthInCharsToPixels(25));
          LayoutUtil.setHorizontalGrabbing(outputField.getTextControl(null));
  
          Control libraryPageControl = libraryPage.getControl(topComp);
          GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
          gd.horizontalSpan = 3;
          libraryPageControl.setLayoutData(gd);
          libraryPage.init(javaProject);
          return topComp;
      }
  
      /**
       * Returns the text entered in the output field.
       * @return String the text entered
       */
      public String getOutput()
      {
          return outputField.getText();
      }
  
      /**
       * Returns the text entered in the webapp field.
       * @return String the text entered
       */
      public String getWebappDir()
      {
          return webappDirField.getText();
      }
  
      /**
       * Returns the array of jar entries selected in the libraryPage.
       * @return IClasspathEntry[] the array of jar entries selected
       */
      public IClasspathEntry[] getWebappClasspath()
      {
          Vector result = new Vector();
          List cplist = classPathList.getElements();
          for (int i = 0; i < cplist.size(); i++)
          {
              CPListElement elem = (CPListElement) cplist.get(i);
              if (elem.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
              {
                  result.add(elem.getClasspathEntry());
              }
          }
          return (IClasspathEntry[]) result.toArray(
              new IClasspathEntry[result.size()]);
      }
  
      /**
       * Returns a list of jar entries contained in an array of entries.
       * @param theClasspathEntries array of classpath entries 
       * @return ArrayList list containing the jar entries
       */
      private ArrayList getExistingEntries(IClasspathEntry[] theClasspathEntries)
      {
          ArrayList newClassPath = new ArrayList();
          for (int i = 0; i < theClasspathEntries.length; i++)
          {
              IClasspathEntry curr = theClasspathEntries[i];
              if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
              {
                  try
                  {
                      newClassPath.add(
                          CPListElement.createFromExisting(curr, javaProject));
                  }
                  catch (NullPointerException e)
                  {
                      // an error occured when parsing the entry
                      // (possibly invalid entry)
                      // We don't add it
                  }
              }
          }
          return newClassPath;
  
      }
  
      /**
       * Refreshes the control with the given values.
       * @param theOutput webapp output war location 
       * @param theDir webapp directory
       * @param theEntries jar entries for the webapp
       */
      public void update(
          String theOutput,
          String theDir,
          IClasspathEntry[] theEntries)
      {
          outputField.setText(theOutput);
          webappDirField.setText(theDir);
          classPathList.setElements(getExistingEntries(theEntries));
      }
  
      /**
       * Refreshes the control.
       */
      public void refresh()
      {
          libraryPage.init(javaProject);
      }
  }
  
  
  
  1.1                  
jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/internal/ui/WebAppPropertyPage.java
  
  Index: WebAppPropertyPage.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 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", "Cactus" 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 [EMAIL PROTECTED]
   *
   * 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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.webapp.internal.ui;
  
  import org.apache.cactus.eclipse.webapp.internal.Webapp;
  import org.eclipse.core.resources.IProject;
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IAdaptable;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.jdt.core.JavaCore;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Control;
  import org.eclipse.ui.dialogs.PropertyPage;
  
  /**
   * Property page for the web application.
   * It is displayed in project's property pages.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
   * @version $Id: WebAppPropertyPage.java,v 1.1 2003/06/11 14:48:30 vmassol Exp $
   */
  public class WebAppPropertyPage extends PropertyPage
  {
      /**
       * The only UI block for this property page. 
       */
      private WebAppConfigurationBlock webAppConfigurationBlock;
  
      /**
       * The webapp object that is loaded or persisted. 
       */
      private Webapp webapp;
  
      /**
       * @see org.eclipse.jface.preference.PreferencePage#createContents(
       *     org.eclipse.swt.widgets.Composite)
       */
      protected Control createContents(Composite theParent)
      {
          IJavaProject javaProject = JavaCore.create(getProject());
          webapp = new Webapp(javaProject);
          boolean loadedDefaults = webapp.init();
          if (loadedDefaults)
          {
              // Status line indicating we loaded the defaults 
          }
          webAppConfigurationBlock =
              new WebAppConfigurationBlock(
                  getShell(),
                  javaProject,
                  webapp.getOutput(),
                  webapp.getDir(),
                  webapp.getClasspath());
          return webAppConfigurationBlock.createContents(theParent);
      }
  
      /**
       * @see org.eclipse.jface.preference.PreferencePage#performOk()
       */
      public boolean performOk()
      {
          webapp.setOutput(webAppConfigurationBlock.getOutput());
          webapp.setDir(webAppConfigurationBlock.getWebappDir());
          webapp.setClasspath(webAppConfigurationBlock.getWebappClasspath());
          try
          {
              webapp.persist();
          }
          catch (CoreException e)
          {
              //TODO: update status line
              return false;
          }
          return true;
      }
  
      /**
       * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
       */
      public void performDefaults()
      {
          super.performDefaults();
          webapp.loadDefaultValues();
          webAppConfigurationBlock.update(
              webapp.getOutput(),
              webapp.getDir(),
              webapp.getClasspath());
          webAppConfigurationBlock.refresh();
      }
  
      /**
       * Returns the project on which this property page has been called.
       * @return the current project
       */
      private IProject getProject()
      {
          IAdaptable adaptable = getElement();
          IProject elem = (IProject) adaptable.getAdapter(IProject.class);
          return elem;
      }
  }
  
  
  
  1.1                  
jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/internal/ui/WebappMessages.properties
  
  Index: WebappMessages.properties
  ===================================================================
  # ---------------------------------------------------------------------------
  # Messages that will be shown in the Cactus UI
  #
  # Version $Id: WebappMessages.properties,v 1.1 2003/06/11 14:48:30 vmassol Exp $
  # ---------------------------------------------------------------------------
  
  WarBuilder.message.createwar.monitor = Creating the WAR file
  WarBuilder.message.createwar.temp = Could not create temporary file
  
  WebAppConfigurationBlock.outputfield.label = Output war
  WebAppConfigurationBlock.outputfield.button.label = Browse...
  WebAppConfigurationBlock.webappdirfield.label = Webapp directory
  WebAppConfigurationBlock.tempdirfield.label = Temporary directory
  WebAppConfigurationBlock.tempdirfield.button.label = Browse...
  WebAppConfigurationBlock.outputchooser.label = War file selection
  WebAppConfigurationBlock.tempdirchooser.label = Temp directory selection
  WebAppConfigurationBlock.tempdirchooser.title.label = Select temp directory:
  
  
  
  1.1                  
jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/internal/ui/WebappMessages.java
  
  Index: WebappMessages.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 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", "Cactus" 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 [EMAIL PROTECTED]
   *
   * 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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.webapp.internal.ui;
  
  import java.text.MessageFormat;
  import java.util.MissingResourceException;
  import java.util.ResourceBundle;
  
  /**
   * Helper class to format text messages from the Cactus property resource 
   * bundle.
   * 
   * @version $Id: WebappMessages.java,v 1.1 2003/06/11 14:48:30 vmassol Exp $
   * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
   */
  public final class WebappMessages
  {
      /**
       * Name and location of property resource bundle on disk.
       */
      private static final String BUNDLE_NAME =
          "org.apache.cactus.eclipse.webapp.internal.ui.WebappMessages";
  
      /**
       * The resource bundle object were Cactus messages are stored.
       */
      private static final ResourceBundle RESOURCE_BUNDLE = 
          ResourceBundle.getBundle(BUNDLE_NAME);
  
      /**
       * Prevent this class from being instantiated. It contains only static
       * methods.
       */
      private WebappMessages()
      {
      }
  
      /**
       * Gets a string from the resource bundle and formats it with one argument.
       * 
       * @param theKey the string used to get the bundle value, must not be null
       * @param theArg the object to use when constructing the message
       * @return the formatted string
       */
      public static String getFormattedString(String theKey, Object theArg)
      {
          return MessageFormat.format(getString(theKey), 
              new Object[] {theArg});
      }
  
      /**
       * Gets a string from the resource bundle and formats it with arguments.
       * 
       * @param theKey the string used to get the bundle value, must not be null
       * @param theArgs the objects to use when constructing the message
       * @return the formatted string
       */
      public static String getFormattedString(String theKey, Object[] theArgs)
      {
          return MessageFormat.format(getString(theKey), theArgs);
      }
  
      /**
       * Gets an unformatted string from the resource bundle.
       * 
       * @param theKey the string used to get the bundle value, must not be null
       * @return the string from the resource bundle or "![key name]!" if the key
       *         does not exist in the resource bundle
       */
      public static String getString(String theKey)
      {
          try
          {
              return RESOURCE_BUNDLE.getString(theKey);
          } 
          catch (MissingResourceException e)
          {
              return '!' + theKey + '!';
          }
      }
  }
  
  
  
  1.1                  
jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.webapp/src/java/org/apache/cactus/eclipse/webapp/internal/ui/WebappPlugin.java
  
  Index: WebappPlugin.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 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", "Cactus" 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 [EMAIL PROTECTED]
   *
   * 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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.webapp.internal.ui;
  
  import java.util.MissingResourceException;
  import java.util.ResourceBundle;
  
  import org.apache.cactus.eclipse.webapp.internal.Webapp;
  import org.eclipse.core.resources.IWorkspace;
  import org.eclipse.core.resources.ResourcesPlugin;
  import org.eclipse.core.runtime.IPluginDescriptor;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.ui.plugin.AbstractUIPlugin;
  
  /**
   * The main plugin class to be used in the desktop.
   * 
   * @version $Id: WebappPlugin.java,v 1.1 2003/06/11 14:48:30 vmassol Exp $
   * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
   */
  public class WebappPlugin extends AbstractUIPlugin
  {
      /**
       * The shared instance.
       */
      private static WebappPlugin plugin;
      /**
       * Resource bundle.
       */
      private ResourceBundle resourceBundle;
  
      /**
       * The constructor.
       * @param theDescriptor the descriptor for this plugin
       */
      public WebappPlugin(IPluginDescriptor theDescriptor)
      {
          super(theDescriptor);
          plugin = this;
          try
          {
              resourceBundle =
                  ResourceBundle.getBundle("webapp.webappPluginResources");
          }
          catch (MissingResourceException x)
          {
              resourceBundle = null;
          }
      }
  
      /**
       * Returns the shared instance.
       * @return the instance of this plugin
       */
      public static WebappPlugin getDefault()
      {
          return plugin;
      }
  
      /**
       * Returns the workspace instance.
       * @return the instance of the current workspace
       */
      public static IWorkspace getWorkspace()
      {
          return ResourcesPlugin.getWorkspace();
      }
  
      /**
       * Returns the string from the plugin's resource bundle,
       * or 'key' if not found.
       * @param theKey the key of the resource to return
       * @return the string
       */
      public static String getResourceString(String theKey)
      {
          ResourceBundle bundle = WebappPlugin.getDefault().getResourceBundle();
          try
          {
              return bundle.getString(theKey);
          }
          catch (MissingResourceException e)
          {
              return theKey;
          }
      }
  
      /**
       * Returns the plugin's resource bundle
       * @return the resource bundle
       */
      public ResourceBundle getResourceBundle()
      {
          return resourceBundle;
      }
  
      /**
       * @return the plugin identifier
       */
      public static String getPluginId()
      {
          return getDefault().getDescriptor().getUniqueIdentifier();
      }
  
      /**
       * @param theJavaProject the Java project to get the webapp from
       * @return the webapp associated to the given Java project
       */
      public static Webapp getWebapp(IJavaProject theJavaProject)
      {
          return new Webapp(theJavaProject);
      }
  }
  
  
  
  1.6       +4 -4      
jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.webapp/plugin.xml
  
  Index: plugin.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.webapp/plugin.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- plugin.xml        8 May 2003 11:37:59 -0000       1.5
  +++ plugin.xml        11 Jun 2003 14:48:38 -0000      1.6
  @@ -4,12 +4,12 @@
      name="%pluginName"
      version="1.5.0"
      provider-name="%providerName"
  -   class="org.apache.cactus.eclipse.webapp.ui.WebappPlugin">
  +   class="org.apache.cactus.eclipse.webapp.internal.ui.WebappPlugin">
   
      <runtime>
         <library name="webapp.jar">  
            <export name="*"/>
  -         <packages prefixes="org.apache.cactus.eclipse.webapp"/>
  +         <packages prefixes="org.apache.cactus.eclipse.webapp.internal"/>
         </library> 
      </runtime>
   
  @@ -27,13 +27,13 @@
         <page name="%webAppPageName"
            id="org.apache.cactus.eclipse.WebAppPropertyPage"
             objectClass="org.eclipse.jdt.core.IJavaProject"
  -          class="org.apache.cactus.eclipse.webapp.ui.WebAppPropertyPage">
  +          class="org.apache.cactus.eclipse.webapp.internal.ui.WebAppPropertyPage">
             <filter name="nature" value="org.eclipse.jdt.core.javanature"/>
          </page>
         <page name="%webAppPageName"
            id="org.apache.cactus.eclipse.WebAppPropertyPage"
             objectClass="org.eclipse.core.resources.IProject"
  -          class="org.apache.cactus.eclipse.webapp.ui.WebAppPropertyPage">
  +          class="org.apache.cactus.eclipse.webapp.internal.ui.WebAppPropertyPage">
             <filter name="nature" value="org.eclipse.jdt.core.javanature"/>
          </page>
      </extension>
  
  
  

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

Reply via email to