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

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