Compare commits
1 Commits
master
...
unify-enco
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee4291164d |
@ -41,11 +41,12 @@ import it.geosolutions.geoserver.rest.decoder.RESTNamespaceList;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTResource;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTStyleList;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList;
|
||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -338,13 +339,24 @@ public class GeoServerRESTReader {
|
||||
* @param csName The name of the CoverageStore
|
||||
* @return Coverages list as a {@link RESTCoverageList}
|
||||
*/
|
||||
public RESTCoverageList getCoverages(String workspace, String csName) {
|
||||
// restURL + "/rest/workspaces/" + workspace + "/coveragestores/" + coverageStore + "/coverages.xml";
|
||||
String url = "/rest/workspaces/" + workspace + "/coveragestores/" + csName + "/coverages.xml";
|
||||
public XmlElement getCoverages(String workspace, String csName) {
|
||||
// restURL + "/rest/workspaces/" + workspace + "/coveragestores/" + coverageStore + "/coverages.xml";
|
||||
String url = "/rest/workspaces/" + workspace + "/coveragestores/" + csName
|
||||
+ "/coverages.xml";
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("### Retrieving Covs from " + url);
|
||||
}
|
||||
return RESTCoverageList.build(load(url));
|
||||
String response = load(url);
|
||||
try {
|
||||
return new XmlElement(
|
||||
it.geosolutions.geoserver.rest.encoder.utils.ElementUtils
|
||||
.parseDocument(response));
|
||||
} catch (Exception e) {
|
||||
if (LOGGER.isErrorEnabled()) {
|
||||
LOGGER.error("Error parsing reponse from " + url + " Response: " + response);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,12 +367,23 @@ public class GeoServerRESTReader {
|
||||
* @param name The name of the Coverage
|
||||
* @return Coverage details as a {@link RESTCoverage}
|
||||
*/
|
||||
public RESTCoverage getCoverage(String workspace, String store, String name) {
|
||||
public GSCoverageEncoder getCoverage(String workspace, String store, String name) {
|
||||
String url = "/rest/workspaces/" + workspace + "/coveragestores/" + store + "/coverages/"+name+".xml";
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("### Retrieving Coverage from " + url);
|
||||
}
|
||||
return RESTCoverage.build(load(url));
|
||||
String response = load(url);
|
||||
try {
|
||||
GSCoverageEncoder ce=new GSCoverageEncoder();
|
||||
ce.build(it.geosolutions.geoserver.rest.encoder.utils.ElementUtils
|
||||
.parseDocument(response));
|
||||
return ce;
|
||||
} catch (Exception e) {
|
||||
if (LOGGER.isErrorEnabled()) {
|
||||
LOGGER.error("Error parsing reponse from " + url + " Response: " + response);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -25,12 +25,18 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jdom.filter.Filter;
|
||||
import org.jdom.input.SAXBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -44,6 +50,21 @@ public abstract class ElementUtils {
|
||||
* Default logger
|
||||
*/
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(ElementUtils.class);
|
||||
private final static SAXBuilder builder = new SAXBuilder();
|
||||
|
||||
public static Document parseDocument(final String xml) throws JDOMException, IOException, IllegalArgumentException {
|
||||
if (xml==null){
|
||||
throw new IllegalArgumentException("Unable to parse a null xml string");
|
||||
}
|
||||
return (Document) builder.build(new StringReader(xml));
|
||||
}
|
||||
|
||||
public static Document parseDocument(final Reader xmlReader) throws JDOMException, IOException, IllegalArgumentException {
|
||||
if (xmlReader==null){
|
||||
throw new IllegalArgumentException("Unable to parse a null xml string");
|
||||
}
|
||||
return (Document) builder.build(xmlReader);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@ -27,6 +27,7 @@ package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
|
||||
import org.jdom.Content;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.Text;
|
||||
import org.jdom.output.Format;
|
||||
@ -39,7 +40,7 @@ import org.jdom.output.XMLOutputter;
|
||||
*/
|
||||
public class XmlElement{
|
||||
|
||||
private final Element root;
|
||||
private Element root;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -56,6 +57,18 @@ public class XmlElement{
|
||||
@SuppressWarnings("unused")
|
||||
private XmlElement(){root=null;};
|
||||
|
||||
public XmlElement(final Element root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public XmlElement(final Document doc) {
|
||||
root = doc.getRootElement();
|
||||
}
|
||||
|
||||
public void build(final Document doc) {
|
||||
root = doc.getRootElement();
|
||||
}
|
||||
|
||||
protected void add(final String nodename, final String nodetext) {
|
||||
add(nodename,new Text(nodetext));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user