You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/01/20 01:13:56 UTC
svn commit: r901013 - in /directory/shared/trunk/ldap-schema: pom.xml
src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java
Author: elecharny
Date: Wed Jan 20 00:13:56 2010
New Revision: 901013
URL: http://svn.apache.org/viewvc?rev=901013&view=rev
Log:
Added the necessary code to add the missing entryUUID as a String while extracting the schema
Modified:
directory/shared/trunk/ldap-schema/pom.xml
directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java
Modified: directory/shared/trunk/ldap-schema/pom.xml
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema/pom.xml?rev=901013&r1=901012&r2=901013&view=diff
==============================================================================
--- directory/shared/trunk/ldap-schema/pom.xml (original)
+++ directory/shared/trunk/ldap-schema/pom.xml Wed Jan 20 00:13:56 2010
@@ -26,6 +26,7 @@
<artifactId>shared-parent</artifactId>
<version>0.9.18-SNAPSHOT</version>
</parent>
+
<artifactId>shared-ldap-schema</artifactId>
<name>Apache Directory Shared LDAP Schema</name>
<packaging>jar</packaging>
@@ -42,6 +43,18 @@
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>shared-ldap</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>shared-ldap-constants</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
</dependencies>
<build>
Modified: directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java?rev=901013&r1=901012&r2=901013&view=diff
==============================================================================
--- directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java (original)
+++ directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java Wed Jan 20 00:13:56 2010
@@ -20,21 +20,26 @@
package org.apache.directory.shared.ldap.schema.ldif.extractor.impl;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InvalidObjectException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Map;
import java.util.Stack;
+import java.util.UUID;
import java.util.Map.Entry;
import java.util.regex.Pattern;
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
import org.apache.directory.shared.ldap.schema.ldif.extractor.UniqueResourceException;
import org.slf4j.Logger;
@@ -187,20 +192,60 @@
if ( ! source.getParentFile().exists() )
{
throw new FileNotFoundException( "Cannot copy non-existant " +
- "source file " + source.getAbsolutePath() );
+ "source file " + source.getAbsolutePath() );
}
FileWriter out = new FileWriter( destination );
- BufferedReader in = new BufferedReader( new FileReader( source ) );
- String line;
- while ( null != ( line = in.readLine() ) )
+
+ try
{
- out.write( line + "\n" );
+ LdifReader ldifReader = new LdifReader( source );
+ boolean first = true;
+ LdifEntry ldifEntry = null;
+
+ while ( ldifReader.hasNext() )
+ {
+ if ( first )
+ {
+ ldifEntry = ldifReader.next();
+
+ if ( ldifEntry.get( SchemaConstants.ENTRY_UUID_AT ) == null )
+ {
+ // No UUID, let's create one
+ UUID entryUuid = UUID.randomUUID();
+ ldifEntry.addAttribute( SchemaConstants.ENTRY_UUID_AT, entryUuid.toString() );
+ }
+
+ first = false;
+ }
+ else
+ {
+ // throw an exception : we should not have more than one entry per schema ldif file
+ String msg = "Cannot have more than one entry in a schema ldif file : " + source;
+ LOG.error( msg );
+ throw new InvalidObjectException( msg );
+ }
+ }
+
+ ldifReader.close();
+
+ // Add the version at the first line, to avoid a warning
+ String ldifString = "version: 1\n" + ldifEntry.toString();
+
+ out.write( ldifString );
+ out.flush();
+ }
+ catch ( NamingException ne )
+ {
+ // throw an exception : we should not have more than one entry per schema ldif file
+ String msg = "Excepion occured while parsing the ldif file " + source + " : " + ne.getMessage();
+ LOG.error( msg );
+ throw new InvalidObjectException( msg );
+ }
+ finally
+ {
+ out.close();
}
-
- in.close();
- out.flush();
- out.close();
}
@@ -338,7 +383,7 @@
try
{
- File destination = new File( outputDirectory, resource );
+ File destination = new File( outputDirectory, resource );
/*
* Do not overwrite an LDIF file if it has already been extracted.
@@ -347,12 +392,12 @@
{
return;
}
-
- if ( ! destination.getParentFile().exists() )
- {
- destination.getParentFile().mkdirs();
- }
-
+
+ if ( ! destination.getParentFile().exists() )
+ {
+ destination.getParentFile().mkdirs();
+ }
+
FileOutputStream out = new FileOutputStream( destination );
try
{