1 package org.tigris.scarab.actions.admin; 2 3 48 49 import java.util.Iterator ; 51 52 import org.apache.commons.collections.IteratorUtils; 53 import org.apache.commons.collections.iterators.EnumerationIterator; 54 import org.apache.commons.configuration.CompositeConfiguration; 55 import org.apache.commons.configuration.PropertiesConfiguration; 56 import org.apache.fulcrum.parser.ParameterParser; 57 import org.apache.turbine.RunData; 58 import org.apache.turbine.TemplateContext; 59 import org.apache.turbine.Turbine; 60 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 61 import org.tigris.scarab.tools.localization.L10NKeySet; 62 import org.tigris.scarab.util.comparators.StartsWithPredicate; 63 64 70 public class AppConfigurationSettings 71 extends RequireLoginFirstAction 72 { 73 74 public void doSave(RunData data, TemplateContext context) 75 throws Exception 76 { 77 boolean customSettingsChanged = false; 78 ParameterParser pp = data.getParameters(); 79 CompositeConfiguration c = (CompositeConfiguration)Turbine.getConfiguration(); 80 PropertiesConfiguration customSettings =null; 81 for (int i = 0;i<c.getNumberOfConfigurations();i++){ 82 if(c.getConfiguration(i) instanceof PropertiesConfiguration){ 83 PropertiesConfiguration pc = (PropertiesConfiguration)c.getConfiguration(i); 84 if(pc.getFileName().endsWith("custom.properties")){ 85 customSettings = pc; 86 break; 87 } 88 } 89 } 90 91 if (customSettings==null){ 92 throw new Exception ("custom.properties file was not defined in TurbineConfiguration.xml"); 93 } 94 95 for (Iterator i = 96 IteratorUtils.filteredIterator( 97 new EnumerationIterator(pp.keys()), 98 new StartsWithPredicate("configuration.key.")); 99 i.hasNext(); 100 ) 101 { 102 String key = (String ) i.next(); 103 String realKey = pp.getString(key); 104 String value = pp.getString("configuration.value." + realKey); 105 106 if (!Turbine.getConfiguration().getString(realKey).equals(value)){ 107 Turbine.getConfiguration().setProperty(realKey,value); 108 customSettings.setProperty(realKey,value); 109 customSettingsChanged=true; 110 } 111 112 } 113 if (customSettingsChanged){ 114 customSettings.save(); 115 } 116 117 118 getScarabRequestTool(context).setConfirmMessage(L10NKeySet.AppConfigurationChangesSaved); 119 } 120 } 121 | Popular Tags |