01: /**
02: * LibreSource
03: * Copyright (C) 2004-2008 Artenum SARL / INRIA
04: * http://www.libresource.org - contact@artenum.com
05: *
06: * This file is part of the LibreSource software,
07: * which can be used and distributed under license conditions.
08: * The license conditions are provided in the LICENSE.TXT file
09: * at the root path of the packaging that enclose this file.
10: * More information can be found at
11: * - http://dev.libresource.org/home/license
12: *
13: * Initial authors :
14: *
15: * Guillaume Bort / INRIA
16: * Francois Charoy / Universite Nancy 2
17: * Julien Forest / Artenum
18: * Claude Godart / Universite Henry Poincare
19: * Florent Jouille / INRIA
20: * Sebastien Jourdain / INRIA / Artenum
21: * Yves Lerumeur / Artenum
22: * Pascal Molli / Universite Henry Poincare
23: * Gerald Oster / INRIA
24: * Mariarosa Penzi / Artenum
25: * Gerard Sookahet / Artenum
26: * Raphael Tani / INRIA
27: *
28: * Contributors :
29: *
30: * Stephane Bagnier / Artenum
31: * Amadou Dia / Artenum-IUP Blois
32: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33: */package org.libresource.forum;
34:
35: import org.libresource.Libresource;
36:
37: import org.libresource.forum.interfaces.LibresourceForumService;
38:
39: import org.libresource.xml.ImportExportLogger;
40: import org.libresource.xml.LibresourceImportHandler;
41:
42: import org.xml.sax.Attributes;
43:
44: import java.net.URI;
45:
46: public class ThreadImportHandler extends LibresourceImportHandler {
47: private URI node;
48: private String name;
49: private boolean enteredInDefinition = false;
50: private StringBuffer tmpContent;
51: private LibresourceForumService libresourceForumService;
52:
53: public void handleBeginElement(String name, Attributes attributes,
54: ImportExportLogger logger) throws Exception {
55: if (name.equals("forum:thread")) {
56: enteredInDefinition = true;
57: }
58:
59: if (name.equals("thread:name")) {
60: tmpContent = new StringBuffer();
61: }
62: }
63:
64: public boolean handleEndElement(String name,
65: ImportExportLogger logger) throws Exception {
66: if (name.equals("forum:thread")) {
67: enteredInDefinition = false;
68: libresourceForumService.createThread(node, this .name);
69:
70: return true;
71: }
72:
73: if (name.equals("thread:name")) {
74: this .name = tmpContent.toString().trim();
75:
76: return false;
77: }
78:
79: return false;
80: }
81:
82: public void handleContent(String content, ImportExportLogger logger)
83: throws Exception {
84: if (tmpContent != null) {
85: tmpContent.append(content);
86: }
87: }
88:
89: public void init(URI node, ImportExportLogger logger)
90: throws Exception {
91: this .node = node;
92: name = null;
93: enteredInDefinition = false;
94: tmpContent = null;
95: libresourceForumService = (LibresourceForumService) Libresource
96: .getService("LibresourceForum");
97: }
98: }
|