List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:com.idega.block.cal.renderer.AbstractCompactScheduleRenderer.java
/** * In the compact renderer, we don't take the y coordinate of the mouse * into account when determining the last clicked date. *//*ww w.j av a 2s .c o m*/ @Override protected Date determineLastClickedDate(HtmlSchedule schedule, String dateId, String yPos) { Calendar cal = Calendar.getInstance(); //the dateId is the schedule client id + "_" + yyyyMMdd String day = dateId.substring(dateId.lastIndexOf("_") + 1); Date date = ScheduleUtil.getDateFromId(day, TimeZone.getDefault()); if (date != null) cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, schedule.getVisibleStartHour()); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); log.debug("last clicked datetime: " + cal.getTime()); return cal.getTime(); }
From source file:com.jdom.get.stuff.done.android.AndroidSyncStrategy.java
private Task createLocalTask(com.google.api.services.tasks.model.Task googleTask, String listName) { Boolean deleted = Boolean.TRUE.equals(googleTask.getDeleted()); Task localVersion = new com.jdom.get.stuff.done.domain.Task(googleTask.getTitle(), googleTask.getNotes()); localVersion.setDeleted(deleted);/*from w w w.ja va 2 s. com*/ localVersion.setListName(listName); localVersion.setCompleted(Constants.GOOGLE_COMPLETED_STRING.equals(googleTask.getStatus())); localVersion.setDescription(googleTask.getNotes()); DateTime due = googleTask.getDue(); if (due != null) { long utcTime = due.getValue(); utcTime -= TimeZone.getDefault().getOffset(utcTime); localVersion.setDueDate(new Date(utcTime)); } localVersion.setRemoteIdentifier(googleTask.getId()); return localVersion; }
From source file:fr.dutra.confluence2wordpress.wp.WordpressClient.java
/** * Date values are sent with no time zone information; * Wordpress assumes they are in UTC.//from w w w . jav a 2 s . c o m * Hence the need to convert to a fake date bearing the correct information, * but in a wrong time zone. * @param date * @return */ private Date convertToNaiveUTC(Date date) { TimeZone zone = TimeZone.getDefault(); long time = date.getTime(); return new Date(time - zone.getOffset(time)); }
From source file:org.openmeetings.app.data.calendar.management.AppointmentLogic.java
/** * Sending Reminder in Simple mail format 5 minutes before Meeting begins *//* w ww.j a v a 2 s.c o m*/ // ---------------------------------------------------------------------------------------------- public void doScheduledMeetingReminder() throws Exception { // log.debug("doScheduledMeetingReminder"); Integer minutesReminderSend = cfgManagement.getConfValue("number.minutes.reminder.send", Integer.class, "" + DEFAULT_MINUTES_REMINDER_SEND); if (minutesReminderSend == null) { throw new Exception("minutesReminderSend is null!"); } if (minutesReminderSend == 0) { log.warn("minutesReminderSend is 0, disabling reminder scheduler"); return; } long millisecondsToCheck = (minutesReminderSend * 60 * 1000); List<Appointment> points = appointmentDao .getAppointmentsForAllUsersByTimeRangeStartingNow(millisecondsToCheck, false); if (points == null || points.size() < 1) { log.debug("doScheduledMeetingReminder : no Appointments in range"); return; } Long language_id = Long.valueOf(cfgManagement.getConfKey(3, "default_lang_id").getConf_value()).longValue(); // Get the required labels one time for all meeting members. The // Language of the email will be the system default language String labelid1158 = fieldmanagment.getString(1158L, language_id); Fieldlanguagesvalues labelid1153 = fieldmanagment.getFieldByIdAndLanguage(new Long(1153), language_id); Fieldlanguagesvalues labelid1154 = fieldmanagment.getFieldByIdAndLanguage(new Long(1154), language_id); for (int i = 0; i < points.size(); i++) { Appointment ment = points.get(i); // Prevent email from being send twice, even if the cycle takes // very long to send each if (ment.getIsReminderEmailSend() != null && ment.getIsReminderEmailSend()) { continue; } // Checking ReminderType - only ReminderType simple mail is // concerned! if (ment.getRemind().getTypId() == 2 || ment.getRemind().getTypId() == 3) { // Update Appointment to not send invitation twice ment.setIsReminderEmailSend(true); appointmentDao.updateAppointment(ment); List<MeetingMember> members = meetingMemberDao .getMeetingMemberByAppointmentId(ment.getAppointmentId()); if (members == null) { log.debug("doScheduledMeetingReminder : no members in meeting!"); continue; } // Iterate through all MeetingMembers for (MeetingMember mm : members) { log.debug("doScheduledMeetingReminder : Member " + mm.getEmail()); Invitations inv = mm.getInvitation(); if (inv == null) { log.error("Error retrieving Invitation for member " + mm.getEmail() + " in Appointment " + ment.getAppointmentName()); continue; } if (inv.getBaseUrl() == null || inv.getBaseUrl().length() < 1) { log.error("Error retrieving baseUrl from Invitation ID : " + inv.getInvitations_id()); continue; } TimeZone tZone = null; if (mm.getOmTimeZone() != null) { tZone = timezoneUtil.getTimezoneByOmTimeZoneId(mm.getOmTimeZone().getOmtimezoneId()); } else { tZone = TimeZone.getDefault(); } String subject = generateSubject(labelid1158, ment, tZone); String message = generateMessage(labelid1158, ment, language_id, labelid1153, labelid1154, tZone); invitationManagement.sendInvitationReminderLink(message, inv.getBaseUrl(), mm.getEmail(), subject, inv.getHash()); inv.setUpdatetime(new Date()); invitationManagement.updateInvitation(inv); } } } }
From source file:com.duroty.application.files.manager.SearchManager.java
public SearchObj advanced(Session hsession, String repositoryName, AdvancedObj advancedObj, int page, int messagesByPage, int order, String orderType) throws FilesException { String lucenePathMessages = null; if (!defaultLucenePath.endsWith(File.separator)) { lucenePathMessages = defaultLucenePath + File.separator + repositoryName + File.separator + Constants.MAIL_LUCENE_MESSAGES; } else {/*from w ww .j a v a 2 s .c om*/ lucenePathMessages = defaultLucenePath + repositoryName + File.separator + Constants.MAIL_LUCENE_MESSAGES; } Searcher searcher = null; SearchObj searchObj = new SearchObj(); Sort sort = null; try { Users user = getUser(hsession, repositoryName); Locale locale = new Locale(user.getUseLanguage()); TimeZone timeZone = TimeZone.getDefault(); Date now = new Date(); Calendar calendar = Calendar.getInstance(timeZone, locale); calendar.setTime(now); SimpleDateFormat formatter1 = new SimpleDateFormat("MMM dd", locale); SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", locale); SimpleDateFormat formatter3 = new SimpleDateFormat("MM/yy", locale); searcher = MailIndexer.getSearcher(lucenePathMessages); if (!StringUtils.isBlank(advancedObj.getSubject())) { advancedObj.setSubject("Files-System"); } Query query = AdvancedQueryParser.parseMessages(advancedObj, analyzer); ; /*BooleanQuery booleanQuery = new BooleanQuery(); QueryParser parser = new QueryParser(Field_attachments, analyzer); parser.setDefaultOperator(Operator.AND); Query aux1 = parser.parse("\"Message Text\""); booleanQuery.add(aux1, BooleanClause.Occur.MUST_NOT); Query aux2 = AdvancedQueryParser.parseMessages(advancedObj, analyzer); booleanQuery.add(aux2, BooleanClause.Occur.MUST); query = booleanQuery;*/ Hits hits = null; Date searchStart = new Date(); boolean reverse = true; if (orderType.equals("ASC")) { reverse = false; } else { reverse = true; } switch (order) { case ORDER_BY_SIZE: sort = new Sort(new SortField[] { new SortField(Field_size, SortField.STRING, reverse), SortField.FIELD_SCORE }); break; case ORDER_BY_DATE: sort = new Sort(new SortField[] { new SortField(Field_lastDate, SortField.STRING, reverse), SortField.FIELD_SCORE }); break; default: sort = new Sort(new SortField[] { new SortField(null, SortField.SCORE, !reverse) }); break; } int label = 0; if (advancedObj.getLabel() != null) { label = advancedObj.getLabel().getIdint(); } ChainedFilter chained = null; if (label > 0) { chained = getChainedFilter(hsession, repositoryName, label); } if (chained != null) { hits = searcher.search(query, chained, sort); } else { hits = searcher.search(query, sort); } Date searchEnd = new Date(); //time in seconds double time = ((double) (searchEnd.getTime() - searchStart.getTime())) / (double) 1000; int hitsLength = hits.length(); if (hitsLength <= 0) { return null; } int start = page * messagesByPage; int end = start + messagesByPage; if (end > 0) { end = Math.min(hitsLength, end); } else { end = hitsLength; } if (start > end) { throw new SearchException("Search index of bound. start > end"); } Vector files = new Vector(); for (int j = start; j < end; j++) { Document doc = hits.doc(j); if (doc != null) { LuceneMessage lmsg = new LuceneMessage(doc); Message message = getMessage(hsession, repositoryName, lmsg.getIdint()); if (message != null) { Set set = message.getAttachments(); if (set != null) { Iterator it = set.iterator(); while (it.hasNext()) { Attachment attachment = (Attachment) it.next(); String name = attachment.getAttName(); if (!StringUtils.isBlank(name) && !name.equals("Message Text")) { AttachmentObj obj = new AttachmentObj(); obj.setContentType(attachment.getAttContentType()); obj.setScore((int) (hits.score(j) * 100)); Date date = message.getMesDate(); if (date != null) { Calendar calendar2 = Calendar.getInstance(timeZone, locale); calendar2.setTime(date); if ((calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) && (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)) && (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE))) { obj.setDateStr(formatter2.format(calendar2.getTime())); } else if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) { obj.setDateStr(formatter1.format(calendar2.getTime())); } else { obj.setDateStr(formatter3.format(calendar2.getTime())); } } obj.setDate(date); obj.setDate(date); obj.setIdint(attachment.getAttIdint()); obj.setName(attachment.getAttName()); obj.setPart(attachment.getAttPart()); int size = attachment.getAttSize(); size /= 1024; if (size > 1024) { size /= 1024; obj.setSize(size + " MB"); } else { obj.setSize(((size > 0) ? (size + "") : "<1") + " kB"); } String extension = (String) this.extensions.get(attachment.getAttContentType()); if (StringUtils.isBlank(extension)) { extension = "generic"; } obj.setExtension(extension); if (message.isMesFlagged()) { obj.setFlagged(true); } else { obj.setFlagged(false); } if (message.getLabMeses() != null) { Iterator it2 = message.getLabMeses().iterator(); StringBuffer lab = new StringBuffer(); while (it2.hasNext()) { if (lab.length() > 0) { lab.append(", "); } LabMes labMes = (LabMes) it2.next(); lab.append(labMes.getId().getLabel().getLabName()); } if (lab.length() > 0) { obj.setLabel(lab.toString()); } else { } } obj.setBox(message.getMesBox()); obj.setMid(message.getMesName()); files.addElement(obj); } } } } } } searchObj.setHits(hitsLength); searchObj.setTime(time); searchObj.setFiles(files); } catch (Exception ex) { throw new FilesException(ex); } finally { GeneralOperations.closeHibernateSession(hsession); } return searchObj; }
From source file:net.sourceforge.dvb.projectx.common.Common.java
/** * */// w w w . jav a2s . c o m public static String formatTime_5(long time_value) { time_format_5.setTimeZone(TimeZone.getDefault()); return time_format_5.format(new Date(time_value)); }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createStackedTimeSeriesChart( final TimeTableXYDatasetChartDefinition chartDefinition) { JFreeChart chart = null;/* w ww . ja v a2 s . c om*/ // TODO Make the following accessible from the chartDefinition String domainAxisLabel = null; String rangeAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); DateAxis domainAxis = new DateAxis(domainAxisLabel, TimeZone.getDefault()); ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel); XYItemRenderer renderer = null; switch (chartDefinition.getChartType()) { case AREA_CHART_TYPE: renderer = chartDefinition.isStacked() ? new StackedXYAreaRenderer2() : new XYAreaRenderer(); break; default: // should log an error if invalid chart type passed in - at least return null for no renderer return null; } if (tooltips) { XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new SimpleDateFormat(chartDefinition.getTooltipXFormat()), new DecimalFormat(chartDefinition.getTooltipYFormat())); renderer.setToolTipGenerator(generator); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth())); XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer); JFreeChartEngine.updatePlot(plot, chartDefinition); chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:com.snowplowanalytics.snowplow.collectors.clojure.SnowplowAccessLogValve.java
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */// ww w. j a v a 2 s . c om @Override protected synchronized void startInternal() throws LifecycleException { // Initialize the Date formatters String format = getFileDateFormat(); fileDateFormatter = new SimpleDateFormat(format, Locale.US); fileDateFormatter.setTimeZone(TimeZone.getDefault()); dateStamp = fileDateFormatter.format(new Date(System.currentTimeMillis())); if (rotatable && renameOnRotate) { restore(); } open(); super.startInternal(); }
From source file:com.ecyrd.jspwiki.WikiEngine.java
/** * Does all the real initialization./*w ww .j ava 2 s .co m*/ */ private void initialize(Properties props) throws WikiException { m_startTime = new Date(); m_properties = props; // // Initialized log4j. However, make sure that // we don't initialize it multiple times. Also, if // all of the log4j statements have been removed from // the property file, we do not do any property setting // either.q // if (!c_configured) { if (props.getProperty("log4j.rootCategory") != null) { PropertyConfigurator.configure(props); } c_configured = true; } log.info("*******************************************"); log.info(Release.APPNAME + " " + Release.getVersionString() + " starting. Whee!"); fireEvent(WikiEngineEvent.INITIALIZING); // begin initialization log.debug("Java version: " + System.getProperty("java.runtime.version")); log.debug("Java vendor: " + System.getProperty("java.vm.vendor")); log.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch")); log.debug("Default server locale: " + Locale.getDefault()); log.debug("Default server timezone: " + TimeZone.getDefault().getDisplayName(true, TimeZone.LONG)); if (m_servletContext != null) { log.info("Servlet container: " + m_servletContext.getServerInfo()); if (m_servletContext.getMajorVersion() < 2 || (m_servletContext.getMajorVersion() == 2 && m_servletContext.getMinorVersion() < 4)) { throw new InternalWikiException( "I require a container which supports at least version 2.4 of Servlet specification"); } } log.debug("Configuring WikiEngine..."); // Initializes the CommandResolver m_commandResolver = new CommandResolver(this, props); // // Create and find the default working directory. // m_workDir = TextUtil.getStringProperty(props, PROP_WORKDIR, null); if (m_workDir == null) { m_workDir = System.getProperty("java.io.tmpdir", "."); m_workDir += File.separator + Release.APPNAME + "-" + m_appid; } try { File f = new File(m_workDir); f.mkdirs(); // // A bunch of sanity checks // if (!f.exists()) throw new WikiException("Work directory does not exist: " + m_workDir); if (!f.canRead()) throw new WikiException("No permission to read work directory: " + m_workDir); if (!f.canWrite()) throw new WikiException("No permission to write to work directory: " + m_workDir); if (!f.isDirectory()) throw new WikiException("jspwiki.workDir does not point to a directory: " + m_workDir); } catch (SecurityException e) { log.fatal("Unable to find or create the working directory: " + m_workDir, e); throw new IllegalArgumentException("Unable to find or create the working dir: " + m_workDir); } log.info("JSPWiki working directory is '" + m_workDir + "'"); m_saveUserInfo = TextUtil.getBooleanProperty(props, PROP_STOREUSERNAME, m_saveUserInfo); m_useUTF8 = "UTF-8".equals(TextUtil.getStringProperty(props, PROP_ENCODING, "ISO-8859-1")); m_baseURL = TextUtil.getStringProperty(props, PROP_BASEURL, ""); if (!m_baseURL.endsWith("/")) { m_baseURL = m_baseURL + "/"; } m_beautifyTitle = TextUtil.getBooleanProperty(props, PROP_BEAUTIFYTITLE, m_beautifyTitle); m_templateDir = TextUtil.getStringProperty(props, PROP_TEMPLATEDIR, "default"); m_frontPage = TextUtil.getStringProperty(props, PROP_FRONTPAGE, "Main"); // Initialize the page name comparator now as it may be used while // initializing other modules initPageSorter(props); // // Initialize the important modules. Any exception thrown by the // managers means that we will not start up. // // FIXME: This part of the code is getting unwieldy. We must think // of a better way to do the startup-sequence. try { Class urlclass = ClassUtil.findClass("com.ecyrd.jspwiki.url", TextUtil.getStringProperty(props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor")); m_urlConstructor = (URLConstructor) urlclass.newInstance(); m_urlConstructor.initialize(this, props); m_pageManager = (PageManager) ClassUtil.getMappedObject(PageManager.class.getName(), this, props); m_pluginManager = (PluginManager) ClassUtil.getMappedObject(PluginManager.class.getName(), this, props); m_differenceManager = (DifferenceManager) ClassUtil.getMappedObject(DifferenceManager.class.getName(), this, props); m_attachmentManager = (AttachmentManager) ClassUtil.getMappedObject(AttachmentManager.class.getName(), this, props); m_variableManager = (VariableManager) ClassUtil.getMappedObject(VariableManager.class.getName(), props); // m_filterManager = (FilterManager)ClassUtil.getMappedObject(FilterManager.class.getName(), this, props ); m_renderingManager = (RenderingManager) ClassUtil.getMappedObject(RenderingManager.class.getName()); m_searchManager = (SearchManager) ClassUtil.getMappedObject(SearchManager.class.getName(), this, props); m_authenticationManager = (AuthenticationManager) ClassUtil .getMappedObject(AuthenticationManager.class.getName()); m_authorizationManager = (AuthorizationManager) ClassUtil .getMappedObject(AuthorizationManager.class.getName()); m_userManager = (UserManager) ClassUtil.getMappedObject(UserManager.class.getName()); m_groupManager = (GroupManager) ClassUtil.getMappedObject(GroupManager.class.getName()); m_editorManager = (EditorManager) ClassUtil.getMappedObject(EditorManager.class.getName(), this); m_editorManager.initialize(props); m_progressManager = new ProgressManager(); // Initialize the authentication, authorization, user and acl managers m_authenticationManager.initialize(this, props); m_authorizationManager.initialize(this, props); m_userManager.initialize(this, props); m_groupManager.initialize(this, props); m_aclManager = getAclManager(); // Start the Workflow manager m_workflowMgr = (WorkflowManager) ClassUtil.getMappedObject(WorkflowManager.class.getName()); m_workflowMgr.initialize(this, props); m_internationalizationManager = (InternationalizationManager) ClassUtil .getMappedObject(InternationalizationManager.class.getName(), this); m_templateManager = (TemplateManager) ClassUtil.getMappedObject(TemplateManager.class.getName(), this, props); m_adminBeanManager = (AdminBeanManager) ClassUtil.getMappedObject(AdminBeanManager.class.getName(), this); // Since we want to use a page filters initilize() method // as a engine startup listener where we can initialize global event listeners, // it must be called lastly, so that all object references in the engine // are availabe to the initialize() method m_filterManager = (FilterManager) ClassUtil.getMappedObject(FilterManager.class.getName(), this, props); // RenderingManager depends on FilterManager events. m_renderingManager.initialize(this, props); // // ReferenceManager has the side effect of loading all // pages. Therefore after this point, all page attributes // are available. // // initReferenceManager is indirectly using m_filterManager, therefore // it has to be called after it was initialized. // initReferenceManager(); // // Hook the different manager routines into the system. // getFilterManager().addPageFilter(m_referenceManager, -1001); getFilterManager().addPageFilter(m_searchManager, -1002); } catch (RuntimeException e) { // RuntimeExceptions may occur here, even if they shouldn't. log.fatal("Failed to start managers.", e); e.printStackTrace(); throw new WikiException("Failed to start managers: " + e.getMessage(), e); } catch (ClassNotFoundException e) { log.fatal("JSPWiki could not start, URLConstructor was not found: ", e); e.printStackTrace(); throw new WikiException(e.getMessage(), e); } catch (InstantiationException e) { log.fatal("JSPWiki could not start, URLConstructor could not be instantiated: ", e); e.printStackTrace(); throw new WikiException(e.getMessage(), e); } catch (IllegalAccessException e) { log.fatal("JSPWiki could not start, URLConstructor cannot be accessed: ", e); e.printStackTrace(); throw new WikiException(e.getMessage(), e); } catch (Exception e) { // Final catch-all for everything log.fatal("JSPWiki could not start, due to an unknown exception when starting.", e); e.printStackTrace(); throw new WikiException("Failed to start; please check log files for better information.", e); } // // Initialize the good-to-have-but-not-fatal modules. // try { if (TextUtil.getBooleanProperty(props, RSSGenerator.PROP_GENERATE_RSS, false)) { m_rssGenerator = (RSSGenerator) ClassUtil.getMappedObject(RSSGenerator.class.getName(), this, props); } m_pageRenamer = (PageRenamer) ClassUtil.getMappedObject(PageRenamer.class.getName(), this, props); } catch (Exception e) { log.error( "Unable to start RSS generator - JSPWiki will still work, " + "but there will be no RSS feed.", e); } // Start the RSS generator & generator thread if (m_rssGenerator != null) { m_rssFile = TextUtil.getStringProperty(props, RSSGenerator.PROP_RSSFILE, "rss.rdf"); File rssFile = null; if (m_rssFile.startsWith(File.separator)) { // honor absolute pathnames: rssFile = new File(m_rssFile); } else { // relative path names are anchored from the webapp root path: rssFile = new File(getRootPath(), m_rssFile); } int rssInterval = TextUtil.getIntegerProperty(props, RSSGenerator.PROP_INTERVAL, 3600); RSSThread rssThread = new RSSThread(this, rssFile, rssInterval); rssThread.start(); } fireEvent(WikiEngineEvent.INITIALIZED); // initialization complete log.info("WikiEngine configured."); m_isConfigured = true; }
From source file:com.blackducksoftware.tools.ccimporter.config.CCIConfigurationManager.java
/** * Make sure timezone is set to a valid timezone ID string *///from w w w. ja va 2 s. co m private void ensureTimeZoneIsSet() { // TODO: Temporary workaround to provide timezones. This // handles the case whereby // utility is run against a server that is not in the same // time zone. TimeZone tz; String userSpecifiedTimeZone = timeZone; if (userSpecifiedTimeZone != null && !userSpecifiedTimeZone.isEmpty()) { tz = TimeZone.getTimeZone(userSpecifiedTimeZone); log.info("User specified time zone recognized, using: " + tz.getDisplayName()); } else { tz = TimeZone.getDefault(); } setTimeZone(tz.getID()); }