1 package com.openedit.modules.archive; 2 3 import java.util.List ; 4 import java.util.Map ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 import com.openedit.OpenEditException; 10 import com.openedit.WebPageRequest; 11 import com.openedit.archive.Archive; 12 import com.openedit.archive.ImageMaker; 13 import com.openedit.archive.authenticate.WindowsAuthentication; 14 import com.openedit.error.EmailErrorHandler; 15 import com.openedit.modules.admin.AdminModule; 16 import com.openedit.modules.admin.filemanager.FileUpload; 17 import com.openedit.modules.cart.StoreDataReader; 18 import com.openedit.modules.search.LuceneHitTracker; 19 import com.openedit.modules.store.BaseStoreModule; 20 import com.openedit.page.Page; 21 import com.openedit.store.Product; 22 import com.openedit.store.Store; 23 import com.openedit.store.StoreException; 24 import com.openedit.users.User; 25 import com.openedit.util.PathUtilities; 26 public class ArchiveModule extends BaseStoreModule 27 { 28 private static final Log log = LogFactory.getLog(ArchiveModule.class); 29 private EmailErrorHandler fieldEmailErrorHandler; 30 public ArchiveModule() 31 { 32 } 33 34 44 public Archive getArchive( WebPageRequest inReq ) throws OpenEditException 45 { 46 Store store = getStore(inReq); 47 String id = Archive.ARCHIVE_PARAM + store.getCatalogId() + inReq.getUserName(); 48 Archive archive = (Archive) inReq.getSessionValue( id ); 49 50 if ( archive == null ) 51 { 52 archive = createArchive( inReq ); 53 inReq.putSessionValue( id, archive ); 54 } 55 inReq.putPageValue("cataloghome", archive.getCatalogHome() ); 56 inReq.putPageValue("store",archive.getStore()); 57 inReq.putPageValue("archive",archive); 58 return archive; 59 } 60 69 protected Archive createArchive( WebPageRequest inRequest ) throws OpenEditException 70 { 71 Archive archive = new Archive(); 72 archive.setUser(inRequest.getUser()); 73 archive.setStore( getStore( inRequest ) ); 74 archive.setPageManager(getPageManager()); 75 archive.setEmailErrorHandler(fieldEmailErrorHandler); 76 archive.reladSettings(); 77 return archive; 78 } 79 80 85 public void updateHeaders( WebPageRequest inRequest ) 86 throws OpenEditException 87 { 88 Archive archive = getArchive( inRequest ); 89 archive.updateHeaders(); 90 } 91 public void login(WebPageRequest inReq) throws OpenEditException 98 { 99 String account = inReq.getRequestParameter("accountname"); 100 101 if ( account != null ) 102 { 103 User user = getUserManager().getUser( account ); 104 String password = inReq.getRequestParameter("password"); 105 106 if( user == null || !getUserManager().authenticate(user, password) ) 107 { 108 String domain = inReq.getRequestParameter("domain"); 109 WindowsAuthentication nt = new WindowsAuthentication(); 111 112 if( !nt.login(account,password, domain) ) 113 { 114 inReq.putPageValue("oe-exception","Could not log into Windows domain as user " + account); 115 return; 116 } 117 if( user == null) 118 { 119 120 String groupname = inReq.getPage().get("autologingroup"); 121 if( groupname != null) 122 { 123 log.info("Creating " + groupname + " user " + account); 124 user = getUserManager().createGuestUser(account, password, groupname); 125 } 126 else 127 { 128 inReq.putPageValue("oe-exception","No autologingroup group configured"); 129 return; 130 } 131 } 132 } 133 inReq.putSessionValue( "user", user ); 134 135 AdminModule umodule = (AdminModule)getModule("Admin"); 136 umodule.savePasswordAsCookie(user,inReq); 137 String sendTo = inReq.getRequestParameter("loginokpage"); 138 139 if( sendTo == null) 140 { 141 String sendToOld = (String )inReq.getSessionValue("originalEntryPage"); 142 String referrer = inReq.getRequest().getHeader("REFERER"); 143 if ( sendToOld != null && !sendToOld.equals(referrer)) { 145 sendTo = sendToOld; 146 } 147 inReq.removeSessionValue( "originalEntryPage" ); 148 } 149 150 inReq.redirect(sendTo); 151 } 152 153 } 154 public void createLogin(WebPageRequest inReq) throws OpenEditException 155 { 156 String username = inReq.getCurrentAction().getChildValue("username"); 159 if ( username == null) 160 { 161 username = "production"; 162 } 163 164 User user = getUserManager().getUser(username); 165 166 AdminModule umodule = (AdminModule)getModule("Admin"); 167 umodule.savePasswordAsCookie(user,inReq); 168 inReq.putSessionValue("user",user); 169 inReq.removeSessionValue("catalogTree"); } 171 public void createThumbAndMedium(WebPageRequest inReq) throws Exception  172 { 173 ImageMaker maker = new ImageMaker(); 174 maker.setArchive(getArchive(inReq)); 175 maker.run(); 176 177 } 178 179 public void voteUp(WebPageRequest inReq) throws Exception  180 { 181 String id = inReq.getRequestParameter("productid"); 182 if ( id != null) 183 { 184 Archive archive = getArchive(inReq); 185 Product product = archive.getProduct(id); 186 String vote = product.get("votecount"); 187 int val = 1; 188 if ( vote != null) 189 { 190 val = Integer.parseInt(vote); 191 val++; 192 } 193 product.putAttribute("votecount",String.valueOf( val) ); 194 archive.getStore().saveProduct(product); 195 reloadSearch(inReq, archive); 196 197 } 198 } 199 200 public void voteDown(WebPageRequest inReq) throws Exception  201 { 202 String id = inReq.getRequestParameter("productid"); 203 if ( id != null) 204 { 205 Archive archive = getArchive(inReq); 206 Product product = archive.getProduct(id); 207 String vote = product.get("votecount"); 208 int val = 0; 209 if ( vote != null) 210 { 211 val = Integer.parseInt(vote); 212 val--; 213 } 214 if ( val < 0) 215 { 216 val = 0; 217 } 218 product.putAttribute("votecount",String.valueOf( val) ); 219 archive.getStore().saveProduct(product); 220 221 reloadSearch(inReq, archive); 222 } 223 } 224 225 protected void reloadSearch(WebPageRequest inReq, Archive archive) throws StoreException 226 { 227 LuceneHitTracker tracker = (LuceneHitTracker)inReq.getPageValue("hits"); 228 if( tracker != null) 229 { 230 int oldNum = tracker.getPage(); 231 LuceneHitTracker tracker2 = archive.getStore().search( tracker.getQuery(), tracker.getOrdering() ); 232 tracker2.setPage(oldNum); 233 inReq.putSessionValue("hits",tracker2); 234 inReq.putPageValue("hits",tracker2); 235 } 236 } 237 238 public void toggleSlideshow(WebPageRequest inReq) throws Exception  239 { 240 Archive archive = getArchive(inReq); 241 archive.setSlideshow(archive.isSlideshow()); 242 } 243 public void uploadNewRecords(WebPageRequest inReq) throws Exception  244 { 245 246 FileUpload command = new FileUpload(); 247 command.setPageManager(getPageManager()); 248 Map properties = command.parseArguments(inReq); 249 if ( properties == null) 250 { 251 return; 252 } 253 String name = (String )properties.get("uploadedfilename"); 254 name = PathUtilities.extractFileName(name); 256 Archive archive = getArchive(inReq); 257 258 String saveas = archive.getCatalogHome() + "/uploads/" + name; 261 262 command.saveFile(properties,saveas,inReq); 263 264 String notes = inReq.getRequestParameter("notes"); 265 266 267 archive.recordUploaded(saveas, notes); 268 } 269 public void backUpOriginals( WebPageRequest inReq) throws Exception  270 { 271 ImageMaker maker = new ImageMaker(); 272 maker.setArchive(getArchive(inReq)); 273 maker.backUpOriginals(); 274 } 275 276 public Store getStore(WebPageRequest inPageRequest) throws OpenEditException 277 { 278 Page page = inPageRequest.getPage(); 279 String readername = null; 280 if( page != null) 281 { 282 readername = page.get("storereadername"); 283 } 284 if( readername == null) 285 { 286 readername = "AssetStoreDataReader"; 287 } 288 StoreDataReader reader = (StoreDataReader)getModuleManager().getBean(readername); 289 Store store = reader.getStore(page); 290 return store; 291 } 292 293 public void convertData(WebPageRequest inPageRequest) throws Exception  294 { 295 Store store = getStore(inPageRequest); 296 297 List errorlog = store.convertCatalog(); 298 if (inPageRequest != null) 299 { 300 inPageRequest.removeSessionValue("store"); 301 inPageRequest.putPageValue("exception-report", errorlog); 302 } 303 } 304 public void reIndexStore(WebPageRequest inPageRequest) throws Exception  305 { 306 Store store = getStore(inPageRequest); 307 308 store.reindexAll(); 309 store.getCatalogArchive().reloadCatalogs(); 310 } 311 public void clearSearchIndex(WebPageRequest inPageRequest) throws Exception  312 { 313 Store store = getStore(inPageRequest); 314 315 store.getStoreSearcher().clearIndex(); 316 } 317 318 public EmailErrorHandler getEmailErrorHandler() { 319 return fieldEmailErrorHandler; 320 } 321 322 public void setEmailErrorHandler(EmailErrorHandler fieldEmailErrorHandler) { 323 this.fieldEmailErrorHandler = fieldEmailErrorHandler; 324 } 325 public void toggleProperty(WebPageRequest inReq) throws Exception  326 { 327 User user = inReq.getUser(); 328 if( user != null) 329 { 330 String id = inReq.getRequestParameter("id"); 331 if( id != null) 332 { 333 boolean has = user.hasProperty(id); 334 if( has) 335 { 336 user.remove(id); 337 } 338 else 339 { 340 user.put(id, String.valueOf(has)); 341 } 342 getUserManager().saveUser(user); 343 } 344 } 345 } 346 public void changeHitsPerPage(WebPageRequest inReq) throws Exception  347 { 348 String count = inReq.getRequestParameter("count"); 349 if( count != null) 350 { 351 Archive archive = getArchive(inReq); 352 archive.setHitsPerPage(Integer.parseInt(count)); 353 } 354 } 355 } 356
| Popular Tags
|