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.

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