/** * This method is public as an implementation side effect and should never be called directly. */ @Override public void endElement(String uri, String localName, String qName) throws SAXException { depth--; if(depth == 0) return; // If the current element doesn't have subsections, considers it to be a variable. if(isVariable) { String value; value = buffer.toString().trim(); // Ignores empty values, otherwise notifies the builder of a new variable. if(!value.isEmpty()) { try {builder.addVariable(qName, value);} catch(Exception e) {throw new SAXParseException(e.getMessage(), locator, e);} } } // The current element is a container, closes it. else { try {builder.endSection(qName);} catch(Exception e) {throw new SAXParseException(e.getMessage(), locator, e);} } isVariable = false; itemName = null; }
/** * 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); } } }