2 * Created on 09.08.2003
5 package net.sourceforge.phpdt.internal.ui.util;
7 import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
8 import net.sourceforge.phpeclipse.ui.overlaypages.Util;
10 import org.eclipse.core.resources.IFile;
16 public class PHPFileUtil {
17 public final static String[] PHP_EXTENSIONS = {
27 // public final static String[] HTML_EXTENSIONS = {
32 public final static String[] SMARTY_EXTENSIONS = {
36 public static boolean isPHPFile(IFile file) {
37 String extension = file.getFileExtension();
38 return isPHPFileName(file.getLocation().toString());
41 public final static String getFileExtension(String name) {
42 int index = name.lastIndexOf('.');
45 if (index == (name.length() - 1))
46 return null; //$NON-NLS-1$
47 return name.substring(index + 1);
51 * Returns true iff str.toLowerCase().endsWith(".php")
52 * implementation is not creating extra strings.
54 public final static boolean isPHPFileName(String name) {
55 String extension = getFileExtension(name);
56 if (extension==null) {
59 extension = extension.toLowerCase();
60 for (int i=0;i<PHP_EXTENSIONS.length;i++) {
61 if (extension.equals(PHP_EXTENSIONS[i])) {
69 * Returns true iff str.toLowerCase().endsWith(".html")
70 * implementation is not creating extra strings.
72 // public final static boolean isHTML_FileName(String name) {
73 // String extension = getFileExtension(name);
74 // if (extension==null) {
77 // extension = extension.toLowerCase();
78 // for (int i=0;i<HTML_EXTENSIONS.length;i++) {
79 // if (extension.equals(HTML_EXTENSIONS[i])) {
87 * Returns true iff str.toLowerCase().endsWith(".tpl")
88 * implementation is not creating extra strings.
90 // public final static boolean isTPL_FileName(String name) {
91 // String extension = getFileExtension(name);
92 // if (extension==null) {
95 // extension = extension.toLowerCase();
96 // for (int i=0;i<SMARTY_EXTENSIONS.length;i++) {
97 // if (extension.equals(SMARTY_EXTENSIONS[i])) {
105 * Returns true iff the file extension is a valid PHP Unit name
106 * implementation is not creating extra strings.
108 public final static boolean isValidPHPUnitName(String filename) {
109 return PHPFileUtil.isPHPFileName(filename);
111 // PHPFileUtil.isHTML_FileName(filename) ||
112 // PHPFileUtil.isTPL_FileName(filename);