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.kernel.KernelConstants;
038: import org.libresource.kernel.interfaces.KernelService;
039:
040: import org.libresource.so6.server.ls.interfaces.LibresourceSynchronizerService;
041:
042: import org.libresource.xml.ImportExportLogger;
043: import org.libresource.xml.LibresourceImportHandler;
044:
045: import org.xml.sax.Attributes;
046:
047: import java.net.URI;
048:
049: import java.util.Date;
050:
051: /**
052: * WsConnection XML Import handler
053: * @author <a href="mailto:jourdain@artenum.com">Sebastien Jourdain</a> - <a href="http://www.artenum.com">Artenum</a>
054: */
055: public class WsConnectionImportHandler extends LibresourceImportHandler {
056: private URI node;
057: private String name;
058: private String manager;
059: private String wscPath;
060: private Date lastSynchro;
061: private long lastTicket;
062: private String wsId;
063:
064: // service
065: private LibresourceSynchronizerService synchronizerService;
066: private KernelService kernelService;
067:
068: // tmp
069: private StringBuffer tmpContent;
070:
071: public void handleBeginElement(String name, Attributes attributes,
072: ImportExportLogger logger) throws Exception {
073: tmpContent = new StringBuffer();
074: }
075:
076: public boolean handleEndElement(String name,
077: ImportExportLogger logger) throws Exception {
078: //System.out.println("> " + name + "\n" + tmpContent.toString().trim());
079: if (name.equals("so6:wsc")) {
080: URI parentURI = new URI(node.toString().substring(0,
081: node.toString().lastIndexOf("/")));
082: synchronizerService.createWorkspace(this .wsId);
083:
084: String newUri = synchronizerService
085: .createWorkspaceConnection(parentURI, this .wsId,
086: this .name, this .wscPath);
087: kernelService.deleteURI(node);
088: kernelService.move(new URI(newUri), node);
089: synchronizerService.editWorkspaceConnection(node,
090: this .name, this .wscPath, this .manager);
091: synchronizerService.updateWorkspaceConnectionTicket(node,
092: lastTicket, lastSynchro);
093:
094: return true;
095: }
096:
097: if (name.equals("wsc:name")) {
098: this .name = tmpContent.toString().trim();
099:
100: return false;
101: }
102:
103: if (name.equals("wsc:manager")) {
104: this .manager = new URI(tmpContent.toString().trim())
105: .getPath();
106:
107: return false;
108: }
109:
110: if (name.equals("wsc:wsc-path")) {
111: this .wscPath = tmpContent.toString().trim();
112:
113: return false;
114: }
115:
116: if (name.equals("wsc:last-ticket")) {
117: this .lastTicket = Long.parseLong(tmpContent.toString()
118: .trim());
119:
120: return false;
121: }
122:
123: if (name.equals("wsc:ws-id")) {
124: this .wsId = tmpContent.toString().trim();
125:
126: return false;
127: }
128:
129: if (name.equals("wsc:last-synchro")) {
130: this .lastSynchro = Libresource.parseDate(tmpContent
131: .toString().trim());
132:
133: return false;
134: }
135:
136: return false;
137: }
138:
139: public void init(URI node, ImportExportLogger logger)
140: throws Exception {
141: this .node = node;
142: name = "";
143: manager = "";
144: wscPath = "";
145: lastTicket = 0;
146: lastSynchro = null;
147: wsId = "";
148: tmpContent = null;
149: synchronizerService = (LibresourceSynchronizerService) Libresource
150: .getService(LibresourceSynchronizerConstants.SERVICE);
151: kernelService = (KernelService) Libresource
152: .getService(KernelConstants.SERVICE);
153: }
154:
155: public void handleContent(String content, ImportExportLogger logger)
156: throws Exception {
157: if (tmpContent != null) {
158: tmpContent.append(content);
159: } else {
160: tmpContent = new StringBuffer(content);
161: }
162: }
163: }
|