Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6075 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hello,

Included with your ScriptMaster plugin is an examples database that contains functions for Base64 encoding/decoding. However, the encoding function inserts returns every 76 characters (as per the Base64 standard). Ideally, I need an encoding function that does *not* insert returns, and I found one in this library:

Apache Commons Codec

My questions revolve around implementing the above library (the library loads just fine). I'm not a Java programmer, but after browsing the library documentation, I came up with the following custom functions:

1) Base64.encode ( text ; chunk )

/**

 Converts any string into another string composed of only the Base64 character set.

  

 @param text *str: any string

 @param chunk *num: 0 (do *not* split into blocks of 76 characters) or 1 (split into blocks of 76 characters)

 @return *str: a string composed of the Base64 characters



*/



Let (

        [

                _result = SMSetVariable( "textToEncode" ; text ) ; 

                _code = "import org.apache.commons.codec.binary.*;" ; 

                _code = _code & Case ( 

                                        chunk ; 

                                        "new String(new Base64().encodeBase64(textToEncode.getBytes(), true));" ; 

                                        "new String(new Base64().encodeBase64(textToEncode.getBytes(), false));"

                                ) 

        ] ;

        

        Case ( not IsEmpty ( text ) ; EvaluateGroovy ( _code ) ) 

)


2) Base64.Decode ( text )




/**

 Converts a string encoded with the Base64 algorithm back to its "natural" form

  

 @param text *str: any string encoded with the Base64 algorithm

 @return *str: a string in its "natural" form



*/



Let (

        [

                _result = SMSetVariable( "encodedText" ; text ) ; 

                _code = "import org.apache.commons.codec.binary.*;" ; 

                _code = _code & "new String(new Base64().decodeBase64(encodedText.getBytes()));" 

        ] ;

        

        Case ( not IsEmpty ( text ) ; EvaluateGroovy ( _code ) ) 

)

The functions seem to work, but I do have some questions:

1) If I want to encode text in the usual way--using Base64.Encode ( text ; 1 )--the encoded text has *two* returns after every 76th character, which seems unexpected. Any ideas why?

2) When sending a return-delimited list from FileMaker to Groovy using the SMSetVariable function, does each return translate to r, n, or rn?

3) When converting an array in Groovy to a return-delimited list using the Array.Join function, for use with the SMGetVariable function, should the join character be r, n, or rn?

Regards,

Sean

Posted

FYI, the Base64 encoding function supplied with your examples database also adds two returns after every 76th character, but only on Windows.

Posted

This issue with newlines was caused by the Base64Encoder class, which uses platform-specific newlines.

Previously, ScriptMaster converted all newline characters to carriage returns, which is how FileMaker wants to receive it. However, when the Base64Encoder is running on windows, it inserts rn for newlines. Then ScriptMaster was converting the second n to a r, leaving two rr in a row.

Version 1.651 (Fresh hot now!) will fix this issue by first checking for carriage returns ® in the returned text on Windows.

-Sam Barnum

360Works

Posted

Hi Sam,

Thanks for all of your help. FYI, when using the base64 encoding function from the Apache library mentioned in the original post, I still see two returns on the Mac.

  • 4 weeks later...
  • 4 weeks later...
Posted

Hi Grant, what version of ScriptMaster are you using?

I believe this has been fixed, the current version is 1.653

This topic is 6075 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.