minor
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / markup / MarkupImportConfigurator.java
1 /**
2 * Copyright (C) 2009 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.markup;
11
12 import java.net.URI;
13 import java.util.UUID;
14
15 import org.apache.log4j.Logger;
16 import org.springframework.stereotype.Component;
17
18 import eu.etaxonomy.cdm.database.ICdmDataSource;
19 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
20 import eu.etaxonomy.cdm.io.common.XmlImportConfiguratorBase;
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 @Component
26 public class MarkupImportConfigurator extends XmlImportConfiguratorBase<MarkupImportState> implements IImportConfigurator {
27 private static final Logger logger = Logger.getLogger(MarkupImportConfigurator.class);
28
29 public static MarkupImportConfigurator NewInstance(URI uri, ICdmDataSource destination){
30 return new MarkupImportConfigurator(uri, destination);
31 }
32
33 private boolean replaceStandardKeyTitles = true;
34
35 private boolean doTaxa = true;
36
37 private boolean reuseExistingState = false;
38
39 private boolean allowCapitalSpeciesEpithet = false; //set to true if you want to allow specific epithets with capital letter at the beginning. This was allowed by the code for epithets referring to persons such as Beilschmiedia Zenkeri.
40
41 private boolean handlePagesAsDetailWhereNeeded = true; //often details in publications and citations are tagged as pages, not as details. If value is true, pages are handled as details where possible
42
43 private boolean useEditorAsInAuthorWhereNeeded = true; //often the inAuthor is stored as "Editor" in citations, atleast in FM.
44
45 //TODO
46 private static IInputTransformer defaultTransformer = null;
47 private String classificationTitle = "E-Flora Import";
48 private String sourceReferenceTitle = "E-Flora";
49 private UUID defaultLanguageUuid;
50
51 //TODO move to state, but a state gets lost after each import.invoke, so I can't move this information
52 //from the one import to another import in case I run 2 imports in line
53 private UUID lastTaxonUuid;
54
55 //if true, the keys will be printed after they have been created
56 private boolean doPrintKeys = false;
57
58 private MarkupImportState state;
59
60 /* (non-Javadoc)
61 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#makeIoClassList()
62 */
63 protected void makeIoClassList(){
64 ioClassList = new Class[]{
65 MarkupDocumentImport.class
66 };
67 };
68
69 protected MarkupImportConfigurator() {
70 super(defaultTransformer);
71 }
72
73
74 /**
75 *
76 */
77 protected MarkupImportConfigurator(IInputTransformer transformer) {
78 super(transformer);
79 }
80
81
82 /**
83 * @param url
84 * @param destination
85 */
86 protected MarkupImportConfigurator(URI uri, ICdmDataSource destination) {
87 super(defaultTransformer);
88 setSource(uri);
89 setDestination(destination);
90 }
91
92 /**
93 * @param url
94 * @param destination
95 */
96 protected MarkupImportConfigurator(URI uri, ICdmDataSource destination, IInputTransformer transformer) {
97 super(transformer);
98 setSource(uri);
99 setDestination(destination);
100 }
101
102
103 /* (non-Javadoc)
104 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
105 */
106 public MarkupImportState getNewState() {
107 if (this.isReuseExistingState() == true){
108 if (this.state == null){
109 this.state = new MarkupImportState(this);
110 }else{
111 state.reset();
112 }
113 return this.state;
114 }else{
115 return new MarkupImportState(this);
116 }
117
118
119 }
120
121
122 /* (non-Javadoc)
123 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
124 */
125 @Override
126 public Reference getSourceReference() {
127 //TODO
128 if (this.sourceReference == null){
129 logger.warn("getSource Reference not yet fully implemented");
130 sourceReference = ReferenceFactory.newGeneric();
131 sourceReference.setTitleCache(sourceReferenceTitle, true);
132 }
133 return sourceReference;
134 }
135
136
137 /* (non-Javadoc)
138 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
139 */
140 public String getSourceNameString() {
141 if (this.getSource() == null){
142 return null;
143 }else{
144 return this.getSource().toString();
145 }
146 }
147
148
149 public UUID getLastTaxonUuid() {
150 return lastTaxonUuid;
151 }
152
153 public void setLastTaxonUuid(UUID lastTaxonUuid) {
154 this.lastTaxonUuid = lastTaxonUuid;
155 }
156
157 public void setDoPrintKeys(boolean doPrintKeys) {
158 this.doPrintKeys = doPrintKeys;
159 }
160
161 public boolean isDoPrintKeys() {
162 return doPrintKeys;
163 }
164
165 public UUID getDefaultLanguageUuid() {
166 return this.defaultLanguageUuid;
167 }
168
169 public void setDefaultLanguageUuid(UUID defaultLanguageUuid) {
170 this.defaultLanguageUuid = defaultLanguageUuid;
171 }
172
173 public boolean isDoTaxa() {
174 return doTaxa;
175 }
176 public void setDoTaxa(boolean doTaxa) {
177 this.doTaxa = doTaxa;
178 }
179
180 public void setReplaceStandardKeyTitles(boolean replaceStandardKeyTitles) {
181 this.replaceStandardKeyTitles = replaceStandardKeyTitles;
182 }
183
184 public boolean isReplaceStandardKeyTitles() {
185 return replaceStandardKeyTitles;
186 }
187
188 /**
189 * If true, the state is saved in the configurator between 2 imports using this same configurator.
190 * Use with care as you may run into memory issues or also data consistency issues otherwise.
191 * This value must be set before getNewState is called for the <b>first</b> time. The feature is
192 * experimental.
193 * @return if reuse existing state is set to true.
194 */
195 public boolean isReuseExistingState() {
196 return reuseExistingState;
197 }
198
199 /**
200 * @see #isReuseExistingState()
201 * @param reuseExistingState
202 */
203 public void setReuseExistingState(boolean reuseExistingState) {
204 this.reuseExistingState = reuseExistingState;
205 }
206
207 /**
208 * If {@link #isReuseExistingState()} is true, this method returns the state.
209 * This is an experimental workaround for Markup import. The functionality
210 * should better be moved to CdmImportBase somewhere.
211 * @return
212 */
213 public MarkupImportState getState() {
214 return state;
215 }
216
217 public boolean isAllowCapitalSpeciesEpithet() {
218 return allowCapitalSpeciesEpithet;
219 }
220
221 public void setAllowCapitalSpeciesEpithet(boolean allowCapitalSpeciesEpithet) {
222 this.allowCapitalSpeciesEpithet = allowCapitalSpeciesEpithet;
223 }
224
225 public boolean isHandlePagesAsDetailWhereNeeded() {
226 return this.handlePagesAsDetailWhereNeeded;
227 }
228
229 public void setHandlePagesAsDetailWhereNeeded(boolean handlePagesAsDetailWhereNeeded) {
230 this.handlePagesAsDetailWhereNeeded = handlePagesAsDetailWhereNeeded;
231 }
232
233 public boolean isUseEditorAsInAuthorWhereNeeded() {
234 return useEditorAsInAuthorWhereNeeded;
235 }
236
237 public void setUseEditorAsInAuthorWhereNeeded(boolean useEditorAsInAuthorWhereNeeded) {
238 this.useEditorAsInAuthorWhereNeeded = useEditorAsInAuthorWhereNeeded;
239 }
240
241
242 }