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.survey;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.survey.ejb.model.SurveyResourceValue;
038: import org.libresource.survey.interfaces.LibresourceSurveyService;
039:
040: import org.libresource.xml.ImportExportLogger;
041: import org.libresource.xml.LibresourceExportHandler;
042: import org.libresource.xml.XmlDumpAttributes;
043: import org.libresource.xml.XmlDumpHelper;
044:
045: import org.xml.sax.ContentHandler;
046:
047: import java.net.URI;
048:
049: import java.text.SimpleDateFormat;
050:
051: import java.util.HashMap;
052: import java.util.Iterator;
053:
054: /**
055: * LibreSource
056: * @author <a href="mailto:jouille@loria.fr">Florent Jouille</a>
057: */
058: public class SurveyExportHandler extends LibresourceExportHandler {
059: private URI uri;
060:
061: public SurveyExportHandler(URI uri) {
062: this .uri = uri;
063: }
064:
065: public void export(ContentHandler handler, ImportExportLogger logger)
066: throws Exception {
067: LibresourceSurveyService surveyService = (LibresourceSurveyService) Libresource
068: .getService("LibresourceSurvey");
069: SurveyResourceValue surveyResourceValue = surveyService
070: .getSurvey(uri);
071:
072: XmlDumpAttributes attributes = new XmlDumpAttributes();
073: attributes.put("creation", Libresource
074: .formatDate(surveyResourceValue.getCreationDate()));
075: attributes.put("lastVote", Libresource
076: .formatDate(surveyResourceValue.getLastVoteDate()));
077:
078: XmlDumpHelper.beginElement("survey", "survey", XmlDumpHelper
079: .generateAttributesSet(attributes), handler);
080:
081: XmlDumpHelper.outputElementWithContent("survey", "question",
082: surveyResourceValue.getQuestion(), XmlDumpHelper
083: .getEmptyAttributesSet(), handler);
084: XmlDumpHelper.outputElementWithContent("survey", "votersList",
085: surveyResourceValue.getVotersList(), XmlDumpHelper
086: .getEmptyAttributesSet(), handler);
087: XmlDumpHelper.outputElementWithContent("survey", "opening",
088: surveyResourceValue.getState(), XmlDumpHelper
089: .getEmptyAttributesSet(), handler);
090: XmlDumpHelper.outputElementWithContent("survey", "displayMode",
091: surveyResourceValue.getDisplayMode(), XmlDumpHelper
092: .getEmptyAttributesSet(), handler);
093:
094: HashMap options = surveyResourceValue.getOptions();
095:
096: if (options != null) {
097: for (Iterator i = options.keySet().iterator(); i.hasNext();) {
098: String key = (String) i.next();
099: Option option = (Option) options.get(key);
100: XmlDumpHelper.beginElement("survey", "option",
101: XmlDumpHelper.getEmptyAttributesSet(), handler);
102: XmlDumpHelper.outputElementWithContent("option",
103: "choice", option.getChoice(), XmlDumpHelper
104: .getEmptyAttributesSet(), handler);
105: XmlDumpHelper.outputElementWithContent("option",
106: "nbVotes", new Integer(option.getNbVote())
107: .toString(), XmlDumpHelper
108: .getEmptyAttributesSet(), handler);
109: XmlDumpHelper.endElement("survey", "option", handler);
110: }
111: }
112:
113: XmlDumpHelper.endElement("survey", "survey", handler);
114: }
115: }
|