1 /*
   2  * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *     http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xml.internal.serializer;
  22 
  23 import java.io.IOException;
  24 import java.io.OutputStream;
  25 import java.io.Writer;
  26 import java.util.List;
  27 import java.util.Properties;
  28 import javax.xml.transform.SourceLocator;
  29 import javax.xml.transform.Transformer;
  30 import org.w3c.dom.Node;
  31 import org.xml.sax.Attributes;
  32 import org.xml.sax.ContentHandler;
  33 import org.xml.sax.Locator;
  34 import org.xml.sax.SAXException;
  35 import org.xml.sax.SAXParseException;
  36 
  37 /**
  38  * This class is an adapter class. Its only purpose is to be extended and
  39  * for that extended class to over-ride all methods that are to be used.
  40  *
  41  * This class is not a public API, it is only public because it is used
  42  * across package boundaries.
  43  *
  44  * @xsl.usage internal
  45  * @LastModified: Oct 2017
  46  */
  47 public class EmptySerializer implements SerializationHandler
  48 {
  49     protected static final String ERR = "EmptySerializer method not over-ridden";
  50 
  51     protected void couldThrowIOException() throws IOException {
  52         return; // don't do anything.
  53     }
  54 
  55     protected void couldThrowSAXException() throws SAXException {
  56         return; // don't do anything.
  57     }
  58 
  59     protected void couldThrowSAXException(char[] chars, int off, int len)
  60         throws SAXException
  61     {
  62         return; // don't do anything.
  63     }
  64 
  65     protected void couldThrowSAXException(String elemQName)
  66         throws SAXException
  67     {
  68         return; // don't do anything.
  69     }
  70 
  71     void aMethodIsCalled() {
  72         // throw new RuntimeException(err);
  73         return;
  74     }
  75 
  76     /**
  77      * @see SerializationHandler#asContentHandler()
  78      */
  79     public ContentHandler asContentHandler() throws IOException {
  80         couldThrowIOException();
  81         return null;
  82     }
  83 
  84     /**
  85      * @see SerializationHandler#setContentHandler(org.xml.sax.ContentHandler)
  86      */
  87     public void setContentHandler(ContentHandler ch) {
  88         aMethodIsCalled();
  89     }
  90 
  91     /**
  92      * @see SerializationHandler#close()
  93      */
  94     public void close() {
  95         aMethodIsCalled();
  96     }
  97 
  98     /**
  99      * @see SerializationHandler#getOutputFormat()
 100      */
 101     public Properties getOutputFormat() {
 102         aMethodIsCalled();
 103         return null;
 104     }
 105 
 106     /**
 107      * @see SerializationHandler#getOutputStream()
 108      */
 109     public OutputStream getOutputStream() {
 110         aMethodIsCalled();
 111         return null;
 112     }
 113 
 114     /**
 115      * @see SerializationHandler#getWriter()
 116      */
 117     public Writer getWriter() {
 118         aMethodIsCalled();
 119         return null;
 120     }
 121 
 122     /**
 123      * @see SerializationHandler#reset()
 124      */
 125     public boolean reset() {
 126         aMethodIsCalled();
 127         return false;
 128     }
 129 
 130     /**
 131      * @see SerializationHandler#serialize(org.w3c.dom.Node)
 132      */
 133     public void serialize(Node node) throws IOException {
 134         couldThrowIOException();
 135     }
 136 
 137     /**
 138      * @see SerializationHandler#setCdataSectionElements(java.util.ArrayList<String>)
 139      */
 140     public void setCdataSectionElements(List<String> URI_and_localNames) {
 141         aMethodIsCalled();
 142     }
 143 
 144     /**
 145      * @see SerializationHandler#setEscaping(boolean)
 146      */
 147     public boolean setEscaping(boolean escape) throws SAXException {
 148         couldThrowSAXException();
 149         return false;
 150     }
 151 
 152     /**
 153      * @see SerializationHandler#setIndent(boolean)
 154      */
 155     public void setIndent(boolean indent) {
 156         aMethodIsCalled();
 157     }
 158 
 159     /**
 160      * @see SerializationHandler#setIndentAmount(int)
 161      */
 162     public void setIndentAmount(int spaces) {
 163         aMethodIsCalled();
 164     }
 165 
 166     /**
 167      * @see SerializationHandler#setIsStandalone(boolean)
 168      */
 169     public void setIsStandalone(boolean isStandalone) {
 170         aMethodIsCalled();
 171     }
 172 
 173     /**
 174      * @see SerializationHandler#setOutputFormat(java.util.Properties)
 175      */
 176     public void setOutputFormat(Properties format) {
 177         aMethodIsCalled();
 178     }
 179 
 180     /**
 181      * @see SerializationHandler#setOutputStream(java.io.OutputStream)
 182      */
 183     public void setOutputStream(OutputStream output) {
 184         aMethodIsCalled();
 185     }
 186 
 187     /**
 188      * @see SerializationHandler#setVersion(java.lang.String)
 189      */
 190     public void setVersion(String version) {
 191         aMethodIsCalled();
 192     }
 193 
 194     /**
 195      * @see SerializationHandler#setWriter(java.io.Writer)
 196      */
 197     public void setWriter(Writer writer) {
 198         aMethodIsCalled();
 199     }
 200 
 201     /**
 202      * @see SerializationHandler#setTransformer(javax.xml.transform.Transformer)
 203      */
 204     public void setTransformer(Transformer transformer) {
 205         aMethodIsCalled();
 206     }
 207 
 208     /**
 209      * @see SerializationHandler#getTransformer()
 210      */
 211     public Transformer getTransformer() {
 212         aMethodIsCalled();
 213         return null;
 214     }
 215 
 216     /**
 217      * @see SerializationHandler#flushPending()
 218      */
 219     public void flushPending() throws SAXException {
 220         couldThrowSAXException();
 221     }
 222 
 223     /**
 224      * @see ExtendedContentHandler#addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 225      */
 226     public void addAttribute(String uri, String localName, String rawName,
 227                              String type, String value, boolean XSLAttribute)
 228         throws SAXException
 229     {
 230         couldThrowSAXException();
 231     }
 232 
 233     /**
 234      * @see ExtendedContentHandler#addAttributes(org.xml.sax.Attributes)
 235      */
 236     public void addAttributes(Attributes atts) throws SAXException {
 237         couldThrowSAXException();
 238     }
 239 
 240     /**
 241      * @see ExtendedContentHandler#addAttribute(java.lang.String, java.lang.String)
 242      */
 243     public void addAttribute(String name, String value) {
 244         aMethodIsCalled();
 245     }
 246 
 247     /**
 248      * @see ExtendedContentHandler#characters(java.lang.String)
 249      */
 250     public void characters(String chars) throws SAXException {
 251         couldThrowSAXException();
 252     }
 253 
 254     /**
 255      * @see ExtendedContentHandler#endElement(java.lang.String)
 256      */
 257     public void endElement(String elemName) throws SAXException {
 258         couldThrowSAXException();
 259     }
 260 
 261     /**
 262      * @see ExtendedContentHandler#startDocument()
 263      */
 264     public void startDocument() throws SAXException {
 265         couldThrowSAXException();
 266     }
 267 
 268     /**
 269      * @see ExtendedContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String)
 270      */
 271     public void startElement(String uri, String localName, String qName)
 272         throws SAXException
 273     {
 274         couldThrowSAXException(qName);
 275     }
 276 
 277     /**
 278      * @see ExtendedContentHandler#startElement(java.lang.String)
 279      */
 280     public void startElement(String qName) throws SAXException {
 281         couldThrowSAXException(qName);
 282     }
 283 
 284     /**
 285      * @see ExtendedContentHandler#namespaceAfterStartElement(java.lang.String, java.lang.String)
 286      */
 287     public void namespaceAfterStartElement(String uri, String prefix)
 288         throws SAXException
 289     {
 290         couldThrowSAXException();
 291     }
 292     /**
 293      * @see ExtendedContentHandler#startPrefixMapping(java.lang.String, java.lang.String, boolean)
 294      */
 295     public boolean startPrefixMapping(String prefix, String uri,
 296                                       boolean shouldFlush)
 297         throws SAXException
 298     {
 299         couldThrowSAXException();
 300         return false;
 301     }
 302 
 303     /**
 304      * @see ExtendedContentHandler#entityReference(java.lang.String)
 305      */
 306     public void entityReference(String entityName) throws SAXException {
 307         couldThrowSAXException();
 308     }
 309 
 310     /**
 311      * @see ExtendedContentHandler#getNamespaceMappings()
 312      */
 313     public NamespaceMappings getNamespaceMappings() {
 314         aMethodIsCalled();
 315         return null;
 316     }
 317 
 318     /**
 319      * @see ExtendedContentHandler#getPrefix(java.lang.String)
 320      */
 321     public String getPrefix(String uri) {
 322         aMethodIsCalled();
 323         return null;
 324     }
 325 
 326     /**
 327      * @see ExtendedContentHandler#getNamespaceURI(java.lang.String, boolean)
 328      */
 329     public String getNamespaceURI(String name, boolean isElement) {
 330         aMethodIsCalled();
 331         return null;
 332     }
 333 
 334     /**
 335      * @see ExtendedContentHandler#getNamespaceURIFromPrefix(java.lang.String)
 336      */
 337     public String getNamespaceURIFromPrefix(String prefix) {
 338         aMethodIsCalled();
 339         return null;
 340     }
 341 
 342     /**
 343      * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
 344      */
 345     public void setDocumentLocator(Locator arg0) {
 346         aMethodIsCalled();
 347     }
 348 
 349     /**
 350      * @see org.xml.sax.ContentHandler#endDocument()
 351      */
 352     public void endDocument() throws SAXException {
 353         couldThrowSAXException();
 354     }
 355 
 356     /**
 357      * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
 358      */
 359     public void startPrefixMapping(String arg0, String arg1)
 360         throws SAXException
 361     {
 362         couldThrowSAXException();
 363     }
 364 
 365     /**
 366      * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
 367      */
 368     public void endPrefixMapping(String arg0) throws SAXException {
 369         couldThrowSAXException();
 370     }
 371 
 372     /**
 373      * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
 374      */
 375     public void startElement(String arg0, String arg1, String arg2,
 376                              Attributes arg3)
 377         throws SAXException
 378     {
 379         couldThrowSAXException();
 380     }
 381 
 382     /**
 383      * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
 384      */
 385     public void endElement(String arg0, String arg1, String arg2)
 386         throws SAXException
 387     {
 388         couldThrowSAXException();
 389     }
 390 
 391     /**
 392      * @see org.xml.sax.ContentHandler#characters(char[], int, int)
 393      */
 394     public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
 395         couldThrowSAXException(arg0, arg1, arg2);
 396     }
 397 
 398     /**
 399      * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
 400      */
 401     public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
 402         throws SAXException
 403     {
 404         couldThrowSAXException();
 405     }
 406 
 407     /**
 408      * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
 409      */
 410     public void processingInstruction(String arg0, String arg1)
 411         throws SAXException
 412     {
 413         couldThrowSAXException();
 414     }
 415 
 416     /**
 417      * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
 418      */
 419     public void skippedEntity(String arg0) throws SAXException {
 420         couldThrowSAXException();
 421     }
 422 
 423     /**
 424      * @see ExtendedLexicalHandler#comment(java.lang.String)
 425      */
 426     public void comment(String comment) throws SAXException {
 427         couldThrowSAXException();
 428     }
 429 
 430     /**
 431      * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
 432      */
 433     public void startDTD(String arg0, String arg1, String arg2)
 434         throws SAXException
 435     {
 436         couldThrowSAXException();
 437     }
 438 
 439     /**
 440      * @see org.xml.sax.ext.LexicalHandler#endDTD()
 441      */
 442     public void endDTD() throws SAXException {
 443         couldThrowSAXException();
 444     }
 445 
 446     /**
 447      * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
 448      */
 449     public void startEntity(String arg0) throws SAXException {
 450         couldThrowSAXException();
 451     }
 452 
 453     /**
 454      * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
 455      */
 456     public void endEntity(String arg0) throws SAXException {
 457         couldThrowSAXException();
 458     }
 459 
 460     /**
 461      * @see org.xml.sax.ext.LexicalHandler#startCDATA()
 462      */
 463     public void startCDATA() throws SAXException {
 464         couldThrowSAXException();
 465     }
 466 
 467     /**
 468      * @see org.xml.sax.ext.LexicalHandler#endCDATA()
 469      */
 470     public void endCDATA() throws SAXException {
 471         couldThrowSAXException();
 472     }
 473 
 474     /**
 475      * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
 476      */
 477     public void comment(char[] arg0, int arg1, int arg2) throws SAXException {
 478         couldThrowSAXException();
 479     }
 480 
 481     /**
 482      * @see XSLOutputAttributes#getDoctypePublic()
 483      */
 484     public String getDoctypePublic() {
 485         aMethodIsCalled();
 486         return null;
 487     }
 488 
 489     /**
 490      * @see XSLOutputAttributes#getDoctypeSystem()
 491      */
 492     public String getDoctypeSystem() {
 493         aMethodIsCalled();
 494         return null;
 495     }
 496 
 497     /**
 498      * @see XSLOutputAttributes#getEncoding()
 499      */
 500     public String getEncoding() {
 501         aMethodIsCalled();
 502         return null;
 503     }
 504 
 505     /**
 506      * @see XSLOutputAttributes#getIndent()
 507      */
 508     public boolean getIndent() {
 509         aMethodIsCalled();
 510         return false;
 511     }
 512 
 513     /**
 514      * @see XSLOutputAttributes#getIndentAmount()
 515      */
 516     public int getIndentAmount() {
 517         aMethodIsCalled();
 518         return 0;
 519     }
 520 
 521     /**
 522      * @see XSLOutputAttributes#getMediaType()
 523      */
 524     public String getMediaType() {
 525         aMethodIsCalled();
 526         return null;
 527     }
 528 
 529     /**
 530      * @see XSLOutputAttributes#getOmitXMLDeclaration()
 531      */
 532     public boolean getOmitXMLDeclaration() {
 533         aMethodIsCalled();
 534         return false;
 535     }
 536 
 537     /**
 538      * @see XSLOutputAttributes#getStandalone()
 539      */
 540     public String getStandalone() {
 541         aMethodIsCalled();
 542         return null;
 543     }
 544 
 545     /**
 546      * @see XSLOutputAttributes#getVersion()
 547      */
 548     public String getVersion() {
 549         aMethodIsCalled();
 550         return null;
 551     }
 552 
 553     /**
 554      * @see XSLOutputAttributes#setDoctype(java.lang.String, java.lang.String)
 555      */
 556     public void setDoctype(String system, String pub) {
 557         aMethodIsCalled();
 558     }
 559 
 560     /**
 561      * @see XSLOutputAttributes#setDoctypePublic(java.lang.String)
 562      */
 563     public void setDoctypePublic(String doctype) {
 564         aMethodIsCalled();
 565     }
 566 
 567     /**
 568      * @see XSLOutputAttributes#setDoctypeSystem(java.lang.String)
 569      */
 570     public void setDoctypeSystem(String doctype) {
 571         aMethodIsCalled();
 572     }
 573 
 574     /**
 575      * @see XSLOutputAttributes#setEncoding(java.lang.String)
 576      */
 577     public void setEncoding(String encoding) {
 578         aMethodIsCalled();
 579     }
 580 
 581     /**
 582      * @see XSLOutputAttributes#setMediaType(java.lang.String)
 583      */
 584     public void setMediaType(String mediatype) {
 585         aMethodIsCalled();
 586     }
 587 
 588     /**
 589      * @see XSLOutputAttributes#setOmitXMLDeclaration(boolean)
 590      */
 591     public void setOmitXMLDeclaration(boolean b) {
 592         aMethodIsCalled();
 593     }
 594 
 595     /**
 596      * @see XSLOutputAttributes#setStandalone(java.lang.String)
 597      */
 598     public void setStandalone(String standalone) {
 599         aMethodIsCalled();
 600     }
 601 
 602     /**
 603      * @see org.xml.sax.ext.DeclHandler#elementDecl(java.lang.String, java.lang.String)
 604      */
 605     public void elementDecl(String arg0, String arg1) throws SAXException {
 606         couldThrowSAXException();
 607     }
 608 
 609     /**
 610      * @see org.xml.sax.ext.DeclHandler#attributeDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 611      */
 612     public void attributeDecl(String arg0, String arg1, String arg2,
 613                               String arg3, String arg4)
 614         throws SAXException
 615     {
 616         couldThrowSAXException();
 617     }
 618 
 619     /**
 620      * @see org.xml.sax.ext.DeclHandler#internalEntityDecl(java.lang.String, java.lang.String)
 621      */
 622     public void internalEntityDecl(String arg0, String arg1)
 623         throws SAXException
 624     {
 625         couldThrowSAXException();
 626     }
 627 
 628     /**
 629      * @see org.xml.sax.ext.DeclHandler#externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
 630      */
 631     public void externalEntityDecl(String arg0, String arg1, String arg2)
 632         throws SAXException
 633     {
 634         couldThrowSAXException();
 635     }
 636 
 637     /**
 638      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
 639      */
 640     public void warning(SAXParseException arg0) throws SAXException {
 641         couldThrowSAXException();
 642     }
 643 
 644     /**
 645      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
 646      */
 647     public void error(SAXParseException arg0) throws SAXException {
 648         couldThrowSAXException();
 649     }
 650 
 651     /**
 652      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
 653      */
 654     public void fatalError(SAXParseException arg0) throws SAXException {
 655         couldThrowSAXException();
 656     }
 657 
 658     /**
 659      * @see Serializer#asDOMSerializer()
 660      */
 661     public DOMSerializer asDOMSerializer() throws IOException {
 662         couldThrowIOException();
 663         return null;
 664     }
 665 
 666     /**
 667      * @see SerializationHandler#setNamespaceMappings(NamespaceMappings)
 668      */
 669     public void setNamespaceMappings(NamespaceMappings mappings) {
 670         aMethodIsCalled();
 671     }
 672 
 673     /**
 674      * @see ExtendedContentHandler#setSourceLocator(javax.xml.transform.SourceLocator)
 675      */
 676     public void setSourceLocator(SourceLocator locator) {
 677         aMethodIsCalled();
 678     }
 679 
 680     /**
 681      * @see ExtendedContentHandler#addUniqueAttribute(java.lang.String, java.lang.String, int)
 682      */
 683     public void addUniqueAttribute(String name, String value, int flags)
 684         throws SAXException
 685     {
 686         couldThrowSAXException();
 687     }
 688 
 689     /**
 690      * @see ExtendedContentHandler#characters(org.w3c.dom.Node)
 691      */
 692     public void characters(Node node) throws SAXException {
 693         couldThrowSAXException();
 694     }
 695 
 696     /**
 697      * @see ExtendedContentHandler#addXSLAttribute(java.lang.String, java.lang.String, java.lang.String)
 698      */
 699     public void addXSLAttribute(String qName, String value, String uri) {
 700         aMethodIsCalled();
 701     }
 702 
 703     /**
 704      * @see ExtendedContentHandler#addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 705      */
 706     public void addAttribute(String uri, String localName, String rawName,
 707                              String type, String value) throws SAXException {
 708         couldThrowSAXException();
 709     }
 710 
 711     /**
 712      * @see org.xml.sax.DTDHandler#notationDecl(java.lang.String, java.lang.String, java.lang.String)
 713      */
 714     public void notationDecl(String arg0, String arg1, String arg2)
 715         throws SAXException
 716     {
 717         couldThrowSAXException();
 718     }
 719 
 720     /**
 721      * @see org.xml.sax.DTDHandler#unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 722      */
 723     public void unparsedEntityDecl(String arg0, String arg1, String arg2,
 724                                    String arg3) throws SAXException {
 725         couldThrowSAXException();
 726     }
 727 
 728     /**
 729      * @see SerializationHandler#setDTDEntityExpansion(boolean)
 730      */
 731     public void setDTDEntityExpansion(boolean expand) {
 732         aMethodIsCalled();
 733     }
 734 
 735     public String getOutputProperty(String name) {
 736         aMethodIsCalled();
 737         return null;
 738     }
 739 
 740     public String getOutputPropertyDefault(String name) {
 741         aMethodIsCalled();
 742         return null;
 743     }
 744 
 745     public void setOutputProperty(String name, String val) {
 746         aMethodIsCalled();
 747     }
 748 
 749     public void setOutputPropertyDefault(String name, String val) {
 750         aMethodIsCalled();
 751     }
 752 
 753     /**
 754      * @see org.apache.xml.serializer.Serializer#asDOM3Serializer()
 755      */
 756     public Object asDOM3Serializer() throws IOException {
 757         couldThrowIOException();
 758         return null;
 759     }
 760 }