All LDAP Classes
Internal LDAP Classes

com.novell.ldap.util
Class DSMLWriter

java.lang.Object
  extended by com.novell.ldap.util.DSMLWriter
All Implemented Interfaces:
LDAPWriter

public class DSMLWriter
extends java.lang.Object
implements LDAPWriter

Writes LDAPMessages into a Writer or outputStream as DSML batch requests and batch responses.

See Also:
DSMLReader, DOMWriter, LDAPMessage

Field Summary
private static java.lang.String BATCH_REQUEST_START
           
private static java.lang.String BATCH_RESPONSE_START
           
private static boolean fswitch
           
private  boolean indent
           
private static int NEW_BATCH
           
private  java.io.Writer out
           
private static int REQUEST_BATCH
           
private static int RESPONSE_BATCH
           
private  boolean resumeOnError
           
private static int SEARCH_TAG
           
private  int state
           
private  java.lang.String tabString
           
private  boolean useSOAP
           
private  java.lang.String version
           
 
Constructor Summary
DSMLWriter(java.io.OutputStream stream)
          Initializes this writer with the specified outputstream to write DSML into.
DSMLWriter(java.lang.String file)
          Initializes this writer by opening the specified file to write DSML into.
DSMLWriter(java.io.Writer writer)
          Initializes this writer with the specified writer to write DSML into.
 
Method Summary
private static java.lang.String byteString(byte[] value)
          Convert a UTF8 encoded string, or binary data, into a String encoded for a string filter.
private  void checkState(boolean isResponse)
          Tests the current state with a new message that is either a response or request.
 void finish()
          Writes closing tags for searchResponse, batchRequests, and batchResponse depending on the current state.
 java.lang.String getVersion()
          Gets the version of the LDIF data associated with the input stream
 boolean isRequest()
          Returns true if request data ist associated with the input stream, or false if content data.
 boolean isUseSOAP()
           
private  boolean isXMLSafe(byte[] val)
           
private  java.lang.String makeAttributeSafe(java.lang.String attrib)
           
private  java.lang.String makeXMLSafe(java.lang.String msg)
           
private  void newLine(int indentTabs)
          Writes a new line and then the specified number of indentTabs to indent the next characters to be written.
 void setIndent(int spaces)
          Sets the number of spaces for indentation of XML tags.
 void setResumeOnError(boolean resumeOnError)
           
 void setUseSOAP(boolean useSOAP)
           
 void useIndent(boolean useIndent)
          Turns on or off 'pretty-printing' of XML with newlines and indentation to make output more readable.
private  void writeAddRequest(LDAPAddRequest request)
          Writes the Add request requested within a LDAP Add request
private  void writeAddRequestEntry(LDAPAddRequest request, LDAPControl[] controls, java.lang.String requestID)
           
private  void writeAttribute(LDAPAttribute attr)
          Used to write an attribute and its values.
 void writeComments(java.lang.String lines)
          Writes the specified strings as XML comments.
private  void writeCompareRequest(LDAPCompareRequest request)
          Writes the Compare request requested within a LDAP Compare request
private  void writeCompareRequestEntry(LDAPCompareRequest request, LDAPControl[] controls, java.lang.String requestID)
           
private  void writeControls(LDAPControl[] controls, int indent)
          Writes a control in DSML.
private  void writeDeleteRequest(LDAPDeleteRequest request)
          Writes the Delete request requested within a LDAP Delete request
private  void writeDeleteRequestEntry(LDAPDeleteRequest request, LDAPControl[] controls, java.lang.String requestID)
           
 void writeEntry(LDAPEntry entry)
          Write an LDAP entry into LDIF file as LDAPContent data.
 void writeEntry(LDAPEntry entry, LDAPControl[] controls)
          Write an LDAP entry into LDIF file as LDAPContent data.
 void writeEntry(LDAPEntry entry, LDAPControl[] controls, java.lang.String requestID)
          Write an LDAP entry into LDIF file as LDAPContent data.
 void writeError(java.lang.Exception e)
          Any Exception can be written in DSML with this method, via the tag.
private  void writeExtendedRequest(LDAPExtendedRequest request)
          Writes the Extended request requested within a LDAP Extended request
private  void writeExtendedRequestEntry(LDAPExtendedRequest request, LDAPControl[] controls, java.lang.String requestID)
           
private  void writeFilter(java.util.Iterator itr)
           
 void writeMessage(LDAPMessage messageToWrite)
          Writes an LDAPMessage as DSML.
private  void writeModifyDNRequest(LDAPModifyDNRequest request)
          Writes the Modify request requested within a LDAP Modify request
private  void writeModifyDNRequestEntry(LDAPModifyDNRequest request, LDAPControl[] controls, java.lang.String requestID)
           
private  void writeModifyRequest(LDAPModifyRequest request)
          Writes the Modify request requested within a LDAP Modify request
private  void writeModifyRequestEntry(LDAPModifyRequest request, LDAPControl[] controls, java.lang.String requestID)
           
private  void writeResult(LDAPResponse result, int indent)
          Writes all information associated with a result such as controls, referrals, result code with description, and any server message.
private  void writeSearchRequest(LDAPSearchRequest request)
          Writes the Search request requested within a LDAP search request
private  void writeSearchRequestEntry(LDAPSearchRequest request, LDAPControl[] controls, java.lang.String requestID)
           
private  void writeSearchResponse(LDAPSearchResult result)
          Writes the entries returned within search responses.
private  void writeSearchResultReference(LDAPSearchResultReference ref)
          Writes referrences that are returned from a search.
private  void writeTagWithID(java.lang.String tag, LDAPMessage message)
          Writes an XML tag with it's requestID and possibly a matchedDN.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fswitch

private static boolean fswitch

out

private java.io.Writer out

state

private int state

NEW_BATCH

private static final int NEW_BATCH
See Also:
Constant Field Values

REQUEST_BATCH

private static final int REQUEST_BATCH
See Also:
Constant Field Values

RESPONSE_BATCH

private static final int RESPONSE_BATCH
See Also:
Constant Field Values

SEARCH_TAG

private static final int SEARCH_TAG
See Also:
Constant Field Values

indent

private boolean indent

tabString

private java.lang.String tabString

version

private java.lang.String version

useSOAP

private boolean useSOAP

resumeOnError

private boolean resumeOnError

BATCH_REQUEST_START

private static final java.lang.String BATCH_REQUEST_START
See Also:
Constant Field Values

BATCH_RESPONSE_START

private static final java.lang.String BATCH_RESPONSE_START
See Also:
Constant Field Values
Constructor Detail

DSMLWriter

public DSMLWriter(java.lang.String file)
           throws java.io.FileNotFoundException
Initializes this writer by opening the specified file to write DSML into.

Parameters:
file - File to write DSML
Throws:
java.io.FileNotFoundException - occurs when the specified file could not be opened or is not found.

DSMLWriter

public DSMLWriter(java.io.OutputStream stream)
Initializes this writer with the specified outputstream to write DSML into. Note that the output characters will be UTF-8 encoded.

Parameters:
stream - Output stream to write DSML

DSMLWriter

public DSMLWriter(java.io.Writer writer)
Initializes this writer with the specified writer to write DSML into.

Parameters:
writer - Writer to write DSML
Method Detail

setResumeOnError

public void setResumeOnError(boolean resumeOnError)

writeError

public void writeError(java.lang.Exception e)
                throws java.io.IOException
Any Exception can be written in DSML with this method, via the tag. In general LDAPExceptions should be written to the errorResponse tag and other exception in a SOAP Fault.

Specified by:
writeError in interface LDAPWriter
Parameters:
e - LDAPException to be written in DSML.
Throws:
java.io.IOException

finish

public void finish()
            throws java.io.IOException
Writes closing tags for searchResponse, batchRequests, and batchResponse depending on the current state.

Specified by:
finish in interface LDAPWriter
Throws:
java.io.IOException

writeComments

public void writeComments(java.lang.String lines)
                   throws java.io.IOException
Writes the specified strings as XML comments.

Specified by:
writeComments in interface LDAPWriter
Parameters:
lines - Comments to be written
Throws:
java.io.IOException

writeMessage

public void writeMessage(LDAPMessage messageToWrite)
                  throws java.io.IOException,
                         LDAPLocalException
Writes an LDAPMessage as DSML.

Specified by:
writeMessage in interface LDAPWriter
Parameters:
messageToWrite - Message to be written as DSML
Throws:
LDAPLocalException - Occurs when a message is written out of sequence, i.e. a response is written into a batchRequest.
java.io.IOException - if an I/O error occurs.

writeEntry

public void writeEntry(LDAPEntry entry)
                throws java.io.IOException,
                       LDAPLocalException
Write an LDAP entry into LDIF file as LDAPContent data. An LDAPEntry is written as a SearchResultEntry record.

You are not allowed to mix request data and content data

Specified by:
writeEntry in interface LDAPWriter
Parameters:
entry - LDAPEntry object
Throws:
java.io.IOException - if an I/O error occurs.
LDAPLocalException
See Also:
LDAPEntry

writeEntry

public void writeEntry(LDAPEntry entry,
                       LDAPControl[] controls)
                throws java.io.IOException,
                       LDAPLocalException
Write an LDAP entry into LDIF file as LDAPContent data. An LDAPEntry is written as a SearchResultEntry record.

