Package org.mycore.mets.tools
Class MCRMetsSave
java.lang.Object
org.mycore.mets.tools.MCRMetsSave
Class is responsible for saving a mets document to a derivate. It also can
handle addition and removing files from a derivate.
- Author:
- shermann Sebastian Hofmann TODO: Complete rework needed
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<org.mycore.mets.model.files.FileGrp>
buildFileGroups
(List<MCRPath> paths) Builds new mets:fileGrp's based on the given paths using the mycore derivate convetions.static MCRPath
createMetsFile
(String derivateID) static String
getFileBase
(String href) Returns the name without any path information or file extension.static String
getFileBase
(MCRPath path) Returns the name without any path information or file extension.static String
getFileGroupUse
(MCRPath file) Decides in which file group the file should be insertedstatic String
Returns the mets:file/@ID for the given path.static MCRPath
getMetsFile
(String derivateID) static String
static boolean
isComplete
(org.mycore.mets.model.files.FileGrp fileGroup, MCRPath rootDir) static boolean
isComplete
(org.mycore.mets.model.Mets mets, MCRObjectID derivateId) listFiles
(MCRPath path, Collection<MCRPath> ignore) Returns a list of files in the given path.listFileUse
(List<MCRPath> paths) Returns a list of allMCRMetsFileUse
in the given paths.static boolean
saveMets
(Document document, MCRObjectID derivateId) Saves the content of the given document to file and then adds the file to the derivate with the given id.static boolean
saveMets
(Document document, MCRObjectID derivateId, boolean overwrite, boolean validate) Saves the content of the given document to file, if no mets present and then adds the file to the derivate with the given id.static void
updateFiles
(org.mycore.mets.model.Mets mets, MCRPath derivatePath) Call this method to update the mets.xml if files of the derivate have changed.static void
updateMetsOnFileAdd
(MCRPath file) Updates the mets.xml belonging to the given derivate.static void
Updates the mets.xml belonging to the given derivate.static void
updateMetsOnUrnGenerate
(MCRDerivate derivate) Inserts the given URNs into the mets document.static void
updateMetsOnUrnGenerate
(MCRObjectID derivateID, Map<String, String> fileUrnMap) Inserts the given URNs into the Mets document.static void
updateURNsInMetsDocument
(org.mycore.mets.model.Mets mets, Map<String, String> fileUrnMap) Inserts the given URNs into theMets
Object.
-
Field Details
-
ALTO_FOLDER_PREFIX
- See Also:
-
TEI_FOLDER_PREFIX
- See Also:
-
TRANSLATION_FOLDER_PREFIX
- See Also:
-
TRANSCRIPTION_FOLDER_PREFIX
- See Also:
-
UNKNOWN_FILEGROUP
- See Also:
-
-
Constructor Details
-
MCRMetsSave
public MCRMetsSave()
-
-
Method Details
-
saveMets
Saves the content of the given document to file and then adds the file to the derivate with the given id. The name of the file depends on property 'MCR.Mets.Filename'. If this property has not been set 'mets.xml' is used as a default filename.- Returns:
- true if the given document was successfully saved, otherwise false
-
saveMets
public static boolean saveMets(Document document, MCRObjectID derivateId, boolean overwrite, boolean validate) Saves the content of the given document to file, if no mets present and then adds the file to the derivate with the given id. The name of the file depends on property 'MCR.Mets.Filename'. If this property has not been set 'mets.xml' is used as a default filename.- Parameters:
overwrite
- if true existing mets-file will be overwrittenvalidate
- if true the document will be validated before its stored- Returns:
- true if the given document was successfully saved, otherwise false
-
getMetsFileName
-
updateMetsOnFileAdd
Updates the mets.xml belonging to the given derivate. Adds the file to the mets document (updates file sections and stuff within the mets.xml)- Parameters:
file
- a handle for the file to add to the mets.xml- Throws:
Exception
-
getMetsFile
-
createMetsFile
-
getFileGroupUse
Decides in which file group the file should be inserted- Parameters:
file
- the to check- Returns:
- the id of the filegGroup
-
updateMetsOnFileDelete
public static void updateMetsOnFileDelete(MCRPath file) throws JDOMException, SAXException, IOException Updates the mets.xml belonging to the given derivate. Removes the file from the mets document (updates file sections and stuff within the mets.xml)- Parameters:
file
- a handle for the file to add to the mets.xml- Throws:
JDOMException
SAXException
IOException
-
updateMetsOnUrnGenerate
Inserts the given URNs into the mets document.- Parameters:
derivate
- TheMCRDerivate
which contains the mets file
-
updateMetsOnUrnGenerate
public static void updateMetsOnUrnGenerate(MCRObjectID derivateID, Map<String, String> fileUrnMap) throws JDOMException, SAXException, IOExceptionInserts the given URNs into the Mets document.- Parameters:
derivateID
- TheMCRObjectID
of the Derivate wich contains the METs filefileUrnMap
- aMap
which contains the file as key and the urn as as value- Throws:
JDOMException
SAXException
IOException
-
updateURNsInMetsDocument
public static void updateURNsInMetsDocument(org.mycore.mets.model.Mets mets, Map<String, String> fileUrnMap) throws UnsupportedEncodingExceptionInserts the given URNs into theMets
Object.- Parameters:
mets
- theMets
object were the URNs should be inserted.fileUrnMap
- aMap
wich contains the file as key and the urn as as value- Throws:
UnsupportedEncodingException
-
isComplete
- Returns:
- true if all files owned by the derivate appearing in the master file group or false otherwise
-
isComplete
- Returns:
- true if all files in the
MCRDirectory
appears in the fileGroup
-
updateFiles
public static void updateFiles(org.mycore.mets.model.Mets mets, MCRPath derivatePath) throws IOException Call this method to update the mets.xml if files of the derivate have changed. Files will be added or removed from the mets:fileSec and mets:StructMap[@type=PHYSICAL]. The mets:structLink part will be rebuild after.This method takes care of the group assignment. For example: image files will be added to the MASTER group and ALTO files to the ALTO group. It will also bundle files with the same name e.g. sample1.tiff and alto/sample1.xml to the same physical struct map div.
Important: This method does not update the mets.xml in the derivate, its just updating the given mets instance.
- Parameters:
mets
- the mets to updatederivatePath
- path to the derivate -> required for looking up new files- Throws:
IOException
- derivate couldn't be read
-
listFiles
Returns a list of files in the given path. This does not return directories!- Parameters:
path
- the path to listignore
- paths which should be ignored- Returns:
- list of
MCRPath's
files - Throws:
IOException
- if an I/O error is thrown when accessing the starting file.
-
buildFileGroups
Builds new mets:fileGrp's based on the given paths using the mycore derivate convetions.- root folder -> mets:fileGrp[@USE=MASTER]
- alto/ folder -> mets:fileGrp[@USE=ALTO]
- tei/translation folder -> mets:fileGrp[@USE=TRANSLATION
- tei/transcription folder -> mets:fileGrp[@USE=TRANSCRIPTION
- Parameters:
paths
- the paths to check for the groups- Returns:
- a list of new created
FileGrp
objects
-
listFileUse
Returns a list of allMCRMetsFileUse
in the given paths.- Parameters:
paths
- paths to check- Returns:
- list of
MCRMetsFileUse
-
getFileBase
Returns the name without any path information or file extension. Usable to create mets ID's.- abc123.jpg -> abc123
- alto/abc123.xml -> abc123
- Parameters:
href
- the href to get the file base name- Returns:
- the href shortcut
-
getFileBase
Returns the name without any path information or file extension. Useable to create mets ID's.- abc123.jpg -> abc123
- alto/abc123.xml -> abc123
- Parameters:
path
- the href to get the file base name- Returns:
- the href shortcut
-
getFileId
Returns the mets:file/@ID for the given path.- Parameters:
path
- path to the file- Returns:
- mets:file ID
-