View Javadoc
1   /*
2    * Copyright 2012-2021 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.crawler.transformer;
17  
18  import javax.annotation.PostConstruct;
19  
20  import org.apache.logging.log4j.LogManager;
21  import org.apache.logging.log4j.Logger;
22  import org.codelibs.fess.crawler.entity.ResponseData;
23  import org.codelibs.fess.crawler.extractor.Extractor;
24  import org.codelibs.fess.crawler.extractor.ExtractorFactory;
25  import org.codelibs.fess.exception.FessSystemException;
26  import org.codelibs.fess.mylasta.direction.FessConfig;
27  import org.codelibs.fess.util.ComponentUtil;
28  
29  public class FessStandardTransformer extends AbstractFessFileTransformer {
30      private static final Logger logger = LogManager.getLogger(FessStandardTransformer.class);
31  
32      @PostConstruct
33      public void init() {
34          if (logger.isDebugEnabled()) {
35              logger.debug("Initialize {}", this.getClass().getSimpleName());
36          }
37          fessConfig = ComponentUtil.getFessConfig();
38      }
39  
40      @Override
41      public FessConfig getFessConfig() {
42          return fessConfig;
43      }
44  
45      @Override
46      public Logger getLogger() {
47          return logger;
48      }
49  
50      @Override
51      protected Extractor getExtractor(final ResponseData responseData) {
52          final ExtractorFactory extractorFactory = ComponentUtil.getExtractorFactory();
53          if (extractorFactory == null) {
54              throw new FessSystemException("Could not find extractorFactory.");
55          }
56          Extractor extractor = extractorFactory.getExtractor(responseData.getMimeType());
57          if (extractor == null) {
58              extractor = ComponentUtil.getComponent("tikaExtractor");
59              if (extractor == null) {
60                  throw new FessSystemException("Could not find tikaExtractor.");
61              }
62          }
63  
64          if (logger.isDebugEnabled()) {
65              logger.debug("url={}, extractor={}", responseData.getUrl(), extractor);
66          }
67          return extractor;
68      }
69  }