You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDFLaunch.java 2.8KB

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