< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java

Print this page


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright 2001-2004 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * 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  * $Id: ToXMLStream.java,v 1.2.4.2 2005/09/15 12:01:25 suresh_emailid Exp $
  22  */
  23  package com.sun.org.apache.xml.internal.serializer;
  24 
  25 import java.io.IOException;
  26 
  27 import javax.xml.transform.ErrorListener;
  28 import javax.xml.transform.Result;
  29 import javax.xml.transform.Transformer;
  30 import javax.xml.transform.TransformerException;
  31 
  32 import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
  33 import com.sun.org.apache.xml.internal.serializer.utils.Utils;
  34 import org.xml.sax.SAXException;
  35 
  36 /**
  37  * This class converts SAX or SAX-like calls to a
  38  * serialized xml document.  The xsl:output method is "xml".
  39  *
  40  * This class is used explicitly in code generated by XSLTC,
  41  * so it is "public", but it should
  42  * be viewed as internal or package private, this is not an API.


  75 
  76     /**
  77      * Copy properties from another SerializerToXML.
  78      *
  79      * @param xmlListener non-null reference to a SerializerToXML object.
  80      */
  81     public void CopyFrom(ToXMLStream xmlListener)
  82     {
  83 
  84         m_writer = xmlListener.m_writer;
  85 
  86 
  87         // m_outputStream = xmlListener.m_outputStream;
  88         String encoding = xmlListener.getEncoding();
  89         setEncoding(encoding);
  90 
  91         setOmitXMLDeclaration(xmlListener.getOmitXMLDeclaration());
  92 
  93         m_ispreserve = xmlListener.m_ispreserve;
  94         m_preserves = xmlListener.m_preserves;






  95         m_isprevtext = xmlListener.m_isprevtext;
  96         m_doIndent = xmlListener.m_doIndent;
  97         setIndentAmount(xmlListener.getIndentAmount());
  98         m_startNewLine = xmlListener.m_startNewLine;
  99         m_needToOutputDocTypeDecl = xmlListener.m_needToOutputDocTypeDecl;
 100         setDoctypeSystem(xmlListener.getDoctypeSystem());
 101         setDoctypePublic(xmlListener.getDoctypePublic());
 102         setStandalone(xmlListener.getStandalone());
 103         setMediaType(xmlListener.getMediaType());
 104         m_maxCharacter = xmlListener.m_maxCharacter;
 105         m_encodingInfo = xmlListener.m_encodingInfo;
 106         m_spaceBeforeClose = xmlListener.m_spaceBeforeClose;
 107         m_cdataStartCalled = xmlListener.m_cdataStartCalled;
 108 
 109     }
 110 
 111     /**
 112      * Receive notification of the beginning of a document.
 113      *
 114      * @throws org.xml.sax.SAXException Any SAX exception, possibly
 115      *            wrapping another exception.
 116      *
 117      * @throws org.xml.sax.SAXException
 118      */
 119     public void startDocumentInternal() throws org.xml.sax.SAXException
 120     {
 121 
 122         if (m_needToCallStartDocument)
 123         {
 124             super.startDocumentInternal();
 125             m_needToCallStartDocument = false;
 126 
 127             if (m_inEntityRef)
 128                 return;
 129 
 130             m_needToOutputDocTypeDecl = true;
 131             m_startNewLine = false;
 132             /* The call to getXMLVersion() might emit an error message
 133              * and we should emit this message regardless of if we are
 134              * writing out an XML header or not.
 135              */
 136             if (getOmitXMLDeclaration() == false)
 137             {
 138                 String encoding = Encodings.getMimeEncoding(getEncoding());
 139                 String version = getVersion();
 140                 if (version == null)
 141                     version = "1.0";
 142                 String standalone;
 143 
 144                 if (m_standaloneWasSpecified)
 145                 {
 146                     standalone = " standalone=\"" + getStandalone() + "\"";
 147                 }


 180                 }
 181                 catch(IOException e)
 182                 {
 183                     throw new SAXException(e);
 184                 }
 185 
 186             }
 187         }
 188     }
 189 
 190     /**
 191      * Receive notification of the end of a document.
 192      *
 193      * @throws org.xml.sax.SAXException Any SAX exception, possibly
 194      *            wrapping another exception.
 195      *
 196      * @throws org.xml.sax.SAXException
 197      */
 198     public void endDocument() throws org.xml.sax.SAXException
 199     {

 200         flushPending();
 201         if (m_doIndent && !m_isprevtext)
 202         {
 203             try
 204             {
 205             outputLineSep();
 206             }
 207             catch(IOException e)
 208             {
 209                 throw new SAXException(e);
 210             }
 211         }
 212 
 213         flushWriter();
 214 
 215         if (m_tracer != null)
 216             super.fireEndDoc();
 217     }
 218 
 219     /**


 248     {
 249 
 250         // Not sure this is really what we want.  -sb
 251         m_ispreserve = m_preserves.isEmpty() ? false : m_preserves.pop();
 252     }
 253 
 254     /**
 255      * Receive notification of a processing instruction.
 256      *
 257      * @param target The processing instruction target.
 258      * @param data The processing instruction data, or null if
 259      *        none was supplied.
 260      * @throws org.xml.sax.SAXException Any SAX exception, possibly
 261      *            wrapping another exception.
 262      *
 263      * @throws org.xml.sax.SAXException
 264      */
 265     public void processingInstruction(String target, String data)
 266         throws org.xml.sax.SAXException
 267     {
 268         if (m_inEntityRef)
 269             return;
 270 


 271         flushPending();
 272 
 273         if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))
 274         {
 275             startNonEscaping();
 276         }
 277         else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING))
 278         {
 279             endNonEscaping();
 280         }
 281         else
 282         {
 283             try
 284             {
 285                 if (m_elemContext.m_startTagOpen)
 286                 {
 287                     closeStartTag();
 288                     m_elemContext.m_startTagOpen = false;
 289                 }
 290                 else if (m_needToCallStartDocument)


   1 /*
   2  * Copyright (c) 2014, 2016 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 
  25 import javax.xml.transform.ErrorListener;
  26 import javax.xml.transform.Result;
  27 import javax.xml.transform.Transformer;
  28 import javax.xml.transform.TransformerException;
  29 
  30 import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
  31 import com.sun.org.apache.xml.internal.serializer.utils.Utils;
  32 import org.xml.sax.SAXException;
  33 
  34 /**
  35  * This class converts SAX or SAX-like calls to a
  36  * serialized xml document.  The xsl:output method is "xml".
  37  *
  38  * This class is used explicitly in code generated by XSLTC,
  39  * so it is "public", but it should
  40  * be viewed as internal or package private, this is not an API.


  73 
  74     /**
  75      * Copy properties from another SerializerToXML.
  76      *
  77      * @param xmlListener non-null reference to a SerializerToXML object.
  78      */
  79     public void CopyFrom(ToXMLStream xmlListener)
  80     {
  81 
  82         m_writer = xmlListener.m_writer;
  83 
  84 
  85         // m_outputStream = xmlListener.m_outputStream;
  86         String encoding = xmlListener.getEncoding();
  87         setEncoding(encoding);
  88 
  89         setOmitXMLDeclaration(xmlListener.getOmitXMLDeclaration());
  90 
  91         m_ispreserve = xmlListener.m_ispreserve;
  92         m_preserves = xmlListener.m_preserves;
  93         m_ispreserveSpace = xmlListener.m_ispreserveSpace;
  94         m_preserveSpaces = xmlListener.m_preserveSpaces;
  95         m_childNodeNum = xmlListener.m_childNodeNum;
  96         m_childNodeNumStack = xmlListener.m_childNodeNumStack;
  97         m_charactersBuffer = xmlListener.m_charactersBuffer;
  98         m_inEntityRef = xmlListener.m_inEntityRef;
  99         m_isprevtext = xmlListener.m_isprevtext;
 100         m_doIndent = xmlListener.m_doIndent;
 101         setIndentAmount(xmlListener.getIndentAmount());
 102         m_startNewLine = xmlListener.m_startNewLine;
 103         m_needToOutputDocTypeDecl = xmlListener.m_needToOutputDocTypeDecl;
 104         setDoctypeSystem(xmlListener.getDoctypeSystem());
 105         setDoctypePublic(xmlListener.getDoctypePublic());
 106         setStandalone(xmlListener.getStandalone());
 107         setMediaType(xmlListener.getMediaType());
 108         m_maxCharacter = xmlListener.m_maxCharacter;
 109         m_encodingInfo = xmlListener.m_encodingInfo;
 110         m_spaceBeforeClose = xmlListener.m_spaceBeforeClose;
 111         m_cdataStartCalled = xmlListener.m_cdataStartCalled;
 112 
 113     }
 114 
 115     /**
 116      * Receive notification of the beginning of a document.
 117      *
 118      * @throws org.xml.sax.SAXException Any SAX exception, possibly
 119      *            wrapping another exception.
 120      *
 121      * @throws org.xml.sax.SAXException
 122      */
 123     public void startDocumentInternal() throws org.xml.sax.SAXException
 124     {
 125 
 126         if (m_needToCallStartDocument)
 127         {
 128             super.startDocumentInternal();
 129             m_needToCallStartDocument = false;
 130 
 131             if (isInEntityRef())
 132                 return;
 133 
 134             m_needToOutputDocTypeDecl = true;
 135             m_startNewLine = false;
 136             /* The call to getXMLVersion() might emit an error message
 137              * and we should emit this message regardless of if we are
 138              * writing out an XML header or not.
 139              */
 140             if (getOmitXMLDeclaration() == false)
 141             {
 142                 String encoding = Encodings.getMimeEncoding(getEncoding());
 143                 String version = getVersion();
 144                 if (version == null)
 145                     version = "1.0";
 146                 String standalone;
 147 
 148                 if (m_standaloneWasSpecified)
 149                 {
 150                     standalone = " standalone=\"" + getStandalone() + "\"";
 151                 }


 184                 }
 185                 catch(IOException e)
 186                 {
 187                     throw new SAXException(e);
 188                 }
 189 
 190             }
 191         }
 192     }
 193 
 194     /**
 195      * Receive notification of the end of a document.
 196      *
 197      * @throws org.xml.sax.SAXException Any SAX exception, possibly
 198      *            wrapping another exception.
 199      *
 200      * @throws org.xml.sax.SAXException
 201      */
 202     public void endDocument() throws org.xml.sax.SAXException
 203     {
 204         flushCharactersBuffer();
 205         flushPending();
 206         if (m_doIndent && !m_isprevtext)
 207         {
 208             try
 209             {
 210             outputLineSep();
 211             }
 212             catch(IOException e)
 213             {
 214                 throw new SAXException(e);
 215             }
 216         }
 217 
 218         flushWriter();
 219 
 220         if (m_tracer != null)
 221             super.fireEndDoc();
 222     }
 223 
 224     /**


 253     {
 254 
 255         // Not sure this is really what we want.  -sb
 256         m_ispreserve = m_preserves.isEmpty() ? false : m_preserves.pop();
 257     }
 258 
 259     /**
 260      * Receive notification of a processing instruction.
 261      *
 262      * @param target The processing instruction target.
 263      * @param data The processing instruction data, or null if
 264      *        none was supplied.
 265      * @throws org.xml.sax.SAXException Any SAX exception, possibly
 266      *            wrapping another exception.
 267      *
 268      * @throws org.xml.sax.SAXException
 269      */
 270     public void processingInstruction(String target, String data)
 271         throws org.xml.sax.SAXException
 272     {
 273         if (isInEntityRef())
 274             return;
 275 
 276         m_childNodeNum++;
 277         flushCharactersBuffer();
 278         flushPending();
 279 
 280         if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))
 281         {
 282             startNonEscaping();
 283         }
 284         else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING))
 285         {
 286             endNonEscaping();
 287         }
 288         else
 289         {
 290             try
 291             {
 292                 if (m_elemContext.m_startTagOpen)
 293                 {
 294                     closeStartTag();
 295                     m_elemContext.m_startTagOpen = false;
 296                 }
 297                 else if (m_needToCallStartDocument)


< prev index next >