1 20 package org.apache.slide.projector; 21 22 import java.io.InputStream ; 23 import java.lang.reflect.Method ; 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 27 import org.apache.commons.httpclient.Credentials; 28 import org.apache.commons.httpclient.UsernamePasswordCredentials; 29 import org.apache.slide.projector.i18n.ErrorMessage; 30 import org.apache.slide.projector.repository.Configurable; 31 import org.apache.slide.projector.repository.Repository; 32 import org.jdom.Document; 33 import org.jdom.Element; 34 import org.jdom.input.SAXBuilder; 35 36 public class Projector { 37 private final static Logger logger = Logger.getLogger(Projector.class.getName()); 38 39 private static Credentials credentials; 40 private static Repository repository; 41 private static String projectorDir, applicationsDir, workDir; 42 43 public static void configure(InputStream configuration) throws ConfigurationException { 44 logger.log(Level.INFO, "Starting projector"); 45 SAXBuilder saxBuilder = new SAXBuilder(); 46 try { 47 Document document = saxBuilder.build(configuration); 48 Element credentialsElement = document.getRootElement().getChild("credentials"); 49 String user = credentialsElement.getAttributeValue("user"); 50 String password = credentialsElement.getAttributeValue("password"); 51 credentials = new UsernamePasswordCredentials(user, password); 52 Element repositoryElement = document.getRootElement().getChild("repository"); 53 String repositoryClassname = repositoryElement.getAttributeValue("class"); 54 Class repositoryClass = Class.forName(repositoryClassname); 55 Method getInstanceMethod = repositoryClass.getMethod("getInstance", new Class [0]); 56 repository = (Repository)getInstanceMethod.invoke(null, null); 57 Element configurationElement = repositoryElement.getChild("configuration"); 58 if ( repository instanceof Configurable ) { 59 ((Configurable)repository).configure(configurationElement); 60 } 61 Element pathsElement = repositoryElement.getChild("paths"); 62 projectorDir = pathsElement.getChildText("projector"); 63 applicationsDir = pathsElement.getChildText("applications"); 64 workDir = pathsElement.getChildText("work"); 65 } catch (Exception e) { 66 throw new ConfigurationException(new ErrorMessage("projector/configurationFailed"), e); 67 } 68 } 69 70 public static Repository getRepository() { 71 return repository; 72 } 73 74 public static String getApplicationsDir() { 75 return applicationsDir; 76 } 77 78 public static String getProjectorDir() { 79 return projectorDir; 80 } 81 82 public static String getWorkDir() { 83 return workDir; 84 } 85 86 public static Credentials getCredentials() { 87 return credentials; 88 } 89 } | Popular Tags |