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.

ListBlock.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.datatypes.Length;
  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.BreakPropertySet;
  27. import org.apache.fop.fo.properties.CommonAccessibility;
  28. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  29. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  30. import org.apache.fop.fo.properties.CommonMarginBlock;
  31. import org.apache.fop.fo.properties.KeepProperty;
  32. /**
  33. * Class modelling the <a href=http://www.w3.org/TR/xsl/#fo_list-block">
  34. * <code>fo:list-block</code></a> object.
  35. */
  36. public class ListBlock extends FObj implements BreakPropertySet, CommonAccessibilityHolder {
  37. // The value of properties relevant for fo:list-block.
  38. private CommonAccessibility commonAccessibility;
  39. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  40. private CommonMarginBlock commonMarginBlock;
  41. private int breakAfter;
  42. private int breakBefore;
  43. private KeepProperty keepTogether;
  44. private KeepProperty keepWithNext;
  45. private KeepProperty keepWithPrevious;
  46. // Unused but valid items, commented out for performance:
  47. // private CommonAural commonAural;
  48. // private CommonRelativePosition commonRelativePosition;
  49. // private int intrusionDisplace;
  50. // private Length provisionalDistanceBetweenStarts;
  51. // private Length provisionalLabelSeparation;
  52. // End of property values
  53. /** extension properties */
  54. private Length widowContentLimit;
  55. private Length orphanContentLimit;
  56. // used for child node validation
  57. private boolean hasListItem;
  58. /**
  59. * Base constructor
  60. *
  61. * @param parent {@link FONode} that is the parent of this object
  62. */
  63. public ListBlock(FONode parent) {
  64. super(parent);
  65. }
  66. /** {@inheritDoc} */
  67. public void bind(PropertyList pList) throws FOPException {
  68. super.bind(pList);
  69. commonAccessibility = CommonAccessibility.getInstance(pList);
  70. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  71. commonMarginBlock = pList.getMarginBlockProps();
  72. breakAfter = pList.get(PR_BREAK_AFTER).getEnum();
  73. breakBefore = pList.get(PR_BREAK_BEFORE).getEnum();
  74. keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep();
  75. keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
  76. keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
  77. //Bind extension properties
  78. widowContentLimit = pList.get(PR_X_WIDOW_CONTENT_LIMIT).getLength();
  79. orphanContentLimit = pList.get(PR_X_ORPHAN_CONTENT_LIMIT).getLength();
  80. }
  81. /** {@inheritDoc} */
  82. public void startOfNode() throws FOPException {
  83. super.startOfNode();
  84. getFOEventHandler().startList(this);
  85. }
  86. /**
  87. * Make sure the content model is satisfied, if so then tell the
  88. * {@link org.apache.fop.fo.FOEventHandler} that we are at the end
  89. * of the list-block.
  90. * {@inheritDoc}
  91. */
  92. public void endOfNode() throws FOPException {
  93. if (!hasListItem) {
  94. missingChildElementError("marker* (list-item)+");
  95. }
  96. getFOEventHandler().endList(this);
  97. }
  98. /**
  99. * {@inheritDoc}
  100. * <br>XSL Content Model: marker* (list-item)+
  101. */
  102. protected void validateChildNode(Locator loc, String nsURI, String localName)
  103. throws ValidationException {
  104. if (FO_URI.equals(nsURI)) {
  105. if (localName.equals("marker")) {
  106. if (hasListItem) {
  107. nodesOutOfOrderError(loc, "fo:marker", "fo:list-item");
  108. }
  109. } else if (localName.equals("list-item")) {
  110. hasListItem = true;
  111. } else {
  112. invalidChildError(loc, nsURI, localName);
  113. }
  114. }
  115. }
  116. /** {@inheritDoc} */
  117. public CommonAccessibility getCommonAccessibility() {
  118. return commonAccessibility;
  119. }
  120. /** @return the {@link CommonMarginBlock} */
  121. public CommonMarginBlock getCommonMarginBlock() {
  122. return commonMarginBlock;
  123. }
  124. /** @return the {@link CommonBorderPaddingBackground} */
  125. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  126. return commonBorderPaddingBackground;
  127. }
  128. /** @return the "break-after" property */
  129. public int getBreakAfter() {
  130. return breakAfter;
  131. }
  132. /** @return the "break-before" property */
  133. public int getBreakBefore() {
  134. return breakBefore;
  135. }
  136. /** @return the "keep-with-next" property. */
  137. public KeepProperty getKeepWithNext() {
  138. return keepWithNext;
  139. }
  140. /** @return the "keep-with-previous" property. */
  141. public KeepProperty getKeepWithPrevious() {
  142. return keepWithPrevious;
  143. }
  144. /** @return the "keep-together" property. */
  145. public KeepProperty getKeepTogether() {
  146. return keepTogether;
  147. }
  148. /** @return the "fox:widow-content-limit" extension property */
  149. public Length getWidowContentLimit() {
  150. return widowContentLimit;
  151. }
  152. /** @return the "fox:orphan-content-limit" extension property */
  153. public Length getOrphanContentLimit() {
  154. return orphanContentLimit;
  155. }
  156. /** {@inheritDoc} */
  157. public String getLocalName() {
  158. return "list-block";
  159. }
  160. /**
  161. * {@inheritDoc}
  162. * @return {@link org.apache.fop.fo.Constants#FO_LIST_BLOCK}
  163. */
  164. public int getNameId() {
  165. return FO_LIST_BLOCK;
  166. }
  167. }