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

Added support of XSLT 2.0 #999

Merged
merged 5 commits into from
Jan 24, 2020
Merged
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
4 changes: 0 additions & 4 deletions deegree-core/deegree-core-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this specific xerces dependency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xerces is used only in deegree-core-commons.

<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
12 changes: 4 additions & 8 deletions deegree-core/deegree-core-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
Expand Down Expand Up @@ -103,14 +107,6 @@
<groupId>org.deegree</groupId>
<artifactId>deegree-ogcschemas</artifactId>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>serializer</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.deegree.commons.xml;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;

import javax.xml.transform.TransformerFactory;

import org.junit.Test;

/**
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
public class XsltUtilsTest {

@Test
public void verifyXslt_20_ImplementationIsAvailable() {
TransformerFactory factory = TransformerFactory.newInstance();
assertThat( factory, is( instanceOf( net.sf.saxon.TransformerFactoryImpl.class ) ) );
}

@Test
public void testXslt10()
throws Exception {
InputStream docToTransform = XsltUtilsTest.class.getResourceAsStream( "feature.gml" );
URL xslt = XsltUtilsTest.class.getResource( "featureToHtml-Xslt10.xslt" );
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XsltUtils.transform( docToTransform, xslt, bos );
bos.close();

assertThat( bos.toString(), containsString( "Identifier: i1 Name: feature name 1 Props: 1a, 1b" ) );
assertThat( bos.toString(), containsString( "Identifier: i2 Name: feature name 2 Props: 2a, 2b, 2c" ) );
}

@Test
public void testXslt20()
throws Exception {
InputStream docToTransform = XsltUtilsTest.class.getResourceAsStream( "feature.gml" );
URL xslt = XsltUtilsTest.class.getResource( "featureToHtml-Xslt20.xslt" );
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XsltUtils.transform( docToTransform, xslt, bos );
bos.close();

assertThat( bos.toString(), containsString( "Identifier: i1 Name: feature name 1 Props: 1a, 1b" ) );
assertThat( bos.toString(), containsString( "Identifier: i2 Name: feature name 2 Props: 2a, 2b, 2c" ) );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<gml:FeatureCollection xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:app="http://deegree.org/app">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:25833">
<gml:lowerCorner>334830.868300 5871407.128200</gml:lowerCorner>
<gml:upperCorner>358634.056200 5900836.645100</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<app:Instance gml:id="Instance_1">
<app:identifier>i1</app:identifier>
<app:name>feature name 1</app:name>
<app:prop1>1a</app:prop1>
<app:prop1>1b</app:prop1>
</app:Instance>
</gml:featureMember>
<gml:featureMember>
<app:Instance gml:id="Instance_2">
<app:identifier>i2</app:identifier>
<app:name>feature name 2</app:name>
<app:prop1>2a</app:prop1>
<app:prop1>2b</app:prop1>
<app:prop1>2c</app:prop1>
</app:Instance>
</gml:featureMember>
</gml:FeatureCollection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:app="http://deegree.org/app">

<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
<html lang="de">
<head/>
<body>
<div>
<ul>
<xsl:for-each select="//app:Instance">
<xsl:apply-templates select="."/>
</xsl:for-each>
</ul>
</div>
</body>
</html>
</xsl:template>

<xsl:template match="app:Instance">
<li>
<xsl:text>Identifier: </xsl:text>
<xsl:value-of select="app:identifier"/>
<xsl:text> Name: </xsl:text>
<xsl:value-of select="app:name"/>
<xsl:text> Props: </xsl:text>
<xsl:for-each select="app:prop1">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>
</li>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:app="http://deegree.org/app">

<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
<html lang="de">
<head/>
<body>
<h1>Ergebnis GFI</h1>
<div>
<ul>
<xsl:for-each select="//app:Instance">
<xsl:apply-templates select="."/>
</xsl:for-each>
</ul>
</div>
</body>
</html>
</xsl:template>

<xsl:template match="app:Instance">
<li>
<xsl:text> </xsl:text>
<xsl:value-of select="('Identifier:', app:identifier, 'Name:', app:name)" separator=" "/>
<xsl:text> Props: </xsl:text>
<xsl:value-of select="app:prop1" separator=", "/>
</li>
</xsl:template>
</xsl:stylesheet>
4 changes: 0 additions & 4 deletions deegree-core/deegree-core-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
<dependency>
<groupId>jai</groupId>
<artifactId>jai-codec</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@
<artifactId>deegree-core-layer</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions deegree-services/deegree-services-wms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@
<artifactId>deegree-core-filterfunctions</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
<dependency>
<groupId>org.deegree</groupId>
<artifactId>deegree-mdstore-commons</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/REC-html40"
xmlns:wms="http://www.opengis.net/wms">
xmlns:wms="http://www.opengis.net/wms" version="1.0">

<xsl:output method="html" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/REC-html40"
xmlns:ogc="http://www.opengis.net/ogc">
xmlns:ogc="http://www.opengis.net/ogc" version="1.0">

<xsl:output method="html" />

Expand Down
4 changes: 0 additions & 4 deletions deegree-tools/deegree-tools-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
<artifactId>deegree-featurestore-sql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
<dependency>
<groupId>org.deegree</groupId>
<artifactId>deegree-mdstore-iso</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.List;

import javax.xml.stream.XMLStreamException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.deegree.commons.xml.XsltUtils;
import org.deegree.services.OWS;
import org.deegree.services.OwsManager;
import org.deegree.services.wms.controller.WMSController;
Expand All @@ -68,27 +66,22 @@
*/
public class ThemeExtractor {

private final Workspace workspace;

private Transformer transformer;

public ThemeExtractor( Workspace workspace ) throws TransformerConfigurationException {
this.workspace = workspace;
TransformerFactory fac = TransformerFactory.newInstance();
InputStream xsl = ThemeExtractor.class.getResourceAsStream( "extracttheme.xsl" );
this.transformer = fac.newTransformer( new StreamSource( xsl ) );
private ThemeExtractor() {
}

public void transform()
throws TransformerException, XMLStreamException {
public static void transform( Workspace workspace )
throws TransformerException, XMLStreamException, URISyntaxException, IOException {
OwsManager mgr = workspace.getResourceManager( OwsManager.class );
List<OWS> wmss = mgr.getByOWSClass( WMSController.class );
for ( OWS ows : wmss ) {
ResourceMetadata<? extends Resource> md = ows.getMetadata();
ResourceIdentifier<? extends Resource> id = md.getIdentifier();
File loc = md.getLocation().resolveToFile( id.getId() + ".xml" );
ByteArrayOutputStream bos = new ByteArrayOutputStream();
transformer.transform( new StreamSource( loc ), new StreamResult( bos ) );

FileInputStream doc = new FileInputStream( loc );
XsltUtils.transform( doc, ThemeExtractor.class.getResource( "extracttheme.xsl" ), bos );
doc.close();

ThemeXmlStreamEncoder.writeOut( bos );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void main( String[] args ) {
ws = new DefaultWorkspace( wsloc );
ws.initAll();
new FeatureLayerExtractor( ws ).extract();
new ThemeExtractor( ws ).transform();
ThemeExtractor.transform(ws);
} catch ( Throwable e ) {
System.out.println( "There was a problem transforming the configuration." );
e.printStackTrace();
Expand Down
19 changes: 6 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -654,19 +654,7 @@
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>serializer</artifactId>
<version>2.7.2</version>
<scope>runtime</scope>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>de.odysseus.staxon</groupId>
Expand All @@ -683,6 +671,11 @@
<artifactId>netty</artifactId>
<version>3.2.10.Final</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>9.9.1-4</version>
</dependency>
<!-- JAI -->
<dependency>
<groupId>jai</groupId>
Expand Down