List of usage examples for org.joda.time.format DateTimeFormatterBuilder DateTimeFormatterBuilder
public DateTimeFormatterBuilder()
From source file:org.jasig.portlet.blackboardvcportlet.mvc.sessionmngr.SessionCreateEditController.java
License:Apache License
@InitBinder public void initBinder(WebDataBinder binder) { final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("MM/dd/yyyy") .toFormatter();// w w w . ja v a2 s .c om binder.registerCustomEditor(DateMidnight.class, new CustomDateMidnightEditor(formatter, false)); final DateTimeFormatter formatter2 = new DateTimeFormatterBuilder().appendPattern("HH:mm").toFormatter(); binder.registerCustomEditor(LocalTime.class, new CustomTimeEditor(formatter2, false)); }
From source file:org.jasig.portlet.calendar.adapter.CalendarEventsDao.java
License:Apache License
protected DateTimeFormatter getDateFormatter(Locale locale, DateTimeZone timezone) { if (this.dateFormatters.containsKey(timezone.getID())) { return this.dateFormatters.get(timezone.getID()); }//from w w w. j a v a2 s . co m final String displayPattern = this.messageSource.getMessage("date.formatter.display", null, "EEE MMM d", locale); DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern(displayPattern).toFormatter() .withZone(timezone); this.dateFormatters.put(timezone.getID(), df); return df; }
From source file:org.jasig.portlet.calendar.adapter.CalendarEventsDao.java
License:Apache License
protected DateTimeFormatter getTimeFormatter(Locale locale, DateTimeZone timezone) { if (this.timeFormatters.containsKey(timezone.getID())) { return this.timeFormatters.get(timezone.getID()); }/* w w w .ja va 2s. c o m*/ final String displayPattern = this.messageSource.getMessage("time.formatter.display", null, "h:mm a", locale); DateTimeFormatter tf = new DateTimeFormatterBuilder().appendPattern(displayPattern).toFormatter() .withZone(timezone); this.timeFormatters.put(timezone.getID(), tf); return tf; }
From source file:org.jasig.portlet.calendar.mvc.controller.AjaxCalendarController.java
License:Apache License
@ResourceMapping public ModelAndView getEventList(ResourceRequest request, ResourceResponse response) throws Exception { // Pull parameters out of the resourceId final String resourceId = request.getResourceID(); final String[] resourceIdTokens = resourceId.split("-"); final String startDate = resourceIdTokens[0]; final int days = Integer.parseInt(resourceIdTokens[1]); final long startTime = System.currentTimeMillis(); final List<String> errors = new ArrayList<String>(); final Map<String, Object> model = new HashMap<String, Object>(); final PortletSession session = request.getPortletSession(); // get the user's configured time zone final String timezone = (String) session.getAttribute("timezone"); final DateTimeZone tz = DateTimeZone.forID(timezone); // get the period for this request final Interval interval = DateUtil.getInterval(startDate, days, request); final Set<CalendarDisplayEvent> calendarEvents = helper.getEventList(errors, interval, request); int index = 0; final Set<JsonCalendarEventWrapper> events = new TreeSet<JsonCalendarEventWrapper>(); for (CalendarDisplayEvent e : calendarEvents) { events.add(new JsonCalendarEventWrapper(e, index++)); }/*w w w. j a v a 2 s . co m*/ /* * Transform the event set into a map keyed by day. This code is * designed to separate events by day according to the user's configured * time zone. This ensures that we keep complicated time-zone handling * logic out of the JavaScript. * * Events are keyed by a string uniquely representing the date that is * still orderable. So that we can display a more user-friendly date * name, we also create a map representing date display names for each * date keyed in this response. */ // define a DateFormat object that uniquely identifies dates in a way // that can easily be ordered DateTimeFormatter orderableDf = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd").toFormatter() .withZone(tz); // define a DateFormat object that can produce user-facing display // as user-facing get it from i18N final String displayPattern = this.applicationContext.getMessage("date.formatter.display", null, "EEE MMM d", request.getLocale()); // names for dates DateTimeFormatter displayDf = new DateTimeFormatterBuilder().appendPattern(displayPattern).toFormatter() .withZone(tz); // define "today" and "tomorrow" so we can display these specially in the user interface DateMidnight now = new DateMidnight(tz); String today = orderableDf.print(now); String tomorrow = orderableDf.print(now.plusDays(1)); Map<String, String> dateDisplayNames = new HashMap<String, String>(); Map<String, List<JsonCalendarEventWrapper>> eventsByDay = new LinkedHashMap<String, List<JsonCalendarEventWrapper>>(); for (JsonCalendarEventWrapper event : events) { String day = orderableDf.print(event.getEvent().getDayStart()); // if we haven't seen this day before, add entries to the event and date name maps if (!eventsByDay.containsKey(day)) { // add a list for this day to the eventsByDay map eventsByDay.put(day, new ArrayList<JsonCalendarEventWrapper>()); // Add an appropriate day name for this date to the date names map. // If the day appears to be today or tomorrow display a special string value. // Otherwise, use the user-facing date format object. if (today.equals(day)) { dateDisplayNames.put(day, applicationContext.getMessage("today", null, "Today", request.getLocale())); } else if (tomorrow.equals(day)) { dateDisplayNames.put(day, this.applicationContext.getMessage("tomorrow", null, "Tomorrow", request.getLocale())); } else { dateDisplayNames.put(day, displayDf.print(event.getEvent().getDayStart())); } } // add the event to the by-day map eventsByDay.get(day).add(event); } log.trace("Prepared the following eventsByDay collection for user {}: {}", request.getRemoteUser(), eventsByDay); model.put("dateMap", eventsByDay); model.put("dateNames", dateDisplayNames); model.put("viewName", "jsonView"); model.put("errors", errors); // eTag processing, see https://wiki.jasig.org/display/UPM41/Portlet+Caching String etag = String.valueOf(model.hashCode()); String requestEtag = request.getETag(); // if the request ETag matches the hash for this response, send back // an empty response indicating that cached content should be used if (etag.equals(requestEtag)) { log.debug("Sending an empty response (due to matched ETag {} for user {})'", requestEtag, request.getRemoteUser()); // Must communicate new expiration time > 0 per Portlet Spec 22.2 response.getCacheControl().setExpirationTime(1); response.getCacheControl().setUseCachedContent(true); // Portal will return cached content or HTTP 304 // Return null so response is not committed before portal decides to return HTTP 304 or cached response. return null; } log.trace("Sending a full response for user {}", request.getRemoteUser()); // create new content with new validation tag response.getCacheControl().setETag(etag); // Must have expiration time > 0 to use response.getCacheControl().setUseCachedContent(true) response.getCacheControl().setExpirationTime(1); long overallTime = System.currentTimeMillis() - startTime; log.debug("AjaxCalendarController took {} ms to produce JSON model", overallTime); return new ModelAndView("json", model); }
From source file:org.jasig.portlet.calendar.url.CalendarkeyUrlCreatorImpl.java
License:Apache License
public CalendarkeyUrlCreatorImpl() { formatter = new DateTimeFormatterBuilder().appendPattern("yyyyMMdd").toFormatter(); }
From source file:org.jasig.portlet.calendar.url.StringTemplateUrlCreatorImpl.java
License:Apache License
protected DateTimeFormatter getDateFormatter(String format) { if (this.dateFormatters.containsKey(format)) { return this.dateFormatters.get(format); }// ww w. ja va 2s .co m DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern(format).toFormatter(); this.dateFormatters.put(format, df); return df; }
From source file:org.jasig.portlet.calendar.util.DateUtil.java
License:Apache License
public static Interval getInterval(String startDate, int days, PortletRequest request) throws ParseException { final PortletSession session = request.getPortletSession(); final String timezone = (String) session.getAttribute("timezone"); final DateTimeZone tz = DateTimeZone.forID(timezone); final DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern("MMddyyyy").toFormatter() .withZone(tz);//from w w w. ja v a 2s . c o m final DateMidnight start = new DateMidnight(df.parseDateTime(startDate), tz); return getInterval(start, days); }
From source file:org.jasig.portlet.conference.program.dao.ConferenceSessionDao.java
License:Apache License
@Scheduled(fixedRate = 900000) protected void retrieveProgram() { log.debug("Requesting program data from " + this.programUrl); final ConferenceProgram program = restTemplate.getForObject(programUrl, ConferenceProgram.class, Collections.<String, String>emptyMap()); if (program != null) { cache.put(new Element(PROGRAM_CACHE_KEY, program)); final List<String> tracks = new ArrayList<String>(); final List<String> types = new ArrayList<String>(); final List<String> levels = new ArrayList<String>(); final List<DateMidnight> dates = new ArrayList<DateMidnight>(); final DateTimeFormatter providedDF = new DateTimeFormatterBuilder().appendPattern("dd-MMM-yyyy") .toFormatter();/* w w w . ja v a 2 s . c o m*/ final DateTimeFormatter displayDF = new DateTimeFormatterBuilder().appendPattern("EEE MMMM d") .toFormatter(); for (final ConferenceSession session : getProgram().getSessions()) { final String track = session.getTrack(); if (shouldAddToList(track, tracks)) { tracks.add(track); } final String type = session.getType(); if (shouldAddToList(type, types)) { types.add(type); } final String level = session.getLevel(); if (shouldAddToList(level, levels)) { levels.add(level); } final String value = session.getDate(); final DateMidnight date = providedDF.parseDateTime(value).toDateMidnight(); if (!dates.contains(date)) { dates.add(date); } } Collections.sort(tracks); Collections.sort(levels); Collections.sort(types); Collections.sort(dates); LinkedHashMap<String, String> dateMap = new LinkedHashMap<String, String>(); for (DateMidnight date : dates) { dateMap.put(providedDF.print(date), displayDF.print(date)); } cache.put(new Element(PROGRAM_CACHE_KEY, program)); cache.put(new Element(TRACK_LIST_KEY, tracks)); cache.put(new Element(LEVEL_LIST_KEY, levels)); cache.put(new Element(TYPE_LIST_KEY, types)); cache.put(new Element(DATE_MAP_KEY, dateMap)); } }
From source file:org.jevis.commons.driver.DataSourceHelper.java
License:Open Source License
public static List<String> getFTPMatchedFileNames(FTPClient fc, DateTime lastReadout, String filePath) { filePath = filePath.replace("\\", "/"); String[] pathStream = getPathTokens(filePath); String startPath = ""; if (filePath.startsWith("/")) { startPath = "/"; }/*w w w . jav a2s.c o m*/ List<String> folderPathes = getMatchingPathes(startPath, pathStream, new ArrayList<String>(), fc, lastReadout, new DateTimeFormatterBuilder()); // System.out.println("foldersize,"+folderPathes.size()); List<String> fileNames = new ArrayList<String>(); if (folderPathes.isEmpty()) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable folder on the device"); return fileNames; } // String fileName = null; String fileNameScheme = pathStream[pathStream.length - 1]; String currentfolder = null; try { for (String folder : folderPathes) { // fc.changeWorkingDirectory(folder); // System.out.println("currentFolder,"+folder); currentfolder = folder; // for (FTPFile file : fc.listFiles(folder)) { // System.out.println(file.getName()); // } fc.changeWorkingDirectory(folder); for (FTPFile file : fc.listFiles()) { // org.apache.log4j.Logger.getLogger(Launcher.class.getName()).log(org.apache.log4j.Level.ALL, "CurrentFileName: " + fileName); // fileName = removeFoler(fileName, folder); if (file.getTimestamp().compareTo(lastReadout.toGregorianCalendar()) < 0) { continue; } boolean match = false; System.out.println(file.getName()); if (DataSourceHelper.containsTokens(fileNameScheme)) { boolean matchDate = matchDateString(file.getName(), fileNameScheme); DateTime folderTime = getFileTime(folder + file.getName(), pathStream); boolean isLater = folderTime.isAfter(lastReadout); if (matchDate && isLater) { match = true; } } else { Pattern p = Pattern.compile(fileNameScheme); Matcher m = p.matcher(file.getName()); match = m.matches(); } if (match) { fileNames.add(folder + file.getName()); } } } } catch (IOException ex) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, ex.getMessage()); } catch (Exception ex) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Error while searching a matching file"); org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Folder: " + currentfolder); org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "FileName: " + fileNameScheme); org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, ex.getMessage()); } if (folderPathes.isEmpty()) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable files on the device"); } // System.out.println("filenamesize"+fileNames.size()); return fileNames; }
From source file:org.jevis.commons.driver.DataSourceHelper.java
License:Open Source License
public static List<String> getSFTPMatchedFileNames(ChannelSftp _channel, DateTime lastReadout, String filePath) {//from w w w .ja v a2 s . co m filePath = filePath.replace("\\", "/"); String[] pathStream = getPathTokens(filePath); String startPath = ""; if (filePath.startsWith("/")) { startPath = "/"; } List<String> folderPathes = getSFTPMatchingPathes(startPath, pathStream, new ArrayList<String>(), _channel, lastReadout, new DateTimeFormatterBuilder()); // System.out.println("foldersize,"+folderPathes.size()); List<String> fileNames = new ArrayList<String>(); if (folderPathes.isEmpty()) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable folder on the device"); return fileNames; } if (folderPathes.isEmpty()) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable folder on the device"); return fileNames; } String fileNameScheme = pathStream[pathStream.length - 1]; String currentfolder = null; try { for (String folder : folderPathes) { // fc.changeWorkingDirectory(folder); // System.out.println("currentFolder,"+folder); currentfolder = folder; // for (FTPFile file : fc.listFiles(folder)) { // System.out.println(file.getName()); // } // Vector ls = _channel.ls(folder); for (Object fileName : _channel.ls(folder)) { LsEntry currentFile = (LsEntry) fileName; String currentFileName = currentFile.getFilename(); currentFileName = removeFoler(currentFileName, folder); boolean match = false; System.out.println(currentFileName); if (DataSourceHelper.containsTokens(fileNameScheme)) { boolean matchDate = matchDateString(currentFileName, fileNameScheme); DateTime folderTime = getFileTime(folder + currentFileName, pathStream); boolean isLater = folderTime.isAfter(lastReadout); if (matchDate && isLater) { match = true; } } else { Pattern p = Pattern.compile(fileNameScheme); Matcher m = p.matcher(currentFileName); match = m.matches(); } if (match) { fileNames.add(folder + currentFileName); } } } } catch (Exception ex) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Error while searching a matching file"); org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Folder: " + currentfolder); org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "FileName: " + fileNameScheme); org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, ex.getMessage()); } if (folderPathes.isEmpty()) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable files on the device"); } // System.out.println("filenamesize"+fileNames.size()); return fileNames; }