0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License, Version 1.0 only
0N/A * (the "License"). You may not use this file except in compliance
0N/A * with the License.
0N/A *
0N/A * You can obtain a copy of the license at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
0N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
0N/A * add the following below this CDDL HEADER, with the fields enclosed
873N/A * by brackets "[]" replaced with your own identifying information:
0N/A * Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A *
0N/A *
3231N/A * Copyright 2006-2008 Sun Microsystems, Inc.
5866N/A * Portions Copyright 2012 ForgeRock AS
0N/A */
0N/Apackage org.opends.server.schema;
0N/A
0N/A
0N/A
0N/Aimport java.util.HashSet;
0N/A
1617N/Aimport org.opends.server.admin.std.server.AttributeSyntaxCfg;
0N/Aimport org.opends.server.api.ApproximateMatchingRule;
0N/Aimport org.opends.server.api.AttributeSyntax;
0N/Aimport org.opends.server.api.EqualityMatchingRule;
0N/Aimport org.opends.server.api.OrderingMatchingRule;
0N/Aimport org.opends.server.api.SubstringMatchingRule;
0N/Aimport org.opends.server.config.ConfigException;
0N/Aimport org.opends.server.core.DirectoryServer;
4134N/Aimport org.opends.server.types.ByteSequence;
2086N/A
0N/A
1280N/Aimport static org.opends.server.loggers.ErrorLogger.*;
2086N/Aimport static org.opends.messages.SchemaMessages.*;
2086N/Aimport org.opends.messages.MessageBuilder;
0N/Aimport static org.opends.server.schema.SchemaConstants.*;
0N/A
0N/A
0N/A
0N/A/**
0N/A * This class implements the teletex terminal identifier attribute syntax, which
0N/A * contains a printable string (the terminal identifier) followed by zero or
0N/A * more parameters, which start with a dollar sign and are followed by a
0N/A * parameter name, a colon, and a value. The parameter value should consist of
0N/A * any string of bytes (the dollar sign and backslash must be escaped with a
0N/A * preceding backslash), and the parameter name must be one of the following
0N/A * strings:
0N/A * <UL>
0N/A * <LI>graphic</LI>
0N/A * <LI>control</LI>
0N/A * <LI>misc</LI>
0N/A * <LI>page</LI>
0N/A * <LI>private</LI>
0N/A * </UL>
0N/A */
0N/Apublic class TeletexTerminalIdentifierSyntax
1617N/A extends AttributeSyntax<AttributeSyntaxCfg>
0N/A{
0N/A /**
0N/A * The set of allowed fax parameter values, formatted entirely in lowercase
0N/A * characters.
0N/A */
0N/A public static final HashSet<String> ALLOWED_TTX_PARAMETERS =
0N/A new HashSet<String>(5);
0N/A
0N/A static
0N/A {
0N/A ALLOWED_TTX_PARAMETERS.add("graphic");
0N/A ALLOWED_TTX_PARAMETERS.add("control");
0N/A ALLOWED_TTX_PARAMETERS.add("misc");
0N/A ALLOWED_TTX_PARAMETERS.add("page");
0N/A ALLOWED_TTX_PARAMETERS.add("private");
0N/A }
0N/A
0N/A
0N/A
0N/A // The default equality matching rule for this syntax.
0N/A private EqualityMatchingRule defaultEqualityMatchingRule;
0N/A
0N/A // The default ordering matching rule for this syntax.
0N/A private OrderingMatchingRule defaultOrderingMatchingRule;
0N/A
0N/A // The default substring matching rule for this syntax.
0N/A private SubstringMatchingRule defaultSubstringMatchingRule;
0N/A
0N/A
0N/A
0N/A /**
0N/A * Creates a new instance of this syntax. Note that the only thing that
0N/A * should be done here is to invoke the default constructor for the
0N/A * superclass. All initialization should be performed in the
0N/A * <CODE>initializeSyntax</CODE> method.
0N/A */
0N/A public TeletexTerminalIdentifierSyntax()
0N/A {
0N/A super();
0N/A }
0N/A
0N/A
0N/A
0N/A /**
1617N/A * {@inheritDoc}
0N/A */
1617N/A public void initializeSyntax(AttributeSyntaxCfg configuration)
0N/A throws ConfigException
0N/A {
0N/A defaultEqualityMatchingRule =
0N/A DirectoryServer.getEqualityMatchingRule(EMR_CASE_IGNORE_OID);
0N/A if (defaultEqualityMatchingRule == null)
0N/A {
2086N/A logError(ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get(
2086N/A EMR_CASE_IGNORE_OID, SYNTAX_TELETEX_TERM_ID_NAME));
0N/A }
0N/A
0N/A defaultOrderingMatchingRule =
0N/A DirectoryServer.getOrderingMatchingRule(OMR_CASE_IGNORE_OID);
0N/A if (defaultOrderingMatchingRule == null)
0N/A {
2086N/A logError(ERR_ATTR_SYNTAX_UNKNOWN_ORDERING_MATCHING_RULE.get(
2086N/A OMR_CASE_IGNORE_OID, SYNTAX_TELETEX_TERM_ID_NAME));
0N/A }
0N/A
0N/A defaultSubstringMatchingRule =
0N/A DirectoryServer.getSubstringMatchingRule(SMR_CASE_IGNORE_OID);
0N/A if (defaultSubstringMatchingRule == null)
0N/A {
2086N/A logError(ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get(
2086N/A SMR_CASE_IGNORE_OID, SYNTAX_TELETEX_TERM_ID_NAME));
0N/A }
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the common name for this attribute syntax.
0N/A *
0N/A * @return The common name for this attribute syntax.
0N/A */
0N/A public String getSyntaxName()
0N/A {
0N/A return SYNTAX_TELETEX_TERM_ID_NAME;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the OID for this attribute syntax.
0N/A *
0N/A * @return The OID for this attribute syntax.
0N/A */
0N/A public String getOID()
0N/A {
0N/A return SYNTAX_TELETEX_TERM_ID_OID;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves a description for this attribute syntax.
0N/A *
0N/A * @return A description for this attribute syntax.
0N/A */
0N/A public String getDescription()
0N/A {
0N/A return SYNTAX_TELETEX_TERM_ID_DESCRIPTION;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the default equality matching rule that will be used for
0N/A * attributes with this syntax.
0N/A *
0N/A * @return The default equality matching rule that will be used for
0N/A * attributes with this syntax, or <CODE>null</CODE> if equality
0N/A * matches will not be allowed for this type by default.
0N/A */
0N/A public EqualityMatchingRule getEqualityMatchingRule()
0N/A {
0N/A return defaultEqualityMatchingRule;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the default ordering matching rule that will be used for
0N/A * attributes with this syntax.
0N/A *
0N/A * @return The default ordering matching rule that will be used for
0N/A * attributes with this syntax, or <CODE>null</CODE> if ordering
0N/A * matches will not be allowed for this type by default.
0N/A */
0N/A public OrderingMatchingRule getOrderingMatchingRule()
0N/A {
0N/A return defaultOrderingMatchingRule;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the default substring matching rule that will be used for
0N/A * attributes with this syntax.
0N/A *
0N/A * @return The default substring matching rule that will be used for
0N/A * attributes with this syntax, or <CODE>null</CODE> if substring
0N/A * matches will not be allowed for this type by default.
0N/A */
0N/A public SubstringMatchingRule getSubstringMatchingRule()
0N/A {
0N/A return defaultSubstringMatchingRule;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the default approximate matching rule that will be used for
0N/A * attributes with this syntax.
0N/A *
0N/A * @return The default approximate matching rule that will be used for
0N/A * attributes with this syntax, or <CODE>null</CODE> if approximate
0N/A * matches will not be allowed for this type by default.
0N/A */
0N/A public ApproximateMatchingRule getApproximateMatchingRule()
0N/A {
0N/A // There is no approximate matching rule by default.
0N/A return null;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Indicates whether the provided value is acceptable for use in an attribute
0N/A * with this syntax. If it is not, then the reason may be appended to the
0N/A * provided buffer.
0N/A *
0N/A * @param value The value for which to make the determination.
0N/A * @param invalidReason The buffer to which the invalid reason should be
0N/A * appended.
0N/A *
0N/A * @return <CODE>true</CODE> if the provided value is acceptable for use with
0N/A * this syntax, or <CODE>false</CODE> if not.
0N/A */
4134N/A public boolean valueIsAcceptable(ByteSequence value,
2086N/A MessageBuilder invalidReason)
0N/A {
0N/A // Get a lowercase string representation of the value and find its length.
4134N/A String valueString = value.toString();
0N/A int valueLength = valueString.length();
0N/A
0N/A
0N/A // The value must contain at least one character.
0N/A if (valueLength == 0)
0N/A {
2086N/A
2086N/A invalidReason.append(ERR_ATTR_SYNTAX_TELETEXID_EMPTY.get());
0N/A return false;
0N/A }
0N/A
0N/A
0N/A // The first character must be a printable string character.
0N/A char c = valueString.charAt(0);
0N/A if (! PrintableString.isPrintableCharacter(c))
0N/A {
2086N/A
2086N/A invalidReason.append(ERR_ATTR_SYNTAX_TELETEXID_NOT_PRINTABLE.get(
2086N/A valueString, String.valueOf(c), 0));
0N/A return false;
0N/A }
0N/A
0N/A
0N/A // Continue reading until we find a dollar sign or the end of the string.
0N/A // Every intermediate character must be a printable string character.
0N/A int pos = 1;
0N/A for ( ; pos < valueLength; pos++)
0N/A {
0N/A c = valueString.charAt(pos);
0N/A if (c == '$')
0N/A {
0N/A pos++;
0N/A break;
0N/A }
0N/A else
0N/A {
0N/A if (! PrintableString.isPrintableCharacter(c))
0N/A {
2086N/A
2086N/A invalidReason.append(ERR_ATTR_SYNTAX_TELETEXID_NOT_PRINTABLE.get(
2086N/A valueString, String.valueOf(c), pos));
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (pos >= valueLength)
0N/A {
0N/A // We're at the end of the value, so it must be valid unless the last
0N/A // character was a dollar sign.
0N/A if (c == '$')
0N/A {
2086N/A
2086N/A invalidReason.append(ERR_ATTR_SYNTAX_TELETEXID_END_WITH_DOLLAR.get(
2086N/A valueString));
0N/A return false;
0N/A }
0N/A else
0N/A {
0N/A return true;
0N/A }
0N/A }
0N/A
0N/A
0N/A // Continue reading until we find the end of the string. Each substring
0N/A // must be a valid teletex terminal identifier parameter followed by a colon
0N/A // and the value. Dollar signs must be escaped
0N/A int paramStartPos = pos;
0N/A boolean escaped = false;
0N/A while (pos < valueLength)
0N/A {
0N/A if (escaped)
0N/A {
0N/A pos++;
0N/A continue;
0N/A }
0N/A
0N/A c = valueString.charAt(pos++);
0N/A if (c == '\\')
0N/A {
0N/A escaped = true;
0N/A continue;
0N/A }
0N/A else if (c == '$')
0N/A {
0N/A String paramStr = valueString.substring(paramStartPos, pos);
0N/A
0N/A int colonPos = paramStr.indexOf(':');
0N/A if (colonPos < 0)
0N/A {
2086N/A
2086N/A invalidReason.append(ERR_ATTR_SYNTAX_TELETEXID_PARAM_NO_COLON.get(
2086N/A valueString));
0N/A return false;
0N/A }
0N/A
0N/A String paramName = paramStr.substring(0, colonPos);
0N/A if (! ALLOWED_TTX_PARAMETERS.contains(paramName))
0N/A {
2086N/A
2086N/A invalidReason.append(ERR_ATTR_SYNTAX_TELETEXID_ILLEGAL_PARAMETER.get(
2086N/A valueString, paramName));
0N/A return false;
0N/A }
0N/A
0N/A paramStartPos = pos;
0N/A }
0N/A }
0N/A
0N/A
0N/A // We must be at the end of the value. Read the last parameter and make
0N/A // sure it is valid.
0N/A String paramStr = valueString.substring(paramStartPos);
0N/A int colonPos = paramStr.indexOf(':');
0N/A if (colonPos < 0)
0N/A {
2086N/A
2086N/A invalidReason.append(ERR_ATTR_SYNTAX_TELETEXID_PARAM_NO_COLON.get(
2086N/A valueString));
0N/A return false;
0N/A }
0N/A
0N/A String paramName = paramStr.substring(0, colonPos);
0N/A if (! ALLOWED_TTX_PARAMETERS.contains(paramName))
0N/A {
2086N/A
2086N/A invalidReason.append(ERR_ATTR_SYNTAX_TELETEXID_ILLEGAL_PARAMETER.get(
2086N/A valueString, paramName));
0N/A return false;
0N/A }
0N/A
0N/A
0N/A // If we've gotten here, then the value must be valid.
0N/A return true;
0N/A }
3853N/A
3853N/A
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public boolean isBinary()
3853N/A {
3853N/A return false;
3853N/A }
5866N/A
5866N/A
5866N/A
5866N/A /**
5866N/A * {@inheritDoc}
5866N/A */
5866N/A public boolean isHumanReadable()
5866N/A {
5866N/A return true;
5866N/A }
0N/A}
0N/A