3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
.dwca
.in
;
14 import org
.apache
.commons
.lang
.StringUtils
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.io
.common
.IoStateBase
;
18 import eu
.etaxonomy
.cdm
.io
.common
.events
.IIoEvent
;
19 import eu
.etaxonomy
.cdm
.io
.common
.events
.IIoObserver
;
20 import eu
.etaxonomy
.cdm
.io
.common
.events
.IoProblemEvent
;
21 import eu
.etaxonomy
.cdm
.io
.dwca
.TermUri
;
28 public class ConverterBase
<STATE
extends IoStateBase
> {
29 @SuppressWarnings("unused")
30 private static final Logger logger
= Logger
.getLogger(ConverterBase
.class);
32 protected STATE state
;
35 protected void fireWarningEvent(String message
, CsvStreamItem item
, Integer severity
) {
36 fireWarningEvent(message
, getDataLocation(item
), severity
, 1);
39 private String
getDataLocation(CsvStreamItem item
) {
40 String location
= item
.getLocation();
44 protected void fireWarningEvent(String message
, String dataLocation
, Integer severity
) {
45 fireWarningEvent(message
, dataLocation
, severity
, 1);
48 protected void fireWarningEvent(String message
, String dataLocation
, Integer severity
, int stackDepth
) {
50 StackTraceElement
[] stackTrace
= new Exception().getStackTrace();
51 int lineNumber
= stackTrace
[stackDepth
].getLineNumber();
52 String methodName
= stackTrace
[stackDepth
].getMethodName();
54 IoProblemEvent event
= IoProblemEvent
.NewInstance(this.getClass(), message
, dataLocation
,
55 lineNumber
, severity
, methodName
);
57 //for performance improvement one may read:
58 //http://stackoverflow.com/questions/421280/in-java-how-do-i-find-the-caller-of-a-method-using-stacktrace-or-reflection
59 // Object o = new SecurityManager().getSecurityContext();
64 protected void fire(IIoEvent event
){
65 Set
<IIoObserver
> observers
= state
.getConfig().getObservers();
66 for (IIoObserver observer
: observers
){
67 observer
.handleEvent(event
);
69 if (observers
.size() == 0){
70 logger
.warn(event
.getMessage() + " (no observer for message!).");
77 * Returns the value for the given term in the item.
79 protected String
getValue(CsvStreamItem item
, TermUri term
) {
80 return item
.get(term
.getUriString());
84 * Checks if the given term has a value in item that is not blank (null, empty or whitespace only).
87 * @return true if value is not blank
89 protected boolean exists(TermUri term
, CsvStreamItem item
) {
90 return ! StringUtils
.isBlank(getValue(item
, term
));