Package org.ldaptive.io
Class Dsmlv1Writer
- java.lang.Object
-
- org.ldaptive.io.Dsmlv1Writer
-
- All Implemented Interfaces:
SearchResultWriter
public class Dsmlv1Writer extends Object implements SearchResultWriter
Writes aSearchResult
as DSML version 1 to aWriter
.
-
-
Field Summary
Fields Modifier and Type Field Description private static DocumentBuilderFactory
DOC_BUILDER_FACTORY
Document builder factory.private Writer
dsmlWriter
Writer to write to.private Map<String,String>
outputProperties
Transformer output properties.private static TransformerFactory
TRANSFORMER_FACTORY
Transformer factory.
-
Constructor Summary
Constructors Constructor Description Dsmlv1Writer(Writer writer)
Creates a new dsml writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Element
createAttrElement(Document doc, LdapAttribute attr)
Returns a <dsml:attr/> element for the supplied ldap attribute.protected Document
createDsml(SearchResult result)
Creates DSML that corresponds to the supplied search result.protected List<Element>
createDsmlAttributes(Document doc, Collection<LdapAttribute> attrs)
Returns a list of <dsml:attr/> elements for the supplied attributes.protected Element
createObjectclassElement(Document doc, LdapAttribute attr)
Returns a <dsml:objectclass/> element for the supplied ldap attribute.Map<String,String>
getOutputProperties()
Returns the transformer output properties used by this writer.protected void
setAttrValue(Document doc, Element valueElement, String value, boolean isBase64)
Adds the supplied string to the value element.void
setOutputProperties(Map<String,String> properties)
Sets the transformer output properties used by this writer.void
write(SearchResult result)
Writes the supplied search result to the writer.
-
-
-
Field Detail
-
DOC_BUILDER_FACTORY
private static final DocumentBuilderFactory DOC_BUILDER_FACTORY
Document builder factory.
-
TRANSFORMER_FACTORY
private static final TransformerFactory TRANSFORMER_FACTORY
Transformer factory.
-
dsmlWriter
private final Writer dsmlWriter
Writer to write to.
-
outputProperties
private Map<String,String> outputProperties
Transformer output properties. SeeTransformer.setOutputProperty(String, String)
.
-
-
Constructor Detail
-
Dsmlv1Writer
public Dsmlv1Writer(Writer writer)
Creates a new dsml writer. The following transformer output properties are set by default:- "doctype-public", "yes"
- "indent", "yes"
- "{http://xml.apache.org/xslt}indent-amount", "2"
- Parameters:
writer
- to write DSML to
-
-
Method Detail
-
getOutputProperties
public Map<String,String> getOutputProperties()
Returns the transformer output properties used by this writer.- Returns:
- transformer output properties
-
setOutputProperties
public void setOutputProperties(Map<String,String> properties)
Sets the transformer output properties used by this writer.- Parameters:
properties
- transformer output properties
-
write
public void write(SearchResult result) throws IOException
Writes the supplied search result to the writer.- Specified by:
write
in interfaceSearchResultWriter
- Parameters:
result
- search result to write- Throws:
IOException
- if an error occurs using the writer
-
createDsml
protected Document createDsml(SearchResult result) throws ParserConfigurationException
Creates DSML that corresponds to the supplied search result.- Parameters:
result
- search result to parse- Returns:
- DSML
- Throws:
ParserConfigurationException
- if a document builder cannot be created
-
createDsmlAttributes
protected List<Element> createDsmlAttributes(Document doc, Collection<LdapAttribute> attrs)
Returns a list of <dsml:attr/> elements for the supplied attributes.- Parameters:
doc
- to source elements fromattrs
- to iterate over- Returns:
- list of elements contains attributes
-
createAttrElement
protected Element createAttrElement(Document doc, LdapAttribute attr)
Returns a <dsml:attr/> element for the supplied ldap attribute.- Parameters:
doc
- to source elements fromattr
- ldap attribute to add- Returns:
- element containing the attribute
-
createObjectclassElement
protected Element createObjectclassElement(Document doc, LdapAttribute attr)
Returns a <dsml:objectclass/> element for the supplied ldap attribute.- Parameters:
doc
- to source elements fromattr
- ldap attribute to add- Returns:
- element containing the attribute values
-
setAttrValue
protected void setAttrValue(Document doc, Element valueElement, String value, boolean isBase64)
Adds the supplied string to the value element.- Parameters:
doc
- to create nodes withvalueElement
- to append value tovalue
- to create node forisBase64
- whether the value is base64 encoded
-
-