├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── geoserver-manager ├── pom.xml └── src │ ├── log4j.properties │ └── main │ └── java │ └── it │ └── geosolutions │ └── geoserver │ └── rest │ ├── GeoServerRESTManager.java │ ├── GeoServerRESTPublisher.java │ ├── GeoServerRESTReader.java │ ├── HTTPUtils.java │ ├── Util.java │ ├── decoder │ ├── RESTAbstractList.java │ ├── RESTBoundingBox.java │ ├── RESTCoverage.java │ ├── RESTCoverageList.java │ ├── RESTCoverageStore.java │ ├── RESTCoverageStoreList.java │ ├── RESTDataStore.java │ ├── RESTDataStoreList.java │ ├── RESTDimensionInfo.java │ ├── RESTFeatureType.java │ ├── RESTFeatureTypeList.java │ ├── RESTLayer.java │ ├── RESTLayer21.java │ ├── RESTLayerGroup.java │ ├── RESTLayerGroupList.java │ ├── RESTLayerList.java │ ├── RESTMetadataList.java │ ├── RESTNamespace.java │ ├── RESTNamespaceList.java │ ├── RESTPublished.java │ ├── RESTPublishedList.java │ ├── RESTResource.java │ ├── RESTStructuredCoverageGranulesList.java │ ├── RESTStructuredCoverageIndexSchema.java │ ├── RESTStyle.java │ ├── RESTStyleList.java │ ├── RESTWms.java │ ├── RESTWmsList.java │ ├── RESTWmsStore.java │ ├── RESTWmsStoreList.java │ ├── RESTWorkspaceList.java │ ├── about │ │ └── GSVersionDecoder.java │ ├── package.html │ └── utils │ │ ├── JDOMBuilder.java │ │ ├── JDOMListIterator.java │ │ ├── NameLinkElem.java │ │ └── package.html │ ├── encoder │ ├── GSAbstractStoreEncoder.java │ ├── GSBackupEncoder.java │ ├── GSLayerEncoder.java │ ├── GSLayerEncoder21.java │ ├── GSLayerGroupEncoder.java │ ├── GSLayerGroupEncoder23.java │ ├── GSNamespaceEncoder.java │ ├── GSPostGISDatastoreEncoder.java │ ├── GSResourceEncoder.java │ ├── GSWorkspaceEncoder.java │ ├── authorityurl │ │ ├── AuthorityURLInfo.java │ │ └── GSAuthorityURLInfoEncoder.java │ ├── coverage │ │ ├── GSAbstractCoveragestoreEncoder.java │ │ ├── GSCoverageEncoder.java │ │ ├── GSImageMosaicEncoder.java │ │ └── GSJP2KEncoder.java │ ├── datastore │ │ ├── GSAbstractDatastoreEncoder.java │ │ ├── GSArcSDEDatastoreEncoder.java │ │ ├── GSDirectoryOfShapefilesDatastoreEncoder.java │ │ ├── GSGeoTIFFDatastoreEncoder.java │ │ ├── GSMosaicDatastoreEncoder.java │ │ ├── GSOracleNGDatastoreEncoder.java │ │ ├── GSPostGISDatastoreEncoder.java │ │ └── GSShapefileDatastoreEncoder.java │ ├── dimensions │ │ └── GSCoverageDimensionEncoder.java │ ├── feature │ │ ├── FeatureTypeAttribute.java │ │ ├── GSAttributeEncoder.java │ │ └── GSFeatureTypeEncoder.java │ ├── identifier │ │ ├── GSIdentifierInfoEncoder.java │ │ └── IdentifierInfo.java │ ├── metadata │ │ ├── GSDimensionInfoEncoder.java │ │ ├── GSFeatureDimensionInfoEncoder.java │ │ └── virtualtable │ │ │ ├── GSVirtualTableEncoder.java │ │ │ ├── VTGeometry.java │ │ │ ├── VTGeometryEncoder.java │ │ │ ├── VTParameter.java │ │ │ └── VTParameterEncoder.java │ ├── metadatalink │ │ ├── GSMetadataLinkInfoEncoder.java │ │ └── ResourceMetadataLinkInfo.java │ ├── package.html │ ├── service │ │ └── GSServiceSettingsEncoder.java │ └── utils │ │ ├── ElementUtils.java │ │ ├── NestedElementEncoder.java │ │ ├── PropertyXMLEncoder.java │ │ ├── XmlElement.java │ │ └── package.html │ ├── manager │ ├── GeoServerRESTAbstractManager.java │ ├── GeoServerRESTStoreManager.java │ ├── GeoServerRESTStructuredGridCoverageReaderManager.java │ └── GeoServerRESTStyleManager.java │ └── package.html ├── geoserver-rest ├── pom.xml └── src │ ├── log4j.properties │ ├── main │ └── java │ │ └── com │ │ └── zach │ │ └── services │ │ ├── DeleStore.java │ │ ├── Fileurl.java │ │ ├── LayerDetail.java │ │ ├── ShpPublish.java │ │ ├── TiffPublish.java │ │ ├── TreeDetail.java │ │ ├── WmsLegend.java │ │ ├── test.java │ │ └── util │ │ ├── ComUtil.java │ │ ├── Constant.java │ │ ├── DateTimeUtil.java │ │ ├── FileUtils.java │ │ ├── GeoServerUtil.java │ │ ├── HttpLayerPropertyUtil.java │ │ └── XmlUtil.java │ └── test │ └── java │ └── com │ └── zach │ └── geoserver_rest │ ├── AppTest.java │ ├── services │ └── WmsLegend.java │ ├── shpTest.java │ ├── test.java │ ├── test01.java │ └── tiffTest.java ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── qiang │ │ └── springvue │ │ ├── SpringVueApplication.java │ │ ├── config │ │ └── CrosConfig.java │ │ ├── controller │ │ └── BookController.java │ │ ├── entity │ │ └── Book.java │ │ ├── mapper │ │ └── BookMapper.java │ │ └── service │ │ └── BookService.java └── resources │ ├── application.properties │ └── application.yml └── test └── java └── com └── qiang └── springvue └── SpringVueApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import java.net.*; 18 | import java.io.*; 19 | import java.nio.channels.*; 20 | import java.util.Properties; 21 | 22 | public class MavenWrapperDownloader { 23 | 24 | private static final String WRAPPER_VERSION = "0.5.6"; 25 | /** 26 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 27 | */ 28 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 29 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 30 | 31 | /** 32 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 33 | * use instead of the default one. 34 | */ 35 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 36 | ".mvn/wrapper/maven-wrapper.properties"; 37 | 38 | /** 39 | * Path where the maven-wrapper.jar will be saved to. 40 | */ 41 | private static final String MAVEN_WRAPPER_JAR_PATH = 42 | ".mvn/wrapper/maven-wrapper.jar"; 43 | 44 | /** 45 | * Name of the property which should be used to override the default download url for the wrapper. 46 | */ 47 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 48 | 49 | public static void main(String args[]) { 50 | System.out.println("- Downloader started"); 51 | File baseDirectory = new File(args[0]); 52 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 53 | 54 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 55 | // wrapperUrl parameter. 56 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 57 | String url = DEFAULT_DOWNLOAD_URL; 58 | if (mavenWrapperPropertyFile.exists()) { 59 | FileInputStream mavenWrapperPropertyFileInputStream = null; 60 | try { 61 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 62 | Properties mavenWrapperProperties = new Properties(); 63 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 64 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 65 | } catch (IOException e) { 66 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 67 | } finally { 68 | try { 69 | if (mavenWrapperPropertyFileInputStream != null) { 70 | mavenWrapperPropertyFileInputStream.close(); 71 | } 72 | } catch (IOException e) { 73 | // Ignore ... 74 | } 75 | } 76 | } 77 | System.out.println("- Downloading from: " + url); 78 | 79 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 80 | if (!outputFile.getParentFile().exists()) { 81 | if (!outputFile.getParentFile().mkdirs()) { 82 | System.out.println( 83 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 84 | } 85 | } 86 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 87 | try { 88 | downloadFileFromURL(url, outputFile); 89 | System.out.println("Done"); 90 | System.exit(0); 91 | } catch (Throwable e) { 92 | System.out.println("- Error downloading"); 93 | e.printStackTrace(); 94 | System.exit(1); 95 | } 96 | } 97 | 98 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 99 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 100 | String username = System.getenv("MVNW_USERNAME"); 101 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 102 | Authenticator.setDefault(new Authenticator() { 103 | @Override 104 | protected PasswordAuthentication getPasswordAuthentication() { 105 | return new PasswordAuthentication(username, password); 106 | } 107 | }); 108 | } 109 | URL website = new URL(urlString); 110 | ReadableByteChannel rbc; 111 | rbc = Channels.newChannel(website.openStream()); 112 | FileOutputStream fos = new FileOutputStream(destination); 113 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 114 | fos.close(); 115 | rbc.close(); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/As-Zach/GeoServer-SpringBoot/efc98dcdfb88be7cd4912e0e48cbbfcb88ae260d/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /geoserver-manager/src/log4j.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/As-Zach/GeoServer-SpringBoot/efc98dcdfb88be7cd4912e0e48cbbfcb88ae260d/geoserver-manager/src/log4j.properties -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2016 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest; 26 | 27 | import it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager; 28 | import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager; 29 | import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager; 30 | import it.geosolutions.geoserver.rest.manager.GeoServerRESTStyleManager; 31 | 32 | import java.net.MalformedURLException; 33 | import java.net.URL; 34 | 35 | /** 36 | * The single entry point to all of geoserver-manager functionality. 37 | * 38 | * Instance this one, and use getters to use different components. These are: 39 | * 44 | * 45 | * @author Oscar Fonts 46 | * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it 47 | */ 48 | public class GeoServerRESTManager extends GeoServerRESTAbstractManager { 49 | 50 | private final GeoServerRESTPublisher publisher; 51 | private final GeoServerRESTReader reader; 52 | 53 | private final GeoServerRESTStoreManager storeManager; 54 | private final GeoServerRESTStyleManager styleManager; 55 | 56 | private final GeoServerRESTStructuredGridCoverageReaderManager structuredGridCoverageReader; 57 | 58 | /** 59 | * Default constructor. 60 | * 61 | * Indicates connection parameters to remote GeoServer instance. 62 | * 63 | * @param restURL GeoServer REST API endpoint 64 | * @param username GeoServer REST API authorized username 65 | * @param password GeoServer REST API password for the former username 66 | * @throws MalformedURLException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)} 67 | * @throws IllegalArgumentException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)} 68 | */ 69 | public GeoServerRESTManager(URL restURL, String username, String password) 70 | throws IllegalArgumentException { 71 | super(restURL, username, password); 72 | 73 | // Internal publisher and reader, provide simple access methods. 74 | publisher = new GeoServerRESTPublisher(restURL.toString(), username, password); 75 | reader = new GeoServerRESTReader(restURL, username, password); 76 | structuredGridCoverageReader = new GeoServerRESTStructuredGridCoverageReaderManager(restURL, username, password); 77 | storeManager = new GeoServerRESTStoreManager(restURL, gsuser, gspass); 78 | styleManager = new GeoServerRESTStyleManager(restURL, gsuser, gspass); 79 | } 80 | 81 | public GeoServerRESTPublisher getPublisher() { 82 | return publisher; 83 | } 84 | 85 | public GeoServerRESTReader getReader() { 86 | return reader; 87 | } 88 | 89 | public GeoServerRESTStoreManager getStoreManager() { 90 | return storeManager; 91 | } 92 | 93 | public GeoServerRESTStyleManager getStyleManager() { 94 | return styleManager; 95 | } 96 | 97 | public GeoServerRESTStructuredGridCoverageReaderManager getStructuredGridCoverageReader() { 98 | return structuredGridCoverageReader; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007 - 2016 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.RESTStyle; 29 | import java.util.ArrayList; 30 | import java.util.Collection; 31 | import java.util.Collections; 32 | import java.util.List; 33 | import java.util.Map; 34 | 35 | /** 36 | * 37 | * @author ETj (etj at geo-solutions.it) 38 | */ 39 | public class Util { 40 | 41 | public static final String QUIET_ON_NOT_FOUND_PARAM = "quietOnNotFound="; 42 | 43 | public static final boolean DEFAULT_QUIET_ON_NOT_FOUND = true; 44 | 45 | /** 46 | * Search for a stylename in global and in all workspaces. 47 | */ 48 | public static List searchStyles(GeoServerRESTReader reader, String stylename) { 49 | 50 | List styles = new ArrayList(); 51 | 52 | RESTStyle style = reader.getStyle(stylename); 53 | 54 | // We don't want geoserver to be lenient here: take only the real global style if it exists 55 | if(style != null) { 56 | if(style.getWorkspace() == null || style.getWorkspace().isEmpty()) { 57 | styles.add(style); 58 | } 59 | } 60 | 61 | for (String workspace : reader.getWorkspaceNames()) { 62 | style = reader.getStyle(workspace, stylename); 63 | if(style != null) 64 | styles.add(style); 65 | } 66 | 67 | return styles; 68 | } 69 | 70 | /** 71 | * Append the quietOnNotFound parameter to the input URL 72 | * @param quietOnNotFound parameter 73 | * @param url input url 74 | * @return a composed url with the parameter appended 75 | */ 76 | public static String appendQuietOnNotFound(boolean quietOnNotFound, String url) { 77 | boolean contains = url.contains("?"); 78 | String composed = url + (contains ? "&":"?") + QUIET_ON_NOT_FOUND_PARAM + quietOnNotFound; 79 | return composed; 80 | } 81 | 82 | public static List safeList(List list) { 83 | return list == null ? Collections.EMPTY_LIST : list; 84 | } 85 | 86 | public static Collection safeCollection(Collection collection) { 87 | return collection == null ? Collections.EMPTY_SET : collection; 88 | } 89 | 90 | public static Map safeMap(Map map) { 91 | return map == null ? Collections.EMPTY_MAP : map; 92 | } 93 | 94 | public static char getParameterSeparator(String url) { 95 | char parameterSeparator = '?'; 96 | if (url.contains("?")) { 97 | parameterSeparator = '&'; 98 | } 99 | return parameterSeparator; 100 | } 101 | 102 | public static char getParameterSeparator(StringBuilder url) { 103 | char parameterSeparator = '?'; 104 | if (url.indexOf("?") != -1) { 105 | parameterSeparator = '&'; 106 | } 107 | return parameterSeparator; 108 | } 109 | 110 | public static boolean appendParameter(StringBuilder url, String parameterName, 111 | String parameterValue) { 112 | boolean result = false; 113 | if (parameterName != null && !parameterName.isEmpty() 114 | && parameterValue != null && !parameterValue.isEmpty()) { 115 | char parameterSeparator = getParameterSeparator(url); 116 | url.append(parameterSeparator).append(parameterName.trim()) 117 | .append('=').append(parameterValue.trim()); 118 | } 119 | return result; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTAbstractList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMListIterator; 29 | import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; 30 | 31 | import java.util.ArrayList; 32 | import java.util.Collections; 33 | import java.util.Iterator; 34 | import java.util.List; 35 | 36 | import org.jdom.Element; 37 | 38 | /** 39 | * Parses list of summary data. 40 | * 41 | *

This is the XML REST representation: 42 | *

 43 |   {@code
 44 | 
 45 |       
 46 |         elem1
 47 |         
 48 |       
 49 |       
 50 |         elem2
 51 |         
 52 |       
 53 | 
 54 | }
55 | * 56 | * @author ETj (etj at geo-solutions.it) 57 | */ 58 | public class RESTAbstractList implements Iterable { 59 | 60 | protected final List elementList; 61 | 62 | protected RESTAbstractList(Element list) { 63 | List tempList = new ArrayList(); 64 | String baseName = null; 65 | 66 | for (Element listItem : (List) list.getChildren()) { 67 | if(baseName == null) 68 | baseName = listItem.getName(); 69 | else 70 | if(! baseName.equals(listItem.getName())) { 71 | throw new RuntimeException("List elements mismatching (" + baseName+","+listItem.getName()+")"); 72 | } 73 | 74 | tempList.add(listItem); 75 | } 76 | 77 | elementList = Collections.unmodifiableList(tempList); 78 | } 79 | 80 | public int size() { 81 | return elementList.size(); 82 | } 83 | 84 | public boolean isEmpty(String[] fileList) { 85 | return elementList.isEmpty(); 86 | } 87 | 88 | public ELEM get(int index) { 89 | return createElement(elementList.get(index)); 90 | } 91 | 92 | public Iterator iterator() { 93 | return new RESTAbstractListIterator(elementList); 94 | } 95 | 96 | public List getNames() { 97 | List names = new ArrayList(elementList.size()); 98 | for (ELEM elem: this) { 99 | names.add(elem.getName()); 100 | } 101 | return names; 102 | } 103 | 104 | 105 | private class RESTAbstractListIterator extends JDOMListIterator { 106 | 107 | public RESTAbstractListIterator(List orig) { 108 | super(orig); 109 | } 110 | 111 | @Override 112 | public ELEM transform(Element listItem) { 113 | return createElement(listItem); 114 | } 115 | } 116 | 117 | protected ELEM createElement(Element el) { 118 | return (ELEM)new NameLinkElem(el); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTBoundingBox.java: -------------------------------------------------------------------------------- 1 | package it.geosolutions.geoserver.rest.decoder; 2 | 3 | import org.jdom.Element; 4 | 5 | /** 6 | * Parse a Boundingbox of the following structure 7 | * 8 | * 472800.0 9 | * 817362.0 10 | * 35053.40625 11 | * 301500.0 12 | * EPSG:21781 13 | * 14 | * @author nmandery 15 | */ 16 | public class RESTBoundingBox { 17 | 18 | protected Element bboxElem; 19 | 20 | public RESTBoundingBox(Element bboxElem) { 21 | this.bboxElem = bboxElem; 22 | } 23 | 24 | public String getCRS() { 25 | return this.bboxElem.getChildText("crs"); 26 | } 27 | public String getSRS() { 28 | return this.bboxElem.getChildText("srs"); 29 | } 30 | 31 | protected double getEdge(String edge) { 32 | return Double.parseDouble(this.bboxElem.getChildText(edge)); 33 | } 34 | 35 | public double getMinX() { 36 | return this.getEdge("minx"); 37 | } 38 | 39 | public double getMaxX() { 40 | return this.getEdge("maxx"); 41 | } 42 | 43 | public double getMinY() { 44 | return this.getEdge("miny"); 45 | } 46 | 47 | public double getMaxY() { 48 | return this.getEdge("maxy"); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTCoverageList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; 30 | 31 | import org.jdom.Element; 32 | 33 | /** 34 | * Parses list of summary data about Coverages. 35 | * 36 | *

This is the XML REST representation: 37 | *

{@code 
38 |   
39 |     5-25-1-120-11-DOF
40 |     
45 |   
46 | 
47 |  *
48 | }
49 | * 50 | * @author ETj (etj at geo-solutions.it) 51 | */ 52 | public class RESTCoverageList extends RESTAbstractList { 53 | 54 | public static RESTCoverageList build(String response) { 55 | Element elem = JDOMBuilder.buildElement(response); 56 | return elem == null? null : new RESTCoverageList(elem); 57 | } 58 | 59 | protected RESTCoverageList(Element list) { 60 | super(list); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTCoverageStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | 30 | import org.jdom.Element; 31 | 32 | /** 33 | * Parse CoverageStores returned as XML REST objects. 34 | *

35 | * This is the XML document returned by GeoServer when requesting a CoverageStore: 36 | *

 37 |  * {@code 
 38 |  * 
 39 |  *      testRESTStoreGeotiff
 40 |  *      GeoTIFF
 41 |  *      true
 42 |  *      
 43 |  *          it.geosolutions
 44 |  *          http://localhost:8080/geoserver/rest/workspaces/it.geosolutions.xml
 45 |  *      
 46 |  *      file:/home/geosolutions/prj/git/gman/target/test-classes/testdata/resttestdem.tif
 47 |  *      
 48 |  *          
 51 |  *      
 52 |  * 
 53 |  * }
 54 |  * 
55 | * 56 | * Note: the whole XML fragment is stored in memory. At the moment, there are 57 | * methods to retrieve only the more useful data. 58 | * 59 | * @author etj 60 | */ 61 | public class RESTCoverageStore { 62 | private final Element cs; 63 | 64 | 65 | public RESTCoverageStore(Element cs) { 66 | this.cs = cs; 67 | } 68 | 69 | public static RESTCoverageStore build(String response) { 70 | if(response == null) 71 | return null; 72 | if(response.isEmpty()) 73 | return new RESTCoverageStore(new Element("coverageStore")); // TODO check how to response 74 | 75 | Element pb = JDOMBuilder.buildElement(response); 76 | if(pb != null) 77 | return new RESTCoverageStore(pb); 78 | else 79 | return null; 80 | } 81 | 82 | public String getName() { 83 | return cs.getChildText("name"); 84 | } 85 | 86 | public String getWorkspaceName() { 87 | return cs.getChild("workspace").getChildText("name"); 88 | } 89 | 90 | public String getURL() { 91 | return cs.getChildText("url"); 92 | } 93 | 94 | public String getType() { 95 | return cs.getChildText("type"); 96 | } 97 | 98 | public String toString() { 99 | StringBuilder sb = new StringBuilder(getClass().getSimpleName()) 100 | .append('['); 101 | if(cs == null) 102 | sb.append("null"); 103 | else 104 | sb.append("name:").append(getName()) 105 | .append(" wsname:").append(getWorkspaceName()); 106 | 107 | return sb.toString(); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTCoverageStoreList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; 30 | 31 | import org.jdom.Element; 32 | 33 | /** 34 | * Parses list of summary data about CoverageStores. 35 | * 36 | *

This is the XML REST representation: 37 | *

{@code 
38 |   
39 |     sfdem
40 |     
44 |   
45 | 
46 |  *
47 | }
48 | * 49 | * @author ETj (etj at geo-solutions.it) 50 | */ 51 | public class RESTCoverageStoreList extends RESTAbstractList { 52 | 53 | public static RESTCoverageStoreList build(String response) { 54 | Element elem = JDOMBuilder.buildElement(response); 55 | return elem == null? null : new RESTCoverageStoreList(elem); 56 | } 57 | 58 | protected RESTCoverageStoreList(Element list) { 59 | super(list); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTDataStoreList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; 30 | 31 | import org.jdom.Element; 32 | 33 | /** 34 | * Parses list of summary data about Datastores. 35 | * 36 | * @author ETj (etj at geo-solutions.it) 37 | */ 38 | public class RESTDataStoreList extends RESTAbstractList { 39 | 40 | public static RESTDataStoreList build(String response) { 41 | Element elem = JDOMBuilder.buildElement(response); 42 | return elem == null? null : new RESTDataStoreList(elem); 43 | } 44 | 45 | protected RESTDataStoreList(Element list) { 46 | super(list); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTDimensionInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoBatch - Open Source geospatial batch processing system 3 | * https://github.com/nfms4redd/nfms-geobatch 4 | * Copyright (C) 2007-2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * GPLv3 + Classpath exception 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | package it.geosolutions.geoserver.rest.decoder; 23 | 24 | import org.jdom.Element; 25 | 26 | /** 27 | * @author DamianoG 28 | * 29 | */ 30 | public class RESTDimensionInfo extends RESTMetadataList.RESTMetadataElement{ 31 | 32 | private boolean enabled; 33 | private String presentation; 34 | private String resolution; 35 | 36 | public static final String TIME = "time"; 37 | public static final String ELEVATION = "elevation"; 38 | 39 | /** 40 | * @param elem 41 | */ 42 | public RESTDimensionInfo(Element elem) { 43 | super(elem); 44 | if(elem.getChild("dimensionInfo")!=null){ 45 | enabled = Boolean.parseBoolean(elem.getChild("dimensionInfo").getChildText("enabled")); 46 | presentation = elem.getChild("dimensionInfo").getChildText("presentation"); 47 | resolution = elem.getChild("dimensionInfo").getChildText("resolution"); 48 | } 49 | } 50 | 51 | /** 52 | * @return the enabled 53 | */ 54 | public boolean isEnabled() { 55 | return enabled; 56 | } 57 | 58 | /** 59 | * @param enabled the enabled to set 60 | */ 61 | public void setEnabled(boolean enabled) { 62 | this.enabled = enabled; 63 | } 64 | 65 | /** 66 | * @return the presentation 67 | */ 68 | public String getPresentation() { 69 | return presentation; 70 | } 71 | 72 | /** 73 | * @param presentation the presentation to set 74 | */ 75 | public void setPresentation(String presentation) { 76 | this.presentation = presentation; 77 | } 78 | 79 | /** 80 | * @return the resolution 81 | */ 82 | public String getResolution() { 83 | return resolution; 84 | } 85 | 86 | /** 87 | * @param resolution the resolution to set 88 | */ 89 | public void setResolution(String resolution) { 90 | this.resolution = resolution; 91 | } 92 | 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTFeatureTypeList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; 30 | 31 | import org.jdom.Element; 32 | 33 | /** 34 | * Parses list of summary data about FeatureTypes. 35 | * 36 | * 37 | * FeatureType summary info. 38 | *
This is an XML fragment: 39 | *
40 |  *{@code
41 | 
42 |     states
43 |     
46 | 
47 |  * }
48 |  * 
49 | * 50 | * @author wumpz 51 | */ 52 | public class RESTFeatureTypeList extends RESTAbstractList { 53 | 54 | public static RESTFeatureTypeList build(String response) { 55 | Element elem = JDOMBuilder.buildElement(response); 56 | return elem == null? null : new RESTFeatureTypeList(elem); 57 | } 58 | 59 | protected RESTFeatureTypeList(Element list) { 60 | super(list); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTLayerGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | 30 | import org.jdom.Element; 31 | 32 | /** 33 | * Parse LayerGroups returned as XML REST objects. 34 | * 35 | *

This is the XML REST representation: 36 | *

 37 |  * {@code
 38 | 
 39 |   tasmania
 40 |   
 41 |     
 42 |       tasmania_state_boundaries
 43 |       
 44 |     
 45 |     
 46 |       tasmania_water_bodies
 47 |       
 48 |     
 49 |     
 50 |       tasmania_roads
 51 |       
 52 |     
 53 |     
 54 |       tasmania_cities
 55 |       
 56 |     
 57 |   
 58 |   
 59 |     
43 |       
47 |       
51 | }
52 | * 53 | * @author ETj (etj at geo-solutions.it) 54 | */ 55 | public class RESTStyleList extends RESTAbstractList { 56 | 57 | public static RESTStyleList build(String response) { 58 | Element elem = JDOMBuilder.buildElement(response); 59 | return elem == null? null : new RESTStyleList(elem); 60 | } 61 | 62 | protected RESTStyleList(Element list) { 63 | super(list); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTWmsList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; 30 | 31 | import org.jdom.Element; 32 | 33 | /** 34 | * Parses list of summary data about Wms. 35 | * 36 | *

This is the XML REST representation: 37 | *

{@code 
38 | 	
39 | 		comunilazio
40 | 		
41 | 	
42 | 
43 |  *
44 | }
45 | * 46 | * @author cip 47 | */ 48 | public class RESTWmsList extends RESTAbstractList { 49 | 50 | public static RESTWmsList build(String response) { 51 | Element elem = JDOMBuilder.buildElement(response); 52 | return elem == null? null : new RESTWmsList(elem); 53 | } 54 | 55 | protected RESTWmsList(Element list) { 56 | super(list); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTWmsStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | 30 | import org.jdom.Element; 31 | 32 | /** 33 | * Parse WmsStores returned as XML REST objects. 34 | *

35 | * This is the XML document returned by GeoServer when requesting a WmsStore: 36 | *

 37 |  * {@code 
 38 | 
 39 | 	regione
 40 | 	WMS
 41 | 	true
 42 | 	
 43 | 		arit
 44 | 		
 45 | 	
 46 | 	
 47 | 		true
 48 | 	
 49 | 	<__default>false
 50 | 	http://www.regione.lazio.it/geoserver/wms
 51 | 	admin
 52 | 	geoserver
 53 | 	6
 54 | 	60
 55 | 	30
 56 | 	
 57 | 		
 58 | 	
 59 | 
 60 |  * }
 61 |  * 
62 | * 63 | * Note: the whole XML fragment is stored in memory. At the moment, there are 64 | * methods to retrieve only the more useful data. 65 | * 66 | * @author etj 67 | */ 68 | public class RESTWmsStore { 69 | private final Element cs; 70 | 71 | 72 | public RESTWmsStore(Element cs) { 73 | this.cs = cs; 74 | } 75 | 76 | public static RESTWmsStore build(String response) { 77 | if(response == null) 78 | return null; 79 | if(response.isEmpty()) 80 | return new RESTWmsStore(new Element("wmsStore")); // TODO check how to response 81 | 82 | Element pb = JDOMBuilder.buildElement(response); 83 | if(pb != null) 84 | return new RESTWmsStore(pb); 85 | else 86 | return null; 87 | } 88 | 89 | public String getName() { 90 | return cs.getChildText("name"); 91 | } 92 | 93 | public String getType() { 94 | return cs.getChildText("type"); 95 | } 96 | 97 | public Boolean getEnabled() { 98 | return Boolean.parseBoolean(cs.getChildText("enabled")); 99 | } 100 | 101 | public String getWorkspaceName() { 102 | return cs.getChild("workspace").getChildText("name"); 103 | } 104 | 105 | public Boolean getUseConnectionPooling(){ 106 | Element entry = cs.getChild("metadata").getChild("entry"); 107 | return entry.getAttributeValue("key").equals("useConnectionPooling") && Boolean.parseBoolean(entry.getValue()); 108 | } 109 | 110 | public String getCapabilitiesURL() { 111 | return cs.getChildText("capabilitiesURL"); 112 | } 113 | 114 | public String getMaxConnections() { 115 | return cs.getChildText("maxConnections"); 116 | } 117 | 118 | public String getReadTimeout() { 119 | return cs.getChildText("readTimeout"); 120 | } 121 | 122 | public String getConnectTimeout() { 123 | return cs.getChildText("connectTimeout"); 124 | } 125 | 126 | public String getUser() { 127 | return cs.getChildText("user"); 128 | } 129 | 130 | public String getPassword() { 131 | return cs.getChildText("password"); 132 | } 133 | 134 | public String toString() { 135 | StringBuilder sb = new StringBuilder(getClass().getSimpleName()) 136 | .append('['); 137 | if(cs == null) 138 | sb.append("null"); 139 | else 140 | sb.append("name:").append(getName()) 141 | .append(" wsname:").append(getWorkspaceName()); 142 | 143 | return sb.toString(); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTWmsStoreList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; 30 | 31 | import org.jdom.Element; 32 | 33 | /** 34 | * Parses list of summary data about WmsStores. 35 | * 36 | *

This is the XML REST representation: 37 | *

{@code 
38 | 
39 | 	
40 | 		regione
41 | 		
42 | 	
43 | 
44 |  *
45 | }
46 | * 47 | * @author cip 48 | */ 49 | public class RESTWmsStoreList extends RESTAbstractList { 50 | 51 | public static RESTWmsStoreList build(String response) { 52 | Element elem = JDOMBuilder.buildElement(response); 53 | return elem == null? null : new RESTWmsStoreList(elem); 54 | } 55 | 56 | protected RESTWmsStoreList(Element list) { 57 | super(list); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTWorkspaceList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder; 27 | 28 | import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; 29 | import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; 30 | 31 | import java.util.ArrayList; 32 | import java.util.Collections; 33 | import java.util.Iterator; 34 | import java.util.List; 35 | 36 | import org.jdom.Element; 37 | 38 | /** 39 | * Parses list of summary data about Workspaces. 40 | *
Single items are handled by {@link RESTShortWorkspace}. 41 | 42 | * @author ETj (etj at geo-solutions.it) 43 | */ 44 | public class RESTWorkspaceList implements Iterable { 45 | 46 | private final List wsList; 47 | 48 | public static RESTWorkspaceList build(String response) { 49 | if(response == null) 50 | return null; 51 | 52 | Element elem = JDOMBuilder.buildElement(response); 53 | if(elem != null) 54 | return new RESTWorkspaceList(elem); 55 | else 56 | return null; 57 | } 58 | 59 | protected RESTWorkspaceList(Element wslistroot) { 60 | List tmpList = new ArrayList(); 61 | for (Element wselem : (List) wslistroot.getChildren("workspace")) { 62 | tmpList.add(wselem); 63 | } 64 | 65 | wsList = Collections.unmodifiableList(tmpList); 66 | } 67 | 68 | public int size() { 69 | return wsList.size(); 70 | } 71 | 72 | public boolean isEmpty() { 73 | return wsList.isEmpty(); 74 | } 75 | 76 | public RESTShortWorkspace get(int index) { 77 | return new RESTShortWorkspace(wsList.get(index)); 78 | } 79 | 80 | public Iterator iterator() { 81 | return new RESTWSListIterator(wsList); 82 | } 83 | 84 | 85 | private static class RESTWSListIterator implements Iterator { 86 | 87 | private final Iterator iter; 88 | 89 | public RESTWSListIterator(List orig) { 90 | iter = orig.iterator(); 91 | } 92 | 93 | public boolean hasNext() { 94 | return iter.hasNext(); 95 | } 96 | 97 | public RESTShortWorkspace next() { 98 | return new RESTShortWorkspace(iter.next()); 99 | } 100 | 101 | public void remove() { 102 | throw new UnsupportedOperationException("Not supported."); 103 | } 104 | } 105 | 106 | /** 107 | * Workspace summary info. 108 | *
This is an XML fragment: 109 | *
110 |      * {@code
111 |      *   
112 |      *      it.geosolutions
113 |      *      
117 |      *  
118 |      * }
119 |      * 
120 | */ 121 | 122 | public static class RESTShortWorkspace extends NameLinkElem { 123 | 124 | public RESTShortWorkspace(Element elem) { 125 | super(elem); 126 | } 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/package.html: -------------------------------------------------------------------------------- 1 | 2 | Decoders for GeoServer's beans. 3 | Only some getters are available; there were developed only the most used getters, 4 | in order not to replicate the whole GeoServer beans hierarchy. 5 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/utils/JDOMBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder.utils; 27 | 28 | import java.io.IOException; 29 | import java.io.StringReader; 30 | 31 | import org.jdom.Document; 32 | import org.jdom.Element; 33 | import org.jdom.JDOMException; 34 | import org.jdom.input.SAXBuilder; 35 | import org.slf4j.Logger; 36 | import org.slf4j.LoggerFactory; 37 | 38 | /** 39 | * 40 | * @author ETj (etj at geo-solutions.it) 41 | */ 42 | public class JDOMBuilder { 43 | 44 | private final static Logger LOGGER = LoggerFactory.getLogger(JDOMBuilder.class); 45 | 46 | public static Element buildElement(String response) { 47 | if(response == null) 48 | return null; 49 | 50 | try{ 51 | SAXBuilder builder = new SAXBuilder(); 52 | Document doc = builder.build(new StringReader(response)); 53 | return doc.getRootElement(); 54 | } catch (JDOMException ex) { 55 | LOGGER.warn("Ex parsing response", ex); 56 | } catch (IOException ex) { 57 | LOGGER.warn("Ex loading response", ex); 58 | } 59 | 60 | return null; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/utils/JDOMListIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder.utils; 27 | 28 | import java.util.Iterator; 29 | import java.util.List; 30 | 31 | import org.jdom.Element; 32 | 33 | /** 34 | * 35 | * @author ETj (etj at geo-solutions.it) 36 | */ 37 | public abstract class JDOMListIterator implements Iterator { 38 | 39 | private final Iterator iter; 40 | 41 | public JDOMListIterator(List orig) { 42 | iter = orig.iterator(); 43 | } 44 | 45 | public boolean hasNext() { 46 | return iter.hasNext(); 47 | } 48 | 49 | public ELEM next() { 50 | return transform(iter.next()); 51 | } 52 | 53 | public abstract ELEM transform(Element listItem); 54 | 55 | public void remove() { 56 | throw new UnsupportedOperationException("Not supported."); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/utils/NameLinkElem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.decoder.utils; 27 | 28 | import org.jdom.Element; 29 | 30 | /** 31 | * 32 | * @author ETj (etj at geo-solutions.it) 33 | */ 34 | public class NameLinkElem { 35 | private final Element elem; 36 | 37 | public NameLinkElem(Element elem) { 38 | this.elem = elem; 39 | } 40 | 41 | public String getName() { 42 | return elem.getChildText("name"); 43 | } 44 | 45 | public String getValue() { 46 | 47 | return elem.getContent(0).getValue(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/decoder/utils/package.html: -------------------------------------------------------------------------------- 1 | 2 | Some util classes for decoders. 3 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/GSAbstractStoreEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder; 26 | 27 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; 28 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType; 29 | import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; 30 | import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; 31 | 32 | import org.jdom.Element; 33 | 34 | /** 35 | * Generic Store encoder. 36 | * 37 | * Provides getters and setters for parameters common to all CoverageStore. 38 | * 39 | * @author Carlo Cancellieri - GeoSolutions 40 | */ 41 | public abstract class GSAbstractStoreEncoder extends PropertyXMLEncoder { 42 | 43 | private final StoreType type; 44 | 45 | protected GSAbstractStoreEncoder(StoreType type, String storeName) { 46 | super(type.getType()); 47 | this.type=type; 48 | } 49 | 50 | public StoreType getStoreType() { 51 | return this.type; 52 | } 53 | 54 | public void setType(String type) { 55 | set("type", type); 56 | } 57 | 58 | public String getType() { 59 | return ElementUtils.contains(getRoot(), "type").getTextTrim(); 60 | } 61 | 62 | public void setName(String name) { 63 | ensureValidName(name); 64 | set("name", name); 65 | } 66 | 67 | public String getName() { 68 | Element e = ElementUtils.contains(getRoot(), "name"); 69 | return e!=null?e.getTextTrim():null; 70 | } 71 | 72 | public void setDescription(String description) { 73 | set("description", description); 74 | } 75 | 76 | public String getDescription() { 77 | Element e = ElementUtils.contains(getRoot(), "description"); 78 | return e!=null?e.getTextTrim():null; 79 | } 80 | 81 | public void setEnabled(boolean enabled) { 82 | set("enabled", Boolean.toString(enabled)); 83 | } 84 | 85 | public boolean getEnabled() { 86 | Element e = ElementUtils.contains(getRoot(), "name"); 87 | if (e!=null) 88 | return Boolean.parseBoolean(e.getTextTrim()); 89 | else 90 | return false; 91 | } 92 | 93 | /** 94 | * Check name validity. 95 | * 96 | * @param name the name 97 | * @throws IllegalArgumentException if name is null or empty 98 | */ 99 | protected void ensureValidName(String name) { 100 | if (name == null || name.isEmpty()) { 101 | throw new IllegalArgumentException("Store name cannot be null or empty"); 102 | } 103 | } 104 | 105 | /** 106 | * Check type validity. 107 | * 108 | * @param type the type. 109 | * @throws IllegalArgumentException if type is not {@value #TYPE} 110 | */ 111 | protected void ensureValidType(String type) { 112 | if (!type.equals(getValidType())) { 113 | throw new IllegalArgumentException("The store type '" + type + "' is not valid"); 114 | } 115 | } 116 | 117 | /** 118 | * The type of the implementing store. 119 | */ 120 | protected abstract String getValidType(); 121 | } 122 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2013 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.encoder; 27 | 28 | import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; 29 | 30 | import org.jdom.Element; 31 | 32 | /** 33 | * LayerGroup encoder for GeoServer < 2.3 34 | * 35 | * @author Davide Savazzi (geo-solutions.it) 36 | */ 37 | public class GSLayerGroupEncoder extends PropertyXMLEncoder { 38 | 39 | protected Element nameElem; 40 | protected Element workspaceElem; 41 | protected Element boundsElem; 42 | protected Element publishablesElem; 43 | protected Element stylesElem; 44 | 45 | 46 | public GSLayerGroupEncoder() { 47 | super("layerGroup"); 48 | } 49 | 50 | 51 | public void setWorkspace(String workspace) { 52 | workspaceElem = elem("workspace", elem("name", workspace)); 53 | } 54 | 55 | public void setName(String name) { 56 | nameElem = elem("name", name); 57 | } 58 | 59 | public void addLayer(String layer) { 60 | addLayer(layer, null); 61 | } 62 | 63 | public void addLayer(String layer, String styleName) { 64 | initPublishables("layers"); 65 | 66 | publishablesElem.addContent(elem("layer", elem("name", layer))); 67 | 68 | Element style = new Element("style"); 69 | stylesElem.addContent(style); 70 | if (styleName != null) { 71 | style.addContent(elem("name", styleName)); 72 | } 73 | } 74 | 75 | public void setBounds(String crs, double minx, double maxx, double miny, double maxy) { 76 | boundsElem = elem("bounds", 77 | elem("minx", Double.toString(minx)), 78 | elem("maxx", Double.toString(maxx)), 79 | elem("miny", Double.toString(miny)), 80 | elem("maxy", Double.toString(maxy)), 81 | elem("crs", "class", "projected").setText(crs)); 82 | } 83 | 84 | protected void initPublishables(String publishablesTag) { 85 | if (publishablesElem == null) { 86 | publishablesElem = new Element(publishablesTag); 87 | } 88 | 89 | if (stylesElem == null) { 90 | stylesElem = new Element("styles"); 91 | } 92 | } 93 | 94 | protected void addToRoot(Element ... elements) { 95 | for (Element e : elements) { 96 | if (e != null) { 97 | getRoot().addContent(e); 98 | } 99 | } 100 | } 101 | 102 | protected Element elem(String tag, String attributeName, String attributeValue) { 103 | return new Element(tag).setAttribute(attributeName, attributeValue); 104 | } 105 | 106 | protected Element elem(String tag, String text) { 107 | return new Element(tag).setText(text); 108 | } 109 | 110 | protected Element elem(String tag, Element ... children) { 111 | Element parent = new Element(tag); 112 | for (Element child : children) { 113 | parent.addContent(child); 114 | } 115 | return parent; 116 | } 117 | 118 | @Override 119 | public String toString() { 120 | addToRoot(nameElem, workspaceElem, boundsElem, publishablesElem, stylesElem); 121 | return super.toString(); 122 | } 123 | } -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder23.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2013 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.encoder; 27 | 28 | import java.util.HashSet; 29 | import java.util.Set; 30 | 31 | import org.jdom.Element; 32 | 33 | /** 34 | * LayerGroup encoder for GeoServer >= 2.3 35 | * 36 | * @author Davide Savazzi (geo-solutions.it) 37 | */ 38 | public class GSLayerGroupEncoder23 extends GSLayerGroupEncoder { 39 | 40 | public static final String MODE_SINGLE = "SINGLE"; 41 | public static final String MODE_NAMED = "NAMED"; 42 | public static final String MODE_CONTAINER = "CONTAINER"; 43 | public static final String MODE_EO = "EO"; 44 | private static final Set modes; 45 | static { 46 | modes = new HashSet(); 47 | modes.add(MODE_SINGLE); 48 | modes.add(MODE_NAMED); 49 | modes.add(MODE_CONTAINER); 50 | modes.add(MODE_EO); 51 | } 52 | 53 | private Element titleElem; 54 | private Element abstractElem; 55 | private Element modeElem; 56 | private Element rootLayerElem; 57 | private Element rootLayerStyleElem; 58 | 59 | public void setTitle(String title) { 60 | titleElem = elem("title", title); 61 | } 62 | 63 | public void setAbstract(String abstractTxt) { 64 | abstractElem = elem("abstractTxt", abstractTxt); 65 | } 66 | 67 | public void setMode(String mode) { 68 | if (!modes.contains(mode)) { 69 | throw new IllegalArgumentException("Invalid mode: " + mode); 70 | } 71 | 72 | modeElem = elem("mode", mode); 73 | } 74 | 75 | public void setRootLayer(String layer, String style) { 76 | rootLayerElem = elem("rootLayer", elem("name", layer)); 77 | rootLayerStyleElem = elem("rootLayerStyle", elem("name", style)); 78 | } 79 | 80 | @Override 81 | public void addLayer(String layer, String styleName) { 82 | initPublishables("publishables"); 83 | 84 | publishablesElem.addContent( 85 | new Element("published").setAttribute("type", "layer").addContent( 86 | elem("name", layer))); 87 | 88 | Element style = new Element("style"); 89 | stylesElem.addContent(style); 90 | if (styleName != null) { 91 | style.addContent(elem("name", styleName)); 92 | } 93 | } 94 | 95 | public void addLayer(String layer, String styleName, String styleWorkspace) { 96 | initPublishables("publishables"); 97 | 98 | publishablesElem.addContent( 99 | new Element("published").setAttribute("type", "layer").addContent( 100 | elem("name", layer))); 101 | 102 | Element style = new Element("style"); 103 | stylesElem.addContent(style); 104 | if (styleName != null) { 105 | style.addContent(elem("name", styleName)); 106 | style.addContent(elem("workspace", styleWorkspace)); 107 | } 108 | } 109 | 110 | public void addLayerGroup(String group) { 111 | initPublishables("publishables"); 112 | 113 | publishablesElem.addContent( 114 | new Element("published").setAttribute("type", "layerGroup").addContent( 115 | elem("name", group))); 116 | 117 | stylesElem.addContent(new Element("style")); 118 | } 119 | 120 | @Override 121 | public String toString() { 122 | addToRoot(titleElem, abstractElem, modeElem, rootLayerElem, rootLayerStyleElem); 123 | return super.toString(); 124 | } 125 | } -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/GSNamespaceEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder; 26 | 27 | import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; 28 | import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; 29 | 30 | import java.net.URI; 31 | 32 | /** 33 | * Namespace XML encoder. Namespaces must contain a non empty prefix and a URI: 34 | * 35 | *
 36 |  * <namespace>
 37 |  *   <prefix>example</prefix>
 38 |  *   <uri>http://example.com</uri>
 39 |  * </namespace>
 40 |  * 
41 | * 42 | * @see GeoServer Documentation 43 | * @author Oscar Fonts 44 | */ 45 | public class GSNamespaceEncoder extends PropertyXMLEncoder { 46 | 47 | public final static String NAMESPACE="namespace"; 48 | public final static String PREFIX="prefix"; 49 | public final static String URI="uri"; 50 | 51 | /** 52 | * Create a namespace XML encoder. 53 | * 54 | * @param prefix the namespace prefix 55 | * @param uri the namespace URI 56 | * @throws IllegalArgumentException if prefix or uri are null or empty 57 | */ 58 | public GSNamespaceEncoder(String prefix, URI uri) { 59 | super(NAMESPACE); 60 | 61 | ensureValidPrefix(prefix); 62 | ensureValidURI(uri); 63 | 64 | add(PREFIX, prefix); 65 | add(URI, uri.toString()); 66 | } 67 | 68 | /** 69 | * Get the namespace prefix. 70 | * @return the prefix 71 | */ 72 | public String getPrefix() { 73 | return ElementUtils.contains(getRoot(), PREFIX).getTextTrim(); 74 | } 75 | 76 | /** 77 | * Change the namespace prefix. 78 | * @param prefix the new prefix 79 | * @throws IllegalArgumentException if prefix is null or empty 80 | */ 81 | public void setPrefix(final String prefix) { 82 | ensureValidPrefix(prefix); 83 | ElementUtils.contains(getRoot(), PREFIX).setText(prefix); 84 | } 85 | 86 | /** 87 | * Get the namespace uri. 88 | * @return the uri 89 | */ 90 | public URI getURI() { 91 | String sUri = ElementUtils.contains(getRoot(), URI).getTextTrim(); 92 | return java.net.URI.create(sUri); 93 | } 94 | 95 | /** 96 | * change the nampespace uri. 97 | * @param URI the new uri 98 | * @throws IllegalArgumentException if uri is null or empty 99 | */ 100 | public void setURI(final URI uri) { 101 | ensureValidURI(uri); 102 | String sUri = uri.toString(); 103 | ElementUtils.contains(getRoot(), URI).setText(sUri); 104 | } 105 | 106 | /** 107 | * Check prefix value. 108 | * 109 | * @param prefix the prefix 110 | * @throws IllegalArgumentException if prefix is null or empty 111 | */ 112 | private static void ensureValidPrefix(String prefix) { 113 | if (prefix == null || prefix.isEmpty()) { 114 | throw new IllegalArgumentException( 115 | "Namespace prefix cannot be null or empty"); 116 | } 117 | } 118 | 119 | /** 120 | * Check uri value. 121 | * 122 | * @param prefix the uri 123 | * @throws IllegalArgumentException if uri is null or empty 124 | */ 125 | private static void ensureValidURI(URI uri) { 126 | if (uri == null || uri.toString().isEmpty()) { 127 | throw new IllegalArgumentException( 128 | "Namespace uri cannot be null or empty"); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/GSWorkspaceEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.encoder; 27 | 28 | import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; 29 | import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; 30 | 31 | import org.jdom.Element; 32 | 33 | /** 34 | * 35 | * @author ETj (etj at geo-solutions.it) 36 | * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it 37 | */ 38 | public class GSWorkspaceEncoder extends PropertyXMLEncoder { 39 | public final static String WORKSPACE="workspace"; 40 | public final static String NAME="name"; 41 | 42 | public GSWorkspaceEncoder() { 43 | super(WORKSPACE); 44 | } 45 | 46 | /** 47 | * @param name the workspace name 48 | */ 49 | public GSWorkspaceEncoder(String name) { 50 | super(WORKSPACE); 51 | addName(name); 52 | } 53 | 54 | /** 55 | * Add the name to this workspace 56 | * @param name 57 | * @throws IllegalStateException if name is already set 58 | */ 59 | protected void addName(final String name) { 60 | final Element el=ElementUtils.contains(getRoot(),NAME); 61 | if (el==null) 62 | add(NAME, name); 63 | else 64 | throw new IllegalStateException("Workspace name is already set: "+el.getText()); 65 | } 66 | 67 | /** 68 | * add or change (if already set) the workspace name 69 | * @param name 70 | */ 71 | public void setName(final String name) { 72 | final Element el=ElementUtils.contains(getRoot(),NAME); 73 | if (el==null) 74 | add(NAME, name); 75 | else 76 | el.setText(name); 77 | } 78 | 79 | public String getName(){ 80 | final Element el=ElementUtils.contains(getRoot(),NAME); 81 | if (el!=null) 82 | return el.getTextTrim(); 83 | else 84 | return null; 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/authorityurl/AuthorityURLInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.authorityurl; 26 | 27 | /** 28 | * Enumeration of layer authorityURL members 29 | * 30 | * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | 31 | * emmanuel.blondel@fao.org 32 | * 33 | */ 34 | public enum AuthorityURLInfo { 35 | 36 | name, href; 37 | } -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSAbstractCoveragestoreEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.coverage; 26 | 27 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType; 28 | import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder; 29 | 30 | /** 31 | * Generic CoverageStore encoder. 32 | * 33 | * Provides getters and setters for parameters common to all CoverageStore. 34 | * 35 | * @author Carlo Cancellieri - GeoSolutions 36 | * 37 | * @deprecated TODO complete specialization 38 | */ 39 | public abstract class GSAbstractCoveragestoreEncoder extends GSAbstractStoreEncoder { 40 | 41 | protected GSAbstractCoveragestoreEncoder(String storeName) { 42 | super(StoreType.COVERAGESTORES,storeName); 43 | // Add mandatory parameter 44 | ensureValidName(storeName); 45 | setName(storeName); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSAbstractDatastoreEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.datastore; 26 | 27 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; 28 | import it.geosolutions.geoserver.rest.decoder.RESTDataStore; 29 | import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder; 30 | import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder; 31 | 32 | import java.util.Map; 33 | 34 | /** 35 | * Generic Datastore encoder. 36 | * 37 | * Provides getters and setters for parameters common to all Datastores, an internal placeholder for specific connection parameters, and a constructor 38 | * to read parameters from a {@link RESTDataStore}. 39 | * 40 | * @author Oscar Fonts 41 | */ 42 | public abstract class GSAbstractDatastoreEncoder extends GSAbstractStoreEncoder { 43 | 44 | final static String ROOT = "dataStore"; 45 | 46 | NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters"); 47 | 48 | GSAbstractDatastoreEncoder(String storeName) { 49 | super(GeoServerRESTPublisher.StoreType.DATASTORES, ROOT); 50 | // Add mandatory parameter 51 | ensureValidName(storeName); 52 | setName(storeName); 53 | 54 | // Add connection parameters 55 | addContent(connectionParameters.getRoot()); 56 | } 57 | 58 | /** 59 | * Create a {@value #TYPE} datastore encoder from a store read from server. 60 | * 61 | * @param store The existing store. 62 | * @throws IllegalArgumentException if store type or mandatory parameters are not valid 63 | */ 64 | GSAbstractDatastoreEncoder(RESTDataStore store) { 65 | this(store.getName()); 66 | 67 | // Match datastore type 68 | ensureValidType(store.getStoreType()); 69 | 70 | // Copy store parameters 71 | setDescription(store.getDescription()); 72 | setEnabled(store.isEnabled()); 73 | 74 | // Copy connection parameters - bulk 75 | Map params = store.getConnectionParameters(); 76 | for (String key : params.keySet()) { 77 | connectionParameters.set(key, params.get(key)); 78 | } 79 | } 80 | 81 | /** 82 | * The type of the implementing datastore. 83 | */ 84 | protected abstract String getValidType(); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSDirectoryOfShapefilesDatastoreEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.datastore; 26 | 27 | import it.geosolutions.geoserver.rest.decoder.RESTDataStore; 28 | 29 | import java.net.URL; 30 | 31 | /** 32 | * Encoder for a {@value #TYPE} datastore. 33 | * 34 | * @author Oscar Fonts 35 | */ 36 | public class GSDirectoryOfShapefilesDatastoreEncoder extends GSShapefileDatastoreEncoder { 37 | 38 | static final String TYPE = "Directory of spatial files (shapefiles)"; 39 | 40 | /** 41 | * Create a {@value #TYPE} datastore with default connection parameters, given a store name and a url (the store location). 42 | * 43 | * @param name New datastore name 44 | * @param url The shapefile location in the server, relative to $GEOSERVER_DATA_DIR. 45 | */ 46 | public GSDirectoryOfShapefilesDatastoreEncoder(String name, URL url) { 47 | super(name, url); 48 | setType(TYPE); 49 | } 50 | 51 | /** 52 | * Create a {@value #TYPE} datastore encoder from an existing store read from server. 53 | * 54 | * @param store The existing store. 55 | * @throws IllegalArgumentException if store type or mandatory parameters are not valid 56 | */ 57 | public GSDirectoryOfShapefilesDatastoreEncoder(RESTDataStore store) { 58 | super(store); 59 | } 60 | 61 | /** 62 | * @return {@value #TYPE} 63 | */ 64 | protected String getValidType() { 65 | return TYPE; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSGeoTIFFDatastoreEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.datastore; 26 | 27 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType; 28 | import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder; 29 | import it.geosolutions.geoserver.rest.encoder.utils.XmlElement; 30 | 31 | import java.net.URL; 32 | 33 | /** 34 | * Encoder for a {@value #TYPE} datastore. 35 | * 36 | * @author Peter van de Riet 37 | */ 38 | public class GSGeoTIFFDatastoreEncoder extends GSAbstractStoreEncoder { 39 | static final String TYPE = "GeoTIFF"; 40 | 41 | public GSGeoTIFFDatastoreEncoder(String name) { 42 | super(StoreType.COVERAGESTORES, name); 43 | setName(name); 44 | 45 | // Set mandatory parameter 46 | setType(TYPE); 47 | add("enabled", "true"); 48 | } 49 | 50 | public void setUrl(URL url) { 51 | add("url", url.toString()); 52 | } 53 | /** 54 | * @return {@value #TYPE} 55 | */ 56 | protected String getValidType() { 57 | return TYPE; 58 | } 59 | 60 | public void setWorkspaceName(String workspaceName) { 61 | GsWorkspaceElement workspaceXml = new GsWorkspaceElement(workspaceName); 62 | addContent(workspaceXml.getRoot()); 63 | } 64 | 65 | private class GsWorkspaceElement extends XmlElement { 66 | public GsWorkspaceElement(String workspaceName) { 67 | super("workspace"); 68 | add("name", workspaceName); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSMosaicDatastoreEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.datastore; 26 | 27 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType; 28 | import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder; 29 | import it.geosolutions.geoserver.rest.encoder.utils.XmlElement; 30 | 31 | import java.net.URL; 32 | 33 | /** 34 | * Encoder for a {@value #TYPE} datastore. 35 | * 36 | * @author Peter van de Riet 37 | */ 38 | public class GSMosaicDatastoreEncoder extends GSAbstractStoreEncoder { 39 | static final String TYPE = "ImageMosaic"; 40 | 41 | public GSMosaicDatastoreEncoder(String name) { 42 | super(StoreType.COVERAGESTORES, name); 43 | // super(name); 44 | setName(name); 45 | 46 | // Set mandatory parameter 47 | setType(TYPE); 48 | add("enabled", "true"); 49 | } 50 | 51 | public void setUrl(URL url) { 52 | add("url", url.toString()); 53 | } 54 | 55 | /** 56 | * @return {@value #TYPE} 57 | */ 58 | protected String getValidType() { 59 | return TYPE; 60 | } 61 | 62 | public void setWorkspaceName(String workspaceName) { 63 | GsWorkspaceElement workspaceXml = new GsWorkspaceElement(workspaceName); 64 | addContent(workspaceXml.getRoot()); 65 | } 66 | 67 | private class GsWorkspaceElement extends XmlElement { 68 | public GsWorkspaceElement(String workspaceName) { 69 | super("workspace"); 70 | add("name", workspaceName); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/FeatureTypeAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.feature; 26 | 27 | /** 28 | * Enumeration of featureType attribute members 29 | */ 30 | public enum FeatureTypeAttribute { 31 | name, minOccurs, maxOccurs, nillable, binding, length 32 | } -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSAttributeEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.feature; 26 | 27 | import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; 28 | import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; 29 | 30 | import java.util.Map; 31 | import java.util.Map.Entry; 32 | 33 | import org.jdom.Element; 34 | import org.jdom.filter.Filter; 35 | 36 | /** 37 | * 38 | * @author carlo cancellieri - GeoSolutions 39 | * 40 | */ 41 | public class GSAttributeEncoder extends PropertyXMLEncoder { 42 | 43 | public static class filterByName implements Filter { 44 | 45 | final private String key; 46 | 47 | public filterByName(String keyword){ 48 | this.key=keyword; 49 | } 50 | 51 | private static final long serialVersionUID = 1L; 52 | 53 | public boolean matches(Object obj) { 54 | Element el=((Element) obj).getChild(FeatureTypeAttribute.name.toString()); 55 | if (el!=null && el.getTextTrim().equals(key)) { 56 | return true; 57 | } 58 | return false; 59 | } 60 | } 61 | 62 | public static Filter getFilterByName(String name){ 63 | return new filterByName(name); 64 | } 65 | 66 | public GSAttributeEncoder() { 67 | super("attribute"); 68 | } 69 | 70 | public void setup(Map attributes){ 71 | for (Entry attr:attributes.entrySet()){ 72 | set(attr.getKey().toString(),attr.getValue()); 73 | } 74 | } 75 | 76 | public void setAttribute(FeatureTypeAttribute type, String value){ 77 | set(type.toString(),value); 78 | } 79 | 80 | public void delAttribute(FeatureTypeAttribute type){ 81 | ElementUtils.remove(this.getRoot(), get(type.toString())); 82 | } 83 | 84 | public String getAttribute(FeatureTypeAttribute type){ 85 | Element el = get(type.toString()); 86 | if (el!=null) 87 | return el.getTextTrim(); 88 | else 89 | return null; 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureTypeEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.encoder.feature; 27 | 28 | import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; 29 | import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; 30 | import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder; 31 | import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.GSVirtualTableEncoder; 32 | 33 | import org.jdom.Element; 34 | 35 | /** 36 | * 37 | * Encode a GeoServer resource as FeatureType 38 | * 39 | * @author ETj (etj at geo-solutions.it) 40 | * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it 41 | */ 42 | public class GSFeatureTypeEncoder extends GSResourceEncoder { 43 | 44 | public final static String ATTRIBUTES = "attributes"; 45 | 46 | final private Element attributes = new Element(ATTRIBUTES); 47 | 48 | public GSFeatureTypeEncoder() { 49 | super("featureType"); 50 | addContent(attributes); 51 | } 52 | 53 | 54 | /** 55 | * @deprecated Use {@link GSResourceEncoder#addMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon 56 | * @param key 57 | * @param dimensionInfo 58 | * 59 | */ 60 | protected void addMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) { 61 | super.addMetadata(key, dimensionInfo); 62 | } 63 | 64 | 65 | /** 66 | * @deprecated Use {@link GSResourceEncoder#setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon 67 | * @param key 68 | * @param dimensionInfo 69 | * 70 | */ 71 | public void setMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) { 72 | super.setMetadata(key, dimensionInfo); 73 | } 74 | 75 | /** 76 | * Add a VirtualTable (SQL View feature type) 77 | * 78 | * @param virtualtable 79 | */ 80 | protected void addMetadataVirtualTable( 81 | final GSVirtualTableEncoder virtualtable) { 82 | super.addMetadata("JDBC_VIRTUAL_TABLE", virtualtable); 83 | } 84 | 85 | /** 86 | * Set a VirtualTable (SQL View feature type) 87 | * 88 | * @param virtualtable 89 | */ 90 | public void setMetadataVirtualTable(final GSVirtualTableEncoder virtualtable) { 91 | super.setMetadata("JDBC_VIRTUAL_TABLE", virtualtable); 92 | } 93 | 94 | /** 95 | * Deletes the VirtualTable metadata 96 | * 97 | * @return true if deleted, false otherwise 98 | */ 99 | public boolean delMetadataVirtualTable(){ 100 | return super.delMetadata("JDB_VIRTUAL_TABLE"); 101 | } 102 | 103 | /** 104 | * delete a keyword from the list 105 | * 106 | * @param keyword 107 | * @return true if something is removed, false otherwise 108 | */ 109 | public boolean delAttribute(final String keyword) { 110 | final Element el = new Element("string"); 111 | el.setText(keyword); 112 | return (attributes.removeContent(GSAttributeEncoder.getFilterByName(keyword))).size() == 0 ? false 113 | : true; 114 | } 115 | 116 | /** 117 | * @param attribute the attribute to add 118 | */ 119 | protected void addAttribute(GSAttributeEncoder attribute) { 120 | attributes.addContent(attribute.getRoot()); 121 | } 122 | 123 | /** 124 | * @param attribute the attribute to set (overriding an attribute with the same name if present) 125 | */ 126 | public void setAttribute(GSAttributeEncoder attribute) { 127 | delAttribute(attribute.getAttribute(FeatureTypeAttribute.name)); 128 | addAttribute(attribute); 129 | } 130 | 131 | } -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/identifier/IdentifierInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.identifier; 26 | 27 | /** 28 | * Enumeration of layer authorityURL members 29 | * 30 | * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | 31 | * emmanuel.blondel@fao.org 32 | * 33 | */ 34 | public enum IdentifierInfo { 35 | 36 | authority, identifier; 37 | } -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSDimensionInfoEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.encoder.metadata; 27 | 28 | import it.geosolutions.geoserver.rest.encoder.utils.XmlElement; 29 | 30 | import java.math.BigDecimal; 31 | 32 | /** 33 | * 34 | * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it 35 | * @author Simone Giannecchini, GeoSolutions 36 | * 37 | */ 38 | public class GSDimensionInfoEncoder extends XmlElement{ 39 | public final static String DIMENSIONINFO="dimensionInfo"; 40 | 41 | public final static String RESOLUTION="resolution"; 42 | 43 | public final static String PRESENTATION="presentation"; 44 | 45 | public final static String UNITS="units"; 46 | 47 | public final static String UNIT_SYMBOL="unitSymbol"; 48 | 49 | private boolean enabled; 50 | 51 | /** 52 | * Enum for presentation mode 53 | */ 54 | public enum Presentation { 55 | LIST, 56 | CONTINUOUS_INTERVAL, 57 | DISCRETE_INTERVAL 58 | } 59 | 60 | /** 61 | * Build a dimension 62 | * @param enabled enable dimension if true 63 | * @note a enabled dimension also need a presentation mode set. 64 | */ 65 | public GSDimensionInfoEncoder(final boolean enabled) { 66 | super(DIMENSIONINFO); 67 | add("enabled", (enabled)?"true":"false"); 68 | this.enabled=enabled; 69 | } 70 | 71 | /** 72 | * build an not enabled dimension 73 | */ 74 | public GSDimensionInfoEncoder() { 75 | super(DIMENSIONINFO); 76 | add("enabled", "false"); 77 | this.enabled=Boolean.FALSE; 78 | } 79 | 80 | public void setEnabled(final boolean enabled){ 81 | set("enabled", "true"); 82 | this.enabled=Boolean.TRUE; 83 | } 84 | 85 | public void setPresentation(final Presentation pres){ 86 | setPresentation(pres, null); 87 | } 88 | 89 | /** 90 | * @param pres 91 | * @param interval 92 | */ 93 | protected void addPresentation(final Presentation pres, final BigDecimal interval){ 94 | if (enabled){ 95 | add(PRESENTATION,pres.toString()); 96 | if(pres==Presentation.DISCRETE_INTERVAL){ 97 | if(pres==Presentation.DISCRETE_INTERVAL&&interval==null){ 98 | throw new IllegalArgumentException("Null interval was provided while trying to set the presentation to discrete interval."); 99 | } 100 | add(RESOLUTION,String.valueOf(interval)); 101 | } else { 102 | remove(RESOLUTION); 103 | } 104 | } 105 | } 106 | 107 | public void setPresentation(final Presentation pres, final BigDecimal interval){ 108 | if (enabled){ 109 | set(PRESENTATION,pres.toString()); 110 | if(pres==Presentation.DISCRETE_INTERVAL){ 111 | if(pres==Presentation.DISCRETE_INTERVAL&&interval==null){ 112 | throw new IllegalArgumentException("Null interval was provided while trying to set the presentation to discrete interval."); 113 | } 114 | set(RESOLUTION,String.valueOf(interval)); 115 | } else { 116 | remove(RESOLUTION); 117 | } 118 | } 119 | } 120 | 121 | 122 | /** 123 | * Set UoM for this dimension. 124 | * 125 | * null is acceptable and leave this UoM blank. 126 | * 127 | * @param unit UoM for this dimension. 128 | */ 129 | public void setUnit(final String unit){ 130 | if(unit==null||unit.length()<=0){ 131 | return; 132 | } 133 | if (enabled){ 134 | set(UNITS,unit); 135 | } 136 | } 137 | 138 | /** 139 | * Set UoM for this dimension. 140 | * 141 | * null is acceptable and leave this UoM blank. 142 | * 143 | * @param unit UoM for this dimension. 144 | */ 145 | public void setUnitSymbol(final String unitSymbol){ 146 | if(unitSymbol==null||unitSymbol.length()<=0){ 147 | return; 148 | } 149 | if (enabled){ 150 | set(UNIT_SYMBOL,unitSymbol); 151 | } 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSFeatureDimensionInfoEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.encoder.metadata; 27 | 28 | 29 | public class GSFeatureDimensionInfoEncoder extends GSDimensionInfoEncoder { 30 | public final static String ATTRIBUTE="attribute"; 31 | public final static String END_ATTRIBUTE="endAttribute"; 32 | 33 | /** 34 | * if this dimension is enabled this constructor should be called. 35 | * @param attribute the attribute field name to use as dimension 36 | */ 37 | public GSFeatureDimensionInfoEncoder(final String attribute){ 38 | super(true); 39 | add(ATTRIBUTE, attribute); 40 | } 41 | 42 | /** 43 | * Change the attribute used as dimension 44 | * @param attribute the attribute to use as dimension 45 | */ 46 | public void setAttribute(final String attribute){ 47 | set(ATTRIBUTE, attribute); 48 | } 49 | 50 | /** 51 | * Set the end attribute used in the dimension (optional) 52 | * @param endAttribute the dimension end attribute 53 | */ 54 | public void setEndAttribute(final String endAttribute){ 55 | set(END_ATTRIBUTE, endAttribute); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/virtualtable/VTGeometry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable; 26 | 27 | /** 28 | * Enumeration of Virtual Table geometry members 29 | * 30 | * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | 31 | * emmanuel.blondel@fao.org 32 | * 33 | */ 34 | public enum VTGeometry { 35 | name, type, srid 36 | } 37 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/virtualtable/VTParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable; 26 | 27 | /** 28 | * Enumeration of SQL View featureType virtual table parameter members 29 | * 30 | * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | 31 | * emmanuel.blondel@fao.org 32 | * 33 | */ 34 | public enum VTParameter { 35 | name, defaultValue, regexpValidator 36 | 37 | } 38 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/metadatalink/ResourceMetadataLinkInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.encoder.metadatalink; 26 | 27 | /** 28 | * Enumeration of featureType metadataLink member 29 | * 30 | * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | 31 | * emmanuel.blondel@fao.org 32 | * 33 | */ 34 | public enum ResourceMetadataLinkInfo { 35 | type, metadataType, content 36 | 37 | } 38 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/package.html: -------------------------------------------------------------------------------- 1 | 2 | Encoders for GeoServer's beans. 3 | Only some setters are available; there were developed only the most used setters, 4 | in order not to replicate the whole GeoServer beans hierarchy. 5 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2011 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | package it.geosolutions.geoserver.rest.encoder.utils; 27 | 28 | 29 | import org.jdom.Content; 30 | import org.jdom.Element; 31 | import org.jdom.Text; 32 | import org.jdom.output.Format; 33 | import org.jdom.output.XMLOutputter; 34 | 35 | /** 36 | * 37 | * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it 38 | * 39 | */ 40 | public class XmlElement{ 41 | 42 | private Element root; 43 | 44 | 45 | private static final long serialVersionUID = 1L; 46 | 47 | private final static XMLOutputter OUTPUTTER = new XMLOutputter(Format.getCompactFormat()); 48 | 49 | public XmlElement(final String name){ 50 | root=new Element(name); 51 | } 52 | 53 | public XmlElement(final Element e) { 54 | root = e; 55 | } 56 | 57 | /** 58 | * Empty constructor:
59 | * Use {@link #setRoot()} to initialize the root 60 | */ 61 | protected XmlElement() { 62 | } 63 | 64 | /** 65 | * update the root of this node 66 | * @param root 67 | */ 68 | protected void setRoot(final Element root) { 69 | this.root = root; 70 | } 71 | 72 | /** 73 | * update the root of this node 74 | * @param name is the name of the root node 75 | */ 76 | protected void setRoot(final String name){ 77 | root=new Element(name); 78 | } 79 | 80 | public Element getRoot(){ 81 | return root; 82 | } 83 | 84 | protected void add(final String nodename, final String nodetext) { 85 | add(nodename,new Text(nodetext)); 86 | } 87 | 88 | protected void add(final String nodename, final Content nodetext) { 89 | final Element el=new Element(nodename); 90 | el.setContent(nodetext); 91 | this.addContent(el); 92 | } 93 | 94 | protected void set(final String nodename, final String nodetext) { 95 | set(nodename,new Text(nodetext)); 96 | } 97 | 98 | protected void set(final String nodename, final Content nodeContent) { 99 | final Element el=ElementUtils.contains(getRoot(),nodename); 100 | if (el==null){ 101 | add(nodename,nodeContent); 102 | } 103 | else { 104 | el.setContent(nodeContent); 105 | } 106 | } 107 | 108 | protected Element addContent(Content child){ 109 | return root.addContent(child); 110 | } 111 | 112 | public boolean isEmpty() { 113 | return root.getChildren().isEmpty(); 114 | } 115 | 116 | public boolean remove(final String key){ 117 | final Element el=ElementUtils.contains(root,key); 118 | if (el!=null){ 119 | return ElementUtils.remove(root,el); 120 | } 121 | else 122 | return false; 123 | } 124 | 125 | /** 126 | * @return an xml String 127 | */ 128 | @Override 129 | public String toString() { 130 | return OUTPUTTER.outputString(root); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/package.html: -------------------------------------------------------------------------------- 1 | 2 | Some util classes for encoders. 3 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/manager/GeoServerRESTAbstractManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GeoServer-Manager - Simple Manager Library for GeoServer 3 | * 4 | * Copyright (C) 2007,2012 GeoSolutions S.A.S. 5 | * http://www.geo-solutions.it 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package it.geosolutions.geoserver.rest.manager; 26 | 27 | import it.geosolutions.geoserver.rest.HTTPUtils; 28 | 29 | import java.net.MalformedURLException; 30 | import java.net.URL; 31 | 32 | /** 33 | * Abstract manager, common functionality and interface for all 34 | * GeoServerRESTFooManager classes. 35 | * 36 | * @author Oscar Fonts 37 | * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it 38 | */ 39 | public abstract class GeoServerRESTAbstractManager { 40 | 41 | protected final URL gsBaseUrl; 42 | protected final String gsuser; 43 | protected final String gspass; 44 | 45 | /** 46 | * Default constructor. 47 | * 48 | * Indicates connection parameters to remote GeoServer instance. 49 | * 50 | * @param restURL GeoServer REST API endpoint 51 | * @param username GeoServer REST API authorized username 52 | * @param password GeoServer REST API password for the former username 53 | */ 54 | public GeoServerRESTAbstractManager(URL restURL, String username, String password) 55 | throws IllegalArgumentException { 56 | try { 57 | if (restURL == null || username == null || password == null) 58 | throw new IllegalArgumentException("Unable to create the manager using a null argument"); 59 | 60 | this.gsBaseUrl = new URL(restURL.getProtocol(), restURL.getHost(), restURL.getPort(), 61 | HTTPUtils.decurtSlash(restURL.getPath()), null); 62 | 63 | this.gsuser = username; 64 | this.gspass = password; 65 | 66 | } catch (MalformedURLException ex) { 67 | throw new IllegalArgumentException("URL can't be parsed properly", ex); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /geoserver-manager/src/main/java/it/geosolutions/geoserver/rest/package.html: -------------------------------------------------------------------------------- 1 | 2 | Main GSManager classes are here. 3 | -------------------------------------------------------------------------------- /geoserver-rest/src/log4j.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/As-Zach/GeoServer-SpringBoot/efc98dcdfb88be7cd4912e0e48cbbfcb88ae260d/geoserver-rest/src/log4j.properties -------------------------------------------------------------------------------- /geoserver-rest/src/main/java/com/zach/services/DeleStore.java: -------------------------------------------------------------------------------- 1 | package com.zach.services; 2 | 3 | import it.geosolutions.geoserver.rest.GeoServerRESTManager; 4 | import it.geosolutions.geoserver.rest.decoder.RESTLayer; 5 | import it.geosolutions.geoserver.rest.encoder.datastore.GSGeoTIFFDatastoreEncoder; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.net.MalformedURLException; 9 | import java.net.URL; 10 | import java.util.List; 11 | 12 | @RestController 13 | @CrossOrigin(origins = "*",maxAge = 8095) 14 | public class DeleStore { 15 | @PostMapping("/delestore") 16 | public String Delete(@RequestBody String input) throws MalformedURLException { 17 | //GeoServer的连接配置 18 | String url = "http://localhost:8080/geoserver"; 19 | String username = "admin"; 20 | String passwd = "geoserver"; 21 | 22 | String store_name ; //待创建和发布图层的数据存储名称store 23 | String ws ; //待创建和发布图层的工作区名称workspace 24 | //判断工作区(workspace)是否存在,不存在则创建 25 | URL u = new URL(url); 26 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 27 | List workspaces = manager.getReader().getWorkspaceNames(); 28 | input = input.substring(0,input.length()-1); 29 | RESTLayer restLayer = manager.getReader().getLayer(input); 30 | ws = manager.getReader().getResource(restLayer).getNameSpace(); 31 | String StoreName = manager.getReader().getResource(restLayer).getStoreName(); 32 | store_name = StoreName.split(":")[1]; 33 | if (!workspaces.contains(ws)) { 34 | System.out.println("workspace不存在,ws : " + ws ); 35 | return String.valueOf(workspaces.contains(ws)); 36 | } else { 37 | System.out.println("workspace已经存在了,ws :" + ws); 38 | } 39 | GSGeoTIFFDatastoreEncoder gsGeoTIFFDatastoreEncoder = new GSGeoTIFFDatastoreEncoder(store_name); 40 | gsGeoTIFFDatastoreEncoder.setWorkspaceName(ws); 41 | boolean deleStore = manager.getStoreManager().remove(ws,gsGeoTIFFDatastoreEncoder,true); 42 | System.out.println("remove store : " + deleStore); 43 | return String.valueOf(deleStore); 44 | } 45 | 46 | @GetMapping("/tetstttja") 47 | public String test(){ 48 | return "retur"; 49 | } 50 | public static void main(String[] args){ 51 | // BasicConfigurator.configure(); //自动快速地使用缺省Log4j环境(spring boot中无需添加) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /geoserver-rest/src/main/java/com/zach/services/Fileurl.java: -------------------------------------------------------------------------------- 1 | package com.zach.services; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | @RestController 6 | @CrossOrigin(origins = "*",maxAge = 8095) 7 | public class Fileurl { 8 | 9 | @PostMapping("/testfile") 10 | public String Findfile(@RequestBody String input){ 11 | String url = "1111"; 12 | url = input; 13 | System.out.println(url); 14 | return url; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /geoserver-rest/src/main/java/com/zach/services/LayerDetail.java: -------------------------------------------------------------------------------- 1 | package com.zach.services; 2 | import it.geosolutions.geoserver.rest.GeoServerRESTManager; 3 | import it.geosolutions.geoserver.rest.decoder.RESTDataStore; 4 | import it.geosolutions.geoserver.rest.decoder.RESTLayer; 5 | import it.geosolutions.geoserver.rest.decoder.RESTLayerList; 6 | import lombok.Data; 7 | import org.apache.log4j.BasicConfigurator; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.io.File; 11 | import java.net.MalformedURLException; 12 | import java.net.URL; 13 | import java.util.List; 14 | 15 | @RestController 16 | @CrossOrigin(origins = "*",maxAge = 8095) 17 | public class LayerDetail { 18 | 19 | @Data 20 | public static class Bounds { 21 | private String SRS; 22 | private String NameSpace; 23 | private double MinX; 24 | private double MinY; 25 | private double MaxX; 26 | private double MaxY; 27 | 28 | 29 | public String getNameSpace() { 30 | return NameSpace; 31 | } 32 | 33 | public void setNameSpace(String nameSpace) { 34 | this.NameSpace = nameSpace; 35 | } 36 | public String getSRS() { 37 | return SRS; 38 | } 39 | 40 | public void setSRS(String SRS) { 41 | this.SRS = SRS; 42 | } 43 | 44 | public double getMinX() { 45 | return MinX; 46 | } 47 | 48 | public void setMinX(double minX) { 49 | MinX = minX; 50 | } 51 | 52 | public double getMinY() { 53 | return MinY; 54 | } 55 | 56 | public void setMinY(double minY) { 57 | MinY = minY; 58 | } 59 | 60 | public double getMaxX() { 61 | return MaxX; 62 | } 63 | 64 | public void setMaxX(double maxX) { 65 | MaxX = maxX; 66 | } 67 | 68 | public double getMaxY() { 69 | return MaxY; 70 | } 71 | 72 | public void setMaxY(double maxY) { 73 | MaxY = maxY; 74 | } 75 | } 76 | @PostMapping("/layerdetail") 77 | public Bounds getAll(@RequestBody String input) throws MalformedURLException { 78 | String url = "http://localhost:8080/geoserver"; 79 | String username = "admin"; 80 | String passwd = "geoserver"; 81 | URL u = new URL(url); 82 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 83 | input = input.substring(0,input.length()-1); 84 | RESTLayer restLayer = manager.getReader().getLayer(input); 85 | 86 | Bounds bounds = new Bounds(); 87 | bounds.setSRS(manager.getReader().getResource(restLayer).getSRS()); 88 | bounds.setNameSpace(manager.getReader().getResource(restLayer).getNameSpace()); 89 | bounds.setMinX(manager.getReader().getResource(restLayer).getMinX()); 90 | bounds.setMinY(manager.getReader().getResource(restLayer).getMinY()); 91 | bounds.setMaxX(manager.getReader().getResource(restLayer).getMaxX()); 92 | bounds.setMaxY(manager.getReader().getResource(restLayer).getMaxY()); 93 | return bounds; 94 | } 95 | 96 | @GetMapping("/layernames") 97 | public static List test01() throws MalformedURLException { 98 | String url = "http://localhost:8080/geoserver"; 99 | String username = "admin"; 100 | String passwd = "geoserver"; 101 | 102 | URL u = new URL(url); 103 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 104 | RESTLayerList restStore = manager.getReader().getLayers(); 105 | System.out.println(restStore.getNames()); 106 | return restStore.getNames(); 107 | } 108 | public static void main(String[] args) throws MalformedURLException { 109 | BasicConfigurator.configure(); //自动快速地使用缺省Log4j环境(spring boot中无需添加) 110 | //List test = test01(); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /geoserver-rest/src/main/java/com/zach/services/TreeDetail.java: -------------------------------------------------------------------------------- 1 | package com.zach.services; 2 | 3 | import it.geosolutions.geoserver.rest.GeoServerRESTManager; 4 | import it.geosolutions.geoserver.rest.decoder.RESTLayerList; 5 | import lombok.Data; 6 | import org.apache.log4j.BasicConfigurator; 7 | import org.springframework.web.bind.annotation.CrossOrigin; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.net.MalformedURLException; 12 | import java.net.URL; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | @RestController 17 | @CrossOrigin(origins = "*",maxAge = 8095) 18 | public class TreeDetail { 19 | 20 | @Data 21 | public static class Tree{ 22 | private String id; 23 | private String text; 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | 29 | public void setId(String id) { 30 | this.id = id; 31 | } 32 | 33 | public String getText() { 34 | return text; 35 | } 36 | 37 | public void setText(String text) { 38 | this.text = text; 39 | } 40 | 41 | public Tree(String id, String text) { 42 | this.id = id; 43 | this.text = text; 44 | } 45 | } 46 | 47 | @GetMapping("/treelist") 48 | public static List test01() throws MalformedURLException { 49 | String url = "http://localhost:8080/geoserver"; 50 | String username = "admin"; 51 | String passwd = "geoserver"; 52 | List list = new ArrayList(); 53 | list.add(new Tree("00","GeoServer")); 54 | list.add(new Tree("000","elevation")); 55 | list.add(new Tree("001","shp")); 56 | list.add(new Tree("002","map")); 57 | list.add(new Tree("003","cite")); 58 | //if (!list.contains()) 59 | URL u = new URL(url); 60 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 61 | RESTLayerList restStore = manager.getReader().getLayers(); 62 | List names = restStore.getNames(); 63 | list.add(new Tree("0011","China")); 64 | list.add(new Tree("0012","Russia")); 65 | for (int i=0;i rules = new HashMap(); 50 | List> legends = new ArrayList>(); 51 | rules.put("field", nodeFields.item(0).getTextContent().toLowerCase()); 52 | for(int i=0;i legend = new HashMap(); 56 | legend.put("title",title.getTextContent()); 57 | legend.put("rule",name.getTextContent()); 58 | legends.add(legend); 59 | } 60 | rules.put("rules",legends); 61 | JSON json = JSONObject.fromObject(rules); 62 | response.setContentType("text/html;charset=utf-8"); 63 | response.setCharacterEncoding("UTF-8"); 64 | PrintWriter out = response.getWriter(); 65 | out.println(json); 66 | out.flush(); 67 | out.close(); 68 | } 69 | } 70 | catch(Exception e){ 71 | e.printStackTrace(); 72 | } 73 | } 74 | 75 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 76 | this.doPost(request,response); 77 | } 78 | 79 | public static void main(String[] args) { 80 | String url = "http://localhost:8080/geoserver"; 81 | try { 82 | GeoServerRESTReader reader = new GeoServerRESTReader(url, "admin", "geoserver"); 83 | String workspace = "guotu"; 84 | RESTLayer restLayer = reader.getLayer(workspace, "csght"); 85 | String styleName = restLayer.getDefaultStyle(); 86 | String sld = reader.getSLD(styleName); 87 | if(sld!=null){ 88 | StringReader sr = new StringReader(sld); 89 | InputSource is = new InputSource(sr); 90 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 91 | DocumentBuilder builder = factory.newDocumentBuilder(); 92 | Document doc = (Document) builder.parse(is); 93 | NodeList nodeNames = doc.getElementsByTagName("sld:Name"); 94 | NodeList nodeTitles = doc.getElementsByTagName("ogc:Literal"); 95 | NodeList nodeFields = doc.getElementsByTagName("ogc:PropertyName"); 96 | Map rules = new HashMap(); 97 | List> legends = new ArrayList>(); 98 | rules.put("field", nodeFields.item(0).getTextContent().toLowerCase()); 99 | for(int i=0;i legend = new HashMap(); 103 | legend.put("title",title.getTextContent()); 104 | legend.put("rule",name.getTextContent()); 105 | legends.add(legend); 106 | } 107 | rules.put("rules",legends); 108 | JSON json = JSONObject.fromObject(rules); 109 | System.out.println(json); 110 | } 111 | } 112 | catch(Exception e){ 113 | e.printStackTrace(); 114 | } 115 | } 116 | } -------------------------------------------------------------------------------- /geoserver-rest/src/main/java/com/zach/services/test.java: -------------------------------------------------------------------------------- 1 | package com.zach.services; 2 | 3 | import org.springframework.web.bind.annotation.CrossOrigin; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import java.io.File; 8 | 9 | @RestController 10 | //@RequestMapping("/shp") 11 | 12 | @CrossOrigin(origins = "*",maxAge = 8095) 13 | 14 | public class test { 15 | @GetMapping("/test") 16 | public String index() { 17 | return "Test !!!"; 18 | } 19 | 20 | public static void main(String[] args){ 21 | /*遍历文件夹路径下.tif文件*/ 22 | String path = "F:\\Document\\Graduation Project\\MapData\\mapData_test\\Shp"; //要遍历的路径 23 | File file = new File(path); //获取其file对象 24 | File[] fs = file.listFiles(); //遍历path下的文件和目录,放在File数组中 25 | for(File f : fs) 26 | { 27 | if(f.isFile()) 28 | { 29 | if (f.getName().endsWith(".zip")) { 30 | // 就输出该文件的绝对路径 31 | System.out.println(f.getName().replaceAll("[.][^.]+$", "")); 32 | System.out.println(f.getAbsolutePath()); 33 | System.out.println(f.getAbsolutePath().replaceAll("[.][^.]+$", "")); 34 | } 35 | } 36 | /* else if (f.isDirectory()){ 37 | System.out.println(f.getAbsolutePath()); 38 | }*/ 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /geoserver-rest/src/main/java/com/zach/services/util/ComUtil.java: -------------------------------------------------------------------------------- 1 | package com.zach.services.util; 2 | 3 | public class ComUtil { 4 | 5 | public static boolean isEmpty(String fileList) { 6 | return true; 7 | } 8 | public static boolean isEmpty1(String[] fileList) { 9 | return true; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /geoserver-rest/src/main/java/com/zach/services/util/Constant.java: -------------------------------------------------------------------------------- 1 | package com.zach.services.util; 2 | 3 | public class Constant { 4 | 5 | public static final int BYTE_BUFFER = 1024; 6 | 7 | public static final int BUFFER_MULTIPLE = 10; 8 | public static final int AtlasStyleType = 10; 9 | 10 | public class AtlasStyleType01{ 11 | public static final String AtlasStyleType = "1"; 12 | } 13 | 14 | /** 15 | * 县图集类型 16 | */ 17 | public class AtlasType { 18 | //点位图 19 | public static final String ATLAS_TYPE_1 = "1"; 20 | //单元图 21 | public static final String ATLAS_TYPE_2 = "2"; 22 | //土壤类型图 23 | public static final String ATLAS_TYPE_3 = "3"; 24 | //评价结果表 25 | public static final String ATLAS_TYPE_4 = "4"; 26 | } 27 | 28 | public class FileType{ 29 | public static final int FILE_IMG = 1; 30 | public static final int FILE_ZIP = 2; 31 | public static final int FILE_VEDIO= 3; 32 | public static final int FILE_APK = 4; 33 | public static final int FIVE_OFFICE = 5; 34 | public static final String FILE_IMG_DIR= "/img/"; 35 | public static final String FILE_ZIP_DIR= "/zip/"; 36 | public static final String FILE_VEDIO_DIR= "/video/"; 37 | public static final String FILE_APK_DIR= "/apk/"; 38 | public static final String FIVE_OFFICE_DIR= "/office/"; 39 | } 40 | 41 | 42 | public static String parseAtlasTypeToName(String type){ 43 | String typeName=""; 44 | switch (type){ 45 | case AtlasType.ATLAS_TYPE_1: typeName="bitMap"; break; 46 | case AtlasType.ATLAS_TYPE_2: typeName="unitMap"; break; 47 | case AtlasType.ATLAS_TYPE_3: typeName="typeMap"; break; 48 | default:break; 49 | } 50 | return typeName; 51 | } 52 | 53 | public static class FilePostFix{ 54 | public static final String ZIP_FILE =".zip"; 55 | 56 | public static final String [] IMAGES ={"jpg", "jpeg", "JPG", "JPEG", "gif", "GIF", "bmp", "BMP"}; 57 | public static final String [] ZIP ={"ZIP","zip","rar","RAR"}; 58 | public static final String [] VIDEO ={"mp4","MP4","mpg","mpe","mpa","m15","m1v", "mp2","rmvb"}; 59 | public static final String [] APK ={"apk","exe"}; 60 | public static final String [] OFFICE ={"xls","xlsx","docx","doc","ppt","pptx"}; 61 | 62 | } 63 | 64 | public class Atlas { 65 | public static final int ATLAS_FIELD_STATUS_HIDE = 0; 66 | public static final int ATLAS_FIELD_STATUS_SHOW = 1; 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /geoserver-rest/src/main/java/com/zach/services/util/GeoServerUtil.java: -------------------------------------------------------------------------------- 1 | package com.zach.services.util; 2 | 3 | import it.geosolutions.geoserver.rest.GeoServerRESTManager; 4 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; 5 | import it.geosolutions.geoserver.rest.GeoServerRESTReader; 6 | import org.apache.commons.httpclient.NameValuePair; 7 | 8 | import java.io.File; 9 | import java.net.MalformedURLException; 10 | import java.net.URL; 11 | import java.util.ResourceBundle; 12 | 13 | public class GeoServerUtil { 14 | public static final String RESTURL; 15 | 16 | public static final String RESTUSER; 17 | 18 | public static final String RESTPW; 19 | 20 | public static final String GS_VERSION; 21 | 22 | public static java.net.URL URL; 23 | 24 | public static GeoServerRESTManager manager; 25 | 26 | public static GeoServerRESTReader reader; 27 | 28 | public static GeoServerRESTPublisher publisher; 29 | 30 | private static ResourceBundle bundle = ResourceBundle.getBundle("constant"); 31 | 32 | //初始化用户名密码赋值,发布图集时会进行身份认证 33 | static { 34 | RESTURL = getenv("gsmgr_resturl", "http://localhost:18080/geoserver/"); 35 | RESTUSER = getenv("gsmgr_restuser","admin"); 36 | RESTPW = getenv("gsmgr_restpw", "geoserver"); 37 | GS_VERSION = getenv("gsmgr_version", "2.11.2"); 38 | try { 39 | URL = new URL(RESTURL); 40 | manager = new GeoServerRESTManager(URL, RESTUSER, RESTPW); 41 | reader = manager.getReader(); 42 | publisher = manager.getPublisher(); 43 | } catch (MalformedURLException e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | 48 | //获取环境信息 49 | private static String getenv(String envName, String envDefault) { 50 | String env = System.getenv(envName); 51 | String prop = System.getProperty(envName, env); 52 | return prop != null ? prop : envDefault; 53 | } 54 | 55 | public static boolean publishShpAndReloadStore(String workspace,String zipFilePath,String storeName,String layerName,String styleType,String coordinateSystem) throws Exception{ 56 | //坐标系,判断是否为空 57 | if(ComUtil.isEmpty(coordinateSystem)){ 58 | coordinateSystem=GeoServerRESTPublisher.DEFAULT_CRS; 59 | } 60 | //存在相应的工作区 61 | if(!reader.existsWorkspace(workspace)){ 62 | publisher.createWorkspace(workspace); 63 | } 64 | boolean published; 65 | if(Constant.AtlasStyleType01.AtlasStyleType.equals(styleType)){ 66 | published = publisher.publishShp(workspace, storeName, layerName, new File(zipFilePath),coordinateSystem, 67 | new NameValuePair[]{new NameValuePair("charset", "GBK")}); 68 | }else{ 69 | //读取style文件 70 | String styleFile = bundle.getString("geoServer-dir")+"/"+styleType+".sld"; 71 | File file = new File(styleFile); 72 | String strStyle = "style"+styleType; 73 | //是否已经发布了改style 74 | if(!reader.existsStyle(workspace,strStyle)){ 75 | publisher.publishStyleInWorkspace(workspace,file,strStyle); 76 | } 77 | //创建发布类,放入用户名密码和url 78 | GeoServerRESTPublisher geoServerRESTPublisher =new GeoServerRESTPublisher(RESTURL,RESTUSER,RESTPW); 79 | //工作区 数据存储名称 80 | published =geoServerRESTPublisher.publishShp( workspace, storeName, new NameValuePair[]{new NameValuePair("charset", "GBK")}, 81 | //图层名称 指定用于发布资源的方法 82 | layerName, GeoServerRESTPublisher.UploadMethod.FILE, 83 | // zip图集的地址 坐标系 样式 84 | new File(zipFilePath).toURI(),coordinateSystem, strStyle); 85 | } 86 | return published; 87 | } 88 | 89 | public static boolean unPublishShpAndReloadStore(String workspace,String storeName){ 90 | return publisher.removeLayer(workspace,storeName); 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /geoserver-rest/src/main/java/com/zach/services/util/HttpLayerPropertyUtil.java: -------------------------------------------------------------------------------- 1 | package com.zach.services.util; 2 | 3 | import org.jsoup.Jsoup; 4 | import org.jsoup.nodes.Document; 5 | import org.jsoup.select.Elements; 6 | 7 | import java.io.IOException; 8 | import java.util.ArrayList; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | *

15 | * HTTP请求工具类 16 | *

17 | * 18 | * @author liugh 19 | * @since 2018/3/20 20 | */ 21 | public class HttpLayerPropertyUtil { 22 | 23 | /** 24 | * 获取图层所有属性 25 | * @param layerPreviewURL 26 | * @return 27 | */ 28 | public static List> getLayerProperty(String layerPreviewURL){ 29 | List> retList = new ArrayList(); 30 | try { 31 | Document doc = Jsoup.connect(layerPreviewURL).get(); 32 | Elements select = doc.select("th"); 33 | Elements select1 = doc.select("td"); 34 | for (int i = 0; i < select.size(); i++) { 35 | HashMap tempMap = new HashMap(16); 36 | tempMap.put(cutValue(select.get(i).toString()), cutValue(select1.get(i).toString())); 37 | retList.add(tempMap); 38 | } 39 | return retList; 40 | } catch (IOException e) { 41 | System.out.println("页面获取异常!"); 42 | e.printStackTrace(); 43 | } 44 | return null; 45 | } 46 | 47 | private static String cutValue(String s){ 48 | String substring = s.substring(4,s.indexOf(" 16 | * xml解析工具类 17 | *

18 | * 19 | * @author liugh 20 | * @since 2018/4/3 21 | */ 22 | public class XmlUtil { 23 | 24 | private static String GEO_SERVER_PATH = ResourceBundle.getBundle("constant").getString("geoServer-dir"); 25 | 26 | private static String BUNDLE_URL = ResourceBundle.getBundle("constant").getString("geoServer-url"); 27 | 28 | private static String XML_ELEMENT_NAME="latLonBoundingBox"; 29 | public static void main(String[] args)throws Exception { 30 | getMapUrl("1522723368940","unitMap"); 31 | } 32 | 33 | //获取图集发布地址 34 | public static String getMapUrl(String layerId,String workspace)throws Exception{ 35 | File file =new File(GEO_SERVER_PATH+File.separator+workspace); 36 | String[] fileList = file.list(); 37 | StringBuilder mapUrl = new StringBuilder(); 38 | mapUrl.append(BUNDLE_URL+workspace) 39 | .append("/wms?service=WMS&version=1.1.0&request=GetMap&layers=").append(workspace+":"+layerId).append("&styles=&bbox="); 40 | if(!ComUtil.isEmpty1(fileList)){ 41 | for (String fileName:fileList) { 42 | if(fileName.equals(layerId)){ 43 | String [] coordinates = readXMLDocument(layerId,workspace); 44 | mapUrl.append(coordinates[0]+","+coordinates[2]+","+coordinates[1]+","+coordinates[3]).append("&width=768&height=437&srs=").append(coordinates[4]); 45 | } 46 | } 47 | }else{ 48 | return null; 49 | } 50 | return mapUrl.toString(); 51 | } 52 | 53 | private static String [] readXMLDocument(String layerId, String workspace){ 54 | File file = new File(GEO_SERVER_PATH+File.separator+workspace+ 55 | File.separator+layerId+File.separator+layerId+File.separator+"featuretype.xml"); 56 | if (!file.exists()) { 57 | try { 58 | throw new IOException("Can't find the path"); 59 | } catch (IOException e) { 60 | e.printStackTrace(); 61 | } 62 | } 63 | //创建SAXReader对象 64 | SAXReader saxReader = new SAXReader(); 65 | Document document; 66 | try { 67 | //读取文件 转换成Document 68 | document = saxReader.read(file); 69 | //获取根节点元素对象 遍历当前节点下的所有节点 70 | for (Iterator iter = document.getRootElement().elementIterator(); iter.hasNext();){ 71 | //获取节点 72 | Element e1 = (Element) iter.next(); 73 | 74 | //如果过节点的名称等于beanName那么继续进入循环读取beanName节点下的所有节点 75 | if(e1.getName().equalsIgnoreCase(XML_ELEMENT_NAME)){ 76 | String [] ss = new String[5]; 77 | int i =0; 78 | //遍历beanName当前节点下的所有节点 79 | for (Iterator iter1 = e1.elementIterator(); iter1.hasNext();){ 80 | Element e2 = (Element) iter1.next(); 81 | ss[i]= e2.getStringValue(); 82 | i++; 83 | } 84 | return ss; 85 | } 86 | } 87 | } catch (DocumentException e) { 88 | e.printStackTrace(); 89 | return null; 90 | } 91 | return null; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /geoserver-rest/src/test/java/com/zach/geoserver_rest/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.zach.geoserver_rest; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URL; 5 | import java.util.List; 6 | 7 | import it.geosolutions.geoserver.rest.GeoServerRESTManager; 8 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; 9 | import it.geosolutions.geoserver.rest.decoder.RESTDataStore; 10 | import it.geosolutions.geoserver.rest.decoder.RESTLayer; 11 | import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; 12 | import it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder; 13 | import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; 14 | 15 | 16 | public class AppTest 17 | { 18 | 19 | public static void main(String[] args) throws MalformedURLException { 20 | 21 | //geoserver连接配置 22 | String url = "http://localhost:8000/geoserver" ; 23 | String username = "admin" ; 24 | String passwd = "geoserver" ; 25 | 26 | //postgis连接配置 27 | String postgisHost = "localhost" ; 28 | int postgisPort = 6666 ; 29 | String postgisUser = "lyf" ; 30 | String postgisPassword = "lyf" ; 31 | String postgisDatabase = "lyf" ; 32 | 33 | String ws = "lyf" ; //待创建和发布图层的workspace 34 | String store_name = "lyf" ; //数据库连接要创建的store 35 | String table_name = "lyf" ; // 数据库要发布的表名称,后面图层名称和表名保持一致 36 | 37 | URL u = new URL(url); 38 | 39 | 40 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 41 | 42 | GeoServerRESTPublisher publisher = manager.getPublisher() ; 43 | //创建一个workspace 44 | List workspaces = manager.getReader().getWorkspaceNames(); 45 | if(!workspaces.contains(ws)){ 46 | boolean createws = publisher.createWorkspace(ws); 47 | 48 | System.out.println("create ws : " + createws); 49 | }else { 50 | System.out.println("workspace已经存在了,ws :" + ws); 51 | } 52 | 53 | 54 | 55 | //store 包含和workspace一致,一个ws一个连接即可 56 | RESTDataStore restStore = manager.getReader().getDatastore(ws, store_name); 57 | 58 | if(restStore == null){ 59 | 60 | 61 | GSPostGISDatastoreEncoder store = new GSPostGISDatastoreEncoder(store_name); 62 | store.setHost(postgisHost);//设置url 63 | store.setPort(postgisPort);//设置端口 64 | store.setUser(postgisUser);// 数据库的用户名 65 | store.setPassword(postgisPassword);// 数据库的密码 66 | store.setDatabase(postgisDatabase);// 那个数据库; 67 | store.setSchema("public"); //当前先默认使用public这个schema 68 | store.setConnectionTimeout(20);// 超时设置 69 | //store.setName(schema); 70 | store.setMaxConnections(20); // 最大连接数 71 | store.setMinConnections(1); // 最小连接数 72 | store.setExposePrimaryKeys(true); 73 | boolean createStore = manager.getStoreManager().create(ws, store); 74 | 75 | System.out.println("create store : " + createStore); 76 | 77 | } else { 78 | System.out.println("数据store已经发布过了,store:" + store_name); 79 | } 80 | 81 | //发布 82 | 83 | RESTLayer layer = manager.getReader().getLayer(ws, table_name); 84 | 85 | if(layer == null){ 86 | GSFeatureTypeEncoder pds = new GSFeatureTypeEncoder(); 87 | pds.setTitle(table_name); 88 | pds.setName(table_name); 89 | pds.setSRS("EPSG:4326"); 90 | 91 | GSLayerEncoder layerEncoder = new GSLayerEncoder(); 92 | 93 | boolean publish = manager.getPublisher().publishDBLayer(ws, store_name, pds, layerEncoder); 94 | 95 | System.out.println("publish : " + publish); 96 | }else { 97 | System.out.println("表已经发布过了,table:" + table_name); 98 | } 99 | 100 | 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /geoserver-rest/src/test/java/com/zach/geoserver_rest/shpTest.java: -------------------------------------------------------------------------------- 1 | package com.zach.geoserver_rest; 2 | 3 | import it.geosolutions.geoserver.rest.GeoServerRESTManager; 4 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; 5 | import it.geosolutions.geoserver.rest.decoder.RESTDataStore; 6 | import it.geosolutions.geoserver.rest.encoder.datastore.GSShapefileDatastoreEncoder; 7 | import org.apache.log4j.BasicConfigurator; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.io.File; 13 | import java.net.URI; 14 | import java.net.URL; 15 | 16 | @RestController 17 | //@RequestMapping("/shp") 18 | public class shpTest { 19 | @GetMapping("/shp") 20 | public String index(){ 21 | return "shpTest !!!"; 22 | } 23 | 24 | public static void main(String[] args) throws Exception { 25 | BasicConfigurator.configure(); //自动快速地使用缺省Log4j环境 26 | //GeoServer连接配置 27 | String url = "http://localhost:8080/geoserver"; 28 | String userName = "admin"; 29 | String passWord = "geoserver"; 30 | 31 | String workSpace; //创建的工作区名称 32 | String storeName; //创建的数据存储名称 33 | //待发布shp数据路径与矢量数据包路径 34 | String filePath; 35 | String zipPath; 36 | File zipfile; 37 | 38 | //与GeoServer连接,进行管理 39 | GeoServerRESTManager manager = new GeoServerRESTManager(new URL(url), userName, passWord); 40 | GeoServerRESTPublisher publisher = manager.getPublisher(); 41 | 42 | /*遍历文件夹路径下.tif文件*/ 43 | String path = "F:\\Document\\Graduation Project\\MapData\\mapData_test\\Shp"; //要遍历的路径 44 | File file = new File(path); //获取其file对象 45 | File[] fs = file.listFiles(); //遍历path下的文件和目录,放在File数组中 46 | for(File f : fs) 47 | { 48 | if(f.isFile()) 49 | { 50 | if (f.getName().endsWith(".zip")) { 51 | // 就输出该文件的绝对路径 52 | System.out.println(f.getName().replaceAll("[.][^.]+$", "")); 53 | workSpace = "Shp_"+ f.getName().replaceAll("[.][^.]+$", ""); 54 | //创建工作区 55 | boolean createWorkSpace = publisher.createWorkspace(workSpace); 56 | System.out.println("create ws " + createWorkSpace); 57 | 58 | storeName = f.getName().replaceAll("[.][^.]+$", ""); 59 | zipPath = f.getAbsolutePath(); 60 | filePath = zipPath.replaceAll("[.][^.]+$", ""); 61 | zipfile = new File(zipPath); 62 | URI resource = zipfile.toURI(); 63 | 64 | 65 | //shp字符集 66 | 67 | 68 | //创建shp数据存储 69 | GSShapefileDatastoreEncoder gsShapefileDatastoreEncoder= new GSShapefileDatastoreEncoder(storeName,new URL("file:" + path)); 70 | boolean createStore = manager.getStoreManager().create(workSpace, gsShapefileDatastoreEncoder); 71 | System.out.println("create shp store :" + createStore); 72 | 73 | //发布shp图层(如果没有目标数据存储则会先自动创建该命名数据存储再发布) 74 | boolean publish = manager.getPublisher().publishShpCollection(workSpace, storeName, resource); 75 | System.out.println("publish shp :" + publish); 76 | } 77 | 78 | } 79 | } 80 | //读取目标矢量数据存储 81 | //RESTDataStore restDataStore = manager.getReader().getDatastore(workSpace, storeName); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /geoserver-rest/src/test/java/com/zach/geoserver_rest/test.java: -------------------------------------------------------------------------------- 1 | package com.zach.geoserver_rest; 2 | 3 | import it.geosolutions.geoserver.rest.GeoServerRESTManager; 4 | import it.geosolutions.geoserver.rest.decoder.RESTDataStore; 5 | import it.geosolutions.geoserver.rest.decoder.RESTLayer; 6 | import it.geosolutions.geoserver.rest.decoder.RESTLayerList; 7 | import org.apache.log4j.BasicConfigurator; 8 | import org.springframework.web.bind.annotation.CrossOrigin; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.io.File; 13 | import java.net.MalformedURLException; 14 | import java.net.URL; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | @RestController 19 | @CrossOrigin(origins = "*",maxAge = 8095) 20 | public class test { 21 | @GetMapping("/testtt") 22 | public static List test01() throws MalformedURLException { 23 | String url = "http://localhost:8080/geoserver"; 24 | String username = "admin"; 25 | String passwd = "geoserver"; 26 | 27 | URL u = new URL(url); 28 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 29 | RESTLayerList restStore = manager.getReader().getLayers(); 30 | System.out.println(restStore.getNames()); 31 | return restStore.getNames(); 32 | } 33 | 34 | public static class Bounds { 35 | private String SRS; 36 | private double MinX; 37 | private double MinY; 38 | private double MaxX; 39 | private double MaxY; 40 | 41 | } 42 | 43 | @GetMapping("/testtttt") 44 | public List getAll() throws MalformedURLException { 45 | String url = "http://localhost:8080/geoserver"; 46 | String username = "admin"; 47 | String passwd = "geoserver"; 48 | URL u = new URL(url); 49 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 50 | RESTLayer restLayer = manager.getReader().getLayer("test:beijing"); 51 | //List detail = new ArrayList<>(); 52 | Bounds bounds = new Bounds(); 53 | bounds.SRS=manager.getReader().getResource(restLayer).getCRS(); 54 | bounds.MinX=manager.getReader().getResource(restLayer).getMinX(); 55 | bounds.MinY=manager.getReader().getResource(restLayer).getMinY(); 56 | bounds.MaxX=manager.getReader().getResource(restLayer).getMaxX(); 57 | bounds.MaxY=manager.getReader().getResource(restLayer).getMaxY(); 58 | return (List) bounds; 59 | } 60 | 61 | public static void main(String[] args) throws MalformedURLException { 62 | BasicConfigurator.configure(); //自动快速地使用缺省Log4j环境(spring boot中无需添加) 63 | //List test = test01(); 64 | String url = "http://localhost:8080/geoserver"; 65 | String username = "admin"; 66 | String passwd = "geoserver"; 67 | URL u = new URL(url); 68 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 69 | RESTLayer restLayer = manager.getReader().getLayer("test:beijing"); 70 | //List detail = new ArrayList<>(); 71 | Bounds bounds = new Bounds(); 72 | bounds.SRS=manager.getReader().getResource(restLayer).getCRS(); 73 | bounds.MinX=manager.getReader().getResource(restLayer).getMinX(); 74 | bounds.MinY=manager.getReader().getResource(restLayer).getMinY(); 75 | bounds.MaxX=manager.getReader().getResource(restLayer).getMaxX(); 76 | bounds.MaxY=manager.getReader().getResource(restLayer).getMaxY(); 77 | //System.out.println(manager.getReader().getResource(restLayer).getMinX()); 78 | // detail.add(manager.getReader().getResource(restLayer).getMinX()); 79 | // detail.add(manager.getReader().getResource(restLayer).getMinY()); 80 | // detail.add(manager.getReader().getResource(restLayer).getMaxX()); 81 | // detail.add(manager.getReader().getResource(restLayer).getMaxY()); 82 | System.out.println(bounds); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /geoserver-rest/src/test/java/com/zach/geoserver_rest/test01.java: -------------------------------------------------------------------------------- 1 | package com.zach.geoserver_rest; 2 | 3 | import it.geosolutions.geoserver.rest.GeoServerRESTManager; 4 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; 5 | import it.geosolutions.geoserver.rest.decoder.RESTDataStore; 6 | import it.geosolutions.geoserver.rest.encoder.datastore.GSGeoTIFFDatastoreEncoder; 7 | import org.apache.log4j.BasicConfigurator; 8 | 9 | import java.io.File; 10 | import java.net.MalformedURLException; 11 | import java.net.URI; 12 | import java.net.URISyntaxException; 13 | import java.net.URL; 14 | import java.util.List; 15 | 16 | public class test01 { 17 | public static void main(String[] args) throws MalformedURLException { 18 | BasicConfigurator.configure(); //自动快速地使用缺省Log4j环境(spring boot中无需添加) 19 | 20 | //GeoServer的连接配置 21 | String url = "http://localhost:8080/geoserver"; 22 | String username = "admin"; 23 | String passwd = "geoserver"; 24 | 25 | String store_name; //待创建和发布图层的数据存储名称store 26 | String ws = "test01"; //待创建和发布图层的工作区名称workspace 27 | 28 | //判断工作区(workspace)是否存在,不存在则创建 29 | URL u = new URL(url); 30 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 31 | List workspaces = manager.getReader().getWorkspaceNames(); 32 | if (!workspaces.contains(ws)) { 33 | System.out.println("workspace不存在,ws : " + ws ); 34 | } else { 35 | System.out.println("workspace已经存在了,ws :" + ws); 36 | } 37 | store_name = "hebei"; 38 | 39 | 40 | GSGeoTIFFDatastoreEncoder gsGeoTIFFDatastoreEncoder = new GSGeoTIFFDatastoreEncoder(store_name); 41 | gsGeoTIFFDatastoreEncoder.setWorkspaceName(ws); 42 | 43 | boolean deleStore = manager.getStoreManager().remove(ws,gsGeoTIFFDatastoreEncoder,true); 44 | 45 | System.out.println("remove store : " + deleStore); 46 | 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /geoserver-rest/src/test/java/com/zach/geoserver_rest/tiffTest.java: -------------------------------------------------------------------------------- 1 | package com.zach.geoserver_rest; 2 | 3 | import it.geosolutions.geoserver.rest.GeoServerRESTManager; 4 | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; 5 | import it.geosolutions.geoserver.rest.decoder.RESTDataStore; 6 | import it.geosolutions.geoserver.rest.encoder.datastore.GSGeoTIFFDatastoreEncoder; 7 | import org.apache.log4j.BasicConfigurator; 8 | 9 | import java.io.File; 10 | import java.net.URL; 11 | import java.util.List; 12 | 13 | public class tiffTest { 14 | public static void main(String[] args) throws Exception { 15 | BasicConfigurator.configure(); //自动快速地使用缺省Log4j环境 16 | //GeoServer的连接配置 17 | String url = "http://localhost:8080/geoserver"; 18 | String username = "admin"; 19 | String passwd = "geoserver"; 20 | 21 | String ws = "test01"; //待创建和发布图层的工作区名称workspace 22 | //String store_name = "tiffTest"; //待创建和发布图层的数据存储名称store 23 | 24 | //判断工作区(workspace)是否存在,不存在则创建 25 | URL u = new URL(url); 26 | GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd); 27 | GeoServerRESTPublisher publisher = manager.getPublisher(); 28 | List workspaces = manager.getReader().getWorkspaceNames(); 29 | if (!workspaces.contains(ws)) { 30 | boolean createws = publisher.createWorkspace(ws); 31 | System.out.println("create ws : " + createws); 32 | } else { 33 | System.out.println("workspace已经存在了,ws :" + ws); 34 | } 35 | 36 | //判断数据存储(datastore)是否已经存在,不存在则创建 37 | //String fileName = "F:\\Document\\Graduation Project\\MapData\\Tiff\\beijing.tif"; 38 | 39 | 40 | /*遍历文件夹路径下tiff文件*/ 41 | String path = "F:\\Document\\Graduation Project\\MapData\\Tiff"; //要遍历的路径 42 | File file = new File(path); //获取其file对象 43 | File[] fs = file.listFiles(); //遍历path下的文件和目录,放在File数组中 44 | 45 | String store_name; //待创建和发布图层的数据存储名称store 46 | String fileName; 47 | for(File f : fs) 48 | { 49 | if(f.isFile()) 50 | { 51 | if (f.getName().endsWith(".tif")) { 52 | // 就输出该文件的绝对路径 53 | //System.out.println(f.getAbsolutePath()); 54 | store_name = f.getName().replaceAll("[.][^.]+$", ""); 55 | fileName = f.getAbsolutePath(); 56 | RESTDataStore restStore = manager.getReader().getDatastore(ws, store_name); 57 | if (restStore == null) { 58 | GSGeoTIFFDatastoreEncoder gsGeoTIFFDatastoreEncoder = new GSGeoTIFFDatastoreEncoder(store_name); 59 | gsGeoTIFFDatastoreEncoder.setWorkspaceName(ws); 60 | gsGeoTIFFDatastoreEncoder.setUrl(new URL("file:" + fileName)); 61 | boolean createStore = manager.getStoreManager().create(ws, gsGeoTIFFDatastoreEncoder); 62 | System.out.println("create store (TIFF文件创建状态) : " + createStore); 63 | boolean publish = manager.getPublisher().publishGeoTIFF(ws, store_name, new File(fileName)); 64 | System.out.println("publish (TIFF文件发布状态) : " + publish); 65 | //System.out.println(f.getName() + " : 发布成功!"); 66 | } else { 67 | System.out.println("数据存储已经存在了,store:" + store_name); 68 | } 69 | } 70 | } 71 | } 72 | 73 | //验证tiff文件是否全部上传至GeoServer 74 | /*for (File f : fs){ 75 | if(f.isFile()) { 76 | if (f.getName().endsWith(".tif")) { 77 | store_name = f.getName().replaceAll("[.][^.]+$", ""); 78 | RESTDataStore restStore = manager.getReader().getDatastore(ws, store_name); 79 | if (restStore != null){ 80 | System.out.println(f.getName() + " : 发布成功!"); 81 | } 82 | else { 83 | System.out.println("[warn] "+f.getName() + " : 发布失败!"); 84 | } 85 | } 86 | } 87 | }*/ 88 | } 89 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.3.2.RELEASE 9 | 10 | 11 | com.qiang 12 | spring-vue 13 | 0.0.1-SNAPSHOT 14 | spring-vue 15 | Demo project for Spring Boot 16 | 17 | 18 | geoserver-manager 19 | geoserver-rest 20 | 21 | 22 | 23 | 8 24 | 25 | 26 | 27 | 28 | com.jjxliu.geoserver 29 | geoserver_rest 30 | 0.0.1-SNAPSHOT 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-data-jdbc 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-jdbc 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-web 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-devtools 48 | runtime 49 | true 50 | 51 | 56 | 57 | com.microsoft.sqlserver 58 | mssql-jdbc 59 | runtime 60 | 61 | 62 | mysql 63 | mysql-connector-java 64 | runtime 65 | 66 | 67 | org.projectlombok 68 | lombok 69 | true 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-starter-test 74 | test 75 | 76 | 77 | org.junit.vintage 78 | junit-vintage-engine 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.springframework.boot 88 | spring-boot-maven-plugin 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/main/java/com/qiang/springvue/SpringVueApplication.java: -------------------------------------------------------------------------------- 1 | package com.qiang.springvue; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.domain.EntityScan; 7 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 8 | import org.springframework.context.annotation.ComponentScan; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | //@SpringBootApplication 15 | @Configuration 16 | @ComponentScan(value = "com.zach.services") 17 | @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) 18 | public class SpringVueApplication { 19 | 20 | @GetMapping("/demo") 21 | public String index(){ 22 | return "hello!!!"; 23 | } 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(SpringVueApplication.class, args); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/qiang/springvue/config/CrosConfig.java: -------------------------------------------------------------------------------- 1 | package com.qiang.springvue.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | @Configuration 8 | public class CrosConfig implements WebMvcConfigurer { 9 | @Override 10 | public void addCorsMappings(CorsRegistry registry) { 11 | registry.addMapping("/**") 12 | .allowedOrigins("*") 13 | .allowedMethods("GET","HEAD","POST","DELETE","OPTIONS","PUT") 14 | .allowCredentials(true) 15 | .maxAge(3600) 16 | .allowedHeaders("*"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/qiang/springvue/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package com.qiang.springvue.controller; 2 | 3 | import com.qiang.springvue.entity.Book; 4 | import com.qiang.springvue.service.BookService; 5 | //import org.apache.ibatis.annotations.Delete; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import javax.websocket.server.PathParam; 11 | import java.util.List; 12 | 13 | @RestController 14 | @RequestMapping("/book") 15 | public class BookController { 16 | @Autowired 17 | BookService bookService; 18 | /* 19 | @GetMapping("/all") 20 | public List getAll(){ 21 | return bookService.getAllBook(); 22 | } 23 | 24 | 25 | @GetMapping("/limit/{low}/{high}") 26 | public List getBookByLowAndHigh(@PathVariable("low") Integer low,@PathVariable("high") Integer high){ 27 | return bookService.getBookByLowAndHigh(low, high); 28 | } 29 | 30 | @PostMapping("/") 31 | public int insertBook(@RequestBody Book book){ 32 | return bookService.insertBook(book); 33 | } 34 | 35 | @PutMapping("/emp") 36 | public int updateBook(@RequestBody Book book){ 37 | return bookService.updateBook(book); 38 | } 39 | 40 | @DeleteMapping("/{id}") 41 | public int deleteBook(@PathVariable("id") Integer id){ 42 | return bookService.deleteBook(id); 43 | }*/ 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/qiang/springvue/entity/Book.java: -------------------------------------------------------------------------------- 1 | package com.qiang.springvue.entity; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Book { 7 | private Integer id; 8 | private String name; 9 | private String author; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/qiang/springvue/mapper/BookMapper.java: -------------------------------------------------------------------------------- 1 | package com.qiang.springvue.mapper; 2 | 3 | import com.qiang.springvue.entity.Book; 4 | //import org.apache.ibatis.annotations.*; 5 | 6 | import java.util.List; 7 | 8 | //@Mapper 9 | public interface BookMapper { 10 | 11 | /* @Select("select * from book") 12 | public List getAllBook(); 13 | 14 | @Select("select * from book limit #{low},#{high}") 15 | public List getBookByLowAndHigh(Integer low,Integer high); 16 | 17 | @Insert("insert into book(name,author) values(#{name},#{author})") 18 | public int insertBook(Book book); 19 | 20 | @Update("update book set name = #{name} , author = #{author} where id = #{id}") 21 | public int updateBook(Book book); 22 | 23 | @Delete("delete from book where id = #{id}") 24 | public int deleteBook(Integer id);*/ 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/qiang/springvue/service/BookService.java: -------------------------------------------------------------------------------- 1 | package com.qiang.springvue.service; 2 | 3 | import com.qiang.springvue.entity.Book; 4 | import com.qiang.springvue.mapper.BookMapper; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | @Service 11 | public class BookService { 12 | /* @Autowired 13 | BookMapper bookMapper; 14 | 15 | public List getAllBook(){ 16 | return bookMapper.getAllBook(); 17 | } 18 | 19 | public List getBookByLowAndHigh(Integer low,Integer high){ 20 | return bookMapper.getBookByLowAndHigh(low, high); 21 | } 22 | 23 | public int insertBook(Book book){ 24 | return bookMapper.insertBook(book); 25 | } 26 | 27 | public int updateBook(Book book){ 28 | return bookMapper.updateBook(book); 29 | } 30 | 31 | public int deleteBook(Integer id){ 32 | return bookMapper.deleteBook(id); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.mvc.hiddenmethod.filter.enabled=true 3 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #spring: 2 | # datasource: 3 | # url: jdbc:mysql://localhost:3306/library?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8 4 | # username: root 5 | # password: root 6 | # driver-class-name: com.mysql.jdbc.Driver 7 | # initialization-mode: always 8 | 9 | spring: 10 | mvc: 11 | hiddenmethod: 12 | filter: 13 | enabled: true 14 | server: 15 | port: 8083 16 | -------------------------------------------------------------------------------- /src/test/java/com/qiang/springvue/SpringVueApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.qiang.springvue; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringVueApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------