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 String
Corpus description filestatic final String
Deprecated.static final String
Phon project extension, in Phon 4.x and later this is used in place of the properties file.static final String
Deprecated.static final String
Project resources folderstatic final String
Session template filenameFields inherited from class ca.phon.project.AbstractProject
PROJECT_XML_FILE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add corpus folder with given namevoid
Add a new corpus with the specified name.void
addProjectMediaFolder
(int index, String mediaFolder) Add a media folder to the project at the specified indexvoid
addProjectMediaFolder
(String mediaFolder) Add a media folder to the projectprotected void
checkSessionWriteLock
(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.long
getSessionByteSize
(Session session) Returns the size on disk for the given session.long
getSessionByteSize
(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 versionboolean
Tests to see if a given corpus exists in the project.boolean
hasCustomCorpusMediaFolder
(String corpus) Deprecated.boolean
Has a custom project media folder been assignedboolean
hasSession
(String corpus, String session) Test if a given session exists in the specified corpus.boolean
isSessionLocked
(Session session) Tells whether the given session is lockedboolean
isSessionLocked
(String corpus, String session) Tells wheater the given session is lockedint
numberOfRecordsInSession
(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.void
refresh()
Refresh the corpus/session information for a project.void
releaseSessionWriteLock
(Session session, SessionWriteLock writeLock) Release the write lock for a session.void
releaseSessionWriteLock
(String corpus, String session, SessionWriteLock writeLock) Release the write lock for a session.void
removeCorpus
(String corpus) Delete the specified corpus and all sessions it contains.void
removeProjectMediaFolder
(String mediaFolder) Remove a media folder from the projectvoid
removeSession
(Session session, SessionWriteLock writeLock) Remove a session from the project.void
removeSession
(String corpus, String session, SessionWriteLock writeLock) Remove a session from the project.void
renameCorpus
(String corpus, String newName) Rename a corpusprotected void
Save project datavoid
saveSession
(Session session, SessionWriteLock writeLock) Save a session with the provided writeLock.void
saveSession
(String corpus, String sessionName, Session session, SessionWriteLock writeLock) Save a session to the specified corpus and new sessionName.void
saveSession
(String corpus, String sessionName, Session session, SessionWriter writer, SessionWriteLock writeLock) Save a session writing the file using the given writer.void
saveSessionTemplate
(String corpus, Session template) Save the Session template for the given corpus.void
setCorpusDescription
(String corpus, String description) Set the description for the specified corpus.void
setCorpusMediaFolder
(String corpus, String mediaFolder) Deprecated.void
setCorpusPath
(String corpus, String path) Set path of corpus.void
Set project namevoid
setProjectMediaFolder
(String mediaFolder) Deprecated.void
setResourceLocation
(String location) void
Set 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:
getVersion
in interfaceProject
- Returns:
- the project version or 'unk' if not known
-
getLocation
Description copied from interface:ProjectPaths
The location of the project. Meaning is dependent on implementation. ForLocalProject
s this is the path to the project on disk.- Specified by:
getLocation
in interfaceProjectPaths
- Returns:
- the project location
-
getName
-
setName
Description copied from interface:MutableProject
Set project name- Specified by:
setName
in interfaceMutableProject
- Parameters:
name
- must match pattern '[ \w\d-]+'
-
getUUID
-
setUUID
Description copied from interface:MutableProject
Set project UUID- Specified by:
setUUID
in interfaceMutableProject
- Parameters:
uuid
- UUID for the project
-
addCorpus
Description copied from interface:MutableProject
Add corpus folder with given name- Specified by:
addCorpus
in interfaceMutableProject
- Parameters:
name
- the name of the corpus- Throws:
IOException
-
addCorpus
Description copied from interface:MutableProject
Add a new corpus with the specified name.- Specified by:
addCorpus
in 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:MutableProject
Rename a corpus- Specified by:
renameCorpus
in 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:MutableProject
Delete the specified corpus and all sessions it contains.- Specified by:
removeCorpus
in interfaceMutableProject
- Parameters:
corpus
- the corpus to delete- Throws:
IOException
- if the corpus could not be deleted
-
setCorpusDescription
Description copied from interface:MutableProject
Set the description for the specified corpus.- Specified by:
setCorpusDescription
in interfaceMutableProject
- Parameters:
corpus
- the corpus namedescription
- the description of the corpus
-
getSessionWriteLock
Description copied from interface:MutableProject
Get 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:
getSessionWriteLock
in 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:MutableProject
Get 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:
getSessionWriteLock
in interfaceMutableProject
- Parameters:
corpus
- the corpus namesession
- the session to lock- Returns:
- the session write lock or
null
- Throws:
IOException
-
releaseSessionWriteLock
Description copied from interface:MutableProject
Release the write lock for a session. SeeMutableProject.getSessionWriteLock(Session)
for more information on how to use the write lock.- Specified by:
releaseSessionWriteLock
in 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:MutableProject
Release the write lock for a session. SeeMutableProject.releaseSessionWriteLock(Session, SessionWriteLock)
for more information on how to use the write lock.- Specified by:
releaseSessionWriteLock
in interfaceMutableProject
- Parameters:
session
- the session to unlockwriteLock
- the write lock to release- Throws:
IOException
-
isSessionLocked
Description copied from interface:MutableProject
Tells whether the given session is locked- Specified by:
isSessionLocked
in interfaceMutableProject
- Parameters:
session
- the session to check- Returns:
true
if session is locked,false
otherwise
-
isSessionLocked
Description copied from interface:MutableProject
Tells wheater the given session is locked- Specified by:
isSessionLocked
in interfaceMutableProject
- Parameters:
corpus
- the corpus namesession
- the session name- Returns:
true
if the session is locked,false
otherwise
-
saveSession
Description copied from interface:MutableProject
Save 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:
saveSession
in 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:MutableProject
Save 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:
saveSession
in 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:MutableProject
Save 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:
saveSession
in 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:MutableProject
Remove 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:
removeSession
in 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:MutableProject
Remove 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:
removeSession
in interfaceMutableProject
- Parameters:
session
- the session to removewriteLock
- the write lock for the session- Throws:
IOException
-
getCorpusIterator
Description copied from interface:Project
Get an iterator over the corpora in this project.- Specified by:
getCorpusIterator
in interfaceProject
- Returns:
- iterator over corpora
-
hasCorpus
Description copied from interface:Project
Tests 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:Project
Get the description of the specified corpus.- Specified by:
getCorpusDescription
in interfaceProject
- Parameters:
corpus
- the corpus name
-
getSessionIterator
-
hasSession
Description copied from interface:Project
Test if a given session exists in the specified corpus. This method is usually faster than callingProject.getSessionIterator(String)
and checking iteratively.- Specified by:
hasSession
in interfaceProject
- Parameters:
corpus
- the corpus namesession
- the session name- Returns:
true
if the session exists,false
otherwise
-
getCorpusPath
Description copied from interface:ProjectPaths
Return the path to the given corpus.- Specified by:
getCorpusPath
in interfaceProjectPaths
- Parameters:
corpus
- the corpus name- Returns:
- the path to the corpus, usually relative to the project
-
setCorpusPath
Description copied from interface:ProjectPaths
Set path of corpus.- Specified by:
setCorpusPath
in interfaceProjectPaths
- Parameters:
corpus
- the corpus namepath
- the new path for the corpus
-
getParticipants
Description copied from interface:Project
Return a set of participants which are found in the given collection of Sessions. The participant objects returned by this method will include theParticipantHistory
extension. 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:
getParticipants
in interfaceProject
- Parameters:
sessions
-- Returns:
- a set of participants
-
openSession
Description copied from interface:Project
Open the specified session. This will create a new session object with the data currently on the storage device.- Specified by:
openSession
in interfaceProject
- Parameters:
corpus
-session
-- Returns:
- the session
- Throws:
IOException
-
openSession
Description copied from interface:Project
Open specified session using the provided reader.- Specified by:
openSession
in interfaceProject
- Parameters:
corpus
-session
-reader
-- Returns:
- the session
- Throws:
IOException
-
getSessionPath
Description copied from interface:ProjectPaths
Get path to the given session.- Specified by:
getSessionPath
in interfaceProjectPaths
- Parameters:
session
-- Returns:
- path to given session
-
getSessionPath
Description copied from interface:ProjectPaths
Get path to the given session.- Specified by:
getSessionPath
in interfaceProjectPaths
- Parameters:
corpus
-session
-- Returns:
- path to given session
-
getSessionFile
-
getCorpusFolder
-
hasCustomProjectMediaFolder
public boolean hasCustomProjectMediaFolder()Description copied from interface:ProjectMediaFolders
Has a custom project media folder been assigned- Specified by:
hasCustomProjectMediaFolder
in interfaceProjectMediaFolders
- Returns:
true
if project folder has been customized
-
getProjectMediaFolders
Description copied from interface:ProjectMediaFolders
Get all media folders for the project- Specified by:
getProjectMediaFolders
in interfaceProjectMediaFolders
- Returns:
- list of media folders
-
addProjectMediaFolder
Description copied from interface:ProjectMediaFolders
Add a media folder to the project- Specified by:
addProjectMediaFolder
in interfaceProjectMediaFolders
- Parameters:
mediaFolder
-
-
addProjectMediaFolder
Description copied from interface:ProjectMediaFolders
Add a media folder to the project at the specified index- Specified by:
addProjectMediaFolder
in interfaceProjectMediaFolders
- Parameters:
index
-mediaFolder
-
-
removeProjectMediaFolder
Description copied from interface:ProjectMediaFolders
Remove a media folder from the project- Specified by:
removeProjectMediaFolder
in interfaceProjectMediaFolders
- Parameters:
mediaFolder
-
-
getResourceLocation
Description copied from interface:ProjectResources
Get location of project resources folder.- Specified by:
getResourceLocation
in interfaceProjectResources
- Returns:
- location of project resources folder
-
setResourceLocation
-
getResourceInputStream
Description copied from interface:ProjectResources
Get 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:
getResourceInputStream
in interfaceProjectResources
- Parameters:
resourceName
-- Returns:
- an input stream for the specified resource
- Throws:
IOException
-
getResourceOutputStream
Description copied from interface:ProjectResources
Get 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:
getResourceOutputStream
in interfaceProjectResources
- Parameters:
resourceName
-- Returns:
- output stream for the specified resource
- Throws:
IOException
-
getSessionTemplate
Description copied from interface:SessionTemplate
Get the Session template for the given corpus.- Specified by:
getSessionTemplate
in interfaceSessionTemplate
- Parameters:
corpus
-- Returns:
- session template or
null
if not found - Throws:
IOException
-
saveSessionTemplate
Description copied from interface:SessionTemplate
Save the Session template for the given corpus.- Specified by:
saveSessionTemplate
in interfaceSessionTemplate
- Parameters:
corpus
-template
-- Throws:
IOException
-
createSessionFromTemplate
Description copied from interface:SessionTemplate
Create a new session from the corpus template (if it exists) This method will also add the session to the specified corpus.- Specified by:
createSessionFromTemplate
in interfaceSessionTemplate
- Parameters:
corpus
-session
-- Returns:
- new Session object
- Throws:
IOException
-
getSessionModificationTime
Description copied from interface:SessionDetails
Returns the modification date for the given session- Specified by:
getSessionModificationTime
in interfaceSessionDetails
- Parameters:
session
-- Returns:
- session modification date in system time zone
-
getSessionModificationTime
Description copied from interface:SessionDetails
Returns the modification date for the specified session.- Specified by:
getSessionModificationTime
in interfaceSessionDetails
- Parameters:
corpus
-session
-- Returns:
- session modification date in system time zone
-
getSessionByteSize
Description copied from interface:SessionDetails
Returns the size on disk for the given session.- Specified by:
getSessionByteSize
in interfaceSessionDetails
- Parameters:
session
-- Returns:
- session size in bytes
-
getSessionByteSize
Description copied from interface:SessionDetails
Returns the size on disk for the given session.- Specified by:
getSessionByteSize
in interfaceSessionDetails
- Parameters:
corpus
-session
-- Returns:
- session size in bytes
-
numberOfRecordsInSession
Description copied from interface:SessionDetails
Returns the number of records in a session w/o opening the session. This method is faster than using openSession(corpus, session).numberOfRecords()- Specified by:
numberOfRecordsInSession
in interfaceSessionDetails
- Parameters:
session
-- Returns:
- number of records in the session
- Throws:
IOException
-
getCorpora
Deprecated.Description copied from interface:ProjectDeprecated
Get the list of corpora in this project. Corpus names are returned in alphabetical order.- Specified by:
getCorpora
in interfaceProjectDeprecated
- Returns:
- list of corpora
-
getProjectMediaFolder
Deprecated.Description copied from interface:ProjectDeprecated
Get the media folders for the project, if any are set. If multiple media folders are set, the first one is returned.- Specified by:
getProjectMediaFolder
in interfaceProjectDeprecated
-
setProjectMediaFolder
Deprecated.Description copied from interface:ProjectDeprecated
Set 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:
setProjectMediaFolder
in interfaceProjectDeprecated
- Parameters:
mediaFolder
- Ifnull
sets the media folder back to default.
-
hasCustomCorpusMediaFolder
Deprecated.Description copied from interface:ProjectDeprecated
Has a custom corpus media folder been assigned- Specified by:
hasCustomCorpusMediaFolder
in interfaceProjectDeprecated
- Parameters:
corpus
-- Returns:
true
if a custom media folder is assigned for the given corpus
-
getCorpusMediaFolder
Deprecated.Description copied from interface:ProjectDeprecated
Get the media folder for the specified corpus.- Specified by:
getCorpusMediaFolder
in interfaceProjectDeprecated
- Returns:
- mediaFolder or the project media folder if not specified
-
setCorpusMediaFolder
Deprecated.Description copied from interface:ProjectDeprecated
Set the media folder for the specified corpus.- Specified by:
setCorpusMediaFolder
in interfaceProjectDeprecated
- Parameters:
mediaFolder
- the media folder to set
-
getCorpusSessions
Deprecated.Description copied from interface:ProjectDeprecated
Get the session names contained in a corpus in alphabetical order.- Specified by:
getCorpusSessions
in 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:ProjectRefresh
Refresh the corpus/session information for a project.- Specified by:
refresh
in interfaceProjectRefresh
-
toString
-