001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package de.schlund.pfixcore.editor2.core.spring.internal;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.apache.log4j.Logger;
026:
027: import de.schlund.pfixcore.editor2.core.dom.Theme;
028: import de.schlund.pfixcore.editor2.core.dom.ThemeList;
029: import de.schlund.pfixcore.editor2.core.spring.ThemeFactoryService;
030: import de.schlund.pfixxml.targets.Themes;
031:
032: /**
033: * Implementation of ThemeList using de.schlund.pfixxml.targets.Themes internally.
034: *
035: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
036: * @see de.schlund.pfixxml.targets.Themes
037: */
038: public class ThemeListImpl implements ThemeList {
039: private ArrayList<Theme> themes;
040:
041: /**
042: * Creates a ThemeList object
043: *
044: * @param themes Themes object as used by the Pustefix generator
045: */
046: public ThemeListImpl(ThemeFactoryService themefactory, Themes themes) {
047: if (themes.getThemesArr().length == 0) {
048: String msg = "Themes array should not be empty!";
049: Logger.getLogger(this .getClass()).warn(msg);
050: }
051: this .themes = new ArrayList<Theme>();
052: String[] array = themes.getThemesArr();
053: for (int i = 0; i < array.length; i++) {
054: Theme theme = themefactory.getTheme(array[i]);
055: this .themes.add(theme);
056: }
057: }
058:
059: /* (non-Javadoc)
060: * @see de.schlund.pfixcore.editor2.core.dom.ThemeList#getThemes()
061: */
062: public List<Theme> getThemes() {
063: return new ArrayList<Theme>(this .themes);
064: }
065:
066: /* (non-Javadoc)
067: * @see de.schlund.pfixcore.editor2.core.dom.ThemeList#includesTheme(de.schlund.pfixcore.editor2.core.dom.Theme)
068: */
069: public boolean includesTheme(Theme theme) {
070: return this .themes.contains(theme);
071: }
072:
073: /* (non-Javadoc)
074: * @see java.lang.Object#equals(java.lang.Object)
075: */
076: public boolean equals(Object obj) {
077: if (!(obj instanceof ThemeList)) {
078: return false;
079: }
080: ThemeList list = (ThemeList) obj;
081: Iterator<Theme> i1 = this .getThemes().iterator();
082: Iterator<Theme> i2 = list.getThemes().iterator();
083: while (i1.hasNext()) {
084: if (!i2.hasNext()) {
085: return false;
086: }
087: Theme theme1 = i1.next();
088: Theme theme2 = i2.next();
089: if (!theme1.equals(theme2)) {
090: return false;
091: }
092: }
093: return !i2.hasNext();
094: }
095:
096: /* (non-Javadoc)
097: * @see java.lang.Object#hashCode()
098: */
099: public int hashCode() {
100: return ("THEMELIST: " + this .toString()).hashCode();
101: }
102:
103: /* (non-Javadoc)
104: * @see java.lang.Object#toString()
105: */
106: public String toString() {
107: StringBuffer buf = new StringBuffer();
108: for (Iterator<Theme> i = this .themes.iterator(); i.hasNext();) {
109: Theme theme = i.next();
110: buf.append(theme.getName());
111: buf.append(" ");
112: }
113: return buf.substring(0, buf.length() - 1);
114: }
115:
116: public boolean themeOverridesTheme(Theme t1, Theme t2) {
117: if (t1.equals(t2)) {
118: return false;
119: }
120:
121: for (Iterator<Theme> i = this .getThemes().iterator(); i
122: .hasNext();) {
123: Theme t = i.next();
124: if (t.equals(t1)) {
125: return true;
126: } else if (t.equals(t2)) {
127: return false;
128: }
129: }
130:
131: return false;
132: }
133: }
|