javauis/mmapi_qt/baseline/javasrc/com/nokia/microedition/media/animation/AnimationPlayerFactory.java
changeset 49 35baca0e7a2e
parent 35 85266cc22c7f
child 56 abc41079b313
equal deleted inserted replaced
35:85266cc22c7f 49:35baca0e7a2e
    25 import javax.microedition.media.protocol.DataSource;
    25 import javax.microedition.media.protocol.DataSource;
    26 
    26 
    27 import org.eclipse.swt.SWTException;
    27 import org.eclipse.swt.SWTException;
    28 
    28 
    29 import com.nokia.microedition.media.InternalPlayer;
    29 import com.nokia.microedition.media.InternalPlayer;
    30 import com.nokia.microedition.media.Locator;
       
    31 import com.nokia.microedition.media.PlugIn;
    30 import com.nokia.microedition.media.PlugIn;
    32 import com.nokia.mj.impl.utils.Logger;
    31 import com.nokia.mj.impl.utils.Logger;
    33 
    32 
    34 /**
    33 /**
    35  * This class is used for playing GIF image animation. This class also
    34  * This class is used for playing GIF image animation. This class also
    36  * implements PlugIn interface which is used from ManagerImpl.
    35  * implements PlugIn interface which is used from ManagerImpl.
    37  * Entire Animation playing is written using eSWT API.
    36  * Entire Animation playing is written using eSWT API.
    38  * There is no call to native.
    37  * There is no call to native.
    39  *
       
    40  */
    38  */
    41 public class AnimationPlayerFactory implements PlugIn
    39 public class AnimationPlayerFactory implements PlugIn
    42 {
    40 {
    43 
    41 
    44     // Used to recognize supported locators.
    42     // Used to recognize supported locators.
    45     // private static final String ANIMATION_FILE_EXTENSION = ".gif";
    43     // private static final String ANIMATION_FILE_EXTENSION = ".gif";
    46 
       
    47     // Used to get supported protocols and content type.
    44     // Used to get supported protocols and content type.
    48     private static final String ANIMATION_CONTENT_TYPE = "image/gif";
    45     private static final String ANIMATION_CONTENT_TYPE = "image/gif";
    49     private static final String ANIMATION_HTTP_PROTOCOL = "http";
    46     private static final String ANIMATION_HTTP_PROTOCOL = "http";
    50     private static final String ANIMATION_HTTPS_PROTOCOL = "https";
    47     private static final String ANIMATION_HTTPS_PROTOCOL = "https";
    51     private static final String ANIMATION_FILE_PROTOCOL = "file";
    48     private static final String ANIMATION_FILE_PROTOCOL = "file";
    52     // There is no need to read the first 6 byte and compare it with following string
       
    53 //  private static final String ANIMATION_GIF_HEADER="GIF89a";
       
    54 
    49 
    55     /**
    50     /**
    56      * From PlugIn
    51      * From PlugIn
    57      */
    52      */
    58     public InternalPlayer createPlayer(DataSource aDataSource)
    53     public InternalPlayer createPlayer(DataSource aDataSource)
    71         {
    66         {
    72             if (contentType.equals(ANIMATION_CONTENT_TYPE))
    67             if (contentType.equals(ANIMATION_CONTENT_TYPE))
    73             {
    68             {
    74                 player = new AnimationPlayer(aDataSource);
    69                 player = new AnimationPlayer(aDataSource);
    75             }
    70             }
    76 //          else{
       
    77 //              throw new MediaException("Content type not supported: " + contentType);
       
    78 //          }
       
    79         } //Since it was not possible to identify the player from content type, identify it from it's header
    71         } //Since it was not possible to identify the player from content type, identify it from it's header
    80         // Is there any need to create player through Locator?
       
    81 
       
    82         else
    72         else
    83         {
    73         {
    84             // We need only 6 bytes to identify whether it's GIF image data or not.
    74             // We need only 6 bytes to identify whether it's GIF image data or not.
    85             // But the problem here is that if we will read even a single byte from stream
    75             // But the problem here is that if we will read even a single byte from stream
    86             // that stream won't be useful for loading the image data through ImageLoader class
    76             // that stream won't be useful for loading the image data through ImageLoader class
    92                 player = new AnimationPlayer(aDataSource);
    82                 player = new AnimationPlayer(aDataSource);
    93             }
    83             }
    94             catch (SWTException e)
    84             catch (SWTException e)
    95             {
    85             {
    96                 // Simply ignore the exception
    86                 // Simply ignore the exception
    97                 e.printStackTrace();
    87                 //e.printStackTrace();
    98             }
    88             }
    99         }
    89         }
   100         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-");
    90         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-");
   101         return player;
    91         return player;
   102     }
    92     }
   103 
    93 
   104     /**
    94     /**
   105      * @param locator
    95      * @param locator, path of the GIF file.
   106      * @return Interplayer object
    96      * @return InternalPlayer object
   107      * @throws IOException
    97      * @throws IOException if it is not possible to read the file from location specified
   108      */
    98      */
   109     public InternalPlayer createPlayer(String locator) throws IOException
    99     public InternalPlayer createPlayer(String locator) throws IOException
   110     {
   100     {
   111         final String DEBUG_STR="AnimationPlayerFactory::createPlayer(String locator )";
   101         final String DEBUG_STR="AnimationPlayerFactory::createPlayer(String locator )";
   112         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"+");
   102         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"+");
   115         {
   105         {
   116             player = new AnimationPlayer(locator);
   106             player = new AnimationPlayer(locator);
   117         }
   107         }
   118         catch (SWTException e)
   108         catch (SWTException e)
   119         {
   109         {
   120             // For all cases ImageLoader.load throws only SWTException
   110             Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+" SWTException thrown "+e);
   121             // here we are finding why it has throws this Exception
   111             e.printStackTrace();
   122             // if it is IOException we need to pass it to caller
   112             if (e.throwable instanceof java.io.IOException)
   123             if (e.getCause().toString().indexOf((IOException.class.getName()))!=-1)
   113             {
   124                 throw new IOException();
   114                 // TODO remove hardcoding for checking whether it is permission
       
   115                 // related exceptioon
       
   116                 if (e.getCause().toString().indexOf("Permission") != -1)
       
   117                     // TODO Copied the exception message from
       
   118                     throw new SecurityException(
       
   119                         "Application not authorized to access the restricted API");
       
   120                 // For all other remaining IOException throw it as it is
       
   121                 else
       
   122                     // if
       
   123                     // (e.getCause().toString().indexOf((IOException.class.getName()))!=-1)
       
   124                     throw new IOException();
       
   125             }
   125             // if exception is due to any other reason, just ignore it
   126             // if exception is due to any other reason, just ignore it
   126             e.printStackTrace();
       
   127         }
   127         }
   128         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-");
   128         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-");
   129         return player;
   129         return player;
   130     }
   130     }
   131 
   131 
   133     /**
   133     /**
   134      * From PlugIn
   134      * From PlugIn
   135      */
   135      */
   136     public String[] getSupportedContentTypes(String aProtocol)
   136     public String[] getSupportedContentTypes(String aProtocol)
   137     {
   137     {
       
   138         //if aProtocol is not supported, we need to return the string array of zero length
   138         String[] types = new String[0];
   139         String[] types = new String[0];
   139         if (aProtocol == null || aProtocol.equals(ANIMATION_HTTP_PROTOCOL)
   140         if (aProtocol == null || aProtocol.equals(ANIMATION_HTTP_PROTOCOL)
   140                 || aProtocol.equals(ANIMATION_HTTPS_PROTOCOL)
   141                 || aProtocol.equals(ANIMATION_HTTPS_PROTOCOL)
   141                 || aProtocol.equals(ANIMATION_FILE_PROTOCOL))
   142                 || aProtocol.equals(ANIMATION_FILE_PROTOCOL))
   142         {
   143         {
   149     /**
   150     /**
   150      * From PlugIn
   151      * From PlugIn
   151      */
   152      */
   152     public String[] getSupportedProtocols(String aContentType)
   153     public String[] getSupportedProtocols(String aContentType)
   153     {
   154     {
       
   155         // if aContentType is not supported, we need to return the string array of zero length
   154         String[] protocols = new String[0];
   156         String[] protocols = new String[0];
   155         if ((aContentType == null)
   157         if ((aContentType == null)
   156                 || aContentType.equals(ANIMATION_CONTENT_TYPE))
   158                 || aContentType.equals(ANIMATION_CONTENT_TYPE))
   157         {
   159         {
   158             protocols = new String[3];
   160             protocols = new String[3];