Java Code Examples for org.apache.commons.configuration.XMLConfiguration

The following are top voted examples for showing how to use org.apache.commons.configuration.XMLConfiguration. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: KernelHive   File: EngineGraphConfiguration.java   Source Code and License 6 votes vote down vote up
@Override
public void saveGraphForEngine(
		final List<EngineGraphNodeDecorator> graphNodes, final File file)
		throws ConfigurationException {
	final XMLConfiguration tempConfig = (XMLConfiguration) config.clone();
	try {
		config.clear();
		config.setRootNode(tempConfig.getRootNode());
		config.getRootNode().removeChildren();
		final List<ConfigurationNode> inputDataURLNodes = tempConfig
				.getRootNode().getChildren(INPUT_DATA_NODE);
		for (final ConfigurationNode node : inputDataURLNodes) {
			config.getRootNode().addChild(node);
		}
		for (final EngineGraphNodeDecorator engineNode : graphNodes) {
			config.getRoot().addChild(createGraphNodeForEngine(engineNode));
		}
		config.save(file);
	} catch (final ConfigurationException e) {
		config = tempConfig;
		config.save(file);
		throw e;
	}

}
 
Example 2
Project: KernelHive   File: GUIGraphConfiguration.java   Source Code and License 6 votes vote down vote up
@Override
public List<GUIGraphNodeDecorator> loadGraphForGUI(File file)
		throws ConfigurationException {
	XMLConfiguration temp = (XMLConfiguration) config.clone();
	try {
		config.clear();
		config.setFile(file);
		config.load();
		// config.validate();//TODO attach schema
		return loadGraphFromXMLForGUI();
	} catch (ConfigurationException e) {
		LOG.severe("KH: could not load gui graph from file: "
				+ file.getPath() + " " + e.getMessage());
		config = temp;
		config.save();
		throw e;
	}
}
 
Example 3
Project: KernelHive   File: GUIGraphConfiguration.java   Source Code and License 6 votes vote down vote up
@Override
public void saveGraphForGUI(List<GUIGraphNodeDecorator> guiGraphNodes,
		File file) throws ConfigurationException {
	XMLConfiguration tempConfig = (XMLConfiguration) config.clone();
	try {
		config.clear();
		config.setRootNode(tempConfig.getRootNode());
		config.getRootNode().removeChildren();
		for (GUIGraphNodeDecorator guiNode : guiGraphNodes) {
			config.getRoot().addChild(createGraphNodeForGUI(guiNode, file));
		}
		config.save(file);
	} catch (ConfigurationException e) {
		config = tempConfig;
		config.save(file);
		throw e;
	}
}
 
Example 4
Project: KernelHive   File: AbstractGraphConfiguration.java   Source Code and License 6 votes vote down vote up
@Override
public void saveGraph(final List<IGraphNode> nodes, final File file)
		throws ConfigurationException {
	final XMLConfiguration tempConfig = (XMLConfiguration) config.clone();
	try {
		config.clear();
		config.setRootNode(tempConfig.getRootNode());
		config.getRootNode().removeChildren();
		for (final IGraphNode node : nodes) {
			config.getRoot().addChild(createGraphNode(node));
		}
		config.save(file);
	} catch (final ConfigurationException e) {
		config = tempConfig;
		config.save(file);
		throw e;
	}
}
 
Example 5
Project: HTAPBench   File: ResultUploader.java   Source Code and License 6 votes vote down vote up
public ResultUploader(Results r, XMLConfiguration conf, CommandLine argsLine) {
    this.expConf = conf;
    this.results = r;
    this.argsLine = argsLine;

    dbUrl = expConf.getString("DBUrl");
    dbType = expConf.getString("dbtype");
    username = expConf.getString("username");
    password = expConf.getString("password");
    benchType = argsLine.getOptionValue("b");
    windowSize = Integer.parseInt(argsLine.getOptionValue("s"));
    uploadCode = expConf.getString("uploadCode");
    uploadUrl = expConf.getString("uploadUrl");

    this.collector = DBParameterCollectorGen.getCollector(dbType, dbUrl, username, password);
}
 
