what your trying to achieve here?
Is there any specific use case to use only java script?
Brief about your use case or requirement.
I took didnt get what the exact question is about. Is there some integration with another program which uses Java script only?
From the Dev Studio itself you can use XPATH / XSLT for transforming.
1 of 1 people found this helpful
only java functions will work like java:format($dateFormat, $passedDate), also check whether you have declared java namespace "<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="java" version="1.0">"
1 of 1 people found this helpful
Sorry for Late reply.
certain calculations or logics need to be done from AO level, where I tried using Jython and Perl, which Im still in beginer level.
Requirement is simple. I want to convert the string to Unicode format. for example if I give input as A I have to get the output as 97.
ie, I have to achieve this in AO itself. in powershell we can perform this conversion easily by using the following command.
$bytes = [System.Text.Encoding]::Unicode.GetBytes("abcd")
Provide some light please
I imagine you could do this with a bit of Jython and the script adapter. The basic Python/Jython script is:
myString = "This is some text" for c in myString: print ord(c)
And you'd just have to decide how you want to pass data in and out. I've written an initial blog post on using Jython scripts in AO which might be of help.
Many Thanks for the info, SInce the Script Adapter is not enabled in our Environment ( Approval is in process ), I will not be able to test right away.
The following will get you the codepoint for the first character of the input context item. You can extend it to loop through all characters.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="java" version="1.0"> <xsl:output indent="no" /> <xsl:template match="/"> <xsl:variable name="charString" select="java:lang.String.new(.)" /> <xsl:variable name="charArray" select="java:toCharArray($charString)" /> <xsl:variable name="charPos" select="0" /> <result> <xsl:value-of select="java:lang.Character.codePointAt($charArray, $charPos)" disable-output-escaping="no" /> </result> </xsl:template> </xsl:stylesheet>
Thanks for the Reply and it was the correct answer, I am struck in converting the output of Unicode value to Base64.
I tried this one but not working. I get the error at the last line. any solution please.
var2 = "**"
for c in var1:
var2 = var2 + "\n" + "0" + "\n" + str(ord(c))
var2 = var2 + "\n" + "0"
var3 = var2.replace("**" + "\n" + "0"+"\n","")
var4 = base64.b64encode(var3)
This won't work because you're trying to import base64 from the standard Python libs. Currently these aren't included, and I have an open idea requesting that they get added.
In the meantime you'll need to switch to use the standard Java classes:
from org.apache.commons.codec.binary import Base64 from java.lang import String var2 = "**" for c in var1: var2 = var2 + "\n" + "0" + "\n" + str(ord(c)) var2 = var2 + "\n" + "0" var3 = var2.replace("**" + "\n" + "0"+"\n","") var4 = String (Base64.encodeBase64(var3))
Given an input of "This is a string.", this generates the output:
Note that if you modify your Script adapter to include the Jython libs, your script works fine and gives the same output. (See the "Importing Modules" section in this article.)
Thanks a Ton for the Reply and Im in the process of including the Jython Libs.
But the real scenario of mine is to convert the Unicode string to "ToBase64String" not Base64 Encoding ,
was my bad.
Im in a process of converting the powershell commands in encoded format. so that I can run the encoded string through normal command prompt or command line adapter..(cause we dont have the powershell adapter or the remote powershell execution is banned)
Following steps if u run in powershell , you will get the base64 string result.
when encoded result string is executed on command prompt, we will get the expected output.
$command = "dir 'c:\program files' "
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)
powershell.exe -encodedCommand $encodedCommand
for ex : if you run the following copmmand in normal command prompt we will get the last restart event.
powershell.exe -encodedCommand dwBlAHYAdAB1AHQAaQBsACAAcQBlACAAUwB5AHMAdABlAG0AIAAvAHIAZAA6AHQAcgB1AGUAIAAvAGYAOgB0AGUAeAB0ACAALwBjADoAMQAgAC8AcQA6ACcAKgBbAFMAeQBzAHQAZQBtAFsAKABFAHYAZQBuAHQASQBEAD0AMQAwADcANAApACAAbwByACAAKABFAHYAZQBuAHQASQBEAD0ANAAxACkAXQBdACcA
Log Name: System
Event ID: 1074
User Name: NT AUTHORITY\SYSTEM
The process wininit.exe (127.0.0.1) has initiated the restart of computer APACSG
TPAV0708 on behalf of user NT AUTHORITY\SYSTEM for the following reason: Legacy
Reason Code: 0x80070000
Shutdown Type: restart
conversion of Unicode is exact as of the powershell..but when I convert to Base64, I get difference in the base64 string.
So I require to convert the string to Byte (I think So)