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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 String altText;
  48. // private ToBeImplementedProperty targetProcessingContext;
  49. // private ToBeImplementedProperty targetPresentationContext;
  50. // private ToBeImplementedProperty targetStylesheet;
  51. // Unused but valid items, commented out for performance:
  52. // private int dominantBaseline;
  53. // End of property values
  54. // used only for FO validation
  55. private boolean blockOrInlineItemFound;
  56. /**
  57. * Construct a BasicLink instance with the given {@link FONode}
  58. * as its parent.
  59. *
  60. * @param parent {@link FONode} that is the parent of this object
  61. */
  62. public BasicLink(FONode parent) {
  63. super(parent);
  64. }
  65. /** {@inheritDoc} */
  66. public void bind(PropertyList pList) throws FOPException {
  67. super.bind(pList);
  68. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  69. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  70. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  71. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  72. // destinationPlacementOffset = pList.get(PR_DESTINATION_PLACEMENT_OFFSET);
  73. externalDestination = pList.get(PR_EXTERNAL_DESTINATION).getString();
  74. // indicateDestination = pList.get(PR_INDICATE_DESTINATION);
  75. internalDestination = pList.get(PR_INTERNAL_DESTINATION).getString();
  76. showDestination = pList.get(PR_SHOW_DESTINATION).getEnum();
  77. // targetProcessingContext = pList.get(PR_TARGET_PROCESSING_CONTEXT);
  78. // targetPresentationContext = pList.get(PR_TARGET_PRESENTATION_CONTEXT);
  79. // targetStylesheet = pList.get(PR_TARGET_STYLESHEET);
  80. // per spec, internal takes precedence if both specified
  81. if (internalDestination.length() > 0) {
  82. externalDestination = null;
  83. } else if (externalDestination.length() == 0) {
  84. // slightly stronger than spec "should be specified"
  85. getFOValidationEventProducer().missingLinkDestination(this, getName(), locator);
  86. }
  87. if (getUserAgent().isAccessibilityEnabled()) {
  88. altText = pList.get(PR_X_ALT_TEXT).getString();
  89. if (altText.equals("") && getUserAgent().isPdfUAEnabled()) {
  90. getFOValidationEventProducer().altTextMissing(this, getLocalName(), getLocator());
  91. }
  92. }
  93. }
  94. /** {@inheritDoc} */
  95. public void startOfNode() throws FOPException {
  96. super.startOfNode();
  97. getFOEventHandler().startLink(this);
  98. }
  99. /** {@inheritDoc} */
  100. public void endOfNode() throws FOPException {
  101. super.endOfNode();
  102. getFOEventHandler().endLink(this);
  103. }
  104. /** {@inheritDoc} */
  105. protected void validateChildNode(Locator loc, String nsURI, String localName)
  106. throws ValidationException {
  107. if (FO_URI.equals(nsURI)) {
  108. if (localName.equals("marker")) {
  109. if (blockOrInlineItemFound) {
  110. nodesOutOfOrderError(loc, "fo:marker", "(#PCDATA|%inline;|%block;)");
  111. }
  112. } else if (!isBlockOrInlineItem(nsURI, localName)) {
  113. invalidChildError(loc, nsURI, localName);
  114. } else {
  115. blockOrInlineItemFound = true;
  116. }
  117. }
  118. }
  119. /** @return the "alignment-adjust" property */
  120. public Length getAlignmentAdjust() {
  121. return alignmentAdjust;
  122. }
  123. /** @return the "alignment-baseline" property */
  124. public int getAlignmentBaseline() {
  125. return alignmentBaseline;
  126. }
  127. /** @return the "baseline-shift" property */
  128. public Length getBaselineShift() {
  129. return baselineShift;
  130. }
  131. /** @return the "dominant-baseline" property */
  132. public int getDominantBaseline() {
  133. return dominantBaseline;
  134. }
  135. @Override
  136. public void setStructureTreeElement(StructureTreeElement structureTreeElement) {
  137. this.structureTreeElement = structureTreeElement;
  138. }
  139. @Override
  140. public StructureTreeElement getStructureTreeElement() {
  141. return structureTreeElement;
  142. }
  143. /**
  144. * Get the value of the <code>internal-destination</code> property.
  145. *
  146. * @return the "internal-destination" property
  147. */
  148. public String getInternalDestination() {
  149. return internalDestination;
  150. }
  151. /**
  152. * Get the value of the <code>external-destination</code> property.
  153. *
  154. * @return the "external-destination" property
  155. */
  156. public String getExternalDestination() {
  157. return externalDestination;
  158. }
  159. /**
  160. * Convenience method to check if this instance has an internal destination.
  161. *
  162. * @return <code>true</code> if this basic link has an internal destination;
  163. * <code>false</code> otherwise
  164. */
  165. public boolean hasInternalDestination() {
  166. return internalDestination != null && internalDestination.length() > 0;
  167. }
  168. /**
  169. * Convenience method to check if this instance has an external destination
  170. *
  171. * @return <code>true</code> if this basic link has an external destination;
  172. * <code>false</code> otherwise
  173. */
  174. public boolean hasExternalDestination() {
  175. return externalDestination != null && externalDestination.length() > 0;
  176. }
  177. /**
  178. * Get the value of the <code>show-destination</code> property.
  179. *
  180. * @return the "show-destination" property
  181. */
  182. public int getShowDestination() {
  183. return this.showDestination;
  184. }
  185. /** {@inheritDoc} */
  186. public String getLocalName() {
  187. return "basic-link";
  188. }
  189. /**
  190. * {@inheritDoc}
  191. * @return {@link org.apache.fop.fo.Constants#FO_BASIC_LINK}
  192. */
  193. public int getNameId() {
  194. return FO_BASIC_LINK;
  195. }
  196. public String getAltText() {
  197. return altText;
  198. }
  199. }