Skip to content
Snippets Groups Projects
Commit fd1cb0c0 authored by Baptiste Toulemonde's avatar Baptiste Toulemonde
Browse files

Merge branch 'testXslt' into 'master'

add endpoint to convert csw iso 19115 to rdf xml

See merge request !9
parents d6e1ec1e 11541347
No related branches found
No related tags found
1 merge request!9add endpoint to convert csw iso 19115 to rdf xml
package com.smartharvester.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.smartharvester.service.MappingFromIsoService;
import io.swagger.v3.oas.annotations.tags.Tag;
@CrossOrigin(origins = "*")
@RequestMapping("/harvester/api/transform")
@Tag(name = "Harvest",description = "transform xml iso 19115 to RDF")
@RestController
public class SmartHarvesterTransformerController {
@Autowired
private MappingFromIsoService mappingService;
@GetMapping
public ResponseEntity<String> transformXmlToRdf(@RequestParam (value="url") String url, @RequestParam (value="catalogId") String catalogId) {
try {
return ResponseEntity.ok().body(this.mappingService.mapfromCWStoRDF(url, catalogId));
} catch (Exception e) {
return ResponseEntity.badRequest().body("ERROR " + e.getMessage());
}
}
}
package com.smartharvester.service;
import java.io.StringWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.springframework.stereotype.Service;
@Service
public class MappingFromIsoService {
public String mapfromCWStoRDF(String url, String catalogId) throws Exception {
StreamSource xslt = new StreamSource("https://raw.githubusercontent.com/baptiste-Cines/tesXsl/master/test.xsl");
StreamSource xml = new StreamSource(url);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xslt);
transformer.setParameter("catalogId", catalogId);
transformer.setParameter("outputSchema", "extended");
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
transformer.transform(xml, result);
return writer.toString();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment