pax_global_header00006660000000000000000000000064115164532370014521gustar00rootroot0000000000000052 comment=b2588f9e9623697d60c47f28aff94a6b6b798cc6 ini4j-0.5.2-SNAPSHOT/000077500000000000000000000000001151645323700137775ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/LICENSE.txt000066400000000000000000000261351151645323700156310ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ini4j-0.5.2-SNAPSHOT/NOTICE.txt000066400000000000000000000010551151645323700155220ustar00rootroot00000000000000Copyright 2005,2009 Ivan SZKIBA Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.ini4j-0.5.2-SNAPSHOT/pom.xml000066400000000000000000000743721151645323700153310ustar00rootroot00000000000000 4.0.0 org.ini4j ini4j 0.5.2-SNAPSHOT ini4j Java API for handling configuration files in Windows .ini format. The library includes its own Map based API, Java Preferences API and Java Beans API for handling .ini files. Additionally, the library includes a feature rich (variable/macro substitution, multiply property values, etc) java.util.Properties replacement. jar http://www.ini4j.org scm:svn:https://ini4j.svn.sourceforge.net/svnroot/ini4j/trunk scm:svn:https://ini4j.svn.sourceforge.net/svnroot/ini4j/trunk ini4j-release [ini4j] releases on SourceForge scp://shell.sourceforge.net/home/groups/i/in/ini4j/repository/release ini4j-snapshot [ini4j] snapshots on SourceForge scp://shell.sourceforge.net/home/groups/i/in/ini4j/repository/snapshot ini4j-site [ini4j] site on SourceForge scp://shell.sourceforge.net/home/groups/i/in/ini4j/htdocs sourceforge http://sourceforge.net/tracker2/?group_id=129580 Apache 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo ivan Ivan Szkiba szkiba at SourceForge architect developer -1 junit junit 4.5 test jetty jetty 4.2.2 test org.easymock easymock 2.3 test org.easymock easymockclassextension 2.3 test org.beanshell bsh 2.0b4 test net.sf.retrotranslator retrotranslator-runtime 1.2.4 true scp://shell.sourceforge.net//home/frs/project/i/in/ini4j/uploads /usr/local/j2sdk1.4.2_19 windows windows org.apache.maven.plugins maven-surefire-plugin os.family windows release-candidate true org.apache.maven.plugins maven-checkstyle-plugin 2.3 ${basedir}/src/conf/checkstyle.xml true true UTF-8 ${check.skip} verify check org.apache.maven.plugins maven-pmd-plugin pmd pmd-jdk14 4.2.5 true ${basedir}/src/conf/pmd.xml ${check.skip} true UTF-8 1.5 verify check org.apache.maven.plugins maven-dependency-plugin copy-junit process-classes unpack junit junit jar true org.easymock easymock jar true ${project.build.directory}/test-deps org.codehaus.mojo retrotranslator-maven-plugin net.sf.retrotranslator retrotranslator-runtime 1.2.4 org.ini4j.jdk14 true translate-classes translate process-classes ${project.build.directory}/classes-jdk14 ${project.build.outputDirectory} org.ini4j.jdk14 true translate-test-classes translate process-test-classes ${project.build.directory}/test-classes-jdk14 ${project.build.testOutputDirectory} ${project.build.directory}/test-deps org.ini4j.jdk14 true translate-project translate-project jdk14 true true org.apache.maven.plugins maven-antrun-plugin org.apache.ant ant-junit 1.7.0 test test run org.apache.maven.plugins maven-source-plugin attach-sources jar org.apache.maven.plugins maven-javadoc-plugin attach-javadoc jar org.apache.maven.plugins maven-changes-plugin false src/changes UTF-8 ${project.build.directory} releasenotes announcement-generate generate-resources changelog announcement-generate generate-resources sitemap-create announcement-generate pre-site maven-antrun-plugin sitemap-copy run pre-site org.apache.maven.plugins maven-compiler-plugin 1.5 1.5 UTF-8 -Xlint org.apache.maven.plugins maven-resources-plugin UTF-8 maven-surefire-plugin java.util.prefs.PreferencesFactory org.ini4j.IniPreferencesFactory org.ini4j.prefs.user org/ini4j/sample/dwarfs.ini org.ini4j.prefs.system org/ini4j/sample/dwarfs.ini org.apache.maven.plugins maven-assembly-plugin zip deploy single src/main/assembly/src.xml src/main/assembly/bin.xml src/main/assembly/all.xml false demo package single target/generated-site/resources ini4j-demo false src/main/assembly/demo.xml false org.ini4j.demo.DemoMain org.codehaus.mojo wagon-maven-plugin upload upload deploy ini4j-upload ${project.build.directory} ${project.build.finalName}-src*,${project.build.finalName}-bin*,${project.build.finalName}-all* ${upload.url} org.apache.maven.plugins maven-site-plugin 2.0 ${basedir}/target/generated-site com.google.code.maven-license-plugin maven-license-plugin 1.4.0 true true UTF-8 true
NOTICE.txt
**/META-INF/services/** **/*.txt **/*.apt **/*.reg **/.htaccess **/UTF*.ini SLASHSTAR_STYLE SLASHSTAR_STYLE SLASHSTAR_STYLE SEMICOLON_STYLE SCRIPT_STYLE true
initialize format
org.apache.maven.plugins maven-dependency-plugin unpack generate-resources unpack org.beanshell bsh jar false ${project.build.directory}/test-classes
src/test/java **/*.ini **/*.opt **/*.reg **/*.properties **/*.xml **/*.txt src/test/resources
org.apache.maven.plugins maven-jxr-plugin UTF-8 true org.apache.maven.plugins maven-javadoc-plugin UTF-8 ISO-8859-1 true java.* http://java.sun.com/javase/6/docs/api/ true javadoc org.codehaus.mojo taglist-maven-plugin UTF-8 TODO FIXME XXX org.codehaus.mojo cobertura-maven-plugin org.apache.maven.plugins maven-changes-plugin UTF-8 http://sourceforge.net/tracker2/?func=detail&atid=715133&group_id=129580&aid=%ISSUE% changes-report org.apache.maven.plugins maven-project-info-reports-plugin index summary issue-tracking license project-team dependencies
ini4j-0.5.2-SNAPSHOT/src/000077500000000000000000000000001151645323700145665ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/changes/000077500000000000000000000000001151645323700161765ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/changes/ChangeLog.vm000066400000000000000000000014201151645323700203660ustar00rootroot00000000000000#* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *# Change log #foreach( $release in $releases ) * $release.version ($release.dateRelease) - $release.description #foreach( $action in $release.actions ) * $action.action #end #endini4j-0.5.2-SNAPSHOT/src/changes/ReleaseNotes.vm000066400000000000000000000013551151645323700211370ustar00rootroot00000000000000#* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *# Release notes * $release.version ($release.dateRelease) - $release.description #foreach( $action in $release.actions ) * $action.action #end ini4j-0.5.2-SNAPSHOT/src/changes/changes.xml000066400000000000000000000377271151645323700203500ustar00rootroot00000000000000 [ini4j] Changes Backport to java 1.4 fixed. There were a lot of problem. Now all junit tests are run both on current java and on 1.4 jvm. This way backported version is junit tested (on real 1.4 jvm) as the normal version. Removed UnicodeLittle/UnicodeBig charset references because these break the backported version. Add BOM (byte order mark) support. Workaround on java BOM/UTF8 problem. Fixed typo in Options Tutorial. Multiply macro substituton per value fixed. There were a bug in variable/macro substitution if more than one macro used in one option value. Configurable comment handling. The header comment can be disable/enable via Config.setHeaderComment(boolean). Also the whole comment handling can be disable/enable via Config.setComment(boolean). Removed java.util.NavigableMap reference from code, becasue it is break java 1.5 compatibility. Applet support: [ini4j] now able to run in applet environment. Demo applet: now project site contains a small demo applet to check [ini4j] interactive mode from browser. Read/write Windows registry. The new Reg class is able to read/write windows registry. This class is very similar to Ini class, has same data model. Support for .REG (windows regedit) format. The file format is similar to .ini, and now the org.ini4j.Reg class can handle it. Tree data model for ections. Now sections handled as a tree, with subsections. It is based on section names. With a separator ('/' or '\') sectios can organized into trees (like in .REG format). Improve project web site. Bean property mapping with upper case first letter in key names (aka Mozilla .ini files) (Feature request #2706511) Comment support for Ini and Options. There is a header comment, section comment and option comment. Comments at beginig of file are header comments. Continous comment block before section is a section comment, continous comment bleck before option is an option comment. Refactor Ini class, extract Profile interface and BasicProfile superclass. Comfortable access methods for OptionBundle and OptionMap. Code cleanup, remove deprecated methods, classes. Backslash at end of line support: join with next line. Added Options as replacement for java.util.Properties. Options has a lot of useful features, like: ${} macro handling, multi value handling, bean marshalling/unmarshalling etc. Python ConfigParser interface for .ini files. Cleanup code, use PMD+checkstyle. Cleanup deprecated warnings from test code. Skip "class" property in Ini.Section#from method. Added Issue Tracking to Project Information on maven generated site. Fix BeanTool bug: ${} macros an dindexed properties not handled properly in inject(). New from() and to() methods in Ini.Section for marshalling/unmarshalling bean properties. Indexed property access in bean interafce for multi value options and sections. Configurable multi value handling both for options and sections. Configurable escape handling. Now possible to handle windows path values (caontains backslases). Migrate junit test to 4.x version. Added MuliMap datatype: multiple value for same key. It used by Ini and Ini.Section classes. Move FancyIniParser and FancyIniFormatter functionality to IniParser and IniFormatter. Make them configurable (enable/disable features via Config object). Make bean manipulation (BeanTool) and escaping (EscapeTool) replaceable via standard services mechanism (/META-INF/services/XXX) Internal changes: migrating changelog.apt to changes.xml, generating text version of ChangeLog and Releasenotes from changes.xml Internal changes: use wagon plugin for helping SourceForge release upload, use license plugin to keep up to date file headers. ini4j now support files with # in the name (Java 1.5 Support) now ini4j compiled for jdk 1.5 by default (and translated to 1.4) SVN rename. TRUNK and TAGS renamed to lowercase, to use conventional names Write Ini file: skip blanks around " = ": Separated IniFormatter class format the .ini file (and XMLFormatter). This class can instantiate using factory pattern (internally use standard jar service locator pattern), and caller can override default IniFormatter implementation. See FancyIniFormatter in addons package, which is by default do not put space around '='. Ini.store with null values: By default keys with empty (null) values now skipped, but in FancyIniFormatter empty values printed as empty string. Fix file close problem: in some case IniFile and IniParser left files open. This cause file deletion problem on some OS. Fix Unicode escape problem: \u sequences now generated correctly (4 character with leading zeros) Added maven repository support: http://www.ini4j.org/repository/release and http://www.ini4j.org/repository/snapshot Migration: CVS to SVN Migration: Ant to Maven Refactored code for customization: Ini, IniPreferences, IniParser now also handle URL as input. It makes possible to create C like #include directive at IniParser level, when using URL as input source. Added include feature to FancyIniParser: <location> mean: '<' and '>' token, location is either relative or absolute URL of include file. Unlimited level of includes allowed. Relative URLs only allowed, when container file loaded via URL (not via stream or reader). IniFile got getMode() and getFile() accessor methods. PreferencesWrapper class in addon package to support decorator design pattern for java.util.Preferences objects. StrictPreferences decorator class, which has getXXX methods without default parameter, and throws java.util.NoSuchElementException on missing values instead of returning default value. As per many programmers request, finally [ini4j] backported to JDK 1.4. There is a ini4j-compat.jar and retroweaver-rt*.jar in distribution directory. These 2 jar need for JDK 1.4 to use [ini4j]. Every JUnit test run successfully, so I'm sure that [ini4j] work correctly with JDK 1.4 (JUnit test coverage ~ 98% :) I like retroweaver tool, so I'd like to mentoin here: retroweaver.sorceforge.net and forked project (I used for ini4j) retroweaver-ng.sourceforge.net removed some private constructor (cosmetic change) Added factory design pattern for IniParser class: it is possible now to change IniParser implementation at runtime: either "org.ini4j.IniParser" system property or META-INF/services/org.ini4j.IniParser file is the configuration point. This is conform with JAR specifications service definition. Thanx this to James Ahlborn and Steve Buschman. They are suggested some changes in IniParser. I disagree with the changes, but I made the possibility of changing IniParser without change Ini4j source :) added org.ini4j.addon package for optional classes. added org.ini4j.addon.FancyIniParser as alternate parser with following features: - option without = operator mean empty option - empty section names [] mean empty string as section name - first section tag ([name]) is optional, by default it is same as [] - section and/or option names may be converted to lowercase while parsing fixed xhml bugs in documentation set java.util.prefs.PreferencesFactory property in IniPreferencesFactoryListener fix AbstractBeanInvocationHandler#getProperty(), now it returns zero() if getPropertySpi() returns null hasProperty method in AbstractBeanInvocationHandler: if interface has hasXXX method, it will return true if bean has XXX property. fixed logo png in CVS support for webapps: IniPreferencesFactoryListener webapp can use /WEB-INF/user.ini and /ERB-INF/system.ini as user and system root preferences checked in to CVS CVSROOT: :ext:cvs.sourceforge.net/cvsroot/ini4j/main documentation reorganization: footer navigation bar added ini4j.org domain registered, java package names modified to org.ini4j JUnit tests improved Clover code coverage tool used documentation English cleaned Java Beans style interface for sections and for ini too. You should pass interface to Ini.Section.to() (or Ini.to()) and you get a Java object implements passed interface on top of Ini.section (or Ini). Not only setXX and getXX works well, but property change listeners and vetoable change listeners also supported. Variable substitution for option values. You can use ${section/option} style substitution expressions in any option value. Reorganize XML parsing: now IniParser has parseXML method, which simply translate SAX callbacks to IniHandler callbacks Create Convert class for unicode escape conversion: escape and unsecape methods. Initial version ini4j-0.5.2-SNAPSHOT/src/changes/sitemap.vm000066400000000000000000000044461151645323700202140ustar00rootroot00000000000000#* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *# http://ini4j.sourceforge.net/ $release.dateRelease 0.9 monthly http://ini4j.sourceforge.net/tutorial/index.html $release.dateRelease 0.8 monthly http://ini4j.sourceforge.net/sample/index.html $release.dateRelease 0.8 monthly http://ini4j.sourceforge.net/download.html $release.dateRelease 0.8 monthly http://ini4j.sourceforge.net/apidocs/index.html $release.dateRelease 0.7 monthly http://ini4j.sourceforge.net/cobertura/index.html $release.dateRelease 0.6 monthly http://ini4j.sourceforge.net/design.html $release.dateRelease 0.6 monthly ini4j-0.5.2-SNAPSHOT/src/conf/000077500000000000000000000000001151645323700155135ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/conf/checkstyle.xml000066400000000000000000000245041151645323700204000ustar00rootroot00000000000000 ini4j-0.5.2-SNAPSHOT/src/conf/jalopy.xml000066400000000000000000001534321151645323700175430ustar00rootroot00000000000000 2 2 never false false 80 necessary 36 15 true [A-Z][a-zA-Z0-9]+ [A-Z][a-zA-Z0-9]+ [A-Z][a-zA-Z0-9]+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-zA-Z]\w+ _[a-z]\w+ [a-z]\w+ [a-z]\w+ [a-zA-Z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-zA-Z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [A-Z0-9_]+ [A-Z][a-zA-Z0-9]+ \w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]\w+ [a-z]+(?:\.[a-z]+)* [a-z]\w+ \w+ [a-z]\w+ [a-z]\w* [a-z]\w* [a-z]\w* false false false false false false false false false false false false false false false false false false false false false false false logs\run.log log true 30000 30000 30000 30000 30000 30000 30000 30000 true false false false false true false false false false 1 1 1 -1 -1 -1 -1 1 1 1 1
1
0
1 1 1 1 1
0 0 -1 1 0 1 1 1 1 1 0 0
1
0
0
1
1
2 true true 0
1 0 false 1 0 false 1 1 0 false false 1 0 false false false false false false false false false 25 false false true false false false true false false false false false false true false false 1 0 false true 1 0 false true true true true false false true 1 0 false true false false false false false false 1 1 0 false false false false false true true false false false -1 false false false false false false false false false false false false false false false false false false false false false false true true 0 0 false false 0 true 0 false false false false false true false true true false true true 2 false @param^param|@return^return|@throws^throws|@author^common|@version^common|@see^common|@since^common|@serial^common|@serialData^common|@serialField^common|@deprecated^common|@custom^common|@beaninfo^none|@@attribute^none|@invalid^common|@todo^common|@xdoclet^none|@jalopy.group^none|@call-tree^none false false false false false /** DOCUMENT ME! */ false false true true false true true true false true false 80 false -1 false false true false true false true false - false false false false false 80 //~ ${fill.character}* Annotations Inner Classes Constructors Enums Enum constants Instance fields Instance initializers Inner Interfaces Methods Ordinary methods Static fields/initializers 140 20 false false
false true 0 false
false true 0 false
repository 3 *:0|gnu:2|java:2|javax:2 none expand true false true false false false false false standard true standard true true true true true false true standard false false standard true true 8 1 0 0 0 2 55 -1 4 -1 0 8 -1 2 false false false false false ^(is)[A-Z]\w+ false true false false false false true false false false false false false false true false false false false false false false true true isFoo|getFoo|setFoo|foo true true true level|name false true false true true level|count|default|copy true true true true level|name true false true name|count true true true level|name|type true true true true level|name true true true true true true level|bean|regex|name|count|custom true true false true false public|protected|friendly|private|abstract|static|final|native true true true true static|enum|enumConstant|field|initializer|constructor|method|interface|class|annotation false false annotation|public|protected|private|abstract|static|final|synchronized|transient|volatile|native|strictfp true true true true true true true true true true true true true true true true true true true true true true true true true true true true true false false false false false false false false false false false false false false false false false false false false false false true true true true true false true true true false true false false false false 1 true true false true false true true false false false false false false false false false false false false false false false false false false false false false false true true false false false false false false true true true true true true true false false true true true false false true false false false false true true false false true true true true false false true true true false false false false false false false false false false false false false false false false false false false false false false false false false false true false false false false false false false false false false true 0 false true false false false false false false false false false false false true false false false false false false false false false true true false false true false false false false false 140 false false false true false false false false true false false false false false false false false false false false false false false false false false false true false false false false
bak 1 [ini4j] Java Coding Convention ini4j false none US yyyy-MM-dd en hh:mm false UTF-8 false false false false true false true false AUTO false 1 false true false true
ini4j-0.5.2-SNAPSHOT/src/conf/pmd.xml000066400000000000000000000420221151645323700170150ustar00rootroot00000000000000 Coding checks for [ini4j] ini4j-0.5.2-SNAPSHOT/src/main/000077500000000000000000000000001151645323700155125ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/main/assembly/000077500000000000000000000000001151645323700173315ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/main/assembly/all.xml000066400000000000000000000021271151645323700206250ustar00rootroot00000000000000 all zip README* LICENSE* NOTICE* ${project.build.directory} ${project.artifactId}-*.jar ini4j-0.5.2-SNAPSHOT/src/main/assembly/bin.xml000066400000000000000000000022661151645323700206310ustar00rootroot00000000000000 bin zip README* LICENSE* NOTICE* ${project.build.directory} ${project.artifactId}-${project.version}.jar ${project.artifactId}-${project.version}-jdk14.jar ini4j-0.5.2-SNAPSHOT/src/main/assembly/demo.xml000066400000000000000000000033301151645323700207760ustar00rootroot00000000000000 demo jar false README* LICENSE* NOTICE* true target/test-classes bsh/** org/ini4j/demo/* org/ini4j/sample/Dwarf* true target/classes org/ini4j/** true ini4j-0.5.2-SNAPSHOT/src/main/assembly/src.xml000066400000000000000000000021071151645323700206420ustar00rootroot00000000000000 src zip README* LICENSE* NOTICE* pom.xml true src true ini4j-0.5.2-SNAPSHOT/src/main/java/000077500000000000000000000000001151645323700164335ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/main/java/org/000077500000000000000000000000001151645323700172225ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/000077500000000000000000000000001151645323700202375ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/BasicMultiMap.java000066400000000000000000000130641151645323700236000ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.Warnings; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class BasicMultiMap implements MultiMap, Serializable { private static final long serialVersionUID = 4716749660560043989L; private final Map> _impl; public BasicMultiMap() { this(new LinkedHashMap>()); } public BasicMultiMap(Map> impl) { _impl = impl; } @Override public List getAll(Object key) { return _impl.get(key); } @Override public boolean isEmpty() { return _impl.isEmpty(); } @Override public void add(K key, V value) { getList(key, true).add(value); } @Override public void add(K key, V value, int index) { getList(key, true).add(index, value); } @Override public void clear() { _impl.clear(); } @Override public boolean containsKey(Object key) { return _impl.containsKey(key); } @Override public boolean containsValue(Object value) { boolean ret = false; for (List all : _impl.values()) { if (all.contains(value)) { ret = true; break; } } return ret; } @Override public Set> entrySet() { Set> ret = new HashSet>(); for (K key : keySet()) { ret.add(new ShadowEntry(key)); } return ret; } @Override public V get(Object key) { List values = getList(key, false); return (values == null) ? null : values.get(values.size() - 1); } @Override public V get(Object key, int index) { List values = getList(key, false); return (values == null) ? null : values.get(index); } @Override public Set keySet() { return _impl.keySet(); } @Override public int length(Object key) { List values = getList(key, false); return (values == null) ? 0 : values.size(); } @Override public V put(K key, V value) { V ret = null; List values = getList(key, true); if (values.isEmpty()) { values.add(value); } else { ret = values.set(values.size() - 1, value); } return ret; } @Override public V put(K key, V value, int index) { return getList(key, false).set(index, value); } @SuppressWarnings(Warnings.UNCHECKED) @Override public void putAll(Map map) { if (map instanceof MultiMap) { MultiMap mm = (MultiMap) map; for (Object key : mm.keySet()) { putAll((K) key, mm.getAll(key)); } } else { for (K key : map.keySet()) { put(key, map.get(key)); } } } @Override public List putAll(K key, List values) { List ret = _impl.get(key); _impl.put(key, new ArrayList(values)); return ret; } @Override public V remove(Object key) { List prev = _impl.remove(key); return (prev == null) ? null : prev.get(0); } @Override public V remove(Object key, int index) { V ret = null; List values = getList(key, false); if (values != null) { ret = values.remove(index); if (values.isEmpty()) { _impl.remove(key); } } return ret; } @Override public int size() { return _impl.size(); } @Override public String toString() { return _impl.toString(); } @Override public Collection values() { List all = new ArrayList(_impl.size()); for (List values : _impl.values()) { all.addAll(values); } return all; } @SuppressWarnings(Warnings.UNCHECKED) private List getList(Object key, boolean create) { List values = _impl.get(key); if ((values == null) && create) { values = new ArrayList(); _impl.put((K) key, values); } return values; } class ShadowEntry implements Map.Entry { private final K _key; ShadowEntry(K key) { _key = key; } @Override public K getKey() { return _key; } @Override public V getValue() { return get(_key); } @Override public V setValue(V value) { return put(_key, value); } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/BasicOptionMap.java000066400000000000000000000221651151645323700237600ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.BeanAccess; import org.ini4j.spi.BeanTool; import org.ini4j.spi.Warnings; import java.lang.reflect.Array; import java.util.regex.Matcher; import java.util.regex.Pattern; public class BasicOptionMap extends CommonMultiMap implements OptionMap { private static final char SUBST_CHAR = '$'; private static final String SYSTEM_PROPERTY_PREFIX = "@prop/"; private static final String ENVIRONMENT_PREFIX = "@env/"; private static final int SYSTEM_PROPERTY_PREFIX_LEN = SYSTEM_PROPERTY_PREFIX.length(); private static final int ENVIRONMENT_PREFIX_LEN = ENVIRONMENT_PREFIX.length(); private static final Pattern EXPRESSION = Pattern.compile("(? T getAll(Object key, Class clazz) { requireArray(clazz); T value; value = (T) Array.newInstance(clazz.getComponentType(), length(key)); for (int i = 0; i < length(key); i++) { Array.set(value, i, BeanTool.getInstance().parse(get(key, i), clazz.getComponentType())); } return value; } @Override public void add(String key, Object value) { super.add(key, ((value == null) || (value instanceof String)) ? (String) value : String.valueOf(value)); } @Override public void add(String key, Object value, int index) { super.add(key, ((value == null) || (value instanceof String)) ? (String) value : String.valueOf(value), index); } @Override public T as(Class clazz) { return BeanTool.getInstance().proxy(clazz, getDefaultBeanAccess()); } @Override public T as(Class clazz, String keyPrefix) { return BeanTool.getInstance().proxy(clazz, newBeanAccess(keyPrefix)); } @Override public String fetch(Object key) { int len = length(key); return (len == 0) ? null : fetch(key, len - 1); } @Override public String fetch(Object key, int index) { String value = get(key, index); if ((value != null) && (value.indexOf(SUBST_CHAR) >= 0)) { StringBuilder buffer = new StringBuilder(value); resolve(buffer); value = buffer.toString(); } return value; } @Override public T fetch(Object key, Class clazz) { return BeanTool.getInstance().parse(fetch(key), clazz); } @Override public T fetch(Object key, int index, Class clazz) { return BeanTool.getInstance().parse(fetch(key, index), clazz); } @Override @SuppressWarnings(Warnings.UNCHECKED) public T fetchAll(Object key, Class clazz) { requireArray(clazz); T value; value = (T) Array.newInstance(clazz.getComponentType(), length(key)); for (int i = 0; i < length(key); i++) { Array.set(value, i, BeanTool.getInstance().parse(fetch(key, i), clazz.getComponentType())); } return value; } @Override public void from(Object bean) { BeanTool.getInstance().inject(getDefaultBeanAccess(), bean); } @Override public void from(Object bean, String keyPrefix) { BeanTool.getInstance().inject(newBeanAccess(keyPrefix), bean); } @Override public T get(Object key, Class clazz) { return BeanTool.getInstance().parse(get(key), clazz); } @Override public T get(Object key, int index, Class clazz) { return BeanTool.getInstance().parse(get(key, index), clazz); } @Override public String put(String key, Object value) { return super.put(key, ((value == null) || (value instanceof String)) ? (String) value : String.valueOf(value)); } @Override public String put(String key, Object value, int index) { return super.put(key, ((value == null) || (value instanceof String)) ? (String) value : String.valueOf(value), index); } @Override public void putAll(String key, Object value) { if (value != null) { requireArray(value.getClass()); } remove(key); if (value != null) { int n = Array.getLength(value); for (int i = 0; i < n; i++) { add(key, Array.get(value, i)); } } } @Override public void to(Object bean) { BeanTool.getInstance().inject(bean, getDefaultBeanAccess()); } @Override public void to(Object bean, String keyPrefix) { BeanTool.getInstance().inject(bean, newBeanAccess(keyPrefix)); } synchronized BeanAccess getDefaultBeanAccess() { if (_defaultBeanAccess == null) { _defaultBeanAccess = newBeanAccess(); } return _defaultBeanAccess; } boolean isPropertyFirstUpper() { return _propertyFirstUpper; } BeanAccess newBeanAccess() { return new Access(); } BeanAccess newBeanAccess(String propertyNamePrefix) { return new Access(propertyNamePrefix); } void resolve(StringBuilder buffer) { Matcher m = EXPRESSION.matcher(buffer); while (m.find()) { String name = m.group(G_OPTION); int index = (m.group(G_INDEX) == null) ? -1 : Integer.parseInt(m.group(G_INDEX)); String value; if (name.startsWith(ENVIRONMENT_PREFIX)) { value = Config.getEnvironment(name.substring(ENVIRONMENT_PREFIX_LEN)); } else if (name.startsWith(SYSTEM_PROPERTY_PREFIX)) { value = Config.getSystemProperty(name.substring(SYSTEM_PROPERTY_PREFIX_LEN)); } else { value = (index == -1) ? fetch(name) : fetch(name, index); } if (value != null) { buffer.replace(m.start(), m.end(), value); m.reset(buffer); } } } private void requireArray(Class clazz) { if (!clazz.isArray()) { throw new IllegalArgumentException("Array required"); } } class Access implements BeanAccess { private final String _prefix; Access() { this(null); } Access(String prefix) { _prefix = prefix; } @Override public void propAdd(String propertyName, String value) { add(transform(propertyName), value); } @Override public String propDel(String propertyName) { return remove(transform(propertyName)); } @Override public String propGet(String propertyName) { return fetch(transform(propertyName)); } @Override public String propGet(String propertyName, int index) { return fetch(transform(propertyName), index); } @Override public int propLength(String propertyName) { return length(transform(propertyName)); } @Override public String propSet(String propertyName, String value) { return put(transform(propertyName), value); } @Override public String propSet(String propertyName, String value, int index) { return put(transform(propertyName), value, index); } private String transform(String orig) { String ret = orig; if (((_prefix != null) || isPropertyFirstUpper()) && (orig != null)) { StringBuilder buff = new StringBuilder(); if (_prefix != null) { buff.append(_prefix); } if (isPropertyFirstUpper()) { buff.append(Character.toUpperCase(orig.charAt(0))); buff.append(orig.substring(1)); } else { buff.append(orig); } ret = buff.toString(); } return ret; } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/BasicProfile.java000066400000000000000000000230071151645323700234460ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.AbstractBeanInvocationHandler; import org.ini4j.spi.BeanTool; import org.ini4j.spi.IniHandler; import java.lang.reflect.Array; import java.lang.reflect.Proxy; import java.util.regex.Matcher; import java.util.regex.Pattern; public class BasicProfile extends CommonMultiMap implements Profile { private static final String SECTION_SYSTEM_PROPERTIES = "@prop"; private static final String SECTION_ENVIRONMENT = "@env"; private static final Pattern EXPRESSION = Pattern.compile( "(? 0) { String parent = name.substring(0, idx); if (!containsKey(parent)) { add(parent); } } } Section section = newSection(name); add(name, section); return section; } @Override public void add(String section, String option, Object value) { getOrAdd(section).add(option, value); } @Override public T as(Class clazz) { return as(clazz, null); } @Override public T as(Class clazz, String prefix) { return clazz.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { clazz }, new BeanInvocationHandler(prefix))); } @Override public String fetch(Object sectionName, Object optionName) { Section sec = get(sectionName); return (sec == null) ? null : sec.fetch(optionName); } @Override public T fetch(Object sectionName, Object optionName, Class clazz) { Section sec = get(sectionName); return (sec == null) ? BeanTool.getInstance().zero(clazz) : sec.fetch(optionName, clazz); } @Override public String get(Object sectionName, Object optionName) { Section sec = get(sectionName); return (sec == null) ? null : sec.get(optionName); } @Override public T get(Object sectionName, Object optionName, Class clazz) { Section sec = get(sectionName); return (sec == null) ? BeanTool.getInstance().zero(clazz) : sec.get(optionName, clazz); } @Override public String put(String sectionName, String optionName, Object value) { return getOrAdd(sectionName).put(optionName, value); } @Override public Section remove(Section section) { return remove((Object) section.getName()); } @Override public String remove(Object sectionName, Object optionName) { Section sec = get(sectionName); return (sec == null) ? null : sec.remove(optionName); } boolean isTreeMode() { return _treeMode; } char getPathSeparator() { return PATH_SEPARATOR; } boolean isPropertyFirstUpper() { return _propertyFirstUpper; } Section newSection(String name) { return new BasicProfileSection(this, name); } void resolve(StringBuilder buffer, Section owner) { Matcher m = EXPRESSION.matcher(buffer); while (m.find()) { String sectionName = m.group(G_SECTION); String optionName = m.group(G_OPTION); int optionIndex = parseOptionIndex(m); Section section = parseSection(m, owner); String value = null; if (SECTION_ENVIRONMENT.equals(sectionName)) { value = Config.getEnvironment(optionName); } else if (SECTION_SYSTEM_PROPERTIES.equals(sectionName)) { value = Config.getSystemProperty(optionName); } else if (section != null) { value = (optionIndex == -1) ? section.fetch(optionName) : section.fetch(optionName, optionIndex); } if (value != null) { buffer.replace(m.start(), m.end(), value); m.reset(buffer); } } } void store(IniHandler formatter) { formatter.startIni(); store(formatter, getComment()); for (Ini.Section s : values()) { store(formatter, s); } formatter.endIni(); } void store(IniHandler formatter, Section s) { store(formatter, getComment(s.getName())); formatter.startSection(s.getName()); for (String name : s.keySet()) { store(formatter, s, name); } formatter.endSection(); } void store(IniHandler formatter, String comment) { formatter.handleComment(comment); } void store(IniHandler formatter, Section section, String option) { store(formatter, section.getComment(option)); int n = section.length(option); for (int i = 0; i < n; i++) { store(formatter, section, option, i); } } void store(IniHandler formatter, Section section, String option, int index) { formatter.handleOption(option, section.get(option, index)); } private Section getOrAdd(String sectionName) { Section section = get(sectionName); return ((section == null)) ? add(sectionName) : section; } private int parseOptionIndex(Matcher m) { return (m.group(G_OPTION_IDX) == null) ? -1 : Integer.parseInt(m.group(G_OPTION_IDX)); } private Section parseSection(Matcher m, Section owner) { String sectionName = m.group(G_SECTION); int sectionIndex = parseSectionIndex(m); return (sectionName == null) ? owner : ((sectionIndex == -1) ? get(sectionName) : get(sectionName, sectionIndex)); } private int parseSectionIndex(Matcher m) { return (m.group(G_SECTION_IDX) == null) ? -1 : Integer.parseInt(m.group(G_SECTION_IDX)); } private final class BeanInvocationHandler extends AbstractBeanInvocationHandler { private final String _prefix; private BeanInvocationHandler(String prefix) { _prefix = prefix; } @Override protected Object getPropertySpi(String property, Class clazz) { String key = transform(property); Object o = null; if (containsKey(key)) { if (clazz.isArray()) { o = Array.newInstance(clazz.getComponentType(), length(key)); for (int i = 0; i < length(key); i++) { Array.set(o, i, get(key, i).as(clazz.getComponentType())); } } else { o = get(key).as(clazz); } } return o; } @Override protected void setPropertySpi(String property, Object value, Class clazz) { String key = transform(property); remove(key); if (value != null) { if (clazz.isArray()) { for (int i = 0; i < Array.getLength(value); i++) { Section sec = add(key); sec.from(Array.get(value, i)); } } else { Section sec = add(key); sec.from(value); } } } @Override protected boolean hasPropertySpi(String property) { return containsKey(transform(property)); } String transform(String property) { String ret = (_prefix == null) ? property : (_prefix + property); if (isPropertyFirstUpper()) { StringBuilder buff = new StringBuilder(); buff.append(Character.toUpperCase(property.charAt(0))); buff.append(property.substring(1)); ret = buff.toString(); } return ret; } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/BasicProfileSection.java000066400000000000000000000074661151645323700250060ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; class BasicProfileSection extends BasicOptionMap implements Profile.Section { private static final long serialVersionUID = 985800697957194374L; private static final String[] EMPTY_STRING_ARRAY = {}; private static final char REGEXP_ESCAPE_CHAR = '\\'; private final Pattern _childPattern; private final String _name; private final BasicProfile _profile; protected BasicProfileSection(BasicProfile profile, String name) { _profile = profile; _name = name; _childPattern = newChildPattern(name); } @Override public Profile.Section getChild(String key) { return _profile.get(childName(key)); } @Override public String getName() { return _name; } @Override public Profile.Section getParent() { Profile.Section ret = null; int idx = _name.lastIndexOf(_profile.getPathSeparator()); if (idx >= 0) { String name = _name.substring(0, idx); ret = _profile.get(name); } return ret; } @Override public String getSimpleName() { int idx = _name.lastIndexOf(_profile.getPathSeparator()); return (idx < 0) ? _name : _name.substring(idx + 1); } @Override public Profile.Section addChild(String key) { String name = childName(key); return _profile.add(name); } @Override public String[] childrenNames() { List names = new ArrayList(); for (String key : _profile.keySet()) { if (_childPattern.matcher(key).matches()) { names.add(key.substring(_name.length() + 1)); } } return names.toArray(EMPTY_STRING_ARRAY); } @Override public Profile.Section lookup(String... parts) { StringBuilder buff = new StringBuilder(); for (String part : parts) { if (buff.length() != 0) { buff.append(_profile.getPathSeparator()); } buff.append(part); } return _profile.get(childName(buff.toString())); } @Override public void removeChild(String key) { String name = childName(key); _profile.remove(name); } @Override boolean isPropertyFirstUpper() { return _profile.isPropertyFirstUpper(); } @Override void resolve(StringBuilder buffer) { _profile.resolve(buffer, this); } private String childName(String key) { StringBuilder buff = new StringBuilder(_name); buff.append(_profile.getPathSeparator()); buff.append(key); return buff.toString(); } private Pattern newChildPattern(String name) { StringBuilder buff = new StringBuilder(); buff.append('^'); buff.append(Pattern.quote(name)); buff.append(REGEXP_ESCAPE_CHAR); buff.append(_profile.getPathSeparator()); buff.append("[^"); buff.append(REGEXP_ESCAPE_CHAR); buff.append(_profile.getPathSeparator()); buff.append("]+$"); return Pattern.compile(buff.toString()); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/BasicRegistry.java000066400000000000000000000053371151645323700236640ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.Profile.Section; import org.ini4j.spi.IniHandler; import org.ini4j.spi.RegEscapeTool; import org.ini4j.spi.TypeValuesPair; public class BasicRegistry extends BasicProfile implements Registry { private static final long serialVersionUID = -6432826330714504802L; private String _version; public BasicRegistry() { _version = VERSION; } @Override public String getVersion() { return _version; } @Override public void setVersion(String value) { _version = value; } @Override public Key add(String name) { return (Key) super.add(name); } @Override public Key get(Object key) { return (Key) super.get(key); } @Override public Key get(Object key, int index) { return (Key) super.get(key, index); } @Override public Key put(String key, Section value) { return (Key) super.put(key, value); } @Override public Key put(String key, Section value, int index) { return (Key) super.put(key, value, index); } @Override public Key remove(Section section) { return (Key) super.remove(section); } @Override public Key remove(Object key) { return (Key) super.remove(key); } @Override public Key remove(Object key, int index) { return (Key) super.remove(key, index); } @Override Key newSection(String name) { return new BasicRegistryKey(this, name); } @Override void store(IniHandler formatter, Section section, String option) { store(formatter, section.getComment(option)); Type type = ((Key) section).getType(option, Type.REG_SZ); String rawName = option.equals(Key.DEFAULT_NAME) ? option : RegEscapeTool.getInstance().quote(option); String[] values = new String[section.length(option)]; for (int i = 0; i < values.length; i++) { values[i] = section.get(option, i); } String rawValue = RegEscapeTool.getInstance().encode(new TypeValuesPair(type, values)); formatter.handleOption(rawName, rawValue); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/BasicRegistryKey.java000066400000000000000000000036421151645323700243320ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.Registry.Key; class BasicRegistryKey extends BasicProfileSection implements Registry.Key { private static final long serialVersionUID = -1390060044244350928L; private static final String META_TYPE = "type"; public BasicRegistryKey(BasicRegistry registry, String name) { super(registry, name); } @Override public Key getChild(String key) { return (Key) super.getChild(key); } @Override public Key getParent() { return (Key) super.getParent(); } @Override public Registry.Type getType(Object key) { return (Registry.Type) getMeta(META_TYPE, key); } @Override public Registry.Type getType(Object key, Registry.Type defaultType) { Registry.Type type = getType(key); return (type == null) ? defaultType : type; } @Override public Key addChild(String key) { return (Key) super.addChild(key); } @Override public Key lookup(String... path) { return (Key) super.lookup(path); } @Override public Registry.Type putType(String key, Registry.Type type) { return (Registry.Type) putMeta(META_TYPE, key, type); } @Override public Registry.Type removeType(Object key) { return (Registry.Type) removeMeta(META_TYPE, key); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/CommentedMap.java000066400000000000000000000014671151645323700234630ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.util.Map; public interface CommentedMap extends Map { String getComment(Object key); String putComment(K key, String comment); String removeComment(Object key); } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/CommonMultiMap.java000066400000000000000000000065131151645323700240100ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; public class CommonMultiMap extends BasicMultiMap implements CommentedMap { private static final long serialVersionUID = 3012579878005541746L; private static final String SEPARATOR = ";#;"; private static final String FIRST_CATEGORY = ""; private static final String LAST_CATEGORY = "zzzzzzzzzzzzzzzzzzzzzz"; private static final String META_COMMENT = "comment"; private SortedMap _meta; @Override public String getComment(Object key) { return (String) getMeta(META_COMMENT, key); } @Override public void clear() { super.clear(); if (_meta != null) { _meta.clear(); } } @SuppressWarnings("unchecked") @Override public void putAll(Map map) { super.putAll(map); if (map instanceof CommonMultiMap) { Map meta = ((CommonMultiMap) map)._meta; if (meta != null) { meta().putAll(meta); } } } @Override public String putComment(K key, String comment) { return (String) putMeta(META_COMMENT, key, comment); } @Override public V remove(Object key) { V ret = super.remove(key); removeMeta(key); return ret; } @Override public V remove(Object key, int index) { V ret = super.remove(key, index); if (length(key) == 0) { removeMeta(key); } return ret; } @Override public String removeComment(Object key) { return (String) removeMeta(META_COMMENT, key); } Object getMeta(String category, Object key) { return (_meta == null) ? null : _meta.get(makeKey(category, key)); } Object putMeta(String category, K key, Object value) { return meta().put(makeKey(category, key), value); } void removeMeta(Object key) { if (_meta != null) { _meta.subMap(makeKey(FIRST_CATEGORY, key), makeKey(LAST_CATEGORY, key)).clear(); } } Object removeMeta(String category, Object key) { return (_meta == null) ? null : _meta.remove(makeKey(category, key)); } private String makeKey(String category, Object key) { StringBuilder buff = new StringBuilder(); buff.append(String.valueOf(key)); buff.append(SEPARATOR); buff.append(category); return buff.toString(); } private Map meta() { if (_meta == null) { _meta = new TreeMap(); } return _meta; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/Config.java000066400000000000000000000252641151645323700223200ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.io.Serializable; import java.nio.charset.Charset; @SuppressWarnings("PMD.ExcessivePublicCount") public class Config implements Cloneable, Serializable { public static final String KEY_PREFIX = "org.ini4j.config."; public static final String PROP_EMPTY_OPTION = "emptyOption"; public static final String PROP_EMPTY_SECTION = "emptySection"; public static final String PROP_GLOBAL_SECTION = "globalSection"; public static final String PROP_GLOBAL_SECTION_NAME = "globalSectionName"; public static final String PROP_INCLUDE = "include"; public static final String PROP_LOWER_CASE_OPTION = "lowerCaseOption"; public static final String PROP_LOWER_CASE_SECTION = "lowerCaseSection"; public static final String PROP_MULTI_OPTION = "multiOption"; public static final String PROP_MULTI_SECTION = "multiSection"; public static final String PROP_STRICT_OPERATOR = "strictOperator"; public static final String PROP_UNNAMED_SECTION = "unnamedSection"; public static final String PROP_ESCAPE = "escape"; public static final String PROP_PATH_SEPARATOR = "pathSeparator"; public static final String PROP_TREE = "tree"; public static final String PROP_PROPERTY_FIRST_UPPER = "propertyFirstUpper"; public static final String PROP_FILE_ENCODING = "fileEncoding"; public static final String PROP_LINE_SEPARATOR = "lineSeparator"; public static final String PROP_COMMENT = "comment"; public static final String PROP_HEADER_COMMENT = "headerComment"; public static final boolean DEFAULT_EMPTY_OPTION = false; public static final boolean DEFAULT_EMPTY_SECTION = false; public static final boolean DEFAULT_GLOBAL_SECTION = false; public static final String DEFAULT_GLOBAL_SECTION_NAME = "?"; public static final boolean DEFAULT_INCLUDE = false; public static final boolean DEFAULT_LOWER_CASE_OPTION = false; public static final boolean DEFAULT_LOWER_CASE_SECTION = false; public static final boolean DEFAULT_MULTI_OPTION = true; public static final boolean DEFAULT_MULTI_SECTION = false; public static final boolean DEFAULT_STRICT_OPERATOR = false; public static final boolean DEFAULT_UNNAMED_SECTION = false; public static final boolean DEFAULT_ESCAPE = true; public static final boolean DEFAULT_TREE = true; public static final boolean DEFAULT_PROPERTY_FIRST_UPPER = false; public static final boolean DEFAULT_COMMENT = true; public static final boolean DEFAULT_HEADER_COMMENT = true; public static final char DEFAULT_PATH_SEPARATOR = '/'; public static final String DEFAULT_LINE_SEPARATOR = getSystemProperty("line.separator", "\n"); public static final Charset DEFAULT_FILE_ENCODING = Charset.forName("UTF-8"); private static final Config GLOBAL = new Config(); private static final long serialVersionUID = 2865793267410367814L; private boolean _comment; private boolean _emptyOption; private boolean _emptySection; private boolean _escape; private Charset _fileEncoding; private boolean _globalSection; private String _globalSectionName; private boolean _headerComment; private boolean _include; private String _lineSeparator; private boolean _lowerCaseOption; private boolean _lowerCaseSection; private boolean _multiOption; private boolean _multiSection; private char _pathSeparator; private boolean _propertyFirstUpper; private boolean _strictOperator; private boolean _tree; private boolean _unnamedSection; public Config() { reset(); } public static String getEnvironment(String name) { return getEnvironment(name, null); } public static String getEnvironment(String name, String defaultValue) { String value; try { value = System.getenv(name); } catch (SecurityException x) { value = null; } return (value == null) ? defaultValue : value; } public static Config getGlobal() { return GLOBAL; } public static String getSystemProperty(String name) { return getSystemProperty(name, null); } public static String getSystemProperty(String name, String defaultValue) { String value; try { value = System.getProperty(name); } catch (SecurityException x) { value = null; } return (value == null) ? defaultValue : value; } public void setComment(boolean value) { _comment = value; } public boolean isEscape() { return _escape; } public boolean isInclude() { return _include; } public boolean isTree() { return _tree; } public void setEmptyOption(boolean value) { _emptyOption = value; } public void setEmptySection(boolean value) { _emptySection = value; } public void setEscape(boolean value) { _escape = value; } public Charset getFileEncoding() { return _fileEncoding; } public void setFileEncoding(Charset value) { _fileEncoding = value; } public void setGlobalSection(boolean value) { _globalSection = value; } public String getGlobalSectionName() { return _globalSectionName; } public void setGlobalSectionName(String value) { _globalSectionName = value; } public void setHeaderComment(boolean value) { _headerComment = value; } public void setInclude(boolean value) { _include = value; } public String getLineSeparator() { return _lineSeparator; } public void setLineSeparator(String value) { _lineSeparator = value; } public void setLowerCaseOption(boolean value) { _lowerCaseOption = value; } public void setLowerCaseSection(boolean value) { _lowerCaseSection = value; } public void setMultiOption(boolean value) { _multiOption = value; } public void setMultiSection(boolean value) { _multiSection = value; } public boolean isEmptyOption() { return _emptyOption; } public boolean isEmptySection() { return _emptySection; } public boolean isGlobalSection() { return _globalSection; } public boolean isLowerCaseOption() { return _lowerCaseOption; } public boolean isLowerCaseSection() { return _lowerCaseSection; } public boolean isMultiOption() { return _multiOption; } public boolean isMultiSection() { return _multiSection; } public boolean isUnnamedSection() { return _unnamedSection; } public char getPathSeparator() { return _pathSeparator; } public void setPathSeparator(char value) { _pathSeparator = value; } public void setPropertyFirstUpper(boolean value) { _propertyFirstUpper = value; } public boolean isPropertyFirstUpper() { return _propertyFirstUpper; } public boolean isStrictOperator() { return _strictOperator; } public void setStrictOperator(boolean value) { _strictOperator = value; } public boolean isComment() { return _comment; } public boolean isHeaderComment() { return _headerComment; } public void setTree(boolean value) { _tree = value; } public void setUnnamedSection(boolean value) { _unnamedSection = value; } @Override public Config clone() { try { return (Config) super.clone(); } catch (CloneNotSupportedException x) { throw new AssertionError(x); } } public final void reset() { _emptyOption = getBoolean(PROP_EMPTY_OPTION, DEFAULT_EMPTY_OPTION); _emptySection = getBoolean(PROP_EMPTY_SECTION, DEFAULT_EMPTY_SECTION); _globalSection = getBoolean(PROP_GLOBAL_SECTION, DEFAULT_GLOBAL_SECTION); _globalSectionName = getString(PROP_GLOBAL_SECTION_NAME, DEFAULT_GLOBAL_SECTION_NAME); _include = getBoolean(PROP_INCLUDE, DEFAULT_INCLUDE); _lowerCaseOption = getBoolean(PROP_LOWER_CASE_OPTION, DEFAULT_LOWER_CASE_OPTION); _lowerCaseSection = getBoolean(PROP_LOWER_CASE_SECTION, DEFAULT_LOWER_CASE_SECTION); _multiOption = getBoolean(PROP_MULTI_OPTION, DEFAULT_MULTI_OPTION); _multiSection = getBoolean(PROP_MULTI_SECTION, DEFAULT_MULTI_SECTION); _strictOperator = getBoolean(PROP_STRICT_OPERATOR, DEFAULT_STRICT_OPERATOR); _unnamedSection = getBoolean(PROP_UNNAMED_SECTION, DEFAULT_UNNAMED_SECTION); _escape = getBoolean(PROP_ESCAPE, DEFAULT_ESCAPE); _pathSeparator = getChar(PROP_PATH_SEPARATOR, DEFAULT_PATH_SEPARATOR); _tree = getBoolean(PROP_TREE, DEFAULT_TREE); _propertyFirstUpper = getBoolean(PROP_PROPERTY_FIRST_UPPER, DEFAULT_PROPERTY_FIRST_UPPER); _lineSeparator = getString(PROP_LINE_SEPARATOR, DEFAULT_LINE_SEPARATOR); _fileEncoding = getCharset(PROP_FILE_ENCODING, DEFAULT_FILE_ENCODING); _comment = getBoolean(PROP_COMMENT, DEFAULT_COMMENT); _headerComment = getBoolean(PROP_HEADER_COMMENT, DEFAULT_HEADER_COMMENT); } private boolean getBoolean(String name, boolean defaultValue) { String value = getSystemProperty(KEY_PREFIX + name); return (value == null) ? defaultValue : Boolean.parseBoolean(value); } private char getChar(String name, char defaultValue) { String value = getSystemProperty(KEY_PREFIX + name); return (value == null) ? defaultValue : value.charAt(0); } private Charset getCharset(String name, Charset defaultValue) { String value = getSystemProperty(KEY_PREFIX + name); return (value == null) ? defaultValue : Charset.forName(value); } private String getString(String name, String defaultValue) { return getSystemProperty(KEY_PREFIX + name, defaultValue); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/ConfigParser.java000066400000000000000000000365621151645323700235000ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.IniHandler; import org.ini4j.spi.Warnings; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Serializable; import java.io.Writer; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ConfigParser implements Serializable { private static final long serialVersionUID = 9118857036229164353L; private PyIni _ini; @SuppressWarnings(Warnings.UNCHECKED) public ConfigParser() { this(Collections.EMPTY_MAP); } public ConfigParser(Map defaults) { _ini = new PyIni(defaults); } public boolean getBoolean(String section, String option) throws NoSectionException, NoOptionException, InterpolationException { boolean ret; String value = get(section, option); if ("1".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value) || "on".equalsIgnoreCase(value)) { ret = true; } else if ("0".equalsIgnoreCase(value) || "no".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value) || "off".equalsIgnoreCase(value)) { ret = false; } else { throw new IllegalArgumentException(value); } return ret; } public double getDouble(String section, String option) throws NoSectionException, NoOptionException, InterpolationException { return Double.parseDouble(get(section, option)); } public float getFloat(String section, String option) throws NoSectionException, NoOptionException, InterpolationException { return Float.parseFloat(get(section, option)); } public int getInt(String section, String option) throws NoSectionException, NoOptionException, InterpolationException { return Integer.parseInt(get(section, option)); } public long getLong(String section, String option) throws NoSectionException, NoOptionException, InterpolationException { return Long.parseLong(get(section, option)); } public void addSection(String section) throws DuplicateSectionException { if (_ini.containsKey(section)) { throw new DuplicateSectionException(section); } else if (PyIni.DEFAULT_SECTION_NAME.equalsIgnoreCase(section)) { throw new IllegalArgumentException(section); } _ini.add(section); } public Map defaults() { return _ini.getDefaults(); } @SuppressWarnings(Warnings.UNCHECKED) public String get(String section, String option) throws NoSectionException, NoOptionException, InterpolationException { return get(section, option, false, Collections.EMPTY_MAP); } @SuppressWarnings(Warnings.UNCHECKED) public String get(String section, String option, boolean raw) throws NoSectionException, NoOptionException, InterpolationException { return get(section, option, raw, Collections.EMPTY_MAP); } public String get(String sectionName, String optionName, boolean raw, Map variables) throws NoSectionException, NoOptionException, InterpolationException { String value = requireOption(sectionName, optionName); if (!raw && (value != null) && (value.indexOf(PyIni.SUBST_CHAR) >= 0)) { value = _ini.fetch(sectionName, optionName, variables); } return value; } public boolean hasOption(String sectionName, String optionName) { Ini.Section section = _ini.get(sectionName); return (section != null) && section.containsKey(optionName); } public boolean hasSection(String sectionName) { return _ini.containsKey(sectionName); } @SuppressWarnings(Warnings.UNCHECKED) public List> items(String sectionName) throws NoSectionException, InterpolationMissingOptionException { return items(sectionName, false, Collections.EMPTY_MAP); } @SuppressWarnings(Warnings.UNCHECKED) public List> items(String sectionName, boolean raw) throws NoSectionException, InterpolationMissingOptionException { return items(sectionName, raw, Collections.EMPTY_MAP); } public List> items(String sectionName, boolean raw, Map variables) throws NoSectionException, InterpolationMissingOptionException { Ini.Section section = requireSection(sectionName); Map ret; if (raw) { ret = new HashMap(section); } else { ret = new HashMap(); for (String key : section.keySet()) { ret.put(key, _ini.fetch(section, key, variables)); } } return new ArrayList>(ret.entrySet()); } public List options(String sectionName) throws NoSectionException { requireSection(sectionName); return new ArrayList(_ini.get(sectionName).keySet()); } public void read(String... filenames) throws IOException, ParsingException { for (String filename : filenames) { read(new File(filename)); } } public void read(Reader reader) throws IOException, ParsingException { try { _ini.load(reader); } catch (InvalidFileFormatException x) { throw new ParsingException(x); } } public void read(URL url) throws IOException, ParsingException { try { _ini.load(url); } catch (InvalidFileFormatException x) { throw new ParsingException(x); } } public void read(File file) throws IOException, ParsingException { try { _ini.load(new FileReader(file)); } catch (InvalidFileFormatException x) { throw new ParsingException(x); } } public void read(InputStream stream) throws IOException, ParsingException { try { _ini.load(stream); } catch (InvalidFileFormatException x) { throw new ParsingException(x); } } public boolean removeOption(String sectionName, String optionName) throws NoSectionException { Ini.Section section = requireSection(sectionName); boolean ret = section.containsKey(optionName); section.remove(optionName); return ret; } public boolean removeSection(String sectionName) { boolean ret = _ini.containsKey(sectionName); _ini.remove(sectionName); return ret; } public List sections() { return new ArrayList(_ini.keySet()); } public void set(String sectionName, String optionName, Object value) throws NoSectionException { Ini.Section section = requireSection(sectionName); if (value == null) { section.remove(optionName); } else { section.put(optionName, value.toString()); } } public void write(Writer writer) throws IOException { _ini.store(writer); } public void write(OutputStream stream) throws IOException { _ini.store(stream); } public void write(File file) throws IOException { _ini.store(new FileWriter(file)); } protected Ini getIni() { return _ini; } private String requireOption(String sectionName, String optionName) throws NoSectionException, NoOptionException { Ini.Section section = requireSection(sectionName); String option = section.get(optionName); if (option == null) { throw new NoOptionException(optionName); } return option; } private Ini.Section requireSection(String sectionName) throws NoSectionException { Ini.Section section = _ini.get(sectionName); if (section == null) { throw new NoSectionException(sectionName); } return section; } public static class ConfigParserException extends Exception { /** Use serialVersionUID for interoperability. */ private static final long serialVersionUID = -6845546313519392093L; public ConfigParserException(String message) { super(message); } } public static final class DuplicateSectionException extends ConfigParserException { /** Use serialVersionUID for interoperability. */ private static final long serialVersionUID = -5244008445735700699L; private DuplicateSectionException(String message) { super(message); } } public static class InterpolationException extends ConfigParserException { /** Use serialVersionUID for interoperability. */ private static final long serialVersionUID = 8924443303158546939L; protected InterpolationException(String message) { super(message); } } public static final class InterpolationMissingOptionException extends InterpolationException { /** Use serialVersionUID for interoperability. */ private static final long serialVersionUID = 2903136975820447879L; private InterpolationMissingOptionException(String message) { super(message); } } public static final class NoOptionException extends ConfigParserException { /** Use serialVersionUID for interoperability. */ private static final long serialVersionUID = 8460082078809425858L; private NoOptionException(String message) { super(message); } } public static final class NoSectionException extends ConfigParserException { /** Use serialVersionUID for interoperability. */ private static final long serialVersionUID = 8553627727493146118L; private NoSectionException(String message) { super(message); } } public static final class ParsingException extends IOException { /** Use serialVersionUID for interoperability. */ private static final long serialVersionUID = -5395990242007205038L; private ParsingException(Throwable cause) { super(cause.getMessage()); initCause(cause); } } static class PyIni extends Ini { private static final char SUBST_CHAR = '%'; private static final Pattern EXPRESSION = Pattern.compile("(? _defaults; private Ini.Section _defaultSection; public PyIni(Map defaults) { _defaults = defaults; Config cfg = getConfig().clone(); cfg.setEscape(false); cfg.setMultiOption(false); cfg.setMultiSection(false); cfg.setLowerCaseOption(true); cfg.setLowerCaseSection(true); super.setConfig(cfg); } @Override public void setConfig(Config value) { assert true; } public Map getDefaults() { return _defaults; } @Override public Section add(String name) { Section section; if (DEFAULT_SECTION_NAME.equalsIgnoreCase(name)) { if (_defaultSection == null) { _defaultSection = newSection(name); } section = _defaultSection; } else { section = super.add(name); } return section; } public String fetch(String sectionName, String optionName, Map variables) throws InterpolationMissingOptionException { return fetch(get(sectionName), optionName, variables); } protected Ini.Section getDefaultSection() { return _defaultSection; } protected String fetch(Ini.Section section, String optionName, Map variables) throws InterpolationMissingOptionException { String value = section.get(optionName); if ((value != null) && (value.indexOf(SUBST_CHAR) >= 0)) { StringBuilder buffer = new StringBuilder(value); resolve(buffer, section, variables); value = buffer.toString(); } return value; } protected void resolve(StringBuilder buffer, Ini.Section owner, Map vars) throws InterpolationMissingOptionException { Matcher m = EXPRESSION.matcher(buffer); while (m.find()) { String optionName = m.group(G_OPTION); String value = owner.get(optionName); if (value == null) { value = vars.get(optionName); } if (value == null) { value = _defaults.get(optionName); } if ((value == null) && (_defaultSection != null)) { value = _defaultSection.get(optionName); } if (value == null) { throw new InterpolationMissingOptionException(optionName); } buffer.replace(m.start(), m.end(), value); m.reset(buffer); } } @Override protected void store(IniHandler formatter) { formatter.startIni(); if (_defaultSection != null) { store(formatter, _defaultSection); } for (Ini.Section s : values()) { store(formatter, s); } formatter.endIni(); } @Override protected void store(IniHandler formatter, Section section) { formatter.startSection(section.getName()); for (String name : section.keySet()) { formatter.handleOption(name, section.get(name)); } formatter.endSection(); } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/Configurable.java000066400000000000000000000013121151645323700234770ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; public interface Configurable { Config getConfig(); void setConfig(Config value); } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/Ini.java000066400000000000000000000110341151645323700216200ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.IniBuilder; import org.ini4j.spi.IniFormatter; import org.ini4j.spi.IniHandler; import org.ini4j.spi.IniParser; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.net.URL; public class Ini extends BasicProfile implements Persistable, Configurable { private static final long serialVersionUID = -6029486578113700585L; private Config _config; private File _file; public Ini() { _config = Config.getGlobal(); } public Ini(Reader input) throws IOException, InvalidFileFormatException { this(); load(input); } public Ini(InputStream input) throws IOException, InvalidFileFormatException { this(); load(input); } public Ini(URL input) throws IOException, InvalidFileFormatException { this(); load(input); } public Ini(File input) throws IOException, InvalidFileFormatException { this(); _file = input; load(); } @Override public Config getConfig() { return _config; } @Override public void setConfig(Config value) { _config = value; } @Override public File getFile() { return _file; } @Override public void setFile(File value) { _file = value; } @Override public void load() throws IOException, InvalidFileFormatException { if (_file == null) { throw new FileNotFoundException(); } load(_file); } @Override public void load(InputStream input) throws IOException, InvalidFileFormatException { load(new InputStreamReader(input, getConfig().getFileEncoding())); } @Override public void load(Reader input) throws IOException, InvalidFileFormatException { IniParser.newInstance(getConfig()).parse(input, newBuilder()); } @Override public void load(File input) throws IOException, InvalidFileFormatException { load(input.toURI().toURL()); } @Override public void load(URL input) throws IOException, InvalidFileFormatException { IniParser.newInstance(getConfig()).parse(input, newBuilder()); } @Override public void store() throws IOException { if (_file == null) { throw new FileNotFoundException(); } store(_file); } @Override public void store(OutputStream output) throws IOException { store(new OutputStreamWriter(output, getConfig().getFileEncoding())); } @Override public void store(Writer output) throws IOException { store(IniFormatter.newInstance(output, getConfig())); } @Override public void store(File output) throws IOException { OutputStream stream = new FileOutputStream(output); store(stream); stream.close(); } protected IniHandler newBuilder() { return IniBuilder.newInstance(this); } @Override protected void store(IniHandler formatter, Profile.Section section) { if (getConfig().isEmptySection() || (section.size() != 0)) { super.store(formatter, section); } } @Override protected void store(IniHandler formatter, Profile.Section section, String option, int index) { if (getConfig().isMultiOption() || (index == (section.length(option) - 1))) { super.store(formatter, section, option, index); } } @Override boolean isTreeMode() { return getConfig().isTree(); } @Override char getPathSeparator() { return getConfig().getPathSeparator(); } @Override boolean isPropertyFirstUpper() { return getConfig().isPropertyFirstUpper(); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/IniPreferences.java000066400000000000000000000355571151645323700240220ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.prefs.AbstractPreferences; import java.util.prefs.BackingStoreException; public class IniPreferences extends AbstractPreferences { /** frequently used empty String array */ private static final String[] EMPTY = {}; /** underlaying Ini implementation */ private final Ini _ini; /** * Constructs a new preferences node on top of Ini instance. * * @param ini underlaying Ini instance */ public IniPreferences(Ini ini) { super(null, ""); _ini = ini; } /** * Constructs a new preferences node based on newly loaded Ini instance. * * This is just a helper constructor, to make simpler constructing IniPreferences * directly from Reader. * * @param input the Reader containing Ini data * @throws IOException if an I/O error occured * @throws InvalidFileFormatException if Ini parsing error occured */ public IniPreferences(Reader input) throws IOException, InvalidFileFormatException { super(null, ""); _ini = new Ini(input); } /** * Constructs a new preferences node based on newly loaded Ini instance. * * This is just a helper constructor, to make simpler constructing IniPreferences * directly from InputStream. * * @param input the InputStream containing Ini data * @throws IOException if an I/O error occured * @throws InvalidFileFormatException if Ini parsing error occured */ public IniPreferences(InputStream input) throws IOException, InvalidFileFormatException { super(null, ""); _ini = new Ini(input); } /** * Constructs a new preferences node based on newly loaded Ini instance. * * This is just a helper constructor, to make simpler constructing IniPreferences * directly from URL. * * @param input the URL containing Ini data * @throws IOException if an I/O error occured * @throws InvalidFileFormatException if Ini parsing error occured */ public IniPreferences(URL input) throws IOException, InvalidFileFormatException { super(null, ""); _ini = new Ini(input); } /** * Provide access to underlaying {@link org.ini4j.Ini} implementation. * * @return Ini implementation */ protected Ini getIni() { return _ini; } /** * Implements the getSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#getSpi(String)}. * * This implementation doesn't support this operation, so allways throws UnsupportedOperationException. * * @return if the value associated with the specified key at this preference node, or null if there is no association for this key, or the association cannot be determined at this time. * @param key key to getvalue for * @throws UnsupportedOperationException this implementation allways throws this exception */ @Override protected String getSpi(String key) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } /** * Implements the childrenNamesSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#childrenNamesSpi()}. * @return an array containing the names of the children of this preference node. * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override protected String[] childrenNamesSpi() throws BackingStoreException { List names = new ArrayList(); for (String name : _ini.keySet()) { if (name.indexOf(_ini.getPathSeparator()) < 0) { names.add(name); } } return names.toArray(EMPTY); } /** * Implements the childSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#childSpi(String)}. * @param name child name * @return child node */ @Override protected SectionPreferences childSpi(String name) { Ini.Section sec = _ini.get(name); boolean isNew = sec == null; if (isNew) { sec = _ini.add(name); } return new SectionPreferences(this, sec, isNew); } /** * Implements the flushSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#flushSpi()}. * * This implementation does nothing. * * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override protected void flushSpi() throws BackingStoreException { assert true; } /** * Implements the keysSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#keysSpi()}. * * This implementation allways return an empty array. * * @return an empty array. * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override protected String[] keysSpi() throws BackingStoreException { return EMPTY; } /** * Implements the putSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#putSpi(String,String)}. * * This implementation doesn;t support this operation, so allways throws UnsupportedOperationException. * * @param key key to set value for * @param value new value for key * @throws UnsupportedOperationException this implementation allways throws this exception */ @Override protected void putSpi(String key, String value) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } /** * Implements the removeNodeSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#removeNodeSpi()}. * * This implementation doesn;t support this operation, so allways throws UnsupportedOperationException. * @throws UnsupportedOperationException this implementation allways throws this exception * @throws BackingStoreException this implementation never throws this exception */ @Override protected void removeNodeSpi() throws BackingStoreException, UnsupportedOperationException { throw new UnsupportedOperationException(); } /** * Implements the removeSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#removeSpi(String)}. * @param key key to remove * @throws UnsupportedOperationException this implementation allways throws this exception */ @Override protected void removeSpi(String key) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } /** * Implements the syncSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#syncSpi()}. * * This implementation does nothing. * * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override protected void syncSpi() throws BackingStoreException { assert true; } protected class SectionPreferences extends AbstractPreferences { /** underlaying Section implementation */ private final Ini.Section _section; /** * Constructs a new SectionPreferences instance on top of Ini.Section instance. * * @param parent parent preferences node * @parem section underlaying Ini.Section instance * @param isNew indicate is this a new node or already existing one */ SectionPreferences(AbstractPreferences parent, Ini.Section section, boolean isNew) { super(parent, section.getSimpleName()); _section = section; newNode = isNew; } /** * Implements the flush method as per the specification in * {@link java.util.prefs.Preferences#flush()}. * * This implementation just call parent's flush() method. * * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override public void flush() throws BackingStoreException { parent().flush(); } /** * Implements the sync method as per the specification in * {@link java.util.prefs.Preferences#sync()}. * * This implementation just call parent's sync() method. * * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override public void sync() throws BackingStoreException { parent().sync(); } /** * Implements the getSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#getSpi(String)}. * @return if the value associated with the specified key at this preference node, or null if there is no association for this key, or the association cannot be determined at this time. * @param key key to getvalue for */ @Override protected String getSpi(String key) { return _section.fetch(key); } /** * Implements the childrenNamesSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#childrenNamesSpi()}. * * This implementation allways returns an empty array. * * @return an emty array. * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override protected String[] childrenNamesSpi() throws BackingStoreException { return _section.childrenNames(); } /** * Implements the childSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#childSpi(String)}. * * This implementation doesn't support this operation. * * @throws UnsupportedOperationException this implementation allways throws this exception * @param name child name * @return child node */ @Override protected SectionPreferences childSpi(String name) throws UnsupportedOperationException { Ini.Section child = _section.getChild(name); boolean isNew = child == null; if (isNew) { child = _section.addChild(name); } return new SectionPreferences(this, child, isNew); } /** * Implements the flushSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#flushSpi()}. * * This implementation does nothing. * * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override protected void flushSpi() throws BackingStoreException { assert true; } /** * Implements the keysSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#keysSpi()}. * * @return an array of the keys that have an associated value in this preference node. * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override protected String[] keysSpi() throws BackingStoreException { return _section.keySet().toArray(EMPTY); } /** * Implements the putSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#putSpi(String,String)}. * * @param key key to set value for * @param value new value of key */ @Override protected void putSpi(String key, String value) { _section.put(key, value); } /** * Implements the removeNodeSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#removeNodeSpi()}. * * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override protected void removeNodeSpi() throws BackingStoreException { _ini.remove(_section); } /** * Implements the removeSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#removeSpi(String)}. * @param key key to remove */ @Override protected void removeSpi(String key) { _section.remove(key); } /** * Implements the syncSpi method as per the specification in * {@link java.util.prefs.AbstractPreferences#syncSpi()}. * * This implementation does nothing. * * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. */ @Override protected void syncSpi() throws BackingStoreException { assert true; } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/IniPreferencesFactory.java000066400000000000000000000065601151645323700253420ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.io.InputStream; import java.net.URI; import java.net.URL; import java.util.Properties; import java.util.prefs.Preferences; import java.util.prefs.PreferencesFactory; public class IniPreferencesFactory implements PreferencesFactory { public static final String PROPERTIES = "ini4j.properties"; public static final String KEY_USER = "org.ini4j.prefs.user"; public static final String KEY_SYSTEM = "org.ini4j.prefs.system"; private Preferences _system; private Preferences _user; @Override public synchronized Preferences systemRoot() { if (_system == null) { _system = newIniPreferences(KEY_SYSTEM); } return _system; } @Override public synchronized Preferences userRoot() { if (_user == null) { _user = newIniPreferences(KEY_USER); } return _user; } String getIniLocation(String key) { String location = Config.getSystemProperty(key); if (location == null) { try { Properties props = new Properties(); props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(PROPERTIES)); location = props.getProperty(key); } catch (Exception x) { assert true; } } return location; } URL getResource(String location) throws IllegalArgumentException { try { URI uri = new URI(location); URL url; if (uri.getScheme() == null) { url = Thread.currentThread().getContextClassLoader().getResource(location); } else { url = uri.toURL(); } return url; } catch (Exception x) { throw (IllegalArgumentException) new IllegalArgumentException().initCause(x); } } InputStream getResourceAsStream(String location) throws IllegalArgumentException { try { return getResource(location).openStream(); } catch (Exception x) { throw (IllegalArgumentException) new IllegalArgumentException().initCause(x); } } Preferences newIniPreferences(String key) { Ini ini = new Ini(); String location = getIniLocation(key); if (location != null) { try { ini.load(getResourceAsStream(location)); } catch (Exception x) { throw (IllegalArgumentException) new IllegalArgumentException().initCause(x); } } return new IniPreferences(ini); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/InvalidFileFormatException.java000066400000000000000000000015551151645323700263260ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.io.IOException; public class InvalidFileFormatException extends IOException { private static final long serialVersionUID = -4354616830804732309L; public InvalidFileFormatException(String message) { super(message); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/MultiMap.java000066400000000000000000000017631151645323700226410ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.util.List; import java.util.Map; public interface MultiMap extends Map { List getAll(Object key); void add(K key, V value); void add(K key, V value, int index); V get(Object key, int index); int length(Object key); V put(K key, V value, int index); List putAll(K key, List values); V remove(Object key, int index); } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/OptionMap.java000066400000000000000000000030131151645323700230050ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; public interface OptionMap extends MultiMap, CommentedMap { T getAll(Object key, Class clazz); void add(String key, Object value); void add(String key, Object value, int index); T as(Class clazz); T as(Class clazz, String keyPrefix); String fetch(Object key); String fetch(Object key, int index); T fetch(Object key, Class clazz); T fetch(Object key, int index, Class clazz); T fetchAll(Object key, Class clazz); void from(Object bean); void from(Object bean, String keyPrefix); T get(Object key, Class clazz); T get(Object key, int index, Class clazz); String put(String key, Object value); String put(String key, Object value, int index); void putAll(String key, Object value); void to(Object bean); void to(Object bean, String keyPrefix); } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/Options.java000066400000000000000000000114371151645323700225430ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.OptionsBuilder; import org.ini4j.spi.OptionsFormatter; import org.ini4j.spi.OptionsHandler; import org.ini4j.spi.OptionsParser; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.net.URL; public class Options extends BasicOptionMap implements Persistable, Configurable { private static final long serialVersionUID = -1119753444859181822L; private String _comment; private Config _config; private File _file; public Options() { _config = Config.getGlobal().clone(); _config.setEmptyOption(true); } public Options(Reader input) throws IOException, InvalidFileFormatException { this(); load(input); } public Options(InputStream input) throws IOException, InvalidFileFormatException { this(); load(input); } public Options(URL input) throws IOException, InvalidFileFormatException { this(); load(input); } public Options(File input) throws IOException, InvalidFileFormatException { this(); _file = input; load(); } public String getComment() { return _comment; } public void setComment(String value) { _comment = value; } @Override public Config getConfig() { return _config; } @Override public void setConfig(Config value) { _config = value; } @Override public File getFile() { return _file; } @Override public void setFile(File value) { _file = value; } @Override public void load() throws IOException, InvalidFileFormatException { if (_file == null) { throw new FileNotFoundException(); } load(_file); } @Override public void load(InputStream input) throws IOException, InvalidFileFormatException { load(new InputStreamReader(input, getConfig().getFileEncoding())); } @Override public void load(Reader input) throws IOException, InvalidFileFormatException { OptionsParser.newInstance(getConfig()).parse(input, newBuilder()); } @Override public void load(URL input) throws IOException, InvalidFileFormatException { OptionsParser.newInstance(getConfig()).parse(input, newBuilder()); } @Override public void load(File input) throws IOException, InvalidFileFormatException { load(input.toURI().toURL()); } @Override public void store() throws IOException { if (_file == null) { throw new FileNotFoundException(); } store(_file); } @Override public void store(OutputStream output) throws IOException { store(new OutputStreamWriter(output, getConfig().getFileEncoding())); } @Override public void store(Writer output) throws IOException { store(OptionsFormatter.newInstance(output, getConfig())); } @Override public void store(File output) throws IOException { OutputStream stream = new FileOutputStream(output); store(stream); stream.close(); } protected OptionsHandler newBuilder() { return OptionsBuilder.newInstance(this); } protected void store(OptionsHandler formatter) throws IOException { formatter.startOptions(); storeComment(formatter, _comment); for (String name : keySet()) { storeComment(formatter, getComment(name)); int n = getConfig().isMultiOption() ? length(name) : 1; for (int i = 0; i < n; i++) { String value = get(name, i); formatter.handleOption(name, value); } } formatter.endOptions(); } @Override boolean isPropertyFirstUpper() { return getConfig().isPropertyFirstUpper(); } private void storeComment(OptionsHandler formatter, String comment) { formatter.handleComment(comment); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/Persistable.java000066400000000000000000000026501151645323700233620ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; import java.net.URL; public interface Persistable { File getFile(); void setFile(File value); void load() throws IOException, InvalidFileFormatException; void load(InputStream input) throws IOException, InvalidFileFormatException; void load(Reader input) throws IOException, InvalidFileFormatException; void load(File input) throws IOException, InvalidFileFormatException; void load(URL input) throws IOException, InvalidFileFormatException; void store() throws IOException; void store(OutputStream output) throws IOException; void store(Writer output) throws IOException; void store(File output) throws IOException; } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/Profile.java000066400000000000000000000033571151645323700225120ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; public interface Profile extends MultiMap, CommentedMap { char PATH_SEPARATOR = '/'; String getComment(); void setComment(String value); Section add(String sectionName); void add(String sectionName, String optionName, Object value); T as(Class clazz); T as(Class clazz, String prefix); String fetch(Object sectionName, Object optionName); T fetch(Object sectionName, Object optionName, Class clazz); String get(Object sectionName, Object optionName); T get(Object sectionName, Object optionName, Class clazz); String put(String sectionName, String optionName, Object value); Section remove(Profile.Section section); String remove(Object sectionName, Object optionName); interface Section extends OptionMap { Section getChild(String key); String getName(); Section getParent(); String getSimpleName(); Section addChild(String key); String[] childrenNames(); Section lookup(String... path); void removeChild(String key); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/Reg.java000066400000000000000000000174761151645323700216360ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.IniFormatter; import org.ini4j.spi.IniHandler; import org.ini4j.spi.IniParser; import org.ini4j.spi.RegBuilder; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.InterruptedIOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.net.URL; public class Reg extends BasicRegistry implements Registry, Persistable, Configurable { private static final long serialVersionUID = -1485602876922985912L; protected static final String DEFAULT_SUFFIX = ".reg"; protected static final String TMP_PREFIX = "reg-"; private static final int STDERR_BUFF_SIZE = 8192; private static final String PROP_OS_NAME = "os.name"; private static final boolean WINDOWS = Config.getSystemProperty(PROP_OS_NAME, "Unknown").startsWith("Windows"); private static final char CR = '\r'; private static final char LF = '\n'; private Config _config; private File _file; public Reg() { Config cfg = Config.getGlobal().clone(); cfg.setEscape(false); cfg.setGlobalSection(false); cfg.setEmptyOption(true); cfg.setMultiOption(true); cfg.setStrictOperator(true); cfg.setEmptySection(true); cfg.setPathSeparator(KEY_SEPARATOR); cfg.setFileEncoding(FILE_ENCODING); cfg.setLineSeparator(LINE_SEPARATOR); _config = cfg; } public Reg(String registryKey) throws IOException { this(); read(registryKey); } public Reg(File input) throws IOException, InvalidFileFormatException { this(); _file = input; load(); } public Reg(URL input) throws IOException, InvalidFileFormatException { this(); load(input); } public Reg(InputStream input) throws IOException, InvalidFileFormatException { this(); load(input); } public Reg(Reader input) throws IOException, InvalidFileFormatException { this(); load(input); } public static boolean isWindows() { return WINDOWS; } @Override public Config getConfig() { return _config; } public void setConfig(Config value) { _config = value; } @Override public File getFile() { return _file; } @Override public void setFile(File value) { _file = value; } @Override public void load() throws IOException, InvalidFileFormatException { if (_file == null) { throw new FileNotFoundException(); } load(_file); } @Override public void load(InputStream input) throws IOException, InvalidFileFormatException { load(new InputStreamReader(input, getConfig().getFileEncoding())); } @Override public void load(URL input) throws IOException, InvalidFileFormatException { load(new InputStreamReader(input.openStream(), getConfig().getFileEncoding())); } @Override public void load(Reader input) throws IOException, InvalidFileFormatException { int newline = 2; StringBuilder buff = new StringBuilder(); for (int c = input.read(); c != -1; c = input.read()) { if (c == LF) { newline--; if (newline == 0) { break; } } else if ((c != CR) && (newline != 1)) { buff.append((char) c); } } if (buff.length() == 0) { throw new InvalidFileFormatException("Missing version header"); } if (!buff.toString().equals(getVersion())) { throw new InvalidFileFormatException("Unsupported version: " + buff.toString()); } IniParser.newInstance(getConfig()).parse(input, newBuilder()); } @Override public void load(File input) throws IOException, InvalidFileFormatException { load(input.toURI().toURL()); } public void read(String registryKey) throws IOException { File tmp = createTempFile(); try { regExport(registryKey, tmp); load(tmp); } finally { tmp.delete(); } } @Override public void store() throws IOException { if (_file == null) { throw new FileNotFoundException(); } store(_file); } @Override public void store(OutputStream output) throws IOException { store(new OutputStreamWriter(output, getConfig().getFileEncoding())); } @Override public void store(Writer output) throws IOException { output.write(getVersion()); output.write(getConfig().getLineSeparator()); output.write(getConfig().getLineSeparator()); store(IniFormatter.newInstance(output, getConfig())); } @Override public void store(File output) throws IOException { OutputStream stream = new FileOutputStream(output); store(stream); stream.close(); } public void write() throws IOException { File tmp = createTempFile(); try { store(tmp); regImport(tmp); } finally { tmp.delete(); } } protected IniHandler newBuilder() { return RegBuilder.newInstance(this); } @Override boolean isTreeMode() { return getConfig().isTree(); } @Override char getPathSeparator() { return getConfig().getPathSeparator(); } @Override boolean isPropertyFirstUpper() { return getConfig().isPropertyFirstUpper(); } void exec(String[] args) throws IOException { Process proc = Runtime.getRuntime().exec(args); try { int status = proc.waitFor(); if (status != 0) { Reader in = new InputStreamReader(proc.getErrorStream()); char[] buff = new char[STDERR_BUFF_SIZE]; int n = in.read(buff); in.close(); throw new IOException(new String(buff, 0, n).trim()); } } catch (InterruptedException x) { throw (IOException) (new InterruptedIOException().initCause(x)); } } private File createTempFile() throws IOException { File ret = File.createTempFile(TMP_PREFIX, DEFAULT_SUFFIX); ret.deleteOnExit(); return ret; } private void regExport(String registryKey, File file) throws IOException { requireWindows(); exec(new String[] { "cmd", "/c", "reg", "export", registryKey, file.getAbsolutePath() }); } private void regImport(File file) throws IOException { requireWindows(); exec(new String[] { "cmd", "/c", "reg", "import", file.getAbsolutePath() }); } private void requireWindows() { if (!WINDOWS) { throw new UnsupportedOperationException("Unsupported operating system or runtime environment"); } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/Registry.java000066400000000000000000000062631151645323700227210ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; public interface Registry extends Profile { enum Hive { HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS; } // TODO handle delete operations with special Type enum Type { REG_NONE("hex(0)"), REG_SZ(""), REG_EXPAND_SZ("hex(2)"), REG_BINARY("hex"), REG_DWORD("dword"), REG_DWORD_BIG_ENDIAN("hex(5)"), REG_LINK("hex(6)"), REG_MULTI_SZ("hex(7)"), REG_RESOURCE_LIST("hex(8)"), REG_FULL_RESOURCE_DESCRIPTOR("hex(9)"), REG_RESOURCE_REQUIREMENTS_LIST("hex(a)"), REG_QWORD("hex(b)"); private static final Map MAPPING; static { MAPPING = new HashMap(); for (Type t : values()) { MAPPING.put(t.toString(), t); } } public static final char SEPARATOR_CHAR = ':'; public static final String SEPARATOR = String.valueOf(SEPARATOR_CHAR); public static final char REMOVE_CHAR = '-'; public static final String REMOVE = String.valueOf(REMOVE_CHAR); private final String _prefix; private Type(String prefix) { _prefix = prefix; } public static Type fromString(String str) { return MAPPING.get(str); } @Override public String toString() { return _prefix; } } char ESCAPE_CHAR = '\\'; Charset FILE_ENCODING = Charset.forName("UnicodeLittle"); char KEY_SEPARATOR = '\\'; String LINE_SEPARATOR = "\r\n"; char TYPE_SEPARATOR = ':'; String VERSION = "Windows Registry Editor Version 5.00"; String getVersion(); void setVersion(String value); @Override Key get(Object key); @Override Key get(Object key, int index); @Override Key put(String key, Section value); @Override Key put(String key, Section value, int index); @Override Key remove(Object key); @Override Key remove(Object key, int index); interface Key extends Section { String DEFAULT_NAME = "@"; @Override Key getChild(String key); @Override Key getParent(); Type getType(Object key); Type getType(Object key, Type defaulType); @Override Key addChild(String key); @Override Key lookup(String... path); Type putType(String key, Type type); Type removeType(Object key); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/Wini.java000066400000000000000000000036701151645323700220160ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.WinEscapeTool; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URL; public class Wini extends Ini { private static final long serialVersionUID = -2781377824232440728L; public static final char PATH_SEPARATOR = '\\'; public Wini() { Config cfg = Config.getGlobal().clone(); cfg.setEscape(false); cfg.setGlobalSection(true); cfg.setEmptyOption(true); cfg.setMultiOption(false); cfg.setPathSeparator(PATH_SEPARATOR); setConfig(cfg); } public Wini(File input) throws IOException, InvalidFileFormatException { this(); setFile(input); load(); } public Wini(URL input) throws IOException, InvalidFileFormatException { this(); load(input); } public Wini(InputStream input) throws IOException, InvalidFileFormatException { this(); load(input); } public Wini(Reader input) throws IOException, InvalidFileFormatException { this(); load(input); } public String escape(String value) { return WinEscapeTool.getInstance().escape(value); } public String unescape(String value) { return WinEscapeTool.getInstance().unescape(value); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/package.html000066400000000000000000000021501151645323700225160ustar00rootroot00000000000000 [ini4j] main package

[ini4j] main package

This package contains [ini4j] API. This is a very small library, so no interface and implementation separation neccessary. This is why [ini4j] has only one package.

ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/000077500000000000000000000000001151645323700210325ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/AbstractBeanInvocationHandler.java000066400000000000000000000212401151645323700275550ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import java.beans.Introspector; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; import java.beans.VetoableChangeSupport; import java.lang.reflect.Array; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; public abstract class AbstractBeanInvocationHandler implements InvocationHandler { private static final String PROPERTY_CHANGE_LISTENER = "PropertyChangeListener"; private static final String VETOABLE_CHANGE_LISTENER = "VetoableChangeListener"; private static final String ADD_PREFIX = "add"; private static final String READ_PREFIX = "get"; private static final String REMOVE_PREFIX = "remove"; private static final String READ_BOOLEAN_PREFIX = "is"; private static final String WRITE_PREFIX = "set"; private static final String HAS_PREFIX = "has"; private static enum Prefix { READ(READ_PREFIX), READ_BOOLEAN(READ_BOOLEAN_PREFIX), WRITE(WRITE_PREFIX), ADD_CHANGE(ADD_PREFIX + PROPERTY_CHANGE_LISTENER), ADD_VETO(ADD_PREFIX + VETOABLE_CHANGE_LISTENER), REMOVE_CHANGE(REMOVE_PREFIX + PROPERTY_CHANGE_LISTENER), REMOVE_VETO(REMOVE_PREFIX + VETOABLE_CHANGE_LISTENER), HAS(HAS_PREFIX); private int _len; private String _value; private Prefix(String value) { _value = value; _len = value.length(); } public static Prefix parse(String str) { Prefix ret = null; for (Prefix p : values()) { if (str.startsWith(p.getValue())) { ret = p; break; } } return ret; } public String getTail(String input) { return Introspector.decapitalize(input.substring(_len)); } public String getValue() { return _value; } } private PropertyChangeSupport _pcSupport; private Object _proxy; private VetoableChangeSupport _vcSupport; @Override public Object invoke(Object proxy, Method method, Object[] args) throws PropertyVetoException { Object ret = null; Prefix prefix = Prefix.parse(method.getName()); if (prefix != null) { String tail = prefix.getTail(method.getName()); updateProxy(proxy); switch (prefix) { case READ: ret = getProperty(prefix.getTail(method.getName()), method.getReturnType()); break; case READ_BOOLEAN: ret = getProperty(prefix.getTail(method.getName()), method.getReturnType()); break; case WRITE: setProperty(tail, args[0], method.getParameterTypes()[0]); break; case HAS: ret = Boolean.valueOf(hasProperty(prefix.getTail(method.getName()))); break; case ADD_CHANGE: addPropertyChangeListener((String) args[0], (PropertyChangeListener) args[1]); break; case ADD_VETO: addVetoableChangeListener((String) args[0], (VetoableChangeListener) args[1]); break; case REMOVE_CHANGE: removePropertyChangeListener((String) args[0], (PropertyChangeListener) args[1]); break; case REMOVE_VETO: removeVetoableChangeListener((String) args[0], (VetoableChangeListener) args[1]); break; default: break; } } return ret; } protected abstract Object getPropertySpi(String property, Class clazz); protected abstract void setPropertySpi(String property, Object value, Class clazz); protected abstract boolean hasPropertySpi(String property); protected synchronized Object getProperty(String property, Class clazz) { Object o; try { o = getPropertySpi(property, clazz); if (o == null) { o = zero(clazz); } else if (clazz.isArray() && (o instanceof String[]) && !clazz.equals(String[].class)) { String[] str = (String[]) o; o = Array.newInstance(clazz.getComponentType(), str.length); for (int i = 0; i < str.length; i++) { Array.set(o, i, parse(str[i], clazz.getComponentType())); } } else if ((o instanceof String) && !clazz.equals(String.class)) { o = parse((String) o, clazz); } } catch (Exception x) { o = zero(clazz); } return o; } protected synchronized void setProperty(String property, Object value, Class clazz) throws PropertyVetoException { boolean pc = (_pcSupport != null) && _pcSupport.hasListeners(property); boolean vc = (_vcSupport != null) && _vcSupport.hasListeners(property); Object oldVal = null; Object newVal = ((value != null) && clazz.equals(String.class) && !(value instanceof String)) ? value.toString() : value; if (pc || vc) { oldVal = getProperty(property, clazz); } if (vc) { fireVetoableChange(property, oldVal, value); } setPropertySpi(property, newVal, clazz); if (pc) { firePropertyChange(property, oldVal, value); } } protected synchronized Object getProxy() { return _proxy; } protected synchronized void addPropertyChangeListener(String property, PropertyChangeListener listener) { if (_pcSupport == null) { _pcSupport = new PropertyChangeSupport(_proxy); } _pcSupport.addPropertyChangeListener(property, listener); } protected synchronized void addVetoableChangeListener(String property, VetoableChangeListener listener) { if (_vcSupport == null) { _vcSupport = new VetoableChangeSupport(_proxy); } _vcSupport.addVetoableChangeListener(property, listener); } protected synchronized void firePropertyChange(String property, Object oldValue, Object newValue) { if (_pcSupport != null) { _pcSupport.firePropertyChange(property, oldValue, newValue); } } protected synchronized void fireVetoableChange(String property, Object oldValue, Object newValue) throws PropertyVetoException { if (_vcSupport != null) { _vcSupport.fireVetoableChange(property, oldValue, newValue); } } protected synchronized boolean hasProperty(String property) { boolean ret; try { ret = hasPropertySpi(property); } catch (Exception x) { ret = false; } return ret; } protected Object parse(String value, Class clazz) throws IllegalArgumentException { return BeanTool.getInstance().parse(value, clazz); } protected synchronized void removePropertyChangeListener(String property, PropertyChangeListener listener) { if (_pcSupport != null) { _pcSupport.removePropertyChangeListener(property, listener); } } protected synchronized void removeVetoableChangeListener(String property, VetoableChangeListener listener) { if (_vcSupport != null) { _vcSupport.removeVetoableChangeListener(property, listener); } } protected Object zero(Class clazz) { return BeanTool.getInstance().zero(clazz); } private synchronized void updateProxy(Object value) { if (_proxy == null) { _proxy = value; } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/AbstractFormatter.java000066400000000000000000000064011151645323700253250ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import java.io.PrintWriter; abstract class AbstractFormatter implements HandlerBase { private static final char OPERATOR = '='; private static final char COMMENT = '#'; private static final char SPACE = ' '; private Config _config = Config.getGlobal(); private boolean _header = true; private PrintWriter _output; @Override public void handleComment(String comment) { if (getConfig().isComment() && (!_header || getConfig().isHeaderComment()) && (comment != null) && (comment.length() != 0)) { for (String line : comment.split(getConfig().getLineSeparator())) { getOutput().print(COMMENT); getOutput().print(line); getOutput().print(getConfig().getLineSeparator()); } if (_header) { getOutput().print(getConfig().getLineSeparator()); } } _header = false; } @Override public void handleOption(String optionName, String optionValue) { if (getConfig().isStrictOperator()) { if (getConfig().isEmptyOption() || (optionValue != null)) { getOutput().print(escapeFilter(optionName)); getOutput().print(OPERATOR); } if (optionValue != null) { getOutput().print(escapeFilter(optionValue)); } if (getConfig().isEmptyOption() || (optionValue != null)) { getOutput().print(getConfig().getLineSeparator()); } } else { String value = ((optionValue == null) && getConfig().isEmptyOption()) ? "" : optionValue; if (value != null) { getOutput().print(escapeFilter(optionName)); getOutput().print(SPACE); getOutput().print(OPERATOR); getOutput().print(SPACE); getOutput().print(escapeFilter(value)); getOutput().print(getConfig().getLineSeparator()); } } setHeader(false); } protected Config getConfig() { return _config; } protected void setConfig(Config value) { _config = value; } protected PrintWriter getOutput() { return _output; } protected void setOutput(PrintWriter value) { _output = value; } void setHeader(boolean value) { _header = value; } String escapeFilter(String input) { return getConfig().isEscape() ? EscapeTool.getInstance().escape(input) : input; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/AbstractParser.java000066400000000000000000000063321151645323700246210ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import org.ini4j.InvalidFileFormatException; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URL; import java.util.Locale; abstract class AbstractParser { private final String _comments; private Config _config = Config.getGlobal(); private final String _operators; protected AbstractParser(String operators, String comments) { _operators = operators; _comments = comments; } protected Config getConfig() { return _config; } protected void setConfig(Config value) { _config = value; } protected void parseError(String line, int lineNumber) throws InvalidFileFormatException { throw new InvalidFileFormatException("parse error (at line: " + lineNumber + "): " + line); } IniSource newIniSource(InputStream input, HandlerBase handler) { return new IniSource(input, handler, _comments, getConfig()); } IniSource newIniSource(Reader input, HandlerBase handler) { return new IniSource(input, handler, _comments, getConfig()); } IniSource newIniSource(URL input, HandlerBase handler) throws IOException { return new IniSource(input, handler, _comments, getConfig()); } void parseOptionLine(String line, HandlerBase handler, int lineNumber) throws InvalidFileFormatException { int idx = indexOfOperator(line); String name = null; String value = null; if (idx < 0) { if (getConfig().isEmptyOption()) { name = line; } else { parseError(line, lineNumber); } } else { name = unescapeFilter(line.substring(0, idx)).trim(); value = unescapeFilter(line.substring(idx + 1)).trim(); } if (name.length() == 0) { parseError(line, lineNumber); } if (getConfig().isLowerCaseOption()) { name = name.toLowerCase(Locale.getDefault()); } handler.handleOption(name, value); } String unescapeFilter(String line) { return getConfig().isEscape() ? EscapeTool.getInstance().unescape(line) : line; } private int indexOfOperator(String line) { int idx = -1; for (char c : _operators.toCharArray()) { int index = line.indexOf(c); if ((index >= 0) && ((idx == -1) || (index < idx))) { idx = index; } } return idx; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/AbstractProfileBuilder.java000066400000000000000000000061011151645323700262660ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.CommentedMap; import org.ini4j.Config; import org.ini4j.Ini; import org.ini4j.Profile; abstract class AbstractProfileBuilder implements IniHandler { private Profile.Section _currentSection; private boolean _header; private String _lastComment; @Override public void endIni() { // comment only .ini files.... if ((_lastComment != null) && _header) { setHeaderComment(); } } @Override public void endSection() { _currentSection = null; } @Override public void handleComment(String comment) { if ((_lastComment != null) && _header) { _header = false; setHeaderComment(); } _lastComment = comment; } @Override public void handleOption(String name, String value) { _header = false; if (getConfig().isMultiOption()) { _currentSection.add(name, value); } else { _currentSection.put(name, value); } if (_lastComment != null) { putComment(_currentSection, name); _lastComment = null; } } @Override public void startIni() { if (getConfig().isHeaderComment()) { _header = true; } } @Override public void startSection(String sectionName) { if (getConfig().isMultiSection()) { _currentSection = getProfile().add(sectionName); } else { Ini.Section s = getProfile().get(sectionName); _currentSection = (s == null) ? getProfile().add(sectionName) : s; } if (_lastComment != null) { if (_header) { setHeaderComment(); } else { putComment(getProfile(), sectionName); } _lastComment = null; } _header = false; } abstract Config getConfig(); abstract Profile getProfile(); Profile.Section getCurrentSection() { return _currentSection; } private void setHeaderComment() { if (getConfig().isComment()) { getProfile().setComment(_lastComment); } } private void putComment(CommentedMap map, String key) { if (getConfig().isComment()) { map.putComment(key, _lastComment); } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/BeanAccess.java000066400000000000000000000017641151645323700236740ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; public interface BeanAccess { void propAdd(String propertyName, String value); String propDel(String propertyName); String propGet(String propertyName); String propGet(String propertyName, int index); int propLength(String propertyName); String propSet(String propertyName, String value); String propSet(String propertyName, String value, int index); } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/BeanTool.java000066400000000000000000000244021151645323700234020ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.io.File; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.net.URI; import java.net.URL; import java.util.TimeZone; public class BeanTool { private static final String PARSE_METHOD = "valueOf"; private static final BeanTool INSTANCE = ServiceFinder.findService(BeanTool.class); public static final BeanTool getInstance() { return INSTANCE; } public void inject(Object bean, BeanAccess props) { for (PropertyDescriptor pd : getPropertyDescriptors(bean.getClass())) { try { Method method = pd.getWriteMethod(); String name = pd.getName(); if ((method != null) && (props.propLength(name) != 0)) { Object value; if (pd.getPropertyType().isArray()) { value = Array.newInstance(pd.getPropertyType().getComponentType(), props.propLength(name)); for (int i = 0; i < props.propLength(name); i++) { Array.set(value, i, parse(props.propGet(name, i), pd.getPropertyType().getComponentType())); } } else { value = parse(props.propGet(name), pd.getPropertyType()); } method.invoke(bean, value); } } catch (Exception x) { throw (IllegalArgumentException) (new IllegalArgumentException("Failed to set property: " + pd.getDisplayName()).initCause( x)); } } } public void inject(BeanAccess props, Object bean) { for (PropertyDescriptor pd : getPropertyDescriptors(bean.getClass())) { try { Method method = pd.getReadMethod(); if ((method != null) && !"class".equals(pd.getName())) { Object value = method.invoke(bean, (Object[]) null); if (value != null) { if (pd.getPropertyType().isArray()) { for (int i = 0; i < Array.getLength(value); i++) { Object v = Array.get(value, i); if ((v != null) && !v.getClass().equals(String.class)) { v = v.toString(); } props.propAdd(pd.getName(), (String) v); } } else { props.propSet(pd.getName(), value.toString()); } } } } catch (Exception x) { throw new IllegalArgumentException("Failed to set property: " + pd.getDisplayName(), x); } } } @SuppressWarnings("unchecked") public T parse(String value, Class clazz) throws IllegalArgumentException { if (clazz == null) { throw new IllegalArgumentException("null argument"); } Object o = null; if (value == null) { o = zero(clazz); } else if (clazz.isPrimitive()) { o = parsePrimitiveValue(value, clazz); } else { if (clazz == String.class) { o = value; } else if (clazz == Character.class) { o = new Character(value.charAt(0)); } else { o = parseSpecialValue(value, clazz); } } return (T) o; } public T proxy(Class clazz, BeanAccess props) { return clazz.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { clazz }, new BeanInvocationHandler(props))); } @SuppressWarnings("unchecked") public T zero(Class clazz) { Object o = null; if (clazz.isPrimitive()) { if (clazz == Boolean.TYPE) { o = Boolean.FALSE; } else if (clazz == Byte.TYPE) { o = Byte.valueOf((byte) 0); } else if (clazz == Character.TYPE) { o = new Character('\0'); } else if (clazz == Double.TYPE) { o = new Double(0.0); } else if (clazz == Float.TYPE) { o = new Float(0.0f); } else if (clazz == Integer.TYPE) { o = Integer.valueOf(0); } else if (clazz == Long.TYPE) { o = Long.valueOf(0L); } else if (clazz == Short.TYPE) { o = Short.valueOf((short) 0); } } return (T) o; } @SuppressWarnings(Warnings.UNCHECKED) protected Object parseSpecialValue(String value, Class clazz) throws IllegalArgumentException { Object o; try { if (clazz == File.class) { o = new File(value); } else if (clazz == URL.class) { o = new URL(value); } else if (clazz == URI.class) { o = new URI(value); } else if (clazz == Class.class) { o = Class.forName(value); } else if (clazz == TimeZone.class) { o = TimeZone.getTimeZone(value); } else { // TODO handle constructor with String arg as converter from String // look for "valueOf" converter method Method parser = clazz.getMethod(PARSE_METHOD, new Class[] { String.class }); o = parser.invoke(null, new Object[] { value }); } } catch (Exception x) { throw (IllegalArgumentException) new IllegalArgumentException().initCause(x); } return o; } private PropertyDescriptor[] getPropertyDescriptors(Class clazz) { try { return Introspector.getBeanInfo(clazz).getPropertyDescriptors(); } catch (IntrospectionException x) { throw new IllegalArgumentException(x); } } private Object parsePrimitiveValue(String value, Class clazz) throws IllegalArgumentException { Object o = null; try { if (clazz == Boolean.TYPE) { o = Boolean.valueOf(value); } else if (clazz == Byte.TYPE) { o = Byte.valueOf(value); } else if (clazz == Character.TYPE) { o = new Character(value.charAt(0)); } else if (clazz == Double.TYPE) { o = Double.valueOf(value); } else if (clazz == Float.TYPE) { o = Float.valueOf(value); } else if (clazz == Integer.TYPE) { o = Integer.valueOf(value); } else if (clazz == Long.TYPE) { o = Long.valueOf(value); } else if (clazz == Short.TYPE) { o = Short.valueOf(value); } } catch (Exception x) { throw (IllegalArgumentException) new IllegalArgumentException().initCause(x); } return o; } static class BeanInvocationHandler extends AbstractBeanInvocationHandler { private final BeanAccess _backend; BeanInvocationHandler(BeanAccess backend) { _backend = backend; } @Override protected Object getPropertySpi(String property, Class clazz) { Object ret = null; if (clazz.isArray()) { int length = _backend.propLength(property); if (length != 0) { String[] all = new String[length]; for (int i = 0; i < all.length; i++) { all[i] = _backend.propGet(property, i); } ret = all; } } else { ret = _backend.propGet(property); } return ret; } @Override protected void setPropertySpi(String property, Object value, Class clazz) { if (clazz.isArray()) { _backend.propDel(property); for (int i = 0; i < Array.getLength(value); i++) { _backend.propAdd(property, Array.get(value, i).toString()); } } else { _backend.propSet(property, value.toString()); } } @Override protected boolean hasPropertySpi(String property) { return _backend.propLength(property) != 0; } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/EscapeTool.java000066400000000000000000000121501151645323700237320ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; public class EscapeTool { private static final String ESCAPE_LETTERS = "\\tnfbr"; private static final String ESCAPEABLE_CHARS = "\\\t\n\f\b\r"; private static final char ESCAPE_CHAR = '\\'; static final char[] HEX = "0123456789abcdef".toCharArray(); private static final EscapeTool INSTANCE = ServiceFinder.findService(EscapeTool.class); private static final char ASCII_MIN = 0x20; private static final char ASCII_MAX = 0x7e; static final int HEX_DIGIT_MASK = 0x0f; static final int HEX_DIGIT_3_OFFSET = 4; static final int HEX_DIGIT_2_OFFSET = 8; static final int HEX_DIGIT_1_OFFSET = 12; static final int HEX_RADIX = 16; private static final int UNICODE_HEX_DIGITS = 4; static final char DOUBLE_QUOTE = '"'; public static EscapeTool getInstance() { return INSTANCE; } public String escape(String line) { int len = line.length(); StringBuilder buffer = new StringBuilder(len * 2); for (int i = 0; i < len; i++) { char c = line.charAt(i); int idx = ESCAPEABLE_CHARS.indexOf(c); if (idx >= 0) { buffer.append(ESCAPE_CHAR); buffer.append(ESCAPE_LETTERS.charAt(idx)); } else { if ((c < ASCII_MIN) || (c > ASCII_MAX)) { escapeBinary(buffer, c); } else { buffer.append(c); } } } return buffer.toString(); } public String quote(String value) { String ret = value; if ((value != null) && (value.length() != 0)) { StringBuilder buff = new StringBuilder(); buff.append(DOUBLE_QUOTE); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if ((c == ESCAPE_CHAR) || (c == DOUBLE_QUOTE)) { buff.append(ESCAPE_CHAR); } buff.append(c); } buff.append(DOUBLE_QUOTE); ret = buff.toString(); } return ret; } public String unescape(String line) { int n = line.length(); StringBuilder buffer = new StringBuilder(n); int i = 0; while (i < n) { char c = line.charAt(i++); if (c == ESCAPE_CHAR) { c = line.charAt(i++); int next = unescapeBinary(buffer, c, line, i); if (next == i) { int idx = ESCAPE_LETTERS.indexOf(c); if (idx >= 0) { c = ESCAPEABLE_CHARS.charAt(idx); } buffer.append(c); } else { i = next; } } else { buffer.append(c); } } return buffer.toString(); } public String unquote(String value) { StringBuilder buff = new StringBuilder(); boolean escape = false; for (int i = 1; i < (value.length() - 1); i++) { char c = value.charAt(i); if (c == ESCAPE_CHAR) { if (!escape) { escape = true; continue; } escape = false; } buff.append(c); } return buff.toString(); } void escapeBinary(StringBuilder buff, char c) { buff.append("\\u"); buff.append(HEX[(c >>> HEX_DIGIT_1_OFFSET) & HEX_DIGIT_MASK]); buff.append(HEX[(c >>> HEX_DIGIT_2_OFFSET) & HEX_DIGIT_MASK]); buff.append(HEX[(c >>> HEX_DIGIT_3_OFFSET) & HEX_DIGIT_MASK]); buff.append(HEX[c & HEX_DIGIT_MASK]); } int unescapeBinary(StringBuilder buff, char escapeType, String line, int index) { int ret = index; if (escapeType == 'u') { try { buff.append((char) Integer.parseInt(line.substring(index, index + UNICODE_HEX_DIGITS), HEX_RADIX)); ret = index + UNICODE_HEX_DIGITS; } catch (Exception x) { throw new IllegalArgumentException("Malformed \\uxxxx encoding.", x); } } return ret; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/HandlerBase.java000066400000000000000000000013621151645323700240470ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; interface HandlerBase { void handleComment(String comment); void handleOption(String optionName, String optionValue); } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/IniBuilder.java000066400000000000000000000024251151645323700237260ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import org.ini4j.Ini; import org.ini4j.Profile; public class IniBuilder extends AbstractProfileBuilder implements IniHandler { private Ini _ini; public static IniBuilder newInstance(Ini ini) { IniBuilder instance = newInstance(); instance.setIni(ini); return instance; } public void setIni(Ini value) { _ini = value; } @Override Config getConfig() { return _ini.getConfig(); } @Override Profile getProfile() { return _ini; } private static IniBuilder newInstance() { return ServiceFinder.findService(IniBuilder.class); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/IniFormatter.java000066400000000000000000000035621151645323700243060ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import java.io.PrintWriter; import java.io.Writer; public class IniFormatter extends AbstractFormatter implements IniHandler { public static IniFormatter newInstance(Writer out, Config config) { IniFormatter instance = newInstance(); instance.setOutput((out instanceof PrintWriter) ? (PrintWriter) out : new PrintWriter(out)); instance.setConfig(config); return instance; } @Override public void endIni() { getOutput().flush(); } @Override public void endSection() { getOutput().print(getConfig().getLineSeparator()); } @Override public void startIni() { assert true; } @Override public void startSection(String sectionName) { setHeader(false); if (!getConfig().isGlobalSection() || !sectionName.equals(getConfig().getGlobalSectionName())) { getOutput().print(IniParser.SECTION_BEGIN); getOutput().print(escapeFilter(sectionName)); getOutput().print(IniParser.SECTION_END); getOutput().print(getConfig().getLineSeparator()); } } private static IniFormatter newInstance() { return ServiceFinder.findService(IniFormatter.class); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/IniHandler.java000066400000000000000000000016161151645323700237160ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; public interface IniHandler extends HandlerBase { void endIni(); void endSection(); @Override void handleComment(String comment); @Override void handleOption(String optionName, String optionValue); void startIni(); void startSection(String sectionName); } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/IniParser.java000066400000000000000000000075041151645323700235770ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import org.ini4j.InvalidFileFormatException; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URL; import java.util.Locale; public class IniParser extends AbstractParser { private static final String COMMENTS = ";#"; private static final String OPERATORS = ":="; static final char SECTION_BEGIN = '['; static final char SECTION_END = ']'; public IniParser() { super(OPERATORS, COMMENTS); } public static IniParser newInstance() { return ServiceFinder.findService(IniParser.class); } public static IniParser newInstance(Config config) { IniParser instance = newInstance(); instance.setConfig(config); return instance; } public void parse(InputStream input, IniHandler handler) throws IOException, InvalidFileFormatException { parse(newIniSource(input, handler), handler); } public void parse(Reader input, IniHandler handler) throws IOException, InvalidFileFormatException { parse(newIniSource(input, handler), handler); } public void parse(URL input, IniHandler handler) throws IOException, InvalidFileFormatException { parse(newIniSource(input, handler), handler); } private void parse(IniSource source, IniHandler handler) throws IOException, InvalidFileFormatException { handler.startIni(); String sectionName = null; for (String line = source.readLine(); line != null; line = source.readLine()) { if (line.charAt(0) == SECTION_BEGIN) { if (sectionName != null) { handler.endSection(); } sectionName = parseSectionLine(line, source, handler); } else { if (sectionName == null) { if (getConfig().isGlobalSection()) { sectionName = getConfig().getGlobalSectionName(); handler.startSection(sectionName); } else { parseError(line, source.getLineNumber()); } } parseOptionLine(line, handler, source.getLineNumber()); } } if (sectionName != null) { handler.endSection(); } handler.endIni(); } private String parseSectionLine(String line, IniSource source, IniHandler handler) throws InvalidFileFormatException { String sectionName; if (line.charAt(line.length() - 1) != SECTION_END) { parseError(line, source.getLineNumber()); } sectionName = unescapeFilter(line.substring(1, line.length() - 1).trim()); if ((sectionName.length() == 0) && !getConfig().isUnnamedSection()) { parseError(line, source.getLineNumber()); } if (getConfig().isLowerCaseSection()) { sectionName = sectionName.toLowerCase(Locale.getDefault()); } handler.startSection(sectionName); return sectionName; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/IniSource.java000066400000000000000000000131121151645323700235730ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import java.io.IOException; import java.io.InputStream; import java.io.LineNumberReader; import java.io.Reader; import java.net.URL; class IniSource { public static final char INCLUDE_BEGIN = '<'; public static final char INCLUDE_END = '>'; public static final char INCLUDE_OPTIONAL = '?'; private static final char ESCAPE_CHAR = '\\'; private URL _base; private IniSource _chain; private final String _commentChars; private final Config _config; private final HandlerBase _handler; private final LineNumberReader _reader; IniSource(InputStream input, HandlerBase handler, String comments, Config config) { this(new UnicodeInputStreamReader(input, config.getFileEncoding()), handler, comments, config); } IniSource(Reader input, HandlerBase handler, String comments, Config config) { _reader = new LineNumberReader(input); _handler = handler; _commentChars = comments; _config = config; } IniSource(URL input, HandlerBase handler, String comments, Config config) throws IOException { this(new UnicodeInputStreamReader(input.openStream(), config.getFileEncoding()), handler, comments, config); _base = input; } int getLineNumber() { int ret; if (_chain == null) { ret = _reader.getLineNumber(); } else { ret = _chain.getLineNumber(); } return ret; } String readLine() throws IOException { String line; if (_chain == null) { line = readLineLocal(); } else { line = _chain.readLine(); if (line == null) { _chain = null; line = readLine(); } } return line; } private void close() throws IOException { _reader.close(); } private void handleComment(StringBuilder buff) { if (buff.length() != 0) { buff.deleteCharAt(buff.length() - 1); _handler.handleComment(buff.toString()); buff.delete(0, buff.length()); } } private String handleInclude(String input) throws IOException { String line = input; if (_config.isInclude() && (line.length() > 2) && (line.charAt(0) == INCLUDE_BEGIN) && (line.charAt(line.length() - 1) == INCLUDE_END)) { line = line.substring(1, line.length() - 1).trim(); boolean optional = line.charAt(0) == INCLUDE_OPTIONAL; if (optional) { line = line.substring(1).trim(); } URL loc = (_base == null) ? new URL(line) : new URL(_base, line); if (optional) { try { _chain = new IniSource(loc, _handler, _commentChars, _config); } catch (IOException x) { assert true; } finally { line = readLine(); } } else { _chain = new IniSource(loc, _handler, _commentChars, _config); line = readLine(); } } return line; } private String readLineLocal() throws IOException { String line = readLineSkipComments(); if (line == null) { close(); } else { line = handleInclude(line); } return line; } private String readLineSkipComments() throws IOException { String line; StringBuilder comment = new StringBuilder(); StringBuilder buff = new StringBuilder(); for (line = _reader.readLine(); line != null; line = _reader.readLine()) { line = line.trim(); if (line.length() == 0) { handleComment(comment); } else if ((_commentChars.indexOf(line.charAt(0)) >= 0) && (buff.length() == 0)) { comment.append(line.substring(1)); comment.append(_config.getLineSeparator()); } else { handleComment(comment); int escapeCount = 0; for (int i = line.length() - 1; (i >= 0) && (line.charAt(i) == ESCAPE_CHAR); i--) { escapeCount++; } if ((escapeCount & 1) == 0) { buff.append(line); line = buff.toString(); break; } buff.append(line.subSequence(0, line.length() - 1)); } } // handle end comments if ((line == null) && (comment.length() != 0)) { handleComment(comment); } return line; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/OptionsBuilder.java000066400000000000000000000052311151645323700246400ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import org.ini4j.Options; public class OptionsBuilder implements OptionsHandler { private boolean _header; private String _lastComment; private Options _options; public static OptionsBuilder newInstance(Options opts) { OptionsBuilder instance = newInstance(); instance.setOptions(opts); return instance; } public void setOptions(Options value) { _options = value; } @Override public void endOptions() { // comment only .opt file ... if ((_lastComment != null) && _header) { setHeaderComment(); } } @Override public void handleComment(String comment) { if ((_lastComment != null) && _header) { setHeaderComment(); _header = false; } _lastComment = comment; } @Override public void handleOption(String name, String value) { if (getConfig().isMultiOption()) { _options.add(name, value); } else { _options.put(name, value); } if (_lastComment != null) { if (_header) { setHeaderComment(); } else { putComment(name); } _lastComment = null; } _header = false; } @Override public void startOptions() { if (getConfig().isHeaderComment()) { _header = true; } } protected static OptionsBuilder newInstance() { return ServiceFinder.findService(OptionsBuilder.class); } private Config getConfig() { return _options.getConfig(); } private void setHeaderComment() { if (getConfig().isComment()) { _options.setComment(_lastComment); } } private void putComment(String key) { if (getConfig().isComment()) { _options.putComment(key, _lastComment); } } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/OptionsFormatter.java000066400000000000000000000025131151645323700252150ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import java.io.PrintWriter; import java.io.Writer; public class OptionsFormatter extends AbstractFormatter implements OptionsHandler { public static OptionsFormatter newInstance(Writer out, Config config) { OptionsFormatter instance = newInstance(); instance.setOutput((out instanceof PrintWriter) ? (PrintWriter) out : new PrintWriter(out)); instance.setConfig(config); return instance; } public void endOptions() { getOutput().flush(); } public void startOptions() { assert true; } private static OptionsFormatter newInstance() { return ServiceFinder.findService(OptionsFormatter.class); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/OptionsHandler.java000066400000000000000000000015261151645323700246320ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; public interface OptionsHandler extends HandlerBase { void endOptions(); @Override void handleComment(String comment); @Override void handleOption(String optionName, String optionValue); void startOptions(); } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/OptionsParser.java000066400000000000000000000042521151645323700245100ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import org.ini4j.InvalidFileFormatException; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URL; public class OptionsParser extends AbstractParser { private static final String COMMENTS = "!#"; private static final String OPERATORS = ":="; public OptionsParser() { super(OPERATORS, COMMENTS); } public static OptionsParser newInstance() { return ServiceFinder.findService(OptionsParser.class); } public static OptionsParser newInstance(Config config) { OptionsParser instance = newInstance(); instance.setConfig(config); return instance; } public void parse(InputStream input, OptionsHandler handler) throws IOException, InvalidFileFormatException { parse(newIniSource(input, handler), handler); } public void parse(Reader input, OptionsHandler handler) throws IOException, InvalidFileFormatException { parse(newIniSource(input, handler), handler); } public void parse(URL input, OptionsHandler handler) throws IOException, InvalidFileFormatException { parse(newIniSource(input, handler), handler); } private void parse(IniSource source, OptionsHandler handler) throws IOException, InvalidFileFormatException { handler.startOptions(); for (String line = source.readLine(); line != null; line = source.readLine()) { parseOptionLine(line, handler, source.getLineNumber()); } handler.endOptions(); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/RegBuilder.java000066400000000000000000000035161151645323700237260ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import org.ini4j.Profile; import org.ini4j.Reg; import org.ini4j.Registry.Key; import org.ini4j.Registry.Type; public class RegBuilder extends AbstractProfileBuilder { private Reg _reg; public static RegBuilder newInstance(Reg reg) { RegBuilder instance = newInstance(); instance.setReg(reg); return instance; } public void setReg(Reg value) { _reg = value; } @Override public void handleOption(String rawName, String rawValue) { String name = (rawName.charAt(0) == EscapeTool.DOUBLE_QUOTE) ? RegEscapeTool.getInstance().unquote(rawName) : rawName; TypeValuesPair tv = RegEscapeTool.getInstance().decode(rawValue); if (tv.getType() != Type.REG_SZ) { ((Key) getCurrentSection()).putType(name, tv.getType()); } for (String value : tv.getValues()) { super.handleOption(name, value); } } @Override Config getConfig() { return _reg.getConfig(); } @Override Profile getProfile() { return _reg; } private static RegBuilder newInstance() { return ServiceFinder.findService(RegBuilder.class); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/RegEscapeTool.java000066400000000000000000000152771151645323700244050ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Registry; import org.ini4j.Registry.Type; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.Arrays; public class RegEscapeTool extends EscapeTool { private static final RegEscapeTool INSTANCE = ServiceFinder.findService(RegEscapeTool.class); private static final Charset HEX_CHARSET = Charset.forName("UTF-16LE"); private static final int LOWER_DIGIT = 0x0f; private static final int UPPER_DIGIT = 0xf0; private static final int DIGIT_SIZE = 4; public static final RegEscapeTool getInstance() { return INSTANCE; } public TypeValuesPair decode(String raw) { Type type = type(raw); String value = (type == Type.REG_SZ) ? unquote(raw) : raw.substring(type.toString().length() + 1); String[] values; switch (type) { case REG_EXPAND_SZ: case REG_MULTI_SZ: value = bytes2string(binary(value)); break; case REG_DWORD: value = String.valueOf(Long.parseLong(value, HEX_RADIX)); break; case REG_SZ: break; default: break; } if (type == Type.REG_MULTI_SZ) { values = splitMulti(value); } else { values = new String[] { value }; } return new TypeValuesPair(type, values); } public String encode(TypeValuesPair data) { String ret = null; if (data.getType() == Type.REG_SZ) { ret = quote(data.getValues()[0]); } else if (data.getValues()[0] != null) { ret = encode(data.getType(), data.getValues()); } return ret; } byte[] binary(String value) { byte[] bytes = new byte[value.length()]; int idx = 0; int shift = DIGIT_SIZE; for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (Character.isWhitespace(c)) { continue; } if (c == ',') { idx++; shift = DIGIT_SIZE; } else { int digit = Character.digit(c, HEX_RADIX); if (digit >= 0) { bytes[idx] |= digit << shift; shift = 0; } } } return Arrays.copyOfRange(bytes, 0, idx + 1); } String encode(Type type, String[] values) { StringBuilder buff = new StringBuilder(); buff.append(type.toString()); buff.append(Type.SEPARATOR_CHAR); switch (type) { case REG_EXPAND_SZ: buff.append(hexadecimal(values[0])); break; case REG_DWORD: buff.append(String.format("%08x", Long.parseLong(values[0]))); break; case REG_MULTI_SZ: int n = values.length; for (int i = 0; i < n; i++) { buff.append(hexadecimal(values[i])); buff.append(','); } buff.append("00,00"); break; default: buff.append(values[0]); break; } return buff.toString(); } String hexadecimal(String value) { StringBuilder buff = new StringBuilder(); if ((value != null) && (value.length() != 0)) { byte[] bytes = string2bytes(value); for (int i = 0; i < bytes.length; i++) { buff.append(Character.forDigit((bytes[i] & UPPER_DIGIT) >> DIGIT_SIZE, HEX_RADIX)); buff.append(Character.forDigit(bytes[i] & LOWER_DIGIT, HEX_RADIX)); buff.append(','); } buff.append("00,00"); } return buff.toString(); } Registry.Type type(String raw) { Registry.Type type; if (raw.charAt(0) == DOUBLE_QUOTE) { type = Registry.Type.REG_SZ; } else { int idx = raw.indexOf(Registry.TYPE_SEPARATOR); type = (idx < 0) ? Registry.Type.REG_SZ : Registry.Type.fromString(raw.substring(0, idx)); } return type; } // XXX Java 1.4 compatibility hack private String bytes2string(byte[] bytes) { String str; try { str = new String(bytes, 0, bytes.length - 2, HEX_CHARSET); } catch (NoSuchMethodError x) { try { str = new String(bytes, 0, bytes.length, HEX_CHARSET.name()); } catch (UnsupportedEncodingException ex) { throw new IllegalStateException(ex); } } return str; } private String[] splitMulti(String value) { int len = value.length(); int start; int end; int n = 0; start = 0; for (end = value.indexOf(0, start); end >= 0; end = value.indexOf(0, start)) { n++; start = end + 1; if (start >= len) { break; } } String[] values = new String[n]; start = 0; for (int i = 0; i < n; i++) { end = value.indexOf(0, start); values[i] = value.substring(start, end); start = end + 1; } return values; } // XXX Java 1.4 compatibility hack private byte[] string2bytes(String value) { byte[] bytes; try { bytes = value.getBytes(HEX_CHARSET); } catch (NoSuchMethodError x) { try { bytes = value.getBytes(HEX_CHARSET.name()); } catch (UnsupportedEncodingException ex) { throw new IllegalStateException(ex); } } return bytes; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/ServiceFinder.java000066400000000000000000000120661151645323700244320ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; /** * JDK JAR Services API alap� service keres� oszt�ly. * * @author Szkiba Iv�n * @version $Name: $ */ final class ServiceFinder { private static final String SERVICES_PATH = "META-INF/services/"; private ServiceFinder() { } /** * Service objektum keres�s �s p�ld�nyos�t�s * * a JDK JAR specifik�ci�ban defini�lt Services API-nak * megfelel�en service oszt�ly keres�s, majd pedig p�ld�ny k�pz�s a context * ClassLoader seg�ts�g�vel.

* Az implement�l� oszt�ly n�v keres�se a serviceId nev� * system property vizsg�lat�val kezd�dik. Amennyiben nincs ilyen * property, �gy a keres�s a * /META-INF/services/serviceId nev� file tartalm�val * folytat�dik. Amennyiben nincs ilyen nev� file, �gy a param�terk�nt �tadott * defaultService lesz az oszt�ly neve.

* A fenti keres�st k�vet�en t�rt�nik a p�ld�ny k�pz�s. A visszat�r�si * �rt�k mindig egy val�di objektum, l�v�n minden hiba exception-t gener�l. * @param type * @param clazz keresett oszt�ly/service neve * @throws IllegalArgumentException keres�si vagy p�ld�nyos�t�si hiba eset�n * @return a keresett oszt�ly implement�l� objektum */ static T findService(Class clazz) { try { // ez a cast nem lenne szükséges, de úgy a ClassCastException csak a hívónál jön... return clazz.cast(findServiceClass(clazz).newInstance()); } catch (Exception x) { throw (IllegalArgumentException) new IllegalArgumentException("Provider " + clazz.getName() + " could not be instantiated: " + x) .initCause(x); } } @SuppressWarnings(Warnings.UNCHECKED) static Class findServiceClass(Class clazz) throws IllegalArgumentException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); String serviceClassName = findServiceClassName(clazz.getName()); Class ret = clazz; if (serviceClassName != null) { try { ret = (Class) ((classLoader == null) ? Class.forName(serviceClassName) : classLoader.loadClass(serviceClassName)); } catch (ClassNotFoundException x) { throw (IllegalArgumentException) new IllegalArgumentException("Provider " + serviceClassName + " not found").initCause(x); } } return ret; } static String findServiceClassName(String serviceId) throws IllegalArgumentException { String serviceClassName = null; // Use the system property first try { String systemProp = System.getProperty(serviceId); if (systemProp != null) { serviceClassName = systemProp; } } catch (SecurityException x) { assert true; } if (serviceClassName == null) { serviceClassName = loadLine(SERVICES_PATH + serviceId); } return serviceClassName; } private static String loadLine(String servicePath) { String ret = null; // try to find services in CLASSPATH try { InputStream is = null; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { is = ClassLoader.getSystemResourceAsStream(servicePath); } else { is = classLoader.getResourceAsStream(servicePath); } if (is != null) { BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = rd.readLine(); rd.close(); if (line != null) { line = line.trim(); if (line.length() != 0) { ret = line.split("\\s|#")[0]; } } } } catch (Exception x) { assert true; } return ret; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/TypeValuesPair.java000066400000000000000000000020341151645323700246110ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Registry.Type; public class TypeValuesPair { private final Type _type; private final String[] _values; @SuppressWarnings("PMD.ArrayIsStoredDirectly") public TypeValuesPair(Type type, String[] values) { _type = type; _values = values; } public Type getType() { return _type; } public String[] getValues() { return _values; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/UnicodeInputStreamReader.java000066400000000000000000000075561151645323700266170ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PushbackInputStream; import java.io.Reader; import java.nio.charset.Charset; class UnicodeInputStreamReader extends Reader { private static final int BOM_SIZE = 4; private static enum Bom { UTF32BE("UTF-32BE", new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0xFE, (byte) 0xFF }), UTF32LE("UTF-32LE", new byte[] { (byte) 0xFF, (byte) 0xFE, (byte) 0x00, (byte) 0x00 }), UTF16BE("UTF-16BE", new byte[] { (byte) 0xFE, (byte) 0xFF }), UTF16LE("UTF-16LE", new byte[] { (byte) 0xFF, (byte) 0xFE }), UTF8("UTF-8", new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF }); private final byte[] _bytes; private Charset _charset; @SuppressWarnings("PMD.ArrayIsStoredDirectly") private Bom(String charsetName, byte[] bytes) { try { _charset = Charset.forName(charsetName); } catch (Exception x) { _charset = null; } _bytes = bytes; } private static Bom find(byte[] data) { Bom ret = null; for (Bom bom : values()) { if (bom.supported() && bom.match(data)) { ret = bom; break; } } return ret; } private boolean match(byte[] data) { boolean ok = true; for (int i = 0; i < _bytes.length; i++) { if (data[i] != _bytes[i]) { ok = false; break; } } return ok; } private boolean supported() { return _charset != null; } } private final Charset _defaultEncoding; private InputStreamReader _reader; private final PushbackInputStream _stream; UnicodeInputStreamReader(InputStream in, Charset defaultEnc) { _stream = new PushbackInputStream(in, BOM_SIZE); _defaultEncoding = defaultEnc; } public void close() throws IOException { init(); _reader.close(); } public int read(char[] cbuf, int off, int len) throws IOException { init(); return _reader.read(cbuf, off, len); } /** * Read-ahead four bytes and check for BOM marks. Extra bytes are * unread back to the stream, only BOM bytes are skipped. */ protected void init() throws IOException { if (_reader != null) { return; } Charset encoding; byte[] data = new byte[BOM_SIZE]; int n; int unread; n = _stream.read(data, 0, data.length); Bom bom = Bom.find(data); if (bom == null) { encoding = _defaultEncoding; unread = n; } else { encoding = bom._charset; unread = data.length - bom._bytes.length; } if (unread > 0) { _stream.unread(data, (n - unread), unread); } _reader = new InputStreamReader(_stream, encoding); } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/Warnings.java000066400000000000000000000014021151645323700234620ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; public final class Warnings { public static final String UNCHECKED = "unchecked"; private Warnings() { assert true; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/WinEscapeTool.java000066400000000000000000000041571151645323700244200ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; public class WinEscapeTool extends EscapeTool { private static final int ANSI_HEX_DIGITS = 2; private static final int ANSI_OCTAL_DIGITS = 3; private static final int OCTAL_RADIX = 8; private static final WinEscapeTool INSTANCE = new WinEscapeTool(); public static WinEscapeTool getInstance() { return INSTANCE; } @Override void escapeBinary(StringBuilder buff, char c) { buff.append("\\x"); buff.append(HEX[(c >>> HEX_DIGIT_3_OFFSET) & HEX_DIGIT_MASK]); buff.append(HEX[c & HEX_DIGIT_MASK]); } @Override int unescapeBinary(StringBuilder buff, char escapeType, String line, int index) { int ret = index; if (escapeType == 'x') { try { buff.append((char) Integer.parseInt(line.substring(index, index + ANSI_HEX_DIGITS), HEX_RADIX)); ret = index + ANSI_HEX_DIGITS; } catch (Exception x) { throw new IllegalArgumentException("Malformed \\xHH encoding.", x); } } else if (escapeType == 'o') { try { buff.append((char) Integer.parseInt(line.substring(index, index + ANSI_OCTAL_DIGITS), OCTAL_RADIX)); ret = index + ANSI_OCTAL_DIGITS; } catch (Exception x) { throw new IllegalArgumentException("Malformed \\oOO encoding.", x); } } return ret; } } ini4j-0.5.2-SNAPSHOT/src/main/java/org/ini4j/spi/package.html000066400000000000000000000020071151645323700233120ustar00rootroot00000000000000 [ini4j] service provider package

[ini4j] service provider package

This package contains [ini4j] service provider API.

ini4j-0.5.2-SNAPSHOT/src/site/000077500000000000000000000000001151645323700155325ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/site/apt/000077500000000000000000000000001151645323700163165ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/site/apt/design.apt000066400000000000000000000067211151645323700203030ustar00rootroot00000000000000 ------ Design goals Design goals This document summarizes the design aspects of the [ini4j] project. First let me quote something every library designer should keep in mind: "Perfection (in design) is achieved not when there is nothing more to add, but rather when there is nothing more to take away." - Antoine de Saint-Exupéry * Only .ini handling library One of the most important aspects was that the [ini4j] is not a complex configuration management system, but principally a library that allows you to manage files in .ini format. We could say that we regard the java.util.Properties object as a pattern in designing. The Properties object works as a file containing pairs of name and value. It can be read from a stream or be written to a stream (lately even in XML format). This way it is understandable why the Ini object doesn't need to belong to a file: you can read it from InputStream (and Reader) or write it to OutputStream (and Writer). * Simple API The programming interface had to be designed as simple as possible, firstly for the sake of easier understanding and usage, secondly in order to avoid needless complexity. The handling of the .ini files in any application is just a tool, not the goal. As a result of this approach the Ini object is in fact a Map composed of sections. The section object is a Map composed of String values assigned to String keys. * Standard API Another very important design aspect was that if a standard API exists, that must be used to handle the .ini file. Fortunately, ever since the introduction of version 1.4, there is a Preferences API, which is actually a simple tree structure of name/value pairs. This is ideal for the .ini format's top level API, because the programmer using the library doesn't have to learn a new API, but can handle the .ini files using the Preferences API included in the standard JDK! So the .ini file is in fact a one-level Preferences tree. On the only level the nodes of the tree are the sections of the .ini file, and the leaf nodes are the section's name/value pairs. Due to the Preferences API the conversion of values to primitive types or vice versa is solved (getInt(), setInt(), etc). * Comfortable API The designer of a library always seeks the favour of the potential users, the programmers in this case, so comfort is at least as important an aspect as simplicity. An API should be as comfortable as possible. The Java Beans-style programming interface was born on these terms, that is, to allow the programmer to define completely freely how (as what type) he'd wish to access the values of the section as a java interface. * Sequential parser When handling large .ini files, it is not practical to read the whole file into the memory. So there might be a need for a sequential parser that calls the processing routine as a callback while parsing sections or name/value pairs inside sections. The JAXP SAX parser can be regarded as a model. Along these lines, the corresponding document object of the .ini file must be built based on this sequential parser. Thus the model of the Ini object is the JAXP DOM document. A bit of history: an early ancestor of the [ini4j] library was an exercise assigned as homework at a Java programmer course. Its purpose was to prepare the exposition of JAXP SAX/DOM API. The assignment was to write a sequential parser for the .ini file, and then to use it to build an object in the memory. ini4j-0.5.2-SNAPSHOT/src/site/apt/overview.apt000066400000000000000000000062051151645323700206750ustar00rootroot00000000000000 ---- Java API for handling Windows ini file format Java API for handling Windows ini file format The [ini4j] is a simple Java API for handling configuration files in Windows .ini format. Additionally, the library includes {{{http://java.sun.com/javase/6/docs/api/java/util/prefs/Preferences.html}Java Preferences API}} implementation based on the .ini file. Configuration management is an integral part of every application. The standard Java API {{{http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html}Properties}} warrants simple configuration management. A bit more complicated configuration can be managed with the standard Java {{{http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html}Preferences API}} since Java version 1.4. There is also another (much more complicated) method of configuration management: managing configuration files in XML format. In this case the standard Java XML API (JAXP) or another XML-based configuration management system, e.g. {{{http://jakarta.apache.org/commons/digester/}Jakarta Commons Digester}}, is used. The {{{http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html}Properties}} file can't group settings, which is why its services are often not sufficient. The Preferences API can sort settings in a nice tree structure, but the standard implementation uses hidden filesystem directory structures inside the user's home directory. This means that it can't be used for managing configuration files attached to the application. Managing XML configuration files through the JAXP is a tiresome work, and to learn and master a complex XML-based configuration management system is a time-consuming and difficult task. There is another way not mentioned so far: using good old Windows .ini files. This format allows you to group settings, so it's better than the Properties API, whereas it's considerably easier to manage than XML configuration files. Contrary to the standard Preferences implementation, .ini files can be attached to applications as configuration files without worry. At the time of writing this document a "de facto" .ini file handling Java library doesn't exist. The [ini4j] tries to be one. It was an important design aspect to use the standard API. Due to this, I chose the standard {{{http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html}Preferences API}}. This means that the [ini4j] package contains a Preferences implementation that realizes a Preferences API on the .ini files. The Preferences tree has only one level that contains the sections of the .ini file. The only [ini4j] specific thing that remains is to create a Preferences tree that means creating an instance of the IniPreferences object. This object corresponds to the .ini file as a Preferences object. The {{{http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html}Properties}} file is a simple String,String map, while the Ini object is a two-level map. On its first level the String type keys define the Ini.Section type sections. The Ini.Section object itself is a map, a String,String type map of the name/value pairs. ini4j-0.5.2-SNAPSHOT/src/site/resources/000077500000000000000000000000001151645323700175445ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/site/resources/.htaccess000066400000000000000000000014451151645323700213460ustar00rootroot00000000000000 Redirect permanent /license.txt http://ini4j.sourceforge.net/license.html Redirect permanent /changelog.html http://ini4j.sourceforge.net/changes-report.html Redirect permanent /releasenotes.html http://ini4j.sourceforge.net/changes-report.html Redirect permanent /todo.html http://ini4j.sourceforge.net/taglist.html Redirect permanent /tutorial.html http://ini4j.sourceforge.net/tutorial/index.html Redirect permanent /tutorials.html http://ini4j.sourceforge.net/tutorial/index.html Redirect permanent /samples.html http://ini4j.sourceforge.net/sample/index.html RedirectMatch permanent /(testapidocs)/.* http://ini4j.sourceforge.net/ RedirectMatch permanent /(pmd|links|using|cpd|checkstyle|integration|jdepend-report|surefire-report).html http://ini4j.sourceforge.net/ ErrorDocument 404 /404.html ini4j-0.5.2-SNAPSHOT/src/site/resources/404.html000066400000000000000000000034111151645323700207400ustar00rootroot00000000000000 404 Not Found

404 Not Found

The requested URL was not found on this server.

ini4j-0.5.2-SNAPSHOT/src/site/resources/css/000077500000000000000000000000001151645323700203345ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/site/resources/css/site.css000066400000000000000000000034401151645323700220130ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ h1,h2,h3,h4,h5,h6 { border: none; /* border-bottom: 1px solid #808080; */ background-color: white; font-family: Palatino, Linotype, Georgia, "Times New Roman", Times, serif; font-weight: normal; } h1,h2 { /* border-bottom: 3px double #808080;*/ } #breadcrumbs { border: none; background-color: #f0f0f0; border-top: 1px solid #a0a0a0; color: #c0c0c0; /*border-bottom: 1px solid #a0a0a0;*/ } a:link { color: #409040; } a:visited { color: #408040; } a:hover, a:active { color: #20c020; } #footer { border-top: 1px solid #e0e0e0; color: #a0a0a0; } .source { background-color: #fffff0; } #leftColumn { border: none; background-color: white; } #navcolumn h5 { border: none; font-family: Verdana, Helvetica, Arial, sans-serif; } #bodyColumn { margin-left: 170px; } #leftcol, .docs #toc, .docs .courtesylinks, #leftColumn, #navColumn { /* display: none !important;*/ } #bodyColumn, body.docs div.docs { /*margin: 0 !important; border: none !important;*/ } menu li { list-style: none; display: inline; padding: 10px; } menu li img { vertical-align: middle; } menu { padding-top: 20px; } table { width: 99%; } ini4j-0.5.2-SNAPSHOT/src/site/resources/favicon.ico000066400000000000000000000004761151645323700216740ustar00rootroot00000000000000((  Uuuuuutu6wini4j-0.5.2-SNAPSHOT/src/site/resources/img/000077500000000000000000000000001151645323700203205ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/site/resources/img/bugs.png000066400000000000000000000131361151645323700217720ustar00rootroot00000000000000PNG  IHDR@@iqgAMA7tEXtSoftwareAdobe ImageReadyqe<IDATxb?H0@ĂKq <@ Ĝ@_J E/eF (Xŀk; ğAe4乗@A@,@P $bYA6 ߀8'fdB幡wo\@5C= @1@@p]b>AEGhVĈ!DB0(e2m`awAՒŌRHPP73'O|z5Ȩ)@CTxG/@5uzYż# '033?~E_P9'(1!"u׮] ? P@Sh``iy ưrf vj*2 rjj 1gc`z ʓ' XY3_29rh {߿ Ke?B @,Q,yy 䴵X@ŭ$ `]s߿XT4Ç 1|?|3 =,,O``puueطoæM޿h}!⯄  ux>νȢɁU(V ɶz3w0H]@:/ dd 54z8z4vbtiSS@S8۷o3* 7XaacPQaPbP:030A[1&߫@3~b;W9` 2o q"4SΞe0pvp-pր FBJ10Kƫf;`Ug`У, =,7@fܰ۷ ,(8PPNVPATVǧO @3ۀKF&a~Cj@DQ$30 hV1Ws-`f[`t(ٲy@1~mb`Od8C` 089Xe(;|x LXNp˒P`}ᘈ4A(fbR@P@L<ȨX@A LûwX"09cyP <J@wr (;0yX>240@%?0`XA 8i`jy2P)0n!b@ 5eA`! i tI+Qg`{(yXP*f@xe 2Ӭ@?@s十e w@fz_M_Xg: 06x&= 0ԙ1(&(S(Ɓ#$@4Hp<(vAe8P@ ꬁfz ęoM@@<X~ChP\qG` WWgp&[g@ʃcX1 A1exHM@6(s@U@000 z큞O7@YZI0Y/0ŀ @PU σ<H 0σA}P+,a,Ydra a@Q t(00mA{O "*{4tȁAy D<@%uH V#ThP,l.0AI>ps'0R#(p@;/>23BDzec51nZ\`ȁ%>(0󰘆yT=(@a>ΐl ?*<ʊ (!0@ IHnoY <J@yA}a$:8(A<(Aȿ  l4ho1OؒAE= yY j@qyPtz%KP ?P%{zPi1 JlV`G9P=!T 'jo1j14@rg`PVD <@ρ(? >y >HAy;`]4(%<  R !0l~AVAeYGA-M`1CH H BY])8C~PX!0@0,`U<< ya=xn*/<@}PVy\) p@ `B5ChZCKafP@>zANRUUU5Zl !#+(HMA#, >`F .|rɷQ!`ax L30\P+JT"g&btv3%&&fS)(/ "APJ@3 Ab L l Hi@sRn~m !EEEOAs{\c3VGA(~'Du@-2@d -mqZ 9h#ټaAI:F!M’=L G#H\=CХ lB;[۠#D߰ v 49 >XgzyPK'냺@O}z 4Z QPĖ@yaP wAlX8 /' H` eݻzq@ŋa2ǧXZDr ru@1/`,*@w`yA /@j2F|Aec_u0?.}ϯ}׀ fA ^~0.((+) |KXXtMzzg@v=)k`^~ ğ ,’=P?h)@=ڊ M_JZ~3<h&0SUS`f6_7fc: ?@(:BL@O}f ? LLEђohG¿㑠vV`~p\fRSAB)V8,ԡч_px%vDr Rp2B!%cPcym`f) ; (%n9IOw00I C R=  )\3E3+xzu0oc;yhFa%/h#g4<PC<oAC>_-(bRZg`tWc uoh5 ؅g&,ӴI4ʱA'WA<<+.qU @:h }On!(55\P JY@@Nߐ| lQeTb)ބ@ @|Hz hOU`6``0.P|@rRÅ )0-dT?wϤ߿xZڟ5eśH+7U E;&d`% mòf )@~Ac1l?@=?y߇GT<5FSzAyʂ"y4x V^>$2P3Fl>/zݿD TvQY`*ZB4  A38'`{_C<>4y<6@.-þC :' )CZSrBlLh$!{>݂/C>4\F L?R92*?2}6^|ڞ-A\ -*kCcgU$ v]P@jx+>~*h@_#`_24A+X)󷠩?@;$6[ }:bs-f'*nh v6 MWu,Y:h  󷡭Фa@ DN7>4[f%=]ݿ4m6dH=@#~0@1_IENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/community.png000066400000000000000000000165221151645323700230600ustar00rootroot00000000000000PNG  IHDR@@iqgAMA7tEXtSoftwareAdobe ImageReadyqe<IDATxb?H0@Ăadd$ːz%߿ǝњ}|m[,Ĉ\~WRRef`'÷O>=/^xӏM=q#!":vNR[wv}g19%F6?`R~xpE0ܺqy ?HJϏ3Tt|J$@:~x/ ?4~3 vsɧOj~9Pwb!Eô`q?l4Swne`z#P h?__ L̬ Ʈ ,+iO@x>P@Dp1?бqQIe`&o`lpB<(H12C LŠ *#-[/eN*x1 !fTIl#i6W 4 Xo#(  Ũ%ԭԴTxJ@N _߽uU 0X)$= ,(@pX& _VNNu[[w6xchyIP Rbh b ߡL6 1a`dgflV@'ohR/m:7NZƐ%C(< abbs'O0ưao 379@`W+BN YP˺gߐP?@@R D`0231ˈ1h>TebϘfn%cg"&T ?#VuXoIp5͒?@|$6 n>^vnA!H?41 IeT @5@0H4230pr<0~CR_Pu858u5#7l:}vmK{V&@,󰳳1b\6~@@oF 㐘пp#Kn2(*m2'ȌR(P} ,XbOc067ɴ)  1hAC<G ZH_p`Cޭ aPT6bX0ENo,oYgav.%Og4^L@\@ ~ϯ!GAYWH@R@ ,q0)?g)%f~N&~`p`nXYTAA@A (!Ĭt(ӷ_w>~(9e0߂<,c @ {y6 Bu g;\&*L %҇fF^^ބ!7K~N0@4p[`?`IyD` V/80սx=Q7/6{` ~ U&g H#|ESAʂ+L7 y j ̰ɭ߾}zN=7sE0L_/`, ⿙mHh[(RK? p xώ\&63#2Php{_>0x a뿀W>2|׳7 R 4?*T))3@PSNAYN\XKS (%/g0t;ݻ'wa1/`=,@yO>00}!L,,H鿰@߿H^"XGFEGG̸<@9Omэ޻jԂb ?g?0|z?@=0 Bb <#ֿqHS/dgaf@? O(BQޕ :v bz`Ky'lL.}|ءbcx,%iHψ>liHC[@Og@4q (&66 qKD8:8٭)WdpR /0zAFÔ(Ъ\y0~cv^9cUL`gy5Kz*@ T+_Mb"߾Oqjsndý;L̓ l(dxn/80 @?4 7?^3|L ?Sbu#+ed<# ؓ`9C;dyoV_;FT24yeZ;20h*+bh5 L`:sAgFA` XHz~cobR j&콓^{ 3o>#CňVC14뀛yT?`[o?* *c;BUUgLdd`XxzC^ Énʠ!pkLc43%3*0+ ;lزfg%_`'?{ M~A5=dҤ/H{Xh7}ϿAy|]d^ H22u5T2*2xrmuSbef2\_ttmm%.c મ`7/؍~޺!*38z:*#:VXw`[?a8F`5_sߺ (o % Nj >e8 ;Ï_~{, @| (Ƞ!Ơ* TW<#=NgwvfPbePR`|Α`%e ab>H `amw/ jD0G N_}x廛@܅NEX#݀1 < | _|f`ada7+;/`A ? r S0cMbP1HqI33~ `fxkmeR;~A2 -pE-I-w /+x›Rx sJt8U0 P~[b q oNb\ 0 .@N v{ `30h#4N@)/S ++#oQ^Q/@02ge`0bGA=2>68Ł)X[5YLaO 3(0l)g 냴u=/ \o3|°]=៦os=;x Z"Jl: ~a6*sLlPCF?#(u? 2|~0{s5}DDx04333H<\}# %2B>_x+Dfz'˘3aز Cmwsi%\],"vN: Pk) .A>w?^2 4 0c)}&FH+/#x 8@Y78oW &0pchĠ ή "g1?uGIܹ4}f#? UMx10xcػCE!{cp՟t+l "B ߌFR_? g`e2|p<@Ag&2#rS[caw 'n0LaPb`sAQ! Pڽ  ?sX2{AI{^{3~10Æ^LAِUKw !=Ja ~e0Qf jyPۿ>?9^- Z,?dYCc 3< .l^X3u/-X@=[g2 &Xj&h`- 0O}axʜ \$ -M>P{bd`?(+,!?(<3x GEؕ '|bcq`8}=Kǯ/NŃ@O߾#x?4C>( o}p8 ën= +dܜMAU8 ,~nA`ac`e ?\% Iq@̀hH | J zn$%2jb7O??2p2? 8ـ)a̛72x![2p2pp0| 4 @31H h>!Nhb  OB 윬 -/`fJ Y8DuxǞ>wASؐ/YgRlo W/1;;3ɠ;d?$@3t )E_0<"(2yAXAN)wbv=4d G߿/ںH@,V34 r@tޑePc #rnV148 F3W_[:n~3cW a  X÷\ iP7`{qFhAQ! @J 23Vu8`3-@s.+a`ܓbL rڌ rzY/'#x3L q58@g+bE`JT@cLhe##r52e0|`Ps@Myr*óׇ|c,7+ '3'FA`Pre`'lHk#A?/}o o`+ rGp3@8-=h7~~i @SI^H]ήS3+gf>`6A kD}#(Z0# b/Z _Z?__}Dhb/tT3400|97hi-T PqO=3RuVcq4 <@IѺa/B"vn/4>C2@ 6(8#8߯/>5z~xhT“?TצCJYdX=|;:.J Djq$C7ꟷ,O.sr.9 xD&,_S@nq _|g8`éݽϏu·YDі?+wJZl: Z 1f1tM V G@3 S0\Yq[~s;_A~ zoblnpHIK)0H+3)3p 0r[ĕa'A^M }exu Ów^^~ly>@{A~ z,00r31Ef,%-/#-!l./>0ObÏ_//?202+iZl;<,g TuJ2>9]`IAP]y* ľ,4-dW`&_> o)~-@wWI7xDXڶ-`U,3;ԃm P6M@rgvNؑ:)H*\5!vHUOple|qw m,FYIENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/docs.png000066400000000000000000000127041151645323700217620ustar00rootroot00000000000000PNG  IHDR@@iqsBIT|dtEXtSoftwarewww.inkscape.org<VIDAT8{pם?=c€6pƵƆl<6{ޛTVnnvf:ڛN0661 6`$  {%@Bc{:uzZ9RJM+Y<=#4?_ʧq_Yƀg&iۀEJ::|^~I˟T>u";OMJ@ / Rq$|NdJ6m@Պ%ø)=ΦӼ?ǎAB:5**ǭ'BX ӽytf|>ยoJRahK$xwhnlDB2 ^}AB?5-G@fnq1~p[ǤaKdgs*{ގ$x |_ +BT3y33yt6Λ'F*#&X @COx]]J 75!f@(l6޶˖L"RMU]kw3ۋ}Iح󿔲c*<ٯ"x֭@U XWiN~{7C0:\N.;);oWxL+mulz1gd`\w*5~ڶ6^߽X"jץ) ȰmX-1fx0dvϛ2$T<3mVfv1yX M#g% ,bժUx\[gD:o u:#v$zAMH@1߁lgJ XiQq Yio>pPz5+*kڝ KcR`]'쳔\s0tts3|0|:՗\9H%!pޟ9e\[ob嚵; UQgLpNRΝ=Ç͛)³~=bD0b 5#)thNsڮzZsSo\a>ys"z8s2K_h%%%zIn 9R6)R&TPKh;`=N'23P#ϣj:|~>[߱f:NĒ ˀmee?>4#\wEhA><j'%0[.u<-,Qr3:N6 c"c=É_Glapl^6 !޽@,ٰjUy[l#<;9bzkxe`$G̱`45Qe'"%pl@RJĒ ' W-D4ˇPP2+]T$c1v~WXc!!p8n`<7smC!tGK:M6EhړP cWJyne/e#n  b}MD."5ṱ|KF1nk_^5(0?Bhvb~V4Vz0b1Bo@u5]{ =]{,":)e@Pȯ&&a#Iljt"SAf]Nɽ1&p.GvkK*MUw8^nx[{o+-S)@u5ݻwӂ٤Z^q/C+ I 8Jt *լ~Օ4q!#!zK(PZ^En&^C;}X$.McIa! (FѴ1mm!XY`ٵ>Zs{ȭ$o 4 IڏЀ ]N2].XM_ʶ#v"`(t#Das(] ό$ Ð5_hb,+.2?YYY`}W:oW8s~4ɭ"KFFm.SS5'p+#b #f,v41efne-ވw&R˴w&z .X5غ?'rqMbQ {I>UҥVUXߏ$iu@$~4o1BQPlV0![J7qO"k|f Jp UimfOK YN'm(b]QA^U9̼~ߏ&D7 B`wg z-KM8", BQܢa u,hޙdKTo_lw{xzRJO )Aow7i]Gu^_v6ddd+Y7(*飯OcӖ1mtMh#NJłuINoɚظĢE.B̓+w8r\<eF*Ot?$kBlpch#UgνW-PVZ:i#:9FC3))>rkcw}EO&%- ]xWQ홸.ĞY2%BQPT XUn;#EwQd{M# `DQ,Ea1^ V kK8 X*u lFC =C$ {vՙOA%ZFFÈ'unz:;^g0BQH"$3%P&8ç`u)'ȟC]7;%&̺kErro7g2xf7gvqau񺉙|N;;P൏T 9:Cc-h. ]Ct 998HA6rFу .\!M.Χ,i).4Ұ*g]-;f.0aN1O1v:&q4!_&_oNt --T=!zqejlDUĨe]70tCw( 9(VHiҖ43cQTΣWiz5׼{ b{CSw?_)]}X+ qySώ;mOfS`uz Tĺee\4@``j0x3<^SFMef//$L~S8Loc3}Mđ5Wa% <%‘uhFSpwt cLM:Êjw3poDg,g7-RF1ߥ 0o@#ITEf]>:I3,W)[YH<tM7-x'mpf/"t Ca%).IXV,xuW"\Px`z tg<@枸5EȎ9x8V0Em6jC F 0 ֹ( M,@7;wKRLj$PdoQSCs98z!ʩdˊ/er%zL:CLTłEh'bhTuMTy_y4{93a'1N!/&!jg(Rի5 ]Ĝ\ Jݲw{@$6mBl.+{%1ӟ{4L]3o36E_ aihGTOފ$Vv=[ǴyY/GXn{ݭc#a_K__@x~S͐ |m3Vm9Bh5Zmbhn}V0G&\}GɌۧ՘.$%llKUFRxZO\w-opBrsg`TJeK!LAt6Ln geOؒVAIENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/download.png000066400000000000000000000103431151645323700226360ustar00rootroot00000000000000PNG  IHDR@@iqgAMA7tEXtSoftwareAdobe ImageReadyqe<uIDATxb?H8 F|ЈB FFFtsIoz st ?Ocslß1w"/1?s f;& vϹ*_+w9@3001 d SkM;II  ǟ?k< ܪ r28!:0112[@^Fe 0/)NiB ڮ 3k$/r2~a`h%ȰpOXeu%-> Iq@1dt #)` If$B; A^qH@g13)^ ` f10 ZuLaeK?O5 H 0G2 )Tp3 R5@!Ø@ !!M$Hr:  @(ddr_w DZ03 Fp" َ "3C!@_47Dz, `zP2S@ ? `O"Z DA @v;z2 h@ZՙY {,@7@Ki]y̐>W`٫ waq?ïߐ%"30;= YAfc3n?"F` wPH~"/r(T'ed3ԍ /=?8r= d3hȳ F  Rb'wu?l}2[ Dz` @]q2kаn10zpw=mǁ4#rjaа%3 E2 e)=,ܮz032pp2A!0G P0@ $eY`f`2Ҷ`@fCR#3e@8"/`aCTXc X_#$ !4H?_Pddyy?"/2 5& @d5#֡d tGlL@30?ϐ_,XFPz 00CC?#t &f0#0}122p+33h4cp&#ub|-7ÿ?RXpb(01j 6 ~=L@|b`FCٰ&4P )?/O0 _A+Н=~;tiÛ@m85R i<2fHv ?A(Ckp2vN!в ʈ^h**(3"% ` jP0c@#P!  YHpalcʛ\?#hT /"0J:Ō00CBP Hg`ac%/qr6100 h;\ n B eJ3 ء OCKPֆ%mx)@2 88c?49X Y7([(Kz:d/(߬b+gLUD8,nH`4Ӡ`u+xLfh}8fQLz?I @< l#gzTw C@ :u ‡݀AG_\x2aIe/R*6!ZFP\Ղ`?4!5w@m'n2lA~ b273y\j`# n<))Gq 5R̀ч __@K<~ڔ@߁=߰u@~ RIqeU @I0m >Z bR`RH?1W ).pg(O@K@p"ubur9@<_uo,ITqx@v֏ g]bx8>h/uBA%2A9j[K(_ &` VA ţ1bhO o@biWNBY ~@2A?` ,_fP n&;PL ~o w`$&h0(ŀL0 Ua?_C=! >oHX#@,U qQ 1ed`z  ;å ^tx ۏ0|} Zz%$OЁ@X[SDAD;aa.@ ~O\NAUl/^~dv o Otd4  @#*1X0HZ>`- L{^y W._c*4@%.N= : mc qY, j 11ȹ$0cba.j &2 ~ 4DúWo>arЁT ,λpk1hA]@XZA7-Aѧ T9Y*2x*cOp}H º  h8jH0Zx0>3БfwVfif:cP ӷ Od)qW3ݧ^j%)u<1@ HqpfIncR}%`:E dyó':+0>y,1|z]VsT];@:`$? QQ(\u⦽޾/NfЮ,՗b@X ί`^ *x_>}̵=lA`W m 0&,mCLAC9&e rsČBbc.ýͧԨ @<302T ܯFlhVM1 w[gh@2"xIENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/feature.png000066400000000000000000000101311151645323700224550ustar00rootroot00000000000000PNG  IHDR@@iqgAMA7tEXtSoftwareAdobe ImageReadyqe<IDATxb?H0@BFFF10pa`` *J i> ́\_yb`aO~Uh[# h``` dMub)jFV %ssc`o  *HCO }ÎG +610\   @1gJV"* r  L Ll LLa/0|FLJ y`28/00|N)߀C<A&ifȊbgg` $Y+`,sJ$ r`1|@oU z0p~1Ypa>û0*мa T_r ( FqϕiA$#ľ@Ėg0a133 ۀU`}p`10%_2@r I@d@;'Љہް7f @39C<*ă?Գ` KY )0@( <` M`xlI燿:00LJb@,VF ɼ I?0[{`F:8v!2< -E'03Fb@& dC?zFf? s>J#"+t뤈*`~7E4C O=3gҼWڟi#$TxÁR=r`pT0/"+q.@f $d d1@4 BBL_1qKOe,l@Brg? 21|H@4 ~CG40 Hit3\<ΰG`3;؀Dv @,?8X#h?o߾ @4[+wϞ(gXH¬(wp}"a пNYbŋ{O.'Od ݻw v-@ [@O\t7\ KL-? z_ hV ТZ V^<@Mz`':@#@: 2A2RqEP* iޟXH=@#~0@tײIENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/fedora.png000066400000000000000000000014421151645323700222670ustar00rootroot00000000000000PNG  IHDRP -tIME .y pHYsnu>gAMA a`PLTE{Kј)ǹlŦv\;ͺk`ޖl_o5rW\BzH}>o J&EIDATxݚ jV.'ng=ڜTK%'qo:pa]it OӲcv qE&Xu[f/]#]&no8nw*%8g}~Hd`VDpݢ7֞KOy66Po_hӮ_#Z7`S:|׫z-OB!& <ARi(Y)QH,_ϭbMtUZz~*o_^ !,f @ZDM!cRw uD׫9Br493osؔ ?B 8RV)km]A7^}]cq7C'JS(kmtIENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/forum.png000066400000000000000000000156451151645323700221710ustar00rootroot00000000000000PNG  IHDR@@iqgAMA7tEXtSoftwareAdobe ImageReadyqe<7IDATxb?H0@4 F|Јb1)7VY @2PTAh#;* g@ß?>~'bk5q@;303Y333p`/'P 0Y` 䵟 63g `,ÿ|pC B4XWgz؁C ' P\aQVN~!iMQy>  NA>V&$;>{_1{G o޿g@1 ?DE@0V2p10231S_X^FEˆBLAK u ~}aÑח=;p#_/30?``s~_asÕ'k?S+ SUz7?*"PPB_ƂC֔AW3d?)  Kp%0|s{)71_'>~g(P7J@v*)@  z@afgW`c_ !aJfFfp'Ággp3 _Oc~7Oߦ1\} @-ȵ  ;0Nz:4Sf`Pn #OM: 8^0FϏ3023|ݡ ^sÃ'M ;\_ ` 猿3dy2kctYXYa} le5Û"VR +؂lyr2z2$j؁t,l gX|{+66`$p0<oexe@,XE`b fyX,aj;`?=*$a}pE r^" o;ç_: %Ny1`'1X!538e~ 2gn W 8JJG<5>9k!BV Iqib?t0 D8n#! PA+5jitH4Y.~$ߛ|mRB2᫹IYNQ,?3Jj%PN$DXk,v$o%]Y|40/bDlף:v؟[T/ܡ6𞔨8B@ȵi`#_T -؅yy)K KpY43's94+8VYN`e ķ.r1xLbNN`@w7`'`9Կ2)cP0~͠`A%~/?Ƞ j j` PD+rGK lI6f.``pypy'' 7Nq1&(.Ǡh$`/̠ ' lsA% ,_[~3ܺ 'W;0&<̄\xKd<+vVy8bXp0:1 $*Z.!?0Q02+l 0(p:ÎpB0u~ ?0B3B 3xf4e6VA,d , k#>;@1sCiN.vN< &2bfgse``tB<^"0@ ofbXWI<ۺRwJ  y偅 pV; r3Y H47P=7<xC? jx``Pave a6%v5J8X\0|İ Î?ׯ1|ۜlF> η]KZFOv`r`EF Fp sHs=<٥| w*00:1x26% M30H,,Bx5v2 _2 :>՟|a`t2pݠXAw!zR33l30~ÿ/) =2v * ,j h 3#8`[vpưҞVEx0cx%P & @ ,~f@d`za>vyƟ@{1S}Ʋp /ZEW2Y mb lCb}³CYUAVC0Bwhl ?p2l nUyAF$38;9?D?%8U \ *lca ؒgb#|О c8{{nF3TbT1b`WH AZuu\ J20i+2q<:cʣ \\ |\ 6<'a?dA!Xxʰg^D P` w^ex=7ag(e0NCL ThxpG?o}'U~Q^ƯVؿ@GA{u= #x/vMq%O[ٟ 1PT2~c?w8'C~$;c/npU=o`Xw!ۉ!ȘE`K/?0.= f x@'Um&߯A@,x(UCN (1 /Wu97.sSI?WR ~p00|Ѓ t80Б90|8 ț*= lq0<{4_`3O]mHfF#;?vqE`}'r@Q *LTtŀ lXfhfp*'Y ܉cy K `f,,D3v02 すlxAB ^zER x/!/ @6 q fVm`> *8`m07` Y-#^!` ??i?p<0e98;0jǁ L11X&<<(Da0h| |˿ˡ?LB+f@wkL ?Aa JD8~Y/#cll֩xyy68ߝg.mypĝa`de&| ~x 䲱A< r 2T@Zv< 0bnJ4_?0 daD3y[h @,0 *X{o`x0Vcex=>GO?oٹāfƉ~<08mg 6c_4IX?_:x'ϯû?;^pß?yhK,5C{?4s@jJ@ğ@b\2؉!X+ z-ïF{Pi @ UhU÷W> .3~zo{`٠gOϼc?PK@ϳB*`et4;SHJXU+Cį sr{?3 Ot ^A`|bx7߅N N-6n9p}h4)}]&bVٵpY]ap!$.@TZǟ ? A0`~@3SHve_ 3KzAXhk ޝ}3tx oC'Boh ՝jG6^Oe4޽<; }ð:di x r]@׽\ܟLnFA`_[ ^t91ס~ 2 p1 /waxc'&×Ri0f X*##\,6|"P6C:@o,>փ&{`+)'3nC';3&V`ɣn F$gdx:wd1`1x-ZB\ngq&ý 2Z:*y TPpF䮃5 PňS}DDBBBu^quŧW3M\[ u0tw͹3 Ûsױ;D} ]n+۽e ՞OgЮsORկmr;ho׍աM|5L !BtĮXRh>{ZzW ce`uy|_J744գ>܌o/^F0f@"8|j%%%B[[L{m6Ν;NH$BLL &L)S@(b`ҥ`k׮5C(bX[2Çh"r;v eeejJHKKٳVC^D9rgΜJ?F{ :7nDUU~m;wǏJ‚ Uzi&TTT੧¤Iի(((@tt4!Q ՗vN+UP󾃙q(. }Z>׼pѶ%^^ x} ,,̣cF#֭[шl6hZ>}6 <}ᇨch48y$~^>dR5Tٌee)|HT BBZ̟?"hllF5}j"33^wV(J@.;ɕ+W}vBj'Oj~ߕ+, !k |aj(L;]zFx[Z6{_{=uü֑==E}5լLؒddd`̙J`;w?_3TN-[@ %%3g׮]'|ZB,[s0N&x!A&'#N}FQQGEEqڙ ?x衇|Zl$f?qN3f@"f?ӧqYtQSSł8-{}TVV"$$ .Djj*B!*++}v455a޽xj5t:ϟt=ьPsQQ 1zhr;>1(>Z;&2zĭ5:^TB`)9 nFowbP{Q%M1W~DkCze]͌_r"77)0e.˲gh4L<˖-L[ `Ȑ!xǹ'ҽ;}aO?.\u\Kx;.hjjrZv\ 8wCCӦMCvv6n 6mSx;K5^>@Z cǎ̵ 2K.`|qW d2 Φ?Md9!i؍I;>Na:9`uf":X 4]2p@@cc#JJJ\ގMvr5'PPPХ2P;wgϞ1tPw}>9bƌN܍FWumv~aZ3go \ W#447n^R]i3ԣGܵL9nY#z32hR s7#5$i]w)Jf:XJKKs⪃-))09 $_#TW`ZQWWhZ`Сn l6ck999N7 _Ⱦƻ܉ ]EmgZFcxI})f6ꤧ-7u쉦L&sDhZ9rR C3[^/KW^+^+]_$G琸iCjÕd XWw;˗/sɦ%]Fz <<3V˙_紵Fq9. $&&" {|zq455!==X|N&HR뜍\!t\a2R 5>ĒlgH$hooRP(İaxm{ɖA h4h4B"0͘={v*;`jP=Y_ն~;ovlRw|嗸t|IL% .\3}vA*bNW_m4.^-!(B1*_'T~t]'"v rǝce/>p\8 c7wcz\$l`C׮܂? u{@v<k7INRTTT`۶mD\*822-rdGff&>c\|yyyNdmJJ ._{rPhmmErr2 *޽F[GkoHJJ˜1c~|9sNBXXÆ:i'+Oor6q H$qQ>,YYY8t w^sZb$&v@,.O'NVӕ)S=OPjn ׈ rJ;]dJłOCwMM[R6w3Nfut'ij̓|X,ʕ+ LՊcΜ9wiiix!˹'$$$ ++ yyy3V,XI&!((h46l}Y,_ӧOT*lv2vQ `ܹxMl9.G'\S>jD" >/F͠ǣ>u9B&<=3Ԡ <#@ #њ;Ts=vңb1k] fwú~~N_Ѝg}T<О*[9Н*r2UDؕK<_|ͣd IDߡ[lA\\C-O =j|\2~-F8~!NT֢9-IҰ.&j^Q)<F@\EP%Tom%F9-ُv=L QT0L7oGKP].#!zSE(Uayl~- p?Opѣޣ%3!HSFRAbhd%zSHDiį]PLfJA*AAPJAdAAA*AAA*AAdAAJAdAAJU@AdAAJAdAAp?Wɑ}IENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/ini4j.png000066400000000000000000000010171151645323700220420ustar00rootroot00000000000000PNG  IHDRX쪝gAMA abKGD pHYs  ~tIME0jIDATxXّ0 3)SI@ A}2k.1ى# $=6Ҳ^)5}랾*ն|ޟl]JB>5N2!B"v%iDDđhUk*"6Mb* eIDu]oR^S1zN[n[pa3"ƨ4ED^*rZC>!B"཈<IaLyFIENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/sample.png000066400000000000000000000111601151645323700223060ustar00rootroot00000000000000PNG  IHDR@@iqgAMA7tEXtSoftwareAdobe ImageReadyqe<IDATxb?H8 06K10]d 4/a᯿>mP=a yZ6N! A-ƕXX.=3kbi Ol iC+Ï?6FV=)ek~cxc: o-@L?`xϟ+3 ﯁ |@N@>33O ?&Y"-@tF3| Xfϰ``.X?xߜLFE& :0`S ^`8.P_p=ʀ)ßqf&f` G^gx5?M@&\a=` ?cL ^f9ß?3÷B HA7'ToE*&vFnJ+ذ.p#``/;+3 л@_CHM؁AG*Ƞ%Zp)_2?'Fv e+ɗF}bx?8Ux #8L8hsab/2| mަV )jLfi{.?0~ l8ؘ < {A.8g~#@Ѣ p|dz.c(?1|???@/=, |p_N;Ϩ9 03X_gn-x_?^~{;o@ σ<< yÏ_0z~@eG5XU5܍)72tbnq0 ?>zw7 C 8X[V^3"$G{2|A? {^?{ D6Dӆ5B.[/Zv2;×O_ف{ )}*;' WIF@aMQQQLLLeʓ$~իߺ'*`v=Ğm  ɼ B?^/{%C۷Ђ3b`jc4@%]@+`߾{>~ ц 0R@LL&--uNNVիw_.p1ݸ.p%5ᗞ& 'Cٯ m3񚁅&.<-g#s>, \\ @[=Nvqq1VA9ׯ <f37o mKk6##spjy V.@ w*I _zv9D ~6f~` z }V3|20\W;;ff-^Nas{cSA # >g`ش (xZ0 Čua z1NX%Qh BłCgJR1T]G.mH8D`I kzG-pֈiF]`=RX\C9=3Hsq?lyQ:b CuHׯ2ܽ{ ȒR&Y^0L f Q%v0Bf'[g߀3Fd[b\lsN4@DQ<_seԘ Yi]VUq& 1 TBQpiϚ@L?~CX_Z0CfafA1 y`-`~ 4oy,y'!'fH,)@8yYLLK'0E/ PR@a;8 42cOHIeӯ_/ W,r^z w(ƝPY80l}@I#t?MԨgNHq& ܅ б`dcPvDg9HM*8RmKd .IT>x*_ Ă@2m%,lb[G@=FY c@  kLsH7 T2ΠTA64`<ZB2|ń`&,pj"uJIb> 52RskbD8 V;`zt@8yoz` HeA'ic|͌ 7Ȭ_q?2c @` ϟ?f+E,y4-~Ϡ,.DtJD˗/@/Ç$EE0 `l XYF?u@ Zz9÷W '6%L*x"Ѡ]Ã_^>`g WB^^^MMAf|͛7DrX/6P*y"v0Ǐ ?&PЃL&9AXbw Uu(@Afb˗/f8@ S{k0laW` ~ L?fx ѥhv>(}ӧ!% rA[Q w^˞={4%%%Hg  -ءm}ʪs]][II&QZ/0A[ple4<'09pm)00sr!; g`qS;v۠(7jL@d,H_ Q19C>|Ғ5os? j*U,J/3H8C h`w0 ngay Я,B@wϟMRg~NvN.FVPO #p"z y`IAk!H\wMy@P,EyTFyg!!`C,Fx^` ~ rꛃ@TPY^7x!SFDQ=6Zā"@Kdd c@6A5PAx `bð؆ 8,mm]ݻw'f13P2 @dORFxj0@AF ;W  "}`zX< ?~ 00<J=buuMXFLX2 6n(!! N )ŀ@:QIQ,YYyhF}h}d?4/3! 1€<3,p %-I8%[HyBHDA !r$ (yf1Q,.g&KrEi ?..v`9(;l nnNȎ ‚", <Uyઐ6}>W2o@&iT’n Nׯ1\BUb}NonЀ'%@d{I Pz@{YX$ ¾z l0v8pf`~^ o`$1xƍ׮];L'j(X~<ށ3ܵ bNв3NC:lE92ah:t ,Dbiv bd%#!kP@Kixc r' ;n"MIENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/tutorial.png000066400000000000000000000140261151645323700226740ustar00rootroot00000000000000PNG  IHDR@@iqgAMA7tEXtSoftwareAdobe ImageReadyqe<IDATxb?H0@ĂaddDdb` iL. 7D" n&+D1pQJ[AWFG¦9hA<Iы oeP"z >QcF9S<ϟ `scc0qlljcC@?8GEPp BR &ˏ2aX ,CSA %"<Bt5UXQcc!tgBP>'0 6#TNC= u@)/3;0;`@,3P dxcē xY~A?GTOM03?̿ 3C) $t&?Ag` / s<cb?0l@>gU.`(<3CI"þ @A4(Gh#jUy=`oep13T?1I0,J_p6Ŧs - |R@wPeH@6\Vd<v~Wy+3 .~Cm"Uu~E bC$`H0=3p1lkg`gfX AH5!@r ;@d *~p/@_A) ŻG =T ?JS +jZ92\2̊Qn+opb@R [Ùn=Ġ+e LV2 GoF=*AILsq32<ڶG<0vEs>а Gf`qa^xFPk/̆(1R<@m1b&&fFP!ZBϿ2lZɐjŰS)m` | Š@fdf`afXs~5b%5ٹ&01ChLp}f}; LL aoWlcQ7Cx`gg ? z $Ã[ 7_`ae([_pEHg`W;ȭb.K[@#HÈp"%8A<[x @ Bx212r0Hp1ȉ2 ,88!cojσ[BFxP _`K.C>|y޽[w^v|6u&INȈAy`g0A`$1@`<f?~|ǏoW>7&b`<@ js-A` rt+H,PBUK;ᮻ_~]AJi?j:H1>4sGYhn\ʉ0rŰ21ʜ P(Acf S I1 e q, i(F(B@X_>Đ K e3zP9$%D E=/ARAPMϖ;__GF P vz ߸b>}e1 b֖b oDLg$wz 94Xpy( rҌ/ BYbOY, o`` :0*1gD>1K""÷!= 4"POyIpC 8$SIy #1zD X(0)'P"a X0GX~>bȶ| 1220&NtK0DḞA++ކnP W09xf6{M`pv[2" V B]mUĵnpx>:0/^5qix멞ϱG-)CP?*hs7)EgkH4ÎN?P P0C!~ZK@ϳ2Mf.;6_ "ϐ%@ %٘=@X{!ZqѧU%ƨ/7=i_;Xtfz o_2<ܮ;o+N!+4SAhn.`p/gɹ' F|q~?{@~c(~| -bg>R@ H|zCFL?lǟ{ٙ4!Ǘ?J' ~R& dbbt_]K @,W:U!HMAV˷?>q `Dʛ__&,O<03j?ih_ _<+! "LqQ=+syI_D0ǿ,MAG?}?~aPPb6l3|)Oa񟋁OK@8o9Y@?n ihVo&[׿2HK030 20l^N]}ýwQ@w4x rE0'4{`Ayv ~z;''80ͩ*˦3'?blE3#ßpϯ'*Dy0Z X`bef ӿ߿`h`慷 Oe ``%{;P{1ܸAPWFs./0׵~u XHu0beu+A׏%%m.8`s,@$` l²AXWbm ֑o'1ܻpϦsπX3rܸ-z 0O`_EƆ^n K߭G>H*E<"zϐ3:,ωPAA'0b` γ0dO}}&m.>o5NR\냑@Rޖ T/CϿ2jH~a _)73, /~1G7TgÌ^o+P W| ф BXM1p;" Ը1 `8{$Ar`ޏ~ ̠?nVZ$x989] [|0zL4]_@BauA'[ V`I@KB[g2sR =Ap`K٘f_mnv!>N>!v R,L@Ҹ ?<䁝b Y ݣO W};~|} ;0KB?Ms*A^tdZ Z<"X &uFU} ݱwW6oh4elS_`ϿljM?t"|aW 3l @14Ј<IENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/img/ubuntu.png000066400000000000000000000044011151645323700223470ustar00rootroot00000000000000PNG  IHDRdAgAMAOX2bKGD pHYs."."ݒcIDAThlV?羷--J?j#X:ls,QF6!ۜI-SdN݂9edM jFZpHAe:(t=y.}K[or{9d7S/D06$*w^:[2cBH~k0:0f(z4H.9oaˁI`ydPRGHrBxu6!E!vTD^|WZNe$!vRHCT>UyHމvxWE[0ǖcm^ s[]ɴv udG910.v#Mj-*q:׫MfohGJ5ꐌW߅އM~ˑS{\Ӌvqa/}Bg%yTXrݼ_eH]vNXHU{dȱ:HS>OHu풀^_B4bvQoAe9Rf!*} jSϲ 'U'Gzu![Sۧ u F)-=|dgC.T:f8Mӡ@etid#ad#Bp#(h9$ %rk!.-{#XQ࿪pȚ<0vH\gk/q-%)60"" H 20&&qu勝۷n;/jxwbvMFF2\:)?#@Z X9998yxHIPt?(V`@;;;;'';P_D&- @sQ{Q , b;Y(b~_X<8(!Spqq1st7@Q='L1}T?P6 dQD`dd&Wf=708D2<, Z*09L-Ǡ%.Nf`ݻg`dgd4%(ŁR({(1 l}%@DвLLl֭fdd(8[t L`qK^ B/=f8|+n^ O45u44̭~<302c`ceg`500>|9&p C6XXΝ; ֿJ bGؽz8BH@lb }`)81; cbL#19yACM\o^|`` o`/?e A`CaÆ} /_{U@] ,'Ξ=M@|*IH9}jREU9ؔ= o2o A,, ?`Cpp( Õ.^4vuP_O /0F q@#C?A޽֝aî ood`xǿۧp8Dʘ WeGyr3j0$EX2LJdg'$<'?? X/baP_#71yȈAFVJ>bq0\pAAAa )!,6m:İmF`@|g42, b{%z{CPX :bV```PQ`x)0)0%$86DYaڔI ̌, F +V =/[`hh`hd0oz`?e2HIJ=/6SRRl. mSq!7BWAPA\KD%a`'m)!+"!32qb`fPVg1$70D(@|uU˗08:y2߿X=&`//^1̚>'2!:2aX4C`Xt>0@= mQ]<``"G6`~@fA( cI&l=- ^O&]^(ZW'h8a@{* gh` wDbΑ : }:ӿ%1>654f\w+H Ty08jEWᲜ óFb ۜh5& P'$6+^~#K~3\ݹJ s$Pz{ eu6a`0Ɓƿc @c >ҿaղ_ N: 3$i290k koywC|<8l`F쟧 1rg4a!X3`jeh%Ç}MZz / Tf Lv  > 1>|̒@C >0=Zq  u 1:S.D{ x/1XbQ`hIQc HZ`Pg@3.1gz++ \iTZN2CZSLi u% _UrWeu{ ?$v2DO  jV;#a?]u-A`#`# i#h7_/0|0fiyj-0S⯗5aWiab \`~ w fv}j moҞ W@ T}e b?gxuj9s+ B\ |cb AMAYW?1\yaaVߥ1Ȱ|6 y>}{p /4weY`b*!kϟ18CY.5Ç ֶ Z* ?(,sO.|sˀį@H V.`5-ɗAҕ >:2?>a0`;I30{`}X]``+P , } }}`q! < k18s3q0 '/alzΠ-5CӺ J 6@?.]}p6/K K02pҭo= /_5g0|+ $-̆}k ߁}qnk7>2pIj’XGo,X9T>b߻[^=Lf4h/YA\ǜçNX5Mg%>?300p g ;&ǰ ó_YBف1ڳc ezƒR :]u1( sx5Ý^}.,>$ÿFn Br  oL ُU'/;&l 4X}}z,E|D/1nfbh)`KovCNgM6 ;>]fb 1~ 5l0,Xx?IA7 %xjfh9p3 E$>}pUWc'`.lK 0|F^_ri! aII(5X$;;?NR$;)|fOX~_s:_%w@O/=]9l [Uu,L}8eRGu1*8i kw 1>,lV 2D#zejInR6b|0ԚYw7p4Vh{ UuϷ2@ޜ_` VxQ!P=&:F,)D!6TJuC(*zVY^ D'fN2CꈢVF?%+9çjth)iV=QᲑG'#HZ]^H8HR^mFK:. RM!@Ld3GVD5k\Lj̢V<̋?  "26w(#|(j~ՀQ@(i?hM?a4Ј@#> RrIENDB`ini4j-0.5.2-SNAPSHOT/src/site/resources/robots.txt000066400000000000000000000000531151645323700216130ustar00rootroot00000000000000Sitemap: http://www.ini4j.org/sitemap.xml ini4j-0.5.2-SNAPSHOT/src/site/site.xml000066400000000000000000000116721151645323700172270ustar00rootroot00000000000000 org.apache.maven.skins maven-default-skin 1.0 [ini4j] img/ini4j-banner.png http://ini4j.sourceforge.net/index.html SourceForge http://sourceforge.net/sflogo.php?group_id=129580&type=16 http://sourceforge.net ini4j-0.5.2-SNAPSHOT/src/site/xdoc/000077500000000000000000000000001151645323700164675ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/site/xdoc/community.xml000066400000000000000000000046431151645323700212440ustar00rootroot00000000000000 Community

In my work I use a lot of opensource library/tool. I beleive the power of opensource. I develop [ini4j] in my spare time, and it is my donation to community.

The quality of this project is depend on you. You can improve quality with bug reports, featrue requests, comments etc. So please do not hesitate if you have some comments.

  • Bug report
  • Feature request
  • Forums
  • Running ini4j.org has some cost. You can support it by donating this project.

    Support This Project

    ini4j-0.5.2-SNAPSHOT/src/site/xdoc/demo.xml000066400000000000000000000027501151645323700201410ustar00rootroot00000000000000 Demo

    If have Java enabled browser (with Java version 1.5 or above) you can try [ini4j] library with this demo applet (or you can download it as executable jar file: ini4j-demo.jar). Check the help tab in applet for instructions.

    ini4j-0.5.2-SNAPSHOT/src/site/xdoc/documents.xml000066400000000000000000000017621151645323700212200ustar00rootroot00000000000000 Documents
    ini4j-0.5.2-SNAPSHOT/src/site/xdoc/download.xml000066400000000000000000000054211151645323700210220ustar00rootroot00000000000000 Download

    The main download location for [ini4j] is the SourceForge download site.

    Download from SourceForge

    [ini4j] also deployed into Maven Central repository, so if you are using Apache Maven build environment, nothing to do: maven will download automatically.

    Download from Maven Central repository

    If you are using Apache Maven build system, you need only specify [ini4j] as dependency:

    org.ini4j ini4j X.Y.Z ]]>

    For Linux users also easy to get [ini4j]. Most Linux distribution already contains [ini4j] as installable library, called: libini4j-java. You can use standard package manager (rpm/apt-get) to install it.

  • If you have NetBeans IDE installed on your computer, probably you already have [ini4j] :)

    ini4j-0.5.2-SNAPSHOT/src/site/xdoc/features.xml000066400000000000000000000017601151645323700210330ustar00rootroot00000000000000 Features
    ini4j-0.5.2-SNAPSHOT/src/site/xdoc/index.xml000066400000000000000000000114151151645323700203220ustar00rootroot00000000000000 Java API for handling Windows ini file format

    The [ini4j] is a simple Java API for handling configuration files in Windows .ini format. Additionally, the library includes Java Preferences API implementation based on the .ini file.

  • Tutorials
  • Download
  • Community
  • [ini4j] has very simple, but intuitive document model for windows .ini files. Basicly it is two level of Maps. You can use full power of Collections API. The Ini (Wini) class is map of Sections. Section is map of name/value pairs (options). --> Ini Tutorial

    In addition of model above, [ini4j] is able to deal with multiply option/section entries. It can be handled with MultiMap interface, which simply extends Map interface, and allow multiply values per key.

    Many .ini files contains same values more than one times. With [ini4j] you are able to refer other options value via simple macro substitution. The basic syntax is the commonly used ${REF} format: ${section/option} (or with multi option: ${section/option[index]})

    [ini4j] contains class Options which is a better Properties replacement. Options use .properties file format, but allow macro/variable substitution, mult value properties. Unlike original java.util.Properties, Options implements Map<String,String>, so it more confortable to use standard Collections api. --> Options Tutorial

    Yes, it is possible now to read/write registry from java programs without native (JNI) code ! [ini4j] is able to read and write registry keys. And almost all .ini features (expression handling, multi value, bean interface, etc) works with windows registry. --> Windows Registry Tutorial

    On windows systems .REG file is common for registry import/export. It has similar but bit different syntax than old .ini format. [ini4j] fully support .REG file format. --> Reg Tutorial

    ini4j-0.5.2-SNAPSHOT/src/site/xdoc/search.xml000066400000000000000000000037751151645323700204720ustar00rootroot00000000000000 Search
    ini4j-0.5.2-SNAPSHOT/src/test/000077500000000000000000000000001151645323700155455ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/java/000077500000000000000000000000001151645323700164665ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/java/org/000077500000000000000000000000001151645323700172555ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/000077500000000000000000000000001151645323700202725ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/BasicMultiMapTest.java000066400000000000000000000135731151645323700245000ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class BasicMultiMapTest extends Ini4jCase { private static final String KEY1 = "key1"; private static final String KEY2 = "key2"; private static final String KEY3 = "key3"; private static final String VALUE1 = "value1"; private static final String VALUE2 = "value2"; private static final String VALUE3 = "value3"; private static final String[] VALUES = { VALUE1, VALUE2, VALUE3 }; private MultiMap _map; @Before @Override public void setUp() throws Exception { super.setUp(); _map = new BasicMultiMap(); } @Test public void testAdd() { _map.add(KEY1, VALUE1); _map.add(KEY1, VALUE2); _map.add(KEY1, VALUE3); assertEquals(3, _map.length(KEY1)); _map.add(KEY1, VALUE3, 0); assertEquals(4, _map.length(KEY1)); assertEquals(VALUE3, _map.get(KEY1, 0)); assertEquals(VALUE3, _map.get(KEY1, 3)); _map.clear(); assertTrue(_map.isEmpty()); } @Test public void testAll() { _map.putAll(KEY1, Arrays.asList(VALUES)); assertEquals(VALUES.length, _map.length(KEY1)); String[] values = _map.getAll(KEY1).toArray(new String[] {}); assertArrayEquals(VALUES, values); } @Test public void testContainsValue() { _map.putAll(KEY1, Arrays.asList(VALUES)); assertTrue(_map.containsValue(VALUE1)); assertTrue(_map.containsValue(VALUE2)); assertTrue(_map.containsValue(VALUE3)); _map.clear(); _map.put(KEY2, VALUE1); assertFalse(_map.containsValue(VALUE3)); } @Test public void testEntrySet() { _map.putAll(KEY1, Arrays.asList(VALUES)); _map.put(KEY2, VALUE2); _map.put(KEY3, VALUE3); Set> set = _map.entrySet(); assertNotNull(set); assertEquals(3, set.size()); for (Entry e : set) { if (e.getKey().equals(KEY1)) { assertEquals(VALUES[2], e.getValue()); e.setValue(VALUES[1]); } else if (e.getKey().equals(KEY2)) { assertEquals(VALUE2, e.getValue()); e.setValue(VALUE3); } else if (e.getKey().equals(KEY3)) { assertEquals(VALUE3, e.getValue()); e.setValue(VALUE2); } } assertEquals(VALUES[1], _map.get(KEY1)); assertEquals(VALUES.length, _map.length(KEY1)); assertEquals(VALUE3, _map.get(KEY2)); assertEquals(VALUE2, _map.get(KEY3)); } @Test public void testGetEmpty() { assertNull(_map.get(KEY1)); assertNull(_map.get(KEY1, 1)); } @Test public void testPut() { _map.put(KEY1, VALUE1); _map.add(KEY1, VALUE2); assertEquals(VALUE2, _map.get(KEY1, 1)); _map.put(KEY1, VALUE3, 1); assertEquals(VALUE3, _map.get(KEY1, 1)); assertEquals(VALUE3, _map.get(KEY1)); } @Test public void testPutAll() { _map.put(KEY1, VALUE1); _map.put(KEY2, VALUE1); _map.add(KEY2, VALUE2); MultiMap other = new BasicMultiMap(); other.putAll(_map); assertEquals(2, other.size()); assertEquals(2, other.length(KEY2)); assertEquals(1, other.length(KEY1)); assertEquals(VALUE1, _map.get(KEY1)); assertEquals(VALUE1, _map.get(KEY2, 0)); assertEquals(VALUE2, _map.get(KEY2, 1)); Map regular = new HashMap(_map); _map.clear(); _map.putAll(regular); assertEquals(regular.keySet(), _map.keySet()); } @Test public void testRemove() { _map.add(KEY1, VALUE1); _map.add(KEY2, VALUE1); _map.add(KEY2, VALUE2); _map.add(KEY3, VALUE1); _map.add(KEY3, VALUE2); _map.add(KEY3, VALUE3); assertEquals(VALUE2, _map.get(KEY3, 1)); _map.remove(KEY3, 1); assertEquals(VALUE3, _map.get(KEY3, 1)); _map.remove(KEY3, 1); assertEquals(VALUE1, _map.get(KEY3)); _map.remove(KEY3, 0); assertEquals(0, _map.length(KEY3)); assertFalse(_map.containsKey(KEY3)); _map.remove(KEY2); assertFalse(_map.containsKey(KEY2)); _map.remove(KEY1); assertFalse(_map.containsKey(KEY1)); assertEquals(0, _map.size()); assertTrue(_map.isEmpty()); assertNull(_map.remove(KEY1)); assertNull(_map.remove(KEY1, 1)); } @Test public void testValues() { _map.put(KEY1, VALUE1); _map.put(KEY2, VALUE2); _map.add(KEY2, VALUE3); String[] values = _map.values().toArray(new String[] {}); Arrays.sort(values); assertArrayEquals(values, VALUES); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/BasicOptionMapGate.java000066400000000000000000000017521151645323700246130ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.BeanAccess; public class BasicOptionMapGate extends BasicOptionMap { private static final long serialVersionUID = -479440334238558045L; @Override public BeanAccess newBeanAccess() { return super.newBeanAccess(); } @Override public BeanAccess newBeanAccess(String prefix) { return super.newBeanAccess(prefix); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/BasicOptionMapTest.java000066400000000000000000000253301151645323700246500ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.sample.Dwarf; import org.ini4j.sample.DwarfBean; import org.ini4j.test.DwarfsData; import org.ini4j.test.DwarfsData.DwarfData; import org.ini4j.test.Helper; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Test; import java.net.URI; public class BasicOptionMapTest extends Ini4jCase { private static BasicOptionMap _map; static { _map = new BasicOptionMap(); _map.putAll(Helper.newDwarfsOpt()); } @Test public void testAddPutNullAndString() { OptionMap map = new BasicOptionMap(); Object o; // null o = null; map.add(Dwarf.PROP_AGE, o); assertNull(map.get(Dwarf.PROP_AGE)); map.put(Dwarf.PROP_AGE, new Integer(DwarfsData.doc.age)); assertNotNull(map.get(Dwarf.PROP_AGE)); map.add(Dwarf.PROP_AGE, o, 0); assertNull(map.get(Dwarf.PROP_AGE, 0)); map.put(Dwarf.PROP_AGE, new Integer(DwarfsData.doc.age), 0); assertNotNull(map.get(Dwarf.PROP_AGE, 0)); map.put(Dwarf.PROP_AGE, o, 0); assertNull(map.get(Dwarf.PROP_AGE, 0)); map.remove(Dwarf.PROP_AGE); map.put(Dwarf.PROP_AGE, o); assertNull(map.get(Dwarf.PROP_AGE)); // str map.remove(Dwarf.PROP_AGE); o = String.valueOf(DwarfsData.doc.age); map.add(Dwarf.PROP_AGE, o); assertEquals(o, map.get(Dwarf.PROP_AGE)); map.remove(Dwarf.PROP_AGE); map.put(Dwarf.PROP_AGE, o); assertEquals(o, map.get(Dwarf.PROP_AGE)); o = String.valueOf(DwarfsData.happy.age); map.add(Dwarf.PROP_AGE, o, 0); assertEquals(new Integer(DwarfsData.happy.age), (Integer) map.get(Dwarf.PROP_AGE, 0, int.class)); o = String.valueOf(DwarfsData.doc.age); map.put(Dwarf.PROP_AGE, o, 0); assertEquals(DwarfsData.doc.age, (int) map.get(Dwarf.PROP_AGE, 0, int.class)); } @Test public void testFetch() { OptionMap map = new BasicOptionMap(); Helper.addDwarf(map, DwarfsData.dopey, false); Helper.addDwarf(map, DwarfsData.bashful); Helper.addDwarf(map, DwarfsData.doc); // dopey assertEquals(DwarfsData.dopey.weight, map.fetch(Dwarf.PROP_WEIGHT, double.class), Helper.DELTA); map.add(Dwarf.PROP_HEIGHT, map.get(Dwarf.PROP_HEIGHT)); assertEquals(DwarfsData.dopey.height, map.fetch(Dwarf.PROP_HEIGHT, 1, double.class), Helper.DELTA); // sneezy map.clear(); Helper.addDwarf(map, DwarfsData.happy); Helper.addDwarf(map, DwarfsData.sneezy, false); assertEquals(DwarfsData.sneezy.homePage, map.fetch(Dwarf.PROP_HOME_PAGE, URI.class)); // null map = new BasicOptionMap(); map.add(Dwarf.PROP_AGE, null); assertNull(map.fetch(Dwarf.PROP_AGE, 0)); } @Test public void testFetchAllException() { OptionMap map = new BasicOptionMap(); try { map.fetchAll(Dwarf.PROP_FORTUNE_NUMBER, String.class); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @Test public void testFromToAs() throws Exception { DwarfBean bean = new DwarfBean(); _map.to(bean); Helper.assertEquals(DwarfsData.dopey, bean); OptionMap map = new BasicOptionMap(); map.from(bean); bean = new DwarfBean(); map.to(bean); Helper.assertEquals(DwarfsData.dopey, bean); Dwarf proxy = map.as(Dwarf.class); Helper.assertEquals(DwarfsData.dopey, proxy); map.clear(); _map.to(proxy); Helper.assertEquals(DwarfsData.dopey, proxy); } @Test public void testFromToAsPrefixed() throws Exception { fromToAs(DwarfsData.bashful); fromToAs(DwarfsData.doc); fromToAs(DwarfsData.dopey); fromToAs(DwarfsData.grumpy); fromToAs(DwarfsData.happy); fromToAs(DwarfsData.sleepy); fromToAs(DwarfsData.sneezy); } @Test public void testGet() { OptionMap map = new BasicOptionMap(); // bashful Helper.addDwarf(map, DwarfsData.bashful, false); assertEquals(DwarfsData.bashful.weight, map.get(Dwarf.PROP_WEIGHT, double.class), Helper.DELTA); map.add(Dwarf.PROP_HEIGHT, map.get(Dwarf.PROP_HEIGHT)); assertEquals(DwarfsData.bashful.height, map.get(Dwarf.PROP_HEIGHT, 1, double.class), Helper.DELTA); assertEquals(DwarfsData.bashful.homePage, map.fetch(Dwarf.PROP_HOME_PAGE, URI.class)); } @Test public void testGetAllException() { OptionMap map = new BasicOptionMap(); try { map.getAll(Dwarf.PROP_FORTUNE_NUMBER, String.class); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @Test public void testPropertyFirstUpper() { DwarfBean bean; OptionMap map = new BasicOptionMap(true); map.from(DwarfsData.bashful); assertTrue(map.containsKey("Age")); assertTrue(map.containsKey("Height")); assertTrue(map.containsKey("Weight")); assertTrue(map.containsKey("HomePage")); assertTrue(map.containsKey("HomeDir")); bean = new DwarfBean(); map.to(bean); Helper.assertEquals(DwarfsData.bashful, bean); Helper.assertEquals(DwarfsData.bashful, map.as(Dwarf.class)); } @Test public void testPut() { OptionMap map = new BasicOptionMap(); map.add(Dwarf.PROP_AGE, new Integer(DwarfsData.sneezy.age)); map.put(Dwarf.PROP_HEIGHT, new Double(DwarfsData.sneezy.height)); map.add(Dwarf.PROP_HOME_DIR, DwarfsData.sneezy.homeDir); map.add(Dwarf.PROP_WEIGHT, new Double(DwarfsData.sneezy.weight), 0); map.put(Dwarf.PROP_HOME_PAGE, null); map.put(Dwarf.PROP_HOME_PAGE, DwarfsData.sneezy.homePage); map.add(Dwarf.PROP_FORTUNE_NUMBER, new Integer(DwarfsData.sneezy.fortuneNumber[1])); map.add(Dwarf.PROP_FORTUNE_NUMBER, new Integer(DwarfsData.sneezy.fortuneNumber[2])); map.add(Dwarf.PROP_FORTUNE_NUMBER, new Integer(0)); map.put(Dwarf.PROP_FORTUNE_NUMBER, new Integer(DwarfsData.sneezy.fortuneNumber[3]), 2); map.add(Dwarf.PROP_FORTUNE_NUMBER, new Integer(DwarfsData.sneezy.fortuneNumber[0]), 0); Helper.assertEquals(DwarfsData.sneezy, map.as(Dwarf.class)); } @Test public void testPutAllException() { OptionMap map = new BasicOptionMap(); try { map.putAll(Dwarf.PROP_FORTUNE_NUMBER, new Integer(0)); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @Test public void testPutGetFetchAll() { OptionMap map = new BasicOptionMap(); map.putAll(Dwarf.PROP_FORTUNE_NUMBER, DwarfsData.sneezy.fortuneNumber); assertEquals(DwarfsData.sneezy.fortuneNumber.length, map.length(Dwarf.PROP_FORTUNE_NUMBER)); assertArrayEquals(DwarfsData.sneezy.fortuneNumber, map.getAll(Dwarf.PROP_FORTUNE_NUMBER, int[].class)); assertArrayEquals(DwarfsData.sneezy.fortuneNumber, map.fetchAll(Dwarf.PROP_FORTUNE_NUMBER, int[].class)); map.putAll(Dwarf.PROP_FORTUNE_NUMBER, (int[]) null); assertEquals(0, map.length(Dwarf.PROP_FORTUNE_NUMBER)); assertEquals(0, map.getAll(Dwarf.PROP_FORTUNE_NUMBER, int[].class).length); assertEquals(0, map.fetchAll(Dwarf.PROP_FORTUNE_NUMBER, int[].class).length); } @Test public void testResolve() throws Exception { StringBuilder buffer; String input; // simple value input = "${height}"; buffer = new StringBuilder(input); _map.resolve(buffer); assertEquals("" + DwarfsData.dopey.getHeight(), buffer.toString()); // system property input = "${@prop/user.home}"; buffer = new StringBuilder(input); _map.resolve(buffer); assertEquals(System.getProperty("user.home"), buffer.toString()); // system environment input = "${@env/PATH}"; buffer = new StringBuilder(input); try { _map.resolve(buffer); assertEquals(System.getenv("PATH"), buffer.toString()); } catch (Error e) { // retroweaver + JDK 1.4 throws Error on getenv } // unknown variable input = "${no such name}"; buffer = new StringBuilder(input); _map.resolve(buffer); assertEquals(input, buffer.toString()); // small input input = "${"; buffer = new StringBuilder(input); _map.resolve(buffer); assertEquals(input, buffer.toString()); // incorrect references input = "${weight"; buffer = new StringBuilder(input); _map.resolve(buffer); assertEquals(input, buffer.toString()); // empty references input = "jim${}"; buffer = new StringBuilder(input); _map.resolve(buffer); assertEquals(input, buffer.toString()); // escaped references input = "${weight}"; buffer = new StringBuilder(input); _map.resolve(buffer); assertEquals("" + DwarfsData.dopey.getWeight(), buffer.toString()); input = "\\" + input; buffer = new StringBuilder(input); assertEquals(input, buffer.toString()); } private void fromToAs(DwarfData dwarf) { String prefix = dwarf.name + '.'; DwarfBean bean = new DwarfBean(); _map.to(bean, prefix); Helper.assertEquals(dwarf, bean); OptionMap map = new BasicOptionMap(); map.from(bean, prefix); bean = new DwarfBean(); map.to(bean, prefix); Helper.assertEquals(dwarf, bean); Dwarf proxy = map.as(Dwarf.class, prefix); Helper.assertEquals(dwarf, proxy); map.clear(); _map.to(proxy, prefix); Helper.assertEquals(dwarf, proxy); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/BasicProfileSectionTest.java000066400000000000000000000103371151645323700256700ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import org.ini4j.test.TaleData; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import org.junit.Test; public class BasicProfileSectionTest extends Ini4jCase { @Test public void testAddChild() throws Exception { Profile prof = Helper.newTaleIni(); Profile.Section dwarfs = prof.get(TaleData.PROP_DWARFS); Profile.Section doc = dwarfs.getChild(Dwarfs.PROP_DOC); Profile.Section dopey2 = doc.addChild(Dwarfs.PROP_DOPEY); assertSame(doc, dopey2.getParent()); assertSame(dopey2, dwarfs.lookup(Dwarfs.PROP_DOC, Dwarfs.PROP_DOPEY)); assertSame(dopey2, dwarfs.lookup(Dwarfs.PROP_DOC + '/' + Dwarfs.PROP_DOPEY)); assertEquals(1, doc.childrenNames().length); doc.removeChild(Dwarfs.PROP_DOPEY); assertEquals(0, doc.childrenNames().length); assertNull(dwarfs.lookup(Dwarfs.PROP_DOC, Dwarfs.PROP_DOPEY)); assertNull(dwarfs.lookup(Dwarfs.PROP_DOC + '/' + Dwarfs.PROP_DOPEY)); } @Test public void testGetChild() throws Exception { Profile prof = Helper.newTaleIni(); Profile.Section dwarfs = prof.get(TaleData.PROP_DWARFS); assertArrayEquals(DwarfsData.dwarfNames, dwarfs.childrenNames()); assertSame(prof.get(TaleData.bashful.name), dwarfs.getChild(Dwarfs.PROP_BASHFUL)); assertSame(prof.get(TaleData.doc.name), dwarfs.getChild(Dwarfs.PROP_DOC)); assertSame(prof.get(TaleData.dopey.name), dwarfs.getChild(Dwarfs.PROP_DOPEY)); assertSame(prof.get(TaleData.grumpy.name), dwarfs.getChild(Dwarfs.PROP_GRUMPY)); assertSame(prof.get(TaleData.happy.name), dwarfs.getChild(Dwarfs.PROP_HAPPY)); assertSame(prof.get(TaleData.sleepy.name), dwarfs.getChild(Dwarfs.PROP_SLEEPY)); assertSame(prof.get(TaleData.sneezy.name), dwarfs.getChild(Dwarfs.PROP_SNEEZY)); } @Test public void testGetParent() throws Exception { Profile prof = Helper.newTaleIni(); Profile.Section dwarfs = prof.get(TaleData.PROP_DWARFS); assertNull(dwarfs.getParent()); assertSame(dwarfs, prof.get(TaleData.bashful.name).getParent()); assertSame(dwarfs, prof.get(TaleData.doc.name).getParent()); assertSame(dwarfs, prof.get(TaleData.dopey.name).getParent()); assertSame(dwarfs, prof.get(TaleData.grumpy.name).getParent()); assertSame(dwarfs, prof.get(TaleData.happy.name).getParent()); assertSame(dwarfs, prof.get(TaleData.sleepy.name).getParent()); assertSame(dwarfs, prof.get(TaleData.sneezy.name).getParent()); } @Test public void testLoad() throws Exception { Profile prof = Helper.loadTaleIni(); Profile.Section dwarfs = prof.get(TaleData.PROP_DWARFS); Helper.assertEquals(DwarfsData.bashful, dwarfs.getChild(Dwarfs.PROP_BASHFUL).as(Dwarf.class)); Helper.assertEquals(DwarfsData.doc, dwarfs.getChild(Dwarfs.PROP_DOC).as(Dwarf.class)); Helper.assertEquals(DwarfsData.dopey, dwarfs.getChild(Dwarfs.PROP_DOPEY).as(Dwarf.class)); Helper.assertEquals(DwarfsData.grumpy, dwarfs.getChild(Dwarfs.PROP_GRUMPY).as(Dwarf.class)); Helper.assertEquals(DwarfsData.happy, dwarfs.getChild(Dwarfs.PROP_HAPPY).as(Dwarf.class)); Helper.assertEquals(DwarfsData.sleepy, dwarfs.getChild(Dwarfs.PROP_SLEEPY).as(Dwarf.class)); Helper.assertEquals(DwarfsData.sneezy, dwarfs.getChild(Dwarfs.PROP_SNEEZY).as(Dwarf.class)); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/BasicProfileTest.java000066400000000000000000000353501151645323700243450ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.sample.Dwarf; import org.ini4j.sample.DwarfBean; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.DwarfsData.DwarfData; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Test; import java.net.URI; public class BasicProfileTest extends Ini4jCase { private static final String SECTION = "section"; private static final String NUMBER = "number"; private static final String SINGLE = "single"; private static final String SOLO = "solo"; private static final String LOCATION = "location"; private static final String LOCATION_1 = "http://www.ini4j.org"; private static final String LOCATION_2 = "http://ini4j.org"; /* * thanx to Gary Pampara for bug report */ @Test public void bug_2817403() throws Exception { BasicProfile prof = new BasicProfile(); Profile.Section sec = prof.add("section"); sec.add("player.name", "Joe"); sec.add("player.greeting", "Hi ${player.name}!"); sec.add("player.domain", "foo.bar"); sec.add("player.email", "${player.name}@${player.domain}"); // assertEquals("Joe", sec.fetch("player.name")); assertEquals("Hi Joe!", sec.fetch("player.greeting")); assertEquals("foo.bar", sec.fetch("player.domain")); assertEquals("Joe@foo.bar", sec.fetch("player.email")); // sec = prof.add("other"); sec.add("option", "${section/player.name}"); assertEquals("Joe", sec.fetch("option")); sec.put("option", "${section/player.email}"); assertEquals("Joe@foo.bar", sec.fetch("option")); sec.put("option2", "${option} ${section/player.name} ${section/player.domain}"); assertEquals("Joe@foo.bar Joe foo.bar", sec.fetch("option2")); } @Test public void testAddPut() { Profile prof = new BasicProfile(); prof.add(SECTION, Dwarf.PROP_AGE, DwarfsData.sneezy.age); prof.put(SECTION, Dwarf.PROP_HEIGHT, DwarfsData.sneezy.height); prof.add(SECTION, Dwarf.PROP_HOME_DIR, DwarfsData.sneezy.homeDir); prof.add(SECTION, Dwarf.PROP_WEIGHT, DwarfsData.sneezy.weight); prof.put(SECTION, Dwarf.PROP_HOME_PAGE, null); prof.put(SECTION, Dwarf.PROP_HOME_PAGE, DwarfsData.sneezy.homePage); prof.add(SECTION, Dwarf.PROP_FORTUNE_NUMBER, DwarfsData.sneezy.fortuneNumber[0]); prof.add(SECTION, Dwarf.PROP_FORTUNE_NUMBER, DwarfsData.sneezy.fortuneNumber[1]); prof.add(SECTION, Dwarf.PROP_FORTUNE_NUMBER, DwarfsData.sneezy.fortuneNumber[2]); prof.add(SECTION, Dwarf.PROP_FORTUNE_NUMBER, DwarfsData.sneezy.fortuneNumber[3]); Helper.assertEquals(DwarfsData.sneezy, prof.get(SECTION).as(Dwarf.class)); assertNotNull(prof.remove(SECTION, Dwarf.PROP_FORTUNE_NUMBER)); assertEquals(0, prof.get(SECTION).length(Dwarf.PROP_FORTUNE_NUMBER)); assertNotNull(prof.remove(SECTION)); assertNull(prof.remove(SECTION, Dwarf.PROP_FORTUNE_NUMBER)); } @Test public void testFirstUpper() { BasicProfile prof = new BasicProfile(true, true); DwarfsRW dwarfs = prof.as(DwarfsRW.class); dwarfs.setBashful(DwarfsData.bashful); assertTrue(prof.containsKey("Bashful")); assertNotNull(dwarfs.getBashful()); } @Test public void testFromToAs() throws Exception { BasicProfile prof = new BasicProfile(); Helper.addDwarfs(prof); fromToAs(prof, DwarfsData.bashful); fromToAs(prof, DwarfsData.doc); fromToAs(prof, DwarfsData.dopey); fromToAs(prof, DwarfsData.grumpy); fromToAs(prof, DwarfsData.happy); fromToAs(prof, DwarfsData.sleepy); fromToAs(prof, DwarfsData.sneezy); // DwarfsRW dwarfs = prof.as(DwarfsRW.class); Helper.assertEquals(DwarfsData.bashful, dwarfs.getBashful()); Helper.assertEquals(DwarfsData.doc, dwarfs.getDoc()); Helper.assertEquals(DwarfsData.dopey, dwarfs.getDopey()); Helper.assertEquals(DwarfsData.grumpy, dwarfs.getGrumpy()); Helper.assertEquals(DwarfsData.happy, dwarfs.getHappy()); Helper.assertEquals(DwarfsData.sleepy, dwarfs.getSleepy()); Helper.assertEquals(DwarfsData.sneezy, dwarfs.getSneezy()); // prof.remove(Dwarfs.PROP_BASHFUL); assertNull(prof.get(Dwarfs.PROP_BASHFUL)); assertEquals(0, prof.length(Dwarfs.PROP_BASHFUL)); assertNull(dwarfs.getBashful()); dwarfs.setBashful(DwarfsData.dopey); Helper.assertEquals(DwarfsData.dopey, dwarfs.getBashful()); } @Test public void testIniGetFetch() { Profile prof = new BasicProfile(); Profile.Section sec = Helper.addDwarf(prof, DwarfsData.dopey); Helper.addDwarf(prof, DwarfsData.bashful); Helper.addDwarf(prof, DwarfsData.doc); assertEquals(sec.get(Dwarf.PROP_AGE), prof.get(Dwarfs.PROP_DOPEY, Dwarf.PROP_AGE)); assertEquals(DwarfsData.dopey.age, (int) prof.get(Dwarfs.PROP_DOPEY, Dwarf.PROP_AGE, int.class)); assertEquals(sec.get(Dwarf.PROP_WEIGHT), prof.get(Dwarfs.PROP_DOPEY, Dwarf.PROP_WEIGHT)); assertEquals(DwarfsData.dopey.weight, prof.fetch(Dwarfs.PROP_DOPEY, Dwarf.PROP_WEIGHT, double.class), Helper.DELTA); assertEquals(sec.fetch(Dwarf.PROP_HEIGHT), prof.fetch(Dwarfs.PROP_DOPEY, Dwarf.PROP_HEIGHT)); assertEquals(DwarfsData.dopey.weight, prof.fetch(Dwarfs.PROP_DOPEY, Dwarf.PROP_WEIGHT, double.class), Helper.DELTA); assertEquals(sec.fetch(Dwarf.PROP_HOME_PAGE), prof.fetch(Dwarfs.PROP_DOPEY, Dwarf.PROP_HOME_PAGE)); assertEquals(DwarfsData.dopey.homePage, prof.fetch(Dwarfs.PROP_DOPEY, Dwarf.PROP_HOME_PAGE, URI.class)); // nulls assertNull(prof.get(SECTION, Dwarf.PROP_AGE)); assertEquals(0, (int) prof.get(SECTION, Dwarf.PROP_AGE, int.class)); assertNull(prof.get(SECTION, Dwarf.PROP_WEIGHT)); assertEquals(0.0, prof.fetch(SECTION, Dwarf.PROP_WEIGHT, double.class), Helper.DELTA); assertNull(prof.fetch(SECTION, Dwarf.PROP_HEIGHT)); assertEquals(0.0, prof.fetch(SECTION, Dwarf.PROP_WEIGHT, double.class), Helper.DELTA); assertNull(prof.fetch(SECTION, Dwarf.PROP_HOME_PAGE)); assertNull(prof.fetch(SECTION, Dwarf.PROP_HOME_PAGE, URI.class)); } @Test public void testOptionArray() throws Exception { BasicProfile prof = new BasicProfile(); Profile.Section sec = prof.add(SECTION); sec.add(NUMBER, 1); sec.add(LOCATION, LOCATION_1); sec.add(NUMBER, 2); sec.add(LOCATION, LOCATION_2); Section s = prof.get(SECTION).as(Section.class); assertNotNull(s); assertEquals(2, s.getNumber().length); assertEquals(1, s.getNumber()[0]); assertEquals(2, s.getNumber()[1]); assertEquals(2, s.getLocation().length); assertEquals(new URI(LOCATION_1), s.getLocation()[0]); assertNull(s.getMissing()); int[] numbers = new int[] { 1, 2, 3, 4, 5 }; s.setNumber(numbers); assertEquals(5, sec.length(NUMBER)); } @Test public void testResolve() throws Exception { BasicProfile prof = new BasicProfile(); Helper.addDwarf(prof, DwarfsData.happy); Profile.Section doc = Helper.addDwarf(prof, DwarfsData.doc); StringBuilder buffer; String input; // other sections's value input = "${happy/weight}"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(String.valueOf(DwarfsData.happy.weight), buffer.toString()); // same sections's value input = "${height}"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(String.valueOf(DwarfsData.doc.height), buffer.toString()); // system property input = "${@prop/user.home}"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(System.getProperty("user.home"), buffer.toString()); // system environment input = "${@env/PATH}"; buffer = new StringBuilder(input); try { prof.resolve(buffer, doc); assertEquals(System.getenv("PATH"), buffer.toString()); } catch (Error e) { // retroweaver + JDK 1.4 throws Error on getenv } // unknown variable input = "${no such name}"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(input, buffer.toString()); // unknown section's unknown variable input = "${no such section/no such name}"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(input, buffer.toString()); // other section's unknown variable input = "${happy/no such name}"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(input, buffer.toString()); // small input input = "${"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(input, buffer.toString()); // incorrect references input = "${doc/weight"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(input, buffer.toString()); // empty references input = "jim${}"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(input, buffer.toString()); // escaped references input = "${happy/weight}"; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals("" + DwarfsData.happy.weight, buffer.toString()); input = "\\" + input; buffer = new StringBuilder(input); prof.resolve(buffer, doc); assertEquals(input, buffer.toString()); } @Test public void testResolveArray() throws Exception { StringBuilder buffer; BasicProfile prof = new BasicProfile(); prof.add(SECTION).add(NUMBER, 1); prof.add(SECTION).add(NUMBER, 2); Profile.Section sec = prof.get(SECTION); // buffer = new StringBuilder("${section[0]/number}"); prof.resolve(buffer, sec); assertEquals("1", buffer.toString()); buffer = new StringBuilder("${section[1]/number}"); prof.resolve(buffer, sec); assertEquals("2", buffer.toString()); buffer = new StringBuilder("${section[0]/number}-${section[1]/number}"); prof.resolve(buffer, sec); assertEquals("1-2", buffer.toString()); // prof.clear(); sec = prof.add(SECTION); sec.add(NUMBER, 1); sec.add(NUMBER, 2); sec = prof.get(SECTION); assertEquals(2, sec.length(NUMBER)); buffer = new StringBuilder("${number}"); prof.resolve(buffer, sec); assertEquals("2", buffer.toString()); buffer = new StringBuilder("${number[0]}-${section/number[1]}-${section[0]/number}"); prof.resolve(buffer, sec); assertEquals("1-2-2", buffer.toString()); } @Test public void testSectionArray() throws Exception { BasicProfile prof = new BasicProfile(); prof.add(SECTION).add(NUMBER, 1); prof.add(SECTION).add(NUMBER, 2); prof.add(SINGLE).add(NUMBER, 3); Global g = prof.as(Global.class); assertNotNull(g); assertEquals(2, g.getSection().length); assertEquals(1, g.getSingle().length); assertNull(g.getMissing()); assertTrue(g.hasSection()); } @Test public void testSetter() { BasicProfile prof = new BasicProfile(); Global g = prof.as(Global.class); Section s1 = new SectionBean(); Section s2 = new SectionBean(); Section[] all = new Section[] { s1, s2 }; g.setSection(all); assertEquals(2, prof.length("section")); assertNull(g.getSolo()); g.setSolo(s1); assertNotNull(g.getSolo()); g.setSolo(null); assertEquals(0, prof.length("solo")); } private void fromToAs(BasicProfile prof, DwarfData dwarf) { Profile.Section sec = prof.get(dwarf.name); Profile.Section dup = new BasicProfileSection(prof, SECTION); DwarfBean bean = new DwarfBean(); sec.to(bean); Helper.assertEquals(dwarf, bean); dup.from(bean); bean = new DwarfBean(); dup.to(bean); Helper.assertEquals(dwarf, bean); Dwarf proxy = dup.as(Dwarf.class); Helper.assertEquals(dwarf, proxy); dup.clear(); sec.to(proxy); Helper.assertEquals(dwarf, proxy); prof.remove(dup); } public static interface DwarfsRW extends Dwarfs { void setBashful(Dwarf value); } public static interface Global { Section[] getMissing(); Section[] getSection(); void setSection(Section[] value); Section[] getSingle(); Section getSolo(); void setSolo(Section value); boolean hasSection(); } public static interface Section { URI[] getLocation(); void setLocation(URI[] value); String[] getMissing(); void setMissing(String[] value); int[] getNumber(); void setNumber(int[] value); } public static class SectionBean implements Section { private URI[] _location; private String[] _missing; private int[] _number; @Override public URI[] getLocation() { return _location; } @Override public void setLocation(URI[] value) { _location = value; } @Override public String[] getMissing() { return _missing; } @Override public void setMissing(String[] value) { _missing = value; } @Override public int[] getNumber() { return _number; } @Override public void setNumber(int[] value) { _number = value; } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/BasicRegistryKeyTest.java000066400000000000000000000033551151645323700252260ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.Registry.Type; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import org.junit.Test; public class BasicRegistryKeyTest extends Ini4jCase { private static final String KEY = "key"; private static final String DUMMY = "dummy"; private static final String OPTION = "option"; @Test public void testWrapped() throws Exception { BasicRegistry reg = new BasicRegistry(); Registry.Key parent = reg.add(KEY); Registry.Key child = parent.addChild(DUMMY); assertSame(parent, child.getParent()); assertSame(child, parent.getChild(DUMMY)); Registry.Key kid = child.addChild(KEY); assertSame(kid, parent.lookup(DUMMY, KEY)); parent.put(OPTION, DUMMY); parent.putType(OPTION, Type.REG_BINARY); assertEquals(Type.REG_BINARY, parent.getType(OPTION)); parent.removeType(OPTION); assertNull(parent.getType(OPTION)); parent.putType(OPTION, Type.REG_BINARY); parent.remove(OPTION); assertNull(parent.getType(OPTION)); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/BasicRegistryTest.java000066400000000000000000000036651151645323700245610ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import org.junit.Test; public class BasicRegistryTest extends Ini4jCase { private static final String KEY = "key"; private static final String DUMMY = "dummy"; private static final String VERSION = "Windows Registry Editor Version 5.00"; @Test public void testVersion() { BasicRegistry reg = new BasicRegistry(); assertEquals(VERSION, reg.getVersion()); reg.setVersion(DUMMY); assertEquals(DUMMY, reg.getVersion()); } @Test public void testWrapped() throws Exception { BasicRegistry reg = new BasicRegistry(); Registry.Key key1 = reg.add(KEY); Registry.Key key2 = reg.add(KEY); assertNotNull(key1); assertNotNull(key2); assertTrue(reg.get(KEY) instanceof Registry.Key); assertTrue(reg.get(KEY, 1) instanceof Registry.Key); Registry.Key key3 = new BasicRegistryKey(reg, KEY); assertSame(key1, reg.put(KEY, key3, 0)); assertSame(key2, reg.put(KEY, key3)); assertSame(key3, reg.remove(KEY, 1)); assertSame(key3, reg.remove(KEY)); key1 = reg.add(KEY); assertSame(key1, reg.remove(key1)); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/CommonMultiMapTest.java000066400000000000000000000063071151645323700247040ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Test; import java.util.HashMap; import java.util.Map; public class CommonMultiMapTest extends Ini4jCase { private static final String KEY = "key"; private static final String VALUE = "value"; private static final String COMMENT = "comment"; @Test public void testClearAndRemove() throws Exception { CommonMultiMap map = new CommonMultiMap(); assertNull(map.removeComment(KEY)); // map.put(KEY, VALUE); map.clear(); assertTrue(map.isEmpty()); // map.put(KEY, VALUE); map.remove(KEY); assertNull(map.getComment(KEY)); // map.put(KEY, VALUE); map.remove(KEY, 0); assertNull(map.getComment(KEY)); // map.add(KEY, VALUE); map.add(KEY, VALUE); map.putComment(KEY, COMMENT); map.remove(KEY, 0); assertEquals(COMMENT, map.getComment(KEY)); // map.put(KEY, VALUE); map.putComment(KEY, COMMENT); assertEquals(COMMENT, map.getComment(KEY)); map.clear(); assertNull(map.getComment(KEY)); // map.put(KEY, VALUE); map.putComment(KEY, COMMENT); map.remove(KEY); assertNull(map.getComment(KEY)); // map.put(KEY, VALUE); map.putComment(KEY, COMMENT); assertEquals(COMMENT, map.removeComment(KEY)); assertNull(map.getComment(KEY)); // map.put(KEY, VALUE); map.putComment(KEY, COMMENT); map.remove(KEY, 0); assertNull(map.getComment(KEY)); } @Test public void testPutAll() throws Exception { CommonMultiMap map = new CommonMultiMap(); CommonMultiMap copy = new CommonMultiMap(); map.put(KEY, VALUE); map.putComment(KEY, COMMENT); copy.putAll(map); assertEquals(COMMENT, copy.getComment(KEY)); Map simple = new HashMap(); simple.put(KEY, VALUE); copy.clear(); assertTrue(copy.isEmpty()); copy.putAll(simple); assertNull(copy.getComment(KEY)); assertEquals(VALUE, copy.get(KEY)); // map = new CommonMultiMap(); map.put(KEY, VALUE); copy.clear(); copy.putAll(map); assertEquals(VALUE, copy.get(KEY)); assertNull(copy.getComment(KEY)); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/ConfigParserTest.java000066400000000000000000000354021151645323700243630ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import org.junit.After; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Before; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.StringReader; import java.util.HashMap; import java.util.List; import java.util.Map; public class ConfigParserTest extends Ini4jCase { private static final String SECTION = "section"; private static final String OPTION = "option"; private static final String DWARFS_PATH = "org/ini4j/addon/dwarfs-py.ini"; private static final String BAD = "[bashful\nage=3"; private static final String TEST_DATA_PATH = "src/test/resources"; private static final String TEST_WORK_PATH = "target"; private static final String MISSING = "missing"; private static final String MISSING_REF = "%(missing)"; private static final String DUMMY = "dummy"; protected ConfigParser instance; @Before @Override public void setUp() throws Exception { super.setUp(); instance = new ConfigParser(); } @After @Override public void tearDown() { } @Test public void testAddHasRemove() throws Exception { assertFalse(instance.hasSection(SECTION)); assertFalse(instance.hasOption(SECTION, OPTION)); assertFalse(instance.getIni().containsKey(SECTION)); instance.addSection(SECTION); assertTrue(instance.hasSection(SECTION)); instance.set(SECTION, OPTION, "dummy"); assertTrue(instance.hasOption(SECTION, OPTION)); assertTrue(instance.getIni().get(SECTION).containsKey(OPTION)); instance.removeOption(SECTION, OPTION); assertFalse(instance.hasOption(SECTION, OPTION)); instance.removeSection(SECTION); assertFalse(instance.hasSection(SECTION)); } @Test public void testAddSectionDuplicate() throws Exception { instance.addSection(SECTION); try { instance.addSection(SECTION); missing(ConfigParser.DuplicateSectionException.class); } catch (ConfigParser.DuplicateSectionException x) { // } } @Test public void testAddSectionIllegal() throws Exception { try { instance.addSection(ConfigParser.PyIni.DEFAULT_SECTION_NAME); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @Test public void testDefaults() throws Exception { Map defs = new HashMap(); instance = new ConfigParser(defs); assertSame(defs, instance.defaults()); } @Test public void testDwarfs() throws Exception { readDwarfs(); checkEquals(DwarfsData.bashful, Dwarfs.PROP_BASHFUL); checkEquals(DwarfsData.doc, Dwarfs.PROP_DOC); checkEquals(DwarfsData.dopey, Dwarfs.PROP_DOPEY); checkEquals(DwarfsData.happy, Dwarfs.PROP_HAPPY); checkEquals(DwarfsData.grumpy, Dwarfs.PROP_GRUMPY); checkEquals(DwarfsData.sleepy, Dwarfs.PROP_SLEEPY); checkEquals(DwarfsData.sneezy, Dwarfs.PROP_SNEEZY); } @Test public void testGet() throws Exception { Ini.Section section = instance.getIni().add(SECTION); section.put(OPTION, "on"); assertTrue(instance.getBoolean(SECTION, OPTION)); section.put(OPTION, "1"); assertTrue(instance.getBoolean(SECTION, OPTION)); section.put(OPTION, "true"); assertTrue(instance.getBoolean(SECTION, OPTION)); section.put(OPTION, "yes"); assertTrue(instance.getBoolean(SECTION, OPTION)); section.put(OPTION, "TruE"); assertTrue(instance.getBoolean(SECTION, OPTION)); // section.put(OPTION, "off"); assertFalse(instance.getBoolean(SECTION, OPTION)); section.put(OPTION, "0"); assertFalse(instance.getBoolean(SECTION, OPTION)); section.put(OPTION, "no"); assertFalse(instance.getBoolean(SECTION, OPTION)); section.put(OPTION, "false"); assertFalse(instance.getBoolean(SECTION, OPTION)); section.put(OPTION, "FalsE"); assertFalse(instance.getBoolean(SECTION, OPTION)); // ints section.put(OPTION, "12"); assertEquals(12, instance.getInt(SECTION, OPTION)); assertEquals(12L, instance.getLong(SECTION, OPTION)); section.put(OPTION, "1.2"); assertEquals(1.2f, instance.getFloat(SECTION, OPTION), Helper.DELTA); assertEquals(1.2, instance.getDouble(SECTION, OPTION), Helper.DELTA); } @Test public void testGetBooleanException() throws Exception { Ini.Section section = instance.getIni().add(SECTION); section.put(OPTION, "joe"); try { instance.getBoolean(SECTION, OPTION); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @Test public void testGetMissinOptionException() throws Exception { instance.addSection(SECTION); instance.set(SECTION, OPTION, MISSING_REF); try { instance.get(SECTION, OPTION); missing(ConfigParser.InterpolationMissingOptionException.class); } catch (ConfigParser.InterpolationMissingOptionException x) { // } } @Test public void testGetNoOption() throws Exception { instance.getIni().add(SECTION); try { instance.get(SECTION, OPTION); missing(ConfigParser.NoOptionException.class); } catch (ConfigParser.NoOptionException x) { // } } @Test public void testGetNoSection() throws Exception { try { instance.get(SECTION, OPTION); missing(ConfigParser.NoSectionException.class); } catch (ConfigParser.NoSectionException x) { // } } @Test @SuppressWarnings("empty-statement") public void testGetVars() throws Exception { Map vars = new HashMap(); instance = new ConfigParser(vars); instance.addSection(SECTION); instance.set(SECTION, OPTION, MISSING_REF); assertEquals(MISSING_REF, instance.get(SECTION, OPTION, true)); requireMissingOptionException(SECTION, OPTION); vars.put(MISSING, DUMMY); assertEquals(DUMMY, instance.get(SECTION, OPTION)); vars.remove(MISSING); requireMissingOptionException(SECTION, OPTION); instance.getIni().add(ConfigParser.PyIni.DEFAULT_SECTION_NAME); ((ConfigParser.PyIni) instance.getIni()).getDefaultSection().put(MISSING, DUMMY); assertEquals(DUMMY, instance.get(SECTION, OPTION)); ((ConfigParser.PyIni) instance.getIni()).getDefaultSection().remove(MISSING); requireMissingOptionException(SECTION, OPTION); instance = new ConfigParser(); instance.addSection(SECTION); instance.set(SECTION, OPTION, MISSING_REF); vars.put(MISSING, DUMMY); assertEquals(DUMMY, instance.get(SECTION, OPTION, false, vars)); } @Test public void testItems() throws Exception { Ini ini = new Ini(); ini.add(SECTION).from(DwarfsData.dopey); Ini.Section section = ini.get(SECTION); Ini.Section dopey = ini.add(Dwarfs.PROP_DOPEY); for (String key : section.keySet()) { dopey.put(key.toLowerCase(), section.get(key)); } readDwarfs(); List> items = instance.items(Dwarfs.PROP_DOPEY); assertEquals(5, items.size()); assertEquals(6, dopey.size()); for (Map.Entry entry : items) { assertEquals(dopey.get(entry.getKey()), entry.getValue()); } // raw dopey = instance.getIni().get(Dwarfs.PROP_DOPEY); items = instance.items(Dwarfs.PROP_DOPEY, true); assertEquals(5, items.size()); assertEquals("%(_weight)", dopey.get(Dwarf.PROP_WEIGHT)); assertEquals("%(_height)", dopey.get(Dwarf.PROP_HEIGHT)); } @Test public void testOptions() throws Exception { instance.addSection(SECTION); assertEquals(0, instance.options(SECTION).size()); for (int i = 0; i < 10; i++) { instance.set(SECTION, OPTION + i, DUMMY); } assertEquals(10, instance.options(SECTION).size()); } @Test public void testRead() throws Exception { File file = newTestFile(DWARFS_PATH); assertTrue(file.exists()); instance.read(file.getCanonicalPath()); instance.read(file); instance.read(new FileReader(file)); instance.read(new FileInputStream(file)); instance.read(file.toURI().toURL()); } @Test public void testReadFileException() throws Exception { try { instance.read(badFile()); missing(ConfigParser.ParsingException.class); } catch (ConfigParser.ParsingException x) { // } } @Test public void testReadReaderException() throws Exception { try { instance.read(new StringReader(BAD)); missing(ConfigParser.ParsingException.class); } catch (ConfigParser.ParsingException x) { // } } @Test public void testReadStreamException() throws Exception { try { instance.read(new ByteArrayInputStream(BAD.getBytes())); missing(ConfigParser.ParsingException.class); } catch (ConfigParser.ParsingException x) { // } } @Test public void testReadURLException() throws Exception { try { instance.read(badFile().toURI().toURL()); missing(ConfigParser.ParsingException.class); } catch (ConfigParser.ParsingException x) { // } } @Test public void testSections() throws Exception { instance.addSection(SECTION); assertEquals(1, instance.sections().size()); for (int i = 0; i < 10; i++) { instance.addSection(SECTION + i); } assertEquals(11, instance.sections().size()); } @Test public void testSet() throws Exception { instance.addSection(SECTION); instance.set(SECTION, OPTION, "dummy"); assertEquals("dummy", instance.getIni().get(SECTION).get(OPTION)); assertTrue(instance.hasOption(SECTION, OPTION)); instance.set(SECTION, OPTION, null); assertFalse(instance.hasOption(SECTION, OPTION)); } @Test public void testSetNoSection() throws Exception { try { instance.set(SECTION, OPTION, "dummy"); missing(ConfigParser.NoSectionException.class); } catch (ConfigParser.NoSectionException x) { // } } @Test public void testWrite() throws Exception { File input = newTestFile(DWARFS_PATH); File output = new File(TEST_WORK_PATH, input.getName()); instance.read(input); instance.write(output); checkWrite(output); instance.write(new FileWriter(output)); checkWrite(output); instance.write(new FileOutputStream(output)); checkWrite(output); } protected void checkEquals(Dwarf expected, String sectionName) throws Exception { assertEquals("" + expected.getAge(), instance.get(sectionName, Dwarf.PROP_AGE)); assertEquals("" + expected.getHeight(), instance.get(sectionName, Dwarf.PROP_HEIGHT)); assertEquals("" + expected.getWeight(), instance.get(sectionName, Dwarf.PROP_WEIGHT)); assertEquals("" + expected.getHomePage(), instance.get(sectionName, Dwarf.PROP_HOME_PAGE.toLowerCase())); assertEquals("" + expected.getHomeDir(), instance.get(sectionName, Dwarf.PROP_HOME_DIR.toLowerCase())); } protected File newTestFile(String path) { return new File(TEST_DATA_PATH, path); } protected void readDwarfs() throws Exception { instance.read(newTestFile(DWARFS_PATH)); } private File badFile() throws IOException { File f = File.createTempFile("test", "ini"); f.deleteOnExit(); FileWriter w = new FileWriter(f); w.write(BAD, 0, BAD.length()); w.close(); return f; } private void checkEquals(Map a, Map b) throws Exception { if (a == null) { assertNull(b); } else { assertEquals(a.size(), b.size()); for (String key : a.keySet()) { assertEquals(a.get(key), b.get(key)); } } } private void checkWrite(File file) throws Exception { ConfigParser saved = new ConfigParser(instance.defaults()); saved.read(file); checkEquals(((ConfigParser.PyIni) instance.getIni()).getDefaultSection(), ((ConfigParser.PyIni) saved.getIni()).getDefaultSection()); assertEquals(instance.sections().size(), saved.sections().size()); for (String sectionName : instance.sections()) { checkEquals(instance.getIni().get(sectionName), saved.getIni().get(sectionName)); } } @SuppressWarnings("empty-statement") private void requireMissingOptionException(String sectionName, String optionName) throws Exception { try { instance.get(sectionName, optionName); fail(); } catch (ConfigParser.InterpolationMissingOptionException x) { ; } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/ConfigTest.java000066400000000000000000000143361151645323700232110ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.junit.Assert; import org.junit.Test; import java.nio.charset.Charset; public class ConfigTest extends Ini4jCase { @Test public void testDefaults() { Config def = newDefaultConfig(); assertEquals(def, new Config()); assertEquals(def, Config.getGlobal()); assertEquals(def, Config.getGlobal().clone()); } @Test public void testSystemProperties() { Config exp = newInverseConfig(); setBoolean(Config.PROP_EMPTY_OPTION, exp.isEmptyOption()); setBoolean(Config.PROP_EMPTY_SECTION, exp.isEmptySection()); setBoolean(Config.PROP_GLOBAL_SECTION, exp.isGlobalSection()); setString(Config.PROP_GLOBAL_SECTION_NAME, exp.getGlobalSectionName()); setBoolean(Config.PROP_INCLUDE, exp.isInclude()); setBoolean(Config.PROP_LOWER_CASE_OPTION, exp.isLowerCaseOption()); setBoolean(Config.PROP_LOWER_CASE_SECTION, exp.isLowerCaseSection()); setBoolean(Config.PROP_MULTI_OPTION, exp.isMultiOption()); setBoolean(Config.PROP_MULTI_SECTION, exp.isMultiSection()); setBoolean(Config.PROP_STRICT_OPERATOR, exp.isStrictOperator()); setBoolean(Config.PROP_UNNAMED_SECTION, exp.isUnnamedSection()); setBoolean(Config.PROP_ESCAPE, exp.isEscape()); setChar(Config.PROP_PATH_SEPARATOR, exp.getPathSeparator()); setBoolean(Config.PROP_TREE, exp.isTree()); setBoolean(Config.PROP_PROPERTY_FIRST_UPPER, exp.isPropertyFirstUpper()); setString(Config.PROP_LINE_SEPARATOR, exp.getLineSeparator()); setCharset(Config.PROP_FILE_ENCODING, exp.getFileEncoding()); setBoolean(Config.PROP_COMMENT, exp.isComment()); setBoolean(Config.PROP_HEADER_COMMENT, exp.isHeaderComment()); Config cfg = new Config(); assertEquals(exp, cfg); } private void setBoolean(String prop, boolean value) { System.setProperty(Config.KEY_PREFIX + prop, String.valueOf(value)); } private void setChar(String prop, char value) { System.setProperty(Config.KEY_PREFIX + prop, String.valueOf(value)); } private void setCharset(String prop, Charset value) { System.setProperty(Config.KEY_PREFIX + prop, String.valueOf(value)); } private void setString(String prop, String value) { System.setProperty(Config.KEY_PREFIX + prop, value); } private void assertEquals(Config exp, Config act) { Assert.assertEquals(exp.isEmptyOption(), act.isEmptyOption()); Assert.assertEquals(exp.isEmptySection(), act.isEmptySection()); Assert.assertEquals(exp.isEscape(), act.isEscape()); Assert.assertEquals(exp.isGlobalSection(), act.isGlobalSection()); Assert.assertEquals(exp.isInclude(), act.isInclude()); Assert.assertEquals(exp.isLowerCaseOption(), act.isLowerCaseOption()); Assert.assertEquals(exp.isLowerCaseSection(), act.isLowerCaseSection()); Assert.assertEquals(exp.isMultiOption(), act.isMultiOption()); Assert.assertEquals(exp.isMultiSection(), act.isMultiSection()); Assert.assertEquals(exp.isStrictOperator(), act.isStrictOperator()); Assert.assertEquals(exp.isUnnamedSection(), act.isUnnamedSection()); Assert.assertEquals(exp.getGlobalSectionName(), act.getGlobalSectionName()); Assert.assertEquals(exp.getPathSeparator(), act.getPathSeparator()); Assert.assertEquals(exp.isTree(), act.isTree()); Assert.assertEquals(exp.isPropertyFirstUpper(), act.isPropertyFirstUpper()); Assert.assertEquals(exp.getLineSeparator(), act.getLineSeparator()); Assert.assertEquals(exp.getFileEncoding(), act.getFileEncoding()); Assert.assertEquals(exp.isComment(), act.isComment()); Assert.assertEquals(exp.isHeaderComment(), act.isHeaderComment()); } private Config newDefaultConfig() { Config cfg = new Config(); cfg.setEmptyOption(false); cfg.setEmptySection(false); cfg.setEscape(true); cfg.setGlobalSection(false); cfg.setGlobalSectionName("?"); cfg.setInclude(false); cfg.setLowerCaseOption(false); cfg.setLowerCaseSection(false); cfg.setMultiSection(false); cfg.setMultiOption(true); cfg.setStrictOperator(false); cfg.setUnnamedSection(false); cfg.setPathSeparator('/'); cfg.setTree(true); cfg.setPropertyFirstUpper(false); cfg.setLineSeparator(System.getProperty("line.separator")); cfg.setFileEncoding(Charset.forName("UTF-8")); cfg.setComment(true); cfg.setHeaderComment(true); return cfg; } private Config newInverseConfig() { Config cfg = newDefaultConfig(); cfg.setEmptyOption(!cfg.isEmptyOption()); cfg.setEmptySection(!cfg.isEmptySection()); cfg.setEscape(!cfg.isEscape()); cfg.setGlobalSection(!cfg.isGlobalSection()); cfg.setGlobalSectionName("+"); cfg.setInclude(!cfg.isInclude()); cfg.setLowerCaseOption(!cfg.isLowerCaseOption()); cfg.setLowerCaseSection(!cfg.isLowerCaseSection()); cfg.setMultiSection(!cfg.isMultiSection()); cfg.setMultiOption(!cfg.isMultiOption()); cfg.setStrictOperator(!cfg.isStrictOperator()); cfg.setUnnamedSection(!cfg.isUnnamedSection()); cfg.setPathSeparator('?'); cfg.setTree(!cfg.isTree()); cfg.setPropertyFirstUpper(!cfg.isPropertyFirstUpper()); cfg.setComment(!cfg.isComment()); cfg.setHeaderComment(!cfg.isHeaderComment()); //cfg.setLineSeparator("\t"); //cfg.setFileEncoding(Charset.forName("ASCII")); return cfg; } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/Ini4jCase.java000066400000000000000000000017221151645323700227100ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import junit.framework.TestCase; import org.ini4j.test.Helper; public class Ini4jCase extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); Helper.resetConfig(); } protected void missing(Class clazz) { fail("Missing exception: " + clazz.getName()); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/IniPreferencesFactoryTest.java000066400000000000000000000057031151645323700262330ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import org.junit.Test; import java.util.prefs.Preferences; public class IniPreferencesFactoryTest extends Ini4jCase { private static final String DUMMY = "dummy"; @Test public void testGetIniLocation() throws Exception { IniPreferencesFactory factory = new IniPreferencesFactory(); System.setProperty(DUMMY, DUMMY); assertEquals(DUMMY, factory.getIniLocation(DUMMY)); System.getProperties().remove(DUMMY); assertNull(factory.getIniLocation(DUMMY)); } @SuppressWarnings("empty-statement") @Test public void testGetResourceAsStream() throws Exception { IniPreferencesFactory factory = new IniPreferencesFactory(); // class path assertNotNull(factory.getResourceAsStream(Helper.DWARFS_INI)); // url String location = Helper.getResourceURL(Helper.DWARFS_INI).toString(); assertNotNull(factory.getResourceAsStream(location)); // invalid url should throw IllegalArgumentException try { factory.getResourceAsStream("http://"); fail(); } catch (IllegalArgumentException x) { ; } } @Test public void testNewIniPreferences() { System.setProperty(DUMMY, DUMMY); try { new IniPreferencesFactory().newIniPreferences(DUMMY); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } finally { System.getProperties().remove(DUMMY); } } @Test public void testSystemRoot() throws Exception { Preferences prefs = Preferences.systemRoot(); assertNotNull(prefs); assertEquals(IniPreferences.class, prefs.getClass()); assertSame(prefs, Preferences.systemRoot()); } @Test public void testUserRoot() throws Exception { Preferences prefs = Preferences.userRoot(); assertNotNull(prefs); assertEquals(IniPreferences.class, prefs.getClass()); assertSame(prefs, Preferences.userRoot()); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/IniPreferencesTest.java000066400000000000000000000152151151645323700247020ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.spi.BeanAccess; import org.ini4j.spi.BeanTool; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import org.ini4j.test.TaleData; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import org.junit.Test; import java.util.prefs.Preferences; public class IniPreferencesTest extends Ini4jCase { private static final String DUMMY = "dummy"; @Test public void testConstructor() throws Exception { Ini ini = Helper.newDwarfsIni(); IniPreferences prefs = new IniPreferences(ini); assertSame(ini, prefs.getIni()); Helper.assertEquals(DwarfsData.dwarfs, ini.as(Dwarfs.class)); prefs = new IniPreferences(Helper.getResourceStream(Helper.DWARFS_INI)); Helper.assertEquals(DwarfsData.doc, newDwarf(prefs.node(Dwarfs.PROP_DOC))); prefs = new IniPreferences(Helper.getResourceReader(Helper.DWARFS_INI)); Helper.assertEquals(DwarfsData.happy, newDwarf(prefs.node(Dwarfs.PROP_HAPPY))); prefs = new IniPreferences(Helper.getResourceURL(Helper.DWARFS_INI)); Helper.assertEquals(DwarfsData.sleepy, newDwarf(prefs.node(Dwarfs.PROP_SLEEPY))); } @Test public void testMisc() throws Exception { Ini ini = new Ini(); IniPreferences prefs = new IniPreferences(ini); // do nothing, but doesn't throw exception prefs.sync(); prefs.flush(); // node & key count assertEquals(0, prefs.keysSpi().length); assertEquals(0, prefs.childrenNamesSpi().length); // childNode for new and for existing section assertNotNull(prefs.node(Dwarfs.PROP_DOC)); assertEquals(1, prefs.childrenNamesSpi().length); ini.add(Dwarfs.PROP_HAPPY); assertNotNull(prefs.node(Dwarfs.PROP_HAPPY)); assertEquals(2, prefs.childrenNamesSpi().length); // SectionPreferences IniPreferences.SectionPreferences sec = (IniPreferences.SectionPreferences) prefs.node(Dwarfs.PROP_DOC); assertEquals(0, sec.childrenNamesSpi().length); // do nothing, but doesn't throw exception sec.sync(); sec.syncSpi(); sec.flush(); sec.flushSpi(); // empty assertEquals(0, sec.keysSpi().length); // add one key sec.put(Dwarf.PROP_AGE, "87"); sec.flush(); assertEquals("87", sec.getSpi(Dwarf.PROP_AGE)); // has one key assertEquals(1, sec.keysSpi().length); // remove key sec.remove(Dwarf.PROP_AGE); sec.flush(); // has 0 key assertEquals(0, sec.keysSpi().length); sec.removeNode(); prefs.flush(); assertNull(ini.get(Dwarfs.PROP_DOC)); } @Test public void testTaleTree() throws Exception { Ini ini = Helper.newTaleIni(); IniPreferences prefs = new IniPreferences(ini); Preferences dwarfs = prefs.node(TaleData.PROP_DWARFS); Helper.assertEquals(DwarfsData.doc, newDwarf(dwarfs.node(Dwarfs.PROP_DOC))); assertArrayEquals(DwarfsData.dwarfNames, dwarfs.childrenNames()); assertEquals(1, prefs.childrenNames().length); } @Test public void testTree() throws Exception { Ini ini = new Ini(); IniPreferences prefs = new IniPreferences(ini); IniPreferences.SectionPreferences sec = (IniPreferences.SectionPreferences) prefs.node(Dwarfs.PROP_DOC); Preferences child = sec.node(DUMMY); assertNotNull(child); assertNotNull(sec.node(DUMMY)); assertNotNull(ini.get(Dwarfs.PROP_DOC).getChild(DUMMY)); assertEquals(1, prefs.childrenNames().length); } @SuppressWarnings("empty-statement") @Test public void testUnsupported() throws Exception { Ini ini = new Ini(); IniPreferences prefs = new IniPreferences(ini); try { prefs.getSpi(DUMMY); fail(); } catch (UnsupportedOperationException x) { ; } try { prefs.putSpi(DUMMY, DUMMY); fail(); } catch (UnsupportedOperationException x) { ; } try { prefs.removeNodeSpi(); fail(); } catch (UnsupportedOperationException x) { ; } try { prefs.removeSpi(DUMMY); fail(); } catch (UnsupportedOperationException x) { ; } } private Dwarf newDwarf(Preferences node) { return BeanTool.getInstance().proxy(Dwarf.class, new Access(node)); } public static class Access implements BeanAccess { private final Preferences _node; public Access(Preferences node) { _node = node; } public void propAdd(String propertyName, String value) { throw new UnsupportedOperationException("Not supported yet."); } public String propDel(String propertyName) { throw new UnsupportedOperationException("Not supported yet."); } public String propGet(String propertyName) { return _node.get(propertyName, null); } public String propGet(String propertyName, int index) { return (index == 0) ? propGet(propertyName) : null; } public int propLength(String propertyName) { return (propGet(propertyName) == null) ? 0 : 1; } public String propSet(String propertyName, String value) { throw new UnsupportedOperationException("Not supported yet."); } public String propSet(String propertyName, String value, int index) { throw new UnsupportedOperationException("Not supported yet."); } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/IniTest.java000066400000000000000000000172351151645323700225240ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.StringReader; import java.io.StringWriter; public class IniTest extends Ini4jCase { private static final String COMMENT_ONLY = "# first line\n# second line\n"; private static final String COMMENT_ONLY_VALUE = " first line\n second line"; private static final String INI_ONE_HEADER = COMMENT_ONLY + "\n\n[section]\nkey=value\n"; private static final String COMMENTED_OPTION = COMMENT_ONLY + "\n\n[section]\n;comment\nkey=value\n"; private static final String MULTI = "[section]\noption=value\noption=value2\n[section]\noption=value3\noption=value4\noption=value5\n"; @Test public void testCommentedOption() throws Exception { Ini ini = new Ini(new StringReader(COMMENTED_OPTION)); assertEquals("comment", ini.get("section").getComment("key")); } @Test public void testCommentOnly() throws Exception { Ini ini = new Ini(new StringReader(COMMENT_ONLY)); assertEquals(COMMENT_ONLY_VALUE, ini.getComment()); } @Test public void testLoad() throws Exception { Ini ini; ini = new Ini(Helper.getResourceURL(Helper.DWARFS_INI)); Helper.assertEquals(DwarfsData.dwarfs, ini.as(Dwarfs.class)); ini = new Ini(Helper.getResourceStream(Helper.DWARFS_INI)); Helper.assertEquals(DwarfsData.dwarfs, ini.as(Dwarfs.class)); ini = new Ini(Helper.getResourceReader(Helper.DWARFS_INI)); Helper.assertEquals(DwarfsData.dwarfs, ini.as(Dwarfs.class)); ini = new Ini(Helper.getSourceFile(Helper.DWARFS_INI)); Helper.assertEquals(DwarfsData.dwarfs, ini.as(Dwarfs.class)); ini = new Ini(); ini.setFile(Helper.getSourceFile(Helper.DWARFS_INI)); ini.load(); Helper.assertEquals(DwarfsData.dwarfs, ini.as(Dwarfs.class)); } @Test public void testLoadException() throws Exception { Ini ini = new Ini(); try { ini.load(); missing(FileNotFoundException.class); } catch (FileNotFoundException x) { // } } @Test public void testMulti() throws Exception { Ini ini = new Ini(new StringReader(MULTI)); Ini.Section sec; assertEquals(1, ini.length("section")); assertEquals(5, ini.get("section", 0).length("option")); ini.clear(); Config cfg = new Config(); cfg.setMultiSection(true); ini.setConfig(cfg); ini.load(new StringReader(MULTI)); assertEquals(2, ini.get("section", 0).length("option")); assertEquals(3, ini.get("section", 1).length("option")); // StringWriter writer = new StringWriter(); cfg.setMultiOption(false); ini.store(writer); ini.clear(); cfg.setMultiOption(true); ini.load(new StringReader(writer.toString())); assertEquals(1, ini.get("section", 0).length("option")); assertEquals(1, ini.get("section", 1).length("option")); assertEquals("value2", ini.get("section", 0).get("option")); assertEquals("value5", ini.get("section", 1).get("option")); // ini.clear(); cfg.setMultiOption(false); ini.load(new StringReader(MULTI)); assertEquals(1, ini.get("section", 0).length("option")); assertEquals(1, ini.get("section", 1).length("option")); } @Test public void testOneHeaderOnly() throws Exception { Ini ini = new Ini(new StringReader(INI_ONE_HEADER)); assertEquals(COMMENT_ONLY_VALUE, ini.getComment()); } @Test public void testStore() throws Exception { Ini ini = Helper.newDwarfsIni(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ini.store(buffer); Ini dup = new Ini(); dup.load(new ByteArrayInputStream(buffer.toByteArray())); Helper.assertEquals(DwarfsData.dwarfs, dup.as(Dwarfs.class)); buffer = new ByteArrayOutputStream(); ini.store(new OutputStreamWriter(buffer)); dup = new Ini(); dup.load(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray()))); Helper.assertEquals(DwarfsData.dwarfs, dup.as(Dwarfs.class)); // File file = File.createTempFile("test", ".ini"); file.deleteOnExit(); ini.setFile(file); assertEquals(file, ini.getFile()); ini.store(); dup = new Ini(); dup.setFile(file); dup.load(); Helper.assertEquals(DwarfsData.dwarfs, dup.as(Dwarfs.class)); file.delete(); } @Test public void testStoreException() throws Exception { Ini ini = new Ini(); try { ini.store(); missing(FileNotFoundException.class); } catch (FileNotFoundException x) { // } } @Test public void testWithComment() throws Exception { Ini ini = new Ini(); ini.load(Helper.getResourceStream(Helper.DWARFS_INI)); assertNotNull(ini.getComment()); for (Ini.Section sec : ini.values()) { assertNotNull(ini.getComment(sec.getName())); } } @Test public void testWithoutComment() throws Exception { Ini ini = new Ini(); Config cfg = new Config(); cfg.setComment(false); ini.setConfig(cfg); ini.load(Helper.getResourceStream(Helper.DWARFS_INI)); assertNull(ini.getComment()); for (Ini.Section sec : ini.values()) { assertNull(ini.getComment(sec.getName())); } ini = new Ini(); ini.setConfig(cfg); ini.setComment("comment"); Ini.Section sec = ini.add("section"); sec.add("option", "value"); ini.putComment("section", "section-comment"); StringWriter writer = new StringWriter(); ini.store(writer); assertEquals("[section]\noption = value\n\n", writer.toString()); } @Test public void testWithoutHeaderComment() throws Exception { Ini ini = new Ini(); Config cfg = new Config(); cfg.setHeaderComment(false); cfg.setComment(true); ini.setConfig(cfg); ini.load(Helper.getResourceStream(Helper.DWARFS_INI)); assertNull(ini.getComment()); for (Ini.Section sec : ini.values()) { assertNotNull(ini.getComment(sec.getName())); } ini = new Ini(); ini.setConfig(cfg); ini.setComment("comment"); Ini.Section sec = ini.add("section"); sec.add("option", "value"); ini.putComment("section", "section-comment"); StringWriter writer = new StringWriter(); ini.store(writer); assertEquals("#section-comment\n[section]\noption = value\n\n", writer.toString()); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/OptionsTest.java000066400000000000000000000170171151645323700234360ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.sample.Dwarf; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.StringReader; public class OptionsTest extends Ini4jCase { private static final String[] _badOptions = { "=value\n", "\\u000d\\u000d=value\n" }; private static final String COMMENT_ONLY = "# first line\n# second line\n"; private static final String COMMENT_ONLY_VALUE = " first line\n second line"; private static final String OPTIONS_ONE_HEADER = COMMENT_ONLY + "\n\nkey=value\n"; private static final String MULTI = "option=value\noption=value2\noption=value3\noption=value4\noption=value5\n"; @Test public void testCommentOnly() throws Exception { Options opt = new Options(new StringReader(COMMENT_ONLY)); assertEquals(COMMENT_ONLY_VALUE, opt.getComment()); } @Test public void testConfig() { Options opts = new Options(); Config conf = opts.getConfig(); assertTrue(conf.isEmptyOption()); assertTrue(conf.isEscape()); assertFalse(conf.isInclude()); assertTrue(conf.isMultiOption()); conf = new Config(); opts.setConfig(conf); assertSame(conf, opts.getConfig()); } @Test public void testDwarfs() throws Exception { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); Options happy = new Options(); happy.from(DwarfsData.happy); happy.store(buffer); Options dup = new Options(new ByteArrayInputStream(buffer.toByteArray())); Helper.assertEquals(DwarfsData.happy, dup.as(Dwarf.class)); buffer = new ByteArrayOutputStream(); happy.store(new OutputStreamWriter(buffer)); dup = new Options(new ByteArrayInputStream(buffer.toByteArray())); Helper.assertEquals(DwarfsData.happy, dup.as(Dwarf.class)); File file = File.createTempFile("test", ".opt"); file.deleteOnExit(); happy.setFile(file); happy.store(); dup = new Options(); dup.setFile(file); assertEquals(file, dup.getFile()); dup.load(); Helper.assertEquals(DwarfsData.happy, dup.as(Dwarf.class)); file.delete(); } @Test public void testLoad() throws Exception { Options o1 = new Options(Helper.getResourceURL(Helper.DWARFS_OPT)); Options o2 = new Options(Helper.getResourceURL(Helper.DWARFS_OPT).openStream()); Options o3 = new Options(new InputStreamReader(Helper.getResourceURL(Helper.DWARFS_OPT).openStream())); Options o4 = new Options(Helper.getResourceURL(Helper.DWARFS_OPT)); Options o5 = new Options(Helper.getSourceFile(Helper.DWARFS_OPT)); Options o6 = new Options(); o6.setFile(Helper.getSourceFile(Helper.DWARFS_OPT)); o6.load(); Helper.assertEquals(DwarfsData.dopey, o1.as(Dwarf.class)); Helper.assertEquals(DwarfsData.dopey, o2.as(Dwarf.class)); Helper.assertEquals(DwarfsData.dopey, o3.as(Dwarf.class)); Helper.assertEquals(DwarfsData.dopey, o4.as(Dwarf.class)); Helper.assertEquals(DwarfsData.dopey, o5.as(Dwarf.class)); Helper.assertEquals(DwarfsData.dopey, o6.as(Dwarf.class)); } @Test public void testLoadException() throws Exception { Options opt = new Options(); try { opt.load(); missing(FileNotFoundException.class); } catch (FileNotFoundException x) { // } } @Test public void testLowerCase() throws Exception { Config cfg = new Config(); Options opts = new Options(); cfg.setLowerCaseOption(true); opts.setConfig(cfg); opts.load(new StringReader("OptIon=value\n")); assertTrue(opts.containsKey("option")); } @Test public void testMultiOption() throws Exception { Options opts = new Options(new StringReader(MULTI)); assertEquals(5, opts.length("option")); opts.clear(); Config cfg = new Config(); cfg.setMultiOption(false); opts.setConfig(cfg); opts.load(new StringReader(MULTI)); assertEquals(1, opts.length("option")); } @Test public void testNoEmptyOption() throws Exception { Config cfg = new Config(); Options opts = new Options(); opts.setConfig(cfg); try { opts.load(new StringReader("foo\n")); missing(InvalidFileFormatException.class); } catch (InvalidFileFormatException x) { // } cfg.setEmptyOption(true); opts.load(new StringReader("dummy\n")); assertTrue(opts.containsKey("dummy")); assertNull(opts.get("dummy")); } @Test public void testOneHeaderOnly() throws Exception { Options opt = new Options(new StringReader(OPTIONS_ONE_HEADER)); assertEquals(COMMENT_ONLY_VALUE, opt.getComment()); } @Test @SuppressWarnings("empty-statement") public void testParseError() throws Exception { for (String s : _badOptions) { try { new Options(new ByteArrayInputStream(s.getBytes())); fail("expected InvalidIniFormatException: " + s); } catch (InvalidFileFormatException x) { ; } } } @Test public void testStoreException() throws Exception { Options opt = new Options(); try { opt.store(); missing(FileNotFoundException.class); } catch (FileNotFoundException x) { // } } @Test public void testWithComment() throws Exception { Options opts = new Options(); opts.load(Helper.getResourceStream(Helper.DWARFS_OPT)); assertNotNull(opts.getComment()); } @Test public void testWithoutComment() throws Exception { Options opts = new Options(); Config cfg = new Config(); cfg.setComment(false); opts.setConfig(cfg); opts.load(Helper.getResourceStream(Helper.DWARFS_OPT)); assertNull(opts.getComment()); } @Test public void testWithoutHeaderComment() throws Exception { Options opts = new Options(); Config cfg = new Config(); cfg.setComment(true); cfg.setHeaderComment(false); opts.setConfig(cfg); opts.load(Helper.getResourceStream(Helper.DWARFS_OPT)); assertNull(opts.getComment()); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/RegTest.java000066400000000000000000000171451151645323700225220ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; public class RegTest extends Ini4jCase { private static final String DWARFS_PATH = Helper.DWARFS_REG_PATH + "\\dwarfs\\"; @Test public void proba() throws Exception { } @Test public void testDwarfs() throws Exception { Reg reg = Helper.loadDwarfsReg(); Dwarfs dwarfs = reg.as(Dwarfs.class, DWARFS_PATH); assertNotNull(dwarfs); Helper.assertEquals(DwarfsData.dwarfs, dwarfs); } @Test public void testInvalidFileFormatException() throws Exception { try { new Reg(Helper.getResourceReader(Helper.DWARFS_INI)); missing(InvalidFileFormatException.class); } catch (InvalidFileFormatException x) { // } } @Test public void testIsWindwos() { assertEquals(isWindows(), Reg.isWindows()); } @Test public void testLoad() throws Exception { Reg r1 = new Reg(new InputStreamReader(Helper.getResourceStream(Helper.DWARFS_REG), "UnicodeLittle")); Reg r2 = new Reg(Helper.getResourceStream(Helper.DWARFS_REG)); Reg r3 = new Reg(Helper.getResourceURL(Helper.DWARFS_REG)); File f = Helper.getSourceFile(Helper.DWARFS_REG); Reg r4 = new Reg(f); Reg r5 = new Reg(); r5.setFile(f); r5.load(); Helper.assertEquals(DwarfsData.dwarfs, r1.as(Dwarfs.class, DWARFS_PATH)); Helper.assertEquals(DwarfsData.dwarfs, r2.as(Dwarfs.class, DWARFS_PATH)); Helper.assertEquals(DwarfsData.dwarfs, r3.as(Dwarfs.class, DWARFS_PATH)); Helper.assertEquals(DwarfsData.dwarfs, r4.as(Dwarfs.class, DWARFS_PATH)); Helper.assertEquals(DwarfsData.dwarfs, r5.as(Dwarfs.class, DWARFS_PATH)); assertSame(f, r4.getFile()); } @Test public void testLoadFileNotFoundException() throws Exception { Reg reg = new Reg(); try { reg.load(); missing(FileNotFoundException.class); } catch (FileNotFoundException x) { // } } @Test public void testLoadSave() throws Exception { Reg reg = new Reg(Helper.getResourceURL(Helper.TEST_REG)); checkLoadSave(Helper.TEST_REG, reg); } @Test public void testMissingVersion() throws Exception { try { new Reg(new StringReader("\r\n\r\n[section]\r\n\"option\"=\"value\"")); missing(InvalidFileFormatException.class); } catch (InvalidFileFormatException x) { // } } @Test public void testNonWindwosExec() throws Exception { if (isSkip(isWindows(), "testNonWindwosExec")) { return; } Reg reg = new Reg(); reg.exec(new String[] { "/bin/true" }); try { reg.exec(new String[] { "/bin/ls", "no such file" }); fail("IOException expected"); } catch (IOException x) { assert true; } } @Test public void testReadException() throws Exception { if (!isWindows()) { try { new Reg(Reg.Hive.HKEY_CURRENT_USER.toString()); fail("missing UnsupportedOperationException"); } catch (UnsupportedOperationException x) { assert true; } } else { try { new Reg("no such key"); fail("missing IOException"); } catch (IOException x) { assert true; } } } @Test public void testReadWrite() throws Exception { if (isSkip(!isWindows(), "testReadWrite")) { return; } Reg reg = Helper.loadDwarfsReg(); reg.write(); Reg dup = new Reg(Helper.DWARFS_REG_PATH); Helper.assertEquals(reg.get(Helper.DWARFS_REG_PATH), dup.get(Helper.DWARFS_REG_PATH)); Dwarfs dwarfs = dup.as(Dwarfs.class, DWARFS_PATH); assertNotNull(dwarfs); Helper.assertEquals(DwarfsData.dwarfs, dwarfs); } @Test public void testStore() throws Exception { Reg reg = Helper.loadDwarfsReg(); File tmp = File.createTempFile(Reg.TMP_PREFIX, Reg.DEFAULT_SUFFIX); tmp.deleteOnExit(); reg.setFile(tmp); reg.store(); reg = new Reg(tmp); Helper.assertEquals(DwarfsData.dwarfs, reg.as(Dwarfs.class, DWARFS_PATH)); tmp.delete(); } @Test public void testStoreFileNotFoundException() throws Exception { try { new Reg().store(); missing(FileNotFoundException.class); } catch (FileNotFoundException x) { // } } @Test public void testUnsupportedOperatingSystem() throws Exception { if (isSkip(isWindows(), "testUnsupportedOperatingSystem")) { return; } Reg reg = new Reg(); try { reg.read(Helper.DWARFS_REG_PATH); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException x) { assert true; } try { reg.write(); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException x) { assert true; } } private boolean isSkip(boolean flag, String testName) { if (!flag) { System.out.println("Skipping " + getClass().getName() + '#' + testName); } return flag; } private boolean isWindows() { String family = System.getProperty("os.family"); return (family != null) && family.equals("windows"); } private void checkLoadSave(String path, Reg reg) throws Exception { File tmp = File.createTempFile(Reg.TMP_PREFIX, Reg.DEFAULT_SUFFIX); tmp.deleteOnExit(); reg.store(new FileOutputStream(tmp)); assertArrayEquals(read(Helper.getResourceStream(path)), read(new FileInputStream(tmp))); } private byte[] read(InputStream input) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buff = new byte[81912]; int n; while ((n = input.read(buff)) >= 0) { out.write(buff, 0, n); } return out.toByteArray(); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/WiniTest.java000066400000000000000000000101701151645323700227020ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j; import org.ini4j.spi.WinEscapeToolTest; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URL; public class WiniTest extends Ini4jCase { @Test public void testConstructors() throws Exception { File f = File.createTempFile("wini", "test"); f.deleteOnExit(); assertTrue(new WiniHelper(new FileInputStream(f)).isOK()); assertTrue(new WiniHelper(new FileReader(f)).isOK()); assertTrue(new WiniHelper(f).isOK()); assertTrue(new WiniHelper(f.toURI().toURL()).isOK()); } @Test public void testDefaults() { Wini wini = new Wini(); Config cfg = wini.getConfig(); assertTrue(cfg.isGlobalSection()); assertTrue(cfg.isEmptyOption()); assertFalse(cfg.isMultiOption()); assertFalse(cfg.isEscape()); } @Test public void testEscape() { Wini instance = new Wini(); assertEquals(WinEscapeToolTest.ESCAPE1, instance.escape(WinEscapeToolTest.VALUE1)); assertEquals(WinEscapeToolTest.ESCAPE2, instance.escape(WinEscapeToolTest.VALUE2)); assertEquals(WinEscapeToolTest.ESCAPE3, instance.escape(WinEscapeToolTest.VALUE3)); assertEquals(WinEscapeToolTest.ESCAPE4, instance.escape(WinEscapeToolTest.VALUE4)); assertEquals(WinEscapeToolTest.ESCAPE5, instance.escape(WinEscapeToolTest.VALUE5)); } @Test public void testUnescape() throws Exception { Wini instance = new Wini(); assertEquals(WinEscapeToolTest.VALUE1, instance.unescape(WinEscapeToolTest.ESCAPE1)); assertEquals(WinEscapeToolTest.VALUE2, instance.unescape(WinEscapeToolTest.ESCAPE2)); assertEquals(WinEscapeToolTest.VALUE3, instance.unescape(WinEscapeToolTest.ESCAPE3)); assertEquals(WinEscapeToolTest.VALUE4, instance.unescape(WinEscapeToolTest.ESCAPE4)); assertEquals(WinEscapeToolTest.VALUE5, instance.unescape(WinEscapeToolTest.ESCAPE5)); assertEquals("=", instance.unescape("\\=")); assertEquals("xAx", instance.unescape("x\\o101x")); } private static class WiniHelper extends Wini { private boolean _ok; public WiniHelper(Reader input) throws IOException, InvalidFileFormatException { super(input); } public WiniHelper(InputStream input) throws IOException, InvalidFileFormatException { super(input); } public WiniHelper(URL input) throws IOException, InvalidFileFormatException { super(input); } public WiniHelper(File input) throws IOException, InvalidFileFormatException { super(input); } public boolean isOK() { return _ok; } @Override public void load(InputStream input) throws IOException, InvalidFileFormatException { _ok = true; } @Override public void load(Reader input) throws IOException, InvalidFileFormatException { _ok = true; } @Override public void load(File input) throws IOException, InvalidFileFormatException { _ok = true; } @Override public void load(URL input) throws IOException, InvalidFileFormatException { _ok = true; } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/000077500000000000000000000000001151645323700212165ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/Demo.java000066400000000000000000000152661151645323700227570ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.demo; import bsh.util.JConsole; import org.ini4j.demo.DemoModel.Mode; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTextArea; public class Demo { private enum Command { MODE_INI, MODE_REG, MODE_OPTIONS, LOAD_TEST_DATA, PARSE_DATA, CLEAR_DATA } private JConsole _console; private final Container _container; private JTextArea _dataTextArea; private JTextArea _helpTextArea; private DemoModel _model; private JTextArea _tipTextArea; private ActionListener _actionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { Command cmd = Command.valueOf(event.getActionCommand()); switch (cmd) { case MODE_INI: doMode(Mode.INI); break; case MODE_REG: doMode(Mode.REG); break; case MODE_OPTIONS: doMode(Mode.OPTIONS); break; case LOAD_TEST_DATA: doLoad(); break; case PARSE_DATA: doParse(); break; case CLEAR_DATA: doClear(); break; } } }; public Demo(Container container) { _container = container; } public void init() { _container.setBackground(Color.WHITE); _container.setLayout(new BoxLayout(_container, BoxLayout.PAGE_AXIS)); initInputPane(); initButtonsPane(); initOutputPane(); // new Thread(_model).start(); doMode(Mode.INI); } private void addButton(JPanel panel, String label, Command command) { JButton button = new JButton(); button.setText(label); button.setActionCommand(command.name()); button.addActionListener(_actionListener); panel.add(button); } private void addModeButton(ButtonGroup group, JPanel panel, Mode mode) { String label = mode.name().charAt(0) + mode.name().toLowerCase().substring(1); JRadioButton button = new JRadioButton(label); button.setActionCommand("MODE_" + mode.name()); button.setSelected(mode == Mode.INI); panel.add(button); button.addActionListener(_actionListener); group.add(button); } private void doClear() { try { _dataTextArea.setText(""); _model.clear(); } catch (Exception x) { exceptionThrown(x); } } private void doLoad() { try { _dataTextArea.setText(_model.load()); _console.println("Test data loaded"); } catch (Exception x) { exceptionThrown(x); } } private void doMode(Mode mode) { _model.setMode(mode); try { _tipTextArea.setText(_model.tip()); } catch (Exception x) { exceptionThrown(x); } } private void doParse() { try { _model.parse(_dataTextArea.getText()); _console.println("Parse ready"); } catch (Exception x) { exceptionThrown(x); } } private void exceptionThrown(Exception exception) { _console.error(exception); _console.error("\n"); exception.printStackTrace(); } private void initButtonsPane() { JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); buttons.setBackground(Color.WHITE); buttons.add(new JLabel("Mode: ")); ButtonGroup group = new ButtonGroup(); addModeButton(group, buttons, Mode.INI); addModeButton(group, buttons, Mode.REG); addModeButton(group, buttons, Mode.OPTIONS); buttons.add(Box.createHorizontalGlue()); addButton(buttons, " C L E A R ", Command.CLEAR_DATA); addButton(buttons, " L O A D ", Command.LOAD_TEST_DATA); addButton(buttons, " P A R S E ", Command.PARSE_DATA); _container.add(buttons); } private void initInputPane() { JTabbedPane inputPane = new JTabbedPane(JTabbedPane.TOP); inputPane.setPreferredSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); inputPane.setBackground(Color.WHITE); _dataTextArea = new JTextArea(); JScrollPane sp = new JScrollPane(_dataTextArea); inputPane.addTab("data", sp); _tipTextArea = new JTextArea(); _tipTextArea.setEditable(false); sp = new JScrollPane(_tipTextArea); inputPane.addTab("tip", sp); _helpTextArea = new JTextArea(); _helpTextArea.setEditable(false); sp = new JScrollPane(_helpTextArea); inputPane.addTab("help", sp); // _container.add(inputPane); } private void initOutputPane() { JTabbedPane output = new JTabbedPane(JTabbedPane.BOTTOM); JConsole console = new JConsole(); console.setBackground(Color.WHITE); _model = new DemoModel(console); _console = new JConsole(); output.addTab("Console", _console); output.setBackground(Color.WHITE); output.setPreferredSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); output.addTab("Interpreter", console); try { // _helpTextArea.setText(_model.help()); } catch (IOException x) { exceptionThrown(x); } // _container.add(output); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/DemoApplet.java000066400000000000000000000021741151645323700241170ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.demo; import javax.swing.JApplet; import javax.swing.UIManager; public class DemoApplet extends JApplet { private static final long serialVersionUID = -7269388726751989763L; public DemoApplet() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception x) { x.printStackTrace(); } } @Override public void init() { Demo demo = new Demo(getContentPane()); demo.init(); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/DemoMain.java000066400000000000000000000026661151645323700235640ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.demo; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.UIManager; public class DemoMain implements Runnable { private Demo _demo; public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception x) { x.printStackTrace(); } SwingUtilities.invokeLater(new DemoMain()); } @Override public void run() { JFrame frame = new JFrame("TopLevelDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(800, 600)); _demo = new Demo(frame.getContentPane()); _demo.init(); frame.pack(); frame.setVisible(true); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/DemoModel.java000066400000000000000000000064451151645323700237370ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.demo; import bsh.ConsoleInterface; import bsh.EvalError; import bsh.Interpreter; import bsh.NameSpace; import org.ini4j.Config; import org.ini4j.Ini; import org.ini4j.Options; import org.ini4j.Persistable; import org.ini4j.Reg; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; public class DemoModel implements Runnable { public static enum Mode { INI, REG, OPTIONS; } private Persistable _data; private Interpreter _interpreter; private Mode _mode = Mode.INI; public DemoModel(ConsoleInterface console) { _interpreter = new Interpreter(console); NameSpace namespace = _interpreter.getNameSpace(); namespace.importPackage("org.ini4j.spi"); namespace.importPackage("org.ini4j"); namespace.importPackage("org.ini4j.sample"); } public Object getData() { return _data; } public Mode getMode() { return _mode; } public void setMode(Mode mode) { _mode = mode; } public void clear() throws EvalError { _interpreter.unset("data"); } public String help() throws IOException { return readResource("help.txt"); } public String load() throws IOException { return readResource(_mode.name().toLowerCase() + "-data.txt"); } public void parse(String text) throws IOException, EvalError { Persistable data = newData(); data.load(new StringReader(text)); _interpreter.set("data", data); _data = data; } @Override public void run() { _interpreter.setExitOnEOF(false); _interpreter.run(); } public String tip() throws IOException { return readResource(_mode.name().toLowerCase() + "-tip.txt"); } private Persistable newData() { Persistable ret = null; switch (_mode) { case INI: ret = new Ini(); break; case REG: ret = new Reg(); break; case OPTIONS: ret = new Options(); break; } return ret; } private String readResource(String path) throws IOException { InputStream in = getClass().getResourceAsStream(path); Reader reader = new InputStreamReader(in, Config.DEFAULT_FILE_ENCODING); StringBuilder str = new StringBuilder(); char[] buff = new char[8192]; int n; while ((n = reader.read(buff)) >= 0) { str.append(buff, 0, n); } return str.toString(); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/help.txt000066400000000000000000000012161151645323700227070ustar00rootroot00000000000000You can try Ini, Reg and Options class features usgin this demo. In "data" tab you may type data file or load sample test data by pressing "L O A D" button. After typing or loading data, you can parse it by pressing "P A R S E" button. This will parse the data for the format you select. When parse successfully completed, a variable with name "data" will be defined in "Interpreter". You can copy/paste sample expressions from "tip" panel. In "Interpreter" panel you can find a BeanShell interpreter. BeanShell language is very close to Java, you can use it as Java interpreter. So in this panel you can test your parsed data object interactive mode. ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/ini-data.txt000066400000000000000000000007131151645323700234460ustar00rootroot00000000000000; bashful [bashful] weight = 45.7 height = 98.8 age = 67 homePage = http://snowwhite.tale/~bashful homeDir = /home/bashful ; doc [doc] weight = 49.5 height = 87.7 age = 63 homePage = http://doc.dwarfs homeDir = c:\Documents and Settings\doc ; dopey [dopey] weight = ${bashful/weight} height = ${doc/height} age = 23 homePage = http://dopey.snowwhite.tale/ homeDir = c:\\Documents and Settings\\dopey fortuneNumber = 11 fortuneNumber = 33 fortuneNumber = 55 ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/ini-tip.txt000066400000000000000000000004451151645323700233330ustar00rootroot00000000000000Here is some cut/paste code you can use in "Interpreter" tab to test test data file: print(data.size()); print(data.keySet()); print(data.get("doc").keySet()); print(data.get("doc","age",int.class)); for(String s : data.get("doc").keySet()) { print(s + " = " + data.get("doc",s)); } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/options-data.txt000066400000000000000000000014121151645323700243570ustar00rootroot00000000000000! dopey properties without prefix weight = ${bashful.weight} height = ${doc.height} age = 23 homePage = http://dopey.snowwhite.tale/ homeDir = c:\\Documents and Settings\\dopey fortuneNumber = 11 fortuneNumber = 33 fortuneNumber = 55 ! bashful bashful.weight = 45.7 bashful.height = 98.8 bashful.age = 67 bashful.homePage = http://snowwhite.tale/~bashful bashful.homeDir = /home/bashful ! doc doc.weight = 49.5 doc.height = 87.7 doc.age = 63 doc.homePage = http://doc.dwarfs doc.homeDir = c:\Documents and Settings\doc ! dopey dopey.weight = ${bashful.weight} dopey.height = ${doc.height} dopey.age = 23 dopey.homePage = http://dopey.snowwhite.tale/ dopey.homeDir = c:\\Documents and Settings\\dopey dopey.fortuneNumber = 11 dopey.fortuneNumber = 33 dopey.fortuneNumber = 55 ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/options-tip.txt000066400000000000000000000003601151645323700242430ustar00rootroot00000000000000Here is some cut/paste code you can use in "Interpreter" tab to test test data file: print(data.size()); print(data.keySet()); print(data.get("doc.age",int.class)); for(String s : data.keySet()) { print(s + " = " + data.get(s)); } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/reg-data.txt000066400000000000000000000032161151645323700234450ustar00rootroot00000000000000Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER] [HKEY_CURRENT_USER\Software] [HKEY_CURRENT_USER\Software\ini4j-test] [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs] ; bashful ; weight=45.7 ; age=67 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\bashful] @="bashful" "weight"=hex(2):34,00,35,00,2e,00,37,00,00,00 "height"="98.8" "age"=dword:00000043 "homePage"="http://snowwhite.tale/~bashful" "homeDir"="/home/bashful" ; doc ; weight=49.5 ; age=63 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\doc] @="doc" "weight"=hex(2):34,00,39,00,2e,00,35,00,00,00 "height"="87.7" "age"=dword:0000003f "homePage"="http://doc.dwarfs" "homeDir"="c:Documents and Settingsdoc" ; dopey ; weight=${HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\bashful/weight} ; age=23 ; fortuneNumber=11 ; fortuneNumber=33 ; fortuneNumber=55 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\dopey] @="dopey" "weight"=hex(2):24,00,7b,00,48,00,4b,00,45,00,59,00,5f,00,43,00,55,00,52,00,52,\ 00,45,00,4e,00,54,00,5f,00,55,00,53,00,45,00,52,00,5c,00,53,00,\ 6f,00,66,00,74,00,77,00,61,00,72,00,65,00,5c,00,69,00,6e,00,69,\ 00,34,00,6a,00,2d,00,74,00,65,00,73,00,74,00,5c,00,64,00,77,00,\ 61,00,72,00,66,00,73,00,5c,00,62,00,61,00,73,00,68,00,66,00,75,\ 00,6c,00,2f,00,77,00,65,00,69,00,67,00,68,00,74,00,7d,00,00,00 "height"="${HKEY_CURRENT_USER\\Software\\ini4j-test\\dwarfs\\doc/height}" "age"=dword:00000017 "homePage"="http://dopey.snowwhite.tale/" "homeDir"="c:\\Documents and Settings\\dopey" "fortuneNumber"=hex(7):31,00,31,00,00,00,32,00,32,00,00,00,35,00,35,00,00,00,\ 00,00 ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/demo/reg-tip.txt000066400000000000000000000004451151645323700233310ustar00rootroot00000000000000Here is some cut/paste code you can use in "Interpreter" tab to test test data file: print(data.size()); print(data.keySet()); print(data.get("doc").keySet()); print(data.get("doc","age",int.class)); for(String s : data.get("doc").keySet()) { print(s + " = " + data.get("doc",s)); } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/000077500000000000000000000000001151645323700215535ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/BeanEventSample.java000066400000000000000000000041641151645323700254340ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| --------------- //| BeanEventSample //| //|BeanEventSample //| //| A sample that demonstrates the handling of the bound bean properties. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| //| Source code for bean: {{{Dwarf.java.html}Dwarf}}, //| // //{ import org.ini4j.Ini; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.FileInputStream; public class BeanEventSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Ini ini = new Ini(new FileInputStream(filename)); Dwarf sneezy = ini.get("sneezy").as(Dwarf.class); sneezy.addPropertyChangeListener("age", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { System.out.println("property " + event.getPropertyName() + " change"); System.out.println(event.getOldValue() + " -> " + event.getNewValue()); } }); System.out.println("Sneezy's age: " + sneezy.getAge()); sneezy.setAge(44); System.out.println("Sneezy's age: " + sneezy.getAge()); } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/BeanSample.java000066400000000000000000000032751151645323700244340ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| ---------- //| BeanSample //| //|BeanSample //| //| Accessing the whole .ini file as Java Beans-style beans. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| //| Source code for beans: {{{Dwarf.java.html}Dwarf}}, //| {{{Dwarfs.java.html}Dwarfs}} //| // //{ import org.ini4j.Ini; import java.io.FileInputStream; public class BeanSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Dwarfs dwarfs = new Ini(new FileInputStream(filename)).as(Dwarfs.class); Dwarf happy = dwarfs.getHappy(); Dwarf doc = dwarfs.getDoc(); System.out.println("Happy's age: " + happy.getAge()); doc.setAge(44); System.out.println("Doc's age: " + doc.getAge()); } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/DumpSample.java000066400000000000000000000032661151645323700244740ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| ---------- //| DumpSample //| //|DumpSample //| //| Writing the .ini file received as input to the stand output. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| // //{ import org.ini4j.Ini; import java.io.FileReader; public class DumpSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Ini ini = new Ini(new FileReader(filename)); for (Ini.Section section : ini.values()) { System.out.println("[" + section.getName() + "]"); for (String option : section.keySet()) { System.out.println(option + " = " + section.fetch(option)); } System.out.println(); } } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/Dwarf.java000066400000000000000000000047261151645323700234720ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; import java.net.URI; // //| //| --------------- //| Dwarf interface //| //|Dwarf interface //| //| This is a very simple bean interface with a few getter and setter. Some of //| the properties are java primitive types. The <<>> property has a //| complex type (java.net.URI). It is not a problem for \[ini4j\] to do the //| required type conversion automatically between java.lang.String and the tpye //| of the given property. The <<>> property is indexed, just to //| show you may use indexed properties as well. //| // //{ public interface Dwarf { String PROP_AGE = "age"; String PROP_FORTUNE_NUMBER = "fortuneNumber"; String PROP_HEIGHT = "height"; String PROP_HOME_DIR = "homeDir"; String PROP_HOME_PAGE = "homePage"; String PROP_WEIGHT = "weight"; int getAge(); void setAge(int age); int[] getFortuneNumber(); void setFortuneNumber(int[] value); double getHeight(); void setHeight(double height) throws PropertyVetoException; String getHomeDir(); void setHomeDir(String dir); URI getHomePage(); void setHomePage(URI location); double getWeight(); void setWeight(double weight); void addPropertyChangeListener(String property, PropertyChangeListener listener); void addVetoableChangeListener(String property, VetoableChangeListener listener); boolean hasAge(); boolean hasHeight(); boolean hasHomePage(); boolean hasWeight(); void removePropertyChangeListener(String property, PropertyChangeListener listener); void removeVetoableChangeListener(String property, VetoableChangeListener listener); } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/DwarfBean.java000066400000000000000000000101001151645323700242370ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; import java.beans.VetoableChangeSupport; import java.net.URI; // //| //| --------------- //| DwarfBean class //| //|DwarfBean class //| // //{ public class DwarfBean implements Dwarf { private int _age; private int[] _fortuneNumber; private double _height; private String _homeDir; private URI _homePage; private final PropertyChangeSupport _pcSupport; private final VetoableChangeSupport _vcSupport; private double _weight; public DwarfBean() { _pcSupport = new PropertyChangeSupport(this); _vcSupport = new VetoableChangeSupport(this); } @Override public int getAge() { return _age; } @Override public void setAge(int value) { int old = _age; _age = value; _pcSupport.firePropertyChange(PROP_AGE, old, value); } @Override public int[] getFortuneNumber() { return _fortuneNumber; } @Override public void setFortuneNumber(int[] value) { _fortuneNumber = value; } @Override public double getHeight() { return _height; } @Override public void setHeight(double value) throws PropertyVetoException { _vcSupport.fireVetoableChange(PROP_HEIGHT, _height, value); double old = _height; _height = value; _pcSupport.firePropertyChange(PROP_HEIGHT, old, value); } @Override public String getHomeDir() { return _homeDir; } @Override public void setHomeDir(String value) { String old = _homeDir; _homeDir = value; _pcSupport.firePropertyChange(PROP_HOME_DIR, old, value); } @Override public URI getHomePage() { return _homePage; } @Override public void setHomePage(URI value) { URI old = _homePage; _homePage = value; _pcSupport.firePropertyChange(PROP_HOME_PAGE, old, value); } @Override public double getWeight() { return _weight; } @Override public void setWeight(double value) { double old = _weight; _weight = value; _pcSupport.firePropertyChange(PROP_WEIGHT, old, value); } @Override public void addPropertyChangeListener(String property, PropertyChangeListener listener) { _pcSupport.addPropertyChangeListener(property, listener); } @Override public void addVetoableChangeListener(String property, VetoableChangeListener listener) { _vcSupport.addVetoableChangeListener(property, listener); } @Override public boolean hasAge() { return _age != 0; } @Override public boolean hasHeight() { return _height != 0.0; } @Override public boolean hasHomePage() { return _homePage != null; } @Override public boolean hasWeight() { return _weight != 0.0; } @Override public void removePropertyChangeListener(String property, PropertyChangeListener listener) { _pcSupport.removePropertyChangeListener(property, listener); } @Override public void removeVetoableChangeListener(String property, VetoableChangeListener listener) { _vcSupport.removeVetoableChangeListener(property, listener); } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/Dwarfs.java000066400000000000000000000023431151645323700236460ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| --------------- //| Dwarfs interface //| //|Dwarfs interface //| // //{ public interface Dwarfs { String PROP_BASHFUL = "bashful"; String PROP_DOC = "doc"; String PROP_DOPEY = "dopey"; String PROP_GRUMPY = "grumpy"; String PROP_HAPPY = "happy"; String PROP_SLEEPY = "sleepy"; String PROP_SNEEZY = "sneezy"; Dwarf getBashful(); Dwarf getDoc(); Dwarf getDopey(); Dwarf getGrumpy(); Dwarf getHappy(); Dwarf getSleepy(); Dwarf getSneezy(); } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/DwarfsBean.java000066400000000000000000000040751151645323700244400ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| ---------------- //| DwarfsBean class //| //|DwarfsBean class //| // //{ public class DwarfsBean implements Dwarfs { private Dwarf _bashful; private Dwarf _doc; private Dwarf _dopey; private Dwarf _grumpy; private Dwarf _happy; private Dwarf _sleepy; private Dwarf _sneezy; @Override public Dwarf getBashful() { return _bashful; } public void setBashful(Dwarf value) { _bashful = value; } @Override public Dwarf getDoc() { return _doc; } public void setDoc(Dwarf value) { _doc = value; } @Override public Dwarf getDopey() { return _dopey; } public void setDopey(Dwarf value) { _dopey = value; } @Override public Dwarf getGrumpy() { return _grumpy; } public void setGrumpy(Dwarf value) { _grumpy = value; } @Override public Dwarf getHappy() { return _happy; } public void setHappy(Dwarf value) { _happy = value; } @Override public Dwarf getSleepy() { return _sleepy; } public void setSleepy(Dwarf value) { _sleepy = value; } @Override public Dwarf getSneezy() { return _sneezy; } public void setSneezy(Dwarf value) { _sneezy = value; } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/FromSample.java000066400000000000000000000030201151645323700244560ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| ---------- //| FromSample //| //|FromSample //| //| Marshall Java Beans to Ini.Section. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| //| Source code for beans: {{{Dwarf.java.html}Dwarf}}, //| {{{DwarfBean.java.html}DwarfBean}} //| // //{ import org.ini4j.Ini; import java.net.URI; public class FromSample { public static void main(String[] args) throws Exception { Ini ini = new Ini(); DwarfBean doc = new DwarfBean(); doc.setAge(123); doc.setHeight(111); doc.setWeight(22.1); doc.setHomePage(new URI("http://foo.bar")); ini.add("doc").from(doc); ini.store(System.out); } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/IniSample.java000066400000000000000000000031751151645323700243050ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| --------- //| IniSample //| //|IniSample //| //| The [ini4j] library has a simple API: the .ini file is a map of sections, while the section is a map of options. //| Due to the Java 1.5 generics these are type safe maps. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| // //{ import org.ini4j.Ini; import java.io.FileReader; public class IniSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Ini ini = new Ini(new FileReader(filename)); for (String key : ini.get("sleepy").keySet()) { System.out.println("sleepy/" + key + " = " + ini.get("sleepy").fetch(key)); } } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/ListenerSample.java000066400000000000000000000046021151645323700253470ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| -------------- //| ListenerSample //| //|ListenerSample //| //| This advanced sample presents the event-controlled usage. The \[ini4j\] //| library fully supports the events defined in Preferences API. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| // //{ import org.ini4j.IniPreferences; import java.io.FileInputStream; import java.util.prefs.*; public class ListenerSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Preferences prefs = new IniPreferences(new FileInputStream(filename)); Listener listener = new Listener(); prefs.addNodeChangeListener(listener); Preferences jerry = prefs.node("jerry"); jerry.addPreferenceChangeListener(listener); jerry.put("color", "blue"); jerry.put("color", "gray"); jerry.putInt("age", 2); } static class Listener implements NodeChangeListener, PreferenceChangeListener { public void childAdded(NodeChangeEvent event) { System.out.println("node added: " + event.getChild().name()); } public void childRemoved(NodeChangeEvent event) { System.out.println("node removed: " + event.getChild().name()); } public void preferenceChange(PreferenceChangeEvent event) { System.out.println("preference changed: " + event.getKey() + " = " + event.getNewValue()); } } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/NoImportSample.java000066400000000000000000000034031151645323700253270ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| -------------- //| NoImportSample //| //|NoImportSample //| //| Using [ini4j] without class level dependency (no Java imports). You may use //| \[ini4j\] library as full Preferences implementation for user and system //| root. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| // //{ import java.util.prefs.Preferences; public class NoImportSample { static { System.setProperty("java.util.prefs.PreferencesFactory", "org.ini4j.IniPreferencesFactory"); // you should set file:///... like URL as property value to work System.setProperty("org.ini4j.prefs.user", "org/ini4j/sample/dwarfs.ini"); } public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userRoot(); System.out.println("grumpy/homePage: " + prefs.node("grumpy").get("homePage", null)); System.out.println(prefs.getClass()); } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/PyReadSample.java000066400000000000000000000033011151645323700247410ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| ---------------------------------- //| Using Python like ConfigParser API //| //|Using Python like ConfigParser API //| //| For Python programmers the simlest API to use is ConfigParser. //| This sample presents accessing .ini files as Python ConfigParser objects. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs-py.ini.html}dwarfs-py.ini}} //| file. //| // //{ import org.ini4j.ConfigParser; public class PyReadSample { public static final String FILENAME = "dwarfs-py.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; ConfigParser config = new ConfigParser(); config.read(filename); for (String key : config.options("sleepy")) { System.out.println("sleepy/" + key + " = " + config.get("sleepy", key)); } } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/ReadPrimitiveSample.java000066400000000000000000000033051151645323700263250ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| ------------------- //| ReadPrimitiveSample //| //|ReadPrimitiveSample //| //| Reading some Java primitive type values. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| //{ // import org.ini4j.Ini; import org.ini4j.IniPreferences; import java.io.File; import java.util.prefs.Preferences; public class ReadPrimitiveSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Preferences prefs = new IniPreferences(new Ini(new File(filename))); Preferences dopey = prefs.node("dopey"); int age = dopey.getInt("age", 0); float weight = dopey.getFloat("weight", 0); System.out.println("dopey/age: " + age); System.out.println("dopey/weight: " + weight); } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/ReadStringSample.java000066400000000000000000000030541151645323700256240ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| ---------------- //| ReadStringSample //| //|ReadStringSample //| //| This sample presents accessing String type values. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| // //{ import org.ini4j.Ini; import org.ini4j.IniPreferences; import java.io.File; import java.util.prefs.Preferences; public class ReadStringSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Preferences prefs = new IniPreferences(new Ini(new File(filename))); System.out.println("grumpy/homePage: " + prefs.node("grumpy").get("homePage", null)); } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/StreamSample.java000066400000000000000000000034101151645323700250110ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| ------------ //| StreamSample //| //|StreamSample //| //| This sample demonstrates that the Preferences API may be used without a //| filesystem access. In this case, naturally, there's no way of saving the //| altered settings, they may only be accessed in the memory. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| // //{ import org.ini4j.IniPreferences; import java.io.FileInputStream; import java.util.prefs.Preferences; public class StreamSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Preferences prefs = new IniPreferences(new FileInputStream(filename)); for (String key : prefs.node("sleepy").keys()) { System.out.println("sleepy/" + key + " = " + prefs.node("sleepy").get(key, null)); } } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/ToSample.java000066400000000000000000000032301151645323700241400ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; // //| //| -------- //| ToSample //| //|ToSample //| //| Unmarshall Java Beans from Ini.Section. //| //| This sample program expect the .ini file as a command line argument. //| If there is no such argument, it use the {{{dwarfs.ini.html}dwarfs.ini}} file. //| //| Source code for beans: {{{Dwarf.java.html}Dwarf}}, //| {{{DwarfBean.java.html}DwarfBean}} //| // //{ import org.ini4j.Ini; import java.io.FileInputStream; public class ToSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Ini ini = new Ini(new FileInputStream(filename)); DwarfBean happy = new DwarfBean(); ini.get("happy").to(happy); System.out.println("Happy's age: " + happy.getAge()); System.out.println("Happy's homePage: " + happy.getHomePage()); } } //} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/dwarfs-py.ini000066400000000000000000000033351151645323700241740ustar00rootroot00000000000000; Copyright 2005,2009 Ivan SZKIBA ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. ; You may obtain a copy of the License at ; ; http://www.apache.org/licenses/LICENSE-2.0 ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. ;| ---------- ;| dwarfs.ini ;| ;|dwarfs-py.ini ;| ;| Common .ini file for sample programs using Python like ConfigParser class ;| ;{ ; bashful [bashful] weight = 45.7 height = 98.8 age = 67 homePage = http://snowwhite.tale/~bashful homeDir = /home/bashful ; doc [doc] weight = 49.5 height = 87.7 age = 63 homePage = http://doc.dwarfs homeDir = c:Documents and Settingsdoc ; dopey [dopey] weight = %(_weight) height = %(_height) age = 23 homePage = http://dopey.snowwhite.tale/ homeDir = c:\Documents and Settings\dopey ; grumpy [grumpy] weight = 65.3 height = %(_height) age = 76 homePage = http://snowwhite.tale/~grumpy/ homeDir = /home/grumpy ; happy [happy] weight = 56.4 height = 77.66 age = 99 homePage = dummy homeDir = /home/happy ; sleepy [sleepy] name=sleepy weight = 76.11 height = %(_height)8 age = 121 homePage = http://snowwhite.tale/~%(name) homeDir = /home/%(name) ; sneezy [sneezy] weight = 69.7 height = 76.88 age = 64 homePage = %(_site)/~sneezy homeDir = /home/sneezy ; happy again [happy] homePage = http://happy.smurf [default] _site = http://happy.smurf _age = 99 _weight = 45.7 _height = 87.7 ;} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/dwarfs.ini000066400000000000000000000034041151645323700235430ustar00rootroot00000000000000; Copyright 2005,2009 Ivan SZKIBA ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. ; You may obtain a copy of the License at ; ; http://www.apache.org/licenses/LICENSE-2.0 ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. ;| ---------- ;| dwarfs.ini ;| ;|dwarfs.ini ;| ;| Common .ini file for samples ;{ ; bashful [bashful] weight = 45.7 height = 98.8 age = 67 homePage = http://snowwhite.tale/~bashful homeDir = /home/bashful ; doc [doc] weight = 49.5 height = 87.7 age = 63 homePage = http://doc.dwarfs homeDir = c:\Documents and Settings\doc ; dopey [dopey] weight = ${bashful/weight} height = ${doc/height} age = 23 homePage = http://dopey.snowwhite.tale/ homeDir = c:\\Documents and Settings\\dopey fortuneNumber = 11 fortuneNumber = 33 fortuneNumber = 55 ; grumpy [grumpy] weight = 65.3 height = ${dopey/height} age = 76 homePage = http://snowwhite.tale/~grumpy/ homeDir = /home/grumpy ; happy [happy] weight = 56.4 height = 77.66 age = 99 homePage = dummy homeDir = /home/happy ; sleepy [sleepy] weight = 76.11 height = ${doc/height}8 age = 121 homePage = http://snowwhite.tale/~sleepy homeDir = /home/sleepy fortuneNumber = 99 ; sneezy [sneezy] weight = 69.7 height = 76.88 age = 64 homePage = ${happy/homePage}/~sneezy homeDir = /home/sneezy fortuneNumber = 11 fortuneNumber = 22 fortuneNumber = 33 fortuneNumber = 44 ; happy again [happy] homePage = http://happy.smurf ;} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/dwarfs.opt000066400000000000000000000044041151645323700235670ustar00rootroot00000000000000# Copyright 2005,2009 Ivan SZKIBA # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #| ---------- #| dwarfs.opt #| #|dwarfs.opt #| #| Common .opt file for tutorials #| #{ ! ! Dopey properties without prefix ! weight = ${bashful.weight} height = ${doc.height} age = 23 homePage = http://dopey.snowwhite.tale/ homeDir = c:\\Documents and Settings\\dopey fortuneNumber = 11 fortuneNumber = 33 fortuneNumber = 55 ! ! dwarf properties prefixed with dwarf names ! ! bashful bashful.weight = 45.7 bashful.height = 98.8 bashful.age = 67 bashful.homePage = http://snowwhite.tale/~bashful bashful.homeDir = /home/bashful ! doc doc.weight = 49.5 doc.height = 87.7 doc.age = 63 doc.homePage = http://doc.dwarfs doc.homeDir = c:\Documents and Settings\doc ! dopey dopey.weight = ${bashful.weight} dopey.height = ${doc.height} dopey.age = 23 dopey.homePage = http://dopey.snowwhite.tale/ dopey.homeDir = c:\\Documents and Settings\\dopey dopey.fortuneNumber = 11 dopey.fortuneNumber = 33 dopey.fortuneNumber = 55 ! grumpy grumpy.weight = 65.3 grumpy.height = ${dopey.height} grumpy.age = 76 grumpy.homePage = http://snowwhite.tale/~grumpy/ grumpy.homeDir = /home/grumpy ! happy happy.weight = 56.4 happy.height = 77.66 happy.age = 99 happy.homePage = dummy happy.homeDir = /home/happy ! sleepy sleepy.weight = 76.11 sleepy.height = ${doc.height}8 sleepy.age = 121 sleepy.homePage = http://snowwhite.tale/~sleepy sleepy.homeDir = /home/sleepy sleepy.fortuneNumber = 99 ! sneezy sneezy.weight = 69.7 sneezy.height = 76.88 sneezy.age = 64 sneezy.homePage = ${happy.homePage}/~sneezy sneezy.homeDir = /home/sneezy sneezy.fortuneNumber = 11 sneezy.fortuneNumber = 22 sneezy.fortuneNumber = 33 sneezy.fortuneNumber = 44 ! happy again happy.homePage = http://happy.smurf #} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/dwarfs.reg000066400000000000000000000201141151645323700235360ustar00rootroot00000000000000Windows Registry Editor Version 5.00 ;| ---------- ;| dwarfs.reg ;| ;|dwarfs.reg ;| ;| Common .reg file for samples. The values uses many different registry types, just ;| for demonstrating these. So "weight" property allways stored as REG_EXPAND_SZ, the ;| "age" property stored as REG_DWORD, and the "fortuneNumber" stored as REG_MULTI_SZ. ;| Don't worry if you not familiar with this terms, probably simple string values ;| will work for you. ;| ;| This file stored in UTF-16LE (Java charset name: "UnicodeLittle") encoding and the first line allways: ;| ;|+------------------+ ;|Windows Registry Editor Version 5.00 ;|+------------------+ ;| ;| Next few lines just about tree structure ;| ;{ [HKEY_CURRENT_USER] [HKEY_CURRENT_USER\Software] [HKEY_CURRENT_USER\Software\ini4j-test] [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs] ;} ;| ;| And the rest sections is the dwarfs. There is some coment before ;| raw registry values to help reading cryptic hexadecimal values. ;| ;{ ; bashful ; weight=45.7 ; age=67 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\bashful] @="bashful" "weight"=hex(2):34,00,35,00,2e,00,37,00,00,00 "height"="98.8" "age"=dword:00000043 "homePage"="http://snowwhite.tale/~bashful" "homeDir"="/home/bashful" ; doc ; weight=49.5 ; age=63 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\doc] @="doc" "weight"=hex(2):34,00,39,00,2e,00,35,00,00,00 "height"="87.7" "age"=dword:0000003f "homePage"="http://doc.dwarfs" "homeDir"="c:Documents and Settingsdoc" ; dopey ; weight=${HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\bashful/weight} ; age=23 ; fortuneNumber=11 ; fortuneNumber=33 ; fortuneNumber=55 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\dopey] @="dopey" "weight"=hex(2):24,00,7b,00,48,00,4b,00,45,00,59,00,5f,00,43,00,55,00,52,00,52,\ 00,45,00,4e,00,54,00,5f,00,55,00,53,00,45,00,52,00,5c,00,53,00,\ 6f,00,66,00,74,00,77,00,61,00,72,00,65,00,5c,00,69,00,6e,00,69,\ 00,34,00,6a,00,2d,00,74,00,65,00,73,00,74,00,5c,00,64,00,77,00,\ 61,00,72,00,66,00,73,00,5c,00,62,00,61,00,73,00,68,00,66,00,75,\ 00,6c,00,2f,00,77,00,65,00,69,00,67,00,68,00,74,00,7d,00,00,00 "height"="${HKEY_CURRENT_USER\\Software\\ini4j-test\\dwarfs\\doc/height}" "age"=dword:00000017 "homePage"="http://dopey.snowwhite.tale/" "homeDir"="c:\\Documents and Settings\\dopey" "fortuneNumber"=hex(7):31,00,31,00,00,00,32,00,32,00,00,00,35,00,35,00,00,00,\ 00,00 ; grumpy ; weight=65.3 ; age=76 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\grumpy] @="grumpy" "weight"=hex(2):36,00,35,00,2e,00,33,00,00,00 "height"="${HKEY_CURRENT_USER\\Software\\ini4j-test\\dwarfs\\dopey/height}" "age"=dword:0000004c "homePage"="http://snowwhite.tale/~grumpy/" "homeDir"="/home/grumpy" ; happy ; weight=56.4 ; age=99 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\happy] @="happy" "weight"=hex(2):35,00,36,00,2e,00,34,00,00,00 "height"="77.66" "age"=dword:00000063 "homePage"="http://happy.smurf" "homeDir"="/home/happy" ; sleepy ; weight=76.11 ; age=121 ; fortuneNumber=99 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\sleepy] @="sleepy" "weight"=hex(2):37,00,36,00,2e,00,31,00,31,00,00,00 "height"="${HKEY_CURRENT_USER\\Software\\ini4j-test\\dwarfs\\doc/height}8" "age"=dword:00000079 "homePage"="http://snowwhite.tale/~sleepy" "homeDir"="/home/sleepy" "fortuneNumber"=hex(7):39,00,39,00,00,00,00,00 ; sneezy ; weight=69.7 ; age=64 ; fortuneNumber=11 ; fortuneNumber=22 ; fortuneNumber=33 ; fortuneNumber=44 [HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\sneezy] @="sneezy" "weight"=hex(2):36,00,39,00,2e,00,37,00,00,00 "height"="76.88" "age"=dword:00000040 "homePage"="${HKEY_CURRENT_USER\\Software\\ini4j-test\\dwarfs\\happy/homePage}/~sneezy" "homeDir"="/home/sneezy" "fortuneNumber"=hex(7):31,00,31,00,00,00,32,00,32,00,00,00,33,00,33,00,00,00,\ 34,00,34,00,00,00,00,00 ;} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/package-info.java000066400000000000000000000020061151645323700247400ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.sample; //| //| ------- //| Samples //| //|Samples //| //| The simple (but useful) samples you can find here illustrate the usage of [ini4j]. //| These are small, independent programs that may be translates and run. //| The build process of [ini4j] guarantees compilability and runability, since no //| distribution may be created without compiling and running these programs. //| ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/sample/tale.ini000066400000000000000000000035331151645323700232050ustar00rootroot00000000000000; Copyright 2005,2009 Ivan SZKIBA ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. ; You may obtain a copy of the License at ; ; http://www.apache.org/licenses/LICENSE-2.0 ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. ;| ---------- ;| tale.ini ;| ;|tale.ini ;| ;| Common .ini file for samples ;{ ; bashful [dwarfs/bashful] weight = 45.7 height = 98.8 age = 67 homePage = http://snowwhite.tale/~bashful homeDir = /home/bashful ; doc [dwarfs/doc] weight = 49.5 height = 87.7 age = 63 homePage = http://doc.dwarfs homeDir = c:\Documents and Settings\doc ; dopey [dwarfs/dopey] weight = ${dwarfs/bashful/weight} height = ${dwarfs/doc/height} age = 23 homePage = http://dopey.snowwhite.tale/ homeDir = c:\\Documents and Settings\\dopey fortuneNumber = 11 fortuneNumber = 33 fortuneNumber = 55 ; grumpy [dwarfs/grumpy] weight = 65.3 height = ${dwarfs/dopey/height} age = 76 homePage = http://snowwhite.tale/~grumpy/ homeDir = /home/grumpy ; happy [dwarfs/happy] weight = 56.4 height = 77.66 age = 99 homePage = dummy homeDir = /home/happy ; sleepy [dwarfs/sleepy] weight = 76.11 height = ${dwarfs/doc/height}8 age = 121 homePage = http://snowwhite.tale/~sleepy homeDir = /home/sleepy fortuneNumber = 99 ; sneezy [dwarfs/sneezy] weight = 69.7 height = 76.88 age = 64 homePage = ${dwarfs/happy/homePage}/~sneezy homeDir = /home/sneezy fortuneNumber = 11 fortuneNumber = 22 fortuneNumber = 33 fortuneNumber = 44 ; happy again [dwarfs/happy] homePage = http://happy.smurf ;} ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/000077500000000000000000000000001151645323700210655ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/AbstractBeanInvocationHandlerTest.java000066400000000000000000000211221151645323700304470ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Ini4jCase; import org.ini4j.sample.Dwarf; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Test; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; import java.lang.reflect.Proxy; import java.util.HashMap; import java.util.Map; public class AbstractBeanInvocationHandlerTest extends Ini4jCase { private static final String PROP_AGE = Dwarf.PROP_AGE; private static final String PROP_HEIGHT = Dwarf.PROP_HEIGHT; @Test public void testGetProperty() throws Exception { Map map = new HashMap(); MapBeanHandler handler = new MapBeanHandler(map); Integer i = new Integer(23); map.put(PROP_AGE, "23"); assertEquals(i, (Integer) handler.getProperty(PROP_AGE, Integer.class)); assertTrue(handler.hasProperty(PROP_AGE)); assertFalse(handler.hasProperty(null)); map.put(PROP_AGE, "?."); assertEquals(null, handler.getProperty(PROP_AGE, Integer.class)); assertEquals("?.", (String) handler.getProperty(PROP_AGE, String.class)); handler = new MapBeanHandler(map) { @Override protected boolean hasPropertySpi(String property) { throw new UnsupportedOperationException(); } }; assertFalse(handler.hasProperty(PROP_AGE)); } @Test public void testGetSetHas() throws Exception { Dwarf dwarf = MapBeanHandler.newBean(Dwarf.class); assertFalse(dwarf.hasAge()); dwarf.setAge(23); assertEquals(23, dwarf.getAge()); assertNull(dwarf.getHomeDir()); dwarf.setHomeDir("dummy"); } @Test public void testMisc() throws Exception { Map map = new HashMap(); MapBeanHandler handler = new MapBeanHandler(map); Dummy dummy = (Dummy) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Dummy.class }, handler); assertNull(handler.getProxy()); // non existend method calls dummy.dummy(); dummy.addDummy(); dummy.removeDummy(); // boolean invoke map.put("dummy", "true"); assertTrue(dummy.isDummy()); assertSame(dummy, handler.getProxy()); // subclass should call fire methods any time // so null support reference should be not a problem handler.firePropertyChange(PROP_AGE, Integer.valueOf(1), Integer.valueOf(2)); handler.fireVetoableChange(PROP_AGE, Integer.valueOf(1), Integer.valueOf(2)); } @Test public void testPropertyChangeListener() throws Exception { class Listener implements PropertyChangeListener { int _counter; String _property; PropertyChangeEvent _event; Listener(String property) { _property = property; } @Override public void propertyChange(PropertyChangeEvent event) { if (_property.equals(event.getPropertyName())) { _counter++; _event = event; } } } Dwarf d = MapBeanHandler.newBean(Dwarf.class); Listener l = new Listener(PROP_AGE); // test add and remove: invalid state should be OK d.removePropertyChangeListener(PROP_AGE, l); d.addPropertyChangeListener(PROP_AGE, l); d.addPropertyChangeListener(PROP_AGE, l); d.removePropertyChangeListener(PROP_AGE, l); d.removePropertyChangeListener(PROP_AGE, l); // check listener call d.setAge(23); d.addPropertyChangeListener(PROP_AGE, l); d.setAge(45); assertNotNull(l._event); assertEquals(23, ((Integer) l._event.getOldValue()).intValue()); assertEquals(45, ((Integer) l._event.getNewValue()).intValue()); // check listener call again d.setAge(2); d.setWeight(23.4); assertEquals(2, l._counter); d.removePropertyChangeListener(PROP_AGE, l); // should not run listener d.setAge(44); assertEquals(2, l._counter); // test remove listener> invalid state should be OK d.removePropertyChangeListener(PROP_AGE, l); } @Test public void testSetProperty() throws Exception { Map map = new HashMap(); MapBeanHandler handler = new MapBeanHandler(map); // very special case: set string property to non stirng value implies string conversion handler.setProperty(PROP_AGE, new Integer(23), String.class); assertEquals("23", handler.getProperty(PROP_AGE, String.class)); } @Test public void testVetoableChangeListener() throws Exception { class HeightCheck implements VetoableChangeListener { @Override public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException { if (PROP_HEIGHT.equals(event.getPropertyName())) { if (((Double) event.getNewValue()) < 0.0) { throw new PropertyVetoException("invalid value", event); } } } } Dwarf d = MapBeanHandler.newBean(Dwarf.class); HeightCheck l = new HeightCheck(); // test add and remove: invalid state should be OK d.removeVetoableChangeListener(PROP_HEIGHT, l); d.addVetoableChangeListener(PROP_HEIGHT, l); d.addVetoableChangeListener(PROP_HEIGHT, l); d.removeVetoableChangeListener(PROP_HEIGHT, l); d.removeVetoableChangeListener(PROP_HEIGHT, l); // set invalid value without lsitener d.setHeight(-2.0); d.setHeight(33.0); d.addVetoableChangeListener(PROP_HEIGHT, l); // set invalid value with listener try { d.setHeight(-3.4); fail(); } catch (PropertyVetoException x) { assertEquals(33.0, d.getHeight(), Helper.DELTA); } // set valid value d.setHeight(44.0); assertEquals(44.0, d.getHeight(), Helper.DELTA); d.removeVetoableChangeListener(PROP_HEIGHT, l); // set invalid value without lsitener d.setHeight(-4.0); assertEquals(-4.0, d.getHeight(), Helper.DELTA); // test remove: invalid state should be OK d.removeVetoableChangeListener(PROP_HEIGHT, l); } static interface Dummy { boolean isDummy(); void addDummy(); void dummy(); void removeDummy(); } static class MapBeanHandler extends AbstractBeanInvocationHandler { private Map _map; MapBeanHandler(Map map) { super(); _map = map; } protected static T newBean(Class clazz) { return newBean(clazz, new HashMap()); } protected static T newBean(Class clazz, Map map) { return clazz.cast(Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, new MapBeanHandler(map))); } @Override protected Object getPropertySpi(String property, Class clazz) { return _map.get(property); } @Override protected void setPropertySpi(String property, Object value, Class clazz) { _map.put(property, value.toString()); } @Override protected boolean hasPropertySpi(String property) { return _map.containsKey(property); } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/BeanToolTest.java000066400000000000000000000206611151645323700243000ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.BasicOptionMapGate; import org.ini4j.Ini4jCase; import org.ini4j.sample.Dwarf; import org.ini4j.sample.DwarfBean; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import org.junit.Before; import org.junit.Test; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URL; import java.util.TimeZone; public class BeanToolTest extends Ini4jCase { protected BeanTool instance; @Before @Override public void setUp() throws Exception { super.setUp(); instance = BeanTool.getInstance(); } @Test public void testInject() throws Exception { testInject(null); testInject("dummy"); } @Test public void testInjectIllegalArgument1() throws Exception { TestMap map = new TestMap(); try { instance.inject(map.newBeanAccess(), new BadBean()); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @Test public void testInjectIllegalArgument2() throws Exception { TestMap map = new TestMap(); map.put("name", "bad"); try { instance.inject(new BadBean(), map.newBeanAccess()); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @SuppressWarnings("empty-statement") @Test public void testParse() throws Exception { String input = "6"; int value = 6; assertEquals(value, instance.parse(input, byte.class).byteValue()); assertEquals(value, instance.parse(input, short.class).shortValue()); assertEquals(value, instance.parse(input, int.class).intValue()); assertEquals(value, instance.parse(input, long.class).longValue()); assertEquals((float) value, instance.parse(input, float.class).floatValue(), Helper.DELTA); assertEquals((double) value, instance.parse(input, double.class).doubleValue(), Helper.DELTA); assertFalse(instance.parse(input, boolean.class)); assertEquals('6', instance.parse(input, char.class).charValue()); // parse null mean zero assertEquals(0, instance.parse(null, byte.class).byteValue()); // parse to null class mean exception try { instance.parse(input, null); fail(); } catch (IllegalArgumentException x) { ; } // invalid primitive value mean exception try { instance.parse("?", int.class); fail(); } catch (IllegalArgumentException x) { ; } // standard, but not primitive types assertSame(input, instance.parse(input, String.class)); assertEquals(new Character('6'), instance.parse(input, Character.class)); assertEquals(new Byte(input), instance.parse(input, Byte.class)); // special values input = "http://www.ini4j.org"; assertEquals(new URL(input), instance.parse(input, URL.class)); assertEquals(new URI(input), instance.parse(input, URI.class)); assertEquals(new File(input), instance.parse(input, File.class)); input = "Europe/Budapest"; assertEquals(input, instance.parse(input, TimeZone.class).getID()); input = "java.lang.String"; assertEquals(String.class, instance.parse(input, Class.class)); // invalid value should throw IllegalArgumentException try { instance.parse("", URL.class); } catch (IllegalArgumentException x) { ; } } @Test public void testSetGet() throws Exception { TestMap map = new TestMap(); Dwarf proxy = instance.proxy(Dwarf.class, map.newBeanAccess()); assertNull(proxy.getHomeDir()); assertFalse(proxy.hasHomePage()); assertNull(proxy.getFortuneNumber()); proxy.setAge(DwarfsData.sneezy.age); proxy.setHeight(DwarfsData.sneezy.height); proxy.setWeight(DwarfsData.sneezy.weight); proxy.setHomePage(DwarfsData.sneezy.homePage); proxy.setHomeDir(DwarfsData.sneezy.homeDir); proxy.setFortuneNumber(DwarfsData.sneezy.fortuneNumber); Helper.assertEquals(DwarfsData.sneezy, proxy); assertArrayEquals(DwarfsData.sneezy.fortuneNumber, proxy.getFortuneNumber()); } @Test public void testSingleton() throws Exception { assertEquals(BeanTool.class, BeanTool.getInstance().getClass()); } @Test public void testZero() throws Exception { assertEquals(null, instance.zero(Object.class)); assertEquals(0, instance.zero(byte.class).byteValue()); assertEquals(0, instance.zero(short.class).shortValue()); assertEquals(0, instance.zero(int.class).intValue()); assertEquals(0, instance.zero(long.class).longValue()); assertEquals(0.0f, instance.zero(float.class).floatValue(), Helper.DELTA); assertEquals(0.0, instance.zero(double.class).doubleValue(), Helper.DELTA); assertNotNull((instance.zero(boolean.class))); assertFalse(instance.zero(boolean.class)); assertEquals('\0', instance.zero(char.class).charValue()); } protected void testInject(String prefix) throws Exception { String p = (prefix == null) ? "" : prefix; Dwarf bean = new DwarfBean(); bean.setAge(23); bean.setHeight(5.3); URI uri = new URI("http://www.ini4j.org"); bean.setHomePage(uri); String dir = "/home/happy"; bean.setHomeDir(dir); bean.setFortuneNumber(new int[] { 1, 2, 3 }); TestMap map = new TestMap(); instance.inject(map.newBeanAccess(prefix), bean); assertEquals(6, map.size()); assertEquals("23", map.get(p + Dwarf.PROP_AGE)); assertEquals("5.3", map.get(p + Dwarf.PROP_HEIGHT)); assertEquals(uri.toString(), map.get(p + Dwarf.PROP_HOME_PAGE)); assertEquals(dir, map.get(p + Dwarf.PROP_HOME_DIR)); assertEquals(3, map.length(p + Dwarf.PROP_FORTUNE_NUMBER)); assertEquals("1", map.get(p + Dwarf.PROP_FORTUNE_NUMBER, 0)); assertEquals("2", map.get(p + Dwarf.PROP_FORTUNE_NUMBER, 1)); assertEquals("3", map.get(p + Dwarf.PROP_FORTUNE_NUMBER, 2)); bean.setAge(0); bean.setHeight(0); bean.setHomePage(null); instance.inject(bean, map.newBeanAccess(prefix)); assertEquals(23, bean.getAge()); assertEquals(5.3, bean.getHeight(), Helper.DELTA); assertEquals(uri, bean.getHomePage()); assertEquals(dir, bean.getHomeDir()); assertArrayEquals(new int[] { 1, 2, 3 }, bean.getFortuneNumber()); // // bean interface // Dwarf proxy = instance.proxy(Dwarf.class, map.newBeanAccess(prefix)); assertEquals(23, proxy.getAge()); assertEquals(5.3, proxy.getHeight(), Helper.DELTA); assertEquals(uri, proxy.getHomePage()); assertEquals(dir, proxy.getHomeDir()); assertArrayEquals(new int[] { 1, 2, 3 }, proxy.getFortuneNumber()); } static class TestMap extends BasicOptionMapGate { private static final long serialVersionUID = 4818386732025655044L; } private static class BadBean { public String getName() throws IOException { throw new IOException(); } public void setName(String value) throws IOException { throw new IOException(); } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/EscapeToolTest.java000066400000000000000000000062341151645323700246330ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Ini4jCase; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import org.junit.Before; import org.junit.Test; public class EscapeToolTest extends Ini4jCase { private static final String VALUE1 = "simple"; private static final String ESCAPE1 = "simple"; private static final String VALUE2 = "Iv\ufffdn"; private static final String ESCAPE2 = "Iv\\ufffdn"; private static final String VALUE3 = "1\t2\n3\f4\b5\r6"; private static final String ESCAPE3 = "1\\t2\\n3\\f4\\b5\\r6"; private static final String VALUE4 = "Iv\u0017n"; private static final String ESCAPE4 = "Iv\\u0017n"; private static final String INVALID_UNICODE = "\\u98x"; private static final String UNQUOTED1 = "simple"; private static final String QUOTED1 = "\"simple\""; private static final String UNQUOTED2 = "no\\csak\""; private static final String QUOTED2 = "\"no\\\\csak\\\"\""; private static final String UNQUOTED3 = ""; private static final String QUOTED3 = ""; protected EscapeTool instance; @Before @Override public void setUp() throws Exception { super.setUp(); instance = EscapeTool.getInstance(); } @Test public void testEscape() throws Exception { assertEquals(ESCAPE1, instance.escape(VALUE1)); assertEquals(ESCAPE2, instance.escape(VALUE2)); assertEquals(ESCAPE3, instance.escape(VALUE3)); assertEquals(ESCAPE4, instance.escape(VALUE4)); } @Test public void testInvalidUnicode() { try { instance.unescape(INVALID_UNICODE); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @Test public void testQuote() throws Exception { assertEquals(QUOTED1, instance.quote(UNQUOTED1)); assertEquals(QUOTED2, instance.quote(UNQUOTED2)); assertEquals(QUOTED3, instance.quote(UNQUOTED3)); assertNull(instance.quote(null)); } @Test public void testSingleton() throws Exception { assertEquals(EscapeTool.class, EscapeTool.getInstance().getClass()); } @SuppressWarnings("empty-statement") @Test public void testUnescape() throws Exception { assertEquals(VALUE1, instance.unescape(ESCAPE1)); assertEquals(VALUE2, instance.unescape(ESCAPE2)); assertEquals(VALUE3, instance.unescape(ESCAPE3)); assertEquals(VALUE4, instance.unescape(ESCAPE4)); assertEquals("=", instance.unescape("\\=")); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/IniFormatterTest.java000066400000000000000000000227431151645323700252030ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.easymock.EasyMock; import org.ini4j.Config; import org.ini4j.Ini; import org.ini4j.Ini4jCase; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import org.junit.Test; import java.io.PrintWriter; import java.io.StringReader; import java.io.StringWriter; public class IniFormatterTest extends Ini4jCase { private static final String NL = System.getProperty("line.separator"); private static final String DUMMY = "dummy"; @Test public void testFormat() throws Exception { Ini ini = Helper.newDwarfsIni(); IniHandler handler = EasyMock.createMock(IniHandler.class); Dwarf dwarf; handler.startIni(); handler.handleComment(Helper.HEADER_COMMENT); handler.handleComment(" " + Dwarfs.PROP_BASHFUL); dwarf = DwarfsData.bashful; handler.startSection(Dwarfs.PROP_BASHFUL); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_DOC); dwarf = DwarfsData.doc; handler.startSection(Dwarfs.PROP_DOC); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_DOPEY); dwarf = DwarfsData.dopey; handler.startSection(Dwarfs.PROP_DOPEY); handler.handleOption(Dwarf.PROP_WEIGHT, DwarfsData.INI_DOPEY_WEIGHT); handler.handleOption(Dwarf.PROP_HEIGHT, DwarfsData.INI_DOPEY_HEIGHT); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[1])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[2])); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_GRUMPY); dwarf = DwarfsData.grumpy; handler.startSection(Dwarfs.PROP_GRUMPY); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, DwarfsData.INI_GRUMPY_HEIGHT); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_HAPPY); dwarf = DwarfsData.happy; handler.startSection(Dwarfs.PROP_HAPPY); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_SLEEPY); dwarf = DwarfsData.sleepy; handler.startSection(Dwarfs.PROP_SLEEPY); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, DwarfsData.INI_SLEEPY_HEIGHT); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_SNEEZY); dwarf = DwarfsData.sneezy; handler.startSection(Dwarfs.PROP_SNEEZY); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, DwarfsData.INI_SNEEZY_HOME_PAGE); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[1])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[2])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[3])); handler.endSection(); handler.endIni(); EasyMock.replay(handler); verify(ini, handler); } @Test public void testNewInstance() throws Exception { StringWriter stringWriter; PrintWriter printWriter; Config cfg = new Config(); IniFormatter instance; stringWriter = new StringWriter(); instance = IniFormatter.newInstance(stringWriter, cfg); instance.getOutput().print(DUMMY); instance.getOutput().flush(); assertEquals(DUMMY, stringWriter.toString()); assertSame(cfg, instance.getConfig()); // stringWriter = new StringWriter(); instance = IniFormatter.newInstance(stringWriter, cfg); instance.getOutput().print(DUMMY); instance.getOutput().flush(); assertEquals(DUMMY, stringWriter.toString()); // printWriter = new PrintWriter(stringWriter); instance = IniFormatter.newInstance(printWriter, cfg); assertSame(printWriter, instance.getOutput()); } @Test public void testWithEmptyOption() throws Exception { Config cfg = new Config(); cfg.setEmptyOption(true); Ini ini = new Ini(); Ini.Section sec = ini.add(Dwarfs.PROP_BASHFUL); sec.put(Dwarf.PROP_FORTUNE_NUMBER, null); ini.setConfig(cfg); IniHandler handler = EasyMock.createMock(IniHandler.class); handler.startIni(); handler.startSection(Dwarfs.PROP_BASHFUL); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, ""); handler.endSection(); handler.endIni(); EasyMock.replay(handler); verify(ini, handler); } @Test public void testWithoutConfig() throws Exception { Ini ini = new Ini(); Ini.Section sec = ini.add(Dwarfs.PROP_BASHFUL); sec.put(Dwarf.PROP_FORTUNE_NUMBER, null); IniHandler handler = EasyMock.createMock(IniHandler.class); handler.startIni(); handler.startSection(Dwarfs.PROP_BASHFUL); handler.endSection(); handler.endIni(); EasyMock.replay(handler); verify(ini, handler); } @Test public void testWithStrictOperator() throws Exception { Config cfg = new Config(); cfg.setStrictOperator(true); Ini ini = new Ini(); Ini.Section sec = ini.add(Dwarfs.PROP_BASHFUL); sec.put(Dwarf.PROP_AGE, DwarfsData.bashful.age); ini.setConfig(cfg); StringWriter writer = new StringWriter(); ini.store(writer); StringBuilder exp = new StringBuilder(); exp.append(IniParser.SECTION_BEGIN); exp.append(Dwarfs.PROP_BASHFUL); exp.append(IniParser.SECTION_END); exp.append(NL); exp.append(Dwarf.PROP_AGE); exp.append('='); exp.append(DwarfsData.bashful.age); exp.append(NL); exp.append(NL); assertEquals(exp.toString(), writer.toString()); } private void verify(Ini ini, IniHandler mock) throws Exception { StringWriter writer = new StringWriter(); ini.store(writer); IniParser parser = new IniParser(); parser.parse(new StringReader(writer.toString()), mock); EasyMock.verify(mock); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/IniParserTest.java000066400000000000000000000264131151645323700244720ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.easymock.EasyMock; import org.ini4j.Config; import org.ini4j.Ini4jCase; import org.ini4j.InvalidFileFormatException; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.StringReader; public class IniParserTest extends Ini4jCase { private static final String[] BAD = { "[section\noption=value\n", "[]\noption=value", "section\noption=value", "[section]\noption\n", "[section]\n=value\n", "[section]\n\\u000d\\u000d=value\n" }; private static final String CFG_LOWER = "[SectioN]\n\nOptioN=ValuE\n"; private static final String CFG_UNNAMED = "[]\noption=value\n"; private static final String CFG_EMPTY_OPTION = "[section]\noption\n"; private static final String CFG_GLOBAL = "option=value\n"; private static final String[] CFG_EXTRA = { CFG_EMPTY_OPTION, CFG_UNNAMED, CFG_GLOBAL }; private static final String ANONYMOUS = "?"; private static final String EMPTY = ""; private static final String SECTION = "section"; private static final String OPTION = "option"; private static final String VALUE = "value"; @Test public void testEmpty() throws Exception { IniParser parser = new IniParser(); IniHandler handler = EasyMock.createMock(IniHandler.class); handler.startIni(); handler.endIni(); EasyMock.replay(handler); parser.parse(new StringReader(EMPTY), handler); EasyMock.verify(handler); } @Test public void testEmptyOption() throws Exception { IniParser parser = new IniParser(); IniHandler handler = EasyMock.createMock(IniHandler.class); handler.startIni(); handler.startSection(SECTION); handler.handleOption(OPTION, null); handler.endSection(); handler.endIni(); EasyMock.replay(handler); Config cfg = new Config(); cfg.setEmptyOption(true); parser.setConfig(cfg); parser.parse(new StringReader(CFG_EMPTY_OPTION), handler); EasyMock.verify(handler); } @Test public void testGlobalSection() throws Exception { IniParser parser = new IniParser(); IniHandler handler = EasyMock.createMock(IniHandler.class); handler.startIni(); handler.startSection(ANONYMOUS); handler.handleOption(OPTION, VALUE); handler.endSection(); handler.endIni(); EasyMock.replay(handler); Config cfg = new Config(); cfg.setGlobalSection(true); parser.setConfig(cfg); parser.parse(new StringReader(CFG_GLOBAL), handler); EasyMock.verify(handler); } @Test public void testLower() throws Exception { IniParser parser = new IniParser(); IniHandler handler = EasyMock.createMock(IniHandler.class); handler.startIni(); handler.startSection(SECTION); handler.handleOption(OPTION, "ValuE"); handler.endSection(); handler.endIni(); EasyMock.replay(handler); Config cfg = new Config(); cfg.setLowerCaseOption(true); cfg.setLowerCaseSection(true); parser.setConfig(cfg); parser.parse(new StringReader(CFG_LOWER), handler); EasyMock.verify(handler); } @Test public void testNewInstance() throws Exception { Config cfg = new Config(); IniParser parser = IniParser.newInstance(); assertEquals(IniParser.class, parser.getClass()); parser = IniParser.newInstance(cfg); assertEquals(IniParser.class, parser.getClass()); assertSame(cfg, parser.getConfig()); } @Test public void testParse() throws Exception { IniParser parser = new IniParser(); IniHandler handler = EasyMock.createMock(IniHandler.class); Dwarf dwarf; handler.startIni(); handler.handleComment(Helper.HEADER_COMMENT); handler.handleComment((String) EasyMock.anyObject()); handler.handleComment(" " + Dwarfs.PROP_BASHFUL); dwarf = DwarfsData.bashful; handler.startSection(Dwarfs.PROP_BASHFUL); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_DOC); dwarf = DwarfsData.doc; handler.startSection(Dwarfs.PROP_DOC); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_DOPEY); dwarf = DwarfsData.dopey; handler.startSection(Dwarfs.PROP_DOPEY); handler.handleOption(Dwarf.PROP_WEIGHT, DwarfsData.INI_DOPEY_WEIGHT); handler.handleOption(Dwarf.PROP_HEIGHT, DwarfsData.INI_DOPEY_HEIGHT); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[1])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[2])); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_GRUMPY); dwarf = DwarfsData.grumpy; handler.startSection(Dwarfs.PROP_GRUMPY); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, DwarfsData.INI_GRUMPY_HEIGHT); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_HAPPY); dwarf = DwarfsData.happy; handler.startSection(Dwarfs.PROP_HAPPY); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(EasyMock.eq(Dwarf.PROP_HOME_PAGE), (String) EasyMock.anyObject()); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_SLEEPY); dwarf = DwarfsData.sleepy; handler.startSection(Dwarfs.PROP_SLEEPY); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, DwarfsData.INI_SLEEPY_HEIGHT); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_SNEEZY); dwarf = DwarfsData.sneezy; handler.startSection(Dwarfs.PROP_SNEEZY); handler.handleOption(Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, DwarfsData.INI_SNEEZY_HOME_PAGE); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[1])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[2])); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[3])); handler.endSection(); handler.handleComment(" " + Dwarfs.PROP_HAPPY + " again"); dwarf = DwarfsData.happy; handler.startSection(Dwarfs.PROP_HAPPY); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleComment("}"); handler.endSection(); handler.endIni(); // EasyMock.replay(handler); parser.parse(Helper.getResourceURL(Helper.DWARFS_INI), handler); EasyMock.verify(handler); } @Test public void testParseExceptions() throws Exception { assertBad(BAD); assertBad(CFG_EXTRA); } @Test public void testUnnamedSection() throws Exception { IniParser parser = new IniParser(); IniHandler handler = EasyMock.createMock(IniHandler.class); handler.startIni(); handler.startSection(EMPTY); handler.handleOption(OPTION, VALUE); handler.endSection(); handler.endIni(); EasyMock.replay(handler); Config cfg = new Config(); cfg.setUnnamedSection(true); parser.setConfig(cfg); parser.parse(new StringReader(CFG_UNNAMED), handler); EasyMock.verify(handler); } @SuppressWarnings("empty-statement") private void assertBad(String[] values) throws Exception { IniParser parser = new IniParser(); IniHandler handler = EasyMock.createNiceMock(IniHandler.class); for (String s : values) { try { parser.parse(new ByteArrayInputStream(s.getBytes()), handler); fail("expected InvalidIniFormatException: " + s); } catch (InvalidFileFormatException x) { ; } } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/IniSourceTest.java000066400000000000000000000123251151645323700244730ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.easymock.EasyMock; import org.ini4j.Config; import org.ini4j.Ini4jCase; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.InputStream; public class IniSourceTest extends Ini4jCase { private static final String COMMENTS = ";#"; private static final String NESTED_TXT = "nested.txt"; private static final String NESTED = ":" + NESTED_TXT; private static final String NESTED_PATH = "org/ini4j/spi/" + NESTED_TXT; private static final String INCLUDE = ":include.txt"; private static final String PART1 = ":part1.txt"; private static final String PART2 = ":part2.txt"; private static final String OUTER = ":outer"; @Test public void testWithInclude() throws Exception { HandlerBase handler = EasyMock.createMock(HandlerBase.class); handler.handleComment("-1" + OUTER); handler.handleComment("-1" + NESTED); handler.handleComment("-2" + NESTED); handler.handleComment("-1" + INCLUDE); handler.handleComment("-2" + INCLUDE); handler.handleComment("-1" + PART1); handler.handleComment("-2" + PART1); handler.handleComment("-3" + INCLUDE); handler.handleComment("-4" + INCLUDE); handler.handleComment("-5" + INCLUDE); handler.handleComment("-6" + INCLUDE); handler.handleComment("-1" + PART2); handler.handleComment("-2" + PART2); handler.handleComment("-7" + INCLUDE); handler.handleComment("-8" + INCLUDE); handler.handleComment("-3" + NESTED); handler.handleComment("-4" + NESTED); handler.handleComment("-2" + OUTER); EasyMock.replay(handler); StringBuilder outer = new StringBuilder(); outer.append(";-1" + OUTER + '\n'); outer.append("1" + OUTER + '\n'); outer.append('<'); outer.append(Helper.getResourceURL(NESTED_PATH).toExternalForm()); outer.append(">\n"); outer.append("2" + OUTER + '\n'); outer.append(";-2" + OUTER + '\n'); InputStream in = new ByteArrayInputStream(outer.toString().getBytes()); Config cfg = new Config(); cfg.setInclude(true); IniSource src = new IniSource(in, handler, COMMENTS, cfg); assertEquals("1" + OUTER, src.readLine()); assertEquals(2, src.getLineNumber()); assertEquals("1" + NESTED, src.readLine()); assertEquals(2, src.getLineNumber()); assertEquals("1" + INCLUDE, src.readLine()); assertEquals(2, src.getLineNumber()); assertEquals("1" + PART1, src.readLine()); assertEquals(2, src.getLineNumber()); assertEquals("2" + PART1, src.readLine()); assertEquals(4, src.getLineNumber()); assertEquals("3" + PART1 + "\\\\", src.readLine()); assertEquals(5, src.getLineNumber()); assertEquals("4:\\\\part1.txt", src.readLine()); assertEquals(7, src.getLineNumber()); assertEquals("5" + PART1 + "\\\\\\\\", src.readLine()); assertEquals(8, src.getLineNumber()); assertEquals("6" + PART1 + ";", src.readLine()); assertEquals(10, src.getLineNumber()); assertEquals("2" + INCLUDE, src.readLine()); assertEquals(6, src.getLineNumber()); assertEquals("3" + INCLUDE, src.readLine()); assertEquals(10, src.getLineNumber()); assertEquals("1" + PART2, src.readLine()); assertEquals(3, src.getLineNumber()); assertEquals("4" + INCLUDE, src.readLine()); assertEquals(14, src.getLineNumber()); assertEquals("2" + NESTED, src.readLine()); assertEquals(6, src.getLineNumber()); assertEquals("2" + OUTER, src.readLine()); assertEquals(4, src.getLineNumber()); assertNull(src.readLine()); EasyMock.verify(handler); } @Test public void testWithoutInclude() throws Exception { HandlerBase handler = EasyMock.createMock(HandlerBase.class); handler.handleComment("-1" + NESTED); handler.handleComment("-2" + NESTED); handler.handleComment("-3" + NESTED); handler.handleComment("-4" + NESTED); EasyMock.replay(handler); Config cfg = new Config(); cfg.setInclude(false); IniSource src = new IniSource(Helper.getResourceURL(NESTED_PATH), handler, COMMENTS, cfg); assertEquals("1" + NESTED, src.readLine()); assertEquals("", src.readLine()); assertEquals("2" + NESTED, src.readLine()); assertNull(src.readLine()); EasyMock.verify(handler); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/OptionsFormatterTest.java000066400000000000000000000237041151645323700261150ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.easymock.EasyMock; import org.ini4j.Config; import org.ini4j.Ini4jCase; import org.ini4j.Options; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import org.junit.Test; import java.io.PrintWriter; import java.io.StringReader; import java.io.StringWriter; public class OptionsFormatterTest extends Ini4jCase { private static final String NL = System.getProperty("line.separator"); private static final String DUMMY = "dummy"; @Test public void testFormat() throws Exception { Options opts = Helper.newDwarfsOpt(); OptionsHandler handler = EasyMock.createMock(OptionsHandler.class); Dwarf dwarf; String prefix; handler.startOptions(); handler.handleComment(Helper.HEADER_COMMENT); handler.handleComment((String) EasyMock.anyObject()); dwarf = DwarfsData.dopey; handler.handleOption(Dwarf.PROP_WEIGHT, DwarfsData.OPT_DOPEY_WEIGHT); handler.handleOption(Dwarf.PROP_HEIGHT, DwarfsData.OPT_DOPEY_HEIGHT); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, "11"); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, "33"); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, "55"); // // handler.handleComment(" " + Dwarfs.PROP_BASHFUL); dwarf = DwarfsData.bashful; prefix = Dwarfs.PROP_BASHFUL + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleComment(" " + Dwarfs.PROP_DOC); dwarf = DwarfsData.doc; prefix = Dwarfs.PROP_DOC + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleComment(" " + Dwarfs.PROP_DOPEY); dwarf = DwarfsData.dopey; prefix = Dwarfs.PROP_DOPEY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, DwarfsData.OPT_DOPEY_WEIGHT); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, DwarfsData.OPT_DOPEY_HEIGHT); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[1])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[2])); handler.handleComment(" " + Dwarfs.PROP_GRUMPY); dwarf = DwarfsData.grumpy; prefix = Dwarfs.PROP_GRUMPY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, DwarfsData.OPT_GRUMPY_HEIGHT); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleComment(" " + Dwarfs.PROP_HAPPY); dwarf = DwarfsData.happy; prefix = Dwarfs.PROP_HAPPY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleComment(" " + Dwarfs.PROP_SLEEPY); dwarf = DwarfsData.sleepy; prefix = Dwarfs.PROP_SLEEPY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, DwarfsData.OPT_SLEEPY_HEIGHT); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleComment(" " + Dwarfs.PROP_SNEEZY); dwarf = DwarfsData.sneezy; prefix = Dwarfs.PROP_SNEEZY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, DwarfsData.OPT_SNEEZY_HOME_PAGE); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[1])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[2])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[3])); handler.endOptions(); // EasyMock.replay(handler); verify(opts, handler); } @Test public void testNewInstance() throws Exception { StringWriter stringWriter; PrintWriter printWriter; ; Config cfg = new Config(); OptionsFormatter instance; stringWriter = new StringWriter(); instance = OptionsFormatter.newInstance(stringWriter, cfg); instance.getOutput().print(DUMMY); instance.getOutput().flush(); assertEquals(DUMMY, stringWriter.toString()); assertSame(cfg, instance.getConfig()); // stringWriter = new StringWriter(); instance = OptionsFormatter.newInstance(stringWriter, cfg); instance.getOutput().print(DUMMY); instance.getOutput().flush(); assertEquals(DUMMY, stringWriter.toString()); // printWriter = new PrintWriter(stringWriter); instance = OptionsFormatter.newInstance(printWriter, cfg); assertSame(printWriter, instance.getOutput()); } @Test public void testWithStrictOperatorEmptyOptions() throws Exception { Config cfg = new Config(); cfg.setStrictOperator(true); cfg.setEmptyOption(true); Options opts = new Options(); opts.setConfig(cfg); opts.put(Dwarf.PROP_AGE, DwarfsData.bashful.age); opts.put(Dwarf.PROP_WEIGHT, null); StringWriter writer = new StringWriter(); opts.store(writer); StringBuilder exp = new StringBuilder(); exp.append(Dwarf.PROP_AGE); exp.append('='); exp.append(DwarfsData.bashful.age); exp.append(NL); exp.append(Dwarf.PROP_WEIGHT); exp.append('='); exp.append(NL); assertEquals(exp.toString(), writer.toString()); } @Test public void testWithStrictOperatorNoEmptyOptions() throws Exception { Config cfg = new Config(); cfg.setStrictOperator(true); cfg.setEmptyOption(false); Options opts = new Options(); opts.setConfig(cfg); opts.put(Dwarf.PROP_AGE, DwarfsData.bashful.age); opts.put(Dwarf.PROP_WEIGHT, null); StringWriter writer = new StringWriter(); opts.store(writer); StringBuilder exp = new StringBuilder(); exp.append(Dwarf.PROP_AGE); exp.append('='); exp.append(DwarfsData.bashful.age); exp.append(NL); assertEquals(exp.toString(), writer.toString()); } private void verify(Options opts, OptionsHandler mock) throws Exception { StringWriter writer = new StringWriter(); opts.store(writer); OptionsParser parser = new OptionsParser(); parser.parse(new StringReader(writer.toString()), mock); EasyMock.verify(mock); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/OptionsParserTest.java000066400000000000000000000240031151645323700253770ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.easymock.EasyMock; import org.ini4j.Config; import org.ini4j.Ini4jCase; import org.ini4j.InvalidFileFormatException; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import org.junit.Test; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Reader; import java.io.StringReader; public class OptionsParserTest extends Ini4jCase { private static final String CFG_EMPTY_OPTION = "option\n"; private static final String NONAME = "=value\n"; private static final String OPTION = "option"; private static final String UNICODE_STRING = "áÁéÉíÍóÓöÖőŐúÚüÜűŰ-ÄÖÜäöü"; @Test public void testBad() throws Exception { OptionsParser parser = new OptionsParser(); OptionsHandler handler = EasyMock.createNiceMock(OptionsHandler.class); try { parser.parse(new ByteArrayInputStream(NONAME.getBytes()), handler); missing(InvalidFileFormatException.class); } catch (InvalidFileFormatException x) { // } } @Test public void testEmptyOption() throws Exception { OptionsParser parser = new OptionsParser(); OptionsHandler handler = EasyMock.createMock(OptionsHandler.class); handler.startOptions(); handler.handleOption(OPTION, null); handler.endOptions(); EasyMock.replay(handler); Config cfg = new Config(); cfg.setEmptyOption(true); parser.setConfig(cfg); parser.parse(new StringReader(CFG_EMPTY_OPTION), handler); EasyMock.verify(handler); } @Test public void testNewInstance() throws Exception { Config cfg = new Config(); OptionsParser parser = OptionsParser.newInstance(); assertEquals(OptionsParser.class, parser.getClass()); parser = OptionsParser.newInstance(cfg); assertEquals(OptionsParser.class, parser.getClass()); assertSame(cfg, parser.getConfig()); } @Test public void testParse() throws Exception { OptionsParser parser = new OptionsParser(); OptionsHandler handler = EasyMock.createMock(OptionsHandler.class); Dwarf dwarf; String prefix; handler.startOptions(); handler.handleComment(Helper.HEADER_COMMENT); handler.handleComment((String) EasyMock.anyObject()); handler.handleComment((String) EasyMock.anyObject()); dwarf = DwarfsData.dopey; handler.handleOption(Dwarf.PROP_WEIGHT, DwarfsData.OPT_DOPEY_WEIGHT); handler.handleOption(Dwarf.PROP_HEIGHT, DwarfsData.OPT_DOPEY_HEIGHT); handler.handleOption(Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, "11"); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, "33"); handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, "55"); // handler.handleComment((String) EasyMock.anyObject()); // handler.handleComment(" " + Dwarfs.PROP_BASHFUL); dwarf = DwarfsData.bashful; prefix = Dwarfs.PROP_BASHFUL + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleComment(" " + Dwarfs.PROP_DOC); dwarf = DwarfsData.doc; prefix = Dwarfs.PROP_DOC + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleComment(" " + Dwarfs.PROP_DOPEY); dwarf = DwarfsData.dopey; prefix = Dwarfs.PROP_DOPEY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, DwarfsData.OPT_DOPEY_WEIGHT); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, DwarfsData.OPT_DOPEY_HEIGHT); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[1])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[2])); handler.handleComment(" " + Dwarfs.PROP_GRUMPY); dwarf = DwarfsData.grumpy; prefix = Dwarfs.PROP_GRUMPY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, DwarfsData.OPT_GRUMPY_HEIGHT); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleComment(" " + Dwarfs.PROP_HAPPY); dwarf = DwarfsData.happy; prefix = Dwarfs.PROP_HAPPY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(EasyMock.eq(prefix + Dwarf.PROP_HOME_PAGE), (String) EasyMock.anyObject()); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleComment(" " + Dwarfs.PROP_SLEEPY); dwarf = DwarfsData.sleepy; prefix = Dwarfs.PROP_SLEEPY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, DwarfsData.OPT_SLEEPY_HEIGHT); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleComment(" " + Dwarfs.PROP_SNEEZY); dwarf = DwarfsData.sneezy; prefix = Dwarfs.PROP_SNEEZY + "."; handler.handleOption(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); handler.handleOption(prefix + Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); handler.handleOption(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, DwarfsData.OPT_SNEEZY_HOME_PAGE); handler.handleOption(prefix + Dwarf.PROP_HOME_DIR, String.valueOf(dwarf.getHomeDir())); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[0])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[1])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[2])); handler.handleOption(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(dwarf.getFortuneNumber()[3])); handler.handleComment(" " + Dwarfs.PROP_HAPPY + " again"); dwarf = DwarfsData.happy; prefix = Dwarfs.PROP_HAPPY + "."; handler.handleOption(prefix + Dwarf.PROP_HOME_PAGE, String.valueOf(dwarf.getHomePage())); handler.handleComment("}"); handler.endOptions(); // EasyMock.replay(handler); parser.parse(Helper.getResourceURL(Helper.DWARFS_OPT), handler); EasyMock.verify(handler); } @Test public void testUnicode() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); OptionsFormatter formatter = new OptionsFormatter(); formatter.setOutput(new PrintWriter(new OutputStreamWriter(out))); formatter.handleOption(OPTION, UNICODE_STRING); formatter.getOutput().flush(); Reader in = new InputStreamReader(new ByteArrayInputStream(out.toByteArray())); String line = new BufferedReader(in).readLine(); assertEquals(OPTION + " = " + UNICODE_STRING, EscapeTool.getInstance().unescape(line)); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/RegEscapeToolTest.java000066400000000000000000000024351151645323700252700ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Ini4jCase; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; public class RegEscapeToolTest extends Ini4jCase { protected RegEscapeTool instance; @Before @Override public void setUp() throws Exception { super.setUp(); instance = RegEscapeTool.getInstance(); } @Test public void testHexadecimal() { assertEquals(0, instance.hexadecimal(null).length()); assertEquals(0, instance.hexadecimal("").length()); } @Test public void testSingleton() throws Exception { assertEquals(RegEscapeTool.class, RegEscapeTool.getInstance().getClass()); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/ServiceFinderTest.java000066400000000000000000000055511151645323700253260ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Ini4jCase; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Test; public class ServiceFinderTest extends Ini4jCase { static final String DUMMY = "dummy"; static final String DUMMY_SERVICE = "org.ini4j.Dummy"; static final String BAD_CONFIG_SERVICE = "org.ini4j.BadConfig"; static final String EMPTY_CONFIG_SERVICE = "org.ini4j.EmptyConfig"; static final String DUMMY_IMPL = "DummyImpl"; @Test public void testFindService() throws Exception { boolean flag = false; System.setProperty(IniParser.class.getName(), Helper.class.getName()); try { ServiceFinder.findService(IniParser.class); } catch (IllegalArgumentException x) { flag = true; } // System.clearProperty(IniParser.SERVICE_ID); missing in 1.4 System.getProperties().remove(IniParser.class.getName()); assertTrue(flag); } @Test public void testFindServiceClass() throws Exception { boolean flag = false; System.setProperty(IniParser.class.getName(), DUMMY); try { ServiceFinder.findServiceClass(IniParser.class); } catch (IllegalArgumentException x) { flag = true; } // System.clearProperty(IniParser.SERVICE_ID); missing in 1.4 System.getProperties().remove(IniParser.class.getName()); assertTrue(flag); } @Test public void testFindServiceClassName() throws Exception { System.setProperty(IniParser.class.getName(), DUMMY); assertEquals(DUMMY, ServiceFinder.findServiceClassName(IniParser.class.getName())); // System.clearProperty(IniParser.SERVICE_ID); missing in 1.4 System.getProperties().remove(IniParser.class.getName()); assertNull(ServiceFinder.findServiceClassName(IniParser.class.getName())); assertEquals(DUMMY_IMPL, ServiceFinder.findServiceClassName(DUMMY_SERVICE)); assertNull(DUMMY, ServiceFinder.findServiceClassName(BAD_CONFIG_SERVICE)); assertNull(DUMMY, ServiceFinder.findServiceClassName(EMPTY_CONFIG_SERVICE)); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/UnicodeInputStreamReaderTest.java000066400000000000000000000114541151645323700275020ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Config; import org.ini4j.Ini; import org.ini4j.Ini4jCase; import org.ini4j.InvalidFileFormatException; import org.junit.Test; import java.nio.charset.Charset; public class UnicodeInputStreamReaderTest extends Ini4jCase { @Test public void _testUTF32BE() throws Exception { test("UTF-32BE.ini", "UTF-32BE"); } @Test public void _testUTF32BE_BOM() throws Exception { test("UTF-32BE-BOM.ini", null); test("UTF-32BE-BOM.ini", "UTF-8"); test("UTF-32BE-BOM.ini", "UTF-16"); } @Test public void _testUTF32BE_fail() throws Exception { try { test("UTF-32BE.ini", "ISO-8859-1"); missing(IllegalStateException.class); } catch (IllegalStateException x) { // } } @Test public void _testUTF32LE() throws Exception { test("UTF-32LE.ini", "UTF-32LE"); } @Test public void _testUTF32LE_BOM() throws Exception { test("UTF-32LE-BOM.ini", null); test("UTF-32LE-BOM.ini", "UTF-8"); test("UTF-32LE-BOM.ini", "UTF-16"); } @Test public void _testUTF32LE_fail() throws Exception { try { test("UTF-32LE.ini", "ISO-8859-1"); missing(IllegalStateException.class); } catch (IllegalStateException x) { // } } @Test public void t_e_s_tUTF16BE_fail() throws Exception { try { test("UTF-16BE.ini", "ISO-8859-1"); missing(IllegalStateException.class); } catch (IllegalStateException x) { // } } @Test public void t_e_s_tUTF16LE_fail() throws Exception { try { test("UTF-16LE.ini", "ISO-8859-1"); missing(IllegalStateException.class); } catch (IllegalStateException x) { // } } @Test public void testUTF16BE() throws Exception { test("UTF-16BE.ini", "UTF-16BE"); } @Test public void testUTF16BE_BOM() throws Exception { test("UTF-16BE-BOM.ini", null); test("UTF-16BE-BOM.ini", "UTF-8"); test("UTF-16BE-BOM.ini", "UTF-16"); } @Test public void testUTF16LE() throws Exception { test("UTF-16LE.ini", "UTF-16LE"); } @Test public void testUTF16LE_BOM() throws Exception { test("UTF-16LE-BOM.ini", null); test("UTF-16LE-BOM.ini", "UTF-8"); test("UTF-16LE-BOM.ini", "UTF-16"); } @Test public void testUTF8() throws Exception { test("UTF-8.ini", null); test("UTF-8.ini", "UTF-8"); } @Test public void testUTF8_BOM() throws Exception { test("UTF-8-BOM.ini", null); test("UTF-8-BOM.ini", "UTF-8"); test("UTF-8-BOM.ini", "UTF-16"); } @Test public void testUTF8_fail() throws Exception { try { test("UTF-8.ini", "UTF-16"); missing(InvalidFileFormatException.class); } catch (InvalidFileFormatException x) { // } } private UnicodeInputStreamReader instantiate(String filename, String defaultEncoding) { Charset charset = (defaultEncoding == null) ? Charset.defaultCharset() : Charset.forName(defaultEncoding); return new UnicodeInputStreamReader(getClass().getResourceAsStream(filename), charset); } private void test(String filename, String defaultEncoding) throws Exception { Charset charset = (defaultEncoding == null) ? Config.DEFAULT_FILE_ENCODING : Charset.forName(defaultEncoding); UnicodeInputStreamReader reader = new UnicodeInputStreamReader(getClass().getResourceAsStream(filename), charset); Ini ini = new Ini(); ini.setConfig(Config.getGlobal().clone()); ini.getConfig().setFileEncoding(charset); ini.load(reader); Ini.Section sec = ini.get("section"); if (sec == null) { throw new IllegalStateException("Missing section: section"); } if (!"value".equals(sec.get("option"))) { throw new IllegalStateException("Missing option: option"); } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/spi/WinEscapeToolTest.java000066400000000000000000000061511151645323700253070ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.spi; import org.ini4j.Ini4jCase; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; public class WinEscapeToolTest extends Ini4jCase { public static final String VALUE1 = "simple"; public static final String ESCAPE1 = "simple"; public static final String VALUE2 = "Iván"; public static final String ESCAPE2 = "Iv\\xe1n"; public static final String VALUE3 = "1\t2\n3\f4\b5\r6"; public static final String ESCAPE3 = "1\\t2\\n3\\f4\\b5\\r6"; public static final String VALUE4 = "Iv\u0017n"; public static final String ESCAPE4 = "Iv\\x17n"; public static final String VALUE5 = "Árvíztrtükörfúrógép"; public static final String ESCAPE5 = "\\xc1rv\\xedztrt\\xfck\\xf6rf\\xfar\\xf3g\\xe9p"; private static final String INVALID_HEX = "\\x1_"; private static final String INVALID_OCT = "\\o19_"; protected WinEscapeTool instance; @Before @Override public void setUp() throws Exception { super.setUp(); instance = WinEscapeTool.getInstance(); } @Test public void testEscape() throws Exception { assertEquals(ESCAPE1, instance.escape(VALUE1)); assertEquals(ESCAPE2, instance.escape(VALUE2)); assertEquals(ESCAPE3, instance.escape(VALUE3)); assertEquals(ESCAPE4, instance.escape(VALUE4)); assertEquals(ESCAPE5, instance.escape(VALUE5)); } @Test public void testInvalidHex() { try { instance.unescape(INVALID_HEX); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @Test public void testInvalidOctal() { try { instance.unescape(INVALID_OCT); missing(IllegalArgumentException.class); } catch (IllegalArgumentException x) { // } } @Test public void testSingleton() throws Exception { assertEquals(WinEscapeTool.class, WinEscapeTool.getInstance().getClass()); } @Test public void testUnescape() throws Exception { assertEquals(VALUE1, instance.unescape(ESCAPE1)); assertEquals(VALUE2, instance.unescape(ESCAPE2)); assertEquals(VALUE3, instance.unescape(ESCAPE3)); assertEquals(VALUE4, instance.unescape(ESCAPE4)); assertEquals(VALUE5, instance.unescape(ESCAPE5)); assertEquals("=", instance.unescape("\\=")); assertEquals("xAx", instance.unescape("x\\o101x")); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/test/000077500000000000000000000000001151645323700212515ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/test/DwarfsData.java000066400000000000000000000155011151645323700241360ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.test; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; import java.net.URI; public final class DwarfsData implements Dwarfs { public static final DwarfData bashful; public static final DwarfData doc; public static final DwarfData dopey; public static final DwarfData grumpy; public static final DwarfData happy; public static final DwarfData sleepy; public static final DwarfData sneezy; public static final Dwarfs dwarfs; public static final String[] dwarfNames; public static final String INI_DOPEY_WEIGHT = "${bashful/weight}"; public static final String INI_DOPEY_HEIGHT = "${doc/height}"; public static final String INI_GRUMPY_HEIGHT = "${dopey/height}"; public static final String INI_SLEEPY_HEIGHT = "${doc/height}8"; public static final String INI_SNEEZY_HOME_PAGE = "${happy/homePage}/~sneezy"; public static final String OPT_DOPEY_WEIGHT = "${bashful.weight}"; public static final String OPT_DOPEY_HEIGHT = "${doc.height}"; public static final String OPT_GRUMPY_HEIGHT = "${dopey.height}"; public static final String OPT_SLEEPY_HEIGHT = "${doc.height}8"; public static final String OPT_SNEEZY_HOME_PAGE = "${happy.homePage}/~sneezy"; static { // age, fortuneNumber, height, homeDir, homePage, weight bashful = new DwarfData(PROP_BASHFUL, 67, null, 98.8, "/home/bashful", "http://snowwhite.tale/~bashful", 45.7); doc = new DwarfData(PROP_DOC, 63, null, 87.7, "c:Documents and Settingsdoc", "http://doc.dwarfs", 49.5); dopey = new DwarfData(PROP_DOPEY, 23, new int[] { 11, 33, 55 }, doc.height, "c:\\Documents and Settings\\dopey", "http://dopey.snowwhite.tale/", bashful.weight); grumpy = new DwarfData(PROP_GRUMPY, 76, null, dopey.height, "/home/grumpy", "http://snowwhite.tale/~grumpy/", 65.3); happy = new DwarfData(PROP_HAPPY, 99, null, 77.66, "/home/happy", "http://happy.smurf", 56.4); sleepy = new DwarfData(PROP_SLEEPY, 121, new int[] { 99 }, doc.height + 0.08, "/home/sleepy", "http://snowwhite.tale/~sleepy", 76.11); sneezy = new DwarfData(PROP_SNEEZY, 64, new int[] { 11, 22, 33, 44 }, 76.88, "/home/sneezy", happy.homePage.toString() + "/~sneezy", 69.7); dwarfs = new DwarfsData(); dwarfNames = new String[] { bashful.name, doc.name, dopey.name, grumpy.name, happy.name, sleepy.name, sneezy.name }; } @SuppressWarnings("empty-statement") private DwarfsData() { ; } public Dwarf getBashful() { return bashful; } public Dwarf getDoc() { return doc; } public Dwarf getDopey() { return dopey; } public Dwarf getGrumpy() { return grumpy; } public Dwarf getHappy() { return happy; } public Dwarf getSleepy() { return sleepy; } public Dwarf getSneezy() { return sneezy; } public static class DwarfData implements Dwarf { private static final String READ_ONLY_INSTANCE = "Read only instance"; public final int age; public final int[] fortuneNumber; public final double height; public final String homeDir; public final URI homePage; public final String name; public final double weight; public DwarfData(String name, int age, int[] fortuneNumber, double height, String homeDir, String homePage, double weight) { this.name = name; this.age = age; this.fortuneNumber = fortuneNumber; this.height = height; this.homeDir = homeDir; this.homePage = URI.create(homePage); this.weight = weight; } public int getAge() { return age; } public void setAge(int age) { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } public int[] getFortuneNumber() { return fortuneNumber; } public void setFortuneNumber(int[] value) { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } public double getHeight() { return height; } public void setHeight(double height) throws PropertyVetoException { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } public String getHomeDir() { return homeDir; } public void setHomeDir(String dir) { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } public URI getHomePage() { return homePage; } public void setHomePage(URI location) { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } public double getWeight() { return weight; } public void setWeight(double weight) { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } public void addPropertyChangeListener(String property, PropertyChangeListener listener) { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } public void addVetoableChangeListener(String property, VetoableChangeListener listener) { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } public boolean hasAge() { return age != 0; } public boolean hasHeight() { return height != 0.0; } public boolean hasHomePage() { return homePage != null; } public boolean hasWeight() { return weight != 0.0; } public void removePropertyChangeListener(String property, PropertyChangeListener listener) { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } public void removeVetoableChangeListener(String property, VetoableChangeListener listener) { throw new UnsupportedOperationException(READ_ONLY_INSTANCE); } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/test/Helper.java000066400000000000000000000274361151645323700233470ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.test; import org.ini4j.Config; import org.ini4j.Ini; import org.ini4j.OptionMap; import org.ini4j.Options; import org.ini4j.Profile; import org.ini4j.Reg; import org.ini4j.Registry; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.spi.IniFormatter; import org.ini4j.spi.IniParser; import org.ini4j.test.DwarfsData.DwarfData; import org.junit.Assert; import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.util.Properties; public class Helper { private static final String RESOURCE_PREFIX = "org/ini4j/sample/"; private static final File _sourceDir = new File(System.getProperty("basedir") + "/src/test/java/"); private static final File _targetDir = new File(System.getProperty("basedir") + "/target"); public static final String DWARFS_INI = RESOURCE_PREFIX + "dwarfs.ini"; public static final String TALE_INI = RESOURCE_PREFIX + "tale.ini"; public static final String DWARFS_OPT = RESOURCE_PREFIX + "dwarfs.opt"; public static final String DWARFS_REG = RESOURCE_PREFIX + "dwarfs.reg"; public static final String TEST_REG = "org/ini4j/mozilla.reg"; public static final String DWARFS_REG_PATH = Reg.Hive.HKEY_CURRENT_USER + "\\Software\\ini4j-test"; public static final float DELTA = 0.00000001f; private static final String[] CONFIG_PROPERTIES = { Config.PROP_EMPTY_OPTION, Config.PROP_GLOBAL_SECTION, Config.PROP_GLOBAL_SECTION_NAME, Config.PROP_INCLUDE, Config.PROP_LOWER_CASE_OPTION, Config.PROP_LOWER_CASE_SECTION, Config.PROP_MULTI_OPTION, Config.PROP_MULTI_SECTION, Config.PROP_STRICT_OPERATOR, Config.PROP_UNNAMED_SECTION, Config.PROP_ESCAPE }; private static final String[] FACTORY_PROPERTIES = { IniFormatter.class.getName(), IniParser.class.getName() }; public static final String HEADER_COMMENT = " Copyright 2005,2009 Ivan SZKIBA\n" + "\n" + " Licensed under the Apache License, Version 2.0 (the \"License\");\n" + " you may not use this file except in compliance with the License.\n" + " You may obtain a copy of the License at\n" + "\n" + " http://www.apache.org/licenses/LICENSE-2.0\n" + "\n" + " Unless required by applicable law or agreed to in writing, software\n" + " distributed under the License is distributed on an \"AS IS\" BASIS,\n" + " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + " See the License for the specific language governing permissions and\n" + " limitations under the License."; private Helper() { } public static File getBuildDirectory() { return _targetDir; } public static Reader getResourceReader(String path) throws Exception { return new InputStreamReader(getResourceURL(path).openStream()); } public static InputStream getResourceStream(String path) throws Exception { return getResourceURL(path).openStream(); } public static URL getResourceURL(String path) throws Exception { return Helper.class.getClassLoader().getResource(path); } public static File getSourceFile(String path) throws Exception { return new File(_sourceDir, path).getCanonicalFile(); } public static void addDwarf(OptionMap opts, DwarfData dwarf) { addDwarf(opts, dwarf, true); } public static Profile.Section addDwarf(Profile prof, DwarfData dwarf) { Profile.Section s = prof.add(dwarf.name); inject(s, dwarf, ""); if (dwarf.name.equals(Dwarfs.PROP_DOPEY)) { s.put(Dwarf.PROP_WEIGHT, DwarfsData.INI_DOPEY_WEIGHT, 0); s.put(Dwarf.PROP_HEIGHT, DwarfsData.INI_DOPEY_HEIGHT, 0); } else if (dwarf.name.equals(Dwarfs.PROP_GRUMPY)) { s.put(Dwarf.PROP_HEIGHT, DwarfsData.INI_GRUMPY_HEIGHT, 0); } else if (dwarf.name.equals(Dwarfs.PROP_SLEEPY)) { s.put(Dwarf.PROP_HEIGHT, DwarfsData.INI_SLEEPY_HEIGHT, 0); } else if (dwarf.name.equals(Dwarfs.PROP_SNEEZY)) { s.put(Dwarf.PROP_HOME_PAGE, DwarfsData.INI_SNEEZY_HOME_PAGE, 0); } return s; } public static Ini.Section addDwarf(Ini ini, DwarfData dwarf) { Ini.Section s = addDwarf((Profile) ini, dwarf); ini.putComment(dwarf.name, " " + dwarf.name); return s; } public static void addDwarf(OptionMap opts, DwarfData dwarf, boolean addNamePrefix) { String prefix = addNamePrefix ? (dwarf.name + '.') : ""; opts.putComment(prefix + Dwarf.PROP_WEIGHT, " " + dwarf.name); inject(opts, dwarf, prefix); if (dwarf.name.equals(Dwarfs.PROP_DOPEY)) { opts.put(prefix + Dwarf.PROP_WEIGHT, DwarfsData.OPT_DOPEY_WEIGHT, 0); opts.put(prefix + Dwarf.PROP_HEIGHT, DwarfsData.OPT_DOPEY_HEIGHT, 0); } else if (dwarf.name.equals(Dwarfs.PROP_GRUMPY)) { opts.put(prefix + Dwarf.PROP_HEIGHT, DwarfsData.OPT_GRUMPY_HEIGHT, 0); } else if (dwarf.name.equals(Dwarfs.PROP_SLEEPY)) { opts.put(prefix + Dwarf.PROP_HEIGHT, DwarfsData.OPT_SLEEPY_HEIGHT, 0); } else if (dwarf.name.equals(Dwarfs.PROP_SNEEZY)) { opts.put(prefix + Dwarf.PROP_HOME_PAGE, DwarfsData.OPT_SNEEZY_HOME_PAGE, 0); } } public static void addDwarfs(Profile prof) { addDwarf(prof, DwarfsData.bashful); addDwarf(prof, DwarfsData.doc); addDwarf(prof, DwarfsData.dopey); addDwarf(prof, DwarfsData.grumpy); addDwarf(prof, DwarfsData.happy); addDwarf(prof, DwarfsData.sleepy); addDwarf(prof, DwarfsData.sneezy); } public static void assertEquals(Registry.Key exp, Registry.Key act) { Assert.assertNotNull(exp); Assert.assertEquals(exp.size(), act.size()); for (String child : exp.childrenNames()) { assertEquals(exp.getChild(child), act.getChild(child)); } for (String name : exp.keySet()) { Assert.assertEquals(exp.get(name), act.get(name)); } } public static void assertEquals(Dwarfs expected, Dwarfs actual) { assertEquals(expected.getBashful(), actual.getBashful()); assertEquals(expected.getDoc(), actual.getDoc()); assertEquals(expected.getDopey(), actual.getDopey()); assertEquals(expected.getGrumpy(), actual.getGrumpy()); assertEquals(expected.getHappy(), actual.getHappy()); assertEquals(expected.getSleepy(), actual.getSleepy()); assertEquals(expected.getSneezy(), actual.getSneezy()); } public static void assertEquals(Dwarf expected, Dwarf actual) { Assert.assertEquals(expected.getAge(), actual.getAge()); Assert.assertEquals(expected.getHeight(), actual.getHeight(), DELTA); Assert.assertEquals(expected.getWeight(), actual.getWeight(), DELTA); Assert.assertEquals(expected.getHomePage().toString(), actual.getHomePage().toString()); Assert.assertEquals(expected.getHomeDir().toString(), actual.getHomeDir().toString()); Assert.assertEquals(expected.hasAge(), actual.hasAge()); Assert.assertEquals(expected.hasHeight(), actual.hasHeight()); Assert.assertEquals(expected.hasWeight(), actual.hasWeight()); Assert.assertEquals(expected.hasHomePage(), actual.hasHomePage()); } public static Ini loadDwarfsIni() throws Exception { return new Ini(Helper.class.getClassLoader().getResourceAsStream(DWARFS_INI)); } public static Ini loadDwarfsIni(Config config) throws Exception { Ini ini = new Ini(); ini.setConfig(config); ini.load(Helper.class.getClassLoader().getResourceAsStream(DWARFS_INI)); return ini; } public static Options loadDwarfsOpt() throws Exception { return new Options(Helper.class.getClassLoader().getResourceAsStream(DWARFS_OPT)); } public static Options loadDwarfsOpt(Config config) throws Exception { Options opt = new Options(); opt.setConfig(config); opt.load(Helper.class.getClassLoader().getResourceAsStream(DWARFS_OPT)); return opt; } public static Reg loadDwarfsReg() throws Exception { return new Reg(Helper.class.getClassLoader().getResourceAsStream(DWARFS_REG)); } public static Ini loadTaleIni() throws Exception { return new Ini(Helper.class.getClassLoader().getResourceAsStream(TALE_INI)); } public static Ini loadTaleIni(Config config) throws Exception { Ini ini = new Ini(); ini.setConfig(config); ini.load(Helper.class.getClassLoader().getResourceAsStream(TALE_INI)); return ini; } public static Ini newDwarfsIni() { Ini ini = new Ini(); ini.setComment(HEADER_COMMENT); addDwarf(ini, DwarfsData.bashful); addDwarf(ini, DwarfsData.doc); addDwarf(ini, DwarfsData.dopey); addDwarf(ini, DwarfsData.grumpy); addDwarf(ini, DwarfsData.happy); addDwarf(ini, DwarfsData.sleepy); addDwarf(ini, DwarfsData.sneezy); return ini; } public static Options newDwarfsOpt() { Options opts = new Options(); opts.setComment(HEADER_COMMENT); addDwarf(opts, DwarfsData.dopey, false); addDwarf(opts, DwarfsData.bashful); addDwarf(opts, DwarfsData.doc); addDwarf(opts, DwarfsData.dopey); addDwarf(opts, DwarfsData.grumpy); addDwarf(opts, DwarfsData.happy); addDwarf(opts, DwarfsData.sleepy); addDwarf(opts, DwarfsData.sneezy); return opts; } public static Ini newTaleIni() { Ini ini = new Ini(); ini.setComment(HEADER_COMMENT); ini.add(TaleData.PROP_DWARFS); addDwarf(ini, TaleData.bashful); addDwarf(ini, TaleData.doc); addDwarf(ini, TaleData.dopey); addDwarf(ini, TaleData.grumpy); addDwarf(ini, TaleData.happy); addDwarf(ini, TaleData.sleepy); addDwarf(ini, TaleData.sneezy); return ini; } public static void resetConfig() throws Exception { Properties props = System.getProperties(); for (String name : CONFIG_PROPERTIES) { props.remove(Config.KEY_PREFIX + name); } for (String name : FACTORY_PROPERTIES) { props.remove(name); } } private static void inject(OptionMap map, Dwarf dwarf, String prefix) { map.put(prefix + Dwarf.PROP_WEIGHT, String.valueOf(dwarf.getWeight())); map.put(prefix + Dwarf.PROP_HEIGHT, String.valueOf(dwarf.getHeight())); map.put(prefix + Dwarf.PROP_AGE, String.valueOf(dwarf.getAge())); map.put(prefix + Dwarf.PROP_HOME_PAGE, dwarf.getHomePage().toString()); map.put(prefix + Dwarf.PROP_HOME_DIR, dwarf.getHomeDir()); int[] numbers = dwarf.getFortuneNumber(); if ((numbers != null) && (numbers.length > 0)) { for (int i = 0; i < numbers.length; i++) { map.add(prefix + Dwarf.PROP_FORTUNE_NUMBER, String.valueOf(numbers[i])); } } } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/test/SampleRunnerTest.java000066400000000000000000000247721151645323700254030ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.test; import org.ini4j.sample.BeanEventSample; import org.ini4j.sample.BeanSample; import org.ini4j.sample.DumpSample; import org.ini4j.sample.Dwarf; import org.ini4j.sample.DwarfBean; import org.ini4j.sample.Dwarfs; import org.ini4j.sample.DwarfsBean; import org.ini4j.sample.FromSample; import org.ini4j.sample.IniSample; import org.ini4j.sample.ListenerSample; import org.ini4j.sample.NoImportSample; import org.ini4j.sample.PyReadSample; import org.ini4j.sample.ReadPrimitiveSample; import org.ini4j.sample.ReadStringSample; import org.ini4j.sample.StreamSample; import org.ini4j.sample.ToSample; import org.ini4j.tutorial.BeanTutorial; import org.ini4j.tutorial.IniTutorial; import org.ini4j.tutorial.OneMinuteTutorial; import org.ini4j.tutorial.OptTutorial; import org.ini4j.tutorial.PrefsTutorial; import org.ini4j.tutorial.RegTutorial; import org.ini4j.tutorial.WindowsRegistryTutorial; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStream; import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.PrintStream; import java.io.PrintWriter; import java.io.Reader; import java.lang.reflect.Method; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; @RunWith(Parameterized.class) public class SampleRunnerTest { private static final String DOC_PATH = "generated-site/apt"; private static final String JAVA_SUFFIX = ".java"; private static final String PACKAGE_INFO = "package-info" + JAVA_SUFFIX; private static final String APT_SUFFIX = ".apt"; private static final String APT_INDEX = "index" + APT_SUFFIX; private static final String CODE_BEGIN = "\n+----+\n"; private static final String CODE_END = "+----+\n\n"; private static File _documentDir; static { System.setProperty("java.util.prefs.PreferencesFactory", "org.ini4j.IniPreferencesFactory"); _documentDir = new File(Helper.getBuildDirectory(), DOC_PATH); _documentDir.mkdirs(); try { document(sourceFile(Dwarf.class), "//"); document(sourceFile(DwarfBean.class), "//"); document(sourceFile(Dwarfs.class), "//"); document(sourceFile(DwarfsBean.class), "//"); document(sourceFile(IniTutorial.class.getPackage()), "//"); document(sourceFile(IniSample.class.getPackage()), "//"); } catch (Exception x) { throw new IllegalStateException(x); } } private final Class _clazz; private final File _sourceFile; public SampleRunnerTest(Class sampleClass) throws Exception { _clazz = sampleClass; _sourceFile = sourceFile(_clazz); } @Parameters public static Collection data() { return Arrays.asList( new Object[][] { // samples { ReadStringSample.class }, { ReadPrimitiveSample.class }, { IniSample.class }, { StreamSample.class }, { DumpSample.class }, { NoImportSample.class }, { ListenerSample.class }, { BeanSample.class }, { BeanEventSample.class }, { FromSample.class }, { ToSample.class }, { PyReadSample.class }, // tutorials { OneMinuteTutorial.class }, { IniTutorial.class }, { RegTutorial.class }, { WindowsRegistryTutorial.class }, { OptTutorial.class }, { BeanTutorial.class }, { PrefsTutorial.class }, }); } @Test public void test() throws Exception { System.out.println("Executing " + _clazz.getName()); PrintStream saved = System.out; File tmp = File.createTempFile(getClass().getSimpleName(), ".out"); PrintStream out = new PrintStream(new FileOutputStream(tmp)); System.setOut(out); try { execute(); } finally { System.setOut(saved); out.flush(); } document(_sourceFile, "//"); index(source2document(_sourceFile), source2index(_clazz)); if (tmp.length() > 0) { append(tmp); } tmp.delete(); } private static void document(File src, String comment) throws Exception { Pattern docPattern = Pattern.compile(String.format("^\\s*%s\\|(.*)$", comment)); Pattern beginPattern = Pattern.compile(String.format("^\\s*%s\\{.*$", comment)); Pattern endPattern = Pattern.compile(String.format("^\\s*%s\\}.*$", comment)); LineNumberReader reader = new LineNumberReader(openReader(src)); PrintWriter writer = new PrintWriter(new FileWriter(source2document(src))); boolean in = false; for (String line = reader.readLine(); line != null; line = reader.readLine()) { if (in) { if (endPattern.matcher(line).matches()) { in = false; writer.println(CODE_END); } else { writer.println(line); } } else { if (beginPattern.matcher(line).matches()) { in = true; writer.println(CODE_BEGIN); } else { Matcher m = docPattern.matcher(line); if (m.matches()) { writer.println(m.group(1)); } } } } reader.close(); writer.close(); } private static void index(File src, File dst) throws Exception { LineNumberReader reader = new LineNumberReader(new FileReader(src)); PrintWriter writer = new PrintWriter(new FileWriter(dst, true)); String name = src.getName().replace(".apt", ".html"); boolean h1 = false; boolean p = false; for (String line = reader.readLine(); line != null; line = reader.readLine()) { if (line.length() == 0) { if (p) { writer.println(); break; } else if (h1) { p = true; } } else { if (Character.isSpaceChar(line.charAt(0))) { if (p) { writer.println(line); } } else { if (!h1) { h1 = true; writer.print(String.format(" *{{{%s}%s}}", name, line)); writer.println(); writer.println(); } } } } writer.close(); reader.close(); } private static Reader openReader(File src) throws Exception { InputStream stream = new FileInputStream(src); byte[] head = new byte[2]; int n = stream.read(head); stream.close(); Charset charset; if ((n == 2) && (head[0] == -1) && (head[1] == -2)) { charset = Charset.forName("UnicodeLittle"); } else { charset = Charset.forName("UTF-8"); } return new InputStreamReader(new FileInputStream(src), charset); } private static File source2document(File sourceFile) throws Exception { String name = sourceFile.getName(); File dir = new File(_documentDir, sourceFile.getParentFile().getName()); dir.mkdir(); return new File(dir, name.equals(PACKAGE_INFO) ? APT_INDEX : (name + APT_SUFFIX)); } private static File source2index(Class clazz) throws Exception { return source2document(sourceFile(clazz.getPackage())); } private static File sourceFile(Class clazz) throws Exception { return Helper.getSourceFile(clazz.getName().replaceAll("\\.", "/") + JAVA_SUFFIX); } private static File sourceFile(Package pkg) throws Exception { return Helper.getSourceFile(pkg.getName().replaceAll("\\.", "/") + '/' + PACKAGE_INFO); } private void append(File stdout) throws Exception { PrintWriter writer = new PrintWriter(new FileWriter(source2document(_sourceFile), true)); writer.println("\n Standard output:\n"); writer.println(CODE_BEGIN); LineNumberReader reader = new LineNumberReader(new FileReader(stdout)); for (String line = reader.readLine(); line != null; line = reader.readLine()) { writer.println(line); } writer.println(CODE_END); reader.close(); writer.close(); } @SuppressWarnings("unchecked") private void execute() throws Exception { Method main = _clazz.getMethod("main", String[].class); String[] args; try { File argument = new File(_sourceFile.getParentFile(), (String) _clazz.getField("FILENAME").get(null)); document(argument, "[#;!]"); args = new String[] { argument.getCanonicalPath() }; } catch (NoSuchFieldException x) { args = new String[] {}; } main.invoke(null, (Object) args); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/test/TaleData.java000066400000000000000000000033141151645323700235740ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.test; import org.ini4j.test.DwarfsData.DwarfData; public final class TaleData { public static final String PROP_DWARFS = "dwarfs"; public static final char PATH_SEPARATOR = '/'; public static final DwarfData bashful; public static final DwarfData doc; public static final DwarfData dopey; public static final DwarfData grumpy; public static final DwarfData happy; public static final DwarfData sleepy; public static final DwarfData sneezy; static { bashful = newDwarfData(DwarfsData.bashful); doc = newDwarfData(DwarfsData.doc); dopey = newDwarfData(DwarfsData.dopey); grumpy = newDwarfData(DwarfsData.grumpy); happy = newDwarfData(DwarfsData.happy); sleepy = newDwarfData(DwarfsData.sleepy); sneezy = newDwarfData(DwarfsData.sneezy); } private TaleData() { } private static DwarfData newDwarfData(DwarfData orig) { return new DwarfData(PROP_DWARFS + PATH_SEPARATOR + orig.name, orig.age, orig.fortuneNumber, orig.height, orig.homeDir, orig.homePage.toString(), orig.weight); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/000077500000000000000000000000001151645323700221355ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/AbstractTutorial.java000066400000000000000000000016651151645323700262770ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; import java.io.File; public abstract class AbstractTutorial { public static final String FILENAME = "../sample/dwarfs.ini"; protected abstract void run(File arg) throws Exception; protected static File filearg(String[] args) { return new File((args.length > 0) ? args[0] : FILENAME); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/BeanTutorial.java000066400000000000000000000160561151645323700254010ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; import org.ini4j.Config; import org.ini4j.Ini; import org.ini4j.Options; import org.ini4j.sample.Dwarf; import org.ini4j.sample.DwarfBean; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import static org.junit.Assert.*; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URL; // //| //| ------------- //| Bean Tutorial //| //|Bean Tutorial - Using your own API ! //| //| Yes, it can be done! To access the contents of sections you can use any of //| your self-defined Java Beans compatible API. //| In order to do this you only have to create a Java Beans-style interface or class. //| //| Source code for beans: {{{../sample/Dwarf.java.html}Dwarf}}, //| {{{../sample/DwarfBean.java.html}DwarfBean}} //| //| Code sniplets in this tutorial tested with the following .ini file: //| {{{../sample/dwarfs.ini.html}dwarfs.ini}} //| // public class BeanTutorial extends AbstractTutorial { public static void main(String[] args) throws Exception { new BeanTutorial().run(filearg(args)); } @Override protected void run(File arg) throws Exception { Ini ini = new Ini(arg.toURI().toURL()); sample01(ini); sample02(ini); sample03(ini); sample04(arg.toURI().toURL()); Options opts = new Options(); opts.putAll(ini.get(Dwarfs.PROP_BASHFUL)); sample05(opts); // File optFile = new File(arg.getParentFile(), OptTutorial.FILENAME); sample06(optFile.toURI().toURL()); } //| //|* Accessing sections as beans //| //| While writing a program we usually know the type of the section's values, //| so we can define one or more java interfaces to access them. An advantage of //| this solution is that the programmer doesn't have to convert the values //| because they are converted automatically to the type defined in the //| interface. //| //| Ofcourse you may use setters as well, not just getters. In this way you can //| change values type safe way. //{ void sample01(Ini ini) { Ini.Section sec = ini.get("happy"); Dwarf happy = sec.as(Dwarf.class); int age = happy.getAge(); URI homePage = happy.getHomePage(); happy.setWeight(45.55); //} //| //| The <<>> relation is of course fulfilled in the //| example above. //| assertEquals(DwarfsData.happy.homePage.toString(), homePage.toString()); assertEquals(DwarfsData.happy.age, age); assertEquals(45.55, happy.getWeight(), 0.01); } //| //|* Marshalling beans //| //| Sometimes we want to store existing java beans in text file. This operation //| usually called marshalling. //| //| With [ini4j] it is easy to store bean properties in a section. You simply //| create a section, and call the sections's <<>> method. Thats it. //{ void sample02(Ini ini) { DwarfBean sleepy = new DwarfBean(); sleepy.setAge(87); sleepy.setWeight(44.3); Ini.Section sec = ini.add("sleepy"); sec.from(sleepy); //} //| assertTrue(sec.containsKey(Dwarf.PROP_AGE)); assertTrue(sec.containsKey(Dwarf.PROP_WEIGHT)); } //| //|* Unmarshalling beans //| //| If you have a marshalled bean in text file then you may want to read it //| into bean. This operation usually called unmarshalling. //| //| With [ini4j] it is easy to load bean properties from a section. You simply //| instantiate a bean, and call the sections's <<>> method. Thats it. //{ void sample03(Ini ini) { DwarfBean grumpy = new DwarfBean(); ini.get("grumpy").to(grumpy); //} //| assertEquals(DwarfsData.grumpy.age, grumpy.getAge()); assertEquals(DwarfsData.grumpy.homeDir, grumpy.getHomeDir()); } //| //|* Indexed properties //| //| For handling indexed properties, you should allow mulpti option value //| handling in configuration. After enabling this feature, option may contains //| multiply values (multi line in file). These values can mapped to indexed //| bean property. //{ void sample04(URL location) throws IOException { Config cfg = new Config(); cfg.setMultiOption(true); Ini ini = new Ini(); ini.setConfig(cfg); ini.load(location); Ini.Section sec = ini.get("sneezy"); Dwarf sneezy = sec.as(Dwarf.class); int[] numbers = sneezy.getFortuneNumber(); // // same as above but with unmarshalling... // DwarfBean sneezyBean = new DwarfBean(); sec.to(sneezyBean); numbers = sneezyBean.getFortuneNumber(); //} assertArrayEquals(DwarfsData.sneezy.fortuneNumber, numbers); assertEquals(DwarfsData.sneezy.fortuneNumber.length, sec.length("fortuneNumber")); assertArrayEquals(DwarfsData.sneezy.fortuneNumber, sneezy.getFortuneNumber()); assertArrayEquals(DwarfsData.sneezy.fortuneNumber, sneezyBean.getFortuneNumber()); } //| //|* Options //| //| Not only Ini and Ini.Section has bean interface. There is a bean interface //| for OptionMap class and each derived class for example for Options. //| Options is an improved java.util.Properties replacement. //{ void sample05(Options opts) { Dwarf dwarf = opts.as(Dwarf.class); int age = dwarf.getAge(); // // same as above but with unmarshalling // DwarfBean dwarfBean = new DwarfBean(); opts.to(dwarfBean); age = dwarfBean.getAge(); //} //| //| In sample above the top level properties (like "age") mapped to bean //| properties. //| assertEquals(DwarfsData.bashful.age, dwarf.getAge()); assertEquals(DwarfsData.bashful.age, dwarfBean.getAge()); } //| //|* Prefixed mapping //| //| Both Ini.Section and Options has possibility to add a prefix to property //| names while mapping from bean property name to Ini.Section or Options //| key. //{ void sample06(URL optPath) throws IOException { Options opt = new Options(optPath); Dwarf dwarf = opt.as(Dwarf.class, "happy."); DwarfBean bean = new DwarfBean(); opt.to(bean, "dopey."); //} //| //| In the above example, <<>> bean will contain properties starts with //| <<>> while <<>> will contain properties starts with //| <<>> assertEquals(DwarfsData.happy.age, dwarf.getAge()); assertEquals(DwarfsData.dopey.age, bean.getAge()); } //} } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/IniTutorial.java000066400000000000000000000151571151645323700252540ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; import org.ini4j.Ini; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.Map; import java.util.Set; // //| //| ------------- //| Ini Tutorial //| //|Ini Tutorial - How to use \[ini4j\] api //| //| This tutorial familiarize the reader with the usage of //| the [ini4j] library's natural interface. //| //| Code sniplets in this tutorial tested with the following .ini file: //| {{{../sample/dwarfs.ini.html}dwarfs.ini}} //| // public class IniTutorial extends AbstractTutorial { public static void main(String[] args) throws Exception { new IniTutorial().run(filearg(args)); } @Override protected void run(File arg) throws Exception { Ini ini = new Ini(arg.toURI().toURL()); sample01(ini); sample02(arg); sample03(ini); sample04(ini); } //|* Data model //| //| Data model for .ini files is represented by org.ini4j.Ini class. This class //| implements Map\. It mean you can access sections using //| java.util.Map collection API interface. The Section is also a map, which is //| implements Map\. //{ void sample01(Ini ini) { Ini.Section section = ini.get("happy"); // // read some values // String age = section.get("age"); String weight = section.get("weight"); String homeDir = section.get("homeDir"); // // .. or just use java.util.Map interface... // Map map = ini.get("happy"); age = map.get("age"); weight = map.get("weight"); homeDir = map.get("homeDir"); // get all section names Set sectionNames = ini.keySet(); //} Helper.assertEquals(DwarfsData.happy, section.as(Dwarf.class)); } //| //|* Loading and storing data //| //| There is several way to load data into Ini object. It can be done by using //| <<>> methods or overloaded constructors. Data can be load from //| InputStream, Reader, URL or File. //| //| You can store data using <<>> methods. Data can store to OutputStream, //| Writer, or File. //{ void sample02(File file) throws IOException { Ini ini = new Ini(); ini.load(new FileReader(file)); // // or instantiate and load data: // ini = new Ini(new FileReader(file)); File copy = File.createTempFile("sample", ".ini"); ini.store(copy); //} ini = new Ini(copy); Helper.assertEquals(DwarfsData.dwarfs, ini.as(Dwarfs.class)); copy.delete(); } //| //|* Macro/variable substitution //| //| To get a value, besides <<>> you can also //| use <<>> which resolves any occurrent $\{section/option\} format //| variable references in the needed value. //| //{ void sample03(Ini ini) { Ini.Section dopey = ini.get("dopey"); // get method doesn't resolve variable references String weightRaw = dopey.get("weight"); // = ${bashful/weight} String heightRaw = dopey.get("height"); // = ${doc/height} // to resolve references, you should use fetch method String weight = dopey.fetch("weight"); // = 45.7 String height = dopey.fetch("height"); // = 87.7 //} //| Assuming we have an .ini file with the following sections: //| //|+--------------+ //| [dopey] //| weight = ${bashful/weight} //| height = ${doc/height} //| //|[bashful] //| weight = 45.7 //| height = 98.8 //| //| [doc] //| weight = 49.5 //| height = 87.7 //|+--------------+ //| assertEquals(DwarfsData.INI_DOPEY_WEIGHT, weightRaw); assertEquals(DwarfsData.INI_DOPEY_HEIGHT, heightRaw); assertEquals(String.valueOf(DwarfsData.dopey.weight), weight); assertEquals(String.valueOf(DwarfsData.dopey.height), height); } //| //|* Multi values //| //| \[ini4j\] library introduces MultiMap interface, which is extends normal //| Map, but allows multiply values per keys. You can simply index values for //| a given key, similar to indexed properties in JavaBeans api. //| //{ void sample04(Ini ini) { Ini.Section sneezy = ini.get("sneezy"); String n1 = sneezy.get("fortuneNumber", 0); // = 11 String n2 = sneezy.get("fortuneNumber", 1); // = 22 String n3 = sneezy.get("fortuneNumber", 2); // = 33 String n4 = sneezy.get("fortuneNumber", 3); // = 44 // ok, lets do in it easier... int[] n = sneezy.getAll("fortuneNumber", int[].class); //} // #2817399 assertEquals("11", n1); assertEquals("22", n2); assertEquals("33", n3); assertEquals("44", n4); assertEquals(4, n.length); assertEquals(11, n[0]); assertEquals(22, n[1]); assertEquals(33, n[2]); assertEquals(44, n[3]); } //| //|* Tree model //| //| Beyond two level map model, Ini class provides tree model. You can access //| Sections as tree. It means that section names becomes path names, with a //| path separator character ('/' and '\' on Wini and Reg). //| //{ void sample05() { Ini ini = new Ini(); // lets add a section, it will create needed intermediate sections as well ini.add("root/child/sub"); // Ini.Section root; Ini.Section sec; root = ini.get("root"); sec = root.getChild("child").getChild("sub"); // or... sec = root.lookup("child", "sub"); // or... sec = root.lookup("child/sub"); // or even... sec = ini.get("root/child/sub"); //} //| If you are using Wini instead of Ini class, the path separator become '\'. //| assertNotNull(root.lookup("child", "sub")); assertNotNull(ini.get("root/child")); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/OneMinuteTutorial.java000066400000000000000000000073451151645323700264400ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; import org.ini4j.Wini; import org.ini4j.sample.Dwarf; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.*; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; // //| //| ------------------- //| One minute Tutorial //| //|One minute Tutorial - First step //| //| First step with \[ini4j\] library. No data model, no interfaces, no design //| patterns, simply read and write windows .ini files. //| // public class OneMinuteTutorial extends AbstractTutorial { public static void main(String[] args) throws Exception { new OneMinuteTutorial().run(filearg(args)); } protected void copy(File inputFile, File outputFile) throws IOException { FileInputStream is = new FileInputStream(inputFile); FileOutputStream os = new FileOutputStream(outputFile); byte[] buff = new byte[8192]; int n; while ((n = is.read(buff)) > 0) { os.write(buff, 0, n); } is.close(); os.close(); } @Override protected void run(File arg) throws Exception { File file = File.createTempFile("tutorial", ".ini"); file.deleteOnExit(); copy(arg, file); sample01(file.getCanonicalPath()); sample02(file.getCanonicalPath()); } //| //| Lets read some value from .ini file... //| //{ void sample01(String filename) throws IOException { Wini ini = new Wini(new File(filename)); int age = ini.get("happy", "age", int.class); double height = ini.get("happy", "height", double.class); String dir = ini.get("happy", "homeDir"); //} //| ... assuming there is a section with name <<>>, which contains at least //| the following options: <<>>, <<>> and <<>>, something like //| this: //| //|+---------+ //| [happy] //| age = 99 //| height = 77.66 //| homeDir = /home/happy //|+---------+ //| //| assertEquals(DwarfsData.happy.age, age); assertEquals(DwarfsData.happy.height, height, Helper.DELTA); assertEquals(DwarfsData.happy.homeDir, dir); } //| Now let see how to write values.... //| //{ void sample02(String filename) throws IOException { Wini ini = new Wini(new File(filename)); ini.put("sleepy", "age", 55); ini.put("sleepy", "weight", 45.6); ini.store(); //} //| ... and then file will have a section <<>> and this section //| will contains at least two options: <<>> with value <<<55>>> and <<>> //| with value <<<45.6>>>, something like this: //| //|+---------+ //| [sleepy] //| age = 55 //| weight = 45.6 //|+---------+ //| assertEquals(55, (int) ini.get(Dwarfs.PROP_SLEEPY, Dwarf.PROP_AGE, int.class)); assertEquals(45.6, (double) ini.get(Dwarfs.PROP_SLEEPY, Dwarf.PROP_WEIGHT, double.class), Helper.DELTA); } //| //| If you want to know more about this library, read //| {{{../tutorial/index.html}tutorials}} } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/OptTutorial.java000066400000000000000000000122671151645323700252760ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; import org.ini4j.Options; import org.ini4j.sample.Dwarf; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.*; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.Set; // //| //| ---------------- //| Options Tutorial //| //|Options Tutorial - java.util.Properties replacement //| //| Options (org.ini4j.Options) is a java.util.Properties replacement with //| several useful features, like: //| //| * variable/macro substitution. You may refer to other property's value with //| $\{NAME\} expression, where NAME is the name of the referred property. //| ofcourse you can use more than one property reference per property, and //| you can mix constant text and property references: //| //|+-------------------+ //|player.name = Joe //|player.greetings = Hi ${player.name}! //|player.domain = foo.bar //|player.email = ${player.name}@${player.domain} //|+-------------------+ //| //| * multiply property values. You can refer to multi value properties with //| integer indexes. Ofcource it is also works in macro/variable substitutions: //| $\{user.fortuneNumber\[2\]\} //| //|+-------------------+ //|player.fortuneNumber = 33 //|player.fortuneNumber = 44 //|player.fortuneNumber = 55 //|player.fortuneNumber = 66 //| //|magicNumber = ${player.foruneNumber[1]} //|+--------------------+ //| //| The magicNumber property will have value: <<<44>>> //| //| * as Java class, Options is basicly map of Strings indexed with Strings. It //| is standard Collection API (ok, it is a bit enhanced to deal with multi //| values, but in general it is a Map\). //| //| * Java Beans api. You can read/write properties in type safe way. To do it //| you just define an interface, call Options#as() method. This method will //| provide an implementation of given interface on top of Options. Property //| types are mapped automatically between Java type and String. //| //|* Why need Options //| //| With standard Properties class there is several small problem. Most of them //| came from backward compatibility. //| //| * not implements Map\, but Map\. If you //| want to use Collections api, it is a bit unconfortable. //| //| * only single property values allowed. Probably you already see ugly //| workarounds: index number in property names, like: file.1, file.2 ... //| //| * no macro/variable substitution. In some environment, like //| Apache Ant, you can use ${name} like references, but with standard //| java.util.Properties you can't. //| //| As side effect of \[ini4j\] development, there is a solution for aboves. //| This is the org.ini4j.Options class, which is basicly a feature rich //| replacement for java.util.Properties. //| //| Code sniplets in this tutorial tested with the following .opt file: //| {{{../sample/dwarfs.opt.html}dwarfs.opt}} //| // public class OptTutorial extends AbstractTutorial { public static final String FILENAME = "../sample/dwarfs.opt"; public static void main(String[] args) throws Exception { new OptTutorial().run(filearg(args)); } protected void run(File arg) throws Exception { Options opt = new Options(arg.toURI().toURL()); sample01(arg); sample02(opt); } //| //|* Instantiating //| //| There is nothing special with instantiating Options object, but there is a //| few constructor, to simplify loading data. These constructors simply call //| the <<>> method on newly created instance. Ofcource these //| constructors are throws IOException. //{ void sample01(File file) throws IOException { Options opt = new Options(); // // or instantiate and load data: // opt = new Options(new FileReader(file)); //} assertFalse(opt.keySet().isEmpty()); } //| //|* Map of String //{ void sample02(Options opt) { Set optionNames = opt.keySet(); // String age = opt.get("age"); String weight = opt.fetch("weight"); String height = opt.fetch("height"); //} //| //| The Options is a MultiMap\, that is, a map that assigns //| String values to String keys. So the <<>> method is used to get values //| inside the options. To get a value, besides <<>> you can also //| use <<>> which resolves any occurrent $\{option\} format //| variable references in the needed value. Helper.assertEquals(DwarfsData.dopey, opt.as(Dwarf.class)); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/OptionMapTutorial.java000066400000000000000000000110421151645323700264300ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; import org.ini4j.Ini; import org.ini4j.sample.Dwarfs; import org.ini4j.test.DwarfsData; import static org.junit.Assert.*; import java.io.File; import java.util.Set; // //| //| ------------- //| OptionMap Tutorial //| //|OptionMap Tutorial - more than just String,String map //| //| Option is a name/value pair stored in OptionMap. But OptionMap adds a lot of //| usefull data access methods than simple get. OptionMap is base interface for //| both Ini.Section, Registry.Key and Options classes, so this tutorial will //| usefull for all of these. //| //| So in samples bellow you can use either Ini.Section, Registry.Key or Options //| classes instead of OptionMap interface, because these classes implements //| OptionMap. //| //| Code sniplets in this tutorial tested with the following files: //| {{{../sample/dwarfs.ini.html}dwarfs.ini}} //| {{{../sample/dwarfs.opt.html}dwarfs.opt}} //| // public class OptionMapTutorial extends AbstractTutorial { public static void main(String[] args) throws Exception { new OptionMapTutorial().run(filearg(args)); } @Override protected void run(File arg) throws Exception { Ini ini = new Ini(arg.toURI().toURL()); sample01(ini.get(Dwarfs.PROP_HAPPY)); sample03(ini); sample04(ini); } //|* Data model //| //| OptionMap implements Map\, so you can access options using //| standard collection api. //{ void sample01(Ini.Section section) { // // read some values // String age = section.get("age"); String weight = section.get("weight"); String homeDir = section.get("homeDir"); // get all option names Set optionNames = section.keySet(); //} assertEquals(String.valueOf(DwarfsData.happy.age), age); assertEquals(String.valueOf(DwarfsData.happy.weight), weight); assertEquals(String.valueOf(DwarfsData.happy.homeDir), homeDir); } //| //|* Macro/variable substitution //| //| To get a value, besides <<>> you can also //| use <<>> which resolves any occurrent $\{section/option\} format //| variable references in the needed value. //| //{ void sample03(Ini ini) { Ini.Section dopey = ini.get("dopey"); // get method doesn't resolve variable references String weightRaw = dopey.get("weight"); // = ${bashful/weight} String heightRaw = dopey.get("height"); // = ${doc/height} // to resolve references, you should use fetch method String weight = dopey.fetch("weight"); // = 45.7 String height = dopey.fetch("height"); // = 87.7 //} //| Assuming we have an .ini file with the following sections: //| //|+--------------+ //| [dopey] //| weight = ${bashful/weight} //| height = ${doc/height} //| //|[bashful] //| weight = 45.7 //| height = 98.8 //| //| [doc] //| weight = 49.5 //| height = 87.7 //|+--------------+ //| assertEquals(DwarfsData.INI_DOPEY_WEIGHT, weightRaw); assertEquals(DwarfsData.INI_DOPEY_HEIGHT, heightRaw); assertEquals(String.valueOf(DwarfsData.dopey.weight), weight); assertEquals(String.valueOf(DwarfsData.dopey.height), height); } //| //|* Multi values //| //| \[ini4j\] library introduces MultiMap interface, which is extends normal //| Map, but allows multiply values per keys. You can simply index values for //| a given key, similar to indexed properties in JavaBeans api. //| //{ void sample04(Ini ini) { Ini.Section sneezy = ini.get("sneezy"); String n1 = sneezy.get("fortuneNumber", 0); // = 11 String n2 = sneezy.get("fortuneNumber", 1); // = 22 String n3 = sneezy.get("fortuneNumber", 2); // = 33 String n4 = sneezy.get("fortuneNumber", 3); // = 44 // ok, lets do in it easier... int[] n = sneezy.get("fortuneNumber", int[].class); //} } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/PrefsTutorial.java000066400000000000000000000056611151645323700256130ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; import org.ini4j.Ini; import org.ini4j.IniPreferences; import org.ini4j.test.DwarfsData; import static org.junit.Assert.*; import java.io.File; import java.io.IOException; import java.util.prefs.Preferences; // //| //| ------------- //| Preferences Tutorial //| //|Preferences Tutorial //| //| The purpose of this document is to familiarize the reader with the usage of //| the [ini4j] library's Preferences interface. Each chapter contains all the //| necessary code portions and explanation for a given function. //| //| Code sniplets in this tutorial tested with the following .ini file: //| {{{../sample/dwarfs.ini.html}dwarfs.ini}} //| //| As soon as the Preferences object is created it functions as a standard Preferences node, and should be //| used as such. Implicitly only new nodes can be created in the root node (these will be the sections). //| In the first level nodes (sections) only values can be created (these will be the options). //| //| In the case of an invalid operation an <<>> type runtime exception is generated. //| This happens if we try to set a value at the root node or to create a node on the second level, //| since these operations cannot be interpreted on the whole .ini file under Preferences. //| // public class PrefsTutorial extends AbstractTutorial { public static void main(String[] args) throws Exception { new PrefsTutorial().run(filearg(args)); } protected void run(File arg) throws Exception { Ini ini = new Ini(arg.toURI().toURL()); sample01(ini); } //| //|* Reading and writing values //| //| Values can read and write like any other Preferences node, there is no //| differences. //{ void sample01(Ini ini) throws IOException { Preferences prefs = new IniPreferences(ini); Preferences bashful = prefs.node("bashful"); String home = bashful.get("homeDir", "/home"); int age = bashful.getInt("age", -1); bashful.putDouble("weight", 55.6); //} assertEquals(DwarfsData.bashful.homeDir, bashful.get("homeDir", null)); assertEquals(DwarfsData.bashful.age, bashful.getInt("age", -1)); assertEquals(55.6, bashful.getDouble("weight", -1), 0.001); } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/RegTutorial.java000066400000000000000000000111171151645323700252420ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; import org.ini4j.Reg; import org.ini4j.sample.Dwarf; import org.ini4j.test.DwarfsData; import org.ini4j.test.Helper; import static org.junit.Assert.*; import java.io.File; import java.io.IOException; import java.net.URI; // //| //| ------------- //| Reg Tutorial //| //|Reg Tutorial - Windows .REG file handling //| //| Windows regedit commands .REG file format is very close to .ini format. //| \[ini4j\] provides org.ini4j.Reg class to model .REG format. This tutorial //| show the differences between Ini and Reg classes. //| //| Code sniplets in this tutorial tested with the following .reg file: //| {{{../sample/dwarfs.reg.html}dwarfs.reg}} //| // public class RegTutorial extends AbstractTutorial { public static final String FILENAME = "../sample/dwarfs.reg"; public static void main(String[] args) throws Exception { new RegTutorial().run(filearg(args)); } @Override protected void run(File arg) throws Exception { Reg reg = new Reg(arg.toURI().toURL()); sample01(arg); sample02(); } //| //|* Loading and storing //| //| There is nothing special with loading and storing data, it works exactly same //| as in Ini class. But while loading data, Reg class will strip .REG special //| values (double qoute around strings, type data from option, etc). So after //| loading a .REG file, you can use it exactly same way as Ini class. Ofcource //| if you store Reg class, it will put all above meta information int file, so //| the result will be a valid .REG file. You don't need to worry about file //| encoding, version in first line, etc,etc. //| //| Assume you have a .REG file, with the following section/key: //| //|+---+ //|[HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\bashful] //|@="bashful" //|"weight"=hex(2):34,00,35,00,2e,00,37,00,00,00 //|"height"="98.8" //|"age"=dword:00000043 //|"homePage"="http://snowwhite.tale/~bashful" //|"homeDir"="/home/bashful" //|+---+ //| //| As you see, "weight" and "age" is not simlpe strings. The "height" is a REG_DWORD //| type while "weight" is REG_EXPAND_SZ. Don't worry, Reg class take care about //| type conversion, you will access these as with regular .ini files: //{ void sample01(File file) throws IOException { Reg reg = new Reg(file); Reg.Key hive = reg.get(Reg.Hive.HKEY_CURRENT_USER.toString()); Reg.Key bashful; bashful = hive.lookup("Software", "ini4j-test", "dwarfs", "bashful"); // or ... bashful = hive.lookup("Software\\ini4j-test\\dwarfs\\bashful"); // or even... bashful = reg.get("HKEY_CURRENT_USER\\Software\\ini4j-test\\dwarfs\\bashful"); // read some data double weight = bashful.get("weight", double.class); // = 45.7 double height = bashful.get("height", double.class); // = 98.8 int age = bashful.get("age", int.class); // = 67 URI homePage = bashful.get("homePage", URI.class); // = new URI("http://snowwhite.tale/~bashful"); String homeDir = bashful.get("homeDir"); // = "/home/bashful" //} assertNotNull(reg.get(Helper.DWARFS_REG_PATH + "\\dwarfs")); Helper.assertEquals(DwarfsData.bashful, bashful.as(Dwarf.class)); } //| //|* Types //| //| When you load data into Reg class, it will preserve meta informations, such as //| type informations. If you create new values, by default these will have //| tpye REG_SZ. Ofcource you may specify type information for values. //{ void sample02() { Reg reg = new Reg(); Reg.Key key = reg.add("HKEY_CURRENT_USER\\Software\\ini4j-test\\dwarfs\\sleepy"); key.put("fortuneNumber", 99); key.putType("fortuneNumber", Reg.Type.REG_MULTI_SZ); //} //| //| If you store reg object above, it will contains a section similar to this: //| //|+---+ //|[HKEY_CURRENT_USER\Software\ini4j-test\dwarfs\sleepy] //|"fortuneNumber"=hex(7):39,00,39,00,00,00,00,00 //|+---+ //| } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/WindowsRegistryTutorial.java000066400000000000000000000054261151645323700277160ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; import org.ini4j.Reg; import static org.junit.Assert.*; import java.io.File; import java.io.IOException; // //| //| ------------------------- //| Windows Registry Tutorial //| //|Windows Registry Tutorial - Read/Write windows registry //| //| Yes, it is possible now to read/write registry from java programs //| without native (JNI) code ! //| // public class WindowsRegistryTutorial extends AbstractTutorial { public static final String FILENAME = "../sample/dwarfs.reg"; public static void main(String[] args) throws Exception { if (Reg.isWindows()) { new WindowsRegistryTutorial().run(filearg(args)); } } @Override protected void run(File arg) throws Exception { sample01(); sample02(); sample03(); } //| //|* Write //| //| Lets write something to registry //{ void sample01() throws IOException { Reg reg = new Reg(); Reg.Key key = reg.add("HKEY_CURRENT_USER\\hello"); key.put("world", "Hello World !"); reg.write(); //} //| This code will create a "hello" key in HKEY_CURRENT_USER hive, and //| put "Hello World !" with name "world". } //| //|* Read //| //| Lets read something from Control Panel settings... //{ void sample02() throws IOException { Reg reg = new Reg("HKEY_CURRENT_USER\\Control Panel"); Reg.Key cp = reg.get("HKEY_CURRENT_USER\\Control Panel"); Reg.Key sound = cp.getChild("Sound"); String beep = sound.get("Beep"); //} //| } //| //|* Create environment variable //| //| Lets create a new environment variable under current users environment.... //{ void sample03() throws IOException { Reg reg = new Reg(); Reg.Key env = reg.add("HKEY_CURRENT_USER\\Environment"); env.put("SAMPLE_HOME", "c:\\sample"); reg.write(); //} //| Thats it ! Now your environment contains variable SAMPLE_HOME ! Unfortunetly //| you have to restart Windows to see this variable.... but hey, we crated new //| environment variable from java without any native code ! } } ini4j-0.5.2-SNAPSHOT/src/test/java/org/ini4j/tutorial/package-info.java000066400000000000000000000017041151645323700253260ustar00rootroot00000000000000/* * Copyright 2005,2009 Ivan SZKIBA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.ini4j.tutorial; //| //| --------- //| Tutorials //| //|Tutorials //| //| The following tutorials organized on different tpye of API that ini4j provide. //| The build process of [ini4j] guarantees compilability and runability, since no //| distribution may be created without compiling and running the tutorial codes. //| ini4j-0.5.2-SNAPSHOT/src/test/resources/000077500000000000000000000000001151645323700175575ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/resources/META-INF/000077500000000000000000000000001151645323700207175ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/resources/META-INF/services/000077500000000000000000000000001151645323700225425ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/resources/META-INF/services/org.ini4j.BadConfig000066400000000000000000000000251151645323700261000ustar00rootroot00000000000000 org.ini4j.IniParser ini4j-0.5.2-SNAPSHOT/src/test/resources/META-INF/services/org.ini4j.Dummy000066400000000000000000000000111151645323700253520ustar00rootroot00000000000000DummyImplini4j-0.5.2-SNAPSHOT/src/test/resources/META-INF/services/org.ini4j.EmptyConfig000066400000000000000000000000001151645323700265010ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/resources/org/000077500000000000000000000000001151645323700203465ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/000077500000000000000000000000001151645323700213635ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/addon/000077500000000000000000000000001151645323700224505ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/addon/dwarfs-py-bad.ini000066400000000000000000000011421151645323700256070ustar00rootroot00000000000000; ; Copyright 2005,2009 Ivan SZKIBA ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. ; You may obtain a copy of the License at ; ; http://www.apache.org/licenses/LICENSE-2.0 ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. ; ; Bashful [bashful age=3 ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/addon/dwarfs-py.ini000066400000000000000000000030511151645323700250640ustar00rootroot00000000000000; ; Copyright 2005,2009 Ivan SZKIBA ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. ; You may obtain a copy of the License at ; ; http://www.apache.org/licenses/LICENSE-2.0 ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. ; ; Bashful [bashful] weight = 45.7 height = 98.8 age = 67 homePage = http://snowwhite.tale/~bashful homeDir = /home/bashful ; Doc [doc] weight = 49.5 height = 87.7 age = 63 homePage = http://doc.dwarfs homeDir = c:Documents and Settingsdoc ; Dopey [dopey] weight = %(_weight) height = %(_height) age = 23 homePage = http://dopey.snowwhite.tale/ homeDir = c:\Documents and Settings\dopey ; Grumpy [grumpy] weight = 65.3 height = %(_height) age = 76 homePage = http://snowwhite.tale/~grumpy/ homeDir = /home/grumpy ; Happy [happy] weight = 56.4 height = 77.66 age = 99 homePage = dummy homeDir = /home/happy ; Sleepy [sleepy] name=sleepy weight = 76.11 height = %(_height)8 age = 121 homePage = http://snowwhite.tale/~%(name) homeDir = /home/%(name) ; Sneezy [sneezy] weight = 69.7 height = 76.88 age = 64 homePage = %(_site)/~sneezy homeDir = /home/sneezy ; Happy again [happy] homePage = http://happy.smurf [default] _site = http://happy.smurf _age = 99 _weight = 45.7 _height = 87.7 ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/mozilla.reg000066400000000000000000000167041151645323700235410ustar00rootroot00000000000000Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE] [HKEY_LOCAL_MACHINE\SOFTWARE] [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla] [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox] @="1.9.0.7" "CurrentVersion"="3.0.7 (en-US)" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox\3.0.7 (en-US)] @="3.0.7 (en-US)" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox\3.0.7 (en-US)\Main] "Install Directory"="C:\\Program Files\\Mozilla Firefox" "PathToExe"="C:\\Program Files\\Mozilla Firefox\\firefox.exe" "Program Folder Path"="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\" "Start Menu Folder"="Mozilla Firefox" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox\3.0.7 (en-US)\Uninstall] "Uninstall Log Folder"="C:\\Program Files\\Mozilla Firefox\\uninstall" "Description"="Mozilla Firefox (3.0.7)" "Create Start Menu Shortcut"=dword:00000001 [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox 3.0.7] "GeckoVer"="1.9.0.7" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox 3.0.7\bin] "PathToExe"="C:\\Program Files\\Mozilla Firefox\\firefox.exe" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox 3.0.7\extensions] "Components"="C:\\Program Files\\Mozilla Firefox\\components" "Plugins"="C:\\Program Files\\Mozilla Firefox\\plugins" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Sunbird] @="1.8.1.18pre" "CurrentVersion"="0.9 (en-US)" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Sunbird\0.9 (en-US)] @="0.9 (en-US)" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Sunbird\0.9 (en-US)\Main] "Install Directory"="C:\\Program Files\\Mozilla Sunbird" "PathToExe"="C:\\Program Files\\Mozilla Sunbird\\sunbird.exe" "Program Folder Path"="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\" "Create Quick Launch Shortcut"=dword:00000001 "Create Desktop Shortcut"=dword:00000001 "Create Start Menu Shortcut"=dword:00000001 "Start Menu Folder"="Mozilla Sunbird" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Sunbird\0.9 (en-US)\Uninstall] "Uninstall Log Folder"="C:\\Program Files\\Mozilla Sunbird\\uninstall" "Description"="Mozilla Sunbird (0.9)" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Sunbird 0.9] "GeckoVer"="1.8.1.18pre" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Sunbird 0.9\bin] "PathToExe"="C:\\Program Files\\Mozilla Sunbird\\sunbird.exe" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Sunbird 0.9\extensions] "Components"="C:\\Program Files\\Mozilla Sunbird\\components" "Plugins"="C:\\Program Files\\Mozilla Sunbird\\plugins" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Thunderbird] @="1.8.1.21" "CurrentVersion"="2.0.0.21 (en-US)" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Thunderbird\2.0.0.21 (en-US)] @="2.0.0.21 (en-US)" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Thunderbird\2.0.0.21 (en-US)\Main] "Install Directory"="C:\\Program Files\\Mozilla Thunderbird" "PathToExe"="C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe" "Program Folder Path"="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\" "Start Menu Folder"="Mozilla Thunderbird" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Thunderbird\2.0.0.21 (en-US)\Uninstall] "Uninstall Log Folder"="C:\\Program Files\\Mozilla Thunderbird\\uninstall" "Description"="Mozilla Thunderbird (2.0.0.21)" "Create Start Menu Shortcut"=dword:00000001 [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Thunderbird 2.0.0.21] "GeckoVer"="1.8.1.21" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Thunderbird 2.0.0.21\bin] "PathToExe"="C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe" [HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Thunderbird 2.0.0.21\extensions] "Components"="C:\\Program Files\\Mozilla Thunderbird\\components" "Plugins"="C:\\Program Files\\Mozilla Thunderbird\\plugins" ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/000077500000000000000000000000001151645323700221565ustar00rootroot00000000000000ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-16BE-BOM.ini000066400000000000000000000000641151645323700243630ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-16BE.ini000066400000000000000000000000621151645323700237460ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-16LE-BOM.ini000066400000000000000000000000641151645323700243750ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-16LE.ini000066400000000000000000000000621151645323700237600ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-32BE-BOM.ini000066400000000000000000000001501151645323700243550ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-32BE.ini000066400000000000000000000001441151645323700237450ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-32LE-BOM.ini000066400000000000000000000001501151645323700243670ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-32LE.ini000066400000000000000000000001441151645323700237570ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-8-BOM.ini000066400000000000000000000000341151645323700240720ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/UTF-8.ini000066400000000000000000000000311151645323700234540ustar00rootroot00000000000000[section] option = value ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/include.txt000066400000000000000000000003651151645323700243460ustar00rootroot00000000000000#-1:include.txt 1:include.txt #-2:include.txt #-3:include.txt 2:include.txt #-4:include.txt #-5:include.txt 3:include.txt #-6:include.txt < ? part2.txt > #-7:include.txt 4:include.txt #-8:include.txt ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/nested.txt000066400000000000000000000001441151645323700242000ustar00rootroot00000000000000#-1:nested.txt 1:nested.txt #-2:nested.txt #-3:nested.txt 2:nested.txt #-4:nested.txt ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/part1.txt000066400000000000000000000001631151645323700237460ustar00rootroot00000000000000;-1:part1.txt 1:part1.txt 2:\ part1.txt 3:part1.txt\\ 4:\\\ part1.txt 5:part1.txt\\\\ 6:part1.txt\ ; ;-2:part1.txt ini4j-0.5.2-SNAPSHOT/src/test/resources/org/ini4j/spi/part2.txt000066400000000000000000000000521151645323700237440ustar00rootroot00000000000000;-1:part2.txt 1:part2.txt ;-2:part2.txt