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.Collection;
022: import java.util.HashSet;
023: import java.util.Iterator;
024: import java.util.Set;
025: import java.util.TreeSet;
026:
027: import org.apache.log4j.Logger;
028:
029: import de.schlund.pfixcore.editor2.core.dom.Image;
030: import de.schlund.pfixcore.editor2.core.dom.IncludePart;
031: import de.schlund.pfixcore.editor2.core.dom.IncludePartThemeVariant;
032: import de.schlund.pfixcore.editor2.core.dom.Page;
033: import de.schlund.pfixcore.editor2.core.dom.Project;
034: import de.schlund.pfixcore.editor2.core.dom.Theme;
035: import de.schlund.pfixcore.editor2.core.dom.Variant;
036: import de.schlund.pfixcore.editor2.core.exception.EditorParsingException;
037: import de.schlund.pfixcore.editor2.core.exception.EditorSecurityException;
038: import de.schlund.pfixcore.editor2.core.spring.BackupService;
039: import de.schlund.pfixcore.editor2.core.spring.ConfigurationService;
040: import de.schlund.pfixcore.editor2.core.spring.FileSystemService;
041: import de.schlund.pfixcore.editor2.core.spring.ImageFactoryService;
042: import de.schlund.pfixcore.editor2.core.spring.IncludeFactoryService;
043: import de.schlund.pfixcore.editor2.core.spring.PathResolverService;
044: import de.schlund.pfixcore.editor2.core.spring.ProjectFactoryService;
045: import de.schlund.pfixcore.editor2.core.spring.SecurityManagerService;
046: import de.schlund.pfixcore.editor2.core.spring.ThemeFactoryService;
047: import de.schlund.pfixcore.editor2.core.spring.VariantFactoryService;
048: import de.schlund.pfixxml.resources.ResourceUtil;
049: import de.schlund.pfixxml.targets.AuxDependency;
050: import de.schlund.pfixxml.targets.AuxDependencyFactory;
051: import de.schlund.pfixxml.targets.AuxDependencyImage;
052: import de.schlund.pfixxml.targets.AuxDependencyInclude;
053: import de.schlund.pfixxml.targets.DependencyType;
054: import de.schlund.pfixxml.targets.PageInfo;
055: import de.schlund.pfixxml.targets.Target;
056: import de.schlund.pfixxml.targets.TargetDependencyRelation;
057: import de.schlund.pfixxml.targets.TargetGenerator;
058:
059: /**
060: * Implementation of IncludePartThemeVariant using a DOM tree
061: *
062: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
063: */
064: public class IncludePartThemeVariantImpl extends
065: CommonIncludePartThemeVariantImpl {
066:
067: private ProjectFactoryService projectfactory;
068:
069: private VariantFactoryService variantfactory;
070:
071: private IncludeFactoryService includefactory;
072:
073: // private ThemeFactoryService themefactory;
074:
075: private ImageFactoryService imagefactory;
076:
077: private SecurityManagerService securitymanager;
078:
079: public IncludePartThemeVariantImpl(
080: ProjectFactoryService projectfactory,
081: VariantFactoryService variantfactory,
082: IncludeFactoryService includefactory,
083: ThemeFactoryService themefactory,
084: ImageFactoryService imagefactory,
085: FileSystemService filesystem,
086: PathResolverService pathresolver,
087: ConfigurationService configuration,
088: SecurityManagerService securitymanager,
089: BackupService backup, Theme theme, IncludePart part) {
090: super (filesystem, pathresolver, configuration, backup, theme,
091: part);
092: this .projectfactory = projectfactory;
093: this .variantfactory = variantfactory;
094: this .includefactory = includefactory;
095: // this.themefactory = themefactory;
096: this .imagefactory = imagefactory;
097: this .securitymanager = securitymanager;
098: }
099:
100: private AuxDependency getAuxDependency() {
101: return AuxDependencyFactory.getInstance()
102: .getAuxDependencyInclude(
103: ResourceUtil.getFileResourceFromDocroot(this
104: .getIncludePart().getIncludeFile()
105: .getPath()),
106: this .getIncludePart().getName(),
107: this .getTheme().getName());
108: }
109:
110: /*
111: * (non-Javadoc)
112: *
113: * @see de.schlund.pfixcore.editor2.core.dom.IncludePartThemeVariant#getIncludeDependencies(boolean)
114: */
115: public Collection<IncludePartThemeVariant> getIncludeDependencies(
116: boolean recursive) throws EditorParsingException {
117: HashSet<IncludePartThemeVariant> includes = new HashSet<IncludePartThemeVariant>();
118: Collection<AuxDependency> childs = TargetDependencyRelation
119: .getInstance().getChildrenOverallForAuxDependency(
120: this .getAuxDependency());
121: if (childs == null) {
122: return includes;
123: }
124: for (Iterator<AuxDependency> i = childs.iterator(); i.hasNext();) {
125: AuxDependency child = i.next();
126: if (child.getType() == DependencyType.TEXT) {
127: IncludePartThemeVariant variant = this .includefactory
128: .getIncludePartThemeVariant(child);
129: includes.add(variant);
130: if (recursive) {
131: includes.addAll(variant
132: .getIncludeDependencies(true));
133: }
134: }
135: }
136: return includes;
137: }
138:
139: /*
140: * (non-Javadoc)
141: *
142: * @see de.schlund.pfixcore.editor2.core.dom.IncludePartThemeVariant#getImageDependencies(boolean)
143: */
144: public Collection<Image> getImageDependencies(boolean recursive)
145: throws EditorParsingException {
146: HashSet<Image> images = new HashSet<Image>();
147: Collection<AuxDependency> childs = TargetDependencyRelation
148: .getInstance().getChildrenOverallForAuxDependency(
149: this .getAuxDependency());
150: if (childs == null) {
151: return images;
152: }
153: for (Iterator<AuxDependency> i = childs.iterator(); i.hasNext();) {
154: AuxDependency child = i.next();
155: if (child.getType() == DependencyType.IMAGE) {
156: Image image = this .imagefactory
157: .getImage(((AuxDependencyImage) child)
158: .getPath().getRelativePath());
159: images.add(image);
160: } else if ((child.getType() == DependencyType.TEXT)
161: && recursive) {
162: AuxDependencyInclude aux = (AuxDependencyInclude) child;
163: IncludePartThemeVariant variant = this .includefactory
164: .getIncludePartThemeVariant(aux);
165: images.addAll(variant.getImageDependencies(true));
166: }
167: }
168: return images;
169: }
170:
171: /*
172: * (non-Javadoc)
173: *
174: * @see de.schlund.pfixcore.editor2.core.dom.IncludePartThemeVariant#getAffectedPages()
175: */
176: public Collection<Page> getAffectedPages() {
177: HashSet<PageInfo> pageinfos = new HashSet<PageInfo>();
178: HashSet<Page> pages = new HashSet<Page>();
179: Set<Target> afftargets = TargetDependencyRelation.getInstance()
180: .getAffectedTargets(this .getAuxDependency());
181: if (afftargets == null) {
182: return pages;
183: }
184:
185: for (Iterator<Target> i = afftargets.iterator(); i.hasNext();) {
186: Target pfixTarget = i.next();
187: pageinfos.addAll(pfixTarget.getPageInfos());
188: }
189:
190: for (Iterator<PageInfo> i2 = pageinfos.iterator(); i2.hasNext();) {
191: PageInfo pageinfo = i2.next();
192: Project project = projectfactory
193: .getProjectByPustefixTargetGenerator(pageinfo
194: .getTargetGenerator());
195: Variant variant = null;
196: if (pageinfo.getVariant() != null) {
197: variant = variantfactory.getVariant(pageinfo
198: .getVariant());
199: }
200: Page page = project.getPage(pageinfo.getName(), variant);
201: if (page != null) {
202: pages.add(page);
203: }
204: }
205:
206: return pages;
207: }
208:
209: public Collection<IncludePartThemeVariant> getIncludeDependencies(
210: de.schlund.pfixcore.editor2.core.dom.Target target,
211: boolean recursive) throws EditorParsingException {
212: HashSet<IncludePartThemeVariant> includes = new HashSet<IncludePartThemeVariant>();
213:
214: Collection<AuxDependency> childs = getChildrenForTarget(this
215: .getAuxDependency(), target);
216: for (Iterator<AuxDependency> i = childs.iterator(); i.hasNext();) {
217: AuxDependency child = i.next();
218: if (child.getType() == DependencyType.TEXT) {
219: IncludePartThemeVariant variant = this .includefactory
220: .getIncludePartThemeVariant(child);
221: includes.add(variant);
222: if (recursive) {
223: includes.addAll(variant
224: .getIncludeDependencies(true));
225: }
226: }
227: }
228: return includes;
229: }
230:
231: public Collection<Image> getImageDependencies(
232: de.schlund.pfixcore.editor2.core.dom.Target target,
233: boolean recursive) throws EditorParsingException {
234: HashSet<Image> images = new HashSet<Image>();
235:
236: Collection<AuxDependency> childs = getChildrenForTarget(this
237: .getAuxDependency(), target);
238: for (Iterator<AuxDependency> i = childs.iterator(); i.hasNext();) {
239: AuxDependency child = i.next();
240: if (child.getType() == DependencyType.IMAGE) {
241: Image image = this .imagefactory
242: .getImage(((AuxDependencyImage) child)
243: .getPath().getRelativePath());
244: images.add(image);
245: } else if ((child.getType() == DependencyType.TEXT)
246: && recursive) {
247: AuxDependencyInclude aux = (AuxDependencyInclude) child;
248: IncludePartThemeVariant variant = this .includefactory
249: .getIncludePartThemeVariant(aux);
250: images.addAll(variant.getImageDependencies(true));
251: }
252: }
253: return images;
254: }
255:
256: protected void securityCheckCreateIncludePartThemeVariant()
257: throws EditorSecurityException {
258: this .securitymanager.checkCreateIncludePartThemeVariant(this
259: .getIncludePart(), this .getTheme());
260: }
261:
262: protected void securityCheckEditIncludePartThemeVariant()
263: throws EditorSecurityException {
264: this .securitymanager.checkEditIncludePartThemeVariant(this );
265: }
266:
267: public Collection<Project> getAffectedProjects() {
268: HashSet<Project> projects = new HashSet<Project>();
269: Set<TargetGenerator> afftgens = TargetDependencyRelation
270: .getInstance().getAffectedTargetGenerators(
271: this .getAuxDependency());
272: if (afftgens == null) {
273: return projects;
274: }
275:
276: for (Iterator<TargetGenerator> i = afftgens.iterator(); i
277: .hasNext();) {
278: TargetGenerator tgen = i.next();
279: Project project = this .projectfactory
280: .getProjectByPustefixTargetGenerator(tgen);
281: if (project != null) {
282: projects.add(project);
283: }
284: }
285: return projects;
286: }
287:
288: protected void writeChangeLog() {
289: Logger.getLogger("LOGGER_EDITOR").warn(
290: "TXT: " + this .securitymanager.getPrincipal().getName()
291: + ": " + this .toString());
292: }
293:
294: private Set<AuxDependency> getChildrenForTarget(
295: AuxDependency parent,
296: de.schlund.pfixcore.editor2.core.dom.Target target) {
297: Target pfixTarget;
298: if (target instanceof TargetPfixImpl) {
299: pfixTarget = ((TargetPfixImpl) target).getPfixTarget();
300: } else {
301: return new TreeSet<AuxDependency>();
302: }
303: TreeSet<AuxDependency> retval = TargetDependencyRelation
304: .getInstance().getChildrenForTargetForAuxDependency(
305: pfixTarget, parent);
306: if (retval == null) {
307: return new TreeSet<AuxDependency>();
308: } else {
309: return retval;
310: }
311: }
312:
313: }
|