Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ORSR forms standalone and API #467

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import eu.europa.esig.dss.model.DSSDocument;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public abstract class EFormResourcesBuilder {
Expand All @@ -28,10 +29,10 @@ public static EFormResources build(DSSDocument document, String fsFormId, String
public static EFormResources buildFromDocument(DSSDocument document, String fsFormId, String propertiesCanonicalization, String xsdIdentifier, XsltParams xsltParams)
throws AutogramException {

var xml = getXmlFromDocument(document).getDocumentElement();
var xml = getXmlFromDocument(document);
EFormResources eformResources;
if (isXDC(document.getMimeType()))
eformResources = buildFromXDC(xml, propertiesCanonicalization);
eformResources = buildFromXDC(xml.getDocumentElement(), propertiesCanonicalization);
else
eformResources = buildFromEFormXml(xml, propertiesCanonicalization, xsdIdentifier, xsltParams, fsFormId);

Expand Down Expand Up @@ -76,7 +77,7 @@ private static EFormResources buildFromXDC(Element xdc, String canonicalizationM
return buildFromEFormXml(canonicalizationMethod, formUri, xsdDigest, xsltDigest, xsdIdentifier, params);
}

private static EFormResources buildFromEFormXml(Element xml, String canonicalizationMethod, String xsdIdentifier, XsltParams xsltParams, String fsFormId)
private static EFormResources buildFromEFormXml(Document xml, String canonicalizationMethod, String xsdIdentifier, XsltParams xsltParams, String fsFormId)
throws XMLValidationException, UnknownEformException {
if (fsFormId != null)
return FsEFormResources.buildFromFsFormId(fsFormId, canonicalizationMethod, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,26 @@ public static String getFormUri(Element xdc) {
return xsiSchemaLocationNode.getNodeValue();
}

public static String getNamespaceFromEformXml(Node xml) {
var xmlns = xml.getAttributes().getNamedItem("xmlns");
if (xmlns != null)
public static String getNamespaceFromEformXml(Document xml) {
var xmlns = xml.getDocumentElement().getAttributes().getNamedItem("xmlns");
// Never use justice.gov.sk as identifier
if (xmlns != null && !xmlns.getNodeValue().contains("justice.gov.sk"))
return xmlns.getNodeValue();

xmlns = xml.getAttributes().getNamedItemNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
xmlns = xml.getDocumentElement().getAttributes().getNamedItemNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
if (xmlns != null)
return xmlns.getNodeValue();

// extract "href" attribute from <?xml-stylesheet> element
var nodes = xml.getChildNodes();
for (var i = 0; i < nodes.getLength(); i++)
if (nodes.item(i).getNodeType() == Node.PROCESSING_INSTRUCTION_NODE && nodes.item(i).getNodeName().equals("xml-stylesheet"))
for (var attribute : nodes.item(i).getNodeValue().split("\\s+")) {
var keyValue = attribute.split("=");
if (keyValue.length == 2 && "href".equals(keyValue[0]))
return keyValue[1].replace("\"", "").replace(".xslt", ".xsd");
}

return null;
}

Expand Down Expand Up @@ -353,7 +364,7 @@ public static String fillXsdIdentifier(String formIdentifier) {
}

public static boolean isOrsrUri(String uri) {
return uri != null && uri.contains("://eformulare.justice.sk");
return uri != null && uri.contains("://eformulare.justice.sk") || uri.contains("justice.gov.sk/");
}

public static String getFsFormIdFromFilename(String filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ private static EFormAttributes build(String identifier, String transformation, S
}
}

if (transformation != null)
if (transformation != null) {
xsltParams = EFormUtils.fillXsltParams(transformation, identifier, xsltParams);
if (!transformation.isEmpty() && transformation.charAt(0) == '\uFEFF')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tieto vynimky mam pocit, ze nemame uplne pokryte v testoch a zacina sa to tu kopit. Vieme pridat aj nejaky test co overi, ze sa to vsetko nastavilo spravne?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toto iba odstraňuje BOM zo začiatku stringu. Mali sme to na inom mieste, ale nie v API transformácii.

transformation = transformation.substring(1);
}

if (containerXmlns != null && containerXmlns.contains("xmldatacontainer")) {

Expand All @@ -52,6 +55,9 @@ private static EFormAttributes build(String identifier, String transformation, S
throw new EFormException("Chýba identifikátor", "Identifikátor je povinný atribút pre XML Datacontainer");
}

if (EFormUtils.isOrsrUri(identifier))
embedUsedSchemas = true;
Comment on lines +58 to +59
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja by som to radšej takto overridol. Je tu riziko, že v ďalekej budúcnosti prejdú na referencie, ale v tom momente by aj tak prešli na data.gov.sk/slovensko.sk formuát, takže je to jedno.


return new EFormAttributes(identifier, transformation, schema, containerXmlns, xsdIdentifier, xsltParams, embedUsedSchemas);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,14 @@ public static Stream<InMemoryDocument> validCadesDocumentsProvider() throws IOEx
public static Stream<InMemoryDocument> orsrDocumentsProvider() throws IOException {
var fupaXml = cls.getResourceAsStream("FUPA.xml").readAllBytes();
var fupsXml = cls.getResourceAsStream("FUPS.xml").readAllBytes();
var fuzsNewXml = cls.getResourceAsStream("fuzs_new.xml").readAllBytes();
var fupsXdcXml = cls.getResourceAsStream("FUPS.xdc.xml").readAllBytes();
var fupsXdcNoNamespaceXml = cls.getResourceAsStream("FUPS_wo_namespace.xdc.xml").readAllBytes();

return Stream.of(
new InMemoryDocument(fupaXml, "FUPA.xml", MimeTypeEnum.XML),
new InMemoryDocument(fupsXml, "FUPS.xml", MimeTypeEnum.XML),
new InMemoryDocument(fuzsNewXml, "fuzs_new.xml", MimeTypeEnum.XML),
new InMemoryDocument(fupsXdcXml, "FUPS.xdc.xml", MimeTypeEnum.XML),
new InMemoryDocument(fupsXdcNoNamespaceXml, "FUPS_wo_namespace.xdc.xml", MimeTypeEnum.XML)
);
Expand Down
Loading
Loading