Parses the configuration file and stores the values.

@throws Exception if cannot access file
430504
public function parse() {
		$fp = fopen($this->file, "r");
		if (!$fp) {
			throw new Exception("Could not open XML input file");
		}

		$data = fread($fp, 4096);
		while ($data) {
			if (!xml_parse($this->xmlParser, $data, feof($fp))) {
				$errorString = xml_error_string(xml_get_error_code($this->xmlParser));
				$errorLineNo = xml_get_current_line_number($this->xmlParser);
				$msg = sprintf("Warning: XML error: %s at line %d", $errorString, $errorLineNo);
				echo $msg;
				$this->config = array();
			}

			$data = fread($fp, 4096);
		}
	}
337714
public function configure()
    {
        if (!file_exists($this->file) || !is_readable($this->file)) {
            throw new RuntimeException(sprintf('The file "%s" does not exists or is not readable.', $this->file));
        }

        try {
            $parser = new Parser();
            $config = $parser->parse(file_get_contents($this->file));
        } catch (ParseException $exception) {
            throw new RuntimeException(sprintf('Error parsing the file "%s".', $this->file));
        }

        if (array_key_exists('magephp', $config) && is_array($config['magephp'])) {
            $logger = null;
            if (array_key_exists('log_dir', $config['magephp']) && file_exists($config['magephp']['log_dir']) && is_dir($config['magephp']['log_dir'])) {
                $logfile = sprintf('%s/%s.log', $config['magephp']['log_dir'], date('Ymd_His'));
                $config['magephp']['log_file'] = $logfile;

                $logger = new Logger('magephp');
                $logger->pushHandler(new StreamHandler($logfile));

            } elseif (array_key_exists('log_dir', $config['magephp']) && !is_dir($config['magephp']['log_dir'])) {
                throw new RuntimeException(sprintf('The configured log_dir "%s" does not exists or is not a directory.', $config['magephp']['log_dir']));
            }

            $this->runtime->setConfiguration($config['magephp']);
            $this->runtime->setLogger($logger);
            return;
        }

        throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $this->file));
    }
970475
private function initHelper()
    {
        if (!$this->isConfigFileSet()) {
            throw new Exception("The main config file wasn't defined.");
        }
        if (!$this->isAppRootSet()) {
            throw new Exception("The application root wasn't defined.");
        }
        AppHelper::getInstance()
            ->setAppRoot($this->getAppRoot())
            ->setConfigFile($this->getConfigFile())
            ->run();
    }
