Source Code Cross Referenced for DateSymbolJSEmitter.java in  » Web-Framework » RSF » uk » org » ponder » htmlutil » 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 » Web Framework » RSF » uk.org.ponder.htmlutil 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 26 Oct 2006
003:         */
004:        package uk.org.ponder.htmlutil;
005:
006:        import java.text.DateFormat;
007:        import java.text.DateFormatSymbols;
008:        import java.text.SimpleDateFormat;
009:        import java.util.Calendar;
010:        import java.util.Locale;
011:
012:        import uk.org.ponder.arrayutil.ArrayUtil;
013:        import uk.org.ponder.localeutil.LocaleReceiver;
014:        import uk.org.ponder.stringutil.CharWrap;
015:
016:        /**
017:         * Emits a selection of Date symbols and formats for a particular Locale,
018:         * suitable for inclusion as part of a Javascript <script> block.
019:         * 
020:         * @author Antranig Basman (antranig@caret.cam.ac.uk)
021:         */
022:
023:        public class DateSymbolJSEmitter extends LocaleReceiver {
024:            private String prefix = "PUC_";
025:
026:            public void setArrayNamePrefix(String prefix) {
027:                this .prefix = prefix;
028:            }
029:
030:            public String emitDateSymbols() {
031:                Locale locale = getLocale();
032:                CharWrap togo = new CharWrap();
033:                togo.append(HTMLConstants.JS_BLOCK_START);
034:
035:                Calendar defcal = Calendar.getInstance(locale);
036:                DateFormatSymbols formatsymbols = new DateFormatSymbols(locale);
037:                // note that Java numbers months starting at 0!
038:                int cmonths = defcal.getActualMaximum(Calendar.MONTH) + 1;
039:
040:                String[] monthlong = formatsymbols.getMonths();
041:                monthlong = (String[]) ArrayUtil.trim(monthlong, cmonths);
042:                togo.append(HTMLUtil.emitJavascriptArray(
043:                        prefix + "MONTHS_LONG", monthlong));
044:
045:                String[] monthshort = formatsymbols.getShortMonths();
046:                monthshort = (String[]) ArrayUtil.trim(monthshort, cmonths);
047:                togo.append(HTMLUtil.emitJavascriptArray(prefix
048:                        + "MONTHS_SHORT", monthshort));
049:
050:                String[] weeklong = formatsymbols.getWeekdays();
051:                // note that Java numbers weekdays starting at 1!
052:                weeklong = (String[]) ArrayUtil.subArray(weeklong, 1, 8);
053:                togo.append(HTMLUtil.emitJavascriptArray(prefix
054:                        + "WEEKDAYS_LONG", weeklong));
055:
056:                String[] weekmed = formatsymbols.getShortWeekdays();
057:                weekmed = (String[]) ArrayUtil.subArray(weekmed, 1, 8);
058:                togo.append(HTMLUtil.emitJavascriptArray(prefix
059:                        + "WEEKDAYS_MEDIUM", weekmed));
060:
061:                String[] weekshort = shortenWeekdays(weekmed);
062:                togo.append(HTMLUtil.emitJavascriptArray(prefix
063:                        + "WEEKDAYS_SHORT", weekshort));
064:
065:                String[] weekonechar = oneCharWeekdays(weekmed);
066:                togo.append(HTMLUtil.emitJavascriptArray(prefix
067:                        + "WEEKDAYS_1CHAR", weekonechar));
068:
069:                int firstday = defcal.getFirstDayOfWeek() - 1;
070:                togo.append(HTMLUtil.emitJavascriptVar(prefix
071:                        + "FIRST_DAY_OF_WEEK", Integer.toString(firstday)));
072:
073:                // These illegal casts are required to access the pattern string
074:                SimpleDateFormat dateformat = (SimpleDateFormat) DateFormat
075:                        .getDateInstance(DateFormat.SHORT, locale);
076:                togo.append(HTMLUtil.emitJavascriptVar(prefix + "DATE_FORMAT",
077:                        dateformat.toLocalizedPattern()));
078:
079:                SimpleDateFormat datetimeformat = (SimpleDateFormat) DateFormat
080:                        .getDateTimeInstance(DateFormat.SHORT,
081:                                DateFormat.SHORT, locale);
082:                togo.append(HTMLUtil.emitJavascriptVar(prefix
083:                        + "DATETIME_FORMAT", datetimeformat
084:                        .toLocalizedPattern()));
085:
086:                SimpleDateFormat timeformat = (SimpleDateFormat) DateFormat
087:                        .getTimeInstance(DateFormat.SHORT, locale);
088:                togo.append(HTMLUtil.emitJavascriptVar(prefix + "TIME_FORMAT",
089:                        timeformat.toLocalizedPattern()));
090:
091:                togo.append(HTMLConstants.JS_BLOCK_END);
092:                return togo.toString();
093:            }
094:
095:            public static String shorten(String s, int prefix, int length) {
096:                if (prefix != 0) {
097:                    s = s.substring(prefix);
098:                }
099:                return s.length() < length ? s : s.substring(0, length);
100:
101:            }
102:
103:            // Deal with oriental-style weekday names by removing any common prefix
104:            public static int getCommonPrefix(String[] names) {
105:                if (names.length < 2)
106:                    return 0;
107:                else {
108:                    int index = 0;
109:                    while (true) {
110:                        if (index >= names[0].length()
111:                                || index >= names[1].length())
112:                            break;
113:                        if (names[0].charAt(index) != names[1].charAt(index))
114:                            break;
115:                        ++index;
116:                    }
117:                    return index;
118:                }
119:            }
120:
121:            String[] shortenWeekdays(String[] weekmed) {
122:                String[] togo = new String[weekmed.length];
123:                int prefix = getCommonPrefix(weekmed);
124:                for (int i = 0; i < weekmed.length; ++i) {
125:                    togo[i] = shorten(weekmed[i], prefix, 2);
126:                }
127:                return togo;
128:            }
129:
130:            String[] oneCharWeekdays(String[] weekmed) {
131:                String[] togo = new String[weekmed.length];
132:                int prefix = getCommonPrefix(weekmed);
133:                for (int i = 0; i < weekmed.length; ++i) {
134:                    togo[i] = shorten(weekmed[i], prefix, 1);
135:                }
136:                return togo;
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.