@John: In my case I don't like your solution as it means I have to hit
the web container, which I only use for rpc calls.. I have a two
layered deployment model: Apache webserver and Tomcat webcontainer
(can be on separate servers).
Loading the properties through the webcontainer through rpc is
ofcourse an alternative and I used that in other projects. It's easy
and straight forward through a rpc call.
@SrArcos
1) I load the property file through RequestBuilder.
2) The response is parsed through code snippet A below to separate the
lines.
3) The properties are put in a map through code snippet B.
4) I then create a CmsFacadeMap with the created map as input that
implements the interface CmsFacade.
CODE (not including the unit test code):
A)
-----
/**
* Will read all lines in the specified text and will store then in
the returned list.<br>
* This method is handy as you don't need a <code>Reader</code> class
like the <code>BufferedReader</code>.
*
* @param text can be null.
* @return null if input is null.
*/
public static List<String> readLines(final String text) {
if (isEmpty(text)) {
return null;
}
else {
final List<String> result = new ArrayList<String>();
final char[] chars = text.toCharArray();
int startLineIndex = 0;
char ch;
final int size = chars.length;
boolean added = false;
for (int i = 0; i < size; i++) { // loop through all
chars
ch = chars[i];
if (ch == '\n' || ch == '\r') { // end of line
reached
if (!added) { // add line
result.add(new String(chars,
startLineIndex, i -
startLineIndex));
added = true;
}
}
else { // not end of line
if (added) { // init the start of new
line
added = false;
startLineIndex = i;
}
}
}
// add the rest
if (!added) {
result.add(new String(chars, startLineIndex,
size -
startLineIndex));
}
return result;
}
}
-------
B)
/**
* Will convert the specified line that have the format "key =
value". The key and value will be trimmed.
* @param lines can be null.
* @return null if specified input is empty or null.
*/
public static Map<String, String> toProperties(final List<String>
lines) {
if (UtilsCollection.isEmpty(lines)) {
return null;
}
else {
final Map<String, String> result = new HashMap<String,
String>();
for (String line : lines) {
line = trim(line);
if (hasLength(line) && line.charAt(0) != '#') {
final int sepIndex = line.indexOf('=');
GenExpClass.notTrueObjMsg(sepIndex ==
UtilsMisc.INT_UNDEFINED,
UtilsString.class, "PropSepNotFound", line, lines);
result.put(trim(line.substring(0,
sepIndex)),
trim(line.substring(sepIndex + 1).trim()));
}
}
return result;
}
}
On Feb 10, 7:41 pm, John LaBanca <[email protected]> wrote:
> Could you parse the file on the server side and return the Map via
> RequestFactory? That would avoid parsing on the client.
>
> Thanks,
> John LaBanca
> [email protected]
>
>
>
> On Thu, Feb 10, 2011 at 1:39 PM, SrArcos <[email protected]> wrote:
> > Hello, I am interested in this issue, can you send me the example of
> > what you did? Because, I can read any file.. in dev mode(jetty) it has
> > a path, and in hosted mode (in tomcat) it has other path... I seem
> > dificult...
>
> > On 9 feb, 16:27, Ed <[email protected]> wrote:
> > > In the meantime I simple made it myself..
> > > Not so difficult: load the text... read the lines (see the
> > > BufferedReader for example code), and separate the key = value pairs...
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.