1046751
public void load(FileConfiguration config) {
        this.config = config;
        
        try {
            parse();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
421872
public void init() throws Exception {
        userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
        System.setProperty("user.dir", options.getExecutionDirectory().getAbsolutePath());

        if (!cfg.exists()) {

            ConfigurationManager manager = new ConfigurationManager(cfg, false, locateConfigurationProvider());

            try {

                manager.runProjectConfigurationInitializers();

                if (options.isVerbose()) {
                    log.info("CONFIGURATION FILE [" + cfg.getAbsolutePath() + "] CREATION COMPLETE");
                }

            } catch (IOException aux) {
                if (options.isVerbose()) {
                    log.error("The system can't create the file [ " + cfg.getAbsolutePath() + "]");
                }
                if (options.isThrowException()) {
                    System.setProperty("user.dir", userDir);
                    throw aux;
                }
            }

        } else {
            if (options.isVerbose()) {
                log.error("The configuration file [" + cfg.getAbsolutePath() + "] already exists");
            }
        }
        System.setProperty("user.dir", userDir);
    }
186002
public function parse()
    {
        if (!is_file($this->file)) {
            throw new \Exception(sprintf(
                'Template "%s" file doesn\'t exist!', $this->file
            ));
        }

        $fp = fopen($this->file, 'r');

        $lineCount       = 0;
        $nextToken       = '';
        $block           = '';
        $currentValue    = '';
        $stringComposing = false;
        $skipMultilineComment = false;

        while (($line = fgets($fp)) !== false) {
            $lineCount++;

            if ($stringComposing) {
                if (substr(ltrim($line), 0, 3) === '>>>') {
                    $this->blocks[$block][$name] = trim($value);
                    //$block = '';
                    $value = '';
                    $stringComposing = false;
                } else {
                    // $line = trim($line);
//                     if (substr($value, -1) != '>' && ! empty($line)) {
//                         $line = " " . $line;
//                     }

                    //$value .= substr($value, -1) == '>' ? trim($line) : " " . trim($line);
                    $value .= $line;
                }

                continue;
            }

            $line = trim($line);

            if (substr($line, 0, 1) === '#' || $line === '' || substr($line, 0, 2) === '//') {
                continue; // skip single comments or empty lines
            } elseif (substr($line, 0, 2) === '/*') { // start multiline comment
                if (strpos($line, '*/') === false) {
                    $skipMultilineComment = true; // activate multiline comments skipping
                } else {
                    continue; // just skip this line, it has the form: /* ... */
                }
            } elseif (strpos($line, '*/') !== false) { // end multiline comment
                $skipMultilineComment = false;
                continue; // just skip the end multiline comment
            }

            if ($skipMultilineComment) {
                continue; //skip multiline comments segment
            }

            $kwPattern = '^@(?<keyword>\w+)';

            if (! preg_match('/'.$kwPattern.'.*/', $line, $matches)) {
                throw new \Exception(sprintf(
                    'Parse Error: Unknow keyword, lines must starts with a valid keyword, near: %s, on line %s',
                    $line, $lineCount
                ));
            }
            //var_dump($matches);
            $keyword = $matches['keyword'];

            switch ($keyword) {
                case Parser::T_DEF:
                    $pattern = '/'.$kwPattern.'\s+(?<type>[\w]+)\s+(?<name>[\w.]+)\s+(?<value>.+)/';

                    if (!preg_match($pattern, $line, $matches)) {
                        throw new \Exception(sprintf(
                            "Syntax Error: near: '%s', on line %s.\n" .
                            "Syntax should be: @def <type> <name> <value>",
                            $line, $lineCount
                        ));
                    }

                    $keyword = $matches['keyword'];
                    $type    = $matches['type'];
                    $name    = $matches['name'];
                    $value   = $matches['value'];

                    $tmp     = explode('.', $name);
                    $defName = $tmp[0];
                    $defProp = isset($tmp[1]) ? $tmp[1] : '';

                    switch ($type) {
                        case Parser::T_GLOBAL:
                        case Parser::T_ITERATOR:
                        case Parser::T_SETCONF:
                            if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
                                $value = trim($value, '"');
                            } elseif (substr($value, 0, 1) == "'" && substr($value, -1) == "'") {
                                $value = trim($value, "'");
                            }

                            if ($value === '\n' || $value === '\r\n') {
                                $value = "\n";
                            }

                            $value = self::castValue($value);

                            if (empty($defProp)) {
                                $this->defs[$type][$defName] = $value;
                            } else {
                                $this->defs[$type][$defName][$defProp] = $value;
                            }
                            break;
                        default:
                            throw new \Exception(sprintf(
                                'Parse Error: unknow definition type: "%s" on line %s.', $type, $lineCount
                            ));
                    }
                    break;
                case Parser::T_BLOCK:
                    $pattern = '/'.$kwPattern.'\s+(?<block>[\w]+)/';

                    if (!preg_match($pattern, $line, $matches)) {
                        throw new Exception(sprintf(
                            "Parse Error: Syntax error near: %s, on line %s.\n." .
                            "Syntax should be: @def <type> <name> <value>",
                            substr($line, 0, 20).'...', $lineCount
                        ));
                    }
                    //var_dump($matches);

                    $block = $matches['block'];

                    if (!empty($nextToken)) {
                        throw new \Exception(sprintf(
                            'Parse Error: expected: @"%s", given: @"%s"', $nextToken, Parser::T_BLOCK
                        ));
                    }

                    $nextToken = Parser::T_END;
                    break;
                case Parser::T_END:
                    if (empty($nextToken)) {
                        throw new \Exception(sprintf(
                            'Parse Error: close keyword: @"%s" given, but any block was started.', Parser::T_BLOCK
                        ));
                    }

                    if ($nextToken !== Parser::T_END) {
                        throw new \Exception(sprintf(
                            'Parse Error: expected: @"%s", given: @"%s"', $nextToken, Parser::T_END
                        ));
                    }

                    $nextToken = '';
                    break;
                case Parser::T_VAR:
                    $pattern = '/'.$kwPattern.'\s+(?<name>[\w]+)\s+(?<value>.+)/';

                    if (!preg_match($pattern, $line, $matches)) {
                        throw new Exception(sprintf(
                            "Parse Error: Syntax error near: %s, on line %s.\n." .
                            "Syntax should be: @var <name> <value>\n or \n" .
                            "@var <name> <<<\nsome large string\nmultiline...\n>>>\n\n",
                            substr($line, 0, 20).'...', $lineCount
                        ));
                    }
                    //print_r($matches);
                    $keyword = $matches['keyword'];
                    $name    = $matches['name'];
                    $value   = $matches['value'];

                    if (substr($value, 0, 3) === '<<<' && $value !== '<<<') {
                        throw new \Exception(sprintf(
                            "Syntax Error: multiline string must starts on new line after open braces <<<\n" .
                            "near: '%s', on line %s", $line, $lineCount
                        ));
                    }

                    if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
                        $value = trim($value, '"');
                    } elseif (substr($value, 0, 1) == "'" && substr($value, -1) == "'") {
                        $value = trim($value, "'");
                    }

                    if ($value !== '<<<') {
                        $this->blocks[$block][$name] = self::castValue($value);
                    } else {
                        $value = '';
                        $stringComposing = true;
                    }
                    break;
                default:
                    throw new \Exception(sprintf(
                        'Parse Error: Unknown definition type: %s, on line %s', $type, $lineCount
                    ));
            }

        }

        if ($stringComposing) {
            throw new \Exception(sprintf(
                "Parse Error: Multiline string closing braces are missing '>>>',\nfor @block: '%s', @var: '%s' " .
                "until end of file.", $block, $name
            ));
        }
    }
