1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.any23.extractor;
19
20 import org.apache.any23.mime.MIMEType;
21 import org.apache.any23.rdf.Prefixes;
22
23 import java.util.ArrayList;
24 import java.util.Collection;
25
26 /**
27 * This class is a simple and default-like implementation of {@link ExtractorFactory}.
28 *
29 * @param <T>
30 * the type of the {@link Extractor} served by this factory.
31 */
32 public abstract class SimpleExtractorFactory<T extends Extractor<?>> implements ExtractorFactory<T> {
33
34 private final String name;
35
36 private final Prefixes prefixes;
37
38 private Collection<MIMEType> supportedMIMETypes = new ArrayList<>();
39
40 private String exampleInput;
41
42 protected SimpleExtractorFactory(String name, Prefixes prefixes) {
43 this.name = name;
44 this.prefixes = prefixes;
45 }
46
47 protected SimpleExtractorFactory(String name, Prefixes prefixes, Collection<String> supportedMIMETypes,
48 String exampleInput) {
49 this.name = name;
50 this.prefixes = (prefixes == null) ? Prefixes.EMPTY : prefixes;
51 for (String type : supportedMIMETypes) {
52 this.supportedMIMETypes.add(MIMEType.parse(type));
53 }
54 this.exampleInput = exampleInput;
55 }
56
57 /**
58 * @return the name of the {@link Extractor}
59 */
60 @Override
61 public String getExtractorName() {
62 return name;
63 }
64
65 /**
66 * @return the label of the {@link Extractor}
67 */
68 @Override
69 public String getExtractorLabel() {
70 return this.getClass().getName();
71 }
72
73 /**
74 * @return the handled {@link org.apache.any23.rdf.Prefixes}
75 */
76 @Override
77 public Prefixes getPrefixes() {
78 return prefixes;
79 }
80
81 /**
82 * @return the supported {@link org.apache.any23.mime.MIMEType}
83 */
84 @Override
85 public Collection<MIMEType> getSupportedMIMETypes() {
86 return supportedMIMETypes;
87 }
88
89 /**
90 * @return an input example
91 */
92 @Override
93 public String getExampleInput() {
94 return exampleInput;
95 }
96
97 }