001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1
003: * The contents of this file are subject to the Mozilla Public License Version
004: * 1.1 (the "License"); you may not use this file except in compliance with
005: * the License. You may obtain a copy of the License at
006: * http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the
011: * License.
012: *
013: * The Original Code is Riot.
014: *
015: * The Initial Developer of the Original Code is
016: * Neteye GmbH.
017: * Portions created by the Initial Developer are Copyright (C) 2006
018: * the Initial Developer. All Rights Reserved.
019: *
020: * Contributor(s):
021: * Felix Gnass [fgnass at neteye dot de]
022: *
023: * ***** END LICENSE BLOCK ***** */
024: package org.riotfamily.components.model;
025:
026: import java.util.Map;
027: import java.util.Set;
028:
029: /**
030: * Class to support staging and versioning of components. Each
031: * {@link ComponentList ComponentList} has two collections of VersionContainers,
032: * one containing the published (live) components, the other one containing
033: * preview versions. Each container may in turn have a live and a preview
034: * version of the actual component data.
035: */
036: public class VersionContainer {
037:
038: private Long id;
039:
040: private ComponentList liveList;
041:
042: private ComponentList previewList;
043:
044: private ComponentVersion liveVersion;
045:
046: private ComponentVersion previewVersion;
047:
048: private Set versions;
049:
050: private Set childLists;
051:
052: public VersionContainer() {
053: }
054:
055: public Long getId() {
056: return this .id;
057: }
058:
059: public void setId(Long id) {
060: this .id = id;
061: }
062:
063: public ComponentList getList() {
064: return this .previewList != null ? previewList : liveList;
065: }
066:
067: public void setList(ComponentList list) {
068: this .liveList = list;
069: this .previewList = list;
070: }
071:
072: public ComponentVersion getLiveVersion() {
073: return this .liveVersion;
074: }
075:
076: public void setLiveVersion(ComponentVersion liveVersion) {
077: this .liveVersion = liveVersion;
078: if (liveVersion != null) {
079: liveVersion.setContainer(this );
080: }
081: }
082:
083: public ComponentVersion getPreviewVersion() {
084: return this .previewVersion;
085: }
086:
087: public void setPreviewVersion(ComponentVersion previewVersion) {
088: this .previewVersion = previewVersion;
089: if (previewVersion != null) {
090: previewVersion.setContainer(this );
091: }
092: }
093:
094: public Set getVersions() {
095: return this .versions;
096: }
097:
098: public void setVersions(Set versions) {
099: this .versions = versions;
100: }
101:
102: public Set getChildLists() {
103: return this .childLists;
104: }
105:
106: public void setChildLists(Set childLists) {
107: this .childLists = childLists;
108: }
109:
110: public ComponentVersion getLatestVersion() {
111: return previewVersion != null ? previewVersion : liveVersion;
112: }
113:
114: public boolean isDirty() {
115: return previewVersion != null;
116: }
117:
118: public boolean isPublished() {
119: return liveVersion != null;
120: }
121:
122: public Map getProperties(boolean preview) {
123: if (preview) {
124: return getLatestVersion().getProperties();
125: }
126: return liveVersion != null ? liveVersion.getProperties() : null;
127: }
128:
129: public String getProperty(String key, boolean preview) {
130: ComponentVersion version = preview ? getLatestVersion()
131: : liveVersion;
132: return version != null ? version.getProperty(key) : null;
133: }
134:
135: }
|