My requirement was to update a key/value pair property file for which Commons Configuration is used.
But problem is when you save any text using this api it remove space after comma in a value.
If you disable parsing then it create multiple keys of safe name broken by comma :(
PropertiesConfiguration config = new PropertiesConfiguration("prop.properties");
//config.setDelimiterParsingDisabled(true);
config.save();
Expected value (with no truncation of spaces after before comma):
Name = some , Text , for testing
If setDelimiterParsingDisabled is false then below is outout all spaces gone
Name = some,Text,for testing
If that is True then below is output
Name = some
Name = Text
Name = for testing
I need first one with all space intact means key as is...how to do that
I believe both things cannot be achieved so what is id is I changed Delimeter to carrot ^ sign and not it behaving as I like.
So this is answered.
Related
I am new to Solr and facing problems while optimizing the search in solr.
When i search for "C4902AN#140", it displays results with "140" first and result with ""C4902AN#140" is appearing later.i.e. after results containing "140".But I want result with "C4902AN#140" before results having "140".
Thanks in advance!!!
you may have to check with tokenizer you used for field type definition in schema file.
if the field type has solr.standardTokenizer it will remove # character.
OR
you should consider boosting the document which has"C4902AN#140"
you can use elevate.xml file in config folder and just mention which document to appear first in the resultset for specific searchTerm string.
The Analyzer which you are using for this should be using KeyWordTokenizerFactory so that your whole word does not get Tokenized , but only a single token , i.e the word itself is generated .
I am using below tag to query the item from DB. The item presents in DB but not showing up because A&M became as A&M instead of A&M. How to solve this?
<TEA>2720A 100 STATE A&M RD VRAD</TEA>
A backend java code queries the item from DB like 'select * from aa where tea=2720A 100 STATE A&M RD VRAD' and returns no record but it is present in DB like A&M. This is the exact issue, how to solve this?
Double encoding, your string is encoded twice.
First encoding A&M -> A&*M
Second encoding A&*M -> A&*amp*M
Check your code for this issue
Of course representing & in XML is done with &.
If just text is stored in the DB, for instance extracted fron between two tags <name>A&M</name>, then any XML API should give "A&M" to be stored.
If entire XML is stored in the DB, one should store it as-is: "<name>A&M</name>"
The problem arises only when String manipulations are done. Say
String xml = "<name>A&M</name>";
String name = xml.replaceFirst("^.*<name>(.*)</name>.*$", "$1");
name = StringEscapeUtils.unescapeXML(name);
Here apache StringEscapeUtils is used. Not unescaping makes trouble.
It probably goes wrong, when mixing extracted text (should-be-unescaped text) with XML manipulation (DOM). And again placing it in an XML structure. The XML APIs in general return values with the entities unescaped, and escape the XML characters <>&"' to entities.
Especially be careful when editing in HTML, that uses the same entity; not showing the actual characters. Here StringEscapeUtils.unescapeHtml4 comes into play.
I have a file which contains properties like :
MyKey=value1:value2
I am using Properties.load to load these into a property object and then outputting the values into another file (using Property.store ).
But the new file is delimiting it with \
MyKey=value1\:value2
Why is this happening ?
This happens, because : is like = a reserved char.
Truth = Beauty
Truth:Beauty
Truth :Beauty
All these lines will set the value for the Property with the Key Truth to Beauty
http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load(java.io.Reader)
The write method will escape the : sign to \:. After loading this chars will be removed.
I know that properties in the string can be loaded to a java.util.Properties when it is separated by \n as follows.
Is there any way to do the providing a separator dynamically eg : can we use a comma (,) as a separator?
String propertiesString = "#Namal=153\nJanith=253\nSameera=135";
Properties properties = new Properties();
properties.load(new StringReader(propertiesString));
You can tokenize the commas and join them using newlines before loading it into java.util.Properties.
Sample code below uses commons-lang and assumes you're on UNIX newlines (\n)
String propStr = "Monday=1,Tuesday=2,Wednesday=3";
String[] propsArray = StringUtils.split(propStr, ',');
Properties properties = new Properties();
properties.load(new StringReader(StringUtils.join(propsArray, "\n")));
No,you can't do this!And it's not worthy,just do it with a String .
The '\n' is default line separator, and there is a LineReader inner class which define the logic of line-reading operation,I don't think you have a chance to interact with it.
Properties class is an utility designed to load configurations.
Since \n is the newline character, I can only assume that it was chosen to make the property files easily readable.
If your requirement is to get some data stored in a custom format you can always read them and manually parse the configs using Scanner
Or go with a XML config file with a good schema.
BTW what's wrong with using the new line as a separator? I can only assume that you want to use Properties file to load a different kind of a file because for me the format of the property class make perfect sense in terms of usability and readability.
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