View Javadoc
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> the type of the {@link Extractor} served by this factory.
30   */
31  public abstract class SimpleExtractorFactory<T extends Extractor<?>> implements ExtractorFactory<T> {
32  
33      private final String name;
34  
35      private final Prefixes prefixes;
36  
37      private Collection<MIMEType> supportedMIMETypes = new ArrayList<>();
38  
39      private String exampleInput;
40  
41      protected SimpleExtractorFactory(
42              String name,
43              Prefixes prefixes) {
44          this.name = name;
45          this.prefixes = prefixes;
46      }
47  
48      protected SimpleExtractorFactory(
49              String name,
50              Prefixes prefixes,
51              Collection<String> supportedMIMETypes,
52              String exampleInput
53      ) {
54          this.name = name;
55          this.prefixes = (prefixes == null) ? Prefixes.EMPTY : prefixes;
56          for (String type : supportedMIMETypes) {
57              this.supportedMIMETypes.add(MIMEType.parse(type));
58          }
59          this.exampleInput = exampleInput;
60      }
61  
62      /**
63       * @return the name of the {@link Extractor}
64       */
65      @Override
66      public String getExtractorName() {
67          return name;
68      }
69  
70      /**
71       * @return the label of the {@link Extractor}
72       */
73      @Override
74      public String getExtractorLabel() {
75          return this.getClass().getName();
76      }
77  
78      /**
79       * @return the handled {@link org.apache.any23.rdf.Prefixes}
80       */
81      @Override
82      public Prefixes getPrefixes() {
83          return prefixes;
84      }
85  
86      /**
87       * @return the supported {@link org.apache.any23.mime.MIMEType}
88       */
89      @Override
90      public Collection<MIMEType> getSupportedMIMETypes() {
91          return supportedMIMETypes;
92      }
93  
94      /**
95       * @return an input example
96       */
97      @Override
98      public String getExampleInput() {
99          return exampleInput;
100     }
101 
102 }