1 package org.jahia.services.sites; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.IOException ; 6 import java.util.Enumeration ; 7 8 import javax.xml.parsers.FactoryConfigurationError ; 9 import javax.xml.parsers.ParserConfigurationException ; 10 import javax.xml.parsers.SAXParser ; 11 import javax.xml.parsers.SAXParserFactory ; 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 ; 25 import org.xml.sax.SAXException ; 26 27 33 public class JahiaSitesSlideService extends JahiaSitesBaseService { 34 35 38 private JahiaSitesSlideService () throws JahiaException { 39 } 40 41 42 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 61 public synchronized void init (SettingsBean jSettings) 62 throws JahiaInitializationException { 63 super.init (jSettings); 64 65 try { 66 Enumeration e = ServicesRegistry.getInstance ().getJahiaSitesService ().getSites (); 67 String slideConfDirPath = jSettings.getJahiaEtcDiskPath () + File.separator + "slide" + File.separator; 68 69 Configuration domainConfig = getConfiguration(new File (slideConfDirPath + "domain.xml")); 70 JahiaDomain.init(domainConfig); 71 72 try { 73 Configuration defs = 74 getConfiguration (new File (slideConfDirPath + "defs.xml")) 75 .getConfiguration ("definition"); 76 Configuration data = 77 getConfiguration (new File (slideConfDirPath + "data.xml")) 78 .getConfiguration ("data"); 79 Configuration conf = 80 getConfiguration (new File (slideConfDirPath + "conf.xml")) 81 .getConfiguration ("configuration"); 82 83 JahiaDomain.init(defs,data,conf,new Log4jLogger()); 84 } catch (Exception ex) { 85 ex.printStackTrace (); } catch (FactoryConfigurationError factoryConfigurationError) { 87 factoryConfigurationError.printStackTrace (); } 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 e1) { 97 e1.printStackTrace(); 98 throw new JahiaInitializationException ("Cannot initialize Slide service", e1); 99 } 101 } 102 103 106 protected Configuration getConfiguration (File file) 107 throws IOException , SAXException , ParserConfigurationException , 108 FactoryConfigurationError { 109 110 SAXParserFactory factory = SAXParserFactory.newInstance (); 112 factory.setNamespaceAware (false); 113 factory.setValidating (false); 114 SAXParser parser = factory.newSAXParser (); 115 116 FileInputStream is = new FileInputStream (file); 118 Populate pop = new Populate (); 119 return new ConfigurationElement (pop.load (new InputSource (is), 120 parser.getXMLReader ())); 121 122 } 123 124 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 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 cacheName, Object entryKey) { 151 super.onCachePut(cacheName, entryKey); 152 153 } 160 161 public Configuration getConfiguration() { 162 return JahiaDomain.getInstance().getConfiguration(); 163 } 164 165 } 166 | Popular Tags |