java删除sld样式

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

1、新建maven项目

java删除sld样式_第1张图片
image.png

2、pom.xml代码



    4.0.0

    TestGeoserver_success
    TestGeoserver_success
    1.0-SNAPSHOT

    
        
            it.geosolutions
            geoserver-manager
            1.7.0
        

        
            org.slf4j
            slf4j-log4j12
            1.5.11
        

        
            commons-httpclient
            commons-httpclient
            3.1
        

        
            commons-io
            commons-io
            2.0.1
        

        
            jdom
            jdom
            1.1
        
    

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样式)