raphael     2002/11/03 06:33:20

  Modified:    src/java/org/apache/jetspeed/services/psmlmanager
                        CastorPsmlManagerService.java
  Log:
  Fix CastorPsmlManager to not use a media-type map keyed on mime-type.
  Add a MediaTypeRegistry interface to provide needed search capability
  
  Revision  Changes    Path
  1.32      +196 -95   
jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java
  
  Index: CastorPsmlManagerService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- CastorPsmlManagerService.java     8 Oct 2002 15:09:02 -0000       1.31
  +++ CastorPsmlManagerService.java     3 Nov 2002 14:33:20 -0000       1.32
  @@ -143,7 +143,7 @@
   
       // default resource
       public final static String DEFAULT_RESOURCE         = "default.psml";
  -    
  +
       // the root psml resource directory
       protected String root;
       // base store directory
  @@ -153,13 +153,13 @@
   
       /** The documents loaded by this manager */
       protected Map documents = new HashMap();
  -    
  +
       /** The watcher for the document locations */
       protected DocumentWatcher watcher = null;
  -    
  +
       /** the output format for pretty printing when saving registries */
       protected OutputFormat format = null;
  -        
  +
       /** the base refresh rate for documents */
       protected long scanRate = 1000 * 60;
   
  @@ -175,7 +175,7 @@
       protected Mapping mapping = null;
   
       /**
  -     * This is the early initialization method called by the 
  +     * This is the early initialization method called by the
        * Turbine <code>Service</code> framework
        */
       public void init( ServletConfig conf ) throws InitializationException
  @@ -187,7 +187,7 @@
   
           //Ensure that the servlet service is initialized
           TurbineServices.getInstance().initService(ServletService.SERVICE_NAME, 
conf);
  -      
  +
           // get configuration parameters from Jetspeed Resources
           ResourceService serviceConf = 
((TurbineServices)TurbineServices.getInstance())
                                                        
