Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to make wildcard search for repository workspaces using Plain Java API

 In Eclipse I can serach for repository workspaces using a pattern including the wildcards * and ?, where * means any sequence of chars, and ? means any single char.  
I tried this using plain java api, but found that it did not work.
String pattern = "abc-???_cde";
IWorkspaceSearchCriteria wsSearchCriteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.WORKSPACES);
wsSearchCriteria.setPartialName(pattern);
	
The search did not find the workspaces with names 'abc-123_cde' or 'abc-666_cde'

After some investigation I found that the eclipse client calls a Util class that converts the search pattern, before calling the API.

The conversion looks like this
switch (ch) {
            case '*':
                buffer.append("%"); 
                break;
            case '?':
                buffer.append("_"); 
                break;
            case '%':
                buffer.append("\\%"); 
                break;
            case '_':
                buffer.append("\\_"); 
                break;
            case '\\':
                buffer.append("\\\\"); 
                break;
            default:
                buffer.append(ch);
}
So to the above search pattern should be converted to "abc-___\\_cde" then it worked just fine, and it finds both of the above workspaces,

Hope someone can make use of this information.
 

0 votes


Accepted answer

Permanent link
 As explained in the question, it can be done by converting * and ? properly.
Ralph Schoon selected this answer as the correct answer

1 vote

Comments

Thanks for sharing Martin!

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,951
× 411

Question asked: Oct 09 '14, 10:03 a.m.

Question was seen: 4,178 times

Last updated: Oct 09 '14, 10:31 a.m.

Confirmation Cancel Confirm