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

Quick Search    Search Deep

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


1   /*
2   * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/core/Attic/CmsCronTable.java,v $
3   * Date   : $Date: 2004/01/06 13:36:14 $
4   * Version: $Revision: 1.3.2.1 $
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 com.opencms.boot.I_CmsLogChannels;
32  
33  import java.io.IOException;
34  import java.io.LineNumberReader;
35  import java.io.Reader;
36  import java.io.StringReader;
37  import java.util.Vector;
38  
39  /**
40   * Describes a complete crontable with cronentries.
41   */
42  class CmsCronTable {
43  
44      /** This vector contains all CronEntries for this table */
45      private Vector m_cronEntries = new Vector();
46  
47      /**
48       * Creates a new empty table.
49       */
50      CmsCronTable() {
51          // noop
52      }
53  
54      /**
55       * Creates a new table based on the parameter lines in this String.
56       * @param table a String with parameterlines.
57       * @throws IOException if the string couldn't be read
58       */
59      CmsCronTable(String table) throws IOException {
60          this(new StringReader(table));
61      }
62  
63      /**
64       * Creates a new table based on the parameter lines in this Reader.
65       * @param reder a Reader with parameterlines.
66       * @throws IOException if the reader couldn't be read
67       */
68      CmsCronTable(Reader reader) throws IOException {
69          update(reader);
70      }
71  
72      /**
73       * Updates the table with the new values.
74       * 
75       * @param reader - the Reader to get the new values from.
76       * @throws IOException if the reader couldn't be read
77       */
78      void update(Reader reader) throws IOException {
79          m_cronEntries = new Vector();
80          LineNumberReader lnreader = new LineNumberReader(reader);
81          String line = lnreader.readLine();
82  
83          while (line != null) {
84              line = line.trim();
85              if (!"".equals(line)) {
86                  try {
87                      m_cronEntries.add(new CmsCronEntry(line));
88                  } catch (CmsException e) {
89                      if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
90                          A_OpenCms.log(A_OpenCms.C_OPENCMS_CRITICAL, "Error parsing cron tab in line: " + line + ": " + e.toString());
91                      }
92                  }
93              }
94  
95              line = lnreader.readLine();
96          }
97  
98          reader.close();
99      }
100 
101     /**
102      * Updates the table with the new values.
103      * @param table - the String to get the new values from.
104      * @throws IOException if the reader couldn't be read
105      */
106     void update(String table) throws IOException {
107         update(new StringReader(table));
108     }
109 
110     /**
111      * Returns the size of thos table.
112      * @return the size of thos table.
113      */
114     public int size() {
115         return m_cronEntries.size();
116     }
117 
118     /**
119      * Returns one entry of this table.
120      * @param i the id of the etnry to return
121      * @return one CmsCronEntry.
122      */
123     public CmsCronEntry get(int i) {
124         return (CmsCronEntry)m_cronEntries.get(i);
125     }
126 
127     /**
128      * Adds a new CmsCronEntry.
129      * @param entry the entry to add.
130      */
131     public void add(CmsCronEntry entry) {
132         m_cronEntries.add(entry);
133     }
134 
135     /**
136      * Removes one entry from this table.
137      * @param entry the entry to remove.
138      */
139     public void remove(CmsCronEntry entry) {
140         m_cronEntries.removeElement(entry);
141     }
142 
143     /**
144      * Returns this table as string.
145      * @return this table as string.
146      */
147     public String getTable() {
148         StringBuffer result = new StringBuffer();
149         for(int i = 0; i < size(); i++) {
150             result.append(get(i).getParamstring() + "\n");
151         }
152         return result.toString();
153     }
154 
155     /**
156      * Returns a Stringrepresentation of this object.
157      */
158     public String toString() {
159         StringBuffer result = new StringBuffer();
160         result.append(getClass().getName() + "[\n");
161         for(int i = 0; i < size(); i++) {
162             result.append("\t" + get(i).toString() + "\n");
163         }
164         result.append("]\n");
165         return result.toString();
166     }
167 }