+ throw new ArgeoException("Failed to start Apache Directory server",
+ e);
+ }
+ }
+
+ /**
+ * Processes an LDIF resource, filtering out attributes that cannot be
+ * imported in ADS and forcing a password.
+ */
+ protected void processLdif(Resource ldif, File targetFile) {
+ BufferedReader reader = null;
+ Writer writer = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(
+ ldif.getInputStream()));
+ writer = new FileWriter(targetFile);
+ String line = null;
+ lines: while ((line = reader.readLine()) != null) {
+ // comment and empty lines
+ if (line.trim().equals("") || line.startsWith("#")) {
+ writer.write(line);
+ writer.write('\n');
+ continue lines;
+ }
+
+ String[] tokens = line.split(":");
+ String attribute = null;
+ if (tokens != null && tokens.length > 1) {
+ attribute = tokens[0].trim();
+ if (ignoredLdifAttributes.contains(attribute))
+ continue lines;// ignore
+
+ if (attribute.equals("bdb_db_open")) {
+ log.warn("Ignored OpenLDAP output\n" + line);
+ continue lines;
+ }
+
+ if (ldifPassword != null
+ && attribute.equals(ldifPasswordAttribute)) {
+ line = ldifPasswordAttribute + ":: " + ldifPassword;
+ }
+
+ writer.write(line);
+ writer.write('\n');
+ } else {
+ log.warn("Ignored LDIF line\n" + line);
+ }
+ }
+ if (log.isDebugEnabled())
+ log.debug("Processed " + ldif + " to LDIF directory "
+ + configuration.getLdifDirectory());
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot process LDIF " + ldif, e);
+ } finally {
+ IOUtils.closeQuietly(reader);
+ IOUtils.closeQuietly(writer);