< prev index next >
src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -49,11 +49,11 @@
/**
* This abstract class is a base class for other stream
* serializers (xml, html, text ...) that write output to a stream.
*
* @xsl.usage internal
- * @LastModified: Sept 2018
+ * @LastModified: July 2019
*/
abstract public class ToStream extends SerializerBase {
private static final String COMMENT_BEGIN = "<!--";
private static final String COMMENT_END = "-->";
@@ -1229,11 +1229,11 @@
{
closeStartTag();
m_elemContext.m_startTagOpen = false;
}
- if (!m_cdataTagOpen && shouldIndent())
+ if (!m_cdataTagOpen && shouldIndentForText())
indent();
boolean writeCDataBrackets =
(((length >= 1) && escapingNotNeeded(ch[start])));
@@ -1268,10 +1268,11 @@
*/
if (ch[start + length - 1] == ']')
closeCDATA();
}
+ m_isprevtext = true;
// time to fire off CDATA event
if (m_tracer != null)
super.fireCDATAEvent(ch, old_start, length);
}
catch (IOException ioe)
@@ -1534,15 +1535,17 @@
throw new SAXException(e);
}
}
/**
- * Used to flush the buffered characters when indentation is on, this method
- * will be called when the next node is traversed.
+ * Flushes the buffered characters when indentation is on. This method
+ * is called before the next node is traversed.
*
+ * @param isText indicates whether the node to be traversed is text
+ * @throws org.xml.sax.SAXException
*/
- final protected void flushCharactersBuffer() throws SAXException {
+ final protected void flushCharactersBuffer(boolean isText) throws SAXException {
try {
if (shouldFormatOutput() && m_charactersBuffer.isAnyCharactersBuffered()) {
if (m_elemContext.m_isCdataSection) {
/*
* due to cdata-section-elements atribute, we need this as
@@ -1551,11 +1554,13 @@
char[] chars = m_charactersBuffer.toChars();
cdata(chars, 0, chars.length);
return;
}
+ if (!isText) {
m_childNodeNum++;
+ }
boolean skipBeginningNewlines = false;
if (shouldIndentForText()) {
indent();
m_startNewLine = true;
// newline has always been added here because if this is the
@@ -1844,11 +1849,11 @@
if (isInEntityRef())
return;
if (m_doIndent) {
m_childNodeNum++;
- flushCharactersBuffer();
+ flushCharactersBuffer(false);
}
if (m_needToCallStartDocument)
{
startDocumentInternal();
@@ -2115,11 +2120,11 @@
if (isInEntityRef())
return;
if (m_doIndent) {
- flushCharactersBuffer();
+ flushCharactersBuffer(false);
}
// namespaces declared at the current depth are no longer valid
// so get rid of them
m_prefixMap.popNamespaces(m_elemContext.m_currentElemDepth, null);
@@ -2307,11 +2312,11 @@
int start_old = start;
if (isInEntityRef())
return;
if (m_doIndent) {
m_childNodeNum++;
- flushCharactersBuffer();
+ flushCharactersBuffer(false);
}
if (m_elemContext.m_startTagOpen)
{
closeStartTag();
m_elemContext.m_startTagOpen = false;
@@ -2489,12 +2494,11 @@
* @see #endCDATA
*/
public void startCDATA() throws org.xml.sax.SAXException
{
if (m_doIndent) {
- m_childNodeNum++;
- flushCharactersBuffer();
+ flushCharactersBuffer(true);
}
m_cdataStartCalled = true;
}
< prev index next >