Skip to content

Commit

Permalink
Merge branch 'integration' into refact/core-apps-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
carlwilson authored May 21, 2018
2 parents 21fd213 + 667fe96 commit c630d83
Show file tree
Hide file tree
Showing 41 changed files with 681 additions and 799 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public final class AProfile extends PdfProfile

/* The following are the annotation types which are considered
non-text annotations. */
private String[] nonTextAnnotTypes = {
"Link", "Line", "Square", "Circle",
"Polygon", "Polyline", "Stamp", "Caret",
"Ink", "Popup", "Widget", "Screen",
"PrinterMark", "TrapNet"
};
// private String[] nonTextAnnotTypes = {
// "Link", "Line", "Square", "Circle",
// "Polygon", "Polyline", "Stamp", "Caret",
// "Ink", "Popup", "Widget", "Screen",
// "PrinterMark", "TrapNet"
// };

private String[] excludedActions = {
"Launch", "Sound", "Movie", "ResetForm",
Expand Down Expand Up @@ -100,6 +100,7 @@ public void setTaggedProfile (TaggedProfile tpr)
* be called.
*
*/
@Override
public boolean satisfiesThisProfile ()
{
// Assume level A compliance.
Expand Down Expand Up @@ -234,7 +235,7 @@ private boolean fontsOK ()
Iterator<Map<Integer, PdfObject>> iter = lst.listIterator ();
try {
while (iter.hasNext ()) {
Map<Integer, PdfObject> fmap = (Map<Integer, PdfObject>) iter.next ();
Map<Integer, PdfObject> fmap = iter.next ();
Iterator<PdfObject> iter1 = fmap.values ().iterator ();
while (iter1.hasNext ()) {
PdfDictionary font = (PdfDictionary) iter1.next ();
Expand Down Expand Up @@ -318,7 +319,7 @@ private boolean fontOK (PdfDictionary font)
*
* PdfStream toUni = (PdfStream) font.get ("ToUnicode");
*/
PdfObject toUni = (PdfObject) font.get ("ToUnicode");
PdfObject toUni = font.get ("ToUnicode");
if (toUni == null) {
_levelA = false;
}
Expand Down Expand Up @@ -368,7 +369,7 @@ private boolean type0FontsOK ()
// While Adobe warns that this may change in a
// previous version, we require here that the
// first descendant be a CIDFont, and ignore any others.
Vector subfonts = descendants.getContent ();
Vector<PdfObject> subfonts = descendants.getContent ();

/*
* Fix contributed by FCLA, 2007-05-30, to permit the
Expand All @@ -380,7 +381,7 @@ private boolean type0FontsOK ()
* subfont = (PdfDictionary)
* _module.resolveIndirectObject (subfont);
*/
PdfObject objFont = (PdfObject) subfonts.elementAt (0);
PdfObject objFont = subfonts.elementAt (0);
PdfDictionary subfont = (PdfDictionary)
_module.resolveIndirectObject (objFont);
PdfSimpleObject subtype =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public AProfileLevelA(PdfModule module) {
* been called on the profile assigned by <code>setAProfile</code>.
*
*/
@Override
public boolean satisfiesThisProfile() {
return _aProfile.satisfiesLevelA();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package edu.harvard.hul.ois.jhove.module.pdf;

import edu.harvard.hul.ois.jhove.module.PdfModule;

import java.io.IOException;
import java.util.*;

/**
Expand Down Expand Up @@ -42,7 +44,7 @@ public final class Destination
******************************************************************/

/* Flag indicating destination is indirect. */
private boolean _indirect;
private boolean _indirect = false;

/* Name of indirect destination. */
private PdfSimpleObject _indirectDest;
Expand All @@ -61,36 +63,35 @@ public final class Destination
* @param named Flag indicating whether this object came
* from a named destination.
*/
public Destination (PdfObject destObj, PdfModule module, boolean named)
public Destination (final PdfObject destObj, final PdfModule module, final boolean named)
throws PdfException
{
if (!named && destObj instanceof PdfSimpleObject) {
_indirect = true;
_indirectDest = (PdfSimpleObject) destObj;
return;
}
PdfArray destArray = null;
try {
if (!named && destObj instanceof PdfSimpleObject) {
_indirect = true;
_indirectDest = (PdfSimpleObject) destObj;
}
else if (destObj instanceof PdfArray) {
if (destObj instanceof PdfArray) {
destArray = (PdfArray) destObj;
// We extract only the page reference, not the view.
_indirect = false;
Vector v = ((PdfArray) destObj).getContent ();
_pageDest = (PdfDictionary) module.resolveIndirectObject
((PdfObject) v.elementAt (0));
}
else if (named && destObj instanceof PdfDictionary) {
PdfArray destArray = (PdfArray)
_pageDest = findDirectDest(module, destArray);
} else if (named && destObj instanceof PdfDictionary) {
destArray = (PdfArray)
((PdfDictionary) destObj).get ("D");
// The D entry is just like the array above.
_indirect = false;
Vector v = destArray.getContent ();
_pageDest = (PdfDictionary) module.resolveIndirectObject
((PdfObject) v.elementAt (0));
}
else {
throw new Exception ("");
_pageDest = findDirectDest(module, destArray);
} else {
throw new PdfInvalidException (MessageConstants.ERR_DEST_OBJ_INVALID); // PDF-HUL-1
}
}
catch (Exception e) {
throw new PdfInvalidException (MessageConstants.ERR_DEST_OBJ_INVALID);
catch (ClassCastException e) {
throw new PdfInvalidException (MessageConstants.ERR_DEST_OBJ_INVALID); // PDF-HUL-2
}
catch (IOException e) {
throw new PdfInvalidException (String.format(MessageConstants.ERR_DEST_IOEXCEP_READING, // PDF-HUL-3
Integer.valueOf(destArray._objNumber)));
}
}

Expand Down Expand Up @@ -131,4 +132,9 @@ public int getPageDestObjNumber () throws NullPointerException
{
return _pageDest.getObjNumber ();
}

private static PdfDictionary findDirectDest(final PdfModule module, final PdfArray destObj)
throws PdfException, IOException {
return (PdfDictionary) module.resolveIndirectObject(destObj.getContent().elementAt(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ public abstract class DocNode
*/
public DocNode (PdfModule module,
PageTreeNode parent,
PdfDictionary dict)
PdfDictionary dict) throws PdfMalformedException
{
if (dict == null) {
throw new PdfMalformedException (MessageConstants.ERR_DOC_NODE_DICT_MISSING); // PDF-HUL-4
}
_module = module;
_parent = parent;
_dict = dict;
// Debug code
PdfIndirectObj parentRef = (PdfIndirectObj) _dict.get ("Parent");
}

/**
Expand Down Expand Up @@ -99,19 +100,13 @@ public PdfDictionary getDict ()
*/
public PdfDictionary getResources () throws PdfException
{
if (_dict == null) {
throw new PdfMalformedException (MessageConstants.ERR_DOC_NODE_DICT_MISSING);
}
PdfObject resdict = _dict.get ("Resources");
try {
PdfObject resdict = _dict.get ("Resources");
resdict = _module.resolveIndirectObject (resdict);
return (PdfDictionary) resdict;
}
catch (ClassCastException e) {
throw new PdfInvalidException (MessageConstants.ERR_RESOURCES_ENTRY_INVALID);
}
catch (IOException f) {
throw new PdfInvalidException (MessageConstants.ERR_RESOURCES_ENTRY_INVALID);
catch (ClassCastException | IOException f) {
throw new PdfInvalidException(MessageConstants.ERR_RESOURCES_ENTRY_INVALID); // PDF-HUL-5
}
}

Expand All @@ -126,18 +121,18 @@ public PdfDictionary getResources () throws PdfException
public PdfDictionary getFontResources () throws PdfException
{
PdfDictionary resdict = getResources ();
if (resdict != null) {
try {
PdfObject fontdict = (PdfObject) resdict.get("Font");
fontdict = _module.resolveIndirectObject (fontdict);
return (PdfDictionary) fontdict;
}
catch (Exception e) {
throw new PdfMalformedException
(MessageConstants.ERR_RESOURCES_FONT_ENTRY_INVALID);
}
if (resdict == null) {
return null;
}
PdfObject fontdict = resdict.get("Font");
try {
fontdict = _module.resolveIndirectObject (fontdict);
return (PdfDictionary) fontdict;
}
catch (ClassCastException | IOException e) {
throw new PdfMalformedException
(MessageConstants.ERR_RESOURCES_FONT_ENTRY_INVALID); // PDF-HUL-6
}
return null;
}

/**
Expand All @@ -148,17 +143,18 @@ public PdfDictionary getFontResources () throws PdfException
*/
public PdfArray getMediaBox () throws PdfInvalidException
{
PdfArray mbox = null;
try {
PdfArray mbox = (PdfArray) get ("MediaBox", true);
if (mbox.toRectangle () != null) {
return mbox;
}
// There's a MediaBox, but it's not a rectangle
throw new PdfInvalidException (MessageConstants.ERR_PAGE_TREE_MEDIA_BOX_MALFORMED);
mbox = (PdfArray) get ("MediaBox", true);
}
catch (Exception e) {
throw new PdfInvalidException (MessageConstants.ERR_PAGE_TREE_MEDIA_BOX_MALFORMED);
catch (ClassCastException e) {
throw new PdfInvalidException (MessageConstants.ERR_PAGE_TREE_MEDIA_BOX_MALFORMED); // PDF-HUL-7
}
if (mbox != null && mbox.toRectangle () == null) {
// There's a MediaBox, but it's not a rectangle
throw new PdfInvalidException (MessageConstants.ERR_PAGE_TREE_MEDIA_BOX_MALFORMED); // PDF-HUL-8
}
return mbox;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
* <LI>The Macintosh file specification string
* </UL>
*/
public class FileSpecification
public enum FileSpecification
{
String _specString;
PdfObject _sourceObject;

INSTANCE;
private static final String[] dictKeys = {"F", "Unix", "DOS", "Mac"};
/**
* Constructor.
*
Expand All @@ -37,50 +36,25 @@ public class FileSpecification
* then the first of the keys F, Unix, DOS, and Mac
* to be found is used.
*/
public FileSpecification (PdfObject obj) throws PdfException
public static String getFileSpecString (PdfObject obj) throws PdfInvalidException
{
if (obj instanceof PdfSimpleObject) {
return ((PdfSimpleObject) obj).getStringValue ();
}
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 ();
for (final String dictKey : dictKeys) {
PdfSimpleObject pathObj = (PdfSimpleObject) dictObj.get(dictKey);
if (pathObj != null) {
return pathObj.getStringValue();
}
}
}
else if (obj instanceof PdfSimpleObject) {
_specString = ((PdfSimpleObject) obj).getStringValue ();
}
}
catch (ClassCastException e) {
throw new PdfInvalidException (MessageConstants.ERR_FILE_SPEC_INVALID);
throw new PdfInvalidException(MessageConstants.ERR_FILE_SPEC_INVALID); // PDF-HUL-9
}
}

/**
* 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;
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ private void initFileBuffer ()

/** Gets the current position in the file. This method is
* aware of buffering. */
public long getFilePos () throws IOException
public long getFilePos ()
{
return _fileBufferPositionOffset + _fileBufferOffset;
}


/** Gets a character from the file, using a buffer. */
@Override
public int readChar () throws IOException
{
if (_fileBufferOffset >= _fileBufferBytes) {
Expand All @@ -73,14 +74,15 @@ public int readChar () throws IOException
}
_fileBufferOffset = 0;
}
return (int) (_fileBuffer[_fileBufferOffset++] & 0XFF);
return (_fileBuffer[_fileBufferOffset++] & 0XFF);
}

/**
* Set the Tokenizer to a new position in the file.
*
* @param offset The offset in bytes from the start of the file.
*/
@Override
public void seek (long offset)
throws IOException
{
Expand All @@ -102,6 +104,7 @@ public void seek (long offset)
/**
* Back up a byte so it will be read again.
*/
@Override
public void backupChar ()
{
_fileBufferOffset--;
Expand All @@ -111,7 +114,8 @@ public void backupChar ()
* so some of the initialization of a stream object
* goes here.
*/
protected void initStream (Stream token) throws IOException
@Override
protected void initStream (Stream token)
{
token.setOffset (getFilePos ());
}
Expand All @@ -121,7 +125,8 @@ protected void initStream (Stream token) throws IOException
* Only the file-based tokenizer can do this, which is why this
* overrides the Tokenizer method.
*/
protected void setStreamOffset (Stream token) throws IOException
@Override
protected void setStreamOffset (Stream token)
{
if (token.getOffset() < 0) {
token.setOffset (getFilePos ());
Expand Down
Loading

0 comments on commit c630d83

Please sign in to comment.