Wiki source for CommandXProperties


Show raw source

======Command xproperties======


====Name====
**xproperties** Manage a Java Properties file


====Synopsis====
xproperties [ [[SerializationOptions serialization options]] ] [options]

||-in file||Load a Properties file in text form||
||-inxml file||Load a Properties file in xml form||
||-text ||Output properties in text form to stdout||
||-xml||Output properties in xml form to stdout||
||-d,-delete var||Delete a variable from the properties||
||-a,-add var=value||Add (or replace) a variable (name "var", value "value") to the properties||
||-comment||Append or update the comment||
||-v,-var var||print out the value of a variable (cannot be intermixed with -text or -xml) ||

Supports the standard [ [[SerializationOptions serialization options]] ]

====Description====
xproperties can be used to create new properties files, transform files from text to xml form, add, delete and print property values.

xproperties creates a Java Properties object in memory, then optionaly loads values from a file (in text or xml form), optional adds or updates the properties then prints the resultant properties file in either text or xml form.
The text and XML forms are as specified (and implemented) by the Java java.util.Properties object
if one or more -v (or -var) options are specified then instead of serializeing the entire resultant properties file then one or more values from the (possibly edited) properties file are output followed by a newline.

If a input file is specified as "-" then stdin is used.
If neither -v, -text or -xml is specified then -xml is presumed.


Examples

Create a new properties file in text form with initial contents
%%
xproperties -text -a var1="Value 1" -add var2="Value 2"
%%

Produces this output
%%
#Sat Nov 14 12:42:24 EST 2009
var2=Value 2
var1=Value 1
%%

Convert the above property file to xml form
%%
xproperties -in file.properties
%%

Produces

%%(xml)
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd" []>
<properties version="1.0">
<entry key="var2">Value 2</entry>
<entry key="var1">Value 1</entry>
</properties>
%%

Print out the value of var2 from the above xml format
%%
xproperties -inxml prop.xml -v var2
%%

Produces
%%
Value 2
%%

===Using with tie===

xproperties output can be easily referenced using the [[CommandTie tie]] command

Example

Input file config.properties a text formated properties file
%%
login=admin
%%


This command
%%
PROPS=$<(xproperties -in config.properties)
tie PROPS './/entry[@key = $_ ]/string()'

echo ${PROPS:login}
%%

Produces
%%
admin
%%



====Return Value====
Returns 0 if the command executed successfully, 1 if there was an error.
----
[[CommandTie tie]]
[[Commands]]
[[CategoryCommands]]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki