Example usage for java.util GregorianCalendar clone

List of usage examples for java.util GregorianCalendar clone

Introduction

In this page you can find the example usage for java.util GregorianCalendar clone.

Prototype

@Override
    public Object clone() 

Source Link

Usage

From source file:com.dell.asm.asmcore.asmmanager.client.deviceinventory.ManagedDevice.java

public void setServerTemplateDate(GregorianCalendar serverTemplateDate) {
    if (serverTemplateDate != null) {
        this.serverTemplateDate = (GregorianCalendar) serverTemplateDate.clone();
    } else {/*w  ww .ja  v a  2s.co m*/
        this.serverTemplateDate = null;
    }
}

From source file:com.dell.asm.asmcore.asmmanager.client.deviceinventory.ManagedDevice.java

public void setComplianceCheckDate(GregorianCalendar complianceCheckDate) {
    if (complianceCheckDate != null) {
        this.complianceCheckDate = (GregorianCalendar) complianceCheckDate.clone();
    } else {//w  w  w.  ja  v a 2 s  . c om
        this.complianceCheckDate = null;
    }
}

From source file:com.dell.asm.asmcore.asmmanager.db.entity.DeviceInventoryEntity.java

public void setCreatedDate(GregorianCalendar createdDate) {
    if (createdDate != null) {
        this.createdDate = (GregorianCalendar) createdDate.clone();
    } else {/*from  w  w w  .  jav  a2s. c  o m*/
        this.createdDate = null;
    }
}

From source file:com.dell.asm.asmcore.asmmanager.db.entity.DeviceInventoryEntity.java

public void setUpdatedDate(GregorianCalendar updatedDate) {
    if (updatedDate != null) {
        this.updatedDate = (GregorianCalendar) updatedDate.clone();
    } else {//from  ww w.ja  va 2 s. c o m
        this.updatedDate = null;
    }
}

From source file:org.accada.epcis.repository.query.Schedule.java

/**
 * Calculates the next scheduled time after the given time. Algorithm idea:<br> -
 * start with biggest time unit (i.e. year) of the given time <br> - if the
 * time unit is valid (e.g. the time unit matches the <br>
 * scheduled time, this is implicitly true if the time in the <br>
 * schedule was omitted) *and* there exists a valid smaller time <br>
 * unit, *then* return this time unit <br> - do this recursively for all
 * time units <br> - month needs to be special cased because of dayOfWeek
 * /*from   www.ja  v  a 2s.c om*/
 * @param time
 *            Time after which next scheduled time should be returned.
 * @return The next scheduled time after 'time'.
 * @throws ImplementationException
 *             Almost any kind of error.
 */
public GregorianCalendar nextScheduledTime(final GregorianCalendar time)
        throws ImplementationExceptionResponse {
    GregorianCalendar nextSchedule = (GregorianCalendar) time.clone();
    // look at year
    while (!monthMadeValid(nextSchedule)) {
        nextSchedule.roll(YEAR, true);
        setFieldsToMinimum(nextSchedule, MONTH);

    }
    return nextSchedule;
}

From source file:org.extensiblecatalog.ncip.v2.koha.KohaLookupUserService.java

