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.

FONode.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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;
  18. // Java
  19. import java.util.ListIterator;
  20. // XML
  21. import org.xml.sax.Attributes;
  22. import org.xml.sax.Locator;
  23. // Avalon
  24. import org.apache.avalon.framework.logger.Logger;
  25. // FOP
  26. import org.apache.fop.apps.FOPException;
  27. import org.apache.fop.util.CharUtilities;
  28. import org.apache.fop.apps.FOUserAgent;
  29. /**
  30. * base class for nodes in the XML tree
  31. *
  32. */
  33. public abstract class FONode {
  34. /** Parent FO node */
  35. protected FONode parent;
  36. /** Name of the node */
  37. protected String name;
  38. /**
  39. * Main constructor.
  40. * @param parent parent of this node
  41. */
  42. protected FONode(FONode parent) {
  43. this.parent = parent;
  44. }
  45. /**
  46. * Sets the name of the node.
  47. * @param str the name
  48. */
  49. public void setName(String str) {
  50. name = str;
  51. }
  52. /**
  53. * Sets the name of the node.
  54. * @param str the name
  55. */
  56. public void setLocation(Locator locator) {
  57. // do nothing by default
  58. }
  59. /**
  60. * Returns the logger for the node.
  61. * @return the logger
  62. */
  63. public Logger getLogger() {
  64. return getFOTreeControl().getLogger();
  65. }
  66. /**
  67. * Returns the user agent for the node.
  68. * @return FOUserAgent
  69. */
  70. public FOUserAgent getUserAgent() {
  71. return getFOTreeControl().getUserAgent();
  72. }
  73. /**
  74. * Do something with the attributes for this element
  75. * @param attlist Collection of attributes passed to us from the parser.
  76. * @throws FOPException for errors or inconsistencies in the attributes
  77. */
  78. public void handleAttrs(Attributes attlist) throws FOPException {
  79. }
  80. /**
  81. * Returns the name of the object
  82. * @return the name of this object
  83. */
  84. public String getName() {
  85. return this.name;
  86. }
  87. /**
  88. * Adds characters (does nothing here)
  89. * @param data text
  90. * @param start start position
  91. * @param length length of the text
  92. * @param locator location in fo source file.
  93. */
  94. protected void addCharacters(char data[], int start, int length,
  95. Locator locator) {
  96. // ignore
  97. }
  98. /**
  99. *
  100. */
  101. protected void start() {
  102. // do nothing by default
  103. }
  104. /**
  105. *
  106. */
  107. protected void end() {
  108. // do nothing by default
  109. }
  110. /**
  111. * @param child child node to be added to the children of this node
  112. */
  113. protected void addChild(FONode child) {
  114. }
  115. /**
  116. * @return the parent node of this node
  117. */
  118. public FONode getParent() {
  119. return this.parent;
  120. }
  121. /**
  122. * Return an iterator over all the children of this FObj.
  123. * @return A ListIterator.
  124. */
  125. public ListIterator getChildren() {
  126. return null;
  127. }
  128. /**
  129. * Return an iterator over the object's children starting
  130. * at the pased node.
  131. * @param childNode First node in the iterator
  132. * @return A ListIterator or null if childNode isn't a child of
  133. * this FObj.
  134. */
  135. public ListIterator getChildren(FONode childNode) {
  136. return null;
  137. }
  138. /**
  139. * @return an iterator for the characters in this node
  140. */
  141. public CharIterator charIterator() {
  142. return new OneCharIterator(CharUtilities.CODE_EOT);
  143. }
  144. /**
  145. * This is a quick check to see if it is a marker.
  146. * This is needed since there is no other quick way of checking
  147. * for a marker and not adding to the child list.
  148. *
  149. * @return true if this is a marker
  150. */
  151. protected boolean isMarker() {
  152. return false;
  153. }
  154. /**
  155. * Recursively goes up the FOTree hierarchy until the FONode is found,
  156. * which returns the parent Document.
  157. * @return the Document object that is the parent of this node.
  158. */
  159. public FOTreeControl getFOTreeControl() {
  160. return parent.getFOTreeControl();
  161. }
  162. /**
  163. * This is a hook for an FOTreeVisitor subclass to be able to access
  164. * this object.
  165. * @param fotv the FOTreeVisitor subclass that can access this object.
  166. * @see org.apache.fop.fo.FOTreeVisitor
  167. */
  168. public void acceptVisitor(FOTreeVisitor fotv) {
  169. fotv.serveFONode(this);
  170. }
  171. }