当前位置: 首页>>代码示例>>Java>>正文


Java Properties.loadFromXML方法代码示例

本文整理汇总了Java中java.util.Properties.loadFromXML方法的典型用法代码示例。如果您正苦于以下问题:Java Properties.loadFromXML方法的具体用法?Java Properties.loadFromXML怎么用?Java Properties.loadFromXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Properties的用法示例。


在下文中一共展示了Properties.loadFromXML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadPropertiesFromPaths

import java.util.Properties; //导入方法依赖的package包/类
private static Properties loadPropertiesFromPaths(ResourceLoader resourceLoader, List<String> paths) {
	Properties configurationProperties = new Properties();
	for (String path : paths) {
		Resource resource = resourceLoader.getResource(path);
		InputStream is = null;
		try {
			is = resource.getInputStream();
			Properties properties = new Properties();
			properties.loadFromXML(is);
			configurationProperties.putAll(properties);
		} catch (IOException ex) {
			log.error("Failed to load configuration properties. Resource - " + path, ex);
		} finally {
			try {
				if (is != null) {
					is.close();
				}
			} catch (IOException ioe) {
				// ignore
				ioe.printStackTrace();
			}
		}
	}
	return configurationProperties;
}
 
开发者ID:profullstack,项目名称:spring-seed,代码行数:26,代码来源:ProfileApplicationContextInitializer.java

示例2: getRuntimeProperties

import java.util.Properties; //导入方法依赖的package包/类
/**
 * Return runtime properties of given {@code runtimeProperties}. Looks first, if application is running on a dev machine and returns in this case the
 * properties from the resource context. Otherwise a lookup in properties folder in webapps context is fullfilled.
 * 
 * @param runtimeProperties
 * @return properties {@link Properties}
 * @throws PropertyException
 */
public static Properties getRuntimeProperties(final String runtimeProperties) throws PropertyException {
	if (runtimeProperties == null || runtimeProperties.length() == 0) {
		throw new PropertyException("path may not be empty or null");
	}

	final Properties properties = new Properties();
	final String fileType = runtimeProperties.substring(runtimeProperties.lastIndexOf(".") + 1, runtimeProperties.length());
	final File propFile = readFile(runtimeProperties);
	try (FileInputStream fi = new FileInputStream(propFile);) {
		if ("xml".equals(fileType)) {
			properties.loadFromXML(fi);
		} else {
			properties.load(fi);
		}
	} catch (final IOException e) {
		System.err.println(ProjectProperty.class.getSimpleName() + " IOException for " + runtimeProperties + " " + e.getMessage());
	}
	return properties;
}
 
开发者ID:ad-tech-group,项目名称:openssp,代码行数:28,代码来源:ProjectProperty.java

示例3: readProperties

