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.

Wrapper.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.Constants;
  22. import org.apache.fop.fo.FONode;
  23. import org.apache.fop.fo.FOText;
  24. import org.apache.fop.fo.FObjMixed;
  25. import org.apache.fop.fo.ValidationException;
  26. /**
  27. * Class modelling the <a href=http://www.w3.org/TR/xsl/#fo_wrapper">
  28. * <code>fo:wrapper</code></a> object.
  29. * The <code>fo:wrapper</code> object serves as a property holder for
  30. * its child node objects.
  31. */
  32. public class Wrapper extends FObjMixed {
  33. // The value of properties relevant for fo:wrapper.
  34. // End of property values
  35. // used for FO validation
  36. private boolean blockOrInlineItemFound = false;
  37. /**
  38. * Create a Wrapper instance that is a child of the
  39. * given {@link FONode}
  40. *
  41. * @param parent {@link FONode} that is the parent of this object
  42. */
  43. public Wrapper(FONode parent) {
  44. super(parent);
  45. }
  46. @Override
  47. protected void startOfNode() throws FOPException {
  48. super.startOfNode();
  49. getFOEventHandler().startWrapper(this);
  50. }
  51. @Override
  52. protected void endOfNode() throws FOPException {
  53. super.endOfNode();
  54. getFOEventHandler().endWrapper(this);
  55. }
  56. /**
  57. * {@inheritDoc}
  58. * <br>XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
  59. * <br><i>Additionally (unimplemented): "An fo:wrapper that is a child of an
  60. * fo:multi-properties is only permitted to have children that would
  61. * be permitted in place of the fo:multi-properties."</i>
  62. */
  63. protected void validateChildNode(Locator loc, String nsURI, String localName)
  64. throws ValidationException {
  65. if (FO_URI.equals(nsURI)) {
  66. if ("marker".equals(localName)) {
  67. if (blockOrInlineItemFound) {
  68. nodesOutOfOrderError(loc, "fo:marker",
  69. "(#PCDATA|%inline;|%block;)");
  70. }
  71. } else if (isBlockOrInlineItem(nsURI, localName)) {
  72. /* delegate validation to parent, but keep the error reporting
  73. * tidy. If we would simply call validateChildNode() on the
  74. * parent, the user would get a wrong impression, as only the
  75. * locator (if any) will contain a reference to the offending
  76. * fo:wrapper.
  77. */
  78. try {
  79. FONode.validateChildNode(this.parent, loc, nsURI, localName);
  80. } catch (ValidationException vex) {
  81. invalidChildError(loc, getName(), FO_URI, localName,
  82. "rule.wrapperInvalidChildForParent");
  83. }
  84. blockOrInlineItemFound = true;
  85. } else {
  86. invalidChildError(loc, nsURI, localName);
  87. }
  88. }
  89. }
  90. /** {@inheritDoc} */
  91. protected void addChildNode(FONode child) throws FOPException {
  92. super.addChildNode(child);
  93. /* If the child is a text node, and it generates areas
  94. * (i.e. contains either non-white-space or preserved
  95. * white-space), then check whether the nearest non-wrapper
  96. * ancestor allows this.
  97. */
  98. if (child instanceof FOText
  99. && ((FOText)child).willCreateArea()) {
  100. FONode ancestor = parent;
  101. while (ancestor.getNameId() == Constants.FO_WRAPPER) {
  102. ancestor = ancestor.getParent();
  103. }
  104. if (!(ancestor instanceof FObjMixed)) {
  105. invalidChildError(
  106. getLocator(),
  107. getLocalName(),
  108. FONode.FO_URI,
  109. "#PCDATA",
  110. "rule.wrapperInvalidChildForParent");
  111. }
  112. }
  113. }
  114. /** {@inheritDoc} */
  115. public String getLocalName() {
  116. return "wrapper";
  117. }
  118. /**
  119. * {@inheritDoc}
  120. * @return {@link org.apache.fop.fo.Constants#FO_WRAPPER}
  121. */
  122. public int getNameId() {
  123. return FO_WRAPPER;
  124. }
  125. }