KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > file > collectors > CmsCollectorData


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/collectors/CmsCollectorData.java,v $
3  * Date : $Date: 2006/03/27 14:52:50 $
4  * Version: $Revision: 1.9 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
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 Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.file.collectors;
33
34 import org.opencms.file.types.I_CmsResourceType;
35 import org.opencms.loader.CmsLoaderException;
36 import org.opencms.main.CmsIllegalArgumentException;
37 import org.opencms.main.CmsLog;
38 import org.opencms.main.CmsRuntimeException;
39 import org.opencms.main.OpenCms;
40
41 import org.apache.commons.logging.Log;
42
43 /**
44  * Data structure for the collector, parsed from the collector parameters.
45  * <p>
46  *
47  * @author Alexander Kandzior
48  * @author Thomas Weckert
49  *
50  * @version $Revision: 1.9 $
51  *
52  * @since 6.0.0
53  */

54 public class CmsCollectorData {
55
56     /** The log object for this class. */
57     private static final Log LOG = CmsLog.getLog(CmsCollectorData.class);
58
59     /** The display count. */
60     private int m_count;
61
62     /** The absolute file name. */
63     private String JavaDoc m_fileName;
64
65     /** The file type id. */
66     private int m_type;
67
68     /**
69      * Creates a new collector data set.
70      * <p>
71      *
72      * @param data the data to parse
73      */

74     public CmsCollectorData(String JavaDoc data) {
75
76         if (data == null) {
77             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_COLLECTOR_PARAM_EMPTY_0));
78         }
79
80         int pos1 = data.indexOf('|');
81         if (pos1 == -1) {
82             throw new CmsIllegalArgumentException(
83                 Messages.get().container(Messages.ERR_COLLECTOR_PARAM_INVALID_1, data));
84         }
85
86         int pos2 = data.indexOf('|', pos1 + 1);
87         if (pos2 == -1) {
88             pos2 = data.length();
89             m_count = 0;
90         } else {
91             m_count = Integer.valueOf(data.substring(pos2 + 1)).intValue();
92         }
93
94         m_fileName = data.substring(0, pos1);
95         String JavaDoc type = data.substring(pos1 + 1, pos2);
96         try {
97             // try to look up the resource type
98
I_CmsResourceType resourceType = OpenCms.getResourceManager().getResourceType(type);
99             m_type = resourceType.getTypeId();
100         } catch (CmsLoaderException e) {
101             // maybe the int id is directly used?
102
int typeInt = Integer.valueOf(type).intValue();
103             try {
104                 I_CmsResourceType resourceType = OpenCms.getResourceManager().getResourceType(typeInt);
105                 m_type = resourceType.getTypeId();
106                 if (LOG.isWarnEnabled()) {
107                     LOG.warn(Messages.get().getBundle().key(
108                         Messages.LOG_RESTYPE_INTID_2,
109                         resourceType.getTypeName(),
110                         new Integer JavaDoc(m_type)));
111                 }
112             } catch (CmsLoaderException e1) {
113                 // this resource type does not exist
114
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_UNKNOWN_RESTYPE_1, type), e1);
115             }
116         }
117     }
118
119     /**
120      * Returns the count.
121      * <p>
122      *
123      * @return the count
124      */

125     public int getCount() {
126
127         return m_count;
128     }
129
130     /**
131      * Returns the file name.
132      * <p>
133      *
134      * @return the file name
135      */

136     public String JavaDoc getFileName() {
137
138         return m_fileName;
139     }
140
141     /**
142      * Returns the type.
143      * <p>
144      *
145      * @return the type
146      */

147     public int getType() {
148
149         return m_type;
150     }
151 }
152
Popular Tags