/*
* Created on May 10, 2003
*/
package net.sf.jportlet.portlets;
import java.net.MalformedURLException;
import java.net.URL;
import net.sf.jportlet.portlet.PortletContext;
import net.sf.jportlet.portlet.event.ActionEvent;
/**
* @author herve
*/
public class ValidationHelper
{
public static void addError( String msg,
ActionEvent event )
{
PortletContext ctx = event.getPortlet( ).getPortletConfig( ).getPortletContext( );
event.addError( ctx.getText( msg, event.getPortletRequest( ).getLocale( ) ) );
}
public static void assertNotEmpty( String value,
String msg,
ActionEvent event )
{
if ( ( value == null ) || ( value.length( ) == 0 ) )
{
addError( msg, event );
}
}
public static void assertURL( String value,
String msg,
ActionEvent event )
{
try
{
new URL( value );
}
catch ( MalformedURLException m )
{
addError( msg, event );
}
}
public static void assertLength( String value,
int maxlength,
String msg,
ActionEvent event )
{
int len = ( value != null )
? value.length( )
: 0;
if ( len > maxlength )
{
addError( msg, event );
}
}
}