directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r486074 - in /directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2: ./ reponse/
Date Tue, 12 Dec 2006 09:48:41 GMT
Author: pamarcelot
Date: Tue Dec 12 01:48:40 2006
New Revision: 486074

URL: http://svn.apache.org/viewvc?view=rev&rev=486074
Log:
Resolving DIRSTUDIO-15 (In a DSML Response, the DSML Writer should encode values in Base64
when needed).

Modified:
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/ParserUtils.java
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java

Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/ParserUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/ParserUtils.java?view=diff&rev=486074&r1=486073&r2=486074
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/ParserUtils.java
(original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/ParserUtils.java
Tue Dec 12 01:48:40 2006
@@ -1,12 +1,15 @@
 
 package org.apache.directory.ldapstudio.dsmlv2;
 
+import org.apache.directory.shared.ldap.ldif.LdifUtils;
+import org.apache.directory.shared.ldap.util.Base64;
 import org.xmlpull.v1.XmlPullParser;
 
 public class ParserUtils
 {
-    private static final String XML_SCHEMA_URI = "http://www.w3c.org/2001/XMLSchema";
-    private static final String XML_SCHEMA_INSTANCE_URI = "http://www.w3c.org/2001/XMLSchema-instance";
+    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";
 
     
     /**
@@ -49,6 +52,45 @@
         String [] splitedString = attrValue.split( ":" );
         return ( splitedString.length == 2 ) 
                 && ( XML_SCHEMA_URI.equals( parser.getNamespace( splitedString[0]
) ) ) 
-                && ( "base64Binary".equals( splitedString[1] ) );
+                && ( BASE64BINARY.equals( splitedString[1] ) );
+    }
+    
+    /**
+     * Indicates if the value needs to be encoded as Base64
+     *
+     * @param value the value to check
+     * @return true if the value needs to be encoded as Base64
+     */
+    public static boolean needsBase64Encoding( Object value )
+    {
+        if ( value instanceof byte[] )
+        {
+            return true;
+        }
+        else if ( value instanceof String )
+        {
+            return !LdifUtils.isLDIFSafe( (String) value );
+        }
+        return true;
+    }
+    
+    /**
+     * Encodes the value as a Base64 String
+     *
+     * @param value the value to encode
+     * @return the value encoded as a Base64 String 
+     */
+    public static String base64Encode( Object value )
+    {
+        if ( value instanceof byte[] )
+        {
+            return new String( Base64.encode( (byte[]) value ) );
+        }
+        else if ( value instanceof String )
+        {
+            return new String( Base64.encode( (( String ) value).getBytes() ) );
+        }
+        
+        return "";
     }
 }

Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java?view=diff&rev=486074&r1=486073&r2=486074
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java
(original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/ExtendedResponseDsml.java
Tue Dec 12 01:48:40 2006
@@ -20,9 +20,12 @@
 
 package org.apache.directory.ldapstudio.dsmlv2.reponse;
 
-
+import org.apache.directory.ldapstudio.dsmlv2.ParserUtils;
 import org.apache.directory.shared.ldap.codec.LdapMessage;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
 import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
 
 
 /**
@@ -59,13 +62,39 @@
     public Element toDsml( Element root )
     {
         Element element = root.addElement( "extendedResponse" );
+        ExtendedResponse extendedResponse = instance.getExtendedResponse();
 
-        LdapResultDsml ldapResultDsml = new LdapResultDsml( instance.getExtendedResponse().getLdapResult(),
instance );
+        // LDAP Result
+        LdapResultDsml ldapResultDsml = new LdapResultDsml( extendedResponse.getLdapResult(),
instance );
         ldapResultDsml.toDsml( element );
-
-        // TODO add management for ReponseName and Response Tag
-
+        
+        // ResponseName
+        String responseName = extendedResponse.getResponseName();
+        if ( responseName != null )
+        {
+            element.addElement( "responseName").addText( responseName );
+        }
+        
+        // Response
+        Object response = extendedResponse.getResponse();
+        if ( response != null )
+        {
+            if ( ParserUtils.needsBase64Encoding( response ) )
+            {
+                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 responseElement = element.addElement( "response").addText( ParserUtils.base64Encode(
response ) );
+                responseElement.addAttribute( new QName("type", xsiNamespace), "xsd:" + ParserUtils.BASE64BINARY
);
+            }
+            else
+            {
+                element.addElement( "response").addText( response.toString() );
+            }
+        }
+        
         return element;
     }
-
 }

Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java?view=diff&rev=486074&r1=486073&r2=486074
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java
(original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/LdapResultDsml.java
Tue Dec 12 01:48:40 2006
@@ -80,7 +80,7 @@
 
         // ErrorMessage
         String errorMessage = ( result.getErrorMessage() );
-        if ( !errorMessage.equals( "" ) )
+        if ( ( errorMessage != null ) && ( !errorMessage.equals( "" ) ) )
         {
             Element errorMessageElement = root.addElement( "errorMessage" );
             errorMessageElement.addText( errorMessage );

Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java?view=diff&rev=486074&r1=486073&r2=486074
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java
(original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/reponse/SearchResultEntryDsml.java
Tue Dec 12 01:48:40 2006
@@ -26,9 +26,12 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 
+import org.apache.directory.ldapstudio.dsmlv2.ParserUtils;
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.search.SearchResultEntry;
 import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
 
 
 /**
@@ -78,15 +81,29 @@
             Element attributeElement = element.addElement( "attr" );
             attributeElement.addAttribute( "name", attribute.getID() );
 
-            // Loopint on Values Enumeration
+            // Looping on Values Enumeration
             try
             {
                 NamingEnumeration ne2 = attribute.getAll();
 
                 while ( ne2.hasMoreElements() )
                 {
-                    String str = ne2.nextElement().toString();
-                    attributeElement.addElement( "value" ).addText( str );
+                    Object value = ne2.nextElement();
+                    
+                    if ( ParserUtils.needsBase64Encoding( value ) )
+                    {
+                        Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI
);
+                        Namespace xsiNamespace = new Namespace( "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 );
+                    }
+                    else
+                    {
+                        attributeElement.addElement( "value" ).addText( value.toString()
);
+                    }
                 }
             }
             catch ( NamingException e )
@@ -98,5 +115,4 @@
 
         return element;
     }
-
 }



Mime
View raw message