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.

TransformerDefaultHandler.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.util;
  19. import javax.xml.transform.sax.TransformerHandler;
  20. import org.xml.sax.Attributes;
  21. import org.xml.sax.Locator;
  22. import org.xml.sax.SAXException;
  23. import org.xml.sax.ext.DefaultHandler2;
  24. import org.xml.sax.helpers.AttributesImpl;
  25. /**
  26. * A DefaultHandler implementation that delegates all the method calls to a
  27. * {@link TransformerHandler} instance.
  28. */
  29. public class TransformerDefaultHandler extends DefaultHandler2 {
  30. private TransformerHandler transformerHandler;
  31. /**
  32. * Creates a new instance delegating to the given TransformerHandler object.
  33. *
  34. * @param transformerHandler the object to which all the method calls will
  35. * be delegated
  36. */
  37. public TransformerDefaultHandler(TransformerHandler transformerHandler) {
  38. this.transformerHandler = transformerHandler;
  39. }
  40. /**
  41. * Returns the delegate TransformerHandler instance.
  42. *
  43. * @return the object to which all method calls are delegated
  44. */
  45. public TransformerHandler getTransformerHandler() {
  46. return transformerHandler;
  47. }
  48. /** {@inheritDoc} */
  49. public void setDocumentLocator(Locator locator) {
  50. transformerHandler.setDocumentLocator(locator);
  51. }
  52. /** {@inheritDoc} */
  53. public void startDocument() throws SAXException {
  54. transformerHandler.startDocument();
  55. }
  56. /** {@inheritDoc} */
  57. public void endDocument() throws SAXException {
  58. transformerHandler.endDocument();
  59. }
  60. /** {@inheritDoc} */
  61. public void startPrefixMapping(String prefix, String uri) throws SAXException {
  62. transformerHandler.startPrefixMapping(prefix, uri);
  63. }
  64. /** {@inheritDoc} */
  65. public void endPrefixMapping(String string) throws SAXException {
  66. transformerHandler.endPrefixMapping(string);
  67. }
  68. /** {@inheritDoc} */
  69. public void startElement(String uri, String localName, String qName, Attributes attrs)
  70. throws SAXException {
  71. AttributesImpl ai = new AttributesImpl(attrs);
  72. transformerHandler.startElement(uri, localName, qName, ai);
  73. }
  74. /** {@inheritDoc} */
  75. public void endElement(String uri, String localName, String qName) throws SAXException {
  76. transformerHandler.endElement(uri, localName, qName);
  77. }
  78. /** {@inheritDoc} */
  79. public void characters(char[] ch, int start, int length) throws SAXException {
  80. transformerHandler.characters(ch, start, length);
  81. }
  82. /** {@inheritDoc} */
  83. public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
  84. transformerHandler.ignorableWhitespace(ch, start, length);
  85. }
  86. /** {@inheritDoc} */
  87. public void processingInstruction(String target, String data) throws SAXException {
  88. transformerHandler.processingInstruction(target, data);
  89. }
  90. /** {@inheritDoc} */
  91. public void skippedEntity(String name) throws SAXException {
  92. transformerHandler.skippedEntity(name);
  93. }
  94. /** {@inheritDoc} */
  95. public void notationDecl(String name, String publicId, String systemId) throws SAXException {
  96. transformerHandler.notationDecl(name, publicId, systemId);
  97. }
  98. /** {@inheritDoc} */
  99. public void unparsedEntityDecl(String name, String publicId, String systemId,
  100. String notationName) throws SAXException {
  101. transformerHandler.unparsedEntityDecl(name, publicId, systemId, notationName);
  102. }
  103. /** {@inheritDoc} */
  104. public void startDTD(String name, String pid, String lid) throws SAXException {
  105. transformerHandler.startDTD(name, pid, lid);
  106. }
  107. /** {@inheritDoc} */
  108. public void endDTD() throws SAXException {
  109. transformerHandler.endDTD();
  110. }
  111. /** {@inheritDoc} */
  112. public void startEntity(String name) throws SAXException {
  113. transformerHandler.startEntity(name);
  114. }
  115. /** {@inheritDoc} */
  116. public void endEntity(String name) throws SAXException {
  117. transformerHandler.endEntity(name);
  118. }
  119. /** {@inheritDoc} */
  120. public void startCDATA() throws SAXException {
  121. transformerHandler.startCDATA();
  122. }
  123. /** {@inheritDoc} */
  124. public void endCDATA() throws SAXException {
  125. transformerHandler.endCDATA();
  126. }
  127. /** {@inheritDoc} */
  128. public void comment(char[] charArray, int start, int length) throws SAXException {
  129. transformerHandler.comment(charArray, start, length);
  130. }
  131. }