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

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