List of usage examples for java.util TimeZone setDefault
public static void setDefault(TimeZone zone)
From source file:org.jfree.data.time.WeekTest.java
/** * Some checks for the getLastMillisecond() method. *///from www . ja v a 2s . c o m @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Week w = new Week(31, 1970); assertEquals(18485999999L, w.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.archive.crawler.Heritrix.java
public void instanceMain(String[] args) throws Exception { System.out.println(System.getProperty("java.vendor") + ' ' + System.getProperty("java.runtime.name") + ' ' + System.getProperty("java.runtime.version")); // ensure using java 1.6+ before hitting a later cryptic error String version = System.getProperty("java.version"); float floatVersion = Float.valueOf(version.substring(0, version.indexOf('.', 2))); if (floatVersion < 1.6) { System.err.println("Heritrix (as of version 3) requires Java 1.6 or higher."); System.err.println("You attempted to launch with: " + version); System.err.println("Please try again with a later Java."); System.exit(1);/*w ww . j av a 2 s . com*/ } // Set some system properties early. // Can't use class names here without loading them. String ignoredSchemes = "org.archive.net.UURIFactory.ignored-schemes"; if (System.getProperty(ignoredSchemes) == null) { System.setProperty(ignoredSchemes, "mailto, clsid, res, file, rtsp, about"); } String maxFormSize = "org.mortbay.jetty.Request.maxFormContentSize"; if (System.getProperty(maxFormSize) == null) { System.setProperty(maxFormSize, "52428800"); } BufferedOutputStream startupOutStream = new BufferedOutputStream( new FileOutputStream(new File(getHeritrixHome(), STARTLOG)), 16384); PrintStream startupOut = new PrintStream(new TeeOutputStream(System.out, startupOutStream)); CommandLine cl = getCommandLine(startupOut, args); if (cl == null) return; if (cl.hasOption('h')) { usage(startupOut, args); return; } // DEFAULTS until changed by cmd-line options int port = 8443; Set<String> bindHosts = new HashSet<String>(); String authLogin = "admin"; String authPassword = null; String keystorePath; String keystorePassword; String keyPassword; File properties = getDefaultPropertiesFile(); String aOption = cl.getOptionValue('a'); if (cl.hasOption('a')) { String usernameColonPassword = aOption; try { if (aOption.startsWith("@")) { usernameColonPassword = FileUtils.readFileToString(new File(aOption.substring(1))).trim(); } int colonIndex = usernameColonPassword.indexOf(':'); if (colonIndex > -1) { authLogin = usernameColonPassword.substring(0, colonIndex); authPassword = usernameColonPassword.substring(colonIndex + 1); } else { authPassword = usernameColonPassword; } } catch (IOException e) { // only if @filename read had problems System.err.println("Unable to read [username:]password from " + aOption); } } if (authPassword == null) { System.err.println("You must specify a valid [username:]password for the web interface using -a."); System.exit(1); authPassword = ""; // suppresses uninitialized warning } File jobsDir = null; if (cl.hasOption('j')) { jobsDir = new File(cl.getOptionValue('j')); } else { jobsDir = new File("./jobs"); } if (cl.hasOption('l')) { properties = new File(cl.getOptionValue('l')); } if (cl.hasOption('b')) { String hosts = cl.getOptionValue('b'); List<String> list; if ("/".equals(hosts)) { // '/' means all, signified by empty-list list = new ArrayList<String>(); } else { list = Arrays.asList(hosts.split(",")); } bindHosts.addAll(list); } else { // default: only localhost bindHosts.add("localhost"); } if (cl.hasOption('p')) { port = Integer.parseInt(cl.getOptionValue('p')); } // SSL options (possibly none, in which case adhoc keystore // is created or reused if (cl.hasOption('s')) { String[] sslParams = cl.getOptionValue('s').split(","); keystorePath = sslParams[0]; keystorePassword = sslParams[1]; keyPassword = sslParams[2]; } else { // use ad hoc keystore, creating if necessary keystorePath = ADHOC_KEYSTORE; keystorePassword = ADHOC_PASSWORD; keyPassword = ADHOC_PASSWORD; useAdhocKeystore(startupOut); } if (properties.exists()) { FileInputStream finp = new FileInputStream(properties); LogManager.getLogManager().readConfiguration(finp); finp.close(); } // Set timezone here. Would be problematic doing it if we're running // inside in a container. TimeZone.setDefault(TimeZone.getTimeZone("GMT")); setupGlobalProperties(port); // Start Heritrix. try { engine = new Engine(jobsDir); component = new Component(); if (bindHosts.isEmpty()) { // listen all addresses setupServer(port, null, keystorePath, keystorePassword, keyPassword); } else { // bind only to declared addresses, or just 'localhost' for (String address : bindHosts) { setupServer(port, address, keystorePath, keystorePassword, keyPassword); } } component.getClients().add(Protocol.FILE); component.getClients().add(Protocol.CLAP); Guard guard = new RateLimitGuard(null, ChallengeScheme.HTTP_DIGEST, "Authentication Required"); guard.getSecrets().put(authLogin, authPassword.toCharArray()); component.getDefaultHost().attach(guard); guard.setNext(new EngineApplication(engine)); component.start(); startupOut.println("engine listening at port " + port); startupOut.println( "operator login set per " + ((aOption.startsWith("@")) ? "file " + aOption : "command-line")); if (authPassword.length() < 8 || authPassword.matches("[a-zA-Z]{0,10}") || authPassword.matches("\\d{0,10}")) { startupOut.println("NOTE: We recommend a longer, stronger password, especially if your web \n" + "interface will be internet-accessible."); } if (cl.hasOption('r')) { engine.requestLaunch(cl.getOptionValue('r')); } } catch (Exception e) { // Show any exceptions in STARTLOG. e.printStackTrace(startupOut); if (component != null) { component.stop(); } throw e; } finally { startupOut.flush(); // stop writing to side startup file startupOutStream.close(); System.out.println("Heritrix version: " + ArchiveUtils.VERSION); } }
From source file:org.openmrs.module.atomfeed.AtomFeedUtilTest.java
/** * @see AtomFeedUtil#dateToRFC3339(Date) * @verifies convert date to rfc/*from w ww . j a v a 2 s . c o m*/ */ @Test public void dateToRFC3339_shouldConvertDateToRfc() throws Exception { TimeZone tz = TimeZone.getDefault(); System.out.println("timezone: " + tz.getDisplayName()); try { TimeZone.setDefault(TimeZone.getTimeZone("Europe/Helsinki")); String expectedOutput = "2012-05-08T22:39:54+03:00"; Date date = new Date(1336505994083l); Assert.assertEquals(expectedOutput, AtomFeedUtil.dateToRFC3339(date)); } finally { TimeZone.setDefault(tz); // reset back to what it was } }
From source file:br.com.gvt.eng.ipvod.rest.catalog.Assets.java
@PermitAll @RolesAllowed({ IpvodConstants.ROLE_ADMIN, IpvodConstants.ROLE_MARKETING, IpvodConstants.ROLE_VOC }) @POST/*from ww w . ja va 2 s. c o m*/ @Produces("application/json; charset=UTF-8") public Response updateAsset(IpvodAsset ipvodAsset, @HeaderParam(IpvodConstants.AUTHORIZATION_PROPERTY_CMS) String token) throws RestException { IpvodAuthenticationSystem auth = authenticationSystemFacade.findByToken(token); Long userId = auth.getIpvodUserSys().getUserSysId(); if (auth.getIpvodUserSys().getRole().equals("OPR") && ipvodAsset.getIpvodContentProvider() .getContentProviderId() != auth.getIpvodUserSys().getContentProvider().getContentProviderId()) { System.out.println(ipvodAsset.getIpvodContentProvider().getContentProviderId() + " != " + auth.getIpvodUserSys().getContentProvider().getContentProviderId()); RestException.FORBIDDEN.printStackTrace(); throw RestException.FORBIDDEN; } TimeZone.setDefault(TimeZone.getTimeZone("UTC")); IpvodAsset oldIpvodAsset = assetFacade.find(ipvodAsset.getAssetId()); Gson gson = new Gson(); IpvodHistory ipvodHistory = new IpvodHistory(); ipvodHistory.setChangedAt(new GregorianCalendar()); ipvodHistory.setType(HistoryTypeEnum.ASSET); IpvodUserSystem user = new IpvodUserSystem(); user.setUserSysId(userId); ipvodHistory.setUser(user); ipvodHistory.setItemId(ipvodAsset.getAssetId()); ipvodHistory.setOldValue(gson.toJson(getAssetMap(oldIpvodAsset))); IpvodAsset newIpvodAsset = assetFacade.update(ipvodAsset); for (IpvodVisualMenu m : ipvodAsset.getIpvodVisualMenus()) { if (m.getZindex() == null) { IpvodVisualMenuAsset e = new IpvodVisualMenuAsset(); e.setIpvodAsset(newIpvodAsset); e.setIpvodVisualMenu(m); e.setZindex(new Long(0)); menuAssetFacade.save(e); IpvodVisualMenu menu = menuFacade.find(m.getMenuId()); IpvodVisualMenuAsset menuAsset = new IpvodVisualMenuAsset(); menuAsset.setIpvodAsset(ipvodAsset); menu.getIpvodVisualMenuAsset().add(menuAsset); assetPackageFacade.insertAssetPackages(menu); } } ipvodHistory.setNewValue(gson.toJson(getAssetMap(newIpvodAsset))); historyFacade.save(ipvodHistory); if (schedulePublicationFacade.getScheduleByAssetId(ipvodAsset.getAssetId()) != null) { cancelTempAsset(ipvodAsset.getAssetId()); } return Response.status(200).build(); }
From source file:axiom.main.Server.java
/** * initialize the server//from w ww .j a v a 2 s . c o m */ public void init() { // set the log factory property String logFactory = sysProps.getProperty("loggerFactory", "axiom.util.Logging"); axiomLogging = "axiom.util.Logging".equals(logFactory); // remove comment below to control Jetty Logging, axiom.util.JettyLogger // is an implemention of the Jetty Log class, used for logging Jetty error messages System.setProperty("org.mortbay.log.class", "axiom.util.JettyLogger"); System.setProperty("org.apache.commons.logging.LogFactory", logFactory); // set the current working directory to the Axiom home dir. // note that this is not a real cwd, which is not supported // by java. It makes sure relative to absolute path name // conversion is done right, so for Axiom code, this should // work. System.setProperty("user.dir", axiomHome.getPath()); // from now on it's safe to call getLogger() because axiomHome is set up getLogger(); String startMessage = "Starting Axiom " + version + " on Java " + System.getProperty("java.version"); logger.info(startMessage); // also print a msg to System.out System.out.println(startMessage); logger.info("Setting Axiom Home to " + axiomHome); RequestLogHandler requestLogHandler = new RequestLogHandler(); handlers.setHandlers(new Handler[] { contexts, new AxiomHandler(), requestLogHandler }); if (this.sysProps.getProperty("enableRequestLog") == null || Boolean.parseBoolean(this.sysProps.getProperty("enableRequestLog"))) { String logDir = sysProps.getProperty("logdir", "log"); String requestLogName = sysProps.getProperty("requestLog", "axiom.server.request.log"); if (!requestLogName.endsWith(".log")) { requestLogName += ".log"; } NCSARequestLog requestLog = new NCSARequestLog(logDir + "/" + requestLogName); requestLog.setRetainDays(90); requestLog.setAppend(true); requestLog.setExtended(true); requestLog.setLogServer(true); requestLog.setLogTimeZone("GMT"); requestLogHandler.setRequestLog(requestLog); } // read db.properties file in Axiom home directory dbProps = new ResourceProperties(); dbProps.setIgnoreCase(false); dbProps.addResource(new FileResource(new File(axiomHome, "db.properties"))); DbSource.setDefaultProps(dbProps); String language = sysProps.getProperty("language"); String country = sysProps.getProperty("country"); String timezone = sysProps.getProperty("timezone"); if ((language != null) && (country != null)) { Locale.setDefault(new Locale(language, country)); } if (timezone != null) { TimeZone.setDefault(TimeZone.getTimeZone(timezone)); } dbSources = new Hashtable(); // try to load the extensions extensions = new Vector<AxiomExtension>(); initExtensions(); // start the default DB TCP Server with SSL enabled try { if (this.isDbHostServer()) { String h2port = this.sysProps.getProperty("db.port", "9092"); String dbhome = this.sysProps.getProperty("dbHome"); File dir; if (dbhome != null) { dir = new File(dbhome); } else { dir = new File(this.axiomHome, "db"); } dir = new File(dir, "TransactionsDB"); String baseDir = dir.getPath(); System.setProperty("h2.lobFilesPerDirectory", new Long(Long.MAX_VALUE).toString()); String[] args = new String[] { "-tcpPort", h2port, "-baseDir", baseDir }; this.defaultDbServer = org.h2.tools.Server.createTcpServer(args).start(); System.out.println("Starting H2 TCP Server on port " + h2port); } } catch (Exception sqle) { logger.error(ErrorReporter.errorMsg(this.getClass(), "init"), sqle); throw new RuntimeException( "FATAL ERROR::Could not start the default " + "H2 database server, " + sqle.getMessage()); } }
From source file:helma.main.Server.java
/** * initialize the server/* w w w .j av a2 s. co m*/ */ public void init() throws IOException { // set the log factory property String logFactory = sysProps.getProperty("loggerFactory", "helma.util.Logging"); helmaLogging = "helma.util.Logging".equals(logFactory); System.setProperty("org.apache.commons.logging.LogFactory", logFactory); // set the current working directory to the helma home dir. // note that this is not a real cwd, which is not supported // by java. It makes sure relative to absolute path name // conversion is done right, so for Helma code, this should work. System.setProperty("user.dir", hopHome.getPath()); // from now on it's safe to call getLogger() because hopHome is set up getLogger(); String startMessage = "Starting Helma " + version + " on Java " + System.getProperty("java.version"); logger.info(startMessage); // also print a msg to System.out System.out.println(startMessage); logger.info("Setting Helma Home to " + hopHome); // read db.properties file in helma home directory String dbPropfile = sysProps.getProperty("dbPropFile"); File file; if ((dbPropfile != null) && !"".equals(dbPropfile.trim())) { file = new File(dbPropfile); } else { file = new File(hopHome, "db.properties"); } dbProps = new ResourceProperties(); dbProps.setIgnoreCase(false); dbProps.addResource(new FileResource(file)); DbSource.setDefaultProps(dbProps); // read apps.properties file String appsPropfile = sysProps.getProperty("appsPropFile"); if ((appsPropfile != null) && !"".equals(appsPropfile.trim())) { file = new File(appsPropfile); } else { file = new File(hopHome, "apps.properties"); } appsProps = new ResourceProperties(); appsProps.setIgnoreCase(true); appsProps.addResource(new FileResource(file)); paranoid = "true".equalsIgnoreCase(sysProps.getProperty("paranoid")); String language = sysProps.getProperty("language"); String country = sysProps.getProperty("country"); String timezone = sysProps.getProperty("timezone"); if ((language != null) && (country != null)) { Locale.setDefault(new Locale(language, country)); } if (timezone != null) { TimeZone.setDefault(TimeZone.getTimeZone(timezone)); } // logger.debug("Locale = " + Locale.getDefault()); // logger.debug("TimeZone = " + // TimeZone.getDefault().getDisplayName(Locale.getDefault())); dbSources = new Hashtable(); // try to load the extensions extensions = new Vector(); if (sysProps.getProperty("extensions") != null) { initExtensions(); } jetty = JettyServer.init(this, config); }
From source file:org.jfree.data.time.WeekTest.java
/** * A test for a problem in constructing a new Week instance. *//*from www.j a v a 2 s.c om*/ @Test public void testConstructor() { Locale savedLocale = Locale.getDefault(); TimeZone savedZone = TimeZone.getDefault(); Locale.setDefault(new Locale("da", "DK")); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Copenhagen")); GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); // first day of week is monday assertEquals(Calendar.MONDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); Date t = cal.getTime(); Week w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(34, w.getWeek()); Locale.setDefault(Locale.US); TimeZone.setDefault(TimeZone.getTimeZone("US/Detroit")); cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault()); // first day of week is Sunday assertEquals(Calendar.SUNDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); t = cal.getTime(); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(35, w.getWeek()); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), new Locale("da", "DK")); assertEquals(34, w.getWeek()); Locale.setDefault(savedLocale); TimeZone.setDefault(savedZone); }
From source file:com.leclercb.taskunifier.gui.main.Main.java
private static void loadTimeZone() { String id = SETTINGS.getStringProperty("date.timezone"); if (id == null) return;//from w w w . j a va2 s . c o m TimeZone.setDefault(TimeZone.getTimeZone(id)); }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
public void testDateSerializationInCollection() throws Exception { Type listOfDates = new TypeToken<List<Date>>() { }.getType();/*from ww w. j a v a 2 s. co m*/ TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Locale defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.US); try { //Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); List<Date> dates = Arrays.asList(new Date(0)); String json = oson.setDateFormat("yyyy-MM-dd").toJson(dates, listOfDates); assertEquals("[\"1970-01-01\"]", json); assertEquals(0L, oson.<List<Date>>fromJson("[\"1970-01-01\"]", listOfDates).get(0).getTime()); } finally { TimeZone.setDefault(defaultTimeZone); Locale.setDefault(defaultLocale); } }
From source file:org.sipfoundry.sipxconfig.site.TestPage.java
public void defaultDeviceTimeZone() { TimeZone tz = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Helsinki")); getTimeZoneManager().saveDefault();//from w w w .j av a2s .com // clean-up TimeZone.setDefault(tz); }