Clarity

 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="http://www.w3.org/2001/XMLSchema-instance">
      <!-- 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-->
      <!--Query-->
      <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
           ,ISNULL(SUBSTRING(srm.unique_name,1,9)
           + replicate(' ', 9-len(SUBSTRING(srm.unique_name,1,9))),replicate(' ', 9))                          mudanca_soli
     FROM   RIM_RISKS_AND_ISSUES r
     INNER JOIN ODF_CA_PROJECT prj on r.PK_ID=prj.id
     WHERE  r.id = ${gel_objectInstanceId}
      ]]>
      </sql:query>
      <!--Escrevendo o arquivo-->
      <core:if test="${paramDebugLevel > 0}"><gel:log>Criando o arquivo de saída no caminho "${paramFilePath}\${runDateFileName}.txt"</gel:log>
      </core:if>
      <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>
      </core:if>
      <!-- Escrever linhas-->
      <f:line>
      <f:column value="1${paramInicioLinha}${paramMudanca}${sqlResult.rows[0].mudanca_cod}"/>
      </f:line>
      </f:writeFile>
    </gel:script>
    


  • 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="java.io.FileOutputStream" var="foLog">
                <core:arg type="java.lang.String" value="${file_path_csv}"/>
              </core:new>
              <core:new className="java.io.OutputStreamWriter" var="owLog">
                <core:arg type="java.io.FileOutputStream" value="${foLog}"/>
                <core:arg type="java.lang.String" value="Cp1252"/>
              </core:new>
              <core:new className="java.io.BufferedWriter" var="bwLog">
                <core:arg type="java.io.OutputStreamWriter" value="${owLog}"/>
              </core:new>
            </core:catch>
            <core:if test="${ IOException != null }">
              <gel:out>ERR - ${IOException}.</gel:out>
              <gel:log level="error">ERR - ${IOException}.</gel:log>
            </core:if>
            
    

     

    Writing:

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

     

    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!