allow null value to rgbToHex method

This commit is contained in:
Claudio Barril 2015-03-08 00:54:34 -03:00
parent 268f3cfecf
commit a4da6fb7cd

View File

@ -357,13 +357,15 @@ public class FreemindExporter
private String rgbToHex(String color) { private String rgbToHex(String color) {
String result = color; String result = color;
boolean isRGB = Pattern.matches("^rgb\\([0-9]{1,3}, [0-9]{1,3}, [0-9]{1,3}\\)$", color); if (color != null) {
if (isRGB) { boolean isRGB = Pattern.matches("^rgb\\([0-9]{1,3}, [0-9]{1,3}, [0-9]{1,3}\\)$", color);
String[] rgb = color.substring(4, color.length() - 1).split(","); if (isRGB) {
Integer r = Integer.valueOf(rgb[0].trim()); String[] rgb = color.substring(4, color.length() - 1).split(",");
Integer g = Integer.valueOf(rgb[1].trim()); Integer r = Integer.valueOf(rgb[0].trim());
Integer b = Integer.valueOf(rgb[2].trim()); Integer g = Integer.valueOf(rgb[1].trim());
result = String.format("#%02x%02x%02x", r, g, b); Integer b = Integer.valueOf(rgb[2].trim());
result = String.format("#%02x%02x%02x", r, g, b);
}
} }
return result; return result;
} }