KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > components > siteconf > SiteConfImpl


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.frontend.components.siteconf;
17
18 import org.outerj.daisy.repository.VersionState;
19 import org.outerj.daisy.repository.LockType;
20 import org.outerj.daisy.repository.VariantKey;
21 import org.outerj.daisy.navigation.LookupAlternative;
22 import org.outerj.daisy.navigation.NavigationVersionMode;
23 import org.outerj.daisy.frontend.WikiVersionMode;
24 import org.apache.cocoon.xml.SaxBuffer;
25
26 import java.io.File JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Arrays JavaDoc;
31
32 public class SiteConfImpl implements SiteConf, Comparable JavaDoc {
33     private String JavaDoc name;
34     private String JavaDoc title;
35     private String JavaDoc description;
36     private String JavaDoc skin;
37     private VariantKey navigationDoc;
38     private long homePageDocId;
39     private String JavaDoc homePage;
40     private long collectionId;
41     private boolean contextualizedTree;
42     private String JavaDoc cocoonSitemap;
43     private VersionState newVersionStateDefault;
44     private boolean automaticLocking;
45     private LockType lockType;
46     private long defaultLockTime;
47     private boolean autoExtendLock;
48     private SaxBuffer skinConf;
49     private long branchId;
50     private long languageId;
51     private File JavaDoc directory;
52     private long defaultDocumentTypeId;
53     private String JavaDoc publisherRequestSet;
54     private SiteSwitchingMode siteSwicthingMode;
55     private String JavaDoc[] switchSites;
56     private SitesManagerImpl sitesManager;
57
58     public SiteConfImpl(File JavaDoc directory, String JavaDoc name, String JavaDoc title, String JavaDoc description, String JavaDoc skin, long navigationDocId,
59             long homePageDocId, String JavaDoc homePage, long collectionId, boolean contextualizedTree, VersionState newVersionStateDefault,
60             long branchId, long languageId, long defaultDocumentTypeId, String JavaDoc publisherRequestSet,
61             SiteSwitchingMode siteSwitchingMode, String JavaDoc[] switchSites, SitesManagerImpl sitesManager) {
62         this.name = name;
63         this.title = title;
64         this.description = description;
65         this.skin = skin;
66         this.navigationDoc = new VariantKey(navigationDocId, branchId, languageId);
67         this.homePageDocId = homePageDocId;
68         this.homePage = homePage;
69         if (this.homePage == null)
70             this.homePage = String.valueOf(homePageDocId) + ".html";
71         this.collectionId = collectionId;
72         this.contextualizedTree = contextualizedTree;
73         this.newVersionStateDefault = newVersionStateDefault;
74         this.automaticLocking = false;
75         this.branchId = branchId;
76         this.languageId = languageId;
77         this.directory = directory;
78         this.defaultDocumentTypeId = defaultDocumentTypeId;
79         this.sitesManager = sitesManager;
80         this.publisherRequestSet = publisherRequestSet;
81         this.siteSwicthingMode = siteSwitchingMode;
82         this.switchSites = switchSites;
83
84         cocoonSitemap = new File JavaDoc(new File JavaDoc(directory, "cocoon"), "sitemap.xmap").toURI().toString();
85     }
86
87     protected void setAutomaticLocking(boolean automaticLocking) {
88         this.automaticLocking = automaticLocking;
89     }
90
91     public void setAutoExtendLock(boolean autoExtendLock) {
92         this.autoExtendLock = autoExtendLock;
93     }
94
95     public void setLockType(LockType lockType) {
96         this.lockType = lockType;
97     }
98
99     public void setDefaultLockTime(long defaultLockTime) {
100         this.defaultLockTime = defaultLockTime;
101     }
102
103     public VariantKey getNavigationDoc() {
104         return navigationDoc;
105     }
106
107     public long getNavigationDocId() {
108         return navigationDoc.getDocumentId();
109     }
110
111     public long getHomePageDocId() {
112         return homePageDocId;
113     }
114
115     public String JavaDoc getHomePage() {
116         return homePage;
117     }
118
119     public long getCollectionId() {
120         return collectionId;
121     }
122
123     public boolean contextualizedTree() {
124         return contextualizedTree;
125     }
126
127     public String JavaDoc getName() {
128         return name;
129     }
130
131     public String JavaDoc getTitle() {
132         return title;
133     }
134
135     public String JavaDoc getDescription() {
136         return description;
137     }
138
139     public String JavaDoc getSkin() {
140         return skin;
141     }
142
143     public String JavaDoc getCocoonSitemapLocation() {
144         return cocoonSitemap;
145     }
146
147     public String JavaDoc getGlobalCocoonSitemapLocation() {
148         return sitesManager.getGlobalCocoonSitemapLocation();
149     }
150
151     public VersionState getNewVersionStateDefault() {
152         return newVersionStateDefault;
153     }
154
155     public boolean getAutomaticLocking() {
156         return automaticLocking;
157     }
158
159     public LockType getLockType() {
160         return lockType;
161     }
162
163     public long getDefaultLockTime() {
164         return defaultLockTime;
165     }
166
167     public boolean getAutoExtendLock() {
168         return autoExtendLock;
169     }
170
171     public SaxBuffer getSkinConf() {
172         if (skinConf != null)
173             return skinConf;
174         else
175             return sitesManager.getGlobalSkinConf();
176     }
177
178     public String JavaDoc getPublisherRequestSet() {
179         if (this.publisherRequestSet != null)
180             return publisherRequestSet;
181         else
182             return sitesManager.getGlobalPublisherRequestSet();
183     }
184
185     public LookupAlternative[] getNavigationLookupAlternatives(WikiVersionMode versionMode) {
186         NavigationVersionMode navVersionMode = versionMode.getNavigationVersionMode();
187         if (siteSwicthingMode == SiteSwitchingMode.STAY) {
188             return new LookupAlternative[] { new LookupAlternative(getName(), getCollectionId(), getNavigationDoc(), navVersionMode) };
189         } else if (siteSwicthingMode == SiteSwitchingMode.ALL) {
190             List JavaDoc siteConfs = sitesManager.getSiteConfs();
191             List JavaDoc lookupAlternatives = new ArrayList JavaDoc();
192             lookupAlternatives.add(new LookupAlternative(getName(), getCollectionId(), getNavigationDoc(), navVersionMode));
193
194             Iterator JavaDoc siteConfsIt = siteConfs.iterator();
195             while (siteConfsIt.hasNext()) {
196                 SiteConf siteConf = (SiteConf)siteConfsIt.next();
197                 if (!siteConf.getName().equals(name)) {
198                     lookupAlternatives.add(new LookupAlternative(siteConf.getName(), siteConf.getCollectionId(), siteConf.getNavigationDoc(), navVersionMode));
199                 }
200             }
201
202             LookupAlternative[] lookupAlternativesArray = (LookupAlternative[])lookupAlternatives.toArray(new LookupAlternative[lookupAlternatives.size()]);
203
204             // To have consistent results, sort the list of sites (excluding the current site, which should always stay at position 0)
205
if (lookupAlternativesArray.length > 2)
206                 Arrays.sort(lookupAlternativesArray, 1, lookupAlternativesArray.length);
207
208             return lookupAlternativesArray;
209         } else if (siteSwicthingMode == SiteSwitchingMode.SELECTED) {
210             List JavaDoc lookupAlternatives = new ArrayList JavaDoc(switchSites.length + 1);
211             // Add current site as first entry
212
lookupAlternatives.add(new LookupAlternative(getName(), getCollectionId(), getNavigationDoc(), navVersionMode));
213             for (int i = 0; i < switchSites.length; i++) {
214                 SiteConf siteConf = sitesManager.getSiteConfSoftly(switchSites[i]);
215                 if (siteConf != null)
216                     lookupAlternatives.add(new LookupAlternative(siteConf.getName(), siteConf.getCollectionId(),
217                             siteConf.getNavigationDoc(), navVersionMode));
218             }
219             return (LookupAlternative[])lookupAlternatives.toArray(new LookupAlternative[lookupAlternatives.size()]);
220         }
221         throw new RuntimeException JavaDoc("Invalid site switching mode " + siteSwicthingMode);
222     }
223
224     /**
225      * @param skinConf a SaxBuffer not containing startDocument and endDocument events.
226      */

227     protected void setSkinConf(SaxBuffer skinConf) {
228         this.skinConf = skinConf;
229     }
230
231     public long getBranchId() {
232         return branchId;
233     }
234
235     public long getLanguageId() {
236         return languageId;
237     }
238
239     public File JavaDoc getDirectory() {
240         return directory;
241     }
242
243     public long getDefaultDocumentTypeId() {
244         return defaultDocumentTypeId;
245     }
246
247     public int compareTo(Object JavaDoc o) {
248         SiteConfImpl otherSiteConf = (SiteConfImpl)o;
249         return this.name.compareTo(otherSiteConf.name);
250     }
251 }
252
Popular Tags