private void updateResponseData(ILSDIvOneOneLookupUserInitiationData initData,
        ILSDIvOneOneLookupUserResponseData responseData, JSONObject kohaUser, KohaRemoteServiceManager svcMgr)
        throws ParseException, KohaException {

    ResponseHeader responseHeader = KohaUtil.reverseInitiationHeader(initData);

    if (responseHeader != null)
        responseData.setResponseHeader(responseHeader);

    UserId userId = KohaUtil.createUserId(initData.getUserId().getUserIdentifierValue(),
            LocalConfig.getDefaultAgency());
    responseData.setUserId(userId);//from   w ww.j  av a 2s . c  o  m

    UserOptionalFields userOptionalFields = new UserOptionalFields();

    if (LocalConfig.useRestApiInsteadOfSvc()) {

        if (initData.getNameInformationDesired()) {
            String firstname = (String) kohaUser.get("firstname");
            String surname = (String) kohaUser.get("surname");
            String title = (String) kohaUser.get("title");
            String othernames = (String) kohaUser.get("othernames");

            StructuredPersonalUserName structuredPersonalUserName = new StructuredPersonalUserName();
            structuredPersonalUserName.setGivenName(firstname);
            structuredPersonalUserName.setPrefix(title);
            structuredPersonalUserName.setSurname(surname);
            structuredPersonalUserName.setSuffix(othernames);

            PersonalNameInformation personalNameInformation = new PersonalNameInformation();
            personalNameInformation.setStructuredPersonalUserName(structuredPersonalUserName);

            NameInformation nameInformation = new NameInformation();
            nameInformation.setPersonalNameInformation(personalNameInformation);
            userOptionalFields.setNameInformation(nameInformation);
        }

        if (initData.getUserAddressInformationDesired())
            userOptionalFields.setUserAddressInformations(KohaUtil.parseUserAddressInformations(kohaUser));

        if (initData.getUserPrivilegeDesired()) {

            String branchcode = (String) kohaUser.get("branchcode");
            String agencyUserPrivilegeType = (String) kohaUser.get("categorycode");

            if (branchcode != null && agencyUserPrivilegeType != null) {

                List<UserPrivilege> userPrivileges = new ArrayList<UserPrivilege>();
                UserPrivilege userPrivilege = new UserPrivilege();

                userPrivilege.setAgencyId(new AgencyId(branchcode));

                userPrivilege.setAgencyUserPrivilegeType(new AgencyUserPrivilegeType(
                        "http://www.niso.org/ncip/v1_0/imp1/schemes/agencyuserprivilegetype/agencyuserprivilegetype.scm",
                        agencyUserPrivilegeType));

                userPrivilege.setValidFromDate(
                        KohaUtil.parseGregorianCalendarFromKohaDate((String) kohaUser.get("dateenrolled")));
                userPrivilege.setValidToDate(
                        KohaUtil.parseGregorianCalendarFromKohaDate((String) kohaUser.get("dateexpiry")));

                userPrivileges.add(userPrivilege);
                userOptionalFields.setUserPrivileges(userPrivileges);
            }
        }

        if (initData.getDateOfBirthDesired()) {
            String dateOfBirth = (String) kohaUser.get("dateofbirth");
            userOptionalFields.setDateOfBirth(KohaUtil.parseGregorianCalendarFromKohaDate(dateOfBirth));
        }

        if (initData.getLoanedItemsDesired()) {
            JSONArray checkouts = (JSONArray) kohaUser.get("checkouts");

            if (checkouts != null && checkouts.size() != 0) {
                List<LoanedItem> loanedItems = new ArrayList<LoanedItem>();
                for (int i = 0; i < checkouts.size(); ++i) {
                    JSONObject checkout = (JSONObject) checkouts.get(i);
                    loanedItems.add(KohaUtil.parseLoanedItem(checkout));
                }
                responseData.setLoanedItems(loanedItems);
            }

        }

        if (initData.getRequestedItemsDesired()) {
            JSONArray holds = (JSONArray) kohaUser.get("holds");

            if (holds != null && holds.size() != 0) {
                List<RequestedItem> requestedItems = new ArrayList<RequestedItem>();
                for (int i = 0; i < holds.size(); ++i) {
                    JSONObject hold = (JSONObject) holds.get(i);
                    RequestedItem requestedItem = KohaUtil.parseRequestedItem(hold);
                    if (requestedItem != null)
                        requestedItems.add(requestedItem);
                }
                responseData.setRequestedItems(requestedItems);
            }
        }

        if (initData.getBlockOrTrapDesired()) {

            List<BlockOrTrap> blocks = new ArrayList<BlockOrTrap>(4);

            // Parse expiration
            GregorianCalendar expiryDate = KohaUtil
                    .parseGregorianCalendarFromKohaDate((String) kohaUser.get("dateexpiry"));

            GregorianCalendar warningForExpiryDateGregCal = ((GregorianCalendar) expiryDate.clone());
            warningForExpiryDateGregCal.add(GregorianCalendar.DAY_OF_YEAR, -14);

            Date now = new Date();
            if (now.after(expiryDate.getTime())) {

                BlockOrTrap expired = KohaUtil.createBlockOrTrap("Expired");

                blocks.add(expired);

            } else if (now.after(warningForExpiryDateGregCal.getTime())) {

                Days days = Days.daysBetween(new DateTime(now), new DateTime(expiryDate));

                BlockOrTrap expiresSoon = KohaUtil
                        .createBlockOrTrap("Expires in " + (days.getDays() + 1) + " days");

                blocks.add(expiresSoon);
            }

            // Parse debarred status
            String debarredStatus = (String) kohaUser.get("debarred");

            if (debarredStatus != null && !debarredStatus.isEmpty()) {

                String debarredComment = (String) kohaUser.get("debarredcomment");

                BlockOrTrap debarred = KohaUtil.createBlockOrTrap(
                        "Debarred" + (debarredComment != null ? ": " + debarredComment : ""));

                blocks.add(debarred);
            }

            if (blocks.size() > 0)
                userOptionalFields.setBlockOrTraps(blocks);

        }

        if (initData.getUserFiscalAccountDesired()) {

            JSONArray accountLines = (JSONArray) kohaUser.get("accountLines");

            if (accountLines != null && accountLines.size() != 0) {
                List<UserFiscalAccount> userFiscalAccounts = new ArrayList<UserFiscalAccount>(1);
                UserFiscalAccount userFiscalAccount = new UserFiscalAccount();
                List<AccountDetails> accountDetails = new ArrayList<AccountDetails>();

                for (int i = 0; i < accountLines.size(); ++i) {
                    JSONObject accountLine = (JSONObject) accountLines.get(i);
                    accountDetails.add(KohaUtil.parseAccountDetails(accountLine));
                }

                BigDecimal amount = null; // Sum all transactions ..
                for (AccountDetails details : accountDetails) {
                    if (amount == null)
                        amount = details.getFiscalTransactionInformation().getAmount().getMonetaryValue();
                    else
                        amount = amount
                                .add(details.getFiscalTransactionInformation().getAmount().getMonetaryValue());
                }
                userFiscalAccount.setAccountBalance(KohaUtil.createAccountBalance(amount));

                userFiscalAccount.setAccountDetails(accountDetails);
                userFiscalAccounts.add(userFiscalAccount); // Suppose user has
                // only one account
                // ..
                responseData.setUserFiscalAccounts(userFiscalAccounts);
            }
        }

        if (initData.getHistoryDesired() != null) {
            LoanedItemsHistory loanedItemsHistory = KohaUtil.parseLoanedItemsHistory(kohaUser, initData);
            responseData.setLoanedItemsHistory(loanedItemsHistory);
        }

    } else {
        JSONObject userInfo = (JSONObject) kohaUser.get("userInfo");
        if (userInfo != null) {
            if (initData.getNameInformationDesired()) {
                String firstname = (String) userInfo.get("firstname");
                String surname = (String) userInfo.get("surname");
                String title = (String) userInfo.get("title");
                String othernames = (String) userInfo.get("othernames");

                StructuredPersonalUserName structuredPersonalUserName = new StructuredPersonalUserName();
                structuredPersonalUserName.setGivenName(firstname);
                structuredPersonalUserName.setPrefix(title);
                structuredPersonalUserName.setSurname(surname);
                structuredPersonalUserName.setSuffix(othernames);

                PersonalNameInformation personalNameInformation = new PersonalNameInformation();
                personalNameInformation.setStructuredPersonalUserName(structuredPersonalUserName);

                NameInformation nameInformation = new NameInformation();
                nameInformation.setPersonalNameInformation(personalNameInformation);
                userOptionalFields.setNameInformation(nameInformation);
            }

            if (initData.getUserAddressInformationDesired())
                userOptionalFields.setUserAddressInformations(KohaUtil.parseUserAddressInformations(userInfo));

            if (initData.getUserPrivilegeDesired()) {

                String branchcode = (String) userInfo.get("branchcode");
                String agencyUserPrivilegeType = (String) userInfo.get("categorycode");

                if (branchcode != null && agencyUserPrivilegeType != null) {

                    List<UserPrivilege> userPrivileges = new ArrayList<UserPrivilege>();
                    UserPrivilege userPrivilege = new UserPrivilege();

                    userPrivilege.setAgencyId(new AgencyId(branchcode));

                    userPrivilege.setAgencyUserPrivilegeType(new AgencyUserPrivilegeType(
                            "http://www.niso.org/ncip/v1_0/imp1/schemes/agencyuserprivilegetype/agencyuserprivilegetype.scm",
                            agencyUserPrivilegeType));

                    userPrivilege.setValidFromDate(
                            KohaUtil.parseGregorianCalendarFromKohaDate((String) userInfo.get("dateenrolled")));
                    userPrivilege.setValidToDate(
                            KohaUtil.parseGregorianCalendarFromKohaDate((String) userInfo.get("dateexpiry")));

                    userPrivileges.add(userPrivilege);
                    userOptionalFields.setUserPrivileges(userPrivileges);
                }
            }

            if (initData.getBlockOrTrapDesired()) {
                List<BlockOrTrap> blockOrTraps = KohaUtil.parseBlockOrTraps((JSONArray) userInfo.get("blocks"));
                userOptionalFields.setBlockOrTraps(blockOrTraps);
            }

            if (initData.getDateOfBirthDesired()) {
                String dateOfBirth = (String) userInfo.get("dateofbirth");
                userOptionalFields.setDateOfBirth(KohaUtil.parseGregorianCalendarFromKohaDate(dateOfBirth));
            }
        }

        JSONArray requestedItemsParsed = (JSONArray) kohaUser.get("requestedItems");
        if (requestedItemsParsed != null && requestedItemsParsed.size() != 0) {
            List<RequestedItem> requestedItems = new ArrayList<RequestedItem>();
            for (int i = 0; i < requestedItemsParsed.size(); ++i) {
                JSONObject requestedItemParsed = (JSONObject) requestedItemsParsed.get(i);
                RequestedItem requestedItem = KohaUtil.parseRequestedItem(requestedItemParsed);
                if (requestedItem != null)
                    requestedItems.add(requestedItem);
            }
            responseData.setRequestedItems(requestedItems);
        }

        JSONArray loanedItemsParsed = (JSONArray) kohaUser.get("loanedItems");
        if (loanedItemsParsed != null && loanedItemsParsed.size() != 0) {
            List<LoanedItem> loanedItems = new ArrayList<LoanedItem>();
            for (int i = 0; i < loanedItemsParsed.size(); ++i) {
                JSONObject loanedItem = (JSONObject) loanedItemsParsed.get(i);
                loanedItems.add(KohaUtil.parseLoanedItem(loanedItem));
            }
            responseData.setLoanedItems(loanedItems);
        }

        JSONArray userFiscalAccountParsed = (JSONArray) kohaUser.get("userFiscalAccount");
        if (userFiscalAccountParsed != null && userFiscalAccountParsed.size() != 0) {
            List<UserFiscalAccount> userFiscalAccounts = new ArrayList<UserFiscalAccount>();
            UserFiscalAccount userFiscalAccount = new UserFiscalAccount();
            List<AccountDetails> accountDetails = new ArrayList<AccountDetails>();

            for (int i = 0; i < userFiscalAccountParsed.size(); ++i) {
                JSONObject accountDetail = (JSONObject) userFiscalAccountParsed.get(i);
                accountDetails.add(KohaUtil.parseAccountDetails(accountDetail));
            }

            BigDecimal amount = null; // Sum all transactions ..
            for (AccountDetails details : accountDetails) {
                if (amount == null)
                    amount = details.getFiscalTransactionInformation().getAmount().getMonetaryValue();
                else
                    amount.add(details.getFiscalTransactionInformation().getAmount().getMonetaryValue());
            }
            userFiscalAccount.setAccountBalance(KohaUtil.createAccountBalance(amount));

            userFiscalAccount.setAccountDetails(accountDetails);
            userFiscalAccounts.add(userFiscalAccount); // Suppose user has
            // only one account
            // ..
            responseData.setUserFiscalAccounts(userFiscalAccounts);
        }

    }
    responseData.setUserOptionalFields(userOptionalFields);

}

