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.

AbstractAFPExtensionObject.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.render.afp.extensions;
  19. // FOP
  20. import org.apache.fop.apps.FOPException;
  21. import org.apache.fop.fo.FONode;
  22. import org.apache.fop.fo.PropertyList;
  23. import org.apache.fop.fo.ValidationException;
  24. import org.apache.fop.fo.extensions.ExtensionAttachment;
  25. import org.xml.sax.Attributes;
  26. import org.xml.sax.Locator;
  27. /**
  28. * Base class for the AFP-specific extension elements.
  29. */
  30. public abstract class AbstractAFPExtensionObject extends FONode {
  31. /**
  32. * AFP setup code
  33. */
  34. private AFPPageSetup setupCode;
  35. private String name;
  36. /**
  37. * @see org.apache.fop.fo.FONode#FONode(FONode)
  38. * @param parent the parent formatting object
  39. * @param name the name of the afp element
  40. */
  41. public AbstractAFPExtensionObject(FONode parent, String name) {
  42. super(parent);
  43. this.name = name;
  44. this.setupCode = new AFPPageSetup(name);
  45. }
  46. /** {@inheritDoc} */
  47. protected void validateChildNode(Locator loc, String nsURI, String localName)
  48. throws ValidationException {
  49. if (FO_URI.equals(nsURI)) {
  50. invalidChildError(loc, nsURI, localName);
  51. }
  52. }
  53. /** {@inheritDoc} */
  54. protected void addCharacters(char[] data, int start, int end,
  55. PropertyList pList, Locator locator) {
  56. setupCode.setContent(new String(data, start, end - start));
  57. }
  58. /** {@inheritDoc} */
  59. public String getNamespaceURI() {
  60. return AFPElementMapping.NAMESPACE;
  61. }
  62. /** {@inheritDoc} */
  63. public String getNormalNamespacePrefix() {
  64. return AFPElementMapping.NAMESPACE_PREFIX;
  65. }
  66. /** {@inheritDoc} */
  67. public void processNode(String elementName, Locator locator,
  68. Attributes attlist, PropertyList propertyList)
  69. throws FOPException {
  70. String name = attlist.getValue("name");
  71. if (name != null && name.length() > 0) {
  72. setupCode.setName(name);
  73. } else {
  74. throw new FOPException(elementName + " must have a name attribute.");
  75. }
  76. if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(elementName)) {
  77. name = attlist.getValue("src");
  78. if (name != null && name.length() > 0) {
  79. setupCode.setValue(name);
  80. } else {
  81. throw new FOPException(elementName + " must have a src attribute.");
  82. }
  83. } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(elementName)) {
  84. name = attlist.getValue("value");
  85. if (name != null && name.length() > 0) {
  86. setupCode.setValue(name);
  87. } else {
  88. throw new FOPException(elementName + " must have a value attribute.");
  89. }
  90. }
  91. }
  92. /** {@inheritDoc} */
  93. protected void endOfNode() throws FOPException {
  94. super.endOfNode();
  95. }
  96. /** {@inheritDoc} */
  97. public ExtensionAttachment getExtensionAttachment() {
  98. return this.setupCode;
  99. }
  100. /** {@inheritDoc} */
  101. public String getLocalName() {
  102. return name;
  103. }
  104. }