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

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