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.

AFPPageSetup.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. import java.io.Serializable;
  20. import org.apache.fop.fo.extensions.ExtensionAttachment;
  21. import org.apache.fop.util.XMLizable;
  22. import org.xml.sax.ContentHandler;
  23. import org.xml.sax.SAXException;
  24. import org.xml.sax.helpers.AttributesImpl;
  25. /**
  26. * This is the pass-through value object for the PostScript extension.
  27. */
  28. public class AFPPageSetup implements ExtensionAttachment, Serializable, XMLizable {
  29. private static final long serialVersionUID = 7190606822558332901L;
  30. /** The category URI for this extension attachment. */
  31. public static final String CATEGORY = "apache:fop:extensions:afp";
  32. private String elementName;
  33. private String name;
  34. private String value;
  35. private String content;
  36. /**
  37. * Default constructor.
  38. *
  39. * @param elementName the name of the setup code object, may be null
  40. */
  41. public AFPPageSetup(String elementName) {
  42. this.elementName = elementName;
  43. }
  44. /** @return the name */
  45. public String getElementName() {
  46. return elementName;
  47. }
  48. /** @return the name */
  49. public String getName() {
  50. return name;
  51. }
  52. /**
  53. * Sets the name of the setup code object.
  54. * @param name The name to set.
  55. */
  56. public void setName(String name) {
  57. this.name = name;
  58. }
  59. /**
  60. * @return the value
  61. */
  62. public String getValue() {
  63. return value;
  64. }
  65. /**
  66. * Sets the value
  67. * @param source The value name to set.
  68. */
  69. public void setValue(String source) {
  70. this.value = source;
  71. }
  72. /** {@inheritDoc} */
  73. public String getCategory() {
  74. return CATEGORY;
  75. }
  76. /**
  77. * @return the data
  78. */
  79. public String getContent() {
  80. return content;
  81. }
  82. /**
  83. * Sets the data
  84. * @param content The byte data to set.
  85. */
  86. public void setContent(String content) {
  87. this.content = content;
  88. }
  89. /** {@inheritDoc} */
  90. public String toString() {
  91. return "AFPPageSetup(element-name=" + getElementName() + " name=" + getName() + ")";
  92. }
  93. private static final String ATT_NAME = "name";
  94. private static final String ATT_VALUE = "value";
  95. /** {@inheritDoc} */
  96. public void toSAX(ContentHandler handler) throws SAXException {
  97. AttributesImpl atts = new AttributesImpl();
  98. if (name != null && name.length() > 0) {
  99. atts.addAttribute(null, ATT_NAME, ATT_NAME, "CDATA", name);
  100. }
  101. if (value != null && value.length() > 0) {
  102. atts.addAttribute(null, ATT_VALUE, ATT_VALUE, "CDATA", value);
  103. }
  104. handler.startElement(CATEGORY, elementName, elementName, atts);
  105. if (content != null && content.length() > 0) {
  106. char[] chars = content.toCharArray();
  107. handler.characters(chars, 0, chars.length);
  108. }
  109. handler.endElement(CATEGORY, elementName, elementName);
  110. }
  111. }