use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.
the class HTMLContentProperties method getPreferences.
/**
* Get the preferences node associated with the given project scope and
* preference key (subNode) If create is true, the preference node will be
* created if one does not already exist
*
* @param project
* the project the preference node is under
* @param preferenceKey
* the subnode/category the preference node is located in
* @param create
* if true, a preference node will be created if one does not
* already exist
* @return Preferences associated with the given project scope and
* preference key. null if one could not be found and create is
* false
*/
static Preferences getPreferences(IProject project, String preferenceKey, boolean create) {
if (create)
// create all nodes down to the one we are interested in
return new ProjectScope(project).getNode(HTMLCORE_ID).node(preferenceKey);
// be careful looking up for our node so not to create any nodes as
// side effect
Preferences node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
try {
// for now, take the long way
if (!node.nodeExists(project.getName()))
return null;
node = node.node(project.getName());
if (!node.nodeExists(HTMLCORE_ID))
return null;
node = node.node(HTMLCORE_ID);
if (!node.nodeExists(preferenceKey))
return null;
return node.node(preferenceKey);
} catch (BackingStoreException e) {
// nodeExists failed
// $NON-NLS-1$
Logger.log(Logger.WARNING_DEBUG, "Could not retrieve preference node", e);
}
return null;
}
use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.
the class CSSCorePreferencesTest method testDelimiterPreferences.
/**
* Tests line delimiter preferences by making sure document created
* follows line delimiter preference.
*/
public void testDelimiterPreferences() {
// check if content type preferences match
String preferredDelimiter = ContentTypeEncodingPreferences.getPreferredNewLineDelimiter(ContentTypeIdForCSS.ContentTypeID_CSS);
Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForCSS.ContentTypeID_CSS);
String gatewayDelimiter = prefs.get(CommonEncodingPreferenceNames.END_OF_LINE_CODE, null);
assertEquals("ContentTypeEncodingPreferences and ContentBasedPreferenceGateway preferences do not match", gatewayDelimiter, preferredDelimiter);
// set a particular line delimiter
prefs.put(CommonEncodingPreferenceNames.END_OF_LINE_CODE, CommonEncodingPreferenceNames.LF);
// create document
CSSDocumentLoader loader = new CSSDocumentLoader();
IEncodedDocument document = loader.createNewStructuredDocument();
String documentDelimiter = document.getPreferredLineDelimiter();
// verify delimiter in document matches preference
assertEquals("Delimiter in document does not match preference", CommonEncodingPreferenceNames.STRING_LF, documentDelimiter);
// return to original preference
prefs.remove(CommonEncodingPreferenceNames.END_OF_LINE_CODE);
}
use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.
the class HTMLCorePreferencesTest method testDelimiterPreferences.
/**
* Tests line delimiter preferences by making sure document created
* follows line delimiter preference.
*/
public void testDelimiterPreferences() {
// check if content type preferences match
String preferredDelimiter = ContentTypeEncodingPreferences.getPreferredNewLineDelimiter(ContentTypeIdForHTML.ContentTypeID_HTML);
Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForHTML.ContentTypeID_HTML);
String gatewayDelimiter = prefs.get(CommonEncodingPreferenceNames.END_OF_LINE_CODE, null);
assertEquals("ContentTypeEncodingPreferences and ContentBasedPreferenceGateway preferences do not match", gatewayDelimiter, preferredDelimiter);
// set a particular line delimiter
prefs.put(CommonEncodingPreferenceNames.END_OF_LINE_CODE, CommonEncodingPreferenceNames.LF);
// create document
HTMLDocumentLoader loader = new HTMLDocumentLoader();
IEncodedDocument document = loader.createNewStructuredDocument();
String documentDelimiter = document.getPreferredLineDelimiter();
// verify delimiter in document matches preference
assertEquals("Delimiter in document does not match preference", CommonEncodingPreferenceNames.STRING_LF, documentDelimiter);
// return to original preference
prefs.remove(CommonEncodingPreferenceNames.END_OF_LINE_CODE);
}
use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.
the class PrefUtil method getProperty.
private static String getProperty(String property) {
// Importance order is:
// default-default < instanceScope < configurationScope < systemProperty
// < envVar
String value = null;
if (value == null) {
value = System.getenv(property);
}
if (value == null) {
value = System.getProperty(property);
}
if (value == null) {
IPreferencesService preferencesService = Platform.getPreferencesService();
String key = property;
if (property != null && property.startsWith(SSECorePlugin.ID)) {
// +1, include the "."
key = property.substring(SSECorePlugin.ID.length() + 1, property.length());
}
InstanceScope instance = new InstanceScope();
ConfigurationScope config = new ConfigurationScope();
Preferences instanceNode = instance.getNode(SSECorePlugin.ID);
Preferences configNode = config.getNode(SSECorePlugin.ID);
value = preferencesService.get(key, getDefault(property), new Preferences[] { configNode, instanceNode });
}
return value;
}
use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.
the class CSSContentProperties method getPreferences.
/**
* Get the preferences node associated with the given project scope and
* preference key (subNode) If create is true, the preference node will be
* created if one does not already exist
*
* @param project
* the project the preference node is under
* @param preferenceKey
* the subnode/category the preference node is located in
* @param create
* if true, a preference node will be created if one does not
* already exist
* @return Preferences associated with the given project scope and
* preference key. null if one could not be found and create is
* false
*/
static Preferences getPreferences(IProject project, String preferenceKey, boolean create) {
if (create)
// create all nodes down to the one we are interested in
return new ProjectScope(project).getNode(CSSCORE_ID).node(preferenceKey);
// be careful looking up for our node so not to create any nodes as
// side effect
Preferences node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
try {
// for now, take the long way
if (!node.nodeExists(project.getName()))
return null;
node = node.node(project.getName());
if (!node.nodeExists(CSSCORE_ID))
return null;
node = node.node(CSSCORE_ID);
if (!node.nodeExists(preferenceKey))
return null;
return node.node(preferenceKey);
} catch (BackingStoreException e) {
// nodeExists failed
// $NON-NLS-1$
Logger.log(Logger.WARNING_DEBUG, "Could not retrieve preference node", e);
}
return null;
}
Aggregations