Class LocalProject
java.lang.Object
ca.phon.project.AbstractProject
ca.phon.project.LocalProject
- All Implemented Interfaces:
IExtendable,MutableProject,Project,ProjectDeprecated,ProjectEvents,ProjectMediaFolders,ProjectPaths,ProjectRefresh,ProjectResources,SessionDetails,SessionTemplate
- Direct Known Subclasses:
DesktopProject,ShadowProject
public class LocalProject
extends AbstractProject
implements ProjectRefresh, SessionTemplate, SessionDetails, ProjectPaths, ProjectResources, ProjectMediaFolders, MutableProject, ProjectDeprecated
A local on-disk project. Corpora are stored in subfolders of the project folder.
The project folder is the root of the project.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCorpus description filestatic final StringDeprecated.static final StringPhon project extension, in Phon 4.x and later this is used in place of the properties file.static final StringDeprecated.static final StringProject resources folderstatic final StringSession template filenameFields inherited from class ca.phon.project.AbstractProject
PROJECT_XML_FILE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd corpus folder with given namevoidAdd a new corpus with the specified name.voidaddProjectMediaFolder(int index, String mediaFolder) Add a media folder to the project at the specified indexvoidaddProjectMediaFolder(String mediaFolder) Add a media folder to the projectprotected voidcheckSessionWriteLock(String corpus, String session, SessionWriteLock writeLock) Checks given session write lockcreateSessionFromTemplate(String corpus, String session) Create a new session from the corpus template (if it exists) This method will also add the session to the specified corpus.Deprecated.getCorpusDescription(String corpus) Get the description of the specified corpus.getCorpusFolder(String corpus) Get an iterator over the corpora in this project.getCorpusMediaFolder(String corpus) Deprecated.getCorpusPath(String corpus) Return the path to the given corpus.getCorpusSessions(String corpus) Deprecated.The location of the project.getName()The name of the project.getParticipants(Collection<SessionPath> sessions) Return a set of participants which are found in the given collection of Sessions.Deprecated.Get all media folders for the projectgetResourceInputStream(String resourceName) Get an input stream for the specified project resource.Get location of project resources folder.getResourceOutputStream(String resourceName) Get an output stream for the specified resource.longgetSessionByteSize(Session session) Returns the size on disk for the given session.longgetSessionByteSize(String corpus, String session) Returns the size on disk for the given session.getSessionFile(String corpus, String session) getSessionIterator(String corpus) Get an iterator over the sessions in the specified corpus.getSessionModificationTime(Session session) Returns the modification date for the given sessiongetSessionModificationTime(String corpus, String session) Returns the modification date for the specified session.getSessionPath(Session session) Get path to the given session.getSessionPath(String corpus, String session) Get path to the given session.getSessionTemplate(String corpus) Get the Session template for the given corpus.getSessionWriteLock(Session session) Get a write lock for a session.getSessionWriteLock(String corpus, String session) Get a write lock for a session.getUUID()Project UUID UUID for the projectProject versionbooleanTests to see if a given corpus exists in the project.booleanhasCustomCorpusMediaFolder(String corpus) Deprecated.booleanHas a custom project media folder been assignedbooleanhasSession(String corpus, String session) Test if a given session exists in the specified corpus.booleanisSessionLocked(Session session) Tells whether the given session is lockedbooleanisSessionLocked(String corpus, String session) Tells wheater the given session is lockedintnumberOfRecordsInSession(String corpus, String session) Returns the number of records in a session w/o opening the session.openSession(String corpus, String session) Open the specified session.openSession(String corpus, String session, SessionReader reader) Open specified session using the provided reader.voidrefresh()Refresh the corpus/session information for a project.voidreleaseSessionWriteLock(Session session, SessionWriteLock writeLock) Release the write lock for a session.voidreleaseSessionWriteLock(String corpus, String session, SessionWriteLock writeLock) Release the write lock for a session.voidremoveCorpus(String corpus) Delete the specified corpus and all sessions it contains.voidremoveProjectMediaFolder(String mediaFolder) Remove a media folder from the projectvoidremoveSession(Session session, SessionWriteLock writeLock) Remove a session from the project.voidremoveSession(String corpus, String session, SessionWriteLock writeLock) Remove a session from the project.voidrenameCorpus(String corpus, String newName) Rename a corpusprotected voidSave project datavoidsaveSession(Session session, SessionWriteLock writeLock) Save a session with the provided writeLock.voidsaveSession(String corpus, String sessionName, Session session, SessionWriteLock writeLock) Save a session to the specified corpus and new sessionName.voidsaveSession(String corpus, String sessionName, Session session, SessionWriter writer, SessionWriteLock writeLock) Save a session writing the file using the given writer.voidsaveSessionTemplate(String corpus, Session template) Save the Session template for the given corpus.voidsetCorpusDescription(String corpus, String description) Set the description for the specified corpus.voidsetCorpusMediaFolder(String corpus, String mediaFolder) Deprecated.voidsetCorpusPath(String corpus, String path) Set path of corpus.voidSet project namevoidsetProjectMediaFolder(String mediaFolder) Deprecated.voidsetResourceLocation(String location) voidSet project UUIDtoString()Methods inherited from class ca.phon.project.AbstractProject
addProjectListener, fireProjectDataChanged, fireProjectStructureChanged, fireProjectWriteLocksChanged, getExtension, getExtensions, getProjectListeners, putExtension, removeExtension, removeProjectListener
-
Field Details
-
PREV_PROJECT_PROPERTIES_FILE
Deprecated.Project XML file (Phon 2.x and earlier)- See Also:
-
PROJECT_PROPERTIES_FILE
Deprecated.Project properties file (Phon 3.x)- See Also:
-
PROJECT_FILE_EXT
Phon project extension, in Phon 4.x and later this is used in place of the properties file. The format of this file is JSON.The filename will be the project name with a .phonproj extension. This file will only be created when opening an existing Phon 3.x project with a project.properties file; or when a value is written to the file. Double-clicking on a .phonproj file should open the project in Phon.
- See Also:
-
sessionTemplateFile
-
PROJECT_RES_FOLDER
-
CORPUS_DESC_FILE
-
-
Constructor Details
-
LocalProject
- Parameters:
projectFolder-- Throws:
ProjectConfigurationException
-
-
Method Details
-
saveProjectData
-
getVersion
Project version- Specified by:
getVersionin interfaceProject- Returns:
- the project version or 'unk' if not known
-
getLocation
Description copied from interface:ProjectPathsThe location of the project. Meaning is dependent on implementation. ForLocalProjects this is the path to the project on disk.- Specified by:
getLocationin interfaceProjectPaths- Returns:
- the project location
-
getName
-
setName
Description copied from interface:MutableProjectSet project name- Specified by:
setNamein interfaceMutableProject- Parameters:
name- must match pattern '[ \w\d-]+'
-
getUUID
-
setUUID
Description copied from interface:MutableProjectSet project UUID- Specified by:
setUUIDin interfaceMutableProject- Parameters:
uuid- UUID for the project
-
addCorpus
Description copied from interface:MutableProjectAdd corpus folder with given name- Specified by:
addCorpusin interfaceMutableProject- Parameters:
name- the name of the corpus- Throws:
IOException
-
addCorpus
Description copied from interface:MutableProjectAdd a new corpus with the specified name.- Specified by:
addCorpusin interfaceMutableProject- Parameters:
name- the name of the corpusdescription- the description of the corpus- Throws:
IOException- if the corpus could not be created
-
renameCorpus
Description copied from interface:MutableProjectRename a corpus- Specified by:
renameCorpusin interfaceMutableProject- Parameters:
corpus- the corpus to renamenewName- the new name for the corpus- Throws:
IOException- if the corpus could not be renamed
-
removeCorpus
Description copied from interface:MutableProjectDelete the specified corpus and all sessions it contains.- Specified by:
removeCorpusin interfaceMutableProject- Parameters:
corpus- the corpus to delete- Throws:
IOException- if the corpus could not be deleted
-
setCorpusDescription
Description copied from interface:MutableProjectSet the description for the specified corpus.- Specified by:
setCorpusDescriptionin interfaceMutableProject- Parameters:
corpus- the corpus namedescription- the description of the corpus
-
getSessionWriteLock
Description copied from interface:MutableProjectGet a write lock for a session. Before writing a write lock must be obtained from the project. Example:try(SessionWriteLock writeLock = project.getSessionWriteLock(session)) { // do some work with the session } catch (IOException e) { // handle exception }- Specified by:
getSessionWriteLockin interfaceMutableProject- Parameters:
session- the session to lock- Returns:
- the session write lock or invalid input: '<' 0 if a write lock was not obtained
- Throws:
IOException
-
getSessionWriteLock
Description copied from interface:MutableProjectGet a write lock for a session. Before writing a write lock must be obtained from the project. SeeMutableProject.getSessionWriteLock(Session)for more information on how to use the write lock.- Specified by:
getSessionWriteLockin interfaceMutableProject- Parameters:
corpus- the corpus namesession- the session to lock- Returns:
- the session write lock or
null - Throws:
IOException
-
releaseSessionWriteLock
Description copied from interface:MutableProjectRelease the write lock for a session. SeeMutableProject.getSessionWriteLock(Session)for more information on how to use the write lock.- Specified by:
releaseSessionWriteLockin interfaceMutableProject- Parameters:
session- the session to unlockwriteLock- the write lock to release- Throws:
IOException
-
releaseSessionWriteLock
public void releaseSessionWriteLock(String corpus, String session, SessionWriteLock writeLock) throws IOException Description copied from interface:MutableProjectRelease the write lock for a session. SeeMutableProject.releaseSessionWriteLock(Session, SessionWriteLock)for more information on how to use the write lock.- Specified by:
releaseSessionWriteLockin interfaceMutableProject- Parameters:
session- the session to unlockwriteLock- the write lock to release- Throws:
IOException
-
isSessionLocked
Description copied from interface:MutableProjectTells whether the given session is locked- Specified by:
isSessionLockedin interfaceMutableProject- Parameters:
session- the session to check- Returns:
trueif session is locked,falseotherwise
-
isSessionLocked
Description copied from interface:MutableProjectTells wheater the given session is locked- Specified by:
isSessionLockedin interfaceMutableProject- Parameters:
corpus- the corpus namesession- the session name- Returns:
trueif the session is locked,falseotherwise
-
saveSession
Description copied from interface:MutableProjectSave a session with the provided writeLock. Example:try(SessionWriteLock writeLock = project.getSessionWriteLock(session)) { project.saveSession(session, writeLock); } catch (IOException e) { // handle exception }The write lock is auto-closeable and will be released when the try block is exited. To manually release the write lock, call theMutableProject.releaseSessionWriteLock(Session, SessionWriteLock)method or use theclose()method on the write lock.- Specified by:
saveSessionin interfaceMutableProject- Parameters:
session- the session to savewriteLock- the write lock for the session- Throws:
IOException
-
saveSession
public void saveSession(String corpus, String sessionName, Session session, SessionWriteLock writeLock) throws IOException Description copied from interface:MutableProjectSave a session to the specified corpus and new sessionName. SeeMutableProject.saveSession(Session, SessionWriteLock)for more information on how to use the write lock.- Specified by:
saveSessionin interfaceMutableProject- Parameters:
corpus- the corpus namesessionName- the name of the sessionsession- the session to savewriteLock- the write lock for the session- Throws:
IOException
-
saveSession
public void saveSession(String corpus, String sessionName, Session session, SessionWriter writer, SessionWriteLock writeLock) throws IOException Description copied from interface:MutableProjectSave a session writing the file using the given writer. SeeMutableProject.saveSession(Session, SessionWriteLock)for more information on how to use the write lock.- Specified by:
saveSessionin interfaceMutableProject- Parameters:
corpus- the corpus namesessionName- the name of the sessionsession- the session to savewriter- the session writer to usewriteLock- the write lock for the session- Throws:
IOException
-
removeSession
Description copied from interface:MutableProjectRemove a session from the project. The writeLock for the session is also released. SeeMutableProject.removeSession(Session, SessionWriteLock)for more information on how to use the write lock.- Specified by:
removeSessionin interfaceMutableProject- Parameters:
session- the session to removewriteLock- the write lock for the session- Throws:
IOException
-
checkSessionWriteLock
protected void checkSessionWriteLock(String corpus, String session, SessionWriteLock writeLock) throws IOException Checks given session write lock- Throws:
IOException- if the write lock is not valid
-
removeSession
public void removeSession(String corpus, String session, SessionWriteLock writeLock) throws IOException Description copied from interface:MutableProjectRemove a session from the project. The writeLock for the session is also released. SeeMutableProject.removeSession(Session, SessionWriteLock)for more information on how to use the write lock.- Specified by:
removeSessionin interfaceMutableProject- Parameters:
session- the session to removewriteLock- the write lock for the session- Throws:
IOException
-
getCorpusIterator
Description copied from interface:ProjectGet an iterator over the corpora in this project.- Specified by:
getCorpusIteratorin interfaceProject- Returns:
- iterator over corpora
-
hasCorpus
Description copied from interface:ProjectTests to see if a given corpus exists in the project. This may be faster than callingProject.getCorpusIterator()and checking iteratively. -
getCorpusDescription
Description copied from interface:ProjectGet the description of the specified corpus.- Specified by:
getCorpusDescriptionin interfaceProject- Parameters:
corpus- the corpus name
-
getSessionIterator
-
hasSession
Description copied from interface:ProjectTest if a given session exists in the specified corpus. This method is usually faster than callingProject.getSessionIterator(String)and checking iteratively.- Specified by:
hasSessionin interfaceProject- Parameters:
corpus- the corpus namesession- the session name- Returns:
trueif the session exists,falseotherwise
-
getCorpusPath
Description copied from interface:ProjectPathsReturn the path to the given corpus.- Specified by:
getCorpusPathin interfaceProjectPaths- Parameters:
corpus- the corpus name- Returns:
- the path to the corpus, usually relative to the project
-
setCorpusPath
Description copied from interface:ProjectPathsSet path of corpus.- Specified by:
setCorpusPathin interfaceProjectPaths- Parameters:
corpus- the corpus namepath- the new path for the corpus
-
getParticipants
Description copied from interface:ProjectReturn a set of participants which are found in the given collection of Sessions. The participant objects returned by this method will include theParticipantHistoryextension. Participants from two sessions are considered to be the same if their ids, names and roles match. If the speaker for some records is unidenified, a clone of Participant.UNKOWN will be added in the returned set.- Specified by:
getParticipantsin interfaceProject- Parameters:
sessions-- Returns:
- a set of participants
-
openSession
Description copied from interface:ProjectOpen the specified session. This will create a new session object with the data currently on the storage device.- Specified by:
openSessionin interfaceProject- Parameters:
corpus-session-- Returns:
- the session
- Throws:
IOException
-
openSession
Description copied from interface:ProjectOpen specified session using the provided reader.- Specified by:
openSessionin interfaceProject- Parameters:
corpus-session-reader-- Returns:
- the session
- Throws:
IOException
-
getSessionPath
Description copied from interface:ProjectPathsGet path to the given session.- Specified by:
getSessionPathin interfaceProjectPaths- Parameters:
session-- Returns:
- path to given session
-
getSessionPath
Description copied from interface:ProjectPathsGet path to the given session.- Specified by:
getSessionPathin interfaceProjectPaths- Parameters:
corpus-session-- Returns:
- path to given session
-
getSessionFile
-
getCorpusFolder
-
hasCustomProjectMediaFolder
public boolean hasCustomProjectMediaFolder()Description copied from interface:ProjectMediaFoldersHas a custom project media folder been assigned- Specified by:
hasCustomProjectMediaFolderin interfaceProjectMediaFolders- Returns:
trueif project folder has been customized
-
getProjectMediaFolders
Description copied from interface:ProjectMediaFoldersGet all media folders for the project- Specified by:
getProjectMediaFoldersin interfaceProjectMediaFolders- Returns:
- list of media folders
-
addProjectMediaFolder
Description copied from interface:ProjectMediaFoldersAdd a media folder to the project- Specified by:
addProjectMediaFolderin interfaceProjectMediaFolders- Parameters:
mediaFolder-
-
addProjectMediaFolder
Description copied from interface:ProjectMediaFoldersAdd a media folder to the project at the specified index- Specified by:
addProjectMediaFolderin interfaceProjectMediaFolders- Parameters:
index-mediaFolder-
-
removeProjectMediaFolder
Description copied from interface:ProjectMediaFoldersRemove a media folder from the project- Specified by:
removeProjectMediaFolderin interfaceProjectMediaFolders- Parameters:
mediaFolder-
-
getResourceLocation
Description copied from interface:ProjectResourcesGet location of project resources folder.- Specified by:
getResourceLocationin interfaceProjectResources- Returns:
- location of project resources folder
-
setResourceLocation
-
getResourceInputStream
Description copied from interface:ProjectResourcesGet an input stream for the specified project resource. The resource name should be a relative path including filename. E.g., 'ca.phon.myplugin/module/corpus/session.dat'- Specified by:
getResourceInputStreamin interfaceProjectResources- Parameters:
resourceName-- Returns:
- an input stream for the specified resource
- Throws:
IOException
-
getResourceOutputStream
Description copied from interface:ProjectResourcesGet an output stream for the specified resource. If the resource does not exist, it is created. If the resource already exists, it is overwritten.- Specified by:
getResourceOutputStreamin interfaceProjectResources- Parameters:
resourceName-- Returns:
- output stream for the specified resource
- Throws:
IOException
-
getSessionTemplate
Description copied from interface:SessionTemplateGet the Session template for the given corpus.- Specified by:
getSessionTemplatein interfaceSessionTemplate- Parameters:
corpus-- Returns:
- session template or
nullif not found - Throws:
IOException
-
saveSessionTemplate
Description copied from interface:SessionTemplateSave the Session template for the given corpus.- Specified by:
saveSessionTemplatein interfaceSessionTemplate- Parameters:
corpus-template-- Throws:
IOException
-
createSessionFromTemplate
Description copied from interface:SessionTemplateCreate a new session from the corpus template (if it exists) This method will also add the session to the specified corpus.- Specified by:
createSessionFromTemplatein interfaceSessionTemplate- Parameters:
corpus-session-- Returns:
- new Session object
- Throws:
IOException
-
getSessionModificationTime
Description copied from interface:SessionDetailsReturns the modification date for the given session- Specified by:
getSessionModificationTimein interfaceSessionDetails- Parameters:
session-- Returns:
- session modification date in system time zone
-
getSessionModificationTime
Description copied from interface:SessionDetailsReturns the modification date for the specified session.- Specified by:
getSessionModificationTimein interfaceSessionDetails- Parameters:
corpus-session-- Returns:
- session modification date in system time zone
-
getSessionByteSize
Description copied from interface:SessionDetailsReturns the size on disk for the given session.- Specified by:
getSessionByteSizein interfaceSessionDetails- Parameters:
session-- Returns:
- session size in bytes
-
getSessionByteSize
Description copied from interface:SessionDetailsReturns the size on disk for the given session.- Specified by:
getSessionByteSizein interfaceSessionDetails- Parameters:
corpus-session-- Returns:
- session size in bytes
-
numberOfRecordsInSession
Description copied from interface:SessionDetailsReturns the number of records in a session w/o opening the session. This method is faster than using openSession(corpus, session).numberOfRecords()- Specified by:
numberOfRecordsInSessionin interfaceSessionDetails- Parameters:
session-- Returns:
- number of records in the session
- Throws:
IOException
-
getCorpora
Deprecated.Description copied from interface:ProjectDeprecatedGet the list of corpora in this project. Corpus names are returned in alphabetical order.- Specified by:
getCorporain interfaceProjectDeprecated- Returns:
- list of corpora
-
getProjectMediaFolder
Deprecated.Description copied from interface:ProjectDeprecatedGet the media folders for the project, if any are set. If multiple media folders are set, the first one is returned.- Specified by:
getProjectMediaFolderin interfaceProjectDeprecated
-
setProjectMediaFolder
Deprecated.Description copied from interface:ProjectDeprecatedSet media folder for project, if any are set. If multiple media folders are set, then all are removed and the new folder is added.- Specified by:
setProjectMediaFolderin interfaceProjectDeprecated- Parameters:
mediaFolder- Ifnullsets the media folder back to default.
-
hasCustomCorpusMediaFolder
Deprecated.Description copied from interface:ProjectDeprecatedHas a custom corpus media folder been assigned- Specified by:
hasCustomCorpusMediaFolderin interfaceProjectDeprecated- Parameters:
corpus-- Returns:
trueif a custom media folder is assigned for the given corpus
-
getCorpusMediaFolder
Deprecated.Description copied from interface:ProjectDeprecatedGet the media folder for the specified corpus.- Specified by:
getCorpusMediaFolderin interfaceProjectDeprecated- Returns:
- mediaFolder or the project media folder if not specified
-
setCorpusMediaFolder
Deprecated.Description copied from interface:ProjectDeprecatedSet the media folder for the specified corpus.- Specified by:
setCorpusMediaFolderin interfaceProjectDeprecated- Parameters:
mediaFolder- the media folder to set
-
getCorpusSessions
Deprecated.Description copied from interface:ProjectDeprecatedGet the session names contained in a corpus in alphabetical order.- Specified by:
getCorpusSessionsin interfaceProjectDeprecated- Parameters:
corpus- the corpus to get sessions for- Returns:
- the list of sessions in the specified corpus
-
refresh
public void refresh()Description copied from interface:ProjectRefreshRefresh the corpus/session information for a project.- Specified by:
refreshin interfaceProjectRefresh
-
toString
-