You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by df...@apache.org on 2004/05/11 17:23:43 UTC

cvs commit: jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/connector/webdav WebdavConnector.java

dflorey     2004/05/11 08:23:43

  Modified:    proposals/projector/src/java/org/apache/slide/projector/engine
                        ProcessServlet.java ProcessorManager.java
               proposals/projector/src/java/org/apache/slide/projector
                        Constants.java
               proposals/projector/src/java/org/apache/slide/projector/connector
                        Connector.java
               proposals/projector/src/java/org/apache/slide/projector/connector/webdav
                        WebdavConnector.java
  Added:       proposals/projector/src/java/org/apache/slide/projector/engine
                        PackageManager.java
  Log:
  Introduction of PackageManager to handle different applications
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessServlet.java
  
  Index: ProcessServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessServlet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProcessServlet.java	3 May 2004 14:28:36 -0000	1.2
  +++ ProcessServlet.java	11 May 2004 15:23:43 -0000	1.3
  @@ -29,7 +29,7 @@
       private final static String allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
       
       public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  -        Context context = new HttpContext(request, response);
  +    	Context context = new HttpContext(request, response);
           URI uri = new URIResource(request.getRequestURI().substring(request.getContextPath().length()+request.getServletPath().length()));
           try {
               Result result;
  
  
  
  1.3       +18 -26    jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessorManager.java
  
  Index: ProcessorManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessorManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProcessorManager.java	5 May 2004 09:58:08 -0000	1.2
  +++ ProcessorManager.java	11 May 2004 15:23:43 -0000	1.3
  @@ -28,8 +28,6 @@
    * The ProcessorManager is responsible for loading processors and their
    * configuration. Because every processor is located via its URI, it might be
    * possible to handle different versions of the same processor.
  - * FIXME: The ProcessorManager locates the processor class files by searching the
  - * content repository. There is no need to register them manually.
    * They are reloaded if an event occurs that indicates, that the class or configuration has changed
    * or was updated.
    */
  @@ -52,31 +50,25 @@
   
       private ProcessorManager() {
           configure();
  -        ConnectorFactory.getConnector().subscribe("Update", Constants.CONFIG_DIR + PROCESSOR_CONFIG,
  -                0, Constants.SUBSCRIPTION_LIFETIME, Constants.NOTIFICATION_DELAY,
  -                new Subscriber() {
  -                    public void notify(Map information) {
  -                        logger.log(Level.INFO, "Reloading processor manager");
  -                        configure();
  -                    }
  -                }, Constants.CREDENTIALS);
       }
  -
  -    private void configure() {
  -        // The processors should be queried via searching the content repository. There is no need for a manual configuration.
  -        // FIXME: This is needed until processors can be found via content repository search! Type search is not available yet...
  -        processorMap = new HashMap(256);
  -        configuredProcessors = new ArrayList();
  -        processorDescriptors = new ArrayList();
  -        try {
  -            InputStream configuration = ((StreamableResource)ConnectorFactory.getConnector().getResource(new URIResource(Constants.CONFIG_DIR + PROCESSOR_CONFIG), Constants.CREDENTIALS)).getInputStream();
  -            SimpleImporter importer = new SimpleImporter();
  -            ConfigurationHandler handler = new ConfigurationHandler();
  -            importer.addSimpleImportHandler(handler);
  -            importer.parse(new InputSource(configuration));
  -        } catch (Exception exception) {
  -            logger.log(Level.SEVERE, "Error while parsing configuration", exception);
  -        }
  +    	
  +    void configure() {
  +    	processorMap = new HashMap(256);
  +    	configuredProcessors = new ArrayList();
  +    	processorDescriptors = new ArrayList();
  +    	try {
  +    		List processorConfigurations = PackageManager.getInstance().getProcessorConfigurations();
  +    		for ( Iterator i = processorConfigurations.iterator(); i.hasNext(); ) {
  +    			URI configurationUri = (URI)i.next();
  +    			InputStream configuration = ((StreamableResource)ConnectorFactory.getConnector().getResource(configurationUri, Constants.CREDENTIALS)).getInputStream();
  +    			SimpleImporter importer = new SimpleImporter();
  +    			ConfigurationHandler handler = new ConfigurationHandler();
  +    			importer.addSimpleImportHandler(handler);
  +    			importer.parse(new InputSource(configuration));
  +    		}
  +    	} catch (Exception exception) {
  +    		logger.log(Level.SEVERE, "Error while parsing configuration", exception);
  +    	}
       }
   
       public static ProcessorManager getInstance() {
  
  
  
  1.1                  jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/PackageManager.java
  
  Index: PackageManager.java
  ===================================================================
  package org.apache.slide.projector.engine;
  
  import de.zeigermann.xml.simpleImporter.DefaultSimpleImportHandler;
  import de.zeigermann.xml.simpleImporter.SimpleImporter;
  import de.zeigermann.xml.simpleImporter.SimplePath;
  
  import org.apache.slide.projector.*;
  import org.apache.slide.projector.connector.ConnectorFactory;
  import org.apache.slide.projector.connector.Subscriber;
  import org.apache.slide.projector.resource.ArrayResource;
  import org.apache.slide.projector.resource.StreamableResource;
  import org.apache.slide.projector.resource.URIResource;
  import org.xml.sax.InputSource;
  import org.xml.sax.helpers.AttributesImpl;
  
  import java.io.InputStream;
  import java.util.*;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  public class PackageManager implements Subscriber {
      private final static Logger logger = Logger.getLogger(PackageManager.class.getName());
  
      private final static String APPLICATION_CONFIG = "/application.xml";
  
      private static PackageManager packageManager = new PackageManager();
  
      static {
          ConnectorFactory.getConnector().subscribe("Update", Constants.APPLICATIONS_DIR, 1, Constants.SUBSCRIPTION_LIFETIME, Constants.NOTIFICATION_DELAY, packageManager, Constants.CREDENTIALS);
      }
  
      private List applications = new ArrayList();
  
      private PackageManager() {
  		configure();
      }
  
  	private void configure() {
  		final Context context = new SystemContext();
          logger.log(Level.INFO, "Parsing application configurations");
          try {
  	    	ArrayResource installedApplications = ((ArrayResource)ConnectorFactory.getConnector().getChildren(new URIResource(Constants.APPLICATIONS_DIR), context.getCredentials())); 
  			Resource[] applicationDefinitions = installedApplications.getArray();
              SimpleImporter importer = new SimpleImporter();
  			for ( int i = 0; i < applicationDefinitions.length; i++ ) {
  				String applicationUri = applicationDefinitions[i].toString()+"/"; 
  				URI applicationDefinition = new URIResource(applicationUri+APPLICATION_CONFIG);
  	            InputStream configuration = ((StreamableResource)ConnectorFactory.getConnector().getResource(applicationDefinition, context.getCredentials())).getInputStream();
  	            ConfigurationHandler handler = new ConfigurationHandler(applications, applicationUri);
  	            importer.addSimpleImportHandler(handler);
              	importer.parse(new InputSource(configuration));
  			}  
          } catch ( Exception exception ) {
              logger.log(Level.SEVERE, "Error while parsing package manager configuration", exception);
          }
  	}	
  
      public static PackageManager getInstance() {
          return packageManager;
      }
  
      public void notify(Map information) {
          logger.log(Level.INFO, "Package manager received map='"+information+"'");
          configure();
     }
      
      public List getProcessorConfigurations() {
      	List processorConfigurations = new ArrayList();
      	for ( Iterator i = applications.iterator(); i.hasNext(); ) {
      		Application application = (Application)i.next();
          	processorConfigurations.addAll(application.getProcessors());
      	}
      	return processorConfigurations;
      }
      
      static class ConfigurationHandler extends DefaultSimpleImportHandler {
  		private List applications;
  		private Application application;
  		private String applicationUri;
  		
  		public ConfigurationHandler(List applications, String applicationUri) {
  			this.applications = applications;
  			this.applicationUri = applicationUri;
  		}
  
          public void startElement(SimplePath path, String name, AttributesImpl attributes, String leadingCDdata) {
              if (path.matches("application")) {
  				application = new Application();
              } else if ( path.matches("display-name") ) {
  				application.setDisplayName(leadingCDdata);			
              } else if ( path.matches("vendor") ) {
  				application.setVendor(leadingCDdata);			
              } else if ( path.matches("description") ) {
  				application.setDescription(leadingCDdata);			
              } else if ( path.matches("content/processors") ) {
              	String uri = attributes.getValue("uri"); 
              	application.addProcessors(new URIResource(applicationUri+uri));			
  		        ConnectorFactory.getConnector().subscribe("Update", uri, 0, Constants.SUBSCRIPTION_LIFETIME, Constants.NOTIFICATION_DELAY,
  		                new Subscriber() {
  		                    public void notify(Map information) {
  		                        logger.log(Level.INFO, "Reloading processor manager");
  		                        ProcessorManager.getInstance().configure();
  		                    }
  		                }, Constants.CREDENTIALS);
              } else if ( path.matches("content/messages") ) {
  				application.addMessages(new URIResource(applicationUri+attributes.getValue("uri")));			
              } else if ( path.matches("content/jobs") ) {
  				application.addJobs(new URIResource(applicationUri+attributes.getValue("uri")));			
              }
          }
  
          public void endElement(SimplePath path, String name) {
              if (path.matches("application")) {
  				applications.add(application);
              }        	
          }
      }
  
  	static class Application {
  		private String displayName, vendor, description;
  		List processors = new ArrayList();
  		List messages = new ArrayList(); 
  		List jobs = new ArrayList();
  		
  		public String getDescription() {
  			return description;
  		}
  
  		public void setDescription(String description) {
  			this.description = description;
  		}
  
  		public String getDisplayName() {
  			return displayName;
  		}
  
  		public void setDisplayName(String displayName) {
  			this.displayName = displayName;
  		}
  
  		public void addJobs(URI jobsUri) {
  			jobs.add(jobsUri);
  		}
  
  		public List getJobs() {
  			return jobs;
  		}
  
  		public void addMessages(URI messagesUri) {
  			messages.add(messagesUri);
  		}
  
  		public List getMessages() {
  			return messages;
  		}
  
  		public void addProcessors(URI processorsUri) {
  			processors.add(processorsUri);
  		}
  
  		public List getProcessors() {
  			return processors;
  		}
  
   		public String getVendor() {
  			return vendor;
  		}
  
  		public void setVendor(String vendor) {
  			this.vendor = vendor;
  		}
  	}
  }
  
  
  1.5       +2 -0      jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/Constants.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Constants.java	5 May 2004 15:32:44 -0000	1.4
  +++ Constants.java	11 May 2004 15:23:43 -0000	1.5
  @@ -46,6 +46,8 @@
       public final static String DOMAIN = REPOSITORY_DOMAIN+"/files/";
       public final static String SYSTEM_HOME = DOMAIN + "contelligent/";
   
  +    public final static String PROJECTOR_DIR = DOMAIN + "projector/";
  +    public final static String APPLICATIONS_DIR = PROJECTOR_DIR + "applications/";
       public final static String CONFIG_DIR = SYSTEM_HOME + "config/";
       public final static String CONTENT_DIR = SYSTEM_HOME + "content/";
       public final static String TEMPLATES_DIR = SYSTEM_HOME + "templates/";
  
  
  
  1.2       +3 -0      jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/connector/Connector.java
  
  Index: Connector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/connector/Connector.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Connector.java	3 May 2004 14:20:29 -0000	1.1
  +++ Connector.java	11 May 2004 15:23:43 -0000	1.2
  @@ -7,6 +7,7 @@
   import org.apache.slide.projector.resource.StreamableResource;
   
   import java.io.IOException;
  +import java.util.List;
   import java.util.Map;
   
   /**
  @@ -23,6 +24,8 @@
   
       public void removeResource(URI uri, Credentials credentials) throws IOException;
   
  +    public ArrayResource getChildren(URI uri, Credentials credentials) throws IOException;
  +    
       public Resource[] search(String query, Credentials credentials) throws IOException;
   
       public void subscribe(String method, String uri, int depth, int lifetime, int notificationDelay, Subscriber listener, Credentials credentials);
  
  
  
  1.2       +24 -0     jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/connector/webdav/WebdavConnector.java
  
  Index: WebdavConnector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/connector/webdav/WebdavConnector.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WebdavConnector.java	3 May 2004 14:20:27 -0000	1.1
  +++ WebdavConnector.java	11 May 2004 15:23:43 -0000	1.2
  @@ -99,6 +99,30 @@
           deleteMethod.execute(httpState, new HttpConnection(Constants.REPOSITORY_HOST, Constants.REPOSITORY_PORT, Constants.REPOSITORY_PROTOCOL));
       }
   
  +    public ArrayResource getChildren(URI uri, Credentials credentials) throws IOException {
  +        String url = uri.toString();
  +        if ( url.charAt(url.length()-1) == '/') {
  +        	url = url.substring(0, url.length()-1);
  +        }
  +        PropFindMethod propfindMethod = new PropFindMethod(url, 0);
  +        propfindMethod.setDepth(1);
  +        propfindMethod.setDoAuthentication(true);
  +        HttpState httpState = new HttpState();
  +        httpState.setCredentials(null, Constants.REPOSITORY_HOST, credentials);
  +        int state = propfindMethod.execute(httpState, new HttpConnection(Constants.REPOSITORY_HOST, Constants.REPOSITORY_PORT, Constants.REPOSITORY_PROTOCOL));
  +        if ( state != HttpStatus.SC_MULTI_STATUS ) {
  +            throw new IOException("Received status code "+state+" when doing PROPFIND on URI="+url);
  +        }
  +        List children = new ArrayList();
  +        for ( Enumeration propertyEnumeration = propfindMethod.getAllResponseURLs(); propertyEnumeration.hasMoreElements(); ) {
  +        	String childUrl = (String)propertyEnumeration.nextElement();
  +        	if ( !childUrl.equals(url) ) {
  +        		children.add(new URIResource(childUrl));
  +        	}
  +        }
  +        return new ArrayResource((Resource[])children.toArray(new Resource[children.size()]));
  +    }
  +    
       public void subscribe(String method, String uri, int depth, int lifetime, int notificationDelay, Subscriber listener, Credentials credentials) {
           dispatcher.subscribe(method, uri, depth, lifetime, notificationDelay, listener, credentials);
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org