From source file:op.tools.SYSCalendar.java

/**
 * erkennt Uhrzeiten im Format HH:MM und erstellt einen GregorianCalendar basierend auf ref
 *//*  w  w w .  j a v a  2  s.  c o  m*/
public static GregorianCalendar parseTime(String input, GregorianCalendar gc) throws NumberFormatException {
    if (input == null || input.equals("")) {
        throw new NumberFormatException("leere Eingabe");
    }

    StringTokenizer st = new StringTokenizer(input, ":,.");
    if (st.countTokens() > 3) {
        throw new NumberFormatException("falsches Format");
    }

    String sStunde = "00";
    String sMinute = "00";
    String sSekunde = "00";

    if (st.countTokens() == 1) { // maybe a simple hour
        sStunde = st.nextToken();
    } else if (st.countTokens() == 2) { // maybe a simple hour
        sStunde = st.nextToken();
        sMinute = st.nextToken();
    } else {
        sStunde = st.nextToken();
        sMinute = st.nextToken();
        sSekunde = st.nextToken();
    }

    int stunde, minute, sekunde;
    GregorianCalendar now = (GregorianCalendar) gc.clone();

    try {
        stunde = Integer.parseInt(sStunde);
    } catch (NumberFormatException nfe) {
        throw new NumberFormatException("stunde");
    }
    try {
        minute = Integer.parseInt(sMinute);
    } catch (NumberFormatException nfe) {
        throw new NumberFormatException("minute");
    }
    try {
        sekunde = Integer.parseInt(sSekunde);
    } catch (NumberFormatException nfe) {
        throw new NumberFormatException("Sekunde");
    }

    if (stunde < 0) {
        throw new NumberFormatException("stunde");
    }
    if (stunde > 23) {
        throw new NumberFormatException("stunde");
    }
    if (minute < 0 || minute > 59) {
        throw new NumberFormatException("minute");
    }
    if (sekunde < 0 || sekunde > 59) {
        throw new NumberFormatException("Sekunde");
    }

    now.set(GregorianCalendar.HOUR_OF_DAY, stunde);
    now.set(GregorianCalendar.MINUTE, minute);
    now.set(GregorianCalendar.SECOND, sekunde);
    return now;
}

