blob: 579bb561807498827fe1f6099ed11e7109066458 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 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 API and implementation
*******************************************************************************/
package org.eclipse.jst.jsp.core.internal;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
import org.eclipse.jst.jsp.core.internal.java.search.JSPIndexManager;
import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport;
import org.eclipse.wst.sse.core.internal.encoding.CommonCharsetNames;
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
import org.eclipse.wst.sse.core.internal.preferences.CommonModelPreferenceNames;
import org.osgi.framework.BundleContext;
/**
* The main plugin class to be used in the desktop.
*/
public class JSPCorePlugin extends Plugin {
//The shared instance.
private static JSPCorePlugin plugin;
/**
* The constructor.
*/
public JSPCorePlugin() {
super();
plugin = this;
}
/**
* Returns the shared instance.
*/
public static JSPCorePlugin getDefault() {
return plugin;
}
/**
* Returns the workspace instance.
*/
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugin#initializeDefaultPluginPreferences()
*/
protected void initializeDefaultPluginPreferences() {
Preferences prefs = getDefault().getPluginPreferences();
// set model preference defaults
prefs.setDefault(CommonModelPreferenceNames.CLEANUP_TAG_NAME_CASE, CommonModelPreferenceNames.ASIS);
prefs.setDefault(CommonModelPreferenceNames.CLEANUP_ATTR_NAME_CASE, CommonModelPreferenceNames.ASIS);
prefs.setDefault(CommonModelPreferenceNames.INSERT_MISSING_TAGS, true);
prefs.setDefault(CommonModelPreferenceNames.QUOTE_ATTR_VALUES, true);
prefs.setDefault(CommonModelPreferenceNames.FORMAT_SOURCE, true);
prefs.setDefault(CommonModelPreferenceNames.CONVERT_EOL_CODES, false);
prefs.setDefault(CommonEncodingPreferenceNames.INPUT_CODESET, ""); //$NON-NLS-1$
String defaultEnc = CommonModelPreferenceNames.UTF_8;
String systemEnc = System.getProperty("file.encoding"); //$NON-NLS-1$
if (systemEnc != null) {
defaultEnc = CommonCharsetNames.getPreferredDefaultIanaName(systemEnc, CommonModelPreferenceNames.UTF_8);
}
prefs.setDefault(CommonEncodingPreferenceNames.OUTPUT_CODESET, defaultEnc);
prefs.setDefault(CommonEncodingPreferenceNames.END_OF_LINE_CODE, ""); //$NON-NLS-1$
prefs.setDefault(CommonModelPreferenceNames.TAB_WIDTH, CommonModelPreferenceNames.DEFAULT_TAB_WIDTH);
prefs.setDefault(CommonModelPreferenceNames.FORMATTING_SUPPORTED, true);
prefs.setDefault(CommonModelPreferenceNames.LINE_WIDTH, 72);
prefs.setDefault(CommonModelPreferenceNames.SPLIT_MULTI_ATTRS, false);
prefs.setDefault(CommonModelPreferenceNames.INDENT_USING_TABS, true);
prefs.setDefault(CommonModelPreferenceNames.CLEAR_ALL_BLANK_LINES, false);
prefs.setDefault(CommonModelPreferenceNames.PREFERRED_MARKUP_CASE_SUPPORTED, true);
prefs.setDefault(CommonModelPreferenceNames.TAG_NAME_CASE, CommonModelPreferenceNames.UPPER);
prefs.setDefault(CommonModelPreferenceNames.ATTR_NAME_CASE, CommonModelPreferenceNames.LOWER);
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
// JSPIndexManager depends on TaglibController, so TaglibController
// should be started first
TaglibController.startup();
// add JSPIndexManager to keep JSP Index up to date
// listening for IResourceChangeEvent.PRE_DELETE and IResourceChangeEvent.POST_CHANGE
ResourcesPlugin.getWorkspace().addResourceChangeListener(JSPIndexManager.getInstance(), IResourceChangeEvent.POST_CHANGE);
// https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=5091
// makes sure IndexManager is aware of our indexes
JSPIndexManager.getInstance().saveIndexes();
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
// stop listening
ResourcesPlugin.getWorkspace().removeResourceChangeListener(JSPIndexManager.getInstance());
// stop any searching/indexing
JSPSearchSupport.getInstance().setCanceled(true);
TaglibController.shutdown();
super.stop(context);
}
}