726080
public void parse(File file) throws UpdateException {
        LOGGER.debug("Parsing " + file.getName());
        try (InputStream fin = new FileInputStream(file);
                InputStream in = new GZIPInputStream(fin);
                InputStreamReader isr = new InputStreamReader(in, UTF_8);
                JsonReader reader = new JsonReader(isr)) {
            final Gson gson = new GsonBuilder().create();

            reader.beginObject();

            while (reader.hasNext() && !JsonToken.BEGIN_ARRAY.equals(reader.peek())) {
                reader.skipValue();
            }
            reader.beginArray();
            while (reader.hasNext()) {
                final DefCveItem cve = gson.fromJson(reader, DefCveItem.class);

                //cve.getCve().getCVEDataMeta().getSTATE();
                if (testCveCpeStartWithFilter(cve)) {
                    cveDB.updateVulnerability(cve);
                }
            }
        } catch (FileNotFoundException ex) {
            LOGGER.error(ex.getMessage());
            throw new UpdateException("Unable to find the NVD CPE file, `" + file + "`, to parse", ex);
        } catch (IOException ex) {
            LOGGER.error("Error reading NVD JSON data: {}", file);
            LOGGER.debug("Error extracting the NVD JSON data from: " + file.toString(), ex);
            throw new UpdateException("Unable to find the NVD CPE file to parse", ex);
        }
    }
