001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.membership;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.kernel.KernelConstants;
038: import org.libresource.kernel.LibresourceSecurityException;
039: import org.libresource.kernel.URINotExistException;
040: import org.libresource.kernel.interfaces.KernelService;
041:
042: import org.libresource.membership.ejb.model.ProfileResourceValue;
043: import org.libresource.membership.interfaces.MembershipService;
044:
045: import org.libresource.xml.ImportExportLogger;
046: import org.libresource.xml.LibresourceImportHandler;
047:
048: import org.xml.sax.Attributes;
049:
050: import java.net.URI;
051:
052: import java.util.HashMap;
053: import java.util.Iterator;
054:
055: /**
056: * LibreSource
057: *
058: * @author <a href="mailto:bort@loria.fr">Guillaume Bort</a> - <a
059: * href="http://www.inria.fr">INRIA Lorraine</a>
060: */
061: public class ProfileImportHandler extends LibresourceImportHandler {
062: private URI node;
063: private String userId;
064: private String userName;
065: private String userMail;
066: private String userJabberId;
067: private HashMap userInfos;
068: private StringBuffer tmpContent;
069: private String tmpPropertyKey;
070: private boolean enteredInDefinition = false;
071: private MembershipService membershipService;
072: private KernelService kernelService;
073:
074: public void handleBeginElement(String name, Attributes attributes,
075: ImportExportLogger logger) throws Exception {
076: if (name.equals("membership:profile")) {
077: enteredInDefinition = true;
078: }
079:
080: if (name.equals("profile:userid")) {
081: tmpContent = new StringBuffer();
082: }
083:
084: if (name.equals("profile:username")) {
085: tmpContent = new StringBuffer();
086: }
087:
088: if (name.equals("profile:usermail")) {
089: tmpContent = new StringBuffer();
090: }
091:
092: if (name.equals("profile:userjabberid")) {
093: tmpContent = new StringBuffer();
094: }
095:
096: if (name.equals("profile:infos")) {
097: userInfos = new HashMap();
098: }
099:
100: if (name.equals("profile:info")) {
101: tmpPropertyKey = attributes.getValue("key");
102: tmpContent = new StringBuffer();
103:
104: return;
105: }
106: }
107:
108: public boolean handleEndElement(String name,
109: ImportExportLogger logger) throws Exception {
110: if (name.equals("membership:profile")) {
111: try {
112: membershipService.systemCreateProfile(this .userId,
113: this .userName, this .userMail,
114: this .userJabberId, this .userInfos);
115: } catch (Exception e) {
116: //
117: }
118:
119: return true;
120: }
121:
122: if (name.equals("profile:userid")) {
123: this .userId = tmpContent.toString().trim();
124:
125: return false;
126: }
127:
128: if (name.equals("profile:username")) {
129: this .userName = tmpContent.toString().trim();
130:
131: return false;
132: }
133:
134: if (name.equals("profile:usermail")) {
135: this .userMail = tmpContent.toString().trim();
136:
137: return false;
138: }
139:
140: if (name.equals("profile:userjabberid")) {
141: this .userJabberId = tmpContent.toString().trim();
142:
143: return false;
144: }
145:
146: if (name.equals("profile:infos")) {
147: return false;
148: }
149:
150: if (name.equals("profile:info")) {
151: String propertyValue = tmpContent.toString().trim();
152: userInfos.put(tmpPropertyKey, propertyValue);
153:
154: return false;
155: }
156:
157: return false;
158: }
159:
160: public void handleContent(String content, ImportExportLogger logger)
161: throws Exception {
162: if (tmpContent != null) {
163: tmpContent.append(content);
164: }
165: }
166:
167: public void init(URI node, ImportExportLogger logger)
168: throws Exception {
169: this .node = node;
170: userId = null;
171: userName = null;
172: userMail = null;
173: userJabberId = null;
174: userInfos = null;
175: tmpContent = null;
176: tmpPropertyKey = null;
177: membershipService = (MembershipService) Libresource
178: .getService(MembershipConstants.SERVICE);
179: kernelService = (KernelService) Libresource
180: .getService(KernelConstants.SERVICE);
181: }
182: }
|