List of usage examples for java.util GregorianCalendar clone
@Override
public Object clone()
From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.AddBookingRoomViewParamsController.java
@Override public Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { Map map = new HashMap<String, Object>(); int filterGroup = Integer.parseInt(request.getParameter("filterGroup")); String filterDate = request.getParameter("filterDate"); if (filterDate.compareTo("") == 0) filterDate = null;//from w w w. j av a 2 s . c o m int repType = Integer.parseInt(request.getParameter("repType")); int repCount = Integer.parseInt(request.getParameter("repCount")); String date = request.getParameter("date"); String startStr = request.getParameter("startTime"); String endStr = request.getParameter("endTime"); GregorianCalendar cal = BookingRoomUtils.getCalendar(startStr); boolean collisions = false; //reservations in not visible time period if (repCount > 0) { GregorianCalendar nextS = BookingRoomUtils.getCalendar(startStr); GregorianCalendar nextE = BookingRoomUtils.getCalendar(endStr); List<Reservation> coll = BookingRoomUtils.getCollisions(reservationDao, repCount, repType, nextS, nextE); map.put("collisionsInNext", coll); map.put("collisionsInNextCount", coll.size()); if (coll.size() > 0) collisions = true; } //reservations in currently visible time period cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); GregorianCalendar weekStart = BookingRoomUtils.getCalendar(BookingRoomUtils.getDate(cal) + " 00:00:00"); GregorianCalendar weekEnd = (GregorianCalendar) weekStart.clone(); weekEnd.add(Calendar.DAY_OF_YEAR, 7); weekEnd.add(Calendar.SECOND, -1); map.put("reservations", reservationDao.getReservationsBetween(weekStart, weekEnd, filterDate, filterGroup)); map.put("timerange", date + " " + BookingRoomUtils.getHoursAndMinutes(startStr) + " - " + BookingRoomUtils.getHoursAndMinutes(endStr)); String displayed = String.format( messageSource.getMessage("bookRoom.displayed.week", null, RequestContextUtils.getLocale(request)), BookingRoomUtils.getDate(weekStart), BookingRoomUtils.getDate(weekEnd)); boolean filtered = false; if (filterDate != null) {//filter of date filtered = true; displayed = messageSource.getMessage("bookRoom.displayed.day", null, RequestContextUtils.getLocale(request)) + " " + filterDate; } if (filterGroup > 0) { filtered = true; displayed += (filterDate == null ? "," : " and") + " " + messageSource.getMessage("bookRoom.displayed.group", null, RequestContextUtils.getLocale(request)) + " " + getResearchGroup(filterGroup).getTitle(); } if (filtered) {//we must verify that there are no reservations in selected range GregorianCalendar start = BookingRoomUtils.getCalendar(startStr); GregorianCalendar end = BookingRoomUtils.getCalendar(endStr); List<Reservation> coll = reservationDao.getReservationsBetween(start, end); if (coll.size() > 0) { //if the collision exists collisions = true; map.put("collisions", coll); map.put("collisionsCount", coll.size()); } } map.put("displayed", displayed); map.put("collisionsExist", (collisions) ? "1" : "0"); /* -- JSP can get this from params object -- map.put("repCount", repCount); map.put("repType", repType); map.put("group", group); map.put("date", date);*/ map.put("startTime", BookingRoomUtils.getHoursAndMinutes(startStr).replaceAll(":", "")); map.put("endTime", BookingRoomUtils.getHoursAndMinutes(endStr).replaceAll(":", "")); map.put("loggedUser", personDao.getLoggedPerson()); GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); return map; }
From source file:com.dell.asm.asmcore.asmmanager.db.entity.ServiceTemplateEntity.java
public void setLastDeployedDate(GregorianCalendar lastDeployedDate) { this.lastDeployedDate = (lastDeployedDate == null) ? null : (GregorianCalendar) lastDeployedDate.clone(); }
From source file:msec.org.Tools.java
public static String generateDaysChart(String filename, ArrayList<OneDayValue> data, OneAttrDaysChart chart, String title, int duration) { if (data.size() == 0) { return "data size invalid"; }//from www. j a v a 2 s .c o m int date = Integer.parseInt(data.get(0).getDate()); GregorianCalendar startgc = new GregorianCalendar(date / 10000, date % 10000 / 100 - 1, date % 100); XYDataset xydataset = createDaysDataset(data, startgc, chart); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true); try { XYPlot xyplot = (XYPlot) jfreechart.getPlot(); // DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("MM/dd")); dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); // dateaxis.setLabelPaint(ChartColor.gray); dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); dateaxis.setTickLabelPaint(ChartColor.GRAY); dateaxis.setMinimumDate(startgc.getTime()); GregorianCalendar endgc = (GregorianCalendar) startgc.clone(); endgc.add(GregorianCalendar.DATE, duration); dateaxis.setMaximumDate(endgc.getTime()); dateaxis.setTickMarksVisible(true); dateaxis.setTickMarkInsideLength(5); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1)); dateaxis.setVerticalTickLabels(true); dateaxis.setLabel(""); // ValueAxis rangeAxis = xyplot.getRangeAxis();//? rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setLabelPaint(ChartColor.gray); rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setTickLabelPaint(ChartColor.gray); rangeAxis.setLowerBound(0); // jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12)); jfreechart.getLegend().setItemPaint(ChartColor.gray); jfreechart.getLegend().setBorder(0, 0, 0, 0);// // jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));// jfreechart.getTitle().setPaint(ChartColor.gray); //? xyplot.setRangeGridlinePaint(ChartColor.GRAY); xyplot.setBackgroundPaint(ChartColor.WHITE); xyplot.setOutlinePaint(null);// int w = 500; int h = 300; // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h); ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h); return "success"; } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } }
From source file:op.tools.SYSCalendar.java
public static GregorianCalendar setDate2Time(GregorianCalendar source, GregorianCalendar target) { target.set(GregorianCalendar.DATE, source.get(GregorianCalendar.DATE)); target.set(GregorianCalendar.MONTH, source.get(GregorianCalendar.MONTH)); target.set(GregorianCalendar.YEAR, source.get(GregorianCalendar.YEAR)); return (GregorianCalendar) target.clone(); }
From source file:cz.zcu.kiv.eegdatabase.logic.pdf.ReservationPDF.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { try {//from www. ja va 2 s . co m if (request.getParameter("type").compareTo("single") == 0) { int id = Integer.parseInt(request.getParameter("reservationId")); Reservation reservation = reservationDao.getReservationById(id); response.setHeader("Content-Type", "application/pdf"); response.setHeader("Content-Disposition", "attachment;filename=reservation-" + id + ".pdf"); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); document.open(); PDFUtils utils = new PDFUtils(getServletContext().getRealPath("/")); document.add(utils.setHeader(document, "Reservation listing")); /*Paragraph paragraph = new Paragraph("Reservation #" + id, FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, BaseColor.BLACK)); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingBefore(10); paragraph.setSpacingAfter(10); document.add(paragraph);*/ document.add(formatReservation(reservation)); document.close(); response.flushBuffer(); return null; } if (request.getParameter("type").compareTo("range") == 0) { String date = request.getParameter("date") + " 00:00:00"; GregorianCalendar rangeStart = BookingRoomUtils.getCalendar(date); int length = Integer.parseInt(request.getParameter("length")); GregorianCalendar rangeEnd = (GregorianCalendar) rangeStart.clone(); rangeEnd.add(Calendar.DAY_OF_YEAR, length); response.setHeader("Content-Type", "application/pdf"); response.setHeader("Content-Disposition", "attachment;filename=reservations.pdf"); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); document.open(); PDFUtils utils = new PDFUtils(getServletContext().getRealPath("/")); document.add(utils.setHeader(document, "Reservations listing")); java.util.List<Reservation> reservations = reservationDao.getReservationsBetween(rangeStart, rangeEnd, "", 0); int count = 0; for (Reservation reservation : reservations) { document.add(formatReservation(reservation)); if (++count % 6 == 0) { document.newPage(); document.add(utils.setHeader(document, "Reservations listing")); } } document.close(); response.flushBuffer(); return null; } return null; } catch (Exception e) { ModelAndView mav = new ModelAndView(getFormView()); Map data = new HashMap<String, Object>(); data.put("error", e.getMessage()); mav.addAllObjects(data); return mav; } }
From source file:org.opencms.notification.CmsNotificationCandidates.java
/** * Collects all resources that will expire in short time, or will become valid, or are not modified since a long time.<p> * /*from ww w .j av a 2s .com*/ * @param cms the CmsObject * * @throws CmsException if something goes wrong */ public CmsNotificationCandidates(CmsObject cms) throws CmsException { m_resources = new ArrayList(); m_cms = cms; m_cms.getRequestContext() .setCurrentProject(m_cms.readProject(OpenCms.getSystemInfo().getNotificationProject())); String folder = "/"; GregorianCalendar now = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); now.setTimeInMillis(System.currentTimeMillis()); GregorianCalendar inOneWeek = (GregorianCalendar) now.clone(); inOneWeek.add(Calendar.WEEK_OF_YEAR, 1); Iterator resources; CmsResource resource; // read all files with the 'notification-interval' property set try { resources = m_cms .readResourcesWithProperty(folder, CmsPropertyDefinition.PROPERTY_NOTIFICATION_INTERVAL) .iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); int notification_interval = Integer.parseInt(m_cms .readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_NOTIFICATION_INTERVAL, true) .getValue()); GregorianCalendar intervalBefore = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); intervalBefore.setTimeInMillis(resource.getDateLastModified()); intervalBefore.add(Calendar.DAY_OF_YEAR, notification_interval); GregorianCalendar intervalAfter = (GregorianCalendar) intervalBefore.clone(); intervalAfter.add(Calendar.WEEK_OF_YEAR, -1); for (int i = 0; (i < 100) && intervalAfter.getTime().before(now.getTime()); i++) { if (intervalBefore.getTime().after(now.getTime())) { m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_UPDATE_REQUIRED, intervalBefore.getTime())); } intervalBefore.add(Calendar.DAY_OF_YEAR, notification_interval); intervalAfter.add(Calendar.DAY_OF_YEAR, notification_interval); } } } catch (CmsDbEntryNotFoundException e) { // no resources with property 'notification-interval', ignore } // read all files that were not modified longer than the max notification-time GregorianCalendar oneYearAgo = (GregorianCalendar) now.clone(); oneYearAgo.add(Calendar.DAY_OF_YEAR, -OpenCms.getSystemInfo().getNotificationTime()); // create a resource filter to get the resources with CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION .addRequireLastModifiedBefore(oneYearAgo.getTimeInMillis()); resources = m_cms.readResources(folder, filter).iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_OUTDATED, new Date(resource.getDateLastModified()))); } // get all resources that will expire within the next week CmsResourceFilter resourceFilter = CmsResourceFilter.IGNORE_EXPIRATION .addRequireExpireBefore(inOneWeek.getTimeInMillis()); resourceFilter = resourceFilter.addRequireExpireAfter(now.getTimeInMillis()); resources = m_cms.readResources(folder, resourceFilter).iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_EXPIRES, new Date(resource.getDateExpired()))); } // get all resources that will release within the next week resourceFilter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireReleaseBefore(inOneWeek.getTimeInMillis()); resourceFilter = resourceFilter.addRequireReleaseAfter(now.getTimeInMillis()); resources = m_cms.readResources(folder, resourceFilter).iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_RELEASE, new Date(resource.getDateReleased()))); } }
From source file:op.tools.SYSCalendar.java
/** * Setzt die Zeitkomponente eines GregorianCalendars. Das heisst ganz einfach, * wenn man ein Datum hat (in einem GC) und in einem anderen GC steht die Uhrzeit, dann * fgt diese Methode die beiden Komponenten zu einem Datum und Uhrzeit Wert zusammen * und gibt diesen zurck./*from ww w. jav a2s.co m*/ * * @param date - Datumsanteil * @param time - Uhrzeitanzeil * @return Datum und Uhrzeit kombiniert. */ public static GregorianCalendar addTime2Date(GregorianCalendar date, GregorianCalendar time) { date.set(GregorianCalendar.HOUR_OF_DAY, time.get(GregorianCalendar.HOUR_OF_DAY)); date.set(GregorianCalendar.MINUTE, time.get(GregorianCalendar.MINUTE)); date.set(GregorianCalendar.SECOND, time.get(GregorianCalendar.SECOND)); date.set(GregorianCalendar.MILLISECOND, time.get(GregorianCalendar.MILLISECOND)); return (GregorianCalendar) date.clone(); }
From source file:com.dell.asm.asmcore.asmmanager.client.deviceinventory.ManagedDevice.java
public void setInventoryDate(GregorianCalendar inventoryDate) { if (inventoryDate != null) { this.inventoryDate = (GregorianCalendar) inventoryDate.clone(); } else {//from w w w . ja va2 s.c om this.inventoryDate = null; } }
From source file:com.dell.asm.asmcore.asmmanager.client.deviceinventory.ManagedDevice.java
public void setDiscoveredDate(GregorianCalendar discoveredDate) { if (discoveredDate != null) { this.discoveredDate = (GregorianCalendar) discoveredDate.clone(); } else {//from ww w . j a v a 2s . com this.discoveredDate = null; } }
From source file:com.dell.asm.asmcore.asmmanager.client.deviceinventory.ManagedDevice.java
public void setInfraTemplateDate(GregorianCalendar infraTemplateDate) { if (infraTemplateDate != null) { this.infraTemplateDate = (GregorianCalendar) infraTemplateDate.clone(); } else {// www . j av a 2 s.co m this.infraTemplateDate = null; } }