use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.
the class SearchRequestTest method testRequestWithSubstrings1Base64Any.
/**
* Test parsing of a request with a Substrings Filter with 1 Any element
*/
@Test
public void testRequestWithSubstrings1Base64Any() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(SearchRequestTest.class.getResource("filters/request_with_substrings_1_base64_any.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchRequest searchRequest = (SearchRequest) parser.getBatchRequest().getCurrentRequest();
ExprNode filter = searchRequest.getFilter();
assertTrue(filter instanceof SubstringNode);
SubstringNode substringFilter = (SubstringNode) filter;
List<String> initials = substringFilter.getAny();
assertEquals(1, initials.size());
assertEquals("DSMLv2.0 rocks!!", initials.get(0));
}
use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.
the class SearchRequestTest method testRequestWithSubstrings1Final.
/**
* Test parsing of a request with a Substrings Filter with 1 Final element
*/
@Test
public void testRequestWithSubstrings1Final() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(SearchRequestTest.class.getResource("filters/request_with_substrings_1_final.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchRequest searchRequest = (SearchRequest) parser.getBatchRequest().getCurrentRequest();
ExprNode filter = searchRequest.getFilter();
assertTrue(filter instanceof SubstringNode);
SubstringNode substringFilter = (SubstringNode) filter;
assertEquals("john", substringFilter.getFinal().toString());
}
use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.
the class SearchRequestTest method testRequestWithSubstrings2Any.
/**
* Test parsing of a request with a Substrings Filter with 1 Any element
*/
@Test
public void testRequestWithSubstrings2Any() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(SearchRequestTest.class.getResource("filters/request_with_substrings_2_any.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchRequest searchRequest = (SearchRequest) parser.getBatchRequest().getCurrentRequest();
ExprNode filter = searchRequest.getFilter();
assertTrue(filter instanceof SubstringNode);
SubstringNode substringFilter = (SubstringNode) filter;
List<String> initials = substringFilter.getAny();
assertEquals(2, initials.size());
assertEquals("kate", initials.get(0));
assertEquals("sawyer", initials.get(1));
}
use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.
the class SearchRequestTest method testRequestWithSubstrings1Base64Initial.
/**
* Test parsing of a request with a Substrings Filter with 1 Initial element with Base64 value
*/
@Test
public void testRequestWithSubstrings1Base64Initial() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(SearchRequestTest.class.getResource("filters/request_with_substrings_1_base64_initial.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchRequest searchRequest = (SearchRequest) parser.getBatchRequest().getCurrentRequest();
ExprNode filter = searchRequest.getFilter();
assertTrue(filter instanceof SubstringNode);
SubstringNode substringFilter = (SubstringNode) filter;
assertEquals("DSMLv2.0 rocks!!", substringFilter.getInitial().toString());
}
use of org.apache.directory.api.ldap.model.filter.SubstringNode in project structr by structr.
the class StructrLDAPWrapper method matches.
private boolean matches(final LDAPNode node, final ExprNode filter) throws FrameworkException, LdapInvalidAttributeValueException {
if (filter instanceof SimpleNode) {
return evaluateSimpleNode(node, (SimpleNode) filter);
} else if (filter instanceof SubstringNode) {
return evaluateSubstringNode(node, (SubstringNode) filter);
} else if (filter instanceof PresenceNode) {
final PresenceNode presence = (PresenceNode) filter;
final Attribute attribute = new DefaultAttribute(presence.getAttributeType());
return findAttribute(node, attribute.getId()) != null;
} else if (filter instanceof OrNode) {
final OrNode orNode = (OrNode) filter;
for (final ExprNode child : orNode.getChildren()) {
if (matches(node, child)) {
return true;
}
}
return false;
} else if (filter instanceof AndNode) {
final AndNode andNode = (AndNode) filter;
boolean result = true;
for (final ExprNode child : andNode.getChildren()) {
result &= matches(node, child);
}
return result;
} else {
System.out.println("Unsupported filter type " + filter.getClass());
}
return false;
}
Aggregations