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.

BasicLink.java 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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.flow;
  19. import org.xml.sax.Locator;
  20. import org.apache.fop.accessibility.StructureTreeElement;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.datatypes.Length;
  23. import org.apache.fop.fo.FONode;
  24. import org.apache.fop.fo.PropertyList;
  25. import org.apache.fop.fo.ValidationException;
  26. import org.apache.fop.fo.properties.StructureTreeElementHolder;
  27. /**
  28. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_basic-link">
  29. * <code>fo:basic-link</code></a> object.
  30. *
  31. * This class contains the logic to determine the link represented by this FO,
  32. * and whether that link is external (uses a URI) or internal (an id
  33. * reference).
  34. */
  35. public class BasicLink extends InlineLevel implements StructureTreeElementHolder {
  36. // The value of properties relevant for fo:basic-link.
  37. private Length alignmentAdjust;
  38. private int alignmentBaseline;
  39. private Length baselineShift;
  40. private int dominantBaseline;
  41. private StructureTreeElement structureTreeElement;
  42. // private ToBeImplementedProperty destinationPlacementOffset;
  43. private String externalDestination;
  44. // private ToBeImplementedProperty indicateDestination;
  45. private String internalDestination;
  46. private int showDestination;
  47. // private ToBeImplementedProperty targetProcessingContext;
  48. // private ToBeImplementedProperty targetPresentationContext;
  49. // private ToBeImplementedProperty targetStylesheet;
  50. // Unused but valid items, commented out for performance:
  51. // private int dominantBaseline;
  52. // End of property values
  53. // used only for FO validation
  54. private boolean blockOrInlineItemFound;
  55. /**
  56. * Construct a BasicLink instance with the given {@link FONode}
  57. * as its parent.
  58. *
  59. * @param parent {@link FONode} that is the parent of this object
  60. */
  61. public BasicLink(FONode parent) {
  62. super(parent);
  63. }
  64. /** {@inheritDoc} */
  65. public void bind(PropertyList pList) throws FOPException {
  66. super.bind(pList);
  67. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  68. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  69. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  70. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  71. // destinationPlacementOffset = pList.get(PR_DESTINATION_PLACEMENT_OFFSET);
  72. externalDestination = pList.get(PR_EXTERNAL_DESTINATION).getString();
  73. // indicateDestination = pList.get(PR_INDICATE_DESTINATION);
  74. internalDestination = pList.get(PR_INTERNAL_DESTINATION).getString();
  75. showDestination = pList.get(PR_SHOW_DESTINATION).getEnum();
  76. // targetProcessingContext = pList.get(PR_TARGET_PROCESSING_CONTEXT);
  77. // targetPresentationContext = pList.get(PR_TARGET_PRESENTATION_CONTEXT);
  78. // targetStylesheet = pList.get(PR_TARGET_STYLESHEET);
  79. // per spec, internal takes precedence if both specified
  80. if (internalDestination.length() > 0) {
  81. externalDestination = null;
  82. } else if (externalDestination.length() == 0) {
  83. // slightly stronger than spec "should be specified"
  84. getFOValidationEventProducer().missingLinkDestination(this, getName(), locator);
  85. }
  86. }
  87. /** {@inheritDoc} */
  88. public void startOfNode() throws FOPException {
  89. super.startOfNode();
  90. getFOEventHandler().startLink(this);
  91. }
  92. /** {@inheritDoc} */
  93. public void endOfNode() throws FOPException {
  94. super.endOfNode();
  95. getFOEventHandler().endLink(this);
  96. }
  97. /** {@inheritDoc} */
  98. protected void validateChildNode(Locator loc, String nsURI, String localName)
  99. throws ValidationException {
  100. if (FO_URI.equals(nsURI)) {
  101. if (localName.equals("marker")) {
  102. if (blockOrInlineItemFound) {
  103. nodesOutOfOrderError(loc, "fo:marker", "(#PCDATA|%inline;|%block;)");
  104. }
  105. } else if (!isBlockOrInlineItem(nsURI, localName)) {
  106. invalidChildError(loc, nsURI, localName);
  107. } else {
  108. blockOrInlineItemFound = true;
  109. }
  110. }
  111. }
  112. /** @return the "alignment-adjust" property */
  113. public Length getAlignmentAdjust() {
  114. return alignmentAdjust;
  115. }
  116. /** @return the "alignment-baseline" property */
  117. public int getAlignmentBaseline() {
  118. return alignmentBaseline;
  119. }
  120. /** @return the "baseline-shift" property */
  121. public Length getBaselineShift() {
  122. return baselineShift;
  123. }
  124. /** @return the "dominant-baseline" property */
  125. public int getDominantBaseline() {
  126. return dominantBaseline;
  127. }
  128. @Override
  129. public void setStructureTreeElement(StructureTreeElement structureTreeElement) {
  130. this.structureTreeElement = structureTreeElement;
  131. }
  132. @Override
  133. public StructureTreeElement getStructureTreeElement() {
  134. return structureTreeElement;
  135. }
  136. /**
  137. * Get the value of the <code>internal-destination</code> property.
  138. *
  139. * @return the "internal-destination" property
  140. */
  141. public String getInternalDestination() {
  142. return internalDestination;
  143. }
  144. /**
  145. * Get the value of the <code>external-destination</code> property.
  146. *
  147. * @return the "external-destination" property
  148. */
  149. public String getExternalDestination() {
  150. return externalDestination;
  151. }
  152. /**
  153. * Convenience method to check if this instance has an internal destination.
  154. *
  155. * @return <code>true</code> if this basic link has an internal destination;
  156. * <code>false</code> otherwise
  157. */
  158. public boolean hasInternalDestination() {
  159. return internalDestination != null && internalDestination.length() > 0;
  160. }
  161. /**
  162. * Convenience method to check if this instance has an external destination
  163. *
  164. * @return <code>true</code> if this basic link has an external destination;
  165. * <code>false</code> otherwise
  166. */
  167. public boolean hasExternalDestination() {
  168. return externalDestination != null && externalDestination.length() > 0;
  169. }
  170. /**
  171. * Get the value of the <code>show-destination</code> property.
  172. *
  173. * @return the "show-destination" property
  174. */
  175. public int getShowDestination() {
  176. return this.showDestination;
  177. }
  178. /** {@inheritDoc} */
  179. public String getLocalName() {
  180. return "basic-link";
  181. }
  182. /**
  183. * {@inheritDoc}
  184. * @return {@link org.apache.fop.fo.Constants#FO_BASIC_LINK}
  185. */
  186. public int getNameId() {
  187. return FO_BASIC_LINK;
  188. }
  189. }