Example usage for org.apache.pdfbox.cos COSObject getObject

List of usage examples for org.apache.pdfbox.cos COSObject getObject

Introduction

In this page you can find the example usage for org.apache.pdfbox.cos COSObject getObject.

Prototype

public COSBase getObject() 

Source Link

Document

This will get the object that this object encapsulates.

Usage

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * return true if the elt is a COSStream or a reference to a COSStream
 * //  w  w  w.ja  v  a  2  s . c  o m
 * @param elt
 * @param doc
 * @return
 */
public static boolean isStream(COSBase elt, COSDocument doc) {
    if (elt instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) elt);
            COSObject obj = doc.getObjectFromPool(key);
            return (obj != null && obj.getObject() instanceof COSStream);
        } catch (IOException e) {
            return false;
        }
    }

    return (elt instanceof COSStream);
}

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * return true if the elt is a COSInteger or a reference to a COSInteger
 * //w  ww .  j  av  a2  s . c  o m
 * @param elt
 * @param doc
 * @return
 */
public static boolean isInteger(COSBase elt, COSDocument doc) {
    if (elt instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) elt);
            COSObject obj = doc.getObjectFromPool(key);
            return (obj != null && obj.getObject() instanceof COSInteger);
        } catch (IOException e) {
            return false;
        }
    }

    return (elt instanceof COSInteger);
}

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * return true if the elt is a COSInteger or a reference to a COSInteger
 * /*  w  w  w  .  jav  a 2 s. c o  m*/
 * @param elt
 * @param doc
 * @return
 */
public static boolean isFloat(COSBase elt, COSDocument doc) {
    if (elt instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) elt);
            COSObject obj = doc.getObjectFromPool(key);
            return (obj != null && obj.getObject() instanceof COSFloat);
        } catch (IOException e) {
            return false;
        }
    }

    return (elt instanceof COSFloat);
}

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * return true if the elt is a COSArray or a reference to a COSArray
 * /* w w w.j  a v a2s .co  m*/
 * @param elt
 * @param doc
 * @return
 */
public static boolean isArray(COSBase elt, COSDocument doc) {
    if (elt instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) elt);
            COSObject obj = doc.getObjectFromPool(key);
            return (obj != null && obj.getObject() instanceof COSArray);
        } catch (IOException e) {
            return false;
        }
    }

    return (elt instanceof COSArray);
}

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * Return the COSBase object as COSArray if the COSBase object is an instance
 * of COSArray or a reference to a COSArray object. In other cases, this
 * method returns null;//w  w w  . j av a2 s  . com
 * 
 * @param cbase
 * @param cDoc
 * @return
 */
public static COSArray getAsArray(COSBase cbase, COSDocument cDoc) {
    if (cbase instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) cbase);
            COSObject obj = cDoc.getObjectFromPool(key);
            if (obj != null && obj.getObject() instanceof COSArray) {
                return (COSArray) obj.getObject();
            } else {
                return null;
            }
        } catch (IOException e) {
            return null;
        }
    } else if (cbase instanceof COSArray) {
        return (COSArray) cbase;
    } else {
        return null;
    }
}

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * Return the COSBase object as COSString if the COSBase object is an instance
 * of COSString or a reference to a COSString object. In other cases, this
 * method returns null;/*from   w ww  .j av  a 2  s  . com*/
 * 
 * @param cbase
 * @param cDoc
 * @return
 */
public static String getAsString(COSBase cbase, COSDocument cDoc) {
    if (cbase instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) cbase);
            COSObject obj = cDoc.getObjectFromPool(key);
            if (obj != null && obj.getObject() instanceof COSString) {
                return ((COSString) obj.getObject()).getString();
            } else if (obj != null && obj.getObject() instanceof COSName) {
                return ((COSName) obj.getObject()).getName();
            } else {
                return null;
            }
        } catch (IOException e) {
            return null;
        }
    } else if (cbase instanceof COSString) {
        return ((COSString) cbase).getString();
    } else if (cbase instanceof COSName) {
        return ((COSName) cbase).getName();
    } else {
        return null;
    }
}

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * Return the COSBase object as COSDictionary if the COSBase object is an
 * instance of COSDictionary or a reference to a COSDictionary object. In
 * other cases, this method returns null;
 * //w w w.  j  a va2  s. c om
 * @param cbase
 * @param cDoc
 * @return
 */
