< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java

Print this page
rev 1072 : 8172974: [JAXP] XALAN: Wrong result when transforming namespace unaware StAX Input
   1 /*
   2  * Copyright (c) 2007, 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.dtm.ref.sax2dtm;
  22 


2007    *        element has no Namespace URI or if Namespace
2008    *        processing is not being performed.
2009    * @param localName The local name (without prefix), or the
2010    *        empty string if Namespace processing is not being
2011    *        performed.
2012    * @param qName The qualified name (with prefix), or the
2013    *        empty string if qualified names are not available.
2014    * @param attributes The specified or defaulted attributes.
2015    * @throws SAXException Any SAX exception, possibly
2016    *            wrapping another exception.
2017    * @see ContentHandler#startElement
2018    */
2019   public void startElement(String uri, String localName, String qName,
2020                            Attributes attributes) throws SAXException
2021   {
2022     charactersFlush();
2023 
2024     // in case URI and localName are empty, the input is not using the
2025     // namespaces feature. Then we should take the part after the last
2026     // colon of qName as localName (strip all namespace prefixes)
2027     if ((uri == null || uri.isEmpty()) &&
2028         (localName == null || localName.isEmpty()))
2029     {
2030       final int colon = qName.lastIndexOf(':');
2031       localName = (colon > -1) ? qName.substring(colon + 1) : qName;







2032     }
2033 
2034     int exName = m_expandedNameTable.getExpandedTypeID(uri, localName,
2035                                                        DTM.ELEMENT_NODE);
2036 
2037     int prefixIndex = (qName.length() != localName.length())
2038                       ? m_valuesOrPrefixes.stringToIndex(qName) : 0;
2039 
2040     int elemNode = addNode(DTM.ELEMENT_NODE, exName,
2041                            m_parents.peek(), m_previous, prefixIndex, true);
2042 
2043     if (m_indexing)
2044       indexNode(exName, elemNode);
2045 
2046     m_parents.push(elemNode);
2047 
2048     int startDecls = m_contextIndexes.peek();
2049     int nDecls = m_prefixMappings.size();
2050     String prefix;
2051 


2081 
2082     int n = attributes.getLength();
2083 
2084     for (int i = 0; i < n; i++) {
2085       String attrUri = attributes.getURI(i);
2086       String attrLocalName = attributes.getLocalName(i);
2087       String attrQName = attributes.getQName(i);
2088       String valString = attributes.getValue(i);
2089 
2090       // in case URI and localName are empty, the input is not using the
2091       // namespaces feature. Then we should take the part after the last
2092       // colon of qName as localName (strip all namespace prefixes)
2093       // When the URI is empty but localName has colons then we can also
2094       // assume non namespace aware and prefixes can be stripped
2095       if (attrUri == null || attrUri.isEmpty()) {
2096         if (attrLocalName == null || attrLocalName.isEmpty()) {
2097           final int colon = attrQName.lastIndexOf(':');
2098           attrLocalName = (colon > -1) ? attrQName.substring(colon + 1) : attrQName;
2099         } else {
2100           final int colon = attrLocalName.lastIndexOf(':');
2101           attrLocalName = (colon > -1) ? attrLocalName.substring(colon + 1) : attrLocalName;


2102         }
2103       }
2104 
2105       int nodeType;
2106       if ((null != attrQName) &&
2107           (attrQName.equals("xmlns") || attrQName.startsWith("xmlns:")))
2108       {
2109         prefix = getPrefix(attrQName, attrUri);
2110         if (declAlreadyDeclared(prefix))
2111           continue;  // go to the next attribute.
2112 
2113         nodeType = DTM.NAMESPACE_NODE;
2114       } else {
2115         nodeType = DTM.ATTRIBUTE_NODE;
2116 
2117         if (m_buildIdIndex && attributes.getType(i).equalsIgnoreCase("ID"))
2118           setIDAttribute(valString, elemNode);
2119       }
2120 
2121       // Bit of a hack... if somehow valString is null, stringToIndex will


   1 /*
   2  * Copyright (c) 2007, 2017, 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.dtm.ref.sax2dtm;
  22 


2007    *        element has no Namespace URI or if Namespace
2008    *        processing is not being performed.
2009    * @param localName The local name (without prefix), or the
2010    *        empty string if Namespace processing is not being
2011    *        performed.
2012    * @param qName The qualified name (with prefix), or the
2013    *        empty string if qualified names are not available.
2014    * @param attributes The specified or defaulted attributes.
2015    * @throws SAXException Any SAX exception, possibly
2016    *            wrapping another exception.
2017    * @see ContentHandler#startElement
2018    */
2019   public void startElement(String uri, String localName, String qName,
2020                            Attributes attributes) throws SAXException
2021   {
2022     charactersFlush();
2023 
2024     // in case URI and localName are empty, the input is not using the
2025     // namespaces feature. Then we should take the part after the last
2026     // colon of qName as localName (strip all namespace prefixes)
2027     // When the URI is empty but localName has colons then we can also
2028     // assume non namespace aware and prefixes can be stripped
2029     if (uri == null || uri.isEmpty()) {
2030       if (localName == null || localName.isEmpty()) {
2031         final int colon = qName.lastIndexOf(':');
2032         localName = (colon > -1) ? qName.substring(colon + 1) : qName;
2033       } else {
2034         final int colon = localName.lastIndexOf(':');
2035         if (colon > -1) {
2036           localName = localName.substring(colon + 1);
2037         }
2038       }
2039     }
2040 
2041     int exName = m_expandedNameTable.getExpandedTypeID(uri, localName,
2042                                                        DTM.ELEMENT_NODE);
2043 
2044     int prefixIndex = (qName.length() != localName.length())
2045                       ? m_valuesOrPrefixes.stringToIndex(qName) : 0;
2046 
2047     int elemNode = addNode(DTM.ELEMENT_NODE, exName,
2048                            m_parents.peek(), m_previous, prefixIndex, true);
2049 
2050     if (m_indexing)
2051       indexNode(exName, elemNode);
2052 
2053     m_parents.push(elemNode);
2054 
2055     int startDecls = m_contextIndexes.peek();
2056     int nDecls = m_prefixMappings.size();
2057     String prefix;
2058 


2088 
2089     int n = attributes.getLength();
2090 
2091     for (int i = 0; i < n; i++) {
2092       String attrUri = attributes.getURI(i);
2093       String attrLocalName = attributes.getLocalName(i);
2094       String attrQName = attributes.getQName(i);
2095       String valString = attributes.getValue(i);
2096 
2097       // in case URI and localName are empty, the input is not using the
2098       // namespaces feature. Then we should take the part after the last
2099       // colon of qName as localName (strip all namespace prefixes)
2100       // When the URI is empty but localName has colons then we can also
2101       // assume non namespace aware and prefixes can be stripped
2102       if (attrUri == null || attrUri.isEmpty()) {
2103         if (attrLocalName == null || attrLocalName.isEmpty()) {
2104           final int colon = attrQName.lastIndexOf(':');
2105           attrLocalName = (colon > -1) ? attrQName.substring(colon + 1) : attrQName;
2106         } else {
2107           final int colon = attrLocalName.lastIndexOf(':');
2108           if (colon > -1) {
2109             attrLocalName = attrLocalName.substring(colon + 1);
2110           }
2111         }
2112       }
2113 
2114       int nodeType;
2115       if ((null != attrQName) &&
2116           (attrQName.equals("xmlns") || attrQName.startsWith("xmlns:")))
2117       {
2118         prefix = getPrefix(attrQName, attrUri);
2119         if (declAlreadyDeclared(prefix))
2120           continue;  // go to the next attribute.
2121 
2122         nodeType = DTM.NAMESPACE_NODE;
2123       } else {
2124         nodeType = DTM.ATTRIBUTE_NODE;
2125 
2126         if (m_buildIdIndex && attributes.getType(i).equalsIgnoreCase("ID"))
2127           setIDAttribute(valString, elemNode);
2128       }
2129 
2130       // Bit of a hack... if somehow valString is null, stringToIndex will


< prev index next >