Example usage for org.apache.commons.imaging.formats.jpeg.iptc IptcTypes COUNTRY_PRIMARY_LOCATION_NAME

List of usage examples for org.apache.commons.imaging.formats.jpeg.iptc IptcTypes COUNTRY_PRIMARY_LOCATION_NAME

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.jpeg.iptc IptcTypes COUNTRY_PRIMARY_LOCATION_NAME.

Prototype

IptcTypes COUNTRY_PRIMARY_LOCATION_NAME

To view the source code for org.apache.commons.imaging.formats.jpeg.iptc IptcTypes COUNTRY_PRIMARY_LOCATION_NAME.

Click Source Link

Usage

From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataReader.java

public void extractGeocoding() {
    if (jpegMetadata != null) {
        final JpegPhotoshopMetadata photoshopMetadata = jpegMetadata.getPhotoshop();
        if (photoshopMetadata != null) {
            final Geocoding.Builder builder = new Geocoding.Builder();
            final List<IptcRecord> records = photoshopMetadata.photoshopApp13Data.getRecords();

            for (final IptcRecord record : records) {
                if (record.iptcType.equals(IptcTypes.CONTENT_LOCATION_NAME)) {
                    builder.setLocationName(record.getValue());
                } else if (record.iptcType.equals(IptcTypes.CITY)) {
                    builder.setCity(record.getValue());
                } else if (record.iptcType.equals(IptcTypes.SUBLOCATION)) {
                    builder.setSublocation(record.getValue());
                } else if (record.iptcType.equals(IptcTypes.PROVINCE_STATE)) {
                    builder.setProvinceState(record.getValue());
                } else if (record.iptcType.equals(IptcTypes.COUNTRY_PRIMARY_LOCATION_CODE)) {
                    builder.setCountryCode(record.getValue());
                } else if (record.iptcType.equals(IptcTypes.COUNTRY_PRIMARY_LOCATION_NAME)) {
                    builder.setCountryName(record.getValue());
                }//from   w ww .j  av  a  2  s  .c  om
            }

            geocoding = builder.build();
        }
    }
}

From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataWriter.java

private void setGeocoding(final Path aTargetFile) throws IOException, ImageReadException, ImageWriteException {
    final Path sourceFile = picture.getFile();

    final PhotoshopApp13Data photoshopMetadata = getPhotoshopMetadata(sourceFile);
    if (photoshopMetadata == null) {
        throw new ImageReadException("Could not obtain photoshop metadata");
    }//from   w  ww.  j a v  a  2s  .  c  o m

    try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(aTargetFile.toFile()))) {
        final Geocoding geocoding = picture.getGeocoding();

        final EnumSet<IptcTypes> filterTypes = EnumSet.noneOf(IptcTypes.class);
        filterTypes.add(IptcTypes.CONTENT_LOCATION_NAME);
        filterTypes.add(IptcTypes.CITY);
        filterTypes.add(IptcTypes.SUBLOCATION);
        filterTypes.add(IptcTypes.PROVINCE_STATE);
        filterTypes.add(IptcTypes.COUNTRY_PRIMARY_LOCATION_CODE);
        filterTypes.add(IptcTypes.COUNTRY_PRIMARY_LOCATION_NAME);

        final List<IptcRecord> records = photoshopMetadata.getRecords();
        final Iterator<IptcRecord> iter = records.iterator();
        while (iter.hasNext()) {
            final IptcRecord record = iter.next();
            final IptcType type = record.iptcType;
            if (filterTypes.contains(type)) {
                iter.remove();
            }
        }

        records.add(new IptcRecord(IptcTypes.CONTENT_LOCATION_NAME,
                geocoding != null ? geocoding.getLocationName() : ""));
        records.add(new IptcRecord(IptcTypes.CITY, geocoding != null ? geocoding.getCity() : ""));
        records.add(new IptcRecord(IptcTypes.SUBLOCATION, geocoding != null ? geocoding.getSublocation() : ""));
        records.add(new IptcRecord(IptcTypes.PROVINCE_STATE,
                geocoding != null ? geocoding.getProvinceState() : ""));
        records.add(new IptcRecord(IptcTypes.COUNTRY_PRIMARY_LOCATION_CODE,
                geocoding != null ? geocoding.getCountryCode() : ""));
        records.add(new IptcRecord(IptcTypes.COUNTRY_PRIMARY_LOCATION_NAME,
                geocoding != null ? geocoding.getCountryName() : ""));

        final List<IptcBlock> rawBlocks = photoshopMetadata.getRawBlocks();

        new JpegIptcRewriter().writeIPTC(sourceFile.toFile(), os, new PhotoshopApp13Data(records, rawBlocks));
    }
}