Example 6
Project: athena   File: YangXmlUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieves a valid XML configuration for a specific XML path for a single
 * instance of the Map specified key-value pairs.
 *
 * @param file   path of the file to be used.
 * @param values map of key and values to set under the generic path.
 * @return Hierarchical configuration containing XML with values.
 */
public XMLConfiguration getXmlConfiguration(String file, Map<String, String> values) {
    InputStream stream = getCfgInputStream(file);
    XMLConfiguration cfg = loadXml(stream);
    XMLConfiguration complete = new XMLConfiguration();
    List<String> paths = new ArrayList<>();
    Map<String, String> valuesWithKey = new HashMap<>();
    values.keySet().stream().forEach(path -> {
        List<String> allPaths = findPaths(cfg, path);
        String key = nullIsNotFound(allPaths.isEmpty() ? null : allPaths.get(0),
                                    "Yang model does not contain desired path");
        paths.add(key);
        valuesWithKey.put(key, values.get(path));
    });
    Collections.sort(paths, new StringLengthComparator());
    paths.forEach(key -> complete.setProperty(key, valuesWithKey.get(key)));
    addProperties(cfg, complete);
    return complete;
}
 
Example 7
Project: athena   File: YangXmlUtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests getting a single object configuration via passing the path and the map of the desired values.
 *
 * @throws ConfigurationException if the testing xml file is not there.
 */
@Test
public void testGetXmlConfigurationFromMap() throws ConfigurationException {
    Map<String, String> pathAndValues = new HashMap<>();
    pathAndValues.put("capable-switch.id", "openvswitch");
    pathAndValues.put("switch.id", "ofc-bridge");
    pathAndValues.put("controller.id", "tcp:1.1.1.1:1");
    pathAndValues.put("controller.ip-address", "1.1.1.1");
    XMLConfiguration cfg = utils.getXmlConfiguration(OF_CONFIG_XML_PATH, pathAndValues);
    testCreateConfig.load(getClass().getResourceAsStream("/testCreateSingleYangConfig.xml"));
    assertNotEquals("Null testConfiguration", new XMLConfiguration(), testCreateConfig);

    assertEquals("Wrong configuaration", IteratorUtils.toList(testCreateConfig.getKeys()),
                 IteratorUtils.toList(cfg.getKeys()));

    assertEquals("Wrong string configuaration", utils.getString(testCreateConfig),
                 utils.getString(cfg));
}
 
Example 8
Project: athena   File: YangXmlUtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests getting a multiple object nested configuration via passing the path
 * and a list of YangElements containing with the element and desired value.
 *
 * @throws ConfigurationException
 */
@Test
public void getXmlConfigurationFromYangElements() throws ConfigurationException {

    assertNotEquals("Null testConfiguration", new XMLConfiguration(), testCreateConfig);
    testCreateConfig.load(getClass().getResourceAsStream("/testYangConfig.xml"));
    List<YangElement> elements = new ArrayList<>();
    elements.add(new YangElement("capable-switch", ImmutableMap.of("id", "openvswitch")));
    elements.add(new YangElement("switch", ImmutableMap.of("id", "ofc-bridge")));
    List<ControllerInfo> controllers =
            ImmutableList.of(new ControllerInfo(IpAddress.valueOf("1.1.1.1"), 1, "tcp"),
                             new ControllerInfo(IpAddress.valueOf("2.2.2.2"), 2, "tcp"));
    controllers.stream().forEach(cInfo -> {
        elements.add(new YangElement("controller", ImmutableMap.of("id", cInfo.target(),
                                                                   "ip-address", cInfo.ip().toString())));
    });
    XMLConfiguration cfg =
            new XMLConfiguration(YangXmlUtils.getInstance()
                                         .getXmlConfiguration(OF_CONFIG_XML_PATH, elements));
    assertEquals("Wrong configuaration", IteratorUtils.toList(testCreateConfig.getKeys()),
                 IteratorUtils.toList(cfg.getKeys()));
    assertEquals("Wrong string configuaration", utils.getString(testCreateConfig),
                 utils.getString(cfg));
}
 
