Example usage for java.util Calendar ZONE_OFFSET

List of usage examples for java.util Calendar ZONE_OFFSET

Introduction

In this page you can find the example usage for java.util Calendar ZONE_OFFSET.

Prototype

int ZONE_OFFSET

To view the source code for java.util Calendar ZONE_OFFSET.

Click Source Link

Document

Field number for get and set indicating the raw offset from GMT in milliseconds.

Usage

From source file:com.healthmarketscience.jackcess.Column.java

/**
 * Gets the timezone offset from UTC for the given time (including DST).
 *//* w w w  .  j  av a  2s.  c o m*/
private long getTimeZoneOffset(long time) {
    Calendar c = Calendar.getInstance(getTimeZone());
    c.setTimeInMillis(time);
    return ((long) c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET));
}

From source file:cx.fbn.nevernote.sql.REnSearch.java

private GregorianCalendar stringToGregorianCalendar(String date) {
    String datePart = date;//  www . j  a v a2 s. c o  m
    GregorianCalendar calendar = new GregorianCalendar();
    boolean GMT = false;
    String timePart = "";
    if (date.contains("T")) {
        datePart = date.substring(0, date.indexOf("T"));
        timePart = date.substring(date.indexOf("T") + 1);
    } else {
        timePart = "000001";
    }
    if (datePart.length() != 8)
        return null;
    calendar.set(Calendar.YEAR, new Integer(datePart.substring(0, 4)));
    calendar.set(Calendar.MONTH, new Integer(datePart.substring(4, 6)) - 1);
    calendar.set(Calendar.DAY_OF_MONTH, new Integer(datePart.substring(6)));
    if (timePart.endsWith("Z")) {
        GMT = true;
        timePart = timePart.substring(0, timePart.length() - 1);
    }
    timePart = timePart.concat("000000");
    timePart = timePart.substring(0, 6);
    calendar.set(Calendar.HOUR, new Integer(timePart.substring(0, 2)));
    calendar.set(Calendar.MINUTE, new Integer(timePart.substring(2, 4)));
    calendar.set(Calendar.SECOND, new Integer(timePart.substring(4)));
    if (GMT)
        calendar.set(Calendar.ZONE_OFFSET, -1 * (calendar.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60)));
    return calendar;

}

From source file:com.hichinaschool.flashcards.libanki.Utils.java

/**
 * Calculate the UTC offset/* w  w w . j  av  a  2s. c  om*/
 */
