{"id":25334148,"url":"https://github.com/undeffineddev/dconfig","last_synced_at":"2026-01-21T19:34:51.728Z","repository":{"id":271962378,"uuid":"871781029","full_name":"UndeffinedDev/dconfig","owner":"UndeffinedDev","description":"📂 A lightweight and customizable .dconf (DataConfig) parser for configuration files, supporting sections, keys, and lists of values. 🛠️","archived":false,"fork":false,"pushed_at":"2025-01-21T03:30:07.000Z","size":47,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T08:49:07.537Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://undeffineddev.infy.uk/feature-requests","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UndeffinedDev.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-12T23:12:04.000Z","updated_at":"2025-02-01T18:22:10.000Z","dependencies_parsed_at":"2025-01-21T04:22:01.894Z","dependency_job_id":null,"html_url":"https://github.com/UndeffinedDev/dconfig","commit_stats":null,"previous_names":["undeffineddev/dconfig"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/UndeffinedDev/dconfig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UndeffinedDev%2Fdconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UndeffinedDev%2Fdconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UndeffinedDev%2Fdconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UndeffinedDev%2Fdconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UndeffinedDev","download_url":"https://codeload.github.com/UndeffinedDev/dconfig/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UndeffinedDev%2Fdconfig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28641274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T18:04:35.752Z","status":"ssl_error","status_checked_at":"2026-01-21T18:03:55.054Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-14T05:36:32.239Z","updated_at":"2026-01-21T19:34:51.713Z","avatar_url":"https://github.com/UndeffinedDev.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!WARNING]\n\u003e This project is in alpha phase and is a school prototype, so you may NOT find it as comfortable as other configuration files (yaml, toml, etc...) but I will try to improve it.\n\n\u003e [!IMPORTANT]  \n\u003e Please note that some methods have not yet been listed here. The wiki is currently being migrated to GitBook.\n\n#### Author:\nSergio Caguana (UndeffinedDev)\n\n## How To Use - DConfParser (DConfig Interpreter)\n\n### Overview\n\n`DConfParser` is a Java class designed to parse, manipulate, and save configuration files with a `.dconf` extension. The `.dconf` format is similar to INI files, supporting sections, keys, and lists of values. This guide will walk you through how to use the `DConfParser` class.\n\n### 1. Adding the Dependency\n\nBefore using `DConfParser`, ensure it's part of your project. You can either:\n\n- Include the `.jar` file in your classpath.\n- Add the package to your project.\n\n#### 2. **Creating a DConfParser Instance**\n\nTo initialize the parser, provide the path to a `.dconf` file and the character encoding you wish to use (e.g., `UTF-8`):\n\n```java \nimport me.undeffineddev.libdataconfig.DConfParser;\nimport me.undeffineddev.libdataconfig.exceptions.InvalidFileException;\n\nimport java.nio.charset.StandardCharsets;\n\npublic class Main {\n    public static void main(String[] args) {\n        try {\n            DConfParser parser = new DConfParser(\"config.dconf\", StandardCharsets.UTF_8);\n        } catch (InvalidFileException e) {\n            System.err.println(\"Error: \" + e.getMessage());\n        }\n    }\n}\n```\n\nThis will automatically attempt to load the configuration file if it exists and if it has the `.dconf` extension.\n\n#### 3. **Reading Data from the Configuration**\n\nYou can read specific keys from sections using `getList()` or `get()`.\n\n- **Get a List of Values**: This method retrieves values for a key in a specific section. If the values are quoted (either single or double quotes), it will remove the quotes and return the cleaned values.\n\n```java\nList\u003cString\u003e values = parser.getList(\"database\", \"hosts\");\nSystem.out.println(values);  // Output: [localhost, 192.168.1.1]\n```\n\n- **Get a Single Value**: You can also retrieve a single value and convert it to the desired type, using `get()`:\n\n```java\nString host = parser.get(\"database\", \"host\", \"localhost\"); \nint port = parser.get(\"database\", \"port\", 5432); \nboolean useSSL = parser.get(\"database\", \"useSSL\", false);\n```\n\n#### 4. **Checking for Sections or Keys**\n\nBefore retrieving data, you may want to check if a section or key exists:\n\n- **Check for a Section**: Use `containsSection()` to verify if a section is present:\n\n```java\nif (parser.containsSection(\"database\")) {     \n\t// Proceed with further operations \n}\n```\n\n- **Check for a Key**: Use `containsKey()` to check if a key exists in a section:\n\n```java\nif (parser.containsKey(\"database\", \"host\")) {     \n    String host = parser.get(\"database\", \"host\", \"localhost\");\n}\n```\n\n#### 5. **Modifying Data**\n\nTo modify or add new configuration entries, use the `set()` method. This method expects values in a list format, and it automatically wraps the values in quotes when saving.\n\n\n```java \nList\u003cString\u003e newHosts = Arrays.asList(\"localhost\", \"192.168.1.2\");\nparser.set(\"database\", \"hosts\", newHosts);\n```\n\n#### 6. **Saving Changes to the File**\n\nAfter modifying the configuration, you must save the changes to persist them in the `.dconf` file:\n\n\n```java\ntry {\n    parser.save();\n} catch (IOException e) {\n    System.err.println(\"Error saving the configuration: \" + e.getMessage());\n}\n```\n\n#### 7. **Creating a New Section**\n\nIf you need to add a completely new section to the configuration, use the `createSection()` method:\n\n```java \nparser.createSection(\"server\"); \nparser.set(\"server\", \"ip\", Arrays.asList(\"127.0.0.1\"));\nparser.set(\"server\", \"port\", Arrays.asList(\"8080\"));\n```\n\n#### 8. **Using the values of other keys (interpolation)**\n\nThis example shows how to use values from other keys in a configuration file by interpolation. The default.dconf configuration file contains variables and strings that reference other keys within the same file. In the [database] section, the url key uses the host and port values from the same section to form a dynamic URL. In addition, the app_name key in the [config] section is used to set the application name.\n\nDConfig Example File:\n```ini \n# Database values\n[database]\nport = 5432\nhost = \"localhost\"\njava_version = \"The Java vendor name is ${property.java.vendor} version is ${property.java.version} and the OS is ${property.os.name}\"\nversion = 1.0\nurl = \"http://${host}:${port}/${config.app_name}?username=${env.USERNAME}\"\n\n[config]\napp_name = \"MyApp\"\n```\n\nThe Java code below demonstrates how to access these interpolated values through a parser that handles the configuration file and returns the URL constructed with the specified values.\n\n```java\n    public static void main(String[] args) {\n        try {\n            DConfParser config = new DConfParser(\"default.dconf\", StandardCharsets.UTF_8);\n            System.out.println(config.get(\"database\", \"url\", \"default\"));\n            System.out.println(config.get(\"database\", \"java_version\", \"default\"));\n        } catch (InvalidFileException | RuntimeException | IOException e) {\n            throw new RuntimeException(e);\n        }\n    }\n```\n\n#### 9. **Handling Errors**\n\nMake sure to handle potential exceptions when loading, saving, or manipulating the configuration. `InvalidFileException` may be thrown when loading files with incorrect extensions, and `IOException` may be encountered when working with file I/O operations.\n\n#### Example Usage:\n\nHere’s a full example:\n\n```java\nimport me.undeffineddev.libdataconfig.DConfParser;\nimport me.undeffineddev.libdataconfig.exceptions.InvalidFileException;\n\nimport java.io.IOException;\nimport java.nio.charset.StandardCharsets;\nimport java.util.Arrays;\n\npublic class Example {\n    public static void main(String[] args) {\n        try {\n            // Load the config file\n            DConfParser parser = new DConfParser(\"config.dconf\", StandardCharsets.UTF_8);\n            \n            // Read values\n            String host = parser.get(\"database\", \"host\", \"localhost\");\n            System.out.println(\"Database Host: \" + host);\n            \n            // Modify the configuration\n            parser.createSection(\"server\");\n            parser.set(\"server\", \"port\", Arrays.asList(\"8080\"));\n            \n            // Save the changes\n            parser.save();\n            System.out.println(config.get(\"database\", \"url\", \"default\"));\n        } catch (InvalidFileException | IOException e) {\n            System.err.println(\"Error: \" + e.getMessage());\n        }\n    }\n}\n```\n\nWith this guide, you should be able to load, modify, and save `.dconf` files using the `DConfParser` class.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fundeffineddev%2Fdconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fundeffineddev%2Fdconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fundeffineddev%2Fdconfig/lists"}