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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 boolean resolved = false;
  32. private String idRef;
  33. private Area area;
  34. /**
  35. * Create a new link resolver.
  36. *
  37. * @param id the id to resolve
  38. * @param a the area that will have the link attribute
  39. */
  40. public LinkResolver(String id, Area a) {
  41. idRef = id;
  42. area = a;
  43. }
  44. /**
  45. * @return true if this link is resolved
  46. */
  47. public boolean isResolved() {
  48. return resolved;
  49. }
  50. /**
  51. * Get the references for this link.
  52. *
  53. * @return the String array of references.
  54. */
  55. public String[] getIDRefs() {
  56. return new String[] {idRef};
  57. }
  58. /**
  59. * Resolve by adding an internal link to the first PageViewport in the list.
  60. *
  61. * {@inheritDoc}
  62. */
  63. public void resolveIDRef(String id, List pages) {
  64. resolveIDRef(id, (PageViewport)pages.get(0));
  65. }
  66. /**
  67. * Resolve by adding an InternalLink trait to the area
  68. *
  69. * @param id the target id (should be equal to the object's idRef)
  70. * @param pv the PageViewport containing the first area with the given id
  71. */
  72. public void resolveIDRef(String id, PageViewport pv) {
  73. if (idRef.equals(id) && pv != null) {
  74. resolved = true;
  75. Trait.InternalLink iLink = new Trait.InternalLink(pv.getKey(), idRef);
  76. area.addTrait(Trait.INTERNAL_LINK, iLink);
  77. }
  78. }
  79. }