Example 9
Project: openNaEF   File: ConfigUtil.java   Source Code and License 6 votes vote down vote up
@Override
public boolean validate(XMLConfiguration conf) {
    value = conf.getString(paramName);
    if (value == null) {
        if (isNullOk) return true;
        return false;
    }
    try {
        DateFormat format = new SimpleDateFormat(DATE_STRING_FORMAT);
        format.parse(value);
        return true;
    } catch (ParseException e) {
        log.debug("", e);
        validateFalse();
    }
    return false;
}
 
Example 10
Project: openNaEF   File: ConfigUtil.java   Source Code and License 6 votes vote down vote up
@Override
public boolean validate(XMLConfiguration conf) {
    value = conf.getString(paramName);
    if (value == null) {
        if (isNullOk) return true;
        return false;
    }
    try {
        if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value))
            return true;
    } catch (Exception e) {
        log.debug("", e);
        validateFalse();
    }
    return false;
}
 
Example 11
Project: openNaEF   File: ConfigUtil.java   Source Code and License 6 votes vote down vote up
@Override
public boolean validate(XMLConfiguration conf) {
    value = conf.getString(paramName);
    if (value == null) {
        if (isNullOk) return true;
        return false;
    }
    try {
        Integer.parseInt(value);
        return true;
    } catch (Exception e) {
        log.debug("", e);
        validateFalse();
    }
    return false;
}
 
Example 12
Project: openNaEF   File: ConfigUtil.java   Source Code and License 6 votes vote down vote up
@Override
public boolean validate(XMLConfiguration conf) {
    value = conf.getString(paramName);
    if (value == null) {
        if (isNullOk) return true;
        return false;
    }
    try {
        int i = Integer.parseInt(value);
        return i >= border;
    } catch (Exception e) {
        log.debug("", e);
        validateFalse();
    }
    return false;
}
 
Example 13
Project: openNaEF   File: NmsCorePseudoWireConfiguration.java   Source Code and License 6 votes vote down vote up
@Override
protected boolean loadExtraConfigration() throws IOException {
    try {
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(getConfigFile());

        for (Object obj : config.getRootNode().getChildren()) {
            Node node = (Node) obj;
            if (node.getName().equals(KEY_RELATED_LSP_FIELD_NAME)) {
                setRelatedRsvplspFieldName((String) node.getValue());
                return true;
            }
        }
    } catch (ConfigurationException e) {
        log.error(e.getMessage(), e);
        throw new IOException("failed to reload config: " + getConfigFile());
    }
    return false;
}
 
Example 14
Project: openNaEF   File: NmsCoreRsvpLspConfiguration.java   Source Code and License 6 votes vote down vote up
@Override
protected boolean loadExtraConfigration() throws IOException {
    try {
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(getConfigFile());

        for (Object obj : config.getRootNode().getChildren()) {
            Node node = (Node) obj;
            if (node.getName().equals(KEY_HOP_IP_PATH_FIELD_NAME)) {
                List<String> values = new ArrayList<String>();

                for (Object value : node.getChildren()) {
                    values.add((String) ((Node) value).getValue());
                }
                setHopIpPathFieldsName(values);
                return true;
            }
        }
    } catch (ConfigurationException e) {
        log.error(e.getMessage(), e);
        throw new IOException("failed to reload config: " + getConfigFile());
    }
    return false;
}
 
Example 15
Project: openNaEF   File: BuilderConfiguration.java   Source Code and License 6 votes vote down vote up
@Override
protected synchronized void reloadConfigurationInner() throws IOException {
    try {
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(getConfigFile());

        String __isSystemUserUpdateEnabled = config.getString(KEY_ENABLE_SYSTEM_USER_UPDATE);
        boolean _isSystemUserUpdateEnabled = (__isSystemUserUpdateEnabled == null ? false :
                Boolean.parseBoolean(__isSystemUserUpdateEnabled));

        this.isSystemUserUpdateEnabled = _isSystemUserUpdateEnabled;

        log().info("isSystemUserUpdateEnabled=" + this.isSystemUserUpdateEnabled);
        log().info("reload finished.");
    } catch (ConfigurationException e) {
        log().error(e.getMessage(), e);
        throw new IOException("failed to reload config: " + FILE_NAME);
    }
}
 
