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: import org.libresource.LibresourceResourceValue;
037:
038: import org.libresource.membership.ejb.model.GroupResourceValue;
039: import org.libresource.membership.ejb.model.ProfileResourceValue;
040: import org.libresource.membership.interfaces.MembershipService;
041:
042: import org.libresource.xml.ImportExportLogger;
043: import org.libresource.xml.LibresourceExportHandler;
044: import org.libresource.xml.XmlDumpAttributes;
045: import org.libresource.xml.XmlDumpHelper;
046:
047: import org.xml.sax.ContentHandler;
048:
049: import java.net.URI;
050:
051: /**
052: * LibreSource
053: *
054: * @author <a href="mailto:bort@loria.fr">Guillaume Bort</a> - <a
055: * href="http://www.inria.fr">INRIA Lorraine</a>
056: */
057: public class GroupExportHandler extends LibresourceExportHandler {
058: private URI uri;
059: private URI rootNode;
060:
061: public GroupExportHandler(URI userUri) {
062: this .uri = userUri;
063: }
064:
065: public void setRootNode(URI rootNode) {
066: this .rootNode = rootNode;
067: }
068:
069: public void export(ContentHandler handler, ImportExportLogger logger)
070: throws Exception {
071: MembershipService membershipService = (MembershipService) Libresource
072: .getService(MembershipConstants.SERVICE);
073: GroupResourceValue groupResourceValue = membershipService
074: .getGroup(uri);
075:
076: XmlDumpHelper.beginElement("membership", "group", XmlDumpHelper
077: .getEmptyAttributesSet(), handler);
078:
079: XmlDumpHelper.outputElementWithContent("group", "name",
080: groupResourceValue.getName(), XmlDumpHelper
081: .getEmptyAttributesSet(), handler);
082: XmlDumpHelper.outputElementWithContent("group", "description",
083: groupResourceValue.getDescription(), XmlDumpHelper
084: .getEmptyAttributesSet(), handler);
085:
086: // list members
087: XmlDumpAttributes attrs = new XmlDumpAttributes();
088: LibresourceResourceValue[] members = membershipService
089: .listMembers(uri);
090: attrs.put("size", new Integer(members.length));
091: XmlDumpHelper.beginElement("group", "members", XmlDumpHelper
092: .generateAttributesSet(attrs), handler);
093:
094: for (int i = 0; i < members.length; i++) {
095: XmlDumpAttributes uattrs = new XmlDumpAttributes();
096: String type = members[i].getLibresourceResourceIdentifier()
097: .getResourceType();
098: uattrs.put("type", type);
099:
100: if (type.compareTo("Group") == 0) {
101: if (members[i].getUri().getPath().startsWith(
102: rootNode.getPath())) {
103: uattrs.put("uri", "."
104: + members[i].getUri().getPath().substring(
105: rootNode.getPath().length()));
106: } else {
107: uattrs.put("uri", members[i].getUri().getPath());
108: }
109:
110: XmlDumpHelper.outputEmptyElement("group", "member",
111: XmlDumpHelper.generateAttributesSet(uattrs),
112: handler);
113: }
114:
115: if (type.compareTo("Profile") == 0) {
116: uattrs.put("id", members[i]
117: .getLibresourceResourceIdentifier()
118: .getResourceId());
119:
120: ProfileResourceValue user = membershipService
121: .getProfile(members[i].getUri());
122: uattrs.put("name", user.getFullName());
123: uattrs.put("mail", user.getEmail());
124: uattrs.put("jabber", user.getJabberId());
125: XmlDumpHelper.outputEmptyElement("group", "member",
126: XmlDumpHelper.generateAttributesSet(uattrs),
127: handler);
128: }
129: }
130:
131: XmlDumpHelper.endElement("group", "members", handler);
132:
133: XmlDumpHelper.endElement("membership", "group", handler);
134: }
135: }
|