NIHVIVO-2343 Move escapeForRegex() into a base class where it can be shared by ProxyRelationshipSelector.
This commit is contained in:
parent
59f141c581
commit
4422a995f9
2 changed files with 40 additions and 28 deletions
|
@ -0,0 +1,38 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A base class with some methods for building a selector.
|
||||||
|
*/
|
||||||
|
public abstract class AbstractPagingSelector {
|
||||||
|
/**
|
||||||
|
* If the user enters any of these characters in a search term, escape it
|
||||||
|
* with a backslash.
|
||||||
|
*/
|
||||||
|
private static final char[] REGEX_SPECIAL_CHARACTERS = "[\\^$.|?*+()]"
|
||||||
|
.toCharArray();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape any regex special characters in the string.
|
||||||
|
*
|
||||||
|
* Note that the SPARQL parser requires two backslashes, in order to pass a
|
||||||
|
* single backslash to the REGEX function.
|
||||||
|
*/
|
||||||
|
protected String escapeForRegex(String raw) {
|
||||||
|
StringBuilder clean = new StringBuilder();
|
||||||
|
outer: for (char c : raw.toCharArray()) {
|
||||||
|
for (char special : REGEX_SPECIAL_CHARACTERS) {
|
||||||
|
if (c == special) {
|
||||||
|
clean.append('\\').append('\\').append(c);
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clean.append(c);
|
||||||
|
}
|
||||||
|
return clean.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount.Status;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount.Status;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.AbstractPagingSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsOrdering.Field;
|
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsOrdering.Field;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner;
|
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner.QueryParser;
|
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner.QueryParser;
|
||||||
|
@ -26,7 +27,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner.QueryParser;
|
||||||
/**
|
/**
|
||||||
* Pull some UserAccounts from the model, based on a set of criteria.
|
* Pull some UserAccounts from the model, based on a set of criteria.
|
||||||
*/
|
*/
|
||||||
public class UserAccountsSelector {
|
public class UserAccountsSelector extends AbstractPagingSelector {
|
||||||
private static final Log log = LogFactory
|
private static final Log log = LogFactory
|
||||||
.getLog(UserAccountsSelector.class);
|
.getLog(UserAccountsSelector.class);
|
||||||
|
|
||||||
|
@ -68,13 +69,6 @@ public class UserAccountsSelector {
|
||||||
+ " <%uri%> auth:hasPermissionSet ?ps \n" //
|
+ " <%uri%> auth:hasPermissionSet ?ps \n" //
|
||||||
+ "} \n";
|
+ "} \n";
|
||||||
|
|
||||||
/**
|
|
||||||
* If the user enters any of these characters in a search term, escape it
|
|
||||||
* with a backslash.
|
|
||||||
*/
|
|
||||||
private static final char[] REGEX_SPECIAL_CHARACTERS = "[\\^$.|?*+()]"
|
|
||||||
.toCharArray();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method.
|
* Convenience method.
|
||||||
*/
|
*/
|
||||||
|
@ -198,26 +192,6 @@ public class UserAccountsSelector {
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape any regex special characters in the string.
|
|
||||||
*
|
|
||||||
* Note that the SPARQL parser requires two backslashes, in order to pass a
|
|
||||||
* single backslash to the REGEX function.
|
|
||||||
*/
|
|
||||||
private String escapeForRegex(String raw) {
|
|
||||||
StringBuilder clean = new StringBuilder();
|
|
||||||
outer: for (char c : raw.toCharArray()) {
|
|
||||||
for (char special : REGEX_SPECIAL_CHARACTERS) {
|
|
||||||
if (c == special) {
|
|
||||||
clean.append('\\').append('\\').append(c);
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
clean.append(c);
|
|
||||||
}
|
|
||||||
return clean.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sort as desired, and within ties, sort by EMail address. */
|
/** Sort as desired, and within ties, sort by EMail address. */
|
||||||
private String ordering() {
|
private String ordering() {
|
||||||
UserAccountsOrdering orderBy = criteria.getOrderBy();
|
UserAccountsOrdering orderBy = criteria.getOrderBy();
|
||||||
|
|
Loading…
Add table
Reference in a new issue