return false;
}
@Override
public DcObject parse(String filename, int directoryUsage) {
DcObject image = DcModules.get(DcModules._IMAGE).getItem();
try {
image.setIDs();
image.setValue(Image._A_TITLE, getName(filename, directoryUsage));
image.setValue(Image._SYS_FILENAME, filename);
Picture pic = (Picture) DcModules.get(DcModules._PICTURE).getItem();
DcImageIcon icon;
if (filename.toLowerCase().endsWith(".svg")) {
SVGtoBufferedImageConverter converter = new SVGtoBufferedImageConverter();
BufferedImage bi = converter.renderSVG(filename);
icon = new DcImageIcon(Utilities.getScaledImage(new DcImageIcon(bi), 400, 400));
filename = File.createTempFile(String.valueOf(Utilities.getUniqueID()), ".png").toString();
icon.setFilename(filename);
icon.save();
bi.flush();
} else {
icon = new DcImageIcon(Utilities.getScaledImage(new DcImageIcon(filename), 400, 400));
pic.setValue(Picture._G_EXTERNAL_FILENAME, filename);
}
int width = icon.getIconWidth();
int height = icon.getIconHeight();
image.setValue(Image._F_WIDTH, width != -1 ? Long.valueOf(width) : null);
image.setValue(Image._G_HEIGHT, height != -1 ? Long.valueOf(height) : null);
icon.getImage().flush();
pic.setValue(Picture._A_OBJECTID, image.getID());
pic.setValue(Picture._B_FIELD, image.getField(Image._I_IMAGE).getDatabaseFieldName());
pic.setValue(Picture._D_IMAGE, icon);
pic.isEdited(true);
image.setValue(Image._I_IMAGE, pic);
File jpegFile = new File(filename);
try {
Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
if (metadata.containsDirectory(ExifDirectory.class)) {
Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
try {
String camera = exifDirectory.getString(ExifDirectory.TAG_MODEL);
image.setValue(Image._Q_CAMERA, camera);
} catch (Exception me) {}
try {
int compression = exifDirectory.getInt(ExifDirectory.TAG_COMPRESSION);
image.setValue(Image._O_COMPRESSION, Long.valueOf(compression));
} catch (Exception me) {}
try {
String description = exifDirectory.getString(ExifDirectory.TAG_IMAGE_DESCRIPTION);
image.setValue(Image._B_DESCRIPTION, description);
} catch (Exception me) {}
try {
Date date = exifDirectory.getDate(ExifDirectory.TAG_DATETIME);
if (date != null) {
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
image.setValue(Image._N_DATE, cal.getTime());
}
} catch (Exception me) {}
}
if (metadata.containsDirectory(IptcDirectory.class)) {
try {
Directory iptcDirectory = metadata.getDirectory(IptcDirectory.class);
String city = iptcDirectory.getString(IptcDirectory.TAG_CITY);
String country = iptcDirectory.getString(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION);
String state = iptcDirectory.getString(IptcDirectory.TAG_PROVINCE_OR_STATE);
String location = "";
location += country != null ? country + ", " : "";
location += state != null ? state + ", " : "";
location += city != null ? city : "";
image.setValue(Image._P_PLACE, location);
} catch (Exception me) {}
}
} catch (JpegProcessingException jpe) {}