KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > sites > JahiaSitesSlideService


1 package org.jahia.services.sites;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.util.Enumeration JavaDoc;
7
8 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
9 import javax.xml.parsers.ParserConfigurationException JavaDoc;
10 import javax.xml.parsers.SAXParser JavaDoc;
11 import javax.xml.parsers.SAXParserFactory JavaDoc;
12
13 import log4j.Log4jLogger;
14
15 import org.apache.slide.common.JahiaDomain;
16 import org.apache.slide.util.conf.Configuration;
17 import org.apache.slide.util.conf.ConfigurationElement;
18 import org.apache.slide.util.conf.Populate;
19 import org.jahia.exceptions.JahiaException;
20 import org.jahia.exceptions.JahiaInitializationException;
21 import org.jahia.registries.ServicesRegistry;
22 import org.jahia.services.webdav.stores.FileContentStore;
23 import org.jahia.settings.SettingsBean;
24 import org.xml.sax.InputSource JavaDoc;
25 import org.xml.sax.SAXException JavaDoc;
26
27 /**
28  * Created by IntelliJ IDEA.
29  * User: toto
30  * Date: Apr 24, 2003
31  * Time: 1:50:25 PM
32  */

33 public class JahiaSitesSlideService extends JahiaSitesBaseService {
34
35     /**
36      * Default constructor, creates a new <code>JahiaSitesSlideService</code> instance.
37      */

38     private JahiaSitesSlideService () throws JahiaException {
39     }
40
41
42     /**
43      * Retrieves the unique instance of this singleton class.
44      *
45      * @return the unique instance of this class
46      */

47     public static synchronized JahiaSitesBaseService getInstance ()
48             throws JahiaException {
49         if (instance == null) {
50             instance = new JahiaSitesSlideService ();
51         }
52         return instance;
53     }
54
55
56     /**
57      * @param jSettings the Jahia configuration settings
58      *
59      * @throws JahiaInitializationException when an initialization exception occured
60      */

61     public synchronized void init (SettingsBean jSettings)
62             throws JahiaInitializationException {
63         super.init (jSettings);
64
65         try {
66             Enumeration JavaDoc e = ServicesRegistry.getInstance ().getJahiaSitesService ().getSites ();
67             String JavaDoc slideConfDirPath = jSettings.getJahiaEtcDiskPath () + File.separator + "slide" + File.separator;
68
69             Configuration domainConfig = getConfiguration(new File JavaDoc(slideConfDirPath + "domain.xml"));
70             JahiaDomain.init(domainConfig);
71
72             try {
73                 Configuration defs =
74                         getConfiguration (new File JavaDoc (slideConfDirPath + "defs.xml"))
75                         .getConfiguration ("definition");
76                 Configuration data =
77                         getConfiguration (new File JavaDoc (slideConfDirPath + "data.xml"))
78                         .getConfiguration ("data");
79                 Configuration conf =
80                         getConfiguration (new File JavaDoc (slideConfDirPath + "conf.xml"))
81                         .getConfiguration ("configuration");
82
83                 JahiaDomain.init(defs,data,conf,new Log4jLogger());
84             } catch (Exception JavaDoc ex) {
85                 ex.printStackTrace (); //To change body of catch statement use Options | File Templates.
86
} catch (FactoryConfigurationError JavaDoc factoryConfigurationError) {
87                 factoryConfigurationError.printStackTrace (); //To change body of catch statement use Options | File Templates.
88
}
89
90             FileContentStore.setContentPath (jSettings.getSlideContentDiskPath());
91
92             while (e.hasMoreElements ()) {
93                 JahiaSite jahiaSite = (JahiaSite) e.nextElement ();
94                 JahiaDomain.getInstance().addNamespace (jahiaSite.getSiteKey ());
95             }
96         } catch (Throwable JavaDoc e1) {
97             e1.printStackTrace();
98             throw new JahiaInitializationException ("Cannot initialize Slide service", e1);
99             //e1.printStackTrace(); //To change body of catch statement use Options | File Templates.
100
}
101     }
102
103     /**
104      * Get configuration object from a file.
105      */

106     protected Configuration getConfiguration (File JavaDoc file)
107             throws IOException JavaDoc, SAXException JavaDoc, ParserConfigurationException JavaDoc,
108             FactoryConfigurationError JavaDoc {
109
110         // Get XML parser
111
SAXParserFactory JavaDoc factory = SAXParserFactory.newInstance ();
112         factory.setNamespaceAware (false);
113         factory.setValidating (false);
114         SAXParser JavaDoc parser = factory.newSAXParser ();
115
116         // Parse XML file
117
FileInputStream JavaDoc is = new FileInputStream JavaDoc (file);
118         Populate pop = new Populate ();
119         return new ConfigurationElement (pop.load (new InputSource JavaDoc (is),
120                 parser.getXMLReader ()));
121
122     }
123
124     /**
125      * Add a new site only if there is no other site with same server name
126      *
127      * @return boolean false if there is another site using same server name
128      */

129     public synchronized boolean addSite (JahiaSite site)
130             throws JahiaException {
131         boolean res = super.addSite (site);
132         if (res) {
133             JahiaDomain.getInstance().addNamespace (site.getSiteKey ());
134         }
135         return res;
136     }
137
138     /**
139      * Removes the specified site.
140      *
141      * @param site the site to be removed
142      *
143      * @throws JahiaException when any error occured.
144      */

145     public synchronized void removeSite (JahiaSite site) throws JahiaException {
146         JahiaDomain.getInstance().removeNamespace (site.getSiteKey ());
147         super.removeSite (site);
148     }
149
150     public void onCachePut(String JavaDoc cacheName, Object JavaDoc entryKey) {
151         super.onCachePut(cacheName, entryKey);
152
153 // if (entryValue != null && ((CacheEntry)entryValue).getObject() !=null) {
154
// JahiaSite site = (JahiaSite) ((CacheEntry) entryValue).getObject();
155
// if (JahiaDomain.getInstance().getNamespace(site.getSiteKey()) == null) {
156
// JahiaDomain.getInstance().addNamespace (site.getSiteKey ());
157
// }
158
// }
159
}
160
161     public Configuration getConfiguration() {
162         return JahiaDomain.getInstance().getConfiguration();
163     }
164     
165 }
166
Popular Tags