-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extensibility of common preview formats via beans (#3521)
- Loading branch information
1 parent
acfdccc
commit 2c1d5c4
Showing
11 changed files
with
277 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/web/demo/src/main/java/org/geoserver/web/demo/CommonFormatLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* (c) 2019 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.web.demo; | ||
|
||
import org.apache.wicket.markup.html.link.ExternalLink; | ||
import org.geoserver.web.ToolLinkExternalInfo; | ||
|
||
/** | ||
* Extension point for MapPreviewPage. Subclasses will implement getFormatLink which returns an | ||
* ExternalLink to a layer preview in the subclass format represented by the subclass e.g. | ||
* GMLFormatLink. | ||
* | ||
* @author prushforth | ||
*/ | ||
public abstract class CommonFormatLink extends ToolLinkExternalInfo | ||
implements Comparable<CommonFormatLink> { | ||
|
||
private final String componentId = "theLink"; | ||
|
||
private int order = 1000; | ||
|
||
public CommonFormatLink() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Returns an ExternalLink object that is used to link to the layer preview. | ||
* | ||
* @param layer the PreviewLayer object for which the preview link is returned | ||
* @return | ||
*/ | ||
public abstract ExternalLink getFormatLink(PreviewLayer layer); | ||
|
||
@Override | ||
public void setComponentClass(Class<ExternalLink> componentClass) {} | ||
|
||
public String getComponentId() { | ||
return componentId; | ||
} | ||
|
||
/** | ||
* @param order orders the list of common formats, by default new formats will be added at the | ||
* of the list. | ||
*/ | ||
public void setOrder(int order) { | ||
this.order = order; | ||
} | ||
|
||
public int getOrder() { | ||
return order; | ||
} | ||
|
||
@Override | ||
public int compareTo(CommonFormatLink other) { | ||
return getOrder() - other.getOrder(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/web/demo/src/main/java/org/geoserver/web/demo/GMLFormatLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* (c) 2019 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.web.demo; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.wicket.Component; | ||
import org.apache.wicket.markup.html.link.ExternalLink; | ||
import org.apache.wicket.model.StringResourceModel; | ||
import org.geoserver.config.GeoServer; | ||
import org.geoserver.web.demo.PreviewLayer.GMLOutputParams; | ||
import org.geoserver.web.demo.PreviewLayer.PreviewLayerType; | ||
import org.geoserver.wfs.WFSInfo; | ||
|
||
public class GMLFormatLink extends CommonFormatLink { | ||
|
||
private GeoServer geoserver; | ||
|
||
/** GML output params computation may be expensive, results are cached in this map */ | ||
private final transient Map<String, GMLOutputParams> gmlParamsCache = | ||
new HashMap<String, GMLOutputParams>(); | ||
|
||
@Override | ||
public ExternalLink getFormatLink(PreviewLayer layer) { | ||
ExternalLink gmlLink = | ||
new ExternalLink( | ||
this.getComponentId(), | ||
layer.getGmlLink(gmlParamsCache) + this.getMaxFeatures(), | ||
(new StringResourceModel(this.getTitleKey(), (Component) null, null)) | ||
.getString()); | ||
gmlLink.setVisible( | ||
layer.getType() == PreviewLayerType.Vector && layer.hasServiceSupport("WFS")); | ||
return gmlLink; | ||
} | ||
|
||
/** | ||
* Generates the maxFeatures element of the WFS request using the value of | ||
* maxNumberOfFeaturesForPreview. Values <= 0 give no limit. | ||
* | ||
* @return "&maxFeatures=${maxNumberOfFeaturesForPreview}" or "" if | ||
* maxNumberOfFeaturesForPreview <= 0" | ||
*/ | ||
private String getMaxFeatures() { | ||
WFSInfo service = geoserver.getService(WFSInfo.class); | ||
if (service.getMaxNumberOfFeaturesForPreview() > 0) { | ||
return "&maxFeatures=" + service.getMaxNumberOfFeaturesForPreview(); | ||
} | ||
return ""; | ||
} | ||
|
||
public void setGeoserver(GeoServer geoserver) { | ||
this.geoserver = geoserver; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/web/demo/src/main/java/org/geoserver/web/demo/KMLFormatLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* (c) 2019 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.web.demo; | ||
|
||
import org.apache.wicket.Component; | ||
import org.apache.wicket.markup.html.link.ExternalLink; | ||
import org.apache.wicket.model.StringResourceModel; | ||
|
||
public class KMLFormatLink extends CommonFormatLink { | ||
|
||
@Override | ||
public ExternalLink getFormatLink(PreviewLayer layer) { | ||
ExternalLink kmlLink = | ||
new ExternalLink( | ||
this.getComponentId(), | ||
layer.getWmsLink() + "/kml?layers=" + layer.getName(), | ||
(new StringResourceModel(this.getTitleKey(), (Component) null, null)) | ||
.getString()); | ||
kmlLink.setVisible(layer.hasServiceSupport("WMS")); | ||
return kmlLink; | ||
} | ||
} |
70 changes: 36 additions & 34 deletions
70
src/web/demo/src/main/java/org/geoserver/web/demo/MapPreviewPage.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,36 @@ | ||
<html xmlns:wicket="http://wicket.apache.org/"> | ||
<head> | ||
<title><wicket:message key="page.title">Layer Preview</wicket:message></title> | ||
</head> | ||
<body> | ||
<wicket:extend> | ||
<!-- the table component --> | ||
<div wicket:id="table"></div> | ||
|
||
<!-- The fragment for the icon --> | ||
<wicket:fragment wicket:id="iconFragment"> | ||
<img wicket:id="layerIcon"/> | ||
</wicket:fragment> | ||
|
||
<!-- The fragment for the common links --> | ||
<wicket:fragment wicket:id="commonLinks"> | ||
<div style="white-space: nowrap;"><a target="_blank" wicket:id="ol"></a> <a target="_blank" wicket:id="kml"></a> <a target="_blank" wicket:id="gml"></a></div> | ||
</wicket:fragment> | ||
|
||
<!-- The custom drop down with optgroups --> | ||
<wicket:fragment wicket:id="menuFragment"> | ||
<select wicket:id="menu"> | ||
<option><wicket:message key="selectOne">Select one</wicket:message></option> | ||
<optgroup label="WMS" wicket:id="wms"> | ||
<option wicket:id="wmsFormats"></option> | ||
</optgroup> | ||
<optgroup label="WFS" wicket:id="wfs"> | ||
<option wicket:id="wfsFormats"></option> | ||
</optgroup> | ||
</select> | ||
</wicket:fragment> | ||
</wicket:extend> | ||
</body> | ||
</html> | ||
<html xmlns:wicket="http://wicket.apache.org/"> | ||
<head> | ||
<title><wicket:message key="page.title">Layer Preview</wicket:message></title> | ||
</head> | ||
<body> | ||
<wicket:extend> | ||
<!-- the table component --> | ||
<div wicket:id="table"></div> | ||
|
||
<!-- The fragment for the icon --> | ||
<wicket:fragment wicket:id="iconFragment"> | ||
<img wicket:id="layerIcon"/> | ||
</wicket:fragment> | ||
|
||
<!-- The fragment for the common links --> | ||
<wicket:fragment wicket:id="commonLinks"> | ||
<span style="white-space: nowrap;" wicket:id="commonFormat"> | ||
<a target="_blank" href="#" wicket:id="theLink">theTitle</a> | ||
</span> | ||
</wicket:fragment> | ||
|
||
<!-- The custom drop down with optgroups --> | ||
<wicket:fragment wicket:id="menuFragment"> | ||
<select wicket:id="menu"> | ||
<option><wicket:message key="selectOne">Select one</wicket:message></option> | ||
<optgroup label="WMS" wicket:id="wms"> | ||
<option wicket:id="wmsFormats"></option> | ||
</optgroup> | ||
<optgroup label="WFS" wicket:id="wfs"> | ||
<option wicket:id="wfsFormats"></option> | ||
</optgroup> | ||
</select> | ||
</wicket:fragment> | ||
</wicket:extend> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.