protected void startElement(String name) throws ConfigurationException { try {out.startElement("", name, name, emptyAttributes);} catch(SAXException e) {throw new ConfigurationException(e);} }
protected void endElement(String name) throws ConfigurationException { try {out.endElement("", name, name);} catch(SAXException e) {throw new ConfigurationException(e);} }
@Override public void startConfiguration() throws ConfigurationException { // Version the file. // Note: the version attribute was introduced in muCommander 0.8.4. AttributesImpl attributes; attributes = new AttributesImpl(); attributes.addAttribute("", MuPreferences.VERSION_ATTRIBUTE, MuPreferences.VERSION_ATTRIBUTE, "string", RuntimeConstants.VERSION); try {out.startElement("", rootElementName, rootElementName, attributes);} catch(SAXException e) {throw new ConfigurationException(e);} } }
/** * Writes the XML header. * @throws ConfigurationException as a wrapper for any exception that might have occurred. */ public void startConfiguration() throws ConfigurationException { try { out.startDocument(); startElement(rootElementName); } catch(SAXException e) {throw new ConfigurationException(e);} }
/** * Writes the XML footer. * @throws ConfigurationException as a wrapper for any <code>IOException</code> that might have occurred. */ public void endConfiguration() throws ConfigurationException { try { endElement(rootElementName); out.endDocument(); } catch(SAXException e) {throw new ConfigurationException(e);} } }
/** * Reads the content of <code>in</code> an passes build messages to <code>builder</code>. * @param in input stream from which to read the configuration data. * @param builder object to notify of build events. * @throws IOException if an I/O error occurs. * @throws ConfigurationFormatException if a configuration file format occurs. * @throws ConfigurationException if a non-specific error occurs. */ public void read(Reader in, ConfigurationBuilder builder) throws IOException, ConfigurationException, ConfigurationFormatException { this.builder = builder; locator = null; try {SAXParserFactory.newInstance().newSAXParser().parse(new InputSource(in), this);} catch(ParserConfigurationException e) {throw new ConfigurationException("Failed to create a SAX parser", e);} catch(SAXParseException e) {throw new ConfigurationFormatException(e.getMessage(), e.getLineNumber(), e.getColumnNumber());} catch(SAXException e) {throw new ConfigurationFormatException(e.getException() == null ? e : e.getException());} }
/** * Creates a new variable in the current section. * @param name name of the new variable. * @param value value of the new variable. * @throws ConfigurationException as a wrapper for any <code>IOException</code> that might have occurred. */ public void addVariable(String name, String value) throws ConfigurationException { char[] data; try { startElement(name); data = value.toCharArray(); out.characters(data, 0, data.length); endElement(name); } catch(SAXException e) {throw new ConfigurationException(e);} }