001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.widgets.serialdate;
029
030import org.opencms.acacia.shared.I_CmsSerialDateValue.EndType;
031
032import java.util.Calendar;
033import java.util.Date;
034import java.util.SortedSet;
035
036/**
037 * Implementation of @{link org.opencms.widgets.serialdate.I_CmsSerialDateBean}
038 * that handles series' specified on a daily base.
039 */
040public class CmsSerialDateBeanDaily extends A_CmsSerialDateBean {
041
042    /** Days between two events in the series. */
043    private int m_interval;
044
045    /**
046     * Constructs the bean with all the information provided by the {@link org.opencms.widgets.CmsSerialDateWidget}.
047     *
048     * @param startDate the start date of the series as provided by the serial date widget.
049     * @param endDate the end date of the series as provided by the serial date widget.
050     * @param isWholeDay flag, indicating if the event lasts the whole day
051     * @param endType the end type of the series as provided by the serial date widget.
052     * @param serialEndDate the end date of the series as provided by the serial date widget.
053     * @param occurrences the maximal number of occurrences of the event as provided by the serial date widget.
054     * @param exceptions dates where the event does not take place, even if it is in the series.
055     * @param interval number of days till the next event should occur.
056     */
057    public CmsSerialDateBeanDaily(
058        Date startDate,
059        Date endDate,
060        boolean isWholeDay,
061        EndType endType,
062        Date serialEndDate,
063        int occurrences,
064        SortedSet<Date> exceptions,
065        int interval) {
066        super(startDate, endDate, isWholeDay, endType, serialEndDate, occurrences, exceptions);
067        m_interval = interval;
068
069    }
070
071    /**
072     * @see org.opencms.widgets.serialdate.A_CmsSerialDateBean#getFirstDate()
073     */
074    @Override
075    protected Calendar getFirstDate() {
076
077        return (Calendar)getStartDate().clone();
078    }
079
080    /**
081     * @see org.opencms.widgets.serialdate.A_CmsSerialDateBean#isAnyDatePossible()
082     */
083    @Override
084    protected boolean isAnyDatePossible() {
085
086        return true;
087    }
088
089    /**
090     * @see org.opencms.widgets.serialdate.A_CmsSerialDateBean#toNextDate(java.util.Calendar)
091     */
092    @Override
093    protected void toNextDate(Calendar date) {
094
095        date.add(Calendar.DATE, m_interval);
096
097    }
098}