您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractPSExtensionElement.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.xml.sax.Locator;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.fo.FONode;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.ValidationException;
  25. import org.apache.fop.fo.extensions.ExtensionAttachment;
  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. /** {@inheritDoc} */
  59. protected void characters(char[] data, int start, int length,
  60. PropertyList pList, Locator locator) {
  61. PSExtensionAttachment a = (PSExtensionAttachment)getExtensionAttachment();
  62. if (a.getContent() != null) {
  63. StringBuffer sb = new StringBuffer(a.getContent());
  64. sb.append(data, start, length);
  65. a.setContent(sb.toString());
  66. } else {
  67. a.setContent(new String(data, start, length));
  68. }
  69. }
  70. /**
  71. * @return a String representation of this object
  72. * @see org.apache.fop.fo.FONode#getNamespaceURI()
  73. */
  74. public String getNamespaceURI() {
  75. return PSExtensionElementMapping.NAMESPACE;
  76. }
  77. /**
  78. * @return a String representation of this object
  79. * @see org.apache.fop.fo.FONode#getNormalNamespacePrefix()
  80. */
  81. public String getNormalNamespacePrefix() {
  82. return "ps";
  83. }
  84. /**
  85. * @see org.apache.fop.fo.FONode#endOfNode()
  86. * @throws FOPException if there's a problem during processing
  87. */
  88. public void endOfNode() throws FOPException {
  89. super.endOfNode();
  90. String s = ((PSExtensionAttachment)getExtensionAttachment()).getContent();
  91. if (s == null || s.length() == 0) {
  92. missingChildElementError("#PCDATA");
  93. }
  94. }
  95. /**
  96. * @return the extension attachment if one is created by the extension element, null otherwise.
  97. * @see org.apache.fop.fo.FONode#getExtensionAttachment()
  98. */
  99. public ExtensionAttachment getExtensionAttachment() {
  100. if (attachment == null) {
  101. this.attachment = (PSExtensionAttachment)instantiateExtensionAttachment();
  102. }
  103. return this.attachment;
  104. }
  105. /**
  106. * Instantiates extension attachment object
  107. * @return extension attachment
  108. */
  109. protected abstract ExtensionAttachment instantiateExtensionAttachment();
  110. }