Example 16
Project: java-cme-mdp3-handler   File: Configuration.java   Source Code and License 6 votes vote down vote up
/**
 * Loads and parse CME MDP Configuration.
 *
 * @param uri URI to CME MDP Configuration (config.xml, usually available on CME FTP)
 * @throws ConfigurationException if failed to parse configuration file
 * @throws MalformedURLException  if URI to Configuration is malformed
 */
private void load(final URI uri) throws ConfigurationException, MalformedURLException {
    // todo: if to implement the same via standard JAXB then dep to apache commons configuration will be not required
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.setDelimiterParsingDisabled(true);
    configuration.load(uri.toURL());
    for (final HierarchicalConfiguration channelCfg : configuration.configurationsAt("channel")) {
        final ChannelCfg channel = new ChannelCfg(channelCfg.getString("[@id]"), channelCfg.getString("[@label]"));

        for (final HierarchicalConfiguration connCfg : channelCfg.configurationsAt("connections.connection")) {
            final String id = connCfg.getString("[@id]");
            final FeedType type = FeedType.valueOf(connCfg.getString("type[@feed-type]"));
            final TransportProtocol protocol = TransportProtocol.valueOf(connCfg.getString("protocol").substring(0, 3));
            final Feed feed = Feed.valueOf(connCfg.getString("feed"));
            final String ip = connCfg.getString("ip");
            final int port = connCfg.getInt("port");
            final List<String> hostIPs = Arrays.asList(connCfg.getStringArray("host-ip"));

            final ConnectionCfg connection = new ConnectionCfg(feed, id, type, protocol, ip, hostIPs, port);
            channel.addConnection(connection);
            connCfgs.put(connection.getId(), connection);
        }
        channelCfgs.put(channel.getId(), channel);
    }
}
 
Example 17
Project: LiteGraph   File: GraphFactory.java   Source Code and License 6 votes vote down vote up
private static Configuration getConfiguration(final File configurationFile) {
    if (!configurationFile.isFile())
        throw new IllegalArgumentException(String.format("The location configuration must resolve to a file and [%s] does not", configurationFile));

    try {
        final String fileName = configurationFile.getName();
        final String fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);

        switch (fileExtension) {
            case "yml":
            case "yaml":
                final YamlConfiguration config = new YamlConfiguration();
                config.load(configurationFile);
                return config;
            case "xml":
                return new XMLConfiguration(configurationFile);
            default:
                return new PropertiesConfiguration(configurationFile);
        }
    } catch (final ConfigurationException e) {
        throw new IllegalArgumentException(String.format("Could not load configuration at: %s", configurationFile), e);
    }
}
 
Example 18
Project: javaDemo   File: readMultiNode.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws ConfigurationException {
    XMLConfiguration config = new XMLConfiguration("CourseManagementSystem.xml");
    List techIdList = config.getList("Teachers.Teacher.id");
    for (Object id : techIdList) {
        System.out.println(id);
    }
}
 
Example 19
Project: gateway   File: TestConfiguration.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws ConfigurationException {
		
//		// create new configuration file
//		XMLConfiguration config = new XMLConfiguration();
//		config.setProperty("key", "value");
//		config.save("./config.xml");
		
		XMLConfiguration config = new XMLConfiguration("./config.xml");
		
		int numberOfWirings = config.getList("wirings.wiring.input").size();
		System.out.println("Found " + numberOfWirings + " wiring(s)");
		
		for (int index = 0; index < numberOfWirings; index++) {
			String path = "wirings.wiring(" + index + ")";
			String input = config.getString(path + ".input");
			String output = config.getString(path + ".output");
			config.getString(path + ".test"); // returns null because element not available
			
			System.out.println("Wiring: input=" + input + " output=" + output);
		}
		
	}
 
Example 20
Project: JavaDesignPattern   File: CarFactory2.java   Source Code and License 6 votes vote down vote up
public static Car newCar() {
	Car car = null;
	String name = null;
	try {
		XMLConfiguration config = new XMLConfiguration("car.xml");
		name = config.getString("factory2.class");
	} catch (ConfigurationException ex) {
		LOG.error("Parsing xml configuration file failed", ex);
	}
	
	try {
		car = (Car)Class.forName(name).newInstance();
		LOG.info("Created car class name is {}", name);
	} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
		LOG.error("Instantiate car {} failed", name);
	}
	return car;
}
 
