1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.io.dwca.out;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.springframework.stereotype.Component;
|
16
|
|
17
|
/**
|
18
|
* @author a.mueller
|
19
|
* @created 20.04.2011
|
20
|
*/
|
21
|
@Component
|
22
|
public class DwcaZipExport extends DwcaExportBase {
|
23
|
private static final Logger logger = Logger.getLogger(DwcaZipExport.class);
|
24
|
|
25
|
/**
|
26
|
* Constructor
|
27
|
*/
|
28
|
public DwcaZipExport() {
|
29
|
super();
|
30
|
this.ioName = this.getClass().getSimpleName();
|
31
|
}
|
32
|
|
33
|
/** Retrieves the MetaData for a Darwin Core Archive File.
|
34
|
* @param exImpConfig
|
35
|
* @param dbname
|
36
|
* @param filename
|
37
|
*/
|
38
|
@Override
|
39
|
protected void doInvoke(DwcaTaxExportState state){
|
40
|
if (state.isZip()){
|
41
|
try {
|
42
|
state.closeZip();
|
43
|
} catch (IOException e) {
|
44
|
throw new RuntimeException(e);
|
45
|
}
|
46
|
}
|
47
|
// DwcaTaxExportConfigurator config = state.getConfig();
|
48
|
//
|
49
|
// String zipFileName = "dwca.zip";
|
50
|
// String filePath = config.getDestinationNameString();
|
51
|
// String zipFullFileName = filePath + File.separatorChar + zipFileName;
|
52
|
//
|
53
|
// ZipOutputStream zos = null;
|
54
|
// try {
|
55
|
// zos = new ZipOutputStream( new FileOutputStream(zipFullFileName) ) ;
|
56
|
//
|
57
|
// for (DwcaMetaDataRecord record : state.getMetaRecords()){
|
58
|
// try {
|
59
|
// String fileLocation = record.getFileLocation();
|
60
|
// File file = new File(filePath + File.separatorChar + fileLocation);
|
61
|
// ZipEntry newEntry = new ZipEntry(fileLocation);
|
62
|
// zos.putNextEntry(newEntry);
|
63
|
//
|
64
|
// BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
|
65
|
// while (bis.available() > 0) {
|
66
|
// zos.write(bis.read());
|
67
|
// }
|
68
|
// zos.closeEntry();
|
69
|
// bis.close();
|
70
|
// boolean wasDeleted = file.delete();
|
71
|
// logger.debug(wasDeleted); //doesn't work on my machine
|
72
|
// } catch (Exception e) {
|
73
|
// //TODO finally is not called anymore
|
74
|
// throw new IOException(e);
|
75
|
// }
|
76
|
// }
|
77
|
//
|
78
|
// zos.finish();
|
79
|
// zos.close();
|
80
|
//
|
81
|
// } catch (IOException e) {
|
82
|
// try {
|
83
|
// if(zos!=null) zos.close();
|
84
|
// } catch(Exception ex){
|
85
|
//
|
86
|
// }
|
87
|
// e.printStackTrace();
|
88
|
// //TODO finally is not called anymore
|
89
|
// throw new RuntimeException(e);
|
90
|
// } finally {
|
91
|
// try {
|
92
|
// if(zos!=null) zos.close();
|
93
|
// } catch(Exception ex){
|
94
|
//
|
95
|
// }
|
96
|
// }
|
97
|
|
98
|
|
99
|
return;
|
100
|
}
|
101
|
|
102
|
|
103
|
|
104
|
@Override
|
105
|
protected boolean doCheck(DwcaTaxExportState state) {
|
106
|
boolean result = true;
|
107
|
logger.warn("No check implemented for " + this.ioName);
|
108
|
return result;
|
109
|
}
|
110
|
|
111
|
|
112
|
/* (non-Javadoc)
|
113
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
|
114
|
*/
|
115
|
@Override
|
116
|
protected boolean isIgnore(DwcaTaxExportState state) {
|
117
|
return ! state.isZip();
|
118
|
}
|
119
|
|
120
|
}
|