public static double utcOffset() {
    Calendar cal = Calendar.getInstance();
    // 4am
    return 4 * 60 * 60 - (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 1000;
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

@SuppressWarnings("rawtypes")
private void jBackwardButtonActionPerformed(java.awt.event.ActionEvent evt) {
    /*LoginHelper pms = new LoginHelper();
    try {//from  w  w  w  . j  a  v a 2  s  .c  o  m
       PasswordType ptype = new PasswordType();
       ptype.setIsToken(UserInfoBean.getInstance().getUserPasswordIsToken());
       ptype.setTokenMsTimeout(UserInfoBean.getInstance()
       .getUserPasswordTimeout());
       ptype.setValue(UserInfoBean.getInstance().getUserPassword());
       String response = pms.getUserInfo(UserInfoBean.getInstance().getUserName(), ptype, UserInfoBean.getInstance().getSelectedProjectUrl(), 
       UserInfoBean.getInstance().getUserDomain(), false, UserInfoBean.getInstance().getProjectId());
    }
    catch(Exception e) {
       e.printStackTrace();
    }*/

    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    //String searchStr = jSearchStringTextField.getText();
    int category = jCategoryComboBox.getSelectedIndex();
    int strategy = jContainComboBox.getSelectedIndex();

    curCreationDate = previousQueries.get(0).creationTime();
    ////////////////////////////////////////////////
    SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");//.getDateInstance();
    Date date = null;
    try {
        date = df.parse(this.jStartTimeTextField.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    cal.setTime(date);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    //log.info("Timezone: "+tz.getID()+" : "+zt_offset);

    //if (startTime() != -1) {
    ConstrainDateType constraindateType = new ConstrainDateType();
    XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(cal.get(GregorianCalendar.YEAR),
            cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.DAY_OF_MONTH));
    xmlC.setTimezone(zt_offset);//0);//-5*60);
    xmlC.setHour(cal.get(GregorianCalendar.HOUR_OF_DAY));
    xmlC.setMinute(cal.get(GregorianCalendar.MINUTE));
    xmlC.setSecond(cal.get(GregorianCalendar.SECOND));
    constraindateType.setValue(xmlC);
    //timeConstrain.setDateFrom(constraindateType);
    //}
    ////////////////////////////////////////////////
    String xmlStr = writePagingQueryXML("", category, strategy, true, xmlC);//curCreationDate);
    // System.out.println(xmlStr);

    String responseStr = null;
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());
            // System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }
        loadPatientSets();
        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, true);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:org.sakaiproject.component.app.podcasts.PodcastServiceImpl.java

/**
 * Returns the date set in GMT time//  w  w w  . jav  a2  s  .c o  m
 * 
 * @param date
 *          The date represented as a long value
 * 
 * @return Date
 *          The Date object set in GMT time
 */
public Date getGMTdate(long date) {
    final Calendar cal = Calendar.getInstance(timeService.getLocalTimeZone());
    cal.setTimeInMillis(date);

    int gmtoffset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);

    return new Date(date - gmtoffset);
}

From source file:org.sakaiproject.portal.charon.SkinnableCharonPortal.java

public void includeBottom(PortalRenderContext rcontext) {
    if (rcontext.uses(INCLUDE_BOTTOM)) {
        String thisUser = SessionManager.getCurrentSessionUserId();

        //Get user preferences
        PreferencesService preferencesService = (PreferencesService) ComponentManager
                .get(PreferencesService.class);

        Preferences prefs = preferencesService.getPreferences(thisUser);

        boolean showServerTime = ServerConfigurationService.getBoolean("portal.show.time", true);
        if (showServerTime) {
            rcontext.put("showServerTime", "true");
            Calendar now = Calendar.getInstance();
            Date nowDate = new Date(now.getTimeInMillis());

            //first set server date and time
            TimeZone serverTz = TimeZone.getDefault();
            now.setTimeZone(serverTz);/*www  . j  a  va 2 s .  c  om*/

            rcontext.put("serverTzDisplay",
                    serverTz.getDisplayName(serverTz.inDaylightTime(nowDate), TimeZone.SHORT));

            rcontext.put("serverTzGMTOffset", String.valueOf(
                    now.getTimeInMillis() + now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET)));

            //provide the user's preferred timezone information if it is different

            //Get the Properties object that holds user's TimeZone preferences 
            ResourceProperties tzprops = prefs.getProperties(TimeService.APPLICATION_ID);

            //Get the ID of the timezone using the timezone key.
            //Default to 'localTimeZone' (server timezone?)
            String preferredTzId = (String) tzprops.get(TimeService.TIMEZONE_KEY);

            if (preferredTzId != null && !preferredTzId.equals(serverTz.getID())) {
                TimeZone preferredTz = TimeZone.getTimeZone(preferredTzId);

                now.setTimeZone(preferredTz);

                rcontext.put("showPreferredTzTime", "true");

                //now set up the portal information
                rcontext.put("preferredTzDisplay",
                        preferredTz.getDisplayName(preferredTz.inDaylightTime(nowDate), TimeZone.SHORT));

                rcontext.put("preferredTzGMTOffset", String.valueOf(
                        now.getTimeInMillis() + now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET)));
            } else {
                rcontext.put("showPreferredTzTime", "false");
            }
        }

        rcontext.put("pagepopup", false);

        String copyright = ServerConfigurationService.getString("bottom.copyrighttext");

        /**
         * Replace keyword in copyright message from sakai.properties 
         * with the server's current year to auto-update of Copyright end date 
         */
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
        String currentServerYear = simpleDateFormat.format(new Date());
        copyright = copyright.replaceAll(SERVER_COPYRIGHT_CURRENT_YEAR_KEYWORD, currentServerYear);

        String service = ServerConfigurationService.getString("ui.service", "Sakai");
        String serviceVersion = ServerConfigurationService.getString("version.service", "?");
        String sakaiVersion = ServerConfigurationService.getString("version.sakai", "?");
        String server = ServerConfigurationService.getServerId();
        String[] bottomNav = ServerConfigurationService.getStrings("bottomnav");
        String[] poweredByUrl = ServerConfigurationService.getStrings("powered.url");
        String[] poweredByImage = ServerConfigurationService.getStrings("powered.img");
        String[] poweredByAltText = ServerConfigurationService.getStrings("powered.alt");

        {
            List<Object> l = new ArrayList<Object>();
            if ((bottomNav != null) && (bottomNav.length > 0)) {
                for (int i = 0; i < bottomNav.length; i++) {
                    l.add(bottomNav[i]);
                }
            }
            rcontext.put("bottomNav", l);
        }

        boolean neoChatAvailable = ServerConfigurationService.getBoolean("portal.neochat", true)
                && chatHelper.checkChatPermitted(thisUser);

        rcontext.put("neoChat", neoChatAvailable);
        rcontext.put("portalChatPollInterval",
                ServerConfigurationService.getInt("portal.chat.pollInterval", 5000));
        rcontext.put("neoAvatar", ServerConfigurationService.getBoolean("portal.neoavatar", true));
        rcontext.put("neoChatVideo", ServerConfigurationService.getBoolean("portal.chat.video", true));
        rcontext.put("portalVideoChatTimeout",
                ServerConfigurationService.getInt("portal.chat.video.timeout", 25));

        if (sakaiTutorialEnabled && thisUser != null) {
            if (!("1".equals(prefs.getProperties().getProperty("sakaiTutorialFlag")))) {
                rcontext.put("tutorial", true);
                //now save this in the user's prefefences so we don't show it again
                PreferencesEdit preferences = null;
                SecurityAdvisor secAdv = null;
                try {
                    secAdv = new SecurityAdvisor() {
                        @Override
                        public SecurityAdvice isAllowed(String userId, String function, String reference) {
                            if ("prefs.add".equals(function) || "prefs.upd".equals(function)) {
                                return SecurityAdvice.ALLOWED;
                            }
                            return null;
                        }
                    };
                    securityService.pushAdvisor(secAdv);

                    try {
                        preferences = preferencesService.edit(thisUser);
                    } catch (IdUnusedException ex1) {
                        try {
                            preferences = preferencesService.add(thisUser);
                        } catch (IdUsedException ex2) {
                            M_log.error(ex2);
                        } catch (PermissionException ex3) {
                            M_log.error(ex3);
                        }
                    }
                    if (preferences != null) {
                        ResourcePropertiesEdit props = preferences.getPropertiesEdit();
                        props.addProperty("sakaiTutorialFlag", "1");
                        preferencesService.commit(preferences);
                    }
                } catch (Exception e1) {
                    M_log.error(e1);
                } finally {
                    if (secAdv != null) {
                        securityService.popAdvisor(secAdv);
                    }
                }
            }
        }
        // rcontext.put("bottomNavSitNewWindow",
        // Web.escapeHtml(rb.getString("site_newwindow")));

        if ((poweredByUrl != null) && (poweredByImage != null) && (poweredByAltText != null)
                && (poweredByUrl.length == poweredByImage.length)
                && (poweredByUrl.length == poweredByAltText.length)) {
            {
                List<Object> l = new ArrayList<Object>();
                for (int i = 0; i < poweredByUrl.length; i++) {
                    Map<String, Object> m = new HashMap<String, Object>();
                    m.put("poweredByUrl", poweredByUrl[i]);
                    m.put("poweredByImage", poweredByImage[i]);
                    m.put("poweredByAltText", poweredByAltText[i]);
                    l.add(m);
                }
                rcontext.put("bottomNavPoweredBy", l);

            }
        } else {
            List<Object> l = new ArrayList<Object>();
            Map<String, Object> m = new HashMap<String, Object>();
            m.put("poweredByUrl", "http://sakaiproject.org");
            m.put("poweredByImage", "/library/image/sakai_powered.gif");
            m.put("poweredByAltText", "Powered by Sakai");
            l.add(m);
            rcontext.put("bottomNavPoweredBy", l);
        }

        rcontext.put("bottomNavService", service);
        rcontext.put("bottomNavCopyright", copyright);
        rcontext.put("bottomNavServiceVersion", serviceVersion);
        rcontext.put("bottomNavSakaiVersion", sakaiVersion);
        rcontext.put("bottomNavServer", server);

        // SAK-25931 - Do not remove this from session here - removal is done by /direct
        Session s = SessionManager.getCurrentSession();
        String userWarning = (String) s.getAttribute("userWarning");
        rcontext.put("userWarning", new Boolean(StringUtils.isNotEmpty(userWarning)));

        if (ServerConfigurationService.getBoolean("pasystem.enabled", false)) {
            PASystem paSystem = (PASystem) ComponentManager.get(PASystem.class);
            rcontext.put("paSystemEnabled", true);
            rcontext.put("paSystem", paSystem);
        }
    }
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

