edu.umd.cfar.lamp.apploader.prefs
Class PrefsManager

java.lang.Object
  extended byedu.umd.cfar.lamp.apploader.prefs.PrefsManager

public class PrefsManager
extends java.lang.Object

A PrefsManager holds the RDF preferences data for the current setup. It has places to attach listeners, if we ever decide to have a pref editor, but currently the RDF model (Jena 1.6) doesn't support events, so they aren't called. The basic idea is "system prefs < user prefs < file < command line". For example, if the system says that all bounding boxes are red, but the user prefers blue, it will select blue, unless the file says these bounding boxes should be green, in which case they are unless the user specifies another color on the command line. So, the question is, how are the prefs files discovered? The current idea is "default location < system property < java property ". Right now file and cli aren't implemented. The idea for file is to perhaps have an RDF element in the header or something. As for the command line, we would set a map of command line options to properties or something, and then pass the system argument array to a method.


Field Summary
 com.hp.hpl.jena.rdf.model.Model model
          The sink for all the preferences.
 
Constructor Summary
PrefsManager()
          Create a new preference manager with no preferences and the default logger.
 
Method Summary
 void addLeftoverAction(java.lang.Runnable R)
          Adds an action to be executed after the current event is finished being sent out to all listeners.
 void addListener(ModelListener ml)
          Adds a listener for changes to the triplestore.
 void addPrefix(java.lang.String prefix, java.lang.String uri)
          Adds the given namespace short-name (prefix).
 void changeTemporary(com.hp.hpl.jena.rdf.model.Model toRemove, com.hp.hpl.jena.rdf.model.Model toAdd)
          Change data in the temporary triplestore.
 void changeUser(com.hp.hpl.jena.rdf.model.Model toRemove, com.hp.hpl.jena.rdf.model.Model toAdd)
          Changes the user preferences model.
 AppLoader getCore()
          Gets the associated core bean.
 com.hp.hpl.jena.rdf.model.Model getFile()
           
 com.hp.hpl.jena.rdf.model.Resource getLocalizedResource(com.hp.hpl.jena.rdf.model.Resource r, com.hp.hpl.jena.rdf.model.Property p)
          From the list of subject-verb-objects, get the first object that has an undo:forLanguage property whose object is the current user's preferred language.
 java.lang.String getLocalizedString(com.hp.hpl.jena.rdf.model.Resource r, com.hp.hpl.jena.rdf.model.Property p)
          Tries to get the localized version or r's property p.
 java.util.logging.Logger getLogger()
          Gets the error logger associated with the preference manager.
 OptionsManager getOptionsManager()
          Gets the associated command-line options manager bean.
 com.hp.hpl.jena.rdf.model.Model getSystem()
           
 java.net.URI getSystemDirectory()
          Gets the system directory, if defined.
 com.hp.hpl.jena.rdf.model.Model getTemporary()
           
 com.hp.hpl.jena.rdf.model.Model getUser()
           
 java.net.URI getUserDirectory()
          Gets the user directory, if defined.
static boolean isXMLFormat(java.io.Reader r)
          Checks to see if the file begins with an xml processing directive, eg <?
static boolean isXMLFormat(java.net.URI fileName)
          Checks to see if the file begins with an xml processing directive, eg <?
 void loadUserPrefs()
          Loads the se triplestore from a n n3 file.
 void removeListener(ModelListener ml)
          Removes a listener for changes to the triplestore.
 void serializeUserPrefs()
          Save the iser model to the user.n3 file.
 void setCore(AppLoader loader)
          Sets the associated Limn3 core.
 void setLogger(java.util.logging.Logger logger)
          Sets the error logger associated with the preference manager.
 void setSystemPrefs(java.net.URI filename)
          Resets the system prefs to the contents of the given uri.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

public com.hp.hpl.jena.rdf.model.Model model
The sink for all the preferences. Use it to get direct access to the prefs. I trust you not to update this. Perhaps later I will surround it with an immutable nature, but don't wait.

Constructor Detail

PrefsManager

public PrefsManager()
Create a new preference manager with no preferences and the default logger.

Method Detail

setCore

public void setCore(AppLoader loader)
Sets the associated Limn3 core.

Parameters:
loader - the core bean

getCore

public AppLoader getCore()
Gets the associated core bean.

Returns:
the associated core bean, if one has been assigned

addPrefix

public void addPrefix(java.lang.String prefix,
                      java.lang.String uri)
Adds the given namespace short-name (prefix). This is useful during serialization.

Parameters:
prefix - the new prefix
uri - the uri that will use the prefix

getLocalizedString

public java.lang.String getLocalizedString(com.hp.hpl.jena.rdf.model.Resource r,
                                           com.hp.hpl.jena.rdf.model.Property p)
                                    throws com.hp.hpl.jena.rdf.model.RDFException
