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.

AbstractPSExtensionElement.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.ps.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.Locator;
  26. /**
  27. * Base class for the PostScript-specific extension elements.
  28. */
  29. public abstract class AbstractPSExtensionElement extends FONode {
  30. /**
  31. * extension attachment
  32. */
  33. protected PSExtensionAttachment attachment;
  34. /**
  35. * Default constructor
  36. *
  37. * @param parent parent of this node
  38. * @see org.apache.fop.fo.FONode#FONode(FONode)
  39. */
  40. public AbstractPSExtensionElement(FONode parent) {
  41. super(parent);
  42. }
  43. /**
  44. * Blocks XSL FO's from having non-FO parents.
  45. *
  46. * @param loc location in the FO source file
  47. * @param nsURI namespace of incoming node
  48. * @param localName (e.g. "table" for "fo:table")
  49. * @throws ValidationException if incoming node not valid for parent
  50. * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
  51. */
  52. protected void validateChildNode(Locator loc, String nsURI, String localName)
  53. throws ValidationException {
  54. if (FO_URI.equals(nsURI)) {
  55. invalidChildError(loc, nsURI, localName);
  56. }
  57. }
  58. /**
  59. * Adds characters (does nothing here)
  60. * @param data array of characters containing text to be added
  61. * @param start starting array element to add
  62. * @param length of data array to add
  63. * @param pList currently applicable PropertyList
  64. * @param locator location in fo source file.
  65. * @see org.apache.fop.fo.FONode#addCharacters(char[], int, int, PropertyList, Locator)
  66. */
  67. protected void addCharacters(char[] data, int start, int length,
  68. PropertyList pList, Locator locator) {
  69. PSExtensionAttachment a = (PSExtensionAttachment)getExtensionAttachment();
  70. if (a.getContent() != null) {
  71. StringBuffer sb = new StringBuffer(a.getContent());
  72. sb.append(data, start, length - start);
  73. a.setContent(sb.toString());
  74. } else {
  75. a.setContent(new String(data, start, length - start));
  76. }
  77. }
  78. /**
  79. * @return a String representation of this object
  80. * @see org.apache.fop.fo.FONode#getNamespaceURI()
  81. */
  82. public String getNamespaceURI() {
  83. return PSExtensionElementMapping.NAMESPACE;
  84. }
  85. /**
  86. * @return a String representation of this object
  87. * @see org.apache.fop.fo.FONode#getNormalNamespacePrefix()
  88. */
  89. public String getNormalNamespacePrefix() {
  90. return "fox";
  91. }
  92. /**
  93. * @see org.apache.fop.fo.FONode#endOfNode()
  94. * @throws FOPException if there's a problem during processing
  95. */
  96. protected void endOfNode() throws FOPException {
  97. super.endOfNode();
  98. String s = ((PSExtensionAttachment)getExtensionAttachment()).getContent();
  99. if (s == null || s.length() == 0) {
  100. missingChildElementError("#PCDATA");
  101. }
  102. }
  103. /**
  104. * @return the extension attachment if one is created by the extension element, null otherwise.
  105. * @see org.apache.fop.fo.FONode#getExtensionAttachment()
  106. */
  107. public ExtensionAttachment getExtensionAttachment() {
  108. if (attachment == null) {
  109. this.attachment = (PSExtensionAttachment)instantiateExtensionAttachment();
  110. }
  111. return this.attachment;
  112. }
  113. /**
  114. * Instantiates extension attachment object
  115. * @return extension attachment
  116. */
  117. protected abstract ExtensionAttachment instantiateExtensionAttachment();
  118. }