code-template needs new context type
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / util / PHPFileUtil.java
1 /*
2  * Created on 09.08.2003
3  *
4  */
5 package net.sourceforge.phpdt.internal.ui.util;
6
7 import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
8 import net.sourceforge.phpeclipse.ui.overlaypages.Util;
9
10 import org.eclipse.core.resources.IFile;
11
12 /**
13  * @author khartlage
14  *
15  */
16 public class PHPFileUtil {
17   public final static String[] PHP_EXTENSIONS = {
18       "php",
19       "php3",
20       "php4",
21       "php5",
22       "phtml",
23       "module",  // drupal
24       "inc",
25       "class"
26   };
27 //  public final static String[] HTML_EXTENSIONS = {
28 //      "html",
29 //      "htm",
30 //      "xhtml"
31 //  };
32   public final static String[] SMARTY_EXTENSIONS = {
33       "tpl"
34   };
35   
36   public  static boolean isPHPFile(IFile file) {
37     String extension = file.getFileExtension();
38     return isPHPFileName(file.getLocation().toString());
39   }
40
41   public final static String getFileExtension(String name) {
42         int index = name.lastIndexOf('.');
43         if (index == -1)
44                 return null;
45         if (index == (name.length() - 1))
46                 return null; //$NON-NLS-1$
47         return name.substring(index + 1);
48 }
49   
50   /**
51    * Returns true iff str.toLowerCase().endsWith(".php")
52    * implementation is not creating extra strings.
53    */
54   public final static boolean isPHPFileName(String name) {
55     String extension = getFileExtension(name);
56     if (extension==null) {
57       return false;
58     }
59     extension = extension.toLowerCase();
60     for (int i=0;i<PHP_EXTENSIONS.length;i++) {
61       if (extension.equals(PHP_EXTENSIONS[i])) {
62         return true;
63       }
64     }
65     return false;
66   }
67     
68   /**
69    * Returns true iff str.toLowerCase().endsWith(".html")
70    * implementation is not creating extra strings.
71    */
72 //  public final static boolean isHTML_FileName(String name) {
73 //    String extension = getFileExtension(name);
74 //    if (extension==null) {
75 //      return false;
76 //    }
77 //  extension = extension.toLowerCase();
78 //    for (int i=0;i<HTML_EXTENSIONS.length;i++) {
79 //      if (extension.equals(HTML_EXTENSIONS[i])) {
80 //        return true;
81 //      }
82 //    }
83 //    return false;
84 //  }
85   
86   /**
87    * Returns true iff str.toLowerCase().endsWith(".tpl")
88    * implementation is not creating extra strings.
89    */
90 //  public final static boolean isTPL_FileName(String name) {
91 //    String extension = getFileExtension(name);
92 //    if (extension==null) {
93 //      return false;
94 //    }
95 //  extension = extension.toLowerCase();
96 //    for (int i=0;i<SMARTY_EXTENSIONS.length;i++) {
97 //      if (extension.equals(SMARTY_EXTENSIONS[i])) {
98 //        return true;
99 //      }
100 //    }
101 //    return false;
102 //  }
103   
104   /**
105          * Returns true iff the file extension is a valid PHP Unit name
106          * implementation is not creating extra strings.
107          */
108         public final static boolean isValidPHPUnitName(String filename) {
109                 return PHPFileUtil.isPHPFileName(filename);
110 //              ||
111 //                     PHPFileUtil.isHTML_FileName(filename) ||
112 //                         PHPFileUtil.isTPL_FileName(filename);
113         }
114 }