1 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 ; 27 import java.util.List ; 28 import java.util.Iterator ; 29 import java.util.ArrayList ; 30 import java.util.Arrays ; 31 32 public class SiteConfImpl implements SiteConf, Comparable { 33 private String name; 34 private String title; 35 private String description; 36 private String skin; 37 private VariantKey navigationDoc; 38 private long homePageDocId; 39 private String homePage; 40 private long collectionId; 41 private boolean contextualizedTree; 42 private String 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 directory; 52 private long defaultDocumentTypeId; 53 private String publisherRequestSet; 54 private SiteSwitchingMode siteSwicthingMode; 55 private String [] switchSites; 56 private SitesManagerImpl sitesManager; 57 58 public SiteConfImpl(File directory, String name, String title, String description, String skin, long navigationDocId, 59 long homePageDocId, String homePage, long collectionId, boolean contextualizedTree, VersionState newVersionStateDefault, 60 long branchId, long languageId, long defaultDocumentTypeId, String publisherRequestSet, 61 SiteSwitchingMode siteSwitchingMode, String [] 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 (new File (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 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 getName() { 128 return name; 129 } 130 131 public String getTitle() { 132 return title; 133 } 134 135 public String getDescription() { 136 return description; 137 } 138 139 public String getSkin() { 140 return skin; 141 } 142 143 public String getCocoonSitemapLocation() { 144 return cocoonSitemap; 145 } 146 147 public String 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 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 siteConfs = sitesManager.getSiteConfs(); 191 List lookupAlternatives = new ArrayList (); 192 lookupAlternatives.add(new LookupAlternative(getName(), getCollectionId(), getNavigationDoc(), navVersionMode)); 193 194 Iterator 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 if (lookupAlternativesArray.length > 2) 206 Arrays.sort(lookupAlternativesArray, 1, lookupAlternativesArray.length); 207 208 return lookupAlternativesArray; 209 } else if (siteSwicthingMode == SiteSwitchingMode.SELECTED) { 210 List lookupAlternatives = new ArrayList (switchSites.length + 1); 211 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 ("Invalid site switching mode " + siteSwicthingMode); 222 } 223 224 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 getDirectory() { 240 return directory; 241 } 242 243 public long getDefaultDocumentTypeId() { 244 return defaultDocumentTypeId; 245 } 246 247 public int compareTo(Object o) { 248 SiteConfImpl otherSiteConf = (SiteConfImpl)o; 249 return this.name.compareTo(otherSiteConf.name); 250 } 251 } 252 | Popular Tags |