1 package org.mr.core.util.xml.sax; 2 3 import org.xml.sax.Attributes ; 4 import org.xml.sax.helpers.AttributesImpl ; 5 6 import java.util.Collections ; 7 import java.util.Iterator ; 8 import java.util.LinkedList ; 9 10 55 56 63 public class NonNSAttributes { 64 65 private static final String TEXT_ATT_TYPE = "CDATA"; 66 private static final String EMPTY_NS = NonNSContentHandler.EMPTY_NS; 67 private LinkedList m_atts; 68 69 75 public void addAttribute(String i_name, String i_value) { 76 if (m_atts == null) { 77 m_atts = new LinkedList (); 78 } 79 m_atts.add(new NonNSAttribute(i_name, i_value)); 80 } 81 82 85 public void clear() { 86 if (m_atts != null) { 87 m_atts.clear(); 88 } 89 } 90 91 96 public boolean isEmpty() { 97 return (m_atts == null || (m_atts.size() == 0)); 98 } 99 100 105 public Iterator attributes() { 106 if (m_atts == null) { 107 return Collections.EMPTY_LIST.iterator(); 108 } 109 return m_atts.iterator(); 110 } 111 112 public Attributes toAttributes() { 113 AttributesImpl ret = new AttributesImpl (); 114 for (Iterator iterator = attributes(); iterator.hasNext();) { 115 NonNSAttribute nonNSAttribute = (NonNSAttribute) iterator.next(); 116 String name = nonNSAttribute.getName(); 117 String value = nonNSAttribute.getValue(); 118 ret.addAttribute(EMPTY_NS, name, name, TEXT_ATT_TYPE, value); 119 } 120 return ret; 121 } 122 123 private static class NonNSAttribute { 124 private String m_name; 125 private String m_value; 126 127 public NonNSAttribute(String i_name, String i_value) { 128 m_name = i_name; 129 m_value = i_value; 130 } 131 132 public String getName() { 133 return m_name; 134 } 135 136 public String getValue() { 137 return m_value; 138 } 139 } 140 } 141 | Popular Tags |