/** * Load the entries from a Ldif file recursively * @throws LdapLdifException * @throws IOException */ private static void loadEntries( File ldifFile, List<LdifEntry> entries ) throws LdapLdifException, IOException { if ( ldifFile.isDirectory() ) { File[] files = ldifFile.listFiles( ldifFilter ); for ( File f : files ) { loadEntries( f, entries ); } } else { LdifReader reader = new LdifReader(); try { entries.addAll( reader.parseLdifFile( ldifFile.getAbsolutePath() ) ); } finally { reader.close(); } } }
/** * {@inheritDoc} */ @Override public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOException { List<Entry> syntaxList = new ArrayList<>(); if ( schemas == null ) { return syntaxList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.SYNTAXES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "syntax LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); syntaxList.add( entry.getEntry() ); } } } return syntaxList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadMatchingRules( Schema... schemas ) throws LdapException, IOException { List<Entry> matchingRuleList = new ArrayList<>(); if ( schemas == null ) { return matchingRuleList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.MATCHING_RULES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "matchingRules LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); matchingRuleList.add( entry.getEntry() ); } } } return matchingRuleList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadDitStructureRules( Schema... schemas ) throws LdapException, IOException { List<Entry> ditStructureRuleList = new ArrayList<>(); if ( schemas == null ) { return ditStructureRuleList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.DIT_STRUCTURE_RULES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "ditStructureRule LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); ditStructureRuleList.add( entry.getEntry() ); } } } return ditStructureRuleList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IOException { List<Entry> comparatorList = new ArrayList<>(); if ( schemas == null ) { return comparatorList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.COMPARATORS_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "comparator LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); comparatorList.add( entry.getEntry() ); } } } return comparatorList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadDitContentRules( Schema... schemas ) throws LdapException, IOException { List<Entry> ditContentRulesList = new ArrayList<>(); if ( schemas == null ) { return ditContentRulesList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.DIT_CONTENT_RULES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "ditContentRule LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); ditContentRulesList.add( entry.getEntry() ); } } } return ditContentRulesList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadSyntaxCheckers( Schema... schemas ) throws LdapException, IOException { List<Entry> syntaxCheckerList = new ArrayList<>(); if ( schemas == null ) { return syntaxCheckerList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.SYNTAX_CHECKERS_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "syntaxChecker LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); syntaxCheckerList.add( entry.getEntry() ); } } } return syntaxCheckerList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOException { List<Entry> syntaxList = new ArrayList<>(); if ( schemas == null ) { return syntaxList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.SYNTAXES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "syntax LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); syntaxList.add( entry.getEntry() ); } } } return syntaxList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadMatchingRuleUses( Schema... schemas ) throws LdapException, IOException { List<Entry> matchingRuleUseList = new ArrayList<>(); if ( schemas == null ) { return matchingRuleUseList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.MATCHING_RULE_USE_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "matchingRuleUse LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); matchingRuleUseList.add( entry.getEntry() ); } } } return matchingRuleUseList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadDitStructureRules( Schema... schemas ) throws LdapException, IOException { List<Entry> ditStructureRuleList = new ArrayList<>(); if ( schemas == null ) { return ditStructureRuleList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.DIT_STRUCTURE_RULES_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "ditStructureRule LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); ditStructureRuleList.add( entry.getEntry() ); } } } return ditStructureRuleList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadNormalizers( Schema... schemas ) throws LdapException, IOException { List<Entry> normalizerList = new ArrayList<>(); if ( schemas == null ) { return normalizerList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.NORMALIZERS_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "normalizer LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); normalizerList.add( entry.getEntry() ); } } } return normalizerList; }
/** * {@inheritDoc} */ @Override public List<Entry> loadNameForms( Schema... schemas ) throws LdapException, IOException { List<Entry> nameFormList = new ArrayList<>(); if ( schemas == null ) { return nameFormList; } for ( Schema schema : schemas ) { String start = getSchemaDirectoryString( schema ) + SchemaConstants.NAME_FORMS_PATH + "/" + "m-oid="; String end = "." + LDIF_EXT; for ( String resourcePath : RESOURCE_MAP.keySet() ) { if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) ) { URL resource = getResource( resourcePath, "nameForm LDIF file" ); LdifReader reader = new LdifReader( resource.openStream() ); LdifEntry entry = reader.next(); reader.close(); nameFormList.add( entry.getEntry() ); } } } return nameFormList; }
/** * Inject an ldif String into the server. Dn must be relative to the root. * * @param service the directory service to use * @param ldif the ldif containing entries to add to the server. * @throws Exception if there is a problem adding the entries from the LDIF */ public static void injectEntries( DirectoryService service, String ldif ) throws Exception { LdifReader reader = new LdifReader(); List<LdifEntry> entries = reader.parseLdif( ldif ); for ( LdifEntry entry : entries ) { injectEntry( entry, service ); } // And close the reader reader.close(); }
LdifReader reader = new LdifReader(resource.openStream()); LdifEntry ldifEntry = reader.next(); reader.close();