View Only
  • 1.  Generate a file in ANSI encoding

    Posted Jun 17, 2016 03:59 PM

    Is it possible to generate a file in ANSI enconding using Gel Script?


    I am using the the follwing code, but it only creates the file in UTF-8:

    <?xml version="1.0" encoding="Windows-1252"?>
    <gel:script xmlns:core="jelly:core" xmlns:f="jelly:com.niku.union.gel.FileTagLibrary" xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
                    xmlns:sql="jelly:sql" xmlns:xsi="">
      <!-- Abrir conexão com o DB-->
      <gel:setDataSource dbId="niku" var="nikuDS"/>
      <!--Formato da data atual-->
      <gel:formatDate format="yyyyMMddHHmmss" stringVar="runDateFileName"/>
      <gel:formatDate format="ddMMyyyy" stringVar="runDateLine"/>
      <!-- Parametros do arquivo-->
      <gel:parameter var="paramFilePath"/>
      <gel:parameter default="1" var="paramDebugLevel"/>
      <gel:parameter default="£¢" var="paramQuebraLinha"/>
      <gel:parameter default="/#$@%/" var="paramInicioLinha"/>
      <!--Parametros - Linha 1 - Campos fixos-->
      <!--INI:    8-->
      <gel:parameter default="2" var="paramMudanca"/>
      <!--INI:   23-->
      <sql:query dataSource="${nikuDS}" escapeText="false" var="sqlResult"><![CDATA[
    SELECT ISNULL(SUBSTRING(REPLACE(r.rim_risk_issue_code,'SM',''),1,14)      
           + replicate(' ', 14 - len(SUBSTRING(REPLACE(r.rim_risk_issue_code,'SM',''),1,14))),replicate(' ', 14)) mudanca_cod
           + replicate(' ', 9-len(SUBSTRING(srm.unique_name,1,9))),replicate(' ', 9))                          mudanca_soli
     WHERE = ${gel_objectInstanceId}
      <!--Escrevendo o arquivo-->
      <core:if test="${paramDebugLevel > 0}"><gel:log>Criando o arquivo de saída no caminho "${paramFilePath}\${runDateFileName}.txt"</gel:log>
      <f:writeFile delimiter="," embedded="false" fileName="${paramFilePath}\${runDateFileName}.txt">
      <core:if test="${paramDebugLevel > 0}"><gel:log>mudanca_cod: ${sqlResult.rows[0].mudanca_cod}</gel:log>
      <gel:log>mudanca_soli: ${sqlResult.rows[0].mudanca_soli}</gel:log>
      <!-- Escrever linhas-->
      <f:column value="1${paramInicioLinha}${paramMudanca}${sqlResult.rows[0].mudanca_cod}"/>

  • 2.  Re: Generate a file in ANSI encoding
    Best Answer

    Posted Jun 17, 2016 06:43 PM

    Yes, you can!


    Some languages, like portuguese, needs to be read and written using ANSI, so I will put a example that I use to create a CSV file in this encode.

    I don't know if you can use f:write to do this, I couldn't. So I'm using OutputStreamWriter from Java IO to do this. For ANSI you need to use <core:arg type="java.lang.String" value="Cp1252"/>.

    You can switch to utf-8 or utf-16 if necessary.


    Creating a File:


            <core:catch var="IOException">
              <core:new className="" var="foLog">
                <core:arg type="java.lang.String" value="${file_path_csv}"/>
              <core:new className="" var="owLog">
                <core:arg type="" value="${foLog}"/>
                <core:arg type="java.lang.String" value="Cp1252"/>
              <core:new className="" var="bwLog">
                <core:arg type="" value="${owLog}"/>
            <core:if test="${ IOException != null }">
              <gel:out>ERR - ${IOException}.</gel:out>
              <gel:log level="error">ERR - ${IOException}.</gel:log>



    <core:invoke method="write" on="${bwLog}" var="tempVar">
      <core:arg type="java.lang.String" value="${valueToInsert}"/>


    Closing the file:

    <core:invoke method="close" on="${bwLog}" var="tempVar"/>

  • 3.  Re: Generate a file in ANSI encoding

    Posted Jun 24, 2016 04:31 PM

    Hi Arthur.Filiberto - Did sille02 's response help answer your question? If so please mark as Correct Answer. Thanks!