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;
020:
021: import java.util.Collections;
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import org.apache.log4j.Logger;
026:
027: import de.schlund.pfixcore.editor2.core.dom.IncludeFile;
028: import de.schlund.pfixcore.editor2.core.dom.IncludePart;
029: import de.schlund.pfixcore.editor2.core.dom.IncludePartThemeVariant;
030: import de.schlund.pfixcore.editor2.core.dom.Theme;
031: import de.schlund.pfixcore.editor2.core.exception.EditorParsingException;
032: import de.schlund.pfixcore.editor2.core.spring.internal.IncludeFileImpl;
033: import de.schlund.pfixcore.editor2.core.spring.internal.IncludePartThemeVariantImpl;
034: import de.schlund.pfixxml.targets.AuxDependency;
035: import de.schlund.pfixxml.targets.AuxDependencyInclude;
036: import de.schlund.pfixxml.targets.DependencyType;
037:
038: /**
039: * Implementation of IncludeFactoryService using Pustefix IncludeDocumentFactory
040: *
041: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
042: */
043: public class IncludeFactoryServiceImpl implements IncludeFactoryService {
044: private Map<String, IncludeFile> cache;
045:
046: private Map<AuxDependency, IncludePartThemeVariant> auxdepMap;
047:
048: private ThemeFactoryService themefactory;
049:
050: private ProjectFactoryService projectfactory;
051:
052: private VariantFactoryService variantfactory;
053:
054: private IncludeFactoryService includefactory;
055:
056: private ImageFactoryService imagefactory;
057:
058: private PathResolverService pathresolver;
059:
060: private FileSystemService filesystem;
061:
062: private ConfigurationService configuration;
063:
064: private SecurityManagerService securitymanager;
065:
066: private BackupService backup;
067:
068: public void setProjectFactoryService(
069: ProjectFactoryService projectfactory) {
070: this .projectfactory = projectfactory;
071: }
072:
073: public void setThemeFactoryService(ThemeFactoryService themefactory) {
074: this .themefactory = themefactory;
075: }
076:
077: public void setVariantFactoryService(
078: VariantFactoryService variantfactory) {
079: this .variantfactory = variantfactory;
080: }
081:
082: public void setIncludeFactoryService(
083: IncludeFactoryService includefactory) {
084: this .includefactory = includefactory;
085: }
086:
087: public void setImageFactoryService(ImageFactoryService imagefactory) {
088: this .imagefactory = imagefactory;
089: }
090:
091: public void setPathResolverService(PathResolverService pathresolver) {
092: this .pathresolver = pathresolver;
093: }
094:
095: public void setFileSystemService(FileSystemService filesystem) {
096: this .filesystem = filesystem;
097: }
098:
099: public void setConfigurationService(
100: ConfigurationService configuration) {
101: this .configuration = configuration;
102: }
103:
104: public void setSecurityManagerService(
105: SecurityManagerService securitymanager) {
106: this .securitymanager = securitymanager;
107: }
108:
109: public void setBackupService(BackupService backup) {
110: this .backup = backup;
111: }
112:
113: public IncludeFactoryServiceImpl() {
114: this .cache = Collections
115: .synchronizedMap(new HashMap<String, IncludeFile>());
116: this .auxdepMap = new HashMap<AuxDependency, IncludePartThemeVariant>();
117: }
118:
119: /*
120: * (non-Javadoc)
121: *
122: * @see de.schlund.pfixcore.editor2.core.spring.IncludeFactoryService#createIncludeFile(java.lang.String)
123: */
124: public IncludeFile getIncludeFile(String filename)
125: throws EditorParsingException {
126: if (cache.containsKey(filename)) {
127: return (IncludeFile) cache.get(filename);
128: }
129:
130: synchronized (cache) {
131: if (!cache.containsKey(filename)) {
132: IncludeFile incfile = new IncludeFileImpl(themefactory,
133: includefactory, this .projectfactory,
134: this .filesystem, this .pathresolver,
135: this .backup, this .securitymanager, filename);
136: cache.put(filename, incfile);
137: }
138: }
139: return (IncludeFile) cache.get(filename);
140: }
141:
142: private IncludePartThemeVariant getIncludePartThemeVariant(
143: Theme theme, IncludePart part) {
144: return new IncludePartThemeVariantImpl(this .projectfactory,
145: this .variantfactory, this .includefactory,
146: this .themefactory, this .imagefactory, this .filesystem,
147: this .pathresolver, this .configuration,
148: this .securitymanager, this .backup, theme, part);
149: }
150:
151: public IncludePartThemeVariant getIncludePartThemeVariant(
152: AuxDependency auxdep) throws EditorParsingException {
153: if (auxdep.getType() == DependencyType.TEXT) {
154: AuxDependencyInclude aux = (AuxDependencyInclude) auxdep;
155: synchronized (this .auxdepMap) {
156: IncludePartThemeVariant variant = this .auxdepMap
157: .get(aux);
158: if (variant != null) {
159: return variant;
160: }
161: variant = getIncludePartThemeVariant(this .themefactory
162: .getTheme(aux.getTheme()),
163: this .includefactory.getIncludeFile(
164: aux.getPath().getRelativePath())
165: .createPart(aux.getPart()));
166: this .auxdepMap.put(aux, variant);
167: return variant;
168: }
169: } else {
170: String err = "Supplied AuxDependency is not of type DependencyType.TEXT!";
171: Logger.getLogger(this .getClass()).error(err);
172: throw new RuntimeException(err);
173: }
174: }
175:
176: }
|