348353
@SuppressFBWarnings(justification = "try with resources will clean up the input stream", value = {"OBL_UNSATISFIED_OBLIGATION"})
    public AssemblyData parse(File file) throws GrokParseException {
        try (FileInputStream fis = new FileInputStream(file)) {
            return parse(fis);
        } catch (IOException ex) {
            LOGGER.debug("", ex);
            throw new GrokParseException(ex);
        }
    }
929848
public void load() throws FileNotFoundException {

        XMLObjectReader reader = null;
        try {
            this.preparePersistFile();

            File f = new File(persistFile.toString());
            if (f.exists()) {
                // we have V2 config
                loadVer2(persistFile.toString());
            } else {
                String s1 = persistFile.toString().replace("1.xml", ".xml");
                f = new File(s1);

                if (f.exists()) {
                    loadVer1(s1);
                }

                this.store();
                f.delete();
            }
        } catch (XMLStreamException ex) {
            logger.error(String.format("Failed to load the M3UA configuration file. \n%s", ex.getMessage()));
        } catch (FileNotFoundException e) {
            logger.warn(String.format("Failed to load the M3UA configuration file. \n%s", e.getMessage()));
        } catch (IOException e) {
            logger.error(String.format("Failed to load the M3UA configuration file. \n%s", e.getMessage()));
        }
    }
109840
public Configuration getConfiguration() throws Exception {
        Configuration result = null;
        if (cfg.exists()) {

            userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
            System.setProperty("user.dir", options.getExecutionDirectory().getAbsolutePath());
            try {
                ConfigurationManager manager = new ConfigurationManager(cfg, false);
                manager.executeConfigurationProviders();
                result = manager.getConfiguration();
            } finally {
                System.setProperty("user.dir", userDir);
            }
        }
        return result;
    }
1277630
static function parse_file( $f ){
		$src = file_get_contents( $f, true );
		if( $src === false ){
			throw new Exception("Cannot read file $f");
		}
		return self::parse_string( $src );
	}
742027
protected function importConfigurations()
    {
        foreach ($this->files as $key => $file) {
            if (!file_exists(static::$path.DS.$file.'.php')) {
                throw new \Exception("File doesn't exists in the path ".static::$path.DS.$file.'.php');
            }

            /*
            | We will include configuration file into array only
            | for the first time
             */
            if (!isset(static::$config[$key])) {
                static::set($key, include static::$path.DS.$file.'.php');
            }
        }
    }
1339275
protected synchronized void readFile() {
        if (realmFile != null && realmFile.exists() && (realmFile.lastModified() != lastModified)) {
            lastModified = realmFile.lastModified();
            try {
                Preconditions.checkArgument(realmFile.canRead(), "The file '{}' can not be read!", realmFile);
                Config config = ConfigFactory.parseFile(realmFile);
                super.setup(config);
            } catch (Exception e) {
                log.error("Failed to read {}", realmFile, e);
            }
        }
    }
560473
public function read()
    {
        if (empty($this->filename)) {
            Throw new RepositoryException(sprintf('There is no filename set for %s', __CLASS__));
        }

        if (! file_exists($this->filename)) {
            Throw new RepositoryException(sprintf('Config file $s is does not exists', $this->filename));
        }

        if (! is_readable($this->filename)) {
            Throw new RepositoryException(sprintf('Config file $s is not readable', $this->filename));
        }

        $array = include ($this->filename);
    }