From source file:core.nipr.NiprClient.java

public void getNiprReports(Map<String, GregorianCalendar> aInDates,
        Map<String, LicenseInternal> aInOutLatestLicenses, Map<String, GregorianCalendar> aOutSuccessDates,
        StringBuilder aInOutErrors) {

    Map<String, LicenseInternal> lCurrentDayInfo = new HashMap<String, LicenseInternal>();

    for (GregorianCalendar lCal : aInDates.values()) {

        String lFormattedDate = CalenderUtils.getFormattedDate(lCal);
        System.out.println("NiprClient: Get data for " + lFormattedDate);

        AtomicBoolean lSpecificFailure = new AtomicBoolean(false);
        lCurrentDayInfo = getSpecificReport(lCal, lSpecificFailure, aInOutErrors);

        if (lSpecificFailure.get()) {
            System.out.println("Nipr Sync for date " + lFormattedDate + " failed");
            continue;
        }/*www .  j ava2  s . c  o  m*/

        System.out.println("Nipr Sync for date " + lFormattedDate + " SUCCESS, generating CSV file");
        // Generate a CSV for it.
        generateAndSendCsvFile(lFormattedDate, lCurrentDayInfo);

        // Previous Day is higher
        mergeReports(lCurrentDayInfo, aInOutLatestLicenses);
        GregorianCalendar lCalCopy = (GregorianCalendar) lCal.clone();
        aOutSuccessDates.put(CalenderUtils.getFormattedDate(lCalCopy), lCalCopy);
    }
}

