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.

LinkResolver.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.area;
  19. // Java
  20. import java.util.List;
  21. import java.io.Serializable;
  22. // FOP
  23. import org.apache.fop.area.Trait;
  24. import org.apache.fop.area.Resolvable;
  25. import org.apache.fop.area.PageViewport;
  26. import org.apache.fop.area.Area;
  27. /**
  28. * Link resolving for resolving internal links.
  29. */
  30. public class LinkResolver implements Resolvable, Serializable {
  31. private static final long serialVersionUID = -7102134165192960718L;
  32. private boolean resolved = false;
  33. private String idRef;
  34. private Area area;
  35. /**
  36. * Create a new link resolver.
  37. *
  38. * @param id the id to resolve
  39. * @param a the area that will have the link attribute
  40. */
  41. public LinkResolver(String id, Area a) {
  42. idRef = id;
  43. area = a;
  44. }
  45. /**
  46. * @return true if this link is resolved
  47. */
  48. public boolean isResolved() {
  49. return resolved;
  50. }
  51. /**
  52. * Get the references for this link.
  53. *
  54. * @return the String array of references.
  55. */
  56. public String[] getIDRefs() {
  57. return new String[] {idRef};
  58. }
  59. /**
  60. * Resolve by adding an internal link to the first PageViewport in the list.
  61. *
  62. * {@inheritDoc}
  63. */
  64. public void resolveIDRef(String id, List pages) {
  65. resolveIDRef(id, (PageViewport)pages.get(0));
  66. }
  67. /**
  68. * Resolve by adding an InternalLink trait to the area
  69. *
  70. * @param id the target id (should be equal to the object's idRef)
  71. * @param pv the PageViewport containing the first area with the given id
  72. */
  73. public void resolveIDRef(String id, PageViewport pv) {
  74. if (idRef.equals(id) && pv != null) {
  75. resolved = true;
  76. Trait.InternalLink iLink = new Trait.InternalLink(pv.getKey(), idRef);
  77. area.addTrait(Trait.INTERNAL_LINK, iLink);
  78. }
  79. }
  80. }