Skip to content

Commit 0087fd6

Browse files
fix: xml generation set CDATA string as raw content (#222)
1 parent 710d1f5 commit 0087fd6

File tree

18 files changed

+35
-25
lines changed

18 files changed

+35
-25
lines changed

core/src/main/java/io/github/project/openubl/xbuilder/renderer/EngineProducer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.github.project.openubl.xbuilder.content.catalogs.Catalog7;
2121
import io.quarkus.qute.Engine;
2222
import io.quarkus.qute.HtmlEscaper;
23+
import io.quarkus.qute.RawString;
2324
import io.quarkus.qute.ReflectionValueResolver;
2425
import io.quarkus.qute.TemplateLocator.TemplateLocation;
2526
import io.quarkus.qute.ValueResolver;
@@ -54,6 +55,15 @@ public class EngineProducer {
5455
.removeStandaloneLines(true)
5556
.addResultMapper(new HtmlEscaper(List.of("text/html", "text/xml", "application/xml", "application/xhtml+xml")))
5657
.addValueResolver(new ReflectionValueResolver())
58+
.addValueResolver(ValueResolver.builder()
59+
.applyToBaseClass(String.class)
60+
.applyToName("raw")
61+
.resolveSync(ctx -> {
62+
String value = ((String) ctx.getBase());
63+
return new RawString(value);
64+
})
65+
.build()
66+
)
5767
.addValueResolver(ValueResolver.builder()
5868
.applyToBaseClass(LocalDate.class)
5969
.applyToName("format")

core/src/main/resources/templates/Renderer/creditNote.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{#include ubl/standard/include/ubl-extensions.xml /}
66
{#include ubl/standard/include/general-data.xml item=this /}
77
{#for key in leyendas.keySet}
8-
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key)}]]></cbc:Note>
8+
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key).raw}]]></cbc:Note>
99
{/for}
1010
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe" listName="Currency">{moneda}</cbc:DocumentCurrencyCode>
1111
{#include "ubl/standard/include/note/invoice-reference.xml" item=this /}

core/src/main/resources/templates/Renderer/debitNote.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{#include ubl/standard/include/ubl-extensions.xml /}
66
{#include ubl/standard/include/general-data.xml item=this /}
77
{#for key in leyendas.keySet}
8-
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key)}]]></cbc:Note>
8+
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key).raw}]]></cbc:Note>
99
{/for}
1010
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe" listName="Currency">{moneda}</cbc:DocumentCurrencyCode>
1111
{#include "ubl/standard/include/note/invoice-reference.xml" item=this /}

core/src/main/resources/templates/Renderer/despatchAdvice.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{#include ubl/standard/include/general-data.xml item=this /}
1010
<cbc:DespatchAdviceTypeCode>{tipoComprobante}</cbc:DespatchAdviceTypeCode>
1111
{#if observaciones}
12-
<cbc:Note><![CDATA[{observaciones}]]></cbc:Note>
12+
<cbc:Note><![CDATA[{observaciones.raw}]]></cbc:Note>
1313
{/if}
1414
{#if documentoBaja}
1515
<cac:OrderReference>
@@ -31,7 +31,7 @@
3131
<cbc:ID schemeID="6" schemeName="Documento de Identidad" schemeAgencyName="PE:SUNAT" schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">{remitente.ruc}</cbc:ID>
3232
</cac:PartyIdentification>
3333
<cac:PartyLegalEntity>
34-
<cbc:RegistrationName><![CDATA[{remitente.razonSocial}]]></cbc:RegistrationName>
34+
<cbc:RegistrationName><![CDATA[{remitente.razonSocial.raw}]]></cbc:RegistrationName>
3535
</cac:PartyLegalEntity>
3636
</cac:Party>
3737
</cac:DespatchSupplierParty>
@@ -41,7 +41,7 @@
4141
<cbc:ID schemeID="{destinatario.tipoDocumentoIdentidad}" schemeName="Documento de Identidad" schemeAgencyName="PE:SUNAT" schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">{destinatario.numeroDocumentoIdentidad}</cbc:ID>
4242
</cac:PartyIdentification>
4343
<cac:PartyLegalEntity>
44-
<cbc:RegistrationName><![CDATA[{destinatario.nombre}]]></cbc:RegistrationName>
44+
<cbc:RegistrationName><![CDATA[{destinatario.nombre.raw}]]></cbc:RegistrationName>
4545
</cac:PartyLegalEntity>
4646
</cac:Party>
4747
</cac:DeliveryCustomerParty>
@@ -50,7 +50,7 @@
5050
<cbc:CustomerAssignedAccountID schemeID="6">{proveedor.ruc}</cbc:CustomerAssignedAccountID>
5151
<cac:Party>
5252
<cac:PartyLegalEntity>
53-
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial}]]></cbc:RegistrationName>
53+
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial.raw}]]></cbc:RegistrationName>
5454
</cac:PartyLegalEntity>
5555
</cac:Party>
5656
</cac:SellerSupplierParty>
@@ -77,7 +77,7 @@
7777
<cbc:ID schemeID="{envio.transportista.tipoDocumentoIdentidad}">{envio.transportista.numeroDocumentoIdentidad}</cbc:ID>
7878
</cac:PartyIdentification>
7979
<cac:PartyName>
80-
<cbc:Name><![CDATA[{envio.transportista.nombre}]]></cbc:Name>
80+
<cbc:Name><![CDATA[{envio.transportista.nombre.raw}]]></cbc:Name>
8181
</cac:PartyName>
8282
</cac:CarrierParty>
8383
<cac:TransportMeans>
@@ -123,7 +123,9 @@
123123
<cbc:LineID>{it_index.add(1)}</cbc:LineID>
124124
</cac:OrderLineReference>
125125
<cac:Item>
126-
<cbc:Name><![CDATA[{it.descripcion}]]></cbc:Name>
126+
{#if it.descripcion}
127+
<cbc:Name><![CDATA[{it.descripcion.raw}]]></cbc:Name>
128+
{/if}
127129
<cac:SellersItemIdentification>
128130
<cbc:ID>{it.codigo}</cbc:ID>
129131
</cac:SellersItemIdentification>

core/src/main/resources/templates/Renderer/invoice.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<cbc:InvoiceTypeCode listID="{tipoOperacion}" listAgencyName="PE:SUNAT" listName="Tipo de Documento" listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01">{tipoComprobante}</cbc:InvoiceTypeCode>
1111
{#if leyendas}
1212
{#for key in leyendas.keySet}
13-
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key)}]]></cbc:Note>
13+
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key).raw}]]></cbc:Note>
1414
{/for}
1515
{/if}
1616
{#if observaciones}
17-
<cbc:Note><![CDATA[{observaciones}]]></cbc:Note>
17+
<cbc:Note><![CDATA[{observaciones.raw}]]></cbc:Note>
1818
{/if}
1919
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe" listName="Currency">{moneda}</cbc:DocumentCurrencyCode>
2020
{#if ordenDeCompra}

core/src/main/resources/templates/Renderer/perception.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<sac:SUNATPerceptionSystemCode>{tipoRegimen}</sac:SUNATPerceptionSystemCode>
2525
<sac:SUNATPerceptionPercent>{tipoRegimenPorcentaje}</sac:SUNATPerceptionPercent>
2626
{#if observacion}
27-
<cbc:Note><![CDATA[{observacion}]]></cbc:Note>
27+
<cbc:Note><![CDATA[{observacion.raw}]]></cbc:Note>
2828
{/if}
2929
<cbc:TotalInvoiceAmount currencyID="{moneda}">{importeTotalPercibido}</cbc:TotalInvoiceAmount>
3030
<sac:SUNATTotalCashed currencyID="{moneda}">{importeTotalCobrado}</sac:SUNATTotalCashed>

core/src/main/resources/templates/Renderer/retention.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<sac:SUNATRetentionSystemCode>{tipoRegimen}</sac:SUNATRetentionSystemCode>
2525
<sac:SUNATRetentionPercent>{tipoRegimenPorcentaje}</sac:SUNATRetentionPercent>
2626
{#if observacion}
27-
<cbc:Note><![CDATA[{observacion}]]></cbc:Note>
27+
<cbc:Note><![CDATA[{observacion.raw}]]></cbc:Note>
2828
{/if}
2929
<cbc:TotalInvoiceAmount currencyID="{moneda}">{importeTotalRetenido}</cbc:TotalInvoiceAmount>
3030
<sac:SUNATTotalPaid currencyID="{moneda}">{importeTotalPagado}</sac:SUNATTotalPaid>

core/src/main/resources/templates/ubl/common/signature.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<cbc:ID>{firmante.ruc}</cbc:ID>
66
</cac:PartyIdentification>
77
<cac:PartyName>
8-
<cbc:Name><![CDATA[{firmante.razonSocial}]]></cbc:Name>
8+
<cbc:Name><![CDATA[{firmante.razonSocial.raw}]]></cbc:Name>
99
</cac:PartyName>
1010
</cac:SignatoryParty>
1111
<cac:DigitalSignatureAttachment>

core/src/main/resources/templates/ubl/standard/include/address.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{/if}
1919
{#if direccion.direccion}
2020
<cac:AddressLine>
21-
<cbc:Line><![CDATA[{direccion.direccion}]]></cbc:Line>
21+
<cbc:Line><![CDATA[{direccion.direccion.raw}]]></cbc:Line>
2222
</cac:AddressLine>
2323
{/if}
2424
{#if direccion.codigoPais}

core/src/main/resources/templates/ubl/standard/include/customer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<cbc:ID schemeID="{cliente.tipoDocumentoIdentidad}" schemeAgencyName="PE:SUNAT" schemeName="Documento de Identidad" schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">{cliente.numeroDocumentoIdentidad}</cbc:ID>
55
</cac:PartyIdentification>
66
<cac:PartyLegalEntity>
7-
<cbc:RegistrationName><![CDATA[{cliente.nombre}]]></cbc:RegistrationName>
7+
<cbc:RegistrationName><![CDATA[{cliente.nombre.raw}]]></cbc:RegistrationName>
88
{#if cliente.direccion}
99
<cac:RegistrationAddress>
1010
{#include ubl/standard/include/address.xml direccion=cliente.direccion /}

core/src/main/resources/templates/ubl/standard/include/document-line.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<cbc:TaxableAmount currencyID="{moneda}">{item.iscBaseImponible.scale(2)}</cbc:TaxableAmount>
1717
<cbc:TaxAmount currencyID="{moneda}">{item.isc.scale(2)}</cbc:TaxAmount>
1818
<cac:TaxCategory>
19-
<cbc:Percent>{item.tasaIsc.multiply(100)}</cbc:Percent>
19+
<cbc:Percent>{item.tasaIsc.multiply(100).scale(2)}</cbc:Percent>
2020
<cbc:TierRange>{item.iscTipo}</cbc:TierRange>
2121
<cac:TaxScheme>
2222
<cbc:ID>2000</cbc:ID>
@@ -56,7 +56,7 @@
5656
{/if}
5757
</cac:TaxTotal>
5858
<cac:Item>
59-
<cbc:Description><![CDATA[{item.descripcion}]]></cbc:Description>
59+
<cbc:Description><![CDATA[{item.descripcion.raw}]]></cbc:Description>
6060
</cac:Item>
6161
<cac:Price>
6262
<cbc:PriceAmount currencyID="{moneda}">{item.precio.scale(2)}</cbc:PriceAmount>

core/src/main/resources/templates/ubl/standard/include/note/invoice-reference.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<cac:DiscrepancyResponse>
22
<cbc:ReferenceID>{item.comprobanteAfectadoSerieNumero}</cbc:ReferenceID>
33
<cbc:ResponseCode>{item.comprobanteAfectadoTipo}</cbc:ResponseCode>
4-
<cbc:Description><![CDATA[{item.sustentoDescripcion}]]></cbc:Description>
4+
<cbc:Description><![CDATA[{item.sustentoDescripcion.raw}]]></cbc:Description>
55
</cac:DiscrepancyResponse>
66
{#if item.ordenDeCompra}
77
<cac:OrderReference>

core/src/main/resources/templates/ubl/standard/include/supplier.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</cac:PartyName>
1010
{/if}
1111
<cac:PartyLegalEntity>
12-
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial}]]></cbc:RegistrationName>
12+
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial.raw}]]></cbc:RegistrationName>
1313
{#if proveedor.direccion}
1414
<cac:RegistrationAddress>
1515
{#include ubl/standard/include/address.xml direccion=proveedor.direccion /}

core/src/main/resources/templates/ubl/sunat/include/agent-party.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
</cac:PartyIdentification>
55
{#if proveedor.nombreComercial}
66
<cac:PartyName>
7-
<cbc:Name><![CDATA[{proveedor.nombreComercial}]]></cbc:Name>
7+
<cbc:Name><![CDATA[{proveedor.nombreComercial.raw}]]></cbc:Name>
88
</cac:PartyName>
99
{/if}
1010
<cac:PartyLegalEntity>
11-
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial}]]></cbc:RegistrationName>
11+
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial.raw}]]></cbc:RegistrationName>
1212
</cac:PartyLegalEntity>
1313
</cac:AgentParty>

