001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListItem.java,v $
003: * Date : $Date: 2008-02-27 12:05:28 $
004: * Version: $Revision: 1.13 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.list;
033:
034: import org.opencms.main.CmsIllegalArgumentException;
035:
036: import java.util.Collections;
037: import java.util.HashMap;
038: import java.util.Map;
039:
040: /**
041: * Generic list item.<p>
042: *
043: * @author Michael Moossen
044: *
045: * @version $Revision: 1.13 $
046: *
047: * @since 6.0.0
048: */
049: public class CmsListItem {
050:
051: /** Unique id for later recovery. */
052: private final String m_id;
053:
054: /** Associated list definition. */
055: private final CmsListMetadata m_metadata;
056:
057: /** Item values. */
058: private final Map m_values = new HashMap();
059:
060: /**
061: * Default Constructor.<p>
062: *
063: * @param id the id of the item has to be unique
064: * @param metadata the corresponding list definition
065: */
066: public CmsListItem(CmsListMetadata metadata, String id) {
067:
068: if (id == null) {
069: throw new CmsIllegalArgumentException(Messages.get()
070: .container(Messages.ERR_LIST_INVALID_NULL_ARG_1,
071: "id"));
072: }
073: if (metadata == null) {
074: throw new CmsIllegalArgumentException(Messages.get()
075: .container(Messages.ERR_LIST_INVALID_NULL_ARG_1,
076: "metadata"));
077: }
078: m_metadata = metadata;
079: m_id = id;
080: }
081:
082: /**
083: * Returns the value of the column for this item.<p>
084: *
085: * @param columnId the column id
086: *
087: * @return the content, may be <code>null</code>
088: *
089: * @throws CmsIllegalArgumentException if the given <code>columnId</code> is invalid
090: */
091: public Object get(String columnId)
092: throws CmsIllegalArgumentException {
093:
094: if ((getMetadata().getColumnDefinition(columnId) == null)
095: && (getMetadata().getItemDetailDefinition(columnId) == null)) {
096: throw new CmsIllegalArgumentException(Messages.get()
097: .container(Messages.ERR_LIST_INVALID_COLUMN_1,
098: columnId));
099: }
100: return m_values.get(columnId);
101: }
102:
103: /**
104: * Returns the id of the item.<p>
105: *
106: * @return the id
107: *
108: * @see CmsHtmlList#getItem(String)
109: */
110: public String getId() {
111:
112: return m_id;
113: }
114:
115: /**
116: * Returns the meta data.<p>
117: *
118: * @return the meta data
119: */
120: public CmsListMetadata getMetadata() {
121:
122: return m_metadata;
123: }
124:
125: /**
126: * Returns the value map of the list item.<p>
127: *
128: * @return the value map of the list item
129: */
130: public Map getValues() {
131:
132: return Collections.unmodifiableMap(m_values);
133: }
134:
135: /**
136: * Sets the object to display at the given column.<p>
137: *
138: * @param columnId the column id
139: * @param value the value to display
140: *
141: * @return the previous value, or <code>null</code> if not set
142: * @throws CmsIllegalArgumentException if the given <code>columnId</code> is invalid
143: *
144: */
145: public Object set(String columnId, Object value)
146: throws CmsIllegalArgumentException {
147:
148: if ((getMetadata().getColumnDefinition(columnId) == null)
149: && (getMetadata().getItemDetailDefinition(columnId) == null)) {
150: throw new CmsIllegalArgumentException(Messages.get()
151: .container(Messages.ERR_LIST_INVALID_COLUMN_1,
152: columnId));
153: }
154: return m_values.put(columnId, value);
155: }
156:
157: /**
158: * @see java.lang.Object#toString()
159: */
160: public String toString() {
161:
162: return m_values.toString();
163: }
164: }
|