美文网首页GeoServer
java删除sld样式

java删除sld样式

作者: WebGiser | 来源:发表于2019-06-09 18:37 被阅读2次

环境:IDEA java geoserver。
参考:github项目:geoserver-manager
功能:使用java语言通过Geoserver软件发布shp(zip格式)地图服务。

1、新建maven项目

image.png

2、pom.xml代码

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>TestGeoserver_success</groupId>
    <artifactId>TestGeoserver_success</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>it.geosolutions</groupId>
            <artifactId>geoserver-manager</artifactId>
            <version>1.7.0</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.11</version>
        </dependency>

        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.0.1</version>
        </dependency>

        <dependency>
            <groupId>jdom</groupId>
            <artifactId>jdom</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>
</project>

3、UnpublishStyle.java代码

package geoserver;

import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTReader;

//删除某个workspace下的style(若样式已经被使用,会删除失败)
public class UnpublishStyle {
    public static void main(String[] args) throws Exception {
        final String geoserverUrl = "http://localhost:8080/geoserver";
        final String geoserverUsername = "admin";
        final String geoserverPassword = "geoserver";

        GeoServerRESTPublisher geoServerRESTPublisher = new GeoServerRESTPublisher(geoserverUrl,geoserverUsername,geoserverPassword);
        GeoServerRESTReader geoServerRESTReader = new GeoServerRESTReader(geoserverUrl,geoserverUsername,geoserverPassword);

        String workspace = "bbb";       //工作空间
        String styleName = "restteststyle2";
        boolean workspaceExist = geoServerRESTReader.existsWorkspace(workspace);
        if(!workspaceExist){
            System.out.println(workspace+"工作空间不存在!");
            return;
        }
        boolean styleExist = geoServerRESTReader.existsStyle(workspace, styleName);
        if(styleExist){
            boolean styleRemoveResult = geoServerRESTPublisher.removeStyleInWorkspace(workspace, styleName, true);
            if(styleRemoveResult){
                System.out.println(workspace+"工作空间下的"+styleName+"样式删除成功!");
            }else{
                System.out.println(workspace+"工作空间下的"+styleName+"样式删除失败!");
            }
        }else{
            System.out.println("要删除的样式不存在!");
        }
    }
}

相关文章

网友评论

    本文标题:java删除sld样式

    本文链接:https://www.haomeiwen.com/subject/nuyvlqtx.html