|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.microedition.media; |
|
20 |
|
21 import javax.microedition.media.MediaException; |
|
22 |
|
23 /** |
|
24 * Locator parsing class |
|
25 */ |
|
26 public class Locator |
|
27 { |
|
28 private static final String PROTOCOL_SEPARATOR = "://"; |
|
29 private static final char PARAMETER_SEPARATOR = '?'; |
|
30 private final String iLocator; |
|
31 |
|
32 /** |
|
33 * Constructor |
|
34 * @param aLocator Locator to be parsed |
|
35 */ |
|
36 public Locator(String aLocator) |
|
37 { |
|
38 iLocator = aLocator; |
|
39 } |
|
40 /** |
|
41 * Parses the protocol part of the locator e.g. returns |
|
42 * "capture" from "capture://audio?encoding=amr" locator |
|
43 * @return parsed protocol |
|
44 * @throw MediaException if Protocol cannot |
|
45 * be parsed from the locator |
|
46 */ |
|
47 public String getProtocol() throws MediaException |
|
48 { |
|
49 // Find protocol separator |
|
50 int pSep = iLocator.indexOf(PROTOCOL_SEPARATOR); |
|
51 |
|
52 // Protocol must exist |
|
53 if (pSep == -1) |
|
54 { |
|
55 throw new MediaException( |
|
56 "Could not create player, URI separator not found"); |
|
57 } |
|
58 return iLocator.substring(0, pSep); |
|
59 } |
|
60 |
|
61 /** |
|
62 * Parses the middle part of the locator e.g. returns |
|
63 * "audio" from "capture://audio?encoding=amr" locator |
|
64 * @return parsed middle part |
|
65 * @throw MediaException if middle part cannot |
|
66 * be parsed from the locator |
|
67 */ |
|
68 public String getMiddlePart() throws MediaException |
|
69 { |
|
70 // Find possible parameter separator |
|
71 int parSep = iLocator.indexOf(PARAMETER_SEPARATOR); |
|
72 |
|
73 // No parameters |
|
74 if (parSep == -1) |
|
75 { |
|
76 parSep = iLocator.length(); |
|
77 } |
|
78 |
|
79 return iLocator.substring(getProtocol().length() + |
|
80 PROTOCOL_SEPARATOR.length(), parSep); |
|
81 } |
|
82 |
|
83 /** |
|
84 * Parses possible parameters of the locator e.g. returns |
|
85 * "encoding=amr" from "capture://audio?encoding=amr" locator |
|
86 * @return parsed parameters or <code>null</code> if there is |
|
87 * not parameters |
|
88 */ |
|
89 public String getParameters() |
|
90 { |
|
91 // Find possible parameter separator |
|
92 int parSep = iLocator.indexOf(PARAMETER_SEPARATOR); |
|
93 |
|
94 String locator = null; |
|
95 |
|
96 // Null is returned if there is no parameters |
|
97 if (parSep != -1) |
|
98 { |
|
99 locator = iLocator.substring(parSep + 1); |
|
100 } |
|
101 |
|
102 return locator; |
|
103 } |
|
104 |
|
105 /** |
|
106 * Returns the whole locator string |
|
107 * @return locator used to create this instance |
|
108 */ |
|
109 public String getLocatorString() |
|
110 { |
|
111 return iLocator; |
|
112 } |
|
113 } |