@SuppressWarnings("rawtypes")
private void jForwardButtonActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    //String searchStr = jSearchStringTextField.getText();
    int category = jCategoryComboBox.getSelectedIndex();
    int strategy = jContainComboBox.getSelectedIndex();

    curCreationDate = previousQueries.get(previousQueries.size() - 1).creationTime();
    ////////////////////////////////////////////////
    SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");//.getDateInstance();
    Date date = null;//from  w  w  w . j av  a2  s. co  m
    try {
        date = df.parse(this.jStartTimeTextField.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    cal.setTime(date);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    //log.info("Timezone: "+tz.getID()+" : "+zt_offset);

    //if (startTime() != -1) {
    ConstrainDateType constraindateType = new ConstrainDateType();
    XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(cal.get(GregorianCalendar.YEAR),
            cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.DAY_OF_MONTH));
    xmlC.setTimezone(zt_offset);//0);//-5*60);
    xmlC.setHour(cal.get(GregorianCalendar.HOUR_OF_DAY));
    xmlC.setMinute(cal.get(GregorianCalendar.MINUTE));
    xmlC.setSecond(cal.get(GregorianCalendar.SECOND));
    constraindateType.setValue(xmlC);
    //timeConstrain.setDateFrom(constraindateType);
    //}
    ////////////////////////////////////////////////
    String xmlStr = writePagingQueryXML("", category, strategy, false, xmlC);//curCreationDate);
    // System.out.println(xmlStr);

    String responseStr = null;
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());
            // System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId());
            // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }
        loadPatientSets();
        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, false);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

