2  * Created on 09.08.2003
 
   5 package net.sourceforge.phpdt.internal.ui.util;
 
   7 import java.util.ArrayList;
 
   8 import java.util.StringTokenizer;
 
  10 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
  12 import org.eclipse.core.resources.IFile;
 
  13 import org.eclipse.jface.preference.IPreferenceStore;
 
  19 public class PHPFileUtil {
 
  20   private static String[] PHP_EXTENSIONS = null;
 
  28   //      "module", // drupal
 
  32   //  public final static String[] HTML_EXTENSIONS = {
 
  37   public final static String[] SMARTY_EXTENSIONS = { "tpl" };
 
  39   public static boolean isPHPFile(IFile file) {
 
  40     String extension = file.getFileExtension();
 
  41     return isPHPFileName(file.getLocation().toString());
 
  44   public final static String getFileExtension(String name) {
 
  45     int index = name.lastIndexOf('.');
 
  48     if (index == (name.length() - 1))
 
  49       return null; //$NON-NLS-1$
 
  50     return name.substring(index + 1);
 
  54    * Returns true iff str.toLowerCase().endsWith(".php") implementation is not creating extra strings.
 
  56   public final static boolean isPHPFileName(String name) {
 
  57     String extension = getFileExtension(name);
 
  58     if (extension == null) {
 
  61     extension = extension.toLowerCase();
 
  62     PHP_EXTENSIONS = getExtensions();
 
  63     if (PHP_EXTENSIONS == null) {
 
  66     for (int i = 0; i < PHP_EXTENSIONS.length; i++) {
 
  67       if (extension.equals(PHP_EXTENSIONS[i])) {
 
  75    * Returns true iff str.toLowerCase().endsWith(".html") implementation is not creating extra strings.
 
  77   //  public final static boolean isHTML_FileName(String name) {
 
  78   //    String extension = getFileExtension(name);
 
  79   //    if (extension==null) {
 
  82   //  extension = extension.toLowerCase();
 
  83   //    for (int i=0;i<HTML_EXTENSIONS.length;i++) {
 
  84   //      if (extension.equals(HTML_EXTENSIONS[i])) {
 
  91    * Returns true iff str.toLowerCase().endsWith(".tpl") implementation is not creating extra strings.
 
  93   //  public final static boolean isTPL_FileName(String name) {
 
  94   //    String extension = getFileExtension(name);
 
  95   //    if (extension==null) {
 
  98   //  extension = extension.toLowerCase();
 
  99   //    for (int i=0;i<SMARTY_EXTENSIONS.length;i++) {
 
 100   //      if (extension.equals(SMARTY_EXTENSIONS[i])) {
 
 107    * Returns true iff the file extension is a valid PHP Unit name implementation is not creating extra strings.
 
 109   public final static boolean isValidPHPUnitName(String filename) {
 
 110     return PHPFileUtil.isPHPFileName(filename);
 
 112     //                 PHPFileUtil.isHTML_FileName(filename) ||
 
 113     //                     PHPFileUtil.isTPL_FileName(filename);
 
 117    * @return Returns the PHP extensions.
 
 119   public static String[] getExtensions() {
 
 120     if (PHP_EXTENSIONS == null) {
 
 121       ArrayList list = new ArrayList();
 
 122       final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
 
 123       String extensions = store.getString(PHPeclipsePlugin.PHP_EXTENSION_PREFS);
 
 124       extensions = extensions.trim();
 
 125       if (extensions.length() != 0) {
 
 126         StringTokenizer tokenizer = new StringTokenizer(extensions, " ,;:/-|");
 
 128         while (tokenizer.hasMoreTokens()) {
 
 129           token = tokenizer.nextToken();
 
 130           if (token != null && token.length() >= 1) {
 
 134         if (list.size() != 0) {
 
 135           PHP_EXTENSIONS = new String[list.size()];
 
 136           for (int i = 0; i < list.size(); i++) {
 
 137             PHP_EXTENSIONS[i] = (String) list.get(i);
 
 142     return PHP_EXTENSIONS;
 
 146    * @param php_extensions
 
 147    *          The PHP extensions to set.
 
 149   public static void setExtensins(String[] php_extensions) {
 
 150     PHP_EXTENSIONS = php_extensions;