From source file:org.sakaiproject.calendar.impl.RecurrenceRuleBase.java

/**
* Return a List of all RecurrenceInstance objects generated by this rule within the given time range, based on the
* prototype first range, in time order.//from www. j  a v  a 2 s  .  c  om
* @param prototype The prototype first TimeRange.
* @param range A time range to limit the generated ranges.
* @param timeZone The time zone to use for displaying times.
* %%% Note: this is currently not implemented, and always uses the "local" zone.
* @return a List of RecurrenceInstance generated by this rule in this range.
*/
public List generateInstances(TimeRange prototype, TimeRange range, TimeZone timeZone) {
    // these calendars are used if local time zone and the time zone where the first event was created (timeZone) are different
    GregorianCalendar firstEventCalendarDate = null;
    GregorianCalendar nextFirstEventCalendarDate = null;
    // %%% Note: base the breakdonw on the "timeZone" parameter to support multiple timeZone displays -ggolden
    TimeBreakdown startBreakdown = prototype.firstTime().breakdownLocal();

    GregorianCalendar startCalendarDate = TimeService.getCalendar(TimeService.getLocalTimeZone(), 0, 0, 0, 0, 0,
            0, 0);

    startCalendarDate.set(startBreakdown.getYear(), startBreakdown.getMonth() - 1, startBreakdown.getDay(),
            startBreakdown.getHour(), startBreakdown.getMin(), startBreakdown.getSec());

    // if local time zone and first event time zone are different
    // a new calendar is generated to calculate the re-occurring events
    // if not, the local time zone calendar is used
    boolean differentTimeZone = false;
    if (TimeService.getLocalTimeZone().getID().equals(timeZone.getID())) {
        differentTimeZone = false;
    } else {
        differentTimeZone = true;
    }

    if (differentTimeZone) {
        firstEventCalendarDate = TimeService.getCalendar(timeZone, 0, 0, 0, 0, 0, 0, 0);
        firstEventCalendarDate.setTimeInMillis(startCalendarDate.getTimeInMillis());
        nextFirstEventCalendarDate = (GregorianCalendar) firstEventCalendarDate.clone();
    }

    List rv = new Vector();

    GregorianCalendar nextCalendarDate = (GregorianCalendar) startCalendarDate.clone();

    int currentCount = 1;

    do {
        if (differentTimeZone) {
            // next time is calculated according to the first event time zone, not the local one
            nextCalendarDate.setTimeInMillis(nextFirstEventCalendarDate.getTimeInMillis());
        }

        Time nextTime = TimeService.newTime(nextCalendarDate);

        // is this past count?
        if ((getCount() > 0) && (currentCount > getCount()))
            break;

        // is this past until?
        if ((getUntil() != null) && isAfter(nextTime, getUntil()))
            break;

        TimeRange nextTimeRange = TimeService.newTimeRange(nextTime.getTime(), prototype.duration());

        //
        // Is this out of the range?
        //
        if (isOverlap(range, nextTimeRange)) {
            TimeRange eventTimeRange = null;

            // Single time cases require special handling.
            if (prototype.isSingleTime()) {
                eventTimeRange = TimeService.newTimeRange(nextTimeRange.firstTime());
            } else {
                eventTimeRange = TimeService.newTimeRange(nextTimeRange.firstTime(), nextTimeRange.lastTime(),
                        true, false);
            }

            // use this one
            rv.add(new RecurrenceInstance(eventTimeRange, currentCount));
        }

        // if next starts after the range, stop generating
        else if (isAfter(nextTime, range.lastTime()))
            break;

        // advance interval years.

        if (differentTimeZone) {
            nextFirstEventCalendarDate = (GregorianCalendar) firstEventCalendarDate.clone();
            nextFirstEventCalendarDate.add(getRecurrenceType(), getInterval() * currentCount);
        } else {
            nextCalendarDate = (GregorianCalendar) startCalendarDate.clone();
            nextCalendarDate.add(getRecurrenceType(), getInterval() * currentCount);
        }

        currentCount++;
    } while (true);

    return rv;
}