You are not allowed to mix request data and content data

Specified by:
writeEntry in interface LDAPWriter
Parameters:
entry - LDAPEntry object
controls - Controls that were returned with this entry
Throws:
java.io.IOException - if an I/O error occurs.
LDAPLocalException
See Also:
LDAPEntry

writeEntry

public void writeEntry(LDAPEntry entry,
                       LDAPControl[] controls,
                       java.lang.String requestID)
                throws java.io.IOException,
                       LDAPLocalException
Write an LDAP entry into LDIF file as LDAPContent data. An LDAPEntry is written as a SearchResultEntry record.

You are not allowed to mix request data and content data

Parameters:
entry - LDAPEntry object
controls - Controls that were returned with this entry
requestID - the String that associates this response with the request
Throws:
java.io.IOException - if an I/O error occurs.
LDAPLocalException
See Also:
LDAPEntry

byteString

private static java.lang.String byteString(byte[] value)
Convert a UTF8 encoded string, or binary data, into a String encoded for a string filter.


writeFilter

private void writeFilter(java.util.Iterator itr)
                  throws java.io.IOException,
                         LDAPLocalException
Throws:
java.io.IOException
LDAPLocalException

writeModifyDNRequestEntry

private void writeModifyDNRequestEntry(LDAPModifyDNRequest request,
                                       LDAPControl[] controls,
                                       java.lang.String requestID)
                                throws java.io.IOException,
                                       LDAPLocalException
Throws:
java.io.IOException
LDAPLocalException

writeModifyRequestEntry

private void writeModifyRequestEntry(LDAPModifyRequest request,
                                     LDAPControl[] controls,
                                     java.lang.String requestID)
                              throws java.io.IOException,
                                     LDAPLocalException
Throws:
java.io.IOException
LDAPLocalException

writeDeleteRequestEntry

private void writeDeleteRequestEntry(LDAPDeleteRequest request,
                                     LDAPControl[] controls,
                                     java.lang.String requestID)
                              throws java.io.IOException,
                                     LDAPLocalException
Throws:
java.io.IOException
LDAPLocalException

writeExtendedRequestEntry

private void writeExtendedRequestEntry(LDAPExtendedRequest request,
                                       LDAPControl[] controls,
                                       java.lang.String requestID)
                                throws java.io.IOException,
                                       LDAPLocalException
Throws:
java.io.IOException
LDAPLocalException

writeCompareRequestEntry

private void writeCompareRequestEntry(LDAPCompareRequest request,
                                      LDAPControl[] controls,
                                      java.lang.String requestID)
                               throws java.io.IOException,
                                      LDAPLocalException
Throws:
java.io.IOException
LDAPLocalException

writeAddRequestEntry

private void writeAddRequestEntry(LDAPAddRequest request,
                                  LDAPControl[] controls,
                                  java.lang.String requestID)
                           throws java.io.IOException,
                                  LDAPLocalException
Throws:
java.io.IOException
LDAPLocalException

writeSearchRequestEntry

private void writeSearchRequestEntry(LDAPSearchRequest request,
                                     LDAPControl[] controls,
                                     java.lang.String requestID)
                              throws java.io.IOException,
                                     LDAPLocalException
Throws:
java.io.IOException
LDAPLocalException

writeTagWithID

private void writeTagWithID(java.lang.String tag,
                            LDAPMessage message)
                     throws java.io.IOException
Writes an XML tag with it's requestID and possibly a matchedDN.

Parameters:
tag - XML tag name to be written
message - LDAPMessage containing a requestID and possibly matchedDN values to be written with the tag
Throws:
java.io.IOException

getVersion

public java.lang.String getVersion()
Gets the version of the LDIF data associated with the input stream

Specified by:
getVersion in interface LDAPWriter
Returns:
the version number

isRequest

public boolean isRequest()
Returns true if request data ist associated with the input stream, or false if content data.

Specified by:
isRequest in interface LDAPWriter
Returns:
true if input stream contains request data.

writeResult

private void writeResult(LDAPResponse result,
                         int indent)
                  throws java.io.IOException
Writes all information associated with a result such as controls, referrals, result code with description, and any server message.

Parameters:
result - result to be written
indent - number of indentation this result should use for writing
Throws:
java.io.IOException

writeControls

private void writeControls(LDAPControl[] controls,
                           int indent)
                    throws java.io.IOException
Writes a control in DSML.

Used by writeResult and by the searchResponse case in writeMessage.

Parameters:
controls - Controls to be written
indent - Size of indentation for writting.
Throws:
java.io.IOException

writeSearchResultReference

private void writeSearchResultReference(LDAPSearchResultReference ref)
                                 throws java.io.IOException
