⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cosdictionary.java

📁 非常有用的操作pdf文件的java源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    /**
     * This is a convenience method that will convert the value to a COSString
     * object.  If it is null then the object will be removed.
     *
     * @param embedded The embedded dictionary to set the item in.
     * @param key The key to the object,
     * @param value The string value for the name.
     */
    public void setEmbeddedString( String embedded, COSName key, String value )
    {
        COSDictionary dic = (COSDictionary)getDictionaryObject( embedded );
        if( dic == null && value != null )
        {
            dic = new COSDictionary();
            setItem( embedded, dic );
        }
        if( dic != null )
        {
            dic.setString( key, value );
        }
    }
    
    /**
     * This is a convenience method that will convert the value to a COSInteger
     * object.  
     *
     * @param key The key to the object,
     * @param value The int value for the name.
     */
    public void setInt( String key, int value )
    {
        setInt( COSName.getPDFName( key ), value );
    }

    /**
     * This is a convenience method that will convert the value to a COSInteger
     * object.
     *
     * @param key The key to the object,
     * @param value The int value for the name.
     */
    public void setInt( COSName key, int value )
    {
        COSInteger intVal = null;
        intVal = new COSInteger(value);
        setItem( key, intVal );
    }
    
    /**
     * This is a convenience method that will convert the value to a COSInteger
     * object.  
     *
     * @param key The key to the object,
     * @param value The int value for the name.
     */
    public void setLong( String key, long value )
    {
        setLong( COSName.getPDFName( key ), value );
    }

    /**
     * This is a convenience method that will convert the value to a COSInteger
     * object.
     *
     * @param key The key to the object,
     * @param value The int value for the name.
     */
    public void setLong( COSName key, long value )
    {
        COSInteger intVal = null;
        intVal = new COSInteger(value);
        setItem( key, intVal );
    }
    
    /**
     * This is a convenience method that will convert the value to a COSInteger
     * object.  
     *
     * @param embeddedDictionary The embedded dictionary.
     * @param key The key to the object,
     * @param value The int value for the name.
     */
    public void setEmbeddedInt( String embeddedDictionary, String key, int value )
    {
        setEmbeddedInt( embeddedDictionary, COSName.getPDFName( key ), value );
    }

    /**
     * This is a convenience method that will convert the value to a COSInteger
     * object.
     *
     * @param embeddedDictionary The embedded dictionary.
     * @param key The key to the object,
     * @param value The int value for the name.
     */
    public void setEmbeddedInt( String embeddedDictionary, COSName key, int value )
    {
        COSDictionary embedded = (COSDictionary)getDictionaryObject( embeddedDictionary );
        if( embedded == null )
        {
            embedded = new COSDictionary();
            setItem( embeddedDictionary, embedded );
        }
        embedded.setInt( key, value );
    }
    
    /**
     * This is a convenience method that will convert the value to a COSFloat
     * object.  
     *
     * @param key The key to the object,
     * @param value The int value for the name.
     */
    public void setFloat( String key, float value )
    {
        setFloat( COSName.getPDFName( key ), value );
    }

    /**
     * This is a convenience method that will convert the value to a COSFloat
     * object.
     *
     * @param key The key to the object,
     * @param value The int value for the name.
     */
    public void setFloat( COSName key, float value )
    {
        COSFloat fltVal = new COSFloat( value );
        setItem( key, fltVal );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     */
    public String getNameAsString( String key )
    {
        return getNameAsString( COSName.getPDFName( key ) );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     */
    public String getNameAsString( COSName key )
    {
        String retval = null;
        COSName name = (COSName)getDictionaryObject( key );
        if( name != null )
        {
            retval = name.getName();
        }
        return retval;
    }
    
    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @param defaultValue The value to return if the dictionary item is null.
     * @return The name converted to a string.
     */
    public String getNameAsString( String key, String defaultValue )
    {
        return getNameAsString( COSName.getPDFName( key ), defaultValue );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @param defaultValue The value to return if the dictionary item is null.
     * @return The name converted to a string.
     */
    public String getNameAsString( COSName key, String defaultValue )
    {
        String retval = getNameAsString( key );
        if( retval == null )
        {
            retval = defaultValue;
        }
        return retval;
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     */
    public String getString( String key )
    {
        return getString( COSName.getPDFName( key ) );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     */
    public String getString( COSName key )
    {
        String retval = null;
        COSString name = (COSString)getDictionaryObject( key );
        if( name != null )
        {
            retval = name.getString();
        }
        return retval;
    }
    
    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @param defaultValue The default value to return.
     * @return The name converted to a string.
     */
    public String getString( String key, String defaultValue )
    {
        return getString( COSName.getPDFName( key ), defaultValue );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @param defaultValue The default value to return.
     * @return The name converted to a string.
     */
    public String getString( COSName key, String defaultValue )
    {
        String retval = getString( key );
        if( retval == null )
        {
            retval = defaultValue;
        }
        return retval;
    }
    
    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param embedded The embedded dictionary.
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     */
    public String getEmbeddedString( String embedded, String key )
    {
        return getEmbeddedString( embedded, COSName.getPDFName( key ), null );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param embedded The embedded dictionary.
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     */
    public String getEmbeddedString( String embedded, COSName key )
    {
        return getEmbeddedString( embedded, key, null );
    }
    
    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param embedded The embedded dictionary.
     * @param key The key to the item in the dictionary.
     * @param defaultValue The default value to return.
     * @return The name converted to a string.
     */
    public String getEmbeddedString( String embedded, String key, String defaultValue )
    {
        return getEmbeddedString( embedded, COSName.getPDFName( key ), defaultValue );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param embedded The embedded dictionary.
     * @param key The key to the item in the dictionary.
     * @param defaultValue The default value to return.
     * @return The name converted to a string.
     */
    public String getEmbeddedString( String embedded, COSName key, String defaultValue )
    {
        String retval = defaultValue;
        COSDictionary dic = (COSDictionary)getDictionaryObject( embedded );
        if( dic != null )
        {
            retval = dic.getString( key, defaultValue );
        }
        return retval;
    }
    
    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     * @throws IOException If there is an error converting to a date.
     */
    public Calendar getDate( String key ) throws IOException
    {
        return getDate( COSName.getPDFName( key ) );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     * 
     * @throws IOException If there is an error converting to a date.
     */
    public Calendar getDate( COSName key ) throws IOException
    {
        COSString date = (COSString)getDictionaryObject( key );
        return DateConverter.toCalendar( date );
    }
    
    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a date.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @param defaultValue The default value to return.
     * @return The name converted to a string.
     * @throws IOException If there is an error converting to a date.
     */
    public Calendar getDate( String key, Calendar defaultValue ) throws IOException
    {
        return getDate( COSName.getPDFName( key ), defaultValue );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a date.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param key The key to the item in the dictionary.
     * @param defaultValue The default value to return.
     * @return The name converted to a string.
     * @throws IOException If there is an error converting to a date.
     */
    public Calendar getDate( COSName key, Calendar defaultValue ) throws IOException
    {
        Calendar retval = getDate( key );
        if( retval == null )
        {
            retval = defaultValue;
        }
        return retval;
    }
    
    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param embedded The embedded dictionary to get.
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     * @throws IOException If there is an error converting to a date.
     */
    public Calendar getEmbeddedDate( String embedded, String key ) throws IOException
    {
        return getEmbeddedDate( embedded, COSName.getPDFName( key ), null );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a name and convert it to a string.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param embedded The embedded dictionary to get.
     * @param key The key to the item in the dictionary.
     * @return The name converted to a string.
     * 
     * @throws IOException If there is an error converting to a date.
     */
    public Calendar getEmbeddedDate( String embedded, COSName key ) throws IOException
    {
        return getEmbeddedDate( embedded, key, null );
    }
    
    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a date.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param embedded The embedded dictionary to get.
     * @param key The key to the item in the dictionary.
     * @param defaultValue The default value to return.
     * @return The name converted to a string.
     * @throws IOException If there is an error converting to a date.
     */
    public Calendar getEmbeddedDate( String embedded, String key, Calendar defaultValue ) throws IOException
    {
        return getEmbeddedDate( embedded, COSName.getPDFName( key ), defaultValue );
    }

    /**
     * This is a convenience method that will get the dictionary object that
     * is expected to be a date.  Null is returned
     * if the entry does not exist in the dictionary.
     *
     * @param embedded The embedded dictionary to get.
     * @param key The key to the item in the dictionary.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -