Source Code Cross Referenced for CalendarDayContainer.java in  » Blogger-System » thingamablog » net » sf » thingamablog » generator » 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 » Blogger System » thingamablog » net.sf.thingamablog.generator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.thingamablog.generator;
002:
003:        import java.util.ArrayList;
004:        import java.util.Calendar;
005:        import java.util.Date;
006:        import java.util.Hashtable;
007:        import java.util.List;
008:        import java.util.Vector;
009:
010:        import net.sf.thingamablog.blog.ArchiveRange;
011:        import net.sf.thingamablog.blog.BlogEntry;
012:        import net.sf.thingamablog.blog.EntryEnumeration;
013:        import net.sf.thingamablog.blog.TBWeblog;
014:
015:        public class CalendarDayContainer extends ListContainer {
016:            static final int TOP_PAGE = 0;
017:            /** Constant for an archive page */
018:            static final int ARC_PAGE = 1;
019:            /** Constant for a category page */
020:            static final int CAT_PAGE = 2;
021:
022:            private Calendar cal;
023:            private static Calendar monthCheck = Calendar.getInstance();
024:
025:            private int numDays = 7;
026:            private Vector days = new Vector();
027:            private Date startingDay;
028:            private TBWeblog blog;
029:
030:            private TextTag calendarDay = new TextTag("DayOfMonth");
031:            private DateTag calendarDate = new DateTag("DateOfDay");
032:
033:            private List containers;
034:            private DayContainer ifCurrentDay, ifDayHasEntries,
035:                    ifDayHasNoEntries;
036:            private DayContainer ifEmptySpace;
037:
038:            private int pageType;
039:            private String category;
040:            private ArchiveRange archive;
041:            private int month = -1;
042:
043:            public CalendarDayContainer(TBWeblog blog, Date start, int m) {
044:                super ("CalendarDay");
045:                _init(TOP_PAGE, blog, start, m);
046:            }
047:
048:            public CalendarDayContainer(TBWeblog blog, Date start,
049:                    ArchiveRange arc, int m) {
050:                super ("CalendarDay");
051:                archive = arc;
052:                _init(ARC_PAGE, blog, start, m);
053:            }
054:
055:            public CalendarDayContainer(TBWeblog blog, Date start, String cat,
056:                    int m) {
057:                super ("CalendarDay");
058:                category = cat;
059:                _init(CAT_PAGE, blog, start, m);
060:            }
061:
062:            private void _init(int type, TBWeblog wb, Date start, int m) {
063:                blog = wb;
064:                month = m;
065:                cal = Calendar.getInstance(blog.getLocale());
066:                pageType = type;
067:                startingDay = start;
068:
069:                ifCurrentDay = new IfCurrentDayContainer();
070:                ifDayHasEntries = new IfDayHasEntriesContainer();
071:                ifDayHasNoEntries = new IfDayHasNoEntriesContainer();
072:                ifEmptySpace = new IfEmptySpaceContainer();
073:                containers = new ArrayList(4);
074:                containers.add(ifCurrentDay);
075:                containers.add(ifDayHasEntries);
076:                containers.add(ifDayHasNoEntries);
077:                containers.add(ifEmptySpace);
078:            }
079:
080:            public void initListData(boolean asc, Hashtable attribs) {
081:                days.removeAllElements();
082:                cal.setTime(startingDay);
083:                for (int d = 0; d < numDays; d++) {
084:                    days.add(cal.getTime());
085:                    cal.add(Calendar.DAY_OF_YEAR, 1);//next day		        
086:                }
087:            }
088:
089:            public boolean isVisible() {
090:                return true;
091:            }
092:
093:            public List getTags() {
094:                return null;
095:            }
096:
097:            public List getContainers() {
098:                Date d = (Date) days.elementAt(currentIndex());
099:                ifDayHasEntries.setDay(d);
100:                ifDayHasNoEntries.setDay(d);
101:                ifCurrentDay.setDay(d);
102:                ifEmptySpace.setDay(d);
103:
104:                return containers;
105:            }
106:
107:            public Object getValueForTag(TemplateTag t, int i) {
108:                return "";
109:            }
110:
111:            public int getListDataSize() {
112:                return days.size();
113:            }
114:
115:            private String dayString(Date d) {
116:                cal.setTime(d);
117:                return cal.get(Calendar.DAY_OF_MONTH) + "";
118:            }
119:
120:            private BlogEntry getFirstEntryForDay(Date d) {
121:                Date d2 = new Date(d.getTime());
122:                ArchiveRange arc = new ArchiveRange(d, d2);
123:                BlogEntry be = null;
124:                try {
125:                    EntryEnumeration eEnum = blog.getBackend()
126:                            .getEntriesBetween(blog.getKey(),
127:                                    arc.getStartDate(),
128:                                    arc.getExpirationDate(), true);
129:                    while (eEnum.hasMoreEntries()) {
130:                        if (pageType == CAT_PAGE) {
131:                            BlogEntry e = eEnum.nextEntry();
132:                            String cats[] = e.getCategories();
133:
134:                            boolean found = false;
135:                            for (int i = 0; i < cats.length; i++) {
136:                                if (cats[i].equals(category)) {
137:                                    be = e;
138:                                    found = true;
139:                                    break;
140:                                }
141:                            }
142:
143:                            if (found)
144:                                break;//break out of while					
145:                        } else {
146:                            be = eEnum.nextEntry();
147:                            break;//we only want this entry
148:                        }
149:                    }
150:
151:                    eEnum.close();
152:                } catch (Exception ex) {
153:                    ex.printStackTrace();
154:                }
155:
156:                return be;
157:            }
158:
159:            private boolean hasEntriesForDay(Date d) {
160:                //if this cal is on an arc page, we only want the days on the page
161:                //to be highlighted in the cal
162:                if (pageType == ARC_PAGE) {
163:                    if (d.before(archive.getStartDate()))
164:                        return false;
165:                    if (d.after(archive.getExpirationDate()))
166:                        return false;
167:                }
168:
169:                Date d2 = new Date(d.getTime());
170:                ArchiveRange arc = new ArchiveRange(d, d2);
171:
172:                try {
173:                    //we have to check if the blog's archive base date is
174:                    //after the day, otherwise we'll get a calendar with
175:                    //links to non-existant entries
176:                    if (blog.getArchiveBaseDate().after(arc.getStartDate()))
177:                        return false;
178:
179:                    EntryEnumeration eEnum = blog.getBackend()
180:                            .getEntriesBetween(blog.getKey(),
181:                                    arc.getStartDate(),
182:                                    arc.getExpirationDate(), false);
183:
184:                    boolean hasEntries = false;
185:                    if (pageType == TOP_PAGE || pageType == ARC_PAGE) {
186:                        //doesn't matter which cat
187:                        hasEntries = eEnum.hasMoreEntries();
188:                    } else if (pageType == CAT_PAGE) {
189:                        while (eEnum.hasMoreEntries())//find first matching cat
190:                        {
191:                            BlogEntry be = eEnum.nextEntry();
192:                            String cats[] = be.getCategories();
193:
194:                            for (int i = 0; i < cats.length; i++) {
195:                                if (cats[i].equals(category)) {
196:                                    hasEntries = true;
197:                                    break;
198:                                }
199:                            }
200:
201:                            if (hasEntries)
202:                                break;
203:                        }
204:                    }
205:
206:                    eEnum.close();
207:                    return hasEntries;
208:                } catch (Exception ex) {
209:                }
210:
211:                return false;
212:            }
213:
214:            private abstract class DayContainer extends BasicContainer {
215:                private Date day;
216:
217:                public DayContainer(String name) {
218:                    super (name);
219:                }
220:
221:                public void setDay(Date d) {
222:                    day = d;
223:                }
224:
225:                public Date getDay() {
226:                    return day;
227:                }
228:
229:                public boolean isCurrentMonth() {
230:                    monthCheck.setTime(day);
231:                    return monthCheck.get(Calendar.MONTH) == month;
232:                }
233:            }
234:
235:            private class IfDayHasEntriesContainer extends DayContainer //BasicContainer
236:            {
237:                //private Date day;
238:                private TemplateTag entryIDTag = new TextTag("EntryID");
239:                private TemplateTag entryArcPageTag = new TextTag(
240:                        "EntryArchivePage");
241:
242:                public IfDayHasEntriesContainer() {
243:                    super ("IfDayHasEntries");
244:                    registerTag(calendarDay);
245:                    registerTag(calendarDate);
246:                    registerTag(entryIDTag);
247:                    registerTag(entryArcPageTag);
248:                    //day = d;
249:                }
250:
251:                public Object getValueForTag(TemplateTag tag) {
252:                    if (tag == calendarDay)
253:                        return dayString(getDay());
254:                    if (tag == calendarDate)
255:                        return getDay();
256:                    if (tag == entryIDTag) {
257:                        BlogEntry be = getFirstEntryForDay(getDay());
258:                        if (be != null)
259:                            return be.getID() + "";
260:                    }
261:                    if (tag == entryArcPageTag) {
262:                        ArchiveRange ar = blog.getArchiveForDate(getDay());
263:                        if (ar != null)
264:                            return blog.getArchiveUrl()
265:                                    + blog.getArchiveFileName(ar);
266:                    }
267:
268:                    // no entries/something went wrong
269:                    return dayString(getDay());
270:                }
271:
272:                public boolean isVisible() {
273:                    return hasEntriesForDay(getDay()) && isCurrentMonth();
274:                }
275:            }
276:
277:            private class IfDayHasNoEntriesContainer extends DayContainer//BasicContainer
278:            {
279:                //private Date day;
280:
281:                public IfDayHasNoEntriesContainer() {
282:                    super ("IfDayHasNoEntries");
283:                    registerTag(calendarDay);
284:                    registerTag(calendarDate);
285:                    //day = d;
286:                }
287:
288:                public Object getValueForTag(TemplateTag tag) {
289:                    if (tag == calendarDay)
290:                        return dayString(getDay());
291:                    if (tag == calendarDate)
292:                        return getDay();
293:                    return "";
294:                }
295:
296:                public boolean isVisible() {
297:                    return !hasEntriesForDay(getDay()) && isCurrentMonth();
298:                }
299:            }
300:
301:            private class IfCurrentDayContainer extends DayContainer//BasicContainer
302:            {
303:                //private Date day;
304:
305:                public IfCurrentDayContainer() {
306:                    super ("IfCurrentDay");
307:                }
308:
309:                public Object getValueForTag(TemplateTag tag) {
310:                    return "";
311:                }
312:
313:                public boolean isVisible() {
314:                    Calendar c = Calendar.getInstance(blog.getLocale());
315:                    int dOfy = c.get(Calendar.DAY_OF_YEAR);
316:                    c.setTime(getDay());
317:                    return c.get(Calendar.DAY_OF_YEAR) == dOfy
318:                            && isCurrentMonth();
319:                }
320:            }
321:
322:            private class IfEmptySpaceContainer extends DayContainer {
323:                public IfEmptySpaceContainer() {
324:                    super ("IfEmptySpace");
325:                }
326:
327:                public Object getValueForTag(TemplateTag tag) {
328:                    return "";
329:                }
330:
331:                public boolean isVisible() {
332:                    return !isCurrentMonth();
333:                }
334:            }
335:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.