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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.area;
  18. // Java
  19. import java.util.List;
  20. import java.io.Serializable;
  21. // FOP
  22. import org.apache.fop.area.Trait;
  23. import org.apache.fop.area.Resolveable;
  24. import org.apache.fop.area.PageViewport;
  25. import org.apache.fop.area.Area;
  26. /**
  27. * Link resolving for resolving internal links.
  28. */
  29. public class LinkResolver implements Resolveable, Serializable {
  30. private boolean resolved = false;
  31. private String idRef;
  32. private Area area;
  33. /**
  34. * Create a new link resolver.
  35. *
  36. * @param id the id to resolve
  37. * @param a the area that will have the link attribute
  38. */
  39. public LinkResolver(String id, Area a) {
  40. idRef = id;
  41. area = a;
  42. }
  43. /**
  44. * @return true if this link is resolved
  45. */
  46. public boolean isResolved() {
  47. return resolved;
  48. }
  49. public String[] getIDs() {
  50. return new String[] {idRef};
  51. }
  52. /**
  53. * Resolve by adding an internal link.
  54. */
  55. public void resolve(String id, List pages) {
  56. resolved = true;
  57. if (idRef.equals(id) && pages != null) {
  58. PageViewport page = (PageViewport)pages.get(0);
  59. area.addTrait(Trait.INTERNAL_LINK, page.getKey());
  60. }
  61. }
  62. }