Package net.sf.jportlet.service.velocity

Source Code of net.sf.jportlet.service.velocity.Runtime

/*
* Created on Apr 7, 2003
*/
package net.sf.jportlet.service.velocity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import net.sf.jportlet.portlet.Portlet;
import net.sf.jportlet.portlet.PortletWindow;
import net.sf.jportlet.util.Constants;
import net.sf.jportlet.util.HTMLHelper;


/**
* Helper for <a href="http://jakarta.apache.org/velocity">Velocity</a> templates.
*
* @author <a href="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
*/
public class Runtime
{
    //~ Methods ----------------------------------------------------------------

    /**
     * Return a {@link Portlet.Mode} by its name
     * @return Portlet.Mode
     */
    public Portlet.Mode getMode( String name )
    {
        return Portlet.Mode.fromString( name );
    }

    /**
     * Return the key of the returnURI
     * @return String
     */
    public String getReturnUriKey(  )
    {
        return Constants.RETURN_URI_KEY;
    }

    /**
     * Returns a localize text from the jPortlet <code>ResourceBundle</code>
     * @param key key of the text requester
     * @param locale target locale
     * @return String
     */
    public String getText( String key,
                           Locale locale )
    {
        try
        {
            ResourceBundle bundle = ResourceBundle.getBundle( Constants.SYSTEM_BUNDLE_NAME );
            return bundle.getString( key );
        }
        catch ( MissingResourceException m )
        {
            return "???" + key + "???";
        }
    }

    /**
     * Return a {@link PortletWindow.State} by its name
     * @return Portlet.Mode
     */
    public PortletWindow.State getWindowState( String name )
    {
        return PortletWindow.State.fromString( name );
    }
   
    /**
     * Return all the available <code>java.util.Locale</code>
     * @return
     */
    public Collection getLocales()
    {
        ArrayList locales = new ArrayList(  );
        Locale    available[] = Locale.getAvailableLocales(  );
        for ( int i = 0; i < available.length; i++ )
        {
            locales.add( available[ i ] );
        }

        return locales;
    }

    /**
     * @see HTMLHelper#encode(java.lang..String)
     */
    public String htmlEncode( String str )
    {
        return HTMLHelper.encode( str );
    }
}
TOP

Related Classes of net.sf.jportlet.service.velocity.Runtime

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.