KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > list > CmsListItem


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListItem.java,v $
3  * Date : $Date: 2005/06/23 11:11:43 $
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.workplace.list;
33
34 import org.opencms.main.CmsIllegalArgumentException;
35 import org.opencms.util.CmsStringUtil;
36
37 import java.util.HashMap JavaDoc;
38 import java.util.Map JavaDoc;
39
40 /**
41  * Generic list item.<p>
42  *
43  * @author Michael Moossen
44  *
45  * @version $Revision: 1.9 $
46  *
47  * @since 6.0.0
48  */

49 public class CmsListItem {
50
51     /** Unique id for later recovery. */
52     private final String JavaDoc m_id;
53
54     /** Associated list definition. */
55     private final CmsListMetadata m_metadata;
56
57     /** Item values. */
58     private final Map JavaDoc m_values = new HashMap JavaDoc();
59
60     /**
61      * Default Constructor.<p>
62      *
63      * @param id the id of the item has to be unique
64      * @param metadata the corresponding list definition
65      */

66     public CmsListItem(CmsListMetadata metadata, String JavaDoc id) {
67
68         if (CmsStringUtil.isEmptyOrWhitespaceOnly(id)) {
69             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_LIST_INVALID_NULL_ARG_1, "id"));
70         }
71         if (metadata == null) {
72             throw new CmsIllegalArgumentException(Messages.get().container(
73                 Messages.ERR_LIST_INVALID_NULL_ARG_1,
74                 "metadata"));
75         }
76         m_metadata = metadata;
77         m_id = id;
78     }
79
80     /**
81      * Returns the value of the column for this item.<p>
82      *
83      * @param columnId the column id
84      *
85      * @return the content, may be <code>null</code>
86      *
87      * @throws CmsIllegalArgumentException if the given <code>columnId</code> is invalid
88      */

89     public Object JavaDoc get(String JavaDoc columnId) throws CmsIllegalArgumentException {
90
91         if (getMetadata().getColumnDefinition(columnId) == null
92             && getMetadata().getItemDetailDefinition(columnId) == null) {
93             throw new CmsIllegalArgumentException(
94                 Messages.get().container(Messages.ERR_LIST_INVALID_COLUMN_1, columnId));
95         }
96         return m_values.get(columnId);
97     }
98
99     /**
100      * Returns the id of the item.<p>
101      *
102      * @return the id
103      *
104      * @see CmsHtmlList#getItem(String)
105      */

106     public String JavaDoc getId() {
107
108         return m_id;
109     }
110
111     /**
112      * Returns the metadata.<p>
113      *
114      * @return the metadata
115      */

116     public CmsListMetadata getMetadata() {
117
118         return m_metadata;
119     }
120
121     /**
122      * Sets the object to display at the given column.<p>
123      *
124      * @param columnId the column id
125      * @param value the value to display
126      *
127      * @return the previous value, or <code>null</code> if unset
128      * @throws CmsIllegalArgumentException if the given <code>columnId</code> is invalid
129      *
130      */

131     public Object JavaDoc set(String JavaDoc columnId, Object JavaDoc value) throws CmsIllegalArgumentException {
132
133         if (getMetadata().getColumnDefinition(columnId) == null
134             && getMetadata().getItemDetailDefinition(columnId) == null) {
135             throw new CmsIllegalArgumentException(
136                 Messages.get().container(Messages.ERR_LIST_INVALID_COLUMN_1, columnId));
137         }
138         return m_values.put(columnId, value);
139     }
140 }
Popular Tags