Class MCRMetsSave

java.lang.Object
org.mycore.mets.tools.MCRMetsSave

public class MCRMetsSave extends Object
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 Details

  • Constructor Details

    • MCRMetsSave

      public MCRMetsSave()
  • Method Details

    • saveMets

      public 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. 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 overwritten
      validate - if true the document will be validated before its stored
      Returns:
      true if the given document was successfully saved, otherwise false
    • getMetsFileName

      public static String getMetsFileName()
    • updateMetsOnFileAdd

      public static void updateMetsOnFileAdd(MCRPath file) throws Exception
      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

      public static MCRPath getMetsFile(String derivateID)
    • createMetsFile

      public static MCRPath createMetsFile(String derivateID)
    • getFileGroupUse

      public static String getFileGroupUse(MCRPath file)
      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

      public static void updateMetsOnUrnGenerate(MCRDerivate derivate)
      Inserts the given URNs into the mets document.
      Parameters:
      derivate - The MCRDerivate which contains the mets file
    • updateMetsOnUrnGenerate

      public static void updateMetsOnUrnGenerate(MCRObjectID derivateID, Map<String,String> fileUrnMap) throws JDOMException, SAXException, IOException
      Inserts the given URNs into the Mets document.
      Parameters:
      derivateID - The MCRObjectID of the Derivate wich contains the METs file
      fileUrnMap - a Map 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 UnsupportedEncodingException
      Inserts the given URNs into the Mets Object.
      Parameters:
      mets - the Mets object were the URNs should be inserted.
      fileUrnMap - a Map wich contains the file as key and the urn as as value
      Throws:
      UnsupportedEncodingException
    • isComplete

      public static boolean isComplete(org.mycore.mets.model.Mets mets, MCRObjectID derivateId)
      Returns:
      true if all files owned by the derivate appearing in the master file group or false otherwise
    • isComplete

      public static boolean isComplete(org.mycore.mets.model.files.FileGrp fileGroup, MCRPath rootDir)
      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 update
      derivatePath - path to the derivate -> required for looking up new files
      Throws:
      IOException - derivate couldn't be read
    • listFiles

      public static List<MCRPath> listFiles(MCRPath path, Collection<MCRPath> ignore) throws IOException
      Returns a list of files in the given path. This does not return directories!
      Parameters:
      path - the path to list
      ignore - 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

      public static 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.
      • 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

      public static List<String> listFileUse(List<MCRPath> paths)
      Returns a list of all MCRMetsFileUse in the given paths.
      Parameters:
      paths - paths to check
      Returns:
      list of MCRMetsFileUse
    • getFileBase

      public static String getFileBase(String href)
      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

      public static String getFileBase(MCRPath path)
      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

      public static String getFileId(MCRPath path)
      Returns the mets:file/@ID for the given path.
      Parameters:
      path - path to the file
      Returns:
      mets:file ID