View Javadoc
1   /*
2    * Copyright 2012-2017 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.codelibs.fess.crawler.entity.ResponseData;
21  import org.codelibs.fess.crawler.extractor.Extractor;
22  import org.codelibs.fess.crawler.extractor.ExtractorFactory;
23  import org.codelibs.fess.exception.FessSystemException;
24  import org.codelibs.fess.mylasta.direction.FessConfig;
25  import org.codelibs.fess.util.ComponentUtil;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  public class FessFileTransformer extends AbstractFessFileTransformer {
30      private static final Logger logger = LoggerFactory.getLogger(FessFileTransformer.class);
31  
32      @PostConstruct
33      public void init() {
34          fessConfig = ComponentUtil.getFessConfig();
35      }
36  
37      @Override
38      public FessConfig getFessConfig() {
39          return fessConfig;
40      }
41  
42      @Override
43      public Logger getLogger() {
44          return logger;
45      }
46  
47      @Override
48      protected Extractor getExtractor(final ResponseData responseData) {
49          final ExtractorFactory extractorFactory = ComponentUtil.getExtractorFactory();
50          if (extractorFactory == null) {
51              throw new FessSystemException("Could not find extractorFactory.");
52          }
53          final Extractor extractor = extractorFactory.getExtractor(responseData.getMimeType());
54          if (logger.isDebugEnabled()) {
55              logger.debug("url=" + responseData.getUrl() + ", extractor=" + extractor);
56          }
57          return extractor;
58      }
59  }