/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2010 Sun Microsystems, Inc.
*/
/**
* 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
* TARGET="_blank">The LDAP Data Interchange Format (LDIF) -
* Technical Specification</A>.
* <P>
*
* 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 <CODE>LDIFRecord</CODE> objects.
* <P>
*
* @version 1.0
* @see netscape.ldap.util.LDIFRecord
*/
/**
* Internal constants
*/
/**
* Constructs an <CODE>LDIF</CODE> object to parse the
* LDAP data read from stdin.
* @exception IOException An I/O error has occurred.
*/
m_reader = new LineReader(d);
m_source = "System.in";
m_decoder = new MimeBase64Decoder();
}
/**
* Constructs an <CODE>LDIF</CODE> object to parse the
* LDIF data read from a specified file.
* @param file the name of the LDIF file to parse
* @exception IOException An I/O error has occurred.
*/
m_reader = new LineReader(d);
m_decoder = new MimeBase64Decoder();
}
/**
* Constructs an <CODE>LDIF</CODE> object to parse the
* LDIF data read from an input stream.
* @param dstThe input stream providing the LDIF data
* @exception IOException An I/O error has occurred.
*/
m_reader = new LineReader(d);
m_decoder = new MimeBase64Decoder();
}
/**
* Returns the next record in the LDIF data. You can call this
* method repeatedly to iterate through all records in the LDIF data.
* <P>
*
* @return the next record as an <CODE>LDIFRecord</CODE>
* object or null if there are no more records.
* @exception IOException An I/O error has occurred.
* @see netscape.ldap.util.LDIFRecord
*/
if ( m_done )
return null;
else
return parse_ldif_record( m_reader );
}
/**
* Parses ldif content. The list of attributes is
* terminated by \r\n or '-'. This function is
* also used to parse the attributes in modifications.
* @param ds data input stream
*/
throws IOException {
// Skip past any blank lines
}
return null;
}
if ( m_version != 1 ) {
}
// Do the next record
// Skip the newline
}
return null;
}
}
throwLDIFException("expecting dn:");
}
return rec;
}
/**
* Parses ldif content. The list of attributes is
* terminated by \r\n or '-'. This function is
* also used to parse the attributes in modifications.
* @param ds data input stream
*/
throws IOException {
// if this is empty line, then we're finished reading all
// the info for the current entry
m_currEntryDone = true;
}
return null;
}
/* handles (changerecord) */
lc = parse_mod_spec(d);
lc = parse_add_spec(d);
lc = parse_delete_spec(d);
lc = parse_moddn_spec(d);
} else {
throwLDIFException("change type not supported");
}
return lc;
}
/* handles 1*(attrval-spec) */
/* Read lines until we're past the record */
while( true ) {
if ( controlVector == null ) {
controlVector = new Vector();
}
} else {
/* An attribute */
if ( len < 1 ) {
break;
}
/* Must have a colon */
if (idx == -1)
throwLDIFException("no ':' found");
/* attribute type */
val = "";
/* Could be :: for binary */
idx++;
idx++;
try {
} catch (MalformedURLException ex) {
ex +
": cannot construct url "+
}
} else {
}
}
/* Is there a previous value for this attribute? */
}
} else {
}
}
m_currEntryDone = true;
}
break;
}
}
// Copy over the attributes to the record
while( en.hasMoreElements() ) {
}
if( controlVector != null ) {
LDAPControl[] controls =
}
return ac;
}
/* Translate from base 64 */
return decodedBuf.toBytes();
}
if (num == 2) {
}
return b;
}
/**
* Parses add content
* @param ds data input stream
*/
throws IOException {
if (m_currEntryDone)
m_currEntryDone = false;
}
return rc;
}
/**
* Parses delete content
* @param ds data input stream
*/
throws IOException {
if ( controlVector == null ) {
controlVector = new Vector();
}
} else {
throwLDIFException("invalid SEP" );
}
}
if( controlVector != null ) {
}
return dc;
}
/**
* Parses change modification.
* @param ds data input stream
*/
throws IOException {
do {
int oper = -1;
} else
throwLDIFException("unknown modify type");
}
if ( controlVector == null ) {
controlVector = new Vector();
}
}
}
// if there is no attrval-spec, go into the else statement
} else {
if (index == -1)
}
if (m_currEntryDone) {
m_currEntryDone = false;
break;
}
if( controlVector != null ) {
}
return mc;
}
/**
* @param d data input stream
*/
throws IOException {
do {
mc.setDeleteOldRDN(false);
mc.setDeleteOldRDN(true);
else
throwLDIFException("Incorrect input for deleteOldRdn ");
if ( controlVector == null ) {
controlVector = new Vector();
}
}
if( controlVector != null ) {
}
return mc;
}
/**
* Parses the specification of a control<BR>
*
* A control looks line one of the following:
*<BR>
* control: 1.2.3.4.10.210
*<BR>
* control: 1.2.3.4.10.210 true
*<BR>
* control: 1.2.3.4.10.210 true: someASCIIvalue
*<BR>
* control: 1.2.3.4.10.210: someASCIIvalue
*<BR>
* control: 1.2.3.4.10.210 true:: 44GK44GM44GV44KP44KJ
*<BR>
* control: 1.2.3.4.10.210:: 44GK44GM44GV44KP44KJ
*<BR>
*<BR>
*
* @param line a line containing a control spec
* @return a parsed control.
* @exception IOException if the line could not be parsed
*/
throws IOException {
boolean criticality = true;
/* OID, must be present */
throwLDIFException("OID required for control");
}
if ( idx < 0 ) {
} else {
/* Optional criticality */
if (idx > 0) {
} else {
criticalVal = line;
}
criticality = true;
criticality = false;
} else {
"Criticality for control must be true" +
" or false, not " + criticalVal);
}
/* Optional value */
if ( idx > 0 ) {
/* Could be :: for binary */
idx++;
idx++;
try {
} catch (MalformedURLException ex) {
ex + ": cannot construct url "+
}
} else {
try {
} catch(Exception x) {
}
}
}
}
}
}
/**
* 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.
* @return <code>true</code> if all the bytes in the given array are valid for
* output as a String according to the LDIF specification; otherwise,
* <code>false</code>.
*/
public static boolean isPrintable(byte[] b) {
if ( (b[i] < ' ') || (b[i] > 127) ) {
if ( b[i] != '\t' )
return false;
}
}
return true;
}
/**
* 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.
* @param pw the printer writer
* @param value the given string being printed out
* @param max the maximum characters allowed in the line
*/
int written = 0;
/* Limit to 77 characters per line */
while( leftToGo > 0 ) {
if ( written != 0 ) {
} else {
maxChars -= 1;
}
/* Don't use pw.println, because it outputs an extra CR
in Win32 */
}
}
/**
* Gets the version of LDIF used in the data.
* @return version of LDIF used in the data.
*/
public int getVersion() {
return m_version;
}
/**
* Gets the string representation of the
* entire LDIF file.
* @return the string representation of the entire LDIF data file.
*/
}
/**
* Throws a LDIF file exception including the current line number.
* @param msg Error message
*/
throw new IOException ("line " +
}
/**
* Internal variables
*/
private boolean m_done = false;
private boolean m_currEntryDone = false;
private int m_currLineNum;
private int m_continuationLength;
/* Concatenate continuation lines, if present */
class LineReader {
_d = d;
}
/**
* Reads a non-comment line.
* @return a string or null.
*/
do {
/* Leftover line from last time? */
} else {
}
readCnt++;
/* Empty line means end of record */
else {
break;
}
/* Ignore comment lines */
/* Not a continuation line */
} else {
break;
}
} else {
/* Continuation line */
m_currLineNum += readCnt;
throwLDIFException("continuation out of nowhere");
}
}
} else {
/* End of file */
break;
}
} while ( true );
m_currLineNum += readCnt;
// read one line ahead
}
return result;
}
}
/**
* Converts a byte array to a printable string following
* the LDIF rules (encode in base64 if necessary)
*
* @param b the byte array to convert
* @return a converted string which is printable.
*/
String s = "";
if (isPrintable(b)) {
try {
s = new String(b, "UTF8");
}
} else {
// Translate to base 64
if ( nBytes > 0 ) {
}
}
return s;
}
/**
* Test driver - just reads and parses an LDIF file, printing
* each record as interpreted
*
* @param args name of the LDIF file to parse
*/
}
try {
} catch (Exception e) {
", " + e.toString());
}
try {
}
} catch ( IOException ex ) {
}
}
}