This project has retired. For details please refer to its
Attic page.
MetadataParserExif xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.client.parser;
2021import java.io.File;
22import java.util.Iterator;
23import java.util.Map;
2425import org.apache.chemistry.opencmis.client.mapper.MapperException;
26import org.apache.chemistry.opencmis.client.mapper.PropertyMapperExif;
27import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
28import org.apache.commons.logging.Log;
29import org.apache.commons.logging.LogFactory;
3031import com.drew.imaging.ImageMetadataReader;
32import com.drew.imaging.ImageProcessingException;
33import com.drew.metadata.Directory;
34import com.drew.metadata.Tag;
3536/**37 * A parser implementation using a lower level interface to get more control about the 38 * EXIF tags than Tika provides39 * 40 * @author Jens41 *42 */43publicclassMetadataParserExifextendsAbstractMetadataParser {
4445privatestaticfinal Log LOG = LogFactory.getLog(MetadataParserExif.class.getName());
4647publicvoid extractMetadata(File f, TypeDefinition td) throws MapperException {
4849 reset();
5051// see http://code.google.com/p/metadata-extractor/wiki/GettingStarted52try {
53 com.drew.metadata.Metadata metadata = ImageMetadataReader.readMetadata(f);
54 Iterator<?> it = metadata.getDirectoryIterator();
55while (it.hasNext()) {
56 Directory directory = (com.drew.metadata.Directory) it.next();
57 Iterator<?> tagIt = directory.getTagIterator();
58while (tagIt.hasNext()) {
59 Tag tag = (Tag) tagIt.next();
60 Object o = directory.getObject(tag.getTagType());
61 LOG.debug("Tag: " + tag + ", value: " + o + ", class: " + o.getClass() +
62", tag type: " + tag.getTagType() + ", hex-value: " + tag.getTagTypeHex());
63if (null != cmisProperties) {
64 ((PropertyMapperExif)mapper).mapTagAndConvert(directory, tag, td);
65 }
66 }
67 }
68 Map<String, Object> props = ((PropertyMapperExif)mapper).getMappedProperties();
69 cmisProperties.putAll(props);
70 } catch (ImageProcessingException e) {
71 LOG.error(e);
72 }
7374 }
7576 }