jvanzyl 2002/07/14 16:39:56
Added: src/plugins-build/j2ee/src/java/org/apache/maven/j2ee
J2EEEntityResolver.java ValidationBroadcaster.java
ValidationEvent.java ValidationFormatter.java
ValidationListener.java
ValidationStatusListener.java WarClassLoader.java
WarFile.java WarValidator.java
src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/war
FormLoginConfig.java
Log:
o Moved to plugin
Revision Changes Path
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/J2EEEntityResolver.java
Index: J2EEEntityResolver.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* 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.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* A class to resolve external entity definitions for j2ee artifacts.
*
* @author dion
* @version $Id: J2EEEntityResolver.java,v 1.1 2002/07/14 23:39:55 jvanzyl Exp $
*/
public class J2EEEntityResolver implements EntityResolver
{
/** map of ids to resource names */
private Map idToResource = new HashMap();
/** Creates a new instance of EntityResolver */
public J2EEEntityResolver()
{
idToResource.put(
"-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN",
"/application-client_1_3.dtd");
idToResource.put(
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN",
"/application_1_3.dtd");
idToResource.put(
"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN",
"/ejb-jar_2_0.dtd");
idToResource.put(
"-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
"/web-app_2.2.dtd");
idToResource.put(
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
"/web-app_2_3.dtd");
idToResource.put(
"-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN",
"/web-jsptaglibrary_1_2.dtd");
}
/** resolve the entity given by the provided Ids
* @param publicId the public id of the entity
* @param systemId the 'system location' (typically a URL) of the entity
* @return an {@link InputSource input source} for retrieval of the entity
* @throws IOException when an I/O error occurs retrieving the entity
* @throws SAXException if there are any problems
*/
public InputSource resolveEntity(String publicId, String systemId) throws
SAXException, IOException
{
if (publicId != null)
{
String resource = (String) idToResource.get(publicId);
if (resource != null)
{
InputStream in = getClass().getResourceAsStream(resource);
if (in != null)
{
return new InputSource(in);
}
}
}
return null;
}
/** Getter for publicId to resource name map.
* @return Value of property idToResource.
*/
protected Map getIdToResource()
{
return idToResource;
}
/** Setter for publicId to resource name map.
* @param idToResource New value of property idToResource.
*/
protected void setIdToResource(Map idToResource)
{
this.idToResource = idToResource;
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/ValidationBroadcaster.java
Index: ValidationBroadcaster.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* 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.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
*
* @version $Id: ValidationBroadcaster.java,v 1.1 2002/07/14 23:39:55 jvanzyl Exp $
* @author dion
*/
public class ValidationBroadcaster
{
/** {@link ValidationListeners} handled by this broadcaster */
private List listeners = new ArrayList();
/** Creates a new instance of ValidationBroadcaster */
public ValidationBroadcaster()
{
}
/**
* fire a {@link ValidationListener#validationStarted(ValidationEvent)
* started} event.
* @param event the event to broadcast
*/
public void fireStartedEvent(ValidationEvent event)
{
for (Iterator listeners = getListeners().iterator();
listeners.hasNext();)
{
((ValidationListener) listeners.next()).validationStarted(event);
}
}
/**
* fire an {@link ValidationListener#validationEnded(ValidationEvent)
* ended} event.
* @param event the event to broadcast
*/
public void fireEndedEvent(ValidationEvent event)
{
for (Iterator listeners = getListeners().iterator();
listeners.hasNext();)
{
((ValidationListener) listeners.next()).validationEnded(event);
}
}
/**
* fire an {@link ValidationListener#validationError(ValidationEvent)
* error} event.
* @param event the event to broadcast
*/
public void fireErrorEvent(ValidationEvent event)
{
for (Iterator listeners = getListeners().iterator();
listeners.hasNext();)
{
((ValidationListener) listeners.next()).validationError(event);
}
}
/**
* fire a {@link ValidationListener#validationWarning(ValidationEvent)
* warning} event.
* @param event the event to broadcast
*/
public void fireWarningEvent(ValidationEvent event)
{
for (Iterator listeners = getListeners().iterator();
listeners.hasNext();)
{
((ValidationListener) listeners.next()).validationWarning(event);
}
}
/**
* fire a {@link ValidationListener#validationInformation(ValidationEvent)
* information} event.
* @param event the event to broadcast
*/
public void fireInformationEvent(ValidationEvent event)
{
for (Iterator listeners = getListeners().iterator();
listeners.hasNext();)
{
((ValidationListener) listeners.next()).validationInformation(
event);
}
}
/** Getter for property listeners.
* @return Value of property listeners.
*/
private List getListeners()
{
return listeners;
}
/** Setter for property listeners.
* @param listeners New value of property listeners.
*/
private void setListeners(List listeners)
{
this.listeners = listeners;
}
/**
* add a listener to the list to be notified
* @param listener a {@link ValidationListener}
*/
public void addValidationListener(ValidationListener listener)
{
getListeners().add(listener);
}
/**
* remove a listener from the list to be notified
* @param listener a {@link ValidationListener}
*/
public void removeValidationListener(ValidationListener listener)
{
getListeners().remove(listener);
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/ValidationEvent.java
Index: ValidationEvent.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* 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.util.EventObject;
/**
* A class that holds details about the validation
*
* @version $Id: ValidationEvent.java,v 1.1 2002/07/14 23:39:55 jvanzyl Exp $
* @author dion
*/
public class ValidationEvent extends EventObject
{
/** A message describing the validation event that occurred*/
private String message;
/** The thing being validated that the event relates to, e.g a WAR file */
private Object subject;
/** Creates a new instance of ValidationEvent.
* @param source the source of the event, some validator.
*/
public ValidationEvent(Object source)
{
this(source, null, null);
}
/** Creates a new instance of ValidationEvent.
* @param source the source of the event, some validator.
* @param subject the object being validated
* @param message the validation message
*/
public ValidationEvent(Object source, Object subject, String message)
{
super(source);
setSubject(subject);
setMessage(message);
}
/** Getter for property message.
* @return Value of property message.
*/
public String getMessage()
{
return message;
}
/** Setter for property message.
* @param message New value of property message.
*/
public void setMessage(String message)
{
this.message = message;
}
/** Getter for property subject.
* @return Value of property subject.
*/
public Object getSubject()
{
return subject;
}
/** Set the subject of the validation event.
* @param subject New value of property subject.
*/
public void setSubject(Object subject)
{
this.subject = subject;
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/ValidationFormatter.java
Index: ValidationFormatter.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* 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.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
/**
* Base class for formatters of validation events - handles plain and xml
* formats.
* @version $Id: ValidationFormatter.java,v 1.1 2002/07/14 23:39:55 jvanzyl Exp $
* @author dion
*/
public class ValidationFormatter implements ValidationListener
{
/** Whether the formatter should write it's results to a file */
private boolean usefile;
/** name of the file (if usefile is true) to send output to */
private String file;
/** type of output: plain/xml */
private String type = ValidationFormatter.PLAIN;
/** Plain format output */
public static final String PLAIN = "plain";
/** xml format output */
public static final String XML = "xml";
/** output destination */
private PrintStream stream = null;
// --- Constructors --------------------------------------------------------
/** Creates a new instance of ValidationFormatter */
public ValidationFormatter()
{
stream = System.out;
}
// --- Methods -------------------------------------------------------------
/** Test whether the formatter is in plain mode.
* @return true if {@link #type} is set to {@link PLAIN}
*/
private boolean isPlain()
{
return ValidationFormatter.PLAIN.equals(getType());
}
/** print an event in xml format
* @param event the event to print
* @param eventName started/ended/error etc
*/
private void printEventAsXML(ValidationEvent event, String eventName)
{
getStream().println("\t<" + eventName + ">");
getStream().println("\t\t<source>");
getStream().println("\t\t\t" + event.getSource());
getStream().println("\t\t</source>");
getStream().println("\t\t<subject>");
getStream().println("\t\t\t" + event.getSubject());
getStream().println("\t\t</subject>");
getStream().println("\t\t<message>");
getStream().println("\t\t\t" + event.getMessage());
getStream().println("\t\t</message>");
getStream().println("\t</" + eventName + ">");
}
/** print an event in plain format
* @param event the {@link ValidationEvent event} to print
* @param type started, ended etc
*/
private void printEvent(String type, ValidationEvent event)
{
getStream().println(event.getSubject() + " " + type + ": "
+ event.getMessage());
}
/**
* Called when validation ends
* @param event a {@link ValidationEvent}
*/
public void validationEnded(ValidationEvent event)
{
if (isPlain())
{
printEvent("ended", event);
}
else
{
printEventAsXML(event, "ended");
getStream().println("</validation-report>");
}
}
/** Called when a validation error occurs. That is, the subject being
* validated has a serious (fatal) problem
* @param event a {@link ValidationEvent}
*/
public void validationError(ValidationEvent event)
{
if (isPlain())
{
printEvent("error", event);
}
else
{
printEventAsXML(event, "error");
}
}
/**
* Called when validation starts
* @param event a {@link ValidationEvent}
*/
public void validationStarted(ValidationEvent event)
{
if (isPlain())
{
printEvent("started", event);
}
else
{
getStream().println("<?xml version=\"1.0\" ?>");
getStream().println("<validation-report>");
printEventAsXML(event, "started");
}
}
/** Called when a validation warning occurs. That is, the subject being
* validated has a problem which may not be fatal
* @param event a {@link ValidationEvent}
*/
public void validationWarning(ValidationEvent event)
{
if (isPlain())
{
printEvent("warning", event);
}
else
{
printEventAsXML(event, "warning");
}
}
/** Called when validation information events are fired.
* @param event a {@link ValidationEvent}
*/
public void validationInformation(ValidationEvent event)
{
if (isPlain())
{
printEvent("info", event);
}
else
{
printEventAsXML(event, "info");
}
}
/** Getter for property file.
* @return Value of property file.
*/
public String getFile()
{
return file;
}
/** Setter for property file.
* @param file New value of property file.
* @throws FileNotFoundException if the named file doesn't exist
*/
public void setFile(String file) throws FileNotFoundException
{
this.file = file;
FileOutputStream fos = new FileOutputStream(file);
stream = new PrintStream(fos);
}
/** Getter for property usefile.
* @return Value of property usefile.
*/
public boolean isUsefile()
{
return usefile;
}
/** Setter for property usefile.
* @param usefile New value of property usefile.
*/
public void setUsefile(boolean usefile)
{
this.usefile = usefile;
}
/** Getter for property stream.
* @return Value of property stream.
*/
public PrintStream getStream()
{
return stream;
}
/** Setter for property stream.
* @param stream New value of property stream.
*/
public void setStream(PrintStream stream)
{
this.stream = stream;
}
/** Getter for property type.
* @return Value of property type.
*/
public String getType()
{
return type;
}
/** Setter for property type.
* @param type New value of property type.
*/
public void setType(String type)
{
this.type = type;
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/ValidationListener.java
Index: ValidationListener.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* 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.util.EventListener;
/**
* An interface implemented by those who want to receive validation events
* from a J2EE Validator (WAR, EAR etc).
*
* @version $Id: ValidationListener.java,v 1.1 2002/07/14 23:39:55 jvanzyl Exp $
* @author dion
*/
public interface ValidationListener extends EventListener
{
/**
* Called when validation starts
* @param event a {@link ValidationEvent}
*/
void validationStarted(ValidationEvent event);
/**
* Called when a validation error occurs. That is, the subject being
* validated has a serious (fatal) problem
* @param event a {@link ValidationEvent}
*/
void validationError(ValidationEvent event);
/**
* Called when a validation warning occurs. That is, the subject being
* validated has a problem which may not be fatal
* @param event a {@link ValidationEvent}
*/
void validationWarning(ValidationEvent event);
/**
* Called when validation information is provided. This may be any
* information the validator feels is relevant.
* @param event a {@link ValidationEvent}
*/
void validationInformation(ValidationEvent event);
/**
* Called when validation ends
* @param event a {@link ValidationEvent}
*/
void validationEnded(ValidationEvent event);
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/ValidationStatusListener.java
Index: ValidationStatusListener.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* 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/>.
*
* ====================================================================
*/
/**
* A {@link ValidationListener} that tracks events and will provide a true/false
* response about the status of the validation
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version
* $Id: ValidationStatusListener.java,v 1.1 2002/07/14 23:39:55 jvanzyl Exp $
*/
public class ValidationStatusListener implements ValidationListener
{
/** Whether the validation has started */
private boolean started = false;
/** Whether the validation has ended */
private boolean ended = false;
/** Whether the validation has had 1 or more errors */
private boolean error = false;
/** Whether the validation has had 1 or more warnings */
private boolean warning = false;
/** Whether the validation has had 1 or more info messages */
private boolean information = false;
/** Creates a new instance of ValidationStatusListener */
public ValidationStatusListener()
{
}
/** Called when a validation error occurs. That is, the subject being
* validated has a serious (fatal) problem. Sets the <code>error</code>
* property to <code>true</code>.
* @param event a {@link ValidationEvent}
*/
public void validationError(ValidationEvent event)
{
setError(true);
}
/** Called when a validation warning occurs. That is, the subject being
* validated has a problem which may not be fatal. Sets the
* <code>warning</code> property to <code>true</true>.
* @param event a {@link ValidationEvent}
*/
public void validationWarning(ValidationEvent event)
{
setWarning(true);
}
/** Called when validation info messages are issued. Sets the
* <code>information</code> property to <code>true</true>.
* @param event a {@link ValidationEvent}
*/
public void validationInformation(ValidationEvent event)
{
setInformation(true);
}
/**
* Called when validation starts. Sets the <code>started</code> property to
* <code>true</code>
* @param event a {@link ValidationEvent}
*/
public void validationStarted(ValidationEvent event)
{
setStarted(true);
}
/**
* Called when validation ends. Sets the <code>ended</code> property to
* <code>true</code>
* @param event a {@link ValidationEvent}
*/
public void validationEnded(ValidationEvent event)
{
setEnded(true);
}
/** Has validation ended?
* @return Value of property ended.
*/
public boolean isEnded()
{
return ended;
}
/** Sets whether validation has ended.
* @param ended New value of property ended.
*/
private void setEnded(boolean ended)
{
this.ended = ended;
}
/** Has a validation error occurred?
* @return Value of property error.
*/
public boolean isError()
{
return error;
}
/** Sets whether a validation error has occurred.
* @param error New value of property error.
*/
private void setError(boolean error)
{
this.error = error;
}
/** Has validation started?
* @return Value of property started.
*/
public boolean isStarted()
{
return started;
}
/** Sets whether validation has started
* @param started New value of property started.
*/
private void setStarted(boolean started)
{
this.started = started;
}
/** Has a validation warning occurred?
* @return Value of property warning.
*/
public boolean isWarning()
{
return warning;
}
/** Sets whether a validation warning has occurred.
* @param warning New value of property warning.
*/
private void setWarning(boolean warning)
{
this.warning = warning;
}
/** Gets whether an info message has been issued.
* @return Value of property information.
*/
public boolean isInformation()
{
return information;
}
/** Sets whether an info message has been issued.
* @param information New value of property information.
*/
public void setInformation(boolean information)
{
this.information = information;
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/WarClassLoader.java
Index: WarClassLoader.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* 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.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
/**
* A {@link ClassLoader} that loads classes from a {@link WarFile}
*
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version $Id: WarClassLoader.java,v 1.1 2002/07/14 23:39:55 jvanzyl Exp $
*/
public class WarClassLoader extends URLClassLoader
{
/** temp files created by classloader */
private List tempFiles = new ArrayList();
/** war file to be used for class loading */
private WarFile war;
/** Creates a new instance of WarClassLoader
* @param war a {@link WarFile}
* @throws IOException when an I/O error occurs extracting the jars from the
* war
* @throws MalformedURLException if the jar: URL is not supported on the
* underlying platform
*/
public WarClassLoader(WarFile war) throws IOException, MalformedURLException
{
super (new URL[0]);
this.war = war;
addURLs();
}
/** Creates a new instance of WarClassLoader with the provided parent
* classloader as the one to delegate to if classes can't be found
* @param war a {@link WarFile}
* @param classloader a {@link ClassLoader} to delegate to.
* @throws IOException when an I/O error occurs extracting the jars from the
* war
* @throws MalformedURLException if the jar: URL is not supported on the
* underlying platform
*/
public WarClassLoader(WarFile war, ClassLoader classloader) throws
IOException, MalformedURLException
{
super(new URL[0], classloader);
this.war = war;
addURLs();
}
/** Add WEB-INF/classes and WEB-INF/lib/*.jar as extra classpath URLs
* @throws IOException when an I/O error occurs extracting the jars from the
* war
* @throws MalformedURLException if the jar: URL is not supported on the
* underlying platform
*/
private void addURLs() throws IOException, MalformedURLException
{
File warFile = new File(war.getName());
URL webInfClasses = new URL("jar:" + warFile.toURL() + "!/"
+ "WEB-INF/classes/");
addURL(webInfClasses);
Set jars = war.getLibEntries();
JarEntry entry = null;
for (Iterator jarEntries = jars.iterator(); jarEntries.hasNext();)
{
entry = (JarEntry) jarEntries.next();
File jar = war.extract(entry);
tempFiles.add(jar);
jar.deleteOnExit();
addURL(new URL("jar:" + jar.toURL() + "!/"));
}
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/WarFile.java
Index: WarFile.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* 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.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.maven.j2ee.war.FormLoginConfig;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
/**
* Represents a J2EE War File
*
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version $Id: WarFile.java,v 1.1 2002/07/14 23:39:55 jvanzyl Exp $
*/
public class WarFile extends JarFile
{
/** web.xml entry in the war */
public static final String WEB_XML = "WEB-INF/web.xml";
/** lib entry in the war for jar files */
public static final String LIB = "WEB-INF/lib/";
/**
* Creates a new instance of WarFile
* @param name the {@link File file} name of a war file
* @throws IOException when an I/O error occurs
*/
public WarFile(String name) throws IOException
{
super(name);
}
/**
* Creates a new instance of WarFile
* @param name the {@link File file} name of a war file
* @param verify whether or not to verify the war file if it is signed
* @throws IOException when an I/O error occurs
*/
public WarFile(String name, boolean verify) throws IOException
{
super(name, verify);
}
/**
* Creates a new instance of WarFile
* @param warFile a J2EE .war {@link File file}
* @throws IOException when an I/O error occurs
*/
public WarFile(File warFile) throws IOException
{
super(warFile);
}
/**
* Creates a new instance of WarFile
* @param warFile a J2EE .war {@link File file}
* @param verify whether or not to verify the war file if it is signed
* @throws IOException when an I/O error occurs
*/
public WarFile(File warFile, boolean verify) throws IOException
{
super(warFile, verify);
}
/**
* Creates a new instance of WarFile
* @param warFile a J2EE .war {@link File file}
* @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 WarFile(File warFile, boolean verify, int mode) throws IOException
{
super(warFile, verify, mode);
}
/**
* Retrieves the WEB-INF/web.xml entry if it exists.
* @return a {@link JarEntry} for web.xml
*/
public JarEntry getWebXmlEntry()
{
return getJarEntry(WarFile.WEB_XML);
}
/**
* Get a map of servlet name -> servlet class. The map has a size of zero
* if there are no servlets or no web.xml in the war.
* @return a map of servlets held in the war.
* @throws IOException if there are problems reading from the war
*/
public Map getServlets() throws IOException
{
Map servlets = new HashMap();
if (getWebXmlEntry() != null)
{
Document webXml = getWebXml();
List servletNodes = webXml.selectNodes("//servlet");
Node node = null;
for (Iterator nodes = servletNodes.iterator(); nodes.hasNext();)
{
node = (Node) nodes.next();
String servletName = node.selectSingleNode("./servlet-name")
.getText();
Node servletClass = node.selectSingleNode("./servlet-class");
if (servletClass != null)
{
servlets.put(servletName, servletClass.getText());
}
}
}
return servlets;
}
/**
* Get a map of servlet name -> jsp file. The map has a size of zero
* if there are no jsp files defined or no web.xml in the war.
* @return a map of jsps defined using the <code><servlet></code> tag
* held in the war.
* @throws IOException if there are problems reading from the war
*/
public Map getJSPs() throws IOException
{
Map jsps = new HashMap();
if (getWebXmlEntry() != null)
{
Document webXml = getWebXml();
List servletNodes = webXml.selectNodes("//servlet");
Node node = null;
for (Iterator nodes = servletNodes.iterator(); nodes.hasNext();)
{
node = (Node) nodes.next();
String servletName = node.selectSingleNode("./servlet-name")
.getText();
Node jspFile = node.selectSingleNode("./jsp-file");
if (jspFile != null)
{
jsps.put(servletName, jspFile.getText());
}
}
}
return jsps;
}
/** Get a map of taglib-uri -> taglib-location. The map has zero size
* if there are no taglibs defined or no web.xml in the war
* @return a map of uri to location
* @throws IOException when an I/O error occurs reading the war
*/
public Map getTaglibs() throws IOException
{
Map taglibs = new HashMap();
if (getWebXmlEntry() != null)
{
Document webXml = getWebXml();
List taglibNodes = webXml.selectNodes("//taglib");
Node node = null;
for (Iterator nodes = taglibNodes.iterator(); nodes.hasNext();)
{
node = (Node) nodes.next();
String taglibUri = node.selectSingleNode("./taglib-uri")
.getText();
String taglibLocation = node.selectSingleNode(
"./taglib-location").getText();
taglibs.put(taglibUri, taglibLocation);
}
}
return taglibs;
}
/** Get the web.xml back as a dom4j Document, for easier processing
* @return a {@link Document} representing the web.xml
* @throws IOException if there are any issues reading the web.xml
* or producing the xml document
*/
protected Document getWebXml() throws IOException
{
if (getWebXmlEntry() == null)
{
throw new IOException("Attempted to get non-existent web.xml");
}
try
{
SAXReader xmlReader = new SAXReader(false);
xmlReader.setEntityResolver(new J2EEEntityResolver());
InputStream webXmlStream = getInputStream(getWebXmlEntry());
Document webXml = xmlReader.read(webXmlStream);
return webXml;
}
catch (DocumentException de)
{
de.printStackTrace();
throw new IOException(de.getMessage());
}
}
/** Provide a set of jar files as found in WEB-INF/lib
* @return a set of jar files as {@link JarEntry entries} from WEB-INF/lib
*/
public Set getLibEntries()
{
Set libs = new HashSet();
Enumeration entries = entries();
JarEntry entry = null;
while (entries.hasMoreElements())
{
entry = (JarEntry) entries.nextElement();
if (entry.getName().startsWith("WEB-INF/lib/")
&& entry.getName().toLowerCase().endsWith(".jar"))
{
libs.add(entry);
}
}
return libs;
}
/** Extract the given {@link JarEntry entry} to a temporary file
* @param entry a previously retrieved entry from the jar file
* @return the {@link File} created
* @throws IOException when an I/O error occurs reading the war
*/
public File extract(JarEntry entry) throws IOException
{
// expand to temp dir and add to list
File tempFile = File.createTempFile("maven", null);
// read from jar and write to the tempJar file
BufferedInputStream inStream = new BufferedInputStream(getInputStream(
entry));
BufferedOutputStream outStream = new BufferedOutputStream(
new FileOutputStream(tempFile));
int status = -1;
while ((status = inStream.read()) != -1)
{
outStream.write(status);
}
outStream.close();
inStream.close();
return tempFile;
}
/** Tests whether a 'file' exists in the war. A file in this case is
* a jar entry prefixed with a '/'. e.g. the file /WEB-INF/web.xml is
* the same as the jar entry WEB-INF/web.xml
* @param fileName an entry in the war to be searched for
* @return whether the entry exists
*/
public boolean hasFile(String fileName)
{
if (fileName == null)
{
throw new NullPointerException("fileName parameter can't be null");
}
String entryName = null;
if (fileName.startsWith("/"))
{
entryName = fileName.substring(1);
return getJarEntry(entryName) != null;
}
else
{
return false;
}
}
/** Get a map of error pages to error locations. The key of the map is
* either the <code><error-code></code> or <code><
* exception-type></code>, the value is <code><location></code>.
* @return a map of error page to error location
* @throws IOException if there are problems reading from the war
*/
public Map getErrorPages() throws IOException
{
Map errorPages = new HashMap();
if (getWebXmlEntry() != null)
{
Document webXml = getWebXml();
List errorNodes = webXml.selectNodes("//error-page");
Node node = null;
for (Iterator nodes = errorNodes.iterator(); nodes.hasNext();)
{
node = (Node) nodes.next();
Node errorCodeNode = node.selectSingleNode("./error-code");
Node exceptionTypeNode = node.selectSingleNode(
"./exception-type");
String location = node.selectSingleNode("./location").getText();
String key = null;
if (errorCodeNode == null)
{
key = exceptionTypeNode.getText();
}
else
{
key = errorCodeNode.getText();
}
errorPages.put(key, location);
}
}
return errorPages;
}
/** Get the <code><form-login-config></code> details specified in the
* war file, or null if the element is not present
* @return a {@link FormLoginConfig} with the login and error pages
* @throws IOException if there are problems reading from the war
*/
public FormLoginConfig getFormLoginConfig() throws IOException
{
FormLoginConfig config = null;
if (getWebXmlEntry() != null)
{
Document webXml = getWebXml();
Node formLoginConfigNode = webXml.selectSingleNode(
"//form-login-config");
if (formLoginConfigNode != null)
{
String login = formLoginConfigNode.selectSingleNode(
"./form-login-page").getText();
String error = formLoginConfigNode.selectSingleNode(
"./form-error-page").getText();
config = new FormLoginConfig(login, error);
}
}
return config;
}
/**
* Get a map of servlet name -> url pattern for all defined servlets
*
* @return a map as specified
* @throws IOException if there are problems reading from the war
*/
public Map getServletMappings() throws IOException
{
Map mappings = new HashMap();
if (getWebXmlEntry() != null)
{
Document webXml = getWebXml();
List nodes = webXml.selectNodes("/web-app/servlet-mapping");
Node node = null;
for (int nodeIndex = 0; nodeIndex < nodes.size(); nodeIndex++)
{
node = (Node) nodes.get(nodeIndex);
String servletName = node.valueOf("./servlet-name");
String urlPattern = node.valueOf("./url-pattern");
mappings.put(servletName, urlPattern);
}
}
return mappings;
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/WarValidator.java
Index: WarValidator.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* 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.Iterator;
import java.util.Map;
import org.apache.tools.ant.BuildException;
import org.apache.maven.executor.AbstractExecutor;
import org.apache.maven.j2ee.war.FormLoginConfig;
/**
* A task to validate a war file. The following is checked:
* <ol>
* <li>The war file exists</li>
* <li>The war file is readable</li>
* <li>The war file has a web.xml (warning)</li>
* <li>Servlets defined by a <code><servlet><code> tag are loadable
* from the war file and <strong>not</strong> the classpath</li>
* <li>JSPs defined by a <code><servlet><code> tag exist in the war
* </li>
* <li>Taglibs defined by a <code><taglib></code> have a <code>
* <taglib-location></code> that exists in the war</li>
* <li>Error pages specified by a <code><location></code> nested
* within an <code><error-page></code> element must exist in the
* war file</li>
* <li>Login and error pages specified in the <code><form-login-config
* ></code> element must exist in the war file</li>
* </ol>
* @author dIon Gillard
* @version $Id: WarValidator.java,v 1.1 2002/07/14 23:39:55 jvanzyl Exp $
*/
public class WarValidator extends AbstractExecutor
{
/** name of the war file to be validated */
private String warFileName;
/** broadcaster to help with events */
private ValidationBroadcaster broadcaster = new ValidationBroadcaster();
/** status listener to keep track of errors etc */
private ValidationStatusListener status = new ValidationStatusListener();
/** whether or not the build process should fail if a validation error
occurs */
private boolean failOnError = true;
//--- Constructors ---------------------------------------------------------
/** Creates a new instance of WarValidator */
public WarValidator()
{
addValidationListener(getStatus());
}
//--- Methods --------------------------------------------------------------
/** Setter for property broadcaster.
* @param broadcaster New value of property broadcaster.
*/
private void setBroadcaster(ValidationBroadcaster broadcaster)
{
this.broadcaster = broadcaster;
}
/** Provides access to the status listener that is automatically attached
* to the validation
* @return Value of property status.
*/
public ValidationStatusListener getStatus()
{
return status;
}
/** Changes the status listener that is associated with this validator
* @param status New value of property status.
*/
private void setStatus(ValidationStatusListener status)
{
this.status = status;
}
/**
* Perform the validation.
* @throws Exception when any error occurs
*/
public void execute() throws Exception
{
if (getWarFileName() == null)
{
throw new NullPointerException("war file name should not be null");
}
validate();
if (getStatus().isError() && isFailOnError())
{
throw new BuildException("Errors occurred during validation. "
+ "Messages should have been provided");
}
}
/**
* validate the provided war file
*/
public void validate()
{
try
{
startValidation();
validateFile();
if (!getStatus().isError())
{
validateWarContents();
}
}
finally
{
endValidation();
}
}
/** Start validation - issue a started event, and check the war file is
* ok from a filesystem perspective - exists and is readable
*/
protected void startValidation()
{
getBroadcaster().fireStartedEvent(new ValidationEvent(this,
getWarFileName(), "war validation started"));
}
/** Hook point for subclasses to add validations
*/
protected void validateWarContents()
{
validateWebXml();
}
/** End validation - fire an ended event
*/
protected void endValidation()
{
getBroadcaster().fireEndedEvent(new ValidationEvent(this,
getWarFileName(), "war validation ended"));
}
/** validate the war file can be read and exists
*/
private void validateFile()
{
File warFile = new File(getWarFileName());
if (!warFile.exists())
{
error("File does not exist");
return;
}
if (!warFile.canRead())
{
error("File can't be read");
return;
}
}
/** Validate the web.xml entry in the provided jar file.
*/
private void validateWebXml()
{
WarFile war = null;
try
{
war = new WarFile(getWarFileName());
if (war.getWebXmlEntry() == null)
{
warning("web.xml entry not found");
return;
}
validateServlets(war);
validateJSPs(war);
validateTaglibs(war);
validateErrorPages(war);
validateFormLoginConfig(war);
}
catch (IOException ioe)
{
error("Error opening war file for web.xml - possibly missing "
+ "manifest");
}
}
/** Validate the servlets defined in the war file (as defined by a
* <code><servlet></code> tag in web.xml), making sure that their
* class defined can be loaded from the war and is not part of the
* external classpath
* @param war the war file to validate
* @throws IOException when there are any issues reading the war file
*/
private void validateServlets(WarFile war) throws IOException
{
Map servlets = war.getServlets();
if (servlets.size() != 0)
{
ClassLoader classLoader = new WarClassLoader(war, getClass().
getClassLoader());
String className = null;
Map.Entry entry = null;
for (Iterator entries = servlets.entrySet().iterator();
entries.hasNext();)
{
entry = (Map.Entry) entries.next();
className = (String) entry.getValue();
info("validating servlet name: " + entry.getKey() + " class: "
+ className);
// check each servlet by loading the class
validateClass(className, classLoader);
}
}
}
/** Validate the jsps defined in the war file (as defined by a
* <code><servlet></code> tag with a nested <code><jsp-file>
* </code> in web.xml), making sure that the resource specifed by
* <code><jsp-file></code> exists in the war file
* @param war the war file to validate
* @throws IOException when there are any issues reading the war file
*/
private void validateJSPs(WarFile war) throws IOException
{
Map jsps = war.getJSPs();
if (jsps.size() != 0)
{
Map.Entry entry = null;
for (Iterator entries = jsps.entrySet().iterator();
entries.hasNext();)
{
entry = (Map.Entry) entries.next();
String jspFile = (String) entry.getValue();
info("validating servlet name: " + entry.getKey()
+ " jsp file: " + jspFile);
if (!war.hasFile(jspFile))
{
error("JSP File: '" + jspFile + "' not found");
}
}
}
}
/** Validate that the given className can be loaded by the given
* {@link ClasssLoader}
* @param className the name of a class to attempt loading
* @param loader a {@link ClassLoader class loader}
*/
protected void validateClass(String className, ClassLoader loader)
{
try
{
Class clazz = loader.loadClass(className);
if (clazz.getClassLoader() != loader)
{
// loaded from classpath - a no no.
error("class (" + className + ") loaded from system classpath "
+ "rather than war file");
}
}
catch (ClassNotFoundException e)
{
error("class (" + className + ") not found ");
}
catch (NoClassDefFoundError error)
{
error("class (" + className + ") was found, but a referenced class "
+ "was missing: " + error.getMessage());
}
}
/** Validate the taglibs defined in the war file (as defined by a
* <code><taglib></code> tag in web.xml), making sure that the
* resource specifed by <code><taglib-location></code> exists in the
* war file
* @param war the war file to validate
* @throws IOException when there are any issues reading the war file
*/
private void validateTaglibs(WarFile war) throws IOException
{
Map taglibs = war.getTaglibs();
if (taglibs.size() != 0)
{
Map.Entry entry = null;
for (Iterator entries = taglibs.entrySet().iterator();
entries.hasNext();)
{
entry = (Map.Entry) entries.next();
String uri = (String) entry.getKey();
String location = (String) entry.getValue();
info("validating taglib uri: " + uri);
if (!war.hasFile(location))
{
error("Taglib location: '" + location + "' not found");
}
}
}
}
/** Validate the error pages defined in the war file (as defined by a
* <code><error-page></code> tag in web.xml), making sure that the
* location specifed by the nested <code><location></code> exists in
* the war file
* @param war the war file to validate
* @throws IOException when there are any issues reading the war file
*/
public void validateErrorPages(WarFile war) throws IOException
{
Map pages = war.getErrorPages();
if (pages.size() != 0)
{
Map.Entry entry = null;
for (Iterator entries = pages.entrySet().iterator();
entries.hasNext();)
{
entry = (Map.Entry) entries.next();
String errorQualifier = (String) entry.getKey();
String location = (String) entry.getValue();
info("validating error page for: " + errorQualifier);
if (!war.hasFile(location))
{
error("Error page location: '" + location + "' not found");
}
}
}
}
/** validate that the <code><form-login-config></code> element, if it
* exists contains valid login and error pages
* @param war the war file to validate
* @throws IOException when there are any issues reading the war file
*/
public void validateFormLoginConfig(WarFile war) throws IOException
{
FormLoginConfig config = war.getFormLoginConfig();
if (config != null)
{
if (!war.hasFile(config.getLoginPage()))
{
info("<form-config-login> login-page location: '"
+ config.getLoginPage() + "' not found");
}
if (!war.hasFile(config.getErrorPage()))
{
error("<form-config-login> error-page location: '"
+ config.getErrorPage() + "' not found");
}
}
}
/**
* add a listener to the list to be notified
* @param listener a {@link ValidationListener}
*/
public void addValidationListener(ValidationListener listener)
{
getBroadcaster().addValidationListener(listener);
}
/**
* remove a listener from the list to be notified
* @param listener a {@link ValidationListener}
*/
public void removeValidationListener(ValidationListener listener)
{
getBroadcaster().removeValidationListener(listener);
}
/** Getter for property warFileName.
* @return Value of property warFileName.
*/
public String getWarFileName()
{
return warFileName;
}
/** Setter for property warFileName.
* @param warFileName New value of property warFileName.
*/
public void setWarFileName(String warFileName)
{
this.warFileName = warFileName;
}
/** Getter for property broadcaster.
* @return Value of property broadcaster.
*/
protected ValidationBroadcaster getBroadcaster()
{
return broadcaster;
}
/** add a formatter to pick up events and display the output.
* Used by ant when a nested formatter element is present.
* @param formatter a class to format validation events
*/
public void addFormatter(ValidationFormatter formatter)
{
addValidationListener((ValidationListener) formatter);
}
/** provide a string representation of the validator
* @return "WarValidator(file)"
*/
public String toString()
{
StringBuffer buffer = new StringBuffer("WarValidator");
if (getWarFileName() != null)
{
buffer.append("(").append(getWarFileName()).append(")");
}
return buffer.toString();
}
/** Whether the build process will fail if a validation error occurs.
* @return Value of property failOnError.
*/
public boolean isFailOnError()
{
return failOnError;
}
/** Set whether the build process will fail if a validation error occurs.
* @param failOnError New value of property failOnError.
*/
public void setFailOnError(boolean failOnError)
{
this.failOnError = failOnError;
}
/** Helper method to fire an information message using the broadcaster
* @param message to be fired
*/
protected void info(String message)
{
getBroadcaster().fireInformationEvent(new ValidationEvent(this,
getWarFileName(), message));
}
/** Helper method to fire an error message using the broadcaster
* @param message to be fired
*/
protected void error(String message)
{
getBroadcaster().fireErrorEvent(new ValidationEvent(this,
getWarFileName(), message));
}
/** Helper method to fire a warning message using the broadcaster
* @param message to be fired
*/
protected void warning(String message)
{
getBroadcaster().fireWarningEvent(new ValidationEvent(this,
getWarFileName(), message));
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/java/org/apache/maven/j2ee/war/FormLoginConfig.java
Index: FormLoginConfig.java
===================================================================
package org.apache.maven.j2ee.war;
/* ====================================================================
* 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/>.
*
* ====================================================================
*/
/**
* A class to represent the <code><form-login-config></code> element of
* a war file
*
* @author dion
* @version $Id: FormLoginConfig.java,v 1.1 2002/07/14 23:39:56 jvanzyl Exp $
*/
public class FormLoginConfig
{
/** login page in the web app */
private String loginPage;
/** error page in the web app to be displayed when login fails*/
private String errorPage;
/** Create an instance of the class with null values for all fields */
public FormLoginConfig()
{
}
/** Create an instance of the class with the given values for fields
* @param login initial value of loginPage property
* @param error initial value if errorPage property
*/
public FormLoginConfig(String login, String error)
{
setLoginPage(login);
setErrorPage(error);
}
/** Getter for property errorPage.
* @return Value of property errorPage.
*/
public String getErrorPage()
{
return errorPage;
}
/** Setter for property errorPage.
* @param errorPage New value of property errorPage.
*/
public void setErrorPage(String errorPage)
{
this.errorPage = errorPage;
}
/** Getter for property loginPage.
* @return Value of property loginPage.
*/
public String getLoginPage()
{
return loginPage;
}
/** Setter for property loginPage.
* @param loginPage New value of property loginPage.
*/
public void setLoginPage(String loginPage)
{
this.loginPage = loginPage;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>