< prev index next >

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

Print this page

        

*** 1,29 **** /* ! * reserved comment block ! * DO NOT REMOVE OR ALTER! */ /* ! * 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. The ASF licenses this file ! * to you under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ ! /* ! * $Id: ToHTMLStream.java,v 1.2.4.1 2005/09/15 08:15:26 suresh_emailid Exp $ ! */ package com.sun.org.apache.xml.internal.serializer; import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; --- 1,25 ---- /* ! * Copyright (c) 2014, 2016 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. ! * The ASF licenses this file to You under the Apache License, Version 2.0 ! * (the "License"); you may not use this file except in compliance with ! * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ ! package com.sun.org.apache.xml.internal.serializer; import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException;
*** 50,62 **** { /** This flag is set while receiving events from the DTD */ protected boolean m_inDTD = false; ! /** True if the current element is a block element. (seems like ! * this needs to be a stack. -sb). */ ! private boolean m_inBlockElem = false; /** * Map that tells which XML characters should have special treatment, and it * provides character to entity name lookup. */ --- 46,57 ---- { /** This flag is set while receiving events from the DTD */ protected boolean m_inDTD = false; ! /** True if the previous element is a block element. */ ! private boolean m_isprevblock = false; /** * Map that tells which XML characters should have special treatment, and it * provides character to entity name lookup. */
*** 721,731 **** * * @throws org.xml.sax.SAXException */ public final void endDocument() throws org.xml.sax.SAXException { ! flushPending(); if (m_doIndent && !m_isprevtext) { try { --- 716,726 ---- * * @throws org.xml.sax.SAXException */ public final void endDocument() throws org.xml.sax.SAXException { ! flushCharactersBuffer(); flushPending(); if (m_doIndent && !m_isprevtext) { try {
*** 741,770 **** if (m_tracer != null) super.fireEndDoc(); } /** * Receive notification of the beginning of an element. * * * @param namespaceURI * @param localName ! * @param name The element type name. ! * @param atts The attributes attached to the element, if any. ! * @throws org.xml.sax.SAXException Any SAX exception, possibly ! * wrapping another exception. * @see #endElement * @see org.xml.sax.AttributeList */ public void startElement( String namespaceURI, String localName, String name, Attributes atts) throws org.xml.sax.SAXException { ! ElemContext elemContext = m_elemContext; // clean up any pending things first if (elemContext.m_startTagOpen) { --- 736,787 ---- if (m_tracer != null) super.fireEndDoc(); } /** + * If the previous is an inline element, won't insert a new line before the + * text. + * + */ + protected boolean shouldIndentForText() { + return super.shouldIndentForText() && m_isprevblock; + } + + /** + * Only check m_doIndent, disregard m_ispreserveSpace. + * + * @return True if the content should be formatted. + */ + protected boolean shouldFormatOutput() { + return m_doIndent; + } + + /** * Receive notification of the beginning of an element. * * * @param namespaceURI * @param localName ! * @param name ! * The element type name. ! * @param atts ! * The attributes attached to the element, if any. ! * @throws org.xml.sax.SAXException ! * Any SAX exception, possibly wrapping another exception. * @see #endElement * @see org.xml.sax.AttributeList */ public void startElement( String namespaceURI, String localName, String name, Attributes atts) throws org.xml.sax.SAXException { ! //will add extra one if having namespace but no matter ! m_childNodeNum++; ! flushCharactersBuffer(); ElemContext elemContext = m_elemContext; // clean up any pending things first if (elemContext.m_startTagOpen) {
*** 798,823 **** int elemFlags = elemDesc.getFlags(); // deal with indentation issues first if (m_doIndent) { - boolean isBlockElement = (elemFlags & ElemDesc.BLOCK) != 0; ! if (m_ispreserve) ! m_ispreserve = false; ! else if ( ! (null != elemContext.m_elementName) ! && (!m_inBlockElem ! || isBlockElement) /* && !isWhiteSpaceSensitive */ ! ) { m_startNewLine = true; indent(); - } ! m_inBlockElem = !isBlockElement; } // save any attributes for later processing if (atts != null) addAttributes(atts); --- 815,836 ---- int elemFlags = elemDesc.getFlags(); // deal with indentation issues first if (m_doIndent) { boolean isBlockElement = (elemFlags & ElemDesc.BLOCK) != 0; ! if ((null != elemContext.m_elementName) ! // If this element is a block element, ! // or if this is not a block element, then if the ! // previous is neither a text nor an inline ! && (isBlockElement || (!(m_isprevtext || !m_isprevblock)))) { m_startNewLine = true; indent(); } ! m_isprevblock = isBlockElement; } // save any attributes for later processing if (atts != null) addAttributes(atts);
*** 825,835 **** m_isprevtext = false; final java.io.Writer writer = m_writer; writer.write('<'); writer.write(name); ! if (m_tracer != null) firePseudoAttributes(); if ((elemFlags & ElemDesc.EMPTY) != 0) --- 838,849 ---- m_isprevtext = false; final java.io.Writer writer = m_writer; writer.write('<'); writer.write(name); ! m_childNodeNumStack.push(m_childNodeNum); ! m_childNodeNum = 0; if (m_tracer != null) firePseudoAttributes(); if ((elemFlags & ElemDesc.EMPTY) != 0)
*** 848,857 **** --- 862,880 ---- { elemContext = elemContext.push(namespaceURI,localName,name); m_elemContext = elemContext; elemContext.m_elementDesc = elemDesc; elemContext.m_isRaw = (elemFlags & ElemDesc.RAW) != 0; + + // set m_startNewLine for the next element + if (m_doIndent) { + // elemFlags is equivalent to m_elemContext.m_elementDesc.getFlags(), + // in this branch m_elemContext.m_elementName is not null + boolean isBlockElement = (elemFlags & ElemDesc.BLOCK) != 0; + if (isBlockElement) + m_startNewLine = true; + } } if ((elemFlags & ElemDesc.HEADELEM) != 0) {
*** 891,900 **** --- 914,924 ---- final String namespaceURI, final String localName, final String name) throws org.xml.sax.SAXException { + flushCharactersBuffer(); // deal with any pending issues if (m_cdataTagOpen) closeCDATA(); // if the element has a namespace, treat it like XML, not HTML
*** 917,938 **** if (m_doIndent) { final boolean isBlockElement = (elemFlags&ElemDesc.BLOCK) != 0; boolean shouldIndent = false; ! if (m_ispreserve) ! { ! m_ispreserve = false; ! } ! else if (m_doIndent && (!m_inBlockElem || isBlockElement)) { m_startNewLine = true; shouldIndent = true; } ! if (!elemContext.m_startTagOpen && shouldIndent) indent(elemContext.m_currentElemDepth - 1); ! m_inBlockElem = !isBlockElement; } final java.io.Writer writer = m_writer; if (!elemContext.m_startTagOpen) { --- 941,962 ---- if (m_doIndent) { final boolean isBlockElement = (elemFlags&ElemDesc.BLOCK) != 0; boolean shouldIndent = false; ! // If this element is a block element, ! // or if this is not a block element, then if the previous is ! // neither a text nor an inline ! if (isBlockElement || (!(m_isprevtext || !m_isprevblock))) { m_startNewLine = true; shouldIndent = true; } ! if (!elemContext.m_startTagOpen && shouldIndent && (m_childNodeNum > 1 || !m_isprevtext)) indent(elemContext.m_currentElemDepth - 1); ! ! m_isprevblock = isBlockElement; } final java.io.Writer writer = m_writer; if (!elemContext.m_startTagOpen) {
*** 972,981 **** --- 996,1006 ---- { writer.write('>'); } } + m_childNodeNum = m_childNodeNumStack.pop(); // clean up because the element has ended if ((elemFlags & ElemDesc.WHITESPACESENSITIVE) != 0) m_ispreserve = true; m_isprevtext = false;
*** 1509,1519 **** // indent(); // writer.write("<![CDATA["); // writer.write(chars, start, length); writeNormalizedChars(chars, start, length, false, m_lineSepUse); ! // writer.write("]]>"); // time to generate characters event if (m_tracer != null) super.fireCharEvent(chars, start, length); --- 1534,1544 ---- // indent(); // writer.write("<![CDATA["); // writer.write(chars, start, length); writeNormalizedChars(chars, start, length, false, m_lineSepUse); ! m_isprevtext = true; // writer.write("]]>"); // time to generate characters event if (m_tracer != null) super.fireCharEvent(chars, start, length);
*** 1564,1574 **** * @throws org.xml.sax.SAXException */ public final void cdata(char ch[], int start, int length) throws org.xml.sax.SAXException { - if ((null != m_elemContext.m_elementName) && (m_elemContext.m_elementName.equalsIgnoreCase("SCRIPT") || m_elemContext.m_elementName.equalsIgnoreCase("STYLE"))) { try --- 1589,1598 ----
*** 1615,1625 **** * @throws org.xml.sax.SAXException */ public void processingInstruction(String target, String data) throws org.xml.sax.SAXException { ! // Process any pending starDocument and startElement first. flushPending(); // Use a fairly nasty hack to tell if the next node is supposed to be // unescaped text. --- 1639,1650 ---- * @throws org.xml.sax.SAXException */ public void processingInstruction(String target, String data) throws org.xml.sax.SAXException { ! m_childNodeNum++; ! flushCharactersBuffer(); // Process any pending starDocument and startElement first. flushPending(); // Use a fairly nasty hack to tell if the next node is supposed to be // unescaped text.
*** 1944,1954 **** } private void initToHTMLStream() { // m_elementDesc = null; ! m_inBlockElem = false; m_inDTD = false; // m_isRawStack.clear(); m_omitMetaTag = false; m_specialEscapeURLs = true; } --- 1969,1979 ---- } private void initToHTMLStream() { // m_elementDesc = null; ! m_isprevblock = false; m_inDTD = false; // m_isRawStack.clear(); m_omitMetaTag = false; m_specialEscapeURLs = true; }
< prev index next >