Author: tilman
Date: Thu Feb 22 17:06:22 2018
New Revision: 1825082

URL: http://svn.apache.org/viewvc?rev=1825082&view=rev
Log:
PDFBOX-4117: add GoToE action

Added:
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java
   (with props)
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDTargetDirectory.java
   (with props)
Modified:
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionFactory.java

Added: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java?rev=1825082&view=auto
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java
 (added)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java
 Thu Feb 22 17:06:22 2018
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.interactive.action;
+
+import java.io.IOException;
+
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
+import 
org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
+import 
org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
+
+/**
+ * This represents a embedded go-to action that can be executed in a PDF 
document.
+ *
+ * @author Ben Litchfield
+ * @author Panagiotis Toumasis
+ * @author Tilman Hausherr
+ */
+public class PDActionEmbeddedGoTo extends PDAction
+{
+    /**
+     * This type of action this object represents.
+     */
+    public static final String SUB_TYPE = "GoToE";
+
+    /**
+     * Default constructor.
+     */
+    public PDActionEmbeddedGoTo()
+    {
+        setSubType(SUB_TYPE);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param a The action dictionary.
+     */
+    public PDActionEmbeddedGoTo(COSDictionary a)
+    {
+        super(a);
+    }
+
+    /**
+     * This will get the destination to jump to.
+     *
+     * @return The D entry of the specific go-to action dictionary.
+     *
+     * @throws IOException If there is an error creating the destination.
+     */
+    public PDDestination getDestination() throws IOException
+    {
+        return 
PDDestination.create(getCOSObject().getDictionaryObject(COSName.D));
+    }
+
+    /**
+     * This will set the destination to jump to.
+     *
+     * @param d The destination.
+     *
+     * @throws IllegalArgumentException if the destination is not a page 
dictionary object.
+     */
+    public void setDestination(PDDestination d)
+    {
+        if (d instanceof PDPageDestination)
+        {
+            PDPageDestination pageDest = (PDPageDestination) d;
+            COSArray destArray = pageDest.getCOSObject();
+            if (destArray.size() >= 1)
+            {
+                COSBase page = destArray.getObject(0);
+                if (!(page instanceof COSDictionary))
+                {
+                    throw new IllegalArgumentException("Destination of a GoToE 
action must be "
+                            + "a page dictionary object");
+                }
+            }
+        }
+        getCOSObject().setItem(COSName.D, d);
+    }
+
+    /**
+     * This will get the file in which the destination is located.
+     *
+     * @return The F entry of the specific embedded go-to action dictionary.
+     *
+     * @throws IOException If there is an error creating the file spec.
+     */
+    public PDFileSpecification getFile() throws IOException
+    {
+        return 
PDFileSpecification.createFS(getCOSObject().getDictionaryObject(COSName.F));
+    }
+
+    /**
+     * This will set the file in which the destination is located.
+     *
+     * @param fs The file specification.
+     */
+    public void setFile(PDFileSpecification fs)
+    {
+        getCOSObject().setItem(COSName.F, fs);
+    }
+
+    /**
+     * This will specify whether to open the destination document in a new 
window. If this flag is
+     * false, the destination document will replace the current document in 
the same window. If this
+     * entry is absent, the viewer application should behave in accordance 
with the current user
+     * preference.
+     *
+     * @return A flag specifying whether to open the destination document in a 
new window.
+     */
+    public boolean shouldOpenInNewWindow()
+    {
+        return getCOSObject().getBoolean("NewWindow", true);
+    }
+
+    /**
+     * This will specify the destination document to open in a new window.
+     *
+     * @param value The flag value.
+     */
+    public void setOpenInNewWindow(boolean value)
+    {
+        getCOSObject().setBoolean("NewWindow", value);
+    }
+
+    /**
+     * Get the target directory.
+     *
+     * @return the target directory or null if there is none.
+     */
+    public PDTargetDirectory getTargetDirectory()
+    {
+        COSBase base = getCOSObject().getDictionaryObject(COSName.T);
+        if (base instanceof COSDictionary)
+        {
+            return new PDTargetDirectory((COSDictionary) base);
+        }
+        return null;
+    }
+
+    /**
+     * Sets the target directory.
+     * 
+     * @param targetDirectory
+     */
+    public void setTargetDirectory(PDTargetDirectory targetDirectory)
+    {
+        getCOSObject().setItem(COSName.T, targetDirectory);
+    }
+}

Propchange: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionFactory.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionFactory.java?rev=1825082&r1=1825081&r2=1825082&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionFactory.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionFactory.java
 Thu Feb 22 17:06:22 2018
@@ -92,6 +92,9 @@ public final class PDActionFactory
                     case PDActionThread.SUB_TYPE:
                         retval = new PDActionThread(action);
                         break;
+                    case PDActionEmbeddedGoTo.SUB_TYPE:
+                        retval = new PDActionEmbeddedGoTo(action);
+                        break;
                     default:
                         break;
                 }

