Compare commits
232 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d518e9e5a4 | ||
|
|
cf24d45760 | ||
|
|
f10f027fb8 | ||
|
|
25759e86a5 | ||
|
|
febd28bc3a | ||
|
|
ad6fe87e81 | ||
|
|
318be5853e | ||
|
|
c44eece1f1 | ||
|
|
c588f2c66b | ||
|
|
0ec95f03f9 | ||
|
|
415df68d4b | ||
|
|
12c2e09c0e | ||
|
|
8f0efbc5de | ||
|
|
baf27a6ed7 | ||
|
|
b12342007b | ||
|
|
e6c77e9508 | ||
|
|
88668158f6 | ||
|
|
c6d6c3d2b9 | ||
|
|
61b914c610 | ||
|
|
ebee7276b2 | ||
|
|
10bf4971b2 | ||
|
|
9a736d2d7e | ||
|
|
8968e36673 | ||
|
|
224061257f | ||
|
|
9e0e9490c2 | ||
|
|
62d34ac345 | ||
|
|
7490529d2d | ||
|
|
7fdf019cd6 | ||
|
|
a8412ea7e9 | ||
|
|
098999b9b2 | ||
|
|
0259686b3c | ||
|
|
d2bbcc46a7 | ||
|
|
7af3899802 | ||
|
|
ff7f383591 | ||
|
|
5447c06dbc | ||
|
|
db5d949e71 | ||
|
|
e48a2b0d88 | ||
|
|
7c20365099 | ||
|
|
1f11fd3207 | ||
|
|
797dac9289 | ||
|
|
55d0e0bd8e | ||
|
|
12ec730db8 | ||
|
|
dbbd54a8ea | ||
|
|
5fbe7ed2e9 | ||
|
|
4d4813007f | ||
|
|
c360e8c532 | ||
|
|
3f22f36aa2 | ||
|
|
5027ba8112 | ||
|
|
bd6bab3ddb | ||
|
|
28a72e2691 | ||
|
|
bde93118d2 | ||
|
|
ebae6cf086 | ||
|
|
a4268dda60 | ||
|
|
f55cb1cbcc | ||
|
|
feb41ad0f7 | ||
|
|
c76e60205c | ||
|
|
9ebfaaafed | ||
|
|
7d0a8319ea | ||
|
|
94c7871cd1 | ||
|
|
4241e4d83d | ||
|
|
1533c7bec4 | ||
|
|
3e810bb869 | ||
|
|
213ed8326d | ||
|
|
c9f51cf388 | ||
|
|
497ec63408 | ||
|
|
631f3a9ffa | ||
|
|
a7d3efc6f7 | ||
|
|
5bd0f5e2e9 | ||
|
|
8cdc7d02b7 | ||
|
|
02439fa277 | ||
|
|
4cfa86400b | ||
|
|
da5ee7c090 | ||
|
|
6327f699ff | ||
|
|
e04dd7428e | ||
|
|
962d28503a | ||
|
|
86a3de1e2d | ||
|
|
fd84472576 | ||
|
|
3e580b73d1 | ||
|
|
75dec9c726 | ||
|
|
f06c49806d | ||
|
|
c17a14d9e0 | ||
|
|
b60e487ffa | ||
|
|
2526337e7d | ||
|
|
81b13eb404 | ||
|
|
b9aae2620b | ||
|
|
96d734f4e8 | ||
|
|
33b951c8ab | ||
|
|
5ca054d021 | ||
|
|
21b9cb1f00 | ||
|
|
ba8f17c5b1 | ||
|
|
3f90df97ba | ||
|
|
7d5d159b55 | ||
|
|
6dda73a5f1 | ||
|
|
5accaa01ed | ||
|
|
0f833b2664 | ||
|
|
1c60c1d94a | ||
|
|
b5bf46a189 | ||
|
|
6a4849ff97 | ||
|
|
0392ca309b | ||
|
|
9b520e3d24 | ||
|
|
a6041d2bea | ||
|
|
18ff2ee78e | ||
|
|
160227f7cc | ||
|
|
6689211b5d | ||
|
|
eee603e2fe | ||
|
|
8073671631 | ||
|
|
80b1767cd1 | ||
|
|
a277d44e15 | ||
|
|
471c860007 | ||
|
|
afb6ba3be0 | ||
|
|
5d820f5d43 | ||
|
|
6f8e457a77 | ||
|
|
9ca022093b | ||
|
|
7b10be6bdb | ||
|
|
8d47a02e03 | ||
|
|
e5033df000 | ||
|
|
bc233d4f7a | ||
|
|
b7bef77052 | ||
|
|
18d2a11ce2 | ||
|
|
3c502c5f58 | ||
|
|
2b69e1dcb3 | ||
|
|
1afa68b52d | ||
|
|
247ea4c685 | ||
|
|
e93d6dbd3d | ||
|
|
f6e68493ce | ||
|
|
685c0d9d98 | ||
|
|
7deaac685f | ||
|
|
d8e0fc6706 | ||
|
|
65562fd33f | ||
|
|
6a02c2be73 | ||
|
|
142ab3037b | ||
|
|
fea8bec1f6 | ||
|
|
ef4e1db865 | ||
|
|
5277fe9f6c | ||
|
|
4f0862b308 | ||
|
|
80746ff6b0 | ||
|
|
2300d58d5c | ||
|
|
4dac450327 | ||
|
|
205cd75285 | ||
|
|
09299bf320 | ||
|
|
93ec8db2fb | ||
|
|
499924a527 | ||
|
|
a3a8715b03 | ||
|
|
3e9f2bc0b4 | ||
|
|
fec4f007c2 | ||
|
|
85ab057400 | ||
|
|
660dd5d127 | ||
|
|
3cac68ddc3 | ||
|
|
9e17fda833 | ||
|
|
a81cf80f3f | ||
|
|
eeea363c87 | ||
|
|
c3a437de20 | ||
|
|
715fb71508 | ||
|
|
37987049e5 | ||
|
|
29a2636dfb | ||
|
|
1b6be9bc5a | ||
|
|
c70ab99c3e | ||
|
|
9cd87b7ea3 | ||
|
|
637ec22000 | ||
|
|
d61e7fd142 | ||
|
|
00e3f89d10 | ||
|
|
3dc49b952f | ||
|
|
5cd532c96c | ||
|
|
6b27c57bfc | ||
|
|
5ec9a0981f | ||
|
|
2a5fbcbf37 | ||
|
|
944e9d8325 | ||
|
|
755cf4479e | ||
|
|
3ee4e30040 | ||
|
|
f512be87e2 | ||
|
|
4aeac4d080 | ||
|
|
7fee169369 | ||
|
|
ef597824dc | ||
|
|
6f3e3c5075 | ||
|
|
2e9d4883b0 | ||
|
|
0253bbe423 | ||
|
|
b034077930 | ||
|
|
066dd6c716 | ||
|
|
5b489f1f11 | ||
|
|
4319854138 | ||
|
|
d6f28949f4 | ||
|
|
b4d0df24c7 | ||
|
|
5b9e9d9dac | ||
|
|
119e7ab420 | ||
|
|
447e0cef86 | ||
|
|
dd8e567958 | ||
|
|
cad01c6bd8 | ||
|
|
bbc83555e1 | ||
|
|
be6caa8a62 | ||
|
|
852cabbd8c | ||
|
|
fc4251f2d5 | ||
|
|
b99c9c356a | ||
|
|
a56aa61cf5 | ||
|
|
f500243712 | ||
|
|
f8765d6287 | ||
|
|
3a05e405bd | ||
|
|
ed9d1414ad | ||
|
|
70a09e4a06 | ||
|
|
3c11a1ae50 | ||
|
|
0644d4e02e | ||
|
|
db53134610 | ||
|
|
d317ff5ab9 | ||
|
|
286a51a2ee | ||
|
|
f585b2cc56 | ||
|
|
24eee41596 | ||
|
|
1fdc00ce4f | ||
|
|
6db046a626 | ||
|
|
c6f977858a | ||
|
|
68e8056a1b | ||
|
|
49543f609b | ||
|
|
6120344954 | ||
|
|
6d9fbac1c1 | ||
|
|
8f6e8b9ac2 | ||
|
|
d762161960 | ||
|
|
314771e33d | ||
|
|
15341547f1 | ||
|
|
21218e2c0a | ||
|
|
876727a6e2 | ||
|
|
d1352fb470 | ||
|
|
42c3094d9e | ||
|
|
e0df2fe99f | ||
|
|
8b4def8793 | ||
|
|
df736c4fe3 | ||
|
|
48655e3db5 | ||
|
|
667a9b2f69 | ||
|
|
2f70df0cde | ||
|
|
4083b46d9c | ||
|
|
f1c0ac45e2 | ||
|
|
0432534518 | ||
|
|
c9a81141cb | ||
|
|
ec4f18e03b | ||
|
|
b9ffabaf7d |
15
.travis.yml
Normal file
15
.travis.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
sudo: false
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- "$HOME/.m2"
|
||||||
|
language: java
|
||||||
|
jdk:
|
||||||
|
- oraclejdk7
|
||||||
|
- openjdk7
|
||||||
|
script:
|
||||||
|
- mvn -B -T2 -fae clean install
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
on_failure: never
|
||||||
|
after_success:
|
||||||
|
- mvn clean cobertura:cobertura coveralls:report
|
||||||
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 20007-2011 GeoSolutions
|
Copyright (c) 20007-2016 GeoSolutions
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
7
README
7
README
@ -1,7 +0,0 @@
|
|||||||
REST client library to interact with GeoServer (http://www.geoserver.org)
|
|
||||||
|
|
||||||
The purpose of this project is to hold a REST client library to interact with GeoServer; a requirement for this library is to depend as less as possible on external libraries. This library aims at being lean and mean.
|
|
||||||
|
|
||||||
For more information see this page:
|
|
||||||
|
|
||||||
https://github.com/geosolutions-it/geoserver-manager
|
|
||||||
68
README.md
Normal file
68
README.md
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# geoserver-manager
|
||||||
|
## Status
|
||||||
|
* Master on travis [](https://travis-ci.org/geosolutions-it/geoserver-manager)
|
||||||
|
* Master on Linux + OracleJDK7 [](http://build.geo-solutions.it/jenkins/view/GeoServer-manager/job/GeoServer-Manager-Master/)
|
||||||
|
* Master on Windows + OracleJDK7 [](http://winbuild.geo-solutions.it/jenkins/view/GeoServer-Manager/job/GeoServer-Manager-Master/)
|
||||||
|
* Stable on Linux + OracleJDK7 [](http://build.geo-solutions.it/jenkins/view/GeoServer-manager/job/GeoServer-Manager-Stable/)
|
||||||
|
* Stable on Windows + OracleJDK7 [](http://winbuild.geo-solutions.it/jenkins/view/GeoServer-Manager/job/GeoServer-Manager-Stable/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
Client library written in Java to interact with [GeoServer](http://www.geoserver.org) through its [ReST administration interface](http://docs.geoserver.org/stable/en/user/rest/api/index.html).
|
||||||
|
|
||||||
|
The purpose of this project is to hold a ReST client library to interact with GeoServer; a requirement for this library is to depend as less as possible on external libraries. This library aims at being lean and mean.
|
||||||
|
|
||||||
|
For general questions about this project feel free to use the mailing lists.
|
||||||
|
|
||||||
|
## Using the library
|
||||||
|
|
||||||
|
### Working with Maven
|
||||||
|
In order to include the lib and its dependencies in a Maven project, the repository to point at is this one:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<repository>
|
||||||
|
<id>GeoSolutions</id>
|
||||||
|
<url>http://maven.geo-solutions.it/</url>
|
||||||
|
</repository>
|
||||||
|
```
|
||||||
|
|
||||||
|
and the dependency tag for your pom is as follows:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>it.geosolutions</groupId>
|
||||||
|
<artifactId>geoserver-manager</artifactId>
|
||||||
|
<version>1.7.0</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
### Direct Link to JAR
|
||||||
|
If you are simply looking for the JAR to download and use you can find it [here](http://maven.geo-solutions.it/it/geosolutions/geoserver-manager/1.7.0/geoserver-manager-1.7.0.jar).
|
||||||
|
|
||||||
|
### GeoServer Compatibility Matrix
|
||||||
|
|
||||||
|
**GeoServer-Manager/GeoServer** | **2.6.x** |**2.7.x** |**2.8.x** |**2.9.x**
|
||||||
|
-------------------------------- | ----------|----------|----------|---------
|
||||||
|
**1.6.0** | Y | Y | P | P
|
||||||
|
**1.7.0** | N | P | Y | Y
|
||||||
|
|
||||||
|
### Documentation
|
||||||
|
You can find some examples in the wiki.
|
||||||
|
## License
|
||||||
|
|
||||||
|
geoserver-manager is released under a permissive [MIT](https://opensource.org/licenses/MIT) license. See [wikipedia](https://en.wikipedia.org/wiki/MIT_License) for more information.
|
||||||
|
|
||||||
|
|
||||||
|
## Mailing Lists
|
||||||
|
|
||||||
|
* [USERS](https://groups.google.com/group/geoserver-manager-users)
|
||||||
|
* [DEVELOPERS](https://groups.google.com/forum/?fromgroups#!forum/geoserver-manager-devs)
|
||||||
|
|
||||||
|
For more information see [this](https://github.com/geosolutions-it/geoserver-manager/wiki) page.
|
||||||
|
|
||||||
|
## Version
|
||||||
|
Current stable version is [1.7.0](https://github.com/geosolutions-it/geoserver-manager/releases/tag/v1.7.0) ([Changelog](https://github.com/geosolutions-it/geoserver-manager/wiki/Changelog)).
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
The work on this library has been initiated by GeoSolutions. Over the years it has been funded by various organizations like UN FAO, German Space Agency (DLR) and others.
|
||||||
|
|
||||||
150
pom.xml
150
pom.xml
@ -1,8 +1,7 @@
|
|||||||
<!--
|
<!--
|
||||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
* Copyright (C) 2007 - 2016 GeoSolutions S.A.S. http://www.geo-solutions.it
|
||||||
* http://www.geo-solutions.it
|
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -23,24 +22,29 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>it.geosolutions</groupId>
|
<groupId>it.geosolutions</groupId>
|
||||||
<artifactId>geoserver-manager</artifactId>
|
<artifactId>geoserver-manager</artifactId>
|
||||||
<version>1.3.3-SNAPSHOT</version>
|
<version>1.8-SNAPSHOT</version>
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>GeoServer 2 Manager - REST based</name>
|
<name>GeoServer Manager - REST based</name>
|
||||||
<description>
|
<description>
|
||||||
GeoServer Manager is a library to interact with GeoServer 2.x.
|
GeoServer Manager is a library to interact with GeoServer
|
||||||
The scope of this library is to have a simple API, and use as few external
|
The scope of this library is to have a simple API, and use as few external
|
||||||
libs as possible.
|
libs as possible.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<inceptionYear>2007</inceptionYear>
|
<inceptionYear>2007</inceptionYear>
|
||||||
|
|
||||||
|
<url>https://github.com/geosolutions-it/geoserver-manager</url>
|
||||||
|
|
||||||
<organization>
|
<organization>
|
||||||
<name>GeoSolutions</name>
|
<name>GeoSolutions</name>
|
||||||
<url>http://www.geo-solutions.it</url>
|
<url>http://www.geo-solutions.it</url>
|
||||||
@ -81,11 +85,9 @@
|
|||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
<url>http://code.google.com/p/geoserver-manager/</url>
|
|
||||||
|
|
||||||
<issueManagement>
|
<issueManagement>
|
||||||
<system>googlecode</system>
|
<system>GitHub</system>
|
||||||
<url>http://code.google.com/p/geoserver-manager/issues/list</url>
|
<url>https://github.com/geosolutions-it/geoserver-manager/issues</url>
|
||||||
</issueManagement>
|
</issueManagement>
|
||||||
|
|
||||||
<mailingLists>
|
<mailingLists>
|
||||||
@ -98,16 +100,61 @@
|
|||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:[fetch=]https://github.com/geosolutions-it/geoserver-manager.git[push=]git@github.com:geosolutions-it/geoserver-manager.git</connection>
|
<connection>scm:git:[fetch=]https://github.com/geosolutions-it/geoserver-manager.git[push=]git@github.com:geosolutions-it/geoserver-manager.git</connection>
|
||||||
<!--developerConnection>scm:git</developerConnection-->
|
|
||||||
<!--tag>master</tag-->
|
|
||||||
<url>https://github.com/geosolutions-it/geoserver-manager</url>
|
<url>https://github.com/geosolutions-it/geoserver-manager</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<ciManagement>
|
<ciManagement>
|
||||||
<system>jenkins</system>
|
<system>jenkins</system>
|
||||||
<url>http://ci.geo-solutions.it/</url>
|
<url>http://build.geo-solutions.it/jenkins/view/GeoServer-manager/</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>boundless</id>
|
||||||
|
<name>Boundless Maven Repository</name>
|
||||||
|
<url>https://repo.boundlessgeo.com/main/</url>
|
||||||
|
<!-- contains snapshot and release (including third-party-dependences) -->
|
||||||
|
<!-- Restlet maven Repository (http://maven.restlet.org) -->
|
||||||
|
<!-- ucar (https://artifacts.unidata.ucar.edu/content/repositories/unidata-releases) -->
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>osgeo</id>
|
||||||
|
<name>Open Source Geospatial Foundation Repository</name>
|
||||||
|
<url>http://download.osgeo.org/webdav/geotools/</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>maven-restlet</id>
|
||||||
|
<name>Restlet Maven Repository</name>
|
||||||
|
<url>http://maven.restlet.org</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>geosolutions</id>
|
||||||
|
<name>geosolutions repository</name>
|
||||||
|
<url>http://maven.geo-solutions.it/</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<downloadUrl>http://maven.geo-solutions.it</downloadUrl>
|
<downloadUrl>http://maven.geo-solutions.it</downloadUrl>
|
||||||
<repository>
|
<repository>
|
||||||
@ -117,7 +164,7 @@
|
|||||||
</repository>
|
</repository>
|
||||||
<site>
|
<site>
|
||||||
<id>demo.geosolutions</id>
|
<id>demo.geosolutions</id>
|
||||||
<url>scp://demo.geo-solutions.it/var/www/share/javadoc/gsman</url>
|
<url>scp://demo.geo-solutions.it/var/www/share/github/gsman</url>
|
||||||
</site>
|
</site>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
@ -140,11 +187,8 @@
|
|||||||
<version>2.7</version>
|
<version>2.7</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<detectLinks />
|
<detectLinks />
|
||||||
<!-- <links>
|
<!-- <links> <link>http://commons.apache.org/dbcp/apidocs/</link> <link>http://commons.apache.org/fileupload/apidocs/</link>
|
||||||
<link>http://commons.apache.org/dbcp/apidocs/</link>
|
<link>http://download.oracle.com/javase/6/docs/api</link> </links> -->
|
||||||
<link>http://commons.apache.org/fileupload/apidocs/</link>
|
|
||||||
<link>http://download.oracle.com/javase/6/docs/api</link>
|
|
||||||
</links>-->
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
@ -188,7 +232,7 @@
|
|||||||
<extension>
|
<extension>
|
||||||
<groupId>org.apache.maven.wagon</groupId>
|
<groupId>org.apache.maven.wagon</groupId>
|
||||||
<artifactId>wagon-ftp</artifactId>
|
<artifactId>wagon-ftp</artifactId>
|
||||||
<version>1.0-beta-7</version>
|
<version>2.6</version>
|
||||||
</extension>
|
</extension>
|
||||||
</extensions>
|
</extensions>
|
||||||
</build>
|
</build>
|
||||||
@ -207,15 +251,13 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- <plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>cobertura-maven-plugin</artifactId>
|
|
||||||
|
|
||||||
<version>2.2</version>
|
|
||||||
</plugin>-->
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<slf4j.version>1.5.11</slf4j.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -228,19 +270,60 @@
|
|||||||
<groupId>commons-httpclient</groupId>
|
<groupId>commons-httpclient</groupId>
|
||||||
<artifactId>commons-httpclient</artifactId>
|
<artifactId>commons-httpclient</artifactId>
|
||||||
<version>3.1</version>
|
<version>3.1</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jdom</groupId>
|
<groupId>jdom</groupId>
|
||||||
<artifactId>jdom</artifactId>
|
<artifactId>jdom</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sf.json-lib</groupId>
|
||||||
|
<artifactId>json-lib</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<classifier>jdk15</classifier>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.servicemix.bundles</groupId>
|
||||||
|
<artifactId>org.apache.servicemix.bundles.restlet</artifactId>
|
||||||
|
<version>1.1.10_3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- commons-logging can be rather simply and conveniently excluded as
|
||||||
|
a dependency by declaring it in the provided scope within the pom.xml file
|
||||||
|
of your project. The actual commons-logging classes would be provided by
|
||||||
|
jcl-over-slf4j.
|
||||||
|
This translates into the following pom file snippet: -->
|
||||||
|
<!-- <dependency>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
<version>1.1.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>1.2.16</version>
|
<version>1.2.16</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
</dependency>-->
|
||||||
|
|
||||||
<!--================================================================= -->
|
<!--================================================================= -->
|
||||||
<!-- TEST -->
|
<!-- TEST -->
|
||||||
@ -258,6 +341,19 @@
|
|||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>2.5.6.SEC02</version>
|
<version>2.5.6.SEC02</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
39
report.sh
Executable file
39
report.sh
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
if [ "$#" -ne 3 ]; then
|
||||||
|
echo "
|
||||||
|
Generates git log report between two tags:
|
||||||
|
USAGE:
|
||||||
|
$0 {START_TAG} {STOP_TAG|HEAD} {MESSAGE DESCRIPTION}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "What's new?
|
||||||
|
===========
|
||||||
|
|
||||||
|
$3
|
||||||
|
|
||||||
|
Where can I get it?
|
||||||
|
===================
|
||||||
|
|
||||||
|
* Home:
|
||||||
|
https://github.com/geosolutions-it/geoserver-manager
|
||||||
|
* Download:
|
||||||
|
https://github.com/geosolutions-it/geoserver-manager/releases
|
||||||
|
* Documentation:
|
||||||
|
https://github.com/geosolutions-it/geoserver-manager/wiki
|
||||||
|
|
||||||
|
Who contributed to this release?
|
||||||
|
================================
|
||||||
|
|
||||||
|
* List authors of this release
|
||||||
|
"
|
||||||
|
git log $1..$2 --pretty="format:* %aN" | sort | uniq
|
||||||
|
|
||||||
|
echo "
|
||||||
|
========================
|
||||||
|
CHANGES IN THIS RELEASE:
|
||||||
|
========================
|
||||||
|
"
|
||||||
|
git log $1..$2 --no-merges --pretty=oneline --reverse --grep fix --grep improve --grep close --grep "#" --grep add --format='* %s' .
|
||||||
|
|
||||||
|
exit $?
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2016 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager;
|
||||||
|
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
|
||||||
|
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager;
|
||||||
|
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStyleManager;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <i>The</i> single entry point to all of geoserver-manager functionality.
|
||||||
|
*
|
||||||
|
* Instance this one, and use getters to use different components. These are:
|
||||||
|
* <ul>
|
||||||
|
* <li>getReader() simple, high-level access methods.
|
||||||
|
* <li>getPublisher() simple, high-level pubhish methods.
|
||||||
|
* <li>get<i>Foo</i>Manager, full-fledged management of catalog objects.
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @author Oscar Fonts
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoServerRESTManager extends GeoServerRESTAbstractManager {
|
||||||
|
|
||||||
|
private final GeoServerRESTPublisher publisher;
|
||||||
|
private final GeoServerRESTReader reader;
|
||||||
|
|
||||||
|
private final GeoServerRESTStoreManager storeManager;
|
||||||
|
private final GeoServerRESTStyleManager styleManager;
|
||||||
|
|
||||||
|
private final GeoServerRESTStructuredGridCoverageReaderManager structuredGridCoverageReader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*
|
||||||
|
* Indicates connection parameters to remote GeoServer instance.
|
||||||
|
*
|
||||||
|
* @param restURL GeoServer REST API endpoint
|
||||||
|
* @param username GeoServer REST API authorized username
|
||||||
|
* @param password GeoServer REST API password for the former username
|
||||||
|
* @throws MalformedURLException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)}
|
||||||
|
* @throws IllegalArgumentException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)}
|
||||||
|
*/
|
||||||
|
public GeoServerRESTManager(URL restURL, String username, String password)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
super(restURL, username, password);
|
||||||
|
|
||||||
|
// Internal publisher and reader, provide simple access methods.
|
||||||
|
publisher = new GeoServerRESTPublisher(restURL.toString(), username, password);
|
||||||
|
reader = new GeoServerRESTReader(restURL, username, password);
|
||||||
|
structuredGridCoverageReader = new GeoServerRESTStructuredGridCoverageReaderManager(restURL, username, password);
|
||||||
|
storeManager = new GeoServerRESTStoreManager(restURL, gsuser, gspass);
|
||||||
|
styleManager = new GeoServerRESTStyleManager(restURL, gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoServerRESTPublisher getPublisher() {
|
||||||
|
return publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoServerRESTReader getReader() {
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoServerRESTStoreManager getStoreManager() {
|
||||||
|
return storeManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoServerRESTStyleManager getStyleManager() {
|
||||||
|
return styleManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoServerRESTStructuredGridCoverageReaderManager getStructuredGridCoverageReader() {
|
||||||
|
return structuredGridCoverageReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest;
|
package it.geosolutions.geoserver.rest;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -33,8 +34,15 @@ import java.net.ConnectException;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.sf.json.JSON;
|
||||||
|
import net.sf.json.JSONSerializer;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.Credentials;
|
import org.apache.commons.httpclient.Credentials;
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.HttpClient;
|
||||||
|
import org.apache.commons.httpclient.HttpConnectionManager;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
||||||
import org.apache.commons.httpclient.auth.AuthScope;
|
import org.apache.commons.httpclient.auth.AuthScope;
|
||||||
@ -46,20 +54,25 @@ import org.apache.commons.httpclient.methods.PostMethod;
|
|||||||
import org.apache.commons.httpclient.methods.PutMethod;
|
import org.apache.commons.httpclient.methods.PutMethod;
|
||||||
import org.apache.commons.httpclient.methods.RequestEntity;
|
import org.apache.commons.httpclient.methods.RequestEntity;
|
||||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||||
|
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
||||||
|
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
||||||
|
import org.apache.commons.httpclient.methods.multipart.Part;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Low level HTTP utilities.
|
* Low level HTTP utilities.
|
||||||
*/
|
*/
|
||||||
class HTTPUtils {
|
public class HTTPUtils {
|
||||||
private static final Logger LOGGER = Logger.getLogger(HTTPUtils.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(HTTPUtils.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs an HTTP GET on the given URL.
|
* Performs an HTTP GET on the given URL.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
*/
|
*/
|
||||||
public static String get(String url) throws MalformedURLException {
|
public static String get(String url) throws MalformedURLException {
|
||||||
@ -67,27 +80,30 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs an HTTP GET on the given URL.
|
* Performs an HTTP GET on the given URL. <BR>
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
* Basic auth is used if both username and pw are not null.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param username Basic auth credential. No basic auth if null.
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
* @param pw Basic auth credential. No basic auth if null.
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
*/
|
*/
|
||||||
public static String get(String url, String username, String pw) throws MalformedURLException {
|
public static String get(String url, String username, String pw) {
|
||||||
|
|
||||||
GetMethod httpMethod = null;
|
GetMethod httpMethod = null;
|
||||||
try {
|
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
|
HttpConnectionManager connectionManager = client.getHttpConnectionManager();
|
||||||
|
try {
|
||||||
setAuth(client, url, username, pw);
|
setAuth(client, url, username, pw);
|
||||||
httpMethod = new GetMethod(url);
|
httpMethod = new GetMethod(url);
|
||||||
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
|
connectionManager.getParams().setConnectionTimeout(5000);
|
||||||
int status = client.executeMethod(httpMethod);
|
int status = client.executeMethod(httpMethod);
|
||||||
if (status == HttpStatus.SC_OK) {
|
if (status == HttpStatus.SC_OK) {
|
||||||
InputStream is = httpMethod.getResponseBodyAsStream();
|
InputStream is = httpMethod.getResponseBodyAsStream();
|
||||||
String response = IOUtils.toString(is);
|
String response = IOUtils.toString(is);
|
||||||
|
IOUtils.closeQuietly(is);
|
||||||
if (response.trim().length() == 0) { // sometime gs rest fails
|
if (response.trim().length() == 0) { // sometime gs rest fails
|
||||||
LOGGER.warn("ResponseBody is empty");
|
LOGGER.warn("ResponseBody is empty");
|
||||||
return null;
|
return null;
|
||||||
@ -104,21 +120,39 @@ class HTTPUtils {
|
|||||||
} finally {
|
} finally {
|
||||||
if (httpMethod != null)
|
if (httpMethod != null)
|
||||||
httpMethod.releaseConnection();
|
httpMethod.releaseConnection();
|
||||||
|
connectionManager.closeIdleConnections(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PUTs a File to the given URL.
|
* Executes a request using the GET method and parses the result as a json object.
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
*
|
||||||
|
* @param path The path to request.
|
||||||
|
*
|
||||||
|
* @return The result parsed as json.
|
||||||
|
*/
|
||||||
|
public static JSON getAsJSON(String url, String username, String pw) throws Exception {
|
||||||
|
String response = get(url, username, pw);
|
||||||
|
return json(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSON json(String content) {
|
||||||
|
return JSONSerializer.toJSON(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUTs a File to the given URL. <BR>
|
||||||
|
* Basic auth is used if both username and pw are not null.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param file The File to be sent.
|
* @param file The File to be sent.
|
||||||
* @param contentType The content-type to advert in the PUT.
|
* @param contentType The content-type to advert in the PUT.
|
||||||
* @param username Basic auth credential. No basic auth if null.
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
* @param pw Basic auth credential. No basic auth if null.
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @return the HTTP response or <TT>null</TT> on errors.
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
@ -127,15 +161,16 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PUTs a String to the given URL.
|
* PUTs a String to the given URL. <BR>
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
* Basic auth is used if both username and pw are not null.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param content The content to be sent as a String.
|
* @param content The content to be sent as a String.
|
||||||
* @param contentType The content-type to advert in the PUT.
|
* @param contentType The content-type to advert in the PUT.
|
||||||
* @param username Basic auth credential. No basic auth if null.
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
* @param pw Basic auth credential. No basic auth if null.
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @return the HTTP response or <TT>null</TT> on errors.
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
@ -149,14 +184,15 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PUTs a String representing an XML document to the given URL.
|
* PUTs a String representing an XML document to the given URL. <BR>
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
* Basic auth is used if both username and pw are not null.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param content The XML content to be sent as a String.
|
* @param content The XML content to be sent as a String.
|
||||||
* @param username Basic auth credential. No basic auth if null.
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
* @param pw Basic auth credential. No basic auth if null.
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @return the HTTP response or <TT>null</TT> on errors.
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
@ -165,14 +201,32 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a PUT to the given URL.
|
* PUTs a String representing an JSON Object to the given URL. <BR>
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
* Basic auth is used if both username and pw are not null.
|
||||||
|
*
|
||||||
|
* @param url The URL where to connect to.
|
||||||
|
* @param content The JSON Object to be sent as a String.
|
||||||
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
|
*/
|
||||||
|
public static String putJson(String url, String content, String username, String pw) {
|
||||||
|
return put(url, content, "application/json", username, pw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a PUT to the given URL. <BR>
|
||||||
|
* Basic auth is used if both username and pw are not null.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param requestEntity The request to be sent.
|
* @param requestEntity The request to be sent.
|
||||||
* @param username Basic auth credential. No basic auth if null.
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
* @param pw Basic auth credential. No basic auth if null.
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @return the HTTP response or <TT>null</TT> on errors.
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
@ -181,15 +235,16 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POSTs a File to the given URL.
|
* POSTs a File to the given URL. <BR>
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
* Basic auth is used if both username and pw are not null.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param file The File to be sent.
|
* @param file The File to be sent.
|
||||||
* @param contentType The content-type to advert in the POST.
|
* @param contentType The content-type to advert in the POST.
|
||||||
* @param username Basic auth credential. No basic auth if null.
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
* @param pw Basic auth credential. No basic auth if null.
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @return the HTTP response or <TT>null</TT> on errors.
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
@ -198,15 +253,16 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POSTs a String to the given URL.
|
* POSTs a String to the given URL. <BR>
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
* Basic auth is used if both username and pw are not null.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param content The content to be sent as a String.
|
* @param content The content to be sent as a String.
|
||||||
* @param contentType The content-type to advert in the POST.
|
* @param contentType The content-type to advert in the POST.
|
||||||
* @param username Basic auth credential. No basic auth if null.
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
* @param pw Basic auth credential. No basic auth if null.
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @return the HTTP response or <TT>null</TT> on errors.
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
@ -220,14 +276,47 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POSTs a String representing an XML document to the given URL.
|
* POSTs a list of files as attachments to the given URL. <BR>
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
* Basic auth is used if both username and pw are not null.
|
||||||
|
*
|
||||||
|
* @param url The URL where to connect to.
|
||||||
|
* @param dir The folder containing the attachments.
|
||||||
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
|
*/
|
||||||
|
public static String postMultipartForm(String url, File dir, String username, String pw) {
|
||||||
|
try {
|
||||||
|
List<Part> parts = new ArrayList<Part>();
|
||||||
|
for (File f : dir.listFiles()) {
|
||||||
|
parts.add(new FilePart(f.getName(), f));
|
||||||
|
}
|
||||||
|
MultipartRequestEntity multipart = new MultipartRequestEntity(
|
||||||
|
parts.toArray(new Part[parts.size()]), new PostMethod().getParams());
|
||||||
|
|
||||||
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
|
multipart.writeRequest(bout);
|
||||||
|
|
||||||
|
return post(url, multipart, username, pw);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOGGER.error("Cannot POST " + url, ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POSTs a String representing an XML document to the given URL. <BR>
|
||||||
|
* Basic auth is used if both username and pw are not null.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param content The XML content to be sent as a String.
|
* @param content The XML content to be sent as a String.
|
||||||
* @param username Basic auth credential. No basic auth if null.
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
* @param pw Basic auth credential. No basic auth if null.
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @return the HTTP response or <TT>null</TT> on errors.
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
@ -236,14 +325,32 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a POST to the given URL.
|
* POSTs a String representing an JSON Object to the given URL. <BR>
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
* Basic auth is used if both username and pw are not null.
|
||||||
|
*
|
||||||
|
* @param url The URL where to connect to.
|
||||||
|
* @param content The JSON content to be sent as a String.
|
||||||
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
|
*/
|
||||||
|
public static String postJson(String url, String content, String username, String pw) {
|
||||||
|
return post(url, content, "application/json", username, pw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a POST to the given URL. <BR>
|
||||||
|
* Basic auth is used if both username and pw are not null.
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param requestEntity The request to be sent.
|
* @param requestEntity The request to be sent.
|
||||||
* @param username Basic auth credential. No basic auth if null.
|
* @param username Basic auth credential. No basic auth if null.
|
||||||
* @param pw Basic auth credential. No basic auth if null.
|
* @param pw Basic auth credential. No basic auth if null.
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200
|
||||||
|
* (OK).
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @return the HTTP response or <TT>null</TT> on errors.
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
@ -252,43 +359,46 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an HTTP request (PUT or POST) to a server.
|
* Send an HTTP request (PUT or POST) to a server. <BR>
|
||||||
* <BR>Basic auth is used if both username and pw are not null.
|
* Basic auth is used if both username and pw are not null.
|
||||||
* <P>
|
* <P>
|
||||||
* Only <UL>
|
* Only
|
||||||
|
* <UL>
|
||||||
* <LI>200: OK</LI>
|
* <LI>200: OK</LI>
|
||||||
* <LI>201: ACCEPTED</LI>
|
* <LI>201: ACCEPTED</LI>
|
||||||
* <LI>202: CREATED</LI>
|
* <LI>202: CREATED</LI>
|
||||||
* </UL> are accepted as successful codes; in these cases the response string will be returned.
|
* </UL>
|
||||||
|
* are accepted as successful codes; in these cases the response string will
|
||||||
|
* be returned.
|
||||||
*
|
*
|
||||||
* @return the HTTP response or <TT>null</TT> on errors.
|
* @return the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
private static String send(final EntityEnclosingMethod httpMethod, String url, RequestEntity requestEntity, String username, String pw) {
|
private static String send(final EntityEnclosingMethod httpMethod, String url,
|
||||||
|
RequestEntity requestEntity, String username, String pw) {
|
||||||
try {
|
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
|
HttpConnectionManager connectionManager = client.getHttpConnectionManager();
|
||||||
|
try {
|
||||||
setAuth(client, url, username, pw);
|
setAuth(client, url, username, pw);
|
||||||
// httpMethod = new PutMethod(url);
|
connectionManager.getParams().setConnectionTimeout(5000);
|
||||||
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
|
|
||||||
if (requestEntity != null)
|
if (requestEntity != null)
|
||||||
httpMethod.setRequestEntity(requestEntity);
|
httpMethod.setRequestEntity(requestEntity);
|
||||||
int status = client.executeMethod(httpMethod);
|
int status = client.executeMethod(httpMethod);
|
||||||
|
|
||||||
|
InputStream responseBody;
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case HttpURLConnection.HTTP_OK:
|
case HttpURLConnection.HTTP_OK:
|
||||||
case HttpURLConnection.HTTP_CREATED:
|
case HttpURLConnection.HTTP_CREATED:
|
||||||
case HttpURLConnection.HTTP_ACCEPTED:
|
case HttpURLConnection.HTTP_ACCEPTED:
|
||||||
String response = IOUtils.toString(httpMethod.getResponseBodyAsStream());
|
String response = IOUtils.toString(httpMethod.getResponseBodyAsStream());
|
||||||
// LOGGER.info("================= POST " + url);
|
// LOGGER.info("================= POST " + url);
|
||||||
|
if (LOGGER.isInfoEnabled())
|
||||||
LOGGER.info("HTTP " + httpMethod.getStatusText() + ": " + response);
|
LOGGER.info("HTTP " + httpMethod.getStatusText() + ": " + response);
|
||||||
return response;
|
return response;
|
||||||
default:
|
default:
|
||||||
LOGGER.warn("Bad response: code["+status+"]" +
|
responseBody = httpMethod.getResponseBodyAsStream();
|
||||||
" msg["+httpMethod.getStatusText()+"]" +
|
LOGGER.warn("Bad response: code[" + status + "]" + " msg[" + httpMethod.getStatusText() + "]"
|
||||||
" url["+url+"]" +
|
+ " url[" + url + "]" + " method[" + httpMethod.getClass().getSimpleName()
|
||||||
" method["+httpMethod.getClass().getSimpleName()+"]: " +
|
+ "]: " + (responseBody != null ? IOUtils.toString(responseBody) : ""));
|
||||||
IOUtils.toString(httpMethod.getResponseBodyAsStream())
|
|
||||||
);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ConnectException e) {
|
} catch (ConnectException e) {
|
||||||
@ -300,26 +410,28 @@ class HTTPUtils {
|
|||||||
} finally {
|
} finally {
|
||||||
if (httpMethod != null)
|
if (httpMethod != null)
|
||||||
httpMethod.releaseConnection();
|
httpMethod.releaseConnection();
|
||||||
|
connectionManager.closeIdleConnections(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean delete(String url, final String user, final String pw) {
|
public static boolean delete(String url, final String user, final String pw) {
|
||||||
|
|
||||||
DeleteMethod httpMethod = null;
|
DeleteMethod httpMethod = null;
|
||||||
|
|
||||||
try {
|
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
|
HttpConnectionManager connectionManager = client.getHttpConnectionManager();
|
||||||
|
try {
|
||||||
setAuth(client, url, user, pw);
|
setAuth(client, url, user, pw);
|
||||||
httpMethod = new DeleteMethod(url);
|
httpMethod = new DeleteMethod(url);
|
||||||
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
|
connectionManager.getParams().setConnectionTimeout(5000);
|
||||||
int status = client.executeMethod(httpMethod);
|
int status = client.executeMethod(httpMethod);
|
||||||
String response = "";
|
String response = "";
|
||||||
if (status == HttpStatus.SC_OK) {
|
if (status == HttpStatus.SC_OK) {
|
||||||
InputStream is = httpMethod.getResponseBodyAsStream();
|
InputStream is = httpMethod.getResponseBodyAsStream();
|
||||||
response = IOUtils.toString(is);
|
response = IOUtils.toString(is);
|
||||||
if(response.trim().equals("")) { // sometimes gs rest fails
|
IOUtils.closeQuietly(is);
|
||||||
if(LOGGER.isDebugEnabled())
|
if (response.trim().equals("")) {
|
||||||
LOGGER.debug("ResponseBody is empty (this may be not an error since we just performed a DELETE call)");
|
if (LOGGER.isTraceEnabled())
|
||||||
|
LOGGER.trace("ResponseBody is empty (this may be not an error since we just performed a DELETE call)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (LOGGER.isDebugEnabled())
|
if (LOGGER.isDebugEnabled())
|
||||||
@ -336,6 +448,7 @@ class HTTPUtils {
|
|||||||
} finally {
|
} finally {
|
||||||
if (httpMethod != null)
|
if (httpMethod != null)
|
||||||
httpMethod.releaseConnection();
|
httpMethod.releaseConnection();
|
||||||
|
connectionManager.closeIdleConnections(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -351,12 +464,12 @@ class HTTPUtils {
|
|||||||
public static boolean httpPing(String url, String username, String pw) {
|
public static boolean httpPing(String url, String username, String pw) {
|
||||||
|
|
||||||
GetMethod httpMethod = null;
|
GetMethod httpMethod = null;
|
||||||
|
|
||||||
try {
|
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
|
HttpConnectionManager connectionManager = client.getHttpConnectionManager();
|
||||||
|
try {
|
||||||
setAuth(client, url, username, pw);
|
setAuth(client, url, username, pw);
|
||||||
httpMethod = new GetMethod(url);
|
httpMethod = new GetMethod(url);
|
||||||
client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);
|
connectionManager.getParams().setConnectionTimeout(2000);
|
||||||
int status = client.executeMethod(httpMethod);
|
int status = client.executeMethod(httpMethod);
|
||||||
if (status != HttpStatus.SC_OK) {
|
if (status != HttpStatus.SC_OK) {
|
||||||
LOGGER.warn("PING failed at '" + url + "': (" + status + ") " + httpMethod.getStatusText());
|
LOGGER.warn("PING failed at '" + url + "': (" + status + ") " + httpMethod.getStatusText());
|
||||||
@ -364,15 +477,15 @@ class HTTPUtils {
|
|||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ConnectException e) {
|
} catch (ConnectException e) {
|
||||||
return false;
|
return false;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
LOGGER.error(e.getLocalizedMessage(),e);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (httpMethod != null)
|
if (httpMethod != null)
|
||||||
httpMethod.releaseConnection();
|
httpMethod.releaseConnection();
|
||||||
|
connectionManager.closeIdleConnections(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,12 +501,12 @@ class HTTPUtils {
|
|||||||
public static boolean exists(String url, String username, String pw) {
|
public static boolean exists(String url, String username, String pw) {
|
||||||
|
|
||||||
GetMethod httpMethod = null;
|
GetMethod httpMethod = null;
|
||||||
|
|
||||||
try {
|
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
|
HttpConnectionManager connectionManager = client.getHttpConnectionManager();
|
||||||
|
try {
|
||||||
setAuth(client, url, username, pw);
|
setAuth(client, url, username, pw);
|
||||||
httpMethod = new GetMethod(url);
|
httpMethod = new GetMethod(url);
|
||||||
client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);
|
connectionManager.getParams().setConnectionTimeout(2000);
|
||||||
int status = client.executeMethod(httpMethod);
|
int status = client.executeMethod(httpMethod);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case HttpStatus.SC_OK:
|
case HttpStatus.SC_OK:
|
||||||
@ -401,7 +514,8 @@ class HTTPUtils {
|
|||||||
case HttpStatus.SC_NOT_FOUND:
|
case HttpStatus.SC_NOT_FOUND:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unhandled response status at '"+url+"': ("+status+") " + httpMethod.getStatusText());
|
throw new RuntimeException("Unhandled response status at '" + url + "': (" + status + ") "
|
||||||
|
+ httpMethod.getStatusText());
|
||||||
}
|
}
|
||||||
} catch (ConnectException e) {
|
} catch (ConnectException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -410,16 +524,21 @@ class HTTPUtils {
|
|||||||
} finally {
|
} finally {
|
||||||
if (httpMethod != null)
|
if (httpMethod != null)
|
||||||
httpMethod.releaseConnection();
|
httpMethod.releaseConnection();
|
||||||
|
connectionManager.closeIdleConnections(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setAuth(HttpClient client, String url, String username, String pw)
|
||||||
private static void setAuth(HttpClient client, String url, String username, String pw) throws MalformedURLException {
|
throws MalformedURLException {
|
||||||
URL u = new URL(url);
|
URL u = new URL(url);
|
||||||
if (username != null && pw != null) {
|
if (username != null && pw != null) {
|
||||||
Credentials defaultcreds = new UsernamePasswordCredentials(username, pw);
|
Credentials defaultcreds = new UsernamePasswordCredentials(username, pw);
|
||||||
client.getState().setCredentials(new AuthScope(u.getHost(), u.getPort()), defaultcreds);
|
client.getState().setCredentials(new AuthScope(u.getHost(), u.getPort()), defaultcreds);
|
||||||
client.getParams().setAuthenticationPreemptive(true); // GS2 by default always requires authentication
|
client.getParams().setAuthenticationPreemptive(true); // GS2 by
|
||||||
|
// default
|
||||||
|
// always
|
||||||
|
// requires
|
||||||
|
// authentication
|
||||||
} else {
|
} else {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("Not setting credentials to access to " + url);
|
LOGGER.debug("Not setting credentials to access to " + url);
|
||||||
@ -428,16 +547,50 @@ class HTTPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* recursively remove ending slashes
|
|
||||||
*
|
|
||||||
* @param geoserverURL
|
* @param geoserverURL
|
||||||
* @return
|
* @return recursively remove ending slashes
|
||||||
*/
|
*/
|
||||||
public static String decurtSlash(String geoserverURL) {
|
public static String decurtSlash(String geoserverURL) {
|
||||||
if (geoserverURL.endsWith("/")) {
|
if (geoserverURL!=null && geoserverURL.endsWith("/")) {
|
||||||
geoserverURL = decurtSlash(geoserverURL.substring(0, geoserverURL.length() - 1));
|
geoserverURL = decurtSlash(geoserverURL.substring(0, geoserverURL.length() - 1));
|
||||||
}
|
}
|
||||||
return geoserverURL;
|
return geoserverURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param str a string array
|
||||||
|
* @return create a StringBuilder appending all the passed arguments
|
||||||
|
*/
|
||||||
|
public static StringBuilder append(String ... str){
|
||||||
|
if (str==null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder buf=new StringBuilder();
|
||||||
|
for (String s: str){
|
||||||
|
if (s!=null)
|
||||||
|
buf.append(s);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for {@link #append(String...)}
|
||||||
|
* @param base base URL
|
||||||
|
* @param str strings to append
|
||||||
|
* @return the base URL with parameters attached
|
||||||
|
*/
|
||||||
|
public static StringBuilder append(URL base, String ... str){
|
||||||
|
if (str==null){
|
||||||
|
return append(base.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder buf=new StringBuilder(base.toString());
|
||||||
|
for (String s: str){
|
||||||
|
if (s!=null)
|
||||||
|
buf.append(s);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
121
src/main/java/it/geosolutions/geoserver/rest/Util.java
Normal file
121
src/main/java/it/geosolutions/geoserver/rest/Util.java
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 - 2016 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTStyle;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author ETj (etj at geo-solutions.it)
|
||||||
|
*/
|
||||||
|
public class Util {
|
||||||
|
|
||||||
|
public static final String QUIET_ON_NOT_FOUND_PARAM = "quietOnNotFound=";
|
||||||
|
|
||||||
|
public static final boolean DEFAULT_QUIET_ON_NOT_FOUND = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a stylename in global and in all workspaces.
|
||||||
|
*/
|
||||||
|
public static List<RESTStyle> searchStyles(GeoServerRESTReader reader, String stylename) {
|
||||||
|
|
||||||
|
List<RESTStyle> styles = new ArrayList<RESTStyle>();
|
||||||
|
|
||||||
|
RESTStyle style = reader.getStyle(stylename);
|
||||||
|
|
||||||
|
// We don't want geoserver to be lenient here: take only the real global style if it exists
|
||||||
|
if(style != null) {
|
||||||
|
if(style.getWorkspace() == null || style.getWorkspace().isEmpty()) {
|
||||||
|
styles.add(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String workspace : reader.getWorkspaceNames()) {
|
||||||
|
style = reader.getStyle(workspace, stylename);
|
||||||
|
if(style != null)
|
||||||
|
styles.add(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append the quietOnNotFound parameter to the input URL
|
||||||
|
* @param quietOnNotFound parameter
|
||||||
|
* @param url input url
|
||||||
|
* @return a composed url with the parameter appended
|
||||||
|
*/
|
||||||
|
public static String appendQuietOnNotFound(boolean quietOnNotFound, String url) {
|
||||||
|
boolean contains = url.contains("?");
|
||||||
|
String composed = url + (contains ? "&":"?") + QUIET_ON_NOT_FOUND_PARAM + quietOnNotFound;
|
||||||
|
return composed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> List<T> safeList(List<T> list) {
|
||||||
|
return list == null ? Collections.EMPTY_LIST : list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Collection<T> safeCollection(Collection<T> collection) {
|
||||||
|
return collection == null ? Collections.EMPTY_SET : collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <TK, TV> Map<TK, TV> safeMap(Map<TK, TV> map) {
|
||||||
|
return map == null ? Collections.EMPTY_MAP : map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char getParameterSeparator(String url) {
|
||||||
|
char parameterSeparator = '?';
|
||||||
|
if (url.contains("?")) {
|
||||||
|
parameterSeparator = '&';
|
||||||
|
}
|
||||||
|
return parameterSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char getParameterSeparator(StringBuilder url) {
|
||||||
|
char parameterSeparator = '?';
|
||||||
|
if (url.indexOf("?") != -1) {
|
||||||
|
parameterSeparator = '&';
|
||||||
|
}
|
||||||
|
return parameterSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean appendParameter(StringBuilder url, String parameterName,
|
||||||
|
String parameterValue) {
|
||||||
|
boolean result = false;
|
||||||
|
if (parameterName != null && !parameterName.isEmpty()
|
||||||
|
&& parameterValue != null && !parameterValue.isEmpty()) {
|
||||||
|
char parameterSeparator = getParameterSeparator(url);
|
||||||
|
url.append(parameterSeparator).append(parameterName.trim())
|
||||||
|
.append('=').append(parameterValue.trim());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -26,8 +26,8 @@
|
|||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMListIterator;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMListIterator;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|||||||
@ -0,0 +1,48 @@
|
|||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a Boundingbox of the following structure
|
||||||
|
*
|
||||||
|
* <minx>472800.0</minx>
|
||||||
|
* <maxx>817362.0</maxx>
|
||||||
|
* <miny>35053.40625</miny>
|
||||||
|
* <maxy>301500.0</maxy>
|
||||||
|
* <crs class="projected">EPSG:21781</crs>
|
||||||
|
*
|
||||||
|
* @author nmandery
|
||||||
|
*/
|
||||||
|
public class RESTBoundingBox {
|
||||||
|
|
||||||
|
protected Element bboxElem;
|
||||||
|
|
||||||
|
public RESTBoundingBox(Element bboxElem) {
|
||||||
|
this.bboxElem = bboxElem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCRS() {
|
||||||
|
return this.bboxElem.getChildText("crs");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected double getEdge(String edge) {
|
||||||
|
return Double.parseDouble(this.bboxElem.getChildText(edge));
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMinX() {
|
||||||
|
return this.getEdge("minx");
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxX() {
|
||||||
|
return this.getEdge("maxx");
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMinY() {
|
||||||
|
return this.getEdge("miny");
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxY() {
|
||||||
|
return this.getEdge("maxy");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -25,6 +25,13 @@
|
|||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,9 +171,9 @@ public class RESTCoverage extends RESTResource {
|
|||||||
// return rootElem.getChildText("name");
|
// return rootElem.getChildText("name");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// public String getNativeName() {
|
public String getNativeCoverageName() {
|
||||||
// return rootElem.getChildText("nativeName");
|
return rootElem.getChildText("nativeCoverageName");
|
||||||
// }
|
}
|
||||||
|
|
||||||
public String getNativeFormat() {
|
public String getNativeFormat() {
|
||||||
return rootElem.getChildText("nativeFormat");
|
return rootElem.getChildText("nativeFormat");
|
||||||
@ -188,6 +195,154 @@ public class RESTCoverage extends RESTResource {
|
|||||||
return rootElem.getChildText("srs");
|
return rootElem.getChildText("srs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RESTMetadataList getMetadataList() {
|
||||||
|
return new RESTMetadataList(rootElem.getChild("metadata"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RESTDimensionInfo> getDimensionInfo() {
|
||||||
|
List<RESTDimensionInfo> listDim = new ArrayList<RESTDimensionInfo>();
|
||||||
|
for (RESTMetadataList.RESTMetadataElement el : getMetadataList()){
|
||||||
|
if(el.getKey().equals(RESTDimensionInfo.TIME) || el.getKey().equals(RESTDimensionInfo.ELEVATION)){
|
||||||
|
listDim.add(new RESTDimensionInfo(el.getMetadataElem()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return listDim;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the list of parameters for this coverage.
|
||||||
|
*
|
||||||
|
* @return a {@link Map} where the key is the name for the parameter and the value is the value for the parameter.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, String> getParametersList() {
|
||||||
|
Map<String, String> paramsList = new HashMap<String, String>();
|
||||||
|
|
||||||
|
final Element paramsRoot = rootElem.getChild("parameters");
|
||||||
|
if (paramsRoot != null) {
|
||||||
|
final List<Element> params = paramsRoot.getChildren();
|
||||||
|
if (params != null) {
|
||||||
|
for (Element param : params) {
|
||||||
|
final List<Element> values = param.getChildren();
|
||||||
|
assert values.size()==2;
|
||||||
|
paramsList.put(values.get(0).getValue(), values.get(1).getValue()); // save key and value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return paramsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("RESTCoverage [");
|
||||||
|
if (getNativeFormat() != null) {
|
||||||
|
builder.append("getNativeFormat()=");
|
||||||
|
builder.append(getNativeFormat());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getNativeCRS() != null) {
|
||||||
|
builder.append("getNativeCRS()=");
|
||||||
|
builder.append(getNativeCRS());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getSRS() != null) {
|
||||||
|
builder.append("getSRS()=");
|
||||||
|
builder.append(getSRS());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getMetadataList() != null) {
|
||||||
|
builder.append("getMetadataList()=");
|
||||||
|
builder.append(getMetadataList());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getDimensionInfo() != null) {
|
||||||
|
builder.append("getDimensionInfo()=");
|
||||||
|
builder.append(getDimensionInfo());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getParametersList() != null) {
|
||||||
|
builder.append("getParametersList()=");
|
||||||
|
builder.append(getParametersList());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getName() != null) {
|
||||||
|
builder.append("getName()=");
|
||||||
|
builder.append(getName());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getTitle() != null) {
|
||||||
|
builder.append("getTitle()=");
|
||||||
|
builder.append(getTitle());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getNativeName() != null) {
|
||||||
|
builder.append("getNativeName()=");
|
||||||
|
builder.append(getNativeName());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getNativeCoverageName() != null) {
|
||||||
|
builder.append("getNativeCoverageName()=");
|
||||||
|
builder.append(getNativeCoverageName());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getAbstract() != null) {
|
||||||
|
builder.append("getAbstract()=");
|
||||||
|
builder.append(getAbstract());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getNameSpace() != null) {
|
||||||
|
builder.append("getNameSpace()=");
|
||||||
|
builder.append(getNameSpace());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getStoreName() != null) {
|
||||||
|
builder.append("getStoreName()=");
|
||||||
|
builder.append(getStoreName());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getStoreType() != null) {
|
||||||
|
builder.append("getStoreType()=");
|
||||||
|
builder.append(getStoreType());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getStoreUrl() != null) {
|
||||||
|
builder.append("getStoreUrl()=");
|
||||||
|
builder.append(getStoreUrl());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getCRS() != null) {
|
||||||
|
builder.append("getCRS()=");
|
||||||
|
builder.append(getCRS());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
builder.append("getMinX()=");
|
||||||
|
builder.append(getMinX());
|
||||||
|
builder.append(", getMaxX()=");
|
||||||
|
builder.append(getMaxX());
|
||||||
|
builder.append(", getMinY()=");
|
||||||
|
builder.append(getMinY());
|
||||||
|
builder.append(", getMaxY()=");
|
||||||
|
builder.append(getMaxY());
|
||||||
|
builder.append(", ");
|
||||||
|
if (getAttributeList() != null) {
|
||||||
|
builder.append("getAttributeList()=");
|
||||||
|
builder.append(getAttributeList());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getEncodedAttributeList() != null) {
|
||||||
|
builder.append("getEncodedAttributeList()=");
|
||||||
|
builder.append(getEncodedAttributeList());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getEncodedMetadataLinkInfoList() != null) {
|
||||||
|
builder.append("getEncodedMetadataLinkInfoList()=");
|
||||||
|
builder.append(getEncodedMetadataLinkInfoList());
|
||||||
|
}
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
// public String getStoreName() {
|
// public String getStoreName() {
|
||||||
// return rootElem.getChild("store").getChildText("name");
|
// return rootElem.getChild("store").getChildText("name");
|
||||||
|
|||||||
@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,6 +87,14 @@ public class RESTCoverageStore {
|
|||||||
return cs.getChild("workspace").getChildText("name");
|
return cs.getChild("workspace").getChildText("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getURL() {
|
||||||
|
return cs.getChildText("url");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return cs.getChildText("type");
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder(getClass().getSimpleName())
|
StringBuilder sb = new StringBuilder(getClass().getSimpleName())
|
||||||
.append('[');
|
.append('[');
|
||||||
|
|||||||
@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
* Copyright (C) 2007,2014 GeoSolutions S.A.S.
|
||||||
* http://www.geo-solutions.it
|
* http://www.geo-solutions.it
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -26,7 +26,11 @@
|
|||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,6 +71,7 @@ public class RESTDataStore {
|
|||||||
public enum DBType {
|
public enum DBType {
|
||||||
|
|
||||||
POSTGIS("postgis"),
|
POSTGIS("postgis"),
|
||||||
|
ORACLE("oracle"),
|
||||||
SHP("shp"),
|
SHP("shp"),
|
||||||
UNKNOWN(null);
|
UNKNOWN(null);
|
||||||
private final String restName;
|
private final String restName;
|
||||||
@ -109,10 +114,39 @@ public class RESTDataStore {
|
|||||||
return dsElem.getChildText("name");
|
return dsElem.getChildText("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStoreType() {
|
||||||
|
return dsElem.getChildText("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return dsElem.getChildText("description");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return Boolean.parseBoolean(dsElem.getChildText("enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
public String getWorkspaceName() {
|
public String getWorkspaceName() {
|
||||||
return dsElem.getChild("workspace").getChildText("name");
|
return dsElem.getChild("workspace").getChildText("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getConnectionParameters() {
|
||||||
|
Element elConnparm = dsElem.getChild("connectionParameters");
|
||||||
|
if (elConnparm != null) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<Element> elements = (List<Element>)elConnparm.getChildren("entry");
|
||||||
|
Map<String, String> params = new HashMap<String, String>(elements.size());
|
||||||
|
for (Element element : elements) {
|
||||||
|
String key = element.getAttributeValue("key");
|
||||||
|
String value = element.getTextTrim();
|
||||||
|
params.put(key, value);
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected String getConnectionParameter(String paramName) {
|
protected String getConnectionParameter(String paramName) {
|
||||||
Element elConnparm = dsElem.getChild("connectionParameters");
|
Element elConnparm = dsElem.getChild("connectionParameters");
|
||||||
if (elConnparm != null) {
|
if (elConnparm != null) {
|
||||||
|
|||||||
@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* GeoBatch - Open Source geospatial batch processing system
|
||||||
|
* https://github.com/nfms4redd/nfms-geobatch
|
||||||
|
* Copyright (C) 2007-2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* GPLv3 + Classpath exception
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DamianoG
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RESTDimensionInfo extends RESTMetadataList.RESTMetadataElement{
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
private String presentation;
|
||||||
|
private String resolution;
|
||||||
|
|
||||||
|
public static final String TIME = "time";
|
||||||
|
public static final String ELEVATION = "elevation";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param elem
|
||||||
|
*/
|
||||||
|
public RESTDimensionInfo(Element elem) {
|
||||||
|
super(elem);
|
||||||
|
if(elem.getChild("dimensionInfo")!=null){
|
||||||
|
enabled = Boolean.parseBoolean(elem.getChild("dimensionInfo").getChildText("enabled"));
|
||||||
|
presentation = elem.getChild("dimensionInfo").getChildText("presentation");
|
||||||
|
resolution = elem.getChild("dimensionInfo").getChildText("resolution");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the enabled
|
||||||
|
*/
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param enabled the enabled to set
|
||||||
|
*/
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the presentation
|
||||||
|
*/
|
||||||
|
public String getPresentation() {
|
||||||
|
return presentation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param presentation the presentation to set
|
||||||
|
*/
|
||||||
|
public void setPresentation(String presentation) {
|
||||||
|
this.presentation = presentation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the resolution
|
||||||
|
*/
|
||||||
|
public String getResolution() {
|
||||||
|
return resolution;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param resolution the resolution to set
|
||||||
|
*/
|
||||||
|
public void setResolution(String resolution) {
|
||||||
|
this.resolution = resolution;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -27,7 +27,15 @@ package it.geosolutions.geoserver.rest.decoder;
|
|||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMListIterator;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMListIterator;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,4 +251,50 @@ public class RESTFeatureType extends RESTResource {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<Map<FeatureTypeAttribute, String>> getAttributeList() {
|
||||||
|
List<Map<FeatureTypeAttribute, String>> attrsList = null;
|
||||||
|
|
||||||
|
final Element attrsRoot = rootElem.getChild("attributes");
|
||||||
|
if(attrsRoot!=null){
|
||||||
|
final List<Element> attrs = attrsRoot.getChildren();
|
||||||
|
if (attrs != null) {
|
||||||
|
attrsList = new ArrayList<Map<FeatureTypeAttribute, String>>(attrs.size());
|
||||||
|
for (Element attr : attrs) {
|
||||||
|
Map<FeatureTypeAttribute, String> attrsMap = new HashMap<FeatureTypeAttribute, String>();
|
||||||
|
attrsList.add(attrsMap);
|
||||||
|
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
|
||||||
|
String key = at.toString();
|
||||||
|
attrsMap.put(at, attr.getChildText(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attrsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GSAttributeEncoder> getEncodedAttributeList() {
|
||||||
|
List<GSAttributeEncoder> attrsList = null;
|
||||||
|
|
||||||
|
final Element attrsRoot = rootElem.getChild("attributes");
|
||||||
|
if(attrsRoot!=null){
|
||||||
|
final List<Element> attrs = attrsRoot.getChildren();
|
||||||
|
if (attrs != null) {
|
||||||
|
attrsList = new ArrayList<GSAttributeEncoder>(attrs.size());
|
||||||
|
for (Element attr : attrs) {
|
||||||
|
final GSAttributeEncoder attrEnc = new GSAttributeEncoder();
|
||||||
|
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
|
||||||
|
String key = at.toString();
|
||||||
|
attrEnc.setAttribute(at, attr.getChildText(key));
|
||||||
|
}
|
||||||
|
attrsList.add(attrEnc);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attrsList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses list of summary data about FeatureTypes.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* FeatureType summary info.
|
||||||
|
* <BR>This is an XML fragment:
|
||||||
|
* <PRE>
|
||||||
|
*{@code
|
||||||
|
<featureType>
|
||||||
|
<name>states</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
|
||||||
|
href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/states.xml"
|
||||||
|
type="application/xml"/>
|
||||||
|
</featureType>
|
||||||
|
* }
|
||||||
|
* </PRE>
|
||||||
|
*
|
||||||
|
* @author wumpz
|
||||||
|
*/
|
||||||
|
public class RESTFeatureTypeList extends RESTAbstractList<NameLinkElem> {
|
||||||
|
|
||||||
|
public static RESTFeatureTypeList build(String response) {
|
||||||
|
Element elem = JDOMBuilder.buildElement(response);
|
||||||
|
return elem == null? null : new RESTFeatureTypeList(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RESTFeatureTypeList(Element list) {
|
||||||
|
super(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,7 +25,17 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.IdentifierInfo;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.metadatalink.ResourceMetadataLinkInfo;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.Namespace;
|
import org.jdom.Namespace;
|
||||||
|
|
||||||
@ -43,35 +53,56 @@ import org.jdom.Namespace;
|
|||||||
<name>capitals</name>
|
<name>capitals</name>
|
||||||
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/styles/capitals.xml" type="application/xml"/>
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/styles/capitals.xml" type="application/xml"/>
|
||||||
</defaultStyle>
|
</defaultStyle>
|
||||||
|
<styles class="linked-hash-set">
|
||||||
|
<style>
|
||||||
|
<name>green</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/styles/green.xml" type="application/xml"/>
|
||||||
|
</style>
|
||||||
|
</styles>
|
||||||
<resource class="featureType">
|
<resource class="featureType">
|
||||||
<name>tasmania_cities</name>
|
<name>tasmania_cities</name>
|
||||||
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml" type="application/xml"/>
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml" type="application/xml"/>
|
||||||
</resource>
|
</resource>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
|
<queryable>true</queryable>
|
||||||
|
<advertised>true</advertised>
|
||||||
<attribution>
|
<attribution>
|
||||||
<logoWidth>0</logoWidth>
|
<logoWidth>0</logoWidth>
|
||||||
<logoHeight>0</logoHeight>
|
<logoHeight>0</logoHeight>
|
||||||
</attribution>
|
</attribution>
|
||||||
|
<authorityURLs>
|
||||||
|
<AuthorityURL>
|
||||||
|
<name>authority1</name>
|
||||||
|
<href>http://www.authority1.org</href>
|
||||||
|
</AuthorityURL>
|
||||||
|
</authorityURLs>
|
||||||
|
<identifiers>
|
||||||
|
<Identifier>
|
||||||
|
<authority>authority1</authority>
|
||||||
|
<identifier>identifier1</identifier>
|
||||||
|
</Identifier>
|
||||||
|
</identifiers>
|
||||||
</layer>
|
</layer>
|
||||||
* }</PRE>
|
* }</PRE>
|
||||||
* @author etj
|
* @author etj
|
||||||
|
* @author eblondel
|
||||||
*/
|
*/
|
||||||
public class RESTLayer {
|
public class RESTLayer {
|
||||||
private final Element layerElem;
|
protected final Element layerElem;
|
||||||
|
|
||||||
public enum TYPE {
|
public enum Type {
|
||||||
VECTOR("VECTOR"),
|
VECTOR("VECTOR"),
|
||||||
RASTER("RASTER"),
|
RASTER("RASTER"),
|
||||||
UNKNOWN(null);
|
UNKNOWN(null);
|
||||||
|
|
||||||
private final String restName;
|
private final String restName;
|
||||||
|
|
||||||
private TYPE(String restName) {
|
private Type(String restName) {
|
||||||
this.restName = restName;
|
this.restName = restName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TYPE get(String restName) {
|
public static Type get(String restName) {
|
||||||
for (TYPE type : values()) {
|
for (Type type : values()) {
|
||||||
if(type == UNKNOWN)
|
if(type == UNKNOWN)
|
||||||
continue;
|
continue;
|
||||||
if(type.restName.equals(restName))
|
if(type.restName.equals(restName))
|
||||||
@ -96,6 +127,18 @@ public class RESTLayer {
|
|||||||
this.layerElem = layerElem;
|
this.layerElem = layerElem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getEnabled(){
|
||||||
|
return Boolean.parseBoolean(layerElem.getChildText("enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getQueryable(){
|
||||||
|
return Boolean.parseBoolean(layerElem.getChildText("queryable"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAdvertised(){
|
||||||
|
return Boolean.parseBoolean(layerElem.getChildText("advertised"));
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return layerElem.getChildText("name");
|
return layerElem.getChildText("name");
|
||||||
}
|
}
|
||||||
@ -104,8 +147,8 @@ public class RESTLayer {
|
|||||||
return layerElem.getChildText("type");
|
return layerElem.getChildText("type");
|
||||||
}
|
}
|
||||||
|
|
||||||
public TYPE getType() {
|
public Type getType() {
|
||||||
return TYPE.get(getTypeString());
|
return Type.get(getTypeString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultStyle() {
|
public String getDefaultStyle() {
|
||||||
@ -113,6 +156,20 @@ public class RESTLayer {
|
|||||||
return defaultStyle == null? null : defaultStyle.getChildText("name");
|
return defaultStyle == null? null : defaultStyle.getChildText("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RESTStyleList getStyles() {
|
||||||
|
RESTStyleList styleList = null;
|
||||||
|
final Element stylesRoot = layerElem.getChild("styles");
|
||||||
|
if (stylesRoot != null) {
|
||||||
|
styleList = new RESTStyleList(stylesRoot);
|
||||||
|
}
|
||||||
|
return styleList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultStyleWorkspace() {
|
||||||
|
Element defaultStyle = layerElem.getChild("defaultStyle");
|
||||||
|
return defaultStyle == null? null : defaultStyle.getChildText("workspace");
|
||||||
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
Element resource = layerElem.getChild("resource");
|
Element resource = layerElem.getChild("resource");
|
||||||
return resource.getChildText("title");
|
return resource.getChildText("title");
|
||||||
@ -159,6 +216,62 @@ public class RESTLayer {
|
|||||||
return atom.getAttributeValue("href");
|
return atom.getAttributeValue("href");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of AuthorityURLInfo from the GeoServer Layer
|
||||||
|
*
|
||||||
|
* @return the list of GSAuthorityURLInfoEncoder
|
||||||
|
*/
|
||||||
|
public List<GSAuthorityURLInfoEncoder> getEncodedAuthorityURLInfoList() {
|
||||||
|
List<GSAuthorityURLInfoEncoder> authorityURLList = null;
|
||||||
|
|
||||||
|
final Element authorityURLsRoot = layerElem.getChild("authorityURLs");
|
||||||
|
if (authorityURLsRoot != null) {
|
||||||
|
final List<Element> authorityURLs = authorityURLsRoot.getChildren();
|
||||||
|
if (authorityURLs != null) {
|
||||||
|
authorityURLList = new ArrayList<GSAuthorityURLInfoEncoder>(
|
||||||
|
authorityURLs.size());
|
||||||
|
for (Element authorityURL : authorityURLs) {
|
||||||
|
final GSAuthorityURLInfoEncoder authEnc = new GSAuthorityURLInfoEncoder();
|
||||||
|
authEnc.setName(authorityURL
|
||||||
|
.getChildText(AuthorityURLInfo.name.name()));
|
||||||
|
authEnc.setHref(authorityURL
|
||||||
|
.getChildText(AuthorityURLInfo.href.name()));
|
||||||
|
authorityURLList.add(authEnc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return authorityURLList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of IdentifierInfo from the GeoServer Layer
|
||||||
|
*
|
||||||
|
* @return the list of IdentifierInfoEncoder
|
||||||
|
*/
|
||||||
|
public List<GSIdentifierInfoEncoder> getEncodedIdentifierInfoList() {
|
||||||
|
List<GSIdentifierInfoEncoder> idList = null;
|
||||||
|
|
||||||
|
final Element idRoot = layerElem.getChild("identifiers");
|
||||||
|
if (idRoot != null) {
|
||||||
|
final List<Element> identifiers = idRoot.getChildren();
|
||||||
|
if (identifiers != null) {
|
||||||
|
idList = new ArrayList<GSIdentifierInfoEncoder>(
|
||||||
|
identifiers.size());
|
||||||
|
for (Element identifier : identifiers) {
|
||||||
|
final GSIdentifierInfoEncoder idEnc = new GSIdentifierInfoEncoder();
|
||||||
|
idEnc.setAuthority(identifier
|
||||||
|
.getChildText(IdentifierInfo.authority.name()));
|
||||||
|
idEnc.setIdentifier(identifier
|
||||||
|
.getChildText(IdentifierInfo.identifier.name()));
|
||||||
|
idList.add(idEnc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return idList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// protected double getLatLonEdge(String edge) {
|
// protected double getLatLonEdge(String edge) {
|
||||||
// Element resource = layerElem.getChild("resource");
|
// Element resource = layerElem.getChild("resource");
|
||||||
// Element elBBox = resource.getChild("latLonBoundingBox");
|
// Element elBBox = resource.getChild("latLonBoundingBox");
|
||||||
|
|||||||
@ -0,0 +1,178 @@
|
|||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse <TT>Layer</TT>s returned as XML REST objects. Applicable to GS 2.1 for
|
||||||
|
* decoding: - AuthorityURLs - Identifiers - advertised property value
|
||||||
|
*
|
||||||
|
* <P>
|
||||||
|
* This is the XML REST representation:
|
||||||
|
*
|
||||||
|
* <PRE>
|
||||||
|
* {@code
|
||||||
|
* <layer>
|
||||||
|
* <name>tasmania_cities</name>
|
||||||
|
* <path>/</path>
|
||||||
|
* <type>VECTOR</type>
|
||||||
|
* <defaultStyle>
|
||||||
|
* <name>capitals</name>
|
||||||
|
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/styles/capitals.xml" type="application/xml"/>
|
||||||
|
* </defaultStyle>
|
||||||
|
* <resource class="featureType">
|
||||||
|
* <name>tasmania_cities</name>
|
||||||
|
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml" type="application/xml"/>
|
||||||
|
* </resource>
|
||||||
|
* <enabled>true</enabled>
|
||||||
|
* <queryable>true</queryable>
|
||||||
|
* <advertised>true</advertised>
|
||||||
|
* <attribution>
|
||||||
|
* <logoWidth>0</logoWidth>
|
||||||
|
* <logoHeight>0</logoHeight>
|
||||||
|
* </attribution>
|
||||||
|
* <metadata>
|
||||||
|
* <entry key="identifiers">
|
||||||
|
* [{"authority":"authority1","identifier":"identifier1"},]
|
||||||
|
* </entry>
|
||||||
|
* <entry key="authorityURLs">
|
||||||
|
* [{"name":"authority1","href":"http://www.authority1.org"},]
|
||||||
|
* </entry>
|
||||||
|
* <entry key="advertised">true</entry>
|
||||||
|
* </metadata>
|
||||||
|
* </layer>
|
||||||
|
* }
|
||||||
|
* </PRE>
|
||||||
|
*
|
||||||
|
* @author eblondel
|
||||||
|
*/
|
||||||
|
public class RESTLayer21 extends RESTLayer{
|
||||||
|
|
||||||
|
|
||||||
|
public RESTLayer21(Element layerElem) {
|
||||||
|
super(layerElem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RESTLayer21 build(String response) {
|
||||||
|
if(response == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Element pb = JDOMBuilder.buildElement(response);
|
||||||
|
if(pb != null)
|
||||||
|
return new RESTLayer21(pb);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the advertised property from the Geoserver Layer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public boolean getAdvertised(){
|
||||||
|
boolean advertised = true;
|
||||||
|
|
||||||
|
final Element metadataRoot = layerElem.getChild("metadata");
|
||||||
|
if(metadataRoot != null){
|
||||||
|
final List<Element> metaElements = metadataRoot.getChildren();
|
||||||
|
if(metaElements != null){
|
||||||
|
for(Element el : metaElements){
|
||||||
|
String key = el.getAttributeValue("key");
|
||||||
|
if(key.matches("advertised")){
|
||||||
|
advertised = Boolean.parseBoolean(el.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return advertised;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of AuthorityURLInfo from the GeoServer Layer
|
||||||
|
*
|
||||||
|
* @return the list of GSAuthorityURLInfoEncoder
|
||||||
|
*/
|
||||||
|
public List<GSAuthorityURLInfoEncoder> getEncodedAuthorityURLInfoList() {
|
||||||
|
List<GSAuthorityURLInfoEncoder> authorityURLList = null;
|
||||||
|
|
||||||
|
final Element metadataRoot = layerElem.getChild("metadata");
|
||||||
|
if (metadataRoot != null) {
|
||||||
|
final List<Element> metaElements = metadataRoot.getChildren();
|
||||||
|
if (metaElements != null) {
|
||||||
|
for (Element element : metaElements) {
|
||||||
|
String key = element.getAttributeValue("key");
|
||||||
|
if (key.matches("authorityURLs")) {
|
||||||
|
|
||||||
|
String jsonStr = element.getValue();
|
||||||
|
jsonStr = jsonStr.substring(2);
|
||||||
|
jsonStr = jsonStr.substring(0,
|
||||||
|
jsonStr.length() - 3);
|
||||||
|
|
||||||
|
String[] items = jsonStr.split("\\}(,)\\{");
|
||||||
|
authorityURLList = new ArrayList<GSAuthorityURLInfoEncoder>(items.length);
|
||||||
|
for (String item : items) {
|
||||||
|
String[] props = item.split(",");
|
||||||
|
|
||||||
|
String[] kvp1 = props[0].split("\":");
|
||||||
|
String name = kvp1[1].replace("\"", "");
|
||||||
|
String[] kvp2 = props[1].split("\":");
|
||||||
|
String href = kvp2[1].replace("\"", "");
|
||||||
|
|
||||||
|
authorityURLList
|
||||||
|
.add(new GSAuthorityURLInfoEncoder(
|
||||||
|
name, href));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return authorityURLList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of IdentifierInfo from the GeoServer Layer
|
||||||
|
*
|
||||||
|
* @return the list of IdentifierInfoEncoder
|
||||||
|
*/
|
||||||
|
public List<GSIdentifierInfoEncoder> getEncodedIdentifierInfoList() {
|
||||||
|
List<GSIdentifierInfoEncoder> identifierList = null;
|
||||||
|
|
||||||
|
final Element metadataRoot = layerElem.getChild("metadata");
|
||||||
|
if (metadataRoot != null) {
|
||||||
|
final List<Element> metaElements = metadataRoot.getChildren();
|
||||||
|
if (metaElements != null) {
|
||||||
|
for (Element element : metaElements) {
|
||||||
|
String key = element.getAttributeValue("key");
|
||||||
|
if (key.matches("identifiers")) {
|
||||||
|
|
||||||
|
String jsonStr = element.getValue();
|
||||||
|
jsonStr = jsonStr.substring(2);
|
||||||
|
jsonStr = jsonStr.substring(0,
|
||||||
|
jsonStr.length() - 3);
|
||||||
|
|
||||||
|
String[] items = jsonStr.split("\\}(,)\\{");
|
||||||
|
identifierList = new ArrayList<GSIdentifierInfoEncoder>(items.length);
|
||||||
|
for (String item : items) {
|
||||||
|
String[] props = item.split(",");
|
||||||
|
|
||||||
|
String[] kvp1 = props[0].split("\":");
|
||||||
|
String authority = kvp1[1].replace("\"", "");
|
||||||
|
String[] kvp2 = props[1].split("\":");
|
||||||
|
String identifier = kvp2[1].replace("\"", "");
|
||||||
|
|
||||||
|
identifierList
|
||||||
|
.add(new GSIdentifierInfoEncoder(
|
||||||
|
authority, identifier));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return identifierList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -26,6 +26,7 @@
|
|||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,8 +92,50 @@ public class RESTLayerGroup {
|
|||||||
return rootElem.getChildText("name");
|
return rootElem.getChildText("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getWorkspace() {
|
||||||
|
Element rootLayer = rootElem.getChild("workspace");
|
||||||
|
if (rootLayer != null) {
|
||||||
|
return rootLayer.getChildText("name");
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMode() {
|
||||||
|
return rootElem.getChildText("mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return rootElem.getChildText("title");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAbstract() {
|
||||||
|
return rootElem.getChildText("abstractTxt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRootLayer() {
|
||||||
|
Element rootLayer = rootElem.getChild("rootLayer");
|
||||||
|
if (rootLayer != null) {
|
||||||
|
return rootLayer.getChildText("name");
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public RESTLayerList getLayerList() {
|
public RESTLayerList getLayerList() {
|
||||||
|
if (rootElem.getChild("layers") != null) {
|
||||||
return new RESTLayerList(rootElem.getChild("layers"));
|
return new RESTLayerList(rootElem.getChild("layers"));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESTPublishedList getPublishedList() {
|
||||||
|
if (rootElem.getChild("publishables") != null) {
|
||||||
|
return new RESTPublishedList(rootElem.getChild("publishables"));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCRS() {
|
public String getCRS() {
|
||||||
|
|||||||
@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* GeoBatch - Open Source geospatial batch processing system
|
||||||
|
* https://github.com/nfms4redd/nfms-geobatch
|
||||||
|
* Copyright (C) 2007-2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* GPLv3 + Classpath exception
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DamianoG
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RESTMetadataList implements Iterable<RESTMetadataList.RESTMetadataElement> {
|
||||||
|
|
||||||
|
private final List<Element> metadataList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list
|
||||||
|
*/
|
||||||
|
protected RESTMetadataList(Element list) {
|
||||||
|
List<Element> tmpList = new ArrayList<Element>();
|
||||||
|
for(Element el : (List<Element>)list.getChildren("entry")){
|
||||||
|
tmpList.add(el);
|
||||||
|
}
|
||||||
|
metadataList = Collections.unmodifiableList(tmpList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return metadataList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return metadataList.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESTMetadataElement get(int index) {
|
||||||
|
return new RESTMetadataElement(metadataList.get(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Iterable#iterator()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Iterator<RESTMetadataElement> iterator() {
|
||||||
|
return new RESTMetadataIterator(metadataList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class RESTMetadataIterator implements Iterator<RESTMetadataElement>{
|
||||||
|
|
||||||
|
private final Iterator<Element> iter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param iter
|
||||||
|
*/
|
||||||
|
public RESTMetadataIterator(List<Element> orig) {
|
||||||
|
this.iter = orig.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.util.Iterator#hasNext()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return iter.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.util.Iterator#next()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public RESTMetadataElement next() {
|
||||||
|
return new RESTMetadataElement(iter.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.util.Iterator#remove()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void remove() {
|
||||||
|
throw new UnsupportedOperationException("Not supported.");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic metadata Object
|
||||||
|
*
|
||||||
|
* @author DamianoG
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static class RESTMetadataElement {
|
||||||
|
protected final Element metadataElem;
|
||||||
|
|
||||||
|
public RESTMetadataElement(Element elem) {
|
||||||
|
this.metadataElem = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return metadataElem.getAttributeValue("key");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element getMetadataElem() {
|
||||||
|
return metadataElem;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse <TT>namespace</TT>s returned as XML REST objects.
|
||||||
|
*
|
||||||
|
* This is the XML REST representation:
|
||||||
|
* <pre>{@code
|
||||||
|
<namespace>
|
||||||
|
<prefix>topp</prefix>
|
||||||
|
<uri>http://www.openplans.org/topp</uri>
|
||||||
|
<featureTypes>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes.xml" type="application/xml"/>
|
||||||
|
</featureTypes>
|
||||||
|
</namespace>
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
|
* @author Oscar Fonts
|
||||||
|
*/
|
||||||
|
public class RESTNamespace {
|
||||||
|
public final static String NAMESPACE="namespace";
|
||||||
|
public final static String PREFIX="prefix";
|
||||||
|
public final static String URI="uri";
|
||||||
|
public final static String FEATURE_TYPES="featureTypes";
|
||||||
|
|
||||||
|
private final Element namespaceElem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a RESTNamespace from a REST response.
|
||||||
|
*
|
||||||
|
* @param response XML representation of the namespace.
|
||||||
|
* @return a new RESTNamespace, or null if XML could not be parsed.
|
||||||
|
*/
|
||||||
|
public static RESTNamespace build(String response) {
|
||||||
|
if(response == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Element pb = JDOMBuilder.buildElement(response);
|
||||||
|
if(pb != null)
|
||||||
|
return new RESTNamespace(pb);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a RESTNamespace from a XML element.
|
||||||
|
*
|
||||||
|
* @param elem The jdom XML Element describing a namespace.
|
||||||
|
*/
|
||||||
|
public RESTNamespace(Element elem) {
|
||||||
|
this.namespaceElem = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the namespace prefix
|
||||||
|
*
|
||||||
|
* @return the namespace prefix.
|
||||||
|
*/
|
||||||
|
public String getPrefix() {
|
||||||
|
return namespaceElem.getChildText(PREFIX);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the namespace URI.
|
||||||
|
*
|
||||||
|
* @return the namespace uri.
|
||||||
|
*/
|
||||||
|
public URI getURI() {
|
||||||
|
return java.net.URI.create(namespaceElem.getChildText(URI));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -26,6 +26,7 @@
|
|||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|||||||
59
src/main/java/it/geosolutions/geoserver/rest/decoder/RESTPublished.java
Executable file
59
src/main/java/it/geosolutions/geoserver/rest/decoder/RESTPublished.java
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a <TT>published</TT> returned as XML REST objects.
|
||||||
|
*
|
||||||
|
* This is the XML REST representation:
|
||||||
|
* <pre>{@code
|
||||||
|
<published type="layer">
|
||||||
|
<name>sfdem</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/layers/sfdem.xml" type="application/xml"/>
|
||||||
|
</published>
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
|
* @author Davide Savazzi (geo-solutions.it)
|
||||||
|
*/
|
||||||
|
public class RESTPublished extends NameLinkElem {
|
||||||
|
|
||||||
|
private final String type;
|
||||||
|
|
||||||
|
public RESTPublished(Element elem) {
|
||||||
|
super(elem);
|
||||||
|
|
||||||
|
type = elem.getAttributeValue("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
66
src/main/java/it/geosolutions/geoserver/rest/decoder/RESTPublishedList.java
Executable file
66
src/main/java/it/geosolutions/geoserver/rest/decoder/RESTPublishedList.java
Executable file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse <TT>published</TT>s returned as XML REST objects.
|
||||||
|
*
|
||||||
|
* This is the XML REST representation:
|
||||||
|
* <pre>{@code
|
||||||
|
<publishables>
|
||||||
|
<published type="layer">
|
||||||
|
<name>sfdem</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/layers/sfdem.xml" type="application/xml"/>
|
||||||
|
</published>
|
||||||
|
<published type="layer">
|
||||||
|
<name>bugsites</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/layers/bugsites.xml" type="application/xml"/>
|
||||||
|
</published>
|
||||||
|
</publishables>
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
|
* @author Davide Savazzi (geo-solutions.it)
|
||||||
|
*/
|
||||||
|
public class RESTPublishedList extends RESTAbstractList<RESTPublished> {
|
||||||
|
|
||||||
|
public static RESTPublishedList build(String response) {
|
||||||
|
Element elem = JDOMBuilder.buildElement(response);
|
||||||
|
return elem == null ? null : new RESTPublishedList(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RESTPublishedList(Element list) {
|
||||||
|
super(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RESTPublished createElement(Element el) {
|
||||||
|
return new RESTPublished(el);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
* Copyright (C) 2007,2014 GeoSolutions S.A.S.
|
||||||
* http://www.geo-solutions.it
|
* http://www.geo-solutions.it
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -26,13 +26,26 @@
|
|||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.metadatalink.ResourceMetadataLinkInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.Namespace;
|
import org.jdom.Namespace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a resource (FeatureType or Coverage) returned as XML REST objects.
|
* Parse a resource (FeatureType or Coverage) returned as XML REST objects.
|
||||||
*
|
*
|
||||||
* @author etj
|
* @author Emanuele Tajariol <etj at geo-solutions.it>
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org
|
||||||
|
* @author Henry Rotzoll
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class RESTResource {
|
public class RESTResource {
|
||||||
protected final Element rootElem;
|
protected final Element rootElem;
|
||||||
@ -62,6 +75,22 @@ public class RESTResource {
|
|||||||
return rootElem.getChildText("abstract");
|
return rootElem.getChildText("abstract");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getKeywords() {
|
||||||
|
List<String> kwdsList = null;
|
||||||
|
|
||||||
|
final Element keywordsRoot = rootElem.getChild("keywords");
|
||||||
|
if (keywordsRoot != null) {
|
||||||
|
final List<Element> keywords = keywordsRoot.getChildren();
|
||||||
|
if (keywords != null) {
|
||||||
|
kwdsList = new ArrayList<String>(keywords.size());
|
||||||
|
for (Element keyword : keywords) {
|
||||||
|
kwdsList.add(keyword.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return kwdsList;
|
||||||
|
}
|
||||||
|
|
||||||
public String getNameSpace() {
|
public String getNameSpace() {
|
||||||
return rootElem.getChild("namespace").getChildText("name");
|
return rootElem.getChild("namespace").getChildText("name");
|
||||||
}
|
}
|
||||||
@ -76,30 +105,143 @@ public class RESTResource {
|
|||||||
|
|
||||||
public String getStoreUrl() {
|
public String getStoreUrl() {
|
||||||
Element store = rootElem.getChild("store");
|
Element store = rootElem.getChild("store");
|
||||||
Element atom = store.getChild("link", Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));
|
Element atom = store.getChild("link",
|
||||||
|
Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));
|
||||||
return atom.getAttributeValue("href");
|
return atom.getAttributeValue("href");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCRS() {
|
public String getNativeCRS() {
|
||||||
Element elBBox = rootElem.getChild("latLonBoundingBox");
|
return rootElem.getChildText("nativeCRS");
|
||||||
return elBBox.getChildText("crs");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected double getLatLonEdge(String edge) {
|
public RESTBoundingBox getNativeBoundingBox() {
|
||||||
Element elBBox = rootElem.getChild("latLonBoundingBox");
|
RESTBoundingBox bbox = null;
|
||||||
return Double.parseDouble(elBBox.getChildText(edge));
|
Element bboxElement = rootElem.getChild("nativeBoundingBox");
|
||||||
|
if (bboxElement != null) {
|
||||||
|
bbox = new RESTBoundingBox(bboxElement);
|
||||||
|
}
|
||||||
|
return bbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESTBoundingBox getLatLonBoundingBox() {
|
||||||
|
RESTBoundingBox bbox = null;
|
||||||
|
Element bboxElement = rootElem.getChild("latLonBoundingBox");
|
||||||
|
if (bboxElement != null) {
|
||||||
|
bbox = new RESTBoundingBox(bboxElement);
|
||||||
|
}
|
||||||
|
return bbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCRS() {
|
||||||
|
RESTBoundingBox bbox = this.getLatLonBoundingBox();
|
||||||
|
return bbox.getCRS();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMinX() {
|
public double getMinX() {
|
||||||
return getLatLonEdge("minx");
|
return this.getLatLonBoundingBox().getMinX();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMaxX() {
|
public double getMaxX() {
|
||||||
return getLatLonEdge("maxx");
|
return this.getLatLonBoundingBox().getMaxX();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMinY() {
|
public double getMinY() {
|
||||||
return getLatLonEdge("miny");
|
return this.getLatLonBoundingBox().getMinY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMaxY() {
|
public double getMaxY() {
|
||||||
return getLatLonEdge("maxy");
|
return this.getLatLonBoundingBox().getMaxY();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use {@link RESTFeatureType#getAttributeList()}
|
||||||
|
* @return
|
||||||
|
* @throws UnsupportedOperationException
|
||||||
|
*/
|
||||||
|
public List<Map<FeatureTypeAttribute, String>> getAttributeList() {
|
||||||
|
throw new UnsupportedOperationException("This method is specific for RESTFeatureType");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use {@link RESTFeatureType#getEncodedAttributeList()}
|
||||||
|
* @return
|
||||||
|
* @throws UnsupportedOperationException
|
||||||
|
*/
|
||||||
|
public List<GSAttributeEncoder> getEncodedAttributeList() {
|
||||||
|
throw new UnsupportedOperationException("This method is specific for RESTFeatureType");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of MetadataLinkInfo from the GeoServer Resource
|
||||||
|
*
|
||||||
|
* @since gs-2.4.x
|
||||||
|
*
|
||||||
|
* @return the list of GSMetadataLinkEncoder
|
||||||
|
*/
|
||||||
|
public List<GSMetadataLinkInfoEncoder> getEncodedMetadataLinkInfoList() {
|
||||||
|
List<GSMetadataLinkInfoEncoder> metaLinksList = null;
|
||||||
|
|
||||||
|
final Element metaLinksRoot = rootElem.getChild("metadataLinks");
|
||||||
|
if (metaLinksRoot != null) {
|
||||||
|
final List<Element> metaLinks = metaLinksRoot.getChildren();
|
||||||
|
if (metaLinks != null) {
|
||||||
|
metaLinksList = new ArrayList<GSMetadataLinkInfoEncoder>(metaLinks.size());
|
||||||
|
for (Element metaLink : metaLinks) {
|
||||||
|
final GSMetadataLinkInfoEncoder metaLinkEnc = new GSMetadataLinkInfoEncoder();
|
||||||
|
metaLinkEnc
|
||||||
|
.setType(metaLink.getChildText(ResourceMetadataLinkInfo.type.name()));
|
||||||
|
metaLinkEnc.setMetadataType(metaLink
|
||||||
|
.getChildText(ResourceMetadataLinkInfo.metadataType.name()));
|
||||||
|
metaLinkEnc.setContent(metaLink.getChildText(ResourceMetadataLinkInfo.content
|
||||||
|
.name()));
|
||||||
|
metaLinksList.add(metaLinkEnc);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return metaLinksList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of GSCoverageDimensionEncoder from the GeoServer Resource
|
||||||
|
*
|
||||||
|
* @since gs-2.4.x
|
||||||
|
*
|
||||||
|
* @return the list of GSCoverageDimensionEncoder
|
||||||
|
*/
|
||||||
|
public List<GSCoverageDimensionEncoder> getEncodedDimensionsInfoList() {
|
||||||
|
List<GSCoverageDimensionEncoder> dimensionList = null;
|
||||||
|
final Element dimensionsRoot = rootElem.getChild("dimensions");
|
||||||
|
|
||||||
|
if (dimensionsRoot != null) {
|
||||||
|
final List<Element> dimensions = dimensionsRoot.getChildren();
|
||||||
|
if (dimensions != null) {
|
||||||
|
dimensionList = new ArrayList<GSCoverageDimensionEncoder>(dimensions.size());
|
||||||
|
for (Element coverageDimension : dimensions) {
|
||||||
|
final String name = coverageDimension.getChildText("name");
|
||||||
|
final String description = coverageDimension.getChildText("description");
|
||||||
|
String rangeMin = null;
|
||||||
|
String rangeMax = null;
|
||||||
|
final Element rangeElement = coverageDimension.getChild("range");
|
||||||
|
if (rangeElement != null) {
|
||||||
|
rangeMin = rangeElement.getChildText("min");
|
||||||
|
rangeMax = rangeElement.getChildText("max");
|
||||||
|
}
|
||||||
|
final String unit = coverageDimension.getChildText("unit");
|
||||||
|
String dimensionTypeName = null;
|
||||||
|
final Element dimensionTypeElement = coverageDimension
|
||||||
|
.getChild("dimensionType");
|
||||||
|
if (dimensionTypeElement != null) {
|
||||||
|
dimensionTypeName = dimensionTypeElement.getChildText("name");
|
||||||
|
}
|
||||||
|
final GSCoverageDimensionEncoder coverageDimensionEncoder = new GSCoverageDimensionEncoder(
|
||||||
|
name, description, rangeMin, rangeMax, unit, dimensionTypeName);
|
||||||
|
dimensionList.add(coverageDimensionEncoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dimensionList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,268 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.Namespace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This decode turns index format for a GeoServer StructuredGridCoverageReader into something
|
||||||
|
* useful, giving access to the definition of the single attributes.
|
||||||
|
*
|
||||||
|
* <P>This is the XML REST representation:
|
||||||
|
* <PRE>
|
||||||
|
{@code
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<wfs:FeatureCollection xmlns:gf="http://www.geoserver.org/rest/granules" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml">
|
||||||
|
<gml:boundedBy>
|
||||||
|
<gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
|
||||||
|
<gml:coord>
|
||||||
|
<gml:X>5.0</gml:X>
|
||||||
|
<gml:Y>45.0</gml:Y>
|
||||||
|
</gml:coord>
|
||||||
|
<gml:coord>
|
||||||
|
<gml:X>14.875</gml:X>
|
||||||
|
<gml:Y>50.9375</gml:Y>
|
||||||
|
</gml:coord>
|
||||||
|
</gml:Box>
|
||||||
|
</gml:boundedBy>
|
||||||
|
<gml:featureMember>
|
||||||
|
<gf:V fid="V.337">
|
||||||
|
<gf:the_geom>
|
||||||
|
<gml:Polygon>
|
||||||
|
<gml:outerBoundaryIs>
|
||||||
|
<gml:LinearRing>
|
||||||
|
<gml:coordinates>5.0,45.0 5.0,50.9375 14.875,50.9375 14.875,45.0 5.0,45.0</gml:coordinates>
|
||||||
|
</gml:LinearRing>
|
||||||
|
</gml:outerBoundaryIs>
|
||||||
|
</gml:Polygon>
|
||||||
|
</gf:the_geom>
|
||||||
|
<gf:location>..\\polyphemus\\polyphemus_20130302.nc</gf:location>
|
||||||
|
<gf:imageindex>672</gf:imageindex>
|
||||||
|
<gf:time>2013-03-01T23:00:00Z</gf:time>
|
||||||
|
<gf:elevation>10.0</gf:elevation>
|
||||||
|
<gf:fileDate>2013-03-01T23:00:00Z</gf:fileDate>
|
||||||
|
<gf:updated>2013-04-08T05:40:29.061Z</gf:updated>
|
||||||
|
</gf:V>
|
||||||
|
</gml:featureMember>
|
||||||
|
</wfs:FeatureCollection>
|
||||||
|
|
||||||
|
}</PRE>
|
||||||
|
* @author Simone Giannecchini, GeoSolutions SAS
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RESTStructuredCoverageGranulesList implements Iterable<RESTStructuredCoverageGranulesList.RESTStructuredCoverageGranule> {
|
||||||
|
|
||||||
|
/** GML_NAMESPACE */
|
||||||
|
private static final Namespace GML_NAMESPACE = Namespace.getNamespace("gml", "http://www.opengis.net/gml");
|
||||||
|
|
||||||
|
private final List<RESTStructuredCoverageGranule> granulesList;
|
||||||
|
|
||||||
|
private final Element bbox;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the bbox
|
||||||
|
*/
|
||||||
|
public Element getBbox() {
|
||||||
|
return bbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected RESTStructuredCoverageGranulesList(Element featureCollection) {
|
||||||
|
|
||||||
|
// check ordering of elements
|
||||||
|
if(!featureCollection.getName().equals("FeatureCollection")){
|
||||||
|
throw new IllegalStateException("Root element should be wfs:FeatureCollection");
|
||||||
|
}
|
||||||
|
Element boundedBy = featureCollection.getChild("boundedBy",GML_NAMESPACE);
|
||||||
|
if(boundedBy==null){
|
||||||
|
throw new IllegalStateException("Unable to find boundedBy element");
|
||||||
|
}
|
||||||
|
// save bbox
|
||||||
|
bbox=boundedBy.getChild("Box",GML_NAMESPACE);
|
||||||
|
|
||||||
|
// now get the feature members
|
||||||
|
List<RESTStructuredCoverageGranule> tmpList = new ArrayList<RESTStructuredCoverageGranule>();
|
||||||
|
for(Element el : (List<Element>)featureCollection.getChildren("featureMember",GML_NAMESPACE)){
|
||||||
|
tmpList.add(new RESTStructuredCoverageGranule(el));
|
||||||
|
}
|
||||||
|
granulesList = Collections.unmodifiableList(tmpList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RESTStructuredCoverageGranulesList build(String response) {
|
||||||
|
if(response == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Element pb = JDOMBuilder.buildElement(response);
|
||||||
|
if(pb != null){
|
||||||
|
return new RESTStructuredCoverageGranulesList(pb);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return granulesList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return granulesList.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESTStructuredCoverageGranule get(int index) {
|
||||||
|
return granulesList.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Iterable#iterator()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Iterator<RESTStructuredCoverageGranule> iterator() {
|
||||||
|
return granulesList.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic granule of the index.
|
||||||
|
*
|
||||||
|
* <P>This is the XML REST representation:
|
||||||
|
* <PRE>
|
||||||
|
{@code
|
||||||
|
<gml:featureMember>
|
||||||
|
<gf:V fid="V.1">
|
||||||
|
<gf:the_geom>
|
||||||
|
<gml:Polygon>
|
||||||
|
<gml:outerBoundaryIs>
|
||||||
|
<gml:LinearRing>
|
||||||
|
<gml:coordinates>5.0,45.0 5.0,50.9375 14.875,50.9375 14.875,45.0 5.0,45.0</gml:coordinates>
|
||||||
|
</gml:LinearRing>
|
||||||
|
</gml:outerBoundaryIs>
|
||||||
|
</gml:Polygon>
|
||||||
|
</gf:the_geom>
|
||||||
|
<gf:location>polyphemus_20130301.nc</gf:location>
|
||||||
|
<gf:imageindex>672</gf:imageindex>
|
||||||
|
<gf:time>2013-02-28T23:00:00Z</gf:time>
|
||||||
|
<gf:elevation>10.0</gf:elevation>
|
||||||
|
<gf:fileDate>2013-02-28T23:00:00Z</gf:fileDate>
|
||||||
|
<gf:updated>2013-04-08T06:18:41.597Z</gf:updated>
|
||||||
|
</gf:V>
|
||||||
|
</gml:featureMember>
|
||||||
|
|
||||||
|
* @author Simone Giannecchini, GeoSolutions SAS
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static class RESTStructuredCoverageGranule {
|
||||||
|
|
||||||
|
protected final Element granule;
|
||||||
|
|
||||||
|
private final String fid;
|
||||||
|
|
||||||
|
private final List<Element> children;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public RESTStructuredCoverageGranule(Element elem) {
|
||||||
|
if(!elem.getName().equals("featureMember")){
|
||||||
|
throw new IllegalStateException("Root element should be gml:featureMember for a granule");
|
||||||
|
}
|
||||||
|
Element feature = (Element) elem.getChildren().get(0);
|
||||||
|
if(feature==null){
|
||||||
|
throw new IllegalStateException("Unable to find feature element for this granule");
|
||||||
|
}
|
||||||
|
this.granule = feature;
|
||||||
|
this.fid=granule.getAttribute("fid").getValue();
|
||||||
|
this.children=granule.getChildren();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAttributeByName(String name) {
|
||||||
|
return granule.getChildTextTrim(name,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAttributeByIndex(int index) {
|
||||||
|
return children.get(index).getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Iterator<Element> getAttributesIterator() {
|
||||||
|
return granule.getChildren().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the fid
|
||||||
|
*/
|
||||||
|
public String getFid() {
|
||||||
|
return fid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(this.getClass().getSimpleName()).append('[');
|
||||||
|
|
||||||
|
for (Element c : (List<Element>)granule.getChildren()) {
|
||||||
|
String text = c.getText();
|
||||||
|
if(text!= null) {
|
||||||
|
text = text.replace("\n", "");
|
||||||
|
text = text.trim();
|
||||||
|
}
|
||||||
|
sb.append('(').append(c.getName()).append("=").append(text).append(')');
|
||||||
|
}
|
||||||
|
sb.append(']');
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("RESTStructuredCoverageGranulesList [");
|
||||||
|
if (bbox != null) {
|
||||||
|
builder.append("bbox=");
|
||||||
|
builder.append(bbox);
|
||||||
|
}
|
||||||
|
if (granulesList != null) {
|
||||||
|
builder.append("granulesList={");
|
||||||
|
for(RESTStructuredCoverageGranule granule:granulesList){
|
||||||
|
builder.append(granule);
|
||||||
|
}
|
||||||
|
builder.append("}, ");
|
||||||
|
}
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,212 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This decode turns index format for a GeoServer StructuredGridCoverageReader into something
|
||||||
|
* useful, giving access to the definition of the single attributes.
|
||||||
|
*
|
||||||
|
* <P>This is the XML REST representation:
|
||||||
|
* <PRE>
|
||||||
|
{@code
|
||||||
|
|
||||||
|
<Schema>
|
||||||
|
<attributes>
|
||||||
|
<Attribute>
|
||||||
|
<name>the_geom</name>
|
||||||
|
<minOccurs>0</minOccurs>
|
||||||
|
<maxOccurs>1</maxOccurs>
|
||||||
|
<nillable>true</nillable>
|
||||||
|
<binding>com.vividsolutions.jts.geom.Polygon</binding>
|
||||||
|
</Attribute>
|
||||||
|
<Attribute>
|
||||||
|
<name>location</name>
|
||||||
|
<minOccurs>0</minOccurs>
|
||||||
|
<maxOccurs>1</maxOccurs>
|
||||||
|
<nillable>true</nillable>
|
||||||
|
<binding>java.lang.String</binding>
|
||||||
|
</Attribute>
|
||||||
|
<Attribute>
|
||||||
|
<name>imageindex</name>
|
||||||
|
<minOccurs>0</minOccurs>
|
||||||
|
<maxOccurs>1</maxOccurs>
|
||||||
|
<nillable>true</nillable>
|
||||||
|
<binding>java.lang.Integer</binding>
|
||||||
|
</Attribute>
|
||||||
|
<Attribute>
|
||||||
|
<name>time</name>
|
||||||
|
<minOccurs>0</minOccurs>
|
||||||
|
<maxOccurs>1</maxOccurs>
|
||||||
|
<nillable>true</nillable>
|
||||||
|
<binding>java.sql.Timestamp</binding>
|
||||||
|
</Attribute>
|
||||||
|
<Attribute>
|
||||||
|
<name>elevation</name>
|
||||||
|
<minOccurs>0</minOccurs>
|
||||||
|
<maxOccurs>1</maxOccurs>
|
||||||
|
<nillable>true</nillable>
|
||||||
|
<binding>java.lang.Double</binding>
|
||||||
|
</Attribute>
|
||||||
|
<Attribute>
|
||||||
|
<name>fileDate</name>
|
||||||
|
<minOccurs>0</minOccurs>
|
||||||
|
<maxOccurs>1</maxOccurs>
|
||||||
|
<nillable>true</nillable>
|
||||||
|
<binding>java.sql.Timestamp</binding>
|
||||||
|
</Attribute>
|
||||||
|
<Attribute>
|
||||||
|
<name>updated</name>
|
||||||
|
<minOccurs>0</minOccurs>
|
||||||
|
<maxOccurs>1</maxOccurs>
|
||||||
|
<nillable>true</nillable>
|
||||||
|
<binding>java.sql.Timestamp</binding>
|
||||||
|
</Attribute>
|
||||||
|
</attributes>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/it.geosolutions/coveragestores/polyphemus/coverages/V/index/granules.xml" type="application/xml"/>
|
||||||
|
</Schema>
|
||||||
|
}</PRE>
|
||||||
|
* @author Simone Giannecchini, GeoSolutions SAS
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RESTStructuredCoverageIndexSchema implements Iterable<RESTStructuredCoverageIndexSchema.RESTStructuredCoverageIndexAttribute> {
|
||||||
|
|
||||||
|
private final List<RESTStructuredCoverageIndexAttribute> attributeList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected RESTStructuredCoverageIndexSchema(Element schema) {
|
||||||
|
|
||||||
|
// check ordering of elements
|
||||||
|
if(!schema.getName().equals("Schema")){
|
||||||
|
throw new IllegalStateException("Root element should be Schema");
|
||||||
|
}
|
||||||
|
Element attributes = schema.getChild("attributes");
|
||||||
|
if(attributes==null){
|
||||||
|
throw new IllegalStateException("Root element should be Schema");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<RESTStructuredCoverageIndexAttribute> tmpList = new ArrayList<RESTStructuredCoverageIndexAttribute>();
|
||||||
|
for(Element el : (List<Element>)attributes.getChildren()){
|
||||||
|
tmpList.add(new RESTStructuredCoverageIndexAttribute(el));
|
||||||
|
}
|
||||||
|
attributeList = Collections.unmodifiableList(tmpList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RESTStructuredCoverageIndexSchema build(String response) {
|
||||||
|
if(response == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Element pb = JDOMBuilder.buildElement(response);
|
||||||
|
if(pb != null){
|
||||||
|
return new RESTStructuredCoverageIndexSchema(pb);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return attributeList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return attributeList.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESTStructuredCoverageIndexAttribute get(int index) {
|
||||||
|
return attributeList.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Iterable#iterator()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Iterator<RESTStructuredCoverageIndexAttribute> iterator() {
|
||||||
|
return attributeList.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic granule of the index.
|
||||||
|
*
|
||||||
|
* <P>This is the XML REST representation:
|
||||||
|
* <PRE>
|
||||||
|
{@code
|
||||||
|
<Attribute>
|
||||||
|
<name>the_geom</name>
|
||||||
|
<minOccurs>0</minOccurs>
|
||||||
|
<maxOccurs>1</maxOccurs>
|
||||||
|
<nillable>true</nillable>
|
||||||
|
<binding>com.vividsolutions.jts.geom.Polygon</binding>
|
||||||
|
</Attribute>
|
||||||
|
* @author Simone Giannecchini, GeoSolutions SAS
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static class RESTStructuredCoverageIndexAttribute {
|
||||||
|
protected final Element attribute;
|
||||||
|
|
||||||
|
public RESTStructuredCoverageIndexAttribute(Element elem) {
|
||||||
|
this.attribute = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return attribute.getChildTextTrim("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMinOccurs() {
|
||||||
|
return attribute.getChildTextTrim("minOccurs");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaxOccurs() {
|
||||||
|
return attribute.getChildTextTrim("maxOccurs");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNillable() {
|
||||||
|
return attribute.getChildTextTrim("nillable");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBinding() {
|
||||||
|
return attribute.getChildTextTrim("binding");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RESTStructuredCoverageGranule [getName()=" + getName()
|
||||||
|
+ ", getMinOccurs()=" + getMinOccurs() + ", getMaxOccurs()=" + getMaxOccurs()
|
||||||
|
+ ", getNillable()=" + getNillable() + ", getBinding()=" + getBinding() + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2013 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author ETj (etj at geo-solutions.it)
|
||||||
|
*/
|
||||||
|
public class RESTStyle {
|
||||||
|
|
||||||
|
private final Element elem;
|
||||||
|
|
||||||
|
public static RESTStyle build(String xml) {
|
||||||
|
if (xml == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Element e = JDOMBuilder.buildElement(xml);
|
||||||
|
if (e != null) {
|
||||||
|
return new RESTStyle(e);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RESTStyle(Element elem) {
|
||||||
|
this.elem = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return elem.getChildText("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return elem.getChildText("filename");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWorkspace() {
|
||||||
|
if(elem.getChild("workspace") != null)
|
||||||
|
return elem.getChild("workspace").getChildText("name");
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,306 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse <TT>WMS</TT>s returned as XML REST objects.
|
||||||
|
*
|
||||||
|
* <P>This is the XML REST representation:
|
||||||
|
* <PRE>
|
||||||
|
*{@code
|
||||||
|
<wmsLayer>
|
||||||
|
<name>comunilazio</name>
|
||||||
|
<nativeName>lait:comunilazio</nativeName>
|
||||||
|
<namespace>
|
||||||
|
<name>arit</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://172.27.30.25:8080/geoserver/rest/namespaces/arit.xml" type="application/xml"/>
|
||||||
|
</namespace>
|
||||||
|
<title>comunilazio</title>
|
||||||
|
<description/>
|
||||||
|
<keywords>
|
||||||
|
<string>features</string>
|
||||||
|
<string>comunilazio</string>
|
||||||
|
</keywords>
|
||||||
|
<nativeCRS>
|
||||||
|
GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4326"]]
|
||||||
|
</nativeCRS>
|
||||||
|
<srs>EPSG:4326</srs>
|
||||||
|
<nativeBoundingBox>
|
||||||
|
<minx>11.4482128</minx>
|
||||||
|
<maxx>14.0288013</maxx>
|
||||||
|
<miny>40.7848334</miny>
|
||||||
|
<maxy>42.8396541</maxy>
|
||||||
|
<crs>EPSG:4326</crs>
|
||||||
|
</nativeBoundingBox>
|
||||||
|
<latLonBoundingBox>
|
||||||
|
<minx>11.4482128</minx>
|
||||||
|
<maxx>14.0288013</maxx>
|
||||||
|
<miny>40.7848334</miny>
|
||||||
|
<maxy>42.8396541</maxy>
|
||||||
|
<crs>
|
||||||
|
GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]
|
||||||
|
</crs>
|
||||||
|
</latLonBoundingBox>
|
||||||
|
<projectionPolicy>FORCE_DECLARED</projectionPolicy>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
<metadata>
|
||||||
|
<entry key="cachingEnabled">false</entry>
|
||||||
|
</metadata>
|
||||||
|
<store class="wmsStore">
|
||||||
|
<name>regione</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://172.27.30.25:8080/geoserver/rest/workspaces/arit/wmsstores/regione.xml" type="application/xml"/>
|
||||||
|
</store>
|
||||||
|
</wmsLayer>
|
||||||
|
* }</PRE>
|
||||||
|
*
|
||||||
|
* @author cip
|
||||||
|
*/
|
||||||
|
public class RESTWms extends RESTResource {
|
||||||
|
|
||||||
|
|
||||||
|
public static RESTWms build(String response) {
|
||||||
|
Element elem = JDOMBuilder.buildElement(response);
|
||||||
|
return elem == null? null : new RESTWms(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESTWms(Element resource) {
|
||||||
|
super(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESTWms(RESTResource resource) {
|
||||||
|
super(resource.rootElem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// public String getName() {
|
||||||
|
// return rootElem.getChildText("name");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public String getNativeName() {
|
||||||
|
// return rootElem.getChildText("nativeName");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// public String getNameSpace() {
|
||||||
|
// return rootElem.getChild("namespace").getChildText("name");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public String getTitle() {
|
||||||
|
// return rootElem.getChildText("title");
|
||||||
|
// }
|
||||||
|
|
||||||
|
public String getNativeCRS() {
|
||||||
|
return rootElem.getChildText("nativeCRS");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSRS() {
|
||||||
|
return rootElem.getChildText("srs");
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESTMetadataList getMetadataList() {
|
||||||
|
return new RESTMetadataList(rootElem.getChild("metadata"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RESTDimensionInfo> getDimensionInfo() {
|
||||||
|
List<RESTDimensionInfo> listDim = new ArrayList<RESTDimensionInfo>();
|
||||||
|
for (RESTMetadataList.RESTMetadataElement el : getMetadataList()){
|
||||||
|
if(el.getKey().equals(RESTDimensionInfo.TIME) || el.getKey().equals(RESTDimensionInfo.ELEVATION)){
|
||||||
|
listDim.add(new RESTDimensionInfo(el.getMetadataElem()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return listDim;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the list of parameters for this wms.
|
||||||
|
*
|
||||||
|
* @return a {@link Map} where the key is the name for the parameter and the value is the value for the parameter.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, String> getParametersList() {
|
||||||
|
Map<String, String> paramsList = new HashMap<String, String>();
|
||||||
|
|
||||||
|
final Element paramsRoot = rootElem.getChild("parameters");
|
||||||
|
if (paramsRoot != null) {
|
||||||
|
final List<Element> params = paramsRoot.getChildren();
|
||||||
|
if (params != null) {
|
||||||
|
for (Element param : params) {
|
||||||
|
final List<Element> values = param.getChildren();
|
||||||
|
assert values.size()==2;
|
||||||
|
paramsList.put(values.get(0).getValue(), values.get(1).getValue()); // save key and value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return paramsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("RESTWms [");
|
||||||
|
if (getNativeCRS() != null) {
|
||||||
|
builder.append("getNativeCRS()=");
|
||||||
|
builder.append(getNativeCRS());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getSRS() != null) {
|
||||||
|
builder.append("getSRS()=");
|
||||||
|
builder.append(getSRS());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getMetadataList() != null) {
|
||||||
|
builder.append("getMetadataList()=");
|
||||||
|
builder.append(getMetadataList());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getDimensionInfo() != null) {
|
||||||
|
builder.append("getDimensionInfo()=");
|
||||||
|
builder.append(getDimensionInfo());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getParametersList() != null) {
|
||||||
|
builder.append("getParametersList()=");
|
||||||
|
builder.append(getParametersList());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getName() != null) {
|
||||||
|
builder.append("getName()=");
|
||||||
|
builder.append(getName());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getTitle() != null) {
|
||||||
|
builder.append("getTitle()=");
|
||||||
|
builder.append(getTitle());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getNativeName() != null) {
|
||||||
|
builder.append("getNativeName()=");
|
||||||
|
builder.append(getNativeName());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getAbstract() != null) {
|
||||||
|
builder.append("getAbstract()=");
|
||||||
|
builder.append(getAbstract());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getNameSpace() != null) {
|
||||||
|
builder.append("getNameSpace()=");
|
||||||
|
builder.append(getNameSpace());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getStoreName() != null) {
|
||||||
|
builder.append("getStoreName()=");
|
||||||
|
builder.append(getStoreName());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getStoreType() != null) {
|
||||||
|
builder.append("getStoreType()=");
|
||||||
|
builder.append(getStoreType());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getStoreUrl() != null) {
|
||||||
|
builder.append("getStoreUrl()=");
|
||||||
|
builder.append(getStoreUrl());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getCRS() != null) {
|
||||||
|
builder.append("getCRS()=");
|
||||||
|
builder.append(getCRS());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
builder.append("getMinX()=");
|
||||||
|
builder.append(getMinX());
|
||||||
|
builder.append(", getMaxX()=");
|
||||||
|
builder.append(getMaxX());
|
||||||
|
builder.append(", getMinY()=");
|
||||||
|
builder.append(getMinY());
|
||||||
|
builder.append(", getMaxY()=");
|
||||||
|
builder.append(getMaxY());
|
||||||
|
builder.append(", ");
|
||||||
|
if (getAttributeList() != null) {
|
||||||
|
builder.append("getAttributeList()=");
|
||||||
|
builder.append(getAttributeList());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getEncodedAttributeList() != null) {
|
||||||
|
builder.append("getEncodedAttributeList()=");
|
||||||
|
builder.append(getEncodedAttributeList());
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
if (getEncodedMetadataLinkInfoList() != null) {
|
||||||
|
builder.append("getEncodedMetadataLinkInfoList()=");
|
||||||
|
builder.append(getEncodedMetadataLinkInfoList());
|
||||||
|
}
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public String getStoreName() {
|
||||||
|
// return rootElem.getChild("store").getChildText("name");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public String getStoreType() {
|
||||||
|
// return rootElem.getChild("store").getAttributeValue("class");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// public String getStoreUrl() {
|
||||||
|
// Element store = rootElem.getChild("store");
|
||||||
|
// Element atom = store.getChild("link", Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));
|
||||||
|
// return atom.getAttributeValue("href");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public String getBBCRS() {
|
||||||
|
// Element elBBox = rootElem.getChild("latLonBoundingBox");
|
||||||
|
// return elBBox.getChildText("crs");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// protected double getLatLonEdge(String edge) {
|
||||||
|
// Element elBBox = rootElem.getChild("latLonBoundingBox");
|
||||||
|
// return Double.parseDouble(elBBox.getChildText(edge));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public double getMinX() {
|
||||||
|
// return getLatLonEdge("minx");
|
||||||
|
// }
|
||||||
|
// public double getMaxX() {
|
||||||
|
// return getLatLonEdge("maxx");
|
||||||
|
// }
|
||||||
|
// public double getMinY() {
|
||||||
|
// return getLatLonEdge("miny");
|
||||||
|
// }
|
||||||
|
// public double getMaxY() {
|
||||||
|
// return getLatLonEdge("maxy");
|
||||||
|
// }
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses list of summary data about Wms.
|
||||||
|
*
|
||||||
|
* <P>This is the XML REST representation:
|
||||||
|
* <PRE>{@code <wmsLayers>
|
||||||
|
<wmsLayer>
|
||||||
|
<name>comunilazio</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://172.27.30.25:8080/geoserver/rest/workspaces/arit/wmsstores/regione/wmslayers/comunilazio.xml" type="application/xml"/>
|
||||||
|
</wmsLayer>
|
||||||
|
</wmsLayers>
|
||||||
|
*
|
||||||
|
}</PRE>
|
||||||
|
*
|
||||||
|
* @author cip
|
||||||
|
*/
|
||||||
|
public class RESTWmsList extends RESTAbstractList<NameLinkElem> {
|
||||||
|
|
||||||
|
public static RESTWmsList build(String response) {
|
||||||
|
Element elem = JDOMBuilder.buildElement(response);
|
||||||
|
return elem == null? null : new RESTWmsList(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RESTWmsList(Element list) {
|
||||||
|
super(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse <TT>WmsStore</TT>s returned as XML REST objects.
|
||||||
|
* <P>
|
||||||
|
* This is the XML document returned by GeoServer when requesting a WmsStore:
|
||||||
|
* <PRE>
|
||||||
|
* {@code
|
||||||
|
<wmsStore>
|
||||||
|
<name>regione</name>
|
||||||
|
<type>WMS</type>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
<workspace>
|
||||||
|
<name>arit</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://172.27.30.25:8080/geoserver/rest/workspaces/arit.xml" type="application/xml"/>
|
||||||
|
</workspace>
|
||||||
|
<metadata>
|
||||||
|
<entry key="useConnectionPooling">true</entry>
|
||||||
|
</metadata>
|
||||||
|
<__default>false</__default>
|
||||||
|
<capabilitiesURL>http://www.regione.lazio.it/geoserver/wms</capabilitiesURL>
|
||||||
|
<user>admin</user>
|
||||||
|
<password>geoserver</password>
|
||||||
|
<maxConnections>6</maxConnections>
|
||||||
|
<readTimeout>60</readTimeout>
|
||||||
|
<connectTimeout>30</connectTimeout>
|
||||||
|
<wmsLayers>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://172.27.30.25:8080/geoserver/rest/workspaces/arit/wmsstores/regione/wmslayers.xml" type="application/xml"/>
|
||||||
|
</wmsLayers>
|
||||||
|
</wmsStore>
|
||||||
|
* }
|
||||||
|
* </PRE>
|
||||||
|
*
|
||||||
|
* <I>Note: the whole XML fragment is stored in memory. At the moment, there are
|
||||||
|
* methods to retrieve only the more useful data.
|
||||||
|
*
|
||||||
|
* @author etj
|
||||||
|
*/
|
||||||
|
public class RESTWmsStore {
|
||||||
|
private final Element cs;
|
||||||
|
|
||||||
|
|
||||||
|
public RESTWmsStore(Element cs) {
|
||||||
|
this.cs = cs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RESTWmsStore build(String response) {
|
||||||
|
if(response == null)
|
||||||
|
return null;
|
||||||
|
if(response.isEmpty())
|
||||||
|
return new RESTWmsStore(new Element("wmsStore")); // TODO check how to response
|
||||||
|
|
||||||
|
Element pb = JDOMBuilder.buildElement(response);
|
||||||
|
if(pb != null)
|
||||||
|
return new RESTWmsStore(pb);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return cs.getChildText("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return cs.getChildText("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getEnabled() {
|
||||||
|
return Boolean.parseBoolean(cs.getChildText("enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWorkspaceName() {
|
||||||
|
return cs.getChild("workspace").getChildText("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getUseConnectionPooling(){
|
||||||
|
Element entry = cs.getChild("metadata").getChild("entry");
|
||||||
|
return entry.getAttributeValue("key").equals("useConnectionPooling") && Boolean.parseBoolean(entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCapabilitiesURL() {
|
||||||
|
return cs.getChildText("capabilitiesURL");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaxConnections() {
|
||||||
|
return cs.getChildText("maxConnections");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReadTimeout() {
|
||||||
|
return cs.getChildText("readTimeout");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConnectTimeout() {
|
||||||
|
return cs.getChildText("connectTimeout");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return cs.getChildText("user");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return cs.getChildText("password");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder(getClass().getSimpleName())
|
||||||
|
.append('[');
|
||||||
|
if(cs == null)
|
||||||
|
sb.append("null");
|
||||||
|
else
|
||||||
|
sb.append("name:").append(getName())
|
||||||
|
.append(" wsname:").append(getWorkspaceName());
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses list of summary data about WmsStores.
|
||||||
|
*
|
||||||
|
* <P>This is the XML REST representation:
|
||||||
|
* <PRE>{@code
|
||||||
|
<wmsStores>
|
||||||
|
<wmsStore>
|
||||||
|
<name>regione</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://172.27.30.25:8080/geoserver/rest/workspaces/arit/wmsstores/regione.xml" type="application/xml"/>
|
||||||
|
</wmsStore>
|
||||||
|
</wmsStores>
|
||||||
|
*
|
||||||
|
}</PRE>
|
||||||
|
*
|
||||||
|
* @author cip
|
||||||
|
*/
|
||||||
|
public class RESTWmsStoreList extends RESTAbstractList<NameLinkElem> {
|
||||||
|
|
||||||
|
public static RESTWmsStoreList build(String response) {
|
||||||
|
Element elem = JDOMBuilder.buildElement(response);
|
||||||
|
return elem == null? null : new RESTWmsStoreList(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RESTWmsStoreList(Element list) {
|
||||||
|
super(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|||||||
@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2015 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.decoder.about;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Attribute;
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode an XML for about/version.xml
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSVersionDecoder extends XmlElement {
|
||||||
|
public final static String ABOUT = "about";
|
||||||
|
|
||||||
|
private GSAboutResource geoserver;
|
||||||
|
|
||||||
|
public class GSAboutResource extends XmlElement {
|
||||||
|
public final static String RESOURCE = "resource";
|
||||||
|
|
||||||
|
public final static String NAME = "name";
|
||||||
|
|
||||||
|
public final static String VERSION = "Version";
|
||||||
|
|
||||||
|
private Element version;
|
||||||
|
|
||||||
|
public GSAboutResource() {
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void create(){
|
||||||
|
setRoot(RESOURCE);
|
||||||
|
version = new Element(VERSION);
|
||||||
|
addContent(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
final Attribute _name = this.getRoot().getAttribute(GSAboutResource.NAME);
|
||||||
|
if (name!=null)
|
||||||
|
_name.setValue(name);
|
||||||
|
else
|
||||||
|
this.getRoot().setAttribute(GSAboutResource.NAME, name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
final Attribute name = this.getRoot().getAttribute(GSAboutResource.NAME);
|
||||||
|
if (name!=null)
|
||||||
|
return name.getValue();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GSAboutResource(Element el) {
|
||||||
|
super();
|
||||||
|
if (el!=null){
|
||||||
|
setRoot(el);
|
||||||
|
version = ElementUtils.contains(el, GSAboutResource.VERSION);
|
||||||
|
} else {
|
||||||
|
create();
|
||||||
|
setVersion(GSVersionDecoder.VERSION.UNRECOGNIZED.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String v){
|
||||||
|
version.setText(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the string representation into this encoder
|
||||||
|
*
|
||||||
|
* @param document
|
||||||
|
*/
|
||||||
|
public GSVersionDecoder(String document) {
|
||||||
|
Element root=JDOMBuilder.buildElement(document);
|
||||||
|
if (root!=null){
|
||||||
|
setRoot(root);
|
||||||
|
geoserver = new GSAboutResource(ElementUtils.contains(this.getRoot(),
|
||||||
|
GSAboutResource.RESOURCE));
|
||||||
|
}else {
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GSVersionDecoder() {
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void create(){
|
||||||
|
setRoot("about");
|
||||||
|
geoserver = new GSAboutResource();
|
||||||
|
addContent(geoserver.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
public GSAboutResource getGeoServer(){
|
||||||
|
return geoserver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VERSION getVersion() {
|
||||||
|
Element e = ElementUtils.contains(geoserver.version, GSAboutResource.VERSION);
|
||||||
|
return VERSION.getVersion(e.getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link Enum#compareTo(Enum)}
|
||||||
|
* @param v
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int compareTo(VERSION v) {
|
||||||
|
return getVersion().compareTo(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GSVersionDecoder build(String response) {
|
||||||
|
return new GSVersionDecoder(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum VERSION {
|
||||||
|
v22(22, "2\\.2([^0-9]|$).*"),
|
||||||
|
v23(23, "2\\.3([^0-9]|$).*"),
|
||||||
|
v24(24, "2\\.4([^0-9]|$).*"),
|
||||||
|
v25(25, "2\\.5([^0-9]|$).*"),
|
||||||
|
v26(26, "2\\.6([^0-9]|$).*"),
|
||||||
|
v27(27, "2\\.7([^0-9]|$).*"),
|
||||||
|
v28(28, "2\\.8([^0-9]|$).*"),
|
||||||
|
ABOVE(9999, "2\\..+"),
|
||||||
|
UNRECOGNIZED(-1, null);
|
||||||
|
|
||||||
|
final private int version;
|
||||||
|
final private String pattern;
|
||||||
|
|
||||||
|
private VERSION(int val, String pattern) {
|
||||||
|
version = val;
|
||||||
|
this.pattern = pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return Integer.toString(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VERSION getVersion(String v) {
|
||||||
|
if (v == null) {
|
||||||
|
return UNRECOGNIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (VERSION version : VERSION.values()) {
|
||||||
|
if(version.pattern != null && v.matches(version.pattern)) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return UNRECOGNIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String print(){
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder("[");
|
||||||
|
for (VERSION v : VERSION.values()) {
|
||||||
|
sb.append(v.toString()).append(' ');
|
||||||
|
}
|
||||||
|
sb.append("]");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -27,11 +27,13 @@ package it.geosolutions.geoserver.rest.decoder.utils;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.jdom.Document;
|
import org.jdom.Document;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.JDOMException;
|
import org.jdom.JDOMException;
|
||||||
import org.jdom.input.SAXBuilder;
|
import org.jdom.input.SAXBuilder;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -39,7 +41,7 @@ import org.jdom.input.SAXBuilder;
|
|||||||
*/
|
*/
|
||||||
public class JDOMBuilder {
|
public class JDOMBuilder {
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger.getLogger(JDOMBuilder.class);
|
private final static Logger LOGGER = LoggerFactory.getLogger(JDOMBuilder.class);
|
||||||
|
|
||||||
public static Element buildElement(String response) {
|
public static Element buildElement(String response) {
|
||||||
if(response == null)
|
if(response == null)
|
||||||
|
|||||||
@ -27,6 +27,7 @@ package it.geosolutions.geoserver.rest.decoder.utils;
|
|||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic Store encoder.
|
||||||
|
*
|
||||||
|
* Provides getters and setters for parameters common to all CoverageStore.
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - GeoSolutions
|
||||||
|
*/
|
||||||
|
public abstract class GSAbstractStoreEncoder extends PropertyXMLEncoder {
|
||||||
|
|
||||||
|
private final GeoServerRESTPublisher.StoreType type;
|
||||||
|
|
||||||
|
protected GSAbstractStoreEncoder(GeoServerRESTPublisher.StoreType type, String storeName) {
|
||||||
|
super(type.getType());
|
||||||
|
this.type=type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StoreType getStoreType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
set("type", type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return ElementUtils.contains(getRoot(), "type").getTextTrim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
ensureValidName(name);
|
||||||
|
set("name", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
Element e = ElementUtils.contains(getRoot(), "name");
|
||||||
|
return e!=null?e.getTextTrim():null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
set("description", description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
Element e = ElementUtils.contains(getRoot(), "description");
|
||||||
|
return e!=null?e.getTextTrim():null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
set("enabled", Boolean.toString(enabled));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getEnabled() {
|
||||||
|
Element e = ElementUtils.contains(getRoot(), "name");
|
||||||
|
if (e!=null)
|
||||||
|
return Boolean.parseBoolean(e.getTextTrim());
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check name validity.
|
||||||
|
*
|
||||||
|
* @param name the name
|
||||||
|
* @throws IllegalArgumentException if name is null or empty
|
||||||
|
*/
|
||||||
|
protected void ensureValidName(String name) {
|
||||||
|
if (name == null || name.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Store name cannot be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check type validity.
|
||||||
|
*
|
||||||
|
* @param type the type.
|
||||||
|
* @throws IllegalArgumentException if type is not {@value #TYPE}
|
||||||
|
*/
|
||||||
|
protected void ensureValidType(String type) {
|
||||||
|
if (!type.equals(getValidType())) {
|
||||||
|
throw new IllegalArgumentException("The store type '" + type + "' is not valid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of the implementing store.
|
||||||
|
*/
|
||||||
|
protected abstract String getValidType();
|
||||||
|
}
|
||||||
@ -0,0 +1,264 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alessio Fabiani (alessio.fabiani at geo-solutions.it)
|
||||||
|
*/
|
||||||
|
public class GSBackupEncoder extends PropertyXMLEncoder
|
||||||
|
{
|
||||||
|
public static final String TASK = "task";
|
||||||
|
public static final String PATH = "path";
|
||||||
|
public static final String INCLUDE_DATA = "includedata";
|
||||||
|
public static final String INCLUDE_GWC = "includegwc";
|
||||||
|
public static final String INCLUDE_LOG = "includelog";
|
||||||
|
|
||||||
|
public GSBackupEncoder()
|
||||||
|
{
|
||||||
|
super(TASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path the task path
|
||||||
|
*/
|
||||||
|
public GSBackupEncoder(String name)
|
||||||
|
{
|
||||||
|
super(TASK);
|
||||||
|
addPath(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the path to this task
|
||||||
|
* @param path
|
||||||
|
* @throws IllegalStateException if path is already set
|
||||||
|
* @deprecated will be set to protected in the next release
|
||||||
|
*/
|
||||||
|
public void addPath(final String path)
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), PATH);
|
||||||
|
if (el == null)
|
||||||
|
{
|
||||||
|
add(PATH, path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("Task path is already set: " + el.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add or change (if already set) the task path
|
||||||
|
* @param path
|
||||||
|
*/
|
||||||
|
public void setPath(final String path)
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), PATH);
|
||||||
|
if (el == null)
|
||||||
|
{
|
||||||
|
add(PATH, path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
el.setText(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath()
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), PATH);
|
||||||
|
if (el != null)
|
||||||
|
{
|
||||||
|
return el.getTextTrim();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* INCLUDE DATA ELEMENT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the includedata to this task
|
||||||
|
* @param includedata
|
||||||
|
* @deprecated will be set to protected in the next release
|
||||||
|
*/
|
||||||
|
public void addIncludeData(final Boolean includedata)
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), INCLUDE_DATA);
|
||||||
|
if (el == null)
|
||||||
|
{
|
||||||
|
add(INCLUDE_DATA, includedata.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
el.setText(includedata.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add or change (if already set) the task includedata
|
||||||
|
* @param includedata
|
||||||
|
*/
|
||||||
|
public void setIncludeData(final Boolean includedata)
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), INCLUDE_DATA);
|
||||||
|
if (el == null)
|
||||||
|
{
|
||||||
|
add(INCLUDE_DATA, includedata.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
el.setText(includedata.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIncludeData()
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), INCLUDE_DATA);
|
||||||
|
if (el != null)
|
||||||
|
{
|
||||||
|
return el.getTextTrim();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* INCLUDE GWC ELEMENT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the includegwc to this task
|
||||||
|
* @param includegwc
|
||||||
|
* @deprecated will be set to protected in the next release
|
||||||
|
*/
|
||||||
|
public void addIncludeGwc(final Boolean includegwc)
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), INCLUDE_GWC);
|
||||||
|
if (el == null)
|
||||||
|
{
|
||||||
|
add(INCLUDE_GWC, includegwc.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
el.setText(includegwc.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add or change (if already set) the task includegwc
|
||||||
|
* @param includegwc
|
||||||
|
*/
|
||||||
|
public void setIncludeGwc(final Boolean includegwc)
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), INCLUDE_GWC);
|
||||||
|
if (el == null)
|
||||||
|
{
|
||||||
|
add(INCLUDE_GWC, includegwc.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
el.setText(includegwc.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIncludeGwc()
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), INCLUDE_GWC);
|
||||||
|
if (el != null)
|
||||||
|
{
|
||||||
|
return el.getTextTrim();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* INCLUDE LOG ELEMENT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the includelog to this task
|
||||||
|
* @param includelog
|
||||||
|
* @deprecated will be set to protected in the next release
|
||||||
|
*/
|
||||||
|
public void addIncludeLog(final Boolean includelog)
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), INCLUDE_LOG);
|
||||||
|
if (el == null)
|
||||||
|
{
|
||||||
|
add(INCLUDE_LOG, includelog.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
el.setText(includelog.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add or change (if already set) the task includelog
|
||||||
|
* @param includelog
|
||||||
|
*/
|
||||||
|
public void setIncludeLog(final Boolean includelog)
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), INCLUDE_LOG);
|
||||||
|
if (el == null)
|
||||||
|
{
|
||||||
|
add(INCLUDE_LOG, includelog.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
el.setText(includelog.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIncludeLog()
|
||||||
|
{
|
||||||
|
final Element el = ElementUtils.contains(getRoot(), INCLUDE_LOG);
|
||||||
|
if (el != null)
|
||||||
|
{
|
||||||
|
return el.getTextTrim();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,23 +25,69 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.encoder;
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Layer encoder for Geoserver >= 2.2
|
||||||
*
|
*
|
||||||
* @author ETj (etj at geo-solutions.it)
|
* @author ETj (etj at geo-solutions.it)
|
||||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com
|
||||||
*
|
*
|
||||||
* The layer encoder is enabled by default
|
* The layer encoder is enabled by default
|
||||||
*
|
*
|
||||||
|
* {@code
|
||||||
|
* <layer>
|
||||||
|
* <name>{LAYERNAME}</name>
|
||||||
|
* <type>RASTER</type>
|
||||||
|
* <defaultStyle>
|
||||||
|
* <name>{STYLE_NAME}</name>
|
||||||
|
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://{GSURL}/rest/styles/{STYLE}xml" type="application/xml"/>
|
||||||
|
* </defaultStyle>
|
||||||
|
* <resource class="coverage">
|
||||||
|
* <name>{RESOURCE_NAME}</name>
|
||||||
|
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
|
||||||
|
* href="http://{GSURL}/rest/workspaces/{WS}/coveragestores/{STORE}/coverages/{LAYER}.xml" type="application/xml"/>
|
||||||
|
* </resource>
|
||||||
|
* <attribution>
|
||||||
|
* <title>test</title>
|
||||||
|
* <href>http://www.fao.org/fileadmin/templates/faoweb/images/FAO-logo.png</href>
|
||||||
|
* <logoURL>http://www.fao.org/fileadmin/templates/faoweb/images/FAO-logo.png</logoURL>
|
||||||
|
* <logoWidth>412</logoWidth>
|
||||||
|
* <logoHeight>77</logoHeight>
|
||||||
|
* <logoType>image/png</logoType>
|
||||||
|
* </attribution>
|
||||||
|
* ...
|
||||||
|
*
|
||||||
|
* </layer>
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @since gs-2.2.x
|
||||||
*/
|
*/
|
||||||
public class GSLayerEncoder extends PropertyXMLEncoder {
|
public class GSLayerEncoder extends PropertyXMLEncoder {
|
||||||
|
|
||||||
|
public final static String STYLES = "styles";
|
||||||
|
public final static String AUTHORITY_URLS="authorityURLs";
|
||||||
|
public final static String IDENTIFIERS="identifiers";
|
||||||
|
public final static String DEFAULT_STYLE = "defaultStyle";
|
||||||
|
|
||||||
|
final private Element stylesEncoder = new Element(STYLES);
|
||||||
|
final private Element defaultStyleEncoder = new Element(DEFAULT_STYLE);
|
||||||
|
final private Element authorityURLListEncoder = new Element(AUTHORITY_URLS);
|
||||||
|
final private Element identifierListEncoder = new Element(IDENTIFIERS);
|
||||||
|
|
||||||
public GSLayerEncoder() {
|
public GSLayerEncoder() {
|
||||||
super("layer");
|
super("layer");
|
||||||
addEnabled();
|
addEnabled();
|
||||||
|
addContent(stylesEncoder);
|
||||||
|
addContent(authorityURLListEncoder);
|
||||||
|
addContent(identifierListEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,34 +107,36 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
|
|||||||
set("enabled","false");
|
set("enabled","false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private final static String DESCRIPTION = "description";
|
||||||
// /**
|
// /**
|
||||||
// * @param name the name of the layer
|
// * Add the 'description' node with a text value from 'description'
|
||||||
|
// *
|
||||||
// */
|
// */
|
||||||
// protected void addName(final String name){
|
// protected void addDescription(final String description) {
|
||||||
// add("name",name);
|
// add(DESCRIPTION, description);
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// /**
|
// /**
|
||||||
// * @return name the name of the layer or null
|
// * Set or modify the 'description' node with a text value from 'description'
|
||||||
// */
|
// */
|
||||||
// public String getName() {
|
// public void setDescription(final String description) {
|
||||||
// final Element nameNode = get("name");
|
// set(DESCRIPTION, description);
|
||||||
// if (nameNode != null)
|
|
||||||
// return nameNode.getText();
|
|
||||||
// else
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param name the name of the layer
|
|
||||||
// * @throws IllegalArgumentException
|
|
||||||
// */
|
|
||||||
// public void setName(final String name) throws IllegalArgumentException {
|
|
||||||
// if (name==null || name.isEmpty())
|
|
||||||
// throw new IllegalArgumentException("Unable to set an empty or null parameter");
|
|
||||||
// set("name",name);
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// queryable
|
||||||
|
private final static String QUERYABLE = "queryable";
|
||||||
|
/**
|
||||||
|
* Add the 'queryable' node with a text value from 'queryable' (true as default)
|
||||||
|
*/
|
||||||
|
protected void addQueryable(final String queryable) {
|
||||||
|
add(QUERYABLE, queryable!=null?queryable.toString():"true");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Set or modify the 'queryable' node with a text value from 'queryable' (true as default)
|
||||||
|
*/
|
||||||
|
public void setQueryable(final Boolean queryable) {
|
||||||
|
set(QUERYABLE, queryable!=null?queryable.toString():"true");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see {@link GSLayerEncoder#setWmsPath(String)}
|
* @see {@link GSLayerEncoder#setWmsPath(String)}
|
||||||
*
|
*
|
||||||
@ -119,6 +167,20 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
|
|||||||
add("defaultStyle", defaultStyle);
|
add("defaultStyle", defaultStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link GSLayerEncoder#setDefaultStyle(String)}
|
||||||
|
* @param defaultStyle
|
||||||
|
*/
|
||||||
|
protected void addDefaultStyle(String workspace, String defaultStyle) {
|
||||||
|
addContent(defaultStyleEncoder);
|
||||||
|
Element el = new Element("name");
|
||||||
|
el.setText(defaultStyle);
|
||||||
|
defaultStyleEncoder.addContent(el);
|
||||||
|
el = new Element("workspace");
|
||||||
|
el.setText(workspace);
|
||||||
|
defaultStyleEncoder.addContent(el);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param defaultStyle The style that will be applied if no style is specified.
|
* @param defaultStyle The style that will be applied if no style is specified.
|
||||||
* @throws IllegalArgumentException if defaultStyle is null or empty
|
* @throws IllegalArgumentException if defaultStyle is null or empty
|
||||||
@ -128,4 +190,99 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
|
|||||||
throw new IllegalArgumentException("Unable to set an empty or null parameter");
|
throw new IllegalArgumentException("Unable to set an empty or null parameter");
|
||||||
set("defaultStyle", defaultStyle);
|
set("defaultStyle", defaultStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link GSLayerEncoder#setDefaultStyle(String)}
|
||||||
|
* @param defaultStyle
|
||||||
|
*/
|
||||||
|
public void setDefaultStyle(String workspace, String defaultStyle) {
|
||||||
|
remove("defaultStyle");
|
||||||
|
addDefaultStyle(workspace, defaultStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a style
|
||||||
|
*
|
||||||
|
* @param style
|
||||||
|
*/
|
||||||
|
public void addStyle(String style) {
|
||||||
|
final Element el = new Element("style");
|
||||||
|
el.setText(style);
|
||||||
|
stylesEncoder.addContent(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete a style from the list of available styles
|
||||||
|
*
|
||||||
|
* @param style
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delStyle(final String style) {
|
||||||
|
final Element el = new Element("style");
|
||||||
|
el.setText(style);
|
||||||
|
return (stylesEncoder.removeContent(new Filter() {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
if (((Element) obj).getText().equals(style)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})).size() == 0 ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param advertised
|
||||||
|
* true if the layer should be advertised
|
||||||
|
*/
|
||||||
|
public void setAdvertised(boolean advertised) {
|
||||||
|
if (advertised)
|
||||||
|
set("advertised", "true");
|
||||||
|
else
|
||||||
|
set("advertised", "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an authorityURLInfo to the GeoServer layer
|
||||||
|
*
|
||||||
|
* @param authorityURLInfo
|
||||||
|
*/
|
||||||
|
public void addAuthorityURL(GSAuthorityURLInfoEncoder authorityURLInfo) {
|
||||||
|
authorityURLListEncoder.addContent(authorityURLInfo.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a AuthorityURLInfo from the list using the authorityURL
|
||||||
|
* (AuthorityURLInfo href)
|
||||||
|
*
|
||||||
|
* @param authorityURL
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delAuthorityURL(final String authorityURL) {
|
||||||
|
return (authorityURLListEncoder.removeContent(GSAuthorityURLInfoEncoder
|
||||||
|
.getFilterByHref(authorityURL))).size() == 0 ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an identifierInfo to the GeoServer layer
|
||||||
|
*
|
||||||
|
* @param identifierInfo
|
||||||
|
*/
|
||||||
|
public void addIdentifier(GSIdentifierInfoEncoder identifierInfo) {
|
||||||
|
identifierListEncoder.addContent(identifierInfo.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a IdentifierInfo from the list using the authority name
|
||||||
|
* (IdentifierInfo authority)
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delIdentifier(final String authority) {
|
||||||
|
return (identifierListEncoder.removeContent(GSIdentifierInfoEncoder
|
||||||
|
.getFilterByHref(authority))).size() == 0 ? false : true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,212 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007-2016 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.IdentifierInfo;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layer encoder for Geoserver = 2.1
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com
|
||||||
|
*
|
||||||
|
* The layer encoder is enabled by default
|
||||||
|
*
|
||||||
|
* @since gs-2.1.x
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSLayerEncoder21 extends GSLayerEncoder {
|
||||||
|
|
||||||
|
|
||||||
|
public final static String METADATA = "metadata";
|
||||||
|
final private GSMetadataEncoder metadata = new GSMetadataEncoder();
|
||||||
|
public Map<String,String> authorityURLList;
|
||||||
|
public Map<String,List<String>> identifierList;
|
||||||
|
|
||||||
|
private class GSMetadataEncoder extends NestedElementEncoder{
|
||||||
|
public GSMetadataEncoder() {
|
||||||
|
super(METADATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GSLayerEncoder21() {
|
||||||
|
super();
|
||||||
|
addContent(metadata.getRoot());
|
||||||
|
addAdvertised();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key
|
||||||
|
* @param dimensionInfo
|
||||||
|
*/
|
||||||
|
protected void addMetadata(String key, XmlElement dimensionInfo) {
|
||||||
|
metadata.add(key, dimensionInfo.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* advertise the layer
|
||||||
|
*/
|
||||||
|
protected void addAdvertised(){
|
||||||
|
metadata.add("advertised", "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param advertised true if the layer should be advertised
|
||||||
|
*/
|
||||||
|
public void setAdvertised(boolean advertised){
|
||||||
|
if(advertised){
|
||||||
|
metadata.add("advertised", "true");
|
||||||
|
}else{
|
||||||
|
metadata.add("advertised", "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an authorityURLInfo to the GeoServer layer
|
||||||
|
*
|
||||||
|
* @param authorityURLInfo
|
||||||
|
*/
|
||||||
|
public void addAuthorityURL(GSAuthorityURLInfoEncoder authorityURLInfo){
|
||||||
|
if(authorityURLList == null){
|
||||||
|
authorityURLList = new LinkedHashMap<String,String>();
|
||||||
|
}
|
||||||
|
authorityURLList.put(authorityURLInfo.getHref(), authorityURLInfo.getName());
|
||||||
|
String jsonStr = "";
|
||||||
|
for(Entry<String, String> entry : authorityURLList.entrySet()){
|
||||||
|
jsonStr += "{"+
|
||||||
|
"\""+AuthorityURLInfo.name.name()+"\":\""+entry.getValue()+"\","+
|
||||||
|
"\""+AuthorityURLInfo.href.name()+"\":\""+entry.getKey()+"\""+
|
||||||
|
"},";
|
||||||
|
}
|
||||||
|
metadata.set("authorityURLs", "["+jsonStr+"]");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a AuthorityURLInfo from the list using the authorityURL
|
||||||
|
* (AuthorityURLInfo href)
|
||||||
|
*
|
||||||
|
* @param authorityURL
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delAuthorityURL(final String authorityURL){
|
||||||
|
boolean delete = false;
|
||||||
|
if(!(authorityURLList == null || authorityURLList.isEmpty())){
|
||||||
|
if(authorityURLList.containsKey(authorityURL)){
|
||||||
|
identifierList.remove(authorityURL);
|
||||||
|
String jsonStr = "";
|
||||||
|
for (Entry<String, List<String>> entry : identifierList
|
||||||
|
.entrySet()) {
|
||||||
|
for (String value : entry.getValue()) {
|
||||||
|
jsonStr += "{" + "\"" + AuthorityURLInfo.name.name()
|
||||||
|
+ "\":\"" + entry.getValue() + "\"," + "\""
|
||||||
|
+ AuthorityURLInfo.href.name() + "\":\""
|
||||||
|
+ value + "\"" + "},";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
metadata.set("identifiers", "["+jsonStr+"]");
|
||||||
|
delete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an identifierInfo to the GeoServer layer
|
||||||
|
*
|
||||||
|
* @param identifierInfo
|
||||||
|
*/
|
||||||
|
public void addIdentifier(GSIdentifierInfoEncoder identifierInfo){
|
||||||
|
if(identifierList == null){
|
||||||
|
identifierList = new LinkedHashMap<String,List<String>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
String authority = identifierInfo.getAuthority();
|
||||||
|
|
||||||
|
if (!identifierList.containsKey(authority)) {
|
||||||
|
List<String> ids = new ArrayList<String>();
|
||||||
|
ids.add(identifierInfo.getIdentifier());
|
||||||
|
identifierList.put(authority, ids);
|
||||||
|
} else {
|
||||||
|
List<String> ids = identifierList.get(authority);
|
||||||
|
ids.add(identifierInfo.getIdentifier());
|
||||||
|
identifierList.put(authority, ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
String jsonStr = "";
|
||||||
|
for (Entry<String, List<String>> entry : identifierList.entrySet()) {
|
||||||
|
for (String value : entry.getValue()) {
|
||||||
|
jsonStr += "{" + "\"" + IdentifierInfo.authority.name()
|
||||||
|
+ "\":\"" + entry.getKey() + "\"," + "\""
|
||||||
|
+ IdentifierInfo.identifier.name() + "\":\"" + value
|
||||||
|
+ "\"" + "},";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
metadata.set("identifiers", "["+jsonStr+"]");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a IdentifierInfo from the list using the authority
|
||||||
|
* name (IdentifierInfo authority)
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delIdentifier(final String authority){
|
||||||
|
boolean delete = false;
|
||||||
|
if(!(identifierList == null || identifierList.isEmpty())){
|
||||||
|
if(identifierList.containsKey(authority)){
|
||||||
|
identifierList.remove(authority);
|
||||||
|
String jsonStr = "";
|
||||||
|
for (Entry<String, List<String>> entry : identifierList
|
||||||
|
.entrySet()) {
|
||||||
|
for (String value : entry.getValue()) {
|
||||||
|
jsonStr += "{" + "\"" + IdentifierInfo.authority.name()
|
||||||
|
+ "\":\"" + entry.getKey() + "\"," + "\""
|
||||||
|
+ IdentifierInfo.identifier.name() + "\":\""
|
||||||
|
+ value + "\"" + "},";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
metadata.set("identifiers", "["+jsonStr+"]");
|
||||||
|
delete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
123
src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder.java
Executable file
123
src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder.java
Executable file
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LayerGroup encoder for GeoServer < 2.3
|
||||||
|
*
|
||||||
|
* @author Davide Savazzi (geo-solutions.it)
|
||||||
|
*/
|
||||||
|
public class GSLayerGroupEncoder extends PropertyXMLEncoder {
|
||||||
|
|
||||||
|
protected Element nameElem;
|
||||||
|
protected Element workspaceElem;
|
||||||
|
protected Element boundsElem;
|
||||||
|
protected Element publishablesElem;
|
||||||
|
protected Element stylesElem;
|
||||||
|
|
||||||
|
|
||||||
|
public GSLayerGroupEncoder() {
|
||||||
|
super("layerGroup");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setWorkspace(String workspace) {
|
||||||
|
workspaceElem = elem("workspace", elem("name", workspace));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
nameElem = elem("name", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLayer(String layer) {
|
||||||
|
addLayer(layer, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLayer(String layer, String styleName) {
|
||||||
|
initPublishables("layers");
|
||||||
|
|
||||||
|
publishablesElem.addContent(elem("layer", elem("name", layer)));
|
||||||
|
|
||||||
|
Element style = new Element("style");
|
||||||
|
stylesElem.addContent(style);
|
||||||
|
if (styleName != null) {
|
||||||
|
style.addContent(elem("name", styleName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBounds(String crs, double minx, double maxx, double miny, double maxy) {
|
||||||
|
boundsElem = elem("bounds",
|
||||||
|
elem("minx", Double.toString(minx)),
|
||||||
|
elem("maxx", Double.toString(maxx)),
|
||||||
|
elem("miny", Double.toString(miny)),
|
||||||
|
elem("maxy", Double.toString(maxy)),
|
||||||
|
elem("crs", "class", "projected").setText(crs));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initPublishables(String publishablesTag) {
|
||||||
|
if (publishablesElem == null) {
|
||||||
|
publishablesElem = new Element(publishablesTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stylesElem == null) {
|
||||||
|
stylesElem = new Element("styles");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addToRoot(Element ... elements) {
|
||||||
|
for (Element e : elements) {
|
||||||
|
if (e != null) {
|
||||||
|
getRoot().addContent(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element elem(String tag, String attributeName, String attributeValue) {
|
||||||
|
return new Element(tag).setAttribute(attributeName, attributeValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element elem(String tag, String text) {
|
||||||
|
return new Element(tag).setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element elem(String tag, Element ... children) {
|
||||||
|
Element parent = new Element(tag);
|
||||||
|
for (Element child : children) {
|
||||||
|
parent.addContent(child);
|
||||||
|
}
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
addToRoot(nameElem, workspaceElem, boundsElem, publishablesElem, stylesElem);
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
110
src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder23.java
Executable file
110
src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder23.java
Executable file
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LayerGroup encoder for GeoServer >= 2.3
|
||||||
|
*
|
||||||
|
* @author Davide Savazzi (geo-solutions.it)
|
||||||
|
*/
|
||||||
|
public class GSLayerGroupEncoder23 extends GSLayerGroupEncoder {
|
||||||
|
|
||||||
|
public static final String MODE_SINGLE = "SINGLE";
|
||||||
|
public static final String MODE_NAMED = "NAMED";
|
||||||
|
public static final String MODE_CONTAINER = "CONTAINER";
|
||||||
|
public static final String MODE_EO = "EO";
|
||||||
|
private static final Set<String> modes;
|
||||||
|
static {
|
||||||
|
modes = new HashSet<String>();
|
||||||
|
modes.add(MODE_SINGLE);
|
||||||
|
modes.add(MODE_NAMED);
|
||||||
|
modes.add(MODE_CONTAINER);
|
||||||
|
modes.add(MODE_EO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Element titleElem;
|
||||||
|
private Element abstractElem;
|
||||||
|
private Element modeElem;
|
||||||
|
private Element rootLayerElem;
|
||||||
|
private Element rootLayerStyleElem;
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
titleElem = elem("title", title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAbstract(String abstractTxt) {
|
||||||
|
abstractElem = elem("abstractTxt", abstractTxt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMode(String mode) {
|
||||||
|
if (!modes.contains(mode)) {
|
||||||
|
throw new IllegalArgumentException("Invalid mode: " + mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
modeElem = elem("mode", mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRootLayer(String layer, String style) {
|
||||||
|
rootLayerElem = elem("rootLayer", elem("name", layer));
|
||||||
|
rootLayerStyleElem = elem("rootLayerStyle", elem("name", style));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addLayer(String layer, String styleName) {
|
||||||
|
initPublishables("publishables");
|
||||||
|
|
||||||
|
publishablesElem.addContent(
|
||||||
|
new Element("published").setAttribute("type", "layer").addContent(
|
||||||
|
elem("name", layer)));
|
||||||
|
|
||||||
|
Element style = new Element("style");
|
||||||
|
stylesElem.addContent(style);
|
||||||
|
if (styleName != null) {
|
||||||
|
style.addContent(elem("name", styleName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLayerGroup(String group) {
|
||||||
|
initPublishables("publishables");
|
||||||
|
|
||||||
|
publishablesElem.addContent(
|
||||||
|
new Element("published").setAttribute("type", "layerGroup").addContent(
|
||||||
|
elem("name", group)));
|
||||||
|
|
||||||
|
stylesElem.addContent(new Element("style"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
addToRoot(titleElem, abstractElem, modeElem, rootLayerElem, rootLayerStyleElem);
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace XML encoder. Namespaces must contain a non empty prefix and a URI:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <namespace>
|
||||||
|
* <prefix>example</prefix>
|
||||||
|
* <uri>http://example.com</uri>
|
||||||
|
* </namespace>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @see <a href="http://docs.geoserver.org/stable/en/user/restconfig/rest-config-api.html#namespaces"> GeoServer Documentation</a>
|
||||||
|
* @author Oscar Fonts
|
||||||
|
*/
|
||||||
|
public class GSNamespaceEncoder extends PropertyXMLEncoder {
|
||||||
|
|
||||||
|
public final static String NAMESPACE="namespace";
|
||||||
|
public final static String PREFIX="prefix";
|
||||||
|
public final static String URI="uri";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a namespace XML encoder.
|
||||||
|
*
|
||||||
|
* @param prefix the namespace prefix
|
||||||
|
* @param uri the namespace URI
|
||||||
|
* @throws IllegalArgumentException if prefix or uri are null or empty
|
||||||
|
*/
|
||||||
|
public GSNamespaceEncoder(String prefix, URI uri) {
|
||||||
|
super(NAMESPACE);
|
||||||
|
|
||||||
|
ensureValidPrefix(prefix);
|
||||||
|
ensureValidURI(uri);
|
||||||
|
|
||||||
|
add(PREFIX, prefix);
|
||||||
|
add(URI, uri.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the namespace prefix.
|
||||||
|
* @return the prefix
|
||||||
|
*/
|
||||||
|
public String getPrefix() {
|
||||||
|
return ElementUtils.contains(getRoot(), PREFIX).getTextTrim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the namespace prefix.
|
||||||
|
* @param prefix the new prefix
|
||||||
|
* @throws IllegalArgumentException if prefix is null or empty
|
||||||
|
*/
|
||||||
|
public void setPrefix(final String prefix) {
|
||||||
|
ensureValidPrefix(prefix);
|
||||||
|
ElementUtils.contains(getRoot(), PREFIX).setText(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the namespace uri.
|
||||||
|
* @return the uri
|
||||||
|
*/
|
||||||
|
public URI getURI() {
|
||||||
|
String sUri = ElementUtils.contains(getRoot(), URI).getTextTrim();
|
||||||
|
return java.net.URI.create(sUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* change the nampespace uri.
|
||||||
|
* @param URI the new uri
|
||||||
|
* @throws IllegalArgumentException if uri is null or empty
|
||||||
|
*/
|
||||||
|
public void setURI(final URI uri) {
|
||||||
|
ensureValidURI(uri);
|
||||||
|
String sUri = uri.toString();
|
||||||
|
ElementUtils.contains(getRoot(), URI).setText(sUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check prefix value.
|
||||||
|
*
|
||||||
|
* @param prefix the prefix
|
||||||
|
* @throws IllegalArgumentException if prefix is null or empty
|
||||||
|
*/
|
||||||
|
private static void ensureValidPrefix(String prefix) {
|
||||||
|
if (prefix == null || prefix.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Namespace prefix cannot be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check uri value.
|
||||||
|
*
|
||||||
|
* @param prefix the uri
|
||||||
|
* @throws IllegalArgumentException if uri is null or empty
|
||||||
|
*/
|
||||||
|
private static void ensureValidURI(URI uri) {
|
||||||
|
if (uri == null || uri.toString().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Namespace uri cannot be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -34,6 +34,9 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
|||||||
* @author Eric Grosso
|
* @author Eric Grosso
|
||||||
* @author ETj
|
* @author ETj
|
||||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*
|
||||||
|
* @deprecated Will be removed in next version 1.5.x.
|
||||||
|
* Use {@link it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder} instead.
|
||||||
*/
|
*/
|
||||||
public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
||||||
|
|
||||||
@ -70,10 +73,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
setMaxOpenPreparedStatements(50);
|
setMaxOpenPreparedStatements(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addName(String name) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addName(String name) {
|
|
||||||
add("name", name);
|
add("name", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,10 +81,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
set("name", name);
|
set("name", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addDescription(String description) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addDescription(String description) {
|
|
||||||
add("description", description);
|
add("description", description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,10 +89,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
set("description", description);
|
set("description", description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addType(String type) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addType(String type) {
|
|
||||||
add("type", type);
|
add("type", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,10 +97,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
set("type", type);
|
set("type", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addEnabled(boolean enabled) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addEnabled(boolean enabled) {
|
|
||||||
add("enabled", Boolean.toString(enabled));
|
add("enabled", Boolean.toString(enabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,10 +105,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
set("enabled", Boolean.toString(enabled));
|
set("enabled", Boolean.toString(enabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addNamespace(String namespace) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addNamespace(String namespace) {
|
|
||||||
connectionParameters.add("namespace", namespace);
|
connectionParameters.add("namespace", namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,10 +113,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("namespace", namespace);
|
connectionParameters.set("namespace", namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addHost(String host) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addHost(String host) {
|
|
||||||
connectionParameters.add("host", host);
|
connectionParameters.add("host", host);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,10 +121,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("host", host);
|
connectionParameters.set("host", host);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addPort(int port) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addPort(int port) {
|
|
||||||
connectionParameters.add("port", Integer.toString(port));
|
connectionParameters.add("port", Integer.toString(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,10 +129,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("port", Integer.toString(port));
|
connectionParameters.set("port", Integer.toString(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addDatabase(String database) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addDatabase(String database) {
|
|
||||||
connectionParameters.add("database", database);
|
connectionParameters.add("database", database);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,10 +137,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("database", database);
|
connectionParameters.set("database", database);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addSchema(String schema) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addSchema(String schema) {
|
|
||||||
connectionParameters.add("schema", schema);
|
connectionParameters.add("schema", schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,10 +145,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("schema", schema);
|
connectionParameters.set("schema", schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addUser(String user) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addUser(String user) {
|
|
||||||
connectionParameters.add("user", user);
|
connectionParameters.add("user", user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,10 +153,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("user", user);
|
connectionParameters.set("user", user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addPassword(String password) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addPassword(String password) {
|
|
||||||
connectionParameters.add("passwd", password);
|
connectionParameters.add("passwd", password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,10 +161,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("passwd", password);
|
connectionParameters.set("passwd", password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addDatabaseType(String dbtype) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addDatabaseType(String dbtype) {
|
|
||||||
connectionParameters.add("dbtype", dbtype);
|
connectionParameters.add("dbtype", dbtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,10 +169,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("dbtype", dbtype);
|
connectionParameters.set("dbtype", dbtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addJndiReferenceName(String jndiReferenceName) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addJndiReferenceName(String jndiReferenceName) {
|
|
||||||
connectionParameters.add("jndiReferenceName", jndiReferenceName);
|
connectionParameters.add("jndiReferenceName", jndiReferenceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,10 +177,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("jndiReferenceName", jndiReferenceName);
|
connectionParameters.set("jndiReferenceName", jndiReferenceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addExposePrimaryKeys(boolean exposePrimaryKeys) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addExposePrimaryKeys(boolean exposePrimaryKeys) {
|
|
||||||
connectionParameters.add("Expose primary keys", Boolean.toString(exposePrimaryKeys));
|
connectionParameters.add("Expose primary keys", Boolean.toString(exposePrimaryKeys));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,10 +185,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("Expose primary keys", Boolean.toString(exposePrimaryKeys));
|
connectionParameters.set("Expose primary keys", Boolean.toString(exposePrimaryKeys));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addMaxConnections(int maxConnections) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addMaxConnections(int maxConnections) {
|
|
||||||
connectionParameters.add("max connections", Integer.toString(maxConnections));
|
connectionParameters.add("max connections", Integer.toString(maxConnections));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,10 +193,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("max connections", Integer.toString(maxConnections));
|
connectionParameters.set("max connections", Integer.toString(maxConnections));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addMinConnections(int minConnections) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addMinConnections(int minConnections) {
|
|
||||||
connectionParameters.add("min connections", Integer.toString(minConnections));
|
connectionParameters.add("min connections", Integer.toString(minConnections));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,10 +201,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("min connections", Integer.toString(minConnections));
|
connectionParameters.set("min connections", Integer.toString(minConnections));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addFetchSize(int fetchSize) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addFetchSize(int fetchSize) {
|
|
||||||
connectionParameters.add("fetch size", Integer.toString(fetchSize));
|
connectionParameters.add("fetch size", Integer.toString(fetchSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,10 +209,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("fetch size", Integer.toString(fetchSize));
|
connectionParameters.set("fetch size", Integer.toString(fetchSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addConnectionTimeout(int seconds) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addConnectionTimeout(int seconds) {
|
|
||||||
connectionParameters.add("Connection timeout", Integer.toString(seconds));
|
connectionParameters.add("Connection timeout", Integer.toString(seconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,10 +217,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("Connection timeout", Integer.toString(seconds));
|
connectionParameters.set("Connection timeout", Integer.toString(seconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addValidateConnections(boolean validateConnections) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addValidateConnections(boolean validateConnections) {
|
|
||||||
connectionParameters.add("validate connections", Boolean.toString(validateConnections));
|
connectionParameters.add("validate connections", Boolean.toString(validateConnections));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,10 +225,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("validate connections", Boolean.toString(validateConnections));
|
connectionParameters.set("validate connections", Boolean.toString(validateConnections));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
|
|
||||||
connectionParameters.add("Primary key metadata table", primaryKeyMetadataTable);
|
connectionParameters.add("Primary key metadata table", primaryKeyMetadataTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,10 +233,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("Primary key metadata table", primaryKeyMetadataTable);
|
connectionParameters.set("Primary key metadata table", primaryKeyMetadataTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addLooseBBox(boolean looseBBox) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addLooseBBox(boolean looseBBox) {
|
|
||||||
connectionParameters.add("Loose bbox", Boolean.toString(looseBBox));
|
connectionParameters.add("Loose bbox", Boolean.toString(looseBBox));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,10 +241,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("Loose bbox", Boolean.toString(looseBBox));
|
connectionParameters.set("Loose bbox", Boolean.toString(looseBBox));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addPreparedStatements(boolean preparedStatements) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addPreparedStatements(boolean preparedStatements) {
|
|
||||||
connectionParameters.add("preparedStatements", Boolean.toString(preparedStatements));
|
connectionParameters.add("preparedStatements", Boolean.toString(preparedStatements));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,10 +249,7 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
connectionParameters.set("preparedStatements", Boolean.toString(preparedStatements));
|
connectionParameters.set("preparedStatements", Boolean.toString(preparedStatements));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void addMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
|
||||||
public void addMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
|
|
||||||
connectionParameters.add("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
|
connectionParameters.add("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,8 @@ import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
|||||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
|
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
@ -38,24 +40,33 @@ import org.jdom.filter.Filter;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Encode a GeoServer resouce. The <T> type regards the GDSDimensionInfoEncoder
|
* Encode a GeoServer resource.
|
||||||
* metadata Type which has different specialization for Features.
|
|
||||||
*
|
*
|
||||||
* @see GSDimensionInfoEncoder
|
* @see GSDimensionInfoEncoder
|
||||||
* @see GSFeatureDimensionInfoEncoder
|
* @see GSFeatureDimensionInfoEncoder
|
||||||
*
|
*
|
||||||
* @author ETj (etj at geo-solutions.it)
|
* @author ETj (etj at geo-solutions.it)
|
||||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org
|
||||||
|
* @author Henry Rotzoll
|
||||||
*/
|
*/
|
||||||
public abstract class GSResourceEncoder
|
public abstract class GSResourceEncoder extends PropertyXMLEncoder {
|
||||||
extends PropertyXMLEncoder {
|
|
||||||
public final static String NAME = "name";
|
public final static String NAME = "name";
|
||||||
|
|
||||||
|
public final static String NATIVENAME = "nativeName";
|
||||||
|
|
||||||
public final static String METADATA = "metadata";
|
public final static String METADATA = "metadata";
|
||||||
|
|
||||||
public final static String KEYWORDS = "keywords";
|
public final static String KEYWORDS = "keywords";
|
||||||
|
|
||||||
|
public final static String METADATALINKS = "metadataLinks";
|
||||||
|
|
||||||
final private GSMetadataEncoder metadata = new GSMetadataEncoder();
|
final private GSMetadataEncoder metadata = new GSMetadataEncoder();
|
||||||
|
|
||||||
final private Element keywordsListEncoder = new Element(KEYWORDS);
|
final private Element keywordsListEncoder = new Element(KEYWORDS);
|
||||||
|
|
||||||
|
final private Element metadataLinksListEncoder = new Element(METADATALINKS);
|
||||||
|
|
||||||
private class GSMetadataEncoder extends NestedElementEncoder {
|
private class GSMetadataEncoder extends NestedElementEncoder {
|
||||||
public GSMetadataEncoder() {
|
public GSMetadataEncoder() {
|
||||||
super(METADATA);
|
super(METADATA);
|
||||||
@ -63,8 +74,7 @@ public abstract class GSResourceEncoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param rootName
|
* @param rootName Actually 'feature' or 'coverage'
|
||||||
* Actually 'feature' or 'coverage'
|
|
||||||
* @see GSFeatureTypeEncoder
|
* @see GSFeatureTypeEncoder
|
||||||
* @see GSCoverageEncoder
|
* @see GSCoverageEncoder
|
||||||
*/
|
*/
|
||||||
@ -75,45 +85,106 @@ public abstract class GSResourceEncoder
|
|||||||
// Link members to the parent
|
// Link members to the parent
|
||||||
addContent(metadata.getRoot());
|
addContent(metadata.getRoot());
|
||||||
addContent(keywordsListEncoder);
|
addContent(keywordsListEncoder);
|
||||||
|
addContent(metadataLinksListEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
set("enabled", (enabled) ? "true" : "false");
|
set("enabled", (enabled) ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO MetadataLink
|
|
||||||
// public void setMetadata(String key, String url){
|
|
||||||
// metadata.set(key, url);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key
|
* @param key
|
||||||
* @param dimensionInfo
|
* @param dimensionInfo
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
*/
|
||||||
protected void addMetadata(String key, XmlElement dimensionInfo) {
|
protected void addMetadata(String key, XmlElement dimensionInfo) {
|
||||||
metadata.add(key, dimensionInfo.getRoot());
|
metadata.add(key, dimensionInfo.getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setMetadata(String key, XmlElement dimensionInfo) {
|
/**
|
||||||
|
* @deprecated Use {@link #setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be set as protected for internal use only
|
||||||
|
* @param key
|
||||||
|
* @param dimensionInfo
|
||||||
|
*/
|
||||||
|
public void setMetadata(String key, XmlElement dimensionInfo) {
|
||||||
metadata.set(key, dimensionInfo.getRoot());
|
metadata.set(key, dimensionInfo.getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key
|
* @param key
|
||||||
* the name of the metadata to add (f.e.: elevation, time)
|
* @param dimensionInfo
|
||||||
|
*/
|
||||||
|
protected void addMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo) {
|
||||||
|
addMetadataDimension(key, dimensionInfo, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the metadata for a custom dimension.
|
||||||
|
*
|
||||||
|
* @param key the name of the dimension
|
||||||
|
* @param dimensionInfo {@link GSDimensionInfoEncoder} with additional information about the dimension
|
||||||
|
* @param custom is the dimension custom or not?
|
||||||
|
*/
|
||||||
|
protected void addMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo,
|
||||||
|
boolean custom) {
|
||||||
|
if (custom) {
|
||||||
|
metadata.set("custom_dimension_" + key.toUpperCase(), dimensionInfo.getRoot());
|
||||||
|
} else {
|
||||||
|
metadata.add(key, dimensionInfo.getRoot());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo) {
|
||||||
|
setMetadataDimension(key, dimensionInfo, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadataString(String key, String value) {
|
||||||
|
metadata.set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the metadata for a custom dimension.
|
||||||
|
*
|
||||||
|
* @param key the name of the dimension
|
||||||
|
* @param dimensionInfo {@link GSDimensionInfoEncoder} with additional information about the dimension
|
||||||
|
* @param custom is the dimension custom or not?
|
||||||
|
*/
|
||||||
|
public void setMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo,
|
||||||
|
boolean custom) {
|
||||||
|
if (custom) {
|
||||||
|
metadata.set("custom_dimension_" + key.toUpperCase(), dimensionInfo.getRoot());
|
||||||
|
} else {
|
||||||
|
metadata.set(key, dimensionInfo.getRoot());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key the name of the metadata to add (f.e.: elevation, time)
|
||||||
* @return true if something is removed, false otherwise
|
* @return true if something is removed, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean delMetadata(String key) {
|
public boolean delMetadata(String key) {
|
||||||
return metadata.remove(key);
|
return metadata.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addKeyword(String keyword) {
|
public void addKeyword(String keyword) {
|
||||||
final Element el = new Element("string");
|
checkKeyword(keyword);
|
||||||
el.setText(keyword);
|
putKeyword(keyword);
|
||||||
keywordsListEncoder.addContent(el);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code
|
||||||
|
* <keywords>
|
||||||
|
* <string>WCS</string>
|
||||||
|
* <string>ImageMosaic</string>
|
||||||
|
* <string>srtm30</string> <string> KEYWORD}\@language={LANGUAGE}\;\@vocabulary={VOCABULARY}\;</string>
|
||||||
|
* <string>{KEYWORD_2}\@vocabulary={VOCABULARY_2}\;</string> <string>{KEYWORD_3}\@language={LANGUAGE_3}\;</string> </keywords> }
|
||||||
|
*
|
||||||
|
* @param keyword mandatory keyword ('\' characters are not permitted)
|
||||||
|
* @param language optional parameter
|
||||||
|
* @param vocabulary optional parameter
|
||||||
|
*/
|
||||||
|
public void addKeyword(final String keyword, final String language, final String vocabulary) {
|
||||||
|
checkKeyword(keyword);
|
||||||
|
putKeyword(buildKeyword(keyword, language, vocabulary));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,13 +194,28 @@ public abstract class GSResourceEncoder
|
|||||||
* @return true if something is removed, false otherwise
|
* @return true if something is removed, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean delKeyword(final String keyword) {
|
public boolean delKeyword(final String keyword) {
|
||||||
final Element el = new Element("string");
|
return removeKeyword(keyword, null, null);
|
||||||
el.setText(keyword);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete a keyword from the list
|
||||||
|
*
|
||||||
|
* @param keyword
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delKeyword(final String keyword, final String language, final String vocabulary) {
|
||||||
|
return removeKeyword(keyword, language, vocabulary);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeKeyword(final String keyword, final String language,
|
||||||
|
final String vocabulary) {
|
||||||
|
checkKeyword(keyword);
|
||||||
|
final String text = buildKeyword(keyword, language, vocabulary);
|
||||||
return (keywordsListEncoder.removeContent(new Filter() {
|
return (keywordsListEncoder.removeContent(new Filter() {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public boolean matches(Object obj) {
|
public boolean matches(Object obj) {
|
||||||
if (((Element) obj).getText().equals(keyword)) {
|
if (((Element) obj).getText().equals(text)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -137,11 +223,81 @@ public abstract class GSResourceEncoder
|
|||||||
})).size() == 0 ? false : true;
|
})).size() == 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putKeyword(String keyword) {
|
||||||
|
final Element el = new Element("string");
|
||||||
|
el.setText(keyword);
|
||||||
|
keywordsListEncoder.addContent(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkKeyword(String keyword) {
|
||||||
|
if (keyword == null || keyword.isEmpty() || keyword.contains("\\")) {
|
||||||
|
throw new IllegalArgumentException("keyword may not be null, empty or contains '\'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildKeyword(final String keyword, final String language, final String vocabulary) {
|
||||||
|
StringBuilder sb = new StringBuilder(keyword);
|
||||||
|
// \@language={LANGUAGE_3}\;
|
||||||
|
if (language != null && !language.isEmpty()) {
|
||||||
|
sb.append("\\@language=").append(language).append("\\;");
|
||||||
|
}
|
||||||
|
// \@vocabulary={VOCABULARY}\;
|
||||||
|
if (vocabulary != null && !vocabulary.isEmpty()) {
|
||||||
|
sb.append("\\@vocabulary=").append(vocabulary).append("\\;");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
* Adds a MetadataLinkInfo to the GeoServer Resource
|
||||||
|
*
|
||||||
|
* @param MetadataLink
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void addMetadataLinkInfo(GSMetadataLinkInfoEncoder metadataLinkInfo) {
|
||||||
|
metadataLinksListEncoder.addContent(metadataLinkInfo.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds quickly a MetadataLinkInfo to the GeoServer Resource
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param metadataType
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
public void addMetadataLinkInfo(String type, String metadataType, String content) {
|
||||||
|
final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder(type, metadataType,
|
||||||
|
content);
|
||||||
|
metadataLinksListEncoder.addContent(mde.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a metadataLinkInfo from the list using the metadataURL (MetadataLinkInfo content)
|
||||||
|
*
|
||||||
|
* @param metadataURL
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delMetadataLinkInfo(final String metadataURL) {
|
||||||
|
return (metadataLinksListEncoder.removeContent(GSMetadataLinkInfoEncoder
|
||||||
|
.getFilterByContent(metadataURL))).size() == 0 ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reprojection policy for a published layer. One of:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link #REPROJECT_TO_DECLARED} Reproject from native to declared CRS
|
||||||
|
* <li>{@link #FORCE_DECLARED} Use the declared CRS (ignore native)
|
||||||
|
* <li>{@link #NONE} No reprojection (use native CRS)
|
||||||
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public enum ProjectionPolicy {
|
public enum ProjectionPolicy {
|
||||||
REPROJECT_TO_DECLARED, FORCE_DECLARED, NONE
|
/** Reproject from native to declared CRS */
|
||||||
|
REPROJECT_TO_DECLARED,
|
||||||
|
/** Use the declared CRS (ignore native) */
|
||||||
|
FORCE_DECLARED,
|
||||||
|
/** Keep native */
|
||||||
|
NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String PROJECTIONPOLICY = "projectionPolicy";
|
private final static String PROJECTIONPOLICY = "projectionPolicy";
|
||||||
@ -149,10 +305,8 @@ public abstract class GSResourceEncoder
|
|||||||
/**
|
/**
|
||||||
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
||||||
*
|
*
|
||||||
* @deprecated use the setProjectionPolicy. <br>
|
|
||||||
* This method will be set as protected in the next release
|
|
||||||
*/
|
*/
|
||||||
public void addProjectionPolicy(ProjectionPolicy policy) {
|
protected void addProjectionPolicy(ProjectionPolicy policy) {
|
||||||
add(PROJECTIONPOLICY, policy.toString());
|
add(PROJECTIONPOLICY, policy.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,10 +321,8 @@ public abstract class GSResourceEncoder
|
|||||||
* Add the 'name' node with a text value from 'name'
|
* Add the 'name' node with a text value from 'name'
|
||||||
*
|
*
|
||||||
* @note REQUIRED to configure a resource
|
* @note REQUIRED to configure a resource
|
||||||
* @deprecated use the setName. <br>
|
|
||||||
* This method will be set as protected in the next release
|
|
||||||
*/
|
*/
|
||||||
public void addName(final String name) {
|
protected void addName(final String name) {
|
||||||
add(NAME, name);
|
add(NAME, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,22 +336,86 @@ public abstract class GSResourceEncoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
final Element nameNode = get(NAME);
|
final Element nameNode = ElementUtils.contains(getRoot(), NAME, 1);
|
||||||
if (nameNode != null)
|
if (nameNode != null)
|
||||||
return nameNode.getText();
|
return nameNode.getText();
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'nativename' node with a text value from 'name'
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected void addNativeName(final String nativename) {
|
||||||
|
add(NATIVENAME, nativename);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set or modify the 'nativename' node with a text value from 'name'
|
||||||
|
*
|
||||||
|
* @note if not specified, the nativeName will be set with the value of the 'name' node.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setNativeName(final String nativename) {
|
||||||
|
set(NATIVENAME, nativename);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the nativeName
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getNativeName() {
|
||||||
|
final Element nameNode = ElementUtils.contains(getRoot(), NATIVENAME, 1);
|
||||||
|
if (nameNode != null)
|
||||||
|
return nameNode.getText();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static String DESCRIPTION = "description";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'description' node with a text value from 'description'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected void addDescription(final String description) {
|
||||||
|
add(DESCRIPTION, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set or modify the 'description' node with a text value from 'description'
|
||||||
|
*/
|
||||||
|
public void setDescription(final String description) {
|
||||||
|
set(DESCRIPTION, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static String ABSTRACT = "abstract";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'abstract' node with a text value from 'abstract'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected void addAbstract(final String _abstract) {
|
||||||
|
add(ABSTRACT, _abstract);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set or modify the 'abstract' node with a text value from 'abstract'
|
||||||
|
*/
|
||||||
|
public void setAbstract(final String _abstract) {
|
||||||
|
set(ABSTRACT, _abstract);
|
||||||
|
}
|
||||||
|
|
||||||
private final static String TITLE = "title";
|
private final static String TITLE = "title";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the 'title' node with a text value from 'title'
|
* Add the 'title' node with a text value from 'title'
|
||||||
*
|
*
|
||||||
* @deprecated use the setTitle. <br>
|
|
||||||
* This method will be set as protected in the next release
|
|
||||||
*/
|
*/
|
||||||
public void addTitle(final String title) {
|
protected void addTitle(final String title) {
|
||||||
add(TITLE, title);
|
add(TITLE, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,11 +430,8 @@ public abstract class GSResourceEncoder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the 'SRS' node with a text value from 'srs'
|
* Add the 'SRS' node with a text value from 'srs'
|
||||||
*
|
|
||||||
* @deprecated use the setSRS. <br>
|
|
||||||
* This method will be set as protected in the next release
|
|
||||||
*/
|
*/
|
||||||
public void addSRS(final String srs) {
|
protected void addSRS(final String srs) {
|
||||||
add(SRS, srs);
|
add(SRS, srs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,15 +442,33 @@ public abstract class GSResourceEncoder
|
|||||||
set(SRS, srs);
|
set(SRS, srs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final static String NATIVECRS = "nativeCRS";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'nativeCRS' node with a text value from 'nativeCRS'
|
||||||
|
*/
|
||||||
|
protected void addNativeCRS(final String nativeCRS) {
|
||||||
|
add(NATIVECRS, nativeCRS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set or modify the 'nativeCRS' node with a text value from 'nativeCRS'
|
||||||
|
*/
|
||||||
|
public void setNativeCRS(final String nativeCRS) {
|
||||||
|
set(NATIVECRS, nativeCRS);
|
||||||
|
}
|
||||||
|
|
||||||
private final static String LATLONBBMINX = "latLonBoundingBox/minx";
|
private final static String LATLONBBMINX = "latLonBoundingBox/minx";
|
||||||
|
|
||||||
private final static String LATLONBBMAXX = "latLonBoundingBox/maxx";
|
private final static String LATLONBBMAXX = "latLonBoundingBox/maxx";
|
||||||
|
|
||||||
private final static String LATLONBBMINY = "latLonBoundingBox/miny";
|
private final static String LATLONBBMINY = "latLonBoundingBox/miny";
|
||||||
|
|
||||||
private final static String LATLONBBMAXY = "latLonBoundingBox/maxy";
|
private final static String LATLONBBMAXY = "latLonBoundingBox/maxy";
|
||||||
|
|
||||||
private final static String LATLONBBCRS = "latLonBoundingBox/crs";
|
private final static String LATLONBBCRS = "latLonBoundingBox/crs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use the setSRS. <br>
|
|
||||||
* This method will be set as protected in the next release
|
|
||||||
*
|
*
|
||||||
* @param minx
|
* @param minx
|
||||||
* @param maxy
|
* @param maxy
|
||||||
@ -245,8 +476,8 @@ public abstract class GSResourceEncoder
|
|||||||
* @param miny
|
* @param miny
|
||||||
* @param crs
|
* @param crs
|
||||||
*/
|
*/
|
||||||
public void addLatLonBoundingBox(double minx, double miny, double maxx,
|
protected void addLatLonBoundingBox(double minx, double miny, double maxx, double maxy,
|
||||||
double maxy, final String crs) {
|
final String crs) {
|
||||||
add(LATLONBBMINX, String.valueOf(minx));
|
add(LATLONBBMINX, String.valueOf(minx));
|
||||||
add(LATLONBBMINY, String.valueOf(miny));
|
add(LATLONBBMINY, String.valueOf(miny));
|
||||||
add(LATLONBBMAXY, String.valueOf(maxy));
|
add(LATLONBBMAXY, String.valueOf(maxy));
|
||||||
@ -254,8 +485,8 @@ public abstract class GSResourceEncoder
|
|||||||
add(LATLONBBCRS, crs);
|
add(LATLONBBCRS, crs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLatLonBoundingBox(double minx, double miny, double maxx,
|
public void setLatLonBoundingBox(double minx, double miny, double maxx, double maxy,
|
||||||
double maxy, final String crs) {
|
final String crs) {
|
||||||
set(LATLONBBMINX, String.valueOf(minx));
|
set(LATLONBBMINX, String.valueOf(minx));
|
||||||
set(LATLONBBMAXY, String.valueOf(maxy));
|
set(LATLONBBMAXY, String.valueOf(maxy));
|
||||||
set(LATLONBBMAXX, String.valueOf(maxx));
|
set(LATLONBBMAXX, String.valueOf(maxx));
|
||||||
@ -264,23 +495,24 @@ public abstract class GSResourceEncoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final static String NATIVEBBMINX = "nativeBoundingBox/minx";
|
private final static String NATIVEBBMINX = "nativeBoundingBox/minx";
|
||||||
|
|
||||||
private final static String NATIVEBBMAXX = "nativeBoundingBox/maxx";
|
private final static String NATIVEBBMAXX = "nativeBoundingBox/maxx";
|
||||||
|
|
||||||
private final static String NATIVEBBMINY = "nativeBoundingBox/miny";
|
private final static String NATIVEBBMINY = "nativeBoundingBox/miny";
|
||||||
|
|
||||||
private final static String NATIVEBBMAXY = "nativeBoundingBox/maxy";
|
private final static String NATIVEBBMAXY = "nativeBoundingBox/maxy";
|
||||||
|
|
||||||
private final static String NATIVEBBCRS = "nativeBoundingBox/crs";
|
private final static String NATIVEBBCRS = "nativeBoundingBox/crs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use the setSRS. <br>
|
|
||||||
* This method will be set as protected in the next release
|
|
||||||
*
|
|
||||||
* @param minx
|
* @param minx
|
||||||
* @param maxy
|
* @param maxy
|
||||||
* @param maxx
|
* @param maxx
|
||||||
* @param miny
|
* @param miny
|
||||||
* @param crs
|
* @param crs
|
||||||
*/
|
*/
|
||||||
public void addNativeBoundingBox(double minx, double miny, double maxx,
|
protected void addNativeBoundingBox(double minx, double miny, double maxx, double maxy,
|
||||||
double maxy, final String crs) {
|
final String crs) {
|
||||||
add(NATIVEBBMINX, String.valueOf(minx));
|
add(NATIVEBBMINX, String.valueOf(minx));
|
||||||
add(NATIVEBBMAXY, String.valueOf(maxy));
|
add(NATIVEBBMAXY, String.valueOf(maxy));
|
||||||
add(NATIVEBBMAXX, String.valueOf(maxx));
|
add(NATIVEBBMAXX, String.valueOf(maxx));
|
||||||
@ -288,8 +520,8 @@ public abstract class GSResourceEncoder
|
|||||||
add(NATIVEBBCRS, crs);
|
add(NATIVEBBCRS, crs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNativeBoundingBox(double minx, double miny, double maxx,
|
public void setNativeBoundingBox(double minx, double miny, double maxx, double maxy,
|
||||||
double maxy, final String crs) {
|
final String crs) {
|
||||||
set(NATIVEBBMINX, String.valueOf(minx));
|
set(NATIVEBBMINX, String.valueOf(minx));
|
||||||
set(NATIVEBBMAXY, String.valueOf(maxy));
|
set(NATIVEBBMAXY, String.valueOf(maxy));
|
||||||
set(NATIVEBBMAXX, String.valueOf(maxx));
|
set(NATIVEBBMAXX, String.valueOf(maxx));
|
||||||
|
|||||||
@ -25,11 +25,11 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.encoder;
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
import org.jdom.Element;
|
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ETj (etj at geo-solutions.it)
|
* @author ETj (etj at geo-solutions.it)
|
||||||
@ -55,9 +55,8 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
|||||||
* Add the name to this workspace
|
* Add the name to this workspace
|
||||||
* @param name
|
* @param name
|
||||||
* @throws IllegalStateException if name is already set
|
* @throws IllegalStateException if name is already set
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
*/
|
||||||
public void addName(final String name) {
|
protected void addName(final String name) {
|
||||||
final Element el=ElementUtils.contains(getRoot(),NAME);
|
final Element el=ElementUtils.contains(getRoot(),NAME);
|
||||||
if (el==null)
|
if (el==null)
|
||||||
add(NAME, name);
|
add(NAME, name);
|
||||||
|
|||||||
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.authorityurl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of layer authorityURL members
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum AuthorityURLInfo {
|
||||||
|
|
||||||
|
name, href;
|
||||||
|
}
|
||||||
@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.authorityurl;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GSAuthorityURLInfoEncoder - encodes an authorityURL for a given GeoServer
|
||||||
|
* layer as follows:
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* final GSAuthorityURLInfoEncoder ae = new GSAuthorityURLInfoEncoder();
|
||||||
|
* ae.setName("an authority");
|
||||||
|
* ae.setHref("http://www.organization.org");
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* For this example, the XML output is:
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <AuthorityURL>
|
||||||
|
* <name>an authority</name>
|
||||||
|
* <href>http://www.organization.org</href>
|
||||||
|
* </AuthorityURL>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSAuthorityURLInfoEncoder extends XmlElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to filter the AuthorityURL by href
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static class filterByHref implements Filter {
|
||||||
|
|
||||||
|
final private String key;
|
||||||
|
|
||||||
|
public filterByHref(String href) {
|
||||||
|
this.key = href;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
Element el = ((Element) obj).getChild(AuthorityURLInfo.href
|
||||||
|
.toString());
|
||||||
|
if (el != null && el.getTextTrim().equals(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Filter using the AuthorityURLInfo href (authorityURL)
|
||||||
|
*
|
||||||
|
* @param href
|
||||||
|
* @return the filter
|
||||||
|
*/
|
||||||
|
public static Filter getFilterByHref(String href) {
|
||||||
|
return new filterByHref(href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new GSAuthorityURLInfoEncoder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GSAuthorityURLInfoEncoder() {
|
||||||
|
super("AuthorityURL");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs quickly an AuthorityURL info
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* (required)
|
||||||
|
* @param href
|
||||||
|
* (required)
|
||||||
|
*/
|
||||||
|
public GSAuthorityURLInfoEncoder(String name, String href) {
|
||||||
|
super("AuthorityURL");
|
||||||
|
this.setup(name, href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set-up quickly an AuthorityURL info
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param href
|
||||||
|
*/
|
||||||
|
protected void setup(String name, String href) {
|
||||||
|
set(AuthorityURLInfo.name.name(), name);
|
||||||
|
set(AuthorityURLInfo.href.name(), href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an AuthorityURLInfo member (name, href)
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
protected void setMember(AuthorityURLInfo type, String value) {
|
||||||
|
set(type.toString(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the name
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.setMember(AuthorityURLInfo.name, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the href
|
||||||
|
*
|
||||||
|
* @param href
|
||||||
|
*/
|
||||||
|
public void setHref(String href) {
|
||||||
|
this.setMember(AuthorityURLInfo.href, href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an AuthorityURLInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return true if the AuthorityURLInfo member is removed
|
||||||
|
*/
|
||||||
|
protected boolean delMember(AuthorityURLInfo type) {
|
||||||
|
return ElementUtils.remove(this.getRoot(),
|
||||||
|
this.getRoot().getChild(type.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the authority name
|
||||||
|
*
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delName() {
|
||||||
|
return this.delMember(AuthorityURLInfo.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the href
|
||||||
|
*
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delHref() {
|
||||||
|
return this.delMember(AuthorityURLInfo.href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the AuthorityURLInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return the value of the AuthorityURLInfo member
|
||||||
|
*/
|
||||||
|
protected String getMember(AuthorityURLInfo type) {
|
||||||
|
Element el = this.getRoot().getChild(type.toString());
|
||||||
|
if (el != null)
|
||||||
|
return el.getTextTrim();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return this.getMember(AuthorityURLInfo.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the href
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getHref() {
|
||||||
|
return this.getMember(AuthorityURLInfo.href);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.coverage;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic CoverageStore encoder.
|
||||||
|
*
|
||||||
|
* Provides getters and setters for parameters common to all CoverageStore.
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - GeoSolutions
|
||||||
|
*
|
||||||
|
* @deprecated TODO complete specialization
|
||||||
|
*/
|
||||||
|
public abstract class GSAbstractCoveragestoreEncoder extends GSAbstractStoreEncoder {
|
||||||
|
|
||||||
|
protected GSAbstractCoveragestoreEncoder(String storeName) {
|
||||||
|
super(StoreType.COVERAGESTORES,storeName);
|
||||||
|
// Add mandatory parameter
|
||||||
|
ensureValidName(storeName);
|
||||||
|
setName(storeName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -25,10 +25,12 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.encoder.coverage;
|
package it.geosolutions.geoserver.rest.encoder.coverage;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
import org.jdom.Element;
|
||||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
|
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an XML
|
* Creates an XML
|
||||||
@ -37,22 +39,147 @@ import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEnc
|
|||||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GSCoverageEncoder extends GSResourceEncoder/*<GSDimensionInfoEncoder>*/ {
|
public class GSCoverageEncoder extends GSResourceEncoder {
|
||||||
|
|
||||||
|
public final static String NATIVECOVERAGENAME = "nativeCoverageName";
|
||||||
|
|
||||||
|
private final static String NATIVE_FORMAT="nativeFormat";
|
||||||
|
private final static String SUPPORTED_FORMATS="supportedFormats";
|
||||||
|
|
||||||
|
private final static String REQUEST_SRS="requestSRS";
|
||||||
|
private final static String RESPONSE_SRS="responseSRS";
|
||||||
|
|
||||||
|
private final Element supportedFormatsListEncoder = new Element(SUPPORTED_FORMATS);
|
||||||
|
public final static String DIMENSIONS = "dimensions";
|
||||||
|
|
||||||
|
final private Element dimensionsEncoder = new Element(DIMENSIONS);
|
||||||
|
|
||||||
public GSCoverageEncoder() {
|
public GSCoverageEncoder() {
|
||||||
super("coverage");
|
super("coverage");
|
||||||
|
addContent(supportedFormatsListEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key
|
* @param key
|
||||||
* @param dimensionInfo
|
* @param dimensionInfo
|
||||||
* @deprecated will be set to protected in the next release
|
* @deprecated Use {@link GSResourceEncoder#addMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
|
||||||
*/
|
*/
|
||||||
public void addMetadata(String key, GSDimensionInfoEncoder dimensionInfo) {
|
protected void addMetadata(String key, GSDimensionInfoEncoder dimensionInfo) {
|
||||||
super.addMetadata(key, dimensionInfo);
|
super.addMetadata(key, dimensionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link GSResourceEncoder#setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
|
||||||
|
* @param key
|
||||||
|
* @param dimensionInfo
|
||||||
|
*/
|
||||||
public void setMetadata(String key, GSDimensionInfoEncoder dimensionInfo) {
|
public void setMetadata(String key, GSDimensionInfoEncoder dimensionInfo) {
|
||||||
super.setMetadata(key, dimensionInfo);
|
super.setMetadata(key, dimensionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'nativeFormat' node with a text value
|
||||||
|
*/
|
||||||
|
public void setNativeFormat(String format) {
|
||||||
|
set(NATIVE_FORMAT, format);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'supportedFormat' node with a text value
|
||||||
|
*/
|
||||||
|
public void addSupportedFormats(String format) {
|
||||||
|
final Element el = new Element("string");
|
||||||
|
el.setText(format);
|
||||||
|
supportedFormatsListEncoder.addContent(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'requestSRS' node with a text value
|
||||||
|
*/
|
||||||
|
public void setRequestSRS(String srs) {
|
||||||
|
final Element el = new Element("string");
|
||||||
|
el.setText(srs);
|
||||||
|
set(REQUEST_SRS, el);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'responseSRS' node with a text value
|
||||||
|
*/
|
||||||
|
public void setResponseSRS(String srs) {
|
||||||
|
final Element el = new Element("string");
|
||||||
|
el.setText(srs);
|
||||||
|
set(RESPONSE_SRS, el);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a CoverageDimensionInfo to the GeoServer Resource
|
||||||
|
*
|
||||||
|
* @param coverageDimensionInfo
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void addCoverageDimensionInfo(GSCoverageDimensionEncoder coverageDimensionInfo) {
|
||||||
|
if (ElementUtils.contains(getRoot(), DIMENSIONS) == null)
|
||||||
|
addContent(dimensionsEncoder);
|
||||||
|
dimensionsEncoder.addContent(coverageDimensionInfo.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds quickly a CoverageDimensionInfo to the GeoServer Resource
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param description
|
||||||
|
* @param rangeMin
|
||||||
|
* @param rangeMax
|
||||||
|
* @param unit
|
||||||
|
* @param dimensionType
|
||||||
|
*/
|
||||||
|
public void addCoverageDimensionInfo(String name, String description, String rangeMin,
|
||||||
|
String rangeMax, String unit, String dimensionType) {
|
||||||
|
final GSCoverageDimensionEncoder coverageDimensionEncoder = new GSCoverageDimensionEncoder(
|
||||||
|
name, description, rangeMin, rangeMax, unit, dimensionType);
|
||||||
|
addCoverageDimensionInfo(coverageDimensionEncoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a CoverageDimensionInfo from the list using the CoverageDimension Name (CoverageDimensionInfo content)
|
||||||
|
*
|
||||||
|
* @param coverageDimensionName
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delCoverageDimensionInfo(final String coverageDimensionName) {
|
||||||
|
return (dimensionsEncoder.removeContent(GSCoverageDimensionEncoder
|
||||||
|
.getFilterByContent(coverageDimensionName))).size() == 0 ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'nativeCoverageName' node with a text value from 'name'
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void addNativeCoverageName(final String nativeCoverageName) {
|
||||||
|
add(NATIVECOVERAGENAME, nativeCoverageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the 'nativeCoverageName' node with a text value from 'name'
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setNativeCoverageName(final String nativeCoverageName) {
|
||||||
|
set(NATIVECOVERAGENAME, nativeCoverageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the nativeCoverageName
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getNativeCoverageName() {
|
||||||
|
final Element nativeCoverageNameNode = ElementUtils.contains(getRoot(), NATIVECOVERAGENAME, 1);
|
||||||
|
if (nativeCoverageNameNode != null)
|
||||||
|
return nativeCoverageNameNode.getText();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,13 +35,17 @@ import org.jdom.Element;
|
|||||||
import org.jdom.filter.Filter;
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Use this encoder for ImageMosaic coverages.
|
||||||
*
|
*
|
||||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
* @author Simone Giannecchini, GeoSolutions SAS
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||||
|
|
||||||
final private static String STRING = "string";
|
final private static String STRING = "string";
|
||||||
|
|
||||||
final private static String ENTRY = "entry";
|
final private static String ENTRY = "entry";
|
||||||
|
|
||||||
final private NestedElementEncoder parameters = new NestedElementEncoder("parameters");
|
final private NestedElementEncoder parameters = new NestedElementEncoder("parameters");
|
||||||
@ -53,11 +57,13 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
|
|
||||||
static class parametersFilter implements Filter {
|
static class parametersFilter implements Filter {
|
||||||
final String name;
|
final String name;
|
||||||
|
|
||||||
public parametersFilter(final String name) {
|
public parametersFilter(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public boolean matches(Object obj) {
|
public boolean matches(Object obj) {
|
||||||
if (obj instanceof Element) {
|
if (obj instanceof Element) {
|
||||||
if (((Element) obj).getName().equals(ENTRY)) {
|
if (((Element) obj).getName().equals(ENTRY)) {
|
||||||
@ -85,12 +91,21 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String allowMultithreading="AllowMultithreading";
|
private final Element getParameter(final Filter filter) {
|
||||||
|
final Iterator<Element> it = ElementUtils.search(getRoot(), filter).iterator();
|
||||||
|
if (it.hasNext()) {
|
||||||
|
final Element el = it.next();
|
||||||
|
return ElementUtils.contains(el, el);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static String allowMultithreading = "AllowMultithreading";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addAllowMultithreading(final boolean val){
|
protected void addAllowMultithreading(final boolean val) {
|
||||||
final List<Element> list = new ArrayList<Element>(2);
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
list.add(new Element(STRING).setText(allowMultithreading));
|
list.add(new Element(STRING).setText(allowMultithreading));
|
||||||
list.add(new Element(STRING).setText((val) ? "true" : "false"));
|
list.add(new Element(STRING).setText((val) ? "true" : "false"));
|
||||||
@ -98,18 +113,37 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
parameters.add(null, list);
|
parameters.add(null, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter allowMultithreadingFilter=new parametersFilter(allowMultithreading);
|
private final static Filter allowMultithreadingFilter = new parametersFilter(
|
||||||
|
allowMultithreading);
|
||||||
|
|
||||||
public void setAllowMultithreading(final boolean val) {
|
public void setAllowMultithreading(final boolean val) {
|
||||||
removeParameter(allowMultithreadingFilter);
|
removeParameter(allowMultithreadingFilter);
|
||||||
addAllowMultithreading(val);
|
addAllowMultithreading(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String filter="Filter";
|
public Boolean getAllowMultithreading() {
|
||||||
|
Element el = getParameter(allowMultithreadingFilter);
|
||||||
|
if (el != null) {
|
||||||
|
List<Element> values = el.getChildren();
|
||||||
|
for (Element elm : values) {
|
||||||
|
String value = elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(allowMultithreading)) {
|
||||||
|
return Boolean.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filter
|
||||||
|
//
|
||||||
|
public final static String filter = "Filter";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addFilter(final String val){
|
protected void addFilter(final String val) {
|
||||||
final List<Element> list = new ArrayList<Element>(2);
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
list.add(new Element(STRING).setText(filter));
|
list.add(new Element(STRING).setText(filter));
|
||||||
list.add(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
@ -117,17 +151,34 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter filterFilter = new parametersFilter(filter);
|
private final static Filter filterFilter = new parametersFilter(filter);
|
||||||
|
|
||||||
public void setFilter(final String val) {
|
public void setFilter(final String val) {
|
||||||
removeParameter(filterFilter);
|
removeParameter(filterFilter);
|
||||||
addFilter(val);
|
addFilter(val);
|
||||||
}
|
}
|
||||||
|
public Boolean getFilter() {
|
||||||
|
Element el = getParameter(filterFilter);
|
||||||
|
if (el != null) {
|
||||||
|
List<Element> values = el.getChildren();
|
||||||
|
for (Element elm : values) {
|
||||||
|
String value = elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(filter)) {
|
||||||
|
return Boolean.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// MaxAllowedTiles
|
||||||
|
//
|
||||||
|
public final static String maxAllowedTiles = "MaxAllowedTiles";
|
||||||
|
|
||||||
private final static String maxAllowedTiles="MaxAllowedTiles";
|
|
||||||
/**
|
/**
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addMaxAllowedTiles(final int val){
|
protected void addMaxAllowedTiles(final int val) {
|
||||||
final List<Element> list = new ArrayList<Element>(2);
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
list.add(new Element(STRING).setText(maxAllowedTiles));
|
list.add(new Element(STRING).setText(maxAllowedTiles));
|
||||||
list.add(new Element(STRING).setText(String.valueOf(val)));
|
list.add(new Element(STRING).setText(String.valueOf(val)));
|
||||||
@ -135,72 +186,148 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter maxAllowedTilesFilter = new parametersFilter(maxAllowedTiles);
|
private final static Filter maxAllowedTilesFilter = new parametersFilter(maxAllowedTiles);
|
||||||
|
|
||||||
public void setMaxAllowedTiles(final int val) {
|
public void setMaxAllowedTiles(final int val) {
|
||||||
removeParameter(maxAllowedTilesFilter);
|
removeParameter(maxAllowedTilesFilter);
|
||||||
addMaxAllowedTiles(val);
|
addMaxAllowedTiles(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String inputTransparentColor="InputTransparentColor";
|
public Boolean getMaxAllowedTiles() {
|
||||||
|
Element el = getParameter(maxAllowedTilesFilter);
|
||||||
|
if (el != null) {
|
||||||
|
List<Element> values = el.getChildren();
|
||||||
|
for (Element elm : values) {
|
||||||
|
String value = elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(maxAllowedTiles)) {
|
||||||
|
return Boolean.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// InputTransparentColor
|
||||||
|
//
|
||||||
|
public final static String inputTransparentColor = "InputTransparentColor";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addInputTransparentColor(final String val){
|
protected void addInputTransparentColor(final String val) {
|
||||||
final List<Element> list = new ArrayList<Element>(2);
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
list.add(new Element(STRING).setText(inputTransparentColor));
|
list.add(new Element(STRING).setText(inputTransparentColor));
|
||||||
list.add(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
parameters.add(null, list);
|
parameters.add(null, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter inputTransparentColorFilter=new parametersFilter(inputTransparentColor);
|
private final static Filter inputTransparentColorFilter = new parametersFilter(
|
||||||
|
inputTransparentColor);
|
||||||
|
|
||||||
public void setInputTransparentColor(final String val) {
|
public void setInputTransparentColor(final String val) {
|
||||||
removeParameter(inputTransparentColorFilter);
|
removeParameter(inputTransparentColorFilter);
|
||||||
addInputTransparentColor(val);
|
addInputTransparentColor(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String outputTransparentColor="OutputTransparentColor";
|
public Boolean getInputTransparentColor() {
|
||||||
|
Element el = getParameter(inputTransparentColorFilter);
|
||||||
|
if (el != null) {
|
||||||
|
List<Element> values = el.getChildren();
|
||||||
|
for (Element elm : values) {
|
||||||
|
String value = elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(inputTransparentColor)) {
|
||||||
|
return Boolean.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// OutputTransparentColor
|
||||||
|
//
|
||||||
|
public final static String outputTransparentColor = "OutputTransparentColor";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addOutputTransparentColor(final String val){
|
protected void addOutputTransparentColor(final String val) {
|
||||||
final List<Element> list = new ArrayList<Element>(2);
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
list.add(new Element(STRING).setText(outputTransparentColor));
|
list.add(new Element(STRING).setText(outputTransparentColor));
|
||||||
list.add(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
parameters.add(null, list);
|
parameters.add(null, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter outputTransparentColorFilter=new parametersFilter(outputTransparentColor);
|
private final static Filter outputTransparentColorFilter = new parametersFilter(
|
||||||
|
outputTransparentColor);
|
||||||
|
|
||||||
public void setOutputTransparentColor(final String val) {
|
public void setOutputTransparentColor(final String val) {
|
||||||
removeParameter(outputTransparentColorFilter);
|
removeParameter(outputTransparentColorFilter);
|
||||||
addInputTransparentColor(val);
|
addInputTransparentColor(val);
|
||||||
}
|
}
|
||||||
|
public Boolean getOutputTransparentColor() {
|
||||||
|
Element el = getParameter(outputTransparentColorFilter);
|
||||||
|
if (el != null) {
|
||||||
|
List<Element> values = el.getChildren();
|
||||||
|
for (Element elm : values) {
|
||||||
|
String value = elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(outputTransparentColor)) {
|
||||||
|
return Boolean.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// SUGGESTED_TILE_SIZE
|
||||||
|
//
|
||||||
|
public final static String SUGGESTED_TILE_SIZE = "SUGGESTED_TILE_SIZE";
|
||||||
|
|
||||||
private final static String SUGGESTED_TILE_SIZE="SUGGESTED_TILE_SIZE";
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param val
|
* @param val
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
*/
|
*/
|
||||||
public void addSUGGESTED_TILE_SIZE(final String val){
|
protected void addSUGGESTED_TILE_SIZE(final String val) {
|
||||||
final List<Element> list = new ArrayList<Element>(2);
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
list.add(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
|
list.add(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
|
||||||
list.add(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
parameters.add(null, list);
|
parameters.add(null, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter SUGGESTED_TILE_SIZEFilter=new parametersFilter(SUGGESTED_TILE_SIZE);
|
private final static Filter SUGGESTED_TILE_SIZEFilter = new parametersFilter(
|
||||||
|
SUGGESTED_TILE_SIZE);
|
||||||
|
|
||||||
public void setSUGGESTED_TILE_SIZE(final String val) {
|
public void setSUGGESTED_TILE_SIZE(final String val) {
|
||||||
removeParameter(SUGGESTED_TILE_SIZEFilter);
|
removeParameter(SUGGESTED_TILE_SIZEFilter);
|
||||||
addSUGGESTED_TILE_SIZE(val);
|
addSUGGESTED_TILE_SIZE(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String USE_JAI_IMAGEREAD="USE_JAI_IMAGEREAD";
|
public String getSuggestedTileSize() {
|
||||||
|
Element el = getParameter(SUGGESTED_TILE_SIZEFilter);
|
||||||
|
if (el != null) {
|
||||||
|
List<Element> values = el.getChildren();
|
||||||
|
for (Element elm : values) {
|
||||||
|
String value = elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(SUGGESTED_TILE_SIZE)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// USE_JAI_IMAGEREAD
|
||||||
|
//
|
||||||
|
public final static String USE_JAI_IMAGEREAD = "USE_JAI_IMAGEREAD";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addUSE_JAI_IMAGEREAD(final boolean val){
|
protected void addUSE_JAI_IMAGEREAD(final boolean val) {
|
||||||
final List<Element> list = new ArrayList<Element>(2);
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
list.add(new Element(STRING).setText(USE_JAI_IMAGEREAD));
|
list.add(new Element(STRING).setText(USE_JAI_IMAGEREAD));
|
||||||
list.add(new Element(STRING).setText((val) ? "true" : "false"));
|
list.add(new Element(STRING).setText((val) ? "true" : "false"));
|
||||||
@ -208,17 +335,35 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter USE_JAI_IMAGEREADFilter = new parametersFilter(USE_JAI_IMAGEREAD);
|
private final static Filter USE_JAI_IMAGEREADFilter = new parametersFilter(USE_JAI_IMAGEREAD);
|
||||||
|
|
||||||
public void setUSE_JAI_IMAGEREAD(final boolean val) {
|
public void setUSE_JAI_IMAGEREAD(final boolean val) {
|
||||||
removeParameter(USE_JAI_IMAGEREADFilter);
|
removeParameter(USE_JAI_IMAGEREADFilter);
|
||||||
addUSE_JAI_IMAGEREAD(val);
|
addUSE_JAI_IMAGEREAD(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String backgroundValues="BackgroundValues";
|
public Boolean getUseJaiImageRead() {
|
||||||
|
Element el = getParameter(USE_JAI_IMAGEREADFilter);
|
||||||
|
if (el != null) {
|
||||||
|
List<Element> values = el.getChildren();
|
||||||
|
for (Element elm : values) {
|
||||||
|
String value = elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(USE_JAI_IMAGEREAD)) {
|
||||||
|
return Boolean.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// BackgroundValues
|
||||||
|
//
|
||||||
|
public final static String backgroundValues = "BackgroundValues";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated will be set to protected in the next release
|
|
||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addBackgroundValues(final String val){
|
protected void addBackgroundValues(final String val) {
|
||||||
final List<Element> list = new ArrayList<Element>(2);
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
list.add(new Element(STRING).setText(backgroundValues));
|
list.add(new Element(STRING).setText(backgroundValues));
|
||||||
list.add(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
@ -226,9 +371,67 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter backgroundValuesFilter = new parametersFilter(backgroundValues);
|
private final static Filter backgroundValuesFilter = new parametersFilter(backgroundValues);
|
||||||
|
|
||||||
public void setBackgroundValues(final String val) {
|
public void setBackgroundValues(final String val) {
|
||||||
removeParameter(backgroundValuesFilter);
|
removeParameter(backgroundValuesFilter);
|
||||||
addBackgroundValues(val);
|
addBackgroundValues(val);
|
||||||
}
|
}
|
||||||
|
public Boolean getBackgroundValues() {
|
||||||
|
Element el = getParameter(backgroundValuesFilter);
|
||||||
|
if (el != null) {
|
||||||
|
List<Element> values = el.getChildren();
|
||||||
|
for (Element elm : values) {
|
||||||
|
String value = elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(backgroundValues)) {
|
||||||
|
return Boolean.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// SORTING
|
||||||
|
//
|
||||||
|
public final static String SORTING = "SORTING";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param val
|
||||||
|
*/
|
||||||
|
protected void addSORTING(final String val) {
|
||||||
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
|
list.add(new Element(STRING).setText(SORTING));
|
||||||
|
list.add(new Element(STRING).setText(val));
|
||||||
|
parameters.add(null, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static Filter SORTING_FILTER = new parametersFilter(SORTING);
|
||||||
|
|
||||||
|
public void setSORTING(final String val) {
|
||||||
|
removeParameter(SORTING_FILTER);
|
||||||
|
addBackgroundValues(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// SORTING
|
||||||
|
//
|
||||||
|
|
||||||
|
public final static String MERGEBEHAVIOR = "MergeBehavior";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param val
|
||||||
|
*/
|
||||||
|
protected void addMergeBehavior(final String val) {
|
||||||
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
|
list.add(new Element(STRING).setText(MERGEBEHAVIOR));
|
||||||
|
list.add(new Element(STRING).setText(val));
|
||||||
|
parameters.add(null, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static Filter MERGEBEHAVIOR_FILTER = new parametersFilter(MERGEBEHAVIOR);
|
||||||
|
|
||||||
|
public void setMergeBehavior(final String val) {
|
||||||
|
removeParameter(MERGEBEHAVIOR_FILTER);
|
||||||
|
addBackgroundValues(val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,208 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.coverage;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be used to encode a Jpeg2K coverage.
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSJP2KEncoder extends GSCoverageEncoder {
|
||||||
|
|
||||||
|
final private static String STRING = "string";
|
||||||
|
|
||||||
|
final private static String ENTRY = "entry";
|
||||||
|
|
||||||
|
final private NestedElementEncoder parameters = new NestedElementEncoder("parameters");
|
||||||
|
|
||||||
|
public GSJP2KEncoder() {
|
||||||
|
// Link members to the parent
|
||||||
|
addContent(parameters.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
static class parametersFilter implements Filter {
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
public parametersFilter(final String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
if (obj instanceof Element) {
|
||||||
|
if (((Element) obj).getName().equals(ENTRY)) {
|
||||||
|
List<Element> values=((Element) obj).getChildren(STRING);
|
||||||
|
for (Element el : values){
|
||||||
|
if (el == null)
|
||||||
|
return false;
|
||||||
|
if (el.getText().equals(this.name)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// final Element el = ((Element) obj).getChild(STRING);
|
||||||
|
// if (el == null)
|
||||||
|
// return false;
|
||||||
|
// if (el.getText().equals(this.name)) {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final boolean removeParameter(final Filter filter) {
|
||||||
|
final Iterator<Element> it = ElementUtils.search(getRoot(), filter).iterator();
|
||||||
|
if (it.hasNext()) {
|
||||||
|
final Element el = it.next();
|
||||||
|
return ElementUtils.remove(el, el);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Element getParameter(final Filter filter) {
|
||||||
|
final Iterator<Element> it = ElementUtils.search(getRoot(), filter).iterator();
|
||||||
|
if (it.hasNext()) {
|
||||||
|
final Element el = it.next();
|
||||||
|
return ElementUtils.contains(el, el);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static String useMultithreading = "USE_MULTITHREADING";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param val
|
||||||
|
*/
|
||||||
|
protected void addUseMultithreading(final boolean val) {
|
||||||
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
|
list.add(new Element(STRING).setText(useMultithreading));
|
||||||
|
list.add(new Element(STRING).setText((val) ? "true" : "false"));
|
||||||
|
|
||||||
|
parameters.add(null, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static Filter useMultithreadingFilter = new parametersFilter(useMultithreading);
|
||||||
|
|
||||||
|
public void setUseMultithreading(final boolean val) {
|
||||||
|
removeParameter(useMultithreadingFilter);
|
||||||
|
addUseMultithreading(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getUseMultithreading() {
|
||||||
|
Element el=getParameter(useMultithreadingFilter);
|
||||||
|
if (el!=null){
|
||||||
|
List<Element> values=el.getChildren();
|
||||||
|
for (Element elm : values){
|
||||||
|
String value=elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(useMultithreading)){
|
||||||
|
return Boolean.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static String SUGGESTED_TILE_SIZE = "SUGGESTED_TILE_SIZE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param val
|
||||||
|
*/
|
||||||
|
protected void addSuggestedTileSize(final String val) {
|
||||||
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
|
list.add(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
|
||||||
|
list.add(new Element(STRING).setText(val));
|
||||||
|
parameters.add(null, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static Filter SUGGESTED_TILE_SIZEFilter = new parametersFilter(
|
||||||
|
SUGGESTED_TILE_SIZE);
|
||||||
|
|
||||||
|
public void setSuggestedTileSize(final String val) {
|
||||||
|
removeParameter(SUGGESTED_TILE_SIZEFilter);
|
||||||
|
addSuggestedTileSize(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSuggestedTileSize() {
|
||||||
|
Element el=getParameter(SUGGESTED_TILE_SIZEFilter);
|
||||||
|
if (el!=null){
|
||||||
|
List<Element> values=el.getChildren();
|
||||||
|
for (Element elm : values){
|
||||||
|
String value=elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(SUGGESTED_TILE_SIZE)){
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static String USE_JAI_IMAGEREAD = "USE_JAI_IMAGEREAD";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param val
|
||||||
|
*/
|
||||||
|
protected void addUseJaiImageRead(final boolean val) {
|
||||||
|
final List<Element> list = new ArrayList<Element>(2);
|
||||||
|
list.add(new Element(STRING).setText(USE_JAI_IMAGEREAD));
|
||||||
|
list.add(new Element(STRING).setText((val) ? "true" : "false"));
|
||||||
|
parameters.add(null, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static Filter USE_JAI_IMAGEREADFilter = new parametersFilter(USE_JAI_IMAGEREAD);
|
||||||
|
|
||||||
|
public void setUseJaiImageRead(final boolean val) {
|
||||||
|
removeParameter(USE_JAI_IMAGEREADFilter);
|
||||||
|
addUseJaiImageRead(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getUseJaiImageRead() {
|
||||||
|
Element el=getParameter(USE_JAI_IMAGEREADFilter);
|
||||||
|
if (el!=null){
|
||||||
|
List<Element> values=el.getChildren();
|
||||||
|
for (Element elm : values){
|
||||||
|
String value=elm.getValue();
|
||||||
|
if (!value.equalsIgnoreCase(USE_JAI_IMAGEREAD)){
|
||||||
|
return Boolean.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.datastore;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic Datastore encoder.
|
||||||
|
*
|
||||||
|
* Provides getters and setters for parameters common to all Datastores, an internal placeholder for specific connection parameters, and a constructor
|
||||||
|
* to read parameters from a {@link RESTDataStore}.
|
||||||
|
*
|
||||||
|
* @author Oscar Fonts
|
||||||
|
*/
|
||||||
|
public abstract class GSAbstractDatastoreEncoder extends GSAbstractStoreEncoder {
|
||||||
|
|
||||||
|
final static String ROOT = "dataStore";
|
||||||
|
|
||||||
|
NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters");
|
||||||
|
|
||||||
|
GSAbstractDatastoreEncoder(String storeName) {
|
||||||
|
super(GeoServerRESTPublisher.StoreType.DATASTORES, ROOT);
|
||||||
|
// Add mandatory parameter
|
||||||
|
ensureValidName(storeName);
|
||||||
|
setName(storeName);
|
||||||
|
|
||||||
|
// Add connection parameters
|
||||||
|
addContent(connectionParameters.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@value #TYPE} datastore encoder from a store read from server.
|
||||||
|
*
|
||||||
|
* @param store The existing store.
|
||||||
|
* @throws IllegalArgumentException if store type or mandatory parameters are not valid
|
||||||
|
*/
|
||||||
|
GSAbstractDatastoreEncoder(RESTDataStore store) {
|
||||||
|
this(store.getName());
|
||||||
|
|
||||||
|
// Match datastore type
|
||||||
|
ensureValidType(store.getStoreType());
|
||||||
|
|
||||||
|
// Copy store parameters
|
||||||
|
setDescription(store.getDescription());
|
||||||
|
setEnabled(store.isEnabled());
|
||||||
|
|
||||||
|
// Copy connection parameters - bulk
|
||||||
|
Map<String, String> params = store.getConnectionParameters();
|
||||||
|
for (String key : params.keySet()) {
|
||||||
|
connectionParameters.set(key, params.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of the implementing datastore.
|
||||||
|
*/
|
||||||
|
protected abstract String getValidType();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,217 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.datastore;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encoder for an {@value #TYPE} datastore.
|
||||||
|
*
|
||||||
|
* @author Gianni Barrotta
|
||||||
|
* @author Oscar Fonts
|
||||||
|
*/
|
||||||
|
public class GSArcSDEDatastoreEncoder extends GSAbstractDatastoreEncoder {
|
||||||
|
|
||||||
|
static final String TYPE = "ArcSDE";
|
||||||
|
|
||||||
|
static final String DEFAULT_DB_TYPE = "arcsde";
|
||||||
|
static final int DEFAULT_PORT = 5151;
|
||||||
|
static final int DEFAULT_MIN_CONNECTIONS = 2;
|
||||||
|
static final int DEFAULT_MAX_CONNECTIONS = 6;
|
||||||
|
static final int DEFAULT_CONNECTION_TIMEOUT = 500;
|
||||||
|
static final boolean DEFAULT_ALLOW_NON_SPATIAL_TABLES = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an {@value #TYPE} datastore with default connection parameters,
|
||||||
|
* given a store name, a server name, and a user name.
|
||||||
|
*
|
||||||
|
* The following default connection parameters are set:
|
||||||
|
* <ul>
|
||||||
|
* <li>dbtype: {@value #DEFAULT_DB_TYPE}
|
||||||
|
* <li>port: {@value #DEFAULT_PORT}
|
||||||
|
* <li>pool.minConnections: {@value #DEFAULT_MIN_CONNECTIONS}
|
||||||
|
* <li>pool.maxConnections: {@value #DEFAULT_MAX_CONNECTIONS}
|
||||||
|
* <li>pool.timeOut: {@value #DEFAULT_CONNECTION_TIMEOUT}
|
||||||
|
* <li>datastore.allowNonSpatialTables: {@value #DEFAULT_ALLOW_NON_SPATIAL_TABLES}
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param name New datastore name
|
||||||
|
* @param server New server name
|
||||||
|
* @param user New user name
|
||||||
|
*/
|
||||||
|
public GSArcSDEDatastoreEncoder(String name, String server, String user) {
|
||||||
|
super(name);
|
||||||
|
|
||||||
|
// Set mandatory parameters
|
||||||
|
setServer(server);
|
||||||
|
setUser(user);
|
||||||
|
|
||||||
|
// Set default values
|
||||||
|
setDbType(DEFAULT_DB_TYPE);
|
||||||
|
setPort(DEFAULT_PORT);
|
||||||
|
setMinConnections(DEFAULT_MIN_CONNECTIONS);
|
||||||
|
setMaxConnections(DEFAULT_MAX_CONNECTIONS);
|
||||||
|
setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
|
||||||
|
setAllowNonSpatialTables(DEFAULT_ALLOW_NON_SPATIAL_TABLES);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an {@value #TYPE} datastore encoder from an existing store read from server.
|
||||||
|
*
|
||||||
|
* @param store The existing store.
|
||||||
|
* @throws IllegalArgumentException if store type or mandatory parameters are not valid
|
||||||
|
*/
|
||||||
|
public GSArcSDEDatastoreEncoder(RESTDataStore store) {
|
||||||
|
super(store);
|
||||||
|
|
||||||
|
// Check mandatory parameter validity
|
||||||
|
ensureValidServer(store.getConnectionParameters().get("server"));
|
||||||
|
ensureValidUser(store.getConnectionParameters().get("user"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDbType(String dbtype) {
|
||||||
|
connectionParameters.set("dbtype", dbtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDbType() {
|
||||||
|
return ElementUtils.contains(connectionParameters.getRoot(), "dbtype").getTextTrim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServer(String server) {
|
||||||
|
ensureValidServer(server);
|
||||||
|
connectionParameters.set("server", server);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServer() {
|
||||||
|
return ElementUtils.contains(connectionParameters.getRoot(), "server").getTextTrim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
connectionParameters.set("port", Integer.toString(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return Integer.parseInt(ElementUtils.contains(connectionParameters.getRoot(), "port").getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstance(String instance) {
|
||||||
|
connectionParameters.set("instance", instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInstance() {
|
||||||
|
return ElementUtils.contains(connectionParameters.getRoot(), "instance").getTextTrim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(String user) {
|
||||||
|
ensureValidUser(user);
|
||||||
|
connectionParameters.set("user", user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return ElementUtils.contains(connectionParameters.getRoot(), "user").getTextTrim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
connectionParameters.set("password", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return ElementUtils.contains(connectionParameters.getRoot(), "password").getTextTrim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNamespace(String namespace) {
|
||||||
|
connectionParameters.set("namespace", namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNamespace() {
|
||||||
|
return ElementUtils.contains(connectionParameters.getRoot(), "namespace").getTextTrim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinConnections(int minConnections) {
|
||||||
|
connectionParameters.set("pool.minConnections", Integer.toString(minConnections));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinConnections() {
|
||||||
|
return Integer.parseInt(ElementUtils.contains(connectionParameters.getRoot(), "pool.minConnections").getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxConnections(int maxConnections) {
|
||||||
|
connectionParameters.set("pool.maxConnections", Integer.toString(maxConnections));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxConnections() {
|
||||||
|
return Integer.parseInt(ElementUtils.contains(connectionParameters.getRoot(), "pool.maxConnections").getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectionTimeout(int seconds) {
|
||||||
|
connectionParameters.set("pool.timeOut", Integer.toString(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getConnectionTimeout() {
|
||||||
|
return Integer.parseInt(ElementUtils.contains(connectionParameters.getRoot(), "pool.timeOut").getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowNonSpatialTables(boolean allowNonSpatialTables) {
|
||||||
|
connectionParameters.set("datastore.allowNonSpatialTables", Boolean.toString(allowNonSpatialTables));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAllowNonSpatialTables() {
|
||||||
|
return Boolean.parseBoolean(ElementUtils.contains(connectionParameters.getRoot(), "datastore.allowNonSpatialTables").getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check server validity.
|
||||||
|
*
|
||||||
|
* @param server the server name
|
||||||
|
* @throws IllegalArgumentException if server name is null or empty
|
||||||
|
*/
|
||||||
|
private static void ensureValidServer(String server) {
|
||||||
|
if (server == null || server.length() == 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"ArcSDE store server name cannot be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check user validity.
|
||||||
|
*
|
||||||
|
* @param user the user name
|
||||||
|
* @throws IllegalArgumentException if user name is null or empty
|
||||||
|
*/
|
||||||
|
private static void ensureValidUser(String user) {
|
||||||
|
if (user == null || user.length() == 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"ArcSDE store user name cannot be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@value #TYPE}
|
||||||
|
*/
|
||||||
|
protected String getValidType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.datastore;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encoder for a {@value #TYPE} datastore.
|
||||||
|
*
|
||||||
|
* @author Oscar Fonts
|
||||||
|
*/
|
||||||
|
public class GSDirectoryOfShapefilesDatastoreEncoder extends GSShapefileDatastoreEncoder {
|
||||||
|
|
||||||
|
static final String TYPE = "Directory of spatial files (shapefiles)";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@value #TYPE} datastore with default connection parameters, given a store name and a url (the store location).
|
||||||
|
*
|
||||||
|
* @param name New datastore name
|
||||||
|
* @param url The shapefile location in the server, relative to $GEOSERVER_DATA_DIR.
|
||||||
|
*/
|
||||||
|
public GSDirectoryOfShapefilesDatastoreEncoder(String name, URL url) {
|
||||||
|
super(name, url);
|
||||||
|
setType(TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@value #TYPE} datastore encoder from an existing store read from server.
|
||||||
|
*
|
||||||
|
* @param store The existing store.
|
||||||
|
* @throws IllegalArgumentException if store type or mandatory parameters are not valid
|
||||||
|
*/
|
||||||
|
public GSDirectoryOfShapefilesDatastoreEncoder(RESTDataStore store) {
|
||||||
|
super(store);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@value #TYPE}
|
||||||
|
*/
|
||||||
|
protected String getValidType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,199 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.datastore;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encoder for an {@value #TYPE} datastore.
|
||||||
|
*
|
||||||
|
* @author Gianni Barrotta
|
||||||
|
* @author Oscar Fonts
|
||||||
|
*/
|
||||||
|
public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
|
||||||
|
|
||||||
|
static final String TYPE = "Oracle NG";
|
||||||
|
|
||||||
|
static final String DEFAULT_DB_TYPE = "oracle";
|
||||||
|
static final int DEFAULT_MIN_CONNECTIONS = 1;
|
||||||
|
static final int DEFAULT_MAX_CONNECTIONS = 10;
|
||||||
|
static final int DEFAULT_FETCH_SIZE = 1000;
|
||||||
|
static final int DEFAULT_CONNECTION_TIMEOUT = 20;
|
||||||
|
static final boolean DEFAULT_LOOSE_BBOX = true;
|
||||||
|
static final boolean DEFAULT_PREPARED_STATEMENTS = true;
|
||||||
|
static final int DEFAULT_MAX_OPEN_PREPARED_STATEMENTS = 50;
|
||||||
|
static final boolean DEFAULT_ESTIMATED_EXTENDS = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an {@value #TYPE} datastore with default connection parameters,
|
||||||
|
* given a store name, and a database name.
|
||||||
|
*
|
||||||
|
* The following default connection parameters are set:
|
||||||
|
* <ul>
|
||||||
|
* <li>min connections: {@value #DEFAULT_MIN_CONNECTIONS}
|
||||||
|
* <li>max connections: {@value #DEFAULT_MAX_CONNECTIONS}
|
||||||
|
* <li>fetch size: {@value #DEFAULT_FETCH_SIZE}
|
||||||
|
* <li>Connection timeout: {@value #DEFAULT_CONNECTION_TIMEOUT}
|
||||||
|
* <li>Loose bbox: {@value #DEFAULT_LOOSE_BBOX}
|
||||||
|
* <li>preparedStatements: {@value #DEFAULT_PREPARED_STATEMENTS}
|
||||||
|
* <li>Max open prepared statements: {@value #DEFAULT_MAX_OPEN_PREPARED_STATEMENTS}
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param name New datastore name
|
||||||
|
* @param server New server name
|
||||||
|
* @param user New user name
|
||||||
|
*/
|
||||||
|
public GSOracleNGDatastoreEncoder(String name, String database) {
|
||||||
|
super(name);
|
||||||
|
|
||||||
|
// Set mandatory parameter
|
||||||
|
setType(TYPE);
|
||||||
|
setDatabaseType(DEFAULT_DB_TYPE);
|
||||||
|
setDatabase(database);
|
||||||
|
|
||||||
|
// Set default values
|
||||||
|
setMinConnections(DEFAULT_MIN_CONNECTIONS);
|
||||||
|
setMaxConnections(DEFAULT_MAX_CONNECTIONS);
|
||||||
|
setFetchSize(DEFAULT_FETCH_SIZE);
|
||||||
|
setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
|
||||||
|
setLooseBBox(DEFAULT_LOOSE_BBOX);
|
||||||
|
setPreparedStatements(DEFAULT_PREPARED_STATEMENTS);
|
||||||
|
setMaxOpenPreparedStatements(DEFAULT_MAX_OPEN_PREPARED_STATEMENTS);
|
||||||
|
setEstimatedExtends(DEFAULT_ESTIMATED_EXTENDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an {@value #TYPE} datastore encoder from an existing store read from server.
|
||||||
|
*
|
||||||
|
* @param store The existing store.
|
||||||
|
* @throws IllegalArgumentException if store type or mandatory parameters are not valid
|
||||||
|
*/
|
||||||
|
public GSOracleNGDatastoreEncoder(RESTDataStore store) {
|
||||||
|
super(store);
|
||||||
|
|
||||||
|
// Check mandatory parameter validity
|
||||||
|
ensureValidDatabase(store.getConnectionParameters().get("database"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
connectionParameters.set("host", host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
connectionParameters.set("port", Integer.toString(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNamespace(String namespace) {
|
||||||
|
connectionParameters.set("namespace", namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatabase(String database) {
|
||||||
|
connectionParameters.set("database", database);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchema(String schema) {
|
||||||
|
connectionParameters.set("schema", schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(String user) {
|
||||||
|
connectionParameters.set("user", user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
connectionParameters.set("passwd", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatabaseType(String dbtype) {
|
||||||
|
connectionParameters.set("dbtype", dbtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJndiReferenceName(String jndiReferenceName) {
|
||||||
|
connectionParameters.set("jndiReferenceName", jndiReferenceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExposePrimaryKeys(boolean exposePrimaryKeys) {
|
||||||
|
connectionParameters.set("Expose primary keys", Boolean.toString(exposePrimaryKeys));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxConnections(int maxConnections) {
|
||||||
|
connectionParameters.set("max connections", Integer.toString(maxConnections));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinConnections(int minConnections) {
|
||||||
|
connectionParameters.set("min connections", Integer.toString(minConnections));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFetchSize(int fetchSize) {
|
||||||
|
connectionParameters.set("fetch size", Integer.toString(fetchSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectionTimeout(int seconds) {
|
||||||
|
connectionParameters.set("Connection timeout", Integer.toString(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValidateConnections(boolean validateConnections) {
|
||||||
|
connectionParameters.set("validate connections", Boolean.toString(validateConnections));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
|
||||||
|
connectionParameters.set("Primary key metadata table", primaryKeyMetadataTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLooseBBox(boolean looseBBox) {
|
||||||
|
connectionParameters.set("Loose bbox", Boolean.toString(looseBBox));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreparedStatements(boolean preparedStatements) {
|
||||||
|
connectionParameters.set("preparedStatements", Boolean.toString(preparedStatements));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
|
||||||
|
connectionParameters.set("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEstimatedExtends(boolean estimatedExtends){
|
||||||
|
connectionParameters.set("Estimated extends", Boolean.toString(estimatedExtends));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check database validity.
|
||||||
|
*
|
||||||
|
* @param database the database name
|
||||||
|
* @throws IllegalArgumentException if database is null or empty
|
||||||
|
*/
|
||||||
|
private static void ensureValidDatabase(String database) {
|
||||||
|
if (database == null || database.length() == 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Oracle store database cannot be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@value #TYPE}
|
||||||
|
*/
|
||||||
|
protected String getValidType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,157 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.datastore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encoder for a {@value #TYPE} datastore.
|
||||||
|
*
|
||||||
|
* @author Eric Grosso
|
||||||
|
* @author ETj
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
* @author Oscar Fonts
|
||||||
|
*/
|
||||||
|
public class GSPostGISDatastoreEncoder extends GSAbstractDatastoreEncoder {
|
||||||
|
|
||||||
|
static final String TYPE = "PostGIS";
|
||||||
|
|
||||||
|
static final int DEFAULT_MIN_CONNECTIONS = 1;
|
||||||
|
static final int DEFAULT_MAX_CONNECTIONS = 10;
|
||||||
|
static final int DEFAULT_FETCH_SIZE = 1000;
|
||||||
|
static final int DEFAULT_CONNECTION_TIMEOUT = 20;
|
||||||
|
static final boolean DEFAULT_LOOSE_BBOX = true;
|
||||||
|
static final boolean DEFAULT_PREPARED_STATEMENTS = false;
|
||||||
|
static final int DEFAULT_MAX_OPEN_PREPARED_STATEMENTS = 50;
|
||||||
|
static final boolean DEFAULT_ESTIMATED_EXTENDS = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param name DataStore name
|
||||||
|
*/
|
||||||
|
public GSPostGISDatastoreEncoder(String name) {
|
||||||
|
super(name);
|
||||||
|
|
||||||
|
// Set mandatory parameter
|
||||||
|
setType(TYPE);
|
||||||
|
setDatabaseType("postgis");
|
||||||
|
|
||||||
|
// Set default values
|
||||||
|
setMinConnections(DEFAULT_MIN_CONNECTIONS);
|
||||||
|
setMaxConnections(DEFAULT_MAX_CONNECTIONS);
|
||||||
|
setFetchSize(DEFAULT_FETCH_SIZE);
|
||||||
|
setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
|
||||||
|
setLooseBBox(DEFAULT_LOOSE_BBOX);
|
||||||
|
setPreparedStatements(DEFAULT_PREPARED_STATEMENTS);
|
||||||
|
setMaxOpenPreparedStatements(DEFAULT_MAX_OPEN_PREPARED_STATEMENTS);
|
||||||
|
setEstimatedExtends(DEFAULT_ESTIMATED_EXTENDS);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNamespace(String namespace) {
|
||||||
|
connectionParameters.set("namespace", namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
connectionParameters.set("host", host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
connectionParameters.set("port", Integer.toString(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatabase(String database) {
|
||||||
|
connectionParameters.set("database", database);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchema(String schema) {
|
||||||
|
connectionParameters.set("schema", schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(String user) {
|
||||||
|
connectionParameters.set("user", user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
connectionParameters.set("passwd", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatabaseType(String dbtype) {
|
||||||
|
connectionParameters.set("dbtype", dbtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJndiReferenceName(String jndiReferenceName) {
|
||||||
|
connectionParameters.set("jndiReferenceName", jndiReferenceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExposePrimaryKeys(boolean exposePrimaryKeys) {
|
||||||
|
connectionParameters.set("Expose primary keys", Boolean.toString(exposePrimaryKeys));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxConnections(int maxConnections) {
|
||||||
|
connectionParameters.set("max connections", Integer.toString(maxConnections));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinConnections(int minConnections) {
|
||||||
|
connectionParameters.set("min connections", Integer.toString(minConnections));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFetchSize(int fetchSize) {
|
||||||
|
connectionParameters.set("fetch size", Integer.toString(fetchSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectionTimeout(int seconds) {
|
||||||
|
connectionParameters.set("Connection timeout", Integer.toString(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValidateConnections(boolean validateConnections) {
|
||||||
|
connectionParameters.set("validate connections", Boolean.toString(validateConnections));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
|
||||||
|
connectionParameters.set("Primary key metadata table", primaryKeyMetadataTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLooseBBox(boolean looseBBox) {
|
||||||
|
connectionParameters.set("Loose bbox", Boolean.toString(looseBBox));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreparedStatements(boolean preparedStatements) {
|
||||||
|
connectionParameters.set("preparedStatements", Boolean.toString(preparedStatements));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
|
||||||
|
connectionParameters.set("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEstimatedExtends(boolean estimatedExtends){
|
||||||
|
connectionParameters.set("Estimated extends", Boolean.toString(estimatedExtends));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@value #TYPE}
|
||||||
|
*/
|
||||||
|
protected String getValidType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.datastore;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encoder for a {@value #TYPE} datastore.
|
||||||
|
*
|
||||||
|
* @author Oscar Fonts
|
||||||
|
*/
|
||||||
|
public class GSShapefileDatastoreEncoder extends GSAbstractDatastoreEncoder {
|
||||||
|
|
||||||
|
static final String TYPE = "Shapefile";
|
||||||
|
|
||||||
|
final static boolean DEFAULT_ENABLED = true;
|
||||||
|
final static String DEFAULT_CHARSET = "ISO-8859-1";
|
||||||
|
final static boolean DEFAULT_CREATE_SPATIAL_INDEX = true;
|
||||||
|
final static boolean DEFAULT_MEMORY_MAPPED_BUFFER = false;
|
||||||
|
final static boolean DEFAULT_CACHE_AND_REUSE_MEMORY_MAPS = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@value #TYPE} datastore with default connection parameters,
|
||||||
|
* given a store name and a url (the store location).
|
||||||
|
*
|
||||||
|
* The following default connection parameters are set:
|
||||||
|
* <ul>
|
||||||
|
* <li>enabled: {@value #DEFAULT_ENABLED}
|
||||||
|
* <li>charset: {@value #DEFAULT_CHARSET}
|
||||||
|
* <li>create spatial index: {@value #DEFAULT_CREATE_SPATIAL_INDEX}
|
||||||
|
* <li>memory mapped buffer: {@value #DEFAULT_MEMORY_MAPPED_BUFFER}
|
||||||
|
* <li>cache and reuse memory maps: {@value #DEFAULT_CACHE_AND_REUSE_MEMORY_MAPS}
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param name New datastore name
|
||||||
|
* @param url The shapefile location in the server, relative to $GEOSERVER_DATA_DIR.
|
||||||
|
*/
|
||||||
|
public GSShapefileDatastoreEncoder(String name, URL url) {
|
||||||
|
// Set fixed values
|
||||||
|
super(name);
|
||||||
|
setType(TYPE);
|
||||||
|
|
||||||
|
// Set mandatory parameter
|
||||||
|
ensureValidURL(url);
|
||||||
|
setUrl(url);
|
||||||
|
|
||||||
|
// Set default values
|
||||||
|
setEnabled(DEFAULT_ENABLED);
|
||||||
|
setCharset(Charset.forName(DEFAULT_CHARSET));
|
||||||
|
setCreateSpatialIndex(DEFAULT_CREATE_SPATIAL_INDEX);
|
||||||
|
setMemoryMappedBuffer(DEFAULT_MEMORY_MAPPED_BUFFER);
|
||||||
|
setCacheAndReuseMemoryMaps(DEFAULT_CACHE_AND_REUSE_MEMORY_MAPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@value #TYPE} datastore encoder from an existing store read from server.
|
||||||
|
*
|
||||||
|
* @param store The existing store.
|
||||||
|
* @throws IllegalArgumentException if store type or mandatory parameters are not valid
|
||||||
|
*/
|
||||||
|
public GSShapefileDatastoreEncoder(RESTDataStore store) {
|
||||||
|
super(store);
|
||||||
|
|
||||||
|
// Check mandatory parameter validity
|
||||||
|
try {
|
||||||
|
ensureValidURL(new URL(store.getConnectionParameters().get("url")));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new IllegalArgumentException("Shapefile store URL is malformed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(URL url) {
|
||||||
|
ensureValidURL(url);
|
||||||
|
connectionParameters.set("url", url.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getUrl() {
|
||||||
|
try {
|
||||||
|
return new URL(ElementUtils.contains(connectionParameters.getRoot(), "description").getTextTrim());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCharset(Charset charset) {
|
||||||
|
connectionParameters.set("charset", charset.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Charset getCharset() {
|
||||||
|
return Charset.forName(ElementUtils.contains(connectionParameters.getRoot(), "charset").getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateSpatialIndex(boolean createSpatialIndex) {
|
||||||
|
connectionParameters.set("create spatial index", Boolean.toString(createSpatialIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getCreateSpatialIndex() {
|
||||||
|
return Boolean.parseBoolean(ElementUtils.contains(connectionParameters.getRoot(), "create spatial index").getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMemoryMappedBuffer(boolean memoryMappedBuffer) {
|
||||||
|
connectionParameters.set("memory mapped buffer", Boolean.toString(memoryMappedBuffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getMemoryMappedBuffer() {
|
||||||
|
return Boolean.parseBoolean(ElementUtils.contains(connectionParameters.getRoot(), "memory mapped buffer").getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCacheAndReuseMemoryMaps(boolean cacheAndReuseMemoryMaps) {
|
||||||
|
connectionParameters.set("cache and reuse memory maps", Boolean.toString(cacheAndReuseMemoryMaps));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getCacheAndReuseMemoryMaps() {
|
||||||
|
return Boolean.parseBoolean(ElementUtils.contains(connectionParameters.getRoot(), "cache and reuse memory maps").getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check url validity.
|
||||||
|
*
|
||||||
|
* @param url the url
|
||||||
|
* @throws IllegalArgumentException if url is null or empty
|
||||||
|
*/
|
||||||
|
private static void ensureValidURL(URL url) {
|
||||||
|
if (url == null || url.toString().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Shapefile store URL cannot be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@value #TYPE}
|
||||||
|
*/
|
||||||
|
protected String getValidType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,393 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.dimensions;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GSCoverageDimension - encodes a CoverageDimension for a given GeoServer Resource (feature type /coverage), as follows:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* final GSCoverageDimensionEncoder gsCoverageDimensionEncoder =
|
||||||
|
* new GSCoverageDimensionEncoder("GRAY_INDEX", "GridSampleDimension[-2.147483648E9,-2.147483648E9]",
|
||||||
|
* String.valueOf(Integer.MIN_VALUE), String.valueOf(Integer.MAX_VALUE), "dobson units", "REAL_32BITS");
|
||||||
|
* coverageEncoder.addCoverageDimensionInfo(gsCoverageDimensionEncoder);
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* For this example, the XML output is:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <coverageDimension>
|
||||||
|
* <name>GRAY_INDEX</name>
|
||||||
|
* <description>GridSampleDimension[-2.147483648E9,2.147483648E9]</description>
|
||||||
|
* <range>
|
||||||
|
* <min>-2.147483648E9</min>
|
||||||
|
* <max>2.147483647E9</max>
|
||||||
|
* </range>
|
||||||
|
* <unit>dobson units</unit>
|
||||||
|
* <dimensionType>
|
||||||
|
* <name>REAL_32BITS</name>
|
||||||
|
* </dimensionType>
|
||||||
|
* </coverageDimension>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Henry Rotzoll (henry.rotzoll@dlr.de)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSCoverageDimensionEncoder extends XmlElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to filter the GSCoverageDimension by content
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static class filterByContent implements Filter {
|
||||||
|
|
||||||
|
final private String key;
|
||||||
|
|
||||||
|
public filterByContent(String content) {
|
||||||
|
this.key = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
Element el = ((Element) obj).getChild("name");
|
||||||
|
if (el != null && el.getTextTrim().equals(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Filter using the GSCoverageDimensionEncoder content (GSCoverageDimensionEncoder name)
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* @return the filter
|
||||||
|
*/
|
||||||
|
public static Filter getFilterByContent(String content) {
|
||||||
|
return new filterByContent(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new GSCoverageDimensionEncoder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GSCoverageDimensionEncoder() {
|
||||||
|
super("coverageDimension");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs quickly a GSCoverageDimensionEncoder info
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param description
|
||||||
|
* @param rangeMin
|
||||||
|
* @param rangeMax
|
||||||
|
* @param unit
|
||||||
|
* @param dimensionTypeName
|
||||||
|
*/
|
||||||
|
public GSCoverageDimensionEncoder(String name, String description, String rangeMin,
|
||||||
|
String rangeMax, String unit, String dimensionTypeName) {
|
||||||
|
super("coverageDimension");
|
||||||
|
this.setup(name, description, rangeMin, rangeMax, unit, dimensionTypeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set-up quickly a GSCoverageDimensionEncoder info
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param description
|
||||||
|
* @param rangeMin
|
||||||
|
* @param rangeMax
|
||||||
|
* @param unit
|
||||||
|
* @param dimensionTypeName
|
||||||
|
*/
|
||||||
|
protected void setup(String name, String description, String rangeMin, String rangeMax,
|
||||||
|
String unit, String dimensionTypeName) {
|
||||||
|
// name
|
||||||
|
setName(name);
|
||||||
|
|
||||||
|
// description
|
||||||
|
setDescription(description);
|
||||||
|
|
||||||
|
// range
|
||||||
|
setRange(rangeMin, rangeMax);
|
||||||
|
|
||||||
|
// unit
|
||||||
|
setUnit(unit);
|
||||||
|
|
||||||
|
// dimension Type
|
||||||
|
setDimensionType(dimensionTypeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the GSCoverageDimensionEncoder member
|
||||||
|
*
|
||||||
|
* @param memberName
|
||||||
|
* @return the value of the GSCoverageDimensionEncoder member
|
||||||
|
*/
|
||||||
|
protected String getMember(String memberName) {
|
||||||
|
Element el = this.getRoot().getChild(memberName.toString());
|
||||||
|
if (el != null)
|
||||||
|
return el.getTextTrim();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a GSCoverageDimensionEncoder member
|
||||||
|
*
|
||||||
|
* @param memberName
|
||||||
|
* @return true if the GSCoverageDimensionEncoder member is removed
|
||||||
|
*/
|
||||||
|
protected boolean delMemberIfExists(String memberName) {
|
||||||
|
if (ElementUtils.contains(getRoot(), memberName) != null) {
|
||||||
|
return ElementUtils.remove(this.getRoot(),
|
||||||
|
this.getRoot().getChild(memberName.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a GSCoverageDimensionEncoder member
|
||||||
|
*
|
||||||
|
* @param memberName
|
||||||
|
* @param memberValue
|
||||||
|
*/
|
||||||
|
protected void setMember(String memberName, String memberValue) {
|
||||||
|
if (memberName != null && !memberName.isEmpty() && memberValue != null
|
||||||
|
&& !memberValue.isEmpty()) {
|
||||||
|
delMemberIfExists(memberName); // delete the element if it already exists
|
||||||
|
addMember(memberName.toString(), memberValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adds a GSCoverageDimensionEncoder member
|
||||||
|
*
|
||||||
|
* @param memberName
|
||||||
|
* @param memberValue
|
||||||
|
*/
|
||||||
|
protected void addMember(String memberName, String memberValue) {
|
||||||
|
if (memberName != null && !memberName.isEmpty() && memberValue != null
|
||||||
|
&& !memberValue.isEmpty()) {
|
||||||
|
set(memberName.toString(), memberValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the name
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
setMember("name", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the name
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delName() {
|
||||||
|
return this.delMemberIfExists("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the description
|
||||||
|
*
|
||||||
|
* @return description
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return this.getMember("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the description
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
*/
|
||||||
|
public void setDescription(String description) {
|
||||||
|
setMember("description", description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the description
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delDescription() {
|
||||||
|
return this.delMemberIfExists("description");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the description
|
||||||
|
*
|
||||||
|
* @return description
|
||||||
|
*/
|
||||||
|
public String getDescription() {
|
||||||
|
return this.getMember("description");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the range
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
*/
|
||||||
|
public void setRange(String rangeMin, String rangeMax) {
|
||||||
|
if (rangeMin != null && !rangeMin.isEmpty() && rangeMax != null && !rangeMax.isEmpty()) {
|
||||||
|
remove("range");
|
||||||
|
|
||||||
|
final Element rangeElement = new Element("range");
|
||||||
|
final Element rangeMinElement = new Element("min");
|
||||||
|
rangeMinElement.setText(rangeMin);
|
||||||
|
final Element rangeMaxElement = new Element("max");
|
||||||
|
rangeMaxElement.setText(rangeMax);
|
||||||
|
rangeElement.addContent(rangeMinElement);
|
||||||
|
rangeElement.addContent(rangeMaxElement);
|
||||||
|
addContent(rangeElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the range
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delRange() {
|
||||||
|
return this.delMemberIfExists("range");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the range min
|
||||||
|
*
|
||||||
|
* @return range min
|
||||||
|
*/
|
||||||
|
public String getRangeMin() {
|
||||||
|
final Element range = this.getRoot().getChild("range");
|
||||||
|
if (range != null) {
|
||||||
|
return range.getChildText("min");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the range max
|
||||||
|
*
|
||||||
|
* @return range max
|
||||||
|
*/
|
||||||
|
public String getRangeMax() {
|
||||||
|
final Element range = this.getRoot().getChild("range");
|
||||||
|
if (range != null) {
|
||||||
|
return range.getChildText("max");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the unit
|
||||||
|
*
|
||||||
|
* @param unit
|
||||||
|
*/
|
||||||
|
public void setUnit(String unit) {
|
||||||
|
setMember("unit", unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the type
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delUnit() {
|
||||||
|
return this.delMemberIfExists("unit");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the unit
|
||||||
|
*
|
||||||
|
* @return unit
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return this.getMember("unit");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dimensionType
|
||||||
|
*
|
||||||
|
* @param dimensionType
|
||||||
|
*/
|
||||||
|
public void setDimensionType(String dimensionTypeName) {
|
||||||
|
if (dimensionTypeName != null && !dimensionTypeName.isEmpty()) {
|
||||||
|
remove("dimensionType");
|
||||||
|
|
||||||
|
final Element dimensionTypeElement = new Element("dimensionType");
|
||||||
|
final Element dimensionNameElement = new Element("name");
|
||||||
|
dimensionNameElement.setText(dimensionTypeName);
|
||||||
|
dimensionTypeElement.addContent(dimensionNameElement);
|
||||||
|
addContent(dimensionTypeElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the dimensionType
|
||||||
|
*
|
||||||
|
* @param dimensionType
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delDimensionType() {
|
||||||
|
return this.delMemberIfExists("dimensionType");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dimensionType name
|
||||||
|
*
|
||||||
|
* @return dimensionType name
|
||||||
|
*/
|
||||||
|
public String getDimensionTypeName() {
|
||||||
|
final Element dimensionType = this.getRoot().getChild("dimensionType");
|
||||||
|
if (dimensionType != null) {
|
||||||
|
return dimensionType.getChildText("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.feature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of featureType attribute members
|
||||||
|
*/
|
||||||
|
public enum FeatureTypeAttribute {
|
||||||
|
name, minOccurs, maxOccurs, nillable, binding, length
|
||||||
|
}
|
||||||
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.feature;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author carlo cancellieri - GeoSolutions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSAttributeEncoder extends PropertyXMLEncoder {
|
||||||
|
|
||||||
|
public static class filterByName implements Filter {
|
||||||
|
|
||||||
|
final private String key;
|
||||||
|
|
||||||
|
public filterByName(String keyword){
|
||||||
|
this.key=keyword;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
Element el=((Element) obj).getChild(FeatureTypeAttribute.name.toString());
|
||||||
|
if (el!=null && el.getTextTrim().equals(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Filter getFilterByName(String name){
|
||||||
|
return new filterByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GSAttributeEncoder() {
|
||||||
|
super("attribute");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setup(Map<FeatureTypeAttribute, String> attributes){
|
||||||
|
for (Entry<FeatureTypeAttribute,String> attr:attributes.entrySet()){
|
||||||
|
set(attr.getKey().toString(),attr.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttribute(FeatureTypeAttribute type, String value){
|
||||||
|
set(type.toString(),value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delAttribute(FeatureTypeAttribute type){
|
||||||
|
ElementUtils.remove(this.getRoot(), get(type.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAttribute(FeatureTypeAttribute type){
|
||||||
|
Element el = get(type.toString());
|
||||||
|
if (el!=null)
|
||||||
|
return el.getTextTrim();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -25,11 +25,12 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.encoder.feature;
|
package it.geosolutions.geoserver.rest.encoder.feature;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
|
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.GSVirtualTableEncoder;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -38,22 +39,93 @@ import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
|||||||
* @author ETj (etj at geo-solutions.it)
|
* @author ETj (etj at geo-solutions.it)
|
||||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
*/
|
*/
|
||||||
public class GSFeatureTypeEncoder extends GSResourceEncoder/*<GSFeatureDimensionInfoEncoder>*/ {
|
public class GSFeatureTypeEncoder extends GSResourceEncoder {
|
||||||
|
|
||||||
|
public final static String ATTRIBUTES = "attributes";
|
||||||
|
|
||||||
|
final private Element attributes = new Element(ATTRIBUTES);
|
||||||
|
|
||||||
public GSFeatureTypeEncoder() {
|
public GSFeatureTypeEncoder() {
|
||||||
super("featureType");
|
super("featureType");
|
||||||
|
addContent(attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated Use {@link GSResourceEncoder#addMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
|
||||||
* @param key
|
* @param key
|
||||||
* @param dimensionInfo
|
* @param dimensionInfo
|
||||||
* @deprecated will be set to protected in the next release
|
*
|
||||||
*/
|
*/
|
||||||
public void addMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) {
|
protected void addMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) {
|
||||||
super.addMetadata(key, dimensionInfo);
|
super.addMetadata(key, dimensionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link GSResourceEncoder#setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
|
||||||
|
* @param key
|
||||||
|
* @param dimensionInfo
|
||||||
|
*
|
||||||
|
*/
|
||||||
public void setMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) {
|
public void setMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) {
|
||||||
super.setMetadata(key, dimensionInfo);
|
super.setMetadata(key, dimensionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a VirtualTable (SQL View feature type)
|
||||||
|
*
|
||||||
|
* @param virtualtable
|
||||||
|
*/
|
||||||
|
protected void addMetadataVirtualTable(
|
||||||
|
final GSVirtualTableEncoder virtualtable) {
|
||||||
|
super.addMetadata("JDBC_VIRTUAL_TABLE", virtualtable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a VirtualTable (SQL View feature type)
|
||||||
|
*
|
||||||
|
* @param virtualtable
|
||||||
|
*/
|
||||||
|
public void setMetadataVirtualTable(final GSVirtualTableEncoder virtualtable) {
|
||||||
|
super.setMetadata("JDBC_VIRTUAL_TABLE", virtualtable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the VirtualTable metadata
|
||||||
|
*
|
||||||
|
* @return true if deleted, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delMetadataVirtualTable(){
|
||||||
|
return super.delMetadata("JDB_VIRTUAL_TABLE");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete a keyword from the list
|
||||||
|
*
|
||||||
|
* @param keyword
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delAttribute(final String keyword) {
|
||||||
|
final Element el = new Element("string");
|
||||||
|
el.setText(keyword);
|
||||||
|
return (attributes.removeContent(GSAttributeEncoder.getFilterByName(keyword))).size() == 0 ? false
|
||||||
|
: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param attribute the attribute to add
|
||||||
|
*/
|
||||||
|
protected void addAttribute(GSAttributeEncoder attribute) {
|
||||||
|
attributes.addContent(attribute.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param attribute the attribute to set (overriding an attribute with the same name if present)
|
||||||
|
*/
|
||||||
|
public void setAttribute(GSAttributeEncoder attribute) {
|
||||||
|
delAttribute(attribute.getAttribute(FeatureTypeAttribute.name));
|
||||||
|
addAttribute(attribute);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.identifier;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GSIdentifierInfoEncoder - encodes an Identifier for a given GeoServer
|
||||||
|
* layer as follows:
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* final GSIdentifierInfoEncoder ie = new GSIdentifierInfoEncoder();
|
||||||
|
* ie.setAuthority("an authority");
|
||||||
|
* ie.setIdentifier("an identifier");
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* For this example, the XML output is:
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <Identifier>
|
||||||
|
* <authority>an authority</authority>
|
||||||
|
* <identifier>an identifier</identifier>
|
||||||
|
* </Identifier>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSIdentifierInfoEncoder extends XmlElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to filter the Idenfiers by authority
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static class filterByAuthority implements Filter {
|
||||||
|
|
||||||
|
final private String key;
|
||||||
|
|
||||||
|
public filterByAuthority(String authority) {
|
||||||
|
this.key = authority;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
Element el = ((Element) obj).getChild(IdentifierInfo.authority
|
||||||
|
.toString());
|
||||||
|
if (el != null && el.getTextTrim().equals(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Filter using the IdentifierInfo authority
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* @return the filter
|
||||||
|
*/
|
||||||
|
public static Filter getFilterByHref(String authority) {
|
||||||
|
return new filterByAuthority(authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new GSIdentifierInfoEncoder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GSIdentifierInfoEncoder() {
|
||||||
|
super("Identifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs quickly an Identifier info
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* (required)
|
||||||
|
* @param identifier
|
||||||
|
* (required)
|
||||||
|
*/
|
||||||
|
public GSIdentifierInfoEncoder(String authority, String identifier) {
|
||||||
|
super("Identifier");
|
||||||
|
this.setup(authority, identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set-up quickly an Identifier info
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* @param identifier
|
||||||
|
*/
|
||||||
|
protected void setup(String authority, String identifier) {
|
||||||
|
set(IdentifierInfo.authority.name(), authority);
|
||||||
|
set(IdentifierInfo.identifier.name(), identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an IdentifierInfo member (authority, identifier)
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
protected void setMember(IdentifierInfo type, String value) {
|
||||||
|
set(type.toString(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the authority
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
*/
|
||||||
|
public void setAuthority(String authority) {
|
||||||
|
this.setMember(IdentifierInfo.authority, authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the identifier
|
||||||
|
*
|
||||||
|
* @param identifier
|
||||||
|
*/
|
||||||
|
public void setIdentifier(String identifier) {
|
||||||
|
this.setMember(IdentifierInfo.identifier, identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an IdentifierInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return true if the IdentifierInfo member is removed
|
||||||
|
*/
|
||||||
|
protected boolean delMember(IdentifierInfo type) {
|
||||||
|
return ElementUtils.remove(this.getRoot(),
|
||||||
|
this.getRoot().getChild(type.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the authority
|
||||||
|
*
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delAuthority() {
|
||||||
|
return this.delMember(IdentifierInfo.authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the identifier
|
||||||
|
*
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delIdentifier() {
|
||||||
|
return this.delMember(IdentifierInfo.identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the IdentifierInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return the value of the IdentifierInfo member
|
||||||
|
*/
|
||||||
|
protected String getMember(IdentifierInfo type) {
|
||||||
|
Element el = this.getRoot().getChild(type.toString());
|
||||||
|
if (el != null)
|
||||||
|
return el.getTextTrim();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the authority
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getAuthority() {
|
||||||
|
return this.getMember(IdentifierInfo.authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the identifier
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getIdentifier() {
|
||||||
|
return this.getMember(IdentifierInfo.identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.identifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of layer authorityURL members
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum IdentifierInfo {
|
||||||
|
|
||||||
|
authority, identifier;
|
||||||
|
}
|
||||||
@ -32,14 +32,20 @@ import java.math.BigDecimal;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
* @author Simone Giannecchini, GeoSolutions
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GSDimensionInfoEncoder extends XmlElement{
|
public class GSDimensionInfoEncoder extends XmlElement{
|
||||||
public final static String DIMENSIONINFO="dimensionInfo";
|
public final static String DIMENSIONINFO="dimensionInfo";
|
||||||
|
|
||||||
public final static String RESOLUTION="resolution";
|
public final static String RESOLUTION="resolution";
|
||||||
|
|
||||||
public final static String PRESENTATION="presentation";
|
public final static String PRESENTATION="presentation";
|
||||||
|
|
||||||
|
public final static String UNITS="units";
|
||||||
|
|
||||||
|
public final static String UNIT_SYMBOL="unitSymbol";
|
||||||
|
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,12 +53,7 @@ public class GSDimensionInfoEncoder extends XmlElement{
|
|||||||
*/
|
*/
|
||||||
public enum Presentation {
|
public enum Presentation {
|
||||||
LIST,
|
LIST,
|
||||||
CONTINUOUS_INTERVAL
|
CONTINUOUS_INTERVAL,
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Enum for presentation mode which needs arguments
|
|
||||||
*/
|
|
||||||
public enum PresentationDiscrete{
|
|
||||||
DISCRETE_INTERVAL
|
DISCRETE_INTERVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,41 +82,73 @@ public class GSDimensionInfoEncoder extends XmlElement{
|
|||||||
this.enabled=Boolean.TRUE;
|
this.enabled=Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated will be set to protected in the next release {@link setPresentation(final Presentation pres)}
|
|
||||||
* @param pres
|
|
||||||
*/
|
|
||||||
public void addPresentation(final Presentation pres){
|
|
||||||
if (enabled){
|
|
||||||
add(PRESENTATION,pres.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPresentation(final Presentation pres){
|
public void setPresentation(final Presentation pres){
|
||||||
if (enabled){
|
setPresentation(pres, null);
|
||||||
set(PRESENTATION,pres.toString());
|
|
||||||
remove(RESOLUTION);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param pres
|
* @param pres
|
||||||
* @param interval
|
* @param interval
|
||||||
* @deprecated will be set to protected in the next release {@link setPresentation(final PresentationDiscrete pres, final BigDecimal interval)}
|
|
||||||
*/
|
*/
|
||||||
public void addPresentation(final PresentationDiscrete pres, final BigDecimal interval){
|
protected void addPresentation(final Presentation pres, final BigDecimal interval){
|
||||||
if (enabled){
|
if (enabled){
|
||||||
add(PRESENTATION,pres.toString());
|
add(PRESENTATION,pres.toString());
|
||||||
|
if(pres==Presentation.DISCRETE_INTERVAL){
|
||||||
|
if(pres==Presentation.DISCRETE_INTERVAL&&interval==null){
|
||||||
|
throw new IllegalArgumentException("Null interval was provided while trying to set the presentation to discrete interval.");
|
||||||
|
}
|
||||||
add(RESOLUTION,String.valueOf(interval));
|
add(RESOLUTION,String.valueOf(interval));
|
||||||
|
} else {
|
||||||
|
remove(RESOLUTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPresentation(final PresentationDiscrete pres, final BigDecimal interval){
|
public void setPresentation(final Presentation pres, final BigDecimal interval){
|
||||||
if (enabled){
|
if (enabled){
|
||||||
set(PRESENTATION,pres.toString());
|
set(PRESENTATION,pres.toString());
|
||||||
|
if(pres==Presentation.DISCRETE_INTERVAL){
|
||||||
|
if(pres==Presentation.DISCRETE_INTERVAL&&interval==null){
|
||||||
|
throw new IllegalArgumentException("Null interval was provided while trying to set the presentation to discrete interval.");
|
||||||
|
}
|
||||||
set(RESOLUTION,String.valueOf(interval));
|
set(RESOLUTION,String.valueOf(interval));
|
||||||
|
} else {
|
||||||
|
remove(RESOLUTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set UoM for this dimension.
|
||||||
|
*
|
||||||
|
* <code>null</code> is acceptable and leave this UoM blank.
|
||||||
|
*
|
||||||
|
* @param unit UoM for this dimension.
|
||||||
|
*/
|
||||||
|
public void setUnit(final String unit){
|
||||||
|
if(unit==null||unit.length()<=0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (enabled){
|
||||||
|
set(UNITS,unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set UoM for this dimension.
|
||||||
|
*
|
||||||
|
* <code>null</code> is acceptable and leave this UoM blank.
|
||||||
|
*
|
||||||
|
* @param unit UoM for this dimension.
|
||||||
|
*/
|
||||||
|
public void setUnitSymbol(final String unitSymbol){
|
||||||
|
if(unitSymbol==null||unitSymbol.length()<=0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (enabled){
|
||||||
|
set(UNIT_SYMBOL,unitSymbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ package it.geosolutions.geoserver.rest.encoder.metadata;
|
|||||||
|
|
||||||
public class GSFeatureDimensionInfoEncoder extends GSDimensionInfoEncoder {
|
public class GSFeatureDimensionInfoEncoder extends GSDimensionInfoEncoder {
|
||||||
public final static String ATTRIBUTE="attribute";
|
public final static String ATTRIBUTE="attribute";
|
||||||
|
public final static String END_ATTRIBUTE="endAttribute";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if this dimension is enabled this constructor should be called.
|
* if this dimension is enabled this constructor should be called.
|
||||||
@ -46,6 +47,12 @@ public class GSFeatureDimensionInfoEncoder extends GSDimensionInfoEncoder {
|
|||||||
set(ATTRIBUTE, attribute);
|
set(ATTRIBUTE, attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the end attribute used in the dimension (optional)
|
||||||
|
* @param endAttribute the dimension end attribute
|
||||||
|
*/
|
||||||
|
public void setEndAttribute(final String endAttribute){
|
||||||
|
set(END_ATTRIBUTE, endAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,341 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GSVirtualTableEncoder - Encodes a metadata VirtualTable for a GeoServer
|
||||||
|
* featureType.
|
||||||
|
*
|
||||||
|
* Example (based on the example provided in the Geoserver documentation - see
|
||||||
|
* {@link http://docs.geoserver.org/latest/en/user/data/database/sqlview.html#
|
||||||
|
* parameterizing-sql-views}):
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {
|
||||||
|
* @code
|
||||||
|
* // Set-up the vtGeom
|
||||||
|
* final VTGeometryEncoder vtGeom = new VTGeometryEncoder();
|
||||||
|
* vtGeom.setName("the_geom");
|
||||||
|
* vtGeom.setType("MultiPolygon");
|
||||||
|
* vtGeom.setSrid("4326");
|
||||||
|
*
|
||||||
|
* // Set-up 2 virtual table parameters
|
||||||
|
* final VTParameterEncoder vtParam1 = new VTParameterEncoder("high",
|
||||||
|
* "100000000", "^[\\d]+$");
|
||||||
|
* final VTParameterEncoder vtParam2 = new VTParameterEncoder("low", "0",
|
||||||
|
* "^[\\d]+$");
|
||||||
|
*
|
||||||
|
* // sql
|
||||||
|
* String sql = "select gid, state_name, the_geom from pgstates where persons between %low% and %high%";
|
||||||
|
*
|
||||||
|
* // Set-up the virtual table
|
||||||
|
* final GSVirtualTableEncoder vte = new GSVirtualTableEncoder();
|
||||||
|
* vte.setName("popstates");
|
||||||
|
* vte.setSql("select gid, state_name, the_geom from pgstates where persons between %low% and %high%");
|
||||||
|
* vte.addKeyColumn("gid");
|
||||||
|
* vte.addVirtualTableGeometry(vtGeom);
|
||||||
|
* vte.addVirtualTableParameter(vtParam1);
|
||||||
|
* vte.addVirtualTableParameter(vtParam2);
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* For this example, the XML output is:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <virtualTable>
|
||||||
|
* <name>popstates</name>
|
||||||
|
* <sql>select gid, state_name, the_geom from pgstates where persons between %low% and %high%</sql>
|
||||||
|
* <geometry>
|
||||||
|
* <name>the_geom</name>
|
||||||
|
* <type>MultiPolygon</type>
|
||||||
|
* <srid>4326</srid>
|
||||||
|
* </geometry>
|
||||||
|
* <keyColumn>gid</keyColumn>
|
||||||
|
* <parameter>
|
||||||
|
* <name>high</name>
|
||||||
|
* <defaultValue>100000000</defaultValue>
|
||||||
|
* <regexpValidator>^[\d]+$</regexpValidator>
|
||||||
|
* </parameter>
|
||||||
|
* <parameter>
|
||||||
|
* <name>low</name>
|
||||||
|
* <defaultValue>0</defaultValue>
|
||||||
|
* <regexpValidator>^[\d]+$</regexpValidator>
|
||||||
|
* </parameter>
|
||||||
|
* </virtualTable>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSVirtualTableEncoder extends XmlElement {
|
||||||
|
|
||||||
|
public final static String NAME = "name";
|
||||||
|
public final static String SQL = "sql";
|
||||||
|
public final static String KEYCOLUMN = "keyColumn";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a GSVirtualTableEncoder
|
||||||
|
*/
|
||||||
|
public GSVirtualTableEncoder() {
|
||||||
|
super("virtualTable");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs directly a GSVirtualTableEncoder
|
||||||
|
*
|
||||||
|
* @param name (required)
|
||||||
|
* @param sql (required)
|
||||||
|
* @param keyColumns (optional)
|
||||||
|
* @param geomEncList (optional for geometryless sql view)
|
||||||
|
* @param paramEncList (optional)
|
||||||
|
*/
|
||||||
|
public GSVirtualTableEncoder(String name, String sql, List<String> keyColumns,
|
||||||
|
List<VTGeometryEncoder> geomEncList,
|
||||||
|
List<VTParameterEncoder> paramEncList){
|
||||||
|
super("virtualTable");
|
||||||
|
this.setup(name, sql, keyColumns, geomEncList, paramEncList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set-up quickly a GSVirtualTableEncoder
|
||||||
|
*
|
||||||
|
* @param name (must be the same as the featureType nativeName)
|
||||||
|
* @param sql
|
||||||
|
* @param keyColumns
|
||||||
|
* @param geomEncList
|
||||||
|
* @param paramEncList
|
||||||
|
*/
|
||||||
|
protected void setup(String name, String sql, List<String> keyColumns,
|
||||||
|
List<VTGeometryEncoder> geomEncList,
|
||||||
|
List<VTParameterEncoder> paramEncList) {
|
||||||
|
|
||||||
|
setName(name);
|
||||||
|
setSql(sql);
|
||||||
|
|
||||||
|
if (keyColumns != null) {
|
||||||
|
for (String pk : keyColumns) {
|
||||||
|
addKeyColumn(pk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (geomEncList != null) {
|
||||||
|
for (VTGeometryEncoder geomEnc : geomEncList) {
|
||||||
|
addVirtualTableGeometry(geomEnc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paramEncList != null) {
|
||||||
|
for(VTParameterEncoder paramEnc : paramEncList){
|
||||||
|
addVirtualTableParameter(paramEnc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'name' node with a text value from 'name'
|
||||||
|
*
|
||||||
|
* @note REQUIRED to configure a virtual table
|
||||||
|
*/
|
||||||
|
protected void addName(final String name){
|
||||||
|
add(NAME, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set or modify the 'name' node with a text value from 'name'
|
||||||
|
*
|
||||||
|
* @note REQUIRED to configure a virtual table
|
||||||
|
*/
|
||||||
|
public void setName(final String name) {
|
||||||
|
set(NAME, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the virtual table
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
final Element nameNode = ElementUtils.contains(getRoot(), NAME, 1);
|
||||||
|
if (nameNode != null)
|
||||||
|
return nameNode.getText();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the 'sql' node with a text value from 'sql'
|
||||||
|
*
|
||||||
|
* @note REQUIRED to configure a virtual table
|
||||||
|
*/
|
||||||
|
protected void addSql(final String sql){
|
||||||
|
add(SQL, sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set or modify the 'sql' node with a text value from 'sql'
|
||||||
|
*
|
||||||
|
* @note REQUIRED to configure a virtual table
|
||||||
|
*/
|
||||||
|
public void setSql(final String sql) {
|
||||||
|
set(SQL, sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the sql query
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getSql() {
|
||||||
|
final Element sqlNode = ElementUtils.contains(getRoot(), SQL, 1);
|
||||||
|
if (sqlNode != null)
|
||||||
|
return sqlNode.getText();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a keyColumn
|
||||||
|
*
|
||||||
|
* @param keycolumn
|
||||||
|
*/
|
||||||
|
public void addKeyColumn(String keycolumn){
|
||||||
|
final Element el = new Element(KEYCOLUMN);
|
||||||
|
el.setText(keycolumn);
|
||||||
|
this.getRoot().addContent(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a keyColumn
|
||||||
|
*
|
||||||
|
* @param keycolumn
|
||||||
|
* @return true if the keycolumn was removed
|
||||||
|
*/
|
||||||
|
public boolean delKeyColumn(final String keycolumn){
|
||||||
|
final Element el = new Element(KEYCOLUMN);
|
||||||
|
el.setText(keycolumn);
|
||||||
|
return (this.getRoot().removeContent(new Filter() {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
if (((Element) obj).getText().equals(keycolumn)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})).size() == 0 ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a geometry to the VirtualTable
|
||||||
|
*
|
||||||
|
* @param geomEnc
|
||||||
|
*/
|
||||||
|
public void addVirtualTableGeometry(VTGeometryEncoder geomEnc){
|
||||||
|
this.getRoot().addContent(geomEnc.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds quickly a geometry to the virtual table
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param geometryType
|
||||||
|
* @param srid
|
||||||
|
*/
|
||||||
|
public void addVirtualTableGeometry(String name, String geometryType, String srid){
|
||||||
|
final VTGeometryEncoder gEnc = new VTGeometryEncoder();
|
||||||
|
gEnc.setup(name, geometryType, srid);
|
||||||
|
this.getRoot().addContent(gEnc.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a geometry from the VirtualTable
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return true if the geometry was removed, otherwise false
|
||||||
|
*/
|
||||||
|
public boolean delVirtualTableGeometry(String name){
|
||||||
|
return (this.getRoot()
|
||||||
|
.removeContent(VTGeometryEncoder
|
||||||
|
.getFilterByName(name))).size() == 0 ? false
|
||||||
|
: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a parameter to the VirtualTable
|
||||||
|
*
|
||||||
|
* @param paramEnc
|
||||||
|
*/
|
||||||
|
public void addVirtualTableParameter(VTParameterEncoder paramEnc){
|
||||||
|
this.getRoot().addContent(paramEnc.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds quickly a parameter to the VirtualTable
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param defaultValue
|
||||||
|
* @param regexpValidator
|
||||||
|
*/
|
||||||
|
public void addVirtualTableParameter(String name, String defaultValue, String regexpValidator){
|
||||||
|
final VTParameterEncoder pEnc = new VTParameterEncoder();
|
||||||
|
pEnc.setup(name, defaultValue, regexpValidator);
|
||||||
|
this.getRoot().addContent(pEnc.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a parameter from the VirtualTable
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean delVirtualTableParameter(String name){
|
||||||
|
return (this.getRoot()
|
||||||
|
.removeContent(VTParameterEncoder
|
||||||
|
.getFilterByName(name))).size() == 0 ? false
|
||||||
|
: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* a method to check either the virtual parameters as specified in the sql
|
||||||
|
* query map those encoded in VTParameterEncoder, i.e. check the number and
|
||||||
|
* names of parameters.
|
||||||
|
*/
|
||||||
|
public boolean validate() throws IllegalStateException{
|
||||||
|
throw new UnsupportedOperationException("not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of Virtual Table geometry members
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum VTGeometry {
|
||||||
|
name, type, srid
|
||||||
|
}
|
||||||
@ -0,0 +1,247 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VTGeometryEncoder - Encodes a metadata VirtualTable geometry for a
|
||||||
|
* GeoServer featureType, as follows:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {
|
||||||
|
* @code
|
||||||
|
* final VTGeometryEncoder vtGeom = new VTGeometryEncoder();
|
||||||
|
* vtGeom.setName("the_geom");
|
||||||
|
* vtGeom.setType("MultiPolygon");
|
||||||
|
* vtGeom.setSrid("4326");
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* For this example, the XML output is:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <geometry>
|
||||||
|
* <name>the_geom</name>
|
||||||
|
* <type>MultiPolygon</type>
|
||||||
|
* <srid>4326</srid>
|
||||||
|
* </geometry>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class VTGeometryEncoder extends XmlElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to filter the VirtualTable geometries by name
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static class filterByName implements Filter {
|
||||||
|
|
||||||
|
final private String key;
|
||||||
|
|
||||||
|
public filterByName(String name) {
|
||||||
|
this.key = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
Element el = ((Element) obj)
|
||||||
|
.getChild(VTGeometry.name.toString());
|
||||||
|
if (el != null && el.getTextTrim().equals(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Filter using the VTGeometry name
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return the filter
|
||||||
|
*/
|
||||||
|
public static Filter getFilterByName(String name) {
|
||||||
|
return new filterByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a GSVirtualTableGeomEncoder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public VTGeometryEncoder() {
|
||||||
|
super("geometry");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs quickly a VTGeometryEncoder
|
||||||
|
*
|
||||||
|
* @param name (required)
|
||||||
|
* @param geometryType (required)
|
||||||
|
* @param srid (required)
|
||||||
|
*/
|
||||||
|
public VTGeometryEncoder(String name, String geometryType, String srid) {
|
||||||
|
super("geometry");
|
||||||
|
this.setup(name, geometryType, srid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set-up quickly a GSVirtualTableGeomEncoder
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param geometryType
|
||||||
|
* @param srid
|
||||||
|
*/
|
||||||
|
protected void setup(String name, String geometryType, String srid) {
|
||||||
|
setName(name);
|
||||||
|
setType(geometryType);
|
||||||
|
setSrid(srid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a VirtualTable Geometry member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
protected void setMember(VTGeometry type,
|
||||||
|
String value) {
|
||||||
|
set(type.toString(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a geometry name
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public void setName(String name){
|
||||||
|
this.setMember(VTGeometry.name, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a geometry type
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
public void setType(String type){
|
||||||
|
this.setMember(VTGeometry.type, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a geometry srid
|
||||||
|
*
|
||||||
|
* @param srid
|
||||||
|
*/
|
||||||
|
public void setSrid(String srid){
|
||||||
|
this.setMember(VTGeometry.srid, srid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a VirtualTableGeometry member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return true if removed, false otherwise
|
||||||
|
*/
|
||||||
|
protected boolean delMember(VTGeometry type) {
|
||||||
|
return ElementUtils.remove(this.getRoot(), this.getRoot().getChild(type.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the name
|
||||||
|
*
|
||||||
|
* @return true if removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delName(){
|
||||||
|
return this.delMember(VTGeometry.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the type
|
||||||
|
*
|
||||||
|
* @return true if removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delType(){
|
||||||
|
return this.delMember(VTGeometry.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the srid
|
||||||
|
*
|
||||||
|
* @return true if removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delSrid(){
|
||||||
|
return this.delMember(VTGeometry.srid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the VirtualTableGeometry member value
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getMember(VTGeometry type) {
|
||||||
|
Element el = this.getRoot().getChild(type.toString());
|
||||||
|
if (el != null)
|
||||||
|
return el.getTextTrim();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the geometry column name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getName(){
|
||||||
|
return this.getMember(VTGeometry.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the geometry column type
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getType(){
|
||||||
|
return this.getMember(VTGeometry.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the geometry column srid
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getSrid(){
|
||||||
|
return this.getMember(VTGeometry.srid);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of SQL View featureType virtual table parameter members
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum VTParameter {
|
||||||
|
name, defaultValue, regexpValidator
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,246 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VTParameterEncoder - Encodes a metadata VirtualTable parameter for a
|
||||||
|
* GeoServer featureType, as follows:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* { @code
|
||||||
|
* final VTParameterEncoder vtParam = new VTParameterEncoder();
|
||||||
|
* vtParam.setName("fieldname");
|
||||||
|
* vtParam.setDefaultValue("default_value");
|
||||||
|
* vtParam.setRegexpValidator("^[\\w\\d\\s]+$");
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* For this example, the XML output is:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* { @code
|
||||||
|
* <parameter>
|
||||||
|
* <name>fieldname</name>
|
||||||
|
* <defaultValue>default_value</defaultValue>
|
||||||
|
* <regexpValidator>^[\w\d\s]+$</regexpValidator>
|
||||||
|
* </parameter>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class VTParameterEncoder extends XmlElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to filter the VirtualTable parameters by name
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static class filterByName implements Filter {
|
||||||
|
|
||||||
|
final private String key;
|
||||||
|
|
||||||
|
public filterByName(String name) {
|
||||||
|
this.key = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
Element el = ((Element) obj)
|
||||||
|
.getChild(VTParameter.name.toString());
|
||||||
|
if (el != null && el.getTextTrim().equals(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Filter using the VTParameter name
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return the filter
|
||||||
|
*/
|
||||||
|
public static Filter getFilterByName(String name) {
|
||||||
|
return new filterByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a GSVirtualTableParamEncoder
|
||||||
|
*/
|
||||||
|
public VTParameterEncoder() {
|
||||||
|
super("parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs quickly a VTParameterEncoder
|
||||||
|
*
|
||||||
|
* @param name (required)
|
||||||
|
* @param defaultValue (required)
|
||||||
|
* @param regexpValidator (required)
|
||||||
|
*/
|
||||||
|
public VTParameterEncoder(String name, String defaultValue, String regexpValidator){
|
||||||
|
super("parameter");
|
||||||
|
this.setup(name, defaultValue, regexpValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set-up quickly a VirtualTable parameter
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param defaultValue
|
||||||
|
* @param regexpValidator
|
||||||
|
*/
|
||||||
|
protected void setup(String name, String defaultValue, String regexpValidator) {
|
||||||
|
setName(name);
|
||||||
|
setDefaultValue(defaultValue);
|
||||||
|
setRegexpValidator(regexpValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a VirtualTableParameter member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
protected void setMember(VTParameter type,
|
||||||
|
String value) {
|
||||||
|
set(type.toString(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the parameter name
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public void setName(String name){
|
||||||
|
this.setMember(VTParameter.name, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the parameter default value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public void setDefaultValue(String value){
|
||||||
|
this.setMember(VTParameter.defaultValue, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the parameter regexp validator
|
||||||
|
*
|
||||||
|
* @param validator
|
||||||
|
*/
|
||||||
|
public void setRegexpValidator(String validator){
|
||||||
|
this.setMember(VTParameter.regexpValidator, validator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a VirtualTableParameter member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected boolean delMember(VTParameter type) {
|
||||||
|
return ElementUtils.remove(this.getRoot(), this.getRoot().getChild(type.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the name
|
||||||
|
*
|
||||||
|
* @return true if removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delName(){
|
||||||
|
return this.delMember(VTParameter.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the default value
|
||||||
|
*
|
||||||
|
* @return true if removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delDefaultValue(){
|
||||||
|
return this.delMember(VTParameter.defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the Regexp validator
|
||||||
|
*
|
||||||
|
* @return true if removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delRegexpValidator(){
|
||||||
|
return this.delMember(VTParameter.regexpValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a VirtualTableParameter member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getMember(VTParameter type) {
|
||||||
|
Element el = getRoot().getChild(type.toString());
|
||||||
|
if (el != null)
|
||||||
|
return el.getTextTrim();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the parameter name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getName(){
|
||||||
|
return this.getMember(VTParameter.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the parameter default value
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getDefaultValue(){
|
||||||
|
return this.getMember(VTParameter.defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the parameter regexp validator
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getRegexpValidator(){
|
||||||
|
return this.getMember(VTParameter.regexpValidator);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,247 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.metadatalink;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GSMetadataLinkEncoder - encodes a metadataLink for a given GeoServer Resource
|
||||||
|
* (feature type /coverage), as follows:
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder();
|
||||||
|
* mde.setType("text/xml");
|
||||||
|
* mde.setMetadataType("ISO19115:2003");
|
||||||
|
* mde.setContent("http://www.organization.org/metadata");
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* For this example, the XML output is:
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <metadataLink>
|
||||||
|
* <type>text/xml</type>
|
||||||
|
* <metadataType>ISO19115:2003</metadataType>
|
||||||
|
* <content>http://www.organization.org/metadata</content>
|
||||||
|
* </metadataLink>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSMetadataLinkInfoEncoder extends XmlElement {
|
||||||
|
|
||||||
|
/** A class to filter the MetadataLinkInfo by content
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static class filterByContent implements Filter {
|
||||||
|
|
||||||
|
final private String key;
|
||||||
|
|
||||||
|
public filterByContent(String content) {
|
||||||
|
this.key = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
Element el = ((Element) obj)
|
||||||
|
.getChild(ResourceMetadataLinkInfo.content.toString());
|
||||||
|
if (el != null && el.getTextTrim().equals(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Filter using the MetadataLinkInfo content (metadataURL)
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* @return the filter
|
||||||
|
*/
|
||||||
|
public static Filter getFilterByContent(String content) {
|
||||||
|
return new filterByContent(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new GSMetadataLinkInfoEncoder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GSMetadataLinkInfoEncoder() {
|
||||||
|
super("metadataLink");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs quickly a MetadataLink info
|
||||||
|
*
|
||||||
|
* @param type (required)
|
||||||
|
* @param metadataType (required)
|
||||||
|
* @param content (required)
|
||||||
|
*/
|
||||||
|
public GSMetadataLinkInfoEncoder(String type, String metadataType, String content){
|
||||||
|
super("metadataLink");
|
||||||
|
this.setup(type, metadataType, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set-up quickly a metadataLinkInfo
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param metadataType
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
protected void setup(String type, String metadataType, String content) {
|
||||||
|
set(ResourceMetadataLinkInfo.type.name(), type);
|
||||||
|
set(ResourceMetadataLinkInfo.metadataType.name(), metadataType);
|
||||||
|
set(ResourceMetadataLinkInfo.content.name(), content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a MetadataLinkInfo member (type, metadataType or content)
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
protected void setMember(ResourceMetadataLinkInfo type,
|
||||||
|
String value) {
|
||||||
|
set(type.toString(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the mime type
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
public void setType(String type){
|
||||||
|
this.setMember(ResourceMetadataLinkInfo.type, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the metadata type
|
||||||
|
*
|
||||||
|
* @param metadataType
|
||||||
|
*/
|
||||||
|
public void setMetadataType(String metadataType){
|
||||||
|
this.setMember(ResourceMetadataLinkInfo.metadataType, metadataType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the content
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
public void setContent(String content){
|
||||||
|
this.setMember(ResourceMetadataLinkInfo.content, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a MetadataLinkInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return true if the metadataLinkInfo member is removed
|
||||||
|
*/
|
||||||
|
protected boolean delMember(ResourceMetadataLinkInfo type) {
|
||||||
|
return ElementUtils.remove(this.getRoot(), this.getRoot().getChild(type.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the type
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delType(){
|
||||||
|
return this.delMember(ResourceMetadataLinkInfo.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the metadata type
|
||||||
|
*
|
||||||
|
* @param metadata type
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delMetadataType(){
|
||||||
|
return this.delMember(ResourceMetadataLinkInfo.metadataType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the content
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delContent(){
|
||||||
|
return this.delMember(ResourceMetadataLinkInfo.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the MetadataLinkInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return the value of the MetadataLinkInfo member
|
||||||
|
*/
|
||||||
|
protected String getMember(ResourceMetadataLinkInfo type) {
|
||||||
|
Element el = this.getRoot().getChild(type.toString());
|
||||||
|
if (el != null)
|
||||||
|
return el.getTextTrim();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mime type
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getType(){
|
||||||
|
return this.getMember(ResourceMetadataLinkInfo.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the metadata type
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getMetadataType(){
|
||||||
|
return this.getMember(ResourceMetadataLinkInfo.metadataType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the content
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getContent(){
|
||||||
|
return this.getMember(ResourceMetadataLinkInfo.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.metadatalink;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of featureType metadataLink member
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum ResourceMetadataLinkInfo {
|
||||||
|
type, metadataType, content
|
||||||
|
|
||||||
|
}
|
||||||
@ -29,9 +29,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.filter.Filter;
|
import org.jdom.filter.Filter;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -42,7 +43,7 @@ public abstract class ElementUtils {
|
|||||||
/**
|
/**
|
||||||
* Default logger
|
* Default logger
|
||||||
*/
|
*/
|
||||||
private final static Logger LOGGER = Logger.getLogger(ElementUtils.class);
|
private final static Logger LOGGER = LoggerFactory.getLogger(ElementUtils.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -92,20 +93,20 @@ public abstract class ElementUtils {
|
|||||||
final Filter filter, final int depth)
|
final Filter filter, final int depth)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
if (root == null || filter == null || depth < 0) {
|
if (root == null || filter == null) {
|
||||||
throw new IllegalArgumentException("Bad arguments: root=" + root
|
throw new IllegalArgumentException("Bad arguments: root=" + root
|
||||||
+ " filter=" + filter + " depth=" + depth);
|
+ " filter=" + filter + " depth=" + depth);
|
||||||
}
|
}
|
||||||
final List<Element> ret = new ArrayList<Element>();
|
final List<Element> ret = new ArrayList<Element>();
|
||||||
// if match add myself
|
// if match add myself
|
||||||
if (filter.matches(root)) {
|
if (filter.matches(root)) {
|
||||||
if (LOGGER.isDebugEnabled())
|
if (LOGGER.isTraceEnabled())
|
||||||
LOGGER.debug("LOCATED-> name:" + root.getName() + " text:"
|
LOGGER.trace("LOCATED-> name:" + root.getName() + " text:"
|
||||||
+ root.getText());
|
+ root.getText());
|
||||||
ret.add(root);
|
ret.add(root);
|
||||||
}
|
}
|
||||||
// check my children
|
// check my children
|
||||||
if (depth > 1) {
|
if (depth != 0) {
|
||||||
final List<?> childrenList = root.getContent();
|
final List<?> childrenList = root.getContent();
|
||||||
final Iterator<?> it = childrenList.iterator();
|
final Iterator<?> it = childrenList.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@ -127,8 +128,8 @@ public abstract class ElementUtils {
|
|||||||
final List<Element> ret = new ArrayList<Element>();
|
final List<Element> ret = new ArrayList<Element>();
|
||||||
// if match add myself
|
// if match add myself
|
||||||
if (filter.matches(root)) {
|
if (filter.matches(root)) {
|
||||||
if (LOGGER.isDebugEnabled())
|
if (LOGGER.isTraceEnabled())
|
||||||
LOGGER.debug("LOCATED-> name:" + root.getName() + " text:"
|
LOGGER.trace("LOCATED-> name:" + root.getName() + " text:"
|
||||||
+ root.getText());
|
+ root.getText());
|
||||||
ret.add(root);
|
ret.add(root);
|
||||||
}
|
}
|
||||||
@ -139,8 +140,8 @@ public abstract class ElementUtils {
|
|||||||
if (obj instanceof Element) {
|
if (obj instanceof Element) {
|
||||||
Element el = (Element) obj;
|
Element el = (Element) obj;
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled())
|
if (LOGGER.isTraceEnabled())
|
||||||
LOGGER.debug("LOCATED-> name:" + el.getName() + " text:"
|
LOGGER.trace("LOCATED-> name:" + el.getName() + " text:"
|
||||||
+ el.getText());
|
+ el.getText());
|
||||||
|
|
||||||
ret.add(el);
|
ret.add(el);
|
||||||
@ -200,6 +201,7 @@ public abstract class ElementUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the FIRST element with name equals to the passed key
|
* return the FIRST element with name equals to the passed key
|
||||||
*
|
*
|
||||||
@ -207,7 +209,18 @@ public abstract class ElementUtils {
|
|||||||
* @param name
|
* @param name
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Element contains(final Element root, final String name)
|
public static Element contains(final Element root, final String name){
|
||||||
|
return contains(root, name, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return the FIRST element with name equals to the passed key
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Element contains(final Element root, final String name, final int deep)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if (root == null || name == null) {
|
if (root == null || name == null) {
|
||||||
throw new IllegalArgumentException("Bad arguments: root=" + root
|
throw new IllegalArgumentException("Bad arguments: root=" + root
|
||||||
@ -227,7 +240,7 @@ public abstract class ElementUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final Iterator<Element> it = search(root, filter).iterator();
|
final Iterator<Element> it = search(root, filter, deep).iterator();
|
||||||
if (it.hasNext())
|
if (it.hasNext())
|
||||||
return it.next();
|
return it.next();
|
||||||
else
|
else
|
||||||
|
|||||||
@ -155,7 +155,7 @@ public class NestedElementEncoder extends XmlElement {
|
|||||||
// if some previous similar object is found
|
// if some previous similar object is found
|
||||||
final Element search;
|
final Element search;
|
||||||
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
|
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
|
||||||
getRoot(), key, value))) != null) {
|
getRoot(), key, null))) != null) {
|
||||||
// remove it
|
// remove it
|
||||||
ElementUtils.remove(getRoot(), search);
|
ElementUtils.remove(getRoot(), search);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,8 +57,8 @@ public class PropertyXMLEncoder extends XmlElement {
|
|||||||
super(rootName);
|
super(rootName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void get(final String key, final String value) {
|
protected Element get(final String key, int deep) {
|
||||||
|
return get(getRoot(), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Element get(final String key) {
|
protected Element get(final String key) {
|
||||||
|
|||||||
@ -39,7 +39,8 @@ import org.jdom.output.XMLOutputter;
|
|||||||
*/
|
*/
|
||||||
public class XmlElement{
|
public class XmlElement{
|
||||||
|
|
||||||
private final Element root;
|
private Element root;
|
||||||
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@ -49,13 +50,37 @@ public class XmlElement{
|
|||||||
root=new Element(name);
|
root=new Element(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XmlElement(final Element e) {
|
||||||
|
root = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty constructor:<br/>
|
||||||
|
* Use {@link #setRoot()} to initialize the root
|
||||||
|
*/
|
||||||
|
protected XmlElement() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the root of this node
|
||||||
|
* @param root
|
||||||
|
*/
|
||||||
|
protected void setRoot(final Element root) {
|
||||||
|
this.root = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the root of this node
|
||||||
|
* @param name is the name of the root node
|
||||||
|
*/
|
||||||
|
protected void setRoot(final String name){
|
||||||
|
root=new Element(name);
|
||||||
|
}
|
||||||
|
|
||||||
public Element getRoot(){
|
public Element getRoot(){
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private XmlElement(){root=null;};
|
|
||||||
|
|
||||||
protected void add(final String nodename, final String nodetext) {
|
protected void add(final String nodename, final String nodetext) {
|
||||||
add(nodename,new Text(nodetext));
|
add(nodename,new Text(nodetext));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.manager;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.HTTPUtils;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract manager, common functionality and interface for all
|
||||||
|
* GeoServerREST<i>Foo</i>Manager classes.
|
||||||
|
*
|
||||||
|
* @author Oscar Fonts
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public abstract class GeoServerRESTAbstractManager {
|
||||||
|
|
||||||
|
protected final URL gsBaseUrl;
|
||||||
|
protected final String gsuser;
|
||||||
|
protected final String gspass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*
|
||||||
|
* Indicates connection parameters to remote GeoServer instance.
|
||||||
|
*
|
||||||
|
* @param restURL GeoServer REST API endpoint
|
||||||
|
* @param username GeoServer REST API authorized username
|
||||||
|
* @param password GeoServer REST API password for the former username
|
||||||
|
*/
|
||||||
|
public GeoServerRESTAbstractManager(URL restURL, String username, String password)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
try {
|
||||||
|
if (restURL == null || username == null || password == null)
|
||||||
|
throw new IllegalArgumentException("Unable to create the manager using a null argument");
|
||||||
|
|
||||||
|
this.gsBaseUrl = new URL(restURL.getProtocol(), restURL.getHost(), restURL.getPort(),
|
||||||
|
HTTPUtils.decurtSlash(restURL.getPath()), null);
|
||||||
|
|
||||||
|
this.gsuser = username;
|
||||||
|
this.gspass = password;
|
||||||
|
|
||||||
|
} catch (MalformedURLException ex) {
|
||||||
|
throw new IllegalArgumentException("URL can't be parsed properly", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,321 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.manager;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.HTTPUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import net.sf.json.JSON;
|
||||||
|
import net.sf.json.JSONObject;
|
||||||
|
|
||||||
|
import org.restlet.data.MediaType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Alessio Fabiani, GeoSolutions S.A.S.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GeoServerRESTImporterManager extends GeoServerRESTAbstractManager {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTImporterManager.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*
|
||||||
|
* @param restURL GeoServer REST API endpoint
|
||||||
|
* @param username GeoServer REST API authorized username
|
||||||
|
* @param password GeoServer REST API password for the former username
|
||||||
|
*/
|
||||||
|
public GeoServerRESTImporterManager(URL restURL, String username, String password)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
super(restURL, username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the Import JSON Object given its identifier
|
||||||
|
*
|
||||||
|
* @param imp int: Import context number ID
|
||||||
|
*/
|
||||||
|
public JSONObject getImport(int imp) throws Exception {
|
||||||
|
JSON json = HTTPUtils.getAsJSON(String.format(buildUrl()+"/%d", imp), gsuser , gspass);
|
||||||
|
return ((JSONObject)json).getJSONObject("import");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the Import Task JSON Object given its identifier and task number
|
||||||
|
*
|
||||||
|
* @param imp int: Import context number ID
|
||||||
|
* @param task int: Task number
|
||||||
|
*/
|
||||||
|
public JSONObject getTask(int imp, int task) throws Exception {
|
||||||
|
JSON json = HTTPUtils.getAsJSON(String.format(buildUrl()+"/%d/tasks/%d?expand=all", imp, task), gsuser , gspass);
|
||||||
|
return ((JSONObject)json).getJSONObject("task");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example usage:
|
||||||
|
* <pre>
|
||||||
|
* // Creates a new Importer Context and gets back the ID
|
||||||
|
* int i = postNewImport();
|
||||||
|
*
|
||||||
|
* // Attaches to the new Importer Context a Task pointing to a shapefile's zip archive
|
||||||
|
* int t = postNewTaskAsMultiPartForm(i, "/path_to/shape/archsites_no_crs.zip");
|
||||||
|
*
|
||||||
|
* // Check that the Task was actually created and that the CRS has not recognized in this case
|
||||||
|
* JSONObject task = getTask(i, t);
|
||||||
|
* assertEquals("NO_CRS", task.getString("state"));
|
||||||
|
*
|
||||||
|
* // Prepare the JSON String instructing the Task about the SRS to use
|
||||||
|
* String json =
|
||||||
|
* "{" +
|
||||||
|
* "\"task\": {" +
|
||||||
|
* "\"layer\": {" +
|
||||||
|
* "\"srs\": \"EPSG:4326\"" +
|
||||||
|
* "}" +
|
||||||
|
* "}" +
|
||||||
|
* "}";
|
||||||
|
*
|
||||||
|
* // Performing the Task update
|
||||||
|
* putTask(i, t, json);
|
||||||
|
*
|
||||||
|
* // Double check that the Task is in the READY state
|
||||||
|
* task = getTask(i, t);
|
||||||
|
* assertEquals("READY", task.getString("state"));
|
||||||
|
* assertEquals("gs_archsites", task.getJSONObject("layer").getJSONObject("style").getString("name"));
|
||||||
|
*
|
||||||
|
* // Prepare the JSON String instructing the Task avout the SLD to use for the new Layer
|
||||||
|
* json =
|
||||||
|
* "{" +
|
||||||
|
* "\"task\": {" +
|
||||||
|
* "\"layer\": {" +
|
||||||
|
* "\"style\": {" +
|
||||||
|
* "\"name\": \"point\"" +
|
||||||
|
* "}" +
|
||||||
|
* "}" +
|
||||||
|
* "}" +
|
||||||
|
* "}";
|
||||||
|
*
|
||||||
|
* // Performing the Task update
|
||||||
|
* putTask(i, t,json);
|
||||||
|
*
|
||||||
|
* // Double check that the Task is in the READY state and that the Style has been correctly updated
|
||||||
|
* task = getTask(i, t);
|
||||||
|
* assertEquals("READY", task.getString("state"));
|
||||||
|
* assertEquals("point", task.getJSONObject("layer").getJSONObject("style").getString("name"));
|
||||||
|
*
|
||||||
|
* // Finally starts the Import ...
|
||||||
|
* postImport(i);
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param imp int: Import context number ID
|
||||||
|
* @param task int: Task number
|
||||||
|
* @param json String: JSON containing the Task properties to be updated
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void putTask(int imp, int task, final String json) throws Exception {
|
||||||
|
//HTTPUtils.putJson(String.format(buildUrl()+"/%d/tasks/%d", imp, task), json, gsuser, gspass);
|
||||||
|
HTTPUtils.put(String.format(buildUrl()+"/%d/tasks/%d", imp, task), json, "text/plain", gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just update the Layers properties associated to a Task (t) in the Importer Context (i).
|
||||||
|
*
|
||||||
|
* e.g.:
|
||||||
|
* <pre>
|
||||||
|
* putTaskLayer(i, t, "{\"title\":\"Archsites\", \"abstract\":\"Archeological Sites\"}");
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param imp int: Import context number ID
|
||||||
|
* @param task int: Task number
|
||||||
|
* @param json String: JSON containing the Layer properties to be updated
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void putTaskLayer(int imp, int task, final String json) throws Exception {
|
||||||
|
HTTPUtils.putJson(String.format(buildUrl()+"/%d/tasks/%d/layer", imp, task), json, gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just update the Layers properties associated to a Task (t) in the Importer Context (i).
|
||||||
|
*
|
||||||
|
* e.g.:
|
||||||
|
* <pre>
|
||||||
|
* putTaskLayer(i, t, "{\"title\":\"Archsites\", \"abstract\":\"Archeological Sites\"}");
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param imp int: Import context number ID
|
||||||
|
* @param task int: Task number
|
||||||
|
* @param json String: JSON containing the Layer properties to be updated
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void postTaskTransform(int imp, int task, final String json) throws Exception {
|
||||||
|
HTTPUtils.postJson(String.format(buildUrl()+"/%d/tasks/%d/transforms", imp, task), json, gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an empty Importer Context.
|
||||||
|
*
|
||||||
|
* @return The new Importer Context ID
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public int postNewImport() throws Exception {
|
||||||
|
return postNewImport(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* e.g.:
|
||||||
|
* <pre>
|
||||||
|
* String body =
|
||||||
|
* "{" +
|
||||||
|
* "\"import\": { " +
|
||||||
|
* "\"data\": {" +
|
||||||
|
* "\"type\": \"mosaic\", " +
|
||||||
|
* "\"time\": {" +
|
||||||
|
* " \"mode\": \"auto\"" +
|
||||||
|
* "}" +
|
||||||
|
* "}" +
|
||||||
|
* "}" +
|
||||||
|
* "}";
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param body JSON String representing the Importer Context definition
|
||||||
|
* @return The new Importer Context ID
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public int postNewImport(String body) throws Exception {
|
||||||
|
String resp = body == null ? HTTPUtils.post(buildUrl(), "", "text/plain", gsuser, gspass)
|
||||||
|
: HTTPUtils.postJson(buildUrl(), body, gsuser, gspass);
|
||||||
|
|
||||||
|
JSONObject json = (JSONObject) HTTPUtils.json(resp);
|
||||||
|
JSONObject imprt = json.getJSONObject("import");
|
||||||
|
return imprt.getInt("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actually starts the READY State Import.
|
||||||
|
*
|
||||||
|
* @param imp int: Import context number ID
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void postImport(int imp) throws Exception {
|
||||||
|
HTTPUtils.post(buildUrl()+"/" + imp + "?exec=true", "", "text/plain", gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param imp int: Import context number ID
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public int postNewTaskAsMultiPartForm(int imp, String data) throws Exception {
|
||||||
|
String resp = HTTPUtils.postMultipartForm(buildUrl()+"/" + imp + "/tasks", unpack(data), gsuser, gspass);
|
||||||
|
|
||||||
|
JSONObject json = (JSONObject) HTTPUtils.json(resp);
|
||||||
|
|
||||||
|
JSONObject task = json.getJSONObject("task");
|
||||||
|
return task.getInt("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to attach a new zip file to an existing Importer Context.
|
||||||
|
*
|
||||||
|
* @param imp int: Import context number ID
|
||||||
|
* @param path
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public int putNewTask(int imp, String path) throws Exception {
|
||||||
|
File zip = new File(path);
|
||||||
|
|
||||||
|
String resp = HTTPUtils.put(buildUrl()+"/" + imp + "/tasks/" + zip.getName(), zip, MediaType.APPLICATION_ZIP.toString(), gsuser, gspass);
|
||||||
|
|
||||||
|
JSONObject json = (JSONObject) HTTPUtils.json(resp);
|
||||||
|
|
||||||
|
JSONObject task = json.getJSONObject("task");
|
||||||
|
return task.getInt("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
//=========================================================================
|
||||||
|
// Util methods
|
||||||
|
//=========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the base REST URL for the imports
|
||||||
|
*/
|
||||||
|
protected String buildUrl() {
|
||||||
|
StringBuilder sUrl = new StringBuilder(gsBaseUrl.toString()).append("/rest/imports");
|
||||||
|
|
||||||
|
return sUrl.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a temporary file
|
||||||
|
*
|
||||||
|
* @return Path to the temporary file
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static File tmpDir() throws Exception {
|
||||||
|
File dir = File.createTempFile("importer", "data", new File("target"));
|
||||||
|
dir.delete();
|
||||||
|
dir.mkdirs();
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expands a zip archive into the temporary folder.
|
||||||
|
*
|
||||||
|
* @param path The absolute path to the source zip file
|
||||||
|
* @return Path to the temporary folder containing the expanded files
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static File unpack(String path) throws Exception {
|
||||||
|
return unpack(path, tmpDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expands a zip archive into the target folder.
|
||||||
|
*
|
||||||
|
* @param path The absolute path to the source zip file
|
||||||
|
* @param dir Full path of the target folder where to expand the archive
|
||||||
|
* @return Path to the temporary folder containing the expanded files
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static File unpack(String path, File dir) throws Exception {
|
||||||
|
|
||||||
|
File file = new File(path);
|
||||||
|
|
||||||
|
//new VFSWorker().extractTo(file, dir);
|
||||||
|
if (!file.delete()) {
|
||||||
|
// fail early as tests will expect it's deleted
|
||||||
|
throw new IOException("deletion failed during extraction");
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.manager;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.Format;
|
||||||
|
import it.geosolutions.geoserver.rest.HTTPUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage stores.
|
||||||
|
*
|
||||||
|
* To pass connection parameters, use the encoders derived from
|
||||||
|
* {@link GSAbstractDatastoreEncoder}.
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoServerRESTStoreManager extends GeoServerRESTAbstractManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*
|
||||||
|
* @param restURL GeoServer REST API endpoint
|
||||||
|
* @param username GeoServer REST API authorized username
|
||||||
|
* @param password GeoServer REST API password for the former username
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
*/
|
||||||
|
public GeoServerRESTStoreManager(URL restURL, String username, String password)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
super(restURL, username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a store.
|
||||||
|
*
|
||||||
|
* @param workspace Name of the workspace to contain the store. This
|
||||||
|
* will also be the prefix of any layer names contained in the
|
||||||
|
* store.
|
||||||
|
* @param datastore the set of parameters to be set to the store
|
||||||
|
* (including connection parameters).
|
||||||
|
* @return <TT>true</TT> if the store has been successfully created,
|
||||||
|
* <TT>false</TT> otherwise
|
||||||
|
*/
|
||||||
|
public boolean create(String workspace, GSAbstractStoreEncoder store) {
|
||||||
|
String sUrl = HTTPUtils.append(gsBaseUrl, "/rest/workspaces/", workspace, "/", store.getStoreType().toString(),".",Format.XML.toString()).toString();
|
||||||
|
String xml = store.toString();
|
||||||
|
String result = HTTPUtils.postXml(sUrl, xml, gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a store.
|
||||||
|
*
|
||||||
|
* @param workspace Name of the workspace that contains the store.
|
||||||
|
* @param datastore the set of parameters to be set to the store
|
||||||
|
* (including connection parameters).
|
||||||
|
* @return <TT>true</TT> if the store has been successfully updated,
|
||||||
|
* <TT>false</TT> otherwise
|
||||||
|
*/
|
||||||
|
public boolean update(String workspace, GSAbstractStoreEncoder store) {
|
||||||
|
String sUrl = HTTPUtils.append(gsBaseUrl, "/rest/workspaces/", workspace,"/", store.getStoreType().toString(),"/",
|
||||||
|
store.getName(),".",Format.XML.toString()).toString();
|
||||||
|
String xml = store.toString();
|
||||||
|
String result = HTTPUtils.putXml(sUrl, xml, gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a given CoverageStore in a given Workspace.
|
||||||
|
*
|
||||||
|
* @param workspace The name of the workspace
|
||||||
|
* @param storename The name of the CoverageStore to remove.
|
||||||
|
* @param recurse if remove should be performed recursively
|
||||||
|
* @return <TT>true</TT> if the CoverageStore was successfully removed.
|
||||||
|
* @throws MalformedURLException
|
||||||
|
*/
|
||||||
|
public boolean remove(final String workspace, final GSAbstractStoreEncoder store,
|
||||||
|
final boolean recurse) throws IllegalArgumentException, MalformedURLException {
|
||||||
|
// if (workspace == null || storename == null)
|
||||||
|
// throw new IllegalArgumentException("Arguments may not be null!");
|
||||||
|
// if (workspace.isEmpty() || storename.isEmpty())
|
||||||
|
// throw new IllegalArgumentException("Arguments may not be empty!");
|
||||||
|
|
||||||
|
final StringBuilder url=HTTPUtils.append(gsBaseUrl,"/rest/workspaces/",workspace,"/", store.getStoreType().toString(), "/",store.getName());
|
||||||
|
if (recurse)
|
||||||
|
url.append("?recurse=true");
|
||||||
|
final URL deleteStore = new URL(url.toString());
|
||||||
|
|
||||||
|
boolean deleted = HTTPUtils.delete(deleteStore.toExternalForm(), gsuser, gspass);
|
||||||
|
// if (!deleted) {
|
||||||
|
// LOGGER.warn("Could not delete CoverageStore " + workspace + ":" + storename);
|
||||||
|
// } else {
|
||||||
|
// LOGGER.info("CoverageStore successfully deleted " + workspace + ":" + storename);
|
||||||
|
// }
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,499 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.manager;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.UploadMethod;
|
||||||
|
import it.geosolutions.geoserver.rest.HTTPUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageGranulesList;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageIndexSchema;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage GeoTools StructuredGridCoverageReader. It allows to create a store from a file or harvest the coverages contained in a file, to delete
|
||||||
|
* granules from an existing coverage and eventually to get information about the granules inside a StructuredGridCoverageReader.
|
||||||
|
*
|
||||||
|
* @author Simone Giannecchini, GeoSolutions
|
||||||
|
*/
|
||||||
|
public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerRESTAbstractManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Option that tells GeoServer whether or not to configure all the coverages for a certain ImageMosaic.
|
||||||
|
*
|
||||||
|
* @author Simone Giannecchini, GeoSolutions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum ConfigureCoveragesOption{
|
||||||
|
NONE,
|
||||||
|
ALL;
|
||||||
|
|
||||||
|
public static ConfigureCoveragesOption getDefault() {
|
||||||
|
return ALL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default logger
|
||||||
|
*/
|
||||||
|
private final static Logger LOGGER = LoggerFactory
|
||||||
|
.getLogger(GeoServerRESTStructuredGridCoverageReaderManager.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*
|
||||||
|
* @param restURL GeoServer REST API endpoint
|
||||||
|
* @param username GeoServer REST API authorized username
|
||||||
|
* @param password GeoServer REST API password for the former username
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
*/
|
||||||
|
public GeoServerRESTStructuredGridCoverageReaderManager(URL restURL, String username,
|
||||||
|
String password) throws IllegalArgumentException {
|
||||||
|
super(restURL, username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ImageMosaic with the provided configuration provided as a zip file.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* This call configures all the coverages contained in the ImageMosaic.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param the absolute path to the file to upload
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
|
*/
|
||||||
|
public boolean create(String workspace, String coverageStore, String path) {
|
||||||
|
return create(workspace, coverageStore, path, ConfigureCoveragesOption.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ImageMosaic with the provided configuration provided as a zip file.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* With the options configure we can decide whether or not to configure or not the coverages contained in the ImageMosaic.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param the absolute path to the file to upload
|
||||||
|
* @param configureOpt tells GeoServer whether to configure all coverages in this mosaic (ALL) or none of them (NONE).
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
|
*/
|
||||||
|
public boolean create(String workspace, String coverageStore, String path, ConfigureCoveragesOption configureOpt) {
|
||||||
|
// checks
|
||||||
|
checkString(workspace);
|
||||||
|
checkString(coverageStore);
|
||||||
|
checkString(path);
|
||||||
|
final File zipFile= new File(path);
|
||||||
|
if(!zipFile.exists()||!zipFile.isFile()||!zipFile.canRead()){
|
||||||
|
throw new IllegalArgumentException("The provided pathname does not point to a valide zip file: "+path);
|
||||||
|
}
|
||||||
|
// is it a zip?
|
||||||
|
ZipFile zip=null;
|
||||||
|
try{
|
||||||
|
zip= new ZipFile(zipFile);
|
||||||
|
zip.getName();
|
||||||
|
}catch (Exception e) {
|
||||||
|
LOGGER.trace(e.getLocalizedMessage(),e.getStackTrace());
|
||||||
|
throw new IllegalArgumentException("The provided pathname does not point to a valide zip file: "+path);
|
||||||
|
}finally{
|
||||||
|
if(zip!=null){
|
||||||
|
try {
|
||||||
|
zip.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// swallow
|
||||||
|
LOGGER.trace(e.getLocalizedMessage(),e.getStackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create URL
|
||||||
|
StringBuilder ss=HTTPUtils.append(gsBaseUrl, "/rest/workspaces/", workspace, "/coveragestores/",
|
||||||
|
coverageStore, "/file.imagemosaic");
|
||||||
|
switch(configureOpt){
|
||||||
|
case ALL:
|
||||||
|
break;
|
||||||
|
case NONE:
|
||||||
|
ss.append("?configure=none");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unrecognized COnfigureOption: "+configureOpt);
|
||||||
|
}
|
||||||
|
String sUrl = ss.toString();
|
||||||
|
|
||||||
|
// POST request
|
||||||
|
String result = HTTPUtils.put(sUrl, zipFile, "application/zip", gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a store or harvest the coverage from the provided <b>external</b> path.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param format the format of the file to upload
|
||||||
|
* @param the absolute path to the file to upload
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
|
*/
|
||||||
|
public boolean harvestExternal(String workspace, String coverageStore, String format,
|
||||||
|
String path) {
|
||||||
|
// checks
|
||||||
|
checkString(workspace);
|
||||||
|
checkString(coverageStore);
|
||||||
|
checkString(format);
|
||||||
|
checkString(path);
|
||||||
|
|
||||||
|
// create URL
|
||||||
|
String sUrl = HTTPUtils.append(gsBaseUrl, "/rest/workspaces/", workspace, "/coveragestores/",
|
||||||
|
coverageStore, "/", UploadMethod.EXTERNAL.toString(), ".", format).toString();
|
||||||
|
|
||||||
|
// POST request
|
||||||
|
String result = HTTPUtils.post(sUrl, "file://" + path, "text/plain", gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the provided string for not being null or empty.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* It throws an exception in case the string is either null or empty.
|
||||||
|
*
|
||||||
|
* @param string the {@link String} to be checked
|
||||||
|
*/
|
||||||
|
private static void checkString(String string) {
|
||||||
|
if (string == null) {
|
||||||
|
throw new NullPointerException("Provided string is is null!");
|
||||||
|
}
|
||||||
|
if (string.length() <= 0) {
|
||||||
|
throw new IllegalArgumentException("Provided string is is empty!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove granules from a structured coverage, by providing a CQL filter.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param coverage the name of the target coverage from which we are going to remove
|
||||||
|
* @param filter the absolute path to the file to upload
|
||||||
|
*
|
||||||
|
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
||||||
|
*
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
*
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
|
*/
|
||||||
|
public boolean removeGranulesByCQL(final String workspace, String coverageStore,
|
||||||
|
String coverage, String filter) throws UnsupportedEncodingException {
|
||||||
|
// checks
|
||||||
|
checkString(workspace);
|
||||||
|
checkString(coverage);
|
||||||
|
checkString(filter);
|
||||||
|
checkString(coverageStore);
|
||||||
|
|
||||||
|
// does it exist?
|
||||||
|
RESTStructuredCoverageGranulesList granulesList = null;
|
||||||
|
try {
|
||||||
|
granulesList = getGranules(workspace, coverageStore, coverage, filter, null, 1);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (granulesList == null || granulesList.isEmpty()) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("Granules for filter: " + filter + " does not exist for coverage "
|
||||||
|
+ coverage);
|
||||||
|
}
|
||||||
|
return true; // nothing to remove
|
||||||
|
}
|
||||||
|
|
||||||
|
// method
|
||||||
|
String sUrl = HTTPUtils.append(gsBaseUrl, "/rest/workspaces/", workspace, "/coveragestores",
|
||||||
|
"/", coverageStore, "/coverages/", coverage, "/index/granules?filter=",
|
||||||
|
URLEncoder.encode(filter, "UTF-8")).toString();
|
||||||
|
if (!HTTPUtils.delete(sUrl, gsuser, gspass)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// does it exist?
|
||||||
|
granulesList = null;
|
||||||
|
try {
|
||||||
|
granulesList = getGranules(workspace, coverageStore, coverage, filter, null, 1);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (granulesList == null || granulesList.isEmpty()) {
|
||||||
|
return true; // nothing to remove
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a granule from a structured coverage by id.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param coverage the name of the target coverage from which we are going to remove
|
||||||
|
* @param filter the absolute path to the file to upload
|
||||||
|
*
|
||||||
|
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
||||||
|
*
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
*
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
|
*/
|
||||||
|
public boolean removeGranuleById(final String workspace, String coverageStore, String coverage,
|
||||||
|
String granuleId) {
|
||||||
|
// checks
|
||||||
|
checkString(workspace);
|
||||||
|
checkString(coverage);
|
||||||
|
checkString(granuleId);
|
||||||
|
checkString(coverageStore);
|
||||||
|
|
||||||
|
// does it exist?
|
||||||
|
RESTStructuredCoverageGranulesList granule = null;
|
||||||
|
try {
|
||||||
|
granule = getGranuleById(workspace, coverageStore, coverage, granuleId);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (granule == null) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("Granule for id: " + granuleId + " does not exist for coverage "
|
||||||
|
+ coverage);
|
||||||
|
}
|
||||||
|
return true; // nothing to remove
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete
|
||||||
|
String sUrl = HTTPUtils.append(gsBaseUrl, "/rest/workspaces/", workspace, "/coveragestores",
|
||||||
|
"/", coverageStore, "/coverages/", coverage, "/index/granules/", granuleId)
|
||||||
|
.toString();
|
||||||
|
if (!HTTPUtils.delete(sUrl, gsuser, gspass)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// has it been canceled?
|
||||||
|
// does it exist?
|
||||||
|
granule = null;
|
||||||
|
try {
|
||||||
|
granule = getGranuleById(workspace, coverageStore, coverage, granuleId);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (granule == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about the schema of the index for a structured coverage.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param format the format of the file to upload
|
||||||
|
*
|
||||||
|
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
||||||
|
*
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
*
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
|
*/
|
||||||
|
public RESTStructuredCoverageIndexSchema getGranuleIndexSchema(final String workspace,
|
||||||
|
String coverageStore, String coverage) throws MalformedURLException {
|
||||||
|
// checks
|
||||||
|
checkString(workspace);
|
||||||
|
checkString(coverage);
|
||||||
|
checkString(coverageStore);
|
||||||
|
|
||||||
|
// create URL and then call it
|
||||||
|
String sUrl = HTTPUtils.append(gsBaseUrl, "/rest/workspaces/", workspace, "/coveragestores/",
|
||||||
|
coverageStore, "/coverages/", coverage, "/index.xml").toString();
|
||||||
|
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
||||||
|
if (result != null) {
|
||||||
|
return RESTStructuredCoverageIndexSchema.build(result);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about all the granules for a coverage with optional filter and paging.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param coverage the name of the target coverage
|
||||||
|
*
|
||||||
|
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
||||||
|
*
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
*
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
|
*/
|
||||||
|
public RESTStructuredCoverageGranulesList getGranules(final String workspace,
|
||||||
|
String coverageStore, String coverage)
|
||||||
|
throws MalformedURLException, UnsupportedEncodingException {
|
||||||
|
return getGranules(workspace, coverageStore, coverage, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about the granules for a coverage with optional filter and paging.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param coverage the name of the target coverage
|
||||||
|
* @param filter the format of the file to upload, can be <code>null</code> to include all the granules
|
||||||
|
* @param offset the start page, can be <code>null</code> or an integer
|
||||||
|
* @param limit the dimension of the page, can be <code>null</code> or a positive integer
|
||||||
|
*
|
||||||
|
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
||||||
|
*
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
*
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
|
*/
|
||||||
|
public RESTStructuredCoverageGranulesList getGranules(final String workspace,
|
||||||
|
String coverageStore, String coverage, String filter, Integer offset, Integer limit)
|
||||||
|
throws MalformedURLException, UnsupportedEncodingException {
|
||||||
|
// checks
|
||||||
|
checkString(workspace);
|
||||||
|
checkString(coverage);
|
||||||
|
checkString(coverageStore);
|
||||||
|
|
||||||
|
// method
|
||||||
|
boolean append = false;
|
||||||
|
String sUrl = HTTPUtils.append(gsBaseUrl, "/rest/workspaces/", workspace, "/coveragestores/",
|
||||||
|
coverageStore, "/coverages/", coverage, "/index/granules.xml").toString();
|
||||||
|
if (filter != null && !filter.isEmpty()) {
|
||||||
|
append = true;
|
||||||
|
sUrl = HTTPUtils.append(sUrl, "?filter=", URLEncoder.encode(filter, "UTF-8"))
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
if (offset != null) {
|
||||||
|
if (offset < 0)
|
||||||
|
offset = 0;
|
||||||
|
sUrl = HTTPUtils.append(sUrl, append ? "&offset=" : "?offset=", offset.toString())
|
||||||
|
.toString();
|
||||||
|
append = true;
|
||||||
|
}
|
||||||
|
if (limit != null) {
|
||||||
|
if (limit < 1) {
|
||||||
|
limit = 1;
|
||||||
|
}
|
||||||
|
sUrl = HTTPUtils.append(sUrl, append ? "&limit=" : "?limit=", limit.toString())
|
||||||
|
.toString();
|
||||||
|
append = true;
|
||||||
|
}
|
||||||
|
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
||||||
|
if (result != null) {
|
||||||
|
return RESTStructuredCoverageGranulesList.build(result);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about a granule for a structured coverage.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param format the format of the file to upload
|
||||||
|
* @param the absolute path to the file to upload
|
||||||
|
* @param id the ID of the granule to get information for
|
||||||
|
*
|
||||||
|
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
||||||
|
*
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
*
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
|
*/
|
||||||
|
public RESTStructuredCoverageGranulesList getGranuleById(final String workspace,
|
||||||
|
String coverageStore, String coverage, String id) throws MalformedURLException,
|
||||||
|
UnsupportedEncodingException {
|
||||||
|
// checks
|
||||||
|
checkString(workspace);
|
||||||
|
checkString(coverage);
|
||||||
|
checkString(coverageStore);
|
||||||
|
checkString(id);
|
||||||
|
try {
|
||||||
|
Integer.parseInt(id);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// method
|
||||||
|
String sUrl = HTTPUtils.append(gsBaseUrl, "/rest/workspaces/", workspace, "/coveragestores/",
|
||||||
|
coverageStore, "/coverages/", coverage, "/index/granules/", id, ".xml").toString();
|
||||||
|
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
||||||
|
if (result != null) {
|
||||||
|
return RESTStructuredCoverageGranulesList.build(result);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,791 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2015 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.manager;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||||
|
import it.geosolutions.geoserver.rest.HTTPUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.Util;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTStyle;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTStyleList;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.xpath.XPath;
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpression;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author ETj (etj at geo-solutions.it)
|
||||||
|
*/
|
||||||
|
public class GeoServerRESTStyleManager extends GeoServerRESTAbstractManager {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTStyleManager.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*
|
||||||
|
* @param restURL GeoServer REST API endpoint
|
||||||
|
* @param username GeoServer REST API authorized username
|
||||||
|
* @param password GeoServer REST API password for the former username
|
||||||
|
*/
|
||||||
|
public GeoServerRESTStyleManager(URL restURL, String username, String password)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
super(restURL, username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a Style exists in the configured GeoServer instance.
|
||||||
|
* @param name the name of the style to check for.
|
||||||
|
* @return <TT>true</TT> on HTTP 200, <TT>false</TT> on HTTP 404
|
||||||
|
* @throws RuntimeException if any other HTTP code than 200 or 404 was retrieved.
|
||||||
|
*/
|
||||||
|
public boolean existsStyle(String name) throws RuntimeException {
|
||||||
|
return existsStyle(name, Util.DEFAULT_QUIET_ON_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a Style exists in the configured GeoServer instance. User can choose if log a possible exception or not
|
||||||
|
* @param name the name of the style to check for.
|
||||||
|
* @param quietOnNotFound if true, mute exception if false is returned
|
||||||
|
* @return <TT>true</TT> on HTTP 200, <TT>false</TT> on HTTP 404
|
||||||
|
* @throws RuntimeException if any other HTTP code than 200 or 404 was retrieved.
|
||||||
|
*/
|
||||||
|
public boolean existsStyle(String name, boolean quietOnNotFound) {
|
||||||
|
String url = buildXmlUrl(null, name);
|
||||||
|
String composed = Util.appendQuietOnNotFound(quietOnNotFound, url);
|
||||||
|
return HTTPUtils.exists(composed , gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get summary info about all Styles.
|
||||||
|
*
|
||||||
|
* @return summary info about Styles as a {@link RESTStyleList}
|
||||||
|
*/
|
||||||
|
public RESTStyleList getStyles() {
|
||||||
|
String url = "/rest/styles.xml";
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("### Retrieving Styles list from " + url);
|
||||||
|
}
|
||||||
|
|
||||||
|
String response = HTTPUtils.get(gsBaseUrl + url, gsuser, gspass);
|
||||||
|
return RESTStyleList.build(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESTStyle getStyle(String name) {
|
||||||
|
String url = buildXmlUrl(null, name);
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("### Retrieving Style " + name + " from " + url);
|
||||||
|
}
|
||||||
|
|
||||||
|
String response = HTTPUtils.get(url, gsuser, gspass);
|
||||||
|
return RESTStyle.build(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SLD body of a Style.
|
||||||
|
*/
|
||||||
|
public String getSLD(String styleName) {
|
||||||
|
String url = buildUrl(null, styleName, ".sld");
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("### Retrieving SLD body from " + url);
|
||||||
|
}
|
||||||
|
return HTTPUtils.get( url, gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//=========================================================================
|
||||||
|
// Workspaces
|
||||||
|
//=========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public boolean existsStyle(String workspace, String name) {
|
||||||
|
return existsStyle(workspace, name, Util.DEFAULT_QUIET_ON_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since GeoServer 2.6
|
||||||
|
*/
|
||||||
|
public boolean existsStyle(String workspace, String name, boolean quietOnNotFound) {
|
||||||
|
String url = buildXmlUrl(workspace, name);
|
||||||
|
String composed = Util.appendQuietOnNotFound(quietOnNotFound, url);
|
||||||
|
return HTTPUtils.exists(composed , gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get summary info about Styles in a workspace.
|
||||||
|
*
|
||||||
|
* @return summary info about Styles as a {@link RESTStyleList}
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public RESTStyleList getStyles(String workspace) {
|
||||||
|
String url = "/rest/workspaces/"+workspace+"/styles.xml";
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("### Retrieving Styles list from " + url);
|
||||||
|
}
|
||||||
|
|
||||||
|
String response = HTTPUtils.get(gsBaseUrl + url, gsuser, gspass);
|
||||||
|
return RESTStyleList.build(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public RESTStyle getStyle(String workspace, String name) {
|
||||||
|
String url = buildXmlUrl(workspace, name);
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("### Retrieving Style " + name + " from " + url);
|
||||||
|
}
|
||||||
|
|
||||||
|
String response = HTTPUtils.get(url, gsuser, gspass);
|
||||||
|
return RESTStyle.build(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SLD body of a Style.
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public String getSLD(String workspace, String name) {
|
||||||
|
String url = buildUrl(workspace, name, ".sld");
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("### Retrieving SLD body from " + url);
|
||||||
|
}
|
||||||
|
return HTTPUtils.get(url, gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
//=========================================================================
|
||||||
|
// Publishing
|
||||||
|
//=========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style.
|
||||||
|
*
|
||||||
|
* @param sldBody the full SLD document as a String.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
*/
|
||||||
|
public boolean publishStyle(String sldBody) {
|
||||||
|
/*
|
||||||
|
* This is the equivalent call with cUrl:
|
||||||
|
*
|
||||||
|
* {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \
|
||||||
|
* http://$GSIP:$GSPORT/$SERVLET/rest/styles}
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
return publishStyle(sldBody, null);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
if (LOGGER.isErrorEnabled()) {
|
||||||
|
LOGGER.error(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style, assigning it a name.
|
||||||
|
*
|
||||||
|
* @param sldBody the full SLD document as a String.
|
||||||
|
* @param name the Style name.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if the style body is null or empty.
|
||||||
|
*/
|
||||||
|
public boolean publishStyle(final String sldBody, final String name)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
/*
|
||||||
|
* This is the equivalent call with cUrl:
|
||||||
|
*
|
||||||
|
* {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \
|
||||||
|
* http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=name}
|
||||||
|
*/
|
||||||
|
if (sldBody == null || sldBody.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style body may not be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
String sUrl = buildPostUrl(null, name);
|
||||||
|
|
||||||
|
final String result = HTTPUtils.post(sUrl, sldBody, "application/vnd.ogc.sld+xml", gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style.
|
||||||
|
*
|
||||||
|
* @param sldFile the File containing the SLD document.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
*/
|
||||||
|
public boolean publishStyle(File sldFile) {
|
||||||
|
return publishStyle(sldFile, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style, assigning it a name.
|
||||||
|
*
|
||||||
|
* @param sldFile the File containing the SLD document.
|
||||||
|
* @param name the Style name.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
*/
|
||||||
|
public boolean publishStyle(File sldFile, String name) {
|
||||||
|
String sUrl = buildPostUrl(null, name);
|
||||||
|
LOGGER.debug("POSTing new style " + name + " to " + sUrl);
|
||||||
|
String result = HTTPUtils.post(sUrl, sldFile, GeoServerRESTPublisher.Format.SLD.getContentType(), gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style, assigning it a name and choosing the raw
|
||||||
|
* format.
|
||||||
|
*
|
||||||
|
* @param sldBody the full SLD document as a String.
|
||||||
|
* @param name the Style name.
|
||||||
|
* @param raw the raw format
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
*/
|
||||||
|
public boolean publishStyle(final String sldBody, final String name, final boolean raw) {
|
||||||
|
/*
|
||||||
|
* This is the equivalent call with cUrl:
|
||||||
|
*
|
||||||
|
* {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \
|
||||||
|
* http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=$name&raw=$raw}
|
||||||
|
*/
|
||||||
|
if (sldBody == null || sldBody.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style body may not be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sUrl = new StringBuilder(buildPostUrl(null, name));
|
||||||
|
Util.appendParameter(sUrl, "raw", ""+raw);
|
||||||
|
String contentType = GeoServerRESTPublisher.Format.SLD.getContentType();
|
||||||
|
if(!this.checkSLD10Version(sldBody)){
|
||||||
|
contentType = GeoServerRESTPublisher.Format.SLD_1_1_0.getContentType();
|
||||||
|
}
|
||||||
|
LOGGER.debug("POSTing new style " + name + " to " + sUrl + " using version: " + contentType);
|
||||||
|
String result = HTTPUtils.post(sUrl.toString(), sldBody, contentType, gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style, assigning it a name and choosing the raw
|
||||||
|
* format.
|
||||||
|
*
|
||||||
|
* @param sldFile the File containing the SLD document.
|
||||||
|
* @param name the Style name.
|
||||||
|
* @param raw the raw format
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
*/
|
||||||
|
public boolean publishStyle(final File sldFile, final String name, final boolean raw) {
|
||||||
|
/*
|
||||||
|
* This is the equivalent call with cUrl:
|
||||||
|
*
|
||||||
|
* {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \
|
||||||
|
* http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=$name&raw=$raw}
|
||||||
|
*/
|
||||||
|
StringBuilder sUrl = new StringBuilder(buildPostUrl(null, name));
|
||||||
|
Util.appendParameter(sUrl, "raw", ""+raw);
|
||||||
|
String contentType = GeoServerRESTPublisher.Format.SLD.getContentType();
|
||||||
|
if(!this.checkSLD10Version(sldFile)){
|
||||||
|
contentType = GeoServerRESTPublisher.Format.SLD_1_1_0.getContentType();
|
||||||
|
}
|
||||||
|
LOGGER.debug("POSTing new style " + name + " to " + sUrl + " using version: " + contentType);
|
||||||
|
String result = HTTPUtils.post(sUrl.toString(), sldFile, contentType, gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a Style.
|
||||||
|
*
|
||||||
|
* @param sldFile the File containing the SLD document.
|
||||||
|
* @param name the Style name.
|
||||||
|
* @param raw the raw format
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if the style body or name are null or empty.
|
||||||
|
*/
|
||||||
|
public boolean updateStyle(final File sldFile, final String name, final boolean raw)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
/*
|
||||||
|
* This is the equivalent call with cUrl:
|
||||||
|
*
|
||||||
|
* {@code curl -u admin:geoserver -XPUT \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \
|
||||||
|
* http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=$name&raw=$raw}
|
||||||
|
*/
|
||||||
|
if (sldFile == null) {
|
||||||
|
throw new IllegalArgumentException("Unable to updateStyle using a null parameter file");
|
||||||
|
} else if (name == null || name.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style name may not be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sUrl = new StringBuilder(buildUrl(null, name, null));
|
||||||
|
Util.appendParameter(sUrl, "raw", ""+raw);
|
||||||
|
String contentType = GeoServerRESTPublisher.Format.SLD.getContentType();
|
||||||
|
if(!this.checkSLD10Version(sldFile)){
|
||||||
|
contentType = GeoServerRESTPublisher.Format.SLD_1_1_0.getContentType();
|
||||||
|
}
|
||||||
|
LOGGER.debug("PUTting style " + name + " to " + sUrl + " using version: " + contentType);
|
||||||
|
String result = HTTPUtils.put(sUrl.toString(), sldFile, contentType, gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a Style.
|
||||||
|
*
|
||||||
|
* @param sldBody the new SLD document as a String.
|
||||||
|
* @param name the Style name.
|
||||||
|
* @param raw the raw format
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if the style body or name are null or empty.
|
||||||
|
*/
|
||||||
|
public boolean updateStyle(final String sldBody, final String name, final boolean raw)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
/*
|
||||||
|
* This is the equivalent call with cUrl:
|
||||||
|
*
|
||||||
|
* {@code curl -u admin:geoserver -XPUT \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \
|
||||||
|
* http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=$name&raw=$raw}
|
||||||
|
*/
|
||||||
|
if (sldBody == null || sldBody.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style body may not be null or empty");
|
||||||
|
} else if (name == null || name.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style name may not be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sUrl = new StringBuilder(buildUrl(null, name, null));
|
||||||
|
Util.appendParameter(sUrl, "raw", ""+raw);
|
||||||
|
String contentType = GeoServerRESTPublisher.Format.SLD.getContentType();
|
||||||
|
if(!this.checkSLD10Version(sldBody)){
|
||||||
|
contentType = GeoServerRESTPublisher.Format.SLD_1_1_0.getContentType();
|
||||||
|
}
|
||||||
|
LOGGER.debug("PUTting style " + name + " to " + sUrl + " using version: " + contentType);
|
||||||
|
String result = HTTPUtils.put(sUrl.toString(), sldBody, contentType, gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a Style.
|
||||||
|
*
|
||||||
|
* @param sldBody the new SLD document as a String.
|
||||||
|
* @param name the Style name to update.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if the style body or name are null or empty.
|
||||||
|
*/
|
||||||
|
public boolean updateStyle(final String sldBody, final String name)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
/*
|
||||||
|
* This is the equivalent call with cUrl:
|
||||||
|
*
|
||||||
|
* {@code curl -u admin:geoserver -XPUT \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \
|
||||||
|
* http://$GSIP:$GSPORT/$SERVLET/rest/styles/$NAME}
|
||||||
|
*/
|
||||||
|
if (sldBody == null || sldBody.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style body may not be null or empty");
|
||||||
|
} else if (name == null || name.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style name may not be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
final String sUrl = buildUrl(null, name, null);
|
||||||
|
|
||||||
|
final String result = HTTPUtils.put(sUrl, sldBody, "application/vnd.ogc.sld+xml", gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a Style.
|
||||||
|
*
|
||||||
|
* @param sldFile the File containing the SLD document.
|
||||||
|
* @param name the Style name.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if the sldFile file or name are null or name is empty.
|
||||||
|
*/
|
||||||
|
public boolean updateStyle(final File sldFile, final String name)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
|
if (sldFile == null) {
|
||||||
|
throw new IllegalArgumentException("Unable to updateStyle using a null parameter file");
|
||||||
|
} else if (name == null || name.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style name may not be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
final String sUrl = buildUrl(null, name, null);
|
||||||
|
|
||||||
|
final String result = HTTPUtils.put(sUrl, sldFile,
|
||||||
|
"application/vnd.ogc.sld+xml", gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a Style.
|
||||||
|
* <P>
|
||||||
|
* The Style will be unpublished, and (optionally) the SLD file will be removed.
|
||||||
|
*
|
||||||
|
* @param styleName the name of the Style to remove.
|
||||||
|
* @param purge remove the related SLD file from disk.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if styleName is null or empty.
|
||||||
|
*/
|
||||||
|
public boolean removeStyle(String styleName, final boolean purge)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
if (styleName == null || styleName.isEmpty())
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Check styleName parameter, it may never be null or empty");
|
||||||
|
|
||||||
|
// check style name
|
||||||
|
// TODO may we want to throw an exception instead of
|
||||||
|
// change style name?
|
||||||
|
if(styleName.contains(":"))
|
||||||
|
LOGGER.warn("Style name is going to be changed ["+styleName+"]");
|
||||||
|
styleName = styleName.replaceAll(":", "_");
|
||||||
|
|
||||||
|
// currently REST interface does't support URLencoded URL
|
||||||
|
// styleName = URLEncoder.encode(styleName);
|
||||||
|
|
||||||
|
String sUrl = buildUrl(null, styleName, null);
|
||||||
|
if (purge) {
|
||||||
|
sUrl += "?purge=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
return HTTPUtils.delete(sUrl, gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a Style.
|
||||||
|
* <P>
|
||||||
|
* The Style will be unpublished and the related SLD file will be removed.
|
||||||
|
*
|
||||||
|
* @param styleName the name of the Style to remove.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
*/
|
||||||
|
public boolean removeStyle(String styleName) {
|
||||||
|
try {
|
||||||
|
return removeStyle(styleName, true);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
if (LOGGER.isErrorEnabled()) {
|
||||||
|
LOGGER.error(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//=========================================================================
|
||||||
|
// Publishing in workspace
|
||||||
|
//=========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style.
|
||||||
|
*
|
||||||
|
* @param sldBody the full SLD document as a String.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public boolean publishStyleInWorkspace(final String workspace, String sldBody) {
|
||||||
|
try {
|
||||||
|
return publishStyleInWorkspace(workspace, sldBody, null);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
if (LOGGER.isErrorEnabled()) {
|
||||||
|
LOGGER.error(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style, assigning it a name.
|
||||||
|
*
|
||||||
|
* @param sldBody the full SLD document as a String.
|
||||||
|
* @param name the Style name.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if the style body is null or empty.
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public boolean publishStyleInWorkspace(final String workspace, final String sldBody, final String name)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
|
if (sldBody == null || sldBody.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style body may not be null or empty");
|
||||||
|
}
|
||||||
|
String sUrl = buildPostUrl(workspace, name);
|
||||||
|
final String result = HTTPUtils.post(sUrl, sldBody, "application/vnd.ogc.sld+xml", gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style.
|
||||||
|
*
|
||||||
|
* @param sldFile the File containing the SLD document.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public boolean publishStyleInWorkspace(final String workspace, File sldFile) {
|
||||||
|
return publishStyleInWorkspace(workspace, sldFile, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish a Style, assigning it a name.
|
||||||
|
*
|
||||||
|
* @param sldFile the File containing the SLD document.
|
||||||
|
* @param name the Style name.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public boolean publishStyleInWorkspace(final String workspace, File sldFile, String name) {
|
||||||
|
String sUrl = buildPostUrl(workspace, name);
|
||||||
|
LOGGER.debug("POSTing new style " + name + " to " + sUrl);
|
||||||
|
String result = HTTPUtils.post(sUrl, sldFile, GeoServerRESTPublisher.Format.SLD.getContentType(), gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a Style.
|
||||||
|
*
|
||||||
|
* @param sldBody the new SLD document as a String.
|
||||||
|
* @param name the Style name to update.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if the style body or name are null or empty.
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public boolean updateStyleInWorkspace(final String workspace, final String sldBody, final String name)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
if (sldBody == null || sldBody.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style body may not be null or empty");
|
||||||
|
} else if (name == null || name.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style name may not be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
final String sUrl = buildUrl(workspace, name, null);
|
||||||
|
|
||||||
|
final String result = HTTPUtils.put(sUrl, sldBody,
|
||||||
|
"application/vnd.ogc.sld+xml", gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a Style.
|
||||||
|
*
|
||||||
|
* @param sldFile the File containing the SLD document.
|
||||||
|
* @param name the Style name.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if the sldFile file or name are null or name is empty.
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public boolean updateStyleInWorkspace(final String workspace, final File sldFile, final String name)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
|
if (sldFile == null) {
|
||||||
|
throw new IllegalArgumentException("Unable to updateStyle using a null parameter file");
|
||||||
|
} else if (name == null || name.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The style name may not be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
final String sUrl = buildUrl(workspace, name, null);
|
||||||
|
|
||||||
|
final String result = HTTPUtils.put(sUrl, sldFile,
|
||||||
|
"application/vnd.ogc.sld+xml", gsuser, gspass);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a Style.
|
||||||
|
* <P>
|
||||||
|
* The Style will be unpublished, and (optionally) the SLD file will be removed.
|
||||||
|
*
|
||||||
|
* @param styleName the name of the Style to remove.
|
||||||
|
* @param purge remove the related SLD file from disk.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @throws IllegalArgumentException if styleName is null or empty.
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public boolean removeStyleInWorkspace(final String workspace, String styleName, final boolean purge)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
if (styleName == null || styleName.isEmpty())
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Check styleName parameter, it may never be null or empty");
|
||||||
|
|
||||||
|
// check style name
|
||||||
|
// TODO may we want to throw an exception instead of change style name?
|
||||||
|
if(styleName.contains(":"))
|
||||||
|
LOGGER.warn("Style name is going to be changed ["+styleName+"]");
|
||||||
|
styleName = styleName.replaceAll(":", "_");
|
||||||
|
styleName = URLEncoder.encode(styleName);
|
||||||
|
|
||||||
|
String sUrl = buildUrl(workspace, styleName, null);
|
||||||
|
|
||||||
|
if (purge) {
|
||||||
|
sUrl += "?purge=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
return HTTPUtils.delete(sUrl, gsuser, gspass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a Style.
|
||||||
|
* <P>
|
||||||
|
* The Style will be unpublished and the related SLD file will be removed.
|
||||||
|
*
|
||||||
|
* @param styleName the name of the Style to remove.
|
||||||
|
*
|
||||||
|
* @return <TT>true</TT> if the operation completed successfully.
|
||||||
|
* @since GeoServer 2.2
|
||||||
|
*/
|
||||||
|
public boolean removeStyleInWorkspace(final String workspace, String styleName) {
|
||||||
|
try {
|
||||||
|
return removeStyleInWorkspace(workspace, styleName, true);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
if (LOGGER.isErrorEnabled()) {
|
||||||
|
LOGGER.error(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//=========================================================================
|
||||||
|
// Util methods
|
||||||
|
//=========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a URL for the given stylename with the name in querystring
|
||||||
|
* @param workspace nullable workspace name
|
||||||
|
* @param name style name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String buildPostUrl(final String workspace, String name) {
|
||||||
|
StringBuilder sUrl = new StringBuilder(gsBaseUrl.toString()).append("/rest");
|
||||||
|
|
||||||
|
if(workspace != null)
|
||||||
|
sUrl.append("/workspaces/").append(workspace);
|
||||||
|
|
||||||
|
sUrl.append("/styles");
|
||||||
|
if ( name != null && !name.isEmpty()) {
|
||||||
|
sUrl.append("?name=").append(URLEncoder.encode(name));
|
||||||
|
}
|
||||||
|
return sUrl.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected String buildXmlUrl(final String workspace, final String name) {
|
||||||
|
return buildUrl(workspace, name, ".xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a URL for the given stylename with the name in the REST path
|
||||||
|
* @param workspace nullable workspace name
|
||||||
|
* @param name style name
|
||||||
|
* @param ext nullable output extension (e.g. ".xml" ".sld")
|
||||||
|
*/
|
||||||
|
protected String buildUrl(final String workspace, final String name, final String ext) {
|
||||||
|
StringBuilder sUrl = new StringBuilder(gsBaseUrl.toString()).append("/rest");
|
||||||
|
|
||||||
|
if(workspace != null)
|
||||||
|
sUrl.append("/workspaces/").append(workspace);
|
||||||
|
|
||||||
|
sUrl.append("/styles/").append(URLEncoder.encode(name));
|
||||||
|
|
||||||
|
if(ext != null)
|
||||||
|
sUrl.append(ext);
|
||||||
|
|
||||||
|
return sUrl.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkSLD10Version(String sldBody) {
|
||||||
|
boolean result = false;
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
try {
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
InputStream stream = new ByteArrayInputStream(sldBody.getBytes(Charset.forName("UTF-8")));
|
||||||
|
Document doc = builder.parse(stream);
|
||||||
|
result = this.checkSLD10Version(doc);
|
||||||
|
} catch (SAXException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
} catch (ParserConfigurationException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkSLD10Version(File fileSLD) {
|
||||||
|
boolean result = false;
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
try {
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document doc = builder.parse(fileSLD);
|
||||||
|
result = this.checkSLD10Version(doc);
|
||||||
|
} catch (SAXException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
} catch (ParserConfigurationException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkSLD10Version(Document doc) {
|
||||||
|
boolean result = false;
|
||||||
|
try {
|
||||||
|
XPathFactory xPathfactory = XPathFactory.newInstance();
|
||||||
|
XPath xpath = xPathfactory.newXPath();
|
||||||
|
XPathExpression expr = xpath.compile("//@version='1.0.0'");
|
||||||
|
result = (Boolean)expr.evaluate(doc, XPathConstants.BOOLEAN);
|
||||||
|
} catch (XPathExpressionException ex) {
|
||||||
|
LOGGER.error("Error parsing SLD file: " + ex);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
package it.geosolutions.geoserver.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer21;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Apply Layer decoder tests on a GS 2.1 layer REST config
|
||||||
|
*
|
||||||
|
* @author eblondel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LayerDecoder21Test{
|
||||||
|
|
||||||
|
private final static Logger LOGGER = LoggerFactory.getLogger(LayerDecoder21Test.class);
|
||||||
|
|
||||||
|
RESTLayer21 layer;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws IOException{
|
||||||
|
File layerFile = new ClassPathResource("testdata/layerExample21.xml").getFile();
|
||||||
|
String layerString = FileUtils.readFileToString(layerFile);
|
||||||
|
layer = (RESTLayer21) RESTLayer21.build(layerString);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvertised(){
|
||||||
|
Assert.assertEquals(true, layer.getAdvertised());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAuthorityURLs() {
|
||||||
|
List<GSAuthorityURLInfoEncoder> authorityURLs = layer
|
||||||
|
.getEncodedAuthorityURLInfoList();
|
||||||
|
LOGGER.debug("Number of authority URLs: " + authorityURLs.size());
|
||||||
|
Assert.assertEquals("authority1", authorityURLs.get(0).getName());
|
||||||
|
Assert.assertEquals("http://www.authority1.org", authorityURLs.get(0)
|
||||||
|
.getHref());
|
||||||
|
Assert.assertEquals("authority2", authorityURLs.get(1).getName());
|
||||||
|
Assert.assertEquals("http://www.authority2.org", authorityURLs.get(1)
|
||||||
|
.getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIdentifiers() {
|
||||||
|
List<GSIdentifierInfoEncoder> authorityURLs = layer
|
||||||
|
.getEncodedIdentifierInfoList();
|
||||||
|
Assert.assertEquals("authority1", authorityURLs.get(0).getAuthority());
|
||||||
|
Assert.assertEquals("identifier1", authorityURLs.get(0).getIdentifier());
|
||||||
|
Assert.assertEquals("authority2", authorityURLs.get(1).getAuthority());
|
||||||
|
Assert.assertEquals("identifier2", authorityURLs.get(1).getIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,107 @@
|
|||||||
|
package it.geosolutions.geoserver.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTStyleList;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author eblondel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LayerDecoderTest {
|
||||||
|
|
||||||
|
RESTLayer layer;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws IOException{
|
||||||
|
File layerFile = new ClassPathResource("testdata/layerExample.xml").getFile();
|
||||||
|
String layerString = FileUtils.readFileToString(layerFile);
|
||||||
|
layer = RESTLayer.build(layerString);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnabled(){
|
||||||
|
Assert.assertEquals(true, layer.getEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testQueryable(){
|
||||||
|
Assert.assertEquals(true, layer.getQueryable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvertised(){
|
||||||
|
Assert.assertEquals(true, layer.getAdvertised());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testName() {
|
||||||
|
Assert.assertEquals("tasmania_cities", layer.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTypeString() {
|
||||||
|
Assert.assertEquals("VECTOR", layer.getTypeString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testType(){
|
||||||
|
Assert.assertEquals(RESTLayer.Type.VECTOR, layer.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultStyle() {
|
||||||
|
Assert.assertEquals("capitals", layer.getDefaultStyle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStyles() {
|
||||||
|
RESTStyleList styles = layer.getStyles();
|
||||||
|
Assert.assertTrue(styles.size() == 2);
|
||||||
|
Assert.assertEquals("green", styles.get(0).getName());
|
||||||
|
Assert.assertEquals("blue", styles.get(1).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResourceUrl() {
|
||||||
|
Assert.assertEquals(
|
||||||
|
"http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml",
|
||||||
|
layer.getResourceUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAuthorityURLs() {
|
||||||
|
List<GSAuthorityURLInfoEncoder> authorityURLs = layer
|
||||||
|
.getEncodedAuthorityURLInfoList();
|
||||||
|
Assert.assertEquals("authority1", authorityURLs.get(0).getName());
|
||||||
|
Assert.assertEquals("http://www.authority1.org", authorityURLs.get(0)
|
||||||
|
.getHref());
|
||||||
|
Assert.assertEquals("authority2", authorityURLs.get(1).getName());
|
||||||
|
Assert.assertEquals("http://www.authority2.org", authorityURLs.get(1)
|
||||||
|
.getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIdentifiers() {
|
||||||
|
List<GSIdentifierInfoEncoder> authorityURLs = layer
|
||||||
|
.getEncodedIdentifierInfoList();
|
||||||
|
Assert.assertEquals("authority1", authorityURLs.get(0).getAuthority());
|
||||||
|
Assert.assertEquals("identifier1", authorityURLs.get(0).getIdentifier());
|
||||||
|
Assert.assertEquals("authority2", authorityURLs.get(1).getAuthority());
|
||||||
|
Assert.assertEquals("identifier2", authorityURLs.get(1).getIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* GeoBatch - Open Source geospatial batch processing system
|
||||||
|
* https://github.com/nfms4redd/nfms-geobatch
|
||||||
|
* Copyright (C) 2007-2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* GPLv3 + Classpath exception
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTCoverage;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTDimensionInfo;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DamianoG
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MetadataDecoderTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMetadataDimensionInfo() throws IOException {
|
||||||
|
|
||||||
|
File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile();
|
||||||
|
String coverageString = FileUtils.readFileToString(coverageFile);
|
||||||
|
RESTCoverage coverage = RESTCoverage.build(coverageString);
|
||||||
|
List<RESTDimensionInfo> list = coverage.getDimensionInfo();
|
||||||
|
|
||||||
|
Assert.assertEquals(list.size(),2);
|
||||||
|
|
||||||
|
|
||||||
|
for (RESTDimensionInfo el : list){
|
||||||
|
if(el.getKey().equals("time")){
|
||||||
|
Assert.assertEquals(el.getResolution(),null);
|
||||||
|
Assert.assertEquals(el.getPresentation(),"LIST");
|
||||||
|
Assert.assertEquals(el.getKey(),"time");
|
||||||
|
Assert.assertEquals(el.isEnabled(),true);
|
||||||
|
}
|
||||||
|
if(el.getKey().equals("elevation")){
|
||||||
|
Assert.assertEquals(el.getResolution(),"2");
|
||||||
|
Assert.assertEquals(el.getPresentation(),"DISCRETE_INTERVAL");
|
||||||
|
Assert.assertEquals(el.getKey(),"elevation");
|
||||||
|
Assert.assertEquals(el.isEnabled(),true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,164 @@
|
|||||||
|
package it.geosolutions.geoserver.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTBoundingBox;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTCoverage;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ResourceDecoderTest
|
||||||
|
*
|
||||||
|
* @author eblondel
|
||||||
|
* @author Henry Rotzoll (henry.rotzoll@dlr.de)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ResourceDecoderTest {
|
||||||
|
|
||||||
|
RESTCoverage coverage;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws IOException {
|
||||||
|
File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile();
|
||||||
|
String coverageString = FileUtils.readFileToString(coverageFile);
|
||||||
|
coverage = RESTCoverage.build(coverageString);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testName() {
|
||||||
|
Assert.assertEquals(coverage.getName(), "granuleTestMosaic");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNativeName() {
|
||||||
|
Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTitle() {
|
||||||
|
Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAbstract() {
|
||||||
|
Assert.assertEquals(coverage.getAbstract(), "this is an abstract");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testKeywords() {
|
||||||
|
List<String> keywords = coverage.getKeywords();
|
||||||
|
Assert.assertEquals(keywords.get(0), "keyword1");
|
||||||
|
Assert.assertEquals(keywords.get(1), "keyword2");
|
||||||
|
Assert.assertEquals(keywords.get(2), "keyword3");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNameSpace() {
|
||||||
|
Assert.assertEquals(coverage.getNameSpace(), "topp");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStoreName() {
|
||||||
|
Assert.assertEquals(coverage.getStoreName(), "granuleTestMosaic");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStoreType() {
|
||||||
|
Assert.assertEquals(coverage.getStoreType(), "coverageStore");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStoreUrl() {
|
||||||
|
Assert.assertEquals(coverage.getStoreUrl(),
|
||||||
|
"http://localhost:8080/geoserver/rest/workspaces/topp/coveragestores/granuleTestMosaic.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNativeCRS() {
|
||||||
|
String expectedCrs = "GEOGCS[\"WGS 84\", \r\n DATUM[\"World Geodetic\n System 1984\", \r\n"
|
||||||
|
+" SPHEROID[\"WGS 84\", 6378137.0,\n 298.257223563,\n AUTHORITY[\"EPSG\",\"7030\"]], \r\n"
|
||||||
|
+" AUTHORITY[\"EPSG\",\"6326\"]], \r\n PRIMEM[\"Greenwich\", 0.0,\n AUTHORITY[\"EPSG\",\"8901\"]], \r\n"
|
||||||
|
+" UNIT[\"degree\", 0.017453292519943295], \r\n AXIS[\"Geodetic longitude\", EAST], \r\n"
|
||||||
|
+" AXIS[\"Geodetic\n latitude\", NORTH], \r\n AUTHORITY[\"EPSG\",\"4326\"]]";
|
||||||
|
|
||||||
|
Assert.assertEquals(expectedCrs, coverage.getNativeCRS());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCRS() {
|
||||||
|
Assert.assertEquals(coverage.getCRS(), "EPSG:4326");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBoundingBox() {
|
||||||
|
Assert.assertEquals(coverage.getMinX(), -180.0, 0);
|
||||||
|
Assert.assertEquals(coverage.getMaxX(), 180.0, 0);
|
||||||
|
Assert.assertEquals(coverage.getMinY(), -90, 0);
|
||||||
|
Assert.assertEquals(coverage.getMaxY(), 90, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLatLonBoundingBox() {
|
||||||
|
RESTBoundingBox bbox = coverage.getLatLonBoundingBox();
|
||||||
|
Assert.assertTrue(bbox != null);
|
||||||
|
Assert.assertEquals("EPSG:4326", bbox.getCRS());
|
||||||
|
Assert.assertEquals(-180.0, bbox.getMinX(), 0);
|
||||||
|
Assert.assertEquals(180.0, bbox.getMaxX(), 0);
|
||||||
|
Assert.assertEquals(-90, bbox.getMinY(), 0);
|
||||||
|
Assert.assertEquals(90, bbox.getMaxY(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNativeBoundingBox() {
|
||||||
|
RESTBoundingBox bbox = coverage.getNativeBoundingBox();
|
||||||
|
Assert.assertTrue(bbox != null);
|
||||||
|
Assert.assertEquals("EPSG:4326", bbox.getCRS());
|
||||||
|
Assert.assertEquals(-180.0, bbox.getMinX(), 0);
|
||||||
|
Assert.assertEquals(180.0, bbox.getMaxX(), 0);
|
||||||
|
Assert.assertEquals(-90, bbox.getMinY(), 0);
|
||||||
|
Assert.assertEquals(90, bbox.getMaxY(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMetadataLinkInfo() throws IOException {
|
||||||
|
|
||||||
|
List<GSMetadataLinkInfoEncoder> list = coverage.getEncodedMetadataLinkInfoList();
|
||||||
|
|
||||||
|
GSMetadataLinkInfoEncoder metadataLinkInfo1 = list.get(0);
|
||||||
|
Assert.assertEquals("text/xml", metadataLinkInfo1.getType());
|
||||||
|
Assert.assertEquals("ISO19115:2003", metadataLinkInfo1.getMetadataType());
|
||||||
|
Assert.assertEquals("http://www.organization.org/metadata1", metadataLinkInfo1.getContent());
|
||||||
|
|
||||||
|
GSMetadataLinkInfoEncoder metadataLinkInfo2 = list.get(1);
|
||||||
|
Assert.assertEquals("text/html", metadataLinkInfo2.getType());
|
||||||
|
Assert.assertEquals("ISO19115:2003", metadataLinkInfo2.getMetadataType());
|
||||||
|
Assert.assertEquals("http://www.organization.org/metadata2", metadataLinkInfo2.getContent());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCoverageDimension() throws IOException {
|
||||||
|
|
||||||
|
List<GSCoverageDimensionEncoder> list = coverage.getEncodedDimensionsInfoList();
|
||||||
|
|
||||||
|
GSCoverageDimensionEncoder coverageDimension1 = list.get(0);
|
||||||
|
Assert.assertEquals("GRAY_INDEX", coverageDimension1.getName());
|
||||||
|
Assert.assertEquals("GridSampleDimension[-Infinity,Infinity]",
|
||||||
|
coverageDimension1.getDescription());
|
||||||
|
Assert.assertEquals("-inf", coverageDimension1.getRangeMin());
|
||||||
|
Assert.assertEquals("inf", coverageDimension1.getRangeMax());
|
||||||
|
// Assert.assertEquals("dobson units", coverageDimension1.getUnit());
|
||||||
|
Assert.assertTrue(coverageDimension1.getUnit().startsWith("dobson units"));
|
||||||
|
Assert.assertEquals("REAL_32BITS", coverageDimension1.getDimensionTypeName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* GeoBatch - Open Source geospatial batch processing system
|
||||||
|
* https://github.com/nfms4redd/nfms-geobatch
|
||||||
|
* Copyright (C) 2007-2012 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* GPLv3 + Classpath exception
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.output.XMLOutputter;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Carlo Cancellieri {@code
|
||||||
|
* <about>
|
||||||
|
* <resource name="GeoServer">
|
||||||
|
* <Build-Timestamp>10-Oct-2013 03:08</Build-Timestamp>
|
||||||
|
* <Git-Revision>32db076555e57cc5f826b0361d1af4efe6d3f01b</Git-Revision>
|
||||||
|
* <Version>2.2-ENTERPRISE-SNAPSHOT</Version>
|
||||||
|
* </resource>
|
||||||
|
* <resource name="GeoTools">
|
||||||
|
* <Build-Timestamp>10-Oct-2013 03:01</Build-Timestamp>
|
||||||
|
* <Git-Revision>da12effd42a9545628bd6e8ec20494607fbfe3a4</Git-Revision>
|
||||||
|
* <Version>8-ENTERPRISE-SNAPSHOT</Version>
|
||||||
|
* </resource>
|
||||||
|
* </about>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public class VersionDecoderTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final String version = "<about><resource name=\"GeoServer\"><Build-Timestamp>10-Oct-2013 03:08</Build-Timestamp>"
|
||||||
|
+ "<Git-Revision>32db076555e57cc5f826b0361d1af4efe6d3f01b</Git-Revision><Version>2.2-ENTERPRISE-SNAPSHOT</Version></resource></about>";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVersionDecoder() {
|
||||||
|
|
||||||
|
GSVersionDecoder dec=new GSVersionDecoder(version);
|
||||||
|
Assert.assertEquals(GSVersionDecoder.VERSION.v22, dec.getVersion());
|
||||||
|
Assert.assertEquals("GeoServer", dec.getGeoServer().getName());
|
||||||
|
|
||||||
|
GSVersionDecoder.GSAboutResource geoserver=dec.getGeoServer();
|
||||||
|
geoserver.setVersion("2.3-SNAPSHOT");
|
||||||
|
geoserver.setName("_CustomGeoServerName_");
|
||||||
|
Assert.assertEquals(GSVersionDecoder.VERSION.v23, dec.getVersion());
|
||||||
|
Assert.assertEquals("_CustomGeoServerName_", dec.getGeoServer().getName());
|
||||||
|
|
||||||
|
dec=new GSVersionDecoder(null);
|
||||||
|
Assert.assertEquals(GSVersionDecoder.VERSION.UNRECOGNIZED, dec.getVersion());
|
||||||
|
Assert.assertEquals(null, dec.getGeoServer().getName());
|
||||||
|
|
||||||
|
//print(dec.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIntegrationVersionDecoder() {
|
||||||
|
if (!enabled())
|
||||||
|
return;
|
||||||
|
GSVersionDecoder geoserver = reader.getGeoserverVersion();
|
||||||
|
if (GSVersionDecoder.VERSION.v22.equals(GSVersionDecoder.VERSION.getVersion(GS_VERSION))) {
|
||||||
|
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.v22);
|
||||||
|
} else if (GSVersionDecoder.VERSION.UNRECOGNIZED.equals(GSVersionDecoder.VERSION
|
||||||
|
.getVersion(GS_VERSION))) {
|
||||||
|
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
// print(dec.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String print(Element e){
|
||||||
|
return new XMLOutputter().outputString(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
package it.geosolutions.geoserver.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTWmsStore;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WmsStoreDecoderTest
|
||||||
|
*
|
||||||
|
* @author cip (cippinofg at gmail.com)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class WmsStoreDecoderTest {
|
||||||
|
|
||||||
|
RESTWmsStore wmsstore;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws IOException {
|
||||||
|
File wmsstoreFile = new ClassPathResource("testdata/wmsstoreExample.xml").getFile();
|
||||||
|
String wmsstoreContent = FileUtils.readFileToString(wmsstoreFile);
|
||||||
|
wmsstore = RESTWmsStore.build(wmsstoreContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testName() {
|
||||||
|
Assert.assertEquals(wmsstore.getName(), "wmsstore001");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testType() {
|
||||||
|
Assert.assertEquals(wmsstore.getType(), "WMS");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnabled() {
|
||||||
|
Assert.assertEquals(wmsstore.getEnabled(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWorkspace() {
|
||||||
|
Assert.assertEquals(wmsstore.getWorkspaceName(), "ws001");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUseConnectionPooling() {
|
||||||
|
Assert.assertEquals(wmsstore.getUseConnectionPooling(),true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCapabilitiesURL() {
|
||||||
|
Assert.assertEquals(wmsstore.getCapabilitiesURL(), "http://myhost/geoserver/wms");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUser() {
|
||||||
|
Assert.assertEquals(wmsstore.getUser(), "admin");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPassword() {
|
||||||
|
Assert.assertEquals(wmsstore.getPassword(), "geoserver");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaxConnections() {
|
||||||
|
Assert.assertEquals(wmsstore.getMaxConnections(), "6");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReadTimeout() {
|
||||||
|
Assert.assertEquals(wmsstore.getReadTimeout(), "60");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConnectTimeout() {
|
||||||
|
Assert.assertEquals(wmsstore.getConnectTimeout(), "30");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -26,10 +26,7 @@
|
|||||||
package it.geosolutions.geoserver.rest;
|
package it.geosolutions.geoserver.rest;
|
||||||
|
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
||||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -38,67 +35,69 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.commons.io.filefilter.SuffixFileFilter;
|
import org.apache.commons.io.filefilter.SuffixFileFilter;
|
||||||
import org.apache.log4j.Logger;
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Testcase for publishing layers on geoserver.
|
* Testcase for publishing layers on geoserver.
|
||||||
* We need a running GeoServer to properly run the tests.
|
|
||||||
* Login credentials are hardcoded at the moment (localhost:8080 admin/geoserver).
|
|
||||||
* If such geoserver instance cannot be contacted, tests will be skipped.
|
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* @author etj
|
* @author etj
|
||||||
*/
|
*/
|
||||||
public class ConfigTest extends GeoserverRESTTest {
|
public class ConfigTest extends GeoserverRESTTest {
|
||||||
private final static Logger LOGGER = Logger.getLogger(ConfigTest.class);
|
private final static Logger LOGGER = LoggerFactory.getLogger(ConfigTest.class);
|
||||||
|
|
||||||
private static final String DEFAULT_WS = "geosolutions";
|
private static final String DEFAULT_WS = "geosolutions";
|
||||||
|
|
||||||
|
@Test
|
||||||
public ConfigTest(String testName) {
|
|
||||||
super(testName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEtj() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) return;
|
|
||||||
deleteAll();
|
|
||||||
|
|
||||||
assertTrue(reader.getWorkspaces().isEmpty());
|
|
||||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
|
||||||
|
|
||||||
insertStyles();
|
|
||||||
insertExternalGeotiff();
|
|
||||||
insertExternalShape();
|
|
||||||
|
|
||||||
boolean ok = publisher.publishDBLayer(DEFAULT_WS, "pg_kids", "easia_gaul_0_aggr", "EPSG:4326", "default_polygon");
|
|
||||||
// assertTrue(ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void insertStyles() throws FileNotFoundException, IOException {
|
public void insertStyles() throws FileNotFoundException, IOException {
|
||||||
|
if(!enabled()){
|
||||||
|
LOGGER.info("Skipping test "+"insertStyles"+"for class:"+this.getClass().getSimpleName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteAllStyles();
|
||||||
|
|
||||||
File sldDir = new ClassPathResource("testdata").getFile();
|
File sldDir = new ClassPathResource("testdata").getFile();
|
||||||
for(File sldFile : sldDir.listFiles((FilenameFilter)new SuffixFileFilter(".sld"))) {
|
for(File sldFile : sldDir.listFiles((FilenameFilter)new SuffixFileFilter(".sld"))) {
|
||||||
LOGGER.info("Existing styles: " + reader.getStyles().getNames());
|
LOGGER.info("Existing styles: " + reader.getStyles().getNames());
|
||||||
String basename = FilenameUtils.getBaseName(sldFile.toString());
|
String basename = FilenameUtils.getBaseName(sldFile.toString());
|
||||||
LOGGER.info("Publishing style " + sldFile + " as " + basename);
|
LOGGER.info("Publishing style " + sldFile + " as " + basename);
|
||||||
assertTrue("Cound not publish " + sldFile, publisher.publishStyle(sldFile, basename));
|
assertTrue("Could not publish " + sldFile, publisher.publishStyle(sldFile, basename));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void insertExternalGeotiff() throws FileNotFoundException, IOException {
|
public void insertExternalGeotiff() throws FileNotFoundException, IOException {
|
||||||
|
if(!enabled()){
|
||||||
|
LOGGER.info("Skipping test "+"insertExternalGeotiff"+"for class:"+this.getClass().getSimpleName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
String storeName = "testRESTStoreGeotiff";
|
String storeName = "testRESTStoreGeotiff";
|
||||||
String layerName = "resttestdem";
|
String layerName = "resttestdem";
|
||||||
|
|
||||||
|
publisher.createWorkspace(DEFAULT_WS);
|
||||||
|
publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(),"raster.sld"));
|
||||||
|
|
||||||
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
||||||
boolean pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, layerName,"EPSG:4326",ProjectionPolicy.FORCE_DECLARED,"raster");
|
boolean pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, layerName,"EPSG:4326",ProjectionPolicy.FORCE_DECLARED,"raster");
|
||||||
|
|
||||||
assertTrue(pc);
|
assertTrue(pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void insertExternalShape() throws FileNotFoundException, IOException {
|
public void insertExternalShape() throws FileNotFoundException, IOException {
|
||||||
|
if(!enabled()){
|
||||||
|
LOGGER.info("Skipping test "+"insertExternalShape"+"for class:"+this.getClass().getSimpleName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
publisher.createWorkspace(DEFAULT_WS);
|
||||||
|
publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(),"default_point.sld"));
|
||||||
|
|
||||||
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple class for testing that the DeleteAllLayerGroups() method behaves correctly.
|
||||||
|
*
|
||||||
|
* @author Nicola Lagomarsini
|
||||||
|
*/
|
||||||
|
public class GeoServerRESTClassTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTTest.class);;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetLayerGroups() {
|
||||||
|
if(!enabled()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> groups = reader.getLayerGroups().getNames();
|
||||||
|
LOGGER.info("Found " + groups.size() + " layerGroups");
|
||||||
|
for (String groupName : groups) {
|
||||||
|
RESTLayerGroup group = reader.getLayerGroup(groupName);
|
||||||
|
if (groups != null) {
|
||||||
|
assertNotNull(group.getPublishedList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,14 +25,21 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest;
|
package it.geosolutions.geoserver.rest;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTDataStoreList;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTDataStoreList;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayerList;
|
import it.geosolutions.geoserver.rest.decoder.RESTLayerList;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTNamespaceList;
|
import it.geosolutions.geoserver.rest.decoder.RESTNamespaceList;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList;
|
import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -40,13 +47,12 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
public GeoserverRESTReaderTest(String testName) {
|
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTReaderTest.class);
|
||||||
super(testName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getLayers method, of class GeoServerRESTReader.
|
* Test of getLayers method, of class GeoServerRESTReader.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetLayers() {
|
public void testGetLayers() {
|
||||||
if(!enabled()) return;
|
if(!enabled()) return;
|
||||||
|
|
||||||
@ -55,21 +61,22 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
|||||||
// assertEquals(/*CHANGEME*/19, result.getChildren("layer").size()); // value in default gs installation
|
// assertEquals(/*CHANGEME*/19, result.getChildren("layer").size()); // value in default gs installation
|
||||||
|
|
||||||
// System.out.println("Layers:" + result.getChildren("layer").size());
|
// System.out.println("Layers:" + result.getChildren("layer").size());
|
||||||
System.out.println("Layers:" + result.size());
|
LOGGER.debug("Layers: " + result.size());
|
||||||
System.out.print("Layers:" );
|
// LOGGER.debug("Layers:" );
|
||||||
for (NameLinkElem shlayer : result) {
|
for (NameLinkElem shlayer : result) {
|
||||||
assertNotNull(shlayer.getName());
|
assertNotNull(shlayer.getName());
|
||||||
System.out.print(shlayer.getName() + " ");
|
LOGGER.debug(shlayer.getName() + " ");
|
||||||
}
|
}
|
||||||
// for (Element layer : (List<Element>)result.getChildren("layer")) {
|
// for (Element layer : (List<Element>)result.getChildren("layer")) {
|
||||||
// System.out.print(layer.getChildText("name") + " ");
|
// System.out.print(layer.getChildText("name") + " ");
|
||||||
// }
|
// }
|
||||||
System.out.println();
|
LOGGER.debug("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getDatastores method, of class GeoServerRESTReader.
|
* Test of getDatastores method, of class GeoServerRESTReader.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetDatastores() {
|
public void testGetDatastores() {
|
||||||
if(!enabled()) return;
|
if(!enabled()) return;
|
||||||
|
|
||||||
@ -77,29 +84,30 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
|||||||
assertNotNull(wslist);
|
assertNotNull(wslist);
|
||||||
// assertEquals(7, wslist.size()); // value in default gs installation
|
// assertEquals(7, wslist.size()); // value in default gs installation
|
||||||
|
|
||||||
System.out.println("Workspaces: " + wslist.size());
|
LOGGER.debug("Workspaces: " + wslist.size());
|
||||||
int dsnum = 0;
|
int dsnum = 0;
|
||||||
for (RESTWorkspaceList.RESTShortWorkspace ws : wslist) {
|
for (RESTWorkspaceList.RESTShortWorkspace ws : wslist) {
|
||||||
System.out.println("Getting DSlist for WS " + ws.getName() + "..." );
|
LOGGER.debug("Getting DSlist for WS " + ws.getName() + "..." );
|
||||||
RESTDataStoreList result = reader.getDatastores(ws.getName());
|
RESTDataStoreList result = reader.getDatastores(ws.getName());
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
dsnum += result.size();
|
dsnum += result.size();
|
||||||
for (NameLinkElem ds : result) {
|
for (NameLinkElem ds : result) {
|
||||||
assertNotNull(ds.getName());
|
assertNotNull(ds.getName());
|
||||||
System.out.print(ds.getName() + " " );
|
LOGGER.debug(ds.getName() + " " );
|
||||||
RESTDataStore datastore = reader.getDatastore(ws.getName(), ds.getName());
|
RESTDataStore datastore = reader.getDatastore(ws.getName(), ds.getName());
|
||||||
assertNotNull(datastore);
|
assertNotNull(datastore);
|
||||||
assertEquals(ds.getName(), datastore.getName());
|
assertEquals(ds.getName(), datastore.getName());
|
||||||
assertEquals(ws.getName(), datastore.getWorkspaceName());
|
assertEquals(ws.getName(), datastore.getWorkspaceName());
|
||||||
}
|
}
|
||||||
System.out.println();
|
LOGGER.debug("");
|
||||||
}
|
}
|
||||||
System.out.println();
|
LOGGER.debug("");
|
||||||
System.out.println("Datastores:" + dsnum); // value in default gs installation
|
LOGGER.debug("Datastores:" + dsnum); // value in default gs installation
|
||||||
// assertEquals(4, dsnum); // value in default gs installation
|
// assertEquals(4, dsnum); // value in default gs installation
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetWSDSNames() {
|
public void testGetWSDSNames() {
|
||||||
if(!enabled())
|
if(!enabled())
|
||||||
return;
|
return;
|
||||||
@ -113,7 +121,6 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
|||||||
// assertEquals(7, wsnames.size()); // value in default gs installation
|
// assertEquals(7, wsnames.size()); // value in default gs installation
|
||||||
|
|
||||||
// System.out.println("Workspaces: " + wslist.size());
|
// System.out.println("Workspaces: " + wslist.size());
|
||||||
int dsnum = 0;
|
|
||||||
int wscnt = 0;
|
int wscnt = 0;
|
||||||
for (RESTWorkspaceList.RESTShortWorkspace ws : wslist) {
|
for (RESTWorkspaceList.RESTShortWorkspace ws : wslist) {
|
||||||
String wsname = wsnames.get(wscnt++);
|
String wsname = wsnames.get(wscnt++);
|
||||||
@ -129,6 +136,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
|||||||
/**
|
/**
|
||||||
* Test of getDatastore method, of class GeoServerRESTReader.
|
* Test of getDatastore method, of class GeoServerRESTReader.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetDatastore() {
|
public void testGetDatastore() {
|
||||||
//tested in testGetDatastores()
|
//tested in testGetDatastores()
|
||||||
}
|
}
|
||||||
@ -136,12 +144,14 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
|||||||
/**
|
/**
|
||||||
* Test of getLayer method, of class GeoServerRESTReader.
|
* Test of getLayer method, of class GeoServerRESTReader.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetLayer() {
|
public void testGetLayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getNamespaceNames method, of class GeoServerRESTReader.
|
* Test of getNamespaceNames method, of class GeoServerRESTReader.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetNamespaces() {
|
public void testGetNamespaces() {
|
||||||
if(!enabled()) return;
|
if(!enabled()) return;
|
||||||
|
|
||||||
@ -152,20 +162,39 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
|||||||
assertNotNull(names);
|
assertNotNull(names);
|
||||||
assertEquals(names.size(), result.size()); // value in default gs installation
|
assertEquals(names.size(), result.size()); // value in default gs installation
|
||||||
|
|
||||||
System.out.println("Namespaces:" + result.size());
|
LOGGER.debug("Namespaces:" + result.size());
|
||||||
System.out.print("Namespaces:" );
|
LOGGER.debug("Namespaces:" );
|
||||||
int namesIdx = 0;
|
int namesIdx = 0;
|
||||||
for (RESTNamespaceList.RESTShortNamespace ns : result) {
|
for (RESTNamespaceList.RESTShortNamespace ns : result) {
|
||||||
assertEquals("namespace mismatch", names.get(namesIdx++), ns.getName());
|
assertEquals("namespace mismatch", names.get(namesIdx++), ns.getName());
|
||||||
System.out.print(ns.getName() + " " );
|
LOGGER.debug(ns.getName() + " " );
|
||||||
}
|
}
|
||||||
System.out.println();
|
LOGGER.debug("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getWorkspaceNames method, of class GeoServerRESTReader.
|
* Test of getWorkspaceNames method, of class GeoServerRESTReader.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetNamespaceNames() {
|
||||||
|
if(!enabled()) return;
|
||||||
|
|
||||||
|
List<String> names = reader.getNamespaceNames();
|
||||||
|
assertNotNull(names);
|
||||||
|
// assertEquals(7, names.size()); // value in default gs installation
|
||||||
|
|
||||||
|
LOGGER.debug("Namespaces:" + names.size());
|
||||||
|
LOGGER.debug("Namespaces:");
|
||||||
|
for (String name : names) {
|
||||||
|
LOGGER.debug(name + " ");
|
||||||
|
}
|
||||||
|
LOGGER.debug("");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of getWorkspaceNames method, of class GeoServerRESTReader.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
public void testGetWorkspaces() {
|
public void testGetWorkspaces() {
|
||||||
if(!enabled()) return;
|
if(!enabled()) return;
|
||||||
|
|
||||||
@ -173,18 +202,19 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
|||||||
assertNotNull(wslist);
|
assertNotNull(wslist);
|
||||||
// assertEquals(7, wslist.size()); // value in default gs installation
|
// assertEquals(7, wslist.size()); // value in default gs installation
|
||||||
|
|
||||||
System.out.println("Workspaces:" + wslist.size());
|
LOGGER.debug("Workspaces:" + wslist.size());
|
||||||
System.out.print("Workspaces:");
|
LOGGER.debug("Workspaces:");
|
||||||
for (RESTWorkspaceList.RESTShortWorkspace ws : wslist) {
|
for (RESTWorkspaceList.RESTShortWorkspace ws : wslist) {
|
||||||
System.out.print(ws.getName() + " ");
|
LOGGER.debug(ws.getName() + " ");
|
||||||
}
|
}
|
||||||
System.out.println();
|
LOGGER.debug("");
|
||||||
|
|
||||||
assertEquals(wslist.size(), reader.getWorkspaceNames().size());
|
assertEquals(wslist.size(), reader.getWorkspaceNames().size());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Test of getWorkspaceNames method, of class GeoServerRESTReader.
|
* Test of getWorkspaceNames method, of class GeoServerRESTReader.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetWorkspaceNames() {
|
public void testGetWorkspaceNames() {
|
||||||
if(!enabled()) return;
|
if(!enabled()) return;
|
||||||
|
|
||||||
@ -192,12 +222,12 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
|||||||
assertNotNull(names);
|
assertNotNull(names);
|
||||||
// assertEquals(7, names.size()); // value in default gs installation
|
// assertEquals(7, names.size()); // value in default gs installation
|
||||||
|
|
||||||
System.out.println("Workspaces:" + names.size());
|
LOGGER.debug("Workspaces:" + names.size());
|
||||||
System.out.print("Workspaces:");
|
LOGGER.debug("Workspaces:");
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
System.out.print(name + " ");
|
LOGGER.debug(name + " ");
|
||||||
}
|
}
|
||||||
System.out.println();
|
LOGGER.debug("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user