Project

General

Profile

« Previous | Next » 

Revision 60199

fixed NPE

View differences:

modules/dnet-isti/trunk/src/test/java/eu/dnetlib/data/utils/BibTexConverterTest.java
1 1
package eu.dnetlib.data.utils;
2 2

  
3
import java.io.IOException;
4

  
5
import javax.xml.bind.JAXBException;
6

  
7
import org.apache.commons.io.IOUtils;
3 8
import org.junit.Ignore;
4 9
import org.junit.Test;
5 10

  
11
import com.google.gson.JsonSyntaxException;
12

  
6 13
import eu.dnetlib.data.mdstore.plugins.objects.MdRecord;
14
import eu.dnetlib.data.mdstore.plugins.objects.MdRecordConvertUtils;
7 15

  
8 16
public class BibTexConverterTest {
9 17

  
......
32 40
	}
33 41

  
34 42
	@Test
43
	@Ignore
35 44
	public void testAsBibTex_article_source_1() {
36 45

  
37 46
		final MdRecord record = new MdRecord();
......
47 56

  
48 57
	}
49 58

  
59
	@Test
60
	public void testAsBibTex_file() throws JsonSyntaxException, IOException, JAXBException {
61

  
62
		final String xml = IOUtils.toString(getClass().getResourceAsStream("record.xml"));
63

  
64
		final MdRecord record = MdRecordConvertUtils.fromString(xml);
65

  
66
		final String bib = BibTexConverter.asBibTex(record);
67

  
68
		System.out.println(bib);
69

  
70
	}
50 71
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/utils/CsvConverter.java
40 40
	}
41 41

  
42 42
	private static String prepareValue(final String s) {
43
		return s.replaceAll("\\n", " ")
44
				.replaceAll("\\t", " ")
45
				.replaceAll("\\s+", " ")
46
				.replaceAll("\\p{C}", "?") // Unprintable chars
47
				.trim();
43
		return s == null ? ""
44
				: s.replaceAll("\\n", " ")
45
						.replaceAll("\\t", " ")
46
						.replaceAll("\\s+", " ")
47
						.replaceAll("\\p{C}", "?") // Unprintable chars
48
						.trim();
48 49
	}
49 50
}

Also available in: Unified diff