diff options
Diffstat (limited to 'src/uk/org/ury/config/ConfigReader.java')
-rw-r--r-- | src/uk/org/ury/config/ConfigReader.java | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/uk/org/ury/config/ConfigReader.java b/src/uk/org/ury/config/ConfigReader.java index 6b66e24..6166ec4 100644 --- a/src/uk/org/ury/config/ConfigReader.java +++ b/src/uk/org/ury/config/ConfigReader.java @@ -10,24 +10,44 @@ import org.xml.sax.SAXParseException; import uk.org.ury.database.UserClass; +/** + * Reads in an XML config file and creates config objects + * + * @author Nathan + */ public class ConfigReader { private Database database; private Auth auth; + /** + * Get the database configuration + * + * @return Database database + */ public Database getDatabase() { return database; } + /** + * Get the login auth configuration + * + * @return Auth auth + */ public Auth getAuth() { return auth; } + /** + * Read in the config file and create the Database and Auth configuration objects. + */ public ConfigReader() { + new ConfigReader("res/conf.xml"); + } + + public ConfigReader(String configFile) { try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); - Document doc = docBuilder.parse (new File("res/conf.xml")); + Document doc = docBuilder.parse (new File(configFile)); doc.getDocumentElement().normalize(); - System.out.println(doc.getDocumentElement().getNodeName()); - String user = doc.getElementsByTagName("user").item(0).getTextContent(); String pass = doc.getElementsByTagName("pass").item(0).getTextContent(); UserClass type; |