1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.wiki.engines.friki;
16  
17  import com.efsol.friki.BasicDriver;
18  
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
22  
23  import java.util.HashMap;
24  import java.util.Iterator;
25  import java.util.Map;
26  
27  import org.stringtree.util.tract.Tract;
28  
29  /**
30   * <a href="NodeRepository.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class NodeRepository extends BasicDriver {
35  
36      public NodeRepository(long nodeId) {
37          _nodeId = nodeId;
38          _names = new HashMap<String, Boolean>();
39      }
40  
41      public Iterator<String> allPageNames() {
42          return _names.keySet().iterator();
43      }
44  
45      public String backup(String name) {
46          return name;
47      }
48  
49      public boolean contains(String name) {
50          boolean exists = false;
51  
52          try {
53              Boolean existsObj = _names.get(name);
54  
55              if (existsObj == null) {
56                  if (WikiPageLocalServiceUtil.getPagesCount(
57                          _nodeId, name, true) > 0) {
58  
59                      existsObj = Boolean.TRUE;
60                  }
61                  else {
62                      existsObj = Boolean.FALSE;
63                  }
64  
65                  _names.put(name, existsObj);
66              }
67  
68              exists = existsObj.booleanValue();
69          }
70          catch (Exception e) {
71              _log.error(e, e);
72          }
73  
74          return exists;
75      }
76  
77      public Tract get(String name) {
78          return null;
79      }
80  
81      public Map<String, Boolean> getTitles() {
82          return _names;
83      }
84  
85      public void put(String name, Tract page) {
86      }
87  
88      private static Log _log = LogFactoryUtil.getLog(NodeRepository.class);
89  
90      private long _nodeId;
91      private Map<String, Boolean> _names;
92  
93  }