1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.convert;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.util.MaintenanceUtil;
20  import com.liferay.portlet.wiki.model.WikiPage;
21  import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
22  import com.liferay.portlet.wiki.translators.ClassicToCreoleTranslator;
23  
24  import java.util.List;
25  
26  /**
27   * <a href="ConvertWikiCreole.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Jorge Ferrer
30   */
31  public class ConvertWikiCreole extends ConvertProcess {
32  
33      public String getDescription() {
34          return "convert-wiki-pages-from-classic-wiki-to-creole-format";
35      }
36  
37      public boolean isEnabled() {
38          boolean enabled = false;
39  
40          try {
41              int pagesCount = WikiPageLocalServiceUtil.getPagesCount(
42                  "classic_wiki");
43  
44              if (pagesCount > 0) {
45                  enabled = true;
46              }
47          }
48          catch (Exception e) {
49              _log.error(e, e);
50          }
51  
52          return enabled;
53      }
54  
55      protected void doConvert() throws Exception {
56          List<WikiPage> pages = WikiPageLocalServiceUtil.getPages(
57              "classic_wiki");
58  
59          ClassicToCreoleTranslator translator = new ClassicToCreoleTranslator();
60  
61          MaintenanceUtil.appendStatus(
62              "Converting " + pages.size() +
63                  " Wiki pages from Classic Wiki to Creole format");
64  
65          for (int i = 0; i < pages.size(); i++) {
66              if ((i > 0) && (i % (pages.size() / 4) == 0)) {
67                  MaintenanceUtil.appendStatus((i * 100. / pages.size()) + "%");
68              }
69  
70              WikiPage page = pages.get(i);
71  
72              page.setFormat("creole");
73  
74              page.setContent(translator.translate(page.getContent()));
75  
76              WikiPageLocalServiceUtil.updateWikiPage(page);
77          }
78      }
79  
80      private static Log _log = LogFactoryUtil.getLog(ConvertWikiCreole.class);
81  
82  }