semanticwfs  Version 0.1.0.0
XSLTTransformer Class Reference

A class performing XSLT transformations on XML files and XSD schema validations. More...

Static Public Member Functions

static Boolean validateAgainstXSDSchema (String inputStr, String schemapath) throws SAXException, IOException
 Validates an XML file given as a String against an XSD schema given by a filepath to it on the harddisk. More...
 
static String gmdToGeoDCAT (String source) throws TransformerException
 Converts a GMD representation to GeoDCAT using the GDM2GeoDCAT XSLT file. More...
 
static String GeoDCATToHTML (String source) throws TransformerException
 Performs a transformation from GeoDCAT XML to GeoDCAT in HTML. More...
 

Detailed Description

A class performing XSLT transformations on XML files and XSD schema validations.

Member Function Documentation

◆ GeoDCATToHTML()

static String GeoDCATToHTML ( String  source) throws TransformerException
static

Performs a transformation from GeoDCAT XML to GeoDCAT in HTML.

Parameters
sourcethe GeoDCAT XML representation as String
Returns
the HTML representation as a String
Exceptions
TransformerExceptionwhen transformation errors occur
77  {
78  System.out.println("Source: " + source);
79  InputStreamReader input = new InputStreamReader(new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)));
80  TransformerFactory tFactory = new net.sf.saxon.TransformerFactoryImpl();
81  Source xmlSource = new StreamSource(input);
82  Source xslSource = new StreamSource(new File("dcat-ap-rdf2rdfa.xsl"));
83  StringWriter outWriter = new StringWriter();
84  StreamResult fOutresult = new StreamResult( outWriter );
85  Transformer transformer = tFactory.newTransformer(xslSource);
86  transformer.transform(xmlSource, fOutresult);
87  return outWriter.toString();
88  }

Referenced by DCATFormatter.formatter().

◆ gmdToGeoDCAT()

static String gmdToGeoDCAT ( String  source) throws TransformerException
static

Converts a GMD representation to GeoDCAT using the GDM2GeoDCAT XSLT file.

Parameters
sourceA String representing a GMD XML document
Returns
A GeoDCAT representation as XML
Exceptions
TransformerExceptionwhen transformation errors occur
58  {
59  System.out.println("Source: " + source);
60  InputStreamReader input = new InputStreamReader(new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)));
61  TransformerFactory tFactory = new net.sf.saxon.TransformerFactoryImpl();
62  Source xmlSource = new StreamSource(input);
63  Source xslSource = new StreamSource(new File("gmd2geodcat.xsl"));
64  StringWriter outWriter = new StringWriter();
65  StreamResult fOutresult = new StreamResult( outWriter );
66  Transformer transformer = tFactory.newTransformer(xslSource);
67  transformer.transform(xmlSource, fOutresult);
68  return outWriter.toString();
69  }

Referenced by DCATFormatter.formatter().

◆ validateAgainstXSDSchema()

static Boolean validateAgainstXSDSchema ( String  inputStr,
String  schemapath 
) throws SAXException, IOException
static

Validates an XML file given as a String against an XSD schema given by a filepath to it on the harddisk.

Parameters
inputStrThe XML document to verify
schemapathThe path to the XSD schema
Returns
True if the validation was successful, False otherwise
Exceptions
SAXExceptionon parsing errors
IOExceptionon reading errors
37  {
38  SchemaFactory factory =
39  SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
40  Schema schema = factory.newSchema(new File(schemapath));
41  Validator validator = schema.newValidator();
42  InputStreamReader input = new InputStreamReader(new ByteArrayInputStream(inputStr.getBytes(StandardCharsets.UTF_8)));
43  try {
44  validator.validate(new StreamSource(input));
45  return true;
46  } catch (SAXException e) {
47  e.printStackTrace();
48  return false;
49  }
50  }