Source Code Cross Referenced for CldcUtils.java in  » 6.0-JDK-Modules » j2me » com » sun » j2me » payment » 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.j2me.payment 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package com.sun.j2me.payment;
028:
029:        import java.io.InputStream;
030:        import java.io.IOException;
031:        import java.io.UnsupportedEncodingException;
032:
033:        import java.util.TimeZone;
034:        import java.util.Calendar;
035:        import java.util.Date;
036:
037:        import com.sun.midp.util.Properties;
038:        import com.sun.midp.util.DateParser;
039:
040:        import com.sun.midp.installer.JadProperties;
041:
042:        import com.sun.midp.i18n.Resource;
043:        import com.sun.midp.i18n.ResourceConstants;
044:
045:        /**
046:         * This class implements utility methods used in the 
047:         * <code>com.sun.j2me.payment</code> package.
048:         *
049:         * @version 
050:         */
051:        public class CldcUtils extends Utils {
052:
053:            /** The offset value between Utils and ResourceConstants resource keys. */
054:            public static final int PAYMENT_ID_OFFSET = Utils.PAYMENT_PROV_SEL_DLG_NEVER
055:                    - ResourceConstants.PAYMENT_PROV_SEL_DLG_NEVER;
056:
057:            /** Creates a new instance of <code>CldcUtils</code>. */
058:            public CldcUtils() {
059:            }
060:
061:            /**
062:             * Parses properties from the given input stream and returns them as an
063:             * instance of the <code>Properties</code> class. The <code>charset</code>
064:             * parameter contains the actual character encoding of the input stream.
065:             *
066:             * @param is the input stream which contains properties
067:             * @param charset the character set of the input stream
068:             * @return the properties read from the stream
069:             * @throws UnsupportedEncodingException if <code>charset</code> is not 
070:             *      supported by the implementation
071:             * @throws IOException if the input stream doesn't have properties in the
072:             *      correct format
073:             */
074:            public Properties loadProperties(InputStream is, String charset)
075:                    throws UnsupportedEncodingException, IOException {
076:                JadProperties props = new JadProperties();
077:                props.load(is, charset);
078:
079:                return props;
080:            }
081:
082:            /**
083:             * Returns a resource string for the given key.
084:             *
085:             * @param key the key
086:             * @return the string assigned to the key
087:             */
088:            public String getString(int key) {
089:                if (key >= PAYMENT_ID_OFFSET) {
090:                    key -= PAYMENT_ID_OFFSET;
091:                }
092:                return Resource.getString(key);
093:            }
094:
095:            /**
096:             * Returns a modified resource string for the given key. It replaces any
097:             * occurence of %1, %2, ... in the original resource string with the first, 
098:             * second, ... string from <code>values</code>.
099:             *
100:             * @param key the key
101:             * @param values the replacement strings
102:             * @return the modified resource string
103:             */
104:            public String getString(int key, String[] values) {
105:                if (key >= PAYMENT_ID_OFFSET) {
106:                    key -= PAYMENT_ID_OFFSET;
107:                }
108:                return Resource.getString(key, values);
109:            }
110:
111:            /**
112:             * Parses a date string according to the ISO 8601 standard.
113:             *
114:             * @param date the date string in the format YYYY-MM-DDTHH:MM[:SS][[+|-]
115:             *      HH[MM]]
116:             * @return the number of milliseconds elapsed since 1970-1-1 GMT to this
117:             *      date
118:             * @throws IllegalArgumentException if the format of the date string is
119:             *      incorrect or the date is invalid
120:             */
121:            public long parseISODate(String date) {
122:                return DateParser.parseISO(date);
123:            }
124:
125:            /**
126:             * Converts the given date to the string formatted according to the 
127:             * ISO 8601 standard.
128:             *
129:             * @param date the date as the number of milliseconds elapsed since 
130:             *      1970-1-1 GMT
131:             * @return the date string
132:             */
133:            public String formatISODate(long date) {
134:                TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT");
135:                Calendar gmtCalendar = Calendar.getInstance(gmtTimeZone);
136:
137:                gmtCalendar.setTime(new Date(date));
138:
139:                StringBuffer buffer = new StringBuffer();
140:                char[] temp = new char[4];
141:
142:                formatNumber(temp, gmtCalendar.get(Calendar.YEAR), 4);
143:                buffer.append(temp, 0, 4);
144:                buffer.append('-');
145:                formatNumber(temp, gmtCalendar.get(Calendar.MONTH) + 1, 2);
146:                buffer.append(temp, 0, 2);
147:                buffer.append('-');
148:                formatNumber(temp, gmtCalendar.get(Calendar.DAY_OF_MONTH), 2);
149:                buffer.append(temp, 0, 2);
150:                buffer.append(' ');
151:
152:                formatNumber(temp, gmtCalendar.get(Calendar.HOUR_OF_DAY), 2);
153:                buffer.append(temp, 0, 2);
154:                buffer.append(':');
155:                formatNumber(temp, gmtCalendar.get(Calendar.MINUTE), 2);
156:                buffer.append(temp, 0, 2);
157:                buffer.append(':');
158:                formatNumber(temp, gmtCalendar.get(Calendar.SECOND), 2);
159:                buffer.append(temp, 0, 2);
160:
161:                buffer.append('Z');
162:
163:                return buffer.toString();
164:            }
165:
166:            private void formatNumber(char[] dest, int number, int digits) {
167:                int index = digits;
168:                while (index > 0) {
169:                    dest[--index] = (char) ((number % 10) + '0');
170:                    number = number / 10;
171:                }
172:            }
173:
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.