use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.
the class JSPCorePreferencesTest 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(ContentTypeIdForJSP.ContentTypeID_JSP);
Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForJSP.ContentTypeID_JSP);
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
JSPDocumentLoader loader = new JSPDocumentLoader();
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 XMLCorePreferencesTest 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(ContentTypeIdForXML.ContentTypeID_XML);
Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForXML.ContentTypeID_XML);
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
XMLDocumentLoader loader = new XMLDocumentLoader();
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 JSPFContentProperties 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(JSPCORE_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(JSPCORE_ID))
return null;
node = node.node(JSPCORE_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 XSLValidationPreferencePage method getModelPreferences.
protected Preferences getModelPreferences() {
IEclipsePreferences prefs = Platform.getPreferencesService().getRootNode();
IProject project = getProject();
if (project != null) {
return prefs.node(ProjectScope.SCOPE).node(getPreferenceNodeQualifier());
}
Preferences instanceScope = prefs.node(InstanceScope.SCOPE).node(getPreferenceNodeQualifier());
if (instanceScope != null) {
return instanceScope;
}
return prefs.node(DefaultScope.SCOPE).node(getPreferenceNodeQualifier());
}
use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.
the class XSLValidationPreferencePage method storeValues.
@Override
protected void storeValues() {
super.storeValues();
int maxErrors = Integer.parseInt(maxErrorsText.getText());
Preferences prefs = getModelPreferences();
prefs.putInt(ValidationPreferences.MAX_ERRORS, maxErrors);
try {
prefs.flush();
} catch (BackingStoreException ex) {
XSLUIPlugin.log(ex);
}
}
Aggregations