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.

PDFNavigator.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /**
  22. * Navigation Node Dictionary, which we call a 'navigator'.
  23. * This class is used to for sub-page navigation.
  24. */
  25. public class PDFNavigator extends PDFIdentifiedDictionary {
  26. public abstract static class Resolver {
  27. private boolean resolved;
  28. private PDFNavigator navigator;
  29. private Object extension;
  30. public Resolver(PDFNavigator navigator, Object extension) {
  31. this.navigator = navigator;
  32. this.extension = extension;
  33. }
  34. public PDFNavigator getNavigator() {
  35. return navigator;
  36. }
  37. public Object getExtension() {
  38. return extension;
  39. }
  40. public void resolve() {
  41. if (!resolved) {
  42. performResolution();
  43. resolved = true;
  44. }
  45. }
  46. protected void performResolution() {
  47. }
  48. }
  49. private Resolver resolver;
  50. public PDFNavigator(String id) {
  51. super(id);
  52. put("Type", new PDFName("NavNode"));
  53. }
  54. @Override
  55. public int output(OutputStream stream) throws IOException {
  56. if (resolver != null) {
  57. resolver.resolve();
  58. }
  59. return super.output(stream);
  60. }
  61. public void setResolver(Resolver resolver) {
  62. this.resolver = resolver;
  63. }
  64. public void populate(Object nextAction, Object nextNode, Object prevAction, Object prevNode, Object duration) {
  65. if (nextAction != null) {
  66. put("NA", nextAction);
  67. }
  68. if (nextNode != null) {
  69. put("Next", nextNode);
  70. }
  71. if (prevAction != null) {
  72. put("PA", prevAction);
  73. }
  74. if (prevNode != null) {
  75. put("Prev", prevNode);
  76. }
  77. if (duration != null) {
  78. put("Dur", duration);
  79. }
  80. }
  81. }