KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Hashtable JavaDoc;
16 import java.util.Vector JavaDoc;
17
18 import org.jahia.exceptions.JahiaException;
19 import java.util.Collections JavaDoc;
20
21 /**
22  * Html Editors Factory Default implementation
23  *
24  * @author Khue Nguyen
25  */

26 class JahiaHtmlEditorsFactory implements HtmlEditorsFactory
27 {
28     private Hashtable JavaDoc htmlEditors;
29     private Hashtable JavaDoc htmlEditorCSSs;
30     private JahiaHtmlEditorsDigester htmlEditorsDigester;
31
32     /**
33      * Xml Configuration file.
34      */

35     private String JavaDoc configFile;
36
37     /**
38      *
39      * @param configFile, full path to the configuration file
40      */

41     public JahiaHtmlEditorsFactory(String JavaDoc configFile) throws JahiaException{
42         this.configFile = configFile;
43         this.htmlEditors = new Hashtable JavaDoc();
44         this.htmlEditorCSSs = new Hashtable JavaDoc();
45         this.htmlEditorsDigester = new JahiaHtmlEditorsDigester();
46
47         if ( !loadEditors() ){
48             throw new JahiaException("Error load html editors config file",
49                                      "Error load html editors config file",
50                                      JahiaException.CONFIG_ERROR,
51                                      JahiaException.CONFIG_ERROR);
52         }
53     }
54
55     /**
56      * Returns a Vector of all Html Editors registered in the System
57      *
58      * @return all Html Editors registered in the system
59      * @throws JahiaException
60      */

61     public Vector JavaDoc getEditors()
62     throws JahiaException
63     {
64         Vector JavaDoc v = new Vector JavaDoc(this.htmlEditors.values());
65         Collections.sort(v);
66         return v;
67     }
68
69     /**
70      * Returns a Vector of all Html Editor CSS registered in the System
71      *
72      * @return all Html Editor CSS registered in the system
73      * @throws JahiaException
74      */

75     public Vector JavaDoc getCSSs()
76     throws JahiaException
77     {
78         Vector JavaDoc v = new Vector JavaDoc(this.htmlEditorCSSs.values());
79         return v;
80     }
81
82     /**
83      * Returns an Editor looking at it id
84      *
85      * @param id the Editor identifier
86      * @return an Editor looking at it id
87      * @throws JahiaException
88      */

89     public HtmlEditor getEditor(String JavaDoc id)
90     throws JahiaException {
91         if ( id == null ){
92             return null;
93         }
94         return (HtmlEditor)this.htmlEditors.get(id);
95     }
96
97     /**
98      * Returns an CSS looking at it id
99      *
100      * @param id the CSS identifier
101      * @return an CSS looking at it id
102      * @throws JahiaException
103      */

104     public HtmlEditorCSS getCSS(String JavaDoc id) throws JahiaException {
105         if ( id == null ){
106             return null;
107         }
108         return (HtmlEditorCSS)this.htmlEditorCSSs.get(id);
109     }
110
111     /**
112      * Load Html Editors from persistence, the internal list of
113      * Html Editors is cleared before loading again.
114      *
115      */

116     public boolean loadEditors(){
117
118         boolean success = this.htmlEditorsDigester.loadHtmlEditors(this.configFile);
119         if ( !success ){
120             return false;
121         }
122
123         this.htmlEditors = new Hashtable JavaDoc();
124
125         Vector JavaDoc v = this.htmlEditorsDigester.getHtmlEditors();
126         int size = v.size();
127         HtmlEditor editor = null;
128         for ( int i=0; i<size; i++ ){
129             editor = (HtmlEditor)v.get(i);
130             this.htmlEditors.put(editor.getId(),editor);
131         }
132
133         v = this.htmlEditorsDigester.getCSSList();
134         size = v.size();
135         HtmlEditorCSS css = null;
136         for ( int i=0; i<size; i++ ){
137             css = (HtmlEditorCSS)v.get(i);
138             this.htmlEditorCSSs.put(css.getId(),css);
139         }
140         return true;
141     }
142 }
143
144
Popular Tags