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 18 /* $Id: PDFLaunch.java 1780923 2017-01-30 15:24:20Z ssteiner $ */ 19 20 package org.apache.fop.pdf; 21 22 /** 23 * This class represents the /Launch action. 24 */ 25 public class PDFLaunch extends PDFAction { 26 27 private PDFReference externalFileSpec; 28 private boolean newWindow; 29 30 /** 31 * Creates a new /Launch action. 32 * @param fileSpec the file specification to launch 33 */ PDFLaunch(PDFFileSpec fileSpec)34 public PDFLaunch(PDFFileSpec fileSpec) { 35 this(fileSpec.makeReference()); 36 this.newWindow = false; 37 } 38 39 /** 40 * Creates a new /Launch action. 41 * @param fileSpec the file specification to launch 42 * @param newWindow boolean indicating whether the target should be 43 * displayed in a new window 44 */ PDFLaunch(PDFFileSpec fileSpec, boolean newWindow)45 public PDFLaunch(PDFFileSpec fileSpec, boolean newWindow) { 46 this(fileSpec.makeReference()); 47 this.newWindow = newWindow; 48 } 49 50 /** 51 * Creates a new /Launch action. 52 * @param fileSpec a reference to the file specification 53 */ PDFLaunch(PDFReference fileSpec)54 public PDFLaunch(PDFReference fileSpec) { 55 PDFObject fs = fileSpec.getObject(); 56 if (fs != null) { 57 assert fs instanceof PDFFileSpec; 58 } 59 this.externalFileSpec = fileSpec; 60 } 61 62 /** {@inheritDoc} */ getAction()63 public String getAction() { 64 return this.referencePDF(); 65 } 66 67 /** {@inheritDoc} */ toPDFString()68 public String toPDFString() { 69 StringBuffer sb = new StringBuffer(64); 70 sb.append("<<\n/S /Launch\n/F "); 71 sb.append(externalFileSpec.toString()); 72 if (newWindow) { 73 sb.append("\n/NewWindow true"); 74 } 75 sb.append("\n>>"); 76 77 return sb.toString(); 78 } 79 80 /** {@inheritDoc} */ contentEquals(PDFObject obj)81 protected boolean contentEquals(PDFObject obj) { 82 if (this == obj) { 83 return true; 84 } 85 86 if (obj == null || !(obj instanceof PDFLaunch)) { 87 return false; 88 } 89 90 PDFLaunch launch = (PDFLaunch) obj; 91 92 if (!launch.externalFileSpec.toString().equals(externalFileSpec.toString())) { 93 return false; 94 } 95 96 return true; 97 } 98 } 99