md5 ext function
This commit is contained in:
parent
7fbffa4afa
commit
c386401b52
|
@ -14,6 +14,7 @@ import eu.dnetlib.common.clients.DnetServiceClientFactory;
|
|||
import eu.dnetlib.common.clients.SimpleResourceClient;
|
||||
import eu.dnetlib.common.clients.VocabularyClient;
|
||||
import eu.dnetlib.common.mapping.RecordTransformer;
|
||||
import eu.dnetlib.common.mapping.xslt.functions.CalculateMd5;
|
||||
import eu.dnetlib.common.mapping.xslt.functions.XsltDateCleaner;
|
||||
import eu.dnetlib.common.mapping.xslt.functions.XsltPersonCleaner;
|
||||
import eu.dnetlib.common.mapping.xslt.functions.XsltVocabularyCleaner;
|
||||
|
@ -49,6 +50,7 @@ public class XsltTransformerFactory {
|
|||
|
||||
public RecordTransformer<String, String> getTransformerByXSLT(final String xsltText, final Map<String, Object> params) throws TransformationException {
|
||||
final Processor processor = new Processor(false);
|
||||
processor.registerExtensionFunction(new CalculateMd5());
|
||||
processor.registerExtensionFunction(new XsltDateCleaner());
|
||||
processor.registerExtensionFunction(new XsltPersonCleaner());
|
||||
processor.registerExtensionFunction(new XsltVocabularyCleaner(this.clientFactory.getClient(VocabularyClient.class)));
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package eu.dnetlib.common.mapping.xslt.functions;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import eu.dnetlib.common.mapping.xslt.XsltTransformerFactory;
|
||||
import net.sf.saxon.s9api.ExtensionFunction;
|
||||
import net.sf.saxon.s9api.ItemType;
|
||||
import net.sf.saxon.s9api.OccurrenceIndicator;
|
||||
import net.sf.saxon.s9api.QName;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.SequenceType;
|
||||
import net.sf.saxon.s9api.XdmAtomicValue;
|
||||
import net.sf.saxon.s9api.XdmValue;
|
||||
|
||||
public class CalculateMd5 implements ExtensionFunction {
|
||||
|
||||
@Override
|
||||
public QName getName() {
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/common", "md5");
|
||||
}
|
||||
|
||||
@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(final XdmValue[] xdmValues) throws SaxonApiException {
|
||||
final XdmValue r = xdmValues[0];
|
||||
if (r.size() == 0) { return new XdmAtomicValue(""); }
|
||||
final String currentValue = xdmValues[0].itemAt(0).getStringValue();
|
||||
return new XdmAtomicValue(StringUtils.isNotBlank(currentValue) ? DigestUtils.md5Hex(currentValue) : null);
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ public class XsltDateCleaner implements ExtensionFunction {
|
|||
|
||||
@Override
|
||||
public QName getName() {
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/dateISO", "dateISO");
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/dates", "dateISO");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,7 +24,7 @@ public class XsltPersonCleaner implements ExtensionFunction {
|
|||
|
||||
@Override
|
||||
public QName getName() {
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/person", "normalize");
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/persons", "normalize");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,7 +37,7 @@ public class XsltVocabularyCleaner implements ExtensionFunction {
|
|||
|
||||
@Override
|
||||
public QName getName() {
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/clean", "clean");
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/vocs", "clean");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue