Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/opencms/core/CmsCronEntry.java


1   /*
2   * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/core/Attic/CmsCronEntry.java,v $
3   * Date   : $Date: 2001/11/16 09:36:34 $
4   * Version: $Revision: 1.2 $
5   *
6   * This library is part of OpenCms -
7   * the Open Source Content Mananagement System
8   *
9   * Copyright (C) 2001  The OpenCms Group
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about OpenCms, please see the
22  * OpenCms Website: http://www.opencms.org
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27  */
28  
29  package com.opencms.core;
30  
31  import java.util.*;
32  import com.opencms.util.*;
33  
34  class CmsCronEntry {
35  
36    /**
37     * The minute, when to lauch.
38     */
39    private int m_minute;
40  
41    /**
42     * The hour, when to lauch.
43     */
44    private int m_hour;
45  
46    /**
47     * The day of a month, when to lauch.
48     */
49    private int m_dayOfMonth;
50  
51    /**
52     * The month, when to lauch.
53     */
54    private int m_month;
55  
56    /**
57     * The day of a week, when to lauch.
58     */
59    private int m_dayOfWeek;
60  
61    /**
62     * The module to lauch at its time.
63     */
64    private String m_moduleToLaunch;
65  
66    /**
67     * The parameter fot the module to lauch.
68     */
69    private String m_moduleParameter;
70  
71    /**
72     * The user with its rights to lauch the module.
73     */
74    private String m_user;
75  
76    /**
77     * The group with its rights to lauch the module.
78     */
79    private String m_group;
80  
81    /**
82     * The asterix-Value this value is set where no check has to be performed.
83     */
84    public static final int C_ASTERIX = -1;
85  
86    /**
87     * This string indicates, where to split the parameterstring.
88     */
89    private static final String C_SPLITSTRING = " ";
90  
91    /**
92     * A constructor for this Table-Entry.
93     *
94     * @param paramstring a string which indicates the complete table-entry.
95     * This string will be split into the parameters for the table-entry. The
96     * format for the string is
97     * "min hour day-of-month month day-of-week module username".
98     */
99    CmsCronEntry(String paramstring)
100     throws CmsException  {
101         paramstring = Utils.replace(paramstring, "*", C_ASTERIX + "");
102     try {
103       String params[] =  Utils.split(paramstring, C_SPLITSTRING);
104       m_minute =      Integer.parseInt(params[0]);
105       m_hour =      Integer.parseInt(params[1]);
106       m_dayOfMonth =    Integer.parseInt(params[2]);
107       m_month =      Integer.parseInt(params[3]);
108       m_dayOfWeek =    Integer.parseInt(params[4]);
109       m_user =      new String(params[5]);
110       m_group =      new String(params[6]);
111       m_moduleToLaunch =  new String(params[7]);
112             if(params.length > 8) {
113           m_moduleParameter =  new String(params[8]);
114             } else {
115                 m_moduleParameter = null;
116             }
117     } catch(Exception exc) {
118       throw new CmsException("Invalid parameterstring. Exception: " + exc.toString());
119     }
120   }
121 
122   /**
123    * This method returns the paramstring for this table-entry. It is a string with all
124    * fields conected via C_SPLITSTRING
125    *
126    * @return the parameterstring.
127    */
128   public String getParamstring() {
129     return new String( ((m_minute == C_ASTERIX) ? "*" : m_minute + "") + C_SPLITSTRING +
130                ((m_hour == C_ASTERIX) ? "*" : m_hour + "") + C_SPLITSTRING +
131                ((m_dayOfMonth == C_ASTERIX) ? "*" : m_dayOfMonth + "") + C_SPLITSTRING +
132                ((m_month == C_ASTERIX) ? "*" : m_month + "") + C_SPLITSTRING +
133                ((m_dayOfWeek == C_ASTERIX) ? "*" : m_dayOfWeek + "")+ C_SPLITSTRING +
134                            m_user + C_SPLITSTRING +
135                            m_group + C_SPLITSTRING +
136                m_moduleToLaunch +
137                (m_moduleParameter == null ? "" : C_SPLITSTRING + m_moduleParameter));
138   }
139 
140   /**
141    * Checks this schedule-entry.
142    *
143    * @param lastTime the date of the last checkScheduleTable-run.
144    * @param now the date of this checkScheduleTable-run.
145    *
146    * @return true, if the module has to be launched or false, if not.
147    */
148   boolean check(Calendar lastTime, Calendar now) {
149         if(m_minute != C_ASTERIX) // check the minute
150         if(!isBetween(lastTime.get(Calendar.MINUTE), m_minute, now.get(Calendar.MINUTE)))
151           return false;
152 
153     if(m_hour != C_ASTERIX)  // check the hour
154       if(m_hour != now.get(Calendar.HOUR_OF_DAY))
155         return false;
156 
157     if(m_dayOfMonth != C_ASTERIX)  // check the dayOfMonth
158       if(m_dayOfMonth != now.get(Calendar.DAY_OF_MONTH))
159         return false;
160 
161     if(m_month != C_ASTERIX)  // check the month
162       if(m_month != now.get(Calendar.MONTH))
163         return false;
164 
165     if(m_dayOfWeek != C_ASTERIX)  // check the dayOfWeek
166       if(m_dayOfWeek != now.get(Calendar.DAY_OF_WEEK))
167         return false;
168 
169     // all checks are ok - signal to launch the module
170     return true;
171   }
172 
173   /**
174    * Checks, if the value is inbetween min and max.
175    *
176    * @param min.
177    * @param value.
178    * @param max.
179    */
180   private boolean isBetween(int min, int value, int max) {
181     if((min < value) && (value <= max))
182       return true;
183     else
184       return false;
185   }
186 
187   /**
188    * Gets the name of the module.
189    *
190    * @return the module-name for this entry.
191    */
192   public String getModuleName() {
193     return m_moduleToLaunch;
194   }
195 
196   /**
197    * Gets the parameter for the module.
198    *
199    * @return the module-parameter for this entry.
200    */
201   public String getModuleParameter() {
202     return m_moduleParameter;
203   }
204 
205   /**
206    * Gets the name of the user.
207    *
208    * @return the user-name for this entry.
209    */
210   public String getUserName() {
211     return m_user;
212   }
213 
214   /**
215    * Gets the name of the group.
216    *
217    * @return the group-name for this entry.
218    */
219   public String getGroupName() {
220     return m_group;
221   }
222 
223   public int getMinute() {
224     return m_minute;
225   }
226 
227   public int getHour() {
228     return m_hour;
229   }
230 
231   public int getDayOfMonth() {
232     return m_dayOfMonth;
233   }
234 
235   public int getMonth() {
236     return m_month;
237   }
238 
239   public int getDayOfWeek() {
240     return m_dayOfWeek;
241   }
242 
243     public String toString() {
244         return getClass().getName() + "{" + getParamstring() + "}";
245     }
246 }