Java Code Examples for java.util.Properties.loadFromXML()

The following are Jave code examples for showing how to use loadFromXML() of the java.util.Properties class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: spring-seed   File: ProfileApplicationContextInitializer.java   View Source Code Vote up 6 votes
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;
}
 
Example 2
Project: openssp   File: ProjectProperty.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 3
Project: powsybl-core   File: ConversionTool.java   View Source Code Vote up 6 votes
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;
}
 
Example 4
Project: alfresco-repository   File: XmlPropertiesFileMetadataLoader.java   View Source Code Vote up 6 votes
/**
 * @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);
}
 
Example 5
Project: neoscada   File: DataStoreAccesor.java   View Source Code Vote up 6 votes
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 );
}
 
Example 6
Project: jdk8u-jdk   File: ConcurrentLoadAndStoreXML.java   View Source Code Vote up 6 votes
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;
}
 
Example 7
Project: traccar-service   File: Config.java   View Source Code Vote up 6 votes
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"));
}
 
Example 8
Project: oscm   File: PluginServiceFactory.java   View Source Code Vote up 6 votes
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;

}
 
Example 9
Project: incubator-netbeans   File: ProfilerStorageProvider.java   View Source Code Vote up 5 votes
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();
        }
    }
}
 
Example 10
Project: joanne   File: XMLManager.java   View Source Code Vote up 5 votes
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;
}
 
Example 11
Project: openjdk-jdk10   File: CompatibilityTest.java   View Source Code Vote up 5 votes
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());
    }
}
 
Example 12
Project: openjdk-jdk10   File: LoadAndStoreXML.java   View Source Code Vote up 5 votes
/**
 * 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) { }
}
 
Example 13
Project: oscm-app   File: Operation.java   View Source Code Vote up 5 votes
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;
}
 
Example 14
Project: ramus   File: RolesView.java   View Source Code Vote up 5 votes
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;
}
 
Example 15
Project: oscm   File: ServiceInstance.java   View Source Code Vote up 5 votes
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;
}
 
Example 16
Project: oscm   File: Operation.java   View Source Code Vote up 5 votes
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;
}
 
Example 17
Project: oscm   File: BillingAdapterAssembler.java   View Source Code Vote up 5 votes
static Properties convertXMLToProperties(String xmlString) {
    if (xmlString != null) {
        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;
    }
    return null;
}
 
Example 18
Project: Equella   File: PluginResourcesBundle.java   View Source Code Vote up 5 votes
@SuppressWarnings("nls")
public void addProperties(InputStream in, String prepend, boolean isXml) throws IOException
{
	Properties properties = new Properties();
	if( isXml )
	{
		properties.loadFromXML(in);
	}
	else
	{
		properties.load(new UnicodeReader(in, "UTF-8"));
	}

	for( Entry<Object, Object> entry : properties.entrySet() )
	{
		String key = (String) entry.getKey();
		if( prepend != null )
		{
			if( key == null || key.length() == 0 )
			{
				throw new Error("Missing key on language string in " + prepend + " plugin");
			}
			if( key.charAt(0) == '/' )
			{
				key = key.substring(1);
			}
			else
			{
				key = prepend + key;
			}
		}
		lookup.put(key, entry.getValue());
	}
}
 
Example 19
Project: openjdk-jdk10   File: MyResourcesProvider.java   View Source Code Vote up 4 votes
XMLResourceBundle(InputStream stream) throws IOException {
    props = new Properties();
    props.loadFromXML(stream);
}
 
Example 20
Project: util   File: DefaultPropertiesPersister.java   View Source Code Vote up 4 votes
@Override
public void loadFromXml(Properties props, InputStream is) throws IOException {
	props.loadFromXML(is);
}