private void jBackwardButtonActionPerformed(java.awt.event.ActionEvent evt) {
    /*LoginHelper pms = new LoginHelper();
    try {/*from  w  w  w . j  a va 2  s . c om*/
       PasswordType ptype = new PasswordType();
       ptype.setIsToken(UserInfoBean.getInstance().getUserPasswordIsToken());
       ptype.setTokenMsTimeout(UserInfoBean.getInstance()
       .getUserPasswordTimeout());
       ptype.setValue(UserInfoBean.getInstance().getUserPassword());
       String response = pms.getUserInfo(UserInfoBean.getInstance().getUserName(), ptype, UserInfoBean.getInstance().getSelectedProjectUrl(), 
       UserInfoBean.getInstance().getUserDomain(), false, UserInfoBean.getInstance().getProjectId());
    }
    catch(Exception e) {
       e.printStackTrace();
    }*/

    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    String searchStr = jSearchStringTextField.getText();
    int category = jCategoryComboBox.getSelectedIndex();
    int strategy = jContainComboBox.getSelectedIndex();

    curCreationDate = previousQueries.get(0).creationTime();
    ////////////////////////////////////////////////
    SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");//.getDateInstance();
    Date date = null;
    try {
        date = df.parse(this.jStartTimeTextField.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    cal.setTime(date);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    //log.info("Timezone: "+tz.getID()+" : "+zt_offset);

    //if (startTime() != -1) {
    ConstrainDateType constraindateType = new ConstrainDateType();
    XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(cal.get(GregorianCalendar.YEAR),
            cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.DAY_OF_MONTH));
    xmlC.setTimezone(zt_offset);//0);//-5*60);
    xmlC.setHour(cal.get(GregorianCalendar.HOUR_OF_DAY));
    xmlC.setMinute(cal.get(GregorianCalendar.MINUTE));
    xmlC.setSecond(cal.get(GregorianCalendar.SECOND));
    constraindateType.setValue(xmlC);
    //timeConstrain.setDateFrom(constraindateType);
    //}
    ////////////////////////////////////////////////
    String xmlStr = writePagingQueryXML("", category, strategy, true, xmlC);//curCreationDate);
    // System.out.println(xmlStr);

    String responseStr = null;
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());// System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }

        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, true);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

