Project

General

Profile

Download (2.18 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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
package eu.etaxonomy.cdm.io.dwca.out;
10

    
11
import java.io.IOException;
12
import java.io.PrintWriter;
13

    
14
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
15
import org.springframework.stereotype.Component;
16

    
17
/**
18
 * Final result processor for Darwin Core Archive exports.
19
 *
20
 * @author a.mueller
21
 * @since 25.06.2017
22
 *
23
 */
24
@Component
25
public class DwcaResultWriter extends DwcaExportBase {
26

    
27
    private static final long serialVersionUID = -1657568483721887287L;
28
    @SuppressWarnings("unused")
29
    private static final Logger logger = LogManager.getLogger(DwcaDescriptionExport.class);
30

    
31

    
32
    /**
33
     * {@inheritDoc}
34
     */
35
    @Override
36
    protected void doInvoke(DwcaTaxExportState state) {
37
        addReport(state);
38
        closeZip(state);
39
        state.getProcessor().createFinalResult();
40
    }
41

    
42
    /**
43
     * @param state
44
     */
45
    protected void addReport(DwcaTaxExportState state) {
46
        if (state.getConfig().getDestination() != null){
47
            try {
48
                StringBuffer report = state.getResult().createReport();
49
                PrintWriter writer = createPrintWriter(state, DwcaTaxExportFile.REPORT);
50
                writer.print(report.toString());
51
                writer.flush();
52

    
53
            } catch (IOException e) {
54
                state.getResult().addError("Unexpected exception when trying to add export report.");
55
            }
56
        }
57
    }
58

    
59
    /**
60
     * @param state
61
     */
62
    protected void closeZip(DwcaTaxExportState state) {
63
        if (state.isZip()){
64
            try {
65
                state.closeZip();
66
            } catch (IOException e) {
67
                throw new RuntimeException(e);
68
            }
69
        }
70
    }
71

    
72
    /**
73
     * {@inheritDoc}
74
     */
75
    @Override
76
    protected boolean doCheck(DwcaTaxExportState state) {
77
        return false;
78
    }
79

    
80

    
81
    /**
82
     * {@inheritDoc}
83
     */
84
    @Override
85
    protected boolean isIgnore(DwcaTaxExportState state) {
86
        return false;
87
    }
88

    
89
}
(20-20/33)