Example 21
Project: JavaDesignPattern   File: Driver2.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws ConfigurationException {
	XMLConfiguration config = new XMLConfiguration("car.xml");
	String name = config.getString("driver2.name");
	Car car;

	switch (name) {
	case "Land Rover":
		car = new LandRoverCar();
		break;
	case "BMW":
		car = new BMWCar();
		break;
	case "Benz":
		car = new BenzCar();
		break;
	default:
		car = null;
		break;
	}
	LOG.info("Created car name is {}", name);
	car.drive();
}
 
Example 22
Project: goffish_v2   File: GMLPartitionBuilder.java   Source Code and License 6 votes vote down vote up
public void saveIntermediateGMLFile() throws IOException{ 
	XMLConfiguration configuration = getConfiguration();
	configuration.setRootElementName("gml");
	List<Path> instancePathCollection;
	for(int partitionId : _partitionedTemplates.keySet()){
		configuration.addProperty("partition(-1)[@id]", partitionId);
		configuration.addProperty("partition.template", _partitionedTemplates.get(partitionId).toFile().getAbsolutePath());

		instancePathCollection = _partitionedInstances.get(partitionId);
		for(Path instancePath : instancePathCollection){
			configuration.addProperty("partition.instances.instance(-1)", instancePath.toFile().getAbsolutePath());
		}
	}

	try {
		File partitionedGMLFileDir = _workingDirPath.resolve(_intermediateGMLInputFile).toFile();
		configuration.save(partitionedGMLFileDir);
		System.out.println("saving the partitioned gml information to " + partitionedGMLFileDir.getAbsolutePath());
	} catch (ConfigurationException e) {
		throw new RuntimeException(e);
	}
}
 
Example 23
Project: development   File: LServerClient.java   Source Code and License 6 votes vote down vote up
public void updateConfiguration(String countCPU, String memorySize)
        throws IaasException {
    HashMap<String, String> request = this.getRequestParameters();
    request.put(LParameter.ACTION, LOperation.UPDATE_LSERVER_CONFIG);
    boolean execute = false;
    if (countCPU != null) {
        request.put(LParameter.CPU_NUMBER, countCPU);
        execute = true;
    }
    if (memorySize != null) {
        request.put(LParameter.MEMORY_SIZE, memorySize);
        execute = true;
    }
    if (!execute) {
        throw new RORException("Nothing to modify");
    }
    XMLConfiguration result = lplatformClient.getVdcClient().execute(
            request);
    System.out.println(result.toString());
    // FIXME error handling
}
 
Example 24
Project: development   File: LServerClient.java   Source Code and License 6 votes vote down vote up
XMLConfiguration executeLServerAction(String action) throws IaasException {
    List<String> emptyParams = new ArrayList<String>();
    if (isEmpty(this.getRequestParameters().get(LParameter.LPLATFORM_ID))) {
        emptyParams.add(LParameter.LPLATFORM_ID);
    }
    if (isEmpty(this.getRequestParameters().get(LParameter.LSERVER_ID))) {
        emptyParams.add(LParameter.LSERVER_ID);
    }
    if (!emptyParams.isEmpty()) {
        throw new MissingParameterException(action, emptyParams);
    }

    HashMap<String, String> request = this.getRequestParameters();
    request.put(LParameter.ACTION, action);
    XMLConfiguration result = lplatformClient.getVdcClient().execute(
            request);
    return result;
}
 
Example 25
Project: development   File: RORClient.java   Source Code and License 6 votes vote down vote up
/**
 * Returns a list of all available LPlatform configurations.
 * 
 * @param verbose
 *            set to <code>true</code> to retrieve extended information
 * @return the list of configurations (may be empty but not
 *         <code>null</code>)
 * @throws RORException
 */
public List<LPlatformConfiguration> listLPlatforms(boolean verbose)
		throws IaasException {
	HashMap<String, String> request = getBasicParameters();
	request.put(LParameter.ACTION, LOperation.LIST_LPLATFORM);
	request.put(LParameter.VERBOSE, (verbose ? "true" : "false"));
	XMLConfiguration result = execute(request);

	List<LPlatformConfiguration> resultList = new LinkedList<LPlatformConfiguration>();
	if (result != null) {
		List<HierarchicalConfiguration> platforms = result
				.configurationsAt("lplatforms.lplatform");
		for (HierarchicalConfiguration platform : platforms) {
			resultList.add(new LPlatformConfiguration(platform));
		}
	}
	return resultList;
}
 
Example 26
Project: development   File: RORClient.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieves a list of templates available for the tenant.
 * 
 * @return the list
 * @throws RORException
 */
public List<LPlatformDescriptor> listLPlatformDescriptors()
		throws IaasException {
	HashMap<String, String> request = getBasicParameters();
	request.put(LParameter.ACTION, LOperation.LIST_LPLATFORM_DESCR);
	XMLConfiguration result = execute(request);

	List<LPlatformDescriptor> resultList = new LinkedList<LPlatformDescriptor>();
	if (result != null) {
		List<HierarchicalConfiguration> descriptors = result
				.configurationsAt("lplatformdescriptors.lplatformdescriptor");
		for (HierarchicalConfiguration descriptor : descriptors) {
			resultList.add(new LPlatformDescriptor(descriptor));
		}
	}
	return resultList;
}
 
Example 27
Project: development   File: RORClient.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieves a list of disk images available for the tenant.
 * 
 * @return the list
 * @throws RORException
 */
public List<DiskImage> listDiskImages() throws IaasException {
	HashMap<String, String> request = getBasicParameters();
	request.put(LParameter.ACTION, LOperation.LIST_DISKIMAGE);
	XMLConfiguration result = execute(request);

	List<DiskImage> resultList = new LinkedList<DiskImage>();
	if (result != null) {
		List<HierarchicalConfiguration> images = result
				.configurationsAt("diskimages.diskimage");
		for (HierarchicalConfiguration image : images) {
			resultList.add(new RORDiskImage(image));
		}
	}
	return resultList;
}
 
Example 28
Project: development   File: SequentialHostBalancerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testBalancerStorageSequentialSingle() throws Exception {

    SequentialHostBalancer balancer = new SequentialHostBalancer();

    String balancerConfig = "<essvcenter><balancer hosts=\"elm1\" /></essvcenter>";
    XMLConfiguration xmlConfiguration = new XMLHostConfiguration();
    xmlConfiguration.load(new StringReader(balancerConfig));
    balancer.setConfiguration(xmlConfiguration.configurationAt("balancer"));

    VMwareDatacenterInventory inventory = new VMwareDatacenterInventory();

    VMwareHost elm = inventory.addHostSystem((VMwareDatacenterInventoryTest
            .createHostSystemProperties("elm1", "128", "1")));
    elm.setEnabled(true);

    balancer.setInventory(inventory);

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm1", elm.getName());

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm1", elm.getName());
}
 
Example 29
Project: yamj-v2   File: Library.java   Source Code and License 6 votes vote down vote up
private static void fillGenreMap(String xmlGenreFilename) {
    File xmlGenreFile = new File(xmlGenreFilename);
    if (xmlGenreFile.exists() && xmlGenreFile.isFile() && xmlGenreFilename.toUpperCase().endsWith("XML")) {

        try {
            XMLConfiguration c = new XMLConfiguration(xmlGenreFile);

            List<HierarchicalConfiguration> genres = c.configurationsAt("genre");
            for (HierarchicalConfiguration genre : genres) {
                String masterGenre = genre.getString(LIT_NAME);
                LOG.trace("New masterGenre parsed : (" + masterGenre + ")");
                List<Object> subgenres = genre.getList("subgenre");
                for (Object subgenre : subgenres) {
                    LOG.trace("New genre added to map : (" + subgenre + "," + masterGenre + ")");
                    GENRES_MAP.put((String) subgenre, masterGenre);
                }

            }
        } catch (ConfigurationException error) {
            LOG.error("Failed parsing moviejukebox genre input file: {}", xmlGenreFile.getName());
            LOG.error(SystemTools.getStackTrace(error));
        }
    } else {
        LOG.error("The moviejukebox genre input file you specified is invalid: {}", xmlGenreFile.getName());
    }
}
 
Example 30
Project: moneta   File: MonetaConfiguration.java   Source Code and License 6 votes vote down vote up
protected void initTopics(XMLConfiguration config) {
	int nbrTopics = 0;
	Object temp = config.getList("Topics.Topic[@name]");
	if (temp instanceof Collection) {
		nbrTopics = ((Collection)temp).size();
	}
	
	Topic topic;
	String readOnlyStr;
	for (int i = 0; i < nbrTopics; i++) {
		topic = new Topic();
		gatherTopicAttributes(config, topic, i);
		gatherAliasAttributes(config, topic);
		gatherKeyFields(config, topic);
		
		validateTopic(topic);			
		topicMap.put(topic.getTopicName(), topic);
		pluralNameMap.put(topic.getPluralName(), topic);
	}
	
	Validate.isTrue(topicMap.size() > 0, "No Topics configured.");	
}
 
Example 31
Project: settings4j   File: ConfigurationToConnectorAdapterTest.java   Source Code and License 6 votes vote down vote up
private XMLConfiguration addXmlConfiguration(final Settings4jRepository testSettings, final String connectorName,
        final String fileName, final String propertyDelimiter) throws ConfigurationException {
    ConfigurationToConnectorAdapter connector = (ConfigurationToConnectorAdapter) testSettings.getSettings()//
        .getConnector(connectorName);
    if (connector == null) {
        final File iniConfig = new File(TestUtils.getTestFolder(), "helper/configuration/" + fileName);
        iniConfig.delete();
        XMLConfiguration configuration = new XMLConfiguration(iniConfig);
        final DefaultExpressionEngine expressionEngine = new DefaultExpressionEngine();
        expressionEngine.setPropertyDelimiter(propertyDelimiter);
        configuration.setExpressionEngine(expressionEngine);

        connector = new ConfigurationToConnectorAdapter(connectorName, configuration);

        testSettings.getSettings().addConnector(connector, //
            ConnectorPositions.firstValid(//
                ConnectorPositions.afterLast(SystemPropertyConnector.class), //
                ConnectorPositions.atFirst() // if no SystemPropertyConnector is configured.
                )//
            );

    }
    return (XMLConfiguration) connector.getConfiguration();
}
 
Example 32
Project: cognition   File: ConfigurableIngestTopology.java   Source Code and License 6 votes vote down vote up
/**
 * This class takes an XML configuration and builds and submits a storm topology.
 *
 * @throws org.apache.commons.configuration.ConfigurationException
 * @throws ConfigurationException
 */
public static void main(String[] args) throws Exception {
  // using config file
  if (args.length != 1) {
    System.err.println("usage: xmlConfigFile");
    System.exit(1);
  }
  XMLConfiguration conf = new XMLConfiguration(args[0]);

  ConfigurableIngestTopology topology = new ConfigurableIngestTopology();
  topology.configure(conf);

  boolean doLocalSubmit = conf.getBoolean(DO_LOCAL_SUBMIT, DO_LOCAL_SUBMIT_DEFAULT);
  if (doLocalSubmit)
    topology.submitLocal(new LocalCluster());
  else
    topology.submit();
}
 
Example 33
Project: Tank   File: MailMessageConfig.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void initConfig(XMLConfiguration configuration) {
    messages.clear();
    if (config != null) {
        String style = getStyle();
        @SuppressWarnings("unchecked") List<HierarchicalConfiguration> msgConfigs = config
                .configurationsAt(KEY_MESSAGE_NODE);
        for (HierarchicalConfiguration msgConfig : msgConfigs) {
            String event = msgConfig.getString(KEY_EVENT);
            String subject = msgConfig.getString(KEY_SUBJECT);
            String body = msgConfig.getString(KEY_BODY);
            if (!StringUtils.isEmpty(event) && !StringUtils.isEmpty(subject) && !StringUtils.isEmpty(body)) {
                messages.put(event, new MailMessage(body, subject, style));
            }
        }
    }
}
 
