TransformFF extends FunctionBase3 { @Override public NodeValue exec(NodeValue v1, NodeValue v2, NodeValue v3) { try { if (!(v2.isIRI() || v2.isString())) { throw new ExprEvalException("Not a URI: " + FmtUtils.stringForNode(v2.asNode())); } if (!(v3.isIRI() || v3.isString())) { throw new ExprEvalException("Not a URI: " + FmtUtils.stringForNode(v3.asNode())); } String datatypeURI; if (v2.isIRI()) { datatypeURI = v2.asNode().getURI(); } else { datatypeURI = v2.asString(); } String srsURI; if (v3.isIRI()) { srsURI = v3.asNode().getURI(); } else { srsURI = v3.asString(); } GeometryWrapper geometry = GeometryWrapper.extract(v1, GeometryLiteralIndex.GeometryIndex.PRIMARY); GeometryWrapper convertedGeom = geometry.transform(srsURI); Literal convertedGeomLit = convertedGeom.asLiteral(datatypeURI); return NodeValue.makeNode(convertedGeomLit.getLexicalForm(), convertedGeomLit.getDatatype()); } catch (DatatypeFormatException | TransformException | FactoryException ex) { throw new ExprEvalException(ex.getMessage(), ex); } }  @Override NodeValue exec(NodeValue v1, NodeValue v2, NodeValue v3);  }
@Test public void testExec_string_string() { NodeValue v1 = NodeValue.makeNode("<gml:Point xmlns:gml=\"http: NodeValue v2 = NodeValue.makeString(WKTDatatype.URI); NodeValue v3 = NodeValue.makeString(SRS_URI.DEFAULT_WKT_CRS84); TransformFF instance = new TransformFF(); NodeValue expResult = NodeValue.makeNode("POINT(10 0)", WKTDatatype.INSTANCE); NodeValue result = instance.exec(v1, v2, v3); assertEquals(expResult, result); }
@Test public void testExec_string_URI() { NodeValue v1 = NodeValue.makeNode("<gml:Point xmlns:gml=\"http: NodeValue v2 = NodeValue.makeString(WKTDatatype.URI); NodeValue v3 = NodeValue.makeNode(NodeFactory.createURI(SRS_URI.DEFAULT_WKT_CRS84)); TransformFF instance = new TransformFF(); NodeValue expResult = NodeValue.makeNode("POINT(10 0)", WKTDatatype.INSTANCE); NodeValue result = instance.exec(v1, v2, v3); assertEquals(expResult, result); }
@Test public void testExec_URI_string() { NodeValue v1 = NodeValue.makeNode("<gml:Point xmlns:gml=\"http: NodeValue v2 = NodeValue.makeNode(NodeFactory.createURI(WKTDatatype.URI)); NodeValue v3 = NodeValue.makeString(SRS_URI.DEFAULT_WKT_CRS84); TransformFF instance = new TransformFF(); NodeValue expResult = NodeValue.makeNode("POINT(10 0)", WKTDatatype.INSTANCE); NodeValue result = instance.exec(v1, v2, v3); assertEquals(expResult, result); }
@Test public void testExec_URI_URI() { NodeValue v1 = NodeValue.makeNode("<gml:Point xmlns:gml=\"http: NodeValue v2 = NodeValue.makeNode(NodeFactory.createURI(WKTDatatype.URI)); NodeValue v3 = NodeValue.makeNode(NodeFactory.createURI(SRS_URI.DEFAULT_WKT_CRS84)); TransformFF instance = new TransformFF(); NodeValue expResult = NodeValue.makeNode("POINT(10 0)", WKTDatatype.INSTANCE); NodeValue result = instance.exec(v1, v2, v3); assertEquals(expResult, result); }
@Test(expected = ExprEvalException.class) public void testExec_fail() { NodeValue v1 = NodeValue.makeNode("<gml:Point xmlns:gml=\"http: NodeValue v2 = NodeValue.makeInteger(8); NodeValue v3 = NodeValue.makeNode(NodeFactory.createURI(SRS_URI.DEFAULT_WKT_CRS84)); TransformFF instance = new TransformFF(); NodeValue expResult = NodeValue.makeNode("POINT(10 0)", WKTDatatype.INSTANCE); NodeValue result = instance.exec(v1, v2, v3); assertEquals(expResult, result); }
@Test(expected = ExprEvalException.class) public void testExec_fail2() { NodeValue v1 = NodeValue.makeNode("<gml:Point xmlns:gml=\"http: NodeValue v2 = NodeValue.makeNode(NodeFactory.createURI(WKTDatatype.URI)); NodeValue v3 = NodeValue.makeInteger(8); TransformFF instance = new TransformFF(); NodeValue expResult = NodeValue.makeNode("POINT(10 0)", WKTDatatype.INSTANCE); NodeValue result = instance.exec(v1, v2, v3); assertEquals(expResult, result); }