01: /*
02: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
03: * Copyright (C) 2007 Mathieu BENOIT <mathieu-benoit@hotmail.fr>
04: *
05: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
06: * General Public License as published by the Free Software Foundation; either version 2 of the License,
07: * or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU General Public License for more details.
12: *
13: * You should have received a copy of the GNU General Public License along with this program; if not,
14: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15: */
16:
17: package wilos.tools.imports.epfcomposer;
18:
19: import java.io.File;
20: import java.util.zip.ZipException;
21:
22: import wilos.model.spem2.process.Process;
23: import wilos.tools.imports.IProcessImportManager;
24: import wilos.tools.imports.epfcomposer.parser.XMLParser;
25: import wilos.tools.imports.epfcomposer.utils.XMLUtils;
26: import wilos.tools.imports.epfcomposer.utils.ZIPUtils;
27:
28: public class EpfComposerProcessImportManager implements
29: IProcessImportManager {
30:
31: /**
32: * Getter of ToolsName
33: */
34: public String getToolsName() {
35: return "EPF Composer";
36: }
37:
38: public String getToolsVersion() {
39: return "1.0.2";
40: }
41:
42: /**
43: * importProcess : return a Process Object and if the param is a zip file,
44: * it is extracted automatically in a repertory named by the guid of the
45: * Process
46: *
47: * @param filePath :
48: * can be a XML File or a ZIP File
49: * @return a Process Object
50: */
51: public Process importProcess(String filePath, String pathToExtract) {
52: Process p = null;
53: File f = new File(filePath);
54: if (XMLUtils.isExtension(filePath, "zip")) {
55: try {
56: ZIPUtils z = new ZIPUtils(f);
57: if (!z.isEmpty()) {
58: p = XMLParser.getProcess(f);
59: if (p != null) {
60: if (pathToExtract.length() != 0
61: && pathToExtract.charAt(pathToExtract
62: .length() - 1) != File.separatorChar) {
63: pathToExtract += File.separatorChar;
64: }
65: z.extract(pathToExtract + p.getGuid()
66: + File.separatorChar);
67: }
68: }
69: } catch (ZipException e) {
70:
71: }
72: } else {
73: p = XMLParser.getProcess(f);
74: }
75: return p;
76: }
77: }
|