Strings escaping problem

I need to pass a file location into a method as a parameter.
The input to the method is like this in a java properties file.
//Example file location as entered in properties file
C:\home\apps_dev\tomcat\apache-tomcat-6.0.16\shared\lib\QAWSERVE.INII know about escaping but since this is user input, the filename will not be escaped by the user.
I have to pass it to the another method in this original format
C:\home\apps_dev\tomcat\apache-tomcat-6.0.16\shared\lib\QAWSERVE.INIMy problem is, since the backslash character is an escape character, it doesn't resolve as a proper file location.
This is the code I have written
    this.iniFile = properties.getProperty("ini-file");
    System.out.println(" INI-FILE IS "+iniFile);this is the output.
INI-FILE IS C:homeapps_dev        omcatapache-tomcat-6.0.16sharedlibQAWSERVE.INII need to make the output just like the original. How can this escaping be done
Edited by: gcameo on Jul 13, 2009 3:21 AM
Edited by: gcameo on Jul 13, 2009 3:22 AM

gcameo wrote:
the properties file is all I have got. Its an application that already exists. We can try going by xml but the impact will be too much for just a single configuration.
I am looking at parsing it myself but have never done so so I looking on the internet. If any of you guys can give me any pointers that will be great.
My other option is to hard code the file into a specific location, but that is bad coding practise and dont feel good about that.
Anyway am impressed how you clearly understood my bone of contention..
RegardsOpen a e.g a FileReader and wrap it in a BufferedReader. Call readLine in a loop and split each line on the first "=". The left part is the key, the right part is the value. You can place each key and value in a Properties object that you have instantiated, and return that instance.
Kaj

