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.files;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.files.interfaces.LibresourceFilesService;
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 DropBoxImportHandler extends LibresourceImportHandler {
047: private URI node;
048: private String name;
049: private String description;
050: private boolean enteredInDefinition = false;
051: private StringBuffer tmpContent;
052: private LibresourceFilesService libresourceFilesService;
053:
054: public void handleBeginElement(String name, Attributes attributes,
055: ImportExportLogger logger) throws Exception {
056: if (name.equals("files:dropbox")) {
057: enteredInDefinition = true;
058: }
059:
060: if (name.equals("dropbox:name")) {
061: tmpContent = new StringBuffer();
062: }
063:
064: if (name.equals("dropbox:description")) {
065: tmpContent = new StringBuffer();
066: }
067: }
068:
069: public boolean handleEndElement(String name,
070: ImportExportLogger logger) throws Exception {
071: if (name.equals("files:dropbox")) {
072: enteredInDefinition = false;
073: libresourceFilesService.createDropBox(node, this .name,
074: this .description);
075:
076: return true;
077: }
078:
079: if (name.equals("dropbox:name")) {
080: this .name = tmpContent.toString().trim();
081:
082: return false;
083: }
084:
085: if (name.equals("dropbox:description")) {
086: this .description = tmpContent.toString().trim();
087:
088: return false;
089: }
090:
091: return false;
092: }
093:
094: public void handleContent(String content, ImportExportLogger logger)
095: throws Exception {
096: if (tmpContent != null) {
097: tmpContent.append(content);
098: }
099: }
100:
101: public void init(URI node, ImportExportLogger logger)
102: throws Exception {
103: this .node = node;
104: name = null;
105: description = null;
106: enteredInDefinition = false;
107: tmpContent = null;
108: libresourceFilesService = (LibresourceFilesService) Libresource
109: .getService("LibresourceFiles");
110: }
111: }
|