core/src/main/resources/templates/ubl/sunat/include/receiver-party.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<cbc:ID schemeID="{cliente.tipoDocumentoIdentidad}">{cliente.numeroDocumentoIdentidad}</cbc:ID>
44
</cac:PartyIdentification>
55
<cac:PartyLegalEntity>
6-
<cbc:RegistrationName><![CDATA[{cliente.nombre}]]></cbc:RegistrationName>
6+
<cbc:RegistrationName><![CDATA[{cliente.nombre.raw}]]></cbc:RegistrationName>
77
</cac:PartyLegalEntity>
88
</cac:ReceiverParty>

core/src/main/resources/templates/ubl/sunat/include/supplier.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<cbc:AdditionalAccountID>6</cbc:AdditionalAccountID>
44
<cac:Party>
55
<cac:PartyLegalEntity>
6-
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial}]]></cbc:RegistrationName>
6+
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial.raw}]]></cbc:RegistrationName>
77
</cac:PartyLegalEntity>
88
</cac:Party>
99
</cac:AccountingSupplierParty>

core/src/test/resources/e2e/renderer/despatchadvice/DespatchAdviceTest/minData.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
<cbc:LineID>1</cbc:LineID>
8484
</cac:OrderLineReference>
8585
<cac:Item>
86-
<cbc:Name><![CDATA[]]></cbc:Name>
8786
<cac:SellersItemIdentification>
8887
<cbc:ID>123456</cbc:ID>
8988
</cac:SellersItemIdentification>

quarkus-extension/integration-tests/src/test/java/io/github/project/openubl/quarkus/xbuilder/it/QuarkusXbuilderResourceTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,6 @@ public void testDespatchAdvice() {
12811281
" <cbc:LineID>1</cbc:LineID>\n" +
12821282
" </cac:OrderLineReference>\n" +
12831283
" <cac:Item>\n" +
1284-
" <cbc:Name><![CDATA[]]></cbc:Name>\n" +
12851284
" <cac:SellersItemIdentification>\n" +
12861285
" <cbc:ID>123456</cbc:ID>\n" +
12871286
" </cac:SellersItemIdentification>\n" +

0 commit comments

Comments
 (0)