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.

ListItem.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 java.util.Stack;
  20. import org.xml.sax.Locator;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.complexscripts.bidi.DelimitedTextRange;
  23. import org.apache.fop.fo.FONode;
  24. import org.apache.fop.fo.FObj;
  25. import org.apache.fop.fo.PropertyList;
  26. import org.apache.fop.fo.ValidationException;
  27. import org.apache.fop.fo.properties.BreakPropertySet;
  28. import org.apache.fop.fo.properties.CommonAccessibility;
  29. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  30. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  31. import org.apache.fop.fo.properties.CommonMarginBlock;
  32. import org.apache.fop.fo.properties.KeepProperty;
  33. /**
  34. * Class modelling the <a href=http://www.w3.org/TR/xsl/#fo_list-item">
  35. * <code>fo:list-item</code></a> object.
  36. */
  37. public class ListItem extends FObj implements BreakPropertySet, CommonAccessibilityHolder {
  38. // The value of properties relevant for fo:list-item.
  39. private CommonAccessibility commonAccessibility;
  40. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  41. private CommonMarginBlock commonMarginBlock;
  42. private int breakAfter;
  43. private int breakBefore;
  44. private KeepProperty keepTogether;
  45. private KeepProperty keepWithNext;
  46. private KeepProperty keepWithPrevious;
  47. // Unused but valid items, commented out for performance:
  48. // private CommonAural commonAural;
  49. // private CommonRelativePosition commonRelativePosition;
  50. // private int intrusionDisplace;
  51. // private int relativeAlign;
  52. // End of property values
  53. private ListItemLabel label;
  54. private ListItemBody body;
  55. /**
  56. * Base constructor
  57. *
  58. * @param parent {@link FONode} that is the parent of this object
  59. */
  60. public ListItem(FONode parent) {
  61. super(parent);
  62. }
  63. /** {@inheritDoc} */
  64. public void bind(PropertyList pList) throws FOPException {
  65. super.bind(pList);
  66. commonAccessibility = CommonAccessibility.getInstance(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. }
  75. /** {@inheritDoc} */
  76. public void startOfNode() throws FOPException {
  77. super.startOfNode();
  78. getFOEventHandler().startListItem(this);
  79. }
  80. /** {@inheritDoc} */
  81. public void endOfNode() throws FOPException {
  82. if (label == null || body == null) {
  83. missingChildElementError("marker* (list-item-label,list-item-body)");
  84. }
  85. getFOEventHandler().endListItem(this);
  86. }
  87. /**
  88. * {@inheritDoc}
  89. * <br>XSL Content Model: marker* (list-item-label,list-item-body)
  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 (label != null) {
  96. nodesOutOfOrderError(loc, "fo:marker", "fo:list-item-label");
  97. }
  98. } else if (localName.equals("list-item-label")) {
  99. if (label != null) {
  100. tooManyNodesError(loc, "fo:list-item-label");
  101. }
  102. } else if (localName.equals("list-item-body")) {
  103. if (label == null) {
  104. nodesOutOfOrderError(loc, "fo:list-item-label", "fo:list-item-body");
  105. } else if (body != null) {
  106. tooManyNodesError(loc, "fo:list-item-body");
  107. }
  108. } else {
  109. invalidChildError(loc, nsURI, localName);
  110. }
  111. }
  112. }
  113. /**
  114. * {@inheritDoc}
  115. * TODO see if can/should rely on base class for this
  116. * (i.e., add to childNodes instead)
  117. */
  118. public void addChildNode(FONode child) {
  119. int nameId = child.getNameId();
  120. if (nameId == FO_LIST_ITEM_LABEL) {
  121. label = (ListItemLabel) child;
  122. } else if (nameId == FO_LIST_ITEM_BODY) {
  123. body = (ListItemBody) child;
  124. } else if (nameId == FO_MARKER) {
  125. addMarker((Marker) child);
  126. }
  127. }
  128. /** {@inheritDoc} */
  129. public CommonAccessibility getCommonAccessibility() {
  130. return commonAccessibility;
  131. }
  132. /** @return the {@link CommonMarginBlock} */
  133. public CommonMarginBlock getCommonMarginBlock() {
  134. return commonMarginBlock;
  135. }
  136. /** @return the {@link CommonBorderPaddingBackground} */
  137. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  138. return commonBorderPaddingBackground;
  139. }
  140. /** @return the "break-after" property */
  141. public int getBreakAfter() {
  142. return breakAfter;
  143. }
  144. /** @return the "break-before" property */
  145. public int getBreakBefore() {
  146. return breakBefore;
  147. }
  148. /** @return the "keep-with-next" property */
  149. public KeepProperty getKeepWithNext() {
  150. return keepWithNext;
  151. }
  152. /** @return the "keep-with-previous" property */
  153. public KeepProperty getKeepWithPrevious() {
  154. return keepWithPrevious;
  155. }
  156. /** @return the "keep-together" property */
  157. public KeepProperty getKeepTogether() {
  158. return keepTogether;
  159. }
  160. /** @return the label of the list item */
  161. public ListItemLabel getLabel() {
  162. return label;
  163. }
  164. /**
  165. * @return the body of the list item
  166. */
  167. public ListItemBody getBody() {
  168. return body;
  169. }
  170. /** {@inheritDoc} */
  171. public String getLocalName() {
  172. return "list-item";
  173. }
  174. /**
  175. * {@inheritDoc}
  176. * @return {@link org.apache.fop.fo.Constants#FO_LIST_ITEM}
  177. */
  178. public int getNameId() {
  179. return FO_LIST_ITEM;
  180. }
  181. @Override
  182. protected Stack<DelimitedTextRange> collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges,
  183. DelimitedTextRange currentRange) {
  184. ListItemLabel label = getLabel();
  185. if (label != null) {
  186. ranges = label.collectDelimitedTextRanges(ranges);
  187. }
  188. ListItemBody body = getBody();
  189. if (body != null) {
  190. ranges = body.collectDelimitedTextRanges(ranges);
  191. }
  192. return ranges;
  193. }
  194. }