directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r495174 - in /directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2: ./ reponse/ request/
Date Thu, 11 Jan 2007 10:14:59 GMT
Author: pamarcelot
Date: Thu Jan 11 02:14:56 2007
New Revision: 495174

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

Modified:
    directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/ParserUtils.java
    directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java
    directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java
    directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java
    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/ParserUtils.java
URL: http://svn.apache.org/viewvc/directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/ParserUtils.java?view=diff&rev=495174&r1=495173&r2=495174
==============================================================================
--- directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/ParserUtils.java
(original)
+++ directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/ParserUtils.java
Thu Jan 11 02:14:56 2007
@@ -1,8 +1,14 @@
 package org.apache.directory.ldapstudio.dsmlv2;
 
 
+import java.util.List;
+
+import org.apache.directory.shared.ldap.codec.Control;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.util.Base64;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -18,6 +24,8 @@
     public static final String XML_SCHEMA_URI = "http://www.w3c.org/2001/XMLSchema";
     public static final String XML_SCHEMA_INSTANCE_URI = "http://www.w3c.org/2001/XMLSchema-instance";
     public static final String BASE64BINARY = "base64Binary";
+    public static final String XSI = "xsi";
+    public static final String XSD = "xsd";
 
 
     /**
@@ -143,6 +151,59 @@
         catch ( NumberFormatException e )
         {
             throw new XmlPullParserException( "the given requestID is not an integer", xpp,
null );
+        }
+    }
+
+
+    /**
+     * Adds Controls to the given Element.
+     *
+     * @param element
+     *      the element to add the Controls to
+     * @param controls
+     *      a List of Controls
+     */
+    public static void addControls( Element element, List<Control> controls )
+    {
+        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( ParserUtils.XSD, ParserUtils.XML_SCHEMA_URI
);
+                        Namespace xsiNamespace = new Namespace( ParserUtils.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 ), ParserUtils.XSD
+ ":"
+                            + ParserUtils.BASE64BINARY );
+                    }
+                    else
+                    {
+                        controlElement.addElement( "controlValue" ).setText( ( String ) value
);
+                    }
+                }
+            }
         }
     }
 }

Modified: directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java
URL: http://svn.apache.org/viewvc/directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java?view=diff&rev=495174&r1=495173&r2=495174
==============================================================================
--- directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java
(original)
+++ directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java
Thu Jan 11 02:14:56 2007
@@ -83,13 +83,13 @@
         {
             if ( ParserUtils.needsBase64Encoding( response ) )
             {
-                Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI
);
-                Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI
);
+                Namespace xsdNamespace = new Namespace( ParserUtils.XSD, ParserUtils.XML_SCHEMA_URI
);
+                Namespace xsiNamespace = new Namespace( ParserUtils.XSI, ParserUtils.XML_SCHEMA_INSTANCE_URI
);
                 element.getDocument().getRootElement().add( xsdNamespace );
                 element.getDocument().getRootElement().add( xsiNamespace );
                 
                 Element responseElement = element.addElement( "response").addText( ParserUtils.base64Encode(
response ) );
-                responseElement.addAttribute( new QName("type", xsiNamespace), "xsd:" + ParserUtils.BASE64BINARY
);
+                responseElement.addAttribute( new QName("type", xsiNamespace), ParserUtils.XSD
+ ":" + ParserUtils.BASE64BINARY );
             }
             else
             {

Modified: directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java
URL: http://svn.apache.org/viewvc/directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java?view=diff&rev=495174&r1=495173&r2=495174
==============================================================================
--- directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java
(original)
+++ directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java
Thu Jan 11 02:14:56 2007
@@ -24,6 +24,7 @@
 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.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapResult;
 import org.apache.directory.shared.ldap.codec.util.LdapURL;
@@ -65,14 +66,14 @@
      */
     public Element toDsml( Element root )
     {
-
+        
         // RequestID
         int requestID = message.getMessageId();
         if ( requestID != 0 )
         {
             root.addAttribute( "requestID", "" + requestID );
         }
-
+        
         // Matched DN
         String matchedDN = result.getMatchedDN();
         if ( !matchedDN.equals( "" ) )
@@ -80,7 +81,8 @@
             root.addAttribute( "matchedDN", matchedDN );
         }
 
-        // TODO Add Control values
+        // Controls
+        ParserUtils.addControls( root, message.getControls() );
 
         // ResultCode
         Element resultCodeElement = root.addElement( "resultCode" );

Modified: directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java
URL: http://svn.apache.org/viewvc/directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java?view=diff&rev=495174&r1=495173&r2=495174
==============================================================================
--- directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java
(original)
+++ directory/trunks/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java
Thu Jan 11 02:14:56 2007
@@ -95,15 +95,15 @@
 
                     if ( ParserUtils.needsBase64Encoding( value ) )
                     {
-                        Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI
);
-                        Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI
);
+                        Namespace xsdNamespace = new Namespace( ParserUtils.XSD, ParserUtils.XML_SCHEMA_URI
);
+                        Namespace xsiNamespace = new Namespace( ParserUtils.XSI, ParserUtils.XML_SCHEMA_INSTANCE_URI
);
                         attributeElement.getDocument().getRootElement().add( xsdNamespace
);
                         attributeElement.getDocument().getRootElement().add( xsiNamespace
);
 
                         Element valueElement = attributeElement.addElement( "value" ).addText(
                             ParserUtils.base64Encode( value ) );
                         valueElement
-                            .addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY
);
+                            .addAttribute( new QName( "type", xsiNamespace ), ParserUtils.XSD
+ ":" + ParserUtils.BASE64BINARY );
                     }
                     else
                     {
@@ -113,8 +113,6 @@
             }
             catch ( NamingException e )
             {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
             }
         }
 

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=495174&r1=495173&r2=495174
==============================================================================
--- 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 02:14:56 2007
@@ -1,16 +1,11 @@
 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
@@ -24,7 +19,6 @@
     public AbstractRequestDsml( LdapMessage ldapMessage )
     {
         super( ldapMessage );
-        // TODO Auto-generated constructor stub
     }
 
 
@@ -48,48 +42,7 @@
         }
 
         // 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
);
-                    }
-                }
-            }
-        }
+        ParserUtils.addControls( element, instance.getControls() );
         
         return element;
     }



Mime
View raw message