當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。