1 20 package org.apache.directory.ldapstudio.dsmlv2.request; 21 22 23 import javax.naming.NamingEnumeration ; 24 import javax.naming.NamingException ; 25 import javax.naming.directory.Attribute ; 26 import javax.naming.directory.Attributes ; 27 28 import org.apache.directory.ldapstudio.dsmlv2.ParserUtils; 29 import org.apache.directory.shared.ldap.codec.LdapMessage; 30 import org.apache.directory.shared.ldap.codec.add.AddRequest; 31 import org.dom4j.Element; 32 import org.dom4j.Namespace; 33 import org.dom4j.QName; 34 35 36 42 public class AddRequestDsml extends AbstractRequestDsml 43 { 44 50 public AddRequestDsml( LdapMessage ldapMessage ) 51 { 52 super( ldapMessage ); 53 } 54 55 56 59 public int getMessageType() 60 { 61 return instance.getMessageType(); 62 } 63 64 65 68 public Element toDsml( Element root ) 69 { 70 Element element = super.toDsml( root ); 71 72 AddRequest request = ( AddRequest ) instance; 73 74 if ( request.getEntry() != null ) 76 { 77 element.addAttribute( "dn", request.getEntry().toString() ); 78 } 79 80 Attributes attributes = request.getAttributes(); 82 if ( attributes != null ) 83 { 84 NamingEnumeration ne = attributes.getAll(); 85 while ( ne.hasMoreElements() ) 86 { 87 Attribute attribute = ( Attribute ) ne.nextElement(); 88 Element attributeElement = element.addElement( "attr" ); 89 attributeElement.addAttribute( "name", attribute.getID() ); 90 91 try 93 { 94 NamingEnumeration ne2 = attribute.getAll(); 95 96 while ( ne2.hasMoreElements() ) 97 { 98 Object value = ne2.nextElement(); 99 100 if ( ParserUtils.needsBase64Encoding( value ) ) 101 { 102 Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI ); 103 Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI ); 104 attributeElement.getDocument().getRootElement().add( xsdNamespace ); 105 attributeElement.getDocument().getRootElement().add( xsiNamespace ); 106 107 Element valueElement = attributeElement.addElement( "value" ).addText( 108 ParserUtils.base64Encode( value ) ); 109 valueElement 110 .addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY ); 111 } 112 else 113 { 114 attributeElement.addElement( "value" ).addText( value.toString() ); 115 } 116 } 117 } 118 catch ( NamingException e ) 119 { 120 } 121 } 122 } 123 124 return element; 125 } 126 } 127 | Popular Tags |