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.mapper;
20
21 import java.util.Properties;
22
23 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
24
25 /**
26 * A property mapper is a class being responsible to map a Content-Type (e.g. image/jpeg)
27 * to a CMIS type id and to map and convert properties. Extracted tags are mapped to
28 * CMIS property ids and sometimes type conversion is required (e.g. a string to a date).
29 * Classes implementing this interface are not responsible for extracting the metadata
30 * (see MetadataParser). It only reads a configuration and maps properties. The
31 * Configurator will read the configuration properties and instantiate implementations
32 * of this interface (one instance per CMIS type)
33 *
34 * @author Jens
35 *
36 */
37 public interface PropertyMapper {
38
39 /**
40 * initialize a property mapper
41 * @param cfgPrefix
42 * prefix for all configuration entries in properties file
43 * @param typeKey
44 * type key in configuration used to identify this type
45 * @param properties
46 * all properties read from resource mapping.properties
47 * @return
48 * true, if processing should continue, false if not
49 */
50 boolean initialize(String cfgPrefix, String typeKey, Properties properties);
51
52 /**
53 * Reset all internal data to get ready for a new parsing process
54 */
55 void reset();
56
57 /**
58 * return the CMIS type id used for this mapper
59 * @return
60 * CMIS type id to map this content type to or null if not mappable
61 */
62 String getMappedTypeId();
63
64 /**
65 * return the CMIS property id for a found tag in a file
66 * @param key
67 * tag (usually parsed from Tika) found in file
68 * @return
69 * CMIS property this tag gets mapped to, null if not mapped
70 */
71 String getMappedPropertyId(String key);
72
73 /**
74 * Convert a value parsed from the file to the type the corresponding property expects
75 * @param id
76 * CMIS property id
77 * @param propertyType
78 * property type from type definition
79 * @param strValue
80 * value read from file (Tika always gives a string)
81 * @return
82 * converted value conforming to the mapped property
83 */
84 Object convertValue(String id, PropertyDefinition<?> propDef, String strValue);
85
86 /**
87 * get all content types handled by this parser
88 * @return
89 * array with content types
90 */
91 public String[] getContentTypes();
92
93 }