weaver      2004/08/24 07:14:29

  Modified:    components/page-manager/src/java/org/apache/jetspeed/page/impl
                        CastorXmlPageManager.java
  Log:
  Added the begins of folder meta data support.  I used Dublin Core schema for basic 
metadata like.  Metadata is marshaled/unmarshalled
  using JDom and metadata is accessed via XPath queries.  We may want to look into 
switching over to castor given that castor has the
  namespace support we require.
  
  Revision  Changes    Path
  1.8       +85 -81    
jakarta-jetspeed-2/components/page-manager/src/java/org/apache/jetspeed/page/impl/CastorXmlPageManager.java
  
  Index: CastorXmlPageManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/page-manager/src/java/org/apache/jetspeed/page/impl/CastorXmlPageManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CastorXmlPageManager.java 18 Aug 2004 13:54:15 -0000      1.7
  +++ CastorXmlPageManager.java 24 Aug 2004 14:14:29 -0000      1.8
  @@ -53,16 +53,17 @@
   import org.xml.sax.InputSource;
   
   /**
  - * This service is responsible for loading and saving PSML pages
  - * serialized to disk
  - *
  - * @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta</a>
  + * This service is responsible for loading and saving PSML pages serialized to
  + * disk
  + * 
  + * @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta </a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott T Weaver</a>
    * @version $Id$
    */
   public class CastorXmlPageManager extends AbstractPageManager implements 
