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.
41 *
42 * @xsl.usage internal
43 */
44 public final class ToXMLStream extends ToStream
45 {
46
47 /**
48 * remembers if we need to write out "]]>" to close the CDATA
49 */
50 boolean m_cdataTagOpen = false;
51
52
53 /**
54 * Map that tells which XML characters should have special treatment, and it
55 * provides character to entity name lookup.
56 */
57 private static CharInfo m_xmlcharInfo =
58 // new CharInfo(CharInfo.XML_ENTITIES_RESOURCE);
59 CharInfo.getCharInfoInternal(CharInfo.XML_ENTITIES_RESOURCE, Method.XML);
60
61 /**
62 * Default constructor.
183 catch(IOException e)
184 {
185 throw new SAXException(e);
186 }
187
188 }
189 }
190 }
191
192 /**
193 * Receive notification of the end of a document.
194 *
195 * @throws org.xml.sax.SAXException Any SAX exception, possibly
196 * wrapping another exception.
197 *
198 * @throws org.xml.sax.SAXException
199 */
200 public void endDocument() throws org.xml.sax.SAXException
201 {
202 if (m_doIndent) {
203 flushCharactersBuffer();
204 }
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
250
251 /**
252 * Receive notification of a processing instruction.
253 *
254 * @param target The processing instruction target.
255 * @param data The processing instruction data, or null if
256 * none was supplied.
257 * @throws org.xml.sax.SAXException Any SAX exception, possibly
258 * wrapping another exception.
259 *
260 * @throws org.xml.sax.SAXException
261 */
262 public void processingInstruction(String target, String data)
263 throws org.xml.sax.SAXException
264 {
265 if (isInEntityRef())
266 return;
267
268 if (m_doIndent) {
269 m_childNodeNum++;
270 flushCharactersBuffer();
271 }
272 flushPending();
273
274 if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))
275 {
276 startNonEscaping();
277 }
278 else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING))
279 {
280 endNonEscaping();
281 }
282 else
283 {
284 try
285 {
286 if (m_elemContext.m_startTagOpen)
287 {
288 closeStartTag();
289 m_elemContext.m_startTagOpen = false;
290 }
|
1 /*
2 * Copyright (c) 2014, 2019, 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.
41 *
42 * @xsl.usage internal
43 * @LastModified: July 2019
44 */
45 public final class ToXMLStream extends ToStream
46 {
47
48 /**
49 * remembers if we need to write out "]]>" to close the CDATA
50 */
51 boolean m_cdataTagOpen = false;
52
53
54 /**
55 * Map that tells which XML characters should have special treatment, and it
56 * provides character to entity name lookup.
57 */
58 private static CharInfo m_xmlcharInfo =
59 // new CharInfo(CharInfo.XML_ENTITIES_RESOURCE);
60 CharInfo.getCharInfoInternal(CharInfo.XML_ENTITIES_RESOURCE, Method.XML);
61
62 /**
63 * Default constructor.
184 catch(IOException e)
185 {
186 throw new SAXException(e);
187 }
188
189 }
190 }
191 }
192
193 /**
194 * Receive notification of the end of a document.
195 *
196 * @throws org.xml.sax.SAXException Any SAX exception, possibly
197 * wrapping another exception.
198 *
199 * @throws org.xml.sax.SAXException
200 */
201 public void endDocument() throws org.xml.sax.SAXException
202 {
203 if (m_doIndent) {
204 flushCharactersBuffer(false);
205 }
206 flushPending();
207 if (m_doIndent && !m_isprevtext)
208 {
209 try
210 {
211 outputLineSep();
212 }
213 catch(IOException e)
214 {
215 throw new SAXException(e);
216 }
217 }
218
219 flushWriter();
220
221 if (m_tracer != null)
222 super.fireEndDoc();
223 }
224
251
252 /**
253 * Receive notification of a processing instruction.
254 *
255 * @param target The processing instruction target.
256 * @param data The processing instruction data, or null if
257 * none was supplied.
258 * @throws org.xml.sax.SAXException Any SAX exception, possibly
259 * wrapping another exception.
260 *
261 * @throws org.xml.sax.SAXException
262 */
263 public void processingInstruction(String target, String data)
264 throws org.xml.sax.SAXException
265 {
266 if (isInEntityRef())
267 return;
268
269 if (m_doIndent) {
270 m_childNodeNum++;
271 flushCharactersBuffer(false);
272 }
273 flushPending();
274
275 if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))
276 {
277 startNonEscaping();
278 }
279 else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING))
280 {
281 endNonEscaping();
282 }
283 else
284 {
285 try
286 {
287 if (m_elemContext.m_startTagOpen)
288 {
289 closeStartTag();
290 m_elemContext.m_startTagOpen = false;
291 }
|