Tries to get the localized version or r's property p. If not found, will return the one without a lang property or, if all have the lang property, the 'en' one if it exists or or the last one if not. A better solution would be to find the translation with the highest score, with 1 = a language the user knows, and .5 being something like French if the speaker knows English, down to 0 if all the speaker knows is Euskera or Japanese. If no property is found with the name, returns null, so watch out!

Parameters:
r - the resouce on which to check
p - the property name to check
Returns:
the string, if found
Throws:
com.hp.hpl.jena.rdf.model.RDFException - if the property takes a non-literal value, for example

getLocalizedResource

public com.hp.hpl.jena.rdf.model.Resource getLocalizedResource(com.hp.hpl.jena.rdf.model.Resource r,
                                                               com.hp.hpl.jena.rdf.model.Property p)
From the list of subject-verb-objects, get the first object that has an undo:forLanguage property whose object is the current user's preferred language. If none is found, uses the first object without a language specified.

Parameters:
r - the resource that takes a localizable property
p - the property to search for
Returns:
The object that most closely matches the user's language preference
See Also:
getLocalizedString(Resource, Property), LAL.lang

getSystemDirectory

public java.net.URI getSystemDirectory()
                                throws PreferenceException
Gets the system directory, if defined. This defaults to whatever directory contains the n3 file.

Returns:
the system directory
Throws:
PreferenceException

getUserDirectory

public java.net.URI getUserDirectory()
                              throws PreferenceException
Gets the user directory, if defined.

Returns:
the user's home directory
Throws:
PreferenceException

serializeUserPrefs

public void serializeUserPrefs()
Save the iser model to the user.n3 file.


loadUserPrefs

public void loadUserPrefs()
                   throws PreferenceException
Loads the se triplestore from a n n3 file.

Throws:
PreferenceException

setSystemPrefs

public void setSystemPrefs(java.net.URI filename)
                    throws PreferenceException
Resets the system prefs to the contents of the given uri.

Parameters:
filename - the location of the system prefs
Throws:
PreferenceException - if there is a problem while loading

addListener

public void addListener(ModelListener ml)
Adds a listener for changes to the triplestore.

Parameters:
ml - the listener to add

removeListener

public void removeListener(ModelListener ml)
Removes a listener for changes to the triplestore.

Parameters:
ml - the listener to remove

addLeftoverAction

public void addLeftoverAction(java.lang.Runnable R)
Adds an action to be executed after the current event is finished being sent out to all listeners. A hack to avoid deadlock issues, a leftover action is an event that will be run after the currently registered event is sent to all listeners. If not notifying listeners, the action is just run immediately, in process.

Parameters:
R - the action to perform

getOptionsManager

public OptionsManager getOptionsManager()
Gets the associated command-line options manager bean.

Returns:
the command-line options manager

changeUser

public void changeUser(com.hp.hpl.jena.rdf.model.Model toRemove,
                       com.hp.hpl.jena.rdf.model.Model toAdd)
Changes the user preferences model. Unlike the other models, this one is serialized, and editing it causes it to be saved.

Parameters:
toRemove - triples to remove from the user preferences triplestore
toAdd - triples to add to the user preferences triplestore

changeTemporary

public void changeTemporary(com.hp.hpl.jena.rdf.model.Model toRemove,
                            com.hp.hpl.jena.rdf.model.Model toAdd)
Change data in the temporary triplestore.

Parameters:
toRemove - triples to remove
toAdd - triples to add

isXMLFormat

public static boolean isXMLFormat(java.net.URI fileName)
                           throws java.io.IOException
Checks to see if the file begins with an xml processing directive, eg <?xml?>. This method does not check to see that the file is well-formed, or even if the processing directive is good, just that the first non-whitespace characters are "<?xml".

Parameters:
fileName - The file to check for xml processing directive
Returns:
true if the directive was found.
Throws:
java.io.IOException - if there is an error while reading the file, eg FileNotFoundException

isXMLFormat

public static boolean isXMLFormat(java.io.Reader r)
                           throws java.io.IOException
Checks to see if the file begins with an xml processing directive, eg <?xml?>. This method does not check to see that the file is well-formed, or even if the processing directive is good, just that the first non-whitespace characters are "<?xml". Note that this calls mark and reset on the stream. So, the stream has to be in the starting position before and will be put back in after.

Parameters:
r - the source to check for xml processing directive
Returns:
true if the directive was found.
Throws:
java.io.IOException - if there is an error while reading the file, eg FileNotFoundException
java.lang.IllegalArgumentException - if the Reader doesn't support mark and reset

getLogger

public java.util.logging.Logger getLogger()
Gets the error logger associated with the preference manager.

Returns:
the logger

setLogger

public void setLogger(java.util.logging.Logger logger)
Sets the error logger associated with the preference manager.

Parameters:
logger - the new logger

getFile

public com.hp.hpl.jena.rdf.model.Model getFile()

getSystem

public com.hp.hpl.jena.rdf.model.Model getSystem()

getTemporary

public com.hp.hpl.jena.rdf.model.Model getTemporary()

getUser

public com.hp.hpl.jena.rdf.model.Model getUser()