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.print;
|
11
|
|
12
|
import java.io.File;
|
13
|
import java.io.Serializable;
|
14
|
import java.net.MalformedURLException;
|
15
|
import java.net.URL;
|
16
|
import java.util.ArrayList;
|
17
|
import java.util.List;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.jdom.Element;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
24
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
25
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
26
|
import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor;
|
27
|
import eu.etaxonomy.cdm.print.out.IPublishOutputModule;
|
28
|
|
29
|
/**
|
30
|
* This class holds the complete configuration for the print publishing process.
|
31
|
* All aspects of the process are defined here.
|
32
|
*
|
33
|
* @author n.hoffmann
|
34
|
* @since Aug 3, 2010
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
public class PublishConfigurator implements Serializable {
|
38
|
|
39
|
private static final Logger logger = Logger
|
40
|
.getLogger(PublishConfigurator.class);
|
41
|
|
42
|
private static final long serialVersionUID = 4896190792717383839L;
|
43
|
|
44
|
private ICdmRepository applicationConfiguration;
|
45
|
|
46
|
private URL webserviceUrl;
|
47
|
|
48
|
private List<Element> selectedTaxonNodeElements = new ArrayList<Element>();
|
49
|
|
50
|
private boolean doSynonymy = true;
|
51
|
|
52
|
private boolean doDescriptions = true;
|
53
|
|
54
|
private boolean doPolytomousKey = true;
|
55
|
|
56
|
private UUID featureTreeUuid;
|
57
|
|
58
|
private boolean doImages = true;
|
59
|
|
60
|
private boolean doPublishEntireBranches = true;
|
61
|
|
62
|
private File exportFolder;
|
63
|
|
64
|
private List<IPublishOutputModule> outputModules;
|
65
|
|
66
|
private boolean remote;
|
67
|
|
68
|
private IProgressMonitor progressMonitor;
|
69
|
|
70
|
/**
|
71
|
* Hidden default constructor
|
72
|
*/
|
73
|
private PublishConfigurator() {
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* Creates a new instance connected to the given application controller.
|
78
|
*
|
79
|
* @param applicationConfiguration
|
80
|
* @return
|
81
|
*/
|
82
|
public static PublishConfigurator NewLocalInstance(
|
83
|
ICdmRepository applicationConfiguration) {
|
84
|
PublishConfigurator configurator = new PublishConfigurator();
|
85
|
configurator.setLocal();
|
86
|
configurator.setApplicationConfiguration(applicationConfiguration);
|
87
|
logger.trace("New local publish configurator instantiated.");
|
88
|
return configurator;
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* Creates a new instance, ready to be connected to a CDM Community Stores
|
93
|
* access point.
|
94
|
*
|
95
|
* @return
|
96
|
*/
|
97
|
public static PublishConfigurator NewRemoteInstance() {
|
98
|
PublishConfigurator configurator = new PublishConfigurator();
|
99
|
configurator.setRemote();
|
100
|
logger.trace("New remote publish configurator instantiated.");
|
101
|
return configurator;
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* Returns the CDM Community Stores access point connected to this
|
106
|
* configuration.
|
107
|
*
|
108
|
* @return the access points url or null if this configurator is configured
|
109
|
* to be local.
|
110
|
*/
|
111
|
public URL getWebserviceUrl() {
|
112
|
return webserviceUrl;
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* @see {@link #getWebserviceUrl()}
|
117
|
* @param webserviceUrlString
|
118
|
* @throws MalformedURLException
|
119
|
*/
|
120
|
public void setWebserviceUrl(String webserviceUrlString)
|
121
|
throws MalformedURLException {
|
122
|
URL url = new URL(webserviceUrlString);
|
123
|
setWebserviceUrl(url);
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* @see {@link #getWebserviceUrl()}
|
128
|
* @param webserviceUrl
|
129
|
*/
|
130
|
public void setWebserviceUrl(URL webserviceUrl) {
|
131
|
this.webserviceUrl = webserviceUrl;
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Returns a list of taxon node elements that should be processed by the
|
136
|
* print publisher.
|
137
|
*
|
138
|
* @return a list of elements
|
139
|
*/
|
140
|
public List<Element> getSelectedTaxonNodeElements() {
|
141
|
return selectedTaxonNodeElements;
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* Set the list of taxon node elements that should be processed by the print
|
146
|
* publisher.
|
147
|
*
|
148
|
* @see {@link #getSelectedTaxonNodeElements()}
|
149
|
* @param selectedTaxonNodeElements
|
150
|
*/
|
151
|
public void setSelectedTaxonNodeElements(
|
152
|
List<Element> selectedTaxonNodeElements) {
|
153
|
this.selectedTaxonNodeElements = selectedTaxonNodeElements;
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* Add a taxon node element to list of taxon nodes that will be processed by
|
158
|
* the print publisher.
|
159
|
*
|
160
|
* @see {@link #getSelectedTaxonNodeElements()}
|
161
|
* @param selectedTaxonNodeElement
|
162
|
*/
|
163
|
public void addSelectedTaxonNodeElements(Element selectedTaxonNodeElement) {
|
164
|
this.selectedTaxonNodeElements.add(selectedTaxonNodeElement);
|
165
|
}
|
166
|
|
167
|
/**
|
168
|
* Whether to export descriptions.
|
169
|
*
|
170
|
* @return
|
171
|
*/
|
172
|
public boolean isDoDescriptions() {
|
173
|
return doDescriptions;
|
174
|
}
|
175
|
|
176
|
/**
|
177
|
* @see {@link #isDoDescriptions()}
|
178
|
* @param doDescriptions
|
179
|
*/
|
180
|
public void setDoDescriptions(boolean doDescriptions) {
|
181
|
this.doDescriptions = doDescriptions;
|
182
|
}
|
183
|
|
184
|
/**
|
185
|
* Whether to export images
|
186
|
*
|
187
|
* @return
|
188
|
*/
|
189
|
public boolean isDoImages() {
|
190
|
return doImages;
|
191
|
}
|
192
|
|
193
|
/**
|
194
|
* @see {@link #isDoImages()}
|
195
|
* @param doImages
|
196
|
*/
|
197
|
public void setDoImages(boolean doImages) {
|
198
|
this.doImages = doImages;
|
199
|
}
|
200
|
|
201
|
/**
|
202
|
* The folder, the produced output will be written to.
|
203
|
*
|
204
|
* @return the exportFile
|
205
|
*/
|
206
|
public File getExportFolder() {
|
207
|
return exportFolder;
|
208
|
}
|
209
|
|
210
|
/**
|
211
|
* @see {@link #getExportFolder()}
|
212
|
* @param exportFolder
|
213
|
* the exportFile to set
|
214
|
*/
|
215
|
public void setExportFolder(File exportFolder) {
|
216
|
if (!exportFolder.isDirectory()) {
|
217
|
throw new IllegalArgumentException(
|
218
|
"Given export folder is not a directory.");
|
219
|
}
|
220
|
if (!exportFolder.canWrite()) {
|
221
|
throw new IllegalArgumentException(
|
222
|
"Can not write to given export folder");
|
223
|
}
|
224
|
this.exportFolder = exportFolder;
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* Returns a list of output modules. The print publisher will export into
|
229
|
* the formats defined by these output modules
|
230
|
*
|
231
|
* @see {@link IPublishOutputModule} and implementations thereof
|
232
|
* @return the outputModules
|
233
|
*/
|
234
|
public List<IPublishOutputModule> getOutputModules() {
|
235
|
if (outputModules == null) {
|
236
|
outputModules = new ArrayList<IPublishOutputModule>();
|
237
|
}
|
238
|
return outputModules;
|
239
|
}
|
240
|
|
241
|
/**
|
242
|
* @see {@link #getOutputModules()}
|
243
|
* @param outputModules
|
244
|
* the outputModules to set
|
245
|
*/
|
246
|
public void setOutputModules(List<IPublishOutputModule> outputModules) {
|
247
|
if (outputModules == null) {
|
248
|
throw new IllegalArgumentException(
|
249
|
"List of output modules may not be null.");
|
250
|
}
|
251
|
this.outputModules = outputModules;
|
252
|
}
|
253
|
|
254
|
/**
|
255
|
* Adds an output modules to this configurators list of output modules.
|
256
|
*
|
257
|
* @see {@link IPublishOutputModule} and implementations thereof
|
258
|
* @param module
|
259
|
*/
|
260
|
public void addOutputModule(IPublishOutputModule module) {
|
261
|
getOutputModules().add(module);
|
262
|
}
|
263
|
|
264
|
/**
|
265
|
* Whether this configurator is connected to a remote CDM Community Store
|
266
|
*
|
267
|
* @return
|
268
|
*/
|
269
|
public boolean isRemote() {
|
270
|
return remote;
|
271
|
}
|
272
|
|
273
|
/**
|
274
|
* @see {@link #isRemote()}
|
275
|
*/
|
276
|
private void setRemote() {
|
277
|
this.remote = true;
|
278
|
}
|
279
|
|
280
|
/**
|
281
|
* Whether this configurator is connected to a local application controller.
|
282
|
*
|
283
|
* @return
|
284
|
*/
|
285
|
public boolean isLocal() {
|
286
|
return !remote;
|
287
|
}
|
288
|
|
289
|
/**
|
290
|
* @see {@link #isLocal()}
|
291
|
*/
|
292
|
private void setLocal() {
|
293
|
this.remote = false;
|
294
|
}
|
295
|
|
296
|
/**
|
297
|
* Returns a {@link RemoteXMLEntityFactory} if <code>this</code> is a remote
|
298
|
* instance or a {@link LocalXMLEntityFactory} if <code>this</code> is a
|
299
|
* local instance
|
300
|
*
|
301
|
* @return an {@link IXMLEntityFactory}
|
302
|
*/
|
303
|
public IXMLEntityFactory getFactory() {
|
304
|
return isRemote() ? new RemoteXMLEntityFactory(getWebserviceUrl(),
|
305
|
getProgressMonitor()) : new LocalXMLEntityFactory(
|
306
|
getApplicationConfiguration(), getProgressMonitor());
|
307
|
}
|
308
|
|
309
|
/**
|
310
|
* FIXME this is a dummy implementation
|
311
|
*
|
312
|
* @return
|
313
|
*/
|
314
|
public int calculateNumberOfNodes() {
|
315
|
int count = 100;
|
316
|
|
317
|
return count;
|
318
|
}
|
319
|
|
320
|
/**
|
321
|
* Whether taxonomically included taxa for the
|
322
|
* {@linkplain #getSelectedTaxonNodeElements() selected taxon nodes} should
|
323
|
* be exported recursively.
|
324
|
*
|
325
|
* @return <code>true</code> if this is desired
|
326
|
*/
|
327
|
public boolean isDoPublishEntireBranches() {
|
328
|
return doPublishEntireBranches;
|
329
|
}
|
330
|
|
331
|
/**
|
332
|
* @see {@link #isDoPublishEntireBranches()}
|
333
|
* @param doPublishEntireBranches
|
334
|
*/
|
335
|
public void setDoPublishEntireBranches(boolean doPublishEntireBranches) {
|
336
|
this.doPublishEntireBranches = doPublishEntireBranches;
|
337
|
}
|
338
|
|
339
|
/**
|
340
|
* Whether the synonymy should be exported.
|
341
|
*
|
342
|
* @return <code>true</code> if this is desired
|
343
|
*/
|
344
|
public boolean isDoSynonymy() {
|
345
|
return doSynonymy;
|
346
|
}
|
347
|
|
348
|
/**
|
349
|
* @see {@link #isDoSynonymy()}
|
350
|
* @param selection
|
351
|
*/
|
352
|
public void setDoSynonymy(boolean selection) {
|
353
|
this.doSynonymy = selection;
|
354
|
}
|
355
|
|
356
|
/**
|
357
|
* The {@linkplain CdmApplicationController application controller}
|
358
|
* associated with this instance
|
359
|
*
|
360
|
* @return the {@link CdmApplicationController} or null if <code>this</code>
|
361
|
* is a {@linkplain #isRemote() remote} instance
|
362
|
*/
|
363
|
public ICdmRepository getApplicationConfiguration() {
|
364
|
return applicationConfiguration;
|
365
|
}
|
366
|
|
367
|
/**
|
368
|
* @see {@link #getApplicationController()}
|
369
|
* @param applicationConfiguration
|
370
|
*/
|
371
|
private void setApplicationConfiguration(
|
372
|
ICdmRepository applicationConfiguration) {
|
373
|
this.applicationConfiguration = applicationConfiguration;
|
374
|
}
|
375
|
|
376
|
/**
|
377
|
* The feature tree configures which features and in which order and nesting
|
378
|
* will be exported by the application
|
379
|
*
|
380
|
* @return the featureTrees uuid
|
381
|
*/
|
382
|
public UUID getFeatureTreeUuid() {
|
383
|
return featureTreeUuid;
|
384
|
}
|
385
|
|
386
|
/**
|
387
|
* @see {@link #getFeatureTreeUuid()}
|
388
|
* @param featureTreeUuid
|
389
|
* the featureTree to set
|
390
|
*/
|
391
|
public void setFeatureTree(UUID featureTreeUuid) {
|
392
|
this.featureTreeUuid = featureTreeUuid;
|
393
|
}
|
394
|
|
395
|
public void setProgressMonitor(IProgressMonitor progressMonitor) {
|
396
|
this.progressMonitor = progressMonitor;
|
397
|
}
|
398
|
|
399
|
public IProgressMonitor getProgressMonitor() {
|
400
|
return progressMonitor != null ? progressMonitor
|
401
|
: new NullProgressMonitor();
|
402
|
}
|
403
|
|
404
|
/**
|
405
|
* @return the doPolytomousKey
|
406
|
*/
|
407
|
public boolean isDoPolytomousKey() {
|
408
|
return doPolytomousKey;
|
409
|
}
|
410
|
|
411
|
/**
|
412
|
* @param doPolytomousKey the doPolytomousKey to set
|
413
|
*/
|
414
|
public void setDoPolytomousKey(boolean doPolytomousKey) {
|
415
|
this.doPolytomousKey = doPolytomousKey;
|
416
|
}
|
417
|
|
418
|
}
|