/** * This method is public as an implementation side effect and should never be called directly. */ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { depth++; if(depth == 1) return; if(itemName != null) { try {builder.startSection(itemName);} catch(Exception e) {throw new SAXParseException(e.getMessage(), locator, e);} } buffer.setLength(0); itemName = qName; isVariable = true; }
/** * Recursively explores the specified section and invokes the specified builder's callback methods. * @param builder object that will receive building events. * @param root section to explore. * @throws ConfigurationException if any error occurs. */ private synchronized void build(ConfigurationBuilder builder, ConfigurationSection root) throws ConfigurationException { Iterator<String> enumeration; // Enumeration on the section's variables, then subsections. String name; // Name of the current variable, then section. ConfigurationSection section; // Current section. // Explores the section's variables. enumeration = root.variableNames(); while(enumeration.hasNext()) builder.addVariable(name = enumeration.next(), root.getVariable(name)); // Explores the section's subsections. enumeration = root.sectionNames(); while(enumeration.hasNext()) { name = enumeration.next(); section = root.getSection(name); // We only go through subsections if contain either variables or subsections of their own. if(section.hasSections() || section.hasVariables()) { builder.startSection(name); build(builder, section); builder.endSection(name); } } }