1 4 package org.roller.business; 5 6 import org.apache.commons.lang.StringUtils; 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 import org.roller.RollerException; 10 import org.roller.model.ConfigManager; 11 import org.roller.model.Roller; 12 import org.roller.pojos.RollerConfigData; 13 import org.roller.util.OldRollerConfig; 14 15 import java.io.FileInputStream ; 16 import java.io.FileNotFoundException ; 17 import java.math.BigDecimal ; 18 19 24 public abstract class ConfigManagerImpl implements ConfigManager { 25 26 private static Log mLogger = 27 LogFactory.getFactory().getInstance(ConfigManagerImpl.class); 28 29 protected PersistenceStrategy mStrategy; 30 31 public ConfigManagerImpl(PersistenceStrategy strategy) 32 { 33 mStrategy = strategy; 34 } 35 36 public void release() 37 { 38 } 39 40 43 public void storeRollerConfig(RollerConfigData data) throws RollerException 44 { 45 mStrategy.store(data); 46 } 47 48 53 private RollerConfigData newConfigFromFile(OldRollerConfig file) throws RollerException 54 { 55 RollerConfigData config = new RollerConfigData(); 56 config.setAbsoluteURL ( file.getAbsoluteURL() ); 57 config.setRssUseCache ( Boolean.valueOf(file.getRssUseCache()) ); 58 config.setRssCacheTime ( new Integer (file.getRssCacheTime()) ); 59 config.setNewUserAllowed ( Boolean.valueOf(file.getNewUserAllowed()) ); 60 config.setAdminUsers ( StringUtils.join( file.getAdminUsers().toArray(), ",") ); 61 config.setUserThemes ( file.getNewUserThemes() ); 62 config.setEditorPages ( StringUtils.join( file.getEditorPages().toArray(), ",") ); 63 config.setEnableAggregator ( Boolean.valueOf(file.getEnableAggregator()) ); 64 config.setUploadEnabled ( Boolean.valueOf(file.getUploadEnabled()) ); 65 config.setUploadMaxDirMB ( new BigDecimal (file.getUploadMaxDirMB().doubleValue()).setScale(2) ); 66 config.setUploadMaxFileMB ( new BigDecimal (file.getUploadMaxFileMB().doubleValue()).setScale(2) ); 67 config.setUploadAllow ( StringUtils.join( file.getUploadAllow().toArray(), ",") ); 68 config.setUploadForbid ( StringUtils.join( file.getUploadForbid().toArray(), ",") ); 69 config.setUploadDir ( file.getUploadDir() ); 70 config.setUploadPath ( file.getUploadPath() ); 71 config.setMemDebug ( Boolean.valueOf(file.getMemDebug()) ); 72 config.setAutoformatComments ( Boolean.valueOf(file.getAutoformatComments()) ); 73 config.setEscapeCommentHtml ( Boolean.valueOf(file.getEscapeCommentHtml()) ); 74 config.setEmailComments ( Boolean.valueOf(file.getEmailComments()) ); 75 config.setEnableLinkback ( Boolean.valueOf(file.isEnableLinkback()) ); 76 config.setSiteName ( file.getSiteName() ); 77 config.setSiteDescription ( file.getSiteDescription() ); 78 config.setEmailAddress ( file.getEmailAddress() ); 79 config.setIndexDir ( file.getIndexDir() ); 80 config.setEncryptPasswords( Boolean.valueOf(file.getEncryptPasswords()) ); 81 return config; 82 } 83 84 89 public RollerConfigData readFromFile(String filePath) throws RollerException 90 { 91 OldRollerConfig file = null; 93 java.io.InputStream in = null; 94 try 95 { 96 in = new FileInputStream (filePath); 97 file = OldRollerConfig.readConfig(in); 98 } 99 catch (FileNotFoundException fnf) 100 { 101 mLogger.info("roller-config.xml not found, creating new: "+ filePath); 102 return new RollerConfigData(); 103 } 104 catch (SecurityException se) 105 { 106 throw new RuntimeException (se); 107 } 108 finally 109 { 110 try 111 { 112 if (in != null) 113 in.close(); 114 } 115 catch (java.io.IOException ioe) 116 { 117 mLogger.warn("ERROR closing InputStream", ioe); 118 } 119 } 120 121 if (file == null) 122 { 123 file = new OldRollerConfig(); 124 mLogger.warn("Unable to read in roller-config.xml, creating 'blank' RollerConfigFile"); 125 } 126 return newConfigFromFile(file); 127 } 128 129 134 public void removeRollerConfig(String id) throws RollerException 135 { 136 mStrategy.remove(id,RollerConfigData.class); 137 } 138 } 139 | Popular Tags |