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.

PDFGoToRemote.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * Class representing a /GoToR object.
  21. */
  22. public class PDFGoToRemote extends PDFAction {
  23. /**
  24. * the file specification
  25. */
  26. private PDFReference pdfFileSpec;
  27. private int pageReference = 0;
  28. private String destination = null;
  29. private boolean newWindow = false;
  30. /**
  31. * Create an GoToR object.
  32. *
  33. * @param pdfFileSpec the fileSpec associated with the action
  34. * @param newWindow boolean indicating whether the target should be
  35. * displayed in a new window
  36. */
  37. public PDFGoToRemote(PDFFileSpec pdfFileSpec, boolean newWindow) {
  38. /* generic creation of object */
  39. super();
  40. this.pdfFileSpec = pdfFileSpec.makeReference();
  41. this.newWindow = newWindow;
  42. }
  43. /**
  44. * Create an GoToR object.
  45. *
  46. * @param pdfFileSpec the fileSpec associated with the action
  47. * @param page a page reference within the remote document
  48. * @param newWindow boolean indicating whether the target should be
  49. * displayed in a new window
  50. */
  51. public PDFGoToRemote(PDFFileSpec pdfFileSpec, int page, boolean newWindow) {
  52. this(pdfFileSpec.makeReference(), page, newWindow);
  53. }
  54. /**
  55. * Create an GoToR object.
  56. *
  57. * @param pdfFileSpec the fileSpec associated with the action
  58. * @param page a page reference within the remote document
  59. * @param newWindow boolean indicating whether the target should be
  60. * displayed in a new window
  61. */
  62. public PDFGoToRemote(PDFReference pdfFileSpec, int page, boolean newWindow) {
  63. super();
  64. this.pdfFileSpec = pdfFileSpec;
  65. this.pageReference = page;
  66. this.newWindow = newWindow;
  67. }
  68. /**
  69. * create an GoToR object.
  70. *
  71. * @param pdfFileSpec the fileSpec associated with the action
  72. * @param dest a named destination within the remote document
  73. * @param newWindow boolean indicating whether the target should be
  74. * displayed in a new window
  75. */
  76. public PDFGoToRemote(PDFFileSpec pdfFileSpec, String dest, boolean newWindow) {
  77. /* generic creation of object */
  78. super();
  79. this.pdfFileSpec = pdfFileSpec.makeReference();
  80. this.destination = dest;
  81. this.newWindow = newWindow;
  82. }
  83. /**
  84. * return the action string which will reference this object
  85. *
  86. * @return the action String
  87. */
  88. public String getAction() {
  89. return this.referencePDF();
  90. }
  91. /**
  92. * {@inheritDoc}
  93. */
  94. public String toPDFString() {
  95. StringBuffer sb = new StringBuffer(64);
  96. sb.append(getObjectID());
  97. sb.append("<<\n/S /GoToR\n/F ");
  98. sb.append(pdfFileSpec.toString());
  99. sb.append("\n");
  100. if (destination != null) {
  101. sb.append("/D (").append(this.destination).append(")");
  102. } else {
  103. sb.append("/D [ ").append(this.pageReference).append(" /XYZ null null null ]");
  104. }
  105. if (newWindow) {
  106. sb.append("/NewWindow true");
  107. }
  108. sb.append(" \n>>\nendobj\n");
  109. return sb.toString();
  110. }
  111. /*
  112. * example
  113. * 28 0 obj
  114. * <<
  115. * /S /GoToR
  116. * /F 29 0 R
  117. * /D [ 0 /XYZ -6 797 null ]
  118. * >>
  119. * endobj
  120. */
  121. /** {@inheritDoc} */
  122. protected boolean contentEquals(PDFObject obj) {
  123. if (this == obj) {
  124. return true;
  125. }
  126. if (obj == null || !(obj instanceof PDFGoToRemote)) {
  127. return false;
  128. }
  129. PDFGoToRemote remote = (PDFGoToRemote)obj;
  130. if (!remote.pdfFileSpec.toString().equals(pdfFileSpec.toString())) {
  131. return false;
  132. }
  133. if (destination != null) {
  134. if (!destination.equals(remote.destination)) {
  135. return false;
  136. }
  137. } else {
  138. if (pageReference != remote.pageReference) {
  139. return false;
  140. }
  141. }
  142. return (this.newWindow == remote.newWindow);
  143. }
  144. }