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.bugtracker;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.bugtracker.interfaces.LibresourceBugTrackerService;
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 IssueImportHandler extends LibresourceImportHandler {
051: private URI node;
052: private int issueId;
053: private String summary;
054: private String body;
055: private String author;
056: private String type;
057: private String priority;
058: private String resolution;
059: private Date creationDate;
060: private Date updateDate;
061: private String assignee;
062: private boolean enteredInDefinition = false;
063: private StringBuffer tmpContent;
064: private LibresourceBugTrackerService libresourceBugTrackerService;
065: private boolean contentMode;
066:
067: public void handleBeginElement(String name, Attributes attributes,
068: ImportExportLogger logger) throws Exception {
069: if (name.equals("bugtracker:issue")) {
070: enteredInDefinition = true;
071: }
072:
073: if (name.equals("issue:issueId")) {
074: tmpContent = new StringBuffer();
075: }
076:
077: if (name.equals("issue:summary")) {
078: tmpContent = new StringBuffer();
079: }
080:
081: if (name.equals("issue:body")) {
082: tmpContent = new StringBuffer();
083: }
084:
085: if (name.equals("issue:author")) {
086: tmpContent = new StringBuffer();
087: }
088:
089: if (name.equals("issue:type")) {
090: tmpContent = new StringBuffer();
091: }
092:
093: if (name.equals("issue:priority")) {
094: tmpContent = new StringBuffer();
095: }
096:
097: if (name.equals("issue:resolution")) {
098: tmpContent = new StringBuffer();
099: }
100:
101: if (name.equals("issue:creationDate")) {
102: tmpContent = new StringBuffer();
103: }
104:
105: if (name.equals("issue:updateDate")) {
106: tmpContent = new StringBuffer();
107: }
108:
109: if (name.equals("issue:assignee")) {
110: tmpContent = new StringBuffer();
111: }
112: }
113:
114: public boolean handleEndElement(String name,
115: ImportExportLogger logger) throws Exception {
116: if (name.equals("bugtracker:issue")) {
117: enteredInDefinition = false;
118: libresourceBugTrackerService.createIssue(node,
119: this .issueId, this .summary, this .body, this .type,
120: this .priority, this .resolution, this .author,
121: this .assignee, this .creationDate, this .updateDate);
122:
123: return true;
124: }
125:
126: if (name.equals("issue:issueId")) {
127: try {
128: this .issueId = Integer.parseInt(tmpContent.toString()
129: .trim());
130: } catch (NumberFormatException e) {
131: this .issueId = -1;
132: }
133:
134: return false;
135: }
136:
137: if (name.equals("issue:summary")) {
138: this .summary = tmpContent.toString().trim();
139:
140: return false;
141: }
142:
143: if (name.equals("issue:body")) {
144: this .body = tmpContent.toString().trim();
145:
146: return false;
147: }
148:
149: if (name.equals("issue:author")) {
150: this .author = tmpContent.toString().trim();
151:
152: return false;
153: }
154:
155: if (name.equals("issue:type")) {
156: this .type = tmpContent.toString().trim();
157:
158: return false;
159: }
160:
161: if (name.equals("issue:priority")) {
162: this .priority = tmpContent.toString().trim();
163:
164: return false;
165: }
166:
167: if (name.equals("issue:resolution")) {
168: this .resolution = tmpContent.toString().trim();
169:
170: return false;
171: }
172:
173: if (name.equals("issue:creationDate")) {
174: this .creationDate = Libresource.parseDate(tmpContent
175: .toString().trim());
176:
177: return false;
178: }
179:
180: if (name.equals("issue:updateDate")) {
181: this .updateDate = Libresource.parseDate(tmpContent
182: .toString().trim());
183:
184: return false;
185: }
186:
187: if (name.equals("issue:assignee")) {
188: this .assignee = tmpContent.toString().trim();
189:
190: return false;
191: }
192:
193: return false;
194: }
195:
196: public void handleContent(String content, ImportExportLogger logger)
197: throws Exception {
198: if (tmpContent != null) {
199: tmpContent.append(content);
200: }
201: }
202:
203: public void init(URI node, ImportExportLogger logger)
204: throws Exception {
205: this .node = node;
206: issueId = -1;
207: summary = null;
208: body = null;
209: author = null;
210: type = null;
211: priority = null;
212: resolution = null;
213: creationDate = null;
214: updateDate = null;
215: assignee = null;
216: libresourceBugTrackerService = (LibresourceBugTrackerService) Libresource
217: .getService("LibresourceBugTracker");
218: }
219: }
|