1 package net.sourceforge.phpeclipse.ui.overlaypages;
4 import java.util.ArrayList;
6 import java.util.StringTokenizer;
8 import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
9 import net.sourceforge.phpeclipse.ui.WebUI;
10 import net.sourceforge.phpeclipse.ui.preferences.PHPMiscProjectPreferences;
11 import net.sourceforge.phpeclipse.ui.preferences.PHPPreviewProjectPreferences;
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IPath;
17 import org.eclipse.core.runtime.Path;
18 import org.eclipse.core.runtime.QualifiedName;
20 public class ProjectPrefUtil {
21 public static String getMiscProjectsPreferenceValue(IResource resource,
23 return getOverlayedPrefProjectValue(resource,
24 PHPMiscProjectPreferences.PREF_ID, key);
27 public static List getIncludePaths(IResource resource) {
28 String includePaths = getMiscProjectsPreferenceValue(resource,
29 IPreferenceConstants.PHP_INCLUDE_PATHS);
30 ArrayList list = new ArrayList();
31 if (includePaths != null) {
32 StringTokenizer st = new StringTokenizer(includePaths,
33 File.pathSeparator + "\n\r");//$NON-NLS-1$
34 while (st.hasMoreElements()) {
35 list.add(st.nextElement());
41 public static IPath getDocumentRoot(IResource resource) {
42 String documentRoot = getMiscProjectsPreferenceValue(resource,
43 IPreferenceConstants.PHP_DOCUMENTROOT_PREF);
44 IPath path = new Path(documentRoot);
45 // documentRoot = documentRoot.replace('\\', '/');
49 public static String getOverlayedPrefProjectValue(IResource resource,
50 String pageId, String key) {
51 IProject project = resource.getProject();
53 if (useProjectSettings(project, pageId)) {
54 value = getProperty(resource, pageId, key);
58 return WebUI.getDefault().getPreferenceStore().getString(key);
61 public static String getOverlayedPrefResourceValue(IResource resource,
62 String pageId, String key) {
64 if (useProjectSettings(resource, pageId)) {
65 value = getProperty(resource, pageId, key);
69 return WebUI.getDefault().getPreferenceStore().getString(key);
72 public static boolean getPreviewBooleanValue(IResource resource, String key) {
73 return getOverlayedPrefResourceValue(resource,
74 PHPPreviewProjectPreferences.PREF_ID, key).equals("true");
77 // public static String getPreviewStringValue(IResource resource, String key) {
78 // return getOverlayedPrefResourceValue(resource,
79 // PHPPreviewProjectPreferences.PREF_ID, key);
82 private static String getProperty(IResource resource, String pageId,
86 .getPersistentProperty(new QualifiedName(pageId, key));
87 } catch (CoreException e) {
92 private static boolean useProjectSettings(IResource resource, String pageId) {
93 String use = getProperty(resource, pageId,
94 FieldEditorOverlayPage.USEPROJECTSETTINGS);
95 return "true".equals(use);