本文整理汇总了Java中javax.naming.directory.InvalidSearchFilterException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidSearchFilterException类的具体用法?Java InvalidSearchFilterException怎么用?Java InvalidSearchFilterException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvalidSearchFilterException类属于javax.naming.directory包,在下文中一共展示了InvalidSearchFilterException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeFilterString
import javax.naming.directory.InvalidSearchFilterException; //导入依赖的package包/类
/**
* First convert filter string into byte[].
* For LDAP v3, the conversion uses Unicode -> UTF8
* For LDAP v2, the conversion uses Unicode -> ISO 8859 (Latin-1)
*
* Then parse the byte[] as a filter, converting \hh to
* a single byte, and encoding the resulting filter
* into the supplied BER buffer
*/
static void encodeFilterString(BerEncoder ber, String filterStr,
boolean isLdapv3) throws IOException, NamingException {
if ((filterStr == null) || (filterStr.equals(""))) {
throw new InvalidSearchFilterException("Empty filter");
}
byte[] filter;
int filterLen;
if (isLdapv3) {
filter = filterStr.getBytes("UTF8");
} else {
filter = filterStr.getBytes("8859_1");
}
filterLen = filter.length;
if (dbg) {
dbgIndent = 0;
System.err.println("String filter: " + filterStr);
System.err.println("size: " + filterLen);
dprint("original: ", filter, 0, filterLen);
}
encodeFilter(ber, filter, 0, filterLen);
}
示例2: parseFilter
import javax.naming.directory.InvalidSearchFilterException; //导入依赖的package包/类
public static Filter parseFilter(String filter, Object[] args)
throws InvalidSearchFilterException {
if (filter == null) {
// ldap.28=Parameter of filter should not be null
throw new NullPointerException(Messages.getString("ldap.28")); //$NON-NLS-1$
}
FilterParser parser = new FilterParser(filter);
if (args == null) {
args = new Object[0];
}
parser.setArgs(args);
try {
return parser.parse();
} catch (ParseException e) {
// ldap.29=Invalid search filter
InvalidSearchFilterException ex = new InvalidSearchFilterException(
Messages.getString("ldap.29")); //$NON-NLS-1$
ex.setRootCause(e);
throw ex;
}
}
示例3: findRightParen
import javax.naming.directory.InvalidSearchFilterException; //导入依赖的package包/类
private static int[] findRightParen(byte[] filter, int filtOffset[], int end)
throws IOException, NamingException {
int balance = 1;
boolean escape = false;
int nextOffset = filtOffset[0];
while (nextOffset < end && balance > 0) {
if (!escape) {
if (filter[nextOffset] == '(')
balance++;
else if (filter[nextOffset] == ')')
balance--;
}
if (filter[nextOffset] == '\\' && !escape)
escape = true;
else
escape = false;
if (balance > 0)
nextOffset++;
}
if (balance != 0) {
throw new InvalidSearchFilterException("Unbalanced parenthesis");
}
// String tmp = filter.substring(filtOffset[0], nextOffset);
int[] tmp = new int[] {filtOffset[0], nextOffset};
filtOffset[0] = nextOffset + 1;
return tmp;
}
示例4: LdapSchemaFilter
import javax.naming.directory.InvalidSearchFilterException; //导入依赖的package包/类
public LdapSchemaFilter(String filterValue, Object[] filterArgs)
throws InvalidSearchFilterException {
try {
FilterParser commonFilterParser = new FilterParser(filterValue);
commonFilterParser.setArgs(filterArgs);
commonFilter = commonFilterParser.parse();
} catch (ParseException e) {
// ldap.29=Invalid search filter
throw new InvalidSearchFilterException(Messages
.getString("ldap.29")); //$NON-NLS-1$
}
}
示例5: unescapeFilterValue
import javax.naming.directory.InvalidSearchFilterException; //导入依赖的package包/类
static byte[] unescapeFilterValue(byte[] orig, int start, int end)
throws NamingException {
boolean escape = false, escStart = false;
int ival;
byte ch;
if (dbg) {
dprint("unescape: " , orig, start, end);
}
int len = end - start;
byte tbuf[] = new byte[len];
int j = 0;
for (int i = start; i < end; i++) {
ch = orig[i];
if (escape) {
// Try LDAP V3 escape (\xx)
if ((ival = hexchar2int(ch)) < 0) {
/**
* If there is no hex char following a '\' when
* parsing a LDAP v3 filter (illegal by v3 way)
* we fallback to the way we unescape in v2.
*/
if (escStart) {
// V2: \* \( \)
escape = false;
tbuf[j++] = ch;
} else {
// escaping already started but we can't find 2nd hex
throw new InvalidSearchFilterException("invalid escape sequence: " + orig);
}
} else {
if (escStart) {
tbuf[j] = (byte)(ival<<4);
escStart = false;
} else {
tbuf[j++] |= (byte)ival;
escape = false;
}
}
} else if (ch != '\\') {
tbuf[j++] = ch;
escape = false;
} else {
escStart = escape = true;
}
}
byte[] answer = new byte[j];
System.arraycopy(tbuf, 0, answer, 0, j);
if (dbg) {
Ber.dumpBER(System.err, "", answer, 0, j);
}
return answer;
}
示例6: encodeFilterList
import javax.naming.directory.InvalidSearchFilterException; //导入依赖的package包/类
private static void encodeFilterList(BerEncoder ber, byte[] filter,
int filterType, int start, int end) throws IOException, NamingException {
if (dbg) {
dprint("encFilterList: ", filter, start, end);
dbgIndent++;
}
int filtOffset[] = new int[1];
int listNumber = 0;
for (filtOffset[0] = start; filtOffset[0] < end; filtOffset[0]++) {
if (Character.isSpaceChar((char)filter[filtOffset[0]]))
continue;
if ((filterType == LDAP_FILTER_NOT) && (listNumber > 0)) {
throw new InvalidSearchFilterException(
"Filter (!) cannot be followed by more than one filters");
}
if (filter[filtOffset[0]] == '(') {
continue;
}
int[] parens = findRightParen(filter, filtOffset, end);
// add enclosing parens
int len = parens[1]-parens[0];
byte[] newfilter = new byte[len+2];
System.arraycopy(filter, parens[0], newfilter, 1, len);
newfilter[0] = (byte)'(';
newfilter[len+1] = (byte)')';
encodeFilter(ber, newfilter, 0, newfilter.length);
listNumber++;
}
if (dbg) {
dbgIndent--;
}
}