grantwood Posted February 16, 2008 Posted February 16, 2008 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
grantwood Posted February 16, 2008 Author Posted February 16, 2008 FYI, the Base64 encoding function supplied with your examples database also adds two returns after every 76th character, but only on Windows.
shmert Posted February 21, 2008 Posted February 21, 2008 Hi Grant, Thanks for the post! I'm looking into the duplicate newline issue.
shmert Posted February 21, 2008 Posted February 21, 2008 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
grantwood Posted February 21, 2008 Author Posted February 21, 2008 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.
grantwood Posted March 19, 2008 Author Posted March 19, 2008 Any luck figuring out why there are two returns inserted after using the Base64 encoding function on a Mac?
shmert Posted April 17, 2008 Posted April 17, 2008 Hi Grant, what version of ScriptMaster are you using? I believe this has been fixed, the current version is 1.653
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now