2026-01-24 - 00:04

Open Source License Checklists - Access to license compliance raw data - Example code

1. PHP script to populate an interactive compatibility checker using sequentially indexed JSON array

Without explanations - With explanations

Widget in action
     

Code to generate the above widget (to be placed on Web server)
 
<?php
/* SPDX-License-Identifier: CC0-1.0 */
/* Copyright (c) 2022 Open Source Automation Development Lab (OSADL) eG <info@osadl.org>, author Carsten Emde */
 
$json = file_get_contents('http://www.osadl.org/fileadmin/checklists/matrixseqexpl.json');
 
echo '
<!DOCTYPE html>
<html>
 
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>OSADL Compatibility Matrix of FOSS Licenses</title>
</head>
 
<body>
<select id="selectleadinglicense" style="display: inline;" onchange="showcompatibility();">
<option selected="selected">Choose a leading license</option>
</select>
&nbsp;&nbsp;
<select id="selectsubordinatelicense" style="display: inline;" onchange="showcompatibility();">
<option selected="selected">Choose a subordinate license</option>
</select>
&nbsp;&nbsp;
<span id="result"></span>
<span id="help"></span>
 
<script type="text/javascript" language="javascript">
 
var jsobject;
 
var selectleading = document.getElementById("selectleadinglicense");
var selectsubordinate = document.getElementById("selectsubordinatelicense");
 
function showcompatibility()
{
  var result = document.getElementById("result");
  var help = document.getElementById("help");
  var compatibility;
 
  if (selectleading.selectedIndex == 0 || selectsubordinate.selectedIndex == 0) {
    result.innerHTML = "";
    help.innerHTML = "";
    return;
  }
  compatibility = jsobject.licenses[selectleading.selectedIndex-1].compatibilities[selectsubordinate.selectedIndex-1].compatibility;
  explanation = jsobject.licenses[selectleading.selectedIndex-1].compatibilities[selectsubordinate.selectedIndex-1].explanation;
  result.style.fontWeight = "bold";
  if (compatibility == "Yes")
    result.style.color = "green";
  else if (compatibility == "No")
    result.style.color = "red";
  else if (compatibility == "Check dependency")
    result.style.color = "rgb(172, 172, 0)";
  else {
    result.style.color = "black";
    result.style.fontWeight = "normal";
  }
  if (compatibility == "Same") {
    result.innerHTML = "";
    help.innerHTML = "";
  } else {
    result.innerHTML = "<b>Compatibility:</b> " + compatibility;
    help.innerHTML = "<br /><br /><b>Reference:</b><br />" + explanation;
  }
}
 
var json = `' . $json . '`;
jsobject = JSON.parse(json);
for (i = 0; i < jsobject.licenses.length; i++) {
  var license = jsobject.licenses[i].name;
  var eleleading = document.createElement("option");
  var elesubordinate = document.createElement("option");
 
  eleleading.textContent = elesubordinate.textContent = license;
  selectleading.appendChild(eleleading);
  selectsubordinate.appendChild(elesubordinate);
}
</script>
</body>
</html>';
 
?>

 

2. Same as above, but maintaining a local copy of the data file and using static HTML code for "client-only" operation

(Please note that with this approach, it is the user's responsibility to ensure that the local copy of the data file is up to date.)

Web page in action

Code to generate the above Web page (to be loaded into browser)
 
<!--
SPDX-License-Identifier: CC0-1.0
Copyright (c) 2022 Open Source Automation Development Lab (OSADL) eG <info@osadl.org>, author Carsten Emde
Copyright (c) 2022 Pilz GmbH & Co. KG, author Thorsten Godau <t.godau@pilz.de>
"Client-only" version based on:
https://www.osadl.org/Example-code-for-license-compliance-raw.procedural-raw-compliance-import.0.html
The OSADL license compatibility matrix is licensed under the Creative Commons Attribution 4.0 International license (CC-BY-4.0), https://creativecommons.org/licenses/by/4.0/.
-->
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>OSADL Compatibility Matrix of FOSS Licenses ("Client-only" version)</title>
  </head>
  <body>
    <p>
    Instructions:
    <ul>
      <li>Download the <a href="https://www.osadl.org/fileadmin/checklists/matrixseqexpl.json">OSADL license compatibility matrix with explanations</a> JSON file (by right click and "Save link as...").</li>
      <li>Choose the downloaded JSON file with the file picker.</li>
      <li>Use the compatibility checker by selecting a leading and a subordinate license.</li>
    </ul>
    <p>
    <input type="file" id="jsonFilePicker" accept=".json"></input>
    <p>
    <select id="selectleadinglicense" style="display: inline;" onchange="showcompatibility();">
      <option selected="selected">Choose a leading license</option>
    </select>
    &nbsp;&nbsp;
    <select id="selectsubordinatelicense" style="display: inline;" onchange="showcompatibility();">
      <option selected="selected">Choose a subordinate license</option>
    </select>
    &nbsp;&nbsp;
    <span id="result"></span>
    <span id="help"></span>
    <script type="text/javascript" language="javascript">
 
    var jsonObject;
    var selectleading = document.getElementById("selectleadinglicense");
    var selectsubordinate = document.getElementById("selectsubordinatelicense");
    document.getElementById("jsonFilePicker").addEventListener("change", function() {
      var fileHandle = document.getElementById("jsonFilePicker").files[0];
      var fileRead = new FileReader();
      fileRead.onload = function(e) {
        jsonObject = JSON.parse(e.target.result);
        for (i = 0; i < jsonObject.licenses.length; i++) {
          var license = jsonObject.licenses[i].name;
          var eleleading = document.createElement("option");
          var elesubordinate = document.createElement("option");
          eleleading.textContent = elesubordinate.textContent = license;
          selectleading.appendChild(eleleading);
          selectsubordinate.appendChild(elesubordinate);
        }
      };
      fileRead.readAsText(fileHandle);
    });
    function showcompatibility()
    {
      var leadingselectbox = document.getElementById("selectleadinglicense");
      var subordinateselectbox = document.getElementById("selectsubordinatelicense");
      var result = document.getElementById("result");
      var help = document.getElementById("help");
      var compatibility;
      if (leadingselectbox.selectedIndex == 0 || subordinateselectbox.selectedIndex == 0) {
        result.innerHTML = "";
        help.innerHTML = "";
        return;
      }
      compatibility = jsonObject.licenses[leadingselectbox.selectedIndex-1].compatibilities[subordinateselectbox.selectedIndex-1].compatibility;
      explanation = jsonObject.licenses[leadingselectbox.selectedIndex-1].compatibilities[subordinateselectbox.selectedIndex-1].explanation;
      result.style.fontWeight = "bold";
      if (compatibility == "Yes")
        result.style.color = "green";
      else if (compatibility == "No")
        result.style.color = "red";
      else if (compatibility == "Check dependency")
        result.style.color = "rgb(172, 172, 0)";
      else {
        result.style.color = "black";
        result.style.fontWeight = "normal";
      }
      if (compatibility == "Same") {
        result.innerHTML = "";
        help.innerHTML = "";
      } else {
        result.innerHTML = "<b>Compatibility:</b> " + compatibility;
        help.innerHTML = "<br /><br /><b>Reference:</b><br />" + explanation;
      }
    }
 
 </script>
  </body>
</html>

 

3. PHP script to generate a list of compatible and incompatible licenses of a given leading license

Without explanations - With explanations

Widget in action