зеркало из https://github.com/mozilla/pjs.git
Resolves: 372194, 62700
Author: sparkins@redhat.com Summary: Re-implemented two bug fixes in the LDIFWriter class in order to allow us to relicense the LDAP JDK under the standard Mozilla tri-license. The first bug had to do with the printEntryStart() method of the LDIFWriter class does not handling non-printable DN's properly. The second bug had to do with only the first value of a multi-valued attribute being written out in LDIF format.
This commit is contained in:
Родитель
b4cde0a17f
Коммит
3161169591
|
@ -17,8 +17,7 @@
|
|||
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* bugzilla 62700: Joe Rank (joer@trapdoor.net)
|
||||
* Contributor(s):
|
||||
*/
|
||||
package netscape.ldap.util;
|
||||
|
||||
|
@ -34,12 +33,12 @@ import java.io.*;
|
|||
public class LDIFWriter extends LDAPWriter {
|
||||
|
||||
// static final long serialVersionUID = -2710382547996750924L;
|
||||
private String m_sep;
|
||||
private boolean m_foldLines;
|
||||
private boolean m_attrsOnly;
|
||||
private boolean m_toFiles;
|
||||
private static final String DEFAULT_SEPARATOR = ":";
|
||||
private static final int MAX_LINE = 77;
|
||||
private String m_sep;
|
||||
private boolean m_foldLines;
|
||||
private boolean m_attrsOnly;
|
||||
private boolean m_toFiles;
|
||||
private static final String DEFAULT_SEPARATOR = ":";
|
||||
private static final int MAX_LINE = 77;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -57,24 +56,24 @@ public class LDIFWriter extends LDAPWriter {
|
|||
* to a stream as LDIF.
|
||||
*
|
||||
* @param pw output stream
|
||||
* @param attrsOnly <code>true</code> if only attribute names, not
|
||||
* values, are to be printed
|
||||
* @param separator String to use between attribute names and values;
|
||||
* the default is ":"
|
||||
* @param foldLines <code>true</code> to fold lines at 77 characters,
|
||||
* <code>false</code> to not fold them; the default is <code>true</code>.
|
||||
* @param toFiles <code>true</code> to write each attribute value to a
|
||||
* file in the temp folder, <code>false</code> to write them to the
|
||||
* output stream in printable format; the default is <code>false</code>.
|
||||
* @param attrsOnly <code>true</code> if only attribute names, not
|
||||
* values, are to be printed
|
||||
* @param separator String to use between attribute names and values;
|
||||
* the default is ":"
|
||||
* @param foldLines <code>true</code> to fold lines at 77 characters,
|
||||
* <code>false</code> to not fold them; the default is <code>true</code>.
|
||||
* @param toFiles <code>true</code> to write each attribute value to a
|
||||
* file in the temp folder, <code>false</code> to write them to the
|
||||
* output stream in printable format; the default is <code>false</code>.
|
||||
*/
|
||||
public LDIFWriter( PrintWriter pw, boolean attrsOnly,
|
||||
String separator, boolean foldLines,
|
||||
boolean toFiles ) {
|
||||
super( pw );
|
||||
m_attrsOnly = attrsOnly;
|
||||
m_sep = separator;
|
||||
m_foldLines = foldLines;
|
||||
m_toFiles = toFiles;
|
||||
String separator, boolean foldLines,
|
||||
boolean toFiles ) {
|
||||
super( pw );
|
||||
m_attrsOnly = attrsOnly;
|
||||
m_sep = separator;
|
||||
m_foldLines = foldLines;
|
||||
m_toFiles = toFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,77 +82,75 @@ public class LDIFWriter extends LDAPWriter {
|
|||
* @param attr the attribute to format to the output stream
|
||||
*/
|
||||
protected void printAttribute( LDAPAttribute attr ) {
|
||||
String attrName = attr.getName();
|
||||
String attrName = attr.getName();
|
||||
|
||||
if ( m_attrsOnly ) {
|
||||
printString( attrName + m_sep );
|
||||
return;
|
||||
}
|
||||
if ( m_attrsOnly ) {
|
||||
printString( attrName + m_sep );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Loop on values for this attribute */
|
||||
Enumeration enumVals = attr.getByteValues();
|
||||
/* Loop on values for this attribute */
|
||||
Enumeration enumVals = attr.getByteValues();
|
||||
|
||||
if ( enumVals == null ) {
|
||||
printString( attrName + m_sep + ' ' );
|
||||
return;
|
||||
}
|
||||
|
||||
while (enumVals.hasMoreElements()) {
|
||||
if ( m_toFiles ) {
|
||||
try {
|
||||
FileOutputStream f = getTempFile( attrName );
|
||||
f.write( (byte[])enumVals.nextElement() );
|
||||
} catch ( Exception e ) {
|
||||
System.err.println( "Error writing values " +
|
||||
"of " + attrName + ", " +
|
||||
e.toString() );
|
||||
System.exit(1);
|
||||
}
|
||||
} else {
|
||||
byte[] b = (byte[])enumVals.nextElement();
|
||||
String s;
|
||||
if ( LDIF.isPrintable(b) ) {
|
||||
try {
|
||||
s = new String( b, "UTF8" );
|
||||
} catch ( UnsupportedEncodingException e ) {
|
||||
s = "";
|
||||
}
|
||||
printString( attrName + m_sep + " " + s );
|
||||
} else {
|
||||
s = getPrintableValue( b );
|
||||
if ( s.length() > 0 ) {
|
||||
printString( attrName + ":: " + s );
|
||||
} else {
|
||||
printString( attrName + m_sep + ' ' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( enumVals != null ) {
|
||||
while (enumVals.hasMoreElements()) {
|
||||
if ( m_toFiles ) {
|
||||
try {
|
||||
FileOutputStream f = getTempFile( attrName );
|
||||
f.write( (byte[])enumVals.nextElement() );
|
||||
} catch ( Exception e ) {
|
||||
System.err.println( "Error writing values " +
|
||||
"of " + attrName + ", " +
|
||||
e.toString() );
|
||||
System.exit(1);
|
||||
}
|
||||
} else {
|
||||
byte[] b = (byte[])enumVals.nextElement();
|
||||
String s;
|
||||
if ( LDIF.isPrintable(b) ) {
|
||||
try {
|
||||
s = new String( b, "UTF8" );
|
||||
} catch ( UnsupportedEncodingException e ) {
|
||||
s = "";
|
||||
}
|
||||
printString( attrName + m_sep + " " + s );
|
||||
} else {
|
||||
s = getPrintableValue( b );
|
||||
if ( s.length() > 0 ) {
|
||||
printString( attrName + ":: " + s );
|
||||
} else {
|
||||
printString( attrName + m_sep + ' ' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printString( attrName + m_sep + ' ' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print prologue to entry
|
||||
*
|
||||
* @param dn the DN of the entry
|
||||
*/
|
||||
protected void printEntryStart( String dn ) {
|
||||
if ( dn == null ) {
|
||||
printString( "dn" + m_sep + " " );
|
||||
} else {
|
||||
protected void printEntryStart( String dn ) {
|
||||
if ( dn == null ) {
|
||||
printString( "dn" + m_sep + " ");
|
||||
} else {
|
||||
byte[] b = null;
|
||||
try {
|
||||
b = dn.getBytes( "UTF8" );
|
||||
} catch ( UnsupportedEncodingException ex ) {
|
||||
b = dn.getBytes();
|
||||
}
|
||||
if ( !LDIF.isPrintable(b) ) {
|
||||
if ( LDIF.isPrintable(b) ) {
|
||||
printString( "dn" + m_sep + " " + dn );
|
||||
} else {
|
||||
dn = getPrintableValue( b );
|
||||
printString( "dn" + m_sep + m_sep + " " + dn );
|
||||
} else {
|
||||
printString( "dn" + m_sep + " " + dn );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print epilogue to entry
|
||||
|
@ -173,26 +170,26 @@ public class LDIFWriter extends LDAPWriter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a unique file name in the temp folder and open an
|
||||
* output stream to the file
|
||||
*
|
||||
* @param name base name of file; an extension is appended which
|
||||
* consists of a number that makes the name unique
|
||||
* @return an open output stream to the file
|
||||
* @exception IOException if the file couldn't be opened for output
|
||||
*/
|
||||
/**
|
||||
* Create a unique file name in the temp folder and open an
|
||||
* output stream to the file
|
||||
*
|
||||
* @param name base name of file; an extension is appended which
|
||||
* consists of a number that makes the name unique
|
||||
* @return an open output stream to the file
|
||||
* @exception IOException if the file couldn't be opened for output
|
||||
*/
|
||||
protected FileOutputStream getTempFile( String name )
|
||||
throws IOException {
|
||||
int num = 0;
|
||||
File f;
|
||||
String filename;
|
||||
do {
|
||||
filename = name + '.' + num;
|
||||
f = new File( filename );
|
||||
num++;
|
||||
} while ( f.exists() );
|
||||
printString(name + m_sep + " " + filename);
|
||||
return new FileOutputStream( f );
|
||||
}
|
||||
int num = 0;
|
||||
File f;
|
||||
String filename;
|
||||
do {
|
||||
filename = name + '.' + num;
|
||||
f = new File( filename );
|
||||
num++;
|
||||
} while ( f.exists() );
|
||||
printString(name + m_sep + " " + filename);
|
||||
return new FileOutputStream( f );
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче