directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r495167 - /directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/request/AbstractRequestDsml.java
Date Thu, 11 Jan 2007 09:36:15 GMT
Author: pamarcelot
Date: Thu Jan 11 01:36:14 2007
New Revision: 495167

URL: http://svn.apache.org/viewvc?view=rev&rev=495167
Log:
Adding Control handling for SharedLDAP => XML DSMLv2  Request Decorators.

Modified:
    directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/request/AbstractRequestDsml.java

Modified: directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/request/AbstractRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/request/AbstractRequestDsml.java?view=diff&rev=495167&r1=495166&r2=495167
==============================================================================
--- directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/request/AbstractRequestDsml.java
(original)
+++ directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/request/AbstractRequestDsml.java
Thu Jan 11 01:36:14 2007
@@ -1,10 +1,16 @@
 package org.apache.directory.ldapstudio.dsmlv2.request;
 
 
+import java.util.List;
+
 import org.apache.directory.ldapstudio.dsmlv2.DsmlDecorator;
+import org.apache.directory.ldapstudio.dsmlv2.ParserUtils;
+import org.apache.directory.shared.ldap.codec.Control;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
 
 
 public abstract class AbstractRequestDsml extends LdapRequestDecorator implements DsmlDecorator
@@ -41,8 +47,49 @@
             element.addAttribute( "requestID", "" + requestID );
         }
 
-        // Control(s)
-        // TODO Handle Control(s)
+        // Controls
+        List<Control> controls = instance.getControls();
+        
+        if ( controls != null )
+        {
+            for ( int i = 0; i < controls.size(); i++ )
+            {
+                Control control = controls.get( i );
+                
+                Element controlElement = element.addElement( "control" );
+                
+                if ( control.getControlType() != null )
+                {
+                    controlElement.addAttribute( "type", control.getControlType() );
+                }
+                
+                if ( control.getCriticality() )
+                {
+                    controlElement.addAttribute( "criticality", "true" );
+                }
+                
+                Object value = control.getControlValue();
+                if ( value != null )
+                {
+                    if ( ParserUtils.needsBase64Encoding( value ) )
+                    {
+                        Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI
);
+                        Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI
);
+                        element.getDocument().getRootElement().add( xsdNamespace );
+                        element.getDocument().getRootElement().add( xsiNamespace );
+    
+                        Element valueElement = 
+                            controlElement.addElement( "controlValue" ).addText(  ParserUtils.base64Encode(
value ) );
+                        valueElement
+                            .addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY
);
+                    }
+                    else
+                    {
+                        controlElement.addElement( "controlValue" ).setText( (String)  value
);
+                    }
+                }
+            }
+        }
         
         return element;
     }



Mime
View raw message