View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.csl;
20  
21  import java.io.IOException;
22  
23  import org.mycore.common.config.MCRConfigurationException;
24  
25  import de.undercouch.citeproc.CSL;
26  
27  public class MCRCSLTransformerInstance implements AutoCloseable {
28  
29      private final AutoCloseable closeable;
30  
31      private final CSL citationProcessor;
32  
33      private final MCRItemDataProvider dataProvider;
34  
35      public MCRCSLTransformerInstance(String style, String format, AutoCloseable closeable,
36          MCRItemDataProvider dataProvider) {
37          this.closeable = closeable;
38          this.dataProvider = dataProvider;
39          try {
40              this.citationProcessor = new CSL(this.dataProvider, style);
41          } catch (IOException e) {
42              throw new MCRConfigurationException("Error while creating CSL with Style " + style, e);
43          }
44          this.citationProcessor.setOutputFormat(format);
45  
46      }
47  
48      public CSL getCitationProcessor() {
49          return citationProcessor;
50      }
51  
52      public MCRItemDataProvider getDataProvider() {
53          return dataProvider;
54      }
55  
56      @Override
57      public void close() throws Exception {
58          this.closeable.close();
59      }
60  }