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.Collection;
023: import java.util.Collections;
024: import java.util.HashSet;
025: import java.util.List;
026:
027: import de.schlund.pfixcore.editor2.core.dom.AbstractPage;
028: import de.schlund.pfixcore.editor2.core.dom.Page;
029: import de.schlund.pfixcore.editor2.core.dom.Project;
030: import de.schlund.pfixcore.editor2.core.dom.Target;
031: import de.schlund.pfixcore.editor2.core.dom.Theme;
032: import de.schlund.pfixcore.editor2.core.dom.ThemeList;
033: import de.schlund.pfixcore.editor2.core.dom.Variant;
034: import de.schlund.pfixcore.editor2.core.spring.PustefixTargetUpdateService;
035: import de.schlund.pfixcore.editor2.core.spring.TargetFactoryService;
036: import de.schlund.pfixcore.editor2.core.spring.ThemeFactoryService;
037: import de.schlund.pfixxml.targets.PageInfoFactory;
038: import de.schlund.pfixxml.targets.TargetGenerationException;
039:
040: /**
041: * Implementation of Page using classes from PFIXCORE
042: *
043: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
044: */
045: public class PageImpl extends AbstractPage implements MutablePage {
046: private String name;
047:
048: private Variant variant;
049:
050: private ProjectImpl project;
051:
052: private TargetFactoryService targetfactory;
053:
054: private PustefixTargetUpdateService updater;
055:
056: private ArrayList<Page> childPages = new ArrayList<Page>();
057:
058: private ThemeFactoryService themefactory;
059:
060: private String handlerPath;
061:
062: /**
063: * Creates a page using the specified parameters
064: *
065: * @param targetfactory
066: * Reference to the TargetFactoryService
067: * @param updater
068: * Reference to the PustefixTargetUpdateService
069: * @param themefactory
070: * Reference to the ThemesFactoryService
071: * @param pageName
072: * Name of the page to create (without variant)
073: * @param variant
074: * Variant of the page (or <code>null</code> for default)
075: * @param project
076: * Project this page belongs to
077: */
078: public PageImpl(TargetFactoryService targetfactory,
079: PustefixTargetUpdateService updater,
080: ThemeFactoryService themefactory, String pageName,
081: Variant variant, Project project) {
082: this .targetfactory = targetfactory;
083: this .name = pageName;
084: this .variant = variant;
085:
086: // Cast without check
087: // There is no other implementation of Project
088: // and even if there was one, we would have no
089: // chance than throwing an exception
090: this .project = (ProjectImpl) project;
091: this .updater = updater;
092: this .themefactory = themefactory;
093: }
094:
095: /*
096: * (non-Javadoc)
097: *
098: * @see de.schlund.pfixcore.editor2.core.dom.Page#getName()
099: */
100: public String getName() {
101: return this .name;
102: }
103:
104: /*
105: * (non-Javadoc)
106: *
107: * @see de.schlund.pfixcore.editor2.core.dom.Page#getVariant()
108: */
109: public Variant getVariant() {
110: return this .variant;
111: }
112:
113: /*
114: * (non-Javadoc)
115: *
116: * @see de.schlund.pfixcore.editor2.core.dom.Page#getHandlerPath()
117: */
118: public String getHandlerPath() {
119: return this .handlerPath;
120: }
121:
122: public void setHandlerPath(String path) {
123: this .handlerPath = path;
124: }
125:
126: /*
127: * (non-Javadoc)
128: *
129: * @see de.schlund.pfixcore.editor2.core.dom.Page#getPageTarget()
130: */
131: public Target getPageTarget() {
132: return this .targetfactory.getTargetFromPustefixTarget(this
133: .getPfixTarget(), this .project);
134: }
135:
136: /*
137: * (non-Javadoc)
138: *
139: * @see de.schlund.pfixcore.editor2.core.dom.Page#getThemes()
140: */
141: public ThemeList getThemes() {
142: de.schlund.pfixxml.targets.Target target = this .getPfixTarget();
143: if (target == null) {
144: return new ThemeList() {
145:
146: public List<Theme> getThemes() {
147: return Collections.emptyList();
148: }
149:
150: public boolean includesTheme(Theme theme) {
151: return false;
152: }
153:
154: public boolean themeOverridesTheme(Theme t1, Theme t2) {
155: return false;
156: }
157: };
158: }
159: return new ThemeListImpl(this .themefactory, target.getThemes());
160: }
161:
162: /*
163: * (non-Javadoc)
164: *
165: * @see de.schlund.pfixcore.editor2.core.dom.Page#getProject()
166: */
167: public Project getProject() {
168: return this .project;
169: }
170:
171: /*
172: * (non-Javadoc)
173: *
174: * @see de.schlund.pfixcore.editor2.core.dom.Page#getSubPages()
175: */
176: public Collection<Page> getSubPages() {
177: HashSet<Page> pages = new HashSet<Page>(this .childPages);
178: return pages;
179: }
180:
181: public void setSubPages(Collection<Page> pages) {
182: this .childPages = new ArrayList<Page>(pages);
183: }
184:
185: public void registerForUpdate() {
186: if (this .getPfixTarget() != null) {
187: this .updater.registerTargetForUpdate(this .getPfixTarget());
188: }
189: }
190:
191: public void update() {
192: if (this .getPfixTarget() == null) {
193: return;
194: }
195: try {
196: this .getPfixTarget().getValue();
197: } catch (TargetGenerationException e) {
198: // Ignore errors during target generation
199: }
200: }
201:
202: private de.schlund.pfixxml.targets.Target getPfixTarget() {
203: return project.getTargetGenerator().getPageTargetTree()
204: .getTargetForPageInfo(
205: PageInfoFactory.getInstance().getPage(
206: project.getTargetGenerator(),
207: this.getName(),
208: (variant == null) ? null : this.variant
209: .getName()));
210: }
211:
212: }
|