402295
public void execute() throws Exception {
        // Read the properties file, if it exists.
        properties = new Properties();
        if (propertiesFile != null) {
            FileInputStream propertiesStream = null;
            try {
                propertiesStream = new FileInputStream(propertiesFile);
                properties.load(propertiesStream);
            } catch (final Exception e) {
                throw new RuntimeException(e);
            } finally {
                if (propertiesStream != null) {
                    try {
                        propertiesStream.close();
                    } catch (final IOException e) {
                        logger.error(e.getMessage(), e) ;
                    }
                }
            }
        } else {
            properties.putAll(Configuration.configuration);
        }
        if (!properties.containsKey(CONF_PLUGIN_DIRS)) {
            properties.setProperty(CONF_PLUGIN_DIRS, configuration.getOrDefault(CONF_PLUGIN_DIRS, "plugins;demo"));
        }
        if (!properties.containsKey(CONF_PLUGIN_IGNORES)) {
            properties.setProperty(CONF_PLUGIN_IGNORES, configuration.getOrDefault(CONF_PLUGIN_IGNORES, ""));
        }

        // Get the list of plugin directories from the properties.
        final String[] pluginDirs = properties.getProperty(CONF_PLUGIN_DIRS).split(PARAM_VALUE_SEPARATOR);

        final Set<String> pluginIgnores = new HashSet<>();
        if (properties.getProperty(CONF_PLUGIN_IGNORES) != null) {
            pluginIgnores.addAll(Arrays.asList(properties.getProperty(CONF_PLUGIN_IGNORES).split(PARAM_VALUE_SEPARATOR)));
        }

        final String pluginOrderProperty = properties.getProperty(CONF_PLUGIN_ORDER);
        if (pluginOrderProperty != null) {
            final List<String> plugins = asList(pluginOrderProperty.trim().split("\\s+"));
            Collections.reverse(plugins);
            int priority = 1;
            for (final String plugin: plugins) {
                pluginOrder.put(plugin, priority++);
            }
        }

        for (final String tmpl : properties.getProperty(CONF_TEMPLATES, "").split(PARAM_VALUE_SEPARATOR)) {
            final String t = tmpl.trim();
            if (t.length() != 0) {
                logger.warn(MessageUtils.getMessage("DOTJ080W", "templates", "template").toString());
                templateSet.put(t, null);
            }
        }

        for (final String pluginDir2 : pluginDirs) {
            File pluginDir = new File(pluginDir2);
            if (!pluginDir.isAbsolute()) {
                pluginDir = new File(ditaDir, pluginDir.getPath());
            }
            final File[] pluginFiles = pluginDir.listFiles();

            for (int i = 0; (pluginFiles != null) && (i < pluginFiles.length); i++) {
                final File f = pluginFiles[i];
                final File descFile = new File(pluginFiles[i], "plugin.xml");
                if (pluginFiles[i].isDirectory() && !pluginIgnores.contains(f.getName()) && descFile.exists()) {
                    descSet.add(descFile);
                }
            }
        }

        mergePlugins();
        integrate();
        logChanges(pluginList, getPluginIds(pluginsDoc));
    }
867427
@Override
  public Configuration loadConfig() throws ConfigurationException, IOException {

    Configuration resultConfig = new Configuration();

    if (!Utils.localFileExists(this.getConfigFileName())) {
      // String configFileName = System.getenv(ConfigConstant.DDF_INI_ENV_VAR.getValue());
      File file = new File(this.locateConfigFileName(this.getConfigDir(), this.getConfigFileName()));
      mConfigDir = file.getParentFile().getName();
      mConfigFileName = file.getCanonicalPath();
    }

    if (!Utils.localFileExists(this.getConfigFileName())) return null;

    HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(this.getConfigFileName());

    @SuppressWarnings("unchecked")
    Set<String> sectionNames = config.getSections();
    for (String sectionName : sectionNames) {
      SubnodeConfiguration section = config.getSection(sectionName);
      if (section != null) {
        Configuration.Section resultSection = resultConfig.getSection(sectionName);

        @SuppressWarnings("unchecked")
        Iterator<String> keys = section.getKeys();
        while (keys.hasNext()) {
          String key = keys.next();
          String value = section.getString(key);
          if (value != null) {
            resultSection.set(key, value);
          }
        }
      }
    }

    mConfig = resultConfig;
    return mConfig;
  }
9506
public synchronized void load() {
        XmlFile file = getConfigFile();
        if(!file.exists())
            return;

        try {
            file.unmarshal(this);
        } catch (IOException e) {
            LOGGER.log(Level.WARNING, "Failed to load "+file, e);
        }
    }