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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.FONode;
  22. import org.apache.fop.fo.FObjMixed;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.ValidationException;
  25. /**
  26. * Class modelling the fo:wrapper object.
  27. * The wrapper object serves as a property holder for
  28. * its child node objects.
  29. */
  30. public class Wrapper extends FObjMixed {
  31. // The value of properties relevant for fo:wrapper.
  32. // End of property values
  33. // used for FO validation
  34. private boolean blockOrInlineItemFound = false;
  35. private boolean inlineChildrenAllowed = false;
  36. /**
  37. * @param parent FONode that is the parent of this object
  38. */
  39. public Wrapper(FONode parent) {
  40. super(parent);
  41. /* Check if the fo:wrapper is a child of a FO that allows mixed content
  42. * (or a descendant in nested fo:wrapper sequence, the first of which
  43. * is a child of a FO that allows mixed content) */
  44. FONode ancestor = this.parent;
  45. while (ancestor instanceof Wrapper) {
  46. ancestor = ancestor.getParent();
  47. }
  48. if (ancestor instanceof FObjMixed ) {
  49. inlineChildrenAllowed = true;
  50. }
  51. }
  52. /**
  53. * {@inheritDoc}
  54. * <br>XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
  55. * <br><i>Additionally (unimplemented): "An fo:wrapper that is a child of an
  56. * fo:multi-properties is only permitted to have children that would
  57. * be permitted in place of the fo:multi-properties."</i>
  58. *
  59. */
  60. protected void validateChildNode(Locator loc, String nsURI, String localName)
  61. throws ValidationException {
  62. if (FO_URI.equals(nsURI)) {
  63. if ("marker".equals(localName)) {
  64. if (blockOrInlineItemFound) {
  65. nodesOutOfOrderError(loc, "fo:marker",
  66. "(#PCDATA|%inline;|%block;)");
  67. }
  68. } else if (isBlockOrInlineItem(nsURI, localName)) {
  69. //delegate validation to parent
  70. FONode.validateChildNode(this.parent, loc, nsURI, localName);
  71. blockOrInlineItemFound = true;
  72. } else {
  73. invalidChildError(loc, nsURI, localName);
  74. }
  75. }
  76. }
  77. /** {@inheritDoc} */
  78. protected void addCharacters(
  79. char[] data,
  80. int start,
  81. int end,
  82. PropertyList pList,
  83. Locator locator) throws FOPException {
  84. /* Only add text if the fo:wrapper's parent allows inline children */
  85. if (this.inlineChildrenAllowed) {
  86. super.addCharacters(data, start, end, pList, locator);
  87. }
  88. }
  89. /** {@inheritDoc} */
  90. public String getLocalName() {
  91. return "wrapper";
  92. }
  93. /** {@inheritDoc} */
  94. public int getNameId() {
  95. return FO_WRAPPER;
  96. }
  97. }