Added: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDTargetDirectory.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDTargetDirectory.java?rev=1825082&view=auto
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDTargetDirectory.java
 (added)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDTargetDirectory.java
 Thu Feb 22 17:06:22 2018
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2018 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.pdmodel.interactive.action;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
+
+/**
+ * A target dictionary specifying path information to the target document. 
Each target dictionary
+ * specifies one element in the full path to the target and may have nested 
target dictionaries
+ * specifying additional elements.
+ *
+ * @author Tilman Hausherr
+ */
+public class PDTargetDirectory implements COSObjectable
+{
+    private final COSDictionary dict;
+
+    /**
+     * Default constructor, creates target directory.
+     */
+    public PDTargetDirectory()
+    {
+        dict = new COSDictionary();
+    }
+
+    /**
+     * Create a target directory from an existing dictionary.
+     *
+     * @param dictionary The existing graphics state.
+     */
+    public PDTargetDirectory(COSDictionary dictionary)
+    {
+        dict = dictionary;
+    }
+
+    /**
+     * This will get the underlying dictionary that this class acts on.
+     *
+     * @return The underlying dictionary for this class.
+     */
+    @Override
+    public COSDictionary getCOSObject()
+    {
+        return dict;
+    }
+
+    /**
+     * Get the relationship between the current document and the target (which 
may be an
+     * intermediate target).
+     *
+     * @return the relationship as a name. Valid values are P (the target is 
the parent of the
+     * current document) and C (the target is a child of the current 
document). Invalid values or
+     * null are also returned.
+     */
+    public COSName getRelationship()
+    {
+        COSBase base = dict.getItem(COSName.R);
+        if (base instanceof COSName)
+        {
+            return (COSName) base;
+        }
+        return null;
+    }
+
+    /**
+     * Set the relationship between the current document and the target (which 
may be an
+     * intermediate target).
+     *
+     * @param relationship Valid values are P (the target is the parent of the 
current document) and
+     * C (the target is a child of the current document).
+     *
+     * throws IllegalArgumentException if the parameter is not P or C.
+     */
+    public void setRelationship(COSName relationship)
+    {
+        if (!COSName.P.equals(relationship) && !COSName.P.equals(relationship))
+        {
+            throw new IllegalArgumentException("The only valid are P or C, not 
" + relationship.getName());
+        }
+        dict.setItem(COSName.R, relationship);
+    }
+
+    /**
+     * Get the name of the file as found in the EmbeddedFiles name tree. This 
is only to be used if
+     * the target is a child of the current document.
+     *
+     * @return a filename or null if there is none.
+     */
+    public String getFilename()
+    {
+        return dict.getString(COSName.N);
+    }
+
+    /**
+     * Sets the name of the file as found in the EmbeddedFiles name tree. This 
is only to be used if
+     * the target is a child of the current document.
+     *
+     * @param filename a filename or null if the entry is to be deleted.
+     */
+    public void setFilename(String filename)
+    {
+        dict.setString(COSName.N, filename);
+    }
+
+    /**
+     * Get the target directory. If this entry is absent, the current document 
is the target file
+     * containing the destination.
+     *
+     * @return the target directory or null if the current document is the 
target file containing
+     * the destination.
+     */
+    public PDTargetDirectory getTargetDirectory()
+    {
+        COSBase base = dict.getDictionaryObject(COSName.T);
+        if (base instanceof COSDictionary)
+        {
+            return new PDTargetDirectory((COSDictionary) base);
+        }
+        return null;
+    }
+
+    /**
+     * Sets the target directory.
+     *
+     * @param targetDirectory the target directory or null if the current 
document is the target
+     * file containing the destination.
+     */
+    public void setTargetDirectory(PDTargetDirectory targetDirectory)
+    {
+        dict.setItem(COSName.T, targetDirectory);
+    }
+
+    // page 420
+    //TODO P, A
+    // getPageNumber int
+    // getNamedDestination PDNamedDestination
+    // getAnnotationIndex int
+    // getAnnotationName String
+}

Propchange: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDTargetDirectory.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to