1 58 package org.krysalis.barcode.xalan; 59 60 import java.util.List ; 61 62 import org.apache.avalon.framework.configuration.AbstractConfiguration; 63 import org.apache.avalon.framework.configuration.Configuration; 64 import org.apache.avalon.framework.configuration.ConfigurationException; 65 import org.w3c.dom.Element ; 66 import org.w3c.dom.Node ; 67 import org.w3c.dom.NodeList ; 68 69 75 public class ElemWrappingConfiguration extends AbstractConfiguration { 76 77 private Element elem; 78 79 83 public ElemWrappingConfiguration(Element elem) { 84 this.elem = elem; 85 } 86 87 90 protected String getPrefix() throws ConfigurationException { 91 return null; 92 } 93 94 97 public String getName() { 98 return this.elem.getLocalName(); 99 } 100 101 104 public String getLocation() { 105 return "unknown"; 106 } 107 108 111 public String getNamespace() throws ConfigurationException { 112 return null; 113 } 114 115 118 public Configuration[] getChildren() { 119 Configuration[] cfgList = new Configuration[this.elem.getChildNodes().getLength()]; 120 for (int i = 0; i < cfgList.length; i++) { 121 cfgList[i] = new ElemWrappingConfiguration((Element )this.elem.getChildNodes().item(i)); 122 } 123 return cfgList; 124 } 125 126 129 public Configuration[] getChildren(String name) { 130 List cfgList = new java.util.LinkedList (); 131 NodeList elems = this.elem.getChildNodes(); 132 for (int i = 0; i < elems.getLength(); i++) { 133 final Node node = elems.item(i); 134 if ((node instanceof Element ) 135 && (node.getLocalName().equals(name))) { 136 cfgList.add(new ElemWrappingConfiguration((Element )node)); 137 } 138 } 139 return (Configuration[])cfgList.toArray(new Configuration[cfgList.size()]); 140 } 141 142 145 public String [] getAttributeNames() { 146 throw new UnsupportedOperationException ("getAttributeNames() is not supported"); 147 } 148 149 152 public String getAttribute(String name) throws ConfigurationException { 153 final String s = this.elem.getAttribute(name); 154 if (s != null) { 155 return s; 156 } else { 157 throw new ConfigurationException("Attribut '" + name + "' does not exist"); 158 } 159 } 160 161 164 public String getValue() throws ConfigurationException { 165 NodeList nodes = elem.getChildNodes(); 169 StringBuffer sb = new StringBuffer (); 170 for (int i = 0; i < nodes.getLength(); i++) { 171 final Node node = nodes.item(i); 172 if (node.getNodeType() != Node.TEXT_NODE) { 176 sb.append(node.getNodeValue()); 177 } 178 } 179 return sb.toString(); 180 } 181 182 } 183 | Popular Tags |