FileCacheEventListener, PageManager, Startable
   {
       private final static Log log = LogFactory.getLog(CastorXmlPageManager.class);
  -    
  +
       // configuration keys
       protected final static String CONFIG_ROOT = "root";
       protected final static String CONFIG_EXT = "ext";
  @@ -71,7 +72,6 @@
   
       // default configuration values
   
  -
       // the root psml resource directory
       protected String root;
       // base store directory
  @@ -91,20 +91,21 @@
       /** the Castor mapping file name */
       protected Mapping mapping = null;
   
  -    public CastorXmlPageManager(IdGenerator generator, FileCache fileCache, String 
root) throws FileNotFoundException
  -    {    
  +    public CastorXmlPageManager( IdGenerator generator, FileCache fileCache, String 
root ) throws FileNotFoundException
  +    {
           super(generator);
           this.rootDir = new File(root);
           verifyPath(rootDir);
  -        this.pages = fileCache;        
  +        this.pages = fileCache;
       }
  -    
  -    public CastorXmlPageManager(IdGenerator generator, FileCache fileCache, String 
root, List modelClasses) throws FileNotFoundException
  +
  +    public CastorXmlPageManager( IdGenerator generator, FileCache fileCache, String 
root, List modelClasses )
  +            throws FileNotFoundException
       {
           super(generator, modelClasses);
           this.rootDir = new File(root);
           verifyPath(rootDir);
  -        this.pages = fileCache;        
  +        this.pages = fileCache;
       }
   
       public CastorXmlPageManager(IdGenerator generator,
  @@ -118,11 +119,9 @@
           this.ext = extension;
       }
   
  -
  -
       public void start()
       {
  -        
  +
           //If it is still missing, try to create it
           if (!rootDir.exists())
           {
  @@ -158,30 +157,31 @@
        * <p>
        * getPage
        * </p>
  -     *
  +     * 
        * @see 
org.apache.jetspeed.page.PageManager#getPage(org.apache.jetspeed.profiler.ProfileLocator)
        * @param locator
  -     * @return
  -     * @throws PageNotFoundException
  +     * @return @throws
  +     *         PageNotFoundException
        */
  -    public Page getPage(ProfileLocator locator) throws PageNotFoundException
  +    public Page getPage( ProfileLocator locator ) throws PageNotFoundException
       {
           return getPage(locator.getValue("page"));
       }
  -    
  +
       /**
        * 
        * <p>
        * getPage
        * </p>
  -     *
  +     * 
        * @see org.apache.jetspeed.page.PageManager#getPage(java.lang.String)
        * @param id
  -     * @return
  -     * @throws PageNotFoundException
  -     * @throws IllegalStateException if the page could be inserted into the 
FileCache.
  +     * @return @throws
  +     *         PageNotFoundException
  +     * @throws IllegalStateException
  +     *             if the page could be inserted into the FileCache.
        */
  -    public Page getPage(String id) throws PageNotFoundException
  +    public Page getPage( String id ) throws PageNotFoundException
       {
           if (id == null)
           {
  @@ -202,37 +202,37 @@
           if (page == null)
           {
               File f = null;
  -            if(id.endsWith(this.ext))
  +            if (id.endsWith(this.ext))
               {
  -                f = new File(this.rootDir, id );
  +                f = new File(this.rootDir, id);
               }
               else
               {
                   f = new File(this.rootDir, id + this.ext);
               }
  -            
  +
               if (!f.exists())
               {
  -                throw new PageNotFoundException("Jetspeed PSML page not found: 
"+id);
  +                throw new PageNotFoundException("Jetspeed PSML page not found: " + 
id);
               }
   
               FileReader reader = null;
  -        
  +
               try
               {
                   reader = new FileReader(f);
                   Unmarshaller unmarshaller = new Unmarshaller(this.mapping);
  -                page = (Page) unmarshaller.unmarshal(reader);    
  +                page = (Page) unmarshaller.unmarshal(reader);
                   page.setId(id);
  -                
  +
               }
               catch (IOException e)
               {
  -                throw new PageNotFoundException("Could not load the file " + 
f.getAbsolutePath(), e);                
  +                throw new PageNotFoundException("Could not load the file " + 
f.getAbsolutePath(), e);
               }
               catch (MarshalException e)
               {
  -                throw new PageNotFoundException("Could not unmarshal the file " + 
f.getAbsolutePath(), e);               
  +                throw new PageNotFoundException("Could not unmarshal the file " + 
f.getAbsolutePath(), e);
               }
               catch (MappingException e)
               {
  @@ -240,7 +240,7 @@
               }
               catch (ValidationException e)
               {
  -                throw new PageNotFoundException("Document " + f.getAbsolutePath() + 
" is not valid", e);                
  +                throw new PageNotFoundException("Document " + f.getAbsolutePath() + 
" is not valid", e);
               }
               finally
               {
  @@ -252,20 +252,21 @@
                   {
                   }
               }
  -            
  -            if(page == null)
  +
  +            if (page == null)
               {
  -                throw new PageNotFoundException("Page not found: "+id);
  +                throw new PageNotFoundException("Page not found: " + id);
               }
   
               synchronized (pages)
               {
  -                // store the document in the hash and reference it to the watcher
  +                // store the document in the hash and reference it to the
  +                // watcher
                   try
                   {
                       pages.put(id, page);
                       int lastSlash = id.indexOf("/");
  -                    if(lastSlash > -1)
  +                    if (lastSlash > -1)
                       {
                           page.setParent(getFolder(id.substring(0, lastSlash)));
                       }
  @@ -277,7 +278,8 @@
                   catch (java.io.IOException e)
                   {
                       log.error("Error putting document: " + e);
  -                    IllegalStateException ise = new IllegalStateException("Error 
storing Page in the FileCache: "+e.toString());
  +                    IllegalStateException ise = new IllegalStateException("Error 
storing Page in the FileCache: "
  +                            + e.toString());
                       ise.initCause(e);
                   }
               }
  @@ -285,24 +287,25 @@
   
           return page;
       }
  -    
  -    public Folder getFolder(String folderPath)
  +
  +    public Folder getFolder( String folderPath ) throws IOException
       {
  -        File f = new File(this.rootDir, folderPath);
  -        if (!f.exists())
  -        {
  -            return null;
  -        }
  -        else
  +        Folder folder = (Folder) pages.getDocument(folderPath);
  +
  +        if (folder == null)
           {
  -            FolderImpl folder = new FolderImpl(f, folderPath, this);                
   
  -            return folder;
  +            File f = new File(this.rootDir, folderPath);
  +
  +            if (f.exists())
  +            {
  +                folder = new FolderImpl(f, folderPath, this );
  +                pages.put(folderPath, folder);
  +
  +            }
           }
  +        return folder;
       }
  -    
  -
   
  -    
       /**
        * @see org.apache.jetspeed.services.page.PageManagerService#listPages()
        */
  @@ -311,7 +314,7 @@
           ArrayList results = new ArrayList();
           File[] files = this.rootDir.listFiles(new FilenameFilter()
           {
  -            public boolean accept(File dir, String file)
  +            public boolean accept( File dir, String file )
               {
                   return file.endsWith(CastorXmlPageManager.this.ext);
               }
  @@ -329,7 +332,7 @@
       /**
        * @see 
org.apache.jetspeed.services.page.PageManagerService#registerPage(org.apache.jetspeed.om.page.Page)
        */
  -    public void registerPage(Page page) throws JetspeedException
  +    public void registerPage( Page page ) throws JetspeedException
       {
           // sanity checks
           if (page == null)
  @@ -412,7 +415,7 @@
       /**
        * @see 
org.apache.jetspeed.services.page.PageManagerService#updatePage(org.apache.jetspeed.om.page.Page)
        */
  -    public void updatePage(Page page) throws JetspeedException
  +    public void updatePage( Page page ) throws JetspeedException
       {
           registerPage(page);
       }
  @@ -420,7 +423,7 @@
       /**
        * @see 
org.apache.jetspeed.services.page.PageManagerService#removePage(org.apache.jetspeed.om.page.Page)
        */
  -    public void removePage(Page page)
  +    public void removePage( Page page )
       {
           String id = page.getId();
   
  @@ -441,62 +444,63 @@
   
       }
   
  -    protected void loadMapping() 
  +    protected void loadMapping()
       {
           try
  -        {            
  +        {
               InputStream stream = 
Thread.currentThread().getContextClassLoader().getResourceAsStream(mapFileResource);
  -                        
  +
               if (log.isDebugEnabled())
               {
                   log.debug("Loading psml mapping file " + mapFileResource);
               }
  -            
  +
               mapping = new Mapping();
  -                    
  -                    
  +
               InputSource is = new InputSource(stream);
               is.setSystemId(mapFileResource);
  -                   
  +
               mapping.loadMapping(is);
           }
           catch (Exception e)
           {
  -            log.error("Error in psml mapping creation", e);            
  +            log.error("Error in psml mapping creation", e);
           }
  -        
  +
       }
   
       /**
        * Refresh event, called when the entry is being refreshed from file system.
  -     *
  -     * @param entry the entry being refreshed.
  +     * 
  +     * @param entry
  +     *            the entry being refreshed.
        */
  -    public void refresh(FileCacheEntry entry)
  +    public void refresh( FileCacheEntry entry )
       {
           log.debug("Entry is refreshing: " + entry.getFile().getName());
       }
   
       /**
        * Evict event, called when the entry is being evicted out of the cache
  -     *
  -     * @param entry the entry being refreshed.
  +     * 
  +     * @param entry
  +     *            the entry being refreshed.
        */
  -    public void evict(FileCacheEntry entry)
  +    public void evict( FileCacheEntry entry )
       {
           log.debug("Entry is evicting: " + entry.getFile().getName());
       }
  -    
  -    protected void verifyPath(File path) throws FileNotFoundException
  +
  +    protected void verifyPath( File path ) throws FileNotFoundException
       {
  -        if(path == null)
  +        if (path == null)
           {
  -              throw new IllegalArgumentException("Page root cannot be null");    
  +            throw new IllegalArgumentException("Page root cannot be null");
           }
  -        
  -        if(!path.exists())
  +
  +        if (!path.exists())
           {
  -            throw new FileNotFoundException("Could not locate root pages path 
"+path.getAbsolutePath());
  +            throw new FileNotFoundException("Could not locate root pages path " + 
path.getAbsolutePath());
           }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to