This project has retired. For details please refer to its Attic page.
MetadataParserExif xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.client.parser;
20  
21  import java.io.File;
22  import java.util.Iterator;
23  import java.util.Map;
24  
25  import org.apache.chemistry.opencmis.client.mapper.MapperException;
26  import org.apache.chemistry.opencmis.client.mapper.PropertyMapperExif;
27  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  
31  import com.drew.imaging.ImageMetadataReader;
32  import com.drew.imaging.ImageProcessingException;
33  import com.drew.metadata.Directory;
34  import com.drew.metadata.Tag;
35  
36  /**
37   * A parser implementation using a lower level interface to get more control about the 
38   * EXIF tags than Tika provides
39   * 
40   * @author Jens
41   *
42   */
43  public class MetadataParserExif extends AbstractMetadataParser  {
44  
45      private static final Log LOG = LogFactory.getLog(MetadataParserExif.class.getName());
46      
47      public void extractMetadata(File f, TypeDefinition td) throws MapperException {
48          
49          reset();
50          
51          // see  http://code.google.com/p/metadata-extractor/wiki/GettingStarted
52          try {
53              com.drew.metadata.Metadata metadata = ImageMetadataReader.readMetadata(f);
54              Iterator<?> it = metadata.getDirectoryIterator();
55              while (it.hasNext()) {
56                  Directory directory = (com.drew.metadata.Directory) it.next();
57                  Iterator<?> tagIt = directory.getTagIterator();
58                  while (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());
63                      if (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          }
73  
74      }
75  
76  }