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

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