package com.sptci.echo2;

import java.io.InputStream;

import nextapp.echo2.app.ImageReference;
import nextapp.echo2.app.ResourceImageReference;
import nextapp.echo2.app.StyleSheet;
import nextapp.echo2.app.componentxml.ComponentXmlException;
import nextapp.echo2.app.componentxml.StyleSheetLoader;

/**
 * Utility class to load the application style XML file.  This class
 * assumes that the style file will be available as
 * <code>/META-INF/resource/style/Default.stylesheet</code>.
 *
 * <p>Copyright 2006 Sans Pareil Technologies, Inc.</p>
 * @author Rakesh Vidyadharan 2006-01-21
 * @version $Id: Styles.java,v 1.1 2006/02/06 00:32:23 rakesh Exp $
 */
public class Styles 
{
  /**
   * The location of the application images.
   *
   * {@value}
   */
  public static final String IMAGE_PATH = 
    "/META-INF/resource/image/";

  /**
   * The location of the XML style sheet.
   *
   * {@value}
   */
  public static final String STYLE_PATH = 
    "/META-INF/resource/style/";
  
  /**
   * Default application style sheet.
   */
  public static final StyleSheet DEFAULT_STYLE_SHEET;

  /**
   * Initialise the default style sheet.
   */
  static 
  {
    try 
    {
      DEFAULT_STYLE_SHEET = 
        StyleSheetLoader.load( 
            getStyleInputStream( "Default.stylesheet" ), 
            Thread.currentThread().getContextClassLoader() );
    } 
    catch ( ComponentXmlException ex )
    {
      throw new BindingException( ex );
    }
  }

  /**
   * Open the {@link #STYLE_PATH} as a resource stream and return
   * the <code>InputStream</code> to it.
   *
   * @param file The name of the style sheet to open
   * @return InputStream The InputStream for the style sheet.
   */
  protected static InputStream getStyleInputStream( String file )
  {
    Class cls = com.sptci.echo2.Styles.class;
    return cls.getResourceAsStream( STYLE_PATH + file );
  }
}
