Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,13 @@ Occam Labs UG (haftungsbeschränkt)
*
* @author <a href="mailto:schmitz@occamlabs.de">Andreas Schmitz</a>
*/
public class FeatureInfoParams {

private Map<String, String> nsBindings;

private FeatureCollection featureCollection;

private String format;

private boolean withGeometries;

private String schemaLocation;

private FeatureType featureType;

private ICRS crs;

private final ICRS infoCrs;
public record FeatureInfoParams(Map<String, String> nsBindings, FeatureCollection featureCollection, String format,
boolean withGeometries, String schemaLocation, FeatureType featureType, ICRS crs, ICRS infoCrs,
String gfiTemplate) {

public FeatureInfoParams(Map<String, String> nsBindings, FeatureCollection col, String format,
boolean withGeometries, String schemaLocation, FeatureType type, ICRS crs, ICRS infoCrs) {
this.nsBindings = nsBindings;
this.featureCollection = col;
this.format = format;
this.withGeometries = withGeometries;
this.schemaLocation = schemaLocation;
this.featureType = type;
this.crs = crs;
this.infoCrs = infoCrs;
this(nsBindings, col, format, withGeometries, schemaLocation, type, crs, infoCrs, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public TemplateFeatureInfoSerializer(final String fiFile) {

@Override
public void serialize(FeatureInfoParams params, FeatureInfoContext context) throws IOException, XMLStreamException {

runTemplate(context.getOutputStream(), fiFile, params.getFeatureCollection(), params.isWithGeometries());
runTemplate(context.getOutputStream(), fiFile, params.getFeatureCollection(), params.isWithGeometries(),
params.gfiTemplate());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.deegree.featureinfo.templating;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ServiceLoader;

import org.deegree.featureinfo.FeatureInfoManager;

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

private static final ServiceLoader<GfiTemplateProvider> gfiTemplateProviderLoader;

static {
gfiTemplateProviderLoader = ServiceLoader.load(GfiTemplateProvider.class);
for (GfiTemplateProvider gfiTemplateProvider : gfiTemplateProviderLoader) {
gfiTemplateProvider.init();
}
}

/**
* @param gfiFile to retrieve the template from, may be <code>null</code>
* @param gfiTemplateParam the value of the gfiTemplate parameter, may be
* <code>null</code>
* @return the template from the gfiTemplateParam, if available or from the gfiFile if
* not <code>null</code>, if both are <code>null</code> or not available the default
* 'html.gfi' is returned
* @throws FileNotFoundException if the gfiFile could not be found
*/
InputStream retrieveTemplate(String gfiFile, String gfiTemplateParam) throws FileNotFoundException {
if (gfiTemplateParam != null && !gfiTemplateParam.isEmpty()) {
for (GfiTemplateProvider gfiTemplateProvider : gfiTemplateProviderLoader) {
InputStream gfiTemplateFromProvider = gfiTemplateProvider.retrieveTemplate(gfiTemplateParam);
if (gfiTemplateFromProvider != null)
return gfiTemplateFromProvider;
}
}
if (gfiFile == null) {
return FeatureInfoManager.class.getResourceAsStream("html.gfi");
}
return new FileInputStream(gfiFile);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.deegree.featureinfo.templating;

import java.io.InputStream;

/**
* Implementations of this class provides gfi templates from a passed query param.
*
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
public interface GfiTemplateProvider {

/**
* Called once to initialize the GfiTemplateProvider
*/
void init();

/**
* @param gfiTemplateParam the value of the query param, never <code>null</code>
* @return the content associated to the query param, may be <code>null</code> if not
* retrievable or parseable
*/
InputStream retrieveTemplate(String gfiTemplateParam);

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@ Occam Labs UG (haftungsbeschränkt)
import static java.util.Collections.singletonList;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;

import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.deegree.feature.FeatureCollection;
import org.deegree.featureinfo.FeatureInfoManager;
import org.deegree.featureinfo.templating.lang.PropertyTemplateCall;
import org.slf4j.Logger;

Expand All @@ -68,18 +66,12 @@ public class TemplatingUtils {

private static final Logger LOG = getLogger(TemplatingUtils.class);

public static void runTemplate(OutputStream response, String fiFile, FeatureCollection col, boolean geometries)
throws IOException {
PrintWriter out = new PrintWriter(new OutputStreamWriter(response, "UTF-8"));
public static void runTemplate(OutputStream response, String fiFile, FeatureCollection col, boolean geometries,
String gfiTemplateParam) {
PrintWriter out = new PrintWriter(new OutputStreamWriter(response, StandardCharsets.UTF_8));

try {
InputStream in;
if (fiFile == null) {
in = FeatureInfoManager.class.getResourceAsStream("html.gfi");
}
else {
in = new FileInputStream(fiFile);
}
InputStream in = new GfiRetriever().retrieveTemplate(fiFile, gfiTemplateParam);

CharStream input = new ANTLRInputStream(in);
Templating2Lexer lexer = new Templating2Lexer(input);
Expand All @@ -90,7 +82,7 @@ public static void runTemplate(OutputStream response, String fiFile, FeatureColl

StringBuilder sb = new StringBuilder();
new PropertyTemplateCall("start", singletonList("*"), false).eval(sb, defs, col, geometries);
out.println(sb.toString());
out.println(sb);
}
catch (Throwable e) {
if (fiFile == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public class GetFeatureInfo extends RequestBase {

private double scale;

private String gfiTemplate;

/**
* @param map
* @param version
Expand Down Expand Up @@ -332,6 +334,7 @@ private double[] handleCommon(Map<String, String> map) throws OWSException {

returnGeometries = map.get("GEOMETRIES") != null && map.get("GEOMETRIES").equalsIgnoreCase("true");
infoCrs = map.get("INFO_CRS") != null ? CRSManager.getCRSRef(map.get("INFO_CRS")) : null;
gfiTemplate = map.get("GFI_TEMPLATE");

return vals;
}
Expand Down Expand Up @@ -442,6 +445,14 @@ public int getY() {
return y;
}

/**
* @return the gfi template (vendor specific parameter GFI_TEMPLATE), may be
* <code>null</code>
*/
public String getGfiTemplate() {
return gfiTemplate;
}

/**
* @return the original parameter map (might be empty if not constructed via request)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ private void doGetFeatureInfo(final HttpResponseBuffer response, Version version

try {
FeatureInfoParams params = new FeatureInfoParams(nsBindings, col, format, geometries, loc, type, crs,
infoCrs);
infoCrs, fi.getGfiTemplate());
featureInfoManager.serializeFeatureInfo(params, new StandardFeatureInfoContext(response));
response.flushBuffer();
}
Expand Down