Similar Messages

  • Javascript escaping problem

    I think i have an escaping problem, could someone please help me out:
    <script>
    function deleteConfirm(ID, thema){
         var theText = "" + thema;
         if( confirm("Weet u zeker dat u " + theText + " wilt verwijderen?"))     {
              document.location='lib/event_frm_process.jsp?action=delete&ID='+ ID;
    </script>
    Link using this function:
    <a href="\"javascript:deleteConfirm('<%=resultset.getString("ID")%">','<%=resultset.getString("thema")%>');"\><img src="images/verwijderen_hog_icon.gif" width="20" height="19" border="0" align="absmiddle"></a>
    Thank you in advance .......</a>

    Try:
    <a href="javascript:deleteConfirm('<%=resultset.getString("ID")%>','<%=resultset.getString("thema")%>');"\>The quotes inside the <%= %> do not conflict with the HTML quotes since they are handled server side and the HTML/javascript is handled client side.
    If that doesn't work, you will have to look at the HTML generated and see what the text coming out of the result set it (if it contains quotes or apostrophes itself). It the string coming from the result set is problematic you will have to re-arrange your quotes or process it some more before it is inserted...

  • Regular Expression escaping problem!

    Hi all,
    Well as you know characters such as '*' and '?' are reserved characters in regular expression so I suppose if I want to find the exact character (a '?' for example) in a string, I have to escape it with a backslash:
    str=str.replaceAll("\?","a");
    In the statement above, I need to replace all question marks with another character but it has a compile error:
    Error(116,48): invalid escape character
    to my surprise this following code does the job while it should be interpreted as: one occurance of the '\' character or nothing at all:
    str=str.replaceAll("\\?","a");
    What's the problem? what's the general rule on escaping such characters?

    I think you're right.
    The point is that java first interprets the String and handle its own scape characters then the result would be passed on to reqular expression parser.
    so I guess in order to search for one occurance of the '\' character or nothing at all the java string would be:
    so that the input to reqular expression parser would be:
    while in the first situation:
    a "\\?" java string is first trasformed into \? which will be considerd as one occurance '?' in reqular expression point of view...
    Message was edited by:
    nerssi
    Message was edited by:
    nerssi

  • Setting input fields to an empty string BIG PROBLEM

    Hi Rob, thanks for your rerply, It makes sense alright, but I am using 2 seperate input fields. I have discovered what is causing the problem .
    After the user types into the inputfield and moves on to a different frame, I have set the input field to an empty string and this is what is causing the problem.
    I have tried setting the input field to an empty string in a movie script and on individual sprites and the first right answer is not excepted.I have to type in the right answer twice to get get a right response. I am actually using three seperate input fields in total, each with a different name and behavior. Even If I use one input field I still have the same problem. Its driving me crazey. Any Ideas.
    Anne

    I believe that the FIM Service always does trims on string, so you may be out of luck.
    What is your scenario / what are you trying to accomplish by setting a space in an attribute? A space is not an empty string in my definition.
    Regards, Soren Granfeldt
    blog is at http://blog.goverco.com | facebook https://www.facebook.com/TheIdentityManagementExplorer | twitter at https://twitter.com/#!/MrGranfeldt

  • String concat PROBLEM??? Please Help

    I have this strange Question regarding String concat
    If I say:
    String str = "Welcome";
    str.concat(" to Java");
    System.out.println(str);
    The output is: Welcome.
    How do I get the output to Welcome to Java??

    I have this strange Question regarding String concat
    If I say:
    String str = "Welcome";
    str.concat(" to Java");
    System.out.println(str);
    The output is: Welcome.
    How do I get the output to Welcome to Java??
    The problem is that String is immutable, The String you have held in str does not change, rather a new Srtring is returned. So all yo have to do is grab the new String
    str = str.concat("to Java");
    or use the new String without keeping it.
    ie
    System.out.println(str.concat("to Java"));

  • String concat problem

    Hi folks,-
    i know this question might be very simple but i just cannot see what i am doing wrong here.
    String stringA, stringB, stringC;
    stringA= new String();
    stringB= new String();
    stringC= new String();
    stringA = null;
    stringB = "TRUE";
    stringC = "Error:";
    stringA.concat(stringB); // my code stops and quits here w/o error
    // other codewhat is wrong here?
    thanks much

    could you then please explain the following?
    public String concat(String str)Concatenates the
    specified string to the end of this string.
    If the length of the argument string is 0, thenthis
    String object is returned. Otherwise, a new String
    object is created, representing a charactersequence
    that is the concatenation of the charactersequence
    represented by this String object and thecharacter
    sequence represented by the argument string.
    Examples:
    "cares".concat("s") returns "caress"
    "to".concat("get").concat("her") returns"together"
    Parameters:
    tr - the String that is concatenated to the end of
    this String.
    Returns:
    a string that represents the concatenation of this
    object's characters followed by the stringargument's
    characters.
    Throws:
    NullPointerException - if str is null.It returns a new String, which you are
    throwing away. Change your code like this:
    stringA = stringA.concat(stringB);
    and then you'd get somewhere.yes, it makes sense but the description does not say this.
    i think that will work but my problem is with the description of this
    concat operation on the java web site.
    thanks for the help

  • XSLT HTML output escaping problem

    I am having problems with JAXP XSLT output escaping in HTML. I have an XML document which correctly escapes &, <, > etc (eg: &amp). However, when I transform the document the XSLT processor is escaping these values again. This means that the HTML output contains &amp; where the XML document contains & (for example). Surely correctly escaped characters in the XML should be left alone? Or should the XML document not contain escaped characters? In my understanding special characters in text nodes of XML documents should be escaped. Obviously a work around is to disable output escaping on these nodes but that is a real pain to have to do each time you pull a value through from the XML document. I'm confused as to what format the XSLT processor expects the XML to be in in relation to escaping of elements. Any information gratefully accepted!
    Thanks.

    Sorry! I was getting confused - the special characters were being escaped twice before they reached the XSLT processor. It looks like the processor will leave alone escape sequences that are already in the XML when it transforms to HTML.

  • String check problem

    I have a doozy of a problem on my hands. My company has introduced a password policy that every user must me now. Some of my criteria is that a password must contain at least one symbol and at least one number. In 10g I can use REGEXP_LIKE function, but I am running 9i. I have tried to use translate, OWA_PATTERN function, everthing. How can I take a string variable, and test to see if there is a symbol in the text or a number. I want to be able to return a true/false value?
    Please advise?

    Like Kamal says, use built-in functionality FIRST.
    Failing that, presumably you would write something like this (I forget the exact naming standard for the password verify function).
    CREATE FUNCTION valid_password (
       p_password IN VARCHAR2)
       RETURN BOOLEAN
    IS
       FUNCTION contains_at_least_one (
          p_string IN VARCHAR2,
          p_characters IN VARCHAR2)
          RETURN BOOLEAN
       IS
       BEGIN
          RETURN LENGTH (TRANSLATE (p_string, 'X' ||
            p_characters, 'X')) < LENGTH (p_string);
       END;
    BEGIN
       RETURN contains_at_least_one (p_password, '0123456789')
          AND contains_at_least_one (p_password, '!£$%^&*(){}~@??|<>');
    END;

  • String overlapping problem in mx:List caused by wordWrap

    I'm using mx:List to display String items. The dataProvider is XMLListCollection. Some of the String is long so it takes more than one rows. I use the wordWrap to display the long String in more than one rows. The problem is that the next String item will overlapping with the long String. The mx:List can not adjust the vertical space for the Strings that needs more than one rows dynamically. Any suggections?

    Here is solution: variableRowHeight="true"

  • String offset problem

    Hi,
    I'm using 1.4.2 at the moment.
    I got the problem below and have no idea how to solve it. The program portion is:
    String x = node.getText();
    The node.getText() should contain value = "\n\r"
    However, it always return me "\r" only.
    I checked with the debugger and found that when I change the offset value of x to 0, it can return me "\n". However, the original offset value is always kept as 1. That's the reason why it always return me "\r".
    Can anyone help and tell me how to get the value "\n" in this case, i.e. any String method which I can check and get the offset value 0 from the string x.
    Thanks million in advance.
    Regards,
    Eric

    Can anyone help and tell me how to get the value "\n"
    in this case, i.e. any String method which I can
    check and get the offset value 0 from the string x.
    x.charAt(0);is probably what you mean.

  • String item problem

    I use mobility pack visual designer.
    When I create a string item in visual screen designer it looks like that:
    Title
    <text>
    but after i run my app it looks different
    Title <text>
    Why there's no line break?
    When I try to add the line break manually it doesn�t work because screen designer property editor adds to the code \\n when I put \n
    so generated code looks like that
    stringItem1 = new StringItem("stringItem1\\n", "<Enter Text>");  and I cannot edit it manually because generated code is blocked by net beans
    I can initialize my stringItem object one again
    stringItem2 = new StringItem("stringItem2\n", "<Enter Text>");  but I thing that�s very stupid to reinitialize an object twice
    And the line break after title doesn't solve my problem because if the title is too long the device will automatically brake the line and I�ll get this
    A long long title........
    <text>
    one empty line because of that break
    Any ideas?
    I don�t want to use textField because when you set it to uneditable its color becomes gray.

    Check the actual URL up in the location bar. Your comma may actually be dropping out there, because it isn't encoded such that in value commas can be differentiated from delimiters, so the fields aren't lining up in the URL properly.
    When you go to a page that takes in parameters for assignment in the link, it has 2 fields. The first is the comma separated list of the item names on the page to assign, which wouldn't contain commas in their names. The other field in the URL is a comma separated list of values to be assigned to the previous list. Since these values aren't encoded, the comma in the value is picked up as delimiter and not a part of the value. I have an example I can load up to apex.oracle.com if you need.
    -Richard
    Edited by: rwendel on Aug 13, 2009 11:51 AM

  • Passing string data problem

    Dear readers,
    I came across some problem in my labview VI where I try to pass a string (stored in a local variable) to other string variables connected to that local variable. In this case, I have a local string variable called 'output_string1', which contains the string '123'. I have it set to 'write'. Then I connect 3 string Indicators to this local variable, called 'string1', 'string2', and 'string3'. I would expect these connected string indicators to also contain the string '123', as they're simply connected to the 'output_string1'. But the strange thing is that only 'string2', and 'string3' contains '123', but 'string1' contains a '.' (ie a dot). Would someone be able to provide some kind advice about what I might be doing wro
    ng to get this result? I've attached the vi that I was making that demonstrates what I described. Thank you very much for your help.
    Attachments:
    remove_trailing_zeros_subvi.vi ‏78 KB

    In the last sequence you have intended to concatinate a string from three inputs; the local variable before, a "." and a local of string1. BUT instead of reading the local of string1 you have it in write mode...and the "." is wired into it! So you really wire 123 to that indicator as well in sequence 5, but it is immediately overwritten by a "." in the next sequence.
    That aside though there's two other things about the code that needs to be commented:
    a) You use locals as you would use them if G was a textual language; like variables. In G though we try to avoid locals all together, in G the wire is the variable! The wire in addition ensures the next thing the code lacks; execution control.
    b) Instead of sequences, use data flow. By working
    with the wire instead of locals you can ensure that things execute in the order you want it to, without the need for a sequence structure. And without a sequence structure the code becomes much easier to read and maintain.
    I have attached a modified version of your code that applies these two conversions to a "G" way of programming.
    Removing trailing zeroes can be done much easier though, attached is also an example of one such way.
    MTO
    Attachments:
    remove_trailing_zeros_Simplified.vi ‏45 KB
    remove_trailing_zeros_improved.vi ‏22 KB

  • String compare problem

    I try to compare 2 strings with compareTo/equalTo, but it's not working, those 2 funcs always return ture.
    public boolean chMark(String name, String test, String newMark)
              boolean flag = false;
              for(int i = 0; i < course.getNumOfStd(); i++)
                   if(course.getStd().getName().compareTo(name)==0)//here is problem;
                        Student tempStd = course.getStd()[i];
                        for(int j = 0; j < tempStd.getMark().getNumOfTests(); j++)
                        if(tempStd.getMark().getTestArray()[j].getTitle().compareTo(test)==0);//here is problem;
                             int mark = Integer.parseInt(newMark);                    }
              return flag;
    Can anybody tell me why?
    REGARDS,
    Elton

    equals() would read more naturally than compareTo()==0. But, in
    either case, use System.out.println() to write the two strings before
    you compare them. This is to check that you are comparing what
    you think you're comparing.System.out.println("name from course is " + course.getStd().getName());
    System.out.println("name is " + name);
    if(course.getStd()[i].getName().compareTo(name)==0)//here is problem;
    System.out.println("name from couse and name compared equal");
    // etc

  • Javabean string invoking problem

    I have two JSPs, one takes a request and the other displays the result and I am having problem with the javabean to connect the two
    here are my codes
    takes request
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <table border="1" align="center">
    <tr>
    <td colspan="3" bgcolor="black" align="center"><font color="orange" size="3">
    Computer Voting Poll</font></td></tr>
    <tr>
    <td colspan="3" bgcolor="black" align="center"><font color="orange" size="3">
    What is your favorite computer game?
    </font></td></tr>
    <tr><td width="20%" bgcolor="black"></td>
    <td width="30%" bgcolor="black" align="left">
    <FORM ACTION="PollResult.jsp">
    <input type="radio" name="firstChoice" value="Oblivion" checked><font color="orange" size="2"> Oblivion </font><br>
    <input type="radio" name="secondChoice" value="starwars"><font color="orange" size="2"> Star Wars: Empire at War </font><br>
    <input type="radio" name="thirdChoice" value="finalfantasy"><font color="orange" size="2"> Final Fantasy XI: Online </font><br>
    <input type="submit" value="vote button" name="Vote">
    </td>
    <td bgcolor="black" width="20%"></td>
    </tr>
    <tr><td bgcolor="black" colspan="3" align="center"><font color="orange" size="3">
    </font><font color="white" size="3">Total Votes</font></td></tr>
    <tr><td height="15" bgcolor="orange" colspan="3"></td></tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Oblivion</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3">0.00%</font></td>
    </tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Star Wars: Empire at War</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3">0.00%</font></td>
    </tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Final Fantasy XI: Online</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3">0.00%</font></td>
    </tr>
    <tr><td height="15" bgcolor="orange" colspan="3"></td></tr>
    </table>
    </body>
    </html>displays
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <table border="1" align="center">
    <tr>
    <td colspan="3" bgcolor="black" align="center"><font color="orange" size="3">
    Computer Voting Poll</font></td></tr>
    <tr>
    <td colspan="3" bgcolor="black" align="center"><font color="orange" size="3">
    What is your favorite computer game?
    </font></td></tr>
    <tr><td width="20%" bgcolor="black"></td>
    <td width="30%" bgcolor="black" align="left">
    <input type="radio" name="firstChoice" value="Oblivion" checked><font color="orange" size="2"> Oblivion </font><br>
    <input type="radio" name="secondChoice" value="starwars"><font color="orange" size="2"> Star Wars: Empire at War </font><br>
    <input type="radio" name="thirdChoice" value="finalfantasy"><font color="orange" size="2"> Final Fantasy XI: Online </font><br>
    <input type="submit" value="vote button" name="Vote">
    </td>
    <td bgcolor="black" width="20%"></td>
    </tr>
      <TR><TH>
          Using jsp:setProperty</TABLE>
    <jsp:useBean id="entry" class="core.BeanPoll" />
    <jsp:setProperty
        name="entry"
        property="firstChoice"
        param="firstChoice" />
    <jsp:setProperty
        name="entry"
        property="secondChoice"
        param="secondChoice" />
    <jsp:setProperty
        name="entry"
        property="thirdChoice"
        param="thirdChoice" />
    <BR>
    <tr><td bgcolor="black" colspan="3" align="center"><font color="orange" size="3">
    </font><font color="white" size="3">Total Votes</font></td></tr>
    <tr><td height="15" bgcolor="orange" colspan="3"></td></tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Oblivion</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3"><jsp:getProperty name="entry" property="firstChoice" />%</font></td>
    </tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Star Wars: Empire at War</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3"><jsp:getProperty name="entry" property="secondChoice" />0.00%</font></td>
    </tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3"><jsp:getProperty name="entry" property="thirdChoice" />Final Fantasy XI: Online</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3">0.00%</font></td>
    </tr>
    <tr><td height="15" bgcolor="orange" colspan="3"></td></tr>
    </table>
    </body>
    </html>javabean
    * BeanPoll.java
    * Created on October 29, 2007, 11:18 PM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package core;
    /** Simple bean to illustrate the various forms
    *  of jsp:setProperty.
    *  <P>
    *  Taken from Core Servlets and JavaServer Pages 2nd Edition
    *  from Prentice Hall and Sun Microsystems Press,
    *  http://www.coreservlets.com/.
    *  &copy; 2003 Marty Hall; may be freely used or adapted.
    public class BeanPoll {
      private String firstChoice = "unknown";
      private String secondChoice = "unknown";
      private String thirdChoice = "unknown";
      public String getfirstChoice() {
        return(firstChoice);
      public void setfirstChoice(String firstChoice) {
        if (firstChoice != null) {
          this.firstChoice = firstChoice;
        } else {
          this.firstChoice = "unknown";
      public String getsecondChoice() {
        return(secondChoice);
      public void setsecondChoice(String secondChoice) {
        if (secondChoice !=null) {
            this.secondChoice = secondChoice;
        } else {
            this.secondChoice = "unknown";
      public String setthirdChoice() {
        return(thirdChoice);
      public void setthirdChoice(String thirdChoice) {
        if (thirdChoice !=null) {
            this.thirdChoice = thirdChoice;
        } else {
            this.thirdChoice = "unknown";
      // In real life, replace this with database lookup.
      // See Chapters 17 and 18 for info on accessing databases
      // from servlets and JSP pages.
      public double getPollResult() {
        double result;
      public double getTotalCost() {
        return(getItemCost() * getNumItems());
    }thanks for your time

    You have a getter method whose name starts with "set".
    You're not following the beans naming conventions correctly. If a property is called "foo", then the getters & setters are named "getFoo" and "setFoo".

  • Struts String Array problem:

    Hello All,
    I'm working on a DynaValidatorForm in struts and I'm not able to define my string arrays without compile errors in WSAD 5.0 and it doesn't work right with the validator for those two items. WSAD 5.0 uses a 1.3 beta version of struts and that may be the problem or it may be a bug in the validator. Not sure which. This is what I have in the struts-config.xml file for the form-bean:
    <form-beans>
    <form-bean name="submitDynaValidateForm"
    type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="lastName"     type="java.lang.String"/>
    <form-property name="address"      type="java.lang.String"/>
    <form-property name="sex"      type="java.lang.String"/>
    <form-property name="married"      type="java.lang.String"/>
    <form-property name="children"      type="java.lang.String[]"/>
    <form-property name="age"      type="java.lang.String"/>
    <form-property name="interests" type="java.lang.String[]"/>
    </form-bean>
    </form-beans>
    Anyone come across this problem before and do you know how to solve it other than doing the validation for the String Arrays in the Action class?
    Thanks,
    James

    I don't know how to solve it, but I'd wonder about the need to validate the array of Strings. I think that should just be a String type.
    If you have String arrays to populate a drop-down list, I think the assumption has to be that the drop-down has been populated properly. There's no need to re-check it every time. Even if the list is changing, because its contents are driven by another selection, the responsibility for getting those values correct lie outside the validator's domain.
    And since the single selection that's actually sent as input comes from an array of valid values, there's no opportunity for the user to send an invalid value.
    I think the validation framework is for checking manual, typed user input to make sure they're the correct types, no typo errors, etc.
    Business validity is another matter that the Struts validation framework shouldn't address. Those business rules belong on the middle tier, IMO.

Maybe you are looking for