import java.net.URL;

import java.util.Vector;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.MissingResourceException;


public class Properties
{
  protected ResourceBundle resources;


  public String getString(String nm)
  {
    if(resources == null) return null;

    String str;

    try {
      str = resources.getString(nm);
    } catch (MissingResourceException mre) {
      str = null;
    }

    return str;
  }

  public String[] getStrings(String nm)
  {
    String str = getString(nm);
    if(str == null) return null;

    Vector v = new Vector();
    StringTokenizer t = new StringTokenizer(str);
    String cmd[];

    while (t.hasMoreTokens()) v.addElement(t.nextToken());
    cmd = new String[v.size()];
    for(int i = 0; i < cmd.length; i++)
      cmd[i] = (String) v.elementAt(i);

    return cmd;
  }

  public URL getResource(String key)
  {
    String name = getString(key);

    if(name != null) {
      URL url = this.getClass().getResource(name);
      return url;
    }

    return null;
  }

  public Properties(String name) throws Exception
  {
    resources = null;

    try {
      resources = ResourceBundle.getBundle(name, Locale.getDefault());
    } catch (MissingResourceException mre) {
      throw new Exception("No se ha podido abrir el archivo de propiedades");
    }
  }
}
