Project

General

Profile

« Previous | Next » 

Revision 5f9a4d04

Added by Patrick Plitzner about 6 years ago

Write export to XML file

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/redlist/out/BfnXmlExport.java
7 7
package eu.etaxonomy.cdm.app.redlist.out;
8 8

  
9 9
import java.io.File;
10
import java.io.FileWriter;
11
import java.io.IOException;
10 12

  
11 13
import org.apache.log4j.Logger;
14
import org.jdom2.Document;
15
import org.jdom2.Element;
16
import org.jdom2.output.Format;
17
import org.jdom2.output.XMLOutputter;
12 18

  
13 19
import eu.etaxonomy.cdm.app.common.CdmDestinations;
14 20
import eu.etaxonomy.cdm.app.sdd.ViolaExportActivator;
15 21
import eu.etaxonomy.cdm.database.ICdmDataSource;
16 22
import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
23
import eu.etaxonomy.cdm.io.redlist.bfnXml.BfnXmlConstants;
17 24
import eu.etaxonomy.cdm.io.redlist.bfnXml.out.BfnXmlExportConfigurator;
18 25
import eu.etaxonomy.cdm.io.redlist.bfnXml.out.BfnXmlExportTransformer;
19 26

  
......
27 34

  
28 35
	private static final Logger logger = Logger.getLogger(ViolaExportActivator.class);
29 36

  
37
    protected Document document;
38

  
30 39
	private void invokeExport(String[] args) {
31 40

  
32 41
		ICdmDataSource sourceDb = CdmDestinations.cdm_test_local_mysql();
33 42
		BfnXmlExportTransformer transformer = new BfnXmlExportTransformer();
34 43
		File destination = new File("/home/pplitzner/Rote Listen 2020/doctronic/export/export.xml");
35
		BfnXmlExportConfigurator config = BfnXmlExportConfigurator.NewInstance(destination, sourceDb, transformer);
44
        document = createDocument();
45
		BfnXmlExportConfigurator config = BfnXmlExportConfigurator.NewInstance(destination, sourceDb, transformer, document);
36 46

  
37
		CdmDefaultExport<BfnXmlExportConfigurator> export =
38
			new CdmDefaultExport<BfnXmlExportConfigurator>();
47
		CdmDefaultExport<BfnXmlExportConfigurator> export = new CdmDefaultExport<BfnXmlExportConfigurator>();
39 48

  
40 49
		// invoke export
41 50
		logger.debug("Invoking BfnXml export");
42 51
		export.invoke(config);
43 52

  
53
        outputXML(destination);
54

  
44 55
	}
45 56

  
57
    private void outputXML(File file) {
58
        XMLOutputter xml = new XMLOutputter();
59
        xml.setFormat(Format.getPrettyFormat());
60
        try {
61
            xml.output(document, new FileWriter(file));
62
        } catch (IOException e) {
63
            e.printStackTrace();
64
        }
65
    }
66

  
67
    private Document createDocument(){
68
        Document document = new Document();// create root element
69
        Element rootElement = new Element(BfnXmlConstants.EL_DEB_EXPORT);
70
        document.setRootElement(rootElement);
71
        return document;
72
    }
73

  
46 74
	public static void main(String[] args) {
47 75
		BfnXmlExport export = new BfnXmlExport();
48 76
		export.invokeExport(args);
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/out/BfnXmlExportConfigurator.java
12 12
import java.io.File;
13 13

  
14 14
import org.apache.log4j.Logger;
15
import org.jdom2.Document;
15 16

  
16 17
import eu.etaxonomy.cdm.database.ICdmDataSource;
17 18
import eu.etaxonomy.cdm.io.common.XmlExportConfiguratorBase;
......
30 31
    @SuppressWarnings("unused")
31 32
	private static Logger logger = Logger.getLogger(BfnXmlExportConfigurator.class);
32 33

  
33
	public static BfnXmlExportConfigurator NewInstance(File destination, ICdmDataSource cdmSource, IExportTransformer transformer){
34
			return new BfnXmlExportConfigurator(destination, cdmSource, transformer);
34
    private final Document document;
35

  
36
	public static BfnXmlExportConfigurator NewInstance(File destination, ICdmDataSource cdmSource, IExportTransformer transformer, Document document){
37
			return new BfnXmlExportConfigurator(destination, cdmSource, transformer, document);
35 38
	}
36 39

  
37
	private BfnXmlExportConfigurator(File destination, ICdmDataSource cdmSource, IExportTransformer transformer) {
40
	private BfnXmlExportConfigurator(File destination, ICdmDataSource cdmSource, IExportTransformer transformer, Document document) {
38 41
	    super(destination, cdmSource, transformer);
42
	    this.document = document;
39 43
	}
40 44

  
41 45
	@Override
......
51 55
		return new BfnXmlExportState(this);
52 56
	}
53 57

  
58
    public Document getDocument() {
59
        return document;
60
    }
61

  
54 62
}

Also available in: Unified diff