.getResources(PsmlManagerService.SERVICE_NAME);
  @@ -220,9 +220,9 @@
           }
   
           // get default extension
  -        this.ext = serviceConf.getString( CONFIG_EXT, DEFAULT_EXT );        
  +        this.ext = serviceConf.getString( CONFIG_EXT, DEFAULT_EXT );
   
  -        // create the serializer output format        
  +        // create the serializer output format
           this.format = new OutputFormat();
           format.setIndenting(true);
           format.setIndent(4);
  @@ -261,9 +261,9 @@
           }
       }
   
  -    
  +
       /**
  -     * This is the shutdown method called by the 
  +     * This is the shutdown method called by the
        * Turbine <code>Service</code> framework
        */
       public void shutdown()
  @@ -288,7 +288,10 @@
               throw new IllegalArgumentException( message );
           }
   
  -        Log.debug( "PSMLManager: asked for " + name );
  +             if (Log.getLogger().isDebugEnabled())
  +             {
  +             Log.debug( "PSMLManager: asked for " + name );
  +             }
   
           PSMLDocument doc = null;
           WeakReference ref = null;
  @@ -297,12 +300,12 @@
           {
               ref = (WeakReference)documents.get(name);
           }
  -        
  +
           if (ref != null)
           {
               doc = (PSMLDocument)ref.get();
           }
  -        
  +
           if (doc == null)
           {
               doc = loadDocument(name);
  @@ -332,9 +335,22 @@
           }
           File base = this.rootDir;
           String path = mapLocatorToFile(locator);
  -        Log.info("PSML-Man: calculated resource:" + path + ". Base: " + base);
           File file = new File(base, path);
  -        String name = file.getAbsolutePath();
  +        String name = null;
  +
  +        try
  +        {
  +                     name = file.getCanonicalPath();
  +             }
  +             catch (IOException e)
  +             {
  +                     Log.error("PSMLManager: unable to resolve file path for "+ 
file);
  +             }
  +
  +             if (Log.getLogger().isDebugEnabled())
  +             {
  +             Log.debug("PSMLManager: calculated resource:" + path + ". Base: " + 
base + " File: " + name);
  +             }
   
           PSMLDocument doc = null;
           WeakReference ref = null;
  @@ -344,7 +360,7 @@
           {
               ref = (WeakReference)documents.get(name);
           }
  -        
  +
           if (ref != null)
           {
               /**
  @@ -362,20 +378,23 @@
                   Log.error( e );
               }
           }
  -        
  +
           if (profile == null)
           {
               doc = loadDocument(name);
               if (null == doc)
               {
  -                Log.info( "CastorPsmlManager: about to return null doc: "  );
  +                if (Log.getLogger().isWarnEnabled())
  +                {
  +                     Log.warn( "PSMLManager: " + name + " not found, returning null 
document" );
  +                             }
                   return null;
               }
   
               synchronized (documents)
               {
                   // store the document in the hash and reference it to the watcher
  -                Profile newProfile = createProfile(locator); 
  +                Profile newProfile = createProfile(locator);
                   newProfile.setDocument(doc);
                   documents.put(name, new WeakReference(newProfile));
               }
  @@ -386,7 +405,7 @@
           return doc;
       }
   
  -    /** 
  +    /**
        * Load a PSMLDOcument from disk
        *
        * @param fileOrUrl a String representing either an absolute URL or an
  @@ -402,10 +421,10 @@
               {
                   fileOrUrl = fileOrUrl.concat(DEFAULT_EXT);
               }
  -            
  +
               // load the document and add it to the watcher
               // we'll assume the name is the the location of the file
  -            
  +
               File f = getFile(fileOrUrl);
               if (null == f)
                   return null;
  @@ -419,15 +438,15 @@
               try
               {
                   reader = new FileReader(f);
  -                
  +
                   portlets = load(reader);
  -                
  +
                   doc.setPortlets(portlets);
   
                   if (this.watcher != null)
                   {
                       this.watcher.addFile(fileOrUrl,f);
  -                }                
  +                }
               }
               catch (IOException e)
               {
  @@ -450,12 +469,12 @@
                   try { reader.close(); } catch (IOException e) {}
               }
           }
  -        
  +
           return doc;
       }
  -    
  +
       /** Refresh a named document
  -     * 
  +     *
        * @param name the name of the document to refresh
        */
       public void refresh(String name) throws IOException
  @@ -467,7 +486,7 @@
           {
               ref = (WeakReference)documents.get(name);
           }
  -        
  +
           if (ref != null)
           {
               doc = (PSMLDocument)ref.get();
  @@ -483,7 +502,7 @@
                   }
                   catch (Exception e)
                   {
  -                    Log.error("Error refrshing "+f.getAbsolutePath(),e);
  +                    Log.error("PSMLManager: Error refrshing 
"+f.getAbsolutePath(),e);
                   }
                   finally
                   {
  @@ -500,13 +519,13 @@
                   }
               }
           }
  -        
  +
           // we don't know anything about this document, load it normally
           getDocument(name);
       }
  -    
  +
       /** Store the PSML document on disk, using its locator
  -     * 
  +     *
        * @param profile the profile locator description.
        * @return true if the operation succeeded
        */
  @@ -516,18 +535,27 @@
   
           File base = this.rootDir;
           String path = mapLocatorToFile(profile);
  -        
  +
           File file = new File(base, path);
  -        String fullpath = file.getAbsolutePath();
  +        String fullpath = null;
  +
  +        try
  +        {
  +                     fullpath = file.getCanonicalPath();
  +             }
  +             catch (IOException e)
  +             {
  +                     Log.error("PSMLManager: unable to resolve file path for "+ 
file);
  +             }
   
           boolean ok = saveDocument(fullpath, doc);
  -        
  +
           // update it in cache
           synchronized (documents)
           {
               documents.put(fullpath, new WeakReference(profile));
           }
  -        
  +
           return ok;
       }
   
  @@ -539,9 +567,9 @@
       {
           return saveDocument(doc.getName(), doc);
       }
  -    
  +
       /** Save the PSML document on disk to the specififed fileOrUrl
  -     * 
  +     *
        * @param fileOrUrl a String representing either an absolute URL
        * or an absolute filepath
        * @param doc the document to save
  @@ -549,7 +577,7 @@
       public boolean saveDocument(String fileOrUrl, PSMLDocument doc)
       {
           boolean success = false;
  -        
  +
           if (doc == null) return false;
           File f = getFile(fileOrUrl);
           if (f == null)
  @@ -565,7 +593,7 @@
               writer = new FileWriter(f);
               save(writer, doc.getPortlets());
               success = true;
  -        } 
  +        }
           catch (MarshalException e)
           {
               Log.error("PSMLManager: Could not marshal the file 
"+f.getAbsolutePath(), e);
  @@ -589,11 +617,11 @@
           finally
           {
               try { writer.close(); } catch (IOException e) {}
  -        }   
  -        
  +        }
  +
           return success;
       }
  -    
  +
       /** Deserializes a PSML structure read from the reader using Castor
        *  XML unmarshaller
        *
  @@ -607,16 +635,19 @@
           Portlets portlets = (Portlets)unmarshaller.unmarshal(reader);
           return portlets;
       }
  -    
  +
       protected void loadMapping()
           throws InitializationException
       {
           // test the mapping file and create the mapping object
  -        
  +
           if (mapFile != null)
           {
               File map = new File(mapFile);
  -            Log.debug("Loading psml mapping file "+mapFile);
  +            if (Log.getLogger().isDebugEnabled())
  +            {
  +             Log.debug("PSMLManager: Loading psml mapping file "+mapFile);
  +                     }
               if (map.exists() && map.isFile() && map.canRead())
               {
                   try
  @@ -628,7 +659,7 @@
                   }
                   catch (Exception e)
                   {
  -                    Log.error("Error in psml mapping creation",e);
  +                    Log.error("PSMLManager: Error in psml mapping creation",e);
                       throw new InitializationException("Error in mapping",e);
                   }
               }
  @@ -650,12 +681,12 @@
       {
           if (portlets != null)
           {
  -            Serializer serializer = new XMLSerializer(writer, format); 
  +            Serializer serializer = new XMLSerializer(writer, format);
   //            portlets.marshal(serializer.asDocumentHandler());
               Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());
               marshaller.setMapping(this.mapping);
               marshaller.marshal(portlets);
  -        }        
  +        }
       }
   
       /** Tests wether the passed argument is an URL string or a file name
  @@ -670,13 +701,13 @@
           File f = null;
   
           f = new File(fileOrUrl);
  -            
  +
           if (f.exists())
           {
               return f;
  -        }          
  +        }
   /*
  -        else        
  +        else
           {
               // try as a relative path
               String path = TurbineServlet.getRealPath(fileOrUrl);
  @@ -700,25 +731,25 @@
               {
                   Log.error("PSMLManager: unabel to retrieve file from diskcache for 
"+fileOrUrl,e);
               }
  -            
  -        }           
  +
  +        }
           return f;
   */
           return null;
  -    }    
  -    
  +    }
  +
       protected class DocumentWatcher extends Thread
       {
           protected Map fileToName = new HashMap();
           protected Map fileToDate = new HashMap();
           protected boolean done = false;
  -        
  +
           protected DocumentWatcher()
           {
               setDaemon(true);
               setPriority(Thread.MIN_PRIORITY+1);
           }
  -        
  +
           protected void addFile(String name, File f)
           {
               synchronized (this)
  @@ -727,7 +758,7 @@
                   fileToDate.put(f, new Date());
               }
           }
  -        
  +
           protected void removeFile(File f)
           {
               synchronized (this)
  @@ -736,12 +767,12 @@
                   fileToDate.remove(f);
               }
           }
  -        
  +
           public void setDone(boolean done)
           {
               this.done = done;
           }
  -        
  +
           public void run()
           {
               try
  @@ -751,7 +782,7 @@
                       try
                       {
                           Iterator i = fileToDate.keySet().iterator();
  -                    
  +
                           while(i.hasNext())
                           {
                               File f = (File)i.next();
  @@ -772,7 +803,7 @@
                       {
                           Log.error("DocumentWatcher: Error in iteration...", e);
                       }
  -                    
  +
                       sleep(CastorPsmlManagerService.this.scanRate);
                   }
               }
  @@ -781,7 +812,7 @@
                   Log.info("DocumentWatcher: recieved interruption, aborting.");
               }
           }
  -        
  +
       }
   
       /** Create a new document.
  @@ -793,11 +824,24 @@
       {
           File base = this.rootDir;
           String path = mapLocatorToFile((ProfileLocator)profile);
  -        Log.debug("PSML-Man: calculated resource:" + path);
  +
  +        if (Log.getLogger().isDebugEnabled())
  +        {
  +             Log.debug("PSMLManager: Create document for profile " + profile +", 
calculated path: " + path);
  +             }
   
           File file = new File(base, path);
  -        String name = file.getAbsolutePath();
  -        
  +        String name = null;
  +
  +        try
  +        {
  +                     name = file.getCanonicalPath();
  +             }
  +             catch (IOException e)
  +             {
  +                     Log.error("PSMLManager: unable to resolve file path for "+ 
file);
  +             }
  +
           PSMLDocument template = profile.getDocument();
           PSMLDocument doc = new BasePSMLDocument( name, template.getPortlets() );
           try
  @@ -806,7 +850,7 @@
               File filePath = new File(parent);
               filePath.mkdirs();
               if (template.getName() != null)
  -            {           
  +            {
                   try
                   {
                       File source = new File(template.getName());
  @@ -826,7 +870,7 @@
           }
           catch (Exception e)
           {
  -            Log.error("Failed to save document: " , e);
  +            Log.error("PSMLManager: Failed to save document: " , e);
               e.printStackTrace();
           }
           return doc;
  @@ -841,16 +885,16 @@
       public PSMLDocument getDocument( List locators )
       {
           PSMLDocument doc=null;
  -        
  +
           Iterator i = locators.iterator();
           while ((doc==null)&&(i.hasNext()))
           {
               doc=getDocument((ProfileLocator)i.next());
           }
  -        
  +
           return doc;
       }
  -    
  +
       /** Removes a document.
        *
        * @param locator The description of the profile resource to be removed.
  @@ -862,7 +906,17 @@
   
           File base = this.rootDir;
           File file = new File(base, fileName);
  -        String name = file.getAbsolutePath();
  +        String name = null;
  +
  +        try
  +        {
  +                     name = file.getCanonicalPath();
  +             }
  +             catch (IOException e)
  +             {
  +                     Log.error("PSMLManager: unable to resolve file path for "+ 
file);
  +             }
  +
   
           synchronized (documents)
           {
  @@ -896,7 +950,16 @@
           String path = buffer.toString();
           File base = this.rootDir;
           File file = new File(base, path);
  -        name = file.getAbsolutePath();
  +
  +        try
  +        {
  +                     name = file.getCanonicalPath();
  +             }
  +             catch (IOException e)
  +             {
  +                     Log.error("PSMLManager: unable to resolve file path for "+ 
file);
  +             }
  +
   
           synchronized (documents)
           {
  @@ -943,7 +1006,16 @@
           String path = buffer.toString();
           File base = this.rootDir;
           File file = new File(base, path);
  -        name = file.getAbsolutePath();
  +
  +        try
  +        {
  +                     name = file.getCanonicalPath();
  +             }
  +             catch (IOException e)
  +             {
  +                     Log.error("PSMLManager: unable to resolve file path for "+ 
file);
  +             }
  +
   
           synchronized (documents)
           {
  @@ -989,7 +1061,16 @@
           String path = buffer.toString();
           File base = this.rootDir;
           File file = new File(base, path);
  -        name = file.getAbsolutePath();
  +
  +        try
  +        {
  +                     name = file.getCanonicalPath();
  +             }
  +             catch (IOException e)
  +             {
  +                     Log.error("PSMLManager: unable to resolve file path for "+ 
file);
  +             }
  +
   
           synchronized (documents)
           {
  @@ -1017,7 +1098,7 @@
   
       /**
        * Maps a ProfileLocator to a file.
  -     * 
  +     *
        * @param locator The profile locator describing the PSML resource to be found.
        * @return the String path of the file.
        */
  @@ -1120,7 +1201,7 @@
           Role role = locator.getRole();
           Group group = locator.getGroup();
           JetspeedUser user = locator.getUser();
  -    
  +
           // search thru anonymous directories?
           int qm = locator.getQueryMode();
           if ((qm & QueryLocator.QUERY_USER) == QueryLocator.QUERY_USER)
  @@ -1170,7 +1251,17 @@
               }
               File base = this.rootDir;
               File file = new File(base, path.toString());
  -            String absPath = file.getAbsolutePath();
  +             String absPath = null;
  +
  +             try
  +             {
  +                             absPath = file.getCanonicalPath();
  +                     }
  +                     catch (IOException e)
  +                     {
  +                             Log.error("PSMLManager: unable to resolve file path 
for "+ file);
  +                     }
  +
               QueryState qs = new QueryState( QUERY_BY_ROLE,
                                                profile,
                                                locator,
  @@ -1198,7 +1289,17 @@
               }
               File base = this.rootDir;
               File file = new File(base, path.toString());
  -            String absPath = file.getAbsolutePath();
  +             String absPath = null;
  +
  +             try
  +             {
  +                             absPath = file.getCanonicalPath();
  +                     }
  +                     catch (IOException e)
  +                     {
  +                             Log.error("PSMLManager: unable to resolve file path 
for "+ file);
  +                     }
  +
               QueryState qs = new QueryState( QUERY_BY_GROUP,
                                                profile,
                                                locator,
  @@ -1245,14 +1346,14 @@
           {
               this.consumer = consumer;
               profiles = query(locator);
  -        
  +
               while (profiles.hasNext() )
               {
                   Profile profile = (Profile)profiles.next();
                   //dumpProfile(profile);
                   try
                   {
  -                    consumer.createDocument(profile);  
  +                    consumer.createDocument(profile);
                       count++;
                   }
                   catch (Exception ex)
  @@ -1264,7 +1365,7 @@
                       }
                       catch (Exception e)
                       {
  -                        Log.error("Failed to export profiles to DB: " + profile, ex 
);
  +                        Log.error("PSMLManager: Failed to export profiles to DB: " 
+ profile, ex );
                       }
                   }
               }
  @@ -1272,7 +1373,7 @@
           catch(Exception e)
           {
               e.printStackTrace();
  -            Log.error("Failed to export profiles to DB: " , e );
  +            Log.error("PSMLManager: Failed to export profiles to DB: " , e );
   
           }
           finally
  @@ -1291,9 +1392,9 @@
       protected void subQuery(QueryState qs, String path)
       {
           File file = new File(path);
  -        if (file.isFile()) 
  +        if (file.isFile())
           {
  -            try 
  +            try
               {
                   String filename = file.getName();
                   if (!filename.endsWith(this.ext))
  @@ -1305,10 +1406,10 @@
               }
               catch (Exception e)
               {
  -                Log.error("Failed to clone profile: " + path + " : " + e, e);
  +                Log.error("PSMLManager: Failed to clone profile: " + path + " : " + 
e, e);
               }
  -        } 
  -        else if (file.isDirectory()) 
  +        }
  +        else if (file.isDirectory())
           {
               String dirName = file.getName();
               qs.state++;
  @@ -1493,13 +1594,13 @@
               QueryLocator locator = new QueryLocator( QueryLocator.QUERY_USER );
               Iterator x1 = query( locator );
               dump( x1 );
  -    
  +
               QueryLocator locator2 = new QueryLocator( QueryLocator.QUERY_USER );
               locator2.setUser( JetspeedSecurity.getUser("turbine") );
               Iterator x2 = query( locator2 );
               dump( x2 );
  -    
  -    
  +
  +
               QueryLocator locator4 = new QueryLocator( QueryLocator.QUERY_GROUP );
   //            locator4.setGroup( JetspeedSecurity.getGroup("apache") );
               Iterator x4 = query( locator4 );
  @@ -1548,7 +1649,7 @@
                   System.out.println("profile name is null");
               else
                   System.out.println("Doc.name=" + profile.getName());
  -        }    
  +        }
   
           System.out.println("----------------------");
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@;jakarta.apache.org>

Reply via email to