import java.util.Properties; //导入方法依赖的package包/类
Properties readProperties(CommandLine line, OptionType optionType, ToolRunningContext context) throws IOException {
    Properties properties = new Properties();

    // Read the parameters file
    String filename = line.getOptionValue(optionType.getLongOpt(), null);
    if (filename != null) {
        try (InputStream inputStream = Files.newInputStream(context.getFileSystem().getPath(filename))) {
            if (filename.endsWith(".xml")) {
                properties.loadFromXML(inputStream);
            } else {
                properties.load(inputStream);
            }
        }
    }

    // Append parameters from the command line
    properties.putAll(line.getOptionProperties(Character.toString(optionType.getShortOpt())));

    return properties;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:21,代码来源:ConversionTool.java

示例4: loadMetadataFromFile

import java.util.Properties; //导入方法依赖的package包/类
/**
 * @see AbstractMapBasedMetadataLoader#loadMetadataFromFile(java.io.File)
 */
@Override
protected Map<String,Serializable> loadMetadataFromFile(Path metadataFile)
{
    Map<String,Serializable> result = null;
    
    try
    {
        Properties props = new Properties();
        props.loadFromXML(new BufferedInputStream(Files.newInputStream(metadataFile)));
        result = new HashMap<String,Serializable>((Map)props);

        // MNT-18001
        removeProtectedProperties(result);
    }
    catch (final IOException ioe)
    {
        if (log.isWarnEnabled()) log.warn("Metadata file '" + FileUtils.getFileName(metadataFile) + "' could not be read.", ioe);
    }
    
    return(result);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:25,代码来源:XmlPropertiesFileMetadataLoader.java

示例5: DataStoreAccesor

import java.util.Properties; //导入方法依赖的package包/类
public DataStoreAccesor ( final File basePath, final DataFilePool pool ) throws Exception
{
    this.basePath = basePath;
    this.pool = pool;

    if ( !basePath.isDirectory () )
    {
        throw new IllegalStateException ( String.format ( "'%s' is not a directory", basePath ) );
    }

    final Properties p = new Properties ();
    p.loadFromXML ( new FileInputStream ( new File ( basePath, "settings.xml" ) ) );

    this.time = Long.parseLong ( p.getProperty ( "time" ) );
    this.unit = TimeUnit.valueOf ( p.getProperty ( "unit" ) );
    this.count = Integer.parseInt ( p.getProperty ( "count" ) );
    this.quantizer = new Quantizer ( this.time, this.unit, this.count );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DataStoreAccesor.java

示例6: call

import java.util.Properties; //导入方法依赖的package包/类
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ConcurrentLoadAndStoreXML.java

示例7: load

import java.util.Properties; //导入方法依赖的package包/类
void load(String file) throws IOException {
    Properties mainProperties = new Properties();
    try (InputStream inputStream = new FileInputStream(file)) {
        mainProperties.loadFromXML(inputStream);
    }

    String defaultConfigFile = mainProperties.getProperty("config.default");
    if (defaultConfigFile != null) {
        try (InputStream inputStream = new FileInputStream(defaultConfigFile)) {
            properties.loadFromXML(inputStream);
        }
    }

    properties.putAll(mainProperties); // override defaults

    useEnvironmentVariables = Boolean.parseBoolean(System.getenv("CONFIG_USE_ENVIRONMENT_VARIABLES"))
            || Boolean.parseBoolean(properties.getProperty("config.useEnvironmentVariables"));
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:19,代码来源:Config.java

示例8: getConnectionProperties

import java.util.Properties; //导入方法依赖的package包/类
protected static Properties getConnectionProperties(
        BillingAdapter billingAdapter) throws BillingApplicationException {
    Properties connectionProperties = new Properties();
    if (billingAdapter.getConnectionProperties() != null) {
        try (InputStream in = IOUtils.toInputStream(
                billingAdapter.getConnectionProperties(),
                StandardCharsets.UTF_8.toString());) {
            connectionProperties.loadFromXML(in);
        } catch (IOException e) {
            throw new BillingApplicationException(
                    "No Connection to Billing Adapter",
                    new BillingAdapterConnectionException(
                            "Unable to load Connection properties", e));
        }
    } else {
        throw new BillingApplicationException(
                "No Connection to Billing Adapter",
                new BillingAdapterConnectionException(
                        "Connection properties are missing"));
    }
    return connectionProperties;

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:PluginServiceFactory.java

示例9: loadProperties

import java.util.Properties; //导入方法依赖的package包/类
protected void loadProperties(Properties properties, FileObject storage) throws IOException {
    synchronized (this) {
        InputStream is = storage.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        try {
            properties.loadFromXML(bis);
        } finally {
            bis.close();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ProfilerStorageProvider.java

示例10: getFoldersList

import java.util.Properties; //导入方法依赖的package包/类
private Properties getFoldersList() throws FileNotFoundException, IOException{
    Properties p = new Properties();
            
        if(Files.exists(new File(PATH).toPath())){
            FileInputStream in = new FileInputStream(new File(PATH));
            p.loadFromXML(in);
            BiConsumer<Object,Object> bi = (x,y) ->{
                p.getProperty(x.toString(), new File(y.toString()).getName());
            };
            p.forEach(bi);

        }
        return p;
}
 
开发者ID:Obsidiam,项目名称:joanne,代码行数:15,代码来源:XMLManager.java

示例11: loadPropertyFile

import java.util.Properties; //导入方法依赖的package包/类
static void loadPropertyFile(String filename) {
    try (InputStream in = new FileInputStream(filename)) {
        Properties prop = new Properties();
        prop.loadFromXML(in);
        verifyProperites(prop);
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:CompatibilityTest.java

示例12: testLoadWithBadEncoding

import java.util.Properties; //导入方法依赖的package包/类
/**
 * Test loadFromXML with unsupported encoding
 */
static void testLoadWithBadEncoding() throws IOException {
    System.out.println("testLoadWithBadEncoding");
    String s = "<?xml version=\"1.0\" encoding=\"BAD\"?>" +
               "<!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\">" +
               "<properties>" +
               "<entry key=\"foo\">bar</entry>" +
               "</properties>";
    ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes("UTF-8"));
    Properties props = new Properties();
    try {
        props.loadFromXML(in);
        throw new RuntimeException("UnsupportedEncodingException expected");
    } catch (UnsupportedEncodingException expected) { }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:LoadAndStoreXML.java

示例13: convertXMLToProperties

import java.util.Properties; //导入方法依赖的package包/类
Properties convertXMLToProperties(String xmlString) {
    Properties properties = new Properties();
    try (InputStream in = new ByteArrayInputStream(xmlString.getBytes())) {
        properties.loadFromXML(in);
    } catch (IOException e) {
        LOGGER.logError(Log4jLogger.SYSTEM_LOG, e,
                LogMessageIdentifier.ERROR);
    }
    return properties;
}
 
开发者ID:servicecatalog,项目名称:oscm-app,代码行数:11,代码来源:Operation.java

示例14: getProperties

import java.util.Properties; //导入方法依赖的package包/类
private Properties getProperties() {
    Properties properties = new Properties();
    final InputStream is = getNamedData(PROPERTIES);
    if (is != null) {
        try {
            properties.loadFromXML(is);
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }
    return properties;
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:13,代码来源:RolesView.java

示例15: convertXMLToProperties

import java.util.Properties; //导入方法依赖的package包/类
Properties convertXMLToProperties(String xmlString) {
    Properties properties = new Properties();
    try (InputStream in = new ByteArrayInputStream(xmlString.getBytes())) {
        properties.loadFromXML(in);
    } catch (IOException e) {
        throw new RuntimeException();
    }
    return properties;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:10,代码来源:ServiceInstance.java


注:本文中的java.util.Properties.loadFromXML方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。