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 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 org.xml.sax.ContentHandler;
  20. import org.xml.sax.SAXException;
  21. import org.xml.sax.helpers.AttributesImpl;
  22. import org.apache.fop.afp.modca.TagLogicalElement;
  23. /**
  24. * This is the pass-through value object for the AFP extension.
  25. */
  26. public class AFPPageSetup extends AFPExtensionAttachment {
  27. /** value attribute */
  28. protected static final String ATT_VALUE = "value";
  29. /** placement attribute */
  30. protected static final String ATT_PLACEMENT = "placement";
  31. /**
  32. * the extension content
  33. */
  34. protected String content;
  35. /**
  36. * the extension value attribute
  37. */
  38. protected String value;
  39. /** defines where to place the extension in the generated file */
  40. protected ExtensionPlacement placement = ExtensionPlacement.DEFAULT;
  41. /**
  42. * the CCSID character set encoding
  43. */
  44. protected int encoding = TagLogicalElement.State.ENCODING_NONE;
  45. /**
  46. *
  47. * @return CCSID character set encoding
  48. */
  49. public int getEncoding() {
  50. return encoding;
  51. }
  52. /**
  53. *
  54. * @param encoding CCSID character set encoding
  55. */
  56. public void setEncoding(int encoding) {
  57. this.encoding = encoding;
  58. }
  59. /**
  60. * Default constructor.
  61. *
  62. * @param elementName the name of the setup code object, may be null
  63. */
  64. public AFPPageSetup(String elementName) {
  65. super(elementName);
  66. }
  67. private static final long serialVersionUID = -549941295384013190L;
  68. /**
  69. * Returns the value of the extension.
  70. * @return the value
  71. */
  72. public String getValue() {
  73. return value;
  74. }
  75. /**
  76. * Sets the value
  77. * @param source The value name to set.
  78. */
  79. public void setValue(String source) {
  80. this.value = source;
  81. }
  82. /**
  83. * Returns the content of the extension.
  84. * @return the data
  85. */
  86. public String getContent() {
  87. return content;
  88. }
  89. /**
  90. * Sets the data
  91. * @param content The byte data to set.
  92. */
  93. public void setContent(String content) {
  94. this.content = content;
  95. }
  96. /**
  97. * Returns the intended placement of the extension inside the generated file.
  98. * @return the intended placement
  99. */
  100. public ExtensionPlacement getPlacement() {
  101. return this.placement;
  102. }
  103. /**
  104. * Sets the intended placement of the extension inside the generated file.
  105. * @param placement the intended placement
  106. */
  107. public void setPlacement(ExtensionPlacement placement) {
  108. if (!AFPElementMapping.NO_OPERATION.equals(getElementName())) {
  109. throw new UnsupportedOperationException(
  110. "The attribute 'placement' can currently only be set for NOPs!");
  111. }
  112. this.placement = placement;
  113. }
  114. /** {@inheritDoc} */
  115. public void toSAX(ContentHandler handler) throws SAXException {
  116. AttributesImpl atts = new AttributesImpl();
  117. if (name != null && name.length() > 0) {
  118. atts.addAttribute(null, ATT_NAME, ATT_NAME, "CDATA", name);
  119. }
  120. if (value != null && value.length() > 0) {
  121. atts.addAttribute(null, ATT_VALUE, ATT_VALUE, "CDATA", value);
  122. }
  123. if (this.placement != ExtensionPlacement.DEFAULT) {
  124. atts.addAttribute(null, ATT_PLACEMENT, ATT_PLACEMENT, "CDATA", placement.getXMLValue());
  125. }
  126. handler.startElement(CATEGORY, elementName, elementName, atts);
  127. if (content != null && content.length() > 0) {
  128. char[] chars = content.toCharArray();
  129. handler.characters(chars, 0, chars.length);
  130. }
  131. handler.endElement(CATEGORY, elementName, elementName);
  132. }
  133. /** {@inheritDoc} */
  134. @Override
  135. public String toString() {
  136. StringBuilder sb = new StringBuilder("AFPPageSetup(");
  137. sb.append("element-name=").append(getElementName());
  138. sb.append(" name=").append(getName());
  139. sb.append(" value=").append(getValue());
  140. if (getPlacement() != ExtensionPlacement.DEFAULT) {
  141. sb.append(" placement=").append(getPlacement());
  142. }
  143. sb.append(")");
  144. return sb.toString();
  145. }
  146. }