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.forum;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.forum.interfaces.LibresourceForumService;
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: import java.text.SimpleDateFormat;
047:
048: import java.util.Date;
049:
050: public class MessageImportHandler extends LibresourceImportHandler {
051: private URI node;
052: private String title;
053: private String body;
054: private String author;
055: private Date date;
056: private boolean enteredInDefinition = false;
057: private StringBuffer tmpContent;
058: private LibresourceForumService libresourceForumService;
059:
060: public void handleBeginElement(String name, Attributes attributes,
061: ImportExportLogger logger) throws Exception {
062: if (name.equals("forum:message")) {
063: enteredInDefinition = true;
064: }
065:
066: if (name.equals("message:title")) {
067: tmpContent = new StringBuffer();
068: }
069:
070: if (name.equals("message:body")) {
071: tmpContent = new StringBuffer();
072: }
073:
074: if (name.equals("message:author")) {
075: tmpContent = new StringBuffer();
076: }
077:
078: if (name.equals("message:date")) {
079: tmpContent = new StringBuffer();
080: }
081: }
082:
083: public boolean handleEndElement(String name,
084: ImportExportLogger logger) throws Exception {
085: if (name.equals("forum:message")) {
086: enteredInDefinition = false;
087: libresourceForumService.createMessage(node, this .title,
088: this .body, this .author, this .date);
089:
090: return true;
091: }
092:
093: if (name.equals("message:title")) {
094: this .title = tmpContent.toString().trim();
095:
096: return false;
097: }
098:
099: if (name.equals("message:body")) {
100: this .body = tmpContent.toString().trim();
101:
102: return false;
103: }
104:
105: if (name.equals("message:author")) {
106: this .author = tmpContent.toString().trim();
107:
108: return false;
109: }
110:
111: if (name.equals("message:date")) {
112: this .date = Libresource.parseDate(tmpContent.toString()
113: .trim());
114:
115: return false;
116: }
117:
118: return false;
119: }
120:
121: public void handleContent(String content, ImportExportLogger logger)
122: throws Exception {
123: if (tmpContent != null) {
124: tmpContent.append(content);
125: }
126: }
127:
128: public void init(URI node, ImportExportLogger logger)
129: throws Exception {
130: this .node = node;
131: title = null;
132: body = null;
133: author = null;
134: date = null;
135: enteredInDefinition = false;
136: tmpContent = null;
137: libresourceForumService = (LibresourceForumService) Libresource
138: .getService("LibresourceForum");
139: }
140: }
|