Source Code Cross Referenced for LocatorParser.java in  » 6.0-JDK-Modules » j2me » com » sun » mmedia » protocol » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » com.sun.mmedia.protocol 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * 
003:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
004:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005:         * 
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License version
008:         * 2 only, as published by the Free Software Foundation.
009:         * 
010:         * This program is distributed in the hope that it will be useful, but
011:         * WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * General Public License version 2 for more details (a copy is
014:         * included at /legal/license.txt).
015:         * 
016:         * You should have received a copy of the GNU General Public License
017:         * version 2 along with this work; if not, write to the Free Software
018:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019:         * 02110-1301 USA
020:         * 
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022:         * Clara, CA 95054 or visit www.sun.com if you need additional
023:         * information or have any questions.
024:         */
025:
026:        package com.sun.mmedia.protocol;
027:
028:        /**
029:         * Parses a given locator or encoding string into its constituent properties.
030:         * Breaks it up into 3 main parts : the protocol, the device and the parameter
031:         * list of the form protocol://device?param1=value1&param2=value2...
032:         */
033:        public final class LocatorParser {
034:
035:            /**
036:             * Constructs a parser object and initializes its state.
037:             * @param s The string to be parsed
038:             */
039:            public LocatorParser(String s) {
040:                length = s.length();
041:                locator = s;
042:            }
043:
044:            /**
045:             * Parses and returns the protocol part of the locator, if any.
046:             * @return The protocol string, or null if there isn't a protocol part
047:             */
048:            public String getProtocol() {
049:                int colonIndex = locator.indexOf("://");
050:                int oldIndex = index;
051:                if (colonIndex < 1)
052:                    return null;
053:                index = colonIndex + 3;
054:                return locator.substring(oldIndex, colonIndex);
055:            }
056:
057:            /**
058:             * Parses and returns the device name part of the locator, if any.
059:             * @return The device name string, or null if there isn't one.
060:             */
061:            public String getDevice() {
062:                if (index >= length)
063:                    return null;
064:                int oldIndex = index;
065:                // Get the index of the question mark
066:                int queryIndex = locator.indexOf("?", index);
067:                // If its not found, then the whole string is assumed to be the device
068:                if (queryIndex < 0) {
069:                    index = length;
070:                    return locator.substring(oldIndex);
071:                } else if (queryIndex == 0) {
072:                    return null;
073:                }
074:                // Otherwise move the index forward past the ?
075:                index = queryIndex + 1;
076:                // return the device name portion
077:                return locator.substring(oldIndex, queryIndex);
078:            }
079:
080:            /**
081:             * Parses and returns the next parameter key in a parameter
082:             * "key=value" pair.
083:             * @return The key part of the parameter "key=value" pair
084:             */
085:            public String getParameter() {
086:                if (index >= length)
087:                    return null;
088:                int ampIndex = locator.indexOf("&", index);
089:                // Assume last parameter
090:                if (ampIndex < 0)
091:                    ampIndex = length;
092:
093:                // token = "abc=xyz"
094:                String token = locator.substring(index, ampIndex);
095:
096:                int eq = token.indexOf("=");
097:                // If there's no = or nothing before the = or nothing after the =
098:                if (eq < 1 || eq == token.length() - 1)
099:                    return null;
100:                String key = token.substring(0, eq);
101:                // What's after the = is the value. Store it for later query thru
102:                // the getValue() method
103:                value = token.substring(eq + 1);
104:                index = ampIndex + 1;
105:                return key;
106:            }
107:
108:            /**
109:             * Returns the value corresponding to the most recently parsed parameter
110:             * @return The value part of the "key=value" parameter pair.
111:             */
112:            public String getValue() {
113:                return value;
114:            }
115:
116:            /**
117:             * Checks if there are any more characters in the string that haven't been
118:             * parsed yet.
119:             * @return true if there are more characters to be parsed, false otherwise
120:             */
121:            public boolean hasMore() {
122:                return index < length;
123:            }
124:
125:            public static final String S_PROTOCOL_CAPTURE = "capture";
126:            //public static final String S_PROTOCOL_HTTP     = "http";
127:            //public static final String S_PROTOCOL_RTP      = "rtp";
128:
129:            public static final String S_DEVICE_AUDIO = "audio";
130:            public static final String S_DEVICE_VIDEO = "video";
131:            //public static final String S_DEVICE_AV       = "audio_video";
132:            public static final String S_DEVICE_RADIO = "radio";
133:
134:            //AUDIO,VIDEO,IMAGE encoding parameter keys and values
135:            public static final String S_ENCODING = "encoding";
136:            public static final String S_ENCODING_JPEG = "jpeg";
137:            public static final String S_ENCODING_PNG = "png";
138:            public static final String S_ENCODING_PCM = "pcm";
139:
140:            public static final String S_TYPE = "type";
141:            public static final String S_TYPE_JFIF = "jfif";
142:            //public static final String S_TYPE_EXIF       = "exif";
143:
144:            public static final String S_WIDTH = "width";
145:
146:            public static final String S_HEIGHT = "height";
147:
148:            public static final String S_QUALITY = "quality";
149:
150:            public static final String S_PROGRESSIVE = "progressive";
151:
152:            public static final String S_INTERLACED = "interlaced";
153:
154:            public static final String S_FPS = "fps";
155:
156:            public static final String S_COLORS = "colors";
157:
158:            public static final String S_JPEG = "jpeg";
159:
160:            public static final String S_PNG = "png";
161:
162:            public static final String S_JFIF = "jfif";
163:
164:            public static final String S_TRUE = "true";
165:
166:            public static final String S_FALSE = "false";
167:
168:            public static final String S_AUDIO = "audio";
169:
170:            public static final String S_VIDEO = "video";
171:
172:            public static final String S_RATE = "rate";
173:            public static final String S_BITS = "bits";
174:            public static final String S_CHANNELS = "channels";
175:            public static final String S_ENDIAN = "endian";
176:            public static final String S_ENDIAN_BIG = "big";
177:            public static final String S_ENDIAN_LITTLE = "little";
178:
179:            public static final String S_SIGN = "signed";
180:            public static final String S_SIGN_SIGNED = "signed";
181:            public static final String S_SIGN_UNSIGNED = "unsigned";
182:
183:            //RADIO encoding parameter keys and values
184:            public static final String S_RADIO_FREQ = "f";
185:
186:            public static final String S_RADIO_MOD = "mod";
187:            public static final String S_RADIO_MOD_FM = "fm";
188:            public static final String S_RADIO_MOD_AM = "am";
189:
190:            public static final String S_RADIO_ST = "st";
191:            public static final String S_RADIO_ST_MONO = "mono";
192:            public static final String S_RADIO_ST_STEREO = "stereo";
193:            public static final String S_RADIO_ST_AUTO = "auto";
194:
195:            public static final String S_RADIO_PRGID = "id";
196:
197:            public static final String S_RADIO_PRESET = "preset";
198:
199:            /** The locator to be parsed */
200:            private String locator;
201:
202:            /** The current pointer into the locator where parsing is to continue */
203:            private int index;
204:
205:            /** The length of the locator */
206:            private int length;
207:
208:            /** The latest value in a "key=value" pair */
209:            private String value;
210:
211:            // Usage:
212:            //     public static void main(String [] args) {
213:            // 	LocatorParser lp = new LocatorParser(args[0]);
214:            // 	System.err.println("Protocol = " + lp.getProtocol());
215:            // 	System.err.println("Device = " + lp.getDevice());
216:            // 	while (lp.hasMore()) {
217:            // 	    System.err.println(lp.getParameter() + " = " + lp.getValue());
218:            // 	}
219:            //     }
220:
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.