]> _ Git - cubeextranet.git/blob
ce0f7e9d68572f66bace5a814360f86e281606b0
[cubeextranet.git] /
1 /*\r
2  * Licensed to the Apache Software Foundation (ASF) under one or more\r
3  * contributor license agreements.  See the NOTICE file distributed with\r
4  * this work for additional information regarding copyright ownership.\r
5  * The ASF licenses this file to You under the Apache License, Version 2.0\r
6  * (the "License"); you may not use this file except in compliance with\r
7  * the License.  You may obtain a copy of the License at\r
8  *\r
9  *      http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 package org.apache.pdfbox.pdmodel.interactive.annotation;\r
18 \r
19 import java.io.IOException;\r
20 \r
21 import org.apache.pdfbox.cos.COSDictionary;\r
22 import org.apache.pdfbox.cos.COSName;\r
23 import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;\r
24 \r
25 /**\r
26  * This is the class that represents a file attachement.\r
27  *\r
28  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>\r
29  * @version $Revision: 1.2 $\r
30  */\r
31 public class PDAnnotationFileAttachment extends PDAnnotationMarkup\r
32 {\r
33     /**\r
34      * See get/setAttachmentName.\r
35      */\r
36     public static final String ATTACHMENT_NAME_PUSH_PIN = "PushPin";\r
37     /**\r
38      * See get/setAttachmentName.\r
39      */\r
40     public static final String ATTACHMENT_NAME_GRAPH = "Graph";\r
41     /**\r
42      * See get/setAttachmentName.\r
43      */\r
44     public static final String ATTACHMENT_NAME_PAPERCLIP = "Paperclip";\r
45     /**\r
46      * See get/setAttachmentName.\r
47      */\r
48     public static final String ATTACHMENT_NAME_TAG = "Tag";\r
49 \r
50     /**\r
51      * The type of annotation.\r
52      */\r
53     public static final String SUB_TYPE = "FileAttachment";\r
54 \r
55     /**\r
56      * Constructor.\r
57      */\r
58     public PDAnnotationFileAttachment()\r
59     {\r
60         super();\r
61         getDictionary().setItem( COSName.SUBTYPE, COSName.getPDFName( SUB_TYPE ) );\r
62     }\r
63 \r
64     /**\r
65      * Creates a Link annotation from a COSDictionary, expected to be\r
66      * a correct object definition.\r
67      *\r
68      * @param field the PDF objet to represent as a field.\r
69      */\r
70     public PDAnnotationFileAttachment(COSDictionary field)\r
71     {\r
72         super( field );\r
73     }\r
74 \r
75     /**\r
76      * Return the attached file.\r
77      *\r
78      * @return The attached file.\r
79      *\r
80      * @throws IOException If there is an error creating the file spec.\r
81      */\r
82     public PDFileSpecification getFile() throws IOException\r
83     {\r
84         return PDFileSpecification.createFS( getDictionary().getDictionaryObject( "FS" ) );\r
85     }\r
86 \r
87     /**\r
88      * Set the attached file.\r
89      *\r
90      * @param file The file that is attached.\r
91      */\r
92     public void setFile( PDFileSpecification file )\r
93     {\r
94         getDictionary().setItem( "FS", file );\r
95     }\r
96 \r
97     /**\r
98      * This is the name used to draw the type of attachment.\r
99      * See the ATTACHMENT_NAME_XXX constants.\r
100      *\r
101      * @return The name that describes the visual cue for the attachment.\r
102      */\r
103     public String getAttachmentName()\r
104     {\r
105         return getDictionary().getNameAsString( "Name", ATTACHMENT_NAME_PUSH_PIN );\r
106     }\r
107 \r
108     /**\r
109      * Set the name used to draw the attachement icon.\r
110      * See the ATTACHMENT_NAME_XXX constants.\r
111      *\r
112      * @param name The name of the visual icon to draw.\r
113      */\r
114     public void setAttachementName( String name )\r
115     {\r
116         getDictionary().setName( "Name", name );\r
117     }\r
118 }\r