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).toLowerCase();
56 if (extension==null) {
59 for (int i=0;i<PHP_EXTENSIONS.length;i++) {
60 if (extension.equals(PHP_EXTENSIONS[i])) {
68 * Returns true iff str.toLowerCase().endsWith(".html")
69 * implementation is not creating extra strings.
71 // public final static boolean isHTML_FileName(String name) {
72 // String extension = getFileExtension(name).toLowerCase();
73 // if (extension==null) {
76 // for (int i=0;i<HTML_EXTENSIONS.length;i++) {
77 // if (extension.equals(HTML_EXTENSIONS[i])) {
85 * Returns true iff str.toLowerCase().endsWith(".tpl")
86 * implementation is not creating extra strings.
88 // public final static boolean isTPL_FileName(String name) {
89 // String extension = getFileExtension(name).toLowerCase();
90 // if (extension==null) {
93 // for (int i=0;i<SMARTY_EXTENSIONS.length;i++) {
94 // if (extension.equals(SMARTY_EXTENSIONS[i])) {
102 * Returns true iff the file extension is a valid PHP Unit name
103 * implementation is not creating extra strings.
105 public final static boolean isValidPHPUnitName(String filename) {
106 return PHPFileUtil.isPHPFileName(filename);
108 // PHPFileUtil.isHTML_FileName(filename) ||
109 // PHPFileUtil.isTPL_FileName(filename);