Package net.sf.jportlet.portlets

Source Code of net.sf.jportlet.portlets.ValidationHelper

/*
* 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 );
        }
    }

}
TOP

Related Classes of net.sf.jportlet.portlets.ValidationHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.