Added logic to recognize SLD version from SLDFIle
Added SLD v 1.1.0 content type for SE
This commit is contained in:
parent
86a3de1e2d
commit
962d28503a
@ -1353,7 +1353,7 @@ public class GeoServerRESTPublisher {
|
|||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public enum Format {
|
public enum Format {
|
||||||
XML, JSON, HTML, SLD;
|
XML, JSON, HTML, SLD, SLD_1_1_0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the mime type from a format.
|
* Gets the mime type from a format.
|
||||||
@ -1371,6 +1371,8 @@ public class GeoServerRESTPublisher {
|
|||||||
return "application/json";
|
return "application/json";
|
||||||
case SLD:
|
case SLD:
|
||||||
return "application/vnd.ogc.sld+xml";
|
return "application/vnd.ogc.sld+xml";
|
||||||
|
case SLD_1_1_0:
|
||||||
|
return "application/vnd.ogc.se+xml";
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,10 +30,21 @@ import it.geosolutions.geoserver.rest.Util;
|
|||||||
import it.geosolutions.geoserver.rest.decoder.RESTStyle;
|
import it.geosolutions.geoserver.rest.decoder.RESTStyle;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTStyleList;
|
import it.geosolutions.geoserver.rest.decoder.RESTStyleList;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.xpath.XPath;
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpression;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import javax.xml.xpath.XPathFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -261,7 +272,8 @@ public class GeoServerRESTStyleManager extends GeoServerRESTAbstractManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store and publish a Style, assigning it a name and choosing the raw format.
|
* Store and publish a Style, assigning it a name and choosing the raw
|
||||||
|
* format.
|
||||||
*
|
*
|
||||||
* @param sldFile the File containing the SLD document.
|
* @param sldFile the File containing the SLD document.
|
||||||
* @param name the Style name.
|
* @param name the Style name.
|
||||||
@ -279,7 +291,11 @@ public class GeoServerRESTStyleManager extends GeoServerRESTAbstractManager {
|
|||||||
String sUrl = buildPostUrl(null, name);
|
String sUrl = buildPostUrl(null, name);
|
||||||
sUrl += "&raw=" + raw;
|
sUrl += "&raw=" + raw;
|
||||||
LOGGER.debug("POSTing new style " + name + " to " + sUrl);
|
LOGGER.debug("POSTing new style " + name + " to " + sUrl);
|
||||||
String result = HTTPUtils.post(sUrl, sldFile, GeoServerRESTPublisher.Format.SLD.getContentType(), gsuser, gspass);
|
String contentType = GeoServerRESTPublisher.Format.SLD.getContentType();
|
||||||
|
if(!this.checkSLD10Version(sldFile)){
|
||||||
|
contentType = GeoServerRESTPublisher.Format.SLD_1_1_0.getContentType();
|
||||||
|
}
|
||||||
|
String result = HTTPUtils.post(sUrl, sldFile, contentType, gsuser, gspass);
|
||||||
return result != null;
|
return result != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,4 +635,26 @@ public class GeoServerRESTStyleManager extends GeoServerRESTAbstractManager {
|
|||||||
return sUrl.toString();
|
return sUrl.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkSLD10Version(File fileSLD) {
|
||||||
|
boolean result = false;
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
try {
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document doc = builder.parse(fileSLD);
|
||||||
|
XPathFactory xPathfactory = XPathFactory.newInstance();
|
||||||
|
XPath xpath = xPathfactory.newXPath();
|
||||||
|
XPathExpression expr = xpath.compile("//@version='1.0.0'");
|
||||||
|
result = (Boolean)expr.evaluate(doc, XPathConstants.BOOLEAN);
|
||||||
|
} catch (SAXException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
} catch (XPathExpressionException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
} catch (ParserConfigurationException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user