ConverterFactory.java :  » XML » alttext » nl » dedicon » converter » core » Java Open Source

Java Open Source » XML » alttext 
alttext » nl » dedicon » converter » core » ConverterFactory.java
/*
 * Copyright (C) 2010 Dedicon <http://dedicon.nl>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Linking altText statically or dynamically with other modules 
is making a combined work based on altText. Thus, the terms and 
conditions of the GNU General Public License cover
the whole combination.  In addition, as a special exception, 
the copyright holders of altText give you permission to
combine altText program with free software programs or libraries 
that are released under the GNU LGPL or the Common Public License version 1.0. 
You may copy and distribute such a system following the terms 
of the GNU GPL for altText and the licenses of the other code
concerned, provided that you include the source code of that other 
code when and as the GNU GPL requires distribution of source code.

Note that people who make modified versions of altText are not obligated to 
grant this special exception for their modified versions; it is their 
choice whether to do so. The GNU General Public License gives permission 
to release a modified version without this exception; this exception 
also makes it possible to release a modified version which carries
forward this exception.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Author : Javier Asensio Cubero capitan{.}cambio{@}gmail{.}com
 */
package nl.dedicon.converter.core;
import java.util.logging.Logger;


import nl.dedicon.converter.core.io.InputFile;


/**
 * The Class ConverterFactory returns the appropiate concrete converter depending on the 
 * InputFile type and directs the convertion building process.
 * 
 * @author javier
 * @version 1.0
 * @created 21-okt-2009 13:52:58
 */
public class ConverterFactory {

  
  /** The logger. */
  private static Logger logger = Logger.getLogger("nl.dedicon.converter.core");


  /**
   * Calls to the converter methods to build the concrete converter type.
   * 
   * @param cb the cb
   */
  private static void construct(ConverterBuilder cb){
    logger.entering("ConverterFactory","construct");
    cb.setPackage();
    cb.addProcessors();
    logger.exiting("ConverterFactory","construct");
    
  }

  /**
   * Returns the concrete converter depending on the input file.  
   * 
   * @param file    file to be converted
   * 
   * @return the converter to convert the file.
   */
  public static Converter getConverter(InputFile file){
    logger.entering("ConverterFactory","getConverter");
    Converter converter = new Converter(file);
    ConverterBuilder cb = null;
    //Depending on the file type a different converter is returned
    switch (file.getFileType()){
      case TEST:
        cb = new nl.dedicon.converter.tests.core.TestConverterBuilder(converter);
        logger.warning("Creating a new test file. this should only happen in test environment");
        break;
      case DOC:
      case DOCX:
      case RTF:
        cb = new nl.dedicon.converter.ooobased.OOOBasedConverterBuilder(converter);
        logger.info("Coverter created for a OOOBased File");
        break;
      case ODT:
        cb = new nl.dedicon.converter.odt.OdtConverterBuilder(converter);
        
        logger.info("Coverter created for a ODT file");
        break;
      case XML:
        switch (file.getOutputFileType()) {
        case DOCX:
          cb = new nl.dedicon.converter.dtbook.DtbookToDocxConverterBuilder(converter);
          logger.info("Coverter created for a dtbook file to docx");

          break;
        case TTS:  
          cb = new nl.dedicon.converter.dtbook.DtbookToTTSConverterBuilder(converter);
          logger.info("Coverter created for a dtbook file to TTS");
          break;
        case BRAILLE:  
          cb = new nl.dedicon.converter.dtbook.DtbookToBrailleConverterBuilder(converter);
          logger.info("Coverter created for a dtbook file to BRAILLE");
          break;
        case PDF_LARGE:  
        case ODT_LARGE:
          cb = new nl.dedicon.converter.dtbook.DtbookToLargePrintConverterBuilder(converter);
          logger.info("Coverter created for a dtbook file to LARGE PRINT");
          break;
        case ANALYZER:
          cb= new nl.dedicon.converter.analyzer.AnalyzerConverterBuilder(converter);
          break;
        default:
          cb = new nl.dedicon.converter.dtbook.DtbookToOdtConverterBuilder(converter);
          logger.info("Coverter created for a dtbook file to doc,pdf,rtf or odt");
          break;
        }
        
        logger.info("Coverter created for a XML file");
    }
    construct(cb);

    logger.exiting("ConverterFactory","getConverter");
    return converter;
  }

  
  

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.