01: /*--------------------------------------------------------------------------*
02: | Copyright (C) 2006 Christopher Kohlhaas |
03: | |
04: | This program is free software; you can redistribute it and/or modify |
05: | it under the terms of the GNU General Public License as published by the |
06: | Free Software Foundation. A copy of the license has been included with |
07: | these distribution in the COPYING file, if not go to www.fsf.org . |
08: | |
09: | As a special exception, you are granted the permissions to link this |
10: | program with every library, which license fulfills the Open Source |
11: | Definition as published by the Open Source Initiative (OSI). |
12: *--------------------------------------------------------------------------*/
13:
14: package org.rapla.storage.xml;
15:
16: import org.rapla.entities.Category;
17: import org.rapla.entities.internal.UserImpl;
18: import org.rapla.framework.RaplaContext;
19: import org.rapla.framework.RaplaException;
20: import org.xml.sax.Attributes;
21: import org.xml.sax.SAXException;
22:
23: public class UserReader extends RaplaXMLReader {
24: UserImpl user;
25: PreferenceReader preferenceHandler;
26:
27: public UserReader(RaplaContext context) throws RaplaException {
28: super (context);
29: preferenceHandler = new PreferenceReader(context);
30: addChildHandler(preferenceHandler);
31: }
32:
33: public void processElement(String namespaceURI, String localName,
34: String qName, Attributes atts) throws SAXException {
35: if (!namespaceURI.equals(RAPLA_NS))
36: return;
37:
38: if (localName.equals("user")) {
39: user = new UserImpl();
40: Object id = setId(user, atts);
41: setVersionIfThere(user, atts);
42: user.setUsername(getString(atts, "username", ""));
43: user.setName(getString(atts, "name", ""));
44: user.setEmail(getString(atts, "email", ""));
45: user.setAdmin(getString(atts, "isAdmin", "false").equals(
46: "true"));
47: String password = getString(atts, "password", null);
48: preferenceHandler.setUser(user);
49: if (password != null) {
50: putPassword(id, password);
51: }
52: }
53:
54: if (localName.equals("group")) {
55: Category group;
56:
57: String groupId = atts.getValue("idref");
58: if (groupId != null) {
59: group = (Category) resolve(Category.TYPE, groupId);
60: } else {
61: String groupKey = getString(atts, "key");
62: group = getGroup(groupKey);
63: }
64: if (group != null) {
65: user.addGroup(group);
66: }
67: }
68:
69: if (localName.equals("preferences")) {
70: delegateElement(preferenceHandler, namespaceURI, localName,
71: qName, atts);
72: }
73: }
74:
75: public void processEnd(String namespaceURI, String localName,
76: String qName) throws SAXException {
77: if (!namespaceURI.equals(RAPLA_NS))
78: return;
79:
80: if (localName.equals("user")) {
81: preferenceHandler.setUser(null);
82: add(user);
83: }
84: }
85:
86: }
|