| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.isAlpha; |
| | | import static com.forgerock.opendj.util.StaticUtils.isDigit; |
| | | import static com.forgerock.opendj.util.StaticUtils.isKeyChar; |
| | | import static org.forgerock.opendj.ldap.CoreMessages.*; |
| | | |
| | | import java.util.*; |
| | |
| | | |
| | | |
| | | |
| | | static List<String> readNameDescriptors(final SubstringReader reader) |
| | | static List<String> readNameDescriptors( |
| | | final SubstringReader reader, final boolean allowCompatChars) |
| | | throws DecodeException |
| | | { |
| | | int length = 0; |
| | | List<String> values; |
| | | |
| | | // Skip over any spaces at the beginning of the value. |
| | |
| | | |
| | | try |
| | | { |
| | | reader.mark(); |
| | | char c = reader.read(); |
| | | if (c == '\'') |
| | | { |
| | | reader.mark(); |
| | | // Parse until the closing quote. |
| | | while (reader.read() != '\'') |
| | | { |
| | | length++; |
| | | } |
| | | |
| | | reader.reset(); |
| | | values = Collections.singletonList(reader.read(length)); |
| | | values = Collections.singletonList(readQuotedDescriptor( |
| | | reader, allowCompatChars)); |
| | | reader.read(); |
| | | } |
| | | else if (c == '(') |
| | |
| | | do |
| | | { |
| | | reader.reset(); |
| | | values.add(readQuotedDescriptor(reader)); |
| | | values.add(readQuotedDescriptor(reader, allowCompatChars)); |
| | | reader.skipWhitespaces(); |
| | | reader.mark(); |
| | | } |
| | |
| | | * |
| | | * @param reader |
| | | * The string representation of the definition. |
| | | * @param allowCompatChars |
| | | * {@code true} if certain illegal characters should be allowed for |
| | | * compatibility reasons. |
| | | * @return The attribute description or numeric OID read from the definition. |
| | | * @throws DecodeException |
| | | * If a problem is encountered while reading the name or OID. |
| | | */ |
| | | static String readOID(final SubstringReader reader) throws DecodeException |
| | | static String readOID(final SubstringReader reader, |
| | | final boolean allowCompatChars) throws DecodeException |
| | | { |
| | | int length = 0; |
| | | boolean enclosingQuote = false; |
| | |
| | | throw DecodeException.error(message); |
| | | } |
| | | |
| | | if (!isAlpha(c) && !isDigit(c) && c != '-' && c != '.' && c != '_') |
| | | if (!isKeyChar(c, allowCompatChars)) |
| | | { |
| | | // This is an illegal character. |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_ILLEGAL_CHAR_IN_STRING_OID |
| | |
| | | * |
| | | * @param reader |
| | | * The string representation of the definition. |
| | | * @param allowCompatChars |
| | | * {@code true} if certain illegal characters should be allowed for |
| | | * compatibility reasons. |
| | | * @return The OID read from the definition. |
| | | * @throws DecodeException |
| | | * If a problem is encountered while reading the token name. |
| | | */ |
| | | static String readOIDLen(final SubstringReader reader) throws DecodeException |
| | | static String readOIDLen(final SubstringReader reader, |
| | | final boolean allowCompatChars) throws DecodeException |
| | | { |
| | | int length = 1; |
| | | boolean enclosingQuote = false; |
| | |
| | | throw DecodeException.error(message); |
| | | } |
| | | |
| | | if (!isAlpha(c) && !isDigit(c) && c != '-' && c != '.' && c != '_') |
| | | if (!isKeyChar(c, allowCompatChars)) |
| | | { |
| | | // This is an illegal character. |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_ILLEGAL_CHAR_IN_STRING_OID |
| | |
| | | |
| | | |
| | | |
| | | static Set<String> readOIDs(final SubstringReader reader) |
| | | throws DecodeException |
| | | static Set<String> readOIDs(final SubstringReader reader, |
| | | final boolean allowCompatChars) throws DecodeException |
| | | { |
| | | Set<String> values; |
| | | |
| | |
| | | values = new LinkedHashSet<String>(); |
| | | do |
| | | { |
| | | values.add(readOID(reader)); |
| | | values.add(readOID(reader, allowCompatChars)); |
| | | |
| | | // Skip over any trailing spaces; |
| | | reader.skipWhitespaces(); |
| | |
| | | else |
| | | { |
| | | reader.reset(); |
| | | values = Collections.singleton(readOID(reader)); |
| | | values = Collections.singleton(readOID(reader, allowCompatChars)); |
| | | } |
| | | |
| | | return values; |
| | |
| | | * |
| | | * @param reader |
| | | * The string representation of the definition. |
| | | * @param allowCompatChars |
| | | * {@code true} if certain illegal characters should be allowed for |
| | | * compatibility reasons. |
| | | * @return The string value read from the definition. |
| | | * @throws DecodeException |
| | | * If a problem is encountered while reading the quoted string. |
| | | */ |
| | | private static String readQuotedDescriptor(final SubstringReader reader) |
| | | private static String readQuotedDescriptor( |
| | | final SubstringReader reader, final boolean allowCompatChars) |
| | | throws DecodeException |
| | | { |
| | | int length = 0; |
| | |
| | | throw DecodeException.error(message); |
| | | } |
| | | |
| | | if (!isAlpha(c) && !isDigit(c) && c != '-' && c != '_' && c != '.') |
| | | if (!isKeyChar(c, allowCompatChars)) |
| | | { |
| | | // This is an illegal character. |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_ILLEGAL_CHAR_IN_STRING_OID |