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

add validation of SKOS files to SKOS-Editor #1139

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
75 changes: 75 additions & 0 deletions my/XRX/src/mom/app/skos-editor/service/validate-skos.service.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<xrx:service xmlns:xrx="http://www.monasterium.net/NS/xrx" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<xrx:id>tag:www.monasterium.net,2011:/mom/service/validate-skos</xrx:id>
<xrx:title>
<xrx:i18n>
<xrx:key>validate-skos</xrx:key>
<xrx:default>Validate-SKOS</xrx:default>
</xrx:i18n>
</xrx:title>
<xrx:description>This service validates the SKOS file before publishing.</xrx:description>
<xrx:author>niklas.tscherne@uni-graz.at</xrx:author>
<xrx:licence>
This is a component file of the VdU Software for a Virtual Research Environment for the handling of Medieval charters.

As the source code is available here, it is somewhere between an alpha- and a beta-release, may be changed without any consideration of backward compatibility of other parts of the system, therefore, without any notice.

This file is part of the VdU Virtual Research Environment Toolkit (VdU/VRET).

The VdU/VRET is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

VdU/VRET is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with VdU/VRET. If not, see http://www.gnu.org/licenses.
</xrx:licence>
<xrx:variables>
<xrx:variable>
<xrx:name>$vocab-name</xrx:name>
<xrx:expression>request:get-parameter("vocab", "")</xrx:expression>
</xrx:variable>
<xrx:variable>
<xrx:name>$skosfile</xrx:name>
<xrx:expression>doc(concat(metadata:base-collection-path('controlledVocabulary', 'private'), $vocab-name, '.xml'))</xrx:expression>
</xrx:variable>
<xrx:variable>
<xrx:name>$skoscontent</xrx:name>
<xrx:expression>$skosfile/atom:entry/atom:content</xrx:expression>
</xrx:variable>
<xrx:variable>
<xrx:name>$data-as-xml</xrx:name>
<xrx:expression>skos-edit:is-wellformed($skoscontent)</xrx:expression>
</xrx:variable>
<xrx:variable>
<xrx:name>$is-wellformed</xrx:name>
<xrx:expression>if(exists($data-as-xml/self::*:error)) then false() else true()</xrx:expression>
</xrx:variable>
<xrx:variable>
<xrx:name>$rdf-schema</xrx:name>
<xrx:expression>$xrx:db-base-collection/xs:schema[@id = 'rdf']</xrx:expression>
</xrx:variable>
<xrx:variable>
<xrx:name>$validation-report</xrx:name>
<xrx:expression>if($is-wellformed) then data:validate($data-as-xml, $rdf-schema) else ()</xrx:expression>
</xrx:variable>
<xrx:variable>
<xrx:name>$session-username</xrx:name>
<xrx:expression>xmldb:get-current-user()</xrx:expression>
</xrx:variable>
</xrx:variables>
<xrx:body>
{
if ($session-username != 'guest') then (
(: let $log_valreport := util:log('error', $validation-report) :)
let $clear-grammar-cache := validation:clear-grammar-cache()
return <output>{$validation-report}</output>
)
else ()
}
</xrx:body>
</xrx:service>
5 changes: 5 additions & 0 deletions my/XRX/src/mom/app/skos-editor/skos-edit.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ declare function skos-edit:get-vocab-filename($atomid as xs:string) as xs:string
return
$vocab-name
};

(: check well-formedness of an XML element:)
declare function skos-edit:is-wellformed($xml as element()){
try { $xml/* } catch * { <error>{ $err:description }</error> }
};
22 changes: 22 additions & 0 deletions my/XRX/src/mom/app/skos-editor/skos-editor.app.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ along with VdU/VRET. If not, see http://www.gnu.org/licenses.
<xrx:uri>http://www.monasterium.net/NS/skos-edit</xrx:uri>
</xrx:module>
</xrx:modules>
<xrx:resources>
<xrx:resource>
<xrx:atomid>tag:www.monasterium.net,2011:/mom/resource/xsd/rdf</xrx:atomid>
<xrx:relativepath>xsd/</xrx:relativepath>
<xrx:name>rdf.xsd</xrx:name>
</xrx:resource>
<xrx:resource>
<xrx:atomid>tag:www.monasterium.net,2011:/mom/resource/xsd/skos</xrx:atomid>
<xrx:relativepath>xsd/</xrx:relativepath>
<xrx:name>skos.xsd</xrx:name>
</xrx:resource>
<xrx:resource>
<xrx:atomid>tag:www.monasterium.net,2011:/mom/resource/xsd/xml</xrx:atomid>
<xrx:relativepath>xsd/</xrx:relativepath>
<xrx:name>xml.xsd</xrx:name>
</xrx:resource>
</xrx:resources>
<xrx:resolver>
<!-- main widget -->
<xrx:map>
Expand Down Expand Up @@ -83,6 +100,11 @@ along with VdU/VRET. If not, see http://www.gnu.org/licenses.
<xrx:mode>service</xrx:mode>
<xrx:atomid>tag:www.monasterium.net,2011:/mom/service/my-collection-release-skos</xrx:atomid>
</xrx:map>
<xrx:map>
<xrx:uripattern>/service/validate-skos$</xrx:uripattern>
<xrx:mode>service</xrx:mode>
<xrx:atomid>tag:www.monasterium.net,2011:/mom/service/validate-skos</xrx:atomid>
</xrx:map>
</xrx:resolver>
</xrx:app>

31 changes: 30 additions & 1 deletion my/XRX/src/mom/app/skos-editor/widget/skos-editor.widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
</xrx:i18n>
</b>
</div>
<div id="release-msg-invalid" style="color:red;display:none;margin:10px"/>
</div>
<script type="text/javascript" src="/bfResources/scripts/ckeditor/ckeditor.js"/>
<script type="text/javascript">
Expand Down Expand Up @@ -491,7 +492,8 @@

CKEDITOR.replace('editor');

$('#release-skos').click(function () {{
// release SKOS file
function release_skos(vocab){{
$.ajax({{
url: "/mom/service/my-collection-release-skos?vocab=" + vocab,
success: function (data) {{
Expand All @@ -513,6 +515,33 @@
$('#release-msg-err').delay(5000).fadeOut('slow');
}}
}})
}};

// validate SKOS file, release if valid
function validate_release_skos(vocab){{
$.ajax({{
url: "/mom/service/validate-skos?vocab=" + vocab,
success: function(response) {{
if ($(response).find('status').text() === 'valid'){{
release_skos(vocab);
}}
else {{
var errorMessage = '<strong>SKOS not valid!</strong><br/>' + $(response).find('message').text();
$('#release-msg-invalid').html(errorMessage).show();
$('#release-msg-invalid').css({{
opacity: 0, display: "block"
}}).animate({{
opacity: 1
}},
'slow');
$('#release-msg-invalid').delay(20000).fadeOut('slow');
}}
}}
}})
}};

$('#release-skos').click(function () {{
validate_release_skos(vocab)
}});

// submits contents of the textarea to the edit-definition service, reload
Expand Down
16 changes: 16 additions & 0 deletions my/XRX/src/mom/app/skos-editor/xsd/rdf.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<xs:schema targetNamespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
id="rdf">
<xs:import namespace="http://www.w3.org/2004/02/skos/core#" schemaLocation="skos.xsd"/>
<xs:element name="RDF">
<xs:complexType mixed="false">
<xs:sequence>
<xs:element ref="skos:ConceptScheme"/>
<xs:element maxOccurs="unbounded" ref="skos:Concept"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:attribute name="about"/>
<xs:attribute name="resource"/>
</xs:schema>
50 changes: 50 additions & 0 deletions my/XRX/src/mom/app/skos-editor/xsd/skos.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<xs:schema targetNamespace="http://www.w3.org/2004/02/skos/core#"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
id="skos">
<xs:import namespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
schemaLocation="rdf.xsd"/>
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
<xs:element name="ConceptScheme">
<xs:complexType>
<xs:all>
<xs:element maxOccurs="unbounded" name="prefLabel"> </xs:element>
<xs:element maxOccurs="unbounded" minOccurs="0" name="note"/>
<xs:element maxOccurs="unbounded" name="hasTopConcept">
<xs:complexType>
<xs:attribute ref="rdf:resource" use="required"/>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute ref="rdf:about" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="Concept">
<xs:complexType>
<xs:all>
<xs:element maxOccurs="unbounded" name="prefLabel">
<xs:complexType mixed="true">
<xs:attribute ref="xml:lang"/>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="unbounded" minOccurs="0" name="definition"/>
<xs:element minOccurs="0" name="broader" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute ref="rdf:resource" use="required"/>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="narrower" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute ref="rdf:resource" use="required"/>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="inScheme">
<xs:complexType>
<xs:attribute ref="rdf:resource" use="required"/>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute ref="rdf:about" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
5 changes: 5 additions & 0 deletions my/XRX/src/mom/app/skos-editor/xsd/xml.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
id="xml">
<xs:attribute name="lang"/>
</xs:schema>