convert string to lower case

I would like to know how to convert the content of the following strings to lower case:

    private String webQueryText;
    private String searchType;
    private String queryText;

WEB_QUERY_TEXT
QUERY_TEXT
package web.search;

import java.io.IOException;
import java.util.Set;

import intradoc.common.ServiceException;
import intradoc.data.DataException;

public class WebSearchService extends intradoc.server.SearchService{
    private String webQueryText;
    private String searchType;
    private String queryText;
    
    private static final String QUERY_TEXT = "QueryText";        // default query text for verity 
    private static final String WEB_QUERY_TEXT = "WebQueryText"; // web query text
    private static final String SEARCH_TYPE = "SearchType";      // type of search to use
    private static final String SEARCH_TERMS = "SearchTerms";    // filtered terms list
    
    // Search types
    private static final String ADVANCED_WEB = "AdvWeb"; 
	
    /**
     * Called from the GET_SEARCH_RESULTS service.
     * Puts the search results into the binder. 
     * 
     * @return void
     */
    public void getWebSearchResults() throws DataException, ServiceException, IOException, Exception{
        webQueryText = m_binder.getAllowMissing(WEB_QUERY_TEXT);
        
        searchType = m_binder.getAllowMissing(SEARCH_TYPE);

        if (webQueryText != null && searchType != null && searchType.equalsIgnoreCase(ADVANCED_WEB)) {
            m_binder.putLocal(QUERY_TEXT,getAdvancedWebSearch());
        } 

        getSearchResults();           
    }
   
    /**
     * Build a basic search query string.  Override this method for more elaborate
     * search queries.
     * 
     * @return Query string
     */
    private String getAdvancedWebSearch() {
        SearchBoxParser parser = new SearchBoxParser(webQueryText);
        Set SearchTokens = parser.parseSearchText();
        
        // save a csv list of terms for displaying to user
        m_binder.putLocal(SEARCH_TERMS,SearchTokens.toString());
        
        return new VerityQueryGenerator(SearchTokens).toString();
    }

}

Open in new window

itortuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
All you need is the following
webQueryText = m_binder.getAllowMissing(WEB_QUERY_TEXT).toLowerCase(); // (and similar)

Open in new window

0
VenabiliCommented:
Don't forget to check for null before calling toLowerCase() if there is a chance the method to be returning null.
0
CEHJCommented:
Good point
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

itortuAuthor Commented:
how can I do that?
0
CEHJCommented:
It would be better to check the docs for getAllowMissing, to see if null is a possible value. Otherwise you're wasting your time
0
Mick BarryJava DeveloperCommented:
> how can I do that?


try this:

        searchType = m_binder.getAllowMissing(SEARCH_TYPE);
        if (searchType!=null) {
            searchType = seachType.toLowerCase();
        }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VenabiliCommented:
>It would be better to check the docs for getAllowMissing, to see if null is a possible value. Otherwise you're wasting your time
If I have a dollar for every time an API documentation tell me that NULL is not possible and my codfe then crashes with NullPointerException...  :)

itortu,
objects gave you the how.
0
CEHJCommented:
You're then going to have to determine what your code should do if it IS null. If being null is an error, you should probably allow the runtime exception
0
VenabiliCommented:
That's true but in most cases the null can be converted to empty string OR just to be handled a bit later so that something happens - instead of allowing a NullPointerException to stay unhandled and just to exit (at the very least so that you can close all types of streams and so on if you have them or to print an error message). But generally I would not call toLowerCase on something that might be a null.

And looking at the code from the author, at least one of those is explicitely checked for null in the code
if (webQueryText != null && searchType != null && searchType.equalsIgnoreCase(ADVANCED_WEB))
 so it seems to be possible for them to be null.
0
itortuAuthor Commented:
it can be null since  before the search is perform using the java classes, the web form contains JavaScript validation to ensure there is a word.
0
CEHJCommented:
>>it can be null since  before the search is perform using the java classes, the web form contains JavaScript validation to ensure there is a word.

Don't you mean it *can't* be null?
0
itortuAuthor Commented:
yes, i meant that. thank you.
0
Mick BarryJava DeveloperCommented:
See the code I posted above, it will handle it for regardless of whether its null or not.
null checking should always be done server side regardless of what is done client side.
0
VenabiliCommented:
*raising an eyebrow slightly*
So the full code gets points but the person that reminded you not to forget null does not? OK...
0
itortuAuthor Commented:
Venabili,

please accept my sincere apology I was not all attentive when I assigned the points. If there is a way to make a modification I would have not problem in re-evaluating the points distribution. Once again, I apologize.
0
VenabiliCommented:
It's ok - no need to get it reopened and then re-closed :)
But be more careful in the future -- some experts get upset with such things.

Thanks for returning and goor luck with your Java and your projects.
0
itortuAuthor Commented:
I will certainly be more careful next time. Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.