Skip to content

Commit

Permalink
Merge pull request #25 from spdx/addjsonldwebsite
Browse files Browse the repository at this point in the history
Add JSON-LD format to website
  • Loading branch information
goneall authored Apr 13, 2018
2 parents dfd6852 + b634d8c commit 7b196ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private static void writeRdf(IModelContainer container, File rdfXml, File rdfTur
* @param format Jena RDF format
* @throws LicenseGeneratorException
*/
private static void writeRdf(IModelContainer container, String fileName, String format) throws LicenseGeneratorException {
public static void writeRdf(IModelContainer container, String fileName, String format) throws LicenseGeneratorException {
File outFile = new File(fileName);
if (!outFile.exists()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
import org.spdx.html.LicenseJSONFile;
import org.spdx.html.LicenseTOCHTMLFile;
import org.spdx.html.LicenseTOCJSONFile;
import org.spdx.rdfparser.InvalidSPDXAnalysisException;
import org.spdx.rdfparser.license.AnyLicenseInfo;
import org.spdx.rdfparser.license.LicenseException;
import org.spdx.rdfparser.license.SpdxListedLicense;
import org.spdx.spdxspreadsheet.SPDXLicenseSpreadsheet.DeprecatedLicenseInfo;
import org.spdx.licenselistpublisher.LicenseContainer;
import org.spdx.licenselistpublisher.LicenseGeneratorException;

import com.github.mustachejava.MustacheException;
Expand Down Expand Up @@ -224,6 +227,15 @@ public void writeLicense(SpdxListedLicense license, boolean deprecated, String d
} else {
tableOfContentsHTML.addLicense(license, licHTMLReference);
}
// JSON-LD format
LicenseContainer onlyThisLicense = new LicenseContainer();
AnyLicenseInfo licenseClone = license.clone();
try {
licenseClone.createResource(onlyThisLicense);
} catch (InvalidSPDXAnalysisException e) {
throw new LicenseGeneratorException("SPDX Analysis error cloning license: "+e.getMessage(),e);
}
LicenseRdfFormatWriter.writeRdf(onlyThisLicense, websiteFolder.getPath() + File.separator + licBaseHtmlFileName + ".jsonld", "JSON-LD");
}

/* (non-Javadoc)
Expand All @@ -243,7 +255,7 @@ public void writeToC() throws IOException {

@Override
public void writeException(LicenseException exception, boolean deprecated, String deprecatedVersion)
throws IOException, InvalidLicenseTemplateException {
throws IOException, InvalidLicenseTemplateException, LicenseGeneratorException {
ExceptionHtml exceptionHtml = new ExceptionHtml(exception);
String exceptionHtmlFileName = LicenseHtmlFormatWriter.formLicenseHTMLFileName(exception.getLicenseExceptionId());
String exceptionHTMLReference = "./"+exceptionHtmlFileName + ".html";
Expand All @@ -257,5 +269,14 @@ public void writeException(LicenseException exception, boolean deprecated, Strin
exceptionJson.setException(exception, deprecated);
File exceptionJsonFile = new File(websiteFolder.getPath() + File.separator + exceptionJsonFileName);
exceptionJson.writeToFile(exceptionJsonFile);
// JSON-LD format
LicenseException exceptionClone = exception.clone();
LicenseContainer onlyThisException = new LicenseContainer();
try {
exceptionClone.createResource(onlyThisException);
} catch (InvalidSPDXAnalysisException e) {
throw new LicenseGeneratorException("SPDX Analysis error cloning exception: "+e.getMessage(),e);
}
LicenseRdfFormatWriter.writeRdf(onlyThisException, websiteFolder.getPath() + File.separator + exceptionHtmlFileName + ".jsonld", "JSON-LD");
}
}

0 comments on commit 7b196ef

Please # to comment.