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.

Flow.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.pagination;
  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.CommonAccessibility;
  26. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  27. /**
  28. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_flow">
  29. * <code>fo:flow</code></a> object.
  30. *
  31. */
  32. public class Flow extends FObj implements CommonAccessibilityHolder {
  33. /** The "flow-name" property name. */
  34. public static final String FLOW_NAME = "flow-name";
  35. private String flowName;
  36. private CommonAccessibility commonAccessibility;
  37. /** used for FO validation */
  38. private boolean blockItemFound = false;
  39. /**
  40. * Create a Flow instance that is a child of the given {@link FONode}.
  41. * @param parent the {@link FONode} that is the parent of this object
  42. */
  43. public Flow(FONode parent) {
  44. super(parent);
  45. }
  46. /** {@inheritDoc} */
  47. public void bind(PropertyList pList) throws FOPException {
  48. super.bind(pList);
  49. flowName = pList.get(PR_FLOW_NAME).getString();
  50. commonAccessibility = CommonAccessibility.getInstance(pList);
  51. }
  52. /** {@inheritDoc} */
  53. protected void startOfNode() throws FOPException {
  54. if (flowName == null || flowName.equals("")) {
  55. missingPropertyError(FLOW_NAME);
  56. }
  57. // according to communication from Paul Grosso (XSL-List,
  58. // 001228, Number 406), confusion in spec section 6.4.5 about
  59. // multiplicity of fo:flow in XSL 1.0 is cleared up - one (1)
  60. // fo:flow per fo:page-sequence only.
  61. /* if (pageSequence.isFlowSet()) {
  62. if (this.name.equals("fo:flow")) {
  63. throw new FOPException("Only a single fo:flow permitted"
  64. + " per fo:page-sequence");
  65. } else {
  66. throw new FOPException(this.name
  67. + " not allowed after fo:flow");
  68. }
  69. }
  70. */
  71. // Now done in addChild of page-sequence
  72. //pageSequence.addFlow(this);
  73. getFOEventHandler().startFlow(this);
  74. }
  75. /** {@inheritDoc} */
  76. protected void endOfNode() throws FOPException {
  77. if (!blockItemFound) {
  78. missingChildElementError("marker* (%block;)+");
  79. }
  80. getFOEventHandler().endFlow(this);
  81. }
  82. /**
  83. * {@inheritDoc}
  84. * <br>XSL Content Model: marker* (%block;)+
  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 (blockItemFound) {
  91. nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
  92. }
  93. } else if (!isBlockItem(nsURI, localName)) {
  94. invalidChildError(loc, nsURI, localName);
  95. } else {
  96. blockItemFound = true;
  97. }
  98. }
  99. }
  100. /**
  101. * {@inheritDoc}
  102. * @return true (Flow can generate reference areas)
  103. */
  104. public boolean generatesReferenceAreas() {
  105. return true;
  106. }
  107. /** @return "flow-name" property. */
  108. public String getFlowName() {
  109. return flowName;
  110. }
  111. public CommonAccessibility getCommonAccessibility() {
  112. return commonAccessibility;
  113. }
  114. /** {@inheritDoc} */
  115. public String getLocalName() {
  116. return "flow";
  117. }
  118. /**
  119. * {@inheritDoc}
  120. * @return {@link org.apache.fop.fo.Constants#FO_FLOW}
  121. */
  122. public int getNameId() {
  123. return FO_FLOW;
  124. }
  125. }