KickJava   Java API By Example, From Geeks To Geeks.

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


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

14 package org.jahia.services.htmleditors;
15
16 import java.util.Hashtable JavaDoc;
17 import org.jahia.registries.ServicesRegistry;
18 import java.io.Serializable JavaDoc;
19
20 /**
21  * <p>Title: HtmlEditor Interface</p>
22  * <p>Description: Interface for Html Editor</p>
23  * <p>Copyright: Copyright (c) 2002</p>
24  * <p>Company: Jahia S.A.R.L</p>
25  * @author Khue Nguyen
26  * @version 1.0
27  */

28
29 public class JahiaHtmlEditor implements Serializable JavaDoc, HtmlEditor, Comparable JavaDoc {
30
31     private static final org.apache.log4j.Logger logger =
32         org.apache.log4j.Logger.getLogger (JahiaHtmlEditor.class);
33
34     private String JavaDoc id;
35     private String JavaDoc displayName;
36     private String JavaDoc includeFile;
37     private String JavaDoc compatibilityTesterClass;
38     private String JavaDoc baseDirectory;
39     private boolean enableCSS = false;
40     private int rank;
41     private boolean fullScreenOnly = false;
42     private boolean fullScreenCapable = false;
43     private Hashtable JavaDoc cssList = new Hashtable JavaDoc();
44
45     public JahiaHtmlEditor( String JavaDoc id,
46                             String JavaDoc displayName,
47                             String JavaDoc baseDirectory,
48                             String JavaDoc includeFile,
49                             String JavaDoc compatibilityTesterClass,
50                             boolean enableCSS,
51                             int rank ){
52         this.id = id;
53         this.displayName = displayName;
54         this.baseDirectory = baseDirectory;
55         this.includeFile = includeFile;
56         this.compatibilityTesterClass = compatibilityTesterClass;
57         this.enableCSS = enableCSS;
58         this.rank = rank;
59     }
60
61     /**
62      * Returns the unique identifier.
63      *
64      * @return the unique identifier
65      */

66     public String JavaDoc getId(){
67         return this.id;
68     }
69
70     /**
71      * Returns the visual Display Name
72      *
73      * @return the visual Display name
74      */

75     public String JavaDoc getDisplayName(){
76         return this.displayName;
77     }
78
79     /**
80      * Returns the base directory relative to
81      *
82      * <jahia-home>/jsp/jahia/htmleditors
83      *
84      * @return
85      */

86     public String JavaDoc getBaseDirectory(){
87         return this.baseDirectory;
88     }
89
90     /**
91      * Returns the path to the file containing the HTML Editor.
92      * This file will be included in Content Editor View ( Jahia Update Engine ).
93      * The path must be relative to Jahia's HtmlEditor root path:
94      *
95      * <jahia-home>/jsp/jahia/htmleditors
96      *
97      * @return
98      */

99     public String JavaDoc getIncludeFile(){
100         return this.includeFile;
101     }
102
103     /**
104      * Returns true if this Editor can run given Client Capabilities.
105      *
106      * @param clientCapabilities
107      * @return true if this Editor can run for the given ClientCapabilities
108      *
109      * @todo implement the check, actually return true.
110      */

111     public boolean isClientCapable(ClientCapabilities clientCapabilities){
112         if (compatibilityTesterClass != null) {
113             try {
114                 Class JavaDoc compatibilityKlass = Class.forName(
115                     compatibilityTesterClass);
116                 Object JavaDoc objInstance = compatibilityKlass.newInstance();
117                 if (!(objInstance instanceof EditorCompatibilityTesteable)) {
118                     logger.error("The class " + compatibilityTesterClass + " is not an HTML editor compatibility class !");
119                     return false;
120                 }
121                 EditorCompatibilityTesteable compatibilityTester = (EditorCompatibilityTesteable) objInstance;
122                 return compatibilityTester.isCompatible(clientCapabilities);
123             } catch (ClassNotFoundException JavaDoc cnfe) {
124                 logger.error("Error while testing HTML editor compatibility with current user's browser platform", cnfe);
125             } catch (InstantiationException JavaDoc ie) {
126                 logger.error("Error while creating instance of HTML editor compatibility tester", ie);
127             } catch (IllegalAccessException JavaDoc iae) {
128                 logger.error("Error while creating instance of HTML editor compatibility tester", iae);
129             }
130             return false;
131         } else {
132             return true;
133         }
134     }
135
136     /**
137      * Returns true if this Editor is authorized for a given site.
138      *
139      * @param siteID
140      * @return true if the given site has autorization to use this Editor
141      */

142     public boolean isSiteAuthorized(int siteID){
143         boolean res = ServicesRegistry.getInstance()
144                        .getHtmlEditorsService()
145                        .isSiteAutorized(siteID,this.getId());
146         return res;
147     }
148
149     /**
150      * Returns true if this Editor support CSS.
151      *
152      * @return true if CSS selection should be displayed for this CSS
153      */

154     public boolean enableCSS(){
155         return this.enableCSS;
156     }
157
158     /**
159      * @return an int representing the ranking specified in the HTML editor's
160      * configuration file.
161      */

162     public int getRank() {
163         return this.rank;
164     }
165
166     public int compareTo(Object JavaDoc o) throws ClassCastException JavaDoc {
167         // first criteria for sorting is ranking (if available), then display
168
// name
169
JahiaHtmlEditor right = (JahiaHtmlEditor) o;
170         if ((getRank() != -1) && (right.getRank() != -1)) {
171             return new Integer JavaDoc(getRank()).compareTo(new Integer JavaDoc(right.getRank()));
172         }
173         return getDisplayName().compareTo(right.getDisplayName());
174     }
175
176 }
177
Popular Tags