Writes referrences that are returned from a search.

Parameters:
ref - search reference
Throws:
java.io.IOException

writeSearchResponse

private void writeSearchResponse(LDAPSearchResult result)
                          throws java.io.IOException,
                                 LDAPLocalException
Writes the entries returned within search responses.

Parameters:
result - a search result entry
Throws:
java.io.IOException
LDAPLocalException

writeSearchRequest

private void writeSearchRequest(LDAPSearchRequest request)
                         throws java.io.IOException,
                                LDAPLocalException
Writes the Search request requested within a LDAP search request

Parameters:
request - a search request entry
Throws:
java.io.IOException
LDAPLocalException

writeAddRequest

private void writeAddRequest(LDAPAddRequest request)
                      throws java.io.IOException,
                             LDAPLocalException
Writes the Add request requested within a LDAP Add request

Parameters:
request - a search request entry
Throws:
java.io.IOException
LDAPLocalException

writeCompareRequest

private void writeCompareRequest(LDAPCompareRequest request)
                          throws java.io.IOException,
                                 LDAPLocalException
Writes the Compare request requested within a LDAP Compare request

Parameters:
request - a search request entry
Throws:
java.io.IOException
LDAPLocalException

writeModifyRequest

private void writeModifyRequest(LDAPModifyRequest request)
                         throws java.io.IOException,
                                LDAPLocalException
Writes the Modify request requested within a LDAP Modify request

Parameters:
request - a search request entry
Throws:
java.io.IOException
LDAPLocalException

writeModifyDNRequest

private void writeModifyDNRequest(LDAPModifyDNRequest request)
                           throws java.io.IOException,
                                  LDAPLocalException
Writes the Modify request requested within a LDAP Modify request

Parameters:
request - a search request entry
Throws:
java.io.IOException
LDAPLocalException

writeDeleteRequest

private void writeDeleteRequest(LDAPDeleteRequest request)
                         throws java.io.IOException,
                                LDAPLocalException
Writes the Delete request requested within a LDAP Delete request

Parameters:
request - a search request entry
Throws:
java.io.IOException
LDAPLocalException

writeExtendedRequest

private void writeExtendedRequest(LDAPExtendedRequest request)
                           throws java.io.IOException,
                                  LDAPLocalException
Writes the Extended request requested within a LDAP Extended request

Parameters:
request - a Extended request entry
Throws:
java.io.IOException
LDAPLocalException

writeAttribute

private void writeAttribute(LDAPAttribute attr)
                     throws java.io.IOException
Used to write an attribute and its values.

Parameters:
attr - Attribute to be written.
Throws:
java.io.IOException

checkState

private void checkState(boolean isResponse)
                 throws java.io.IOException,
                        LDAPLocalException
Tests the current state with a new message that is either a response or request. If the state is NEW_BATCH, check_state will print an appropriate batch tag.

Parameters:
isResponse - Indicates if the message to be written is a response or not.
Throws:
java.io.IOException
LDAPLocalException

newLine

private void newLine(int indentTabs)
              throws java.io.IOException
Writes a new line and then the specified number of indentTabs to indent the next characters to be written.

Allows the writer to 'pretty-print' XML output according to the number of tabs. The size of a tab is determined by tabString which is created by the method setIndent. No pretty-printing will occur if indent is set to false.

Parameters:
indentTabs - number of tabs to indent.
Throws:
java.io.IOException

useIndent

public void useIndent(boolean useIndent)
Turns on or off 'pretty-printing' of XML with newlines and indentation to make output more readable.

For efficiency, useIndent is set to false by default. The size of an indentation can be set using the method setIndent.

Parameters:
useIndent - Indicates whether indentation and newlines should be written to make the output DSML more readable.
See Also:
setIndent(int)

setIndent

public void setIndent(int spaces)
Sets the number of spaces for indentation of XML tags.

This setting is ignored by default unless indentation is turned on via the useIndent method.

Parameters:
spaces - Number of spaces used in each indentation.
See Also:
useIndent(boolean)

isXMLSafe

private boolean isXMLSafe(byte[] val)

makeXMLSafe

private java.lang.String makeXMLSafe(java.lang.String msg)

makeAttributeSafe

private java.lang.String makeAttributeSafe(java.lang.String attrib)

isUseSOAP

public boolean isUseSOAP()
Returns:
Returns the useSOAP.

setUseSOAP

public void setUseSOAP(boolean useSOAP)
Parameters:
useSOAP - The useSOAP to set.

All LDAP Classes
Internal LDAP Classes

Copyright ? 2002 Novell, Inc. All Rights Reserved.
Novell, Inc.
1800 South Novell Place
Provo, Ut 84606
Phone: (801) 861-5000