Package netscape.ldap.util
Class LDIF
java.lang.Object
netscape.ldap.util.LDIF
- All Implemented Interfaces:
Serializable
LDAP Data Interchange Format (LDIF) is a file format used to
import and export directory data from an LDAP server and to
describe a set of changes to be applied to data in a directory.
This format is described in the Internet draft
The LDAP Data Interchange Format (LDIF) -
Technical Specification.
This class implements an LDIF file parser. You can construct
an object of this class to parse data in LDIF format and
manipulate the data as individual LDIFRecord
objects.
- Version:
- 1.0
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char
Internal constantsprivate int
private boolean
private int
private MimeBase64Decoder
private boolean
private LDIF.LineReader
private String
private int
Internal variables(package private) static final long
-
Constructor Summary
ConstructorsConstructorDescriptionLDIF()
Constructs anLDIF
object to parse the LDAP data read from stdin.LDIF
(DataInputStream ds) Constructs anLDIF
object to parse the LDIF data read from an input stream.Constructs anLDIF
object to parse the LDIF data read from a specified file. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
breakString
(PrintWriter pw, String value, int max) Outputs the String in LDIF line-continuation format.private byte[]
getDecodedBytes
(String line) private byte[]
getFileContent
(String url) int
Gets the version of LDIF used in the data.static boolean
isPrintable
(byte[] b) Returns true if all the bytes in the given array are valid for output as a String according to the LDIF specification.static void
Test driver - just reads and parses an LDIF file, printing each record as interpretedReturns the next record in the LDIF data.private LDIFAddContent
Parses add contentprotected LDAPControl
parse_control_spec
(String line) Parses the specification of a control
A control looks line one of the following:
control: 1.2.3.4.10.210
control: 1.2.3.4.10.210 true
control: 1.2.3.4.10.210 true: someASCIIvalue
control: 1.2.3.4.10.210: someASCIIvalue
control: 1.2.3.4.10.210 true:: 44GK44GM44GV44KP44KJ
control: 1.2.3.4.10.210:: 44GK44GM44GV44KP44KJ
control: 1.2.3.4.10.210 true:< file:///usr/local/directory/cont.dta
control: 1.2.3.4.10.210:< file:///usr/local/directory/cont.dtaprivate LDIFDeleteContent
Parses delete contentprivate LDIFContent
Parses ldif content.private LDIFRecord
Parses ldif content.private LDIFModifyContent
Parses change modification.private LDIFModDNContent
Parses moddn/modrdn modification.protected void
throwLDIFException
(String msg) Throws a LDIF file exception including the current line number.static String
toPrintableString
(byte[] b) Converts a byte array to a printable string following the LDIF rules (encode in base64 if necessary)toString()
Gets the string representation of the entire LDIF file.
-
Field Details
-
COMMENT
private static final char COMMENTInternal constants- See Also:
-
serialVersionUID
static final long serialVersionUID- See Also:
-
m_version
private int m_versionInternal variables -
m_done
private boolean m_done -
m_reader
-
m_source
-
m_decoder
-
m_currEntryDone
private boolean m_currEntryDone -
m_currLineNum
private int m_currLineNum -
m_continuationLength
private int m_continuationLength
-
-
Constructor Details
-
LDIF
Constructs anLDIF
object to parse the LDAP data read from stdin.- Throws:
IOException
- An I/O error has occurred.
-
LDIF
Constructs anLDIF
object to parse the LDIF data read from a specified file.- Parameters:
file
- the name of the LDIF file to parse- Throws:
IOException
- An I/O error has occurred.
-
LDIF
Constructs anLDIF
object to parse the LDIF data read from an input stream.- Parameters:
ds
- The input stream providing the LDIF data- Throws:
IOException
- An I/O error has occurred.
-
-
Method Details
-
nextRecord
Returns the next record in the LDIF data. You can call this method repeatedly to iterate through all records in the LDIF data.- Returns:
- the next record as an
LDIFRecord
object or null if there are no more records. - Throws:
IOException
- An I/O error has occurred.- See Also:
-
parse_ldif_record
Parses ldif content. The list of attributes is terminated by \r\n or '-'. This function is also used to parse the attributes in modifications.- Parameters:
ds
- data input stream- Throws:
IOException
-
parse_ldif_content
Parses ldif content. The list of attributes is terminated by \r\n or '-'. This function is also used to parse the attributes in modifications.- Parameters:
ds
- data input stream- Throws:
IOException
-
getDecodedBytes
-
getFileContent
- Throws:
IOException
-
parse_add_spec
Parses add content- Parameters:
ds
- data input stream- Throws:
IOException
-
parse_delete_spec
Parses delete content- Parameters:
ds
- data input stream- Throws:
IOException
-
parse_mod_spec
Parses change modification.- Parameters:
ds
- data input stream- Throws:
IOException
-
parse_moddn_spec
Parses moddn/modrdn modification.- Parameters:
d
- data input stream- Throws:
IOException
-
parse_control_spec
Parses the specification of a control
A control looks line one of the following:
control: 1.2.3.4.10.210
control: 1.2.3.4.10.210 true
control: 1.2.3.4.10.210 true: someASCIIvalue
control: 1.2.3.4.10.210: someASCIIvalue
control: 1.2.3.4.10.210 true:: 44GK44GM44GV44KP44KJ
control: 1.2.3.4.10.210:: 44GK44GM44GV44KP44KJ
control: 1.2.3.4.10.210 true:< file:///usr/local/directory/cont.dta
control: 1.2.3.4.10.210:< file:///usr/local/directory/cont.dta- Parameters:
line
- a line containing a control spec- Returns:
- a parsed control.
- Throws:
IOException
- if the line could not be parsed
-
isPrintable
public static boolean isPrintable(byte[] b) Returns true if all the bytes in the given array are valid for output as a String according to the LDIF specification. If not, the array should output base64-encoded.- Returns:
true
if all the bytes in the given array are valid for output as a String according to the LDIF specification; otherwise,false
.
-
breakString
Outputs the String in LDIF line-continuation format. No line will be longer than the given max. A continuation line starts with a single blank space.- Parameters:
pw
- the printer writervalue
- the given string being printed outmax
- the maximum characters allowed in the line
-
getVersion
public int getVersion()Gets the version of LDIF used in the data.- Returns:
- version of LDIF used in the data.
-
toString
Gets the string representation of the entire LDIF file. -
throwLDIFException
Throws a LDIF file exception including the current line number.- Parameters:
msg
- Error message- Throws:
IOException
-
toPrintableString
Converts a byte array to a printable string following the LDIF rules (encode in base64 if necessary)- Parameters:
b
- the byte array to convert- Returns:
- a converted string which is printable.
-
main
Test driver - just reads and parses an LDIF file, printing each record as interpreted- Parameters:
args
- name of the LDIF file to parse
-