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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fo.pagination;
  18. // Java
  19. import java.util.ArrayList;
  20. // XML
  21. import org.xml.sax.Attributes;
  22. import org.xml.sax.Locator;
  23. // FOP
  24. import org.apache.fop.fo.FONode;
  25. import org.apache.fop.fo.FObj;
  26. import org.apache.fop.fo.FOTreeVisitor;
  27. import org.apache.fop.apps.FOPException;
  28. /**
  29. * Class modelling the fo:flow object. See Sec. 6.4.18 in the XSL-FO Standard.
  30. */
  31. public class Flow extends FObj {
  32. /**
  33. * PageSequence container
  34. */
  35. private PageSequence pageSequence;
  36. /**
  37. * ArrayList to store snapshot
  38. */
  39. private ArrayList markerSnapshot;
  40. /**
  41. * flow-name attribute
  42. */
  43. private String flowName;
  44. /**
  45. * Content-width of current column area during layout
  46. */
  47. private int contentWidth;
  48. /**
  49. * @param parent FONode that is the parent of this object
  50. */
  51. public Flow(FONode parent) {
  52. super(parent);
  53. }
  54. /**
  55. * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
  56. * XSL/FOP Content Model: markers* (%block;)+
  57. */
  58. /* temporarily disabled: need to account for fo-markers which may be initial children
  59. protected void validateChildNode(Locator loc, String nsURI, String localName) {
  60. if (!isBlockItem(nsURI, localName)) {
  61. invalidChildError(loc, nsURI, localName);
  62. }
  63. }
  64. */
  65. /**
  66. * Make sure content model satisfied, if so then tell the
  67. * StructureRenderer that we are at the end of the flow.
  68. * @see org.apache.fop.fo.FONode#end
  69. */
  70. protected void end() {
  71. if (children == null) {
  72. missingChildElementError("(%block;)+");
  73. }
  74. getFOInputHandler().endFlow(this);
  75. }
  76. /**
  77. * @see org.apache.fop.fo.FObj#addProperties
  78. */
  79. protected void addProperties(Attributes attlist) throws FOPException {
  80. super.addProperties(attlist);
  81. if (parent.getName().equals("fo:page-sequence")) {
  82. this.pageSequence = (PageSequence) parent;
  83. } else {
  84. throw new FOPException("flow must be child of "
  85. + "page-sequence, not " + parent.getName());
  86. }
  87. // according to communication from Paul Grosso (XSL-List,
  88. // 001228, Number 406), confusion in spec section 6.4.5 about
  89. // multiplicity of fo:flow in XSL 1.0 is cleared up - one (1)
  90. // fo:flow per fo:page-sequence only.
  91. /* if (pageSequence.isFlowSet()) {
  92. if (this.name.equals("fo:flow")) {
  93. throw new FOPException("Only a single fo:flow permitted"
  94. + " per fo:page-sequence");
  95. } else {
  96. throw new FOPException(this.name
  97. + " not allowed after fo:flow");
  98. }
  99. }
  100. */
  101. setFlowName(getProperty(PR_FLOW_NAME).getString());
  102. // Now done in addChild of page-sequence
  103. //pageSequence.addFlow(this);
  104. getFOInputHandler().startFlow(this);
  105. }
  106. /**
  107. * @param name the name of the flow to set
  108. * @throws FOPException for an empty name
  109. */
  110. protected void setFlowName(String name) throws FOPException {
  111. if (name == null || name.equals("")) {
  112. throw new FOPException("A 'flow-name' is required for "
  113. + getName());
  114. } else {
  115. flowName = name;
  116. }
  117. }
  118. /**
  119. * @return the name of this flow
  120. */
  121. public String getFlowName() {
  122. return flowName;
  123. }
  124. /**
  125. * @param contentWidth content width of this flow, in millipoints (??)
  126. */
  127. protected void setContentWidth(int contentWidth) {
  128. this.contentWidth = contentWidth;
  129. }
  130. /**
  131. * @return the content width of this flow (really of the region
  132. * in which it is flowing), in millipoints (??).
  133. */
  134. public int getContentWidth() {
  135. return this.contentWidth;
  136. }
  137. /**
  138. * @return true (Flow can generate reference areas)
  139. */
  140. public boolean generatesReferenceAreas() {
  141. return true;
  142. }
  143. /**
  144. * This is a hook for an FOTreeVisitor subclass to be able to access
  145. * this object.
  146. * @param fotv the FOTreeVisitor subclass that can access this object.
  147. * @see org.apache.fop.fo.FOTreeVisitor
  148. */
  149. public void acceptVisitor(FOTreeVisitor fotv) {
  150. fotv.serveFlow(this);
  151. }
  152. public String getName() {
  153. return "fo:flow";
  154. }
  155. }