| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2007 IBM Corporation and others. |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.publishing.ui.preferences; |
| |
| import org.eclipse.epf.library.LibraryService; |
| import org.eclipse.epf.library.LibraryServiceUtil; |
| import org.eclipse.epf.library.ui.preferences.LibraryUIPreferences; |
| import org.eclipse.epf.publishing.services.PublishOptions; |
| import org.eclipse.epf.publishing.ui.PublishingUIPlugin; |
| import org.eclipse.epf.uma.MethodConfiguration; |
| import org.eclipse.jface.preference.IPreferenceStore; |
| |
| /** |
| * Manages the Publishing UI preferences. |
| * |
| * @author Kelvin Low |
| * @author Jinhua Xi |
| * @since 1.0 fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=156630 |
| */ |
| public class PublishingUIPreferences { |
| |
| private static String defaultPublishPath = null; |
| |
| private static String defaultTitle = null; |
| |
| private static String defaultBannerImage = null; |
| |
| private static String defaultAboutHTML = null; |
| |
| private static String defaultFeedbackURL = null; |
| |
| static { |
| // Initialize the default preference values. |
| MethodConfiguration[] configs = LibraryServiceUtil |
| .getMethodConfigurations(LibraryService.getInstance() |
| .getCurrentMethodLibrary()); |
| IPreferenceStore store = PublishingUIPlugin.getDefault() |
| .getPreferenceStore(); |
| store.setDefault(PublishOptions.PUBLISH_PATH_DEFAULT, |
| getDefaultPublishPath()); |
| store.setDefault(PublishOptions.FEEDBACK_URL_DEFAULT, |
| getDefaultFeedbackURL()); |
| store.setDefault(PublishOptions.EXTRA_DESCRIPTOR_INFO, |
| getExtraDescriptorInfo(null)); |
| for (int i = 0; i < configs.length; i++) { |
| String configName = configs[i].getName(); |
| String prefix = getConfigPrefPrefix(configName); |
| store.setDefault(prefix + PublishOptions.PUBLISH_PATH, |
| getPublishPath(configName)); |
| store.setDefault(prefix + PublishOptions.TITLE, getDefaultTitle()); |
| store.setDefault(prefix + PublishOptions.BANNER_IMAGE, |
| getDefaultBannerImage()); |
| store.setDefault(prefix + PublishOptions.ABOUT_HTML, |
| getDefaultAboutHTML()); |
| store.setDefault(prefix + PublishOptions.FEEDBACK_URL, |
| getFeedbackURL(configName)); |
| // store.setDefault(prefix+PublishOptions.WEBAPP_NAME, |
| // getWebAppName(configName)); |
| store.setDefault(prefix + PublishOptions.INCLUDE_GLOSSARY, |
| getIncludeGlossary(configName)); |
| store.setDefault(prefix + PublishOptions.INCLUDE_INDEX, |
| getIncludeIndex(configName)); |
| // store.setDefault(prefix+PublishOptions.INCLUDE_CREATE_WAR, |
| // getIncludeWAR(configName)); |
| // store.setDefault(PublishOptions.INCLUDE_SEARCH, true); |
| // store.setDefault(PublishOptions.INCLUDE_PROCESS_CUSTOMIZATION, |
| // true); |
| store.setDefault(prefix + PublishOptions.CHECK_EXTERNAL_LINKS, |
| getCheckExternalLinks(configName)); |
| store.setDefault(prefix + PublishOptions.CONVERT_BROKEN_LINKS, |
| getConvertBrokenLinks(configName)); |
| store.setDefault(prefix + PublishOptions.LIGHT_WEIGHT_TREE, |
| getLightWeightTree(configName)); |
| store.setDefault(prefix + PublishOptions.EXTRA_DESCRIPTOR_INFO, |
| getExtraDescriptorInfo(configName)); |
| store.setDefault(prefix |
| + LibraryUIPreferences.PUBLISH_UNOPEN_ACTIVITY_DD, |
| getPublishUnopenActivitydd(configName)); |
| store.setDefault(prefix |
| + LibraryUIPreferences.PUBLISH_AD_FOR_ACTIVITY_EXTENSION, |
| getPublishADForActivityExtension(configName)); |
| } |
| } |
| |
| /** |
| * Gets the publish path preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return the publish path |
| */ |
| public static String getPublishPath(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getString( |
| getConfigPrefPrefix(configName) + PublishOptions.PUBLISH_PATH); |
| } |
| |
| /** |
| * Sets the publish path preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param path |
| * the publish path |
| */ |
| public static void setPublishPath(String configName, String path) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) + PublishOptions.PUBLISH_PATH, |
| path); |
| } |
| |
| /** |
| * Gets the web site title preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return the web site title |
| */ |
| public static String getTitle(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getString( |
| getConfigPrefPrefix(configName) + PublishOptions.TITLE); |
| } |
| |
| /** |
| * Sets the web site title preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param title |
| * the web site title |
| */ |
| public static void setTitle(String configName, String title) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) + PublishOptions.TITLE, title); |
| } |
| |
| /** |
| * Gets the banner image preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return the banner image |
| */ |
| public static String getBannerImage(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getString( |
| getConfigPrefPrefix(configName) + PublishOptions.BANNER_IMAGE); |
| } |
| |
| /** |
| * Sets the banner image preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param image |
| * The banner image. |
| */ |
| public static void setBannerImage(String configName, String image) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) + PublishOptions.BANNER_IMAGE, |
| image); |
| } |
| |
| /** |
| * Gets the about HTML file path preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return the about HTML file path |
| */ |
| public static String getAboutHTML(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getString( |
| getConfigPrefPrefix(configName) + PublishOptions.ABOUT_HTML); |
| } |
| |
| /** |
| * Sets the about HTML file path preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param file |
| * the about HTML file path |
| */ |
| public static void setAboutHTML(String configName, String file) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) + PublishOptions.ABOUT_HTML, |
| file); |
| } |
| |
| /** |
| * Gets the feedback URL preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return the feedback URL |
| */ |
| public static String getFeedbackURL(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getString( |
| getConfigPrefPrefix(configName) + PublishOptions.FEEDBACK_URL); |
| } |
| |
| /** |
| * Sets the feedback URL preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param url |
| * the feedback URL |
| */ |
| public static void setFeedbackURL(String configName, String url) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) + PublishOptions.FEEDBACK_URL, |
| url); |
| } |
| |
| /** |
| * Gets the include glossary preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return <code>true</code> if the preference is set |
| */ |
| public static boolean getIncludeGlossary(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getBoolean( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.INCLUDE_GLOSSARY); |
| } |
| |
| /** |
| * Sets the include glossary preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param value |
| * the preference value |
| */ |
| public static void setIncludeGlossary(String configName, boolean value) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.INCLUDE_GLOSSARY, value); |
| } |
| |
| /** |
| * Gets the include index preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return <code>true</code> if the preference is set |
| */ |
| public static boolean getIncludeIndex(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getBoolean( |
| getConfigPrefPrefix(configName) + PublishOptions.INCLUDE_INDEX); |
| } |
| |
| /** |
| * Sets the include index preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param value |
| * the preference value |
| */ |
| public static void setIncludeIndex(String configName, boolean flag) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) + PublishOptions.INCLUDE_INDEX, |
| flag); |
| } |
| |
| /** |
| * Gets the convert broken links preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return <code>true</code> if the preference is set |
| */ |
| public static boolean getConvertBrokenLinks(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getBoolean( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.CONVERT_BROKEN_LINKS); |
| } |
| |
| /** |
| * Sets the convert broken links preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param value |
| * the preference value |
| */ |
| public static void setConvertBrokenLinks(String configName, boolean flag) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.CONVERT_BROKEN_LINKS, flag); |
| } |
| |
| /** |
| * Gets the light weight tree preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return <code>true</code> if the preference is set |
| */ |
| public static boolean getLightWeightTree(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getBoolean( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.LIGHT_WEIGHT_TREE); |
| } |
| |
| /** |
| * Sets the light weight tree preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param value |
| * the preference value |
| */ |
| public static void setLightWeightTree(String configName, boolean flag) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.LIGHT_WEIGHT_TREE, flag); |
| } |
| |
| /** |
| * Gets the extra descriptor infopreference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return <code>true</code> if the preference is set |
| */ |
| public static boolean getExtraDescriptorInfo(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getBoolean( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.EXTRA_DESCRIPTOR_INFO); |
| } |
| |
| /** |
| * Sets the extra descriptor info preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param value |
| * the preference value |
| */ |
| public static void setExtraDescriptorInfo(String configName, boolean flag) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.EXTRA_DESCRIPTOR_INFO, flag); |
| } |
| |
| /** |
| * Returns the web app name that was saved in a previous session. |
| * |
| * @return The saved web app name. |
| */ |
| public static String getWebAppName(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getString( |
| getConfigPrefPrefix(configName) + PublishOptions.WEBAPP_NAME); |
| } |
| |
| /** |
| * Saves the current web app name to preference store. |
| * |
| * @param url |
| * A web app name. |
| */ |
| public static void setWebAppName(String configName, String name) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) + PublishOptions.WEBAPP_NAME, |
| name); |
| } |
| |
| /** |
| * Gets the include search preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return <code>true</code> if the preference is set |
| */ |
| public static boolean getIncludeSearch(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore() |
| .getBoolean( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.INCLUDE_SEARCH); |
| } |
| |
| /** |
| * Sets the include search preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param value |
| * the preference value |
| */ |
| public static void setIncludeSearch(String configName, boolean flag) { |
| PublishingUIPlugin.getDefault().getPreferenceStore() |
| .setValue( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.INCLUDE_SEARCH, flag); |
| } |
| |
| /** |
| * Gets the check external links preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return <code>true</code> if the preference is set |
| */ |
| public static boolean getCheckExternalLinks(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getBoolean( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.CHECK_EXTERNAL_LINKS); |
| } |
| |
| /** |
| * Sets the check external links preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param value |
| * the preference value |
| */ |
| public static void setCheckExternalLinks(String configName, boolean flag) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| getConfigPrefPrefix(configName) |
| + PublishOptions.CHECK_EXTERNAL_LINKS, flag); |
| } |
| |
| /** |
| * Gets the publish unopen activity detail diagrams preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @return <code>true</code> if the preference is set |
| */ |
| public static boolean getPublishUnopenActivitydd(String configName) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getBoolean( |
| getConfigPrefPrefix(configName) |
| + LibraryUIPreferences.PUBLISH_UNOPEN_ACTIVITY_DD); |
| } |
| |
| /** |
| * Sets the publish unopen activity detail diagrams preference value. |
| * |
| * @param configName |
| * a method configuration name |
| * @param value |
| * the preference value |
| */ |
| public static void setPublishUnopenActivitydd(String configName, |
| boolean flag) { |
| PublishingUIPlugin |
| .getDefault() |
| .getPreferenceStore() |
| .setValue( |
| getConfigPrefPrefix(configName) |
| + LibraryUIPreferences.PUBLISH_UNOPEN_ACTIVITY_DD, |
| flag); |
| } |
| |
| /** |
| * Save current publish AD for activity extension flag to preference store |
| * |
| * @param configName |
| * the configuration name this flag is for |
| * @param flag |
| * the publish AD for activity extension flag |
| */ |
| public static void setPublishADForActivityExtension(String configName, |
| boolean flag) { |
| PublishingUIPlugin |
| .getDefault() |
| .getPreferenceStore() |
| .setValue( |
| getConfigPrefPrefix(configName) |
| + LibraryUIPreferences.PUBLISH_AD_FOR_ACTIVITY_EXTENSION, |
| flag); |
| } |
| |
| /** |
| * return the publish AD for activity extension flag that was saved in |
| * previous session |
| * |
| * @param configName |
| * the configuration name this flag is for |
| * @return the publish AD for activity extension flag |
| */ |
| public static boolean getPublishADForActivityExtension(String configName) { |
| return PublishingUIPlugin |
| .getDefault() |
| .getPreferenceStore() |
| .getBoolean( |
| getConfigPrefPrefix(configName) |
| + LibraryUIPreferences.PUBLISH_AD_FOR_ACTIVITY_EXTENSION); |
| } |
| |
| /** |
| * Returns the default publish path. |
| * |
| * @return The default publish path. |
| */ |
| public static String getDefaultPublishPath() { |
| defaultPublishPath = PublishingUIPlugin.getDefault() |
| .getPreferenceStore().getString( |
| PublishOptions.PUBLISH_PATH_DEFAULT).trim(); |
| if (defaultPublishPath == null || defaultPublishPath.length() <= 0) { |
| defaultPublishPath = getInitDefaultPublishPath(); |
| } |
| return defaultPublishPath; |
| } |
| |
| public static String getInitDefaultPublishPath() { |
| |
| String userHome = System.getProperty("user.home").replace('\\', '/'); //$NON-NLS-1$ |
| String path = PublishingUIPlugin.getDefault().getString("publishPath"); //$NON-NLS-1$ |
| if (path == null || path.length() == 0 || path.startsWith("[")) { //$NON-NLS-1$ |
| path = userHome + "/publish"; //$NON-NLS-1$ |
| } else if (path.startsWith("<user.home>")) { //$NON-NLS-1$ |
| path = userHome + path.substring(11); |
| } |
| if (System.getProperty("file.separator").equals("\\")) { //$NON-NLS-1$ //$NON-NLS-2$ |
| path = path.replace('/', '\\'); |
| } |
| |
| int idx = -1; |
| if ((idx = path.indexOf("<app.name>")) >= 0) { //$NON-NLS-1$ |
| // String appNameProper = LibraryUIManager.getAppName(); |
| String appNameProper = LibraryUIPreferences |
| .getApplicationShortName(); |
| path = path.substring(0, idx) + appNameProper |
| + path.substring(idx + 10); |
| } |
| |
| return path; |
| } |
| |
| public static void setDefaultPublishPath(String path) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| PublishOptions.PUBLISH_PATH_DEFAULT, path); |
| } |
| |
| /** |
| * Returns the default title for the published website. |
| * |
| * @return The default title for the published website. |
| */ |
| public static String getDefaultTitle() { |
| if (defaultTitle == null) { |
| String url = PublishingUIPlugin.getDefault().getString("title"); //$NON-NLS-1$ |
| if (url == null || url.length() == 0 || url.startsWith("[")) { //$NON-NLS-1$ |
| url = ""; //$NON-NLS-1$ |
| } |
| defaultTitle = url; |
| } |
| return defaultTitle; |
| } |
| |
| /** |
| * Returns the default banner image for the published website. |
| * |
| * @return The default banner image for the published website. |
| */ |
| public static String getDefaultBannerImage() { |
| if (defaultBannerImage == null) { |
| String image = PublishingUIPlugin.getDefault().getString( |
| "bannerImage"); //$NON-NLS-1$ |
| if (image == null || image.length() == 0 || image.startsWith("[")) { //$NON-NLS-1$ |
| image = ""; //$NON-NLS-1$ |
| } |
| defaultBannerImage = image; |
| } |
| return defaultBannerImage; |
| } |
| |
| /** |
| * Returns the default about HTML for the published website. |
| * |
| * @return The default about HTML for the published website. |
| */ |
| public static String getDefaultAboutHTML() { |
| if (defaultAboutHTML == null) { |
| String file = PublishingUIPlugin.getDefault() |
| .getString("aboutHTML"); //$NON-NLS-1$ |
| if (file == null || file.length() == 0 || file.startsWith("[")) { //$NON-NLS-1$ |
| file = ""; //$NON-NLS-1$ |
| } |
| defaultAboutHTML = file; |
| } |
| return defaultAboutHTML; |
| } |
| |
| /** |
| * Returns the default feedback URL. |
| * |
| * @return The default feedback URL. |
| */ |
| public static String getDefaultFeedbackURL() { |
| defaultFeedbackURL = PublishingUIPlugin.getDefault() |
| .getPreferenceStore().getString( |
| PublishOptions.FEEDBACK_URL_DEFAULT).trim(); |
| if (defaultFeedbackURL == null || defaultFeedbackURL.length() <= 0) { |
| defaultFeedbackURL = getInitDefaultFeedbackURL(); |
| } |
| return defaultFeedbackURL; |
| } |
| |
| public static String getInitDefaultFeedbackURL() { |
| String url = PublishingUIPlugin.getDefault().getString("feedbackURL"); //$NON-NLS-1$ |
| if (url == null || url.length() == 0 || url.startsWith("[")) { //$NON-NLS-1$ |
| url = "http://www.published_website.com/feedback"; //$NON-NLS-1$ |
| } |
| |
| return url; |
| } |
| |
| public static void setDefaultFeedbackURL(String path) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue( |
| PublishOptions.FEEDBACK_URL_DEFAULT, path); |
| } |
| |
| // genaric method to get/set values |
| public static void setValue(String name, String value) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue(name, |
| value); |
| |
| } |
| |
| public static void setValue(String name, boolean value) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue(name, |
| value); |
| |
| } |
| |
| public static String getStringValue(String name) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getString( |
| name); |
| } |
| |
| public static boolean getBooleanValue(String name) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getBoolean( |
| name); |
| } |
| |
| public static void setDefaultValue(String name, String value) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue(name, |
| value); |
| |
| } |
| |
| public static void setDefaultValue(String name, boolean value) { |
| PublishingUIPlugin.getDefault().getPreferenceStore().setValue(name, |
| value); |
| |
| } |
| |
| public static String getDefaultStringValue(String name) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getString( |
| name); |
| } |
| |
| public static boolean getDefaultBooleanValue(String name) { |
| return PublishingUIPlugin.getDefault().getPreferenceStore().getBoolean( |
| name); |
| } |
| |
| public static String getConfigPrefPrefix(String configName) { |
| try { |
| MethodConfiguration config = LibraryServiceUtil |
| .getMethodConfiguration(LibraryService.getInstance() |
| .getCurrentMethodLibrary(), configName); |
| return configName + "." + config.getGuid() + "."; |
| } catch (Exception e) { |
| return ""; |
| } |
| } |
| |
| public static void saveAllPreferences() { |
| PublishingUIPlugin.getDefault().savePluginPreferences(); |
| } |
| } |