1   /*
2    * Copyright 2003 - 2013 The eFaps Team
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, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Revision:        $Rev$
17   * Last Changed:    $Date$
18   * Last Changed By: $Author$
19   */
20  
21  package org.efaps.update.schema.program.staticsource;
22  
23  import org.efaps.ci.CIAdminProgram;
24  import org.efaps.ci.CIType;
25  import org.efaps.db.Checkout;
26  import org.efaps.db.Instance;
27  import org.efaps.update.schema.program.staticsource.WikiCompiler.OneWiki;
28  import org.efaps.util.EFapsException;
29  import org.efaps.wikiutil.export.html.WEMHtml;
30  import org.efaps.wikiutil.parser.gwiki.GWikiParser;
31  import org.efaps.wikiutil.parser.gwiki.javacc.ParseException;
32  
33  /**
34   * TODO comment!
35   *
36   * @author The eFaps Team
37   * @version $Id$
38   */
39  public class WikiCompiler
40      extends AbstractStaticSourceCompiler<OneWiki>
41  {
42  
43      /**
44       * {@inheritDoc}
45       */
46      @Override
47      protected CIType getClassName4Type()
48      {
49          return CIAdminProgram.Wiki;
50      }
51  
52      /**
53       * {@inheritDoc}
54       */
55      @Override
56      protected CIType getClassName4Type2Type()
57      {
58          return CIAdminProgram.Wiki2Wiki;
59      }
60  
61      /**
62       * {@inheritDoc}
63       */
64      @Override
65      protected CIType getClassName4TypeCompiled()
66      {
67          return CIAdminProgram.WikiCompiled;
68      }
69  
70      /**
71       * {@inheritDoc}
72       */
73      @Override
74      protected String getCompiledString(final Instance _instance)
75          throws EFapsException
76      {
77          final Checkout checkout = new Checkout(_instance);
78          final WEMHtml wemhtml = new WEMHtml();
79          try {
80              GWikiParser.parse(wemhtml, checkout.execute(), "UTF-8");
81          } catch (final ParseException e) {
82              throw new EFapsException(WikiCompiler.class, "ParseException", e);
83          }
84          return wemhtml.getHtml();
85      }
86  
87       /**
88        * {@inheritDoc}
89        */
90      @Override
91      protected OneWiki getNewSource(final String _name,
92                                            final Instance _instance)
93      {
94          return new OneWiki(_name, _instance);
95      }
96  
97      /**
98       * Class representing one wiki file in the eFaps DataBase.
99       *
100      */
101     public static class OneWiki
102         extends AbstractStaticSourceCompiler.AbstractSource
103     {
104         /**
105          * Constructor.
106          * @param _name name
107          * @param _instance  Instance
108          */
109         public OneWiki(final String _name,
110                        final Instance _instance)
111         {
112             super(_name, _instance);
113         }
114     }
115 }