KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > htmleditors > HtmlEditorsBaseService


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
package org.jahia.services.htmleditors;
14
15 import java.io.File JavaDoc;
16 import java.util.Enumeration JavaDoc;
17 import java.util.Vector JavaDoc;
18
19 import org.jahia.exceptions.JahiaException;
20 import org.jahia.exceptions.JahiaInitializationException;
21 import org.jahia.registries.ServicesRegistry;
22 import org.jahia.services.sites.JahiaSite;
23 import org.jahia.settings.SettingsBean;
24
25
26 /**
27  * Html Editors Service Default Implementation.
28  *
29  * @author Khue Nguyen
30  */

31 public class HtmlEditorsBaseService extends HtmlEditorsService
32 {
33     private static org.apache.log4j.Logger logger =
34             org.apache.log4j.Logger.getLogger (HtmlEditorsBaseService.class);
35
36     static private HtmlEditorsBaseService instance = null;
37     private HtmlEditorsFactory htmlEditorsFactory = null;
38     private String JavaDoc htmlEditorsRootDiskPath = "";
39     private String JavaDoc htmlEditorsContextPath = "";
40     private String JavaDoc htmlEditorsConfigFile = "";
41
42     protected HtmlEditorsBaseService() {
43         logger.info("***** Starting the HtmlEditorsBaseService *****" );
44     }
45
46      public static HtmlEditorsBaseService getInstance() {
47          if (instance == null) {
48              instance = new HtmlEditorsBaseService();
49          }
50          return instance;
51      }
52
53      public void init( SettingsBean jSettings )
54      throws JahiaInitializationException {
55
56          this.htmlEditorsRootDiskPath = jSettings.getJahiaHtmlEditorsDiskPath();
57          this.htmlEditorsContextPath = jSettings.getHtmlEditorsContext();
58          StringBuffer JavaDoc buff = new StringBuffer JavaDoc(jSettings.getJahiaEtcDiskPath());
59          buff.append(File.separator);
60          buff.append("htmleditors");
61          buff.append(File.separator);
62          buff.append(this.configFileName);
63          this.htmlEditorsConfigFile = buff.toString();
64
65          try {
66              htmlEditorsFactory =
67                  new JahiaHtmlEditorsFactory( this.htmlEditorsConfigFile );
68          } catch ( Throwable JavaDoc t ){
69              throw new JahiaInitializationException("Error init Html Editor Service",t);
70          }
71      }
72
73      /**
74       * Reload configuration file from disk
75       *
76       * @throws JahiaException
77       */

78      public void reloadConfigurationFile() throws JahiaException{
79          htmlEditorsFactory =
80                  new JahiaHtmlEditorsFactory( this.htmlEditorsConfigFile );
81      }
82
83     /**
84      * Returns an enumeration of all Html Editors registered in the System
85      *
86      * @return all Html Editors registered in the system
87      * @throws JahiaException
88      */

89     public Enumeration JavaDoc getEditors()
90     throws JahiaException
91     {
92         return htmlEditorsFactory.getEditors().elements();
93     }
94
95     /**
96      * Returns an enumeration of all Html Editors a given site can view.
97      *
98      * @param siteID
99      * @return all Html Editors a given site can view
100      * @throws JahiaException
101      */

102     public Enumeration JavaDoc getEditors(int siteID)
103     throws JahiaException
104     {
105         Vector JavaDoc res = new Vector JavaDoc();
106         Vector JavaDoc editors = htmlEditorsFactory.getEditors();
107         int size = editors.size();
108         HtmlEditor htmlEditor = null;
109         for ( int i=0 ; i<size ; i++ ){
110             htmlEditor = (HtmlEditor)editors.get(i);
111             if ( htmlEditor.isSiteAuthorized(siteID) ){
112                 res.add(htmlEditor);
113             }
114         }
115         return res.elements();
116     }
117
118     /**
119      * Returns an enumeration of all Html Editor CSSs a given site can view.
120      *
121      * @param siteID
122      * @return all Html Editor CSSs a given site can view
123      * @throws JahiaException
124      */

125     public Enumeration JavaDoc getCSSs(int siteID)
126     throws JahiaException
127     {
128         JahiaSite site = ServicesRegistry.getInstance()
129                        .getJahiaSitesService().getSite(siteID);
130         Vector JavaDoc res = new Vector JavaDoc();
131
132         if ( site == null ){
133             return res.elements();
134         }
135
136         Vector JavaDoc cssList = htmlEditorsFactory.getCSSs();
137         int size = cssList.size();
138         HtmlEditorCSS css = null;
139         for ( int i=0 ; i<size ; i++ ){
140             css = (HtmlEditorCSS)cssList.get(i);
141             if ( css.isShared() || css.isSiteAllowed(site.getSiteKey()) ){
142                 res.add(css);
143             }
144         }
145         return res.elements();
146     }
147
148     /**
149      * Returns an Editor looking at it id
150      *
151      * @param id the Editor identifier
152      * @return an Editor looking at it id
153      * @throws JahiaException
154      */

155     public HtmlEditor getEditor(String JavaDoc id)
156     throws JahiaException
157     {
158         return htmlEditorsFactory.getEditor(id);
159     }
160
161     /**
162      * Authorize the site to use the given Editor
163      *
164      * @param siteID
165      * @param id the Editor identifier
166      * @throws JahiaException
167      * @todo : not implemented yet
168      */

169     public void authorizeSite(int siteID, String JavaDoc id)
170     throws JahiaException
171     {
172         // TODO
173
}
174
175     /**
176      * unauthorize the site to use the given Editor
177      *
178      * @param siteID
179      * @param id
180      * @throws JahiaException
181      */

182     public void unAuthorizeSite(int siteID, String JavaDoc id)
183     throws JahiaException
184     {
185         // TODO
186
}
187
188     /**
189      * Returns true if the site has autorization to use the given Editor
190      *
191      * @param siteID
192      * @param id the Editor identifier
193      * @return true if the site has autorization to use the given Editor
194      * @todo : actually return true
195      */

196     public boolean isSiteAutorized(int siteID, String JavaDoc id)
197     {
198         return true;
199     }
200
201 }
202
203
Popular Tags