|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: file protocol |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.microedition.media.protocol.file; |
|
20 |
|
21 import javax.microedition.media.MediaException; |
|
22 |
|
23 import com.nokia.microedition.media.Locator; |
|
24 import com.nokia.microedition.media.InternalPlayer; |
|
25 import com.nokia.microedition.media.ManagerImpl; |
|
26 import com.nokia.microedition.media.NativePlayerFactory; |
|
27 import com.nokia.microedition.media.ConnectorDataSource; |
|
28 import com.nokia.microedition.media.tone.TonePlayer; |
|
29 import javax.microedition.io.file.FileConnection; |
|
30 import javax.microedition.io.Connector; |
|
31 import java.io.IOException; |
|
32 |
|
33 |
|
34 /** |
|
35 * This class presents file protocol |
|
36 */ |
|
37 public class Protocol implements |
|
38 com.nokia.microedition.media.protocol.Protocol |
|
39 { |
|
40 private static final String FILE = "file://"; |
|
41 private static final String DRM_SUFFIX = "dcf"; |
|
42 private static final String DRM_PARAMS = "?drm=enc"; |
|
43 private static final String JTS_SUFFIX = "jts"; |
|
44 /** |
|
45 * Default constructor. |
|
46 */ |
|
47 public Protocol() |
|
48 { |
|
49 } |
|
50 |
|
51 /** |
|
52 * From interface Protocol |
|
53 * @see Protocol |
|
54 */ |
|
55 public InternalPlayer createPlayer(Locator aLocator) |
|
56 throws java.io.IOException, |
|
57 MediaException, |
|
58 java.lang.SecurityException |
|
59 { |
|
60 FileConnection fileConnection = null; |
|
61 try |
|
62 { |
|
63 if ((aLocator.getParameters() == null) && |
|
64 (aLocator.getMiddlePart().endsWith(DRM_SUFFIX) |
|
65 )) |
|
66 { |
|
67 // DRM file, adding parameters to locator |
|
68 fileConnection = (FileConnection)Connector.open(aLocator.getLocatorString(),Connector.READ); |
|
69 } |
|
70 else if (aLocator.getMiddlePart().endsWith(JTS_SUFFIX)) |
|
71 { |
|
72 // JTS file, this format is handled in Java side, so creating player in traditional way |
|
73 ConnectorDataSource dataSource = new ConnectorDataSource(aLocator); |
|
74 return new TonePlayer(dataSource); |
|
75 } |
|
76 else |
|
77 { |
|
78 fileConnection = (FileConnection)Connector.open(aLocator.getLocatorString(), |
|
79 Connector.READ); |
|
80 } |
|
81 String fileAndPath = getPathAndFileName(fileConnection); |
|
82 Locator newLocator = new Locator(fileAndPath); |
|
83 return NativePlayerFactory.createPlayer(newLocator, null); |
|
84 } |
|
85 finally |
|
86 { |
|
87 if (null != fileConnection) |
|
88 { |
|
89 fileConnection.close(); |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 /** |
|
95 * Internal operation to construct path + fileName from the URI of the file. |
|
96 * Note: This operation removes parameter of the URI just like old |
|
97 * FileConnectionImpl.getPathAndFileName() operation (used in older releases). |
|
98 */ |
|
99 private String getPathAndFileName(FileConnection aFileConn) |
|
100 { |
|
101 String path = aFileConn.getPath(); |
|
102 // Path always starts with '/' character. This has to be skipped away because |
|
103 // otherwise this is converted to '\\' below. FILE constant contains this first |
|
104 // character('/') of the path. |
|
105 path = path.substring(1); |
|
106 String pathAndFileName = path + aFileConn.getName(); |
|
107 pathAndFileName = pathAndFileName.replace('/','\\'); |
|
108 return FILE + pathAndFileName; |
|
109 } |
|
110 } |