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.

Bookmark.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.fo.pagination.bookmarks;
  19. import java.util.ArrayList;
  20. import org.xml.sax.Locator;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.fo.FONode;
  23. import org.apache.fop.fo.FObj;
  24. import org.apache.fop.fo.PropertyList;
  25. import org.apache.fop.fo.ValidationException;
  26. import org.apache.fop.fo.properties.CommonAccessibility;
  27. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  28. /**
  29. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_bookmark">
  30. * <code>fo:bookmark</code></a> object, first introduced in the
  31. * XSL 1.1 WD.
  32. */
  33. public class Bookmark extends FObj implements CommonAccessibilityHolder {
  34. private BookmarkTitle bookmarkTitle;
  35. private ArrayList childBookmarks = new ArrayList();
  36. // The value of properties relevant for this FO
  37. private CommonAccessibility commonAccessibility;
  38. private String internalDestination;
  39. private String externalDestination;
  40. private boolean bShow = true; // from starting-state property
  41. // Valid, but unused properties. Commented out for performance
  42. // private CommonAccessibility commonAccessibility;
  43. /**
  44. * Create a new Bookmark object that is a child of the
  45. * given {@link FONode}.
  46. *
  47. * @param parent the parent fo node
  48. */
  49. public Bookmark(FONode parent) {
  50. super(parent);
  51. }
  52. /** {@inheritDoc} */
  53. public void bind(PropertyList pList) throws FOPException {
  54. commonAccessibility = CommonAccessibility.getInstance(pList);
  55. externalDestination = pList.get(PR_EXTERNAL_DESTINATION).getString();
  56. internalDestination = pList.get(PR_INTERNAL_DESTINATION).getString();
  57. bShow = (pList.get(PR_STARTING_STATE).getEnum() == EN_SHOW);
  58. // per spec, internal takes precedence if both specified
  59. if (internalDestination.length() > 0) {
  60. externalDestination = null;
  61. } else if (externalDestination.length() == 0) {
  62. // slightly stronger than spec "should be specified"
  63. getFOValidationEventProducer().missingLinkDestination(this, getName(), locator);
  64. } else {
  65. getFOValidationEventProducer().unimplementedFeature(this, getName(),
  66. "external-destination", getLocator());
  67. }
  68. }
  69. /**
  70. * {@inheritDoc}
  71. * <br>XSL/FOP: (bookmark-title, bookmark*)
  72. */
  73. protected void validateChildNode(Locator loc, String nsURI, String localName)
  74. throws ValidationException {
  75. if (FO_URI.equals(nsURI)) {
  76. if (localName.equals("bookmark-title")) {
  77. if (bookmarkTitle != null) {
  78. tooManyNodesError(loc, "fo:bookmark-title");
  79. }
  80. } else if (localName.equals("bookmark")) {
  81. if (bookmarkTitle == null) {
  82. nodesOutOfOrderError(loc, "fo:bookmark-title", "fo:bookmark");
  83. }
  84. } else {
  85. invalidChildError(loc, nsURI, localName);
  86. }
  87. }
  88. }
  89. /** {@inheritDoc} */
  90. protected void endOfNode() throws FOPException {
  91. if (bookmarkTitle == null) {
  92. missingChildElementError("(bookmark-title, bookmark*)");
  93. }
  94. }
  95. /** {@inheritDoc} */
  96. protected void addChildNode(FONode obj) {
  97. if (obj instanceof BookmarkTitle) {
  98. bookmarkTitle = (BookmarkTitle)obj;
  99. } else if (obj instanceof Bookmark) {
  100. childBookmarks.add(obj);
  101. }
  102. }
  103. /** {@inheritDoc} */
  104. public CommonAccessibility getCommonAccessibility() {
  105. return commonAccessibility;
  106. }
  107. /**
  108. * Get the bookmark title for this bookmark
  109. *
  110. * @return the bookmark title string or an empty string if not found
  111. */
  112. public String getBookmarkTitle() {
  113. return bookmarkTitle == null ? "" : bookmarkTitle.getTitle();
  114. }
  115. /**
  116. * Returns the value of the internal-destination property.
  117. * @return the internal-destination
  118. */
  119. public String getInternalDestination() {
  120. return internalDestination;
  121. }
  122. /**
  123. * Returns the value of the external-destination property.
  124. * @return the external-destination
  125. */
  126. public String getExternalDestination() {
  127. return externalDestination;
  128. }
  129. /**
  130. * Determines if this fo:bookmark's subitems should be initially displayed
  131. * or hidden, based on the starting-state property set on this FO.
  132. *
  133. * @return true if this bookmark's starting-state is "show", false if "hide".
  134. */
  135. public boolean showChildItems() {
  136. return bShow;
  137. }
  138. /**
  139. * Get the child <code>Bookmark</code>s in an <code>java.util.ArrayList</code>.
  140. * @return an <code>ArrayList</code> containing the child Bookmarks
  141. */
  142. public ArrayList getChildBookmarks() {
  143. return childBookmarks;
  144. }
  145. /** {@inheritDoc} */
  146. public String getLocalName() {
  147. return "bookmark";
  148. }
  149. /**
  150. * {@inheritDoc}
  151. * @return {@link org.apache.fop.fo.Constants#FO_BOOKMARK}
  152. */
  153. public int getNameId() {
  154. return FO_BOOKMARK;
  155. }
  156. }