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.membership.ejb.model.ProfileResourceValue;
038: import org.libresource.membership.interfaces.MembershipService;
039:
040: import org.libresource.xml.ImportExportLogger;
041: import org.libresource.xml.LibresourceExportHandler;
042: import org.libresource.xml.XmlDumpAttributes;
043: import org.libresource.xml.XmlDumpHelper;
044:
045: import org.xml.sax.ContentHandler;
046:
047: import java.net.URI;
048:
049: import java.util.HashMap;
050: import java.util.Iterator;
051:
052: /**
053: * LibreSource
054: *
055: * @author <a href="mailto:bort@loria.fr">Guillaume Bort</a> - <a
056: * href="http://www.inria.fr">INRIA Lorraine</a>
057: */
058: public class ProfileExportHandler extends LibresourceExportHandler {
059: private URI uri;
060: private URI rootNode;
061:
062: public ProfileExportHandler(URI userUri) {
063: this .uri = userUri;
064: }
065:
066: public void setRootNode(URI rootNode) {
067: this .rootNode = rootNode;
068: }
069:
070: public void export(ContentHandler handler, ImportExportLogger logger)
071: throws Exception {
072: MembershipService membershipService = (MembershipService) Libresource
073: .getService(MembershipConstants.SERVICE);
074: ProfileResourceValue profileResourceValue = membershipService
075: .getProfile(uri);
076:
077: XmlDumpHelper.beginElement("membership", "profile",
078: XmlDumpHelper.getEmptyAttributesSet(), handler);
079:
080: // user infos
081: XmlDumpHelper.outputElementWithContent("profile", "userid",
082: profileResourceValue.getId(), XmlDumpHelper
083: .getEmptyAttributesSet(), handler);
084: XmlDumpHelper.outputElementWithContent("profile", "username",
085: profileResourceValue.getFullName(), XmlDumpHelper
086: .getEmptyAttributesSet(), handler);
087: XmlDumpHelper.outputElementWithContent("profile", "usermail",
088: profileResourceValue.getEmail(), XmlDumpHelper
089: .getEmptyAttributesSet(), handler);
090: XmlDumpHelper.outputElementWithContent("profile",
091: "userjabberid", profileResourceValue.getJabberId(),
092: XmlDumpHelper.getEmptyAttributesSet(), handler);
093:
094: // users preferences
095: XmlDumpHelper.beginElement("profile", "infos", XmlDumpHelper
096: .getEmptyAttributesSet(), handler);
097:
098: HashMap userInfos = profileResourceValue.getInfos();
099:
100: for (Iterator i = userInfos.keySet().iterator(); i.hasNext();) {
101: String key = (String) i.next();
102: XmlDumpAttributes attrsProp = new XmlDumpAttributes();
103: attrsProp.put("key", key);
104:
105: if (userInfos.get(key) != null) {
106: XmlDumpHelper.outputElementWithContent("profile",
107: "info", userInfos.get(key).toString(),
108: XmlDumpHelper.generateAttributesSet(attrsProp),
109: handler);
110: }
111: }
112:
113: XmlDumpHelper.endElement("profile", "infos", handler);
114:
115: XmlDumpHelper.endElement("membership", "profile", handler);
116: }
117: }
|