1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 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.utils; 23 24 import org.w3c.dom.Attr; 25 import org.w3c.dom.NamedNodeMap; 26 import org.w3c.dom.Node; 27 28 import org.xml.sax.Attributes; 29 30 /** 31 * Wraps a DOM attribute list in a SAX Attributes. 32 * @xsl.usage internal 33 */ 34 public class AttList implements Attributes 35 { 36 37 /** List of attribute nodes */ 38 NamedNodeMap m_attrs; 39 40 /** Index of last attribute node */ 41 int m_lastIndex; 42 43 // ARGHH!! JAXP Uses Xerces without setting the namespace processing to ON! 44 // DOM2Helper m_dh = new DOM2Helper(); 45 46 /** Local reference to DOMHelper */ 47 DOMHelper m_dh; 48 49 // /** 50 // * Constructor AttList 51 // * 52 // * 53 // * @param attrs List of attributes this will contain 54 // */ 55 // public AttList(NamedNodeMap attrs) 56 // { 57 // 58 // m_attrs = attrs; 59 // m_lastIndex = m_attrs.getLength() - 1; 60 // m_dh = new DOM2Helper(); 61 // } 62 63 /** 64 * Constructor AttList 65 * 66 * 67 * @param attrs List of attributes this will contain 68 * @param dh DOMHelper 69 */ 70 public AttList(NamedNodeMap attrs, DOMHelper dh) 71 { 72 73 m_attrs = attrs; 74 m_lastIndex = m_attrs.getLength() - 1; 75 m_dh = dh; 76 } 77 78 /** 79 * Get the number of attribute nodes in the list 80 * 81 * 82 * @return number of attribute nodes 83 */ 84 public int getLength() 85 { 86 return m_attrs.getLength(); 87 } 88 89 /** 90 * Look up an attribute's Namespace URI by index. 91 * 92 * @param index The attribute index (zero-based). 93 * @return The Namespace URI, or the empty string if none 94 * is available, or null if the index is out of 95 * range. 96 */ 97 public String getURI(int index) 98 { 99 String ns = m_dh.getNamespaceOfNode(((Attr) m_attrs.item(index))); 100 if(null == ns) 101 ns = ""; 102 return ns; 103 } 104 105 /** 106 * Look up an attribute's local name by index. 107 * 108 * @param index The attribute index (zero-based). 109 * @return The local name, or the empty string if Namespace 110 * processing is not being performed, or null 111 * if the index is out of range. 112 */ 113 public String getLocalName(int index) 114 { 115 return m_dh.getLocalNameOfNode(((Attr) m_attrs.item(index))); 116 } 117 118 /** 119 * Look up an attribute's qualified name by index. 120 * 121 * 122 * @param i The attribute index (zero-based). 123 * 124 * @return The attribute's qualified name 125 */ 126 public String getQName(int i) 127 { 128 return ((Attr) m_attrs.item(i)).getName(); 129 } 130 131 /** 132 * Get the attribute's node type by index 133 * 134 * 135 * @param i The attribute index (zero-based) | 1 /* 2 * Copyright (c) 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.utils; 22 23 import org.w3c.dom.Attr; 24 import org.w3c.dom.NamedNodeMap; 25 import org.w3c.dom.Node; 26 27 import org.xml.sax.Attributes; 28 29 /** 30 * Wraps a DOM attribute list in a SAX Attributes. 31 * @xsl.usage internal 32 */ 33 public class AttList implements Attributes 34 { 35 36 /** List of attribute nodes */ 37 NamedNodeMap m_attrs; 38 39 /** Index of last attribute node */ 40 int m_lastIndex; 41 42 // JAXP Uses Xerces without setting the namespace processing to ON! 43 // DOM2Helper m_dh = new DOM2Helper(); 44 45 /** 46 * Constructor AttList 47 * 48 * 49 * @param attrs List of attributes this will contain 50 * @param dh DOMHelper 51 */ 52 public AttList(NamedNodeMap attrs) 53 { 54 m_attrs = attrs; 55 m_lastIndex = m_attrs.getLength() - 1; 56 } 57 58 /** 59 * Get the number of attribute nodes in the list 60 * 61 * 62 * @return number of attribute nodes 63 */ 64 public int getLength() 65 { 66 return m_attrs.getLength(); 67 } 68 69 /** 70 * Look up an attribute's Namespace URI by index. 71 * 72 * @param index The attribute index (zero-based). 73 * @return The Namespace URI, or the empty string if none 74 * is available, or null if the index is out of 75 * range. 76 */ 77 public String getURI(int index) 78 { 79 String ns = DOM2Helper.getNamespaceOfNode(((Attr) m_attrs.item(index))); 80 if(null == ns) 81 ns = ""; 82 return ns; 83 } 84 85 /** 86 * Look up an attribute's local name by index. 87 * 88 * @param index The attribute index (zero-based). 89 * @return The local name, or the empty string if Namespace 90 * processing is not being performed, or null 91 * if the index is out of range. 92 */ 93 public String getLocalName(int index) 94 { 95 return DOM2Helper.getLocalNameOfNode(((Attr) m_attrs.item(index))); 96 } 97 98 /** 99 * Look up an attribute's qualified name by index. 100 * 101 * 102 * @param i The attribute index (zero-based). 103 * 104 * @return The attribute's qualified name 105 */ 106 public String getQName(int i) 107 { 108 return ((Attr) m_attrs.item(i)).getName(); 109 } 110 111 /** 112 * Get the attribute's node type by index 113 * 114 * 115 * @param i The attribute index (zero-based) |