List of usage examples for java.util TimeZone setDefault
public static void setDefault(TimeZone zone)
From source file:org.joget.apps.app.service.AppServiceImpl.java
/** * Create a new version of an app from an existing latest version * @param appId/* w w w .j a v a2s . c o m*/ * @param version * @return */ @Transactional public AppDefinition createNewAppDefinitionVersion(String appId) { TimeZone current = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT 0")); Long version = appDefinitionDao.getLatestVersion(appId); AppDefinition appDef = appDefinitionDao.loadVersion(appId, version); Serializer serializer = new Persister(); AppDefinition newAppDef = null; try { byte[] appData = getAppDefinitionXml(appId, version); //for backward compatible Map<String, String> replacement = new HashMap<String, String>(); replacement.put("<!--disableSaveAsDraft>", "<disableSaveAsDraft>"); replacement.put("</disableSaveAsDraft-->", "</disableSaveAsDraft>"); replacement.put("<!--description>", "<description>"); replacement.put("</description-->", "</description>"); replacement.put("<!--meta>", "<meta>"); replacement.put("</meta-->", "</meta>"); appData = StringUtil.searchAndReplaceByteContent(appData, replacement); newAppDef = serializer.read(AppDefinition.class, new ByteArrayInputStream(appData)); } catch (Exception e) { LogUtil.error(AppServiceImpl.class.getName(), e, appId); } finally { TimeZone.setDefault(current); } PackageDefinition packageDef = appDef.getPackageDefinition(); byte[] xpdl = null; if (packageDef != null) { xpdl = workflowManager.getPackageContent(packageDef.getId(), packageDef.getVersion().toString()); } Long newAppVersion = newAppDef.getVersion() + 1; return importAppDefinition(newAppDef, newAppVersion, xpdl); }
From source file:org.obm.opush.command.sync.SyncHandlerTest.java
@Test public void testChangeLeadingToNoPermissionExceptionReplyNothing() throws Exception { TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone.setDefault(DateTimeZone.UTC.toTimeZone()); SyncKey syncKey = new SyncKey("13424"); CollectionId collectionId = CollectionId.of(1); ServerId serverId = CollectionId.of(432).serverId(1456); String clientId = null;// w w w . j av a 2 s .c o m DataDelta serverDataDelta = DataDelta.newEmptyDelta(date("2012-10-10T16:22:53"), syncKey); MSEmail clientData = MSEmail.builder().header(MSEmailHeader.builder().build()) .body(MSEmailBody.builder().mimeData(Optional.of(new SerializableInputStream("obm"))) .bodyType(MSEmailBodyType.PlainText).estimatedDataSize(0).charset(Charsets.UTF_8) .truncated(false).build()) .build(); syncKeyTestUtils.mockNextGeneratedSyncKey(new SyncKey("2345")); syncTestUtils.mockEmailSyncClasses(syncKey, serverDataDelta, userAsList); UserDataRequest udr = new UserDataRequest(users.jaures.credentials, "Sync", users.jaures.device); expect(contentsImporter.importMessageChange(udr, collectionId, serverId, clientId, clientData)) .andThrow(new NoPermissionException()); mocksControl.replay(); opushServer.start(); OPClient opClient = testUtils.buildWBXMLOpushClient(users.jaures, opushServer.getHttpPort(), httpClient); SyncResponse syncResponse = opClient .run(syncBuilder.device(users.jaures.device) .request(ClientSyncRequest.builder().addCollection(AnalysedSyncCollection.builder() .collectionId(collectionId).syncKey(syncKey).dataType(PIMDataType.EMAIL) .command(SyncCollectionCommandRequest.builder().type(SyncCommand.ADD) .serverId(serverId).clientId(clientId).applicationData(clientData).build()) .build()).build()) .build()); assertThat(syncResponse.getStatus()).isEqualTo(SyncStatus.OK); syncTestUtils.checkMailFolderHasNoChange(syncResponse, collectionId); TimeZone.setDefault(defaultTimeZone); }
From source file:it.webappcommon.lib.jsf.AbstractPageBase.java
public TimeZone getTimeZone() { TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); return TimeZone.getDefault(); }
From source file:org.joget.apps.app.service.AppServiceImpl.java
/** * Get App definition XML/*from ww w. java 2s.c o m*/ * @param appId * @param version * @return */ public byte[] getAppDefinitionXml(String appId, Long version) { byte[] appDefinitionXml = null; ByteArrayOutputStream baos = null; TimeZone current = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT 0")); try { baos = new ByteArrayOutputStream(); AppDefinition appDef = getAppDefinition(appId, Long.toString(version)); Serializer serializer = new Persister(); serializer.write(appDef, baos); appDefinitionXml = baos.toByteArray(); baos.close(); String value = new String(appDefinitionXml, "UTF-8"); value = value.replaceAll("org\\.hibernate\\.collection\\.PersistentBag", "java.util.ArrayList"); value = value.replaceAll("org\\.hibernate\\.collection\\.PersistentMap", "java.util.HashMap"); //for backward compatible value = commentTag(value, "disableSaveAsDraft"); value = commentTag(value, "meta"); if (value.indexOf("<formDefinitionList>") > 0) { int start = value.indexOf("<formDefinitionList>"); int end = value.indexOf("</formDefinitionList>"); value = value.substring(0, start - 1) + commentTag(value.substring(start, end - 1), "description") + value.substring(end); } int afterMessagePos = 14; if (value.indexOf("<messageList/>") > 0) { afterMessagePos += value.indexOf("<messageList/>"); } else { afterMessagePos += value.indexOf("</messageList>"); } value = value.substring(0, afterMessagePos) + commentTag(value.substring(afterMessagePos + 1), "description"); return value.getBytes("UTF-8"); } catch (Exception ex) { LogUtil.error(getClass().getName(), ex, ""); } finally { if (baos != null) { try { baos.close(); } catch (Exception e) { LogUtil.error(getClass().getName(), e, ""); } } TimeZone.setDefault(current); } return null; }
From source file:com.android.calendar.event.EditEventView.java
private void setDate(TextView view, long millis) { int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_ABBREV_WEEKDAY; // Unfortunately, DateUtils doesn't support a timezone other than the // default timezone provided by the system, so we have this ugly hack // here to trick it into formatting our time correctly. In order to // prevent all sorts of craziness, we synchronize on the TimeZone class // to prevent other threads from reading an incorrect timezone from // calls to TimeZone#getDefault() // TODO fix this if/when DateUtils allows for passing in a timezone String dateString;//from w w w. ja v a 2s.c om synchronized (TimeZone.class) { TimeZone.setDefault(TimeZone.getTimeZone(mTimezone)); dateString = DateUtils.formatDateTime(mActivity, millis, flags); // setting the default back to null restores the correct behavior TimeZone.setDefault(null); } view.setText(dateString); }
From source file:com.android.calendar.event.EditEventView.java
private void setTime(TextView view, long millis) { int flags = DateUtils.FORMAT_SHOW_TIME; flags |= DateUtils.FORMAT_CAP_NOON_MIDNIGHT; if (DateFormat.is24HourFormat(mActivity)) { flags |= DateUtils.FORMAT_24HOUR; }//w w w . j a v a2 s. c o m // Unfortunately, DateUtils doesn't support a timezone other than the // default timezone provided by the system, so we have this ugly hack // here to trick it into formatting our time correctly. In order to // prevent all sorts of craziness, we synchronize on the TimeZone class // to prevent other threads from reading an incorrect timezone from // calls to TimeZone#getDefault() // TODO fix this if/when DateUtils allows for passing in a timezone String timeString; synchronized (TimeZone.class) { TimeZone.setDefault(TimeZone.getTimeZone(mTimezone)); timeString = DateUtils.formatDateTime(mActivity, millis, flags); TimeZone.setDefault(null); } view.setText(timeString); }
From source file:org.joget.apps.app.service.AppServiceImpl.java
/** * Import app from zip file// ww w. jav a 2 s. c o m * @param zip * @return */ @Transactional public AppDefinition importApp(byte[] zip) throws ImportAppException { TimeZone current = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT 0")); try { byte[] appData = getAppDataXmlFromZip(zip); byte[] xpdl = getXpdlFromZip(zip); //for backward compatible Map<String, String> replacement = new HashMap<String, String>(); replacement.put("<!--disableSaveAsDraft>", "<disableSaveAsDraft>"); replacement.put("</disableSaveAsDraft-->", "</disableSaveAsDraft>"); replacement.put("<!--description>", "<description>"); replacement.put("</description-->", "</description>"); replacement.put("<!--meta>", "<meta>"); replacement.put("</meta-->", "</meta>"); appData = StringUtil.searchAndReplaceByteContent(appData, replacement); Serializer serializer = new Persister(); AppDefinition appDef = serializer.read(AppDefinition.class, new ByteArrayInputStream(appData), false); long appVersion = appDefinitionDao.getLatestVersion(appDef.getAppId()); //Store appDef long newAppVersion = appVersion + 1; AppDefinition newAppDef = importAppDefinition(appDef, newAppVersion, xpdl); importPlugins(zip); return newAppDef; } catch (ImportAppException e) { throw e; } catch (Exception e) { LogUtil.error(getClass().getName(), e, ""); } finally { TimeZone.setDefault(current); } return null; }