Skip to content

Commit

Permalink
Fix empty namespaces in datacontainer & fix signing xml with plain ht…
Browse files Browse the repository at this point in the history
…ml elements
  • Loading branch information
jsuchal committed Nov 30, 2022
1 parent aa60c9c commit 2748e61
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 18 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,20 @@
<version>3.0.0-M7</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>11.4</version>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,21 @@ private String getDocumentContent() throws TransformerException {
var xmlSource = new DOMSource(document);
var outputTarget = new StreamResult(new StringWriter());

var transformerFactory= TransformerFactory.newInstance();
var transformerFactory = TransformerFactory.newInstance();
transformerFactory.newTransformer().transform(xmlSource, outputTarget);

return outputTarget.getWriter().toString();
}

private Element createXMLDataContainer() {
var element = document.createElement("XMLDataContainer");
var element = document.createElementNS(containerXmlns, "XMLDataContainer");
element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
if (containerXmlns != null)
element.setAttribute("xmlns", containerXmlns);

return element;
}

private Element createXMLData() {
var element = document.createElement("XMLData");
var element = document.createElementNS(containerXmlns, "XMLData");
element.setAttribute("ContentType", "application/xml; charset=UTF-8");
element.setAttribute("Identifier", identifierUri);
element.setAttribute("Version", identifierVersion);
Expand All @@ -178,7 +175,7 @@ private Element createXMLData() {
}

private Element createUsedSchemasReferenced() {
var element = document.createElement("UsedSchemasReferenced");
var element = document.createElementNS(containerXmlns, "UsedSchemasReferenced");
if (isPresent(xsdSchema) || isPresent(xsltSchema)) {
var documentXmlnsNode = document.getFirstChild().getAttributes().getNamedItem("xmlns");
if (documentXmlnsNode != null)
Expand Down Expand Up @@ -224,7 +221,7 @@ private static String toURIString(String xmlns, String suffix) {
}

private Element createUsedXSDReference() {
var element = document.createElement("UsedXSDReference");
var element = document.createElementNS(containerXmlns,"UsedXSDReference");
element.setAttribute("TransformAlgorithm", canonicalizationMethod);
element.setAttribute("DigestMethod", toNamespacedString(digestAlgorithm));
element.setAttribute("DigestValue", computeDigest(xsdSchema));
Expand All @@ -234,7 +231,7 @@ private Element createUsedXSDReference() {
}

private Element createUsedPresentationSchemaReference() {
var element = document.createElement("UsedPresentationSchemaReference");
var element = document.createElementNS(containerXmlns, "UsedPresentationSchemaReference");
element.setAttribute("TransformAlgorithm", canonicalizationMethod);
element.setAttribute("DigestMethod", toNamespacedString(digestAlgorithm));
element.setAttribute("DigestValue", computeDigest(xsltSchema));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.octosign.whitelabel.communication.document;

import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

class XMLDocumentTest {

@Test
void testTransformsXMLFormToXdc() {
// doc = new XMLDocument(...);
// doc.getTransformed(transformation);
assertTrue(false);
}
void testTransformsPlainHtmlWithoutAddingNamespaces() throws IOException {
var input = this.getClass().getResourceAsStream("abc.xml").readAllBytes();
var transformation = new String(this.getClass().getResourceAsStream("abc.xslt").readAllBytes());

@Test
void testTransformsPlainHtmlInXMLFormToXdc() {
assertTrue(false);
XMLDocument doc = new XMLDocument(new Document("id1", "test.xml", input));
String transformed = doc.getTransformed(transformation);

assertEquals(-1, transformed.lastIndexOf(":p>"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OutputDocument xmlns="http://schemas.gov.sk/form/36126624.PovolenieZdravotnictvo.sk/1.6">
<Rozhodnutie>
<UvodVyroku>
<p>Úrad pre dohľad nad zdravotnou starostlivosťou, právny odbor (ďalej len „úrad“), ako orgán príslušný na vydanie povolenia podľa § 18 ods. 1 písm. u) zákona č. 581/2004 Z.z. o zdravotných poisťovniach, dohľade nad zdravotnou starostlivosťou a o zmene a doplnení niektorých zákonov v znení neskorších predpisov (ďalej len „zákon č. 581/2004 Z.z.“), § 11 ods. 3 a § 21 ods. 1 zákona č. 578/2004 Z.z. o poskytovateľoch zdravotnej starostlivosti, zdravotníckych pracovníkoch, stavovských organizáciách v zdravotníctve a o zmene a doplnení niektorých zákonov v znení neskorších predpisov (ďalej len „zákon č. 578/2004 Z.z.“) a § 5 a § 6 ods. 2 zákona č. 71/1967 Zb. o správnom konaní (správny poriadok) v znení neskorších predpisov (ďalej len „Správny poriadok“) v súlade s § 46 a § 47 Správneho poriadku a § 25 ods. 1 zákona č. 578/2004 Z.z. rozhodol t a k t o:</p>
<p>Na základe žiadosti zo dňa XXXXXXX žiadateľa XXXXXXX, XXXXX, právna forma spoločnosť s ručením obmedzeným, IČO: XXXXX, zastúpenej štatutárnym orgánom XXXXXXXXXX (ďalej len „žiadateľ“) o vydanie povolenia na prevádzkovanie ambulancie záchrannej zdravotnej služby (ďalej len „ZZS“), a to ambulancie XXXXXXX v sídle stanice XXXXXX, podľa § 18 ods. 1 písm. u) zákona č. 581/2004 Z.z., § 11 ods. 3 písm. d), § 21 ods. 1 zákona č. 578/2004 Z.z. v súlade s § 12 ods. 4 a 5, § 14 ods. 11 a § 15 ods. 1 a 2 zákona č. 578/2004 Z.z.</p>
</UvodVyroku>
</Rozhodnutie>
</OutputDocument>
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:egonp="http://schemas.gov.sk/form/36126624.PovolenieZdravotnictvo.sk/1.6">
<!--<xsl:variable name="breakLine"><![CDATA[<br/>]]></xsl:variable>-->
<xsl:variable name="output-namespace">http://www.w3.org/1999/xhtml</xsl:variable>
<xsl:output method="html" doctype-system="http://www.w3.org/TR/html4/loose.dtd" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/egonp:OutputDocument">
<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;</xsl:text>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xml:lang="sk">
<head>
</head>
<body>
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyzľščťžýáíéú'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZĽŠČŤŽÝÁÍÉÚ'" />

<div class="bodyRozhodnutie">
<xsl:for-each select="egonp:Rozhodnutie/egonp:UvodVyroku">
<div class="divBody">
<xsl:apply-templates/>
</div>
</xsl:for-each>
</div>
</body>
</html>
</xsl:template>
<xsl:template name="DeliverTo">
<xsl:text disable-output-escaping="yes">&lt;br/&gt;</xsl:text>
<xsl:choose>
<xsl:when test="egonp:CorporateBody/egonp:CorporateBodyFullName!=''">
<xsl:value-of select="egonp:CorporateBody/egonp:CorporateBodyFullName"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="egonp:PhysicalPerson/egonp:PersonName/egonp:FormattedName"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>, </xsl:text>
<xsl:for-each select="egonp:PhysicalAddress">
<xsl:call-template name="singleLineAddress"/>
</xsl:for-each>
</xsl:template>

<xsl:template name="udzsAddress">
<xsl:if test="egonp:Unit!=''">
<xsl:value-of select="egonp:Unit"/>
<xsl:text disable-output-escaping="yes">&lt;br/&gt;</xsl:text>
</xsl:if>
<xsl:call-template name="firstLineAddress"/>
<xsl:text disable-output-escaping="yes">&lt;br/&gt;</xsl:text>
<xsl:call-template name="secondLineAddress"/>
<xsl:text disable-output-escaping="yes">&lt;br/&gt;</xsl:text>
<xsl:call-template name="thirdLineAddress"/>
</xsl:template>

<xsl:template name="singleLineAddress">
<xsl:call-template name="firstLineAddress"/>
<xsl:text>, </xsl:text>
<xsl:call-template name="secondLineAddress"/>
</xsl:template>
<xsl:template name="firstLineAddress">
<xsl:choose>
<xsl:when test="egonp:StreetName!=''">
<xsl:value-of select="egonp:StreetName"/>
<xsl:text>&#160;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="egonp:Municipality/egonp:Codelist/*!=''">
<xsl:value-of select="egonp:Municipality/egonp:Codelist/egonp:CodelistItem/egonp:ItemName"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="egonp:Municipality/egonp:NonCodelistData"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
<xsl:text>&#160;</xsl:text>
<xsl:value-of select="egonp:PropertyRegistrationNumber"/>
<xsl:if test="egonp:BuildingNumber!=''">
<xsl:text>/</xsl:text>
<xsl:value-of select="egonp:BuildingNumber"/>
</xsl:if>
</xsl:template>
<xsl:template name="secondLineAddress">
<xsl:value-of select="egonp:DeliveryAddress/egonp:PostalCode"/>
<xsl:text>&#160;</xsl:text>
<xsl:choose>
<xsl:when test="egonp:Municipality/egonp:Codelist/*!=''">
<xsl:value-of select="egonp:Municipality/egonp:Codelist/egonp:CodelistItem/egonp:ItemName"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="egonp:Municipality/egonp:NonCodelistData"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="thirdLineAddress">
<xsl:value-of select="egonp:Country/egonp:Codelist/egonp:CodelistItem/egonp:ItemName"/>
</xsl:template>
<!-- Formatted text thingy START -->
<xsl:template match="egonp:h1|egonp:h2|egonp:h3|egonp:p|egonp:i|egonp:big|egonp:small|egonp:b|egonp:u|egonp:s|egonp:ul|egonp:ol|egonp:li|egonp:br|egonp:table|egonp:thead|egonp:th|egonp:td|egonp:tr|egonp:caption|egonp:a">
<xsl:element name="{name()}" namespace="http://www.w3.org/1999/xhtml">
<xsl:if test="@align != ''">
<xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
</xsl:if>
<xsl:if test="@type != ''">
<xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute>
</xsl:if>
<xsl:if test="@width != ''">
<xsl:attribute name="width"><xsl:value-of select="@width"/>pt</xsl:attribute>
</xsl:if>
<xsl:if test="@colspan != ''">
<xsl:attribute name="colspan"><xsl:value-of select="@colspan"/></xsl:attribute>
</xsl:if>
<xsl:if test="@rowspan != ''">
<xsl:attribute name="rowspan"><xsl:value-of select="@rowspan"/></xsl:attribute>
</xsl:if>
<xsl:if test="@border != ''">
<xsl:attribute name="border"><xsl:value-of select="@border"/></xsl:attribute>
<xsl:if test="name()='table' or name()='td' or name()='th'">
<xsl:attribute name="class">table-border</xsl:attribute>
</xsl:if>
</xsl:if>
<xsl:if test="@href != ''">
<xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="egonp:editable">
<span class="editable">
<xsl:apply-templates/>
</span>
</xsl:template>
<!--<xsl:template match="*" mode="copy">
<xsl:element name="{name()}" namespace="http://www.w3.org/1999/xhtml">
<xsl:apply-templates select="@*|node()" mode="copy"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*|text()|comment()" mode="copy">
<xsl:copy/>
</xsl:template>-->
<!-- Formatted text thingy END -->
<xsl:template name="formatDate">
<xsl:choose>
<xsl:when test="string-length(.) >= 10">
<xsl:value-of select="number(substring(., 9, 2))"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="number(substring(., 6, 2))"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="substring(., 1, 4)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>{</xsl:text>
<xsl:value-of select="."/>
<xsl:text>}</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="formatRCSK">
<xsl:value-of select="substring(., 1, 6)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring(., 7)"/>
</xsl:template>

<xsl:template name="formatDateLongSK">
<xsl:choose>
<xsl:when test="string-length(.) >= 10">
<xsl:value-of select="number(substring(., 9, 2))"/>
<xsl:text>. </xsl:text>

<xsl:choose>
<xsl:when test="number(substring(., 6, 2)) = 1">
<xsl:text>januára</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 2">
<xsl:text>februára</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 3">
<xsl:text>marca</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 4">
<xsl:text>apríla</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 5">
<xsl:text>mája</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 6">
<xsl:text>júna</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 7">
<xsl:text>júla</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 8">
<xsl:text>augusta</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 9">
<xsl:text>septembra</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 10">
<xsl:text>októbra</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 11">
<xsl:text>novembra</xsl:text>
</xsl:when>
<xsl:when test="number(substring(., 6, 2)) = 12">
<xsl:text>decembra</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:text>&#160;</xsl:text>
<xsl:value-of select="substring(., 1, 4)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>{</xsl:text>
<xsl:value-of select="."/>
<xsl:text>}</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="makeUpper">
<xsl:param name="text"/>
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyzľščťžýáíéúóäôüöňď'"/>
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZĽŠČŤŽÝÁÍÉÚÓÄÔÜÖŇĎ'"/>
<xsl:value-of select="translate($text, $smallcase, $uppercase)" />
</xsl:template>
</xsl:stylesheet>

0 comments on commit 2748e61

Please sign in to comment.