Reads the xml from the provided reader and binds the values to the
if (reader == null)
throw new IllegalArgumentException("Reader must not be null");
URL resource = AccountBuilder.class.getResource("/gdata-account.xsd");
if(resource == null)
throw new RuntimeException("can not find xml schema file 'gdata-account.xsd' -- file must be present on the classpath");
String schemaFile = resource.getFile();
GDataAccount account = null;
/*
* Force using apache xerces parser for digester
*/
SAXParser parser = new SAXParser();
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
parser.setFeature("http://xml.org/sax/features/validation",true);
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schemaFile);
Digester digester = new Digester(parser);
digester.setValidating(true);
digester.setErrorHandler(new SimpleSaxErrorHandler());
digester.setSchema(schemaFile);
digester.addObjectCreate("account", GDataAccount.class);
digester.addBeanPropertySetter("account/account-name", "name");
digester.addBeanPropertySetter("account/password", "password");
digester.addBeanPropertySetter("account/account-role", "rolesAsInt");
digester.addBeanPropertySetter("account/account-owner/name",
"authorname");
digester.addBeanPropertySetter("account/account-owner/email-address",
"authorMail");
digester.addBeanPropertySetter("account/account-owner/url",
"authorLink");
account = (GDataAccount) digester.parse(reader);
return account;