public static COSDictionary getAsDictionary(COSBase cbase, COSDocument cDoc) {
    if (cbase instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) cbase);
            COSObject obj = cDoc.getObjectFromPool(key);
            if (obj != null && obj.getObject() instanceof COSDictionary) {
                return (COSDictionary) obj.getObject();
            } else {
                return null;
            }
        } catch (IOException e) {
            return null;
        }
    } else if (cbase instanceof COSDictionary) {
        return (COSDictionary) cbase;
    } else {
        return null;
    }
}

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * Return the COSBase object as COSStream if the COSBase object is an instance
 * of COSStream or a reference to a COSStream object. In other cases, this
 * method returns null;/*from w  w  w.j  a va 2s  . co m*/
 * 
 * @param cbase
 * @param cDoc
 * @return
 */
public static COSStream getAsStream(COSBase cbase, COSDocument cDoc) {
    if (cbase instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) cbase);
            COSObject obj = cDoc.getObjectFromPool(key);
            if (obj != null && obj.getObject() instanceof COSStream) {
                return (COSStream) obj.getObject();
            } else {
                return null;
            }
        } catch (IOException e) {
            return null;
        }
    } else if (cbase instanceof COSStream) {
        return (COSStream) cbase;
    } else {
        return null;
    }
}

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * Return the COSBase object as Float if the COSBase object is an instance of
 * COSFloat or a reference to a COSFloat object. In other cases, this method
 * returns null;/*w w w. ja va 2s  .c o m*/
 * 
 * @param cbase
 * @param cDoc
 * @return
 */
public static Float getAsFloat(COSBase cbase, COSDocument cDoc) {
    if (cbase instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) cbase);
            COSObject obj = cDoc.getObjectFromPool(key);
            if (obj == null) {
                return null;
            } else if (obj.getObject() instanceof COSFloat) {
                return ((COSFloat) obj.getObject()).floatValue();
            } else if (obj.getObject() instanceof COSInteger) {
                return (float) ((COSInteger) obj.getObject()).intValue();
            } else {
                return null;
            }
        } catch (IOException e) {
            return null;
        }
    } else if (cbase instanceof COSFloat) {
        return ((COSFloat) cbase).floatValue();
    } else if (cbase instanceof COSInteger) {
        return (float) ((COSInteger) cbase).intValue();
    } else {
        return null;
    }
}

From source file:net.padaf.preflight.utils.COSUtils.java

License:Apache License

/**
 * Return the COSBase object as Integer if the COSBase object is an instance
 * of COSInteger or a reference to a COSInteger object. In other cases, this
 * method returns null;//  ww  w.  ja v  a 2s .  c  om
 * 
 * @param cbase
 * @param cDoc
 * @return
 */
public static Integer getAsInteger(COSBase cbase, COSDocument cDoc) {
    if (cbase instanceof COSObject) {
        try {
            COSObjectKey key = new COSObjectKey((COSObject) cbase);
            COSObject obj = cDoc.getObjectFromPool(key);
            if (obj == null) {
                return null;
            } else if (obj.getObject() instanceof COSInteger) {
                return ((COSInteger) obj.getObject()).intValue();
            } else if (obj.getObject() instanceof COSFloat) {
                return ((COSFloat) obj.getObject()).intValue();
            } else {
                return null;
            }
        } catch (IOException e) {
            return null;
        }
    } else if (cbase instanceof COSInteger) {
        return ((COSInteger) cbase).intValue();
    } else if (cbase instanceof COSFloat) {
        return ((COSFloat) cbase).intValue();
    } else {
        return null;
    }
}