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, String key) {
22 return getOverlayedPrefProjectValue(resource, PHPMiscProjectPreferences.PREF_ID, key);
25 public static List getIncludePaths(IResource resource) {
26 String includePaths = getMiscProjectsPreferenceValue(resource, IPreferenceConstants.PHP_INCLUDE_PATHS);
27 ArrayList list = new ArrayList();
28 if (includePaths != null) {
29 StringTokenizer st = new StringTokenizer(includePaths, File.pathSeparator + "\n\r");//$NON-NLS-1$
30 while (st.hasMoreElements()) {
31 list.add(st.nextElement());
37 public static IPath getDocumentRoot(IResource resource) {
38 String documentRoot = getMiscProjectsPreferenceValue(resource, IPreferenceConstants.PHP_DOCUMENTROOT_PREF);
39 IPath path = new Path(documentRoot);
40 // documentRoot = documentRoot.replace('\\', '/');
44 public static String getOverlayedPrefProjectValue(IResource resource, String pageId, String key) {
45 IProject project = resource.getProject();
47 if (useProjectSettings(project, pageId)) {
48 value = getProperty(resource, pageId, key);
52 return WebUI.getDefault().getPreferenceStore().getString(key);
55 public static String getOverlayedPrefResourceValue(IResource resource, String pageId, String key) {
57 if (useProjectSettings(resource, pageId)) {
58 value = getProperty(resource, pageId, key);
62 return WebUI.getDefault().getPreferenceStore().getString(key);
65 public static boolean getPreviewBooleanValue(IResource resource, String key) {
66 return getOverlayedPrefResourceValue(resource, PHPPreviewProjectPreferences.PREF_ID, key).equals("true");
69 public static String getPreviewStringValue(IResource resource, String key) {
70 return getOverlayedPrefResourceValue(resource, PHPPreviewProjectPreferences.PREF_ID, key);
73 private static String getProperty(IResource resource, String pageId, String key) {
75 return resource.getPersistentProperty(new QualifiedName(pageId, key));
76 } catch (CoreException e) {
81 private static boolean useProjectSettings(IResource resource, String pageId) {
82 String use = getProperty(resource, pageId, FieldEditorOverlayPage.USEPROJECTSETTINGS);
83 return "true".equals(use);