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.reference.ris.in;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
import java.io.InputStream;
|
13
|
import java.io.InputStreamReader;
|
14
|
import java.net.MalformedURLException;
|
15
|
import java.net.URI;
|
16
|
import java.net.URL;
|
17
|
|
18
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
19
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
20
|
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
|
21
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
22
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
23
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
24
|
|
25
|
/**
|
26
|
* @author a.mueller
|
27
|
* @date 11.05.2017
|
28
|
*
|
29
|
*/
|
30
|
public class RisReferenceImportConfigurator
|
31
|
extends ImportConfiguratorBase<RisReferenceImportState, InputStreamReader>{
|
32
|
|
33
|
private static final long serialVersionUID = -5982826645441621962L;
|
34
|
private static IInputTransformer defaultTransformer = null;
|
35
|
|
36
|
/**
|
37
|
* @param uri
|
38
|
* @param object
|
39
|
* @return
|
40
|
* @throws IOException
|
41
|
* @throws MalformedURLException
|
42
|
*/
|
43
|
public static IImportConfigurator NewInstance(URI uri, ICdmDataSource cdm) throws MalformedURLException, IOException {
|
44
|
return NewInstance(uri.toURL(), cdm);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* @param url
|
49
|
* @param object
|
50
|
* @return
|
51
|
* @throws IOException
|
52
|
*/
|
53
|
public static IImportConfigurator NewInstance(URL url, ICdmDataSource cdm) throws IOException {
|
54
|
InputStream stream = url.openStream();
|
55
|
InputStreamReader reader = new InputStreamReader(stream);
|
56
|
RisReferenceImportConfigurator result = new RisReferenceImportConfigurator(reader, cdm);
|
57
|
return result;
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* @param transformer
|
62
|
*/
|
63
|
protected RisReferenceImportConfigurator() {
|
64
|
super(defaultTransformer);
|
65
|
}
|
66
|
|
67
|
protected RisReferenceImportConfigurator(InputStreamReader source, ICdmDataSource cdm) {
|
68
|
super(defaultTransformer);
|
69
|
this.setSource(source);
|
70
|
this.setDestination(cdm);
|
71
|
}
|
72
|
|
73
|
|
74
|
/**
|
75
|
* {@inheritDoc}
|
76
|
*/
|
77
|
@Override
|
78
|
public RisReferenceImportState getNewState() {
|
79
|
return new RisReferenceImportState(this);
|
80
|
}
|
81
|
|
82
|
|
83
|
/**
|
84
|
* {@inheritDoc}
|
85
|
*/
|
86
|
@Override
|
87
|
protected void makeIoClassList() {
|
88
|
ioClassList = new Class[]{
|
89
|
RisReferenceImport.class
|
90
|
};
|
91
|
}
|
92
|
|
93
|
|
94
|
/**
|
95
|
* {@inheritDoc}
|
96
|
*/
|
97
|
@Override
|
98
|
public Reference getSourceReference() {
|
99
|
if (this.sourceReference == null){
|
100
|
sourceReference = ReferenceFactory.newGeneric();
|
101
|
if (this.getSource() == null){
|
102
|
sourceReference.setTitleCache("RIS Reference Import " + getDateString(), true);
|
103
|
}else{
|
104
|
sourceReference.setTitleCache(getSource().toString(), true);
|
105
|
}
|
106
|
}
|
107
|
return sourceReference;
|
108
|
}
|
109
|
|
110
|
|
111
|
}
|