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.so6.server.ls;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.core.FileData;
038:
039: import org.libresource.kernel.KernelConstants;
040: import org.libresource.kernel.interfaces.KernelService;
041:
042: import org.libresource.so6.server.ls.ejb.model.SynchronizerResourceValue;
043: import org.libresource.so6.server.ls.interfaces.LibresourceSynchronizerService;
044:
045: import org.libresource.xml.ImportExportLogger;
046: import org.libresource.xml.LibresourceExportHandler;
047: import org.libresource.xml.XmlDumpHelper;
048:
049: import org.xml.sax.ContentHandler;
050:
051: import java.net.URI;
052:
053: import java.text.SimpleDateFormat;
054:
055: /**
056: * Synchronizer XML export handler
057: * @author <a href="mailto:jourdain@loria.fr">Sebastien Jourdain</a> - <a href="http://www.inria.fr">INRIA Lorraine</a>
058: */
059: public class SynchronizerExportHandler extends LibresourceExportHandler {
060: private URI uri;
061:
062: public SynchronizerExportHandler(URI userUri) {
063: this .uri = userUri;
064: }
065:
066: public void export(ContentHandler handler, ImportExportLogger logger)
067: throws Exception {
068: KernelService kernelService = (KernelService) Libresource
069: .getService(KernelConstants.SERVICE);
070: LibresourceSynchronizerService synchronizerService = (LibresourceSynchronizerService) Libresource
071: .getService(LibresourceSynchronizerConstants.SERVICE);
072: SynchronizerResourceValue synchronizerResourceValue = synchronizerService
073: .getSynchronizer(uri);
074:
075: XmlDumpHelper.beginElement("so6", "queue", XmlDumpHelper
076: .getEmptyAttributesSet(), handler);
077:
078: XmlDumpHelper.beginElement("so6", "synchronizer", XmlDumpHelper
079: .getEmptyAttributesSet(), handler);
080:
081: XmlDumpHelper.outputElementWithContent("synchronizer", "name",
082: synchronizerResourceValue.getName(), XmlDumpHelper
083: .getEmptyAttributesSet(), handler);
084: XmlDumpHelper.outputElementWithContent("synchronizer",
085: "description", synchronizerResourceValue
086: .getDescription(), XmlDumpHelper
087: .getEmptyAttributesSet(), handler);
088: XmlDumpHelper.outputElementWithContent("synchronizer",
089: "extensions", synchronizerResourceValue
090: .getBinaryExtention(), XmlDumpHelper
091: .getEmptyAttributesSet(), handler);
092: XmlDumpHelper.outputElementWithContent("synchronizer",
093: "encoding",
094: synchronizerResourceValue.getFileEncoding(),
095: XmlDumpHelper.getEmptyAttributesSet(), handler);
096:
097: XmlDumpHelper.endElement("so6", "synchronizer", handler);
098:
099: // Add patch
100: // Check security
101: if (kernelService.checkSecurity(uri,
102: KernelConstants.SECURITY_READ)) {
103: PatchBean[] patchs = synchronizerService
104: .listSynchronizerPatch(uri, 0);
105:
106: for (int i = 0; i < patchs.length; i++) {
107: PatchBean patch = patchs[i];
108: XmlDumpHelper.beginElement("so6", "patch",
109: XmlDumpHelper.getEmptyAttributesSet(), handler);
110: XmlDumpHelper.outputElementWithContent("patch",
111: "wsName", patch.getWsName(), XmlDumpHelper
112: .getEmptyAttributesSet(), handler);
113: XmlDumpHelper.outputElementWithContent("patch",
114: "comment", patch.getComment(), XmlDumpHelper
115: .getEmptyAttributesSet(), handler);
116: XmlDumpHelper
117: .outputElementWithContent("patch", "date",
118: Libresource.formatDate(patch
119: .getCreationDate()),
120: XmlDumpHelper.getEmptyAttributesSet(),
121: handler);
122: XmlDumpHelper.outputElementWithContent("patch", "time",
123: Long
124: .toString(patch.getCreationDate()
125: .getTime()), XmlDumpHelper
126: .getEmptyAttributesSet(), handler);
127: XmlDumpHelper.outputElementWithContent("patch",
128: "fromTicket", Long.toString(patch
129: .getFromTicket()), XmlDumpHelper
130: .getEmptyAttributesSet(), handler);
131: XmlDumpHelper.outputElementWithContent("patch",
132: "toTicket", Long.toString(patch.getToTicket()),
133: XmlDumpHelper.getEmptyAttributesSet(), handler);
134: XmlDumpHelper.outputElementWithContent("patch", "size",
135: Long.toString(patch.getPatchSize()),
136: XmlDumpHelper.getEmptyAttributesSet(), handler);
137:
138: // file content
139: FileData file = synchronizerService.getPatch(uri, patch
140: .getFromTicket(), patch.getToTicket());
141: XmlDumpHelper.outputElementWithContent("patch", "file",
142: file.getInputStream(), XmlDumpHelper
143: .getEmptyAttributesSet(), handler);
144: XmlDumpHelper.endElement("so6", "patch", handler);
145: }
146: }
147:
148: XmlDumpHelper.endElement("so6", "queue", handler);
149: }
150: }
|