Fix ImageMosaic Metadata pubblication and Encoder refactoring
This commit is contained in:
parent
35262dc51c
commit
99104c13cb
2
pom.xml
2
pom.xml
@ -31,7 +31,7 @@
|
||||
|
||||
<groupId>it.geosolutions</groupId>
|
||||
<artifactId>geoserver-manager</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<version>1.2-SNAPSHOT</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@ -26,11 +26,11 @@ package it.geosolutions.geoserver.rest;
|
||||
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTCoverageList;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSFeatureTypeEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -88,7 +88,7 @@ public class GeoServerRESTPublisher {
|
||||
public boolean createWorkspace(String workspace) {
|
||||
String sUrl = restURL + "/rest/workspaces";
|
||||
GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder(workspace);
|
||||
String wsxml = wsenc.encodeXml();
|
||||
String wsxml = wsenc.toString();
|
||||
String result = HTTPUtils.postXml(sUrl, wsxml, gsuser, gspass);
|
||||
return result != null;
|
||||
}
|
||||
@ -176,7 +176,7 @@ public class GeoServerRESTPublisher {
|
||||
*/
|
||||
public boolean createPostGISDatastore(String workspace, GSPostGISDatastoreEncoder datastoreEncoder) {
|
||||
String sUrl = restURL + "/rest/workspaces/" + workspace + "/datastores/";
|
||||
String xml = datastoreEncoder.encodeXml();
|
||||
String xml = datastoreEncoder.toString();
|
||||
String result = HTTPUtils.postXml(sUrl, xml, gsuser, gspass);
|
||||
return result != null;
|
||||
}
|
||||
@ -270,7 +270,7 @@ public class GeoServerRESTPublisher {
|
||||
fte.setName(layername);
|
||||
fte.setSRS(srs);
|
||||
|
||||
String configuredResult = HTTPUtils.putXml(postUrl.toString(), fte.encodeXml(), this.gsuser, this.gspass);
|
||||
String configuredResult = HTTPUtils.putXml(postUrl.toString(), fte.toString(), this.gsuser, this.gspass);
|
||||
boolean shpConfigured = configuredResult != null;
|
||||
|
||||
if (!shpConfigured) {
|
||||
@ -310,7 +310,7 @@ public class GeoServerRESTPublisher {
|
||||
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
|
||||
fte.setName(layername);
|
||||
fte.setSRS(srs); // srs=null?"EPSG:4326":srs);
|
||||
String ftypeXml = fte.encodeXml();
|
||||
String ftypeXml = fte.toString();
|
||||
|
||||
String configuredResult = HTTPUtils.postXml(postUrl.toString(), ftypeXml, this.gsuser, this.gspass);
|
||||
boolean published = configuredResult != null;
|
||||
@ -498,14 +498,14 @@ public class GeoServerRESTPublisher {
|
||||
try {
|
||||
// // retrieve coverage name
|
||||
GeoServerRESTReader reader = new GeoServerRESTReader(restURL, gsuser, gspass);
|
||||
RESTCoverageList covList = reader.getCoverages(workspace, storeName);
|
||||
RESTCoverageList covList = reader.getCoverages(store.getWorkspaceName(), storeName);
|
||||
if (covList.isEmpty()) {
|
||||
LOGGER.error("No coverages found in new coveragestore " + storeName);
|
||||
return null;
|
||||
}
|
||||
String coverageName = covList.get(0).getName();
|
||||
|
||||
configureCoverage(coverageEncoder, workspace, storeName, coverageName);
|
||||
configureCoverage(coverageEncoder, store.getWorkspaceName(), storeName, coverageName);
|
||||
configureLayer(layerEncoder, storeName);
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -709,7 +709,7 @@ public class GeoServerRESTPublisher {
|
||||
|
||||
final String url = restURL + "/rest/layers/" + layerName;
|
||||
|
||||
String layerXml = layer.encodeXml();
|
||||
String layerXml = layer.toString();
|
||||
String sendResult = HTTPUtils.putXml(url, layerXml, gsuser, gspass);
|
||||
if (sendResult != null) {
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
@ -730,7 +730,7 @@ public class GeoServerRESTPublisher {
|
||||
|
||||
final String url = restURL + "/rest/workspaces/" + wsname + "/coveragestores/" + csname + "/coverages/" + cname + ".xml";
|
||||
|
||||
String xmlBody = ce.encodeXml();
|
||||
String xmlBody = ce.toString();
|
||||
String sendResult = HTTPUtils.putXml(url, xmlBody, gsuser, gspass);
|
||||
if (sendResult != null) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
|
||||
@ -35,15 +35,16 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
|
||||
|
||||
public GSLayerEncoder() {
|
||||
super("layer");
|
||||
set("enabled", "true");
|
||||
// enable layer
|
||||
add("enabled","true");
|
||||
}
|
||||
|
||||
public void setWmsPath(String wmspath) {
|
||||
setOrRemove("wmspath", wmspath);
|
||||
}
|
||||
// public void setWmsPath(String wmspath) {
|
||||
// add("wmspath", wmspath);
|
||||
// }
|
||||
|
||||
public void setDefaultStyle(String defaultStyle) {
|
||||
setOrRemove("defaultStyle", defaultStyle);
|
||||
add("defaultStyle", defaultStyle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -27,7 +27,6 @@ package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.EntryKeyListEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
* Geoserver datastore XML encoder.
|
||||
@ -37,7 +36,7 @@ import org.jdom.Element;
|
||||
*/
|
||||
public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
||||
|
||||
private EntryKeyListEncoder connectionParameters = new EntryKeyListEncoder("connectionParameters");
|
||||
private EntryKeyListEncoder<String> connectionParameters = new EntryKeyListEncoder<String>("connectionParameters");
|
||||
|
||||
|
||||
public GSPostGISDatastoreEncoder() {
|
||||
@ -70,19 +69,19 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
setOrRemove("name", name);
|
||||
add("name", name);
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
setOrRemove("description", description);
|
||||
add("description", description);
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
setOrRemove("type", type);
|
||||
add("type", type);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
setOrRemove("enabled", Boolean.toString(enabled));
|
||||
add("enabled", Boolean.toString(enabled));
|
||||
}
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
@ -161,10 +160,4 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
||||
connectionParameters.add("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addNodesBeforeOutput(Element e) {
|
||||
super.addNodesBeforeOutput(e);
|
||||
connectionParameters.attachList(e);
|
||||
}
|
||||
|
||||
}
|
||||
@ -25,27 +25,83 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSMetadataEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.TextNodeListEncoder;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public abstract class GSResourceEncoder extends PropertyXMLEncoder {
|
||||
public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder> extends PropertyXMLEncoder {
|
||||
|
||||
final private GSMetadataEncoder<T> metadata=new GSMetadataEncoder<T>();
|
||||
|
||||
|
||||
protected GSResourceEncoder(String rootName) {
|
||||
super(rootName);
|
||||
}
|
||||
|
||||
public void setSRS(String srs) {
|
||||
setOrRemove("srs", srs);
|
||||
}
|
||||
public void addMetadata(String key, T dimensionInfo) {
|
||||
metadata.add(key, dimensionInfo);
|
||||
}
|
||||
|
||||
public void setLatLonBoundingBox(double minx, double maxy, double maxx, double miny, String crs) {
|
||||
setOrRemove("latLonBoundingBox/minx", String.valueOf(minx));
|
||||
setOrRemove("latLonBoundingBox/maxy", String.valueOf(maxy));
|
||||
setOrRemove("latLonBoundingBox/maxx", String.valueOf(maxx));
|
||||
setOrRemove("latLonBoundingBox/miny", String.valueOf(miny));
|
||||
setOrRemove("latLonBoundingBox/crs", crs);
|
||||
private TextNodeListEncoder keywordsListEncoder = new TextNodeListEncoder("keywords");
|
||||
|
||||
/**
|
||||
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
||||
*/
|
||||
public enum ProjectionPolicy {
|
||||
REPROJECT_TO_DECLARED, FORCE_DECLARED, NONE
|
||||
}
|
||||
|
||||
protected GSResourceEncoder(final String rootName) {
|
||||
super(rootName);
|
||||
add("enabled", "true");
|
||||
|
||||
// Link members to the parent
|
||||
addContent(metadata.getElement());
|
||||
addContent(keywordsListEncoder.getElement());
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
add("name", name);
|
||||
}
|
||||
|
||||
public void setTitle(final String title) {
|
||||
add("title", title);
|
||||
}
|
||||
|
||||
public void setSRS(final String srs) {
|
||||
add("srs", srs);
|
||||
}
|
||||
|
||||
public void setLatLonBoundingBox(double minx, double maxy, double maxx,
|
||||
double miny, final String crs) {
|
||||
add("latLonBoundingBox/minx", String.valueOf(minx));
|
||||
add("latLonBoundingBox/maxy", String.valueOf(maxy));
|
||||
add("latLonBoundingBox/maxx", String.valueOf(maxx));
|
||||
add("latLonBoundingBox/miny", String.valueOf(miny));
|
||||
add("latLonBoundingBox/crs", crs);
|
||||
}
|
||||
|
||||
public void setNativeBoundingBox(double minx, double maxy, double maxx,
|
||||
double miny, final String crs) {
|
||||
add("nativeBoundingBox/minx", String.valueOf(minx));
|
||||
add("nativeBoundingBox/maxy", String.valueOf(maxy));
|
||||
add("nativeBoundingBox/maxx", String.valueOf(maxx));
|
||||
add("nativeBoundingBox/miny", String.valueOf(miny));
|
||||
add("nativeBoundingBox/crs", crs);
|
||||
}
|
||||
|
||||
/**
|
||||
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
||||
*/
|
||||
public void setProjectionPolicy(ProjectionPolicy policy) {
|
||||
add("projectionPolicy", policy.toString());
|
||||
}
|
||||
|
||||
|
||||
public void addKeyword(String keyword) {
|
||||
keywordsListEncoder.add("string", keyword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,11 +25,14 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
||||
|
||||
@ -43,7 +46,15 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
setOrRemove("name", name);
|
||||
add("name", name);
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
final Element el=get("name");
|
||||
if (el!=null)
|
||||
return el.getName();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.coverage;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an XML
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*
|
||||
*/
|
||||
public class GSCoverageEncoder extends GSResourceEncoder<GSDimensionInfoEncoder> {
|
||||
|
||||
|
||||
final private Element parameters=new Element("parameters");
|
||||
|
||||
public GSCoverageEncoder() {
|
||||
super("coverage");
|
||||
// Link members to the parent
|
||||
addContent(parameters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param val
|
||||
*/
|
||||
public void setAllowMultithreading(final boolean val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("AllowMultithreading"));
|
||||
param.addContent(new Element("string").setText((val)?"true":"false"));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setFilter(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("Filter"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setMaxAllowedTiles(final int val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("MaxAllowedTiles"));
|
||||
param.addContent(new Element("string").setText(String.valueOf(val)));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setInputTransparentColor(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("InputTransparentColor"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setOutputTransparentColor(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("OutputTransparentColor"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setSUGGESTED_TILE_SIZE(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("SUGGESTED_TILE_SIZE"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setUSE_JAI_IMAGEREAD(final boolean val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("USE_JAI_IMAGEREAD"));
|
||||
param.addContent(new Element("string").setText((val)?"true":"false"));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setBackgroundValues(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("BackgroundValues"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package it.geosolutions.geoserver.rest.encoder.feature;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
|
||||
public class GSFeatureDimensionInfoEncoder extends GSDimensionInfoEncoder {
|
||||
|
||||
/**
|
||||
* if this dimension is enabled this constructor should be called.
|
||||
* @param attribute the attribute to use as dimension
|
||||
*/
|
||||
public GSFeatureDimensionInfoEncoder(final String attribute){
|
||||
super(true);
|
||||
add("attribute", attribute);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.feature;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class GSFeatureTypeEncoder extends GSResourceEncoder<GSFeatureDimensionInfoEncoder> {
|
||||
|
||||
public GSFeatureTypeEncoder() {
|
||||
super("featureType");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package it.geosolutions.geoserver.rest.encoder.metadata;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.TextNodeListEncoder;
|
||||
|
||||
public class GSDimensionInfoEncoder extends TextNodeListEncoder {
|
||||
final boolean enabled;
|
||||
|
||||
public enum Presentation{
|
||||
LIST,
|
||||
CONTINUOUS_INTERVAL
|
||||
}
|
||||
|
||||
public enum DiscretePresentation{
|
||||
DISCRETE_INTERVAL
|
||||
}
|
||||
|
||||
public GSDimensionInfoEncoder(final boolean enabled) {
|
||||
super("dimensionInfo");
|
||||
add("enabled", (enabled)?"true":"false");
|
||||
this.enabled=enabled;
|
||||
}
|
||||
|
||||
public GSDimensionInfoEncoder() {
|
||||
super("dimensionInfo");
|
||||
add("enabled", "false");
|
||||
this.enabled=Boolean.FALSE;
|
||||
}
|
||||
|
||||
public void setPresentation(final Presentation pres){
|
||||
if (enabled){
|
||||
add("presentation",pres.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void setPresentation(final DiscretePresentation pres, final BigDecimal interval){
|
||||
if (enabled){
|
||||
add("presentation",pres.toString());
|
||||
add("resolution",String.valueOf(interval));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package it.geosolutions.geoserver.rest.encoder.metadata;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.EntryKeyListEncoder;
|
||||
|
||||
public class GSMetadataEncoder <T extends GSDimensionInfoEncoder> extends EntryKeyListEncoder<T>{
|
||||
|
||||
public GSMetadataEncoder() {
|
||||
super("metadata");
|
||||
}
|
||||
|
||||
public void addMetadata(final String key, final T value) {
|
||||
this.add(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
@ -25,13 +25,14 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
* Encodes lists of entries with key attribute.
|
||||
* <br/>e.g.:
|
||||
* Encodes lists of entries with key attribute. <br/>
|
||||
* e.g.:
|
||||
*
|
||||
* <PRE>
|
||||
* {@code
|
||||
* <listName>
|
||||
@ -39,34 +40,71 @@ import org.jdom.Element;
|
||||
* <entry key="k2">val2</entry>
|
||||
* <entry key="k3">val3</entry>
|
||||
* </listName>}
|
||||
*
|
||||
* <PRE>
|
||||
*
|
||||
*
|
||||
* This can be also used in compounded to the PropertyXMLEncoder
|
||||
* or other objects overriding the toString() method
|
||||
* <br/>
|
||||
* e.g.:
|
||||
*
|
||||
* <PRE>
|
||||
* {@code
|
||||
* <listName>
|
||||
* <entry key="time">
|
||||
* <dimensionInfo>
|
||||
* <enabled>false</enabled>
|
||||
* </dimensionInfo>
|
||||
* </entry>
|
||||
* <entry key="elevation">
|
||||
* <dimensionInfo>
|
||||
* <enabled>true</enabled>
|
||||
* <attribute>ele</attribute>
|
||||
* <presentation>LIST</presentation>
|
||||
* </dimensionInfo>
|
||||
* </entry>
|
||||
* </listName>}
|
||||
*
|
||||
* <PRE>
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*
|
||||
*/
|
||||
public class EntryKeyListEncoder {
|
||||
public class EntryKeyListEncoder <T> extends XMLSerializer{
|
||||
|
||||
private Map<String, String> metadata = new LinkedHashMap<String, String>();
|
||||
private final String listName;
|
||||
private final Element root;
|
||||
|
||||
public EntryKeyListEncoder(String listName) {
|
||||
root=new Element(listName);
|
||||
}
|
||||
|
||||
public EntryKeyListEncoder(String listName) {
|
||||
this.listName = listName;
|
||||
}
|
||||
|
||||
public void add(String key, String value) {
|
||||
metadata.put(key, value);
|
||||
}
|
||||
public void add(String key, T value) {
|
||||
final Element entryElem = new Element("entry");
|
||||
entryElem.setAttribute("key", key);
|
||||
if (value instanceof String)
|
||||
entryElem.setText((String)value);
|
||||
else if (value instanceof Element)
|
||||
entryElem.addContent((Element)value);
|
||||
else if (value instanceof GSDimensionInfoEncoder)
|
||||
entryElem.addContent(((GSDimensionInfoEncoder)value).getElement());
|
||||
else
|
||||
throw new IllegalArgumentException("Unable to add entry: unrecognized object");
|
||||
|
||||
root.addContent(entryElem);
|
||||
}
|
||||
|
||||
|
||||
public void attachList(Element e) {
|
||||
|
||||
if( ! metadata.isEmpty() ) {
|
||||
Element md = new Element(listName);
|
||||
for (Map.Entry<String, String> entry : metadata.entrySet()) {
|
||||
Element entryeElem = new Element("entry")
|
||||
.setAttribute("key", entry.getKey())
|
||||
.setText(entry.getValue());
|
||||
md.addContent(entryeElem);
|
||||
}
|
||||
e.addContent(md);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* add a node to the root
|
||||
*
|
||||
* @param el the node to add
|
||||
*/
|
||||
public void addContent(final Element el){
|
||||
root.addContent(el);
|
||||
}
|
||||
|
||||
public Element getElement() {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,11 +25,7 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.output.Format;
|
||||
import org.jdom.output.XMLOutputter;
|
||||
|
||||
/**
|
||||
* Creates an XML document by mapping properties to XML nodes.<br/>
|
||||
@ -44,58 +40,69 @@ import org.jdom.output.XMLOutputter;
|
||||
* <PRE> {@code <k1><k2><k3>value</k3></k2></k1> }</pre>
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class PropertyXMLEncoder {
|
||||
public class PropertyXMLEncoder extends XMLSerializer{
|
||||
|
||||
private final static XMLOutputter OUTPUTTER = new XMLOutputter(Format.getCompactFormat());
|
||||
private final Map<String, String> configElements = new HashMap<String, String>();
|
||||
private final String rootName;
|
||||
// private final Map<String, String> configElements = new HashMap<String, String>();
|
||||
private final Element root;
|
||||
|
||||
public PropertyXMLEncoder(String rootName) {
|
||||
this.rootName = rootName;
|
||||
public PropertyXMLEncoder(final String rootName) {
|
||||
root=new Element(rootName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add a node (as child) to the root node
|
||||
*
|
||||
* @param el the node to add
|
||||
*/
|
||||
@Override
|
||||
public void addContent(final Element el){
|
||||
root.addContent(el);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Deprecated use add()
|
||||
*/
|
||||
@Deprecated
|
||||
protected void setOrRemove(String key, String value) {
|
||||
if (value != null) {
|
||||
configElements.put(key, value);
|
||||
final Element e=root.getChild(key);
|
||||
if (value != null && e==null) {
|
||||
add(root, key, value);
|
||||
} else {
|
||||
configElements.remove(key);
|
||||
root.removeChild(key);
|
||||
}
|
||||
}
|
||||
|
||||
protected void set(String key, String value) {
|
||||
setOrRemove(key, value);
|
||||
|
||||
protected void add(String key, String value) {
|
||||
final Element e=root.getChild(key);
|
||||
if (value != null && e==null) {
|
||||
add(root, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return configElements.isEmpty();
|
||||
// return configElements.isEmpty();
|
||||
return root.getChildren().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an xml document representing the stored properties.
|
||||
*/
|
||||
public String encodeXml() {
|
||||
|
||||
Element root = new Element(rootName);
|
||||
for (String key : configElements.keySet()) {
|
||||
final String value = configElements.get(key);
|
||||
add(root, key, value);
|
||||
}
|
||||
|
||||
addNodesBeforeOutput(root);
|
||||
return OUTPUTTER.outputString(root);
|
||||
public Element get(final String key){
|
||||
return root.getChild(key);
|
||||
// return configElements.get(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclasses may need to override this method if some more info in the XML
|
||||
* string are needed when calling {@link #encodeXml() encodeXml()}.
|
||||
*
|
||||
* @param root the root element that will be converted into String by encodeXml
|
||||
*/
|
||||
protected void addNodesBeforeOutput(Element root) {
|
||||
// nothing to do, just override when needed.
|
||||
@Override
|
||||
public Element getElement(){
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
private void add(Element e, String key, String value) {
|
||||
if( ! key.contains("/") ) {
|
||||
e.addContent(new Element(key).setText(value));
|
||||
@ -114,4 +121,6 @@ public class PropertyXMLEncoder {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -25,8 +25,6 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
@ -42,39 +40,27 @@ import org.jdom.Element;
|
||||
* <PRE>
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class TextNodeListEncoder {
|
||||
|
||||
private List<Pair> list = new ArrayList<Pair>();
|
||||
private final String listName;
|
||||
public class TextNodeListEncoder extends XMLSerializer{
|
||||
|
||||
private final Element root;
|
||||
public TextNodeListEncoder(String listName) {
|
||||
this.listName = listName;
|
||||
root=new Element(listName);
|
||||
}
|
||||
|
||||
public void add(String nodename, String nodetext) {
|
||||
list.add(new Pair(nodename, nodetext));
|
||||
final Element el=new Element(nodename);
|
||||
el.setText(nodetext);
|
||||
root.addContent(el);
|
||||
}
|
||||
|
||||
public void attachList(Element e) {
|
||||
|
||||
if( ! list.isEmpty() ) {
|
||||
Element elist = new Element(listName);
|
||||
for (Pair pair : list) {
|
||||
Element entry = new Element(pair.v1).setText(pair.v2);
|
||||
elist.addContent(entry);
|
||||
}
|
||||
e.addContent(elist);
|
||||
}
|
||||
public Element getElement() {
|
||||
return root;
|
||||
}
|
||||
|
||||
class Pair {
|
||||
String v1;
|
||||
String v2;
|
||||
public void addContent(final Element el){
|
||||
root.addContent(el);
|
||||
}
|
||||
|
||||
public Pair(String v1, String v2) {
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jdom.output.Format;
|
||||
import org.jdom.output.XMLOutputter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*
|
||||
*/
|
||||
public abstract class XMLSerializer {
|
||||
private final static XMLOutputter OUTPUTTER = new XMLOutputter(Format.getCompactFormat());
|
||||
|
||||
public XMLSerializer(){}
|
||||
|
||||
public abstract Element getElement();
|
||||
|
||||
public abstract void addContent(final Element el);
|
||||
|
||||
/**
|
||||
* @return an xml String
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
final Element root= getElement();
|
||||
if (root!=null)
|
||||
return OUTPUTTER.outputString(root);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -42,7 +42,7 @@ public class EntryKeyListEncoderTest extends TestCase {
|
||||
ekle.add("k3", "v3");
|
||||
|
||||
Element root = new Element("root");
|
||||
ekle.attachList(root);
|
||||
root.addContent(ekle.getElement());
|
||||
|
||||
assertEquals(1, root.getChildren().size());
|
||||
assertNotNull(root.getChild("EKL"));
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* GPLv3 + Classpath exception
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class GSCoverageEncoderTest extends TestCase {
|
||||
|
||||
public GSCoverageEncoderTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default logger
|
||||
*/
|
||||
protected final static Logger LOGGER = Logger.getLogger(GSCoverageEncoderTest.class);
|
||||
|
||||
@Test
|
||||
public void testAll() {
|
||||
GSCoverageEncoder encoder=new GSCoverageEncoder();
|
||||
encoder.addKeyword("KEYWORD_1");
|
||||
encoder.addKeyword("KEYWORD_2");
|
||||
encoder.addKeyword("...");
|
||||
encoder.addKeyword("KEYWORD_N");
|
||||
GSDimensionInfoEncoder dim=new GSDimensionInfoEncoder(true);
|
||||
dim.setPresentation(Presentation.CONTINUOUS_INTERVAL);
|
||||
encoder.addMetadata("time", dim);
|
||||
GSDimensionInfoEncoder dim2=new GSDimensionInfoEncoder(true);
|
||||
dim2.setPresentation(Presentation.LIST);
|
||||
encoder.addMetadata("elev", dim2);
|
||||
encoder.setAllowMultithreading(true);
|
||||
|
||||
LOGGER.info(encoder.toString());
|
||||
// TODO TESTS
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* GPLv3 + Classpath exception
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.DiscretePresentation;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class GSFeatureEncoderTest extends TestCase {
|
||||
|
||||
public GSFeatureEncoderTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAll() {
|
||||
GSFeatureTypeEncoder feature = new GSFeatureTypeEncoder();
|
||||
feature.addKeyword("KEYWORD_1");
|
||||
feature.addKeyword("KEYWORD_2");
|
||||
feature.addKeyword("...");
|
||||
feature.addKeyword("KEYWORD_N");
|
||||
GSFeatureDimensionInfoEncoder dim2 = new GSFeatureDimensionInfoEncoder(
|
||||
"ELE");
|
||||
dim2.setPresentation(DiscretePresentation.DISCRETE_INTERVAL,
|
||||
BigDecimal.valueOf(10));
|
||||
feature.addMetadata("elevation", dim2);
|
||||
|
||||
// TODO TESTS
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user