OriginalWithDerivativesBitstreamFilter.java :  » Search » dspace-semantic-search » org » dspace » app » itemupdate » Java Open Source

Java Open Source » Search » dspace semantic search 
dspace semantic search » org » dspace » app » itemupdate » OriginalWithDerivativesBitstreamFilter.java
/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */
package org.dspace.app.itemupdate;

import java.sql.SQLException;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;

/** 
 *     Filter all bitstreams in the ORIGINAL bundle
 *      Also delete all derivative bitstreams, i.e.
 *      all bitstreams in the TEXT and THUMBNAIL bundles
 */
public class OriginalWithDerivativesBitstreamFilter extends BitstreamFilter 
{
  private String[] bundlesToEmpty = { "ORIGINAL", "TEXT", "THUMBNAIL" };  
  
  public OriginalWithDerivativesBitstreamFilter()
  {
    //empty
  }
  
  /**
   *   Tests bitstream for membership in specified bundles (ORIGINAL, TEXT, THUMBNAIL)
   * 
   * @param bitstream
   * @throws BitstreamFilterException
   * @return true if bitstream is in specified bundles
   */
  public boolean accept(Bitstream bitstream) 
  throws BitstreamFilterException
  {    
    try
    {
      Bundle[] bundles = bitstream.getBundles();
      for (Bundle b : bundles)
      {
        for (String bn : bundlesToEmpty)
        {
          if (b.getName().equals(bn))
          {
            return true;
          }
        }
      }    
    }
    catch(SQLException e)
    {
      throw new BitstreamFilterException(e);
    }
    return false;
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.