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.interfaces.KernelService;
039:
040: import org.libresource.membership.interfaces.MembershipService;
041:
042: import org.libresource.xml.ImportExportLogger;
043: import org.libresource.xml.LibresourceImportHandler;
044: import org.libresource.xml.SecurityImportHandler;
045:
046: import org.xml.sax.Attributes;
047:
048: import java.net.URI;
049:
050: /**
051: * LibreSource
052: *
053: * @author <a href="mailto:bort@loria.fr">Guillaume Bort</a> - <a
054: * href="http://www.inria.fr">INRIA Lorraine</a>
055: */
056: public class GroupImportHandler extends LibresourceImportHandler {
057: private URI node;
058: private URI rootNode;
059: private String name;
060: private String description;
061: private StringBuffer tmpContent;
062: private MembershipService membershipService;
063: private KernelService kernelService;
064: private SecurityImportHandler securityImportHandler;
065:
066: public void handleBeginElement(String name, Attributes attributes,
067: ImportExportLogger logger) throws Exception {
068: if (name.equals("group:name")) {
069: tmpContent = new StringBuffer();
070: }
071:
072: if (name.equals("group:description")) {
073: tmpContent = new StringBuffer();
074: }
075:
076: if (name.equals("group:members")) {
077: membershipService.createGroup(node, this .name,
078: this .description);
079: }
080:
081: if (name.equals("group:member")) {
082: String type = attributes.getValue("type");
083:
084: if ((type != null) && (type.compareTo("Profile") == 0)) {
085: URI user = new URI(membershipService.getUsersRootURI()
086: + "/" + attributes.getValue("id"));
087: securityImportHandler.createProfile(attributes
088: .getValue("id"), attributes.getValue("name"),
089: attributes.getValue("mail"), attributes
090: .getValue("jabber"));
091: securityImportHandler.handleUserMemberGroup(node, user);
092: }
093:
094: if ((type != null) && (type.compareTo("Group") == 0)) {
095: URI group = new URI(attributes.getValue("uri"));
096:
097: if (group.getPath().startsWith(".")) {
098: group = new URI(rootNode.getPath() + "/"
099: + group.getPath());
100: }
101:
102: securityImportHandler.handleGroupMemberGroup(node,
103: group);
104: }
105: }
106: }
107:
108: public boolean handleEndElement(String name,
109: ImportExportLogger logger) throws Exception {
110: if (name.equals("membership:group")) {
111: return true;
112: }
113:
114: if (name.equals("group:name")) {
115: this .name = tmpContent.toString().trim();
116:
117: return false;
118: }
119:
120: if (name.equals("group:description")) {
121: this .description = tmpContent.toString().trim();
122:
123: return false;
124: }
125:
126: return false;
127: }
128:
129: public void handleContent(String content, ImportExportLogger logger)
130: throws Exception {
131: if (tmpContent != null) {
132: tmpContent.append(content);
133: }
134: }
135:
136: public void init(URI node, ImportExportLogger logger)
137: throws Exception {
138: this .node = node;
139: name = null;
140: description = null;
141: tmpContent = null;
142: membershipService = (MembershipService) Libresource
143: .getService(MembershipConstants.SERVICE);
144: kernelService = (KernelService) Libresource
145: .getService(KernelConstants.SERVICE);
146: }
147:
148: public void setRootNode(URI rootNode) {
149: this .rootNode = rootNode;
150: }
151:
152: public void setSecurityImportHandler(
153: SecurityImportHandler securityImportHandler) {
154: this.securityImportHandler = securityImportHandler;
155: }
156: }
|