Index: ldap/pom.xml
===================================================================
--- ldap/pom.xml (revision 389684)
+++ ldap/pom.xml (working copy)
@@ -83,6 +83,12 @@
+ commons-io
+ commons-io
+ 1.2
+
+
+
org.apache.directory.shared
shared-asn1
${pom.version}
Index: ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifParserImpl.java
===================================================================
--- ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifParserImpl.java (revision 389684)
+++ ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifParserImpl.java (working copy)
@@ -18,9 +18,9 @@
package org.apache.directory.shared.ldap.ldif;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.BufferedReader;
+import java.io.*;
+import java.net.URL;
+import java.net.MalformedURLException;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
@@ -30,6 +30,7 @@
import org.apache.directory.shared.ldap.exception.LdapNamingException;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.util.Base64;
+import org.apache.commons.io.IOUtils;
/**
@@ -75,6 +76,7 @@
*/
public synchronized void parse( Attributes attributes, String ldif ) throws NamingException
{
+ boolean isImportFile = false;
boolean isBase64Encoded = false;
int lineCount = 0;
int index;
@@ -123,10 +125,15 @@
}
// Consume next char and check if it's a colon for binary attr.
- if ( line.charAt( ++index ) == ':' )
+ index++;
+ if ( line.charAt( index ) == ':' )
{
isBase64Encoded = true;
}
+ else if ( line.charAt( index ) == '<' )
+ {
+ isImportFile = true;
+ }
// Advance index past whitespace to the first char of the value.
try
@@ -165,6 +172,58 @@
}
isBase64Encoded = false;
}
+ else if ( isImportFile && ( attrValue != null ) )
+ {
+ final URL url;
+ InputStream is = null;
+ ByteArrayOutputStream bos = null;
+ final byte[] value;
+
+ try
+ {
+ url = new URL(attrValue);
+ is = url.openStream();
+ bos = new ByteArrayOutputStream(4 * 1024);
+ IOUtils.copy(is, bos);
+ value = bos.toByteArray();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new LdapNamingException( "Line " + lineCount + " [" + line
+ + "] passes malformed URL to ':<' inclusion.\n{" + ldif + "}",
+ ResultCodeEnum.OTHER );
+ }
+ catch (IOException e)
+ {
+ throw new LdapNamingException( "Line " + lineCount + " [" + line
+ + "] failed including URL passed to ':<' inclusion.\n{" + ldif + "}",
+ ResultCodeEnum.OTHER );
+ }
+ finally
+ {
+ if (is != null)
+ try
+ {
+ is.close();
+ } catch (IOException e) {}
+ if (bos != null)
+ try
+ {
+ bos.close();
+ } catch (IOException e) {}
+ }
+
+ if ( attributes.get( attrName ) == null )
+ {
+ attributes.put( attrName, value );
+ }
+ else
+ {
+ Attribute attribute = attributes.get( attrName );
+ attribute.add( value );
+ }
+ isImportFile = false;
+ }
else
{
if ( attributes.get( attrName ) == null )