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.

PDFDestination.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.commons.io.output.CountingOutputStream;
  22. /**
  23. * class representing a named destination
  24. */
  25. public class PDFDestination extends PDFObject {
  26. /**
  27. * ID Reference for this destination
  28. */
  29. private String idRef;
  30. /**
  31. * PDFReference (object reference) for this destination
  32. */
  33. private Object goToReference;
  34. /**
  35. * Create a named destination
  36. * @param idRef ID Reference for this destination (the name of the destination)
  37. * @param goToRef Object reference to the GoTo Action
  38. */
  39. public PDFDestination(String idRef, Object goToRef) {
  40. super();
  41. this.goToReference = goToRef;
  42. this.idRef = idRef;
  43. }
  44. @Override
  45. public int output(OutputStream stream) throws IOException {
  46. CountingOutputStream cout = new CountingOutputStream(stream);
  47. StringBuilder textBuffer = new StringBuilder(64);
  48. formatObject(getIDRef(), cout, textBuffer);
  49. textBuffer.append(' ');
  50. formatObject(goToReference, cout, textBuffer);
  51. PDFDocument.flushTextBuffer(textBuffer, cout);
  52. return cout.getCount();
  53. }
  54. /**
  55. * Sets the GoToReference in the associated DestinationData object.
  56. *
  57. * @param goToReference the reference to set in the associated DestinationData object.
  58. * @deprecated use setGoToReference(Object) instead
  59. */
  60. @Deprecated
  61. public void setGoToReference(String goToReference) {
  62. this.goToReference = goToReference;
  63. }
  64. /**
  65. * Sets the GoToReference in the associated DestinationData object.
  66. *
  67. * @param goToReference the reference to set in the associated DestinationData object.
  68. */
  69. public void setGoToReference(Object goToReference) {
  70. this.goToReference = goToReference;
  71. }
  72. /**
  73. * Returns the GoToReference from the associated DestinationData object.
  74. *
  75. * @return the GoToReference from the associated DestinationData object.
  76. */
  77. public Object getGoToReference() {
  78. return this.goToReference;
  79. }
  80. /**
  81. * Returns the RefID from the associated DestinationData object.
  82. *
  83. * @return the RefID from the associated DestinationData object.
  84. */
  85. public String getIDRef() {
  86. return this.idRef;
  87. }
  88. /**
  89. * Check if this equals another object.
  90. *
  91. * @param obj the object to compare
  92. * @return true if this equals other object
  93. */
  94. @Override
  95. public boolean equals(Object obj) {
  96. if (this == obj) {
  97. return true;
  98. }
  99. if (obj == null || !(obj instanceof PDFDestination)) {
  100. return false;
  101. }
  102. PDFDestination dest = (PDFDestination)obj;
  103. if (dest.getIDRef().equals(this.getIDRef())) {
  104. return true;
  105. }
  106. return false;
  107. }
  108. /** {@inheritDoc} */
  109. @Override
  110. public int hashCode() {
  111. return getIDRef().hashCode();
  112. }
  113. }