It's all about the answers!

Ask a question

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


Martin Dam Pedersen (1352814) | asked Oct 09 '14, 10:03 a.m.
 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.
 

Accepted answer


permanent link
Martin Dam Pedersen (1352814) | answered Oct 09 '14, 10:06 a.m.
 As explained in the question, it can be done by converting * and ? properly.
Ralph Schoon selected this answer as the correct answer

Comments
Ralph Schoon commented Oct 09 '14, 10:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Thanks for sharing Martin!

Your answer


Register or to post your answer.