How to write comments in JSTL properties files - java

I'd like to know how to write comments in properties file that is used like this
PF47=Ankomstdatum måste anges innan SIS kan avslutas. # AF PCT
# is supposed to mean a comment but when I render the messages with fmt format JSTL tag output includes the comment. Do comments in properties file have to be on a separate line?
Thank you

It seems as if java-property files only allow comments on separate lines, so you need to write
# AF PCT
PF47=Ankomstdatum måste anges innan SIS kan avslutas.

The format is described in the java.util.Properties documentation. And yes, the # character is only considered as the start of a comment if it's the first non-whitespace character of the line.

Related

Apache Camel's ${file:ext} picks up everything after the first dot, instead of extension only

As the title says, I am trying to get file extension using Camel's File Language to specify the correct route.
choice().
when().simple("${file:ext} in 'xml'").
unmarshal(coreIt("jaxb[Core]")).
beanRef(connectorName()+coreIt("[Core]ImportConnector"), "processXml").
when().simple("${file:ext} in 'zip,7z'").
beanRef(connectorName()+coreIt("[Core]ImportConnector"), "extractZip").
endChoice();
Problem is, client provides us with xml file that has a date in filename, separated by dots. For some reason camel treats everything after the first dot as an extension. If I do:
when().simple("${file:ext} in '09.16.xml'").
it works...
Is there any solution or workaround apart from creating a separate folder to import xml files? Thanks for your time.
Well its tough as some files may have dot in extension such as '.tar.gz' and so on. So they should ideally not use dot in the file name. To work around this you would need to use some other simple expression to check for this. You can use ends with
${file:name} ends with 'xml'
And then you can use or:
${file:name} ends with 'zip' || ${file:name} ends with '7z'
See more details at: http://camel.apache.org/simple

How do we build Normalized text file from DeNormalized one?

Thanks for your replies/time.
We need to build a Normalized text file from DeNormalized text file. We explored couple of options such as unix shell , and Loading into data base etc. I am looking pick up better ideas for resolutions from this community.
The input text file is various length with comma delimited records. The content may look like this:
**XXXXXXXXXX , YYYYYYYYYY, TTTTTTTTTTT, UUUUUUUUUU, RRRRRRRRR,JJJJJJJJJ
111111111111, 22222222222, 333333333333, 44444444, 5555555, 666666
EEEEEEEE,WWWWWW,QQQQQQQ,PPPPPPPP**
We like to normalize as follows:
**XXXXXXXXXX , YYYYYYYYYY
TTTTTTTTTTT, UUUUUUUUUU
RRRRRRRRR,JJJJJJJJJ
111111111111, 22222222222
333333333333, 44444444
5555555, 666666
EEEEEEEE,WWWWWW
QQQQQQQ,PPPPPPPP**
Are there any simple approach to get the above?
Thanks in helping.

Forcing escaped characters when writing to XML

I'm using org.w3c and javax.xml.parsers in Java for reading and writing xml files.
When I read an xml file, the
escaped line breaks will be replaced by real line breaks. When I write the content back to the file, I loose escaping and the content of the file will change unintentionally.
so
<somenode>First line.
Second line</somenode>
will be replaced by:
<somenode>First line.
Second line.</somenode>
Before writing xml content back to disk I tried:
String content = node.getTextContent().replace("\n","
");
node.setTextContent(content);
Of course it does not work, it will be escaped to &#10; in the file.
I do not want to litter the file with CDATA tags!
What I want to do is legal XML output so there has to be a way to do it.
Thanks in advance for any ideas :)
Do it by setting the following property for the JAXB Marshaller:
marshaller.setProperty("jaxb.encoding", "Unicode");

apache commons configuration loads property until "," character

