Source Code Cross Referenced for Utility.java in  » Web-Mail » claros-intouch2-2.2-beta » org » claros » intouch » calendar » utility » 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 Mail » claros intouch2 2.2 beta » org.claros.intouch.calendar.utility 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.claros.intouch.calendar.utility;
002:
003:        import java.sql.Timestamp;
004:        import java.text.SimpleDateFormat;
005:        import java.util.ArrayList;
006:        import java.util.Calendar;
007:        import java.util.Date;
008:
009:        import org.claros.intouch.calendar.models.CalendarObjectWrap;
010:
011:        /**
012:         * @author Umut Gokbayrak
013:         */
014:        public class Utility {
015:            /**
016:             * Input olarak gelen tarihi parametreye gore ait oldugu gunun basina veya
017:             * sonuna gonderir. Ornegin  haftanin ilk gununu buldugumuzda calendar objemizi 
018:             * o gunun ilk salisesi 00:00.000 saatine cevirir. Bunun icin isBegin parametresi
019:             * true olmalidir.  
020:             * @param cal
021:             * @param isBegin
022:             * @return
023:             */
024:            public static Timestamp getLimitTimestampFromCalendar(Calendar cal,
025:                    boolean isBegin) {
026:                SimpleDateFormat sdf = new SimpleDateFormat(
027:                        "yyyy-MM-dd HH:mm:ss.SSS");
028:                SimpleDateFormat sdfBegin = new SimpleDateFormat(
029:                        "yyyy-MM-dd 00:00:00.000");
030:                SimpleDateFormat sdfEnd = new SimpleDateFormat(
031:                        "yyyy-MM-dd 23:59:59.999");
032:
033:                Calendar calTmp = Calendar.getInstance();
034:                if (isBegin) {
035:                    Timestamp begin = Timestamp.valueOf(sdfBegin.format(cal
036:                            .getTime()));
037:                    calTmp.setTime(new Date(begin.getTime()));
038:                    calTmp.add(Calendar.MILLISECOND, -1);
039:                } else {
040:                    Timestamp end = Timestamp.valueOf(sdfEnd.format(cal
041:                            .getTime()));
042:                    calTmp.setTime(new Date(end.getTime()));
043:                    calTmp.add(Calendar.MILLISECOND, 1);
044:                }
045:                return Timestamp.valueOf(sdf.format(calTmp.getTime()));
046:            }
047:
048:            /**
049:             * 
050:             * @param cal
051:             * @param timeVar
052:             * @return
053:             */
054:            public static ArrayList getBeginEndTimestamps(Calendar cal,
055:                    int timeVar) {
056:                Timestamp begin = null;
057:                Timestamp end = null;
058:                cal.setFirstDayOfWeek(Calendar.SUNDAY);
059:
060:                switch (timeVar) {
061:                case Constants.DAY:
062:                    begin = getLimitTimestampFromCalendar(cal, true);
063:                    end = getLimitTimestampFromCalendar(cal, false);
064:                    break;
065:                case Constants.WEEK:
066:                    // Eger buraya gelmis olan gun pazartesi degilse pazartesi yapmaliyiz.
067:                    int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
068:                    while (dayOfWeek != Calendar.SUNDAY) {
069:                        cal.add(Calendar.DATE, -1);
070:                        dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
071:                    }
072:
073:                    Calendar sunday = (Calendar) cal.clone();
074:                    sunday.add(Calendar.DATE, 6);
075:                    begin = getLimitTimestampFromCalendar(cal, true);
076:                    end = getLimitTimestampFromCalendar(sunday, false);
077:                    sunday = null;
078:                    break;
079:                case Constants.MONTH:
080:                    cal.set(Calendar.DAY_OF_MONTH, 1);
081:
082:                    Calendar lastDay = (Calendar) cal.clone();
083:                    int l = lastDay.getActualMaximum(Calendar.DAY_OF_MONTH);
084:                    lastDay.set(Calendar.DAY_OF_MONTH, l);
085:
086:                    begin = getLimitTimestampFromCalendar(cal, true);
087:                    end = getLimitTimestampFromCalendar(lastDay, false);
088:                    lastDay = null;
089:                    break;
090:                }
091:
092:                ArrayList out = new ArrayList();
093:                out.add(begin);
094:                out.add(end);
095:                return out;
096:            }
097:
098:            /**
099:             * Tekrarlanan olaylar�n belirtilen zaman aral���nda (begin -> end) ger�ekle�ip 
100:             * ger�ekle�medi�ini anlamak i�in o ajanda kayd� belirtilen kriter ile 
101:             * end tarihinden k���k oldu�u s�rece ileriye do�ru sarmak gereklidir. Bu 
102:             * metod bu i�lemi yapar.  
103:             * @param tmpApp			ajanda kayd�
104:             * @param timeCriteria		ileriye do�ru sar�lan kriter. gun/hafta/ay/y�l vs...
105:             * @param ascend			ka�ar ka�ar artt�r�lmal� roll ederken. 
106:             * @param begin				hangi zaman aral���na kadar sar�yoruz. ba�lang�� parametresi
107:             * @param end				hangi zaman aral���na kadar sar�yoruz. biti� parametresi
108:             * @return					sar�lm�� halde ajanda kayd�n� d�nd�r�r
109:             */
110:            public static CalendarObjectWrap rollAppointment(
111:                    CalendarObjectWrap tmpApp, int timeCriteria, int ascend,
112:                    Timestamp begin, Timestamp end) {
113:                Timestamp tmpDate = tmpApp.getRecordDate();
114:
115:                while (tmpDate.before(begin)) {
116:                    Calendar tmpCal = Calendar.getInstance();
117:                    tmpCal.setTime(new Date(tmpDate.getTime()));
118:                    tmpCal.add(timeCriteria, ascend);
119:                    tmpDate = new Timestamp(tmpCal.getTime().getTime());
120:                }
121:                if (tmpDate.before(end)) {
122:                    // tekrarlanan olaylarda olay�n tekrarland��� ve o hafta/ay/y�l i�inde yer ald��� tarihi burada buluyoruz.
123:                    tmpApp.setOccuringDate(tmpDate);
124:                    return tmpApp;
125:                }
126:                return null;
127:            }
128:
129:            public static CalendarObjectWrap rollAppointmentOnce(
130:                    CalendarObjectWrap tmpApp, int timeCriteria, int ascend,
131:                    Timestamp end) {
132:                Timestamp tmpDate = tmpApp.getOccuringDate();
133:
134:                Calendar tmpCal = Calendar.getInstance();
135:                tmpCal.setTime(new Date(tmpDate.getTime()));
136:                tmpCal.add(timeCriteria, ascend);
137:                tmpDate = new Timestamp(tmpCal.getTime().getTime());
138:
139:                if (tmpDate.before(end)) {
140:                    tmpApp.setOccuringDate(tmpDate);
141:                    return tmpApp;
142:                }
143:                return null;
144:            }
145:
146:            /**
147:             * @param cal
148:             * @param b
149:             * @return
150:             */
151:            public static Timestamp getHourLimitTimestampFromCalendar(
152:                    Calendar cal, boolean isBegin) {
153:                SimpleDateFormat sdf = new SimpleDateFormat(
154:                        "yyyy-MM-dd HH:mm:ss.SSS");
155:                SimpleDateFormat sdfBegin = new SimpleDateFormat(
156:                        "yyyy-MM-dd HH:00:00.000");
157:                SimpleDateFormat sdfEnd = new SimpleDateFormat(
158:                        "yyyy-MM-dd HH:59:59.999");
159:
160:                Calendar calTmp = Calendar.getInstance();
161:                if (isBegin) {
162:                    Timestamp begin = Timestamp.valueOf(sdfBegin.format(cal
163:                            .getTime()));
164:                    calTmp.setTime(new Date(begin.getTime()));
165:                    calTmp.add(Calendar.MILLISECOND, -1);
166:                } else {
167:                    Timestamp end = Timestamp.valueOf(sdfEnd.format(cal
168:                            .getTime()));
169:                    calTmp.setTime(new Date(end.getTime()));
170:                    calTmp.add(Calendar.MILLISECOND, 1);
171:                }
172:                return Timestamp.valueOf(sdf.format(calTmp.getTime()));
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.