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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 java.io.Writer;
  22. import org.apache.commons.io.output.CountingOutputStream;
  23. /**
  24. * class representing a named destination
  25. */
  26. public class PDFDestination extends PDFObject {
  27. /**
  28. * ID Reference for this destination
  29. */
  30. private String idRef;
  31. /**
  32. * PDFReference (object reference) for this destination
  33. */
  34. private Object goToReference;
  35. /**
  36. * Create a named destination
  37. * @param idRef ID Reference for this destination (the name of the destination)
  38. * @param goToRef Object reference to the GoTo Action
  39. */
  40. public PDFDestination(String idRef, Object goToRef) {
  41. super();
  42. this.goToReference = goToRef;
  43. this.idRef = idRef;
  44. }
  45. /** {@inheritDoc} */
  46. protected int output(OutputStream stream) throws IOException {
  47. CountingOutputStream cout = new CountingOutputStream(stream);
  48. Writer writer = PDFDocument.getWriterFor(cout);
  49. formatObject(getIDRef(), cout, writer);
  50. writer.write(' ');
  51. formatObject(goToReference, cout, writer);
  52. writer.flush();
  53. return cout.getCount();
  54. }
  55. /**
  56. * Sets the GoToReference in the associated DestinationData object.
  57. *
  58. * @param goToReference the reference to set in the associated DestinationData object.
  59. * @deprecated use setGoToReference(Object) instead
  60. */
  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. public boolean equals(Object obj) {
  95. if (this == obj) {
  96. return true;
  97. }
  98. if (obj == null || !(obj instanceof PDFDestination)) {
  99. return false;
  100. }
  101. PDFDestination dest = (PDFDestination)obj;
  102. if (dest.getIDRef().equals(this.getIDRef())) {
  103. return true;
  104. }
  105. return false;
  106. }
  107. /** {@inheritDoc} */
  108. public int hashCode() {
  109. return getIDRef().hashCode();
  110. }
  111. }