Example 34
Project: Tank   File: TankConfig.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void initConfig(XMLConfiguration configuration) {
    vmManagerConfig = new VmManagerConfig(BaseCommonsXmlConfig.getChildConfigurationAt(configuration,
            KEY_VM_MANAGER_NODE));
    agentConfig = new AgentConfig(BaseCommonsXmlConfig.getChildConfigurationAt(configuration, KEY_AGENT_NODE));
    productConfig = new ProductConfig(
            BaseCommonsXmlConfig.getChildConfigurationAt(configuration, KEY_PRODUCTS_NODE));
    locationsConfig = new LocationsConfig(BaseCommonsXmlConfig.getChildConfigurationAt(configuration,
            KEY_LOCATIONS_NODE));
    mailConfig = new MailConfig(BaseCommonsXmlConfig.getChildConfigurationAt(configuration, KEY_MAIL_NODE));
    securityConfig = new SecurityConfig(BaseCommonsXmlConfig.getChildConfigurationAt(configuration,
            KEY_SECURITY_NODE));
    logicStepConfig = new LogicStepConfig(BaseCommonsXmlConfig.getChildConfigurationAt(configuration,
            KEY_LOGIC_STEP_NODE));
    reportingConfig = new ReportingConfig(BaseCommonsXmlConfig.getChildConfigurationAt(configuration,
            KEY_REPORTING_NODE));
}
 
Example 35
Project: yamj-v2   File: Library.java   Source Code and License 6 votes vote down vote up
private static void fillCategoryMap(String xmlCategoryFilename) {
    File xmlFile = new File(xmlCategoryFilename);
    if (xmlFile.exists() && xmlFile.isFile() && xmlCategoryFilename.toUpperCase().endsWith("XML")) {

        try {
            XMLConfiguration c = new XMLConfiguration(xmlFile);

            List<HierarchicalConfiguration> categories = c.configurationsAt("category");
            for (HierarchicalConfiguration category : categories) {
                boolean enabled = Boolean.parseBoolean(category.getString("enable", TRUE));

                if (enabled) {
                    String origName = category.getString(LIT_NAME);
                    String newName = category.getString("rename", origName);
                    CATEGORIES_MAP.put(origName, newName);
                    //logger.debug("Added category '" + origName + "' with name '" + newName + "'");
                }
            }
        } catch (ConfigurationException error) {
            LOG.error("Failed parsing moviejukebox category input file: {}", xmlFile.getName());
            LOG.error(SystemTools.getStackTrace(error));
        }
    } else {
        LOG.error("The moviejukebox category input file you specified is invalid: {}", xmlFile.getName());
    }
}
 
Example 36
Project: Tank   File: BaseCommonsXmlConfigCpTest.java   Source Code and License 6 votes vote down vote up
/**
 * Run the File getSourceConfigFile() method test.
 * 
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testGetSourceConfigFile_1()
        throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    File result = fixture.getSourceConfigFile();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.SecurityException: Cannot write to files while generating test cases
    // at
    // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
    // at
    // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
    // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
    // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
    assertNotNull(result);
}
 
Example 37
Project: Tank   File: BaseCommonsXmlConfigCpTest.java   Source Code and License 6 votes vote down vote up
/**
 * Run the boolean needsReload() method test.
 * 
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testNeedsReload_3()
        throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    boolean result = fixture.needsReload();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.SecurityException: Cannot write to files while generating test cases
    // at
    // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
    // at
    // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
    // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
    // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
    assertFalse(result);
}
 
Example 38
Project: Tank   File: BaseCommonsXmlConfigCpTest.java   Source Code and License 6 votes vote down vote up
/**
 * Run the void readConfig() method test.
 * 
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testReadConfig_2()
        throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    fixture.readConfig();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.SecurityException: Cannot write to files while generating test cases
    // at
    // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
    // at
    // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
    // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
    // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
}
 
Example 39
Project: Tank   File: BaseCommonsXmlConfigCpTest.java   Source Code and License 6 votes vote down vote up
/**
 * Run the void readConfig() method test.
 * 
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testReadConfig_3()
        throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    fixture.readConfig();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.SecurityException: Cannot write to files while generating test cases
    // at
    // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
    // at
    // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
    // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
    // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
}
 
Example 40
Project: Tank   File: BaseCommonsXmlConfigCpTest.java   Source Code and License 6 votes vote down vote up
/**
 * Run the void readConfig() method test.
 * 
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testReadConfig_5()
        throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    fixture.readConfig();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.SecurityException: Cannot write to files while generating test cases
    // at
    // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
    // at
    // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
    // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
    // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
}