All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.harvard.hul.ois.jhove.module.pdf.FileSpecification Maven / Gradle / Ivy

There is a newer version: 1.12.7
Show newest version
/**********************************************************************
 * 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 enum FileSpecification { INSTANCE; private static final String[] dictKeys = {"F", "Unix", "DOS", "Mac"}; /** * 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 static String getFileSpecString (PdfObject obj) throws PdfInvalidException { if (obj instanceof PdfSimpleObject) { return ((PdfSimpleObject) obj).getStringValue (); } try { if (obj instanceof PdfDictionary) { PdfDictionary dictObj = (PdfDictionary) obj; for (final String dictKey : dictKeys) { PdfSimpleObject pathObj = (PdfSimpleObject) dictObj.get(dictKey); if (pathObj != null) { return pathObj.getStringValue(); } } } } catch (ClassCastException e) { throw new PdfInvalidException(MessageConstants.PDF_HUL_9); // PDF-HUL-9 } return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy