Revision [1348]

This is an old revision of CommandXProperties made by DavidLee on 2010-04-23 07:01:50.

 

Command xproperties



Name

xproperties Manage a Java Properties file


Synopsis

xproperties [ serialization options ] [options]

-in fileLoad a Properties file in text form
-inxml fileLoad a Properties file in xml form
-text Output properties in text form to stdout
-xmlOutput properties in xml form to stdout
-d,-delete varDelete a variable from the properties
-a,-add var=valueAdd (or replace) a variable (name "var", value "value") to the properties
-commentAppend or update the comment
-v,-var varprint out the value of a variable (cannot be intermixed with -text or -xml)

Supports the standard [ 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

<!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 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.

Commands
CategoryCommands
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki