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.core.FileData;
038:
039: import org.libresource.files.ejb.model.FileResourceValue;
040: import org.libresource.files.interfaces.LibresourceFilesService;
041:
042: import org.libresource.xml.ImportExportLogger;
043: import org.libresource.xml.LibresourceExportHandler;
044: import org.libresource.xml.XmlDumpHelper;
045:
046: import org.xml.sax.ContentHandler;
047:
048: import java.net.URI;
049:
050: import java.text.SimpleDateFormat;
051:
052: /**
053: * LibreSource
054: * @author <a href="mailto:bort@loria.fr">Guillaume Bort</a> - <a href="http://www.inria.fr">INRIA Lorraine</a>
055: */
056: public class FileExportHandler extends LibresourceExportHandler {
057: private URI uri;
058:
059: public FileExportHandler(URI uri) {
060: this .uri = uri;
061: }
062:
063: public void export(ContentHandler handler, ImportExportLogger logger)
064: throws Exception {
065: LibresourceFilesService filesService = (LibresourceFilesService) Libresource
066: .getService("LibresourceFiles");
067: FileResourceValue fileResourceValue = filesService.getFile(uri);
068:
069: XmlDumpHelper.beginElement("files", "file", XmlDumpHelper
070: .getEmptyAttributesSet(), handler);
071:
072: XmlDumpHelper.outputElementWithContent("file", "name",
073: fileResourceValue.getName(), XmlDumpHelper
074: .getEmptyAttributesSet(), handler);
075: XmlDumpHelper.outputElementWithContent("file", "description",
076: fileResourceValue.getDescription(), XmlDumpHelper
077: .getEmptyAttributesSet(), handler);
078: XmlDumpHelper.outputElementWithContent("file", "author",
079: fileResourceValue.getAuthor(), XmlDumpHelper
080: .getEmptyAttributesSet(), handler);
081: XmlDumpHelper.outputElementWithContent("file", "type",
082: fileResourceValue.getType(), XmlDumpHelper
083: .getEmptyAttributesSet(), handler);
084: XmlDumpHelper.outputElementWithContent("file", "size", String
085: .valueOf(fileResourceValue.getSize()), XmlDumpHelper
086: .getEmptyAttributesSet(), handler);
087: XmlDumpHelper.outputElementWithContent("file", "throwEvent",
088: String.valueOf(fileResourceValue.getThrowEvent()),
089: XmlDumpHelper.getEmptyAttributesSet(), handler);
090:
091: XmlDumpHelper.outputElementWithContent("file", "date",
092: Libresource.formatDate(fileResourceValue.getDate()),
093: XmlDumpHelper.getEmptyAttributesSet(), handler);
094:
095: FileData content = filesService.getFileContent(uri, null);
096: XmlDumpHelper.outputElementWithContent("file", "content",
097: content.getInputStream(), XmlDumpHelper
098: .getEmptyAttributesSet(), handler);
099:
100: XmlDumpHelper.endElement("files", "file", handler);
101: }
102: }
|