I want to load configuration (apache commons configuration) from a properties file. My program is:
PropertiesConfiguration pc = new PropertiesConfiguration("my.properties");
System.out.println(pc.getString("myValue"));
In my.properties I have
myValue=value,
with comma
When I run program the output is value, not value, with comma. Looks like value is loaded until , character.
Any ideas?
That behavior is clearly documented, i.e., that PropertiesConfiguration treats a value with a comma as multiple values allowing things like:
fruit=apples,banana,oranges
to be interpreted sensibly. The fix (from the doc) is to add a backslash to escape the comma, e.g.,
myKey=value\, with an escaped comma
Check Javadoc. You have to setDelimiterParsingDisabled(true) to disable parsing list of properties.
Actually propConfig.setDelimiterParsingDisabled(true) is working, but you must load the config file after this setting, for example:
propConfig = new PropertiesConfiguration();
propConfig.setDelimiterParsingDisabled(true);
propConfig.load(propertiesFile);
Settings won't work if your code like is:
propConfig = new PropertiesConfiguration(propertiesFile);
propConfig.setDelimiterParsingDisabled(true);
PropertiesConfiguration interprets ',' as a value separator.
If you put \ before the ,, you escape it, and you can read the value
Example:
myValue=value\, with comma
You read = value, with comma without problems

Saving properties in a file with JAVA formatted

Is there a way to save Properties in Java with some formatting using the Properties object? Like is there a way to introduce new lines between entries? Or comments before each key?
I know this can be easilly done with normal I/O but wondered if there's a way of doing it with the properties object.
The key to writing a comment between each set of properties is to store them in multiple Properties objects.
ie
FileOutputStream fos = new FileOutputStream("c:/myconfig.property");
Properties prop = new Properties();
prop.put("com.app.port", "8080");
prop.put("com.app.ip", "127.0.0.1");
prop.store(fos, "A Test to write properties");
fos.flush();
Properties prop2 = new Properties();
prop2.put("com.app.another", "Hello World");
prop2.store(fos, "Where does this go?");
fos.flush();
fos.close();
This will produce an output such as
#A Test to write properties
#Fri Apr 08 15:28:26 ADT 2011
com.app.ip=127.0.0.1
com.app.port=8080
#Where does this go?
#Fri Apr 08 15:28:26 ADT 2011
com.app.another=Hello World
I have made a class that handles comments in properties.
Both general header comments and comments for individual properties.
Have a look at : CommentedProperties JavaDoc
The jar file can be downloaded here : Download jar file from sourceforge
No. How would the Properties element know what comments to write before each key?
You can include file-level comments when you Properties.store( Writer, String ). After that comment and a timestamp comment:
Then every entry in this Properties table is written out, one per line.
For each entry the key string is written, then an ASCII =, then the associated
element string. For the key, all space characters are written with a
preceding \ character. For the element, leading space characters, but not
embedded or trailing space characters, are written with a preceding \ character.
The key and element characters #, !, =, and : are written with a preceding
backslash to ensure that they are properly loaded.
On the other hand, you can provide instructions on writing extra lines and comments in properties files -- using a Properties object as a source of data.
The Properties object itself doesn't retain any details about the structure of how it was saved in the file. It just has a map of data, which in fact means it won't even necessary write them in the same order they were read. You'll have to use normal I/O to keep the formatting and make your desired changes.
The class CommentedProperties
Will parse the properties
## General comment line 1
## General comment line 2
##!General comment line 3, is ignored and not loaded
## General comment line 4
# Property A comment line 1
A=1
# Property B comment line 1
# Property B comment line 2
B=2
! Property C comment line 1
! Property C comment line 2
C=3
D=4
# Property E comment line 1
! Property E comment line 2
E=5
# Property F comment line 1
#!Property F comment line 2, is ignored and not loaded
! Property F comment line 3
F=5
The properties file comments is:
General comment line 1
General comment line 2
General comment line 4
So Property "A" comments is:
Property A comment line 1
So Property "B" comments is:
Property B comment line 1
Property B comment line 2
So Property "C"
Property C comment line 1
Property C comment line 2
So Property "D" comments is empty.
So Property "E" comments is:
Property E comment line 1
Property E comment line 2
So Property "F" comments is:
Property F comment line 1
Property F comment line 3

Categories

Resources