2021-02-12 17:27:08 +01:00
|
|
|
|
2021-02-12 16:34:52 +01:00
|
|
|
package eu.dnetlib.dhp.transformation.xslt;
|
|
|
|
|
2021-02-25 12:28:56 +01:00
|
|
|
import static eu.dnetlib.dhp.transformation.xslt.XSLTTransformationFunction.QNAME_BASE_URI;
|
|
|
|
|
2021-02-24 15:07:59 +01:00
|
|
|
import java.io.Serializable;
|
2021-02-12 16:34:52 +01:00
|
|
|
|
2021-06-11 16:53:01 +02:00
|
|
|
import eu.dnetlib.dhp.schema.oaf.utils.GraphCleaningFunctions;
|
2021-02-12 17:27:08 +01:00
|
|
|
import net.sf.saxon.s9api.*;
|
2021-02-24 15:07:59 +01:00
|
|
|
|
2021-02-12 16:34:52 +01:00
|
|
|
public class DateCleaner implements ExtensionFunction, Serializable {
|
|
|
|
|
2021-02-12 17:27:08 +01:00
|
|
|
@Override
|
|
|
|
public QName getName() {
|
2021-02-24 15:07:59 +01:00
|
|
|
return new QName(QNAME_BASE_URI + "/dateISO", "dateISO");
|
2021-02-12 17:27:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SequenceType getResultType() {
|
|
|
|
return SequenceType.makeSequenceType(ItemType.STRING, OccurrenceIndicator.ZERO_OR_ONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SequenceType[] getArgumentTypes() {
|
|
|
|
return new SequenceType[] {
|
|
|
|
SequenceType.makeSequenceType(ItemType.STRING, OccurrenceIndicator.ZERO_OR_ONE)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public XdmValue call(XdmValue[] xdmValues) throws SaxonApiException {
|
|
|
|
XdmValue r = xdmValues[0];
|
|
|
|
if (r.size() == 0) {
|
|
|
|
return new XdmAtomicValue("");
|
|
|
|
}
|
|
|
|
final String currentValue = xdmValues[0].itemAt(0).getStringValue();
|
|
|
|
return new XdmAtomicValue(clean(currentValue));
|
|
|
|
}
|
2021-06-11 16:53:01 +02:00
|
|
|
|
|
|
|
// for backward compatibility with the existing unit tests
|
|
|
|
public String clean(String date) {
|
|
|
|
return GraphCleaningFunctions.cleanDate(date);
|
|
|
|
}
|
2021-02-12 16:34:52 +01:00
|
|
|
}
|