View Javadoc

1   /*
2    * Copyright (C) 2013 Room Work eXperience
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package net.rwx.maven.asciidoc.services.impl;
18  
19  import com.google.inject.Inject;
20  import net.rwx.maven.asciidoc.configuration.Document;
21  import net.rwx.maven.asciidoc.backends.Backend;
22  import net.rwx.maven.asciidoc.backends.BackendService;
23  import net.rwx.maven.asciidoc.backends.AsciidocBackendTransformation;
24  import net.rwx.maven.asciidoc.services.AsciidocService;
25  import net.rwx.maven.asciidoc.services.FopService;
26  import net.rwx.maven.asciidoc.services.ServiceOrchestrator;
27  import net.rwx.maven.asciidoc.services.TransformationService;
28  import net.rwx.maven.asciidoc.utils.FileUtils;
29  import org.apache.maven.plugin.logging.Log;
30  
31  /**
32   *
33   * @author Arnaud Fonce <arnaud.fonce@r-w-x.net>
34   */
35  public class ServiceOrchestratorImpl implements ServiceOrchestrator {
36      
37      private Log logger;
38      
39      @Inject
40      private BackendService backendService;
41      
42      @Inject
43      private AsciidocService asciidocService;
44      
45      @Inject
46      private TransformationService transformationService;
47      
48      @Inject
49      private FopService fopService;
50      
51      @Override
52      public void execute( Document document ) {
53          try {
54              processDocument( document );
55          } catch ( Exception ex ) {
56              logger.error( "Unable to compile a document", ex );
57          }
58      }
59      
60      private void processDocument( Document document ) throws Exception {
61          logger.info( String.format( "Starting Asciidoc compilation for document [%s]", document.getTitle() ) );
62          
63          String backendName = document.getBackend();
64          Backend backend = backendService.getBackend( backendName );
65  
66          String input = document.getPath();
67          asciidocService.execute( input, document, backend );
68          transformationService.execute( asciidocService.getOuputPath(), document, backend );
69          fopService.execute( transformationService.getOuputPath(), document, backend);
70          
71          FileUtils.moveFileToDirectory( fopService.getOuputPath(), document.getOutputPath() );
72      }
73      
74      @Override
75      public void setLogger( Log logger ) {
76          this.logger = logger;
77          asciidocService.setLogger( logger );
78          transformationService.setLogger( logger );
79          fopService.setLogger( logger );
80      }
81  }