eu.planets_project.services.utils
Class DigitalObjectUtils

java.lang.Object
  extended by eu.planets_project.services.utils.DigitalObjectUtils

public final class DigitalObjectUtils
extends Object

Utils for handling digital objects.

Author:
Andy Jackson

Method Summary
static DigitalObject addEvent(DigitalObject digitalObject, Event newEvent)
           
static boolean cleanDigObUtilsTmp()
           
static DigitalObject createZipTypeDigitalObject(File zip_Or_Folder, String destZipName, boolean createByReference, boolean withChecksum, boolean compress)
          Creates a Zip-type DigitalObject either from a given folder or from a zip file.
static long getContentSize(DigitalObject dob)
           
static List<File> getDigitalObjectsAsFiles(List<DigitalObject> listOfDigObjs, File targetFolder)
          A utility method that creates files for the content of "contained"-DigObs in a DigOb.
static Event getEventBySummary(DigitalObject initObj, String summary)
          This method returns event by summary in the targetObj
static String getFileNameFromDigObject(DigitalObject digOb, URI supposedFormatURI)
          Gets the title from the passed digOb and returns a proper file name
static String getFolderNameFromDigObject(DigitalObject digOb)
          Gets the title from the passed digOb and returns a proper folder name (e.g.
static DigitalObject getFragment(DigitalObject digOb, String fragment, boolean createByReference)
          This method returns a new DigOb, containing a file that is specified by the fragment.
static boolean hasEvent(DigitalObject obj, String summary)
          This method evaluates if particular digital object contains an ingest event
static DigitalObject insertFragment(DigitalObject zipTypeDigOb, File fragmentFile, String targetPathInZip, boolean createByReference)
           
static boolean isZipType(DigitalObject digOb)
          test if this is a zip type DigitalObject (format-URL == planets:fmt/ext/zip)
static List<String> listFragments(DigitalObject digOb)
           
static void main(String[] args)
          These cases:
- A compound DO, zip as Content, with MD outside the zip, pointing into it via Title.
static DigitalObject removeFragment(DigitalObject zipTypeDigOb, String targetPathInZip, boolean createByReference)
           
static File toFile(DigitalObject object)
           
static long toFile(DigitalObject object, File file)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getContentSize

public static long getContentSize(DigitalObject dob)
Returns:
The total size, in bytes, of the bytestream contained or referred to by this Digital Object. Does not include the size of any associated metadata, or the Java objects etc.

toFile

public static File toFile(DigitalObject object)
Parameters:
object - The digital object to copy to a temporary file
Returns:
The temporary file the digital object's byte stream was written to

toFile

public static long toFile(DigitalObject object,
                          File file)
Parameters:
object - The digital object to copy to a file
file - The file to copy the digital object's byte stream to
Returns:
The number of bytes copied

main

public static void main(String[] args)
These cases:
- A compound DO, zip as Content, with MD outside the zip, pointing into it via Title. This is to pass between services.
- A zip file containing CDO, MD inside the zip, pointing to the binaries via the Title. This is an pure file 'IP', in effect.
- A compound DO, pulled from such a CDO zip file, with inputstreams for content. Okay, two formats, different contexts and packing/unpacking options.
- (CDO[zip] or CDO) i.e. If no Content, look up to root and unpack?
- DOIP - a special ZIP file containing CDOs.
Operations:
- Packing one or more CDOs into a DOIP, optionally embedding referenced resources. (Value) resources always to be embedded.
- Unpacking a DOIP and getting N CDOs out, optionally embedding binaries, using ZipInputStreams, or unpacking into Files?
TODO Should DO use URI internally got Content.reference, to allow relative resolution?


getDigitalObjectsAsFiles

public static List<File> getDigitalObjectsAsFiles(List<DigitalObject> listOfDigObjs,
                                                  File targetFolder)
A utility method that creates files for the content of "contained"-DigObs in a DigOb. This method returns all contained DigObs one level deep.

Parameters:
listOfDigObjs - The digital objects to create files from
targetFolder - The folder to store result files in
Returns:
The child elements of the given digital object as files

createZipTypeDigitalObject

public static DigitalObject createZipTypeDigitalObject(File zip_Or_Folder,
                                                       String destZipName,
                                                       boolean createByReference,
                                                       boolean withChecksum,
                                                       boolean compress)
Creates a Zip-type DigitalObject either from a given folder or from a zip file.

Parameters:
zip_Or_Folder -
destZipName - the name of the created zip file
createByReference - Create the Content of the DO by reference or by value
withChecksum - Create a checksum for the zip file to create
compress - compress the content of the zip file
Returns:
The digital object representing the zipped files

getFragment

public static DigitalObject getFragment(DigitalObject digOb,
                                        String fragment,
                                        boolean createByReference)
This method returns a new DigOb, containing a file that is specified by the fragment. The Fragment points to a file inside the zip. If the passed DigOb is not a ZIP type DigOb, null is returned.

Parameters:
digOb - the zip type DigOb to get the fragment from
fragment - the fragment (file in the zip) to retrieve
createByReference - create by reference (true) or as stream (false)
Returns:
a new DigitalObject containing the extracted fragment as content

insertFragment

public static DigitalObject insertFragment(DigitalObject zipTypeDigOb,
                                           File fragmentFile,
                                           String targetPathInZip,
                                           boolean createByReference)

removeFragment

public static DigitalObject removeFragment(DigitalObject zipTypeDigOb,
                                           String targetPathInZip,
                                           boolean createByReference)

listFragments

public static List<String> listFragments(DigitalObject digOb)

isZipType

public static boolean isZipType(DigitalObject digOb)
test if this is a zip type DigitalObject (format-URL == planets:fmt/ext/zip)

Parameters:
digOb - the DigitalObject to test
Returns:
"true" if the digOb is of type zip, "false" if not ;-)

getFolderNameFromDigObject

public static String getFolderNameFromDigObject(DigitalObject digOb)
Gets the title from the passed digOb and returns a proper folder name (e.g. strip the extension etc.)

Parameters:
digOb - to get the folder name from
Returns:
the folder name based on "title" in the passed digOb.

getFileNameFromDigObject

public static String getFileNameFromDigObject(DigitalObject digOb,
                                              URI supposedFormatURI)
Gets the title from the passed digOb and returns a proper file name

Parameters:
digOb - to get the file name from
supposedFormatURI - This could be the format you believe the file has. Used to create a proper file name.
Returns:
the folder name based on "title" in the passed digOb.

cleanDigObUtilsTmp

public static boolean cleanDigObUtilsTmp()

addEvent

public static DigitalObject addEvent(DigitalObject digitalObject,
                                     Event newEvent)
Parameters:
digitalObject - The digital object to be updated
newEvent - The event to add to the digital object
Returns:
changed digital object with new event

getEventBySummary

public static Event getEventBySummary(DigitalObject initObj,
                                      String summary)
This method returns event by summary in the targetObj

Parameters:
initObj - The initial digital object
summary - Event property we are looking for
Returns:
res The found event for particular summary

hasEvent

public static boolean hasEvent(DigitalObject obj,
                               String summary)
This method evaluates if particular digital object contains an ingest event

Parameters:
obj - The digital object
summary - The summary of the event
Returns:
res Returns true if digital object contains ingest event otherwise false


Copyright © 2013 Open Planets Foundation. All Rights Reserved.