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.

PSExtensionAttachment.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. import org.xml.sax.ContentHandler;
  20. import org.xml.sax.SAXException;
  21. import org.xml.sax.helpers.AttributesImpl;
  22. import org.apache.xmlgraphics.util.XMLizable;
  23. import org.apache.fop.fo.extensions.ExtensionAttachment;
  24. /**
  25. * This is the pass-through value object for the PostScript extension.
  26. */
  27. public abstract class PSExtensionAttachment implements ExtensionAttachment, XMLizable {
  28. /** extension node content */
  29. protected String content;
  30. /** The category URI for this extension attachment. */
  31. public static final String CATEGORY = "apache:fop:extensions:postscript";
  32. /**
  33. * Default constructor.
  34. * @param content the content of the setup code object
  35. */
  36. public PSExtensionAttachment(String content) {
  37. this.content = content;
  38. }
  39. /**
  40. * No-argument contructor.
  41. */
  42. public PSExtensionAttachment() {
  43. }
  44. /**
  45. * @return the category URI
  46. * @see org.apache.fop.fo.extensions.ExtensionAttachment#getCategory()
  47. */
  48. public String getCategory() {
  49. return CATEGORY;
  50. }
  51. /** @return the content */
  52. public String getContent() {
  53. return content;
  54. }
  55. /**
  56. * Sets the content for the setup code object.
  57. * @param content The content to set.
  58. */
  59. public void setContent(String content) {
  60. this.content = content;
  61. }
  62. /**
  63. * Generates SAX events representing the object's state.
  64. *
  65. * @param handler ContentHandler instance to send the SAX events to
  66. * @throws SAXException if there's a problem generating the SAX events
  67. * @see org.apache.fop.util.XMLizable#toSAX(org.xml.sax.ContentHandler)
  68. */
  69. public void toSAX(ContentHandler handler) throws SAXException {
  70. AttributesImpl atts = new AttributesImpl();
  71. String element = getElement();
  72. handler.startElement(CATEGORY, element, element, atts);
  73. if (content != null && content.length() > 0) {
  74. char[] chars = content.toCharArray();
  75. handler.characters(chars, 0, chars.length);
  76. }
  77. handler.endElement(CATEGORY, element, element);
  78. }
  79. /** @return type name */
  80. public String getType() {
  81. String className = getClass().getName();
  82. return className.substring(className.lastIndexOf('.') + 3);
  83. }
  84. /**
  85. * @return a string representation of this object
  86. * @see java.lang.Object#toString()
  87. */
  88. public String toString() {
  89. return getType() + ": content=" + content;
  90. }
  91. /** @return element */
  92. protected abstract String getElement();
  93. }