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

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