private void jForwardButtonActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    String searchStr = jSearchStringTextField.getText();
    int category = jCategoryComboBox.getSelectedIndex();
    int strategy = jContainComboBox.getSelectedIndex();

    curCreationDate = previousQueries.get(previousQueries.size() - 1).creationTime();
    ////////////////////////////////////////////////
    SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");//.getDateInstance();
    Date date = null;//from  w w w .  j  a  va 2 s  .co  m
    try {
        date = df.parse(this.jStartTimeTextField.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    cal.setTime(date);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    //log.info("Timezone: "+tz.getID()+" : "+zt_offset);

    //if (startTime() != -1) {
    ConstrainDateType constraindateType = new ConstrainDateType();
    XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(cal.get(GregorianCalendar.YEAR),
            cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.DAY_OF_MONTH));
    xmlC.setTimezone(zt_offset);//0);//-5*60);
    xmlC.setHour(cal.get(GregorianCalendar.HOUR_OF_DAY));
    xmlC.setMinute(cal.get(GregorianCalendar.MINUTE));
    xmlC.setSecond(cal.get(GregorianCalendar.SECOND));
    constraindateType.setValue(xmlC);
    //timeConstrain.setDateFrom(constraindateType);
    //}
    ////////////////////////////////////////////////
    String xmlStr = writePagingQueryXML("", category, strategy, false, xmlC);//curCreationDate);
    // System.out.println(xmlStr);

    String responseStr = null;
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());// System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }

        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, false);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:com.cloud.api.ApiResponseHelper.java

public String getDateStringInternal(Date inputDate) {
    if (inputDate == null) {
        return null;
    }// w w  w  .  j  a  va2 s. c  o m

    TimeZone tz = _usageSvc.getUsageTimezone();
    Calendar cal = Calendar.getInstance(tz);
    cal.setTime(inputDate);

    StringBuilder sb = new StringBuilder(32);
    sb.append(cal.get(Calendar.YEAR)).append('-');

    int month = cal.get(Calendar.MONTH) + 1;
    if (month < 10) {
        sb.append('0');
    }
    sb.append(month).append('-');

    int day = cal.get(Calendar.DAY_OF_MONTH);
    if (day < 10) {
        sb.append('0');
    }
    sb.append(day);

    sb.append("'T'");

    int hour = cal.get(Calendar.HOUR_OF_DAY);
    if (hour < 10) {
        sb.append('0');
    }
    sb.append(hour).append(':');

    int minute = cal.get(Calendar.MINUTE);
    if (minute < 10) {
        sb.append('0');
    }
    sb.append(minute).append(':');

    int seconds = cal.get(Calendar.SECOND);
    if (seconds < 10) {
        sb.append('0');
    }
    sb.append(seconds);

    double offset = cal.get(Calendar.ZONE_OFFSET);
    if (tz.inDaylightTime(inputDate)) {
        offset += (1.0 * tz.getDSTSavings()); // add the timezone's DST
        // value (typically 1 hour
        // expressed in milliseconds)
    }

    offset = offset / (1000d * 60d * 60d);
    int hourOffset = (int) offset;
    double decimalVal = Math.abs(offset) - Math.abs(hourOffset);
    int minuteOffset = (int) (decimalVal * 60);

    if (hourOffset < 0) {
        if (hourOffset > -10) {
            sb.append("-0");
        } else {
            sb.append('-');
        }
        sb.append(Math.abs(hourOffset));
    } else {
        if (hourOffset < 10) {
            sb.append("+0");
        } else {
            sb.append("+");
        }
        sb.append(hourOffset);
    }

    sb.append(':');

    if (minuteOffset == 0) {
        sb.append("00");
    } else if (minuteOffset < 10) {
        sb.append('0').append(minuteOffset);
    } else {
        sb.append(minuteOffset);
    }

    return sb.toString();
}