edu.harvard.hul.ois.jhove.module.pdf.FileSpecification Maven / Gradle / Ivy
/**********************************************************************
* Jhove - JSTOR/Harvard Object Validation Environment
* Copyright 2003 by JSTOR and the President and Fellows of Harvard College
**********************************************************************/
package edu.harvard.hul.ois.jhove.module.pdf;
/**
* A class which encapsulates a file specification in PDF. A file
* specification may be given as either a string or a dictionary.
* The specification is converted to a string according to the following
* rules: If a PDF string object is the file specifier, that string
* is used, without attempting to convert file separators to the local
* file system. If a PDF dictionary is used, one of the following is
* used, in decreasing order of preference:
*
*
* - The system-neutral file specification string
*
- The Unix file specification string
*
- The DOS file specification string
*
- The Macintosh file specification string
*
*/
public class FileSpecification
{
String _specString;
PdfObject _sourceObject;
/**
* Constructor.
*
* @param obj A PdfDictionary with the file specification under the
* key "F", "Unix", "DOS", or "Mac"; or
* a PdfSimpleObject whose string value is the
* file specification. If obj
is
* a dictionary and more than one key is specified,
* then the first of the keys F, Unix, DOS, and Mac
* to be found is used.
*/
public FileSpecification (PdfObject obj) throws PdfException
{
try {
_sourceObject = obj;
if (obj instanceof PdfDictionary) {
PdfDictionary dictObj = (PdfDictionary) obj;
PdfSimpleObject pathObj;
pathObj = (PdfSimpleObject) dictObj.get ("F");
if (pathObj == null) {
pathObj = (PdfSimpleObject) dictObj.get ("Unix");
}
if (pathObj == null) {
pathObj = (PdfSimpleObject) dictObj.get ("DOS");
}
if (pathObj == null) {
pathObj = (PdfSimpleObject) dictObj.get ("Mac");
}
if (pathObj != null) {
_specString = pathObj.getStringValue ();
}
}
else if (obj instanceof PdfSimpleObject) {
_specString = ((PdfSimpleObject) obj).getStringValue ();
}
}
catch (ClassCastException e) {
throw new PdfInvalidException (MessageConstants.ERR_FILE_SPEC_INVALID);
}
}
/**
* Returns the file specification as a string.
*/
public String getSpecString ()
{
return _specString;
}
/**
* Returns the PdfObject from which the file specification was created.
*/
public PdfObject getSourceObject ()
{
return _sourceObject;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy