1
|
package eu.dnetlib.isti.transform;
|
2
|
|
3
|
import static org.junit.Assert.assertEquals;
|
4
|
|
5
|
import java.io.InputStream;
|
6
|
import java.io.StringReader;
|
7
|
import java.io.StringWriter;
|
8
|
import java.io.UnsupportedEncodingException;
|
9
|
import java.net.URLDecoder;
|
10
|
|
11
|
import javax.xml.transform.OutputKeys;
|
12
|
import javax.xml.transform.Transformer;
|
13
|
import javax.xml.transform.TransformerFactory;
|
14
|
import javax.xml.transform.stream.StreamResult;
|
15
|
import javax.xml.transform.stream.StreamSource;
|
16
|
|
17
|
import org.dom4j.io.SAXReader;
|
18
|
import org.junit.Ignore;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import eu.dnetlib.data.utils.XsltFunctions;
|
22
|
|
23
|
/**
|
24
|
* Created by sandro on 9/30/16.
|
25
|
*/
|
26
|
public class TransformTest {
|
27
|
|
28
|
@Test
|
29
|
@Ignore
|
30
|
public void transformPeopleTest() throws Exception {
|
31
|
final InputStream xsltAsStream =
|
32
|
this.getClass().getResourceAsStream("/eu/dnetlib/bootstrap/profiles/TransformationRuleDSResources/people2dataciteTransform.xml");
|
33
|
|
34
|
final String code = new SAXReader().read(xsltAsStream).valueOf("//CODE");
|
35
|
|
36
|
final TransformerFactory factory = TransformerFactory.newInstance();
|
37
|
factory.newTransformer();
|
38
|
final StreamSource xsltSource = new StreamSource(new StringReader(code));
|
39
|
final InputStream recordStream = this.getClass().getResourceAsStream("inputPeople.xml");
|
40
|
final Transformer transformer = factory.newTransformer(xsltSource);
|
41
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
42
|
final StringWriter output = new StringWriter();
|
43
|
transformer.transform(new StreamSource(recordStream), new StreamResult(output));
|
44
|
final String record = output.toString();
|
45
|
|
46
|
// System.out.println("record = " + record);
|
47
|
|
48
|
System.out.println("name :" + XsltFunctions.cleanNames("(eds.)"));
|
49
|
|
50
|
}
|
51
|
|
52
|
@Test
|
53
|
@Ignore
|
54
|
public void test() throws UnsupportedEncodingException {
|
55
|
final String s2 = "https://issue.openaire.research-infrastructures.eu/projects/openaire2020- wiki/wiki/D81_OpenAIRE_Data_Model_Specification";
|
56
|
final String s1 = "https://issue.openaire.research-infrastructures.eu/projects/openaire2020-%20wiki/wiki/D81_OpenAIRE_Data_Model_Specification";
|
57
|
|
58
|
assertEquals(URLDecoder.decode(s1, "UTF-8"), URLDecoder.decode(s2, "UTF-8"));
|
59
|
|
60
|
}
|
61
|
|
62
|
}
|