本文整理匯總了Java中org.apache.commons.configuration.PropertiesConfiguration.setProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java PropertiesConfiguration.setProperty方法的具體用法?Java PropertiesConfiguration.setProperty怎麽用?Java PropertiesConfiguration.setProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.configuration.PropertiesConfiguration
的用法示例。
在下文中一共展示了PropertiesConfiguration.setProperty方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createDefault
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
public void createDefault() throws Exception {
if (file.exists()) {
file.renameTo(new File(Enterence.propFileName + ".bak"));
}
file.createNewFile();
PropertiesConfiguration config = new PropertiesConfiguration(
Enterence.propFileName);
config.setProperty("sudoers", Configs.sudoers);
config.setProperty("sudoPwd", Configs.sudoPwd);
config.setProperty("server", Configs.server);
config.setProperty("name", Configs.name);
config.setProperty("pwd", Configs.pwd);
config.setProperty("channels", Configs.channels);
config.setProperty("preffix", Configs.preffix);
config.setProperty("sudoers", Configs.sudoers);
config.setProperty("recordFileName", Configs.recordFileName);
config.setProperty("useProxy", Configs.useProxy);
config.setProperty("Proxy", Configs.Proxy);
config.save();
}
示例2: normalizeCommands
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
/**
* Normalize all guild commands
* @param collection All commands
* @throws ConfigurationException If apache config throws an exception
*/
private static void normalizeCommands(Collection<Command> collection) throws ConfigurationException {
Collection<File> found = FileUtils.listFiles(new File("resources/guilds"),
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
found.add(new File("resources/guilds/template.properties"));
for (File f : found) {
if (f.getName().equals("GuildProperties.properties") || f.getName().equals("template.properties")) {
PropertiesConfiguration config = new PropertiesConfiguration(f);
List<String> enabledCommands = config.getList("EnabledCommands").stream()
.map(object -> Objects.toString(object, null))
.collect(Collectors.toList());
List<String> disabledCommands = config.getList("DisabledCommands").stream()
.map(object -> Objects.toString(object, null))
.collect(Collectors.toList());
for (Command c : collection) {
if (!enabledCommands.contains(c.toString()) && !disabledCommands.contains(c.toString())) {
enabledCommands.add(c.toString());
}
}
config.setProperty("EnabledCommands", enabledCommands);
config.save();
}
}
}
示例3: save
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
public String save() {
// 設定文件初期讀入
try {
PropertiesConfiguration languageConf = new PropertiesConfiguration(Thread.currentThread()
.getContextClassLoader().getResource("language/package.properties"));
languageConf.setProperty(YiDuConfig.TITLE, Utils.escapePropterties(title));
languageConf.setProperty(YiDuConfig.SITEKEYWORDS, Utils.escapePropterties(siteKeywords));
languageConf.setProperty(YiDuConfig.SITEDESCRIPTION, Utils.escapePropterties(siteDescription));
languageConf.setProperty(YiDuConfig.NAME, Utils.escapePropterties(name));
languageConf.setProperty(YiDuConfig.URL, Utils.escapePropterties(url));
languageConf.setProperty(YiDuConfig.COPYRIGHT, Utils.escapePropterties(copyright));
languageConf.setProperty(YiDuConfig.BEIANNO, Utils.escapePropterties(beianNo));
languageConf.setProperty(YiDuConfig.ANALYTICSCODE, Utils.escapePropterties(analyticscode));
languageConf.setProperty(YiDuConfig.CATEGORY, Utils.escapePropterties(category));
File languageFile = new File(languageConf.getPath());
OutputStream out = new FileOutputStream(languageFile);
languageConf.save(out);
} catch (Exception e) {
addActionError(e.getMessage());
logger.error(e);
return ADMIN_ERROR;
}
loadData();
addActionMessage(getText("messages.save.success"));
return INPUT;
}
示例4: updateMandatoryProperties
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
private void updateMandatoryProperties(final UpgradeResult result, File configDir) throws ConfigurationException,
IOException
{
PropertyFileModifier propMod = new PropertyFileModifier(new File(configDir,
PropertyFileModifier.MANDATORY_CONFIG))
{
@Override
protected boolean modifyProperties(PropertiesConfiguration props)
{
// Add Tomcat ports
String url = (String) props.getProperty("admin.url");
String port = getPort(url);
String tomcatComment = System.lineSeparator()
+ "# Tomcat ports. Specify the ports Tomcat should create connectors for";
PropertiesConfigurationLayout layout = props.getLayout();
layout.setLineSeparator(System.lineSeparator());
if( url.contains("https") )
{
String httpsProp = "https.port";
props.setProperty(httpsProp, port);
layout.setComment(httpsProp, tomcatComment);
props.setProperty("#http.port", "");
}
else
{
String httpProp = "http.port";
props.setProperty(httpProp, port);
layout.setComment(httpProp, tomcatComment);
props.setProperty("#https.port", "");
}
props.setProperty("#ajp.port", "8009");
// Remove Tomcat location
props.clearProperty("tomcat.location");
return true;
}
};
propMod.updateProperties();
}
示例5: upgrade
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
@SuppressWarnings("nls")
@Override
public void upgrade(UpgradeResult result, File tleInstallDir) throws Exception
{
PropertyFileModifier modifier = new PropertyFileModifier(new File(new File(tleInstallDir, CONFIG_FOLDER),
PropertyFileModifier.HIBERNATE_CONFIG))
{
@Override
protected boolean modifyProperties(PropertiesConfiguration props)
{
String dialect = props.getString(HIBERNATE_DIALECT);
String newdialect = null;
if( dialect.equals("org.hibernate.dialect.PostgreSQLDialect") )
{
newdialect = "com.tle.hibernate.dialect.ExtendedPostgresDialect";
}
else if( dialect.equals("org.hibernate.dialect.Oracle10gDialect") )
{
newdialect = "com.tle.hibernate.dialect.ExtendedOracle10gDialect";
}
else if( dialect.equals("org.hibernate.dialect.Oracle9iDialect")
|| dialect.equals("org.hibernate.dialect.Oracle9Dialect") )
{
newdialect = "com.tle.hibernate.dialect.ExtendedOracle9iDialect";
}
if( newdialect != null )
{
props.setProperty(HIBERNATE_DIALECT, newdialect);
return true;
}
return false;
}
};
modifier.updateProperties();
}
示例6: checkPropertyException
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
/**
* Helper to check for the correct exception and message
*
* @param key
*/
private void checkPropertyException(final String key) {
PropertiesConfiguration props = loadProperties();
try {
props.setProperty(key, null);
new AdapterConfig(props);
Assert.fail("Expected an IllegalArgumentException");
} catch (AdapterConfigException ex) {
Assert.assertEquals(key + " is missing in file filePath", ex.getMessage());
}
}
示例7: setUserValues
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
private void setUserValues(String propName, String propValue){
try {
PropertiesConfiguration config = new PropertiesConfiguration(extFolder+propFileName);
config.setProperty(propName, propValue);
config.save();
//logger.info(config.getPath());
} catch (Exception e) {
logger(logger,"error", e.getMessage());
}
}
示例8: loadData
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
@Override
protected void loadData() {
if (StringUtils.isEmpty(uv)) {
addActionError(getText("errors.not.exsits.upgradeVersion"));
return;
}
// step1下載安裝包並解壓縮
logger.info("going to download upgrade file : " + uv + ".zip");
ZIP_FILE_URL = SITE_URL + uv + ".zip";
String currentPath = UpgradeAction.class.getClassLoader().getResource("").getPath();
File f = new File(currentPath).getParentFile().getParentFile();
INPUT_ZIP_FILE = f.getAbsolutePath() + File.separator + "tmp" + File.separator + uv + ".zip";
OUTPUT_FOLDER = f.getAbsolutePath() + File.separator + "tmp" + File.separator + uv + File.separator;
BASE_FOLDER = f.getAbsolutePath() + File.separator;
downloadFile();
if (this.hasErrors()) {
return;
}
logger.info("going to unzip upgrade file : " + uv + ".zip");
unZipFile();
if (this.hasErrors()) {
return;
}
// 讀取rules文件
String content = readFileByLines(OUTPUT_FOLDER + "rule");
Gson g = new Gson();
List<UpgradeBean> upgradeList = g.fromJson(content, new TypeToken<List<UpgradeBean>>() {
}.getType());
for (UpgradeBean rb : upgradeList) {
switch (rb.getType()) {
case FileType.STATIC:
case FileType.CLASS:
case FileType.FTL:
case FileType.JSP:
case FileType.XML:
// 替換或添加靜態文件,class文件,ftl,jsp
// 直接覆蓋
File srcFile = new File(OUTPUT_FOLDER + rb.getPath());
File destFile = new File(BASE_FOLDER + rb.getPath());
try {
FileUtils.copyFile(srcFile, destFile);
} catch (IOException e1) {
// TODO Auto-generated catch block
logger.error(e1.getMessage(), e1);
addActionError(e1.getMessage());
return;
}
break;
case FileType.PROPERTIES:
// 修改properties文件
try {
PropertiesConfiguration propertiesFile = new PropertiesConfiguration(Thread.currentThread().getContextClassLoader()
.getResource(rb.getFileName()));
propertiesFile.setProperty(rb.getKey(), rb.getContent());
File jdbcFile = new File(propertiesFile.getPath());
OutputStream out = new FileOutputStream(jdbcFile);
propertiesFile.save(out);
} catch (Exception e) {
addActionError(e.getMessage());
logger.error(e);
}
break;
case FileType.SQL:
// 執行文件
upgradeService.excuteUpgradeSql(rb.getSql());
break;
default:
break;
}
}
}
示例9: changeKey
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
private boolean changeKey(PropertiesConfiguration props, String suffix, boolean clearOnly)
{
String eventServiceVal = props.getString(EVENT_SERVICE_PREFIX + suffix);
String sessionServiceVal = props.getString(USER_SESSION_SERVICE_PREFIX + suffix);
String useVal = (eventServiceVal == null ? sessionServiceVal : eventServiceVal);
if( useVal != null )
{
if( !clearOnly )
{
props.setProperty(CHANNEL_SERVICE_PREFIX + suffix, useVal);
}
props.clearProperty(EVENT_SERVICE_PREFIX + suffix);
props.clearProperty(USER_SESSION_SERVICE_PREFIX + suffix);
return true;
}
return false;
}