001: /*
002: * Copyright 2005 Sun Microsystems, Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.roller.planet.pojos;
017:
018: import java.io.Serializable;
019: import java.util.Collection;
020: import java.util.HashSet;
021: import java.util.Iterator;
022: import java.util.Set;
023: import java.util.StringTokenizer;
024: import java.util.TreeSet;
025: import org.apache.roller.pojos.*;
026:
027: /**
028: * @struts.form include-all="true"
029: * @ejb:bean name="PlanetGroupData"
030: * @hibernate.class lazy="false" table="rag_group"
031: */
032: public class PlanetGroupData extends PersistentObject implements
033: Serializable {
034: transient private String[] catArray = null;
035:
036: /** Database ID */
037: private String id = null;
038:
039: /** Unique handle by which group may be fetched */
040: private String handle = null;
041:
042: /** Title of this group */
043: private String title = null;
044:
045: /** Description of this group */
046: private String description = null;
047:
048: /** Restrict group by this list of comma separated category names */
049: private String categoryRestriction = null;
050:
051: /** Max number of entries to show in HTML representation of this group */
052: private int maxPageEntries = 45;
053:
054: /** Max number of entries to show in feed representation of this group */
055: private int maxFeedEntries = 45;
056:
057: /** Subscriptions in this group */
058: private Set subscriptions = new HashSet();
059:
060: //------------------------------------------------------- persistent fields
061:
062: /**
063: * @ejb:persistent-field
064: * @hibernate.id column="id" generator-class="uuid.hex" unsaved-value="null"
065: */
066: public String getId() {
067: return id;
068: }
069:
070: public void setId(String id) {
071: this .id = id;
072: }
073:
074: /**
075: * @hibernate.set table="rag_group_subscription" lazy="true" invert="true" cascade="save-update"
076: * @hibernate.collection-key column="group_id"
077: * @hibernate.collection-many-to-many column="subscription_id" class="org.apache.roller.planet.pojos.PlanetSubscriptionData"
078: */
079: public Set getSubscriptions() {
080: return subscriptions;
081: }
082:
083: public void setSubscriptions(Set subscriptions) {
084: this .subscriptions = subscriptions;
085: }
086:
087: /**
088: * @hibernate.property column="cat_restriction" non-null="false" unique="false"
089: */
090: public String getCategoryRestriction() {
091: return categoryRestriction;
092: }
093:
094: public void setCategoryRestriction(String categoryRestriction) {
095: this .categoryRestriction = categoryRestriction;
096: catArray = null;
097: }
098:
099: /**
100: * @hibernate.property column="description" non-null="false" unique="false"
101: */
102: public String getDescription() {
103: return description;
104: }
105:
106: public void setDescription(String description) {
107: this .description = description;
108: }
109:
110: /**
111: * @hibernate.property column="handle" non-null="false" unique="false"
112: */
113: public String getHandle() {
114: return handle;
115: }
116:
117: public void setHandle(String handle) {
118: this .handle = handle;
119: }
120:
121: /**
122: * @hibernate.property column="max_feed_entries" non-null="false" unique="false"
123: */
124: public int getMaxFeedEntries() {
125: return maxFeedEntries;
126: }
127:
128: public void setMaxFeedEntries(int maxFeedEntries) {
129: this .maxFeedEntries = maxFeedEntries;
130: }
131:
132: /**
133: * @hibernate.property column="max_page_entries" non-null="false" unique="false"
134: */
135: public int getMaxPageEntries() {
136: return maxPageEntries;
137: }
138:
139: public void setMaxPageEntries(int maxPageEntries) {
140: this .maxPageEntries = maxPageEntries;
141: }
142:
143: /**
144: * @hibernate.property column="title" non-null="false" unique="false"
145: */
146: public String getTitle() {
147: return title;
148: }
149:
150: public void setTitle(String title) {
151: this .title = title;
152: }
153:
154: //--------------------------------------------------------------- app logic
155:
156: /**
157: * Returns true if entry is qualified for inclusion in this group.
158: */
159: public boolean qualified(PlanetEntryData entry) {
160: String[] cats = getCategoryRestrictionAsArray();
161: if (cats == null || cats.length == 0)
162: return true;
163: for (int i = 0; i < cats.length; i++) {
164: if (entry.inCategory(cats[i]))
165: return true;
166: }
167: return false;
168: }
169:
170: //------------------------------------------------------------- convenience
171:
172: private String[] getCategoryRestrictionAsArray() {
173: if (catArray == null && categoryRestriction != null) {
174: StringTokenizer toker = new StringTokenizer(
175: categoryRestriction, ",");
176: catArray = new String[toker.countTokens()];
177: int i = 0;
178:
179: while (toker.hasMoreTokens()) {
180: catArray[i++] = toker.nextToken();
181: }
182: }
183: return catArray;
184: }
185:
186: /** no-op to please XDoclet generated form */
187: private void setCategoryRestrictionAsArray(String[] ignored) {
188: }
189:
190: //---------------------------------------------------------- implementation
191:
192: public void setData(PersistentObject vo) {
193: // TODO Auto-generated method stub
194: }
195: }
|