dion        02/05/20 16:57:28

  Added:       src/java/org/apache/maven/struts Struts10WarValidator.java
                        Struts10WarFile.java
  Log:
  First cut on Struts 1.0 plugin validation code
  
  Revision  Changes    Path
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/struts/Struts10WarValidator.java
  
  Index: Struts10WarValidator.java
  ===================================================================
  package org.apache.maven.struts;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" 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",
   *    "Apache Maven", 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.
   * ====================================================================
   *
   * 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/>.
   */
  
  import org.apache.maven.j2ee.WarValidator;
  import org.apache.maven.j2ee.ValidationEvent;
  
  /**
   * A class that validates a Struts 1.0 War File.
   * Specific validations performed are:
   * <ol>
   *   <li>Must pass validation as a 'standard' war file</li>
   *   <li>File has a struts configuration file</li>
   * </ol>
   *
   * @author  dion
   * @version $Id: Struts10WarValidator.java,v 1.1 2002/05/20 23:57:28 dion Exp $
   */
  public class Struts10WarValidator extends WarValidator
  {
      /** the location within the war of the Struts configuration file.
       * By default this takes the value of the {@link 
       * Struts10WarFile#DEFAULT_CONFIG default config}
       */
      private String config = Struts10WarFile.DEFAULT_CONFIG;
      
      /** Creates a new instance of Struts10WarValidator */
      public Struts10WarValidator()
      {
      }
      
      /** Validate struts specific war features here
       */
      protected void validateWarContents()
      {
          super.validateWarContents();
          Struts10WarFile strutsWar = new Struts10WarFile(getWarFileName());
          strutsWar.setConfig(getConfig());
          validateStrutsConfig(strutsWar);
      }
      
      /** Getter for Struts config location within the war (no leading slash).
       * e.g. <code>WEB-INF/struts-config.xml</code>
       * @return Value of property config.
       */
      public String getConfig()
      {
          return config;
      }
      
      /** Setter for config location within the war (no leading slash)
       * @param config New value of property config.
       */
      public void setConfig(String config)
      {
          this.config = config;
      }
      
      /** validations for the struts configuration file 
       * @param strutsWar - the struts web app being validated
       */
      private void validateStrutsConfig(Struts10WarFile strutsWar)
      {
          if (strutsWar.getStrutsConfigEntry() == null)
          {
              getBroadcaster().fireErrorEvent(new ValidationEvent(this, 
                  getWarFileName(), "Struts Configuration: '" + 
                  strutsWar.getConfig() + "' not found in the war file"));
          }
      }
  }
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/struts/Struts10WarFile.java
  
  Index: Struts10WarFile.java
  ===================================================================
  package org.apache.maven.struts;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" 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",
   *    "Apache Maven", 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.
   * ====================================================================
   *
   * 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/>.
   */
  
  import java.io.File;
  import java.io.IOException;
  import java.util.jar.JarEntry;
  
  import org.apache.maven.j2ee.WarFile;
  
  /**
   * Encapsulates a Struts 1.0 War File. Holds functionality to access Struts
   * specific resources and data in the war.
   * @author  dion
   * @version $Id: Struts10WarFile.java,v 1.1 2002/05/20 23:57:28 dion Exp $
   */
  public class Struts10WarFile extends WarFile
  {
      /** Default location of Struts configuration file in the war */
      public static final String DEFAULT_CONFIG = "WEB-INF/struts-config.xml";
      /** property for the location of the Struts configuration file in the war */
      private String config = Struts10WarFile.DEFAULT_CONFIG;
      
      /** 
       * Creates a new instance of Struts10WarFile
       * @param name the {@link File file} name of a war file containing a Struts
       * web application
       * @throws IOException when an I/O error occurs
       */
      public Struts10WarFile(String name) throws IOException
      {
          super(name);
      }
      
      /** 
       * Creates a new instance of Struts10WarFile
       * @param name the {@link File file} name of a war file containing a Struts
       * web application
       * @param verify whether or not to verify the war file if it is signed
       * @throws IOException when an I/O error occurs     */
      public Struts10WarFile(String name, boolean verify) throws IOException
      {
          super(name, verify);
      }
      
      /** 
       * Creates a new instance of Struts10WarFile
       * @param warFile a J2EE .war {@link File file} containing a Struts web
       * application
       * @throws IOException when an I/O error occurs
       */
      public Struts10WarFile(File warFile) throws IOException
      {
          super(warFile);
      }
  
      /** 
       * Creates a new instance of Struts10WarFile
       * @param warFile a J2EE .war {@link File file} containing a Struts web
       * application
       * @param verify whether or not to verify the war file if it is signed
       * @throws IOException when an I/O error occurs
       */
      public Struts10WarFile(File warFile, boolean verify) throws IOException
      {
          super(warFile, verify);
      }
  
      /** 
       * Creates a new instance of Struts10WarFile
       * @param warFile a J2EE .war {@link File file} containing a Struts web
       * application
       * @param verify whether or not to verify the war file if it is signed
       * @param mode the mode in which the file is to be opened
       * @throws IOException when an I/O error occurs
       */
      public Struts10WarFile(File warFile, boolean verify, int mode) throws IOException
      {
          super(warFile, verify, mode);
      }
      
      /** Provide the location of the Struts configuration file in the war.
       * @return Value of property config.
       */
      public String getConfig()
      {
          return config;
      }
      
      /** Set the location of the Struts configuration file in the war.
       * @param config New value of property config.
       */
      public void setConfig(String config)
      {
          this.config = config;
      }
      
      /**
       * Retrieves the Struts configuration (as specified by the config property)
       * entry if it exists.
       * @return a {@link JarEntry} for Struts config
       */
      public JarEntry getStrutsConfigEntry()
      {
          return getJarEntry(getConfig());
      }
   
  }
  
  
  

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

Reply via email to