/** * Writes the configuration to a String object. * * @return * a String containing the LDIF * representation of the configuration * @throws ConfigurationException * if an error occurs during the conversion to LDIF */ public String writeToString() throws ConfigurationException { // Converting the configuration bean to a list of LDIF entries convertConfigurationBeanToLdifEntries(); // Building the StringBuilder StringBuilder sb = new StringBuilder(); sb.append( "version: 1\n" ); for ( LdifEntry entry : entries ) { sb.append( entry.toString() ); } return sb.toString(); }
ldifString = "version: 1\n" + ldifEntry.toString();
ldifString = "version: 1\n" + ldifEntry.toString();
ldifString = "version: 1\n" + ldifEntry.toString();
private void importLdif(LdifReader ldifReader) throws Exception { try { for (LdifEntry ldifEntry : ldifReader) { checkPartition(ldifEntry); System.out.print(ldifEntry.toString()); directoryService.getAdminSession() .add(new DefaultEntry(directoryService.getSchemaManager(), ldifEntry.getEntry())); } } finally { IOUtils.closeQuietly(ldifReader); } }
/** * Stream will be closed automatically. */ public void importLdif(InputStream is) throws Exception { try (LdifReader reader = new LdifReader(is)) { CoreSession coreSession = directoryService.getAdminSession(); // see LdifFileLoader for (LdifEntry ldifEntry : reader) { String ldif = ldifEntry.toString(); LOG.info(ldif); if (ChangeType.Add == ldifEntry.getChangeType() || /* assume "add" by default */ ChangeType.None == ldifEntry.getChangeType()) { coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), ldifEntry.getEntry())); } else if (ChangeType.Modify == ldifEntry.getChangeType()) { coreSession.modify(ldifEntry.getDn(), ldifEntry.getModifications()); } else if (ChangeType.Delete == ldifEntry.getChangeType()) { coreSession.delete(ldifEntry.getDn()); } else { throw new IllegalStateException(); } } } }