1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.pdfbox.pdmodel.interactive.action.type; 18 19 import org.apache.pdfbox.cos.COSBase; 20 import org.apache.pdfbox.cos.COSDictionary; 21 22 /** 23 * This represents a URI action that can be executed in a PDF document. 24 * 25 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 26 * @author Panagiotis Toumasis (ptoumasis@mail.gr) 27 * @version $Revision: 1.3 $ 28 */ 29 public class PDActionURI extends PDAction 30 { 31 /** 32 * This type of action this object represents. 33 */ 34 public static final String SUB_TYPE = "URI"; 35 36 /** 37 * Default constructor. 38 */ 39 public PDActionURI() 40 { 41 action = new COSDictionary(); 42 setSubType( SUB_TYPE ); 43 } 44 45 /** 46 * Constructor. 47 * 48 * @param a The action dictionary. 49 */ 50 public PDActionURI( COSDictionary a ) 51 { 52 super( a ); 53 } 54 55 /** 56 * Convert this standard java object to a COS object. 57 * 58 * @return The cos object that matches this Java object. 59 */ 60 public COSBase getCOSObject() 61 { 62 return action; 63 } 64 65 /** 66 * Convert this standard java object to a COS object. 67 * 68 * @return The cos object that matches this Java object. 69 */ 70 public COSDictionary getCOSDictionary() 71 { 72 return action; 73 } 74 75 /** 76 * This will get the type of action that the actions dictionary describes. 77 * It must be URI for a URI action. 78 * 79 * @return The S entry of the specific URI action dictionary. 80 */ 81 public String getS() 82 { 83 return action.getNameAsString( "S" ); 84 } 85 86 /** 87 * This will set the type of action that the actions dictionary describes. 88 * It must be URI for a URI action. 89 * 90 * @param s The URI action. 91 */ 92 public void setS( String s ) 93 { 94 action.setName( "S", s ); 95 } 96 97 /** 98 * This will get the uniform resource identifier to resolve, encoded in 7-bit ASCII. 99 * 100 * @return The URI entry of the specific URI action dictionary. 101 */ 102 public String getURI() 103 { 104 return action.getString( "URI" ); 105 } 106 107 /** 108 * This will set the uniform resource identifier to resolve, encoded in 7-bit ASCII. 109 * 110 * @param uri The uniform resource identifier. 111 */ 112 public void setURI( String uri ) 113 { 114 action.setString( "URI", uri ); 115 } 116 117 /** 118 * This will specify whether to track the mouse position when the URI is resolved. 119 * Default value: false. 120 * This entry applies only to actions triggered by the user's clicking an annotation; 121 * it is ignored for actions associated with outline items or with a document's OpenAction entry. 122 * 123 * @return A flag specifying whether to track the mouse position when the URI is resolved. 124 */ 125 public boolean shouldTrackMousePosition() 126 { 127 return this.action.getBoolean("IsMap", false); 128 } 129 130 /** 131 * This will specify whether to track the mouse position when the URI is resolved. 132 * 133 * @param value The flag value. 134 */ 135 public void setTrackMousePosition( boolean value ) 136 { 137 this.action.setBoolean("IsMap", value); 138 } 139 140 // TODO this must go into PDURIDictionary 141 /** 142 * This will get the base URI to be used in resolving relative URI references. 143 * URI actions within the document may specify URIs in partial form, to be interpreted 144 * relative to this base address. If no base URI is specified, such partial URIs 145 * will be interpreted relative to the location of the document itself. 146 * The use of this entry is parallel to that of the body element <BASE>, as described 147 * in the HTML 4.01 Specification. 148 * 149 * @return The URI entry of the specific URI dictionary. 150 * @deprecated use {@link PDURIDictionary#getBase()} instead 151 */ 152 public String getBase() 153 { 154 return action.getString( "Base" ); 155 } 156 157 // TODO this must go into PDURIDictionary 158 /** 159 * This will set the base URI to be used in resolving relative URI references. 160 * URI actions within the document may specify URIs in partial form, to be interpreted 161 * relative to this base address. If no base URI is specified, such partial URIs 162 * will be interpreted relative to the location of the document itself. 163 * The use of this entry is parallel to that of the body element <BASE>, as described 164 * in the HTML 4.01 Specification. 165 * 166 * @param base The the base URI to be used. 167 * @deprecated use {@link PDURIDictionary#setBase(String)} instead 168 */ 169 public void setBase( String base ) 170 { 171 action.setString( "Base", base ); 172 } 173 }