public void init() throws ServletException { if (!inited) { secureDirPath = getServletContext().getRealPath(SECURE_CONTEXT_PATH); strongProtection = Boolean.valueOf(getInitParameter("strongProtection")).booleanValue(); File secureDir = new File(secureDirPath); if (secureDirPath != null && secureDir.isDirectory()) { inited = true; if (DEBUG) log( "Initialization OK (Strong protection " + (strongProtection ? "enabled" : "DISABLED (better enable it check web.xml) !!!") + "). Setting secureDirPath to " + secureDirPath); } else { if (DEBUG) log( "Initialization problem, please check if " + getServletContext().getRealPath(SECURE_CONTEXT_PATH) + " exists and if it is directory !!!"); } } dateFormat = DateFormat.getDateInstance(); dateFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT")); }
/** * Get a DICOM format {@link java.lang.String String} time zone from a Java {@link * java.util.TimeZone TimeZone} on a particular Java {@link java.util.Date Date} . * * <p>E.g. from +0500 or -0700, the last component of a DateTime attribute value, or the value of * the DICOM attribute TimezoneOffsetFromUTC. * * @param javaTimeZone the {@link java.util.TimeZone TimeZone} time zone * @param javaDate the {@link java.util.Date Date} used to establish whether daylight savings is * in effect or not * @return a DICOM format {@link java.lang.String String} time zone representing the supplied time * zone on the supplied date */ public static String getTimeZone(java.util.TimeZone javaTimeZone, java.util.Date javaDate) { // System.err.println("DateTimeAttribute.getTimeZone(): javaTimeZone = "+javaTimeZone); // System.err.println("DateTimeAttribute.getTimeZone(): javaDate = "+javaDate); int offset = javaTimeZone.getOffset( javaDate .getTime()); // returns the amount of time in milliseconds to add to UTC to get // local time boolean isNegative = false; if (offset < 0) { isNegative = true; offset = -offset; } int offsetTotalMinutes = offset / 1000 / 60; int offsetHoursPart = offsetTotalMinutes / 60; int offsetMinutesPart = offsetTotalMinutes % 60; String tzInDICOMFormat = (isNegative ? "-" : "+") + (offsetHoursPart > 9 ? "" : "0") + offsetHoursPart + (offsetMinutesPart > 9 ? "" : "0") + offsetMinutesPart; // System.err.println("DateTimeAttribute.getTimeZone(): tzInDICOMFormat = "+tzInDICOMFormat); return tzInDICOMFormat; }
/** * Get a DICOM format {@link java.lang.String String} time zone representation of the current * timezone. * * <p>E.g. from +0500 or -0700, the last component of a DateTime attribute value, or the value of * the DICOM attribute TimezoneOffsetFromUTC. * * @return a DICOM format {@link java.lang.String String} time zone representing the current time * zone on the current date */ public static String getCurrentTimeZone() { return getTimeZone(java.util.TimeZone.getDefault(), new java.util.Date()); }