| | |
| | | import java.io.FileWriter; |
| | | import java.io.FilenameFilter; |
| | | import java.io.IOException; |
| | | import java.text.ParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | |
| | | import org.opends.server.schema.NameFormSyntax; |
| | | import org.opends.server.schema.ObjectClassSyntax; |
| | | import org.opends.server.schema.SomeSchemaElement; |
| | | import org.opends.server.util.Base64; |
| | | import org.opends.server.util.ServerConstants; |
| | | import org.opends.server.util.StaticUtils; |
| | | |
| | |
| | | // element list. |
| | | for (StringBuilder buffer : lines) |
| | | { |
| | | // Get the line and add the X-SCHEMA-FILE extension to the end |
| | | // of it. All of them should end with " )" but some might |
| | | // have the parenthesis crammed up against the last character |
| | | // so deal with that as well. |
| | | String line = buffer.toString().trim(); |
| | | if (line.endsWith(" )")) |
| | | { |
| | | line = line.substring(0, line.length()-1) + |
| | | SCHEMA_PROPERTY_FILENAME + " '" + f.getName() + "' )"; |
| | | } |
| | | else if (line.endsWith(")")) |
| | | { |
| | | line = line.substring(0, line.length()-1) + " " + |
| | | SCHEMA_PROPERTY_FILENAME + " '" + f.getName() + "' )"; |
| | | } |
| | | else |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | parseSchemaLine(line, attributeTypes, objectClasses, |
| | | parseSchemaLine(line, f.getName(), attributeTypes, objectClasses, |
| | | nameForms, ditContentRules, ditStructureRules, matchingRuleUses, |
| | | ldapSyntaxes); |
| | | } |
| | |
| | | { |
| | | break; |
| | | } |
| | | parseSchemaLine(line, attributeTypes, objectClasses, |
| | | parseSchemaLine(line, null, attributeTypes, objectClasses, |
| | | nameForms, ditContentRules, ditStructureRules, matchingRuleUses, |
| | | ldapSyntaxes); |
| | | } |
| | |
| | | reader.close(); |
| | | } |
| | | |
| | | /** |
| | | * Parse a line of a schema file into the provided sets. |
| | | * |
| | | * @param line The current line of schema. |
| | | * @param attributeTypes The set into which to place the |
| | | * attribute type if the line represents |
| | | * one. |
| | | * @param objectClasses The set into which to place the object |
| | | * class if the line represents one. |
| | | * @param nameForms The set into which to place the name |
| | | * form if the line represents one. |
| | | * @param ditContentRules The set into which to place the DIT |
| | | * content rule if the line represents one. |
| | | * @param ditStructureRules The set into which to place the DIT |
| | | * structure rule if the line represents one. |
| | | * @param matchingRuleUses The set into which to place the |
| | | * matching rule use if the line represents |
| | | * one. |
| | | * @param ldapSyntaxes The set into which to place the ldap |
| | | * syntax if the line represents one. |
| | | */ |
| | | |
| | | private static void parseSchemaLine(String line, |
| | | private static void parseSchemaLine(String line, String fileName, |
| | | Set<String> attributeTypes, |
| | | Set<String> objectClasses, |
| | | Set<String> nameForms, |
| | |
| | | Set<String> matchingRuleUses, |
| | | Set<String> ldapSyntaxes) |
| | | { |
| | | String value; |
| | | String lowerLine = toLowerCase(line); |
| | | |
| | | try |
| | | { |
| | | if (lowerLine.startsWith(ATTR_ATTRIBUTE_TYPES_LC)) |
| | | { |
| | | value = |
| | | line.substring(ATTR_ATTRIBUTE_TYPES.length()+1).trim(); |
| | | attributeTypes.add(value); |
| | | attributeTypes.add(getSchemaDefinition(line.substring(ATTR_ATTRIBUTE_TYPES_LC.length()), fileName)); |
| | | } |
| | | else if (lowerLine.startsWith(ATTR_OBJECTCLASSES_LC)) |
| | | { |
| | | value = line.substring(ATTR_OBJECTCLASSES.length()+1).trim(); |
| | | objectClasses.add(value); |
| | | objectClasses.add(getSchemaDefinition(line.substring(ATTR_OBJECTCLASSES_LC.length()), fileName)); |
| | | } |
| | | else if (lowerLine.startsWith(ATTR_NAME_FORMS_LC)) |
| | | { |
| | | value = line.substring(ATTR_NAME_FORMS.length()+1).trim(); |
| | | nameForms.add(value); |
| | | nameForms.add(getSchemaDefinition(line.substring(ATTR_NAME_FORMS_LC.length()), fileName)); |
| | | } |
| | | else if (lowerLine.startsWith(ATTR_DIT_CONTENT_RULES_LC)) |
| | | { |
| | | value = line.substring( |
| | | ATTR_DIT_CONTENT_RULES.length()+1).trim(); |
| | | ditContentRules.add(value); |
| | | ditContentRules.add(getSchemaDefinition(line.substring(ATTR_DIT_CONTENT_RULES_LC.length()), fileName)); |
| | | } |
| | | else if (lowerLine.startsWith(ATTR_DIT_STRUCTURE_RULES_LC)) |
| | | { |
| | | value = line.substring( |
| | | ATTR_DIT_STRUCTURE_RULES.length()+1).trim(); |
| | | ditStructureRules.add(value); |
| | | ditStructureRules.add(getSchemaDefinition(line.substring(ATTR_DIT_STRUCTURE_RULES_LC.length()), fileName)); |
| | | } |
| | | else if (lowerLine.startsWith(ATTR_MATCHING_RULE_USE_LC)) |
| | | { |
| | | value = line.substring( |
| | | ATTR_MATCHING_RULE_USE.length()+1).trim(); |
| | | matchingRuleUses.add(value); |
| | | matchingRuleUses.add(getSchemaDefinition(line.substring(ATTR_MATCHING_RULE_USE_LC.length()), fileName)); |
| | | } |
| | | else if (lowerLine.startsWith(ATTR_LDAP_SYNTAXES_LC)) |
| | | { |
| | | value = line.substring( |
| | | ATTR_LDAP_SYNTAXES.length()+1).trim(); |
| | | ldapSyntaxes.add(value); |
| | | ldapSyntaxes.add(getSchemaDefinition(line.substring(ATTR_LDAP_SYNTAXES_LC.length()), fileName)); |
| | | } |
| | | } catch (ParseException pe) |
| | | { |
| | | logger.error(ERR_SCHEMA_PARSE_LINE.get(line, pe.getLocalizedMessage())); |
| | | } |
| | | } |
| | | |
| | | private static String getSchemaDefinition(String line, String fileName) throws ParseException |
| | | { |
| | | if (line.startsWith("::")) |
| | | { |
| | | line = ByteString.wrap(Base64.decode(line.substring(2).trim())).toString(); |
| | | } |
| | | else if (line.startsWith(":")) |
| | | { |
| | | line = line.substring(1).trim(); |
| | | } |
| | | else |
| | | { |
| | | throw new ParseException(ERR_SCHEMA_COULD_NOT_PARSE_DEFINITION.get().toString(), 0); |
| | | } |
| | | |
| | | if (fileName != null) |
| | | { |
| | | if (line.endsWith(" )")) |
| | | { |
| | | line = line.substring(0, line.length() - 1) + SCHEMA_PROPERTY_FILENAME + " '" + fileName + "' )"; |
| | | } |
| | | else if (line.endsWith(")")) |
| | | { |
| | | line = line.substring(0, line.length() - 1) + " " + SCHEMA_PROPERTY_FILENAME + " '" + fileName + "' )"; |
| | | } |
| | | } |
| | | return line; |
| | | } |
| | | |
| | | /** |