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.wiki;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.wiki.ejb.model.PageResourceValue;
038: import org.libresource.wiki.interfaces.LibresourceWikiService;
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.Iterator;
052: import java.util.TreeSet;
053:
054: /**
055: * LibreSource
056: * @author <a href="mailto:bort@loria.fr">Guillaume Bort</a> - <a href="http://www.inria.fr">INRIA Lorraine</a>
057: */
058: public class PageExportHandler extends LibresourceExportHandler {
059: private URI uri;
060:
061: public PageExportHandler(URI uri) {
062: this .uri = uri;
063: }
064:
065: public void export(ContentHandler handler, ImportExportLogger logger)
066: throws Exception {
067: LibresourceWikiService wikiService = (LibresourceWikiService) Libresource
068: .getService(WikiConstants.SERVICE);
069: PageResourceValue pageResourceValue = wikiService.getPage(uri);
070:
071: XmlDumpAttributes attributes = new XmlDumpAttributes();
072: attributes.put("lastEditor", pageResourceValue.getLastEditor());
073:
074: if (pageResourceValue.getLastEdited() != null) {
075: attributes.put("lastEdited", Libresource
076: .formatDate(pageResourceValue.getLastEdited()));
077: } else {
078: attributes.put("lastEdited", "");
079: }
080:
081: XmlDumpHelper.beginElement("wiki", "page", XmlDumpHelper
082: .generateAttributesSet(attributes), handler);
083:
084: XmlDumpHelper.outputElementWithContent("page", "name",
085: pageResourceValue.getName(), XmlDumpHelper
086: .getEmptyAttributesSet(), handler);
087: XmlDumpHelper.outputElementWithContent("page", "content",
088: pageResourceValue.getContent(), XmlDumpHelper
089: .getEmptyAttributesSet(), handler);
090: XmlDumpHelper.outputElementWithContent("page", "versionable",
091: String.valueOf(pageResourceValue.getVersionable()),
092: XmlDumpHelper.getEmptyAttributesSet(), handler);
093:
094: // versions
095: if (pageResourceValue.getVersionable()) {
096: XmlDumpHelper.beginElement("page", "history", XmlDumpHelper
097: .generateAttributesSet(new XmlDumpAttributes()),
098: handler);
099:
100: TreeSet history = wikiService.getPageHistory(uri, 0);
101:
102: for (Iterator i = history.iterator(); i.hasNext();) {
103: HistoryEntry entry = (HistoryEntry) i.next();
104: XmlDumpAttributes entryAttributes = new XmlDumpAttributes();
105: entryAttributes.put("id", new Integer(entry.getId()));
106: entryAttributes.put("user", entry.getUser());
107: entryAttributes.put("date", Libresource
108: .formatDate(entry.getDate()));
109: XmlDumpHelper
110: .beginElement(
111: "history",
112: "entry",
113: XmlDumpHelper
114: .generateAttributesSet(entryAttributes),
115: handler);
116: XmlDumpHelper.outputElementWithContent("entry",
117: "comment", entry.getComment(), XmlDumpHelper
118: .getEmptyAttributesSet(), handler);
119: XmlDumpHelper.outputElementWithContent("entry",
120: "content", entry.getContent(), XmlDumpHelper
121: .getEmptyAttributesSet(), handler);
122: XmlDumpHelper.endElement("history", "entry", handler);
123: }
124:
125: XmlDumpHelper.endElement("page", "history", handler);
126: }
127:
128: XmlDumpHelper.endElement("wiki", "page", handler);
129: }
130: }
|