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.core;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.core.interfaces.LibresourceCoreService;
038:
039: import org.libresource.xml.ImportExportLogger;
040: import org.libresource.xml.LibresourceImportHandler;
041:
042: import org.xml.sax.Attributes;
043:
044: import java.net.URI;
045:
046: import java.text.SimpleDateFormat;
047:
048: import java.util.Date;
049:
050: public class ProjectImportHandler extends LibresourceImportHandler {
051: private URI node;
052: private String name;
053: private String description;
054: private String summary;
055: private String lastEditor;
056: private Date lastEdited;
057: private boolean enteredInDefinition = false;
058: private StringBuffer tmpContent;
059: private LibresourceCoreService libresourceCoreService;
060:
061: public void handleBeginElement(String name, Attributes attributes,
062: ImportExportLogger logger) throws Exception {
063: if (name.equals("libresource:project")) {
064: enteredInDefinition = true;
065: }
066:
067: if (name.equals("project:name")) {
068: tmpContent = new StringBuffer();
069: }
070:
071: if (name.equals("project:description")) {
072: tmpContent = new StringBuffer();
073: }
074:
075: if (name.equals("project:summary")) {
076: lastEdited = Libresource.parseDate(attributes
077: .getValue("lastEdited"));
078: lastEditor = attributes.getValue("lastEditor");
079:
080: tmpContent = new StringBuffer();
081: }
082: }
083:
084: public boolean handleEndElement(String name,
085: ImportExportLogger logger) throws Exception {
086: if (name.equals("libresource:project")) {
087: enteredInDefinition = false;
088: libresourceCoreService.createProject(node, this .name,
089: this .description);
090: libresourceCoreService.editProjectSummary(node,
091: this .summary, lastEditor, lastEdited);
092:
093: return true;
094: }
095:
096: if (name.equals("project:name")) {
097: this .name = tmpContent.toString().trim();
098:
099: return false;
100: }
101:
102: if (name.equals("project:description")) {
103: this .description = tmpContent.toString().trim();
104:
105: return false;
106: }
107:
108: if (name.equals("project:summary")) {
109: this .summary = tmpContent.toString().trim();
110:
111: return false;
112: }
113:
114: return false;
115: }
116:
117: public void handleContent(String content, ImportExportLogger logger)
118: throws Exception {
119: if (tmpContent != null) {
120: tmpContent.append(content);
121: }
122: }
123:
124: public void init(URI node, ImportExportLogger logger)
125: throws Exception {
126: this .node = node;
127: name = null;
128: description = null;
129: summary = null;
130: lastEditor = null;
131: lastEdited = null;
132: enteredInDefinition = false;
133: tmpContent = null;
134: libresourceCoreService = (LibresourceCoreService) Libresource
135: .getService("LibresourceCore");
136: }
137: }
|