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.mailing;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.mailing.interfaces.LibresourceMailingService;
038:
039: import org.libresource.xml.ImportExportLogger;
040: import org.libresource.xml.LibresourceImportHandler;
041:
042: import org.xml.sax.Attributes;
043:
044: import java.net.URI;
045:
046: public class MailingListImportHandler extends LibresourceImportHandler {
047: private URI node;
048: private String mail;
049: private String description;
050: private String subscribers;
051: private boolean enteredInDefinition = false;
052: private StringBuffer tmpContent;
053: private LibresourceMailingService mailingService;
054:
055: public void handleBeginElement(String name, Attributes attributes,
056: ImportExportLogger logger) throws Exception {
057: if (name.equals("mailing:mailinglist")) {
058: enteredInDefinition = true;
059: }
060:
061: if (name.equals("mailinglist:mail")) {
062: tmpContent = new StringBuffer();
063: }
064:
065: if (name.equals("mailinglist:description")) {
066: tmpContent = new StringBuffer();
067: }
068:
069: if (name.equals("mailinglist:subscribers")) {
070: tmpContent = new StringBuffer();
071: }
072: }
073:
074: public boolean handleEndElement(String name,
075: ImportExportLogger logger) throws Exception {
076: if (name.equals("mailing:mailinglist")) {
077: enteredInDefinition = false;
078:
079: try {
080: mailingService.createMailingList(node, this .mail,
081: this .description, this .subscribers);
082: } catch (LibresourceMailingAlreadyExistException e) {
083: this .mail = this .mail + "_" + node.getPath().hashCode();
084: mailingService.createMailingList(node, this .mail,
085: this .description, this .subscribers);
086: }
087:
088: return true;
089: }
090:
091: if (name.equals("mailinglist:mail")) {
092: this .mail = tmpContent.toString().trim();
093:
094: return false;
095: }
096:
097: if (name.equals("mailinglist:description")) {
098: this .description = tmpContent.toString().trim();
099:
100: return false;
101: }
102:
103: if (name.equals("mailinglist:subscribers")) {
104: this .subscribers = tmpContent.toString().trim();
105:
106: return false;
107: }
108:
109: return false;
110: }
111:
112: public void handleContent(String content, ImportExportLogger logger)
113: throws Exception {
114: if (tmpContent != null) {
115: tmpContent.append(content);
116: }
117: }
118:
119: public void init(URI node, ImportExportLogger logger)
120: throws Exception {
121: this .node = node;
122: description = null;
123: subscribers = null;
124: mail = null;
125: enteredInDefinition = false;
126: tmpContent = null;
127: mailingService = (LibresourceMailingService) Libresource
128: .getService(MailingListConstant.SERVICE);
129: }
130: }
|