You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2012/04/28 18:33:39 UTC
svn commit: r1331791 [10/12] - in /chemistry/opencmis/trunk: ./
chemistry-opencmis-client/chemistry-opencmis-client-bindings/
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/cache...
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/mapper/PropertyMapperTika.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/mapper/PropertyMapperTika.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/mapper/PropertyMapperTika.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/mapper/PropertyMapperTika.java Sat Apr 28 16:33:35 2012
@@ -1,188 +1,188 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.chemistry.opencmis.client.mapper;
-
-import java.text.DateFormatSymbols;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
-import org.apache.chemistry.opencmis.commons.enums.Cardinality;
-import org.apache.chemistry.opencmis.commons.enums.PropertyType;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class PropertyMapperTika extends AbstractPropertyMapper {
-
- private static final Log LOG = LogFactory.getLog(PropertyMapperTika.class.getName());
-
- private Map<String, String> propMapTags = new HashMap<String, String> (); // tag to property id
- private Map<String, String> tokenizerMap = new HashMap<String, String> (); // tag to tokenizer regexp
-
- public PropertyMapperTika() {
- reset();
- }
-
- public boolean initialize(String cfgPrefix, String typeKey, Properties properties) {
- super.initialize(cfgPrefix, typeKey, properties);
- buildIdMap(typeKey, properties);
-
- return true;
- }
-
- public void reset() {
- }
-
- public String getMappedPropertyId(String key) {
- String propId = propMapTags.get(key);
- return propId;
- }
-
- public Object convertValue(String key, PropertyDefinition<?> propDef, String strValue) {
- Object value = null;
- PropertyType pt = propDef.getPropertyType();
-
- if (null == pt)
- value = null;
- else if (null != strValue && strValue.length() > 0) {
- // Tika has a bug and sometimes fails to parse MP3 tags, then generates '\0' in String
- // see https://issues.apache.org/jira/browse/TIKA-887
- int lastIllegalPos = -1;
- for (int i=0; i<strValue.length(); i++) {
- int c = strValue.codePointAt(i);
- if (Character.isISOControl(c))
- lastIllegalPos = i;
- }
- if (lastIllegalPos >= 0)
- strValue = strValue.substring(lastIllegalPos+1); // use remaining part after illegal char
-
- switch (pt) {
- case STRING:
- case HTML:
- case URI:
- case ID:
-
- if (propDef.getCardinality() == Cardinality.SINGLE)
- value = strValue;
- else {
- String tokenizer = tokenizerMap.containsKey(key) ? tokenizerMap.get(key) : "\\W";
- String[] result = strValue.split(tokenizer);
- List<String> valList = new ArrayList<String>();
- for (String s : result)
- valList.add(s.trim());
- value = valList;
- }
- break;
- case INTEGER:
- if (propDef.getCardinality() == Cardinality.SINGLE)
- value = Integer.valueOf(strValue);
- else {
- String tokenizer = tokenizerMap.containsKey(key) ? tokenizerMap.get(key) : "\\W";
- String[] result = strValue.split(tokenizer);
- List<Integer> valList = new ArrayList<Integer>();
- for (String s : result)
- valList.add(Integer.valueOf(s.trim()));
- value = valList;
- }
- break;
- case DECIMAL:
- if (propDef.getCardinality() == Cardinality.SINGLE)
- value = Double.valueOf(strValue);
- else {
- String tokenizer = tokenizerMap.containsKey(key) ? tokenizerMap.get(key) : "[\\s;:]";
- String[] result = strValue.split(tokenizer);
- List<Double> valList = new ArrayList<Double>();
- for (String s : result)
- valList.add(Double.valueOf(s.trim()));
- value = valList;
- }
- break;
- case DATETIME:
- try {
- SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, new DateFormatSymbols(Locale.US));
- if (propDef.getCardinality() == Cardinality.SINGLE) {
- Date date = sdf.parse(strValue);
- GregorianCalendar cal = new GregorianCalendar();
- cal.setTime(date);
- value = date;
- } else {
- String tokenizer = tokenizerMap.containsKey(key) ? tokenizerMap.get(key) : "[;,:]";
- String[] result = strValue.split(tokenizer);
- List<GregorianCalendar> valList = new ArrayList<GregorianCalendar>();
- for (String s : result) {
- Date date = sdf.parse(s.trim());
- GregorianCalendar cal = new GregorianCalendar();
- cal.setTime(date);
- valList.add(cal);
- }
- value = valList;
- }
- } catch (ParseException e) {
- LOG.error("Could not parse date: " + strValue + " (check date format");
- LOG.error(e);
- value = null;
- e.printStackTrace();
- }
- break;
- default:
- throw new MapperException("unknown property type " + pt);
- }
- }
- return value;
- }
-
- void buildIdMap(String typeKey, Properties properties) {
- Set<String> keys = properties.stringPropertyNames();
- String prefix = propPrefix + ".id.";
- String tokenizerPrefix = propPrefix + ".tokenizer.";
-
- for (String key : keys) {
- if (key.startsWith(prefix)) {
- String id = key.substring(prefix.length());
- String cmisPropId = properties.getProperty(key).trim();
- if (null == cmisPropId)
- throw new MapperException("Configuration key " + key + " must have a value assigned");
- LOG.debug("Found mapping for type " + typeKey + " with " + id + " to " + cmisPropId);
- propMapTags.put(id, cmisPropId);
- }
- if (key.startsWith(tokenizerPrefix)) {
- String id = key.substring(tokenizerPrefix.length());
- String regex = properties.getProperty(key).trim();
- if (null == regex)
- throw new MapperException("Configuration key " + key + " must have a value assigned");
- LOG.debug("Found tokenizer mapping for property " + id + " to " + regex);
- tokenizerMap.put(id, regex);
- }
- }
- }
-
- int getSize() {
- return propMapTags.size();
- }
-
- }
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.mapper;
+
+import java.text.DateFormatSymbols;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.enums.Cardinality;
+import org.apache.chemistry.opencmis.commons.enums.PropertyType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PropertyMapperTika extends AbstractPropertyMapper {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PropertyMapperTika.class.getName());
+
+ private Map<String, String> propMapTags = new HashMap<String, String> (); // tag to property id
+ private Map<String, String> tokenizerMap = new HashMap<String, String> (); // tag to tokenizer regexp
+
+ public PropertyMapperTika() {
+ reset();
+ }
+
+ public boolean initialize(String cfgPrefix, String typeKey, Properties properties) {
+ super.initialize(cfgPrefix, typeKey, properties);
+ buildIdMap(typeKey, properties);
+
+ return true;
+ }
+
+ public void reset() {
+ }
+
+ public String getMappedPropertyId(String key) {
+ String propId = propMapTags.get(key);
+ return propId;
+ }
+
+ public Object convertValue(String key, PropertyDefinition<?> propDef, String strValue) {
+ Object value = null;
+ PropertyType pt = propDef.getPropertyType();
+
+ if (null == pt)
+ value = null;
+ else if (null != strValue && strValue.length() > 0) {
+ // Tika has a bug and sometimes fails to parse MP3 tags, then generates '\0' in String
+ // see https://issues.apache.org/jira/browse/TIKA-887
+ int lastIllegalPos = -1;
+ for (int i=0; i<strValue.length(); i++) {
+ int c = strValue.codePointAt(i);
+ if (Character.isISOControl(c))
+ lastIllegalPos = i;
+ }
+ if (lastIllegalPos >= 0)
+ strValue = strValue.substring(lastIllegalPos+1); // use remaining part after illegal char
+
+ switch (pt) {
+ case STRING:
+ case HTML:
+ case URI:
+ case ID:
+
+ if (propDef.getCardinality() == Cardinality.SINGLE)
+ value = strValue;
+ else {
+ String tokenizer = tokenizerMap.containsKey(key) ? tokenizerMap.get(key) : "\\W";
+ String[] result = strValue.split(tokenizer);
+ List<String> valList = new ArrayList<String>();
+ for (String s : result)
+ valList.add(s.trim());
+ value = valList;
+ }
+ break;
+ case INTEGER:
+ if (propDef.getCardinality() == Cardinality.SINGLE)
+ value = Integer.valueOf(strValue);
+ else {
+ String tokenizer = tokenizerMap.containsKey(key) ? tokenizerMap.get(key) : "\\W";
+ String[] result = strValue.split(tokenizer);
+ List<Integer> valList = new ArrayList<Integer>();
+ for (String s : result)
+ valList.add(Integer.valueOf(s.trim()));
+ value = valList;
+ }
+ break;
+ case DECIMAL:
+ if (propDef.getCardinality() == Cardinality.SINGLE)
+ value = Double.valueOf(strValue);
+ else {
+ String tokenizer = tokenizerMap.containsKey(key) ? tokenizerMap.get(key) : "[\\s;:]";
+ String[] result = strValue.split(tokenizer);
+ List<Double> valList = new ArrayList<Double>();
+ for (String s : result)
+ valList.add(Double.valueOf(s.trim()));
+ value = valList;
+ }
+ break;
+ case DATETIME:
+ try {
+ SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, new DateFormatSymbols(Locale.US));
+ if (propDef.getCardinality() == Cardinality.SINGLE) {
+ Date date = sdf.parse(strValue);
+ GregorianCalendar cal = new GregorianCalendar();
+ cal.setTime(date);
+ value = date;
+ } else {
+ String tokenizer = tokenizerMap.containsKey(key) ? tokenizerMap.get(key) : "[;,:]";
+ String[] result = strValue.split(tokenizer);
+ List<GregorianCalendar> valList = new ArrayList<GregorianCalendar>();
+ for (String s : result) {
+ Date date = sdf.parse(s.trim());
+ GregorianCalendar cal = new GregorianCalendar();
+ cal.setTime(date);
+ valList.add(cal);
+ }
+ value = valList;
+ }
+ } catch (ParseException e) {
+ LOG.error("Could not parse date: " + strValue + " (check date format");
+ LOG.error(e.toString(), e);
+ value = null;
+ e.printStackTrace();
+ }
+ break;
+ default:
+ throw new MapperException("unknown property type " + pt);
+ }
+ }
+ return value;
+ }
+
+ void buildIdMap(String typeKey, Properties properties) {
+ Set<String> keys = properties.stringPropertyNames();
+ String prefix = propPrefix + ".id.";
+ String tokenizerPrefix = propPrefix + ".tokenizer.";
+
+ for (String key : keys) {
+ if (key.startsWith(prefix)) {
+ String id = key.substring(prefix.length());
+ String cmisPropId = properties.getProperty(key).trim();
+ if (null == cmisPropId)
+ throw new MapperException("Configuration key " + key + " must have a value assigned");
+ LOG.debug("Found mapping for type " + typeKey + " with " + id + " to " + cmisPropId);
+ propMapTags.put(id, cmisPropId);
+ }
+ if (key.startsWith(tokenizerPrefix)) {
+ String id = key.substring(tokenizerPrefix.length());
+ String regex = properties.getProperty(key).trim();
+ if (null == regex)
+ throw new MapperException("Configuration key " + key + " must have a value assigned");
+ LOG.debug("Found tokenizer mapping for property " + id + " to " + regex);
+ tokenizerMap.put(id, regex);
+ }
+ }
+ }
+
+ int getSize() {
+ return propMapTags.size();
+ }
+
+ }
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/AbstractMetadataParser.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/AbstractMetadataParser.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/AbstractMetadataParser.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/AbstractMetadataParser.java Sat Apr 28 16:33:35 2012
@@ -1,68 +1,68 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.chemistry.opencmis.client.parser;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.chemistry.opencmis.client.mapper.MapperException;
-import org.apache.chemistry.opencmis.client.mapper.PropertyMapper;
-import org.apache.chemistry.opencmis.commons.PropertyIds;
-
-public abstract class AbstractMetadataParser implements MetadataParser {
-
- // private static final Log LOG = LogFactory.getLog(AbstractMetadataParser.class.getName());
-
- protected Map<String, Object> cmisProperties;
- protected PropertyMapper mapper = null;
-
- protected AbstractMetadataParser() {
- }
-
- public void initialize(PropertyMapper mapper, String contentType) {
- this.mapper = mapper;
- reset();
- }
-
- public Map<String, Object> getCmisProperties() {
- return cmisProperties;
- }
-
- public void reset() {
- String typeId = mapper.getMappedTypeId();
- cmisProperties = new HashMap<String, Object>();
- mapper.reset();
-
- if (null == typeId)
- throw new MapperException("No CMIS Type configured in this parser.");
- cmisProperties.put(PropertyIds.OBJECT_TYPE_ID, typeId);
- }
-
- public String[] getContentTypes() {
- return mapper.getContentTypes();
- }
-
- public String getMappedTypeId() {
- return mapper.getMappedTypeId();
- }
-
- public PropertyMapper getMapper() {
- return mapper;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.client.mapper.MapperException;
+import org.apache.chemistry.opencmis.client.mapper.PropertyMapper;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+
+public abstract class AbstractMetadataParser implements MetadataParser {
+
+ // private static final Logger LOG = LoggerFactory.getLogger(AbstractMetadataParser.class.getName());
+
+ protected Map<String, Object> cmisProperties;
+ protected PropertyMapper mapper = null;
+
+ protected AbstractMetadataParser() {
+ }
+
+ public void initialize(PropertyMapper mapper, String contentType) {
+ this.mapper = mapper;
+ reset();
+ }
+
+ public Map<String, Object> getCmisProperties() {
+ return cmisProperties;
+ }
+
+ public void reset() {
+ String typeId = mapper.getMappedTypeId();
+ cmisProperties = new HashMap<String, Object>();
+ mapper.reset();
+
+ if (null == typeId)
+ throw new MapperException("No CMIS Type configured in this parser.");
+ cmisProperties.put(PropertyIds.OBJECT_TYPE_ID, typeId);
+ }
+
+ public String[] getContentTypes() {
+ return mapper.getContentTypes();
+ }
+
+ public String getMappedTypeId() {
+ return mapper.getMappedTypeId();
+ }
+
+ public PropertyMapper getMapper() {
+ return mapper;
+ }
+}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/MetadataParserExif.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/MetadataParserExif.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/MetadataParserExif.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/MetadataParserExif.java Sat Apr 28 16:33:35 2012
@@ -1,76 +1,76 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.chemistry.opencmis.client.parser;
-
-import java.io.File;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.chemistry.opencmis.client.mapper.MapperException;
-import org.apache.chemistry.opencmis.client.mapper.PropertyMapperExif;
-import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import com.drew.imaging.ImageMetadataReader;
-import com.drew.imaging.ImageProcessingException;
-import com.drew.metadata.Directory;
-import com.drew.metadata.Tag;
-
-/**
- * A parser implementation using a lower level interface to get more control about the
- * EXIF tags than Tika provides
- *
- * @author Jens
- *
- */
-public class MetadataParserExif extends AbstractMetadataParser {
-
- private static final Log LOG = LogFactory.getLog(MetadataParserExif.class.getName());
-
- public void extractMetadata(File f, TypeDefinition td) throws MapperException {
-
- reset();
-
- // see http://code.google.com/p/metadata-extractor/wiki/GettingStarted
- try {
- com.drew.metadata.Metadata metadata = ImageMetadataReader.readMetadata(f);
- Iterator<?> it = metadata.getDirectoryIterator();
- while (it.hasNext()) {
- Directory directory = (com.drew.metadata.Directory) it.next();
- Iterator<?> tagIt = directory.getTagIterator();
- while (tagIt.hasNext()) {
- Tag tag = (Tag) tagIt.next();
- Object o = directory.getObject(tag.getTagType());
- LOG.debug("Tag: " + tag + ", value: " + o + ", class: " + o.getClass() +
- ", tag type: " + tag.getTagType() + ", hex-value: " + tag.getTagTypeHex());
- if (null != cmisProperties) {
- ((PropertyMapperExif)mapper).mapTagAndConvert(directory, tag, td);
- }
- }
- }
- Map<String, Object> props = ((PropertyMapperExif)mapper).getMappedProperties();
- cmisProperties.putAll(props);
- } catch (ImageProcessingException e) {
- LOG.error(e);
- }
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.parser;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.client.mapper.MapperException;
+import org.apache.chemistry.opencmis.client.mapper.PropertyMapperExif;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.drew.imaging.ImageMetadataReader;
+import com.drew.imaging.ImageProcessingException;
+import com.drew.metadata.Directory;
+import com.drew.metadata.Tag;
+
+/**
+ * A parser implementation using a lower level interface to get more control about the
+ * EXIF tags than Tika provides
+ *
+ * @author Jens
+ *
+ */
+public class MetadataParserExif extends AbstractMetadataParser {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MetadataParserExif.class.getName());
+
+ public void extractMetadata(File f, TypeDefinition td) throws MapperException {
+
+ reset();
+
+ // see http://code.google.com/p/metadata-extractor/wiki/GettingStarted
+ try {
+ com.drew.metadata.Metadata metadata = ImageMetadataReader.readMetadata(f);
+ Iterator<?> it = metadata.getDirectoryIterator();
+ while (it.hasNext()) {
+ Directory directory = (com.drew.metadata.Directory) it.next();
+ Iterator<?> tagIt = directory.getTagIterator();
+ while (tagIt.hasNext()) {
+ Tag tag = (Tag) tagIt.next();
+ Object o = directory.getObject(tag.getTagType());
+ LOG.debug("Tag: " + tag + ", value: " + o + ", class: " + o.getClass() +
+ ", tag type: " + tag.getTagType() + ", hex-value: " + tag.getTagTypeHex());
+ if (null != cmisProperties) {
+ ((PropertyMapperExif)mapper).mapTagAndConvert(directory, tag, td);
+ }
+ }
+ }
+ Map<String, Object> props = ((PropertyMapperExif)mapper).getMappedProperties();
+ cmisProperties.putAll(props);
+ } catch (ImageProcessingException e) {
+ LOG.error(e.toString(), e);
+ }
+
+ }
+
+}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/MetadataParserTika.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/MetadataParserTika.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/MetadataParserTika.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/parser/MetadataParserTika.java Sat Apr 28 16:33:35 2012
@@ -1,106 +1,106 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.chemistry.opencmis.client.parser;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
-import org.apache.chemistry.opencmis.client.mapper.MapperException;
-import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
-import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
-import org.apache.chemistry.opencmis.commons.enums.PropertyType;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.parser.AutoDetectParser;
-import org.apache.tika.parser.ParseContext;
-import org.apache.tika.parser.Parser;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * A metadata parser using the Apache Tika library
- * @author Jens
- *
- */
-public class MetadataParserTika extends AbstractMetadataParser {
-
- private static final Log LOG = LogFactory.getLog(MetadataParserTika.class.getName());
-
- public MetadataParserTika() {
- }
-
- public void extractMetadata(File f, TypeDefinition td) throws MapperException {
- try {
- InputStream stream = new FileInputStream(f);
- Metadata metadata = new Metadata();
- ContentHandler handler = new DefaultHandler();
- Parser parser = new AutoDetectParser();
- ParseContext context = new ParseContext();
- parser.parse(stream, handler, metadata, context);
-
- reset();
-
- for (String key : metadata.names()) {
- String val = metadata.get(key);
- LOG.debug("Found metadata \'" + key + "\': " + val);
- if (null != cmisProperties) {
- String propertyId = mapper.getMappedPropertyId(key);
- if (null != propertyId && null != val) {
- if (td != null) {
- PropertyDefinition<?> propDef = td.getPropertyDefinitions().get(propertyId);
- if (null == propDef)
- throw new MapperException("Mapping error: unknown property "+ propertyId + " in type definition " + td.getId());
- PropertyType propertyType = propDef.getPropertyType();
- Object convVal = mapper.convertValue(propertyId, propDef, val);
- if (null != convVal)
- cmisProperties.put(propertyId, convVal);
- } else
- cmisProperties.put(propertyId, val); // omit conversion if no type definition is available
- }
- }
- }
-
- } catch (Exception e) {
- LOG.error(e);
- throw new MapperException("Extracting metadata failed for file " + f.getAbsolutePath(), e);
- }
- }
-
- public void listMetadata(File f) throws MapperException {
- try {
- InputStream stream = new FileInputStream(f);
- Metadata metadata = new Metadata();
- ContentHandler handler = new DefaultHandler();
- Parser parser = new AutoDetectParser();
- ParseContext context = new ParseContext();
- parser.parse(stream, handler, metadata, context);
-
- for (String key : metadata.names()) {
- String val = metadata.get(key);
- LOG.info("Found metadata \'" + key + "\': " + val);
- }
-
- } catch (Exception e) {
- LOG.error(e);
- throw new MapperException("Extracting metadata failed, file not found: " + f.getAbsolutePath(), e);
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.parser;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.chemistry.opencmis.client.mapper.MapperException;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.PropertyType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.AutoDetectParser;
+import org.apache.tika.parser.ParseContext;
+import org.apache.tika.parser.Parser;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * A metadata parser using the Apache Tika library
+ * @author Jens
+ *
+ */
+public class MetadataParserTika extends AbstractMetadataParser {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MetadataParserTika.class.getName());
+
+ public MetadataParserTika() {
+ }
+
+ public void extractMetadata(File f, TypeDefinition td) throws MapperException {
+ try {
+ InputStream stream = new FileInputStream(f);
+ Metadata metadata = new Metadata();
+ ContentHandler handler = new DefaultHandler();
+ Parser parser = new AutoDetectParser();
+ ParseContext context = new ParseContext();
+ parser.parse(stream, handler, metadata, context);
+
+ reset();
+
+ for (String key : metadata.names()) {
+ String val = metadata.get(key);
+ LOG.debug("Found metadata \'" + key + "\': " + val);
+ if (null != cmisProperties) {
+ String propertyId = mapper.getMappedPropertyId(key);
+ if (null != propertyId && null != val) {
+ if (td != null) {
+ PropertyDefinition<?> propDef = td.getPropertyDefinitions().get(propertyId);
+ if (null == propDef)
+ throw new MapperException("Mapping error: unknown property "+ propertyId + " in type definition " + td.getId());
+ PropertyType propertyType = propDef.getPropertyType();
+ Object convVal = mapper.convertValue(propertyId, propDef, val);
+ if (null != convVal)
+ cmisProperties.put(propertyId, convVal);
+ } else
+ cmisProperties.put(propertyId, val); // omit conversion if no type definition is available
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ LOG.error(e.toString(), e);
+ throw new MapperException("Extracting metadata failed for file " + f.getAbsolutePath(), e);
+ }
+ }
+
+ public void listMetadata(File f) throws MapperException {
+ try {
+ InputStream stream = new FileInputStream(f);
+ Metadata metadata = new Metadata();
+ ContentHandler handler = new DefaultHandler();
+ Parser parser = new AutoDetectParser();
+ ParseContext context = new ParseContext();
+ parser.parse(stream, handler, metadata, context);
+
+ for (String key : metadata.names()) {
+ String val = metadata.get(key);
+ LOG.info("Found metadata \'" + key + "\': " + val);
+ }
+
+ } catch (Exception e) {
+ LOG.error(e.toString(), e);
+ throw new MapperException("Extracting metadata failed, file not found: " + f.getAbsolutePath(), e);
+ }
+ }
+}