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

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