From source file:de.ribeiro.android.gso.core.UntisProvider.java

/**
 * Synchronisiert alle verfgbaren WeekDatas im Stupid
 *
 * @param logger//  w  ww. j a  v  a 2 s  .  c o m
 * @param selectedStringDate
 * @param selectedElement
 * @param myType
 * @param htmlResponse
 * @param stupid
 * @return
 * @throws Exception
 */
public static List<ICalEvent> syncWeekData(GregorianCalendar gc, String selectedElement, Type myType,
        HtmlResponse htmlResponse, Stupid stupid) throws Exception {

    List<ICalEvent> result = new ArrayList<ICalEvent>();

    int currentDayOfWeek = gc.get(Calendar.DAY_OF_WEEK);
    // den currentDay auf den folge Montag setzen
    if (currentDayOfWeek < 2) {
        // 1000*60*60*24 = 1 Tag!
        gc.setTimeInMillis(gc.getTimeInMillis() + (1000 * 60 * 60 * 24 * (2 - currentDayOfWeek)));
    }
    if (currentDayOfWeek > 6) {
        // 1000*60*60*24 = 1 Tag!
        gc.setTimeInMillis(gc.getTimeInMillis() + (1000 * 60 * 60 * 24 * 2));
    }

    String date = ConvertToStupidDateString(gc);

    String selectedType = myType.type;
    String selectedClassIndex = getIndexOfSelectorValue(myType.elementList, selectedElement);
    if (selectedClassIndex == "-1" || selectedType.equalsIgnoreCase("")) {
        throw new Exception(selectedElement + " kann nicht synchronisiert werden! " + selectedElement
                + " wurde nicht in der Liste der verfgbaren Elemente gefunden!");
    }
    while (selectedClassIndex.length() < 3) {
        selectedClassIndex = "0" + selectedClassIndex;
    }

    WeekData weekData = new WeekData(stupid);
    try {

        // URL setzten
        URL url = new URL(
                "https://webuntis.stadt-koeln.de/WebUntis/Ical.do?school=K175055&ajaxCommand=renderTimetable&rpt_sd="
                        + date + "&type=" + 1 + "&elemId=" + selectedClassIndex + "&elemType=" + selectedType);

        htmlResponse.dataReceived = false;

        htmlResponse.xmlContent = XmlOPs.readFromURL(url, Const.CONNECTIONTIMEOUT);

        if (htmlResponse.xmlContent.length() < 50) {
            // ende
            return null;
        }

        _logger.Info("Week downloaded!");
        List<ICalEvent> events = Ical.Parse(htmlResponse.xmlContent);

        weekData.syncTime = new GregorianCalendar().getTimeInMillis();
        weekData.addParameter("syncTime", String.valueOf(weekData.syncTime));
        weekData.date = (Calendar) gc.clone();
        weekData.elementId = selectedElement;
        weekData.addParameter("classId", selectedElement);
        weekData.events = events;
        weekData.weekId = String.valueOf(gc.get(Calendar.WEEK_OF_YEAR));
        weekData.addParameter("weekId", weekData.weekId);
        weekData.typeId = myType.type;
        weekData.addParameter("typeId", weekData.typeId);
        weekData.weekDataVersion = "2";
        weekData.addParameter("weekDataVersion", weekData.weekDataVersion);
        // stupid.stupidData.add(wd);

    } catch (Exception e) {
        throw e;
    }

    // prfen, ob bereits die Woche fr die Klasse und den typ vorliegt:

    WeekData existWeekData = null;
    // alle bestehden Wochen abrufen:
    for (int y = 0; y < stupid.stupidData.size(); y++) {
        existWeekData = stupid.stupidData.get(y);
        // prfen, ob das bestehende Element, dem neu hinzuzufgenden
        // entspricht(klasse,KW,Typ)
        if (existWeekData.elementId.equalsIgnoreCase(weekData.elementId)
                && existWeekData.weekId.equalsIgnoreCase(weekData.weekId)
                && existWeekData.typeId.equalsIgnoreCase(weekData.typeId)) {
            // ja,es ist eine gleiche Woche bereits vorhanden
            // jedes event der neuen woche prfen, ob dieses schon existiert
            for (int ev = 0; ev < weekData.events.size(); ev++) {
                ICalEvent newevent = weekData.events.get(ev);
                // die schulstunde vom neuen event heraussuchen
                int schulstunde = GetSchulstundeOfEvent(newevent);
                // damit die schulstunde vom bestenden stundeplan abrufen
                ICalEvent existingevent = GetSchulstunde(existWeekData,
                        newevent.DTSTART.get(Calendar.DAY_OF_WEEK), schulstunde);
                if (existingevent != null)
                    newevent.UID = existingevent.UID;
                // beide schulstunden vergleichen
                if (compareEvents(existingevent, newevent)) {
                    // unterschiede gefunden
                    newevent.UID = "diff";
                    if (existingevent == null)
                        _logger.Info("Es wurden Unterschiede in den Events gefunden: Neues Event "
                                + newevent.DESCRIPTION + " , " + newevent.SUMMARY
                                + " , kein altes Event vorhanden!");
                    else {
                        _logger.Info("Es wurden Unterschiede in den Events gefunden: Neues Event "
                                + newevent.DESCRIPTION + " , " + newevent.SUMMARY + " , Altes Event "
                                + existingevent.DESCRIPTION + " , " + existingevent.SUMMARY);
                    }
                    // ber unterschiede benachrichtigen
                    result.add(newevent);
                }
                // das existierende event aus dem datensatz lschen
                existWeekData.events.remove(existingevent);
            }
            for (ICalEvent event : existWeekData.events) {
                event.UID = "deleted";
                weekData.events.add(event);
            }
            // alle verbleibenden events aus dem existierenden datensatz
            // sind ausgefallene stunden

            // existiert schon...ersetzen
            weekData.isDirty = true;
            stupid.stupidData.set(y, weekData);
            return SummarizeChanges(result);
        }
    }

    stupid.stupidData.add(weekData); // fgt die geparste Woche den
    // // Hauptdaten
    // // hinzu
    stupid.sort();
    return SummarizeChanges(result);
}