< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Oct 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *     http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xml.internal.serializer;
  23 


1650     {
1651         int startClean = lastDirty + 1;
1652         // if we have some clean characters accumulated
1653         // process them before the dirty one.
1654         if (i > startClean)
1655         {
1656             int lengthClean = i - startClean;
1657             m_writer.write(chars, startClean, lengthClean);
1658         }
1659 
1660         // process the "dirty" character
1661         if (CharInfo.S_LINEFEED == ch && fromTextNode)
1662         {
1663             m_writer.write(m_lineSep, 0, m_lineSepLen);
1664         }
1665         else
1666         {
1667             startClean =
1668                 accumDefaultEscape(
1669                     m_writer,
1670                     (char)ch,
1671                     i,
1672                     chars,
1673                     end,
1674                     fromTextNode,
1675                     false);
1676             i = startClean - 1;
1677         }
1678         // Return the index of the last character that we just processed
1679         // which is a dirty character.
1680         return i;
1681     }
1682 
1683     /**
1684      * Receive notification of character data.
1685      *
1686      * @param s The string of characters to process.
1687      *
1688      * @throws org.xml.sax.SAXException
1689      */
1690     public void characters(String s) throws org.xml.sax.SAXException


2722         }
2723     }
2724 
2725     /**
2726      * Remembers the cdata sections specified in the cdata-section-elements.
2727      * The "official way to set URI and localName pairs.
2728      * This method should be used by both Xalan and XSLTC.
2729      *
2730      * @param URI_and_localNames an ArrayList of pairs of Strings (URI/local)
2731      */
2732     public void setCdataSectionElements(List<String> URI_and_localNames) {
2733         // convert to the new way.
2734         if (URI_and_localNames != null) {
2735             final int len = URI_and_localNames.size() - 1;
2736             if (len > 0) {
2737                 final StringBuilder sb = new StringBuilder();
2738                 for (int i = 0; i < len; i += 2) {
2739                     // whitspace separated "{uri1}local1 {uri2}local2 ..."
2740                     if (i != 0)
2741                         sb.append(' ');
2742                     final String uri = (String) URI_and_localNames.get(i);
2743                     final String localName =
2744                         (String) URI_and_localNames.get(i + 1);
2745                     if (uri != null) {
2746                         // If there is no URI don't put this in, just the localName then.
2747                         sb.append('{');
2748                         sb.append(uri);
2749                         sb.append('}');
2750                     }
2751                     sb.append(localName);
2752                 }
2753                 m_StringOfCDATASections = sb.toString();
2754             }
2755         }
2756         initCdataElems(m_StringOfCDATASections);
2757     }
2758 
2759     /**
2760      * Makes sure that the namespace URI for the given qualified attribute name
2761      * is declared.
2762      * @param ns the namespace URI
2763      * @param rawName the qualified name
2764      * @return returns null if no action is taken, otherwise it returns the


   1 /*
   2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *     http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xml.internal.serializer;
  23 


1650     {
1651         int startClean = lastDirty + 1;
1652         // if we have some clean characters accumulated
1653         // process them before the dirty one.
1654         if (i > startClean)
1655         {
1656             int lengthClean = i - startClean;
1657             m_writer.write(chars, startClean, lengthClean);
1658         }
1659 
1660         // process the "dirty" character
1661         if (CharInfo.S_LINEFEED == ch && fromTextNode)
1662         {
1663             m_writer.write(m_lineSep, 0, m_lineSepLen);
1664         }
1665         else
1666         {
1667             startClean =
1668                 accumDefaultEscape(
1669                     m_writer,
1670                     ch,
1671                     i,
1672                     chars,
1673                     end,
1674                     fromTextNode,
1675                     false);
1676             i = startClean - 1;
1677         }
1678         // Return the index of the last character that we just processed
1679         // which is a dirty character.
1680         return i;
1681     }
1682 
1683     /**
1684      * Receive notification of character data.
1685      *
1686      * @param s The string of characters to process.
1687      *
1688      * @throws org.xml.sax.SAXException
1689      */
1690     public void characters(String s) throws org.xml.sax.SAXException


2722         }
2723     }
2724 
2725     /**
2726      * Remembers the cdata sections specified in the cdata-section-elements.
2727      * The "official way to set URI and localName pairs.
2728      * This method should be used by both Xalan and XSLTC.
2729      *
2730      * @param URI_and_localNames an ArrayList of pairs of Strings (URI/local)
2731      */
2732     public void setCdataSectionElements(List<String> URI_and_localNames) {
2733         // convert to the new way.
2734         if (URI_and_localNames != null) {
2735             final int len = URI_and_localNames.size() - 1;
2736             if (len > 0) {
2737                 final StringBuilder sb = new StringBuilder();
2738                 for (int i = 0; i < len; i += 2) {
2739                     // whitspace separated "{uri1}local1 {uri2}local2 ..."
2740                     if (i != 0)
2741                         sb.append(' ');
2742                     final String uri = URI_and_localNames.get(i);
2743                     final String localName = URI_and_localNames.get(i + 1);

2744                     if (uri != null) {
2745                         // If there is no URI don't put this in, just the localName then.
2746                         sb.append('{');
2747                         sb.append(uri);
2748                         sb.append('}');
2749                     }
2750                     sb.append(localName);
2751                 }
2752                 m_StringOfCDATASections = sb.toString();
2753             }
2754         }
2755         initCdataElems(m_StringOfCDATASections);
2756     }
2757 
2758     /**
2759      * Makes sure that the namespace URI for the given qualified attribute name
2760      * is declared.
2761      * @param ns the namespace URI
2762      * @param rawName the qualified name
2763      * @return returns null if no action is taken, otherwise it returns the


< prev index next >