Clarity

Expand all | Collapse all

Is it possible to do a gel:parse on a variable?

  • 1.  Is it possible to do a gel:parse on a variable?

    Posted Jul 05, 2017 06:41 PM

    I see that you can pass a file location to gel:parse, like:

     

        <gel:parse file="c:/HeresMyFile" var="parsedFile" />

     

    , or you can hard code the contents of gel:parse within the gel:script, like:

     

       <gel:parse var="parsedHardCode"><html>Hello universe!</html></gel:parse>

     

    , but can you pass a string or stream?

     

    I know it's not a documented option, but wondering if it might be an undocumented feature and, if so, has anyone used it.

     

    Thanks!



  • 2.  Re: Is it possible to do a gel:parse on a variable?

    Posted Jul 06, 2017 03:26 AM

    Wouldn't you just include the variable inside the <gel:parse>?

     

     <gel:parse var="parsedHardCode"><html>Hello ${myvariable}</html></gel:parse>



  • 3.  Re: Is it possible to do a gel:parse on a variable?

    Posted Jul 06, 2017 08:25 AM

    That does work, but that's not quite what I'd want to accomplish.  My question wasn't very clear.  I'd want the entire contents of the tag to be a variable.  I want the following script to pull in a value from a custom object and parse it:

     

    <gel:script xmlns:core="jelly:core" xmlns:file="jelly:com.niku.union.gel.FileTagLibrary" xmlns:sql="jelly:sql" xmlns:email="jelly:email"
     xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary" xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
     xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary" xmlns:soapEnv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xog="http://www.niku.com/xog"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <core:catch var="parseException">
      <gel:setDataSource dbId="mydbid" var="myDB"/>
      <sql:query dataSource="${myDB}" escapeText="false" var="rs"><![CDATA[SELECT to_char(MY_LARGE_STRING) as "MyLargeString" FROM ODF_CA_TYR_Test where code = '1']]></sql:query>
      <gel:log level="INFO">MyLargeString = ${rs.rows[0].MyLargeString}</gel:log>
      <gel:parse var="contents">
       ${rs.rows[0].MyLargeString}
      </gel:parse>
     </core:catch>
     <core:choose>
      <core:when test="${parseException != null}">
       <gel:log level="ERROR">${parseException}</gel:log>
      </core:when>
      <core:otherwise>
       <gel:set select="$contents" var="output" asString="true" />
       <gel:log level="INFO">output = <x:expr select="$output"/></gel:log>
      </core:otherwise>
     </core:choose>
    </gel:script>

     

    Here are the resultant log entries when I execute the process:

       MyLargeString = <html>Hello Universe</html>

       org.apache.commons.jelly.JellyTagException: null:9:31: <gel:parse> Reference is not allowed in prolog.

       BPM-0545: An error occurred when executing a custom action.



  • 4.  Re: Is it possible to do a gel:parse on a variable?
    Best Answer

    Posted Jul 06, 2017 09:00 AM

    Maybe <gel:include> is what you need then?

     

    I use it like this;

     

    <gel:include select="$some_xml_I_have_built"/>

     

    (when I've built up the some_xml_I_have_built XML document using a <gel:parse> but I want to include the contents of it in a XOG call or another XML thing I'm building using <gel:parse> ) 



  • 5.  Re: Is it possible to do a gel:parse on a variable?

    Posted Jul 06, 2017 01:15 PM

    I would try Dave's way which should work but if not you can just push the variable into an input stream and parse that.

     

    In this script (at the bottom), I parse a variable via an input stream.

     

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
         xmlns:core="jelly:core"
         xmlns:log="jelly:log"
         xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


         <!-- test values -->
         <core:set var="Plan_code" value="PlanCode1234" />
         <core:set var="Project_code" value="ProjectCode987" />
         <core:set var="Plan_type" value="BUDGET" />

         <!-- Main xog template -->
         <core:set var="xogReadFinPlanString" value="&lt;NikuDataBus xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='../xsd/nikuxog_costPlan.xsd'&gt;  
                        &lt;Header version='13.3.0.286' action='read' objectType='costPlan' externalSource='NIKU'&gt;&lt;args name='no_dependencies' value='true'/&gt;&lt;/Header&gt; 
                        &lt;Query&gt; 
                             &lt;Filter name='code' criteria='EQUALS'&gt;${Plan_code}&lt;/Filter&gt; 
                             &lt;Filter name='investmentCode' criteria='EQUALS'&gt;${Project_code}&lt;/Filter&gt; 
                        &lt;/Query&gt; 
                   &lt;/NikuDataBus&gt;"
    />

         <gel:log>xogReadFinPlanString before Replacement</gel:log>
         <gel:log>${xogReadFinPlanString}"</gel:log>

         <!-- Replace the costPlan for budgetPlan -->
         <core:if test="${Plan_type eq 'BUDGET'}">
              <core:set  var="xogReadFinPlanString" value='${xogReadFinPlanString.replaceAll("costPlan", "budgetPlan")}' />
         </core:if>
         <gel:log>xogReadFinPlanString after Replacement</gel:log>
         <gel:log>${xogReadFinPlanString}"</gel:log>

         <!-- Convert the stringi into something we can use for XOG -->
         <core:new var="inputStreamReader" className="java.io.ByteArrayInputStream" >
              <core:arg value="${xogReadFinPlanString.getBytes()}" />
         </core:new>
         <gel:parse var="xogReadFinPlan" file="${inputStreamReader}" />
         <gel:serialize fileName="xogReadFinPlan.xml" var="${xogReadFinPlan}"/>

    </gel:script>

     

     

    V/r,

    Gene



  • 6.  Re: Is it possible to do a gel:parse on a variable?

    Posted Apr 10, 2018 05:23 AM

    Hi Gene gcubed,

     

    I have one question regarding &lt; and &gt; and its interpretation in <core:set> tag.

    I would like to use it same as in your example, so interpret is as "<" and ">"

    I used this code (tried also with escapeText="false")

                    

    <core:set var="res_name" value="&lt;![CDATA[${eachRow[1]}]]&gt;" />

     <gel:set insert="true" select="$TransactionGroup/resourceName" value="${res_name}"/>

    However in the result XML I still see

       

    <resourceName>&lt;![CDATA[Resource_name]&gt;</resourceName>

    Do you know why &lt; and &gt; are interpreted differently there?

    Problem is with this CDATA construct, that I can't simply add < and > there....

     

    Thanks a lot.



  • 7.  Re: Is it possible to do a gel:parse on a variable?

    Posted Apr 10, 2018 12:22 PM

    You need to insert a CData node.

     

     

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
       xmlns:core="jelly:core"
       xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


         <gel:parse var="xogReadProjects">
              <Envelope>
                   <Body>
                        <ReadProject>
                             <NikuDataBus>
                             This is a test
                             </NikuDataBus>
                             <testNode>
                             </testNode>
                        </ReadProject>
                   </Body>
              </Envelope>
         </gel:parse>
         
         <core:set var='RowValue' value="testValue" />
         <core:set var="testCdataValue" value='${xogReadProjects.createCDATASection(RowValue);}' />

         <gel:set insert="true" select="$xogReadProjects/Envelope/Body/ReadProject/testNode" value="${testCdataValue}"/>
         <gel:serialize fileName="xogReadProjects.xml" var="${xogReadProjects}"/>

    </gel:script>

     

     

    V/r,

    Gene



  • 8.  Re: Is it possible to do a gel:parse on a variable?

    Posted Apr 11, 2018 04:11 AM

    Hi Gene,

     

    thanks a lot, this code did the trick:

    <core:set var="testCdataValue" value='${xogReadProjects.createCDATASection(RowValue);}' />

    However I have a question. When I then use <gel:set insert="true" ... it creates CDATA node, when not it doesn't.
    My case is that I'm creating XML nodes in loop so when used this insert="true", CDATA nodes are not replaced with
    new value but added one by one to other nodes... Ideally it should work without it (as I have it in other XML nodes...), but it doesn't.
    Do you have some tip to solve this? Thanks a lot.
    Matej



  • 9.  Re: Is it possible to do a gel:parse on a variable?

    Posted Apr 11, 2018 01:05 PM

    Once you add the CDATA node you just need to update it after that.

     

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
       xmlns:core="jelly:core"
       xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


         <gel:parse var="xogReadProjects">
              <Envelope>
                   <Body>
                        <ReadProject>
                             <NikuDataBus>
                             This is a test
                             </NikuDataBus>
                             <testNode />
                        </ReadProject>
                   </Body>
              </Envelope>
         </gel:parse>

         <core:forEach begin='1' end='4' var='cnt'>
              <core:set var='RowValue' value="testValue${cnt}" />
              <gel:log message='RowValue = ${RowValue}'/>
              <core:set var="testCdataValue" value='${xogReadProjects.createCDATASection(RowValue);}' />

              <!-- Add the CData Node with the value of testValue1 otherwise just update it -->
              <core:switch on='${RowValue}' >
                   <core:case fallThru='false' value='testValue1'>
                        <gel:set insert="true" select="$xogReadProjects/Envelope/Body/ReadProject/testNode" value="${testCdataValue}"/>
                   </core:case>
                   <core:default>
                        <gel:set select="$xogReadProjects/Envelope/Body/ReadProject/testNode/text()" value="${RowValue}"/>
                   </core:default>
              </core:switch>

              <gel:serialize fileName="xogReadProjects-${cnt}.xml" var="${xogReadProjects}"/>
         </core:forEach>

    </gel:script>

     

     

    V/r,

    Gene



  • 10.  Re: Is it possible to do a gel:parse on a variable?

    Posted Jul 21, 2017 03:19 PM

    Thanks Dave and Gene!  I've spent some time working with this more and am having success.  My issue was with malformed XML that the validator I was using didn't catch for some reason.