OPENDJ-2295 Provide a method to get back human readable strings from normalized index keys
Add a best effort conversion method from keys to a human readable printable string, using hexadecimal dump by default
and string for basic string type matching rules.
| | |
| | | * representation. |
| | | */ |
| | | public static char byteToASCII(final byte b) { |
| | | if (b >= 32 && b <= 126) { |
| | | if (isPrintable(b)) { |
| | | return (char) b; |
| | | } |
| | | |
| | | return ' '; |
| | | } |
| | | |
| | | /** |
| | | * Returns whether the byte is a printable ASCII character. |
| | | * |
| | | * @param b |
| | | * The byte for which to determine whether it is printable ASCII |
| | | * @return true if the byte is a printable ASCII character |
| | | */ |
| | | public static boolean isPrintable(final byte b) { |
| | | return 32 <= b && b <= 126; |
| | | } |
| | | |
| | | /** Prevent instantiation. */ |
| | | private StaticUtils() { |
| | | // No implementation required. |
| | |
| | | |
| | | /** |
| | | * Returns a string representation of the contents of this byte sequence |
| | | * using hexadecimal characters and a percent prefix (#) before each char. |
| | | * using hexadecimal characters and a percent prefix (%) before each char. |
| | | * |
| | | * @return A string representation of the contents of this byte sequence |
| | | * using percent + hexadecimal characters. |
| | |
| | | import org.forgerock.opendj.ldap.spi.Indexer; |
| | | |
| | | import static org.forgerock.opendj.ldap.Assertion.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.*; |
| | | |
| | | /** |
| | | * This class implements a default equality or approximate matching rule that |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return AbstractMatchingRuleImpl.this.keyToHumanReadableString(key); |
| | | } |
| | | |
| | | @Override |
| | | public String getIndexID() { |
| | | return indexID; |
| | | } |
| | | } |
| | | |
| | | String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toByteString().toHexString(); |
| | | } |
| | | |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return AbstractSubstringMatchingRuleImpl.this.keyToHumanReadableString(key); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getIndexID() { |
| | |
| | | this.equalityIndexId = equalityIndexId; |
| | | } |
| | | |
| | | @Override |
| | | String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public final Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, NO_CASE_FOLD); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | throws DecodeException { |
| | | return SchemaUtils.normalizeIA5StringAttributeValue(value, TRIM, NO_CASE_FOLD); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, CASE_FOLD); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | throws DecodeException { |
| | | return SchemaUtils.normalizeIA5StringAttributeValue(value, TRIM, CASE_FOLD); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | // Grab the substring between the start pos and the current pos |
| | | return ByteString.valueOf(string); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | throw DecodeException.error(e.getMessageObject()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | return SchemaUtils.normalizeNumericStringAttributeValue(value); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | final String oid = readOID(reader, schema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS)); |
| | | return ByteString.valueOf(resolveNames(schema, oid)); |
| | | } |
| | | |
| | | @Override |
| | | String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toByteString().toString(); |
| | | } |
| | | } |
| | |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | return value.toByteString(); |
| | | } |
| | | |
| | | @Override |
| | | String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toByteString().toHexString(); |
| | | } |
| | | } |
| | |
| | | |
| | | return ByteString.valueOf(buffer); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | * Decomposes an attribute value into a set of partial date and time |
| | | * index keys. |
| | | * |
| | | * @param attValue |
| | | * @param attributeValue |
| | | * The normalized attribute value |
| | | * @param set |
| | | * @param keys |
| | | * A set into which the keys will be inserted. |
| | | */ |
| | | private void timeKeys(ByteSequence attributeValue, Collection<ByteString> keys) { |
| | |
| | | matchingRule.timeKeys(value, keys); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toByteString().toHexString(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getIndexID() { |
| | |
| | | |
| | | return ByteString.valueOf(builder); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | return value.toByteString(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | */ |
| | | void createKeys(Schema schema, ByteSequence value, Collection<ByteString> keys) throws DecodeException; |
| | | |
| | | /** |
| | | * Returns a human readable representation of the key. |
| | | * Does a best effort conversion from an index key to a string that can be printed, as |
| | | * used by the diagnostic tools, which are the only users of the method. |
| | | * It is not necessary for the resulting string to exactly match the value it was |
| | | * generated from. |
| | | * |
| | | * @param key the byte string for the index key. |
| | | * @return a human readable representation of the key |
| | | */ |
| | | String keyToHumanReadableString(ByteSequence key); |
| | | } |
| | |
| | | keys.add(equalityRule.normalizeAttributeValue(value)); |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) |
| | | { |
| | | return key.toString(); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) |
| | | { |
| | | return "PRESENCE"; |
| | | } |
| | | |
| | | @Override |
| | | public String getIndexID() |
| | | { |
| | | return IndexType.PRESENCE.toString(); |
| | |
| | | { |
| | | return ORDERING_ID; |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) |
| | | { |
| | | return key.toString(); |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String keyToHumanReadableString(ByteSequence key) |
| | | { |
| | | return key.toString(); |
| | | } |
| | | |
| | | @Override |
| | | public String getIndexID() |
| | | { |
| | | return EQUALITY_ID; |