feat: 발주기관 기능 보완
parent
6facb2eb51
commit
47055cc170
130
list.txt
130
list.txt
|
|
@ -6,128 +6,10 @@
|
||||||
#src\main\webapp\com\css\common.v2.0.css.map
|
#src\main\webapp\com\css\common.v2.0.css.map
|
||||||
#src\main\webapp\WEB-INF\views\web\manage\list_reg.jsp
|
#src\main\webapp\WEB-INF\views\web\manage\list_reg.jsp
|
||||||
|
|
||||||
src\main\webapp\js\map\main\map.js
|
|
||||||
src\main\webapp\WEB-INF\views\drilling\common\includeTopMenu.jsp
|
|
||||||
src\main\webapp\WEB-INF\views\drilling\home\drilling_index.jsp
|
|
||||||
src\main\webapp\com\css\common.v2.0.css
|
|
||||||
src\main\webapp\com\css\common.v2.0.css.map
|
|
||||||
src\main\webapp\WEB-INF\views\drilling\inquiry\drilling_inquiry_project.jsp
|
src\main\webapp\WEB-INF\views\drilling\inquiry\drilling_inquiry_project.jsp
|
||||||
src\main\java\geoinfo\drilling\home\DrillingHomeController.java
|
src\main\webapp\js\map\main\map.js
|
||||||
src\main\webapp\WEB-INF\views\drilling\inquiry\drilling_inquiry.jsp
|
src\main\webapp\js\map\main\left\left.js
|
||||||
src\main\java\geoinfo\map\myMap\AVList.java
|
src\main\webapp\js\map\main\left\left_new.js
|
||||||
src\main\java\geoinfo\map\myMap\AWTLabelUtil.java
|
src\main\resources\egovframework\sqlmap\mapper\map\MapLeft_SQL.xml
|
||||||
src\main\java\geoinfo\map\myMap\AttributeList.java
|
|
||||||
src\main\java\geoinfo\map\myMap\CRSMngr.java
|
src\main\resources\egovframework\sqlmap\mapper\drilling\home\DrillingHomeMapper.xml
|
||||||
src\main\java\geoinfo\map\myMap\CategorizeBinding110.java
|
|
||||||
src\main\java\geoinfo\map\myMap\ConnJDBC.java
|
|
||||||
src\main\java\geoinfo\map\myMap\ConnMngr.java
|
|
||||||
src\main\java\geoinfo\map\myMap\CoordinateAccess.java
|
|
||||||
src\main\java\geoinfo\map\myMap\CoordinateAccessFactory.java
|
|
||||||
src\main\java\geoinfo\map\myMap\Coordinates.java
|
|
||||||
src\main\java\geoinfo\map\myMap\EncryptUtil.java
|
|
||||||
src\main\java\geoinfo\map\myMap\ExO2ImgLayer.java
|
|
||||||
src\main\java\geoinfo\map\myMap\ExWMSLayer.java
|
|
||||||
src\main\java\geoinfo\map\myMap\ExtractRasterStyleVisitor.java
|
|
||||||
src\main\java\geoinfo\map\myMap\FeatureLayer.java
|
|
||||||
src\main\java\geoinfo\map\myMap\FileComparator.java
|
|
||||||
src\main\java\geoinfo\map\myMap\GWVectorDriver.java
|
|
||||||
src\main\java\geoinfo\map\myMap\GWaveStoreMngr.java
|
|
||||||
src\main\java\geoinfo\map\myMap\GeoWaveDataStore.java
|
|
||||||
src\main\java\geoinfo\map\myMap\GeometryConverter.java
|
|
||||||
src\main\java\geoinfo\map\myMap\GeometryMngr.java
|
|
||||||
src\main\java\geoinfo\map\myMap\GetMapRequest.java
|
|
||||||
src\main\java\geoinfo\map\myMap\GroupLayer.java
|
|
||||||
src\main\java\geoinfo\map\myMap\InterpolateBinding110.java
|
|
||||||
src\main\java\geoinfo\map\myMap\JdbcStoreMngr.java
|
|
||||||
src\main\java\geoinfo\map\myMap\KLISLabelUtil.java
|
|
||||||
src\main\java\geoinfo\map\myMap\LabelCacheEx.java
|
|
||||||
src\main\java\geoinfo\map\myMap\LabelCacheItemEx.java
|
|
||||||
src\main\java\geoinfo\map\myMap\LabelInfo.java
|
|
||||||
src\main\java\geoinfo\map\myMap\LabelPainterEx.java
|
|
||||||
src\main\java\geoinfo\map\myMap\Layer.java
|
|
||||||
src\main\java\geoinfo\map\myMap\LayerFactory.java
|
|
||||||
src\main\java\geoinfo\map\myMap\LayerSet.java
|
|
||||||
src\main\java\geoinfo\map\myMap\LinkLayer.java
|
|
||||||
src\main\java\geoinfo\map\myMap\LogCacheManager.java
|
|
||||||
src\main\java\geoinfo\map\myMap\LogMngr.java
|
|
||||||
src\main\java\geoinfo\map\myMap\Map.java
|
|
||||||
src\main\java\geoinfo\map\myMap\MapStyle.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2CRSFactory.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2DSFactory.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2DSMngr.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2DSPrimaryKeyFinder.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2DemLayer.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2GeometryTypeMap.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2ImgLayer.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2LayerIndex.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2LayerLevel.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2LayerLevelSet.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2LayerUtil.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2PngWriter.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2SpatialIndexFeatureCollection.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2SqlDialect.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2StyleFactory.java
|
|
||||||
src\main\java\geoinfo\map\myMap\O2WpsLayerSet.java
|
|
||||||
src\main\java\geoinfo\map\myMap\OWSServiceException.java
|
|
||||||
src\main\java\geoinfo\map\myMap\OracleDialect.java
|
|
||||||
src\main\java\geoinfo\map\myMap\OracleFilterToSQL.java
|
|
||||||
src\main\java\geoinfo\map\myMap\OrdinateList.java
|
|
||||||
src\main\java\geoinfo\map\myMap\RefineRenderStyleVisitor.java
|
|
||||||
src\main\java\geoinfo\map\myMap\RefineStyleVisitor.java
|
|
||||||
src\main\java\geoinfo\map\myMap\RenderMngr.java
|
|
||||||
src\main\java\geoinfo\map\myMap\Request.java
|
|
||||||
src\main\java\geoinfo\map\myMap\SDO.java
|
|
||||||
src\main\java\geoinfo\map\myMap\SLDConfiguration110.java
|
|
||||||
src\main\java\geoinfo\map\myMap\SLDParser100.java
|
|
||||||
src\main\java\geoinfo\map\myMap\SLDTransformer110.java
|
|
||||||
src\main\java\geoinfo\map\myMap\ServerConfiguration.java
|
|
||||||
src\main\java\geoinfo\map\myMap\ServerContext.java
|
|
||||||
src\main\java\geoinfo\map\myMap\ServerInfo.java
|
|
||||||
src\main\java\geoinfo\map\myMap\ServerUtil.java
|
|
||||||
src\main\java\geoinfo\map\myMap\SimpleSql.java
|
|
||||||
src\main\java\geoinfo\map\myMap\StyleMngr.java
|
|
||||||
src\main\java\geoinfo\map\myMap\StyledLayerDescriptorBinding110.java
|
|
||||||
src\main\java\geoinfo\map\myMap\TextStyle2DEx.java
|
|
||||||
src\main\java\geoinfo\map\myMap\TransformedIconEx.java
|
|
||||||
src\main\java\geoinfo\map\myMap\WMSGetMap.java
|
|
||||||
src\main\java\geoinfo\map\myMap\WMSLayer.java
|
|
||||||
src\main\java\geoinfo\map\myMap\WpsVecStoreMngr.java
|
|
||||||
src\main\java\geoinfo\map\myMap\XSBooleanBinding110.java
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-api-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-brewer-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-coverage-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-coverage-api-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-coveragetools-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-cql-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-data-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-epsg-wkt-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-geojson-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-geotiff-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-grid-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-jdbc-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-main-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-metadata-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-opengis-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-process-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-referencing-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-render-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-shapefile-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-wfs-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-wms-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-wps-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xml-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-core-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-fes-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-filter-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-gml2-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-gml3-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-ows-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-sld-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-wcs-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-wfs-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-wms-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\gt-xsd-wps-11.0.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\jdom-1.1.3.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\picocontainer-1.2.jar
|
|
||||||
src\main\webapp\WEB-INF\lib\pngj-2.1.1.jar
|
|
||||||
src\main\webapp\js\map\main\map.js
|
|
||||||
|
|
|
||||||
204
pom.xml
204
pom.xml
|
|
@ -28,23 +28,8 @@
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>mesir-repo</id>
|
<id>central</id>
|
||||||
<url>http://mesir.googlecode.com/svn/trunk/mavenrepo</url>
|
<url>https://repo.maven.apache.org/maven2/</url>
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>mvn2</id>
|
|
||||||
<url>http://repo1.maven.org/maven2/</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</releases>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</snapshots>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>egovframe</id>
|
|
||||||
<url>http://www.egovframe.go.kr/maven/</url>
|
|
||||||
<releases>
|
<releases>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</releases>
|
</releases>
|
||||||
|
|
@ -54,9 +39,56 @@
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>oracle</id>
|
<id>eclipse-oxygen-releases</id>
|
||||||
<name>ORACLE JDBC Repository</name>
|
<name>Eclipse Oxygen Releases</name>
|
||||||
<url>http://mesir.googlecode.com/svn/trunk/mavenrepo</url>
|
<url>https://repo.eclipse.org/content/repositories/oxygen-releases/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>eclipse-neon-releases</id>
|
||||||
|
<name>Eclipse Neon Releases</name>
|
||||||
|
<url>https://repo.eclipse.org/content/repositories/neon-releases/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>osgeo</id>
|
||||||
|
<name>OSGeo Release Repository</name>
|
||||||
|
<url>https://repo.osgeo.org/repository/release/</url>
|
||||||
|
<snapshots><enabled>false</enabled></snapshots>
|
||||||
|
<releases><enabled>true</enabled></releases>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>jaspersoft-repo</id>
|
||||||
|
<url>https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>egovframe</id>
|
||||||
|
<url>http://www.egovframe.go.kr/maven/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
|
|
@ -442,7 +474,6 @@
|
||||||
<version>1.1.1</version>
|
<version>1.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/com.lowagie/itext -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lowagie</groupId>
|
<groupId>com.lowagie</groupId>
|
||||||
<artifactId>itext</artifactId>
|
<artifactId>itext</artifactId>
|
||||||
|
|
@ -454,7 +485,136 @@
|
||||||
<artifactId>jjwt</artifactId>
|
<artifactId>jjwt</artifactId>
|
||||||
<version>0.9.1</version>
|
<version>0.9.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-main</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-opengis</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-referencing</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-epsg-hsql</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-cql</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-data</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-api</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-metadata</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-xml</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-swing</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-render</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-shapefile</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools.xsd</groupId>
|
||||||
|
<artifactId>gt-xsd-sld</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-geojson</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-process</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-jdbc</artifactId>
|
||||||
|
<version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools.jdbc</groupId>
|
||||||
|
<artifactId>gt-jdbc-postgis</artifactId> <version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools.jdbc</groupId>
|
||||||
|
<artifactId>gt-jdbc-oracle</artifactId> <version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools.jdbc</groupId>
|
||||||
|
<artifactId>gt-jdbc-h2</artifactId> <version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools.jdbc</groupId>
|
||||||
|
<artifactId>gt-jdbc-mysql</artifactId> <version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools.jdbc</groupId>
|
||||||
|
<artifactId>gt-jdbc-db2</artifactId> <version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools.jdbc</groupId>
|
||||||
|
<artifactId>gt-jdbc-sqlserver</artifactId> <version>11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.vividsolutions</groupId>
|
||||||
|
<artifactId>jts</artifactId>
|
||||||
|
<version>1.13</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.eclipse.xsd/org.eclipse.xsd -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.emf</groupId>
|
||||||
|
<artifactId>org.eclipse.emf.ecore</artifactId>
|
||||||
|
<version>2.9.1-v20130827-0309</version>
|
||||||
|
</dependency>
|
||||||
|
<!--
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.emf</groupId>
|
||||||
|
<artifactId>org.eclipse.emf.common</artifactId>
|
||||||
|
<version>2.9.1-v20130827-0309</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.xsd</groupId>
|
||||||
|
<artifactId>org.eclipse.xsd</artifactId>
|
||||||
|
<version>2.9.1-v20130902-0605</version>
|
||||||
|
</dependency>
|
||||||
|
-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,64 +1,33 @@
|
||||||
package geoinfo.drilling.home;
|
package geoinfo.drilling.home;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.jfree.util.Log;
|
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
||||||
import geoinfo.com.WebConfirm;
|
import geoinfo.com.WebConfirm;
|
||||||
import geoinfo.drilling.home.service.DrillingHomeService;
|
import geoinfo.drilling.home.service.DrillingHomeService;
|
||||||
import geoinfo.drilling.input.service.DrillingInputService;
|
|
||||||
import geoinfo.drilling.inquiry.service.DrillingInquiryService;
|
import geoinfo.drilling.inquiry.service.DrillingInquiryService;
|
||||||
import geoinfo.main.login.service.LoginService;
|
import geoinfo.main.login.service.LoginService;
|
||||||
import geoinfo.main.notice.service.NoticeService;
|
import geoinfo.main.notice.service.NoticeService;
|
||||||
import geoinfo.map.mapControl.service.MapControlService;
|
|
||||||
import geoinfo.regi.selectClassInfo.service.SelectClassService;
|
|
||||||
import geoinfo.regi.status.service.RegiPageService;
|
|
||||||
import geoinfo.regi.util.exportGeotechnicalPointShp2;
|
|
||||||
import geoinfo.util.MobileCertificationUtil;
|
|
||||||
import geoinfo.util.MyUtil;
|
import geoinfo.util.MyUtil;
|
||||||
import ictway.comm.util.parseData;
|
|
||||||
import ictway.comm.util.strUtil;
|
|
||||||
import ictway.comm.web.WebUtil;
|
|
||||||
import ictway.whois.whoisSMS;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class DrillingHomeController {
|
public class DrillingHomeController {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import egovframework.rte.psl.dataaccess.util.EgovMap;
|
||||||
public interface DrillingHomeMapper {
|
public interface DrillingHomeMapper {
|
||||||
List<EgovMap> drillingMapSearchHole(String comCode);
|
List<EgovMap> drillingMapSearchHole(String comCode);
|
||||||
List<EgovMap> drillingMapSearchHoleWithMbr(HashMap<String, Object> params);
|
List<EgovMap> drillingMapSearchHoleWithMbr(HashMap<String, Object> params);
|
||||||
|
String projectCodesByProjectMasterCompanyCodeAsComma(HashMap<String, Object> params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,6 @@ import egovframework.rte.psl.dataaccess.util.EgovMap;
|
||||||
public interface DrillingHomeService {
|
public interface DrillingHomeService {
|
||||||
public List<EgovMap> drillingMapSearchHole(String projectCode);
|
public List<EgovMap> drillingMapSearchHole(String projectCode);
|
||||||
public List<EgovMap> drillingMapSearchHoleWithMbr(HashMap<String, Object> params);
|
public List<EgovMap> drillingMapSearchHoleWithMbr(HashMap<String, Object> params);
|
||||||
|
|
||||||
|
public String projectCodesByProjectMasterCompanyCodeAsComma(HashMap<String, Object> params);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,11 @@ public class DrillingHomeServiceImpl implements DrillingHomeService {
|
||||||
public List<EgovMap> drillingMapSearchHoleWithMbr(HashMap<String, Object> params) {
|
public List<EgovMap> drillingMapSearchHoleWithMbr(HashMap<String, Object> params) {
|
||||||
return drillingHomeMapper.drillingMapSearchHoleWithMbr(params);
|
return drillingHomeMapper.drillingMapSearchHoleWithMbr(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String projectCodesByProjectMasterCompanyCodeAsComma(HashMap<String, Object> params) {
|
||||||
|
return drillingHomeMapper.projectCodesByProjectMasterCompanyCodeAsComma(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2877,5 +2877,29 @@ public class LoginController {
|
||||||
}
|
}
|
||||||
return mv;
|
return mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 패스워드 생성용 - 발주기관 계정 생성시 사용함.
|
||||||
|
@RequestMapping(value = "/makePassword.do", method = RequestMethod.GET)
|
||||||
|
public String drillingMapSearchHoleWithMbr(HttpServletRequest request, String companyCode, ModelMap model, @RequestParam("userId") String userId, @RequestParam("newPass") String newPass) throws Exception {
|
||||||
|
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
|
md.reset();
|
||||||
|
md.update(userId.getBytes());
|
||||||
|
md.update(userId.getBytes());
|
||||||
|
md.update(newPass.getBytes());
|
||||||
|
md.update(userId.getBytes());
|
||||||
|
md.update(userId.getBytes());
|
||||||
|
|
||||||
|
byte[] digest = md.digest();
|
||||||
|
String shaHex = "";
|
||||||
|
shaHex = DatatypeConverter.printHexBinary(digest);
|
||||||
|
newPass = GeoinfoCommon.parseData(newPass);
|
||||||
|
newPass = ScriptUtil.getSha256(newPass, "UTF-8").substring(0, 20);
|
||||||
|
|
||||||
|
model.put("data", newPass);
|
||||||
|
|
||||||
|
return "jsonView";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -53,6 +53,7 @@ import geoinfo.com.GeoInfoSessionMgrListener;
|
||||||
import geoinfo.com.GeoinfoCommon;
|
import geoinfo.com.GeoinfoCommon;
|
||||||
import geoinfo.com.MultiLoginPreventor;
|
import geoinfo.com.MultiLoginPreventor;
|
||||||
import geoinfo.com.file.FileCmmn;
|
import geoinfo.com.file.FileCmmn;
|
||||||
|
import geoinfo.drilling.home.service.DrillingHomeService;
|
||||||
import geoinfo.main.login.service.LoginService;
|
import geoinfo.main.login.service.LoginService;
|
||||||
import geoinfo.map.left.service.MapLeftService;
|
import geoinfo.map.left.service.MapLeftService;
|
||||||
import geoinfo.map.mapControl.service.MapControlService;
|
import geoinfo.map.mapControl.service.MapControlService;
|
||||||
|
|
@ -81,6 +82,11 @@ public class MapLeftController {
|
||||||
|
|
||||||
@Resource(name = "headerService")
|
@Resource(name = "headerService")
|
||||||
private HeaderService headerService;
|
private HeaderService headerService;
|
||||||
|
|
||||||
|
|
||||||
|
@Resource(name = "drillingHomeService")
|
||||||
|
private DrillingHomeService drillingHomeService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(GeoInfoSessionMgrListener.class);
|
private final static Logger logger = LoggerFactory.getLogger(GeoInfoSessionMgrListener.class);
|
||||||
|
|
@ -303,6 +309,21 @@ public class MapLeftController {
|
||||||
String sidoSub = "";
|
String sidoSub = "";
|
||||||
String gugunSub = "";
|
String gugunSub = "";
|
||||||
String dongSub = "";
|
String dongSub = "";
|
||||||
|
|
||||||
|
// 발주기관 프로젝트 코드만 조회
|
||||||
|
String masterCompanyCode = null;
|
||||||
|
String masterCompanyProjectCodes = null;
|
||||||
|
if( params.get("masterCompanyCode") != null ) {
|
||||||
|
masterCompanyCode = GeoinfoCommon.parseData(params.get("masterCompanyCode").toString().trim());
|
||||||
|
|
||||||
|
HashMap<String, Object> paramsMasterCompanyCode = new HashMap<String, Object>();
|
||||||
|
paramsMasterCompanyCode.put("COM_CODE", masterCompanyCode);
|
||||||
|
masterCompanyProjectCodes = drillingHomeService.projectCodesByProjectMasterCompanyCodeAsComma(paramsMasterCompanyCode);
|
||||||
|
|
||||||
|
params.put("masterCompanyCode", masterCompanyCode);
|
||||||
|
params.put("masterCompanyProjectCodes", masterCompanyProjectCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!(sido.equals("all"))) {
|
if (!(sido.equals("all"))) {
|
||||||
sidoSub = sido.substring(0, 4);
|
sidoSub = sido.substring(0, 4);
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,8 @@ public class AVList {
|
||||||
throw new IllegalArgumentException("AVList :: AVList is NULL.");
|
throw new IllegalArgumentException("AVList :: AVList is NULL.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Set entries = list.getEntries();
|
Set<Entry<String, Object>> entries = list.getEntries();
|
||||||
for (Map.Entry entry : entries)
|
for (Entry entry : entries)
|
||||||
{
|
{
|
||||||
setValue((String)entry.getKey(), entry.getValue());
|
setValue((String)entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,507 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
public class AWTLabelUtil {
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.GeneralPath;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
|
import java.awt.geom.PathIterator;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
}
|
public class AWTLabelUtil {
|
||||||
|
public static Point2D getLabelPositionMBR(LabelInfo labelInfo) {
|
||||||
|
Point2D mbrPoint = AWTLabelUtil.getCrossLineCenter(labelInfo.generalPath, new Point2D.Double(labelInfo.generalPath.getBounds().getCenterX(), labelInfo.generalPath.getBounds().getCenterY()));
|
||||||
|
if (mbrPoint == null) {
|
||||||
|
return new Point2D.Double(labelInfo.polygon.getCentroid().getX(), labelInfo.polygon.getCentroid().getY());
|
||||||
|
}
|
||||||
|
return mbrPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Point2D getLabelPosition(LabelInfo labelInfo, Point2D point) {
|
||||||
|
Point2D labelPoint = AWTLabelUtil.getCrossLineCenter(labelInfo.generalPath, new Point2D.Double(point.getX(), point.getY()));
|
||||||
|
if (labelPoint == null) {
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
return labelPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isContainLabel(LabelInfo labelInfo, Point2D center, double rotation) {
|
||||||
|
AffineTransform transform = AWTLabelUtil.getPolygonAlignTextTransform(labelInfo, center, rotation);
|
||||||
|
Rectangle2D labelBound = labelInfo.labelPainter.getFullLabelBounds();
|
||||||
|
Point2D.Double UL = new Point2D.Double(labelBound.getMinX(), labelBound.getMinY());
|
||||||
|
Point2D.Double UR = new Point2D.Double(labelBound.getMaxX(), labelBound.getMinY());
|
||||||
|
Point2D.Double LL = new Point2D.Double(labelBound.getMinX(), labelBound.getMaxY());
|
||||||
|
Point2D.Double LR = new Point2D.Double(labelBound.getMaxX(), labelBound.getMaxY());
|
||||||
|
transform.transform(UL, UL);
|
||||||
|
transform.transform(UR, UR);
|
||||||
|
transform.transform(LL, LL);
|
||||||
|
transform.transform(LR, LR);
|
||||||
|
if (!labelInfo.generalPath.contains(UL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!labelInfo.generalPath.contains(UR)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!labelInfo.generalPath.contains(LL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return labelInfo.generalPath.contains(LR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isContainLabel(LabelInfo labelInfo, AffineTransform transform) {
|
||||||
|
Rectangle2D labelBound = labelInfo.labelPainter.getFullLabelBounds();
|
||||||
|
Point2D.Double UL = new Point2D.Double(labelBound.getMinX(), labelBound.getMinY());
|
||||||
|
Point2D.Double UR = new Point2D.Double(labelBound.getMaxX(), labelBound.getMinY());
|
||||||
|
Point2D.Double LL = new Point2D.Double(labelBound.getMinX(), labelBound.getMaxY());
|
||||||
|
Point2D.Double LR = new Point2D.Double(labelBound.getMaxX(), labelBound.getMaxY());
|
||||||
|
transform.transform(UL, UL);
|
||||||
|
transform.transform(UR, UR);
|
||||||
|
transform.transform(LL, LL);
|
||||||
|
transform.transform(LR, LR);
|
||||||
|
if (!labelInfo.generalPath.contains(UL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!labelInfo.generalPath.contains(UR)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!labelInfo.generalPath.contains(LL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return labelInfo.generalPath.contains(LR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean refineLabelPositionQuadrant(LabelInfo labelInfo, double rotation) {
|
||||||
|
double rectX = labelInfo.generalPath.getBounds2D().getX();
|
||||||
|
double rectY = labelInfo.generalPath.getBounds2D().getY();
|
||||||
|
double width = labelInfo.generalPath.getBounds2D().getWidth() / 4.0;
|
||||||
|
double height = labelInfo.generalPath.getBounds2D().getHeight() / 4.0;
|
||||||
|
Point2D[] rePoints = new Point2D[]{new Point2D.Double(rectX + width, rectY + height), new Point2D.Double(rectX + width * 3.0, rectY + height), new Point2D.Double(rectX + width, rectY + height * 3.0), new Point2D.Double(rectX + width * 3.0, rectY + height * 3.0)};
|
||||||
|
int i = 0;
|
||||||
|
while (i < 4) {
|
||||||
|
rePoints[i] = AWTLabelUtil.getLabelPosition(labelInfo, rePoints[i]);
|
||||||
|
if (AWTLabelUtil.isContainLabel(labelInfo, rePoints[i], rotation)) {
|
||||||
|
labelInfo.center = rePoints[i];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AffineTransform getPolygonAlignTextTransform(LabelInfo labelInfo, Point2D center, double rotation) {
|
||||||
|
AffineTransform transform = new AffineTransform();
|
||||||
|
transform.translate(center.getX(), center.getY());
|
||||||
|
if (Double.isNaN(rotation) || Double.isInfinite(rotation)) {
|
||||||
|
rotation = 0.0;
|
||||||
|
}
|
||||||
|
transform.rotate(rotation);
|
||||||
|
Rectangle2D textBounds = labelInfo.labelPainter.getLabelBounds();
|
||||||
|
double displacementX = labelInfo.anchorX * -textBounds.getWidth() + labelInfo.displacementX;
|
||||||
|
double displacementY = labelInfo.anchorY * textBounds.getHeight() - labelInfo.displacementY - textBounds.getHeight() + labelInfo.labelPainter.getLineHeight();
|
||||||
|
transform.translate(displacementX, displacementY);
|
||||||
|
return transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLabelRotationORTHO(LabelInfo labelInfo) {
|
||||||
|
Vector<Point2D> hPoints = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, labelInfo.center, 0.0);
|
||||||
|
Vector<Point2D> vPoints = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, labelInfo.center, 1.5707963267948966);
|
||||||
|
Line2D hLine = AWTLabelUtil.getIntersectLineH(hPoints, labelInfo.center);
|
||||||
|
Line2D vLine = AWTLabelUtil.getIntersectLineV(vPoints, labelInfo.center);
|
||||||
|
if (hLine.getBounds().getWidth() > vLine.getBounds().getHeight()) {
|
||||||
|
labelInfo.rCenter = labelInfo.center;
|
||||||
|
labelInfo.rotation = 0.0;
|
||||||
|
} else {
|
||||||
|
labelInfo.rCenter = new Point2D.Double(vLine.getX1(), (vLine.getY1() + vLine.getY2()) / 2.0);
|
||||||
|
labelInfo.rotation = -1.5707963267948966;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLabelRotationMBR(LabelInfo labelInfo) {
|
||||||
|
labelInfo.rotation = Math.toRadians(AWTLabelUtil.calcMainAngle(labelInfo.generalPath));
|
||||||
|
KLISLabelUtil pUtil = new KLISLabelUtil(labelInfo.polygon);
|
||||||
|
if (pUtil.isConvex()) {
|
||||||
|
labelInfo.rCenter = AWTLabelUtil.getConvexCenter(labelInfo.generalPath, labelInfo.center, labelInfo.rotation);
|
||||||
|
} else {
|
||||||
|
Point2D rCenter = pUtil.GetMIC_ex();
|
||||||
|
if (rCenter == null) {
|
||||||
|
labelInfo.rCenter = AWTLabelUtil.getOptimalCenter(labelInfo.generalPath, labelInfo.center);
|
||||||
|
} else if (pUtil.hasParabola() == 0) {
|
||||||
|
labelInfo.rCenter = AWTLabelUtil.getConvexCenter(labelInfo.generalPath, labelInfo.center, labelInfo.rotation);
|
||||||
|
} else {
|
||||||
|
Vector<Point2D> points = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, labelInfo.center, labelInfo.rotation);
|
||||||
|
double dist = Point2D.distance(points.get(0).getX(), points.get(0).getY(), points.get(1).getX(), points.get(1).getY());
|
||||||
|
if (pUtil.getMaxRadius() * 10.0 < dist && pUtil.getMaxRadius() > labelInfo.labelPainter.getFullLabelBounds().getHeight() * 5.0) {
|
||||||
|
labelInfo.rCenter = AWTLabelUtil.getOptimalCenter(labelInfo.generalPath, labelInfo.center);
|
||||||
|
} else {
|
||||||
|
Vector<Point2D> rpoints = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, labelInfo.center, labelInfo.rotation + 1.5707963267948966);
|
||||||
|
Vector<Point2D> rpoints_v = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, rCenter, labelInfo.rotation + 1.5707963267948966);
|
||||||
|
Vector<Point2D> rpoints_h = AWTLabelUtil.getIntersectPoints(labelInfo.generalPath, rCenter, labelInfo.rotation);
|
||||||
|
if (rpoints_v.size() == 2 && rpoints.size() == 2 && rpoints_h.size() == 2) {
|
||||||
|
double diff;
|
||||||
|
double dist0 = Point2D.distance(rpoints.get(0).getX(), rpoints.get(0).getY(), rpoints.get(1).getX(), rpoints.get(1).getY());
|
||||||
|
double dist_v = Point2D.distance(rpoints_v.get(0).getX(), rpoints_v.get(0).getY(), rpoints_v.get(1).getX(), rpoints_v.get(1).getY());
|
||||||
|
double dist_h = Point2D.distance(rpoints_h.get(0).getX(), rpoints_h.get(0).getY(), rpoints_h.get(1).getX(), rpoints_h.get(1).getY());
|
||||||
|
double d = diff = dist0 >= dist_v ? dist_v / dist0 : dist0 / dist_v;
|
||||||
|
if (diff > 0.8 && dist_v * 5.0 < dist_h && pUtil.edgeDiffCounts() % 2 != 1) {
|
||||||
|
rCenter = AWTLabelUtil.getConvexCenter(labelInfo.generalPath, labelInfo.center, labelInfo.rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
labelInfo.rCenter = rCenter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Point2D getConvexCenter(GeneralPath generalPath, Point2D center, double rotation) {
|
||||||
|
Vector<Point2D> points = AWTLabelUtil.getIntersectPoints(generalPath, center, rotation);
|
||||||
|
Line2D line = AWTLabelUtil.getIntersectLineHV(points, center);
|
||||||
|
if (line == null) {
|
||||||
|
return center;
|
||||||
|
}
|
||||||
|
return new Point2D.Double((line.getX1() + line.getX2()) / 2.0, (line.getY1() + line.getY2()) / 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Point2D getOptimalCenter(GeneralPath generalPath, Point2D center) {
|
||||||
|
double dist;
|
||||||
|
Point2D endPt;
|
||||||
|
Point2D startPt;
|
||||||
|
Vector<Point2D> points;
|
||||||
|
double angle;
|
||||||
|
Point2D.Double rCenter = new Point2D.Double(center.getX(), center.getY());
|
||||||
|
Point2D initStartPt = null;
|
||||||
|
Point2D initEndPt = null;
|
||||||
|
double maxDist = 0.0;
|
||||||
|
int i = -5;
|
||||||
|
while (i < 7) {
|
||||||
|
angle = Math.PI * (double)i / 12.0;
|
||||||
|
points = AWTLabelUtil.getIntersectPoints(generalPath, rCenter, angle);
|
||||||
|
int j = 0;
|
||||||
|
while (j < points.size() - 1) {
|
||||||
|
startPt = points.get(j);
|
||||||
|
endPt = points.get(j + 1);
|
||||||
|
if (!(startPt.getX() < ((Point2D)rCenter).getX() && ((Point2D)rCenter).getX() > endPt.getX() || startPt.getY() > ((Point2D)rCenter).getY() && ((Point2D)rCenter).getY() < endPt.getY() || !((dist = Point2D.distance(startPt.getX(), startPt.getY(), endPt.getX(), endPt.getY())) >= maxDist))) {
|
||||||
|
maxDist = dist;
|
||||||
|
if (initStartPt == null || initEndPt == null) {
|
||||||
|
initStartPt = new Point2D.Double(startPt.getX(), startPt.getY());
|
||||||
|
initEndPt = new Point2D.Double(endPt.getX(), endPt.getY());
|
||||||
|
} else {
|
||||||
|
initStartPt.setLocation(startPt);
|
||||||
|
initEndPt.setLocation(endPt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
if (initStartPt == null || initEndPt == null) {
|
||||||
|
return center;
|
||||||
|
}
|
||||||
|
((Point2D)rCenter).setLocation((initStartPt.getX() + initEndPt.getX()) / 2.0, (initStartPt.getY() + initEndPt.getY()) / 2.0);
|
||||||
|
++i;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
angle = AWTLabelUtil.calcMainAngle(generalPath);
|
||||||
|
points = AWTLabelUtil.getIntersectPoints(generalPath, rCenter, Math.toRadians(angle));
|
||||||
|
double minDist = Double.MAX_VALUE;
|
||||||
|
int j = 0;
|
||||||
|
while (j < points.size() - 1) {
|
||||||
|
startPt = points.get(j);
|
||||||
|
endPt = points.get(j + 1);
|
||||||
|
if (!(startPt.getX() < ((Point2D)rCenter).getX() && ((Point2D)rCenter).getX() > endPt.getX() || startPt.getY() > ((Point2D)rCenter).getY() && ((Point2D)rCenter).getY() < endPt.getY() || !((dist = Point2D.distance(startPt.getX(), startPt.getY(), endPt.getX(), endPt.getY())) < minDist))) {
|
||||||
|
minDist = dist;
|
||||||
|
initStartPt = new Point2D.Double(startPt.getX(), startPt.getY());
|
||||||
|
initEndPt = new Point2D.Double(endPt.getX(), endPt.getY());
|
||||||
|
}
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
double d = generalPath.getBounds2D().getHeight() > generalPath.getBounds2D().getWidth() ? generalPath.getBounds2D().getHeight() : generalPath.getBounds2D().getWidth();
|
||||||
|
if (maxDist * 10.0 < d) {
|
||||||
|
return center;
|
||||||
|
}
|
||||||
|
return new Point2D.Double((initStartPt.getX() + initEndPt.getX()) / 2.0, (initStartPt.getY() + initEndPt.getY()) / 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Line2D getIntersectLineHV(Vector<Point2D> points, Point2D point) {
|
||||||
|
if (points.size() < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Line2D.Double maxLine = null;
|
||||||
|
double maxDist = 0.0;
|
||||||
|
int i = 0;
|
||||||
|
while (i < points.size() - 1) {
|
||||||
|
Point2D sp1 = points.get(i);
|
||||||
|
Point2D sp2 = points.get(i + 1);
|
||||||
|
if (Math.min(sp1.getX(), sp2.getX()) <= point.getX() && point.getX() <= Math.max(sp1.getX(), sp2.getX()) && Math.min(sp1.getY(), sp2.getY()) <= point.getY() && point.getY() <= Math.max(sp1.getY(), sp2.getY())) {
|
||||||
|
return new Line2D.Double(sp1, sp2);
|
||||||
|
}
|
||||||
|
double currentDist = sp1.distance(sp2);
|
||||||
|
if (maxDist < currentDist) {
|
||||||
|
maxDist = currentDist;
|
||||||
|
maxLine = new Line2D.Double(sp1, sp2);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double calcMainAngle(GeneralPath path) {
|
||||||
|
double[] lineLength = AWTLabelUtil.calcAngleFactor(path);
|
||||||
|
int maxIndex = 0;
|
||||||
|
double maxLength = lineLength[0];
|
||||||
|
int i = 1;
|
||||||
|
while (i < lineLength.length) {
|
||||||
|
if (maxLength < lineLength[i]) {
|
||||||
|
maxIndex = i;
|
||||||
|
maxLength = lineLength[i];
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
int angle = maxIndex * 10;
|
||||||
|
if (angle > 90) {
|
||||||
|
return angle - 180;
|
||||||
|
}
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double[] calcAngleFactor(GeneralPath path) {
|
||||||
|
double[] lineLength = new double[18];
|
||||||
|
double[] startCoords = new double[6];
|
||||||
|
double[] currentCoords = new double[6];
|
||||||
|
int type = -1;
|
||||||
|
double subAngle = 0.0;
|
||||||
|
PathIterator pathIter = path.getPathIterator(new AffineTransform());
|
||||||
|
while (!pathIter.isDone()) {
|
||||||
|
type = pathIter.currentSegment(currentCoords);
|
||||||
|
if (type != 0 && type == 1 && startCoords[0] != currentCoords[0] && startCoords[1] != currentCoords[1]) {
|
||||||
|
subAngle = AWTLabelUtil.getAbsoluteAngle(startCoords[0], startCoords[1], currentCoords[0], currentCoords[1]);
|
||||||
|
int index = (int)(subAngle >= 175.0 ? 0.0 : (subAngle + 5.0) / 10.0);
|
||||||
|
double dist = Point2D.distance(startCoords[0], startCoords[1], currentCoords[0], currentCoords[1]);
|
||||||
|
lineLength[index] = lineLength[index] + dist;
|
||||||
|
}
|
||||||
|
startCoords = Arrays.copyOf(currentCoords, currentCoords.length);
|
||||||
|
pathIter.next();
|
||||||
|
}
|
||||||
|
return lineLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Point2D getCrossLineCenter(GeneralPath path, Point2D point) {
|
||||||
|
Vector<Point2D> hPoints = AWTLabelUtil.getIntersectPoints(path, point, 0.0);
|
||||||
|
Vector<Point2D> vPoints = AWTLabelUtil.getIntersectPoints(path, point, 1.5707963267948966);
|
||||||
|
Vector<Line2D> hLines = AWTLabelUtil.getContainLines(path, hPoints);
|
||||||
|
Vector<Line2D> vLines = AWTLabelUtil.getContainLines(path, vPoints);
|
||||||
|
double maxHDist = 0.0;
|
||||||
|
Line2D maxHLine = null;
|
||||||
|
double dist = 0.0;
|
||||||
|
for (Line2D line : hLines) {
|
||||||
|
dist = Math.abs(line.getX1() - line.getX2());
|
||||||
|
if (!(maxHDist < dist)) continue;
|
||||||
|
maxHDist = dist;
|
||||||
|
maxHLine = line;
|
||||||
|
}
|
||||||
|
double maxVDist = 0.0;
|
||||||
|
Line2D maxVLine = null;
|
||||||
|
for (Line2D line : vLines) {
|
||||||
|
point = new Point2D.Double(line.getX1(), (line.getY1() + line.getY2()) / 2.0);
|
||||||
|
hPoints = AWTLabelUtil.getIntersectPoints(path, point, 0.0);
|
||||||
|
if ((line = AWTLabelUtil.getIntersectLineH(hPoints, point)) == null || !(maxVDist < (dist = Math.abs(line.getX1() - line.getX2())))) continue;
|
||||||
|
maxVDist = dist;
|
||||||
|
maxVLine = line;
|
||||||
|
}
|
||||||
|
if (maxHLine == null && maxVLine == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (maxHLine == null) {
|
||||||
|
return AWTLabelUtil.refineLineCenterV(path, maxVLine);
|
||||||
|
}
|
||||||
|
if (maxVLine == null) {
|
||||||
|
return AWTLabelUtil.refineLineCenterH(path, maxHLine);
|
||||||
|
}
|
||||||
|
if (maxHDist > maxVDist) {
|
||||||
|
return AWTLabelUtil.refineLineCenterH(path, maxHLine);
|
||||||
|
}
|
||||||
|
return AWTLabelUtil.refineLineCenterV(path, maxVLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Point2D refineLineCenterV(GeneralPath path, Line2D line) {
|
||||||
|
return new Point2D.Double((line.getX1() + line.getX2()) / 2.0, line.getY1());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Point2D refineLineCenterH(GeneralPath path, Line2D line) {
|
||||||
|
Point2D.Double center = new Point2D.Double((line.getX1() + line.getX2()) / 2.0, line.getY1());
|
||||||
|
Vector<Point2D> vPoints = AWTLabelUtil.getIntersectPoints(path, center, 1.5707963267948966);
|
||||||
|
Line2D vLine = AWTLabelUtil.getIntersectLineV(vPoints, center);
|
||||||
|
if (vLine == null) {
|
||||||
|
return center;
|
||||||
|
}
|
||||||
|
return new Point2D.Double(vLine.getX1(), (vLine.getY1() + vLine.getY2()) / 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Line2D getIntersectLineH(Vector<Point2D> points, Point2D point) {
|
||||||
|
if (points.size() < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
while (i < points.size() - 1) {
|
||||||
|
Point2D sp1 = points.get(i);
|
||||||
|
Point2D sp2 = points.get(i + 1);
|
||||||
|
if (Math.min(sp1.getX(), sp2.getX()) <= point.getX() && point.getX() <= Math.max(sp1.getX(), sp2.getX())) {
|
||||||
|
return new Line2D.Double(sp1, sp2);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Line2D getIntersectLineV(Vector<Point2D> points, Point2D point) {
|
||||||
|
if (points.size() < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
while (i < points.size() - 1) {
|
||||||
|
Point2D sp1 = points.get(i);
|
||||||
|
Point2D sp2 = points.get(i + 1);
|
||||||
|
if (Math.min(sp1.getY(), sp2.getY()) <= point.getY() && point.getY() <= Math.max(sp1.getY(), sp2.getY())) {
|
||||||
|
return new Line2D.Double(sp1, sp2);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vector<Line2D> getContainLines(GeneralPath path, Vector<Point2D> points) {
|
||||||
|
if (points.size() < 2) {
|
||||||
|
return new Vector<Line2D>();
|
||||||
|
}
|
||||||
|
Vector<Line2D> lines = new Vector<Line2D>();
|
||||||
|
int i = 0;
|
||||||
|
while (i < points.size() - 1) {
|
||||||
|
double cy;
|
||||||
|
double cx;
|
||||||
|
Point2D sp1 = points.get(i);
|
||||||
|
Point2D sp2 = points.get(i + 1);
|
||||||
|
if (sp1.getX() == sp2.getX()) {
|
||||||
|
cx = sp1.getX();
|
||||||
|
cy = (sp1.getY() + sp2.getY()) / 2.0;
|
||||||
|
} else {
|
||||||
|
cx = (sp1.getX() + sp2.getX()) / 2.0;
|
||||||
|
cy = sp1.getY();
|
||||||
|
}
|
||||||
|
if (path.contains(cx, cy)) {
|
||||||
|
lines.add(new Line2D.Double(sp1, sp2));
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vector<Point2D> getIntersectPoints(GeneralPath path, Point2D point, double angle) {
|
||||||
|
Vector<Point2D> holder = new Vector<Point2D>();
|
||||||
|
Line2D baseLine = AWTLabelUtil.getBoundCuttingLine(path.getBounds2D(), point, angle);
|
||||||
|
double a1 = Math.tan(angle);
|
||||||
|
double b1 = point.getY() - a1 * point.getX();
|
||||||
|
double[] startCoords = new double[6];
|
||||||
|
double[] currentCoords = new double[6];
|
||||||
|
int type = -1;
|
||||||
|
double subAngle = 0.0;
|
||||||
|
PathIterator pathIter = path.getPathIterator(new AffineTransform());
|
||||||
|
while (!pathIter.isDone()) {
|
||||||
|
type = pathIter.currentSegment(currentCoords);
|
||||||
|
if (type != 0 && type == 1 && startCoords[0] != currentCoords[0] && startCoords[1] != currentCoords[1] && angle != (subAngle = AWTLabelUtil.getAngle(startCoords[0], startCoords[1], currentCoords[0], currentCoords[1])) && baseLine.intersectsLine(startCoords[0], startCoords[1], currentCoords[0], currentCoords[1])) {
|
||||||
|
double y;
|
||||||
|
double x;
|
||||||
|
double a2 = Math.tan(subAngle);
|
||||||
|
double b2 = currentCoords[1] - a2 * currentCoords[0];
|
||||||
|
if (angle == 1.5707963267948966) {
|
||||||
|
x = point.getX();
|
||||||
|
y = a2 * x + b2;
|
||||||
|
} else if (subAngle == 1.5707963267948966) {
|
||||||
|
x = currentCoords[0];
|
||||||
|
y = a1 * x + b1;
|
||||||
|
} else {
|
||||||
|
x = (b2 - b1) / (a1 - a2);
|
||||||
|
y = (a1 * b2 - a2 * b1) / (a1 - a2);
|
||||||
|
}
|
||||||
|
AWTLabelUtil.addPointBySort(holder, new Point2D.Double(x, y));
|
||||||
|
}
|
||||||
|
startCoords = Arrays.copyOf(currentCoords, currentCoords.length);
|
||||||
|
pathIter.next();
|
||||||
|
}
|
||||||
|
return holder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addPointBySort(Vector<Point2D> holder, Point2D point) {
|
||||||
|
boolean inserted = false;
|
||||||
|
int i = 0;
|
||||||
|
while (i < holder.size()) {
|
||||||
|
Point2D current_point = holder.get(i);
|
||||||
|
if (point.getX() < current_point.getX()) {
|
||||||
|
holder.add(i, point);
|
||||||
|
inserted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (point.getX() == current_point.getX() && point.getY() < current_point.getY()) {
|
||||||
|
holder.add(i, point);
|
||||||
|
inserted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (!inserted) {
|
||||||
|
holder.add(point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Line2D getBoundCuttingLine(Rectangle2D bound, Point2D point, double angle) {
|
||||||
|
double minx = bound.getMinX() - 10.0;
|
||||||
|
double miny = bound.getMinY() - 10.0;
|
||||||
|
double maxx = bound.getMaxX() + 10.0;
|
||||||
|
double maxy = bound.getMaxY() + 10.0;
|
||||||
|
Line2D.Double line = angle == 1.5707963267948966 ? new Line2D.Double(point.getX(), miny, point.getX(), maxy) : (angle == 0.0 ? new Line2D.Double(minx, point.getY(), maxx, point.getY()) : new Line2D.Double(minx, point.getY() - (point.getX() - minx) * Math.tan(angle), maxx, point.getY() + (maxx - point.getX()) * Math.tan(angle)));
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double getAngle(double x1, double y1, double x2, double y2) {
|
||||||
|
Point2D.Double pt = new Point2D.Double(x2 - x1, y2 - y1);
|
||||||
|
if (((Point2D)pt).getX() == 0.0 && ((Point2D)pt).getY() == 0.0) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
if (((Point2D)pt).getY() == 0.0) {
|
||||||
|
if (((Point2D)pt).getX() > 0.0) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
return Math.PI;
|
||||||
|
}
|
||||||
|
if (((Point2D)pt).getX() == 0.0) {
|
||||||
|
if (((Point2D)pt).getY() > 0.0) {
|
||||||
|
return 1.5707963267948966;
|
||||||
|
}
|
||||||
|
return 4.71238898038469;
|
||||||
|
}
|
||||||
|
if (((Point2D)pt).getX() > 0.0) {
|
||||||
|
if (((Point2D)pt).getY() > 0.0) {
|
||||||
|
return Math.atan(((Point2D)pt).getY() / ((Point2D)pt).getX());
|
||||||
|
}
|
||||||
|
return Math.atan(((Point2D)pt).getY() / ((Point2D)pt).getX()) + Math.PI * 2;
|
||||||
|
}
|
||||||
|
return Math.atan(((Point2D)pt).getY() / ((Point2D)pt).getX()) + Math.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double getAbsoluteAngle(double x1, double y1, double x2, double y2) {
|
||||||
|
if (y1 == y2) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
if (x1 == x2) {
|
||||||
|
return 90.0;
|
||||||
|
}
|
||||||
|
boolean excessRightAngle = false;
|
||||||
|
if (x1 > x2 && y1 < y2 || x1 < x2 && y1 > y2) {
|
||||||
|
excessRightAngle = true;
|
||||||
|
}
|
||||||
|
double base = Math.abs(x1 - x2);
|
||||||
|
double height = Math.abs(y1 - y2);
|
||||||
|
double r_angle = Math.atan(height / base);
|
||||||
|
if (excessRightAngle) {
|
||||||
|
return Math.toDegrees(Math.PI - r_angle);
|
||||||
|
}
|
||||||
|
return Math.toDegrees(r_angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
public abstract class AbstractService
|
||||||
|
extends HttpServlet {
|
||||||
|
private static final long serialVersionUID = 2014061020172321L;
|
||||||
|
|
||||||
|
public abstract Object parseQuery(HttpServletRequest var1) throws Exception;
|
||||||
|
|
||||||
|
public abstract String doProcess(String var1);
|
||||||
|
|
||||||
|
public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
|
||||||
|
super.service(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
super.doGet(req, resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
super.doPost(req, resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import org.geotools.factory.GeoTools;
|
import org.geotools.factory.GeoTools;
|
||||||
import org.geotools.factory.Hints;
|
import org.geotools.factory.Hints;
|
||||||
|
|
@ -10,40 +9,297 @@ import org.geotools.util.NameFactory;
|
||||||
import org.opengis.referencing.NoSuchAuthorityCodeException;
|
import org.opengis.referencing.NoSuchAuthorityCodeException;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
import org.opengis.util.GenericName;
|
import org.opengis.util.GenericName;
|
||||||
import org.opengis.util.NameSpace;
|
|
||||||
|
|
||||||
public class CRSMngr {
|
public class CRSMngr
|
||||||
private static final O2CRSFactory crsFactory = new O2CRSFactory();
|
{
|
||||||
|
private static final O2CRSFactory crsFactory = new O2CRSFactory();
|
||||||
public static CoordinateReferenceSystem getLayerCRS(int srid, boolean useEPSG)
|
private static final O2CRSOverrideFactory overrideFactory = new O2CRSOverrideFactory();
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
CoordinateReferenceSystem crs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
crs = crsFactory.getCRS(srid);
|
|
||||||
|
|
||||||
return overrideFactory.createCoordinateReferenceSystem(CRS.toSRS(crs));
|
static
|
||||||
}
|
{
|
||||||
catch (Exception e)
|
System.setProperty("org.geotools.referencing.forceXY", "true");
|
||||||
{
|
Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.valueOf(true));
|
||||||
if (crs != null) {
|
GeoTools.fireConfigurationChanged();
|
||||||
return crs;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogMngr.getInstance().logError("[CRS]", "SRID [" + srid + "] is not exist.");
|
ReferencingFactoryFinder.addAuthorityFactory(crsFactory);
|
||||||
|
ReferencingFactoryFinder.addAuthorityFactory(overrideFactory);
|
||||||
|
}
|
||||||
|
|
||||||
if (useEPSG) {
|
public static CoordinateReferenceSystem getCRS(Integer code)
|
||||||
try
|
{
|
||||||
{
|
return getCRS(String.valueOf(code), true);
|
||||||
LogMngr.getInstance().logInfo("[CRS]", "Try to find SRID from EPSG [EPSG:" + srid + "]");
|
}
|
||||||
return CRS.decode("EPSG:" + srid, true);
|
|
||||||
} catch (Exception e2) {
|
|
||||||
LogMngr.getInstance().logError("[CRS]", "SRID [EPSG:" + srid + "] is not exist.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NoSuchAuthorityCodeException("Not exists authority or code", "LayerCRS", String.valueOf(srid));
|
public static CoordinateReferenceSystem getCRS(String code) {
|
||||||
}
|
return getCRS(code, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CoordinateReferenceSystem getCRS(String code, boolean useEPSG)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
code = code.trim();
|
||||||
|
|
||||||
|
GenericName name = NameFactory.create(code);
|
||||||
|
if ((name.scope().name() == null) && (useEPSG)) {
|
||||||
|
code = "EPSG:" + code;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CRS.decode(code, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "CRS [" + code + "] is not exist.");
|
||||||
|
}return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CoordinateReferenceSystem getLayerCRS(int srid, boolean useEPSG)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem crs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
crs = crsFactory.getCRS(srid);
|
||||||
|
|
||||||
|
return overrideFactory.createCoordinateReferenceSystem(CRS.toSRS(crs));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (crs != null) {
|
||||||
|
return crs;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "SRID [" + srid + "] is not exist.");
|
||||||
|
|
||||||
|
if (useEPSG) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "Try to find SRID from EPSG [EPSG:" + srid + "]");
|
||||||
|
return CRS.decode("EPSG:" + srid, true);
|
||||||
|
} catch (Exception e2) {
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "SRID [EPSG:" + srid + "] is not exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NoSuchAuthorityCodeException("Not exists authority or code", "LayerCRS", String.valueOf(srid));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateLayerCRS()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Map map = ServerContext.getMap();
|
||||||
|
synchronized (map)
|
||||||
|
{
|
||||||
|
Iterator iter = map.getAllLayers().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Layer layer = (Layer)iter.next();
|
||||||
|
layer.updateCRS();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateLayerCRS(CoordinateReferenceSystem targetCRS)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Map map = ServerContext.getMap();
|
||||||
|
synchronized (map)
|
||||||
|
{
|
||||||
|
Iterator iter = map.getAllLayers().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Layer layer = (Layer)iter.next();
|
||||||
|
|
||||||
|
if (CRS.toSRS(layer.getCRS()).equalsIgnoreCase(CRS.toSRS(targetCRS)))
|
||||||
|
layer.updateCRS();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateLayerCRS(String code)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Map map = ServerContext.getMap();
|
||||||
|
synchronized (map)
|
||||||
|
{
|
||||||
|
Iterator iter = map.getAllLayers().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Layer layer = (Layer)iter.next();
|
||||||
|
|
||||||
|
if (CRS.toSRS(layer.getCRS()).equalsIgnoreCase(code))
|
||||||
|
layer.updateCRS();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertBasicCRS(int srid, String auth, String code, String wkt)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
insertBasicCRS(srid, auth, code, wkt, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertBasicCRS(int srid, String auth, String code, String wkt, boolean write)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem crs = null;
|
||||||
|
try {
|
||||||
|
crs = crsFactory.parseWKT(auth, code, wkt);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new Exception("CoordinateReferenceSystem is not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
crsFactory.insertCRS(srid, auth, code, crs, write);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateBasicCRS(int srid, String auth, String code, String wkt) throws Exception
|
||||||
|
{
|
||||||
|
updateBasicCRS(srid, auth, code, wkt, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateBasicCRS(int srid, String auth, String code, String wkt, boolean write)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem crs = null;
|
||||||
|
try {
|
||||||
|
crs = crsFactory.parseWKT(auth, code, wkt);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalArgumentException("CoordinateReferenceSystem is not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
crsFactory.updateCRS(srid, auth, code, crs, write);
|
||||||
|
|
||||||
|
updateLayerCRS(crs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeBasicCRS(int srid) throws Exception
|
||||||
|
{
|
||||||
|
removeBasicCRS(srid, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeBasicCRS(int srid, boolean write)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem crs = crsFactory.getCRS(srid);
|
||||||
|
|
||||||
|
if (isUsedByLayer(crs)) {
|
||||||
|
throw new IllegalArgumentException("SRID [" + srid + "] is used by Layer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
crsFactory.removeCRS(srid, write);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertOverrideCRS(String auth, String code, String wkt)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
insertOverrideCRS(auth, code, wkt, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertOverrideCRS(String auth, String code, String wkt, boolean write)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem crs = null;
|
||||||
|
try {
|
||||||
|
crs = overrideFactory.parseWKT(auth, code, wkt);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new Exception("CoordinateReferenceSystem is not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
overrideFactory.insertCRS(auth, code, crs, write);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateOverrideCRS(String auth, String code, String wkt) throws Exception
|
||||||
|
{
|
||||||
|
updateOverrideCRS(auth, code, wkt, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateOverrideCRS(String auth, String code, String wkt, boolean write)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem crs = null;
|
||||||
|
try {
|
||||||
|
crs = overrideFactory.parseWKT(auth, code, wkt);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalArgumentException("CoordinateReferenceSystem is not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
overrideFactory.updateCRS(auth, code, crs, write);
|
||||||
|
|
||||||
|
String crsKey = auth.trim().toUpperCase() + ":" + code.trim().toUpperCase();
|
||||||
|
updateLayerCRS(crsKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeOverrideCRS(String auth, String code)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
removeOverrideCRS(auth, code, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeOverrideCRS(String auth, String code, boolean write)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem crs = overrideFactory.getCRS(auth, code);
|
||||||
|
String crsKey = auth.trim().toUpperCase() + ":" + code.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (isUsedByLayer(crs)) {
|
||||||
|
throw new IllegalArgumentException("CODE [Authority:" + auth + "] or [Code:" + code + "] is used by Layer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
overrideFactory.removeCRS(auth, code, write);
|
||||||
|
|
||||||
|
updateLayerCRS(crsKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isUsedByLayer(String code)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Iterator iter = ServerContext.getMap().getAllLayers().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Layer layer = (Layer)iter.next();
|
||||||
|
|
||||||
|
if (CRS.toSRS(layer.getCRS()).equalsIgnoreCase(code))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "isUsedByLayer Fail [CODE:" + code + "] :: " + e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isUsedByLayer(CoordinateReferenceSystem targetCRS) throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Iterator iter = ServerContext.getMap().getAllLayers().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Layer layer = (Layer)iter.next();
|
||||||
|
|
||||||
|
if (CRS.equalsIgnoreMetadata(layer.getCRS(), targetCRS))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "isUsedByLayer Fail [CODE:" + targetCRS + "] :: " + e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reloadServiceCRS(boolean updateLayer) throws Exception
|
||||||
|
{
|
||||||
|
crsFactory.initCrsDefinitions();
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "Success to Reload BasicCRS");
|
||||||
|
overrideFactory.initCrsDefinitions();
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "Success to Reload OverrideCRS");
|
||||||
|
|
||||||
|
if (updateLayer)
|
||||||
|
try {
|
||||||
|
updateLayerCRS();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "Fail to Update Layer CRS :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class CacheFormat {
|
||||||
|
int width = 256;
|
||||||
|
int height = 256;
|
||||||
|
String format = "png";
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return this.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return this.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormat() {
|
||||||
|
return this.format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidth(int width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeight(int height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormat(String format) {
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import javax.management.modelmbean.XMLParseException;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
|
||||||
|
public class CacheLevel {
|
||||||
|
private CacheLevelSet levelSet;
|
||||||
|
private final int level;
|
||||||
|
private Double resolution;
|
||||||
|
private Double scaleDenominator;
|
||||||
|
|
||||||
|
public CacheLevel(Integer lv, Double res, Double scale) throws Exception {
|
||||||
|
this.level = lv;
|
||||||
|
this.resolution = res;
|
||||||
|
this.scaleDenominator = scale;
|
||||||
|
if (this.resolution == null && this.scaleDenominator == null) {
|
||||||
|
throw new XMLParseException("<MATRIX> Attribute value [RESOLUTION or SCALE] is null. LEVEL [" + this.level + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return this.level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getResolution() {
|
||||||
|
return this.resolution;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getScale() {
|
||||||
|
return this.scaleDenominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencedEnvelope getBBox() {
|
||||||
|
return this.levelSet.getBBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCacheSizeW() {
|
||||||
|
return this.levelSet.getCacheSizeW();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCacheSizeH() {
|
||||||
|
return this.levelSet.getCacheSizeH();
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getCachePath() {
|
||||||
|
return new File(this.levelSet.getCacheDir(), "/" + this.level);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCacheFormat() {
|
||||||
|
return this.levelSet.getCacheFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerName() {
|
||||||
|
return this.levelSet.getLayerName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerStyle() {
|
||||||
|
return this.levelSet.getLayerStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refineCacheLevel(CacheLevelSet lSet) throws Exception {
|
||||||
|
this.levelSet = lSet;
|
||||||
|
if (this.resolution == null) {
|
||||||
|
this.resolution = lSet.calResolution(this.scaleDenominator);
|
||||||
|
} else if (this.scaleDenominator == null) {
|
||||||
|
this.scaleDenominator = lSet.calScaleDenominator(this.resolution);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.opengis.referencing.crs.GeographicCRS;
|
||||||
|
|
||||||
|
public class CacheLevelSet {
|
||||||
|
private final double dpi = 90.7142857142857;
|
||||||
|
private final double OGC_DEGREE_TO_METER = 111319.49079327358;
|
||||||
|
private final double OGC_INCH_TO_METER = 0.0254;
|
||||||
|
private final boolean isTopLeft = false;
|
||||||
|
private ImgCacheLayer cacheLayer;
|
||||||
|
private TreeMap<Integer, CacheLevel> levelSet = new TreeMap();
|
||||||
|
|
||||||
|
public CacheLevelSet copy() throws Exception {
|
||||||
|
CacheLevelSet copy = new CacheLevelSet();
|
||||||
|
for (CacheLevel lvl : this.levelSet.values()) {
|
||||||
|
CacheLevel level = new CacheLevel(Integer.valueOf(lvl.getLevel()), lvl.getResolution(), lvl.getScale());
|
||||||
|
copy.addLevel(level);
|
||||||
|
}
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLevel(CacheLevel lvl) {
|
||||||
|
this.levelSet.put(lvl.getLevel(), lvl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheLevel getLevel(double res) {
|
||||||
|
CacheLevel level = null;
|
||||||
|
for (CacheLevel lvl : this.levelSet.values()) {
|
||||||
|
if (level == null) {
|
||||||
|
level = lvl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!(Math.abs(level.getResolution() - res) > Math.abs(lvl.getResolution() - res))) continue;
|
||||||
|
level = lvl;
|
||||||
|
}
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencedEnvelope getBBox() {
|
||||||
|
return this.cacheLayer.getBBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCacheSizeW() {
|
||||||
|
return this.cacheLayer.getCacheSizeW();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCacheSizeH() {
|
||||||
|
return this.cacheLayer.getCacheSizeH();
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getCacheDir() {
|
||||||
|
return this.cacheLayer.getCacheDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCacheFormat() {
|
||||||
|
return this.cacheLayer.getCacheFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerName() {
|
||||||
|
return this.cacheLayer.getLayerName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerStyle() {
|
||||||
|
return this.cacheLayer.getLayerStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTopLeft() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calScaleDenominator(double res) {
|
||||||
|
if (this.cacheLayer.getBBox().getCoordinateReferenceSystem() instanceof GeographicCRS) {
|
||||||
|
return res * 111319.49079327358 / 2.8000000000000003E-4;
|
||||||
|
}
|
||||||
|
return res / 2.8000000000000003E-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calResolution(double scale) {
|
||||||
|
if (this.cacheLayer.getBBox().getCoordinateReferenceSystem() instanceof GeographicCRS) {
|
||||||
|
return scale * 2.8000000000000003E-4 * 8.983152841195214E-6;
|
||||||
|
}
|
||||||
|
return scale * 2.8000000000000003E-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refindCacheLevelSet(ImgCacheLayer clayer) throws Exception {
|
||||||
|
this.cacheLayer = clayer;
|
||||||
|
for (CacheLevel level : this.levelSet.values()) {
|
||||||
|
level.refineCacheLevel(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,69 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
public class ConnJDBC {
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
}
|
public abstract class ConnJDBC {
|
||||||
|
protected Connection connection = null;
|
||||||
|
|
||||||
|
public ConnJDBC() {
|
||||||
|
DriverManager.setLoginTimeout(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection openConn() throws Exception {
|
||||||
|
if (this.connection != null) {
|
||||||
|
return this.connection;
|
||||||
|
}
|
||||||
|
HashMap map = ServerConfiguration.getInstance().getConfMap();
|
||||||
|
String sURL = this.getJDBCUrl();
|
||||||
|
String user = (String)map.get("conf.xml.map.user");
|
||||||
|
String passwd = (String)map.get("conf.xml.map.passwd");
|
||||||
|
try {
|
||||||
|
Class.forName(this.getDriverClassName());
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Can't register JDBC Driver :: " + e.getMessage());
|
||||||
|
throw new Exception("Can't register JDBC Driver :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Open Connection :: " + sURL + ", " + user + ", " + passwd);
|
||||||
|
this.connection = DriverManager.getConnection(sURL, user, passwd);
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Open Connection Fail :: " + e.getMessage());
|
||||||
|
throw new SQLException("Open Connection Fail :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return this.connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeConn() {
|
||||||
|
if (this.connection != null) {
|
||||||
|
try {
|
||||||
|
if (!this.connection.isClosed()) {
|
||||||
|
this.connection.close();
|
||||||
|
}
|
||||||
|
this.connection = null;
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
this.connection = null;
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Close Connection Fail :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJDBCUrl() throws Exception {
|
||||||
|
HashMap map = ServerConfiguration.getInstance().getConfMap();
|
||||||
|
String host = (String)map.get("conf.xml.map.host");
|
||||||
|
String port = (String)map.get("conf.xml.map.port");
|
||||||
|
String database = (String)map.get("conf.xml.map.database");
|
||||||
|
return this.getJDBCUrl(host, Integer.valueOf(port), database);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getDriverClassName();
|
||||||
|
|
||||||
|
public abstract String getJDBCUrl(String var1, Integer var2, String var3);
|
||||||
|
|
||||||
|
public abstract FieldSQL getFieldSQL();
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,87 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
public class ConnMngr {
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
}
|
public class ConnMngr
|
||||||
|
{
|
||||||
|
private static ConnMngr instance = null;
|
||||||
|
private ConnJDBC connJDBC = null;
|
||||||
|
|
||||||
|
public static ConnMngr getInstance()
|
||||||
|
{
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new ConnMngr();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnJDBC getConnObj(String dbType) throws Exception
|
||||||
|
{
|
||||||
|
if ((dbType != null) && (dbType.toLowerCase().equals("oracle")))
|
||||||
|
return new ConnOracle();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Database type [" + dbType + "] is not support.");
|
||||||
|
throw new NullPointerException("Database type [" + dbType + "] is not support.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnJDBC getConnObj(O2DSFactory.DBMSType dbType)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if ((dbType != null) && (dbType == O2DSFactory.DBMSType.ORACLE))
|
||||||
|
return new ConnOracle();
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Database type [" + dbType + "] is not support.");
|
||||||
|
throw new NullPointerException("Database type [" + dbType + "] is not support.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection openConn()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
HashMap map = ServerConfiguration.getInstance().getConfMap();
|
||||||
|
|
||||||
|
String dbType = (String)map.get("conf.xml.map.dbtype");
|
||||||
|
dbType = dbType.trim();
|
||||||
|
|
||||||
|
if ((dbType != null) && (dbType.toLowerCase().equals("oracle"))) {
|
||||||
|
this.connJDBC = new ConnOracle();
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Database type [" + dbType + "] is not support.");
|
||||||
|
throw new NullPointerException("Database type [" + dbType + "] is not support.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.connJDBC.openConn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeConn() {
|
||||||
|
if (this.connJDBC != null)
|
||||||
|
this.connJDBC.closeConn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeSafe(Statement st)
|
||||||
|
{
|
||||||
|
if (st == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
st.close();
|
||||||
|
} catch (SQLException localSQLException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeSafe(ResultSet rs) {
|
||||||
|
if (rs == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rs.close();
|
||||||
|
}
|
||||||
|
catch (SQLException localSQLException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class ConnOracle extends ConnJDBC
|
||||||
|
{
|
||||||
|
public String getDriverClassName()
|
||||||
|
{
|
||||||
|
return "oracle.jdbc.driver.OracleDriver";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJDBCUrl(String host, Integer port, String database)
|
||||||
|
{
|
||||||
|
String sURL = "jdbc:oracle:thin:@";
|
||||||
|
sURL = sURL + host + ":" + port + ":" + database;
|
||||||
|
|
||||||
|
return sURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldSQL getFieldSQL()
|
||||||
|
{
|
||||||
|
HashMap fields = new HashMap();
|
||||||
|
fields.put(FieldSQL.FieldType.GEOMETRY, "SDO_GEOMETRY");
|
||||||
|
fields.put(FieldSQL.FieldType.CHARACTER, "VARCHAR2");
|
||||||
|
fields.put(FieldSQL.FieldType.NUMERIC, "NUMBER");
|
||||||
|
fields.put(FieldSQL.FieldType.BOOLEAN, "CHAR(1)");
|
||||||
|
fields.put(FieldSQL.FieldType.DATE, "DATE");
|
||||||
|
fields.put(FieldSQL.FieldType.BLOB, "BLOB");
|
||||||
|
fields.put(FieldSQL.FieldType.UNKNOWN, "VARCHAR2(100)");
|
||||||
|
|
||||||
|
return new FieldSQL(O2DSFactory.DBMSType.ORACLE, fields, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,238 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap; // Map.Entry 대신 HashMap 사용을 명시
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.geotools.data.Transaction;
|
||||||
|
import org.geotools.data.shapefile.ShapefileDataStore;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureSource;
|
||||||
|
import org.geotools.data.store.ContentDataStore;
|
||||||
|
import org.geotools.data.store.ContentEntry; // ContentEntry는 여전히 사용될 수 있습니다.
|
||||||
|
import org.geotools.data.store.ContentFeatureSource;
|
||||||
|
import org.geotools.data.store.ContentState;
|
||||||
|
import org.geotools.feature.AttributeTypeBuilder;
|
||||||
|
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
||||||
|
import org.geotools.jdbc.AutoGeneratedPrimaryKeyColumn;
|
||||||
|
import org.geotools.jdbc.JDBCDataStore; // JDBCDataStore로 캐스팅하여 더 명확하게 사용
|
||||||
|
import org.geotools.jdbc.JDBCState; // JDBCState는 여전히 사용될 수 있습니다.
|
||||||
|
import org.geotools.jdbc.NonIncrementingPrimaryKeyColumn;
|
||||||
|
import org.geotools.jdbc.NullPrimaryKey;
|
||||||
|
import org.geotools.jdbc.PrimaryKey;
|
||||||
|
import org.geotools.jdbc.PrimaryKeyColumn;
|
||||||
|
import org.geotools.jdbc.SequencedPrimaryKeyColumn;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class ContentDataStoreRefinder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JDBC DataStore의 FeatureType 스키마를 재구성합니다.
|
||||||
|
* 주의: 이 메서드는 GeoTools의 내부 구조에 깊이 의존하므로,
|
||||||
|
* GeoTools 버전 업데이트 시 호환성 문제가 발생할 수 있습니다.
|
||||||
|
* 가능한 경우, JDBCDataStore.createSchema()를 통해 새로운 스키마를
|
||||||
|
* 생성하거나 기존 데이터를 새 스키마로 마이그레이션하는 것을 권장합니다.
|
||||||
|
*
|
||||||
|
* @param dataStore 재구성할 JDBC DataStore
|
||||||
|
* @param typeName 대상 FeatureType의 이름
|
||||||
|
* @return 재구성된 ContentFeatureSource
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static synchronized ContentFeatureSource refindJDBCFeatureSource(ContentDataStore dataStore, String typeName) throws IOException {
|
||||||
|
ContentFeatureSource cfs = dataStore.getFeatureSource(typeName);
|
||||||
|
SimpleFeatureType featureType = cfs.getSchema();
|
||||||
|
|
||||||
|
SimpleFeatureTypeBuilder tBuilder = new SimpleFeatureTypeBuilder();
|
||||||
|
tBuilder.init(featureType);
|
||||||
|
tBuilder.setName(featureType.getTypeName().toUpperCase()); // 대문자로 FeatureType 이름 설정
|
||||||
|
|
||||||
|
AttributeTypeBuilder aBuilder = new AttributeTypeBuilder();
|
||||||
|
for (AttributeDescriptor attr : featureType.getAttributeDescriptors()) {
|
||||||
|
tBuilder.remove(attr.getLocalName()); // 기존 속성 제거 (이름 변경을 위해)
|
||||||
|
|
||||||
|
aBuilder.init(attr); // 기존 속성으로 초기화
|
||||||
|
// 사용자 데이터 복사 (attr.getUserData()는 Map<Object, Object>를 반환)
|
||||||
|
for (Map.Entry<Object, Object> entry : attr.getUserData().entrySet()) {
|
||||||
|
aBuilder.addUserData(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
// 속성 이름을 대문자로 변경하여 추가
|
||||||
|
tBuilder.add(aBuilder.buildDescriptor(attr.getLocalName().toUpperCase()));
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleFeatureType nFeatureType = tBuilder.buildFeatureType();
|
||||||
|
nFeatureType.getUserData().putAll(featureType.getUserData()); // FeatureType의 사용자 데이터 복사
|
||||||
|
|
||||||
|
// --- JDBCDataStore의 내부 상태 직접 조작은 매우 위험하며, GeoTools 버전 업데이트 시 깨질 수 있습니다. ---
|
||||||
|
// JDBCState는 JDBCDataStore 내부에서 관리되는 상태 객체입니다.
|
||||||
|
// ContentEntry를 새로 생성하여 상태를 주입하는 방식은 GeoTools의 일반적인 사용 패턴이 아닙니다.
|
||||||
|
// 대신, JDBCDataStore가 스키마를 관리하는 방식을 따르는 것이 좋습니다.
|
||||||
|
|
||||||
|
// 여기서는 기존 로직의 의도를 최대한 살리려고 노력하지만,
|
||||||
|
// 이 부분은 GeoTools 11.3에서 안전하게 작동하지 않을 수 있습니다.
|
||||||
|
// 이상적으로는 JDBCDataStore.createSchema(nFeatureType)를 호출하여
|
||||||
|
// 새로운 스키마를 등록하는 것이 더 안전한 방법입니다.
|
||||||
|
|
||||||
|
// 기존 로직의 문제점: ContentDataStore.entries 필드는 protected이거나 private일 수 있어 직접 접근 불가.
|
||||||
|
// ContentEntry 및 ContentState의 내부 조작 역시 권장되지 않음.
|
||||||
|
// PrimaryKey 관련 로직도 JDBCDataStore의 createSchema 시점에 함께 정의되는 것이 일반적.
|
||||||
|
|
||||||
|
// 임시 해결책 (기존 로직의 의도 최대한 유지):
|
||||||
|
// ContentEntry를 다시 생성하는 대신, 기존 FeatureSource의 Entry를 가져와 상태를 업데이트하는 시도
|
||||||
|
// 이 또한 GeoTools 내부 구현에 의존하므로 불안정할 수 있습니다.
|
||||||
|
ContentEntry existingEntry = cfs.getEntry();
|
||||||
|
ContentState state = existingEntry.getState(Transaction.AUTO_COMMIT); // 기존 Entry의 상태 가져오기
|
||||||
|
|
||||||
|
if (state instanceof JDBCState) {
|
||||||
|
JDBCState jdbcState = (JDBCState) state;
|
||||||
|
jdbcState.setFeatureType(nFeatureType); // 새 FeatureType 설정
|
||||||
|
|
||||||
|
// PrimaryKey 로직: 기존의 PrimaryKey 정보를 가져와 새로운 FeatureType에 맞게 조정
|
||||||
|
// 이 부분은 JDBCDataStore의 JDBCState가 PrimaryKey를 어떻게 관리하는지에 따라 달라집니다.
|
||||||
|
// GeoTools의 jdbc 모듈 소스 코드를 직접 확인하는 것이 가장 정확합니다.
|
||||||
|
PrimaryKey oldPK = jdbcState.getPrimaryKey(); // 이전 PrimaryKey 가져오기
|
||||||
|
ArrayList<PrimaryKeyColumn> nColumns = new ArrayList<>(); // PrimaryKeyColumn 타입으로 명시
|
||||||
|
|
||||||
|
if (oldPK != null) {
|
||||||
|
for (PrimaryKeyColumn column : oldPK.getColumns()) {
|
||||||
|
String newColumnName = column.getName().toUpperCase(); // 컬럼 이름도 대문자로
|
||||||
|
|
||||||
|
if (column instanceof AutoGeneratedPrimaryKeyColumn) {
|
||||||
|
nColumns.add(new AutoGeneratedPrimaryKeyColumn(newColumnName, column.getType()));
|
||||||
|
} else if (column instanceof SequencedPrimaryKeyColumn) {
|
||||||
|
nColumns.add(new SequencedPrimaryKeyColumn(newColumnName, column.getType(), ((SequencedPrimaryKeyColumn) column).getSequenceName()));
|
||||||
|
} else if (column instanceof NonIncrementingPrimaryKeyColumn) {
|
||||||
|
nColumns.add(new NonIncrementingPrimaryKeyColumn(newColumnName, column.getType()));
|
||||||
|
}
|
||||||
|
// 다른 PrimaryKeyColumn 타입이 있다면 여기에 추가
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nColumns.isEmpty()) {
|
||||||
|
jdbcState.setPrimaryKey(new NullPrimaryKey(nFeatureType.getTypeName()));
|
||||||
|
} else {
|
||||||
|
jdbcState.setPrimaryKey(new PrimaryKey(nFeatureType.getTypeName(), nColumns));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// JDBCState가 아닌 경우 (예: 다른 DataStore 구현체)
|
||||||
|
// 혹은 기존의 ContentEntry가 JDBCState를 반환하지 않는 경우
|
||||||
|
// 이 부분은 JDBC DataStore에 특화된 로직입니다.
|
||||||
|
throw new IllegalArgumentException("Provided dataStore is not a JDBCDataStore or does not manage JDBCState correctly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// dataStore.entries.put()와 같은 직접적인 필드 접근은 제거했습니다.
|
||||||
|
// 대신, 스키마 변경이 ContentDataStore에 반영되도록 노력해야 합니다.
|
||||||
|
// ContentDataStore는 FeatureType 변경을 내부적으로 처리하는 메커니즘을 가질 수 있습니다.
|
||||||
|
// 이 코드가 제대로 작동하려면 DataStore의 refresh 또는 reload 메커니즘을 찾아야 합니다.
|
||||||
|
// 아니면 새로운 DataStore 인스턴스를 생성해야 합니다.
|
||||||
|
|
||||||
|
// 여기서는 변경된 스키마로 새로운 FeatureSource를 얻으려는 시도입니다.
|
||||||
|
// 하지만 기존 DataStore가 스키마 변경을 즉시 반영하지 않을 수 있습니다.
|
||||||
|
return (ContentFeatureSource) dataStore.getFeatureSource(nFeatureType.getName()); // 변경된 이름으로 FeatureSource 요청
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ShapefileDataStore의 FeatureType 스키마를 재구성합니다.
|
||||||
|
* JDBCDataStore와 마찬가지로 내부 필드 접근은 피하고,
|
||||||
|
* 스키마 변경을 ShapefileDataStore가 처리할 수 있도록 해야 합니다.
|
||||||
|
* Shapefile의 특성상, 스키마 변경은 파일 자체의 변경을 의미하며,
|
||||||
|
* 이는 DataStore 레벨에서 간단히 `setFeatureType`으로 처리하기 어렵습니다.
|
||||||
|
* 일반적으로 Shapefile의 스키마 변경은 새 Shapefile을 생성하는 방식으로 이루어집니다.
|
||||||
|
*
|
||||||
|
* @param dataStore 재구성할 ShapefileDataStore
|
||||||
|
* @return 재구성된 ShapefileDataStore
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static synchronized ShapefileDataStore refindShapefileDataStore(ShapefileDataStore dataStore) throws IOException {
|
||||||
|
// ShapefileDataStore는 ContentDataStore를 상속하지만, JDBC와는 다르게 스키마를 다룹니다.
|
||||||
|
// Shapefile은 파일 기반이므로, SimpleFeatureType 변경은 파일의 구조 변경을 의미합니다.
|
||||||
|
// DataStore의 내부 상태를 직접 변경하는 것은 Shapefile에서는 매우 위험하고 잘못된 접근입니다.
|
||||||
|
// 일반적으로 Shapefile의 스키마 변경은 새 Shapefile을 생성하고 데이터를 마이그레이션하는 방식으로 이루어집니다.
|
||||||
|
|
||||||
|
// 따라서 이 메서드는 GeoTools의 ShapefileDataStore의 동작 방식과 맞지 않습니다.
|
||||||
|
// 만약 FeatureType의 속성 이름만 대문자로 바꾸는 것이 목적이라면,
|
||||||
|
// FeatureCollection을 읽어서 새로운 FeatureCollection을 만들 때 속성 이름을 변경하거나,
|
||||||
|
// ShapefileDataStore를 다시 로드하는 방식으로 접근해야 합니다.
|
||||||
|
|
||||||
|
// 기존 로직의 의도를 최대한 살려 보지만, 실제 작동을 보장하기 어렵습니다.
|
||||||
|
SimpleFeatureSource cfs = dataStore.getFeatureSource(); // 기본 FeatureSource 가져오기
|
||||||
|
SimpleFeatureType featureType = cfs.getSchema();
|
||||||
|
|
||||||
|
SimpleFeatureTypeBuilder tBuilder = new SimpleFeatureTypeBuilder();
|
||||||
|
tBuilder.init(featureType);
|
||||||
|
tBuilder.setName(featureType.getTypeName().toUpperCase());
|
||||||
|
|
||||||
|
AttributeTypeBuilder aBuilder = new AttributeTypeBuilder();
|
||||||
|
for (AttributeDescriptor attr : featureType.getAttributeDescriptors()) {
|
||||||
|
tBuilder.remove(attr.getLocalName());
|
||||||
|
aBuilder.init(attr);
|
||||||
|
for (Map.Entry<Object, Object> entry : attr.getUserData().entrySet()) { // Map.Entry 타입 명시
|
||||||
|
aBuilder.addUserData(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
tBuilder.add(aBuilder.buildDescriptor(attr.getLocalName().toUpperCase()));
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleFeatureType nFeatureType = tBuilder.buildFeatureType();
|
||||||
|
nFeatureType.getUserData().putAll(featureType.getUserData());
|
||||||
|
|
||||||
|
// --- ShapefileDataStore의 내부 상태 직접 조작도 매우 위험합니다. ---
|
||||||
|
// ShapefileDataStore는 ContentDataStore를 상속하지만,
|
||||||
|
// 그 내부 ContentEntry/ContentState를 직접 조작하는 것은 지원되지 않습니다.
|
||||||
|
// Shapefile은 read-only로 열려있을 경우 스키마를 변경할 수 없습니다.
|
||||||
|
// write-access로 열었을 경우에도 setFeatureType으로 스키마를 변경하는 것은
|
||||||
|
// 파일 자체의 스키마를 바꾸는 것이므로 매우 복잡한 과정이 필요합니다.
|
||||||
|
|
||||||
|
// 이 부분은 GeoTools의 `ShapefileDataStore`가 설계된 방식과 맞지 않으므로,
|
||||||
|
// 이 코드가 제대로 작동하기 어렵습니다.
|
||||||
|
// Shapefile의 스키마 변경은 일반적으로 새 Shapefile을 생성하고 데이터를 다시 쓰는 방식으로 이루어집니다.
|
||||||
|
|
||||||
|
// 주석 처리: 이 부분은 GeoTools의 안정적인 API를 사용하지 않으므로, 작동하지 않을 수 있습니다.
|
||||||
|
/*
|
||||||
|
ContentEntry entry = new ContentEntry(dataStore, nFeatureType.getName());
|
||||||
|
ContentState state = entry.getState(Transaction.AUTO_COMMIT);
|
||||||
|
state.setFeatureType(nFeatureType);
|
||||||
|
dataStore.entries.put(entry.getName(), entry); // 이 줄은 컴파일 에러 발생 가능
|
||||||
|
dataStore.entries.put(cfs.getEntry().getName(), entry); // 이 줄은 컴파일 에러 발생 가능
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 대신, 여기서는 새로운 FeatureType을 바탕으로 DataStore를 다시 로드하거나
|
||||||
|
// 아예 새로운 Shapefile을 생성하는 것을 고려해야 합니다.
|
||||||
|
// 이 메서드는 기존 ShapefileDataStore의 스키마를 "재정의"하는 것이므로,
|
||||||
|
// 실제 Shapefile 파일의 스키마는 변경되지 않을 수 있습니다.
|
||||||
|
// ShapefileDataStore는 스키마를 변경하는 API를 직접적으로 제공하지 않습니다.
|
||||||
|
|
||||||
|
System.err.println("Warning: refindShapefileDataStore attempts to modify internal state of ShapefileDataStore, which is generally not supported for schema changes. Consider creating a new Shapefile with the desired schema.");
|
||||||
|
return dataStore; // 원본 DataStore를 반환 (실제 스키마 변경이 이루어지지 않을 수 있음)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SimpleFeatureSource의 CRS(좌표 참조 시스템)를 변경합니다.
|
||||||
|
* ContentFeatureSource인 경우에만 내부 상태를 업데이트합니다.
|
||||||
|
*
|
||||||
|
* @param featureSource CRS를 변경할 SimpleFeatureSource
|
||||||
|
* @param crs 새로운 CoordinateReferenceSystem
|
||||||
|
* @return CRS가 변경된 SimpleFeatureSource (원본 객체 또는 새로운 객체일 수 있음)
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static synchronized SimpleFeatureSource changeCRSFeatureSource(SimpleFeatureSource featureSource, CoordinateReferenceSystem crs) throws IOException {
|
||||||
|
if (featureSource instanceof ContentFeatureSource) {
|
||||||
|
SimpleFeatureType currentType = featureSource.getSchema();
|
||||||
|
// SimpleFeatureTypeBuilder.retype는 기존 FeatureType을 기반으로 새로운 CRS를 가진 FeatureType을 생성합니다.
|
||||||
|
SimpleFeatureType newType = SimpleFeatureTypeBuilder.retype(currentType, crs);
|
||||||
|
|
||||||
|
// ContentFeatureSource의 Entry를 통해 내부 상태를 업데이트합니다.
|
||||||
|
// 이 방식은 ContentDataStore의 구현에 따라 작동하거나 작동하지 않을 수 있습니다.
|
||||||
|
// 특히 Shapefile의 경우, 파일 자체의 CRS가 변경되지 않는 이상 이 방식은 메타데이터만 변경할 수 있습니다.
|
||||||
|
// 실제 데이터의 CRS 변환은 FeatureCollection을 통해 TransforingFeatureSource를 사용해야 합니다.
|
||||||
|
((ContentFeatureSource) featureSource).getEntry().getState(Transaction.AUTO_COMMIT).setFeatureType(newType);
|
||||||
|
} else {
|
||||||
|
// ContentFeatureSource가 아닌 다른 SimpleFeatureSource 구현체인 경우
|
||||||
|
// (예: PostGISDataStore의 SimpleFeatureSource 등)
|
||||||
|
// 해당 DataStore의 특정 메서드를 통해 CRS를 변경해야 할 수 있습니다.
|
||||||
|
// 또는 TransformingFeatureSource를 사용하여 CRS 변환을 수행하는 것이 더 일반적입니다.
|
||||||
|
System.err.println("Warning: changeCRSFeatureSource is designed for ContentFeatureSource. For other types, consider using a TransformingFeatureSource or DataStore specific methods.");
|
||||||
|
}
|
||||||
|
return featureSource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import org.geotools.data.FeatureSource;
|
||||||
|
import org.geotools.map.FeatureLayer;
|
||||||
|
import org.geotools.styling.Style;
|
||||||
|
|
||||||
|
public class ExFeatureLayer
|
||||||
|
extends FeatureLayer {
|
||||||
|
public ExFeatureLayer(FeatureSource featureSource, Style style) {
|
||||||
|
super(featureSource, style);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWrapTileTextLayer() {
|
||||||
|
return ((MapStyle)this.getStyle()).isWrapTileTextStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getWrapTileText() {
|
||||||
|
return ((MapStyle)this.getStyle()).getWrapTileText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.geotools.data.simple.SimpleFeatureSource;
|
import org.geotools.data.simple.SimpleFeatureSource;
|
||||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
|
@ -11,481 +8,335 @@ import org.geotools.referencing.CRS;
|
||||||
import org.geotools.styling.NamedLayer;
|
import org.geotools.styling.NamedLayer;
|
||||||
import org.geotools.styling.NamedStyle;
|
import org.geotools.styling.NamedStyle;
|
||||||
import org.geotools.styling.Style;
|
import org.geotools.styling.Style;
|
||||||
import org.geotools.styling.StyleFactory;
|
import org.geotools.styling.StyleVisitor;
|
||||||
import org.geotools.styling.StyledLayer;
|
import org.geotools.styling.StyledLayer;
|
||||||
import org.geotools.styling.StyledLayerDescriptor;
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
import org.geotools.styling.UserLayer;
|
import org.geotools.styling.UserLayer;
|
||||||
import org.opengis.feature.simple.SimpleFeatureType;
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
import org.opengis.filter.Filter;
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
public class FeatureLayer
|
||||||
import java.util.Collection;
|
extends Layer {
|
||||||
import java.util.Iterator;
|
private final String sourceName;
|
||||||
import java.util.List;
|
private ReferencedEnvelope bbox;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
private ConcurrentHashMap<String, Style> styleStore = new ConcurrentHashMap();
|
||||||
import org.geotools.data.simple.SimpleFeatureSource;
|
private Style currentStyle;
|
||||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
private ConcurrentHashMap<String, Style> renderStyles = new ConcurrentHashMap();
|
||||||
import org.geotools.referencing.CRS;
|
|
||||||
import org.geotools.styling.NamedLayer;
|
|
||||||
import org.geotools.styling.NamedStyle;
|
|
||||||
import org.geotools.styling.Style;
|
|
||||||
import org.geotools.styling.StyleFactory;
|
|
||||||
import org.geotools.styling.StyledLayer;
|
|
||||||
import org.geotools.styling.StyledLayerDescriptor;
|
|
||||||
import org.geotools.styling.UserLayer;
|
|
||||||
import org.opengis.feature.simple.SimpleFeatureType;
|
|
||||||
import org.opengis.filter.Filter;
|
|
||||||
|
|
||||||
public class FeatureLayer extends Layer
|
public FeatureLayer(AVList params) throws Exception {
|
||||||
{
|
super(params);
|
||||||
private final String sourceName;
|
StyledLayerDescriptor sld;
|
||||||
private ReferencedEnvelope bbox;
|
String sVal = params.getStringValue("conf.service.ref.source");
|
||||||
private ConcurrentHashMap<String, Style> styleStore = new ConcurrentHashMap();
|
this.sourceName = sVal = sVal.trim().toUpperCase();
|
||||||
private Style currentStyle;
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName());
|
||||||
private ConcurrentHashMap<String, Style> renderStyles = new ConcurrentHashMap();
|
this.bbox = featureSource.getBounds();
|
||||||
|
if (params.getValue("conf.service.sld") == null) {
|
||||||
public FeatureLayer(AVList params) throws Exception {
|
Style style = StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName());
|
||||||
super(params);
|
this.setCurrentStyle(style);
|
||||||
try
|
LogMngr.getInstance().logDebug("[LAYER]", "Set Style Use Default :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||||
{
|
} else {
|
||||||
String sVal = params.getStringValue("conf.service.ref.source");
|
sld = (StyledLayerDescriptor)params.getValue("conf.service.sld");
|
||||||
sVal = sVal.trim().toUpperCase();
|
this.initServiceStyle(sld, false);
|
||||||
this.sourceName = sVal;
|
LogMngr.getInstance().logDebug("[LAYER]", "Set Style From DB :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||||
|
|
||||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource(getLayerType(), getServerName(), getSourceName());
|
|
||||||
|
|
||||||
this.bbox = featureSource.getBounds();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params.getValue("conf.service.sld") == null) {
|
|
||||||
Style style = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
|
||||||
setCurrentStyle(style);
|
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[LAYER]",
|
|
||||||
"Set Style Use Default :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
|
||||||
} else {
|
|
||||||
StyledLayerDescriptor sld = (StyledLayerDescriptor)params.getValue("conf.service.sld");
|
|
||||||
initServiceStyle(sld, false);
|
|
||||||
LogMngr.getInstance().logDebug("[LAYER]",
|
|
||||||
"Set Style From DB :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
|
||||||
}
|
|
||||||
LogMngr.getInstance().logDebug("[LAYER]",
|
|
||||||
"Default Style Name Is [" + getCurrentStyle().getName() + "] :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
|
||||||
|
|
||||||
StyledLayerDescriptor sld = StyleMngr.readServiceSLD(getName());
|
|
||||||
if (sld != null) {
|
|
||||||
initServiceStyle(sld, false);
|
|
||||||
LogMngr.getInstance().logDebug("[LAYER]",
|
|
||||||
"Override Style From SLD FILE :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
|
||||||
LogMngr.getInstance().logDebug("[LAYER]",
|
|
||||||
"Default Style Name Is [" + getCurrentStyle().getName() + "] :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (isUseCache().booleanValue()) {
|
|
||||||
O2DSMngr.putMemoryFeatureSource(getLayerType(), getServerName(), getSourceName(), Filter.INCLUDE);
|
|
||||||
LogMngr.getInstance().logDebug("[LAYER]",
|
|
||||||
"Now use memery DataStore :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logDebug("[LAYER]",
|
|
||||||
"Fail to make memery DataStore. Now use common DataStore :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void reloadServiceStyle()
|
|
||||||
{
|
|
||||||
StyledLayerDescriptor sld = StyleMngr.readServiceSLD(getName());
|
|
||||||
if (sld != null) {
|
|
||||||
initServiceStyle(sld, false);
|
|
||||||
LogMngr.getInstance().logDebug("[LAYER]",
|
|
||||||
"Reload Style From SLD FILE :: [Map:" + getMapName() + "/Layer:" + getName() + "]");
|
|
||||||
LogMngr.getInstance().logDebug("[LAYER]",
|
|
||||||
"Default Style Name Is [" + getCurrentStyle().getName() + "] :: [Map:" + getMapName() + "/Layer:" + getName() + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void initServiceStyle(StyledLayerDescriptor sld, boolean write)
|
|
||||||
{
|
|
||||||
Style defaultStyle = null;
|
|
||||||
ConcurrentHashMap tempStore = new ConcurrentHashMap();
|
|
||||||
|
|
||||||
Iterator iterLayer = sld.layers().iterator();
|
|
||||||
Iterator iterStyle;
|
|
||||||
label233: for (; iterLayer.hasNext();
|
|
||||||
iterStyle.hasNext())
|
|
||||||
{
|
|
||||||
StyledLayer styledLayer = (StyledLayer)iterLayer.next();
|
|
||||||
|
|
||||||
if ((!ServerUtil.isNullString(styledLayer.getName())) &&
|
|
||||||
(!styledLayer.getName().equalsIgnoreCase(getName())))
|
|
||||||
{
|
|
||||||
break label233;
|
|
||||||
}
|
|
||||||
|
|
||||||
iterStyle = getStyleIterator(styledLayer);
|
|
||||||
continue;
|
|
||||||
Style style = (Style)iterStyle.next();
|
|
||||||
|
|
||||||
if (!(style instanceof NamedStyle))
|
|
||||||
{
|
|
||||||
if (ServerUtil.isNullString(style.getName()))
|
|
||||||
style.setName(getName());
|
|
||||||
else {
|
|
||||||
style.setName(style.getName().trim().toUpperCase());
|
|
||||||
}
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]", "Default Style Name Is [" + this.getCurrentStyle().getName() + "] :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||||
tempStore.put(style.getName(), style);
|
sld = StyleMngr.readServiceSLD((String)this.getName());
|
||||||
if ((defaultStyle != null) &&
|
if (sld != null) {
|
||||||
(defaultStyle.getName().equals(style.getName()))) {
|
this.initServiceStyle(sld, false);
|
||||||
defaultStyle = null;
|
LogMngr.getInstance().logDebug("[LAYER]", "Override Style From SLD FILE :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]", "Default Style Name Is [" + this.getCurrentStyle().getName() + "] :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
if (this.isUseCache().booleanValue()) {
|
||||||
|
O2DSMngr.putMemoryFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (Filter)Filter.INCLUDE);
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]", "Now use memery DataStore :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]", "Fail to make memery DataStore. Now use common DataStore :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + this.getName() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (style.isDefault())
|
public synchronized void reloadServiceStyle() {
|
||||||
{
|
StyledLayerDescriptor sld = StyleMngr.readServiceSLD((String)this.getName());
|
||||||
if (defaultStyle == null) {
|
if (sld != null) {
|
||||||
defaultStyle = style;
|
this.initServiceStyle(sld, false);
|
||||||
} else {
|
LogMngr.getInstance().logDebug("[LAYER]", "Reload Style From SLD FILE :: [Map:" + this.getMapName() + "/Layer:" + this.getName() + "]");
|
||||||
|
LogMngr.getInstance().logDebug("[LAYER]", "Default Style Name Is [" + this.getCurrentStyle().getName() + "] :: [Map:" + this.getMapName() + "/Layer:" + this.getName() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void initServiceStyle(StyledLayerDescriptor sld, boolean write) {
|
||||||
|
Style defaultStyle = null;
|
||||||
|
ConcurrentHashMap<String, Style> tempStore = new ConcurrentHashMap<String, Style>();
|
||||||
|
for (StyledLayer styledLayer : sld.layers()) {
|
||||||
|
if (!ServerUtil.isNullString((String)styledLayer.getName()) && !styledLayer.getName().equalsIgnoreCase(this.getName())) continue;
|
||||||
|
Iterator<Style> iterStyle = this.getStyleIterator(styledLayer);
|
||||||
|
while (iterStyle.hasNext()) {
|
||||||
|
Style style = iterStyle.next();
|
||||||
|
if (style instanceof NamedStyle) continue;
|
||||||
|
if (ServerUtil.isNullString((String)style.getName())) {
|
||||||
|
style.setName(this.getName());
|
||||||
|
} else {
|
||||||
|
style.setName(style.getName().trim().toUpperCase());
|
||||||
|
}
|
||||||
|
tempStore.put(style.getName(), style);
|
||||||
|
if (defaultStyle != null && defaultStyle.getName().equals(style.getName())) {
|
||||||
|
defaultStyle = null;
|
||||||
|
}
|
||||||
|
if (!style.isDefault()) continue;
|
||||||
|
if (defaultStyle == null) {
|
||||||
|
defaultStyle = style;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
defaultStyle.setDefault(false);
|
||||||
|
defaultStyle = style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (defaultStyle == null) {
|
||||||
|
if (this.getCurrentStyle() == null) {
|
||||||
|
if (tempStore.isEmpty()) {
|
||||||
|
defaultStyle = StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName());
|
||||||
|
} else {
|
||||||
|
defaultStyle = (Style)tempStore.get(this.getName());
|
||||||
|
if (defaultStyle == null) {
|
||||||
|
defaultStyle = (Style)tempStore.values().iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
defaultStyle = (Style)tempStore.get(this.getCurrentStyle().getName());
|
||||||
|
if (defaultStyle == null) {
|
||||||
|
defaultStyle = this.getCurrentStyle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setCurrentStyle(defaultStyle);
|
||||||
|
this.styleStore.putAll(tempStore);
|
||||||
|
if (write) {
|
||||||
|
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void initServiceStyle(StyledLayer styledLayer, boolean write) {
|
||||||
|
Style defaultStyle = null;
|
||||||
|
ConcurrentHashMap<String, Style> tempStore = new ConcurrentHashMap<String, Style>();
|
||||||
|
if (!ServerUtil.isNullString((String)styledLayer.getName()) && !styledLayer.getName().equalsIgnoreCase(this.getName())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Iterator<Style> iterStyle = this.getStyleIterator(styledLayer);
|
||||||
|
while (iterStyle.hasNext()) {
|
||||||
|
Style style = iterStyle.next();
|
||||||
|
if (style instanceof NamedStyle) continue;
|
||||||
|
if (ServerUtil.isNullString((String)style.getName())) {
|
||||||
|
style.setName(this.getName());
|
||||||
|
} else {
|
||||||
|
style.setName(style.getName().trim().toUpperCase());
|
||||||
|
}
|
||||||
|
tempStore.put(style.getName(), style);
|
||||||
|
if (defaultStyle != null && defaultStyle.getName().equals(style.getName())) {
|
||||||
|
defaultStyle = null;
|
||||||
|
}
|
||||||
|
if (!style.isDefault()) continue;
|
||||||
|
if (defaultStyle == null) {
|
||||||
|
defaultStyle = style;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
defaultStyle.setDefault(false);
|
defaultStyle.setDefault(false);
|
||||||
defaultStyle = style;
|
defaultStyle = style;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defaultStyle == null)
|
|
||||||
{
|
|
||||||
if (getCurrentStyle() == null)
|
|
||||||
{
|
|
||||||
if (tempStore.isEmpty()) {
|
|
||||||
defaultStyle = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
|
||||||
} else {
|
|
||||||
defaultStyle = (Style)tempStore.get(getName());
|
|
||||||
if (defaultStyle == null)
|
|
||||||
defaultStyle = (Style)tempStore.values().iterator().next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
defaultStyle = (Style)tempStore.get(getCurrentStyle().getName());
|
|
||||||
if (defaultStyle == null) {
|
if (defaultStyle == null) {
|
||||||
defaultStyle = getCurrentStyle();
|
if (this.getCurrentStyle() == null) {
|
||||||
|
if (tempStore.isEmpty()) {
|
||||||
|
defaultStyle = StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName());
|
||||||
|
} else {
|
||||||
|
defaultStyle = (Style)tempStore.get(this.getName());
|
||||||
|
if (defaultStyle == null) {
|
||||||
|
defaultStyle = (Style)tempStore.values().iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
defaultStyle = (Style)tempStore.get(this.getCurrentStyle().getName());
|
||||||
|
if (defaultStyle == null) {
|
||||||
|
defaultStyle = this.getCurrentStyle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setCurrentStyle(defaultStyle);
|
||||||
|
this.styleStore.putAll(tempStore);
|
||||||
|
if (write) {
|
||||||
|
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentStyle(defaultStyle);
|
public synchronized void initServiceStyle(Style style, boolean write) {
|
||||||
|
if (style == null || style instanceof NamedStyle) {
|
||||||
this.styleStore.putAll(tempStore);
|
return;
|
||||||
|
|
||||||
if (write)
|
|
||||||
StyleMngr.writeServiceSLD110(getStyleSLD());
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void initServiceStyle(StyledLayer styledLayer, boolean write)
|
|
||||||
{
|
|
||||||
Style defaultStyle = null;
|
|
||||||
ConcurrentHashMap tempStore = new ConcurrentHashMap();
|
|
||||||
|
|
||||||
if ((!ServerUtil.isNullString(styledLayer.getName())) &&
|
|
||||||
(!styledLayer.getName().equalsIgnoreCase(getName()))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator iterStyle = getStyleIterator(styledLayer);
|
|
||||||
while (iterStyle.hasNext()) {
|
|
||||||
Style style = (Style)iterStyle.next();
|
|
||||||
|
|
||||||
if (!(style instanceof NamedStyle))
|
|
||||||
{
|
|
||||||
if (ServerUtil.isNullString(style.getName()))
|
|
||||||
style.setName(getName());
|
|
||||||
else {
|
|
||||||
style.setName(style.getName().trim().toUpperCase());
|
|
||||||
}
|
}
|
||||||
|
if (ServerUtil.isNullString((String)style.getName())) {
|
||||||
tempStore.put(style.getName(), style);
|
style.setName(this.getName());
|
||||||
|
|
||||||
if ((defaultStyle != null) &&
|
|
||||||
(defaultStyle.getName().equals(style.getName()))) {
|
|
||||||
defaultStyle = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (style.isDefault())
|
|
||||||
{
|
|
||||||
if (defaultStyle == null) {
|
|
||||||
defaultStyle = style;
|
|
||||||
} else {
|
|
||||||
defaultStyle.setDefault(false);
|
|
||||||
defaultStyle = style;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defaultStyle == null)
|
|
||||||
{
|
|
||||||
if (getCurrentStyle() == null)
|
|
||||||
{
|
|
||||||
if (tempStore.isEmpty()) {
|
|
||||||
defaultStyle = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
|
||||||
} else {
|
} else {
|
||||||
defaultStyle = (Style)tempStore.get(getName());
|
style.setName(style.getName().trim().toUpperCase());
|
||||||
if (defaultStyle == null)
|
|
||||||
defaultStyle = (Style)tempStore.values().iterator().next();
|
|
||||||
}
|
}
|
||||||
}
|
this.styleStore.put(style.getName(), style);
|
||||||
else
|
if (style.isDefault() || style.getName().equalsIgnoreCase(this.getCurrentStyle().getName())) {
|
||||||
{
|
this.setCurrentStyle(style);
|
||||||
defaultStyle = (Style)tempStore.get(getCurrentStyle().getName());
|
|
||||||
if (defaultStyle == null) {
|
|
||||||
defaultStyle = getCurrentStyle();
|
|
||||||
}
|
}
|
||||||
}
|
if (write) {
|
||||||
}
|
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||||
|
|
||||||
setCurrentStyle(defaultStyle);
|
|
||||||
|
|
||||||
this.styleStore.putAll(tempStore);
|
|
||||||
|
|
||||||
if (write)
|
|
||||||
StyleMngr.writeServiceSLD110(getStyleSLD());
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void initServiceStyle(Style style, boolean write)
|
|
||||||
{
|
|
||||||
if ((style == null) || ((style instanceof NamedStyle))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ServerUtil.isNullString(style.getName()))
|
|
||||||
style.setName(getName());
|
|
||||||
else {
|
|
||||||
style.setName(style.getName().trim().toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.styleStore.put(style.getName(), style);
|
|
||||||
|
|
||||||
if ((style.isDefault()) || (style.getName().equalsIgnoreCase(getCurrentStyle().getName()))) {
|
|
||||||
setCurrentStyle(style);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (write)
|
|
||||||
StyleMngr.writeServiceSLD110(getStyleSLD());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Iterator<Style> getStyleIterator(StyledLayer layer)
|
|
||||||
{
|
|
||||||
if ((layer instanceof NamedLayer)) {
|
|
||||||
return ((NamedLayer)layer).styles().iterator();
|
|
||||||
}
|
|
||||||
return ((UserLayer)layer).userStyles().iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReferencedEnvelope getBBox()
|
|
||||||
{
|
|
||||||
return this.bbox;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getServerName()
|
|
||||||
{
|
|
||||||
return super.getServerName().toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSourceName()
|
|
||||||
{
|
|
||||||
return this.sourceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateCRS()
|
|
||||||
{
|
|
||||||
super.updateCRS();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource(getLayerType(), getServerName(), getSourceName());
|
|
||||||
if (!CRS.equalsIgnoreMetadata(getCRS(), ((SimpleFeatureType)featureSource.getSchema()).getCoordinateReferenceSystem())) {
|
|
||||||
featureSource = O2DSMngr.changeCRSFeatureSource(getLayerType(), getServerName(), getSourceName(), getCRS());
|
|
||||||
LogMngr.getInstance().logInfo("[LAYER]", "Success to update CRS for FeatureSouce [" + getSourceName() + "]");
|
|
||||||
|
|
||||||
updateBBox();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[LAYER]",
|
|
||||||
"Fail to update CRS for FeatureSouce [" + getSourceName() + "] :: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateBBox()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource(getLayerType(), getServerName(), getSourceName());
|
|
||||||
this.bbox = featureSource.getBounds();
|
|
||||||
LogMngr.getInstance().logInfo("[LAYER]", "Success to update BBOX for Layer [" + getName() + "]");
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[LAYER]", "Fail to update BBOX for Layer [" + getName() + "] :: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Style getRenderStyle(String styleName)
|
|
||||||
{
|
|
||||||
if (ServerUtil.isNullString(styleName)) {
|
|
||||||
styleName = "DEFAULT";
|
|
||||||
}
|
|
||||||
styleName = styleName.trim().toUpperCase();
|
|
||||||
|
|
||||||
if (this.renderStyles.containsKey(styleName)) {
|
|
||||||
return (Style)this.renderStyles.get(styleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
Style style = getStyle(styleName);
|
|
||||||
if (style == null) {
|
|
||||||
style = getCurrentStyle();
|
|
||||||
}
|
|
||||||
|
|
||||||
RefineRenderStyleVisitor sVisitor = new RefineRenderStyleVisitor();
|
|
||||||
style.accept(sVisitor);
|
|
||||||
style = (Style)sVisitor.getCopy();
|
|
||||||
|
|
||||||
this.renderStyles.put(styleName, style);
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Style getStyle(String styleName)
|
|
||||||
{
|
|
||||||
if (!ServerUtil.isNullString(styleName)) {
|
|
||||||
return (Style)this.styleStore.get(styleName.trim().toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isContainStyle(String styleName)
|
|
||||||
{
|
|
||||||
if ((!ServerUtil.isNullString(styleName)) &&
|
|
||||||
(this.styleStore.containsKey(styleName.trim().toUpperCase()))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StyledLayerDescriptor getStyleSLD(String[] styleNames)
|
|
||||||
{
|
|
||||||
if ((styleNames == null) || (styleNames.length == 0)) {
|
|
||||||
return getStyleSLD();
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList styles = new ArrayList();
|
|
||||||
for (String styleName : styleNames)
|
|
||||||
{
|
|
||||||
if (!ServerUtil.isNullString(styleName))
|
|
||||||
{
|
|
||||||
styleName = styleName.trim().toUpperCase();
|
|
||||||
|
|
||||||
if (this.styleStore.containsKey(styleName)) {
|
|
||||||
styles.add((Style)this.styleStore.get(styleName));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
|
||||||
layer.setName(getName());
|
|
||||||
layer.styles().addAll(styles);
|
|
||||||
|
|
||||||
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
|
||||||
sld.addStyledLayer(layer);
|
|
||||||
sld.setName(getName());
|
|
||||||
|
|
||||||
return sld;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StyledLayerDescriptor getStyleSLD()
|
|
||||||
{
|
|
||||||
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
|
||||||
layer.setName(getName());
|
|
||||||
layer.styles().addAll(this.styleStore.values());
|
|
||||||
|
|
||||||
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
|
||||||
sld.addStyledLayer(layer);
|
|
||||||
sld.setName(getName());
|
|
||||||
|
|
||||||
return sld;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Style getCurrentStyle()
|
|
||||||
{
|
|
||||||
return this.currentStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Style setCurrentStyle(Style style)
|
|
||||||
{
|
|
||||||
this.renderStyles.remove(style.getName().trim().toUpperCase());
|
|
||||||
|
|
||||||
if (this.currentStyle != null) {
|
|
||||||
this.currentStyle.setDefault(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentStyle = style;
|
private Iterator<Style> getStyleIterator(StyledLayer layer) {
|
||||||
this.currentStyle.setDefault(true);
|
if (layer instanceof NamedLayer) {
|
||||||
|
return ((NamedLayer)layer).styles().iterator();
|
||||||
return this.currentStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearStyle(String styleName, boolean write)
|
|
||||||
{
|
|
||||||
if (ServerUtil.isNullString(styleName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
styleName = styleName.trim().toUpperCase();
|
|
||||||
|
|
||||||
if (this.styleStore.remove(styleName) == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getCurrentStyle().getName().equalsIgnoreCase(styleName))
|
|
||||||
{
|
|
||||||
Style style = getStyle(getName());
|
|
||||||
if (style == null)
|
|
||||||
{
|
|
||||||
if (this.styleStore.isEmpty())
|
|
||||||
style = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
|
||||||
else {
|
|
||||||
style = (Style)this.styleStore.values().iterator().next();
|
|
||||||
}
|
}
|
||||||
|
return ((UserLayer)layer).userStyles().iterator();
|
||||||
}
|
|
||||||
|
|
||||||
setCurrentStyle(style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write)
|
public ReferencedEnvelope getBBox() {
|
||||||
StyleMngr.writeServiceSLD110(getStyleSLD());
|
return this.bbox;
|
||||||
}
|
|
||||||
|
|
||||||
public void clearAllStyle(boolean write)
|
|
||||||
{
|
|
||||||
if (this.styleStore.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.styleStore.clear();
|
public String getServerName() {
|
||||||
this.renderStyles.clear();
|
return super.getServerName().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
setCurrentStyle(StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName()));
|
public String getSourceName() {
|
||||||
|
return this.sourceName;
|
||||||
|
}
|
||||||
|
|
||||||
if (write)
|
public void updateCRS() {
|
||||||
StyleMngr.writeServiceSLD110(getStyleSLD());
|
super.updateCRS();
|
||||||
}
|
try {
|
||||||
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName());
|
||||||
|
if (!CRS.equalsIgnoreMetadata((Object)this.getCRS(), (Object)((SimpleFeatureType)featureSource.getSchema()).getCoordinateReferenceSystem())) {
|
||||||
|
featureSource = O2DSMngr.changeCRSFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (CoordinateReferenceSystem)this.getCRS());
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Success to update CRS for FeatureSouce [" + this.getSourceName() + "]");
|
||||||
|
this.updateBBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Fail to update CRS for FeatureSouce [" + this.getSourceName() + "] :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateBBox() {
|
||||||
|
try {
|
||||||
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName());
|
||||||
|
this.bbox = featureSource.getBounds();
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Success to update BBOX for Layer [" + this.getName() + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Fail to update BBOX for Layer [" + this.getName() + "] :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Style getRenderStyle(String styleName) {
|
||||||
|
if (ServerUtil.isNullString((String)styleName)) {
|
||||||
|
styleName = "DEFAULT";
|
||||||
|
}
|
||||||
|
if (this.renderStyles.containsKey(styleName = styleName.trim().toUpperCase())) {
|
||||||
|
return this.renderStyles.get(styleName);
|
||||||
|
}
|
||||||
|
Style style = this.getStyle(styleName);
|
||||||
|
if (style == null) {
|
||||||
|
style = this.getCurrentStyle();
|
||||||
|
}
|
||||||
|
RefineRenderStyleVisitor sVisitor = new RefineRenderStyleVisitor();
|
||||||
|
style.accept((StyleVisitor)sVisitor);
|
||||||
|
style = (Style)sVisitor.getCopy();
|
||||||
|
this.renderStyles.put(styleName, style);
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Style getStyle(String styleName) {
|
||||||
|
if (!ServerUtil.isNullString((String)styleName)) {
|
||||||
|
return this.styleStore.get(styleName.trim().toUpperCase());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isContainStyle(String styleName) {
|
||||||
|
return !ServerUtil.isNullString((String)styleName) && this.styleStore.containsKey(styleName.trim().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public StyledLayerDescriptor getStyleSLD(String[] styleNames) {
|
||||||
|
if (styleNames == null || styleNames.length == 0) {
|
||||||
|
return this.getStyleSLD();
|
||||||
|
}
|
||||||
|
ArrayList<Style> styles = new ArrayList<Style>();
|
||||||
|
String[] stringArray = styleNames;
|
||||||
|
int n = styleNames.length;
|
||||||
|
int n2 = 0;
|
||||||
|
while (n2 < n) {
|
||||||
|
String styleName = stringArray[n2];
|
||||||
|
if (!ServerUtil.isNullString((String)styleName) && this.styleStore.containsKey(styleName = styleName.trim().toUpperCase())) {
|
||||||
|
styles.add(this.styleStore.get(styleName));
|
||||||
|
}
|
||||||
|
++n2;
|
||||||
|
}
|
||||||
|
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
||||||
|
layer.setName(this.getName());
|
||||||
|
layer.styles().addAll(styles);
|
||||||
|
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
||||||
|
sld.addStyledLayer((StyledLayer)layer);
|
||||||
|
sld.setName(this.getName());
|
||||||
|
return sld;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StyledLayerDescriptor getStyleSLD() {
|
||||||
|
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
||||||
|
layer.setName(this.getName());
|
||||||
|
layer.styles().addAll(this.styleStore.values());
|
||||||
|
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
||||||
|
sld.addStyledLayer((StyledLayer)layer);
|
||||||
|
sld.setName(this.getName());
|
||||||
|
return sld;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Style getCurrentStyle() {
|
||||||
|
return this.currentStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Style setCurrentStyle(Style style) {
|
||||||
|
this.renderStyles.remove(style.getName().trim().toUpperCase());
|
||||||
|
if (this.currentStyle != null) {
|
||||||
|
this.currentStyle.setDefault(false);
|
||||||
|
}
|
||||||
|
this.currentStyle = style;
|
||||||
|
this.currentStyle.setDefault(true);
|
||||||
|
return this.currentStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearStyle(String styleName, boolean write) {
|
||||||
|
if (ServerUtil.isNullString((String)styleName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.styleStore.remove(styleName = styleName.trim().toUpperCase()) == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.getCurrentStyle().getName().equalsIgnoreCase(styleName)) {
|
||||||
|
Style style = this.getStyle(this.getName());
|
||||||
|
if (style == null) {
|
||||||
|
style = this.styleStore.isEmpty() ? StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName()) : this.styleStore.values().iterator().next();
|
||||||
|
}
|
||||||
|
this.setCurrentStyle(style);
|
||||||
|
}
|
||||||
|
if (write) {
|
||||||
|
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearAllStyle(boolean write) {
|
||||||
|
if (this.styleStore.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.styleStore.clear();
|
||||||
|
this.renderStyles.clear();
|
||||||
|
this.setCurrentStyle(StyleMngr.getDefaultUserStyle((LayerFactory.LayerType)this.getLayerType(), (String)this.getServerName(), (String)this.getSourceName(), (String)this.getName()));
|
||||||
|
if (write) {
|
||||||
|
StyleMngr.writeServiceSLD110((StyledLayerDescriptor)this.getStyleSLD());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,61 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class FieldInfo {
|
||||||
|
private FieldSQL.FieldType type;
|
||||||
|
private String name;
|
||||||
|
private Integer precision;
|
||||||
|
private Integer scale;
|
||||||
|
private boolean primaryKey;
|
||||||
|
private boolean notNull;
|
||||||
|
|
||||||
|
public FieldInfo(String name, FieldSQL.FieldType type, Integer precision, Integer scale, boolean primaryKey, boolean notNull) {
|
||||||
|
this.type = type;
|
||||||
|
this.name = name.toUpperCase();
|
||||||
|
this.precision = precision;
|
||||||
|
this.scale = scale;
|
||||||
|
this.primaryKey = primaryKey;
|
||||||
|
this.notNull = notNull;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldInfo(String name, FieldSQL.FieldType type, Integer precision, boolean primaryKey, boolean notNull) {
|
||||||
|
this.type = type;
|
||||||
|
this.name = name.toUpperCase();
|
||||||
|
this.precision = precision;
|
||||||
|
this.scale = null;
|
||||||
|
this.primaryKey = primaryKey;
|
||||||
|
this.notNull = notNull;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldInfo(String name, FieldSQL.FieldType type, boolean primaryKey, boolean notNull) {
|
||||||
|
this.type = type;
|
||||||
|
this.name = name.toUpperCase();
|
||||||
|
this.precision = null;
|
||||||
|
this.scale = null;
|
||||||
|
this.primaryKey = primaryKey;
|
||||||
|
this.notNull = notNull;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNotNull() {
|
||||||
|
return this.notNull;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrimaryKey() {
|
||||||
|
return this.primaryKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldSQL.FieldType getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getScale() {
|
||||||
|
return this.scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPrecision() {
|
||||||
|
return this.precision;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class FieldSQL
|
||||||
|
{
|
||||||
|
private final O2DSFactory.DBMSType dbType;
|
||||||
|
private final Map<FieldType, String> dbFields;
|
||||||
|
private final boolean isUnsignedScale;
|
||||||
|
|
||||||
|
public FieldSQL(O2DSFactory.DBMSType dbmsType, HashMap<FieldType, String> fields, boolean unsignedScale)
|
||||||
|
{
|
||||||
|
this.dbType = dbmsType;
|
||||||
|
this.dbFields = Collections.unmodifiableMap(fields);
|
||||||
|
this.isUnsignedScale = unsignedScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public O2DSFactory.DBMSType getDBType() {
|
||||||
|
return this.dbType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGeomFieldType(Class geom, String srid) throws Exception
|
||||||
|
{
|
||||||
|
String sql = (String)this.dbFields.get(FieldType.GEOMETRY);
|
||||||
|
if (sql == null) {
|
||||||
|
sql = FieldType.GEOMETRY.fieldSql;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFieldType(Class clazz, int precision, int scale) throws Exception
|
||||||
|
{
|
||||||
|
FieldType type = FieldType.UNKNOWN;
|
||||||
|
for (FieldType value : FieldType.values()) {
|
||||||
|
for (Class cls : value.fieldTypes) {
|
||||||
|
if (cls.isAssignableFrom(clazz)) {
|
||||||
|
return getFieldType(value, precision, scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return getFieldType(type, precision, scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFieldType(FieldType fType, int precision, int scale)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String sql = (String)this.dbFields.get(fType);
|
||||||
|
if (sql == null) {
|
||||||
|
sql = fType.fieldSql;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((fType == FieldType.GEOMETRY) ||
|
||||||
|
(fType == FieldType.BOOLEAN) ||
|
||||||
|
(fType == FieldType.DATE) ||
|
||||||
|
(fType == FieldType.BLOB) ||
|
||||||
|
(fType == FieldType.UNKNOWN)) {
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (precision < 0) {
|
||||||
|
LogMngr.getInstance().logError("[DB]",
|
||||||
|
"getFieldType :: precision is < 0 for " + fType);
|
||||||
|
throw new SQLException("getFieldType :: precision is < 0 for " + fType);
|
||||||
|
}
|
||||||
|
if ((precision == 0) && (scale == 0)) {
|
||||||
|
LogMngr.getInstance().logError("[DB]",
|
||||||
|
"getFieldType :: precision and scale is 0 for " + fType);
|
||||||
|
throw new SQLException("getFieldType :: precision and scale is 0 for " + fType);
|
||||||
|
}
|
||||||
|
if (scale < 0)
|
||||||
|
{
|
||||||
|
if (this.isUnsignedScale) {
|
||||||
|
LogMngr.getInstance().logError("[DB]",
|
||||||
|
"getFieldType :: scale is must use unsigned value for " + fType);
|
||||||
|
throw new SQLException("getFieldType :: scale is must use unsigned value for " + fType);
|
||||||
|
}
|
||||||
|
if (precision + scale <= 0) {
|
||||||
|
LogMngr.getInstance().logError("[DB]",
|
||||||
|
"getFieldType :: scale is over real length (" + precision + ") for " + fType);
|
||||||
|
throw new SQLException("getFieldType :: scale is over real length (" + precision + ") for " + fType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (precision - scale < 0) {
|
||||||
|
LogMngr.getInstance().logError("[DB]",
|
||||||
|
"getFieldType :: scale is over real length (" + precision + ") for " + fType);
|
||||||
|
throw new SQLException("getFieldType :: scale is over real length (" + precision + ") for " + fType);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer(sql);
|
||||||
|
if (fType == FieldType.CHARACTER) {
|
||||||
|
if (precision == 0) {
|
||||||
|
LogMngr.getInstance().logError("[DB]",
|
||||||
|
"getFieldType :: precision is 0 for " + fType);
|
||||||
|
throw new SQLException("getFieldType :: precision is 0 for " + fType);
|
||||||
|
}
|
||||||
|
sb.append("(").append(precision).append(")");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sb.append("(");
|
||||||
|
sb.append(precision).append(",").append(scale);
|
||||||
|
sb.append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum FieldType
|
||||||
|
{
|
||||||
|
GEOMETRY("GEOMETRY", new Class[] { com.vividsolutions.jts.geom.Geometry.class, org.opengis.geometry.Geometry.class }),
|
||||||
|
CHARACTER("VARCHAR", new Class[] { String.class }),
|
||||||
|
NUMERIC("NUMBER", new Class[] { Short.class, Integer.class, Long.class, Float.class, Double.class }),
|
||||||
|
BOOLEAN("CHAR(1)", new Class[] { Boolean.class }),
|
||||||
|
DATE("DATE", new Class[] { Date.class }),
|
||||||
|
BLOB("BLOB", new Class[] { java.lang.Byte.class }),
|
||||||
|
UNKNOWN("VARCHAR", new Class[] { Object.class });
|
||||||
|
|
||||||
|
private final Class[] fieldTypes;
|
||||||
|
private final String fieldSql;
|
||||||
|
|
||||||
|
private FieldType(String sql, Class[] types) { this.fieldSql = sql;
|
||||||
|
this.fieldTypes = types;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package geoinfo.map.myMap;
|
|
||||||
|
|
||||||
public class GWVectorDriver {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class GWaveLayerInfo {
|
||||||
|
private boolean activate = false;
|
||||||
|
private String layerName;
|
||||||
|
private String layerSource;
|
||||||
|
private String desc;
|
||||||
|
|
||||||
|
public boolean isActivate() {
|
||||||
|
return this.activate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerName() {
|
||||||
|
return this.layerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerSource() {
|
||||||
|
return this.layerSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return this.desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerName(String name) {
|
||||||
|
if (ServerUtil.isNullString((String)name)) {
|
||||||
|
this.layerName = null;
|
||||||
|
}
|
||||||
|
this.layerName = name.trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerSource(String source) {
|
||||||
|
if (ServerUtil.isNullString((String)source)) {
|
||||||
|
this.layerSource = null;
|
||||||
|
}
|
||||||
|
this.layerSource = source.trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivate(String actiStr) {
|
||||||
|
this.activate = ServerUtil.getBooleanValue((String)actiStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String desc) {
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAvailable() {
|
||||||
|
if (!this.activate) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.activate] is False");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)this.layerName)) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.name] is Empty");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)this.layerSource)) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.source] is Empty");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,9 @@ import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
import com.geowave.drvier.GWDriver;
|
||||||
|
import com.geowave.vectordrvier.GWVectorDriver;
|
||||||
|
|
||||||
public class GWaveStoreMngr
|
public class GWaveStoreMngr
|
||||||
{
|
{
|
||||||
private static ConcurrentHashMap<String, GeoWaveDataStore> dataStores = new ConcurrentHashMap();
|
private static ConcurrentHashMap<String, GeoWaveDataStore> dataStores = new ConcurrentHashMap();
|
||||||
|
|
@ -47,7 +50,7 @@ public class GWaveStoreMngr
|
||||||
}
|
}
|
||||||
dataStores.put(dataStore.getStoreName(), dataStore);
|
dataStores.put(dataStore.getStoreName(), dataStore);
|
||||||
|
|
||||||
ArrayList layerInfoList = parseGWaveLayerInfo(confFile);
|
ArrayList<GWaveLayerInfo> layerInfoList = parseGWaveLayerInfo(confFile);
|
||||||
if ((layerInfoList == null) || (layerInfoList.isEmpty())) {
|
if ((layerInfoList == null) || (layerInfoList.isEmpty())) {
|
||||||
LogMngr.getInstance().logError("[GWAVE]",
|
LogMngr.getInstance().logError("[GWAVE]",
|
||||||
"[" + confFile.getName() + "] Fail to create GeoWaveLayer :: GeoWaveLayer size is ZERO[0] from this configuration");
|
"[" + confFile.getName() + "] Fail to create GeoWaveLayer :: GeoWaveLayer size is ZERO[0] from this configuration");
|
||||||
|
|
@ -173,7 +176,7 @@ public class GWaveStoreMngr
|
||||||
bReader = new BufferedReader(new FileReader(conf));
|
bReader = new BufferedReader(new FileReader(conf));
|
||||||
String line;
|
String line;
|
||||||
while ((line = bReader.readLine()) != null) {
|
while ((line = bReader.readLine()) != null) {
|
||||||
String line = line.trim();
|
line = line.trim();
|
||||||
if ((!line.startsWith("#")) && (!ServerUtil.isNullString(line)))
|
if ((!line.startsWith("#")) && (!ServerUtil.isNullString(line)))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -252,7 +255,7 @@ public class GWaveStoreMngr
|
||||||
bReader = new BufferedReader(new FileReader(conf));
|
bReader = new BufferedReader(new FileReader(conf));
|
||||||
String line;
|
String line;
|
||||||
while ((line = bReader.readLine()) != null) {
|
while ((line = bReader.readLine()) != null) {
|
||||||
String line = line.trim();
|
line = line.trim();
|
||||||
if ((!line.startsWith("#")) && (!ServerUtil.isNullString(line)))
|
if ((!line.startsWith("#")) && (!ServerUtil.isNullString(line)))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -291,7 +294,7 @@ public class GWaveStoreMngr
|
||||||
bReader.close();
|
bReader.close();
|
||||||
bReader = null;
|
bReader = null;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e2) {
|
||||||
bReader = null;
|
bReader = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,155 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
public class GeoWaveDataStore {
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.Transaction;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||||
|
import org.geotools.data.store.ContentDataStore;
|
||||||
|
import org.geotools.data.store.ContentEntry;
|
||||||
|
import org.geotools.data.store.ContentFeatureCollection;
|
||||||
|
import org.geotools.data.store.ContentFeatureSource;
|
||||||
|
import org.geotools.factory.Hints;
|
||||||
|
import org.geotools.feature.NameImpl;
|
||||||
|
import org.geotools.filter.FilterCapabilities;
|
||||||
|
import org.opengis.feature.Feature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.Name;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.filter.Id;
|
||||||
|
import org.opengis.filter.identity.GmlObjectId;
|
||||||
|
import org.opengis.filter.spatial.BBOX;
|
||||||
|
|
||||||
}
|
import com.geowave.vectordrvier.GWVectorDriver;
|
||||||
|
|
||||||
|
public class GeoWaveDataStore
|
||||||
|
extends ContentDataStore {
|
||||||
|
private final FilterCapabilities capabilities;
|
||||||
|
private final String serverName;
|
||||||
|
private final String serverIP;
|
||||||
|
private final int serverPort;
|
||||||
|
private final int readRowCount;
|
||||||
|
private final int readBufferSize;
|
||||||
|
|
||||||
|
public GeoWaveDataStore(String name, String ip, int port) throws Exception {
|
||||||
|
this(name, ip, port, 1000, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoWaveDataStore(String name, String ip, int port, Integer rowCount, Integer bufferSize) throws Exception {
|
||||||
|
this.serverName = name.trim().toUpperCase();
|
||||||
|
this.serverIP = ip.trim().toUpperCase();
|
||||||
|
this.serverPort = port;
|
||||||
|
if (rowCount == null) {
|
||||||
|
rowCount = 1000;
|
||||||
|
}
|
||||||
|
if (bufferSize == null) {
|
||||||
|
bufferSize = 10;
|
||||||
|
}
|
||||||
|
this.readRowCount = rowCount;
|
||||||
|
this.readBufferSize = bufferSize * 1024 * 1024;
|
||||||
|
this.capabilities = new FilterCapabilities();
|
||||||
|
this.capabilities.addAll(FilterCapabilities.LOGICAL_OPENGIS);
|
||||||
|
this.capabilities.addType(BBOX.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStoreName() {
|
||||||
|
return this.serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<Name> createTypeNames() throws IOException {
|
||||||
|
ArrayList<Name> typeNames = new ArrayList<Name>();
|
||||||
|
GWVectorDriver driver = this.getGWVDriver();
|
||||||
|
List<String> list = driver.getFeatureList();
|
||||||
|
for (String layerName : list) {
|
||||||
|
typeNames.add((Name)new NameImpl(this.namespaceURI, layerName.toUpperCase()));
|
||||||
|
}
|
||||||
|
driver.close();
|
||||||
|
return typeNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ContentFeatureSource createFeatureSource(ContentEntry entry) throws IOException {
|
||||||
|
SimpleFeatureType schema = entry.getState(Transaction.AUTO_COMMIT).getFeatureType();
|
||||||
|
if (schema == null) {
|
||||||
|
schema = new GeoWaveFeatureSource(entry).buildFeatureType();
|
||||||
|
entry.getState(Transaction.AUTO_COMMIT).setFeatureType(schema);
|
||||||
|
}
|
||||||
|
return new GeoWaveFeatureSource(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoWaveFeatureSource getFeatureSource(String typeName) throws IOException {
|
||||||
|
return (GeoWaveFeatureSource)super.getFeatureSource(typeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> getMapping(String clazz) {
|
||||||
|
if (clazz.equalsIgnoreCase("binary")) {
|
||||||
|
return byte[].class;
|
||||||
|
}
|
||||||
|
if (clazz.equalsIgnoreCase("byte")) {
|
||||||
|
return Byte.TYPE;
|
||||||
|
}
|
||||||
|
if (clazz.equalsIgnoreCase("double")) {
|
||||||
|
return Double.class;
|
||||||
|
}
|
||||||
|
if (clazz.equalsIgnoreCase("float")) {
|
||||||
|
return Float.class;
|
||||||
|
}
|
||||||
|
if (clazz.equalsIgnoreCase("int")) {
|
||||||
|
return Integer.class;
|
||||||
|
}
|
||||||
|
if (clazz.equalsIgnoreCase("bigint")) {
|
||||||
|
return Long.class;
|
||||||
|
}
|
||||||
|
if (clazz.equalsIgnoreCase("short")) {
|
||||||
|
return Short.class;
|
||||||
|
}
|
||||||
|
if (clazz.equalsIgnoreCase("string")) {
|
||||||
|
return String.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GWVectorDriver getGWVDriver() {
|
||||||
|
return new GWVectorDriver(this.serverIP, this.serverPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilterCapabilities getFilterCapabilities() {
|
||||||
|
return this.capabilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRowCount() {
|
||||||
|
return this.readRowCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBufferSize() {
|
||||||
|
return this.readBufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getGmlObject(GmlObjectId id, Hints hints) throws Exception {
|
||||||
|
int i = id.getID().indexOf(46);
|
||||||
|
if (i == -1) {
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "Unable to determine geowave type for GmlObjectId:" + id);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String typeName = id.getID().substring(0, i);
|
||||||
|
Id filter = StyleMngr.ff.id(Collections.singleton(id));
|
||||||
|
Query query = new Query();
|
||||||
|
query.setFilter((Filter)filter);
|
||||||
|
query.setHints(hints);
|
||||||
|
ContentFeatureCollection features = this.getFeatureSource(typeName).getFeatures(query);
|
||||||
|
if (!features.isEmpty()) {
|
||||||
|
SimpleFeatureIterator fi = features.features();
|
||||||
|
try {
|
||||||
|
if (fi.hasNext()) {
|
||||||
|
Feature feature = fi.next();
|
||||||
|
return feature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
fi.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.geowave.vectordrvier.GWVectorDriver;
|
||||||
|
import com.geowave.vectordrvier.GWVectorQuery;
|
||||||
|
import com.geowave.vectordrvier.object.GWFeatureVectorObject;
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import org.geotools.data.FeatureReader;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.feature.simple.SimpleFeatureBuilder;
|
||||||
|
import org.geotools.filter.visitor.ExtractBoundsFilterVisitor;
|
||||||
|
import org.geotools.util.Converters;
|
||||||
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.filter.FilterVisitor;
|
||||||
|
|
||||||
|
public class GeoWaveFeatureReader
|
||||||
|
implements FeatureReader<SimpleFeatureType, SimpleFeature> {
|
||||||
|
private final GWVectorDriver gwvDriver;
|
||||||
|
private final SimpleFeatureType featureType;
|
||||||
|
final GWVectorQuery query;
|
||||||
|
private final int readRowCount;
|
||||||
|
private final int readBufferSize;
|
||||||
|
private SimpleFeatureBuilder builder;
|
||||||
|
private ArrayList<GWFeatureVectorObject> resultList = null;
|
||||||
|
private int featureIDX = 0;
|
||||||
|
|
||||||
|
public GeoWaveFeatureReader(GWVectorDriver driver, int rowCount, int bufferSize, SimpleFeatureType schema, Query q) throws IOException {
|
||||||
|
this.gwvDriver = driver;
|
||||||
|
this.featureType = schema;
|
||||||
|
this.readRowCount = rowCount;
|
||||||
|
this.readBufferSize = bufferSize;
|
||||||
|
this.builder = new SimpleFeatureBuilder(this.featureType);
|
||||||
|
this.gwvDriver.open_layer(this.featureType.getTypeName());
|
||||||
|
if (q.getFilter() == null || q.getFilter() == Filter.INCLUDE) {
|
||||||
|
this.query = null;
|
||||||
|
this.resultList = this.gwvDriver.read_line_bulk_vector(this.readRowCount, this.readBufferSize);
|
||||||
|
} else {
|
||||||
|
Envelope bounds = (Envelope)q.getFilter().accept((FilterVisitor)ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||||
|
this.query = new GWVectorQuery(this.gwvDriver);
|
||||||
|
this.query.setEnvelopeFilter(bounds);
|
||||||
|
this.resultList = this.query.getResult_vector(this.readRowCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureType getFeatureType() {
|
||||||
|
return this.featureType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeature next() throws IOException, IllegalArgumentException, NoSuchElementException {
|
||||||
|
GWFeatureVectorObject vecObj = this.resultList.get(this.featureIDX);
|
||||||
|
++this.featureIDX;
|
||||||
|
String fid = String.valueOf(this.featureType.getTypeName()) + "." + SimpleFeatureBuilder.createDefaultFeatureId();
|
||||||
|
int i = 0;
|
||||||
|
while (i < this.featureType.getAttributeCount()) {
|
||||||
|
Class binding;
|
||||||
|
Object converted;
|
||||||
|
AttributeDescriptor type = this.featureType.getDescriptor(i);
|
||||||
|
Object value = null;
|
||||||
|
if (type instanceof GeometryDescriptor) {
|
||||||
|
Geometry geometry;
|
||||||
|
GeometryDescriptor gatt = (GeometryDescriptor)type;
|
||||||
|
value = vecObj.getGeometry();
|
||||||
|
if (value != null && (geometry = (Geometry)value).getUserData() == null) {
|
||||||
|
geometry.setUserData((Object)gatt.getCoordinateReferenceSystem());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = vecObj.getColumnObj(i);
|
||||||
|
}
|
||||||
|
if (value != null && (converted = Converters.convert((Object)value, (Class)(binding = type.getType().getBinding()))) != null && converted != value) {
|
||||||
|
value = converted;
|
||||||
|
}
|
||||||
|
this.builder.add(value);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return this.builder.buildFeature(fid);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNext() throws IOException {
|
||||||
|
if (this.resultList == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.resultList.size() <= this.featureIDX) {
|
||||||
|
this.resultList = this.query == null ? this.gwvDriver.read_line_bulk_vector(this.readRowCount, this.readBufferSize) : this.query.getResult_vector(this.readRowCount);
|
||||||
|
this.featureIDX = 0;
|
||||||
|
}
|
||||||
|
return this.resultList != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
this.gwvDriver.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,403 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.geowave.metadata.FeatureColumnInfo;
|
||||||
|
import com.geowave.vectordrvier.GWVectorDriver;
|
||||||
|
import com.geowave.vectordrvier.GWVectorQuery;
|
||||||
|
import com.geowave.vectordrvier.constant.GWVectorMetadata;
|
||||||
|
import com.geowave.vectordrvier.object.GWFeatureVectorObject;
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.LineString;
|
||||||
|
import com.vividsolutions.jts.geom.Point;
|
||||||
|
import com.vividsolutions.jts.geom.Polygon;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import org.geotools.data.DefaultQuery;
|
||||||
|
import org.geotools.data.FeatureReader;
|
||||||
|
import org.geotools.data.FilteringFeatureReader;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.ReTypeFeatureReader;
|
||||||
|
import org.geotools.data.store.ContentEntry;
|
||||||
|
import org.geotools.data.store.ContentFeatureSource;
|
||||||
|
import org.geotools.factory.Hints;
|
||||||
|
import org.geotools.feature.AttributeTypeBuilder;
|
||||||
|
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
||||||
|
import org.geotools.filter.FilterAttributeExtractor;
|
||||||
|
import org.geotools.filter.visitor.ExtractBoundsFilterVisitor;
|
||||||
|
import org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.filter.FilterVisitor;
|
||||||
|
import org.opengis.referencing.FactoryException;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.opengis.referencing.crs.SingleCRS;
|
||||||
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
|
public class GeoWaveFeatureSource extends ContentFeatureSource {
|
||||||
|
private final ReferencedEnvelope EMPTY_ENVELOPE = new ReferencedEnvelope();
|
||||||
|
|
||||||
|
public GeoWaveFeatureSource(ContentEntry entry) {
|
||||||
|
super(entry, Query.ALL);
|
||||||
|
HashSet<Hints.Key> hints = new HashSet<>();
|
||||||
|
hints.add(Hints.FEATURE_DETACHED);
|
||||||
|
hints.add(Hints.JTS_GEOMETRY_FACTORY);
|
||||||
|
hints.add(Hints.JTS_COORDINATE_SEQUENCE_FACTORY);
|
||||||
|
hints.add(Hints.GEOMETRY_DISTANCE);
|
||||||
|
hints.add(Hints.SCREENMAP);
|
||||||
|
this.hints = Collections.unmodifiableSet(hints);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ReferencedEnvelope getBoundsInternal(Query query) throws IOException {
|
||||||
|
Filter[] split = this.splitFilter(query.getFilter());
|
||||||
|
Filter preFilter = split[0];
|
||||||
|
Filter postFilter = split[1];
|
||||||
|
try {
|
||||||
|
if (postFilter != null && postFilter != Filter.INCLUDE || query.getMaxFeatures() < Integer.MAX_VALUE && !this.canLimit() || query.getStartIndex() != null && query.getStartIndex() > 0 && !this.canOffset()) {
|
||||||
|
SingleCRS flatCRS = CRS.getHorizontalCRS((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||||
|
ReferencedEnvelope bounds = new ReferencedEnvelope((CoordinateReferenceSystem)flatCRS);
|
||||||
|
FeatureReader i = this.getReader(query);
|
||||||
|
try {
|
||||||
|
if (i.hasNext()) {
|
||||||
|
SimpleFeature f = (SimpleFeature)i.next();
|
||||||
|
bounds.init(f.getBounds());
|
||||||
|
while (i.hasNext()) {
|
||||||
|
f = (SimpleFeature)i.next();
|
||||||
|
bounds.include(f.getBounds());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
i.close();
|
||||||
|
}
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
DefaultQuery q = new DefaultQuery(query);
|
||||||
|
q.setFilter(preFilter);
|
||||||
|
return this.getBoundsOptimal((Query)q);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ReferencedEnvelope getBoundsOptimal(Query query) throws IOException {
|
||||||
|
if (this.getSchema().getGeometryDescriptor() == null) {
|
||||||
|
return this.EMPTY_ENVELOPE;
|
||||||
|
}
|
||||||
|
GWVectorDriver driver = this.getDataStore().getGWVDriver();
|
||||||
|
try {
|
||||||
|
ArrayList<GWFeatureVectorObject> result;
|
||||||
|
driver.open_layer(this.getSchema().getTypeName());
|
||||||
|
if (this.isFullBoundsQuery(query)) {
|
||||||
|
GWVectorMetadata meta = driver.getVectorMeta(this.getSchema().getTypeName());
|
||||||
|
ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(meta.getFull_envelope(), meta.getCRS());
|
||||||
|
return referencedEnvelope;
|
||||||
|
}
|
||||||
|
Envelope envelop = (Envelope)query.getFilter().accept((FilterVisitor)ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||||
|
GWVectorQuery driverQuery = new GWVectorQuery(driver);
|
||||||
|
driverQuery.setEnvelopeFilter(envelop);
|
||||||
|
ReferencedEnvelope bounds = ReferencedEnvelope.create((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||||
|
SingleCRS flatCRS = CRS.getHorizontalCRS((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||||
|
while ((result = driverQuery.getResult_vector(this.getDataStore().getRowCount())) != null) {
|
||||||
|
for (GWFeatureVectorObject obj : result) {
|
||||||
|
Envelope env = obj.getEnvelope();
|
||||||
|
bounds = this.mergeEnvelope(bounds, new ReferencedEnvelope(env, (CoordinateReferenceSystem)flatCRS));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ReferencedEnvelope referencedEnvelope = bounds;
|
||||||
|
return referencedEnvelope;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
String msg = "Error occured calculating bounds for " + this.getSchema().getTypeName();
|
||||||
|
throw (IOException)new IOException(msg).initCause(e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
driver.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isFullBoundsQuery(Query query) {
|
||||||
|
if (query == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Filter.INCLUDE.equals(query.getFilter())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (query.getProperties() == Query.ALL_PROPERTIES) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
List<String> names = Arrays.asList(query.getPropertyNames());
|
||||||
|
for (AttributeDescriptor ad : this.getSchema().getAttributeDescriptors()) {
|
||||||
|
if (!(ad instanceof GeometryDescriptor) || names.contains(ad.getLocalName())) continue;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReferencedEnvelope mergeEnvelope(ReferencedEnvelope base, ReferencedEnvelope merge) throws TransformException, FactoryException {
|
||||||
|
if (base == null || base.isNull()) {
|
||||||
|
return merge;
|
||||||
|
}
|
||||||
|
if (merge == null || merge.isNull()) {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
CoordinateReferenceSystem crsBase = base.getCoordinateReferenceSystem();
|
||||||
|
CoordinateReferenceSystem crsMerge = merge.getCoordinateReferenceSystem();
|
||||||
|
if (crsBase == null) {
|
||||||
|
merge.expandToInclude((Envelope)base);
|
||||||
|
return merge;
|
||||||
|
}
|
||||||
|
if (crsMerge == null) {
|
||||||
|
base.expandToInclude((Envelope)base);
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
if (!CRS.equalsIgnoreMetadata((Object)crsBase, (Object)crsMerge)) {
|
||||||
|
merge = merge.transform(crsBase, true);
|
||||||
|
}
|
||||||
|
base.expandToInclude((Envelope)merge);
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getCountInternal(Query query) throws IOException {
|
||||||
|
Filter[] split = this.splitFilter(query.getFilter());
|
||||||
|
Filter preFilter = split[0];
|
||||||
|
Filter postFilter = split[1];
|
||||||
|
try {
|
||||||
|
boolean manual;
|
||||||
|
boolean bl = manual = postFilter != null && postFilter != Filter.INCLUDE;
|
||||||
|
if (manual) {
|
||||||
|
int count = 0;
|
||||||
|
FeatureReader reader = this.getReader(query);
|
||||||
|
try {
|
||||||
|
while (reader.hasNext()) {
|
||||||
|
reader.next();
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
DefaultQuery q = new DefaultQuery(query);
|
||||||
|
q.setFilter(preFilter);
|
||||||
|
int count = this.getCountOptimal((Query)q);
|
||||||
|
if (query.getStartIndex() != null && query.getStartIndex() > 0) {
|
||||||
|
count = query.getStartIndex() > count ? 0 : (count -= query.getStartIndex().intValue());
|
||||||
|
}
|
||||||
|
if (query.getMaxFeatures() > 0 && count > query.getMaxFeatures()) {
|
||||||
|
count = query.getMaxFeatures();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getCountOptimal(Query query) throws IOException {
|
||||||
|
GWVectorDriver driver = this.getDataStore().getGWVDriver();
|
||||||
|
try {
|
||||||
|
ArrayList result;
|
||||||
|
driver.open_layer(this.getSchema().getTypeName());
|
||||||
|
if (this.isFullBoundsQuery(query)) {
|
||||||
|
GWVectorMetadata meta = driver.getVectorMeta(this.getSchema().getTypeName());
|
||||||
|
int n = meta.getTotal_row_count();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
int count = 0;
|
||||||
|
Envelope envelop = (Envelope)query.getFilter().accept((FilterVisitor)ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||||
|
GWVectorQuery driverQuery = new GWVectorQuery(driver);
|
||||||
|
driverQuery.setEnvelopeFilter(envelop);
|
||||||
|
ReferencedEnvelope bounds = ReferencedEnvelope.create((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||||
|
SingleCRS flatCRS = CRS.getHorizontalCRS((CoordinateReferenceSystem)this.getSchema().getCoordinateReferenceSystem());
|
||||||
|
while ((result = driverQuery.getResult_vector(this.getDataStore().getRowCount())) != null) {
|
||||||
|
count += result.size();
|
||||||
|
}
|
||||||
|
int n = count;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
String msg = "Error occured calculating bounds for " + this.getSchema().getTypeName();
|
||||||
|
throw (IOException)new IOException(msg).initCause(e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
driver.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(Query query) throws IOException {
|
||||||
|
FeatureReader<SimpleFeatureType, SimpleFeature> reader;
|
||||||
|
Filter[] split = this.splitFilter(query.getFilter());
|
||||||
|
Filter preFilter = split[0];
|
||||||
|
Filter postFilter = split[1];
|
||||||
|
DefaultQuery preQuery = new DefaultQuery(query);
|
||||||
|
preQuery.setFilter(preFilter);
|
||||||
|
SimpleFeatureType[] types = this.buildQueryAndReturnFeatureTypes(query.getPropertyNames(), postFilter);
|
||||||
|
SimpleFeatureType querySchema = types[0];
|
||||||
|
SimpleFeatureType returnedSchema = types[1];
|
||||||
|
try {
|
||||||
|
reader = new GeoWaveFeatureReader(this.getDataStore().getGWVDriver(), this.getDataStore().getRowCount(), this.getDataStore().getBufferSize(), querySchema, (Query)preQuery);
|
||||||
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
if (e instanceof Error) {
|
||||||
|
throw (Error)e;
|
||||||
|
}
|
||||||
|
throw (IOException)new IOException().initCause(e);
|
||||||
|
}
|
||||||
|
if (postFilter != null && postFilter != Filter.INCLUDE) {
|
||||||
|
reader = new FilteringFeatureReader((FeatureReader)reader, postFilter);
|
||||||
|
if (!returnedSchema.equals((Object)querySchema)) {
|
||||||
|
reader = new ReTypeFeatureReader((FeatureReader)reader, returnedSchema);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SimpleFeatureType[] buildQueryAndReturnFeatureTypes(String[] propertyNames, Filter filter) {
|
||||||
|
SimpleFeatureType returnedSchema;
|
||||||
|
SimpleFeatureType[] types = null;
|
||||||
|
if (propertyNames == Query.ALL_NAMES) {
|
||||||
|
return new SimpleFeatureType[]{this.getSchema(), this.getSchema()};
|
||||||
|
}
|
||||||
|
SimpleFeatureType querySchema = returnedSchema = SimpleFeatureTypeBuilder.retype((SimpleFeatureType)this.getSchema(), (String[])propertyNames);
|
||||||
|
if (filter != null && !filter.equals(Filter.INCLUDE)) {
|
||||||
|
FilterAttributeExtractor extractor = new FilterAttributeExtractor(this.getSchema());
|
||||||
|
filter.accept((FilterVisitor)extractor, null);
|
||||||
|
String[] extraAttributes = extractor.getAttributeNames();
|
||||||
|
if (extraAttributes != null && extraAttributes.length > 0) {
|
||||||
|
ArrayList<String> allAttributes = new ArrayList<String>(Arrays.asList(propertyNames));
|
||||||
|
String[] stringArray = extraAttributes;
|
||||||
|
int n = extraAttributes.length;
|
||||||
|
int n2 = 0;
|
||||||
|
while (n2 < n) {
|
||||||
|
String extraAttribute = stringArray[n2];
|
||||||
|
if (!allAttributes.contains(extraAttribute)) {
|
||||||
|
allAttributes.add(extraAttribute);
|
||||||
|
}
|
||||||
|
++n2;
|
||||||
|
}
|
||||||
|
String[] allAttributeArray = allAttributes.toArray(new String[allAttributes.size()]);
|
||||||
|
querySchema = SimpleFeatureTypeBuilder.retype((SimpleFeatureType)this.getSchema(), (String[])allAttributeArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
types = new SimpleFeatureType[]{querySchema, returnedSchema};
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SimpleFeatureType buildFeatureType() throws IOException {
|
||||||
|
SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
|
||||||
|
AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();
|
||||||
|
String layerName = this.entry.getName().getLocalPart();
|
||||||
|
typeBuilder.setName(layerName);
|
||||||
|
if (this.entry.getName().getNamespaceURI() != null) {
|
||||||
|
typeBuilder.setNamespaceURI(this.entry.getName().getNamespaceURI());
|
||||||
|
} else {
|
||||||
|
typeBuilder.setNamespaceURI(this.getDataStore().getNamespaceURI());
|
||||||
|
}
|
||||||
|
GWVectorDriver driver = this.getDataStore().getGWVDriver();
|
||||||
|
try {
|
||||||
|
driver.open_layer(layerName);
|
||||||
|
GWVectorMetadata meta = driver.getVectorMeta(layerName);
|
||||||
|
FeatureColumnInfo cInfo = meta.getColumn_info();
|
||||||
|
int idx = 0;
|
||||||
|
while (idx < cInfo.getColumnSize()) {
|
||||||
|
String columnName = cInfo.getColumnName(idx).toUpperCase();
|
||||||
|
String columnType = cInfo.getColumnType(idx);
|
||||||
|
Class<?> binding = this.getDataStore().getMapping(columnType);
|
||||||
|
if (columnName != null && binding != null) {
|
||||||
|
attrBuilder.addUserData((Object)"org.geotools.jdbc.nativeTypeName", (Object)columnType);
|
||||||
|
AttributeDescriptor attrDesc = null;
|
||||||
|
if (idx == meta.getSpatial_column_idx()) {
|
||||||
|
Integer srid = null;
|
||||||
|
CoordinateReferenceSystem crs = meta.getCRS();
|
||||||
|
try {
|
||||||
|
srid = Integer.valueOf(CRS.toSRS((CoordinateReferenceSystem)crs, (boolean)true));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
srid = null;
|
||||||
|
}
|
||||||
|
int dimension = 2;
|
||||||
|
switch (meta.getSpatial_type()) {
|
||||||
|
case 1: {
|
||||||
|
attrBuilder.setBinding(Point.class);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
attrBuilder.setBinding(LineString.class);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
|
attrBuilder.setBinding(Polygon.class);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
attrBuilder.setBinding(binding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attrBuilder.setName(columnName);
|
||||||
|
attrBuilder.setCRS(crs);
|
||||||
|
if (srid != null) {
|
||||||
|
attrBuilder.addUserData((Object)"nativeSRID", (Object)srid);
|
||||||
|
}
|
||||||
|
attrBuilder.addUserData((Object)Hints.COORDINATE_DIMENSION, (Object)dimension);
|
||||||
|
attrDesc = attrBuilder.buildDescriptor(columnName, attrBuilder.buildGeometryType());
|
||||||
|
} else {
|
||||||
|
attrBuilder.setBinding(binding);
|
||||||
|
attrBuilder.setName(columnName);
|
||||||
|
attrDesc = attrBuilder.buildDescriptor(columnName, attrBuilder.buildType());
|
||||||
|
}
|
||||||
|
typeBuilder.add(attrDesc);
|
||||||
|
}
|
||||||
|
++idx;
|
||||||
|
}
|
||||||
|
SimpleFeatureType ft = typeBuilder.buildFeatureType();
|
||||||
|
ft.getUserData().put("org.geotools.jdbc.readOnly", Boolean.TRUE);
|
||||||
|
SimpleFeatureType simpleFeatureType = ft;
|
||||||
|
return simpleFeatureType;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (driver != null) {
|
||||||
|
driver.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoWaveDataStore getDataStore() {
|
||||||
|
return (GeoWaveDataStore)super.getDataStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Filter[] splitFilter(Filter original) {
|
||||||
|
Filter[] split = new Filter[2];
|
||||||
|
if (original != null) {
|
||||||
|
PostPreProcessFilterSplittingVisitor splitter = new PostPreProcessFilterSplittingVisitor(this.getDataStore().getFilterCapabilities(), this.getSchema(), null);
|
||||||
|
original.accept((FilterVisitor)splitter, null);
|
||||||
|
split[0] = splitter.getFilterPre();
|
||||||
|
split[1] = splitter.getFilterPost();
|
||||||
|
}
|
||||||
|
return split;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean canFilter() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean canTransact() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean canRetype() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,104 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
public class GeometryMngr {
|
import com.vividsolutions.jts.geom.LineString;
|
||||||
|
import com.vividsolutions.jts.geom.MultiLineString;
|
||||||
|
import com.vividsolutions.jts.geom.MultiPolygon;
|
||||||
|
import com.vividsolutions.jts.geom.Polygon;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureSource;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
|
import org.opengis.feature.type.GeometryType;
|
||||||
|
import org.opengis.referencing.FactoryException;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
}
|
public class GeometryMngr
|
||||||
|
{
|
||||||
|
public static GeomType getGeometryTypeByLayer(Layer layer)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if ((layer instanceof FeatureLayer)) {
|
||||||
|
FeatureLayer fLayer = (FeatureLayer)layer;
|
||||||
|
return getGeometryType(fLayer.getLayerType(), fLayer.getServerName(), fLayer.getSourceName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GeomType getGeometryType(LayerFactory.LayerType layerType, String serverName, String tableName)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource(layerType, serverName, tableName);
|
||||||
|
|
||||||
|
GeometryDescriptor geomDesc = ((SimpleFeatureType)featureSource.getSchema()).getGeometryDescriptor();
|
||||||
|
|
||||||
|
Class clazz = geomDesc.getType().getBinding();
|
||||||
|
|
||||||
|
if ((Polygon.class.isAssignableFrom(clazz)) ||
|
||||||
|
(MultiPolygon.class.isAssignableFrom(clazz)))
|
||||||
|
{
|
||||||
|
return GeomType.POLYGON;
|
||||||
|
}
|
||||||
|
if ((LineString.class.isAssignableFrom(clazz)) ||
|
||||||
|
(MultiLineString.class.isAssignableFrom(clazz)))
|
||||||
|
{
|
||||||
|
return GeomType.LINE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GeomType.POINT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getGeometryColumnByLayer(Layer layer)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if ((layer instanceof FeatureLayer)) {
|
||||||
|
FeatureLayer fLayer = (FeatureLayer)layer;
|
||||||
|
return getGeometryColumn(fLayer.getLayerType(), fLayer.getServerName(), fLayer.getSourceName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getGeometryColumn(LayerFactory.LayerType layerType, String serverName, String tableName)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource(layerType, serverName, tableName);
|
||||||
|
|
||||||
|
GeometryDescriptor geomDesc = ((SimpleFeatureType)featureSource.getSchema()).getGeometryDescriptor();
|
||||||
|
|
||||||
|
return geomDesc.getLocalName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ReferencedEnvelope mergeEnvelope(ReferencedEnvelope base, ReferencedEnvelope merge)
|
||||||
|
throws TransformException, FactoryException
|
||||||
|
{
|
||||||
|
if ((base == null) || (base.isNull()))
|
||||||
|
return merge;
|
||||||
|
if ((merge == null) || (merge.isNull())) {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoordinateReferenceSystem crsBase = base.getCoordinateReferenceSystem();
|
||||||
|
CoordinateReferenceSystem crsMerge = merge.getCoordinateReferenceSystem();
|
||||||
|
if (crsBase == null) {
|
||||||
|
merge.expandToInclude(base);
|
||||||
|
return merge;
|
||||||
|
}if (crsMerge == null) {
|
||||||
|
base.expandToInclude(merge);
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CRS.equalsIgnoreMetadata(crsBase, crsMerge)) {
|
||||||
|
merge = merge.transform(crsBase, true);
|
||||||
|
}
|
||||||
|
base.expandToInclude(merge);
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum GeomType
|
||||||
|
{
|
||||||
|
POINT, LINE, POLYGON;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
public class GetCapabilitiesRequest extends Request
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class GetFeatureInfoRequest extends Request
|
||||||
|
{
|
||||||
|
private String[] layers = null;
|
||||||
|
private String[] styles = null;
|
||||||
|
private CoordinateReferenceSystem crs = null;
|
||||||
|
private ReferencedEnvelope bbox = null;
|
||||||
|
private int width;
|
||||||
|
private int height;
|
||||||
|
private String[] queryLayer;
|
||||||
|
private String infoFormat;
|
||||||
|
private int i;
|
||||||
|
private int j;
|
||||||
|
private int featureCount = 1;
|
||||||
|
|
||||||
|
private StyledLayerDescriptor sld = null;
|
||||||
|
|
||||||
|
public StyledLayerDescriptor getSld() {
|
||||||
|
return this.sld;
|
||||||
|
}
|
||||||
|
public void setSld(StyledLayerDescriptor sld) {
|
||||||
|
this.sld = sld;
|
||||||
|
}
|
||||||
|
public String[] getLayers() {
|
||||||
|
return this.layers;
|
||||||
|
}
|
||||||
|
public void setLayers(String[] layers) {
|
||||||
|
this.layers = layers;
|
||||||
|
}
|
||||||
|
public String[] getStyles() {
|
||||||
|
return this.styles;
|
||||||
|
}
|
||||||
|
public void setStyles(String[] styles) {
|
||||||
|
this.styles = styles;
|
||||||
|
}
|
||||||
|
public ReferencedEnvelope getBbox() {
|
||||||
|
return this.bbox;
|
||||||
|
}
|
||||||
|
public void setBbox(ReferencedEnvelope bbox) {
|
||||||
|
this.bbox = bbox;
|
||||||
|
}
|
||||||
|
public int getWidth() {
|
||||||
|
return this.width;
|
||||||
|
}
|
||||||
|
public void setWidth(int width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
public int getHeight() {
|
||||||
|
return this.height;
|
||||||
|
}
|
||||||
|
public void setHeight(int height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
public String[] getQueryLayer() {
|
||||||
|
return this.queryLayer;
|
||||||
|
}
|
||||||
|
public void setQueryLayer(String[] queryLayer) {
|
||||||
|
this.queryLayer = queryLayer;
|
||||||
|
}
|
||||||
|
public String getInfoFormat() {
|
||||||
|
return this.infoFormat;
|
||||||
|
}
|
||||||
|
public void setInfoFormat(String infoFormat) {
|
||||||
|
this.infoFormat = infoFormat;
|
||||||
|
}
|
||||||
|
public int getI() {
|
||||||
|
return this.i;
|
||||||
|
}
|
||||||
|
public void setI(int i) {
|
||||||
|
this.i = i;
|
||||||
|
}
|
||||||
|
public int getJ() {
|
||||||
|
return this.j;
|
||||||
|
}
|
||||||
|
public void setJ(int j) {
|
||||||
|
this.j = j;
|
||||||
|
}
|
||||||
|
public void setCRS(CoordinateReferenceSystem crs) {
|
||||||
|
this.crs = crs;
|
||||||
|
}
|
||||||
|
public CoordinateReferenceSystem getCRS() {
|
||||||
|
return this.crs;
|
||||||
|
}
|
||||||
|
public int getFeatureCount() {
|
||||||
|
return this.featureCount;
|
||||||
|
}
|
||||||
|
public void setFeatureCount(int featureCount) {
|
||||||
|
this.featureCount = featureCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
|
|
||||||
|
public class GetLegendGraphicRequest extends Request
|
||||||
|
{
|
||||||
|
private String layer;
|
||||||
|
private String style;
|
||||||
|
private String rule;
|
||||||
|
private StyledLayerDescriptor sld;
|
||||||
|
private String width;
|
||||||
|
private String height;
|
||||||
|
private String scale;
|
||||||
|
private String option;
|
||||||
|
|
||||||
|
public String getLayer()
|
||||||
|
{
|
||||||
|
return this.layer;
|
||||||
|
}
|
||||||
|
public void setLayer(String layer) {
|
||||||
|
this.layer = layer;
|
||||||
|
}
|
||||||
|
public String getStyle() {
|
||||||
|
return this.style;
|
||||||
|
}
|
||||||
|
public void setStyle(String style) {
|
||||||
|
this.style = style;
|
||||||
|
}
|
||||||
|
public void setRule(String rule) {
|
||||||
|
this.rule = rule;
|
||||||
|
}
|
||||||
|
public StyledLayerDescriptor getSld() {
|
||||||
|
return this.sld;
|
||||||
|
}
|
||||||
|
public void setSld(StyledLayerDescriptor sld) {
|
||||||
|
this.sld = sld;
|
||||||
|
}
|
||||||
|
public String getWidth() {
|
||||||
|
return this.width;
|
||||||
|
}
|
||||||
|
public void setWidth(String width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
public String getHeight() {
|
||||||
|
return this.height;
|
||||||
|
}
|
||||||
|
public void setHeight(String height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
public String getRule() {
|
||||||
|
return this.rule;
|
||||||
|
}
|
||||||
|
public String getScale() {
|
||||||
|
return this.scale;
|
||||||
|
}
|
||||||
|
public void setScale(String scale) {
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
public String getOption() {
|
||||||
|
return this.option;
|
||||||
|
}
|
||||||
|
public void setOption(String option) {
|
||||||
|
this.option = option;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,85 +5,96 @@ import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
import org.geotools.styling.StyledLayerDescriptor;
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||||
|
|
||||||
public class GetMapRequest extends Request
|
public class GetMapRequest extends Request {
|
||||||
{
|
private String[] layers = null;
|
||||||
private String[] layers = null;
|
private String[] styles = null;
|
||||||
private String[] styles = null;
|
private ReferencedEnvelope bbox = null;
|
||||||
private ReferencedEnvelope bbox = null;
|
private int width;
|
||||||
private int width;
|
private int height;
|
||||||
private int height;
|
private boolean transparent = false;
|
||||||
private boolean transparent = false;
|
private Color bgcolor = Color.white;
|
||||||
private Color bgcolor = Color.white;
|
private StyledLayerDescriptor sld = null;
|
||||||
private StyledLayerDescriptor sld = null;
|
|
||||||
|
|
||||||
public String[] getLayers() {
|
public String[] getLayers() {
|
||||||
return this.layers;
|
return this.layers;
|
||||||
}
|
|
||||||
public void setLayers(String[] layers) {
|
|
||||||
this.layers = layers;
|
|
||||||
}
|
|
||||||
public String[] getStyles() {
|
|
||||||
return this.styles;
|
|
||||||
}
|
|
||||||
public void setStyles(String[] styles) {
|
|
||||||
this.styles = styles;
|
|
||||||
}
|
|
||||||
public ReferencedEnvelope getBbox() {
|
|
||||||
return this.bbox;
|
|
||||||
}
|
|
||||||
public void setBbox(ReferencedEnvelope bbox) {
|
|
||||||
this.bbox = bbox;
|
|
||||||
}
|
|
||||||
public int getWidth() {
|
|
||||||
return this.width;
|
|
||||||
}
|
|
||||||
public void setWidth(int width) {
|
|
||||||
this.width = width;
|
|
||||||
}
|
|
||||||
public int getHeight() {
|
|
||||||
return this.height;
|
|
||||||
}
|
|
||||||
public void setHeight(int height) {
|
|
||||||
this.height = height;
|
|
||||||
}
|
|
||||||
public boolean isTransparent() {
|
|
||||||
return this.transparent;
|
|
||||||
}
|
|
||||||
public void setTransparent(boolean transparent) {
|
|
||||||
this.transparent = transparent;
|
|
||||||
}
|
|
||||||
public Color getBgcolor() {
|
|
||||||
return this.bgcolor;
|
|
||||||
}
|
|
||||||
public void setBgcolor(Color bgcolor) {
|
|
||||||
this.bgcolor = bgcolor;
|
|
||||||
}
|
|
||||||
public StyledLayerDescriptor getSld() {
|
|
||||||
return this.sld;
|
|
||||||
}
|
|
||||||
public void setSld(StyledLayerDescriptor sld) {
|
|
||||||
this.sld = sld;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GetMapRequest clone() {
|
|
||||||
GetMapRequest newRequest = new GetMapRequest();
|
|
||||||
newRequest.layers = ((String[])this.layers.clone());
|
|
||||||
newRequest.bbox = ReferencedEnvelope.reference(this.bbox);
|
|
||||||
newRequest.bgcolor = new Color(this.bgcolor.getRed(), this.bgcolor.getGreen(), this.bgcolor.getBlue(), this.bgcolor.getTransparency());
|
|
||||||
newRequest.transparent = this.transparent;
|
|
||||||
newRequest.height = this.height;
|
|
||||||
newRequest.width = this.width;
|
|
||||||
|
|
||||||
if (this.styles != null) {
|
|
||||||
newRequest.styles = ((String[])this.styles.clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.sld != null) {
|
public void setLayers(String[] layers) {
|
||||||
DuplicatingStyleVisitor visitor = new DuplicatingStyleVisitor();
|
this.layers = layers;
|
||||||
visitor.visit(this.sld);
|
|
||||||
newRequest.sld = ((StyledLayerDescriptor)visitor.getCopy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newRequest;
|
public String[] getStyles() {
|
||||||
}
|
return this.styles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStyles(String[] styles) {
|
||||||
|
this.styles = styles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencedEnvelope getBbox() {
|
||||||
|
return this.bbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBbox(ReferencedEnvelope bbox) {
|
||||||
|
this.bbox = bbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return this.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidth(int width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return this.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeight(int height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTransparent() {
|
||||||
|
return this.transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTransparent(boolean transparent) {
|
||||||
|
this.transparent = transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getBgcolor() {
|
||||||
|
return this.bgcolor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBgcolor(Color bgcolor) {
|
||||||
|
this.bgcolor = bgcolor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StyledLayerDescriptor getSld() {
|
||||||
|
return this.sld;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSld(StyledLayerDescriptor sld) {
|
||||||
|
this.sld = sld;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetMapRequest clone() {
|
||||||
|
GetMapRequest newRequest = new GetMapRequest();
|
||||||
|
newRequest.layers = (String[])this.layers.clone();
|
||||||
|
newRequest.bbox = ReferencedEnvelope.reference((ReferencedEnvelope)this.bbox);
|
||||||
|
newRequest.bgcolor = new Color(this.bgcolor.getRed(), this.bgcolor.getGreen(), this.bgcolor.getBlue(), this.bgcolor.getTransparency());
|
||||||
|
newRequest.transparent = this.transparent;
|
||||||
|
newRequest.height = this.height;
|
||||||
|
newRequest.width = this.width;
|
||||||
|
if (this.styles != null) {
|
||||||
|
newRequest.styles = (String[])this.styles.clone();
|
||||||
|
}
|
||||||
|
if (this.sld != null) {
|
||||||
|
DuplicatingStyleVisitor visitor = new DuplicatingStyleVisitor();
|
||||||
|
visitor.visit(this.sld);
|
||||||
|
newRequest.sld = (StyledLayerDescriptor)visitor.getCopy();
|
||||||
|
}
|
||||||
|
return newRequest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class ImgCacheLayer {
|
||||||
|
private Layer layer;
|
||||||
|
private String layerStyle = "DEFAULT";
|
||||||
|
private File cacheDir;
|
||||||
|
private CacheFormat cacheFormat = new CacheFormat();
|
||||||
|
private CacheLevelSet levelSet;
|
||||||
|
|
||||||
|
public ImgCacheLayer(String name, String style) throws Exception {
|
||||||
|
this.layer = ServerContext.getMap().getLayer(name);
|
||||||
|
if (!ServerUtil.isNullString((String)style)) {
|
||||||
|
this.layerStyle = style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerName() {
|
||||||
|
return this.layer.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerStyle() {
|
||||||
|
return this.layerStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencedEnvelope getBBox() {
|
||||||
|
return this.layer.getBBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem getCRS() {
|
||||||
|
return this.layer.getCRS();
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getCacheDir() {
|
||||||
|
return this.cacheDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCacheFormat(CacheFormat format) {
|
||||||
|
if (format != null) {
|
||||||
|
this.cacheFormat = format;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCacheSizeW() {
|
||||||
|
return this.cacheFormat.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCacheSizeH() {
|
||||||
|
return this.cacheFormat.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCacheFormat() {
|
||||||
|
return this.cacheFormat.getFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheLevelSet getCacheLevelSet() {
|
||||||
|
return this.levelSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCacheDir(File dir) throws IOException {
|
||||||
|
this.cacheDir = new File(dir, this.layer.getName());
|
||||||
|
if (!this.cacheDir.exists() && !this.cacheDir.mkdirs()) {
|
||||||
|
throw new IOException("Can't access CacheLocation for this layer [" + this.cacheDir.getAbsolutePath() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCacheLevelSet(CacheLevelSet lSet) throws Exception {
|
||||||
|
this.levelSet = lSet;
|
||||||
|
this.levelSet.refindCacheLevelSet(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,264 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import javax.management.modelmbean.XMLParseException;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.jdom.Attribute;
|
||||||
|
import org.jdom.Document;
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.input.SAXBuilder;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class ImgCacheMngr {
|
||||||
|
private static ConcurrentHashMap<String, ImgCacheLayer> cacheLayerStore = new ConcurrentHashMap();
|
||||||
|
private static ConcurrentHashMap<String, ImgCacheLayer> dirtyCacheLayerStore;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public static void initLayers() {
|
||||||
|
ConcurrentHashMap<String, ImgCacheLayer> concurrentHashMap = cacheLayerStore = new ConcurrentHashMap();
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
try {
|
||||||
|
File confFile = new File(ServerContext.getPluginsFolder(), String.valueOf(ServerContext.getMap().getName()) + ".IMGCACHE");
|
||||||
|
if (!confFile.exists()) {
|
||||||
|
throw new IOException("Configuration file is not exist :: " + confFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[IMGCACHE]", "Now create [" + ServerContext.getMap().getName() + "] ImgCache Layer");
|
||||||
|
AVList params = ImgCacheMngr.parseImgCacheLayer(confFile);
|
||||||
|
File cacheDir = (File)params.getValue("img.cache.conf.cache.location");
|
||||||
|
CacheFormat cacheFormat = (CacheFormat)params.getValue("img.cache.conf.cache.format");
|
||||||
|
CacheLevelSet cacheLevelSet = (CacheLevelSet)params.getValue("img.cache.conf.cache.levelset");
|
||||||
|
ArrayList<ImgCacheLayer> layers = (ArrayList)params.getValue("img.cache.conf.layers");
|
||||||
|
for (ImgCacheLayer layer : layers) {
|
||||||
|
try {
|
||||||
|
layer.setCacheDir(cacheDir);
|
||||||
|
layer.setCacheFormat(cacheFormat);
|
||||||
|
layer.setCacheLevelSet(cacheLevelSet.copy());
|
||||||
|
cacheLayerStore.put(layer.getLayerName(), layer);
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "[" + layer.getLayerName() + "] Add ImgCache Layer Success");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[IMGCACHE]", "[" + layer.getLayerName() + "] Add ImgCache Layer Fail :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cacheLayerStore.size() == 0) {
|
||||||
|
LogMngr.getInstance().logError("[IMGCACHE]", "Create ImgCache Layer Fail :: Layer Count is [0]");
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Create ImgCache Layer Success :: Layer Count is [" + cacheLayerStore.size() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[IMGCACHE]", "Create ImgCache Layer Fail :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AVList parseImgCacheLayer(File xml) throws Exception {
|
||||||
|
LogMngr.getInstance().logDebug("[IMGCACHE]", "[" + xml.getName() + "] Parse ImgCache Layer");
|
||||||
|
SAXBuilder builder = new SAXBuilder();
|
||||||
|
Document doc = builder.build(xml);
|
||||||
|
Element root = doc.getRootElement();
|
||||||
|
if (!root.getName().equalsIgnoreCase("IMAGE_CACHE")) {
|
||||||
|
throw new XMLParseException(String.valueOf(xml.getName()) + " > Has no tag <IMAGE_CACHE>");
|
||||||
|
}
|
||||||
|
AVList params = new AVList();
|
||||||
|
for (Object child : root.getChildren()) {
|
||||||
|
if (!(child instanceof Element)) continue;
|
||||||
|
Element element = (Element)child;
|
||||||
|
if (element.getName().equalsIgnoreCase("LAYERS")) {
|
||||||
|
params.setValue("img.cache.conf.layers", ImgCacheMngr.parseLayers(element));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (element.getName().equalsIgnoreCase("CACHELOCATION")) {
|
||||||
|
params.setValue("img.cache.conf.cache.location", (Object)ImgCacheMngr.parseLoc(element));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (element.getName().equalsIgnoreCase("CACHEFORMAT")) {
|
||||||
|
CacheFormat cFormat = new CacheFormat();
|
||||||
|
for (Object attr : element.getAttributes()) {
|
||||||
|
if (!(attr instanceof Attribute)) continue;
|
||||||
|
Attribute tileformatAttr = (Attribute)attr;
|
||||||
|
if (tileformatAttr.getName().equalsIgnoreCase("WIDTH")) {
|
||||||
|
cFormat.setWidth(Integer.parseInt(tileformatAttr.getValue().trim()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (tileformatAttr.getName().equalsIgnoreCase("HEIGHT")) {
|
||||||
|
cFormat.setHeight(Integer.parseInt(tileformatAttr.getValue().trim()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!tileformatAttr.getName().equalsIgnoreCase("FORMAT")) continue;
|
||||||
|
cFormat.setFormat(tileformatAttr.getValue().trim());
|
||||||
|
}
|
||||||
|
params.setValue("img.cache.conf.cache.format", (Object)cFormat);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!element.getName().equalsIgnoreCase("LEVELSET")) continue;
|
||||||
|
CacheLevelSet lvlSet = new CacheLevelSet();
|
||||||
|
for (Object level : element.getChildren()) {
|
||||||
|
Element levelElement;
|
||||||
|
if (!(level instanceof Element) || !(levelElement = (Element)level).getName().equalsIgnoreCase("LEVEL")) continue;
|
||||||
|
lvlSet.addLevel(ImgCacheMngr.parseLevel(levelElement));
|
||||||
|
}
|
||||||
|
params.setValue("img.cache.conf.cache.levelset", (Object)lvlSet);
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CacheLevel parseLevel(Element ele) throws Exception {
|
||||||
|
Integer level = null;
|
||||||
|
Double resoltution = null;
|
||||||
|
Double scale = null;
|
||||||
|
for (Object attr : ele.getAttributes()) {
|
||||||
|
if (!(attr instanceof Attribute)) continue;
|
||||||
|
Attribute matrixAttr = (Attribute)attr;
|
||||||
|
if (matrixAttr.getName().equalsIgnoreCase("LEVEL")) {
|
||||||
|
level = Integer.parseInt(matrixAttr.getValue().trim());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (matrixAttr.getName().equalsIgnoreCase("RESOLUTION")) {
|
||||||
|
resoltution = Double.parseDouble(matrixAttr.getValue().trim());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!matrixAttr.getName().equalsIgnoreCase("SCALE")) continue;
|
||||||
|
scale = Double.parseDouble(matrixAttr.getValue().trim());
|
||||||
|
}
|
||||||
|
if (level == null) {
|
||||||
|
throw new XMLParseException("<MATRIX> Attribute value [LAVEL] is null.");
|
||||||
|
}
|
||||||
|
if (resoltution == null && scale == null) {
|
||||||
|
throw new XMLParseException("<MATRIX> Attribute value [RESOLUTION,SCALE] is null.");
|
||||||
|
}
|
||||||
|
return new CacheLevel(level, resoltution, scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ReferencedEnvelope parseExtent(Element bbox) throws Exception {
|
||||||
|
String crsName = null;
|
||||||
|
for (Object attr : bbox.getAttributes()) {
|
||||||
|
Attribute bboxAttr;
|
||||||
|
if (!(attr instanceof Attribute) || !(bboxAttr = (Attribute)attr).getName().equalsIgnoreCase("CRS")) continue;
|
||||||
|
crsName = bboxAttr.getValue().trim().toUpperCase();
|
||||||
|
}
|
||||||
|
CoordinateReferenceSystem crs = CRSMngr.getCRS(crsName);
|
||||||
|
if (crs == null) {
|
||||||
|
throw new XMLParseException("<" + bbox.getName() + "> Attribute value [CRS] is Not Available. :: [" + crsName + "] is not Exists.");
|
||||||
|
}
|
||||||
|
double minX = 0.0;
|
||||||
|
double minY = 0.0;
|
||||||
|
double maxX = 0.0;
|
||||||
|
double maxY = 0.0;
|
||||||
|
for (Object subChild : bbox.getChildren()) {
|
||||||
|
String[] coord;
|
||||||
|
if (!(subChild instanceof Element)) continue;
|
||||||
|
Element subElement = (Element)subChild;
|
||||||
|
if (subElement.getName().equalsIgnoreCase("LOWERCORNER")) {
|
||||||
|
coord = subElement.getTextTrim().split(",");
|
||||||
|
if (coord.length != 2) {
|
||||||
|
coord = subElement.getTextTrim().split("\\s+");
|
||||||
|
}
|
||||||
|
if (coord.length != 2) {
|
||||||
|
throw new XMLParseException("<LOWERCORNER> value is Not Coordinate. :: " + subElement.getText());
|
||||||
|
}
|
||||||
|
minX = Double.parseDouble(coord[0]);
|
||||||
|
minY = Double.parseDouble(coord[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!subElement.getName().equalsIgnoreCase("UPPERCORNER")) continue;
|
||||||
|
coord = subElement.getTextTrim().split(",");
|
||||||
|
if (coord.length != 2) {
|
||||||
|
coord = subElement.getTextTrim().split("\\s+");
|
||||||
|
}
|
||||||
|
if (coord.length != 2) {
|
||||||
|
throw new XMLParseException("<UPPERCORNER> value is Not Coordinate. :: " + subElement.getText());
|
||||||
|
}
|
||||||
|
maxX = Double.parseDouble(coord[0]);
|
||||||
|
maxY = Double.parseDouble(coord[1]);
|
||||||
|
}
|
||||||
|
return new ReferencedEnvelope(minX, maxX, minY, maxY, crs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File parseLoc(Element ele) throws IOException {
|
||||||
|
File dir = new File(ele.getTextTrim());
|
||||||
|
if (dir.exists()) {
|
||||||
|
for (Object attr : ele.getAttributes()) {
|
||||||
|
Attribute layerAttr;
|
||||||
|
if (!(attr instanceof Attribute) || !(layerAttr = (Attribute)attr).getName().equalsIgnoreCase("CLEARBEFORE") || !ServerUtil.getBooleanValue((String)layerAttr.getValue())) continue;
|
||||||
|
ServerUtil.removeFile((File)dir, (boolean)true);
|
||||||
|
}
|
||||||
|
} else if (!dir.mkdirs()) {
|
||||||
|
throw new IOException("Can't access CacheLocation [" + dir.getAbsolutePath() + "]");
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArrayList<ImgCacheLayer> parseLayers(Element ele) throws IOException {
|
||||||
|
ArrayList<ImgCacheLayer> layers = new ArrayList<ImgCacheLayer>();
|
||||||
|
for (Object child : ele.getChildren()) {
|
||||||
|
Element layer;
|
||||||
|
if (!(child instanceof Element) || !(layer = (Element)child).getName().equalsIgnoreCase("LAYER")) continue;
|
||||||
|
String name = null;
|
||||||
|
String style = "DEFAULT";
|
||||||
|
for (Object attr : layer.getAttributes()) {
|
||||||
|
if (!(attr instanceof Attribute)) continue;
|
||||||
|
Attribute layerAttr = (Attribute)attr;
|
||||||
|
if (layerAttr.getName().equalsIgnoreCase("NAME")) {
|
||||||
|
name = layerAttr.getValue().trim();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!layerAttr.getName().equalsIgnoreCase("STYLE")) continue;
|
||||||
|
style = layerAttr.getValue().trim();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
layers.add(new ImgCacheLayer(name, style));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[IMGCACHE]", "Layer name [" + name + "] has problem :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (layers.size() == 0) {
|
||||||
|
throw new IOException("LAYER count is zero.");
|
||||||
|
}
|
||||||
|
return layers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void reloadLayer() throws Exception {
|
||||||
|
try {
|
||||||
|
dirtyCacheLayerStore = cacheLayerStore;
|
||||||
|
ImgCacheMngr.initLayers();
|
||||||
|
dirtyCacheLayerStore.clear();
|
||||||
|
dirtyCacheLayerStore = null;
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Success to reload ImgCache Layer.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[IMGCACHE]", "Fail to reload ImgCache Layer. Now use previous ImgCache Layer :: " + e);
|
||||||
|
cacheLayerStore = dirtyCacheLayerStore;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImgCacheLayer getImgCacheLayer(String id) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)id)) {
|
||||||
|
throw new NullPointerException("ID value is NULL.");
|
||||||
|
}
|
||||||
|
ImgCacheLayer layer = cacheLayerStore.get(id.trim().toUpperCase());
|
||||||
|
if (layer == null) {
|
||||||
|
throw new NullPointerException("Layer [" + id.trim() + "] is not exist in ImageCache Service.");
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public static void removeImgCache(String id) throws Exception {
|
||||||
|
ConcurrentHashMap<String, ImgCacheLayer> concurrentHashMap = cacheLayerStore;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
ImgCacheLayer layer = ImgCacheMngr.getImgCacheLayer(id);
|
||||||
|
ServerUtil.removeFile((File)layer.getCacheDir(), (boolean)true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.opengis.filter.identity.FeatureId;
|
||||||
|
|
||||||
|
class InsertParams
|
||||||
|
{
|
||||||
|
public String sqlString;
|
||||||
|
public Double maxValue;
|
||||||
|
public ArrayList<FeatureId> featureIDs = new ArrayList();
|
||||||
|
|
||||||
|
public InsertParams(String sql, Double max) {
|
||||||
|
this.sqlString = sql;
|
||||||
|
this.maxValue = max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,524 +10,456 @@ import java.sql.Statement;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.geotools.data.DataAccessFactory.Param;
|
|
||||||
import org.geotools.jdbc.JDBCDataStore;
|
import org.geotools.jdbc.JDBCDataStore;
|
||||||
import org.geotools.referencing.CRS;
|
import org.geotools.referencing.CRS;
|
||||||
import org.geotools.styling.StyledLayerDescriptor;
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
public class JdbcStoreMngr
|
public class JdbcStoreMngr {
|
||||||
{
|
private static ConcurrentHashMap<String, JDBCDataStore> dataStores = new ConcurrentHashMap();
|
||||||
private static ConcurrentHashMap<String, JDBCDataStore> dataStores = new ConcurrentHashMap();
|
private static ConcurrentHashMap<String, JDBCDataStore> dirtyDataStores;
|
||||||
private static ConcurrentHashMap<String, JDBCDataStore> dirtyDataStores;
|
public static final String DEFAULT_PK_COLUMN = "GID";
|
||||||
public static final String DEFAULT_PK_COLUMN = "GID";
|
public static final Boolean DEFAULT_USE_SPATIAL;
|
||||||
public static final Boolean DEFAULT_USE_SPATIAL = Boolean.valueOf(true);
|
public static final int DEFAULT_MIN_CONN = 10;
|
||||||
public static final int DEFAULT_MIN_CONN = 10;
|
public static final int DEFAULT_MAX_CONN = 25;
|
||||||
public static final int DEFAULT_MAX_CONN = 25;
|
public static final int DEFAULT_FETCH_SIZE = 50;
|
||||||
public static final int DEFAULT_FETCH_SIZE = 50;
|
public static final int DEFAULT_CONN_TIMEOUT = 30;
|
||||||
public static final int DEFAULT_CONN_TIMEOUT = 30;
|
public static final int DEFAULT_PS_CACHE_SIZE = 100;
|
||||||
public static final int DEFAULT_PS_CACHE_SIZE = 100;
|
public static final Boolean DEFAULT_EXPOSE_PK;
|
||||||
public static final Boolean DEFAULT_EXPOSE_PK = Boolean.TRUE;
|
|
||||||
|
|
||||||
public static synchronized void initLayers()
|
static {
|
||||||
{
|
DEFAULT_USE_SPATIAL = true;
|
||||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
DEFAULT_EXPOSE_PK = Boolean.TRUE;
|
||||||
LogMngr.getInstance().logInfo("[JDBC]", "Init JDBC Connections");
|
|
||||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
|
||||||
initDataStore();
|
|
||||||
|
|
||||||
if (dataStores.size() == 0) {
|
|
||||||
LogMngr.getInstance().logError("[JDBC]",
|
|
||||||
"Fail to create JdbcLayer :: JdbcDataStore size is ZERO[0]");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
public static synchronized void initLayers() {
|
||||||
LogMngr.getInstance().logInfo("[JDBC]", "Init JDBC Layers");
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
LogMngr.getInstance().logInfo("[JDBC]", "Init JDBC Connections");
|
||||||
initJdbcLayer();
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
}
|
JdbcStoreMngr.initDataStore();
|
||||||
|
if (dataStores.size() == 0) {
|
||||||
private static void initDataStore()
|
LogMngr.getInstance().logError("[JDBC]", "Fail to create JdbcLayer :: JdbcDataStore size is ZERO[0]");
|
||||||
{
|
return;
|
||||||
dataStores = new ConcurrentHashMap();
|
|
||||||
|
|
||||||
Connection conn = null;
|
|
||||||
Statement st = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
|
|
||||||
synchronized (dataStores)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
conn = ConnMngr.getInstance().openConn();
|
|
||||||
st = conn.createStatement();
|
|
||||||
|
|
||||||
String sql = "SELECT * FROM O2MAP_SERVER_INFO";
|
|
||||||
LogMngr.getInstance().logDebug("[JDBC]", "Load configuration info :: SQL> " + sql);
|
|
||||||
|
|
||||||
rs = st.executeQuery(sql);
|
|
||||||
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
String sName = rs.getString("SERVER_NAME").trim().toUpperCase();
|
|
||||||
String sType = rs.getString("SERVER_TYPE").trim().toUpperCase();
|
|
||||||
|
|
||||||
String sIP = rs.getString("SERVER_IP".trim());
|
|
||||||
String sPort = rs.getString("SERVER_PORT").trim();
|
|
||||||
String database = rs.getString("DATABASE_NAME").trim();
|
|
||||||
|
|
||||||
String dbUser = rs.getString("DB_USER").trim();
|
|
||||||
String dbPass = rs.getString("DB_PASSWD").trim();
|
|
||||||
|
|
||||||
if (ServerContext.isEncryption()) {
|
|
||||||
sIP = EncryptUtil.decrypt(sIP, "wldhxn");
|
|
||||||
sPort = EncryptUtil.decrypt(sPort, "wldhxn");
|
|
||||||
database = EncryptUtil.decrypt(database, "wldhxn");
|
|
||||||
|
|
||||||
dbUser = EncryptUtil.decrypt(dbUser, "wldhxn");
|
|
||||||
dbPass = EncryptUtil.decrypt(dbPass, "wldhxn");
|
|
||||||
}
|
|
||||||
|
|
||||||
String pkCol = "GID";
|
|
||||||
String tStr = rs.getString("PK_COLUMN");
|
|
||||||
if (tStr != null) {
|
|
||||||
pkCol = tStr.trim().toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean useSpatial = DEFAULT_USE_SPATIAL.booleanValue();
|
|
||||||
tStr = rs.getString("USE_SPATIAL").trim();
|
|
||||||
if ((!ServerUtil.isNullString(tStr)) && (tStr.equalsIgnoreCase("N"))) {
|
|
||||||
useSpatial = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int minConn = 10;
|
|
||||||
try {
|
|
||||||
minConn = Integer.parseInt(rs.getString("MIN_CONN"));
|
|
||||||
} catch (Exception localException1) {
|
|
||||||
}
|
|
||||||
int maxConn = 25;
|
|
||||||
try {
|
|
||||||
maxConn = Integer.parseInt(rs.getString("MAX_CONN"));
|
|
||||||
} catch (Exception localException2) {
|
|
||||||
}
|
|
||||||
int fetchSize = 50;
|
|
||||||
try {
|
|
||||||
fetchSize = Integer.parseInt(rs.getString("FETCH_SIZE"));
|
|
||||||
}
|
|
||||||
catch (Exception localException3)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap params = new HashMap();
|
|
||||||
params.put(O2DSFactory.DBTYPE.key, sType);
|
|
||||||
params.put(O2DSFactory.HOST.key, sIP);
|
|
||||||
params.put(O2DSFactory.PORT.key, Integer.valueOf(sPort));
|
|
||||||
params.put(O2DSFactory.DATABASE.key, database);
|
|
||||||
params.put(O2DSFactory.USER.key, dbUser);
|
|
||||||
params.put(O2DSFactory.PASSWD.key, dbPass);
|
|
||||||
|
|
||||||
params.put(O2DSFactory.MINCONN.key, Integer.valueOf(minConn));
|
|
||||||
params.put(O2DSFactory.MAXCONN.key, Integer.valueOf(maxConn));
|
|
||||||
params.put(O2DSFactory.MAXWAIT.key, Integer.valueOf(30));
|
|
||||||
params.put(O2DSFactory.VALIDATECONN.key, Boolean.FALSE);
|
|
||||||
|
|
||||||
params.put(O2DSFactory.FETCHSIZE.key, Integer.valueOf(fetchSize));
|
|
||||||
params.put(O2DSFactory.MAX_OPEN_PREPARED_STATEMENTS.key, Integer.valueOf(100));
|
|
||||||
|
|
||||||
params.put(O2DSFactory.EXPOSE_PK.key, DEFAULT_EXPOSE_PK);
|
|
||||||
params.put(O2DSFactory.NAMESPACE.key, ServerContext.getMap().getNameSpaceURI());
|
|
||||||
|
|
||||||
params.put(O2DSFactory.O2_SERVER_NAME.key, sName);
|
|
||||||
params.put(O2DSFactory.O2_PK_COLUMN_NAME.key, pkCol);
|
|
||||||
params.put(O2DSFactory.O2_USE_SPATIAL.key, Boolean.valueOf(useSpatial));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logDebug("[JDBC]", "Crate Jdbc DataStore :: " + params);
|
|
||||||
|
|
||||||
JDBCDataStore ds = new O2DSFactory(params).getDataStore();
|
|
||||||
ds.getTypeNames();
|
|
||||||
|
|
||||||
dataStores.put(sName, ds);
|
|
||||||
|
|
||||||
LogMngr.getInstance().logInfo("[JDBC]", "Success to add Jdbc DataStore [" + sName + "]");
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[JDBC]", "Fail to add Jdbc DataStore [" + sName + "] :: " + e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
catch (Exception e)
|
LogMngr.getInstance().logInfo("[JDBC]", "Init JDBC Layers");
|
||||||
{
|
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||||
LogMngr.getInstance().logError("[JDBC]", "Fail to create JdbcDataStore :: " + e);
|
JdbcStoreMngr.initJdbcLayer();
|
||||||
LogMngr.getInstance().logError("[JDBC]", "Please find and check O2MAP_SERVER_INFO table");
|
|
||||||
} finally {
|
|
||||||
ConnMngr.getInstance().closeConn();
|
|
||||||
ConnMngr.getInstance().closeSafe(st);
|
|
||||||
ConnMngr.getInstance().closeSafe(rs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void initJdbcLayer()
|
/*
|
||||||
{
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
Connection connection = null;
|
*/
|
||||||
Statement stmt = null;
|
private static void initDataStore() {
|
||||||
ResultSet rs = null;
|
dataStores = new ConcurrentHashMap();
|
||||||
InputStream is = null;
|
Connection conn = null;
|
||||||
try
|
Statement st = null;
|
||||||
{
|
ResultSet rs = null;
|
||||||
if (ServerContext.getMap().getServiceLayerSet().getLayers().size() != 0) {
|
ConcurrentHashMap<String, JDBCDataStore> concurrentHashMap = dataStores;
|
||||||
LogMngr.getInstance().logWarn("[JDBC]", "**************************");
|
synchronized (concurrentHashMap) {
|
||||||
LogMngr.getInstance().logWarn("[JDBC]",
|
block20: {
|
||||||
"* This ServiceMap [" + ServerContext.getMap().getName() + "] already has service layers [" + ServerContext.getMap().getServiceLayerSet().getLayers().size() + "]");
|
try {
|
||||||
LogMngr.getInstance().logWarn("[JDBC]",
|
try {
|
||||||
"* JdbcLayer does not allow duplicate service. please check this.");
|
conn = ConnMngr.getInstance().openConn();
|
||||||
LogMngr.getInstance().logWarn("[JDBC]", "**************************");
|
st = conn.createStatement();
|
||||||
}
|
String sql = "SELECT * FROM O2MAP_SERVER_INFO";
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Load configuration info :: SQL> " + sql);
|
||||||
connection = ConnMngr.getInstance().openConn();
|
rs = st.executeQuery(sql);
|
||||||
stmt = connection.createStatement();
|
while (rs.next()) {
|
||||||
|
String sName = rs.getString("SERVER_NAME").trim().toUpperCase();
|
||||||
String sql = "SELECT * FROM O2MAP_SERVICE_INFO";
|
String sType = rs.getString("SERVER_TYPE").trim().toUpperCase();
|
||||||
|
String sIP = rs.getString("SERVER_IP".trim());
|
||||||
LogMngr.getInstance().logDebug("[JDBC]", "Load layers info :: SQL > " + sql);
|
String sPort = rs.getString("SERVER_PORT").trim();
|
||||||
|
String database = rs.getString("DATABASE_NAME").trim();
|
||||||
rs = stmt.executeQuery(sql);
|
String dbUser = rs.getString("DB_USER").trim();
|
||||||
|
String dbPass = rs.getString("DB_PASSWD").trim();
|
||||||
int count = 0;
|
if (ServerContext.isEncryption()) {
|
||||||
ArrayList grpList = new ArrayList();
|
sIP = EncryptUtil.decrypt((String)sIP, (String)"wldhxn");
|
||||||
if (rs != null) {
|
sPort = EncryptUtil.decrypt((String)sPort, (String)"wldhxn");
|
||||||
while (rs.next())
|
database = EncryptUtil.decrypt((String)database, (String)"wldhxn");
|
||||||
{
|
dbUser = EncryptUtil.decrypt((String)dbUser, (String)"wldhxn");
|
||||||
LogMngr.getInstance().logDebug("[JDBC]", "");
|
dbPass = EncryptUtil.decrypt((String)dbPass, (String)"wldhxn");
|
||||||
|
}
|
||||||
String mapName = rs.getString("MAP_NAME");
|
String pkCol = DEFAULT_PK_COLUMN;
|
||||||
if (ServerUtil.isNullString(mapName)) {
|
String tStr = rs.getString("PK_COLUMN");
|
||||||
LogMngr.getInstance().logDebug("[JDBC]", "Skip create layer :: MAP_NAME is NULL");
|
if (tStr != null) {
|
||||||
}
|
pkCol = tStr.trim().toUpperCase();
|
||||||
else if (!mapName.trim().equalsIgnoreCase(ServerContext.getMap().getName())) {
|
}
|
||||||
LogMngr.getInstance().logDebug("[JDBC]",
|
boolean useSpatial = DEFAULT_USE_SPATIAL;
|
||||||
"Skip create layer :: MAP_NAME [" + mapName + "] is not equal ServiceMapName [" + ServerContext.getMap().getName() + "]");
|
tStr = rs.getString("USE_SPATIAL").trim();
|
||||||
}
|
if (!ServerUtil.isNullString((String)tStr) && tStr.equalsIgnoreCase("N")) {
|
||||||
else
|
useSpatial = false;
|
||||||
{
|
}
|
||||||
String layerName = rs.getString("LAYER_NAME");
|
int minConn = 10;
|
||||||
String layerType = rs.getString("LAYER_TYPE");
|
try {
|
||||||
String refServer = rs.getString("REF_SERVER");
|
minConn = Integer.parseInt(rs.getString("MIN_CONN"));
|
||||||
String refSource = rs.getString("REF_SOURCE");
|
}
|
||||||
String refSrid = rs.getString("REF_SRID");
|
catch (Exception exception) {
|
||||||
String useCache = rs.getString("USE_CACHE");
|
// empty catch block
|
||||||
String desc = rs.getString("DESCRIPTION");
|
}
|
||||||
|
int maxConn = 25;
|
||||||
StyledLayerDescriptor sld = null;
|
try {
|
||||||
try {
|
maxConn = Integer.parseInt(rs.getString("MAX_CONN"));
|
||||||
is = rs.getBinaryStream("SLD");
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
byte[] bytes = ServerUtil.cloneInputStream(is);
|
// empty catch block
|
||||||
ByteArrayInputStream cloneIs = new ByteArrayInputStream(bytes);
|
}
|
||||||
sld = StyleMngr.parseSLD(cloneIs);
|
int fetchSize = 50;
|
||||||
} catch (Exception se) {
|
try {
|
||||||
sld = null;
|
fetchSize = Integer.parseInt(rs.getString("FETCH_SIZE"));
|
||||||
}
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
Date lastUpdate = null;
|
// empty catch block
|
||||||
try {
|
}
|
||||||
lastUpdate = rs.getDate("LAST_UPDATE");
|
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||||
} catch (Exception de) {
|
params.put(O2DSFactory.DBTYPE.key, sType);
|
||||||
try {
|
params.put(O2DSFactory.HOST.key, sIP);
|
||||||
Timestamp stamp = rs.getTimestamp("LAST_UPDATE");
|
params.put(O2DSFactory.PORT.key, Integer.valueOf(sPort));
|
||||||
lastUpdate = new Date(stamp.getTime());
|
params.put(O2DSFactory.DATABASE.key, database);
|
||||||
} catch (Exception se) {
|
params.put(O2DSFactory.USER.key, dbUser);
|
||||||
lastUpdate = null;
|
params.put(O2DSFactory.PASSWD.key, dbPass);
|
||||||
}
|
params.put(O2DSFactory.MINCONN.key, minConn);
|
||||||
|
params.put(O2DSFactory.MAXCONN.key, maxConn);
|
||||||
}
|
params.put(O2DSFactory.MAXWAIT.key, 30);
|
||||||
|
params.put(O2DSFactory.VALIDATECONN.key, Boolean.FALSE);
|
||||||
AVList params = new AVList();
|
params.put(O2DSFactory.FETCHSIZE.key, fetchSize);
|
||||||
params.setValue("conf.service.map.name", mapName);
|
params.put(O2DSFactory.MAX_OPEN_PREPARED_STATEMENTS.key, 100);
|
||||||
params.setValue("conf.service.layer.name", layerName);
|
params.put(O2DSFactory.EXPOSE_PK.key, DEFAULT_EXPOSE_PK);
|
||||||
params.setValue("conf.service.ref.server", refServer);
|
params.put(O2DSFactory.NAMESPACE.key, ServerContext.getMap().getNameSpaceURI());
|
||||||
params.setValue("conf.service.ref.source", refSource);
|
params.put(O2DSFactory.O2_SERVER_NAME.key, sName);
|
||||||
params.setValue("conf.service.ref.srid", refSrid);
|
params.put(O2DSFactory.O2_PK_COLUMN_NAME.key, pkCol);
|
||||||
params.setValue("conf.service.sld", sld);
|
params.put(O2DSFactory.O2_USE_SPATIAL.key, useSpatial);
|
||||||
|
try {
|
||||||
if (ServerUtil.getBooleanValue(useCache))
|
LogMngr.getInstance().logDebug("[JDBC]", "Crate Jdbc DataStore :: " + params);
|
||||||
params.setValue("conf.service.use.cache", Boolean.valueOf(true));
|
JDBCDataStore ds = new O2DSFactory(params).getDataStore();
|
||||||
else {
|
ds.getTypeNames();
|
||||||
params.setValue("conf.service.use.cache", Boolean.valueOf(false));
|
dataStores.put(sName, ds);
|
||||||
}
|
LogMngr.getInstance().logInfo("[JDBC]", "Success to add Jdbc DataStore [" + sName + "]");
|
||||||
|
}
|
||||||
params.setValue("conf.service.last.update", lastUpdate);
|
catch (Exception e) {
|
||||||
params.setValue("conf.service.description", desc);
|
LogMngr.getInstance().logError("[JDBC]", "Fail to add Jdbc DataStore [" + sName + "] :: " + e);
|
||||||
try
|
}
|
||||||
{
|
}
|
||||||
Layer layer = null;
|
}
|
||||||
if (layerType.equalsIgnoreCase("FEA")) {
|
catch (Exception e) {
|
||||||
LogMngr.getInstance().logDebug("[JDBC]",
|
LogMngr.getInstance().logError("[JDBC]", "Fail to create JdbcDataStore :: " + e);
|
||||||
"Create FeatureLayer :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
LogMngr.getInstance().logError("[JDBC]", "Please find and check O2MAP_SERVER_INFO table");
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
if (ServerUtil.isNullString(refServer))
|
ConnMngr.getInstance().closeSafe(st);
|
||||||
throw new Exception("REF_SERVER value is NULL.");
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
if (getDataStore(refServer) == null) {
|
break block20;
|
||||||
throw new Exception("REF_SERVER [" + refServer + "] is not exists.");
|
}
|
||||||
}
|
}
|
||||||
|
catch (Throwable throwable) {
|
||||||
layer = LayerFactory.createLayer(LayerFactory.LayerType.JDBC, params); } else {
|
ConnMngr.getInstance().closeConn();
|
||||||
if (layerType.equalsIgnoreCase("GRP")) {
|
ConnMngr.getInstance().closeSafe(st);
|
||||||
grpList.add(params);
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
continue;
|
throw throwable;
|
||||||
}if (layerType.equalsIgnoreCase("WMS")) {
|
|
||||||
LogMngr.getInstance().logDebug("[JDBC]",
|
|
||||||
"Create ImageLayer :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
|
||||||
layer = LayerFactory.createLayer(LayerFactory.LayerType.WMS, params);
|
|
||||||
} else if (layerType.equalsIgnoreCase("WCS")) {
|
|
||||||
LogMngr.getInstance().logDebug("[JDBC]",
|
|
||||||
"Create CoverageLayer :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
|
||||||
layer = LayerFactory.createLayer(LayerFactory.LayerType.WCS, params);
|
|
||||||
}
|
}
|
||||||
}
|
ConnMngr.getInstance().closeConn();
|
||||||
if (layer == null) {
|
ConnMngr.getInstance().closeSafe(st);
|
||||||
throw new Exception("Layer object is NULL.");
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
}
|
|
||||||
|
|
||||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
|
||||||
count++;
|
|
||||||
|
|
||||||
LogMngr.getInstance().logInfo("[JDBC]",
|
|
||||||
"Add Layer Success :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[JDBC]",
|
|
||||||
"Add Layer Fail :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
|
||||||
LogMngr.getInstance().logError("[JDBC]", "Cause :: " + e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < grpList.size(); i++) {
|
private static void initJdbcLayer() {
|
||||||
LogMngr.getInstance().logDebug("[JDBC]",
|
block35: {
|
||||||
"Create GroupLayer :: [Map:" +
|
Connection connection = null;
|
||||||
((AVList)grpList.get(i)).getStringValue("conf.service.map.name") + "/Layer" + ((AVList)grpList.get(i)).getStringValue("conf.service.layer.name") +
|
Statement stmt = null;
|
||||||
"] : [RefServer:" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.server") + "/RefSource" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.source"));
|
ResultSet rs = null;
|
||||||
try
|
InputStream is = null;
|
||||||
{
|
try {
|
||||||
Layer layer = LayerFactory.createLayer(LayerFactory.LayerType.GROUP, (AVList)grpList.get(i));
|
try {
|
||||||
|
if (ServerContext.getMap().getServiceLayerSet().getLayers().size() != 0) {
|
||||||
if (layer == null) {
|
LogMngr.getInstance().logWarn("[JDBC]", "**************************");
|
||||||
throw new Exception("Layer object is NULL.");
|
LogMngr.getInstance().logWarn("[JDBC]", "* This ServiceMap [" + ServerContext.getMap().getName() + "] already has service layers [" + ServerContext.getMap().getServiceLayerSet().getLayers().size() + "]");
|
||||||
|
LogMngr.getInstance().logWarn("[JDBC]", "* JdbcLayer does not allow duplicate service. please check this.");
|
||||||
|
LogMngr.getInstance().logWarn("[JDBC]", "**************************");
|
||||||
|
}
|
||||||
|
connection = ConnMngr.getInstance().openConn();
|
||||||
|
stmt = connection.createStatement();
|
||||||
|
String sql = "SELECT * FROM O2MAP_SERVICE_INFO";
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Load layers info :: SQL > " + sql);
|
||||||
|
rs = stmt.executeQuery(sql);
|
||||||
|
int count = 0;
|
||||||
|
ArrayList<AVList> grpList = new ArrayList<AVList>();
|
||||||
|
if (rs != null) {
|
||||||
|
while (rs.next()) {
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "");
|
||||||
|
String mapName = rs.getString("MAP_NAME");
|
||||||
|
if (ServerUtil.isNullString((String)mapName)) {
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Skip create layer :: MAP_NAME is NULL");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!mapName.trim().equalsIgnoreCase(ServerContext.getMap().getName())) {
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Skip create layer :: MAP_NAME [" + mapName + "] is not equal ServiceMapName [" + ServerContext.getMap().getName() + "]");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String layerName = rs.getString("LAYER_NAME");
|
||||||
|
String layerType = rs.getString("LAYER_TYPE");
|
||||||
|
String refServer = rs.getString("REF_SERVER");
|
||||||
|
String refSource = rs.getString("REF_SOURCE");
|
||||||
|
String refSrid = rs.getString("REF_SRID");
|
||||||
|
String useCache = rs.getString("USE_CACHE");
|
||||||
|
String desc = rs.getString("DESCRIPTION");
|
||||||
|
StyledLayerDescriptor sld = null;
|
||||||
|
try {
|
||||||
|
is = rs.getBinaryStream("SLD");
|
||||||
|
byte[] bytes = ServerUtil.cloneInputStream((InputStream)is);
|
||||||
|
ByteArrayInputStream cloneIs = new ByteArrayInputStream(bytes);
|
||||||
|
sld = StyleMngr.parseSLD((InputStream)cloneIs);
|
||||||
|
}
|
||||||
|
catch (Exception se) {
|
||||||
|
sld = null;
|
||||||
|
}
|
||||||
|
Date lastUpdate = null;
|
||||||
|
try {
|
||||||
|
lastUpdate = rs.getDate("LAST_UPDATE");
|
||||||
|
}
|
||||||
|
catch (Exception de) {
|
||||||
|
try {
|
||||||
|
Timestamp stamp = rs.getTimestamp("LAST_UPDATE");
|
||||||
|
lastUpdate = new Date(stamp.getTime());
|
||||||
|
}
|
||||||
|
catch (Exception se) {
|
||||||
|
lastUpdate = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AVList params = new AVList();
|
||||||
|
params.setValue("conf.service.map.name", (Object)mapName);
|
||||||
|
params.setValue("conf.service.layer.name", (Object)layerName);
|
||||||
|
params.setValue("conf.service.ref.server", (Object)refServer);
|
||||||
|
params.setValue("conf.service.ref.source", (Object)refSource);
|
||||||
|
params.setValue("conf.service.ref.srid", (Object)refSrid);
|
||||||
|
params.setValue("conf.service.sld", (Object)sld);
|
||||||
|
if (ServerUtil.getBooleanValue((String)useCache)) {
|
||||||
|
params.setValue("conf.service.use.cache", (Object)true);
|
||||||
|
} else {
|
||||||
|
params.setValue("conf.service.use.cache", (Object)false);
|
||||||
|
}
|
||||||
|
params.setValue("conf.service.last.update", (Object)lastUpdate);
|
||||||
|
params.setValue("conf.service.description", (Object)desc);
|
||||||
|
try {
|
||||||
|
Layer layer = null;
|
||||||
|
if (layerType.equalsIgnoreCase("FEA")) {
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Create FeatureLayer :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||||
|
if (ServerUtil.isNullString((String)refServer)) {
|
||||||
|
throw new Exception("REF_SERVER value is NULL.");
|
||||||
|
}
|
||||||
|
if (JdbcStoreMngr.getDataStore(refServer) == null) {
|
||||||
|
throw new Exception("REF_SERVER [" + refServer + "] is not exists.");
|
||||||
|
}
|
||||||
|
layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.JDBC, (AVList)params);
|
||||||
|
} else {
|
||||||
|
if (layerType.equalsIgnoreCase("GRP")) {
|
||||||
|
grpList.add(params);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (layerType.equalsIgnoreCase("WMS")) {
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Create ImageLayer :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||||
|
layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.WMS, (AVList)params);
|
||||||
|
} else if (layerType.equalsIgnoreCase("WCS")) {
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Create CoverageLayer :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||||
|
layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.WCS, (AVList)params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (layer == null) {
|
||||||
|
throw new Exception("Layer object is NULL.");
|
||||||
|
}
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||||
|
++count;
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "Add Layer Success :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Add Layer Fail :: [Map:" + mapName + "/Layer:" + layerName + "] : [RefServer:" + refServer + "/RefSource:" + refSource + "]");
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Cause :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
while (i < grpList.size()) {
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "Create GroupLayer :: [Map:" + ((AVList)grpList.get(i)).getStringValue("conf.service.map.name") + "/Layer" + ((AVList)grpList.get(i)).getStringValue("conf.service.layer.name") + "] : [RefServer:" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.server") + "/RefSource" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.source"));
|
||||||
|
try {
|
||||||
|
Layer layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.GROUP, (AVList)((AVList)grpList.get(i)));
|
||||||
|
if (layer == null) {
|
||||||
|
throw new Exception("Layer object is NULL.");
|
||||||
|
}
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||||
|
++count;
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "Add Layer Success :: [Map:" + ((AVList)grpList.get(i)).getStringValue("conf.service.map.name") + "/Layer" + ((AVList)grpList.get(i)).getStringValue("conf.service.layer.name") + "] : [RefServer:" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.server") + "/RefSource" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.source"));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Add Layer Fail :: [Map:" + ((AVList)grpList.get(i)).getStringValue("conf.service.map.name") + "/Layer" + ((AVList)grpList.get(i)).getStringValue("conf.service.layer.name") + "] : [RefServer:" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.server") + "/RefSource" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.source"));
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Cause :: " + e);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[JDBC]", "");
|
||||||
|
if (count == 0) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Create JdbcLayer Fail :: JdbcLayer size is ZERO[0]");
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logInfo("[JDBC]", "Create JdbcLayer Success :: JdbcLayer Count is [" + count + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Fail to create JdbcLayer :: " + e);
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Please find and check O2MAP_SERVICE_INFO table");
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
|
ConnMngr.getInstance().closeSafe(stmt);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
|
break block35;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (Throwable throwable) {
|
||||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
ConnMngr.getInstance().closeConn();
|
||||||
count++;
|
ConnMngr.getInstance().closeSafe(stmt);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
LogMngr.getInstance().logInfo("[JDBC]",
|
throw throwable;
|
||||||
"Add Layer Success :: [Map:" +
|
}
|
||||||
((AVList)grpList.get(i)).getStringValue("conf.service.map.name") + "/Layer" + ((AVList)grpList.get(i)).getStringValue("conf.service.layer.name") +
|
ConnMngr.getInstance().closeConn();
|
||||||
"] : [RefServer:" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.server") + "/RefSource" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.source"));
|
ConnMngr.getInstance().closeSafe(stmt);
|
||||||
}
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[JDBC]",
|
|
||||||
"Add Layer Fail :: [Map:" +
|
|
||||||
((AVList)grpList.get(i)).getStringValue("conf.service.map.name") + "/Layer" + ((AVList)grpList.get(i)).getStringValue("conf.service.layer.name") +
|
|
||||||
"] : [RefServer:" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.server") + "/RefSource" + ((AVList)grpList.get(i)).getStringValue("conf.service.ref.source"));
|
|
||||||
LogMngr.getInstance().logError("[JDBC]", "Cause :: " + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[JDBC]", "");
|
|
||||||
|
|
||||||
if (count == 0)
|
|
||||||
LogMngr.getInstance().logError("[JDBC]",
|
|
||||||
"Create JdbcLayer Fail :: JdbcLayer size is ZERO[0]");
|
|
||||||
else
|
|
||||||
LogMngr.getInstance().logInfo("[JDBC]",
|
|
||||||
"Create JdbcLayer Success :: JdbcLayer Count is [" + count + "]");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logError("[JDBC]", "Fail to create JdbcLayer :: " + e);
|
|
||||||
LogMngr.getInstance().logError("[JDBC]",
|
|
||||||
"Please find and check O2MAP_SERVICE_INFO table");
|
|
||||||
} finally {
|
|
||||||
ConnMngr.getInstance().closeConn();
|
|
||||||
ConnMngr.getInstance().closeSafe(stmt);
|
|
||||||
ConnMngr.getInstance().closeSafe(rs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FeatureLayer addLayer(String storeName, String layerName, String layerSource, String crsCode, String desc)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
JDBCDataStore store = getDataStore(storeName);
|
|
||||||
if (store == null) {
|
|
||||||
throw new IOException("JdbcLayer DataStore is not exist [" + storeName + "]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ServerUtil.isNullString(layerName))
|
public static FeatureLayer addLayer(String storeName, String layerName, String layerSource, String crsCode, String desc) throws Exception {
|
||||||
throw new IOException("JdbcLayer LayerName is null");
|
JDBCDataStore store = JdbcStoreMngr.getDataStore(storeName);
|
||||||
if (ServerContext.getMap().getServiceLayerSet().isExistLayer(layerName)) {
|
if (store == null) {
|
||||||
throw new IOException("JdbcLayer LayerName [" + layerName + "] is already exist");
|
throw new IOException("JdbcLayer DataStore is not exist [" + storeName + "]");
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)layerName)) {
|
||||||
|
throw new IOException("JdbcLayer LayerName is null");
|
||||||
|
}
|
||||||
|
if (ServerContext.getMap().getServiceLayerSet().isExistLayer(layerName)) {
|
||||||
|
throw new IOException("JdbcLayer LayerName [" + layerName + "] is already exist");
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)layerSource)) {
|
||||||
|
throw new IOException("JdbcLayer LayerSource is null");
|
||||||
|
}
|
||||||
|
layerSource = layerSource.trim().toUpperCase();
|
||||||
|
List<String> layers = Arrays.asList(store.getTypeNames());
|
||||||
|
if (!layers.contains(layerSource)) {
|
||||||
|
throw new IOException("JdbcLayer LayerSource [" + layerSource + "] is not exist in this JdbcDataStore [" + storeName + "]");
|
||||||
|
}
|
||||||
|
CoordinateReferenceSystem crs = CRSMngr.getCRS((String)crsCode, (boolean)true);
|
||||||
|
if (crs == null) {
|
||||||
|
crs = CRS.decode((String)"4326");
|
||||||
|
}
|
||||||
|
AVList params = new AVList();
|
||||||
|
params.setValue("conf.service.map.name", (Object)ServerContext.getMap().getName());
|
||||||
|
params.setValue("conf.service.layer.name", (Object)layerName);
|
||||||
|
params.setValue("conf.service.ref.server", (Object)storeName);
|
||||||
|
params.setValue("conf.service.ref.source", (Object)layerSource);
|
||||||
|
params.setValue("conf.service.ref.crs", (Object)crs);
|
||||||
|
params.setValue("conf.service.sld", null);
|
||||||
|
params.setValue("conf.service.use.cache", (Object)false);
|
||||||
|
params.setValue("conf.service.last.update", null);
|
||||||
|
params.setValue("conf.service.description", (Object)desc);
|
||||||
|
Layer layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.JDBC, (AVList)params);
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||||
|
return (FeatureLayer)layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ServerUtil.isNullString(layerSource)) {
|
public static synchronized void reloadLayer() throws Exception {
|
||||||
throw new IOException("JdbcLayer LayerSource is null");
|
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC);
|
||||||
}
|
try {
|
||||||
layerSource = layerSource.trim().toUpperCase();
|
dirtyDataStores = dataStores;
|
||||||
|
JdbcStoreMngr.initLayers();
|
||||||
List layers = Arrays.asList(store.getTypeNames());
|
JdbcStoreMngr.disposeDirtyDataStores();
|
||||||
if (!layers.contains(layerSource)) {
|
LogMngr.getInstance().logInfo("[JDBC]", "Success to reload JdbcStore.");
|
||||||
throw new IOException("JdbcLayer LayerSource [" + layerSource + "] is not exist in this JdbcDataStore [" + storeName + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CoordinateReferenceSystem crs = CRSMngr.getCRS(crsCode, true);
|
|
||||||
if (crs == null) {
|
|
||||||
crs = CRS.decode("4326");
|
|
||||||
}
|
|
||||||
|
|
||||||
AVList params = new AVList();
|
|
||||||
params.setValue("conf.service.map.name", ServerContext.getMap().getName());
|
|
||||||
params.setValue("conf.service.layer.name", layerName);
|
|
||||||
params.setValue("conf.service.ref.server", storeName);
|
|
||||||
params.setValue("conf.service.ref.source", layerSource);
|
|
||||||
params.setValue("conf.service.ref.crs", crs);
|
|
||||||
params.setValue("conf.service.sld", null);
|
|
||||||
params.setValue("conf.service.use.cache", Boolean.valueOf(false));
|
|
||||||
params.setValue("conf.service.last.update", null);
|
|
||||||
params.setValue("conf.service.description", desc);
|
|
||||||
|
|
||||||
Layer layer = LayerFactory.createLayer(LayerFactory.LayerType.JDBC, params);
|
|
||||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
|
||||||
|
|
||||||
return (FeatureLayer)layer;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized void reloadLayer()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
dirtyDataStores = dataStores;
|
|
||||||
initLayers();
|
|
||||||
disposeDirtyDataStores();
|
|
||||||
|
|
||||||
LogMngr.getInstance().logInfo("[JDBC]", "Success to reload JdbcStore.");
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[JDBC]", "Fail to reload JdbcStore. Now use previous JdbcStore :: " + e);
|
|
||||||
|
|
||||||
dataStores = dirtyDataStores;
|
|
||||||
ServerContext.getMap().getServiceLayerSet().addLayers(oldLayers, false);
|
|
||||||
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JDBCDataStore getDataStore(String storeName)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
if (ServerUtil.isNullString(storeName))
|
|
||||||
throw new IllegalArgumentException("Parameter StoreName is NULL.");
|
|
||||||
if (dataStores.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (JDBCDataStore)dataStores.get(storeName.trim().toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized void disposeDirtyDataStores()
|
|
||||||
{
|
|
||||||
if (dirtyDataStores == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator iter = dirtyDataStores.values().iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
JDBCDataStore store = (JDBCDataStore)iter.next();
|
|
||||||
store.dispose();
|
|
||||||
|
|
||||||
store = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
dirtyDataStores.clear();
|
|
||||||
dirtyDataStores = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized void disposeDataStores()
|
|
||||||
{
|
|
||||||
if (dataStores.isEmpty()) return;
|
|
||||||
|
|
||||||
synchronized (dataStores)
|
|
||||||
{
|
|
||||||
for (String storeName : dataStores.keySet()) {
|
|
||||||
JDBCDataStore store = (JDBCDataStore)dataStores.get(storeName);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC, storeName);
|
|
||||||
|
|
||||||
store.dispose();
|
|
||||||
store = null;
|
|
||||||
|
|
||||||
dataStores.remove(storeName);
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
LogMngr.getInstance().logError("[JDBC]",
|
LogMngr.getInstance().logError("[JDBC]", "Fail to reload JdbcStore. Now use previous JdbcStore :: " + e);
|
||||||
"Fail to dispose DataStore :: Can't remove layer linked this DataStore :: " + e);
|
dataStores = dirtyDataStores;
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayers(oldLayers, false);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized boolean disposeDataStore(String storeName)
|
|
||||||
{
|
|
||||||
if (ServerUtil.isNullString(storeName)) {
|
|
||||||
LogMngr.getInstance().logError("[JDBC]", "Parameter StoreName is NULL");
|
|
||||||
return false;
|
|
||||||
}if (dataStores.isEmpty()) {
|
|
||||||
LogMngr.getInstance().logError("[JDBC]", "DataStore is NULL");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
storeName = storeName.trim().toUpperCase();
|
public static JDBCDataStore getDataStore(String storeName) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)storeName)) {
|
||||||
synchronized (dataStores)
|
throw new IllegalArgumentException("Parameter StoreName is NULL.");
|
||||||
{
|
}
|
||||||
JDBCDataStore store = (JDBCDataStore)dataStores.get(storeName);
|
if (dataStores.isEmpty()) {
|
||||||
if (store == null) {
|
return null;
|
||||||
LogMngr.getInstance().logError("[JDBC]", "DataStore [" + storeName + "] is not exist");
|
}
|
||||||
return false;
|
return dataStores.get(storeName.trim().toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
public static synchronized void disposeDirtyDataStores() {
|
||||||
{
|
if (dirtyDataStores == null) {
|
||||||
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC, storeName);
|
return;
|
||||||
|
}
|
||||||
store.dispose();
|
for (JDBCDataStore store : dirtyDataStores.values()) {
|
||||||
store = null;
|
store.dispose();
|
||||||
|
Object var1_1 = null;
|
||||||
dataStores.remove(storeName);
|
}
|
||||||
|
dirtyDataStores.clear();
|
||||||
return true;
|
dirtyDataStores = null;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[JDBC]",
|
/*
|
||||||
"Fail to remove layer linked this DataStore :: " + e);
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
return false;
|
public static synchronized void disposeDataStores() {
|
||||||
}
|
if (dataStores.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ConcurrentHashMap<String, JDBCDataStore> concurrentHashMap = dataStores;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
for (String storeName : dataStores.keySet()) {
|
||||||
|
JDBCDataStore store = dataStores.get(storeName);
|
||||||
|
try {
|
||||||
|
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC, storeName);
|
||||||
|
store.dispose();
|
||||||
|
store = null;
|
||||||
|
dataStores.remove(storeName);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Fail to dispose DataStore :: Can't remove layer linked this DataStore :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
* Enabled aggressive block sorting
|
||||||
|
* Enabled unnecessary exception pruning
|
||||||
|
* Enabled aggressive exception aggregation
|
||||||
|
*/
|
||||||
|
public static synchronized boolean disposeDataStore(String storeName) {
|
||||||
|
if (ServerUtil.isNullString((String)storeName)) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Parameter StoreName is NULL");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (dataStores.isEmpty()) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "DataStore is NULL");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
storeName = storeName.trim().toUpperCase();
|
||||||
|
ConcurrentHashMap<String, JDBCDataStore> concurrentHashMap = dataStores;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
JDBCDataStore store = dataStores.get(storeName);
|
||||||
|
if (store == null) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "DataStore [" + storeName + "] is not exist");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.JDBC, storeName);
|
||||||
|
store.dispose();
|
||||||
|
store = null;
|
||||||
|
dataStores.remove(storeName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[JDBC]", "Fail to remove layer linked this DataStore :: " + e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.feature.FeatureCollection;
|
||||||
|
import org.geotools.geojson.feature.FeatureJSON;
|
||||||
|
import org.geotools.geojson.geom.GeometryJSON;
|
||||||
|
|
||||||
|
public class JsonUtil {
|
||||||
|
public static void writeToResponse(HttpServletResponse resp, SimpleFeatureCollection collection) throws Exception {
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
FeatureJSON fJson = new FeatureJSON(new GeometryJSON(8));
|
||||||
|
try {
|
||||||
|
fJson.writeFeatureCollection((FeatureCollection)collection, (Object)writer);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new Exception("Failed to create json. " + e);
|
||||||
|
}
|
||||||
|
String json = writer.toString();
|
||||||
|
try {
|
||||||
|
resp.setContentType("application/json; charset=UTF-8");
|
||||||
|
resp.setCharacterEncoding("UTF-8");
|
||||||
|
resp.setContentLength(json.getBytes("UTF-8").length);
|
||||||
|
resp.setStatus(200);
|
||||||
|
resp.getWriter().write(json);
|
||||||
|
resp.getWriter().flush();
|
||||||
|
resp.getWriter().close();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new Exception("Failed to write response. " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,168 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
public class KLISLabelUtil {
|
import com.vividsolutions.jts.geom.Coordinate;
|
||||||
|
import com.vividsolutions.jts.geom.Polygon;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import org.gishur.core.ListItem;
|
||||||
|
import org.gishur.core.SimpleList;
|
||||||
|
import org.gishur.x.XPoint;
|
||||||
|
import org.gishur.x.XPolygon;
|
||||||
|
import org.gishur.x.XSegment;
|
||||||
|
import org.gishur.x.voronoi.Skeleton;
|
||||||
|
|
||||||
}
|
public class KLISLabelUtil {
|
||||||
|
private XPolygon polygon = null;
|
||||||
|
private int xOffset = 0;
|
||||||
|
private int yOffset = 0;
|
||||||
|
private Point2D center = null;
|
||||||
|
private double maxRadius = 0.0;
|
||||||
|
private int edgediff = 0;
|
||||||
|
private int hasParabola = 0;
|
||||||
|
|
||||||
|
public KLISLabelUtil(Polygon poly) {
|
||||||
|
this.polygon = this.ConvertPloygon2XGeometry(poly);
|
||||||
|
}
|
||||||
|
|
||||||
|
private XPolygon ConvertPloygon2XGeometry(Polygon poly) {
|
||||||
|
if (poly.getNumInteriorRing() != 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArrayList<Coordinate> coords = new ArrayList<Coordinate>(Arrays.asList(poly.getExteriorRing().getCoordinates()));
|
||||||
|
this.xOffset = (int)coords.get((int)0).x / 100 * 100;
|
||||||
|
this.yOffset = (int)coords.get((int)0).y / 100 * 100;
|
||||||
|
ArrayList<XPoint> points = new ArrayList<XPoint>();
|
||||||
|
int i = 0;
|
||||||
|
while (i < coords.size()) {
|
||||||
|
points.add(new XPoint(coords.get((int)i).x - (double)this.xOffset, coords.get((int)i).y - (double)this.yOffset));
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
i = 0;
|
||||||
|
while (i < points.size() - 2) {
|
||||||
|
XPoint p1 = (XPoint)points.get(i);
|
||||||
|
XPoint p2 = (XPoint)points.get(i + 1);
|
||||||
|
XPoint p3 = (XPoint)points.get(i + 2);
|
||||||
|
double ang1 = p1.angle(p2);
|
||||||
|
double ang2 = p2.angle(p3);
|
||||||
|
double angDiff = Math.abs(ang1 - ang2);
|
||||||
|
int idff = (int)(angDiff * 180.0 / Math.PI);
|
||||||
|
double dist = Point2D.distance(p1.x, p1.y, p2.x, p2.y);
|
||||||
|
if (idff <= 3 || dist < 0.1) {
|
||||||
|
points.remove(i + 1);
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return new XPolygon(points.toArray(new XPoint[points.size()]));
|
||||||
|
}
|
||||||
|
catch (RuntimeException runtimeException) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConvex() {
|
||||||
|
if (this.polygon == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.polygon.convex();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point2D GetMIC() {
|
||||||
|
if (this.polygon == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Skeleton skeleton = new Skeleton(this.polygon);
|
||||||
|
skeleton.execute();
|
||||||
|
XPoint[] cpt = skeleton.MIC();
|
||||||
|
if (cpt == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!this.polygon.contains(cpt[0].x, cpt[0].y)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
this.center = new Point2D.Double((double)this.xOffset + cpt[0].x, (double)this.yOffset + cpt[0].y);
|
||||||
|
Point2D.Double ctp = new Point2D.Double((double)this.xOffset + cpt[1].x, (double)this.yOffset + cpt[1].y);
|
||||||
|
this.maxRadius = Point2D.distance(this.center.getX(), this.center.getY(), ((Point2D)ctp).getX(), ((Point2D)ctp).getY());
|
||||||
|
return this.center;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point2D GetMIC_ex() {
|
||||||
|
if (this.polygon == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Skeleton skeleton = new Skeleton(this.polygon);
|
||||||
|
skeleton.execute();
|
||||||
|
XPoint[] cpt = skeleton.MIC();
|
||||||
|
if (cpt == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!this.polygon.contains(cpt[0].x, cpt[0].y)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
this.center = new Point2D.Double((double)this.xOffset + cpt[0].x, (double)this.yOffset + cpt[0].y);
|
||||||
|
Point2D.Double ctp = new Point2D.Double((double)this.xOffset + cpt[1].x, (double)this.yOffset + cpt[1].y);
|
||||||
|
this.maxRadius = Point2D.distance(this.center.getX(), this.center.getY(), ((Point2D)ctp).getX(), ((Point2D)ctp).getY());
|
||||||
|
SimpleList skeletonPoints = skeleton.getLines(false);
|
||||||
|
this.edgediff = Math.abs(skeletonPoints.length() - skeleton.getLines(true).length());
|
||||||
|
if (skeletonPoints.length() == 1) {
|
||||||
|
Object item = skeletonPoints.first().value();
|
||||||
|
XPoint start = null;
|
||||||
|
XPoint end = null;
|
||||||
|
if (item instanceof XSegment) {
|
||||||
|
start = ((XSegment)item).getStartPoint();
|
||||||
|
end = ((XSegment)item).getEndPoint();
|
||||||
|
} else {
|
||||||
|
start = (XPoint)skeletonPoints.first().value();
|
||||||
|
end = (XPoint)skeletonPoints.last().value();
|
||||||
|
}
|
||||||
|
this.center.setLocation((start.x + end.x) / 2.0, (end.x + end.y) / 2.0);
|
||||||
|
return this.center;
|
||||||
|
}
|
||||||
|
boolean wasParabola = false;
|
||||||
|
XPoint prevPt = new XPoint();
|
||||||
|
double maxAngle = 0.0;
|
||||||
|
double prevAngle = 0.0;
|
||||||
|
ListItem listitem = skeletonPoints.first();
|
||||||
|
while (listitem != null) {
|
||||||
|
try {
|
||||||
|
XSegment line = (XSegment)listitem.value();
|
||||||
|
if (this.polygon.findPoint(line.source()) > 0 || this.polygon.findPoint(line.target()) > 0) {
|
||||||
|
++this.edgediff;
|
||||||
|
}
|
||||||
|
if (wasParabola) {
|
||||||
|
double dist = Point2D.distance(line.source().x, line.source().y, prevPt.x, prevPt.y);
|
||||||
|
double diffAngle = Math.abs(prevAngle - line.angle());
|
||||||
|
if (diffAngle > maxAngle && dist >= 0.5) {
|
||||||
|
maxAngle = diffAngle;
|
||||||
|
} else {
|
||||||
|
--this.hasParabola;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wasParabola = false;
|
||||||
|
prevAngle = line.angle();
|
||||||
|
prevPt.x = line.target().x;
|
||||||
|
prevPt.y = line.target().y;
|
||||||
|
}
|
||||||
|
catch (ClassCastException e) {
|
||||||
|
wasParabola = true;
|
||||||
|
++this.hasParabola;
|
||||||
|
}
|
||||||
|
listitem = listitem.next();
|
||||||
|
}
|
||||||
|
return this.center;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxRadius() {
|
||||||
|
return this.maxRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int edgeDiffCounts() {
|
||||||
|
return this.edgediff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hasParabola() {
|
||||||
|
return this.hasParabola;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -5,188 +5,142 @@ import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
import org.geotools.referencing.CRS;
|
import org.geotools.referencing.CRS;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
public abstract class Layer
|
public abstract class Layer {
|
||||||
{
|
private final LayerFactory.LayerType layerType;
|
||||||
private final LayerFactory.LayerType layerType;
|
private String mapName;
|
||||||
private String mapName;
|
private String layerName;
|
||||||
private String layerName;
|
private String serverName;
|
||||||
private String serverName;
|
private CoordinateReferenceSystem layerCRS;
|
||||||
private CoordinateReferenceSystem layerCRS;
|
private Boolean layerUseCache;
|
||||||
private Boolean layerUseCache;
|
private Date layerLastUpdate;
|
||||||
private Date layerLastUpdate;
|
private String layerTitle;
|
||||||
private String layerTitle;
|
private String layerAbstract;
|
||||||
private String layerAbstract;
|
private String autorID;
|
||||||
private String autorID;
|
private String sourceType;
|
||||||
private String sourceType;
|
private String hashTag;
|
||||||
private String hashTag;
|
private String sourcPath;
|
||||||
private String sourcPath;
|
|
||||||
|
|
||||||
protected Layer(AVList params)
|
protected Layer(AVList params) throws Exception {
|
||||||
throws Exception
|
this.layerType = (LayerFactory.LayerType)params.getValue("conf.service.layer.type");
|
||||||
{
|
if (this.layerType == null) {
|
||||||
this.layerType = ((LayerFactory.LayerType)params.getValue("conf.service.layer.type"));
|
throw new IllegalArgumentException("LayerType is NULL.");
|
||||||
if (this.layerType == null) {
|
}
|
||||||
throw new IllegalArgumentException("LayerType is NULL.");
|
String sVal = params.getStringValue("conf.service.map.name");
|
||||||
|
if (ServerUtil.isNullString((String)sVal)) {
|
||||||
|
throw new IllegalArgumentException("MapName is NULL.");
|
||||||
|
}
|
||||||
|
this.mapName = sVal.trim().toUpperCase();
|
||||||
|
sVal = params.getStringValue("conf.service.layer.name");
|
||||||
|
if (ServerUtil.isNullString((String)sVal)) {
|
||||||
|
throw new IllegalArgumentException("Layer Name is NULL.");
|
||||||
|
}
|
||||||
|
this.layerName = sVal.trim().toUpperCase();
|
||||||
|
sVal = params.getStringValue("conf.service.ref.server");
|
||||||
|
if (ServerUtil.isNullString((String)sVal)) {
|
||||||
|
throw new IllegalArgumentException("Server Name is NULL.");
|
||||||
|
}
|
||||||
|
this.serverName = sVal.trim();
|
||||||
|
try {
|
||||||
|
CoordinateReferenceSystem crs = (CoordinateReferenceSystem)params.getValue("conf.service.ref.crs");
|
||||||
|
if (crs == null) {
|
||||||
|
Integer srid = params.getIntegerValue("conf.service.ref.srid");
|
||||||
|
crs = CRSMngr.getLayerCRS((int)srid, (boolean)true);
|
||||||
|
}
|
||||||
|
this.layerCRS = crs;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new IllegalArgumentException("SRID value is not available.");
|
||||||
|
}
|
||||||
|
Boolean bVal = params.getBooleanValue("conf.service.use.cache");
|
||||||
|
this.layerUseCache = bVal == null ? Boolean.valueOf(false) : bVal;
|
||||||
|
Date dateVal = params.getDateValue("conf.service.last.update");
|
||||||
|
this.layerLastUpdate = dateVal == null ? new Date() : dateVal;
|
||||||
|
this.layerTitle = "O2Map Web Layer : " + this.layerName;
|
||||||
|
sVal = params.getStringValue("conf.service.description");
|
||||||
|
this.layerAbstract = ServerUtil.isNullString((String)sVal) ? "This Layer served FEATURE or IMAGE or COVERAGE on O2Map Web." : sVal.trim();
|
||||||
|
sVal = params.getStringValue("conf.service.o2wps.source.path");
|
||||||
|
this.sourcPath = ServerUtil.isNullString((String)sVal) ? "" : sVal.trim();
|
||||||
|
sVal = params.getStringValue("conf.service.o2wps.hashtag");
|
||||||
|
this.hashTag = ServerUtil.isNullString((String)sVal) ? "" : sVal.trim();
|
||||||
|
sVal = params.getStringValue("conf.service.o2wps.author.id");
|
||||||
|
this.autorID = ServerUtil.isNullString((String)sVal) ? "Anonymous" : sVal.trim();
|
||||||
|
sVal = params.getStringValue("conf.service.o2wps.source.type");
|
||||||
|
if (ServerUtil.isNullString((String)sVal)) {
|
||||||
|
this.sourceType = "shp";
|
||||||
|
} else {
|
||||||
|
this.autorID = sVal.trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String sVal = params.getStringValue("conf.service.map.name");
|
public LayerFactory.LayerType getLayerType() {
|
||||||
if (ServerUtil.isNullString(sVal)) {
|
return this.layerType;
|
||||||
throw new IllegalArgumentException("MapName is NULL.");
|
|
||||||
}
|
|
||||||
this.mapName = sVal.trim().toUpperCase();
|
|
||||||
|
|
||||||
sVal = params.getStringValue("conf.service.layer.name");
|
|
||||||
if (ServerUtil.isNullString(sVal)) {
|
|
||||||
throw new IllegalArgumentException("Layer Name is NULL.");
|
|
||||||
}
|
|
||||||
this.layerName = sVal.trim().toUpperCase();
|
|
||||||
|
|
||||||
sVal = params.getStringValue("conf.service.ref.server");
|
|
||||||
if (ServerUtil.isNullString(sVal)) {
|
|
||||||
throw new IllegalArgumentException("Server Name is NULL.");
|
|
||||||
}
|
|
||||||
this.serverName = sVal.trim();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CoordinateReferenceSystem crs = (CoordinateReferenceSystem)params.getValue("conf.service.ref.crs");
|
|
||||||
|
|
||||||
if (crs == null) {
|
|
||||||
Integer srid = params.getIntegerValue("conf.service.ref.srid");
|
|
||||||
crs = CRSMngr.getLayerCRS(srid.intValue(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.layerCRS = crs;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException("SRID value is not available.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean bVal = params.getBooleanValue("conf.service.use.cache");
|
public String getMapName() {
|
||||||
if (bVal == null)
|
return this.mapName;
|
||||||
this.layerUseCache = Boolean.valueOf(false);
|
|
||||||
else {
|
|
||||||
this.layerUseCache = bVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Date dateVal = params.getDateValue("conf.service.last.update");
|
public String getName() {
|
||||||
if (dateVal == null)
|
return this.layerName;
|
||||||
this.layerLastUpdate = new Date();
|
|
||||||
else {
|
|
||||||
this.layerLastUpdate = dateVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.layerTitle = ("O2Map Web Layer : " + this.layerName);
|
public String getServerName() {
|
||||||
|
return this.serverName;
|
||||||
sVal = params.getStringValue("conf.service.description");
|
|
||||||
if (ServerUtil.isNullString(sVal))
|
|
||||||
this.layerAbstract = "This Layer served FEATURE or IMAGE or COVERAGE on O2Map Web.";
|
|
||||||
else {
|
|
||||||
this.layerAbstract = sVal.trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sVal = params.getStringValue("conf.service.o2wps.source.path");
|
public abstract String getSourceName();
|
||||||
if (ServerUtil.isNullString(sVal))
|
|
||||||
this.sourcPath = "";
|
public CoordinateReferenceSystem getCRS() {
|
||||||
else {
|
return this.layerCRS;
|
||||||
this.sourcPath = sVal.trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sVal = params.getStringValue("conf.service.o2wps.hashtag");
|
public Boolean isUseCache() {
|
||||||
if (ServerUtil.isNullString(sVal))
|
return this.layerUseCache;
|
||||||
this.hashTag = "";
|
|
||||||
else {
|
|
||||||
this.hashTag = sVal.trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sVal = params.getStringValue("conf.service.o2wps.author.id");
|
public String getAuthorId() {
|
||||||
if (ServerUtil.isNullString(sVal))
|
return this.autorID;
|
||||||
this.autorID = "Anonymous";
|
|
||||||
else {
|
|
||||||
this.autorID = sVal.trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sVal = params.getStringValue("conf.service.o2wps.source.type");
|
public String getSourceType() {
|
||||||
if (ServerUtil.isNullString(sVal))
|
return this.sourceType;
|
||||||
this.sourceType = "shp";
|
|
||||||
else
|
|
||||||
this.autorID = sVal.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LayerFactory.LayerType getLayerType()
|
|
||||||
{
|
|
||||||
return this.layerType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMapName() {
|
|
||||||
return this.mapName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.layerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getServerName() {
|
|
||||||
return this.serverName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract String getSourceName();
|
|
||||||
|
|
||||||
public CoordinateReferenceSystem getCRS() {
|
|
||||||
return this.layerCRS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isUseCache() {
|
|
||||||
return this.layerUseCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAuthorId()
|
|
||||||
{
|
|
||||||
return this.autorID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSourceType() {
|
|
||||||
return this.sourceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLastUpdate() {
|
|
||||||
return this.layerLastUpdate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return this.layerTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAbstract() {
|
|
||||||
return this.layerAbstract;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHashTag() {
|
|
||||||
return this.hashTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSourcePath() {
|
|
||||||
return this.sourcPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateCRS()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
LogMngr.getInstance().logInfo("[CRS]", "Update Layer CRS [" + this.layerName + "]");
|
|
||||||
|
|
||||||
CoordinateReferenceSystem crs = CRSMngr.getCRS(CRS.toSRS(this.layerCRS));
|
|
||||||
|
|
||||||
if (CRS.equalsIgnoreMetadata(this.layerCRS, crs)) {
|
|
||||||
LogMngr.getInstance().logInfo("[LAYER]", "Layer CRS has no change [" + this.layerName + "]");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.layerCRS = crs;
|
|
||||||
LogMngr.getInstance().logInfo("[LAYER]", "Success to update CRS for Layer [" + this.layerName + "]");
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logError("[LAYER]", "Fail to update CRS for Layer [" + this.layerName + "] :: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract ReferencedEnvelope getBBox();
|
public Date getLastUpdate() {
|
||||||
|
return this.layerLastUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return this.layerTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAbstract() {
|
||||||
|
return this.layerAbstract;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHashTag() {
|
||||||
|
return this.hashTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSourcePath() {
|
||||||
|
return this.sourcPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateCRS() {
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "Update Layer CRS [" + this.layerName + "]");
|
||||||
|
CoordinateReferenceSystem crs = CRSMngr.getCRS((String)CRS.toSRS((CoordinateReferenceSystem)this.layerCRS));
|
||||||
|
if (CRS.equalsIgnoreMetadata((Object)this.layerCRS, (Object)crs)) {
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Layer CRS has no change [" + this.layerName + "]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.layerCRS = crs;
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Success to update CRS for Layer [" + this.layerName + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Fail to update CRS for Layer [" + this.layerName + "] :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract ReferencedEnvelope getBBox();
|
||||||
}
|
}
|
||||||
|
|
@ -1,43 +1,74 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
public class LayerFactory
|
|
||||||
{
|
|
||||||
|
|
||||||
public static enum LayerType
|
public class LayerFactory {
|
||||||
{
|
public enum LayerType {
|
||||||
JDBC("VECTOR_JDBC", ".jdbc"),
|
JDBC("VECTOR_JDBC", ".jdbc"),
|
||||||
SHAPE("VECTOR_SHAPE", ".shape"),
|
SHAPE("VECTOR_SHAPE", ".shape"),
|
||||||
GEOWAVE("VECTOR_GEOWAVE", ".gwave"),
|
GEOWAVE("VECTOR_GEOWAVE", ".gwave"),
|
||||||
|
GROUP("VECTOR_GROUP", ".group"),
|
||||||
GROUP("VECTOR_GROUP", ".group"),
|
O2WPSVEC("VECTOR_O2WPS", ".o2wpsvec"),
|
||||||
|
O2WPSCOV("COVERAGE_O2WPS", ".o2wpscov"),
|
||||||
O2WPSVEC("VECTOR_O2WPS", ".o2wpsvec"),
|
WMS("LINK_WMS", ".wms"),
|
||||||
O2WPSCOV("COVERAGE_O2WPS", ".o2wpscov"),
|
WCS("LINK_WCS", ".wcs"),
|
||||||
|
O2IMG("RASTER_O2IMG", ".o2img"),
|
||||||
WMS("LINK_WMS", ".wms"),
|
|
||||||
WCS("LINK_WCS", ".wcs"),
|
|
||||||
|
|
||||||
O2IMG("RASTER_O2IMG", ".o2img"),
|
|
||||||
O2DEM("RASTER_O2DEM", ".o2dem");
|
O2DEM("RASTER_O2DEM", ".o2dem");
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
private String pre;
|
private String pre;
|
||||||
|
|
||||||
private LayerType(String type, String pre) { this.type = type;
|
LayerType(String type, String pre) {
|
||||||
this.pre = pre; }
|
this.type = type;
|
||||||
|
this.pre = pre;
|
||||||
public String getType()
|
}
|
||||||
{
|
|
||||||
|
public String getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrefix() {
|
public String getPrefix() {
|
||||||
return this.pre;
|
return this.pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
return getType();
|
return getType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static Layer createLayer(LayerType type, AVList params) throws Exception {
|
||||||
|
switch (type) {
|
||||||
|
case JDBC:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.JDBC);
|
||||||
|
return (Layer)new FeatureLayer(params);
|
||||||
|
case SHAPE:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.SHAPE);
|
||||||
|
return (Layer)new FeatureLayer(params);
|
||||||
|
case GEOWAVE:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.GEOWAVE);
|
||||||
|
return (Layer)new FeatureLayer(params);
|
||||||
|
case O2WPSVEC:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.O2WPSVEC);
|
||||||
|
return (Layer)new FeatureLayer(params);
|
||||||
|
case O2WPSCOV:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.O2WPSCOV);
|
||||||
|
return (Layer)new O2DemLayer(params);
|
||||||
|
case GROUP:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.GROUP);
|
||||||
|
return (Layer)new GroupLayer(params);
|
||||||
|
case WMS:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.WMS);
|
||||||
|
return (Layer)new WMSLayer(params);
|
||||||
|
case WCS:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.WCS);
|
||||||
|
return (Layer)new WCSLayer(params);
|
||||||
|
case O2IMG:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.O2IMG);
|
||||||
|
return (Layer)new O2ImgLayer(params);
|
||||||
|
case O2DEM:
|
||||||
|
params.setValue("conf.service.layer.type", LayerType.O2DEM);
|
||||||
|
return (Layer)new O2DemLayer(params);
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("LayerType [" + type + "] is not support.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ public class LayerSet
|
||||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type)
|
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
ArrayList layers = getLayers(type);
|
ArrayList<Layer> layers = getLayers(type);
|
||||||
|
|
||||||
for (Layer layer : layers) {
|
for (Layer layer : layers) {
|
||||||
this.layerStore.remove(layer.getName());
|
this.layerStore.remove(layer.getName());
|
||||||
|
|
@ -122,7 +122,7 @@ public class LayerSet
|
||||||
|
|
||||||
ArrayList resultList = new ArrayList();
|
ArrayList resultList = new ArrayList();
|
||||||
|
|
||||||
ArrayList layers = getLayers(type);
|
ArrayList<Layer> layers = getLayers(type);
|
||||||
|
|
||||||
for (Layer layer : layers) {
|
for (Layer layer : layers) {
|
||||||
if (layer.getServerName().equalsIgnoreCase(serverName)) {
|
if (layer.getServerName().equalsIgnoreCase(serverName)) {
|
||||||
|
|
@ -146,9 +146,9 @@ public class LayerSet
|
||||||
}
|
}
|
||||||
sourceName = sourceName.trim();
|
sourceName = sourceName.trim();
|
||||||
|
|
||||||
ArrayList resultList = new ArrayList();
|
ArrayList<Layer> resultList = new ArrayList();
|
||||||
|
|
||||||
ArrayList layers = getLayers(type);
|
ArrayList<Layer> layers = getLayers(type);
|
||||||
|
|
||||||
for (Layer layer : layers) {
|
for (Layer layer : layers) {
|
||||||
if ((layer.getServerName().equalsIgnoreCase(serverName)) &&
|
if ((layer.getServerName().equalsIgnoreCase(serverName)) &&
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,667 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Coordinate;
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||||
|
import com.vividsolutions.jts.geom.LineString;
|
||||||
|
import com.vividsolutions.jts.geom.LinearRing;
|
||||||
|
import com.vividsolutions.jts.geom.Point;
|
||||||
|
import com.vividsolutions.jts.geom.Polygon;
|
||||||
|
import java.awt.AlphaComposite;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.geom.RectangularShape;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.RenderedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.geotools.coverage.grid.GridCoverage2D;
|
||||||
|
import org.geotools.data.DataUtilities;
|
||||||
|
import org.geotools.data.Parameter;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureSource;
|
||||||
|
import org.geotools.factory.CommonFactoryFinder;
|
||||||
|
import org.geotools.feature.SchemaException;
|
||||||
|
import org.geotools.feature.simple.SimpleFeatureBuilder;
|
||||||
|
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
||||||
|
import org.geotools.feature.type.GeometryDescriptorImpl;
|
||||||
|
import org.geotools.feature.type.GeometryTypeImpl;
|
||||||
|
import org.geotools.geometry.jts.LiteShape2;
|
||||||
|
import org.geotools.process.Processors;
|
||||||
|
import org.geotools.process.function.ProcessFunction;
|
||||||
|
import org.geotools.renderer.lite.RendererUtilities;
|
||||||
|
import org.geotools.renderer.lite.StyledShapePainter;
|
||||||
|
import org.geotools.renderer.style.SLDStyleFactory;
|
||||||
|
import org.geotools.renderer.style.Style2D;
|
||||||
|
import org.geotools.styling.Description;
|
||||||
|
import org.geotools.styling.FeatureTypeStyle;
|
||||||
|
import org.geotools.styling.LineSymbolizer;
|
||||||
|
import org.geotools.styling.NamedStyle;
|
||||||
|
import org.geotools.styling.PointSymbolizer;
|
||||||
|
import org.geotools.styling.PolygonSymbolizer;
|
||||||
|
import org.geotools.styling.RasterSymbolizer;
|
||||||
|
import org.geotools.styling.Rule;
|
||||||
|
import org.geotools.styling.Style;
|
||||||
|
import org.geotools.styling.StyleVisitor;
|
||||||
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
|
import org.geotools.styling.Symbolizer;
|
||||||
|
import org.geotools.styling.TextSymbolizer;
|
||||||
|
import org.geotools.styling.visitor.DpiRescaleStyleVisitor;
|
||||||
|
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||||
|
import org.geotools.styling.visitor.UomRescaleStyleVisitor;
|
||||||
|
import org.geotools.util.NumberRange;
|
||||||
|
import org.geotools.util.Range;
|
||||||
|
import org.opengis.feature.Feature;
|
||||||
|
import org.opengis.feature.IllegalAttributeException;
|
||||||
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.feature.type.FeatureType;
|
||||||
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
|
import org.opengis.feature.type.GeometryType;
|
||||||
|
import org.opengis.feature.type.Name;
|
||||||
|
import org.opengis.filter.FilterFactory;
|
||||||
|
import org.opengis.filter.expression.Expression;
|
||||||
|
import org.opengis.filter.expression.Literal;
|
||||||
|
import org.opengis.style.GraphicLegend;
|
||||||
|
import org.opengis.util.InternationalString;
|
||||||
|
|
||||||
|
public class LegendGraphicBuilder {
|
||||||
|
public static final double TOLERANCE = 1.0E-6;
|
||||||
|
private static final StyledShapePainter shapePainter = new StyledShapePainter();
|
||||||
|
private static final GeometryFactory geomFac = new GeometryFactory();
|
||||||
|
private LiteShape2 sampleRect;
|
||||||
|
private LiteShape2 sampleLine;
|
||||||
|
private LiteShape2 samplePoint;
|
||||||
|
private final double MINIMUM_SYMBOL_SIZE = 3.0;
|
||||||
|
private final int DEFAULT_WIDTH = 32;
|
||||||
|
private final int DEFAULT_HEIGHT = 32;
|
||||||
|
private final double DEFAULT_SCALE = -1.0;
|
||||||
|
private final AVList parameters;
|
||||||
|
private final HashMap<String, String> legendOption;
|
||||||
|
|
||||||
|
public LegendGraphicBuilder(AVList params) {
|
||||||
|
this.parameters = params;
|
||||||
|
this.legendOption = new HashMap();
|
||||||
|
String optionStr = this.parameters.getStringValue("legend.graphic.option");
|
||||||
|
if (optionStr != null) {
|
||||||
|
String[] options;
|
||||||
|
optionStr = optionStr.toUpperCase();
|
||||||
|
String[] stringArray = options = optionStr.split(";");
|
||||||
|
int n = options.length;
|
||||||
|
int n2 = 0;
|
||||||
|
while (n2 < n) {
|
||||||
|
String kvStr = stringArray[n2];
|
||||||
|
String[] kv = kvStr.trim().split(":");
|
||||||
|
if (kv.length >= 2) {
|
||||||
|
this.legendOption.put(kv[0].trim().toUpperCase(), kv[1].trim().toUpperCase());
|
||||||
|
}
|
||||||
|
++n2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage buildLegendGraphic() throws Exception {
|
||||||
|
RenderedImage titleImage;
|
||||||
|
String forceTitlesOpt;
|
||||||
|
String forceLabelsOpt;
|
||||||
|
Iterator<FeatureLayer> styleIter;
|
||||||
|
String layerName = this.parameters.getStringValue("legend.graphic.layer");
|
||||||
|
String styleName = this.parameters.getStringValue("legend.graphic.style");
|
||||||
|
String ruleName = this.parameters.getStringValue("legend.graphic.rule");
|
||||||
|
StyledLayerDescriptor sld = (StyledLayerDescriptor)this.parameters.getValue("legend.graphic.sld");
|
||||||
|
if (ServerUtil.isNullString((String)layerName)) {
|
||||||
|
throw new IllegalArgumentException("Layer parameter [" + layerName + "] is not available.");
|
||||||
|
}
|
||||||
|
ArrayList<FeatureType> layers = new ArrayList<FeatureType>();
|
||||||
|
ArrayList<Style> styles = new ArrayList<Style>();
|
||||||
|
Layer serviceLayer = ServerContext.getMap().getLayer(layerName);
|
||||||
|
if (serviceLayer instanceof FeatureLayer) {
|
||||||
|
FeatureLayer fLayer = (FeatureLayer)serviceLayer;
|
||||||
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)fLayer.getLayerType(), (String)fLayer.getServerName(), (String)fLayer.getSourceName());
|
||||||
|
layers.add(featureSource.getSchema());
|
||||||
|
Style style = this.getRenderedStyle(fLayer, styleName, sld);
|
||||||
|
styles.add(style);
|
||||||
|
} else if (serviceLayer instanceof GroupLayer) {
|
||||||
|
GroupLayer gLayer = (GroupLayer)serviceLayer;
|
||||||
|
styleIter = gLayer.getLayerList().iterator();
|
||||||
|
while (styleIter.hasNext()) {
|
||||||
|
FeatureLayer gfLayer;
|
||||||
|
FeatureLayer fLayer = gfLayer = styleIter.next();
|
||||||
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)fLayer.getLayerType(), (String)fLayer.getServerName(), (String)fLayer.getSourceName());
|
||||||
|
layers.add(featureSource.getSchema());
|
||||||
|
Style style2 = this.getRenderedStyle(fLayer, styleName, sld);
|
||||||
|
styles.add(style2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Request Layer is not Feature Layer or Group Layer.");
|
||||||
|
}
|
||||||
|
Integer width = this.parameters.getIntegerValue("legend.graphic.width", Integer.valueOf(32));
|
||||||
|
Integer height = this.parameters.getIntegerValue("legend.graphic.height", Integer.valueOf(32));
|
||||||
|
Double dpi = null;
|
||||||
|
Double scaleFactor = null;
|
||||||
|
try {
|
||||||
|
dpi = Double.parseDouble(this.legendOption.get("DPI"));
|
||||||
|
double standardDpi = RendererUtilities.getDpi(Collections.emptyMap());
|
||||||
|
if (dpi != standardDpi) {
|
||||||
|
scaleFactor = dpi / standardDpi;
|
||||||
|
width = (int)Math.round((double)width.intValue() * scaleFactor);
|
||||||
|
height = (int)Math.round((double)height.intValue() * scaleFactor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
width = this.parameters.getIntegerValue("legend.graphic.width", Integer.valueOf(32));
|
||||||
|
height = this.parameters.getIntegerValue("legend.graphic.height", Integer.valueOf(32));
|
||||||
|
dpi = null;
|
||||||
|
scaleFactor = null;
|
||||||
|
}
|
||||||
|
Double scale = this.parameters.getDoubleValue("legend.graphic.scale", Double.valueOf(-1.0));
|
||||||
|
Double pixelsPerMeters = null;
|
||||||
|
try {
|
||||||
|
if (scale > 0.0) {
|
||||||
|
Map dpiMap = Collections.EMPTY_MAP;
|
||||||
|
if (dpi != null) {
|
||||||
|
dpiMap.put("dpi", dpi);
|
||||||
|
}
|
||||||
|
pixelsPerMeters = RendererUtilities.calculatePixelsPerMeterRatio((double)scale, (Map)dpiMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
pixelsPerMeters = null;
|
||||||
|
}
|
||||||
|
String format = this.parameters.getStringValue("legend.graphic.format", "image/png");
|
||||||
|
boolean transparent = false;
|
||||||
|
if (format.split("/")[1].equalsIgnoreCase("PNG")) {
|
||||||
|
transparent = true;
|
||||||
|
}
|
||||||
|
boolean forceLabelsOn = false;
|
||||||
|
if (this.legendOption.get("FORCELABELS") instanceof String && ((forceLabelsOpt = this.legendOption.get("FORCELABELS")).equalsIgnoreCase("ON") || forceLabelsOpt.equalsIgnoreCase("YES") || forceLabelsOpt.equalsIgnoreCase("TRUE") || forceLabelsOpt.equalsIgnoreCase("1"))) {
|
||||||
|
forceLabelsOn = true;
|
||||||
|
}
|
||||||
|
boolean forceTitlesOn = false;
|
||||||
|
if (this.legendOption.get("FORCETITLES") instanceof String && ((forceTitlesOpt = this.legendOption.get("FORCETITLES")).equalsIgnoreCase("ON") || forceTitlesOpt.equalsIgnoreCase("YES") || forceTitlesOpt.equalsIgnoreCase("TRUE") || forceTitlesOpt.equalsIgnoreCase("1"))) {
|
||||||
|
forceTitlesOn = true;
|
||||||
|
}
|
||||||
|
double minimumSymbolSize = 3.0;
|
||||||
|
try {
|
||||||
|
String minSymbolSizeOpt = this.legendOption.get("MINSYMBOLSIZE");
|
||||||
|
minimumSymbolSize = Double.parseDouble(minSymbolSizeOpt);
|
||||||
|
}
|
||||||
|
catch (Exception minSymbolSizeOpt) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
ArrayList<RenderedImage> layersImages = new ArrayList<RenderedImage>();
|
||||||
|
if (forceTitlesOn && (titleImage = this.getLayerTitle(serviceLayer.getName(), width, height, transparent)) != null) {
|
||||||
|
layersImages.add(titleImage);
|
||||||
|
}
|
||||||
|
int pos = 0;
|
||||||
|
while (pos < layers.size()) {
|
||||||
|
Rule[] applicableRules;
|
||||||
|
FeatureType renderLayer = (FeatureType)layers.get(pos);
|
||||||
|
Style renderStyle = (Style)styles.get(pos);
|
||||||
|
if (scaleFactor != null) {
|
||||||
|
DpiRescaleStyleVisitor dpiVisitor = new DpiRescaleStyleVisitor(scaleFactor.doubleValue());
|
||||||
|
dpiVisitor.visit(renderStyle);
|
||||||
|
renderStyle = (Style)dpiVisitor.getCopy();
|
||||||
|
}
|
||||||
|
if (pixelsPerMeters != null) {
|
||||||
|
UomRescaleStyleVisitor rescaleVisitor = new UomRescaleStyleVisitor(pixelsPerMeters.doubleValue());
|
||||||
|
rescaleVisitor.visit(renderStyle);
|
||||||
|
renderStyle = (Style)rescaleVisitor.getCopy();
|
||||||
|
}
|
||||||
|
boolean hasVectorTransformation = false;
|
||||||
|
boolean hasRasterTransformation = false;
|
||||||
|
List ftsList = renderStyle.featureTypeStyles();
|
||||||
|
int i = 0;
|
||||||
|
while (i < ftsList.size()) {
|
||||||
|
ProcessFunction processFunction;
|
||||||
|
Name processName;
|
||||||
|
Map outputs;
|
||||||
|
FeatureTypeStyle fts = (FeatureTypeStyle)ftsList.get(i);
|
||||||
|
Expression exp = fts.getTransformation();
|
||||||
|
if (exp != null && !(outputs = Processors.getResultInfo((Name)(processName = (processFunction = (ProcessFunction)exp).getProcessName()), null)).isEmpty()) {
|
||||||
|
Parameter output = (Parameter)outputs.values().iterator().next();
|
||||||
|
if (SimpleFeatureCollection.class.isAssignableFrom(output.getType())) {
|
||||||
|
hasVectorTransformation = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (GridCoverage2D.class.isAssignableFrom(output.getType())) {
|
||||||
|
hasRasterTransformation = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
Object sampleFeature = hasVectorTransformation ? this.createSampleFeature() : this.createSampleFeature(renderLayer);
|
||||||
|
FeatureTypeStyle[] ftStyles = renderStyle.featureTypeStyles().toArray(new FeatureTypeStyle[0]);
|
||||||
|
if (ruleName != null) {
|
||||||
|
Rule rule = LegendUtils.getRule((FeatureTypeStyle[])ftStyles, (String)ruleName.trim());
|
||||||
|
if (rule == null) {
|
||||||
|
throw new RuntimeException("Specified style does not contains a rule named " + ruleName);
|
||||||
|
}
|
||||||
|
applicableRules = new Rule[]{rule};
|
||||||
|
} else {
|
||||||
|
applicableRules = LegendUtils.getApplicableRules((FeatureTypeStyle[])ftStyles, (double)scale);
|
||||||
|
}
|
||||||
|
SLDStyleFactory styleFactory = new SLDStyleFactory();
|
||||||
|
NumberRange scaleRange = NumberRange.create((double)scale, (double)scale);
|
||||||
|
double symbolScale = this.calcSymbolScale(width, height, renderLayer, (Feature)sampleFeature, applicableRules, minimumSymbolSize);
|
||||||
|
ArrayList<RenderedImage> legendsStack = new ArrayList<RenderedImage>(applicableRules.length);
|
||||||
|
int i2 = 0;
|
||||||
|
while (i2 < applicableRules.length) {
|
||||||
|
BufferedImage image = this.createImage(width, height, transparent);
|
||||||
|
Color backgroundColor = LegendUtils.getBackgroundColor(this.legendOption);
|
||||||
|
Graphics2D graphics = this.prepareTransparency(transparent, backgroundColor, image);
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
Feature sample = this.getSampleFeatureForRule(renderLayer, (Feature)sampleFeature, applicableRules[i2]);
|
||||||
|
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
|
||||||
|
Symbolizer[] symbolizers = applicableRules[i2].getSymbolizers();
|
||||||
|
GraphicLegend legend = applicableRules[i2].getLegend();
|
||||||
|
if (legend != null) {
|
||||||
|
if (this.samplePoint == null) {
|
||||||
|
Coordinate coord = new Coordinate((double)(width / 2), (double)(height / 2));
|
||||||
|
try {
|
||||||
|
this.samplePoint = new LiteShape2((Geometry)geomFac.createPoint(coord), null, null, false);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.samplePoint = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shapePainter.paint(graphics, this.samplePoint, legend, scale.doubleValue(), false);
|
||||||
|
} else {
|
||||||
|
int sIdx = 0;
|
||||||
|
while (sIdx < symbolizers.length) {
|
||||||
|
PointSymbolizer pointSymbolizer;
|
||||||
|
Symbolizer symbolizer = symbolizers[sIdx];
|
||||||
|
if (symbolizer instanceof RasterSymbolizer) {
|
||||||
|
throw new IllegalStateException("It is not legal to have a RasterSymbolizer here");
|
||||||
|
}
|
||||||
|
if (symbolScale > 1.0 && symbolizer instanceof PointSymbolizer && (pointSymbolizer = this.cloneSymbolizer(symbolizer)).getGraphic() != null) {
|
||||||
|
double size = this.getPointSymbolizerSize(sample, pointSymbolizer, Math.min(width, height) - 4);
|
||||||
|
pointSymbolizer.getGraphic().setSize((Expression)ff.literal(size / symbolScale + minimumSymbolSize));
|
||||||
|
symbolizer = pointSymbolizer;
|
||||||
|
}
|
||||||
|
Style2D style2d = styleFactory.createStyle((Object)sample, symbolizer, (Range)scaleRange);
|
||||||
|
LiteShape2 shape = this.getSampleShape(symbolizer, width, height);
|
||||||
|
if (style2d != null) {
|
||||||
|
shapePainter.paint(graphics, shape, style2d, scale.doubleValue());
|
||||||
|
}
|
||||||
|
++sIdx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
legendsStack.add(image);
|
||||||
|
graphics.dispose();
|
||||||
|
++i2;
|
||||||
|
}
|
||||||
|
BufferedImage image = this.mergeLegends(legendsStack, applicableRules, forceLabelsOn, transparent);
|
||||||
|
if (image != null) {
|
||||||
|
layersImages.add(image);
|
||||||
|
}
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
BufferedImage finalLegend = this.mergeLegends(layersImages, null, forceLabelsOn, transparent);
|
||||||
|
if (finalLegend == null) {
|
||||||
|
throw new IllegalArgumentException("no legend passed");
|
||||||
|
}
|
||||||
|
return finalLegend;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Style getRenderedStyle(FeatureLayer layer, String styleName, StyledLayerDescriptor sld) {
|
||||||
|
Style style2;
|
||||||
|
ArrayList<Style> styleList = ServerUtil.isNullString((String)styleName) ? StyleMngr.getStylesFromSLD((String)layer.getName(), (StyledLayerDescriptor)sld) : StyleMngr.getStylesFromSLD((String)layer.getName(), (String)styleName, (StyledLayerDescriptor)sld);
|
||||||
|
if (styleList.size() == 0) {
|
||||||
|
return layer.getRenderStyle(styleName);
|
||||||
|
}
|
||||||
|
for (Style style1 : styleList) {
|
||||||
|
if (!style1.isDefault()) continue;
|
||||||
|
if (style1 instanceof NamedStyle) {
|
||||||
|
return layer.getRenderStyle(style1.getName());
|
||||||
|
}
|
||||||
|
return style1;
|
||||||
|
}
|
||||||
|
style2 = (Style)styleList.get(0);
|
||||||
|
if (style2 instanceof NamedStyle) {
|
||||||
|
return layer.getRenderStyle(style2.getName());
|
||||||
|
}
|
||||||
|
return style2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BufferedImage createImage(int w, int h, boolean transparent) {
|
||||||
|
if (transparent) {
|
||||||
|
return new BufferedImage(w, h, 6);
|
||||||
|
}
|
||||||
|
return new BufferedImage(w, h, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Graphics2D prepareTransparency(boolean transparent, Color bgColor, BufferedImage preparedImage) {
|
||||||
|
Graphics2D graphic = preparedImage.createGraphics();
|
||||||
|
HashMap<RenderingHints.Key, Object> hintsMap = new HashMap<RenderingHints.Key, Object>();
|
||||||
|
hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||||
|
graphic.setRenderingHints(hintsMap);
|
||||||
|
if (transparent) {
|
||||||
|
int type = 2;
|
||||||
|
graphic.setComposite(AlphaComposite.getInstance(type));
|
||||||
|
Color c = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 0);
|
||||||
|
graphic.setBackground(bgColor);
|
||||||
|
graphic.setColor(c);
|
||||||
|
graphic.fillRect(0, 0, preparedImage.getWidth(), preparedImage.getHeight());
|
||||||
|
type = 3;
|
||||||
|
graphic.setComposite(AlphaComposite.getInstance(type));
|
||||||
|
} else {
|
||||||
|
graphic.setColor(bgColor);
|
||||||
|
graphic.fillRect(0, 0, preparedImage.getWidth(), preparedImage.getHeight());
|
||||||
|
}
|
||||||
|
return graphic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RenderedImage getLayerTitle(String title, int w, int h, boolean transparent) {
|
||||||
|
if (title == null) {
|
||||||
|
title = "Legend";
|
||||||
|
}
|
||||||
|
BufferedImage image = this.createImage(w, h, transparent);
|
||||||
|
return this.getRenderedLabel(image, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BufferedImage getRenderedLabel(BufferedImage image, String label) {
|
||||||
|
Font labelFont = LegendUtils.getLabelFont(this.legendOption);
|
||||||
|
boolean useAA = LegendUtils.isFontAntiAliasing(this.legendOption);
|
||||||
|
Graphics2D graphics = image.createGraphics();
|
||||||
|
graphics.setFont(labelFont);
|
||||||
|
if (useAA) {
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
} else {
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||||
|
}
|
||||||
|
return LegendUtils.renderLabel((String)label, (Graphics2D)graphics, this.legendOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SimpleFeature createSampleFeature() {
|
||||||
|
SimpleFeatureType type;
|
||||||
|
try {
|
||||||
|
type = DataUtilities.createType((String)"Sample", (String)"the_geom:Geometry");
|
||||||
|
}
|
||||||
|
catch (SchemaException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return SimpleFeatureBuilder.template((SimpleFeatureType)type, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Feature createSampleFeature(FeatureType schema) {
|
||||||
|
Feature sampleFeature;
|
||||||
|
try {
|
||||||
|
sampleFeature = schema instanceof SimpleFeatureType ? (this.hasMixedGeometry((SimpleFeatureType)schema) ? null : SimpleFeatureBuilder.template((SimpleFeatureType)((SimpleFeatureType)schema), null)) : DataUtilities.templateFeature((FeatureType)schema);
|
||||||
|
}
|
||||||
|
catch (IllegalAttributeException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return sampleFeature;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasMixedGeometry(SimpleFeatureType schema) {
|
||||||
|
for (AttributeDescriptor attDesc : schema.getAttributeDescriptors()) {
|
||||||
|
if (!this.isMixedGeometry(attDesc)) continue;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isMixedGeometry(AttributeDescriptor attDesc) {
|
||||||
|
return attDesc instanceof GeometryDescriptor && attDesc.getType().getBinding() == Geometry.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calcSymbolScale(int width, int height, FeatureType featureType, Feature feature, Rule[] rules, double minimumSymbolsSize) {
|
||||||
|
double minSize = Double.MAX_VALUE;
|
||||||
|
double maxSize = 0.0;
|
||||||
|
int ruleCount = rules.length;
|
||||||
|
int i = 0;
|
||||||
|
while (i < ruleCount) {
|
||||||
|
Feature sample = this.getSampleFeatureForRule(featureType, feature, rules[i]);
|
||||||
|
Symbolizer[] symbolizers = rules[i].getSymbolizers();
|
||||||
|
int sIdx = 0;
|
||||||
|
while (sIdx < symbolizers.length) {
|
||||||
|
Symbolizer symbolizer = symbolizers[sIdx];
|
||||||
|
if (symbolizer instanceof PointSymbolizer) {
|
||||||
|
double size = this.getPointSymbolizerSize(sample, (PointSymbolizer)symbolizer, Math.min(width, height));
|
||||||
|
if (size < minSize) {
|
||||||
|
minSize = size;
|
||||||
|
}
|
||||||
|
if (size > maxSize) {
|
||||||
|
maxSize = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++sIdx;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (minSize != maxSize) {
|
||||||
|
return (maxSize - minSize + 1.0) / ((double)Math.min(width, height) - minimumSymbolsSize);
|
||||||
|
}
|
||||||
|
return maxSize / ((double)Math.min(width, height) - minimumSymbolsSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Feature getSampleFeatureForRule(FeatureType featureType, Feature sample, Rule rule) {
|
||||||
|
Symbolizer[] symbolizers = rule.getSymbolizers();
|
||||||
|
if (sample == null) {
|
||||||
|
int dimensionality = 1;
|
||||||
|
int sIdx = 0;
|
||||||
|
while (sIdx < symbolizers.length) {
|
||||||
|
Symbolizer symbolizer = symbolizers[sIdx];
|
||||||
|
if (LineSymbolizer.class.isAssignableFrom(symbolizer.getClass())) {
|
||||||
|
dimensionality = 2;
|
||||||
|
}
|
||||||
|
if (PolygonSymbolizer.class.isAssignableFrom(symbolizer.getClass())) {
|
||||||
|
dimensionality = 3;
|
||||||
|
}
|
||||||
|
++sIdx;
|
||||||
|
}
|
||||||
|
return this.createSampleFeature(featureType, dimensionality);
|
||||||
|
}
|
||||||
|
return sample;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Feature createSampleFeature(FeatureType schema, int dimensionality) {
|
||||||
|
if (schema instanceof SimpleFeatureType) {
|
||||||
|
schema = this.cloneWithDimensionality(schema, dimensionality);
|
||||||
|
}
|
||||||
|
return this.createSampleFeature(schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) {
|
||||||
|
SimpleFeatureType simpleFt = (SimpleFeatureType)schema;
|
||||||
|
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
|
||||||
|
builder.setName(schema.getName());
|
||||||
|
builder.setCRS(schema.getCoordinateReferenceSystem());
|
||||||
|
for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) {
|
||||||
|
if (this.isMixedGeometry(desc)) {
|
||||||
|
GeometryDescriptor geomDescriptor = (GeometryDescriptor)desc;
|
||||||
|
GeometryType geomType = geomDescriptor.getType();
|
||||||
|
Class<?> geometryClass = this.getGeometryForDimensionality(dimensionality);
|
||||||
|
GeometryTypeImpl gt = new GeometryTypeImpl(geomType.getName(), geometryClass, geomType.getCoordinateReferenceSystem(), geomType.isIdentified(), geomType.isAbstract(), geomType.getRestrictions(), geomType.getSuper(), geomType.getDescription());
|
||||||
|
builder.add((AttributeDescriptor)new GeometryDescriptorImpl((GeometryType)gt, geomDescriptor.getName(), geomDescriptor.getMinOccurs(), geomDescriptor.getMaxOccurs(), geomDescriptor.isNillable(), geomDescriptor.getDefaultValue()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
builder.add(desc);
|
||||||
|
}
|
||||||
|
schema = builder.buildFeatureType();
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Class<?> getGeometryForDimensionality(int dimensionality) {
|
||||||
|
if (dimensionality == 1) {
|
||||||
|
return Point.class;
|
||||||
|
}
|
||||||
|
if (dimensionality == 2) {
|
||||||
|
return LineString.class;
|
||||||
|
}
|
||||||
|
return Polygon.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getPointSymbolizerSize(Feature feature, PointSymbolizer pointSymbolizer, int defaultSize) {
|
||||||
|
Object size;
|
||||||
|
Expression sizeExp;
|
||||||
|
if (pointSymbolizer.getGraphic() != null && (sizeExp = pointSymbolizer.getGraphic().getSize()) instanceof Literal && (size = sizeExp.evaluate((Object)feature)) != null) {
|
||||||
|
if (size instanceof Double) {
|
||||||
|
return (Double)size;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(size.toString());
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
return defaultSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PointSymbolizer cloneSymbolizer(Symbolizer symbolizer) {
|
||||||
|
DuplicatingStyleVisitor duplicator = new DuplicatingStyleVisitor();
|
||||||
|
symbolizer.accept((StyleVisitor)duplicator);
|
||||||
|
PointSymbolizer pointSymbolizer = (PointSymbolizer)duplicator.getCopy();
|
||||||
|
return pointSymbolizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth, int legendHeight) {
|
||||||
|
LiteShape2 sampleShape;
|
||||||
|
float hpad = (float)legendWidth * 0.15f;
|
||||||
|
float vpad = (float)legendHeight * 0.15f;
|
||||||
|
if (symbolizer instanceof LineSymbolizer) {
|
||||||
|
if (this.sampleLine == null) {
|
||||||
|
Coordinate[] coords = new Coordinate[]{new Coordinate((double)hpad, (double)((float)legendHeight - vpad - 1.0f)), new Coordinate((double)((float)legendWidth - hpad - 1.0f), (double)vpad)};
|
||||||
|
LineString geom = geomFac.createLineString(coords);
|
||||||
|
try {
|
||||||
|
this.sampleLine = new LiteShape2((Geometry)geom, null, null, false);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.sampleLine = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sampleShape = this.sampleLine;
|
||||||
|
} else if (symbolizer instanceof PolygonSymbolizer || symbolizer instanceof RasterSymbolizer) {
|
||||||
|
if (this.sampleRect == null) {
|
||||||
|
float w = (float)legendWidth - 2.0f * hpad - 1.0f;
|
||||||
|
float h = (float)legendHeight - 2.0f * vpad - 1.0f;
|
||||||
|
Coordinate[] coords = new Coordinate[]{new Coordinate((double)hpad, (double)vpad), new Coordinate((double)hpad, (double)(vpad + h)), new Coordinate((double)(hpad + w), (double)(vpad + h)), new Coordinate((double)(hpad + w), (double)vpad), new Coordinate((double)hpad, (double)vpad)};
|
||||||
|
LinearRing shell = geomFac.createLinearRing(coords);
|
||||||
|
Polygon geom = geomFac.createPolygon(shell, null);
|
||||||
|
try {
|
||||||
|
this.sampleRect = new LiteShape2((Geometry)geom, null, null, false);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.sampleRect = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sampleShape = this.sampleRect;
|
||||||
|
} else if (symbolizer instanceof PointSymbolizer || symbolizer instanceof TextSymbolizer) {
|
||||||
|
if (this.samplePoint == null) {
|
||||||
|
Coordinate coord = new Coordinate((double)(legendWidth / 2), (double)(legendHeight / 2));
|
||||||
|
try {
|
||||||
|
this.samplePoint = new LiteShape2((Geometry)geomFac.createPoint(coord), null, null, false);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.samplePoint = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sampleShape = this.samplePoint;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unknown symbolizer: " + symbolizer);
|
||||||
|
}
|
||||||
|
return sampleShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BufferedImage mergeLegends(List<RenderedImage> imageStack, Rule[] rules, boolean forceLabelsOn, boolean transparent) {
|
||||||
|
BufferedImage finalLegend;
|
||||||
|
Font labelFont = LegendUtils.getLabelFont(this.legendOption);
|
||||||
|
boolean useAA = LegendUtils.isFontAntiAliasing(this.legendOption);
|
||||||
|
if (imageStack.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!(imageStack.size() != 1 || forceLabelsOn && rules != null)) {
|
||||||
|
finalLegend = (BufferedImage)imageStack.get(0);
|
||||||
|
} else {
|
||||||
|
int imgCount = imageStack.size();
|
||||||
|
String[] labels = new String[imgCount];
|
||||||
|
BufferedImage img = (BufferedImage)imageStack.get(0);
|
||||||
|
int totalHeight = 0;
|
||||||
|
int totalWidth = 0;
|
||||||
|
int[] rowHeights = new int[imgCount];
|
||||||
|
BufferedImage[] labelsGraphics = new BufferedImage[imgCount];
|
||||||
|
int i = 0;
|
||||||
|
while (i < imgCount) {
|
||||||
|
img = (BufferedImage)imageStack.get(i);
|
||||||
|
if (!forceLabelsOn || rules == null) {
|
||||||
|
totalWidth = (int)Math.ceil(Math.max(img.getWidth(), totalWidth));
|
||||||
|
rowHeights[i] = img.getHeight();
|
||||||
|
totalHeight += img.getHeight();
|
||||||
|
} else {
|
||||||
|
InternationalString title;
|
||||||
|
Rule rule = rules[i];
|
||||||
|
Description description = rule.getDescription();
|
||||||
|
if (description != null && description.getTitle() != null && !ServerUtil.isNullString((String)(title = description.getTitle()).toString())) {
|
||||||
|
labels[i] = title.toString();
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)labels[i])) {
|
||||||
|
labels[i] = ServerUtil.isNullString((String)rule.getName()) ? "RULE " + i : rule.getName();
|
||||||
|
}
|
||||||
|
if (labels[i] != null && labels[i].length() > 0) {
|
||||||
|
BufferedImage renderedLabel;
|
||||||
|
labelsGraphics[i] = renderedLabel = this.getRenderedLabel(img, labels[i]);
|
||||||
|
Rectangle2D.Double bounds = new Rectangle2D.Double(0.0, 0.0, renderedLabel.getWidth(), renderedLabel.getHeight());
|
||||||
|
totalWidth = (int)Math.ceil(Math.max((double)img.getWidth() + ((RectangularShape)bounds).getWidth(), (double)totalWidth));
|
||||||
|
rowHeights[i] = (int)Math.ceil(Math.max((double)img.getHeight(), ((RectangularShape)bounds).getHeight()));
|
||||||
|
} else {
|
||||||
|
totalWidth = (int)Math.ceil(Math.max(img.getWidth(), totalWidth));
|
||||||
|
rowHeights[i] = (int)Math.ceil(img.getHeight());
|
||||||
|
labelsGraphics[i] = null;
|
||||||
|
}
|
||||||
|
totalHeight += rowHeights[i];
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
finalLegend = this.createImage(totalWidth += 2, totalHeight, transparent);
|
||||||
|
Color backgroundColor = LegendUtils.getBackgroundColor(this.legendOption);
|
||||||
|
Graphics2D finalGraphics = this.prepareTransparency(transparent, backgroundColor, finalLegend);
|
||||||
|
int topOfRow = 0;
|
||||||
|
int i2 = 0;
|
||||||
|
while (i2 < imgCount) {
|
||||||
|
img = (BufferedImage)imageStack.get(i2);
|
||||||
|
int y = topOfRow;
|
||||||
|
if (img.getHeight() < rowHeights[i2]) {
|
||||||
|
y += (int)((double)(rowHeights[i2] - img.getHeight()) / 2.0);
|
||||||
|
}
|
||||||
|
finalGraphics.drawImage((Image)img, 0, y, null);
|
||||||
|
if (!forceLabelsOn || rules == null) {
|
||||||
|
topOfRow += rowHeights[i2];
|
||||||
|
} else {
|
||||||
|
finalGraphics.setFont(labelFont);
|
||||||
|
if (useAA) {
|
||||||
|
finalGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
} else {
|
||||||
|
finalGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||||
|
}
|
||||||
|
if (labels[i2] != null && labels[i2].length() > 0) {
|
||||||
|
BufferedImage renderedLabel = labelsGraphics[i2];
|
||||||
|
y = topOfRow;
|
||||||
|
if (renderedLabel.getHeight() < rowHeights[i2]) {
|
||||||
|
y += (int)((double)(rowHeights[i2] - renderedLabel.getHeight()) / 2.0);
|
||||||
|
}
|
||||||
|
finalGraphics.drawImage((Image)renderedLabel, img.getWidth(), y, null);
|
||||||
|
renderedLabel.flush();
|
||||||
|
labelsGraphics[i2] = null;
|
||||||
|
}
|
||||||
|
topOfRow += rowHeights[i2];
|
||||||
|
}
|
||||||
|
++i2;
|
||||||
|
}
|
||||||
|
finalGraphics.dispose();
|
||||||
|
}
|
||||||
|
return finalLegend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,248 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.geom.Rectangle2D.Double;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
import org.geotools.renderer.lite.RendererUtilities;
|
||||||
|
import org.geotools.styling.FeatureTypeStyle;
|
||||||
|
import org.geotools.styling.Rule;
|
||||||
|
|
||||||
|
public class LegendUtils
|
||||||
|
{
|
||||||
|
public static final String DEFAULT_FONT_NAME = "Sans-Serif";
|
||||||
|
public static final int DEFAULT_FONT_TYPE = 0;
|
||||||
|
public static final int DEFAULT_FONT_SIZE = 12;
|
||||||
|
public static final Font DEFAULT_FONT = new Font("Sans-Serif", 0, 12);
|
||||||
|
|
||||||
|
public static final Color DEFAULT_BG_COLOR = Color.WHITE;
|
||||||
|
|
||||||
|
public static final Color DEFAULT_FONT_COLOR = Color.BLACK;
|
||||||
|
public static final float hpaddingFactor = 0.15F;
|
||||||
|
public static final float vpaddingFactor = 0.15F;
|
||||||
|
|
||||||
|
public static Font getLabelFont(Map legendOptions)
|
||||||
|
{
|
||||||
|
if (legendOptions == null) {
|
||||||
|
return DEFAULT_FONT;
|
||||||
|
}
|
||||||
|
|
||||||
|
String legendFontName = "Sans-Serif";
|
||||||
|
if (legendOptions.get("FONTNAME") != null) {
|
||||||
|
legendFontName = (String)legendOptions.get("FONTNAME");
|
||||||
|
}
|
||||||
|
|
||||||
|
int legendFontFamily = 0;
|
||||||
|
if (legendOptions.get("FONTSTYLE") != null) {
|
||||||
|
String legendFontFamily_ = (String)legendOptions.get("FONTSTYLE");
|
||||||
|
if (legendFontFamily_.equalsIgnoreCase("ITALIC"))
|
||||||
|
legendFontFamily = 2;
|
||||||
|
else if (legendFontFamily_.equalsIgnoreCase("BOLD")) {
|
||||||
|
legendFontFamily = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int legendFontSize = 12;
|
||||||
|
if (legendOptions.get("FONTSIZE") != null) {
|
||||||
|
try {
|
||||||
|
legendFontSize = Integer.valueOf((String)legendOptions.get("FONTSIZE")).intValue();
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
legendFontSize = 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double dpi = RendererUtilities.getDpi(legendOptions);
|
||||||
|
double standardDpi = RendererUtilities.getDpi(Collections.emptyMap());
|
||||||
|
if (dpi != standardDpi) {
|
||||||
|
double scaleFactor = dpi / standardDpi;
|
||||||
|
legendFontSize = (int)Math.ceil(legendFontSize * scaleFactor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((legendFontFamily == 0) && (legendFontName.equalsIgnoreCase("Sans-Serif")) && (
|
||||||
|
(legendFontSize == 12) || (legendFontSize <= 0))) {
|
||||||
|
return DEFAULT_FONT;
|
||||||
|
}
|
||||||
|
return new Font(legendFontName, legendFontFamily, legendFontSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFontAntiAliasing(Map legendOptions)
|
||||||
|
{
|
||||||
|
if ((legendOptions.get("FONTANTIALIASING") instanceof String)) {
|
||||||
|
String aaVal = (String)legendOptions.get("FONTANTIALIASING");
|
||||||
|
if ((aaVal.equalsIgnoreCase("ON")) || (aaVal.equalsIgnoreCase("TRUE")) ||
|
||||||
|
(aaVal.equalsIgnoreCase("YES")) || (aaVal.equalsIgnoreCase("Y")) ||
|
||||||
|
(aaVal.equalsIgnoreCase("1"))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BufferedImage renderLabel(String label, Graphics2D g, Map legendOption)
|
||||||
|
{
|
||||||
|
Color labelColor = getLabelFontColor(legendOption);
|
||||||
|
BufferedImage renderedLabel;
|
||||||
|
if ((label.indexOf("\n") != -1) || (label.indexOf("\\n") != -1))
|
||||||
|
{
|
||||||
|
Rectangle2D bounds = new Rectangle2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
|
||||||
|
ArrayList lineHeight = new ArrayList();
|
||||||
|
|
||||||
|
String realLabel = label.replaceAll("\\\\n", "\n");
|
||||||
|
StringTokenizer st = new StringTokenizer(realLabel, "\n\r\f");
|
||||||
|
|
||||||
|
while (st.hasMoreElements()) {
|
||||||
|
String token = st.nextToken();
|
||||||
|
Rectangle2D thisLineBounds = g.getFontMetrics().getStringBounds(token, g);
|
||||||
|
|
||||||
|
int thisLineHeight = (int)Math.ceil(thisLineBounds.getHeight());
|
||||||
|
bounds.add(0.0D, thisLineHeight + bounds.getHeight());
|
||||||
|
bounds.add(thisLineBounds.getWidth(), 0.0D);
|
||||||
|
lineHeight.add(Integer.valueOf((int)Math.ceil(thisLineBounds.getHeight())));
|
||||||
|
}
|
||||||
|
|
||||||
|
renderedLabel = new BufferedImage((int)Math.ceil(bounds.getWidth()),
|
||||||
|
(int)Math.ceil(bounds.getHeight()), 2);
|
||||||
|
|
||||||
|
st = new StringTokenizer(realLabel, "\n\r\f");
|
||||||
|
|
||||||
|
Graphics2D rlg = renderedLabel.createGraphics();
|
||||||
|
rlg.setColor(labelColor);
|
||||||
|
rlg.setFont(g.getFont());
|
||||||
|
rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||||
|
g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
|
||||||
|
|
||||||
|
int y = 0 - g.getFontMetrics().getDescent();
|
||||||
|
int c = 0;
|
||||||
|
|
||||||
|
while (st.hasMoreElements()) {
|
||||||
|
y += ((Integer)lineHeight.get(c++)).intValue();
|
||||||
|
rlg.drawString(st.nextToken(), 0, y);
|
||||||
|
}
|
||||||
|
rlg.dispose();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int height = (int)Math.ceil(g.getFontMetrics().getStringBounds(label, g).getHeight());
|
||||||
|
int width = (int)Math.ceil(g.getFontMetrics().getStringBounds(label, g).getWidth());
|
||||||
|
renderedLabel = new BufferedImage(width, height, 2);
|
||||||
|
|
||||||
|
Graphics2D rlg = renderedLabel.createGraphics();
|
||||||
|
rlg.setColor(labelColor);
|
||||||
|
rlg.setFont(g.getFont());
|
||||||
|
rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
|
||||||
|
rlg.drawString(label, 0, height - rlg.getFontMetrics().getDescent());
|
||||||
|
rlg.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderedLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color getLabelFontColor(Map legendOptions)
|
||||||
|
{
|
||||||
|
String color = legendOptions != null ? (String)legendOptions.get("FONTCOLOR") : null;
|
||||||
|
if (color == null) {
|
||||||
|
return DEFAULT_FONT_COLOR;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return color(color); } catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
|
return DEFAULT_FONT_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Rule getRule(FeatureTypeStyle[] fts, String rule)
|
||||||
|
{
|
||||||
|
Rule sldRule = null;
|
||||||
|
for (int i = 0; i < fts.length; i++) {
|
||||||
|
Rule[] rules = fts[i].getRules();
|
||||||
|
|
||||||
|
for (int r = 0; r < rules.length; r++) {
|
||||||
|
if (rule.equalsIgnoreCase(rules[r].getName())) {
|
||||||
|
sldRule = rules[r];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sldRule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Rule[] getApplicableRules(FeatureTypeStyle[] ftStyles, double scaleDenominator)
|
||||||
|
{
|
||||||
|
List ruleList = new ArrayList();
|
||||||
|
|
||||||
|
for (int i = 0; i < ftStyles.length; i++) {
|
||||||
|
FeatureTypeStyle fts = ftStyles[i];
|
||||||
|
Rule[] rules = fts.getRules();
|
||||||
|
|
||||||
|
for (int j = 0; j < rules.length; j++) {
|
||||||
|
Rule r = rules[j];
|
||||||
|
|
||||||
|
if (isWithInScale(r, scaleDenominator)) {
|
||||||
|
ruleList.add(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Rule[])ruleList.toArray(new Rule[ruleList.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWithInScale(Rule r, double scaleDenominator)
|
||||||
|
{
|
||||||
|
return (scaleDenominator == -1.0D) || (
|
||||||
|
(r.getMinScaleDenominator() - 1.0E-006D <= scaleDenominator) && (
|
||||||
|
r.getMaxScaleDenominator() + 1.0E-006D > scaleDenominator));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color getBackgroundColor(Map legendOptions)
|
||||||
|
{
|
||||||
|
if (legendOptions == null) {
|
||||||
|
return DEFAULT_BG_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object clr = legendOptions.get("BGCOLOR");
|
||||||
|
if ((clr instanceof Color))
|
||||||
|
return (Color)clr;
|
||||||
|
if (clr == null) {
|
||||||
|
return DEFAULT_BG_COLOR;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return color((String)clr); } catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
|
return DEFAULT_BG_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color color(String hex)
|
||||||
|
{
|
||||||
|
if (hex.startsWith("0x")) {
|
||||||
|
hex = hex.substring(2);
|
||||||
|
}
|
||||||
|
if (!hex.startsWith("#")) {
|
||||||
|
hex = "#" + hex;
|
||||||
|
}
|
||||||
|
return Color.decode(hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum HAlign
|
||||||
|
{
|
||||||
|
LEFT, CENTERED, RIGHT, JUSTIFIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum VAlign
|
||||||
|
{
|
||||||
|
TOP, MIDDLE, BOTTOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,76 +1,65 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
import org.geotools.styling.DescriptionImpl;
|
|
||||||
import org.geotools.styling.StyleImpl;
|
import org.geotools.styling.StyleImpl;
|
||||||
|
|
||||||
public class MapStyle extends StyleImpl
|
public class MapStyle
|
||||||
{
|
extends StyleImpl {
|
||||||
private LayerFactory.LayerType layerType;
|
private LayerFactory.LayerType layerType;
|
||||||
private String serverName;
|
private String serverName;
|
||||||
private String typeName;
|
private String typeName;
|
||||||
private Double wrapTileText;
|
private Double wrapTileText;
|
||||||
|
|
||||||
public MapStyle()
|
public MapStyle() {
|
||||||
{
|
this.setName("");
|
||||||
setName("");
|
if (this.getDescription() != null) {
|
||||||
if (getDescription() != null) {
|
this.getDescription().setTitle("");
|
||||||
getDescription().setTitle("");
|
this.getDescription().setAbstract("");
|
||||||
getDescription().setAbstract("");
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLayerType(LayerFactory.LayerType lType) {
|
|
||||||
this.layerType = lType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LayerFactory.LayerType getLayerType() {
|
|
||||||
return this.layerType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServerName(String sName) {
|
|
||||||
this.serverName = sName.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getServerName() {
|
|
||||||
return this.serverName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeName(String tName) {
|
|
||||||
this.typeName = tName.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeName() {
|
|
||||||
return this.typeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isWrapTileTextStyle()
|
|
||||||
{
|
|
||||||
if ((this.wrapTileText == null) || (this.wrapTileText.doubleValue() <= 0.0D)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
public void setLayerType(LayerFactory.LayerType lType) {
|
||||||
}
|
this.layerType = lType;
|
||||||
|
|
||||||
public double getWrapTileText()
|
|
||||||
{
|
|
||||||
if ((this.wrapTileText == null) || (this.wrapTileText.doubleValue() <= 0.0D)) {
|
|
||||||
return 0.0D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.wrapTileText.doubleValue();
|
public LayerFactory.LayerType getLayerType() {
|
||||||
}
|
return this.layerType;
|
||||||
|
|
||||||
public void setWrapTileText(double dValue)
|
|
||||||
{
|
|
||||||
if (dValue > 1.0D) {
|
|
||||||
dValue = 1.0D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((this.wrapTileText == null) || (this.wrapTileText.doubleValue() <= 0.0D)) {
|
public void setServerName(String sName) {
|
||||||
this.wrapTileText = Double.valueOf(dValue);
|
this.serverName = sName.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerName() {
|
||||||
|
return this.serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTypeName(String tName) {
|
||||||
|
this.typeName = tName.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTypeName() {
|
||||||
|
return this.typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWrapTileTextStyle() {
|
||||||
|
return this.wrapTileText != null && !(this.wrapTileText <= 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getWrapTileText() {
|
||||||
|
if (this.wrapTileText == null || this.wrapTileText <= 0.0) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
return this.wrapTileText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWrapTileText(double dValue) {
|
||||||
|
if (dValue > 1.0) {
|
||||||
|
dValue = 1.0;
|
||||||
|
}
|
||||||
|
if (this.wrapTileText == null || this.wrapTileText <= 0.0) {
|
||||||
|
this.wrapTileText = dValue;
|
||||||
|
} else if (this.wrapTileText < dValue) {
|
||||||
|
this.wrapTileText = dValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (this.wrapTileText.doubleValue() < dValue)
|
|
||||||
this.wrapTileText = Double.valueOf(dValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class MyStartServer implements ApplicationListener<ContextRefreshedEvent> {
|
||||||
|
|
||||||
|
// 로깅을 위한 Logger 인스턴스
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(MyStartServer.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ContextRefreshedEvent가 발생했을 때 호출되는 메서드입니다.
|
||||||
|
* 이 이벤트는 모든 빈이 로드되고 초기화된 후 애플리케이션 컨텍스트가 성공적으로 새로고침되었을 때 발생합니다.
|
||||||
|
*
|
||||||
|
* @param event 발생한 ContextRefreshedEvent
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||||
|
// 부모 컨텍스트에도 이벤트가 발생할 수 있으므로, 최상위(루트) 컨텍스트에서만 실행되도록 확인합니다.
|
||||||
|
// 이는 중복 실행을 방지합니다.
|
||||||
|
if (event.getApplicationContext().getParent() == null) {
|
||||||
|
LOGGER.info("**************************************");
|
||||||
|
LOGGER.info("* *");
|
||||||
|
LOGGER.info("* WMS 서버 시작 *");
|
||||||
|
LOGGER.info("* *");
|
||||||
|
LOGGER.info("**************************************");
|
||||||
|
|
||||||
|
// 여기에 서버 시작 시 실행하고 싶은 다른 로직을 추가할 수 있습니다.
|
||||||
|
// 예: 초기 데이터 로드, 스케줄러 시작 등
|
||||||
|
|
||||||
|
if (ServerConfiguration.getInstance().startServer())
|
||||||
|
ServerInfo.getInstance().setStarted(true);
|
||||||
|
else {
|
||||||
|
ServerInfo.getInstance().setStarted(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceMngr.initServices();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,737 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.tmax.tibero.jdbc.TbBlob;
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||||
|
import com.vividsolutions.jts.geom.LinearRing;
|
||||||
|
import com.vividsolutions.jts.io.WKBWriter;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.sql.Blob;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.geotools.geometry.jts.JTS;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.jdbc.JDBCDataStore;
|
||||||
|
import org.geotools.jdbc.PreparedFilterToSQL;
|
||||||
|
import org.geotools.jdbc.PreparedStatementSQLDialect;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class NonSpatialDialect extends PreparedStatementSQLDialect
|
||||||
|
implements O2SqlDialect
|
||||||
|
{
|
||||||
|
final String O2SERVER_BOUND_KEY_START = "?S?";
|
||||||
|
final String O2SERVER_BOUND_KEY_END = "?E?";
|
||||||
|
final Integer DEFAULT_CRS = Integer.valueOf(4326);
|
||||||
|
final String serverName;
|
||||||
|
final String dbType;
|
||||||
|
public ConcurrentHashMap<String, Double> gridStore = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
ThreadLocal<WKBAttributeIO> wkbReader = new ThreadLocal();
|
||||||
|
|
||||||
|
public NonSpatialDialect(String name, String type, JDBCDataStore dataStore)
|
||||||
|
{
|
||||||
|
super(dataStore);
|
||||||
|
this.serverName = name;
|
||||||
|
this.dbType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> getMapping(ResultSet columnMetaData, Connection cx)
|
||||||
|
throws SQLException
|
||||||
|
{
|
||||||
|
String typeName = columnMetaData.getString("TYPE_NAME");
|
||||||
|
|
||||||
|
if ("blob".equalsIgnoreCase(typeName))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class gemetry = lookupGeometryType(columnMetaData, cx);
|
||||||
|
|
||||||
|
if (gemetry != null) {
|
||||||
|
return gemetry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException localIOException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Class lookupGeometryType(ResultSet columnMetaData, Connection cx)
|
||||||
|
throws SQLException, IOException
|
||||||
|
{
|
||||||
|
String schemaName = columnMetaData.getString("TABLE_SCHEM");
|
||||||
|
String tableName = columnMetaData.getString("TABLE_NAME");
|
||||||
|
String columnName = columnMetaData.getString("COLUMN_NAME");
|
||||||
|
|
||||||
|
lookupGridSize(cx, schemaName, tableName, columnName);
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Lookup geometry type for [" + columnMetaData.getString("TABLE_NAME") + "]");
|
||||||
|
|
||||||
|
if ((schemaName == null) || (schemaName.equals("")))
|
||||||
|
schemaName = "";
|
||||||
|
else {
|
||||||
|
schemaName = schemaName.toUpperCase() + ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT GEOMETRY_TYPE FROM ");
|
||||||
|
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
|
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||||
|
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
|
||||||
|
if (rs.next())
|
||||||
|
return O2GeometryTypeMap.lookUpMeta(Integer.valueOf(rs.getInt(1)));
|
||||||
|
} catch (Exception localException) {
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT ");
|
||||||
|
sql.append(columnName.toUpperCase());
|
||||||
|
sql.append(" FROM ");
|
||||||
|
sql.append(schemaName).append(tableName.toUpperCase());
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
|
||||||
|
if ((rs != null) && (rs.next())) {
|
||||||
|
Geometry geom = decodeGeometryValue(null, rs, columnName, new GeometryFactory(), cx);
|
||||||
|
Class localClass2 = O2GeometryTypeMap.lookUpGeometry(geom.getGeometryType()); return localClass2;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lookupGridSize(Connection cx, String schemaName, String tableName, String columnName)
|
||||||
|
throws SQLException, IOException
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Lookup GridSize for [" + tableName + "]");
|
||||||
|
|
||||||
|
String gridKey = tableName.trim().toUpperCase() + "_" + columnName.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (this.gridStore.get(gridKey) != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((schemaName == null) || (schemaName.equals("")))
|
||||||
|
schemaName = "";
|
||||||
|
else {
|
||||||
|
schemaName = schemaName.toUpperCase() + ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT GRID_SIZE FROM ");
|
||||||
|
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
|
sql.append(" WHERE TABLE_NAME = '").append(tableName.trim().toUpperCase()).append("'");
|
||||||
|
sql.append(" AND COLUMN_NAME = '").append(columnName.trim().toUpperCase()).append("'");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if ((rs != null) && (rs.next())) {
|
||||||
|
double grid = rs.getDouble(1);
|
||||||
|
this.gridStore.put(gridKey, Double.valueOf(grid));
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logError("[DB]",
|
||||||
|
"Failed to get GridSize from O2SERVER_GEOMETRY_LAYER for [" +
|
||||||
|
tableName.trim().toUpperCase() + "/" + columnName.trim().toUpperCase() + "]");
|
||||||
|
throw new IOException("GridSize is NULL for [" + tableName.trim().toUpperCase() + "/" + columnName.trim().toUpperCase() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerSqlTypeNameToClassMappings(Map<String, Class<?>> mappings)
|
||||||
|
{
|
||||||
|
super.registerSqlTypeNameToClassMappings(mappings);
|
||||||
|
|
||||||
|
mappings.put("TEXT", String.class);
|
||||||
|
mappings.put("text", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerSqlTypeToClassMappings(Map<Integer, Class<?>> mappings)
|
||||||
|
{
|
||||||
|
super.registerSqlTypeToClassMappings(mappings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getGeometrySRID(String schemaName, String tableName, String columnName, Connection cx)
|
||||||
|
throws SQLException
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Get Geometry SRID value for [" + tableName.toUpperCase() + "]");
|
||||||
|
|
||||||
|
if ((schemaName == null) || (schemaName.equals("")))
|
||||||
|
schemaName = "";
|
||||||
|
else {
|
||||||
|
schemaName = schemaName.toUpperCase() + ".";
|
||||||
|
}
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Integer localInteger;
|
||||||
|
try {
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append("SELECT REF_SRID FROM ");
|
||||||
|
sb.append(schemaName).append("O2MAP_SERVICE_INFO");
|
||||||
|
sb.append(" WHERE REF_SOURCE = '").append(tableName.toUpperCase()).append("'");
|
||||||
|
sb.append(" OR REF_SOURCE = '").append(tableName.toLowerCase()).append("'");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sb.toString());
|
||||||
|
rs = stat.executeQuery(sb.toString());
|
||||||
|
|
||||||
|
if ((rs != null) && (rs.next())) {
|
||||||
|
Object obj = rs.getObject(1);
|
||||||
|
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2MAP_SERVICE_INFO for [" +
|
||||||
|
tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT SRID FROM ");
|
||||||
|
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
|
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||||
|
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
|
||||||
|
if ((rs != null) && (rs.next())) {
|
||||||
|
Object obj = rs.getObject(1);
|
||||||
|
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2SERVER_GEOMETRY_LAYER for [" +
|
||||||
|
tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Failed to get Geometry SRID value. Now Use Default [" + this.DEFAULT_CRS + "]");
|
||||||
|
return this.DEFAULT_CRS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem createCRS(int srid, Connection cx) throws SQLException
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return CRSMngr.getLayerCRS(srid, true); } catch (Exception e) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLimitOffsetSupported()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyLimitOffset(StringBuffer sql, int limit, int offset)
|
||||||
|
{
|
||||||
|
if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.ALTIBASE.getTypeName()))
|
||||||
|
{
|
||||||
|
if ((limit >= 0) && (limit < 2147483647)) {
|
||||||
|
sql.append(" LIMIT " + limit);
|
||||||
|
if (offset > 0)
|
||||||
|
sql.append(" OFFSET " + offset);
|
||||||
|
}
|
||||||
|
else if (offset > 0) {
|
||||||
|
sql.append(" OFFSET " + offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.TIBERO.getTypeName()))
|
||||||
|
{
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
sql.insert(0, "SELECT * FROM (");
|
||||||
|
sql.append(") WHERE ROWNUM <= " + limit);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
long max = limit == 2147483647 ? 9223372036854775807L : limit + offset;
|
||||||
|
sql.insert(0, "SELECT * FROM (SELECT A.*, ROWNUM RNUM FROM ( ");
|
||||||
|
sql.append(") A WHERE ROWNUM <= " + max + ")");
|
||||||
|
sql.append("WHERE RNUM > " + offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.ORACLE.getTypeName()))
|
||||||
|
{
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
sql.insert(0, "SELECT * FROM (");
|
||||||
|
sql.append(") WHERE ROWNUM <= " + limit);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
long max = limit == 2147483647 ? 9223372036854775807L : limit + offset;
|
||||||
|
sql.insert(0, "SELECT * FROM (SELECT A.*, ROWNUM RNUM FROM ( ");
|
||||||
|
sql.append(") A WHERE ROWNUM <= " + max + ")");
|
||||||
|
sql.append("WHERE RNUM > " + offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.MYSQL.getTypeName()))
|
||||||
|
{
|
||||||
|
if ((limit >= 0) && (limit < 2147483647)) {
|
||||||
|
if (offset > 0)
|
||||||
|
sql.append(" LIMIT " + offset + ", " + limit);
|
||||||
|
else
|
||||||
|
sql.append(" LIMIT " + limit);
|
||||||
|
} else if (offset > 0)
|
||||||
|
{
|
||||||
|
sql.append(" LIMIT " + offset + ", " + 9223372036854775807L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.POSTGIS.getTypeName()))
|
||||||
|
{
|
||||||
|
if ((limit >= 0) && (limit < 2147483647)) {
|
||||||
|
sql.append(" LIMIT " + limit);
|
||||||
|
if (offset > 0)
|
||||||
|
sql.append(" OFFSET " + offset);
|
||||||
|
}
|
||||||
|
else if (offset > 0) {
|
||||||
|
sql.append(" OFFSET " + offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.KAIROS.getTypeName()))
|
||||||
|
{
|
||||||
|
if ((limit >= 0) && (limit < 2147483647)) {
|
||||||
|
if (offset > 0)
|
||||||
|
sql.append(" LIMIT " + offset + ", " + limit);
|
||||||
|
else
|
||||||
|
sql.append(" LIMIT " + limit);
|
||||||
|
} else if (offset > 0)
|
||||||
|
sql.append(" LIMIT " + offset + ", " + 9223372036854775807L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReferencedEnvelope> getOptimizedBounds(String schemaName, SimpleFeatureType featureType, Connection cx)
|
||||||
|
throws SQLException, IOException
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Make optimal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||||
|
|
||||||
|
List resultList = new ArrayList();
|
||||||
|
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
|
String schema = "";
|
||||||
|
if ((schemaName == null) || (schemaName.equals("")))
|
||||||
|
schema = "";
|
||||||
|
else {
|
||||||
|
schema = schemaName + ".";
|
||||||
|
}
|
||||||
|
schema = schema.toUpperCase();
|
||||||
|
|
||||||
|
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||||
|
if ((att instanceof GeometryDescriptor))
|
||||||
|
{
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT MIN_1D, MAX_1D, MIN_2D, MAX_2D FROM ");
|
||||||
|
sql.append(schema).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
|
sql.append(" WHERE");
|
||||||
|
sql.append(" TABLE_NAME = ").append("'").append(featureType.getTypeName().toUpperCase()).append("'");
|
||||||
|
sql.append(" AND");
|
||||||
|
sql.append(" COLUMN_NAME = ").append("'").append(att.getLocalName().toUpperCase()).append("'");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
|
||||||
|
if ((rs != null) && (rs.next())) {
|
||||||
|
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||||
|
double x1 = rs.getDouble(1);
|
||||||
|
double x2 = rs.getDouble(2);
|
||||||
|
double y1 = rs.getDouble(3);
|
||||||
|
double y2 = rs.getDouble(4);
|
||||||
|
|
||||||
|
resultList.add(new ReferencedEnvelope(x1, x2, y1, y2, crs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
List localList1;
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Failed to make optimal bounds, falling back intenal bounds.");
|
||||||
|
return getInternalBounds(schemaName, featureType, cx);
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReferencedEnvelope> getInternalBounds(String schemaName, SimpleFeatureType featureType, Connection cx)
|
||||||
|
{
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Make internal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||||
|
|
||||||
|
List resultList = new ArrayList();
|
||||||
|
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
|
if ((schemaName == null) || (schemaName.equals("")))
|
||||||
|
schemaName = "";
|
||||||
|
else {
|
||||||
|
schemaName = schemaName + ".";
|
||||||
|
}
|
||||||
|
schemaName = schemaName.toUpperCase();
|
||||||
|
|
||||||
|
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||||
|
if ((att instanceof GeometryDescriptor))
|
||||||
|
{
|
||||||
|
String tableName = featureType.getTypeName() + "_" + att.getLocalName() + "_INDEX";
|
||||||
|
tableName.toUpperCase();
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT MIN(MIN_1D), MAX(MAX_1D), MIN(MIN_2D), MAX(MAX_2D) FROM ");
|
||||||
|
sql.append(schemaName).append(tableName);
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
|
||||||
|
if ((rs != null) && (rs.next())) {
|
||||||
|
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||||
|
double x1 = rs.getDouble(1);
|
||||||
|
double x2 = rs.getDouble(2);
|
||||||
|
double y1 = rs.getDouble(3);
|
||||||
|
double y2 = rs.getDouble(4);
|
||||||
|
|
||||||
|
resultList.add(new ReferencedEnvelope(x1, x2, y1, y2, crs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Failed to make intenal bounds, falling back on envelope aggregation.");
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeGeometryEnvelope(String tableName, String geometryColumn, StringBuffer sql)
|
||||||
|
{
|
||||||
|
String envelopeTable = null;
|
||||||
|
if ((this.dataStore.getDatabaseSchema() == null) || (this.dataStore.getDatabaseSchema().equals("")))
|
||||||
|
envelopeTable = tableName + "_" + geometryColumn + "_INDEX";
|
||||||
|
else {
|
||||||
|
envelopeTable = this.dataStore.getDatabaseSchema() + "." + tableName + "_" + geometryColumn + "_INDEX";
|
||||||
|
}
|
||||||
|
envelopeTable = envelopeTable.toUpperCase();
|
||||||
|
|
||||||
|
sql.append("?S?");
|
||||||
|
sql.append(envelopeTable);
|
||||||
|
sql.append("?E?");
|
||||||
|
sql.append(" MIN(MIN_1D), MAX(MAX_1D), MIN(MIN_2D), MAX(MAX_2D) ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx)
|
||||||
|
throws SQLException, IOException
|
||||||
|
{
|
||||||
|
int count = rs.getMetaData().getColumnCount();
|
||||||
|
int evnObject = count / 4 - 1;
|
||||||
|
|
||||||
|
if (evnObject + 1 == column)
|
||||||
|
{
|
||||||
|
double x1 = rs.getDouble(evnObject + 1);
|
||||||
|
double x2 = rs.getDouble(evnObject + 2);
|
||||||
|
double y1 = rs.getDouble(evnObject + 3);
|
||||||
|
double y2 = rs.getDouble(evnObject + 4);
|
||||||
|
|
||||||
|
return new Envelope(x1, x2, y1, y2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void prepareGeometryValue(Geometry g, int dimension, int srid, Class binding, StringBuffer sql)
|
||||||
|
{
|
||||||
|
super.prepareGeometryValue(g, dimension, srid, binding, sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column)
|
||||||
|
throws SQLException
|
||||||
|
{
|
||||||
|
if (g != null) {
|
||||||
|
if ((g instanceof LinearRing))
|
||||||
|
{
|
||||||
|
g = g.getFactory().createLineString(((LinearRing)g).getCoordinateSequence());
|
||||||
|
}
|
||||||
|
|
||||||
|
WKBWriter wkbWriter = new WKBWriter(dimension);
|
||||||
|
byte[] bytes = wkbWriter.write(g);
|
||||||
|
|
||||||
|
int length = bytes.length + getBytesSize(dimension);
|
||||||
|
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocateDirect(length);
|
||||||
|
byte[] extentBytes = getExtentBytes(dimension, g);
|
||||||
|
buffer.put(extentBytes);
|
||||||
|
buffer.put(bytes);
|
||||||
|
|
||||||
|
buffer.rewind();
|
||||||
|
byte[] o2Geom = new byte[length];
|
||||||
|
buffer.get(o2Geom);
|
||||||
|
|
||||||
|
ps.setBytes(column, o2Geom);
|
||||||
|
} else {
|
||||||
|
ps.setNull(column, 1111, "GEOMETRY");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getExtentBytes(int dimension, Geometry geom) {
|
||||||
|
int bufferSize = dimension * 8 * 2 + 1;
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
|
||||||
|
|
||||||
|
buffer.put((byte)dimension);
|
||||||
|
|
||||||
|
ReferencedEnvelope env = JTS.toEnvelope(geom);
|
||||||
|
|
||||||
|
if (dimension >= 1) {
|
||||||
|
buffer.putDouble(env.getMinX());
|
||||||
|
buffer.putDouble(env.getMaxX());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dimension >= 2) {
|
||||||
|
buffer.putDouble(env.getMinY());
|
||||||
|
buffer.putDouble(env.getMaxY());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dimension >= 3) {
|
||||||
|
buffer.putDouble(0.0D);
|
||||||
|
buffer.putDouble(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dimension >= 4) {
|
||||||
|
buffer.putDouble(0.0D);
|
||||||
|
buffer.putDouble(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Geometry decodeGeometryValue(GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx)
|
||||||
|
throws IOException, SQLException
|
||||||
|
{
|
||||||
|
byte[] bytes = getBytes(rs.getBlob(column));
|
||||||
|
|
||||||
|
int size = getBytesSize(bytes[0]);
|
||||||
|
byte[] newBytes = new byte[bytes.length - size];
|
||||||
|
|
||||||
|
System.arraycopy(bytes, size, newBytes, 0, newBytes.length);
|
||||||
|
|
||||||
|
WKBAttributeIO reader = getWKBReader(factory);
|
||||||
|
Geometry geom = reader.read(newBytes);
|
||||||
|
|
||||||
|
return geom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getBytes(Blob blob) throws SQLException, IOException
|
||||||
|
{
|
||||||
|
InputStream blobStream = null;
|
||||||
|
ByteArrayOutputStream outStream = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.TIBERO.getTypeName())) {
|
||||||
|
TbBlob tbblob = (TbBlob)blob;
|
||||||
|
blobStream = tbblob.getBinaryStream();
|
||||||
|
} else {
|
||||||
|
blobStream = blob.getBinaryStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
outStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int nbytes = 0;
|
||||||
|
while ((nbytes = blobStream.read(buffer)) != -1) {
|
||||||
|
outStream.write(buffer, 0, nbytes);
|
||||||
|
}
|
||||||
|
return outStream.toByteArray();
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (this.dbType.equalsIgnoreCase(O2DSFactory.DBMSType.ORACLE.getTypeName())) {
|
||||||
|
blob.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blobStream != null) {
|
||||||
|
blobStream.close();
|
||||||
|
}
|
||||||
|
if (outStream != null)
|
||||||
|
outStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getBytesSize(int dimension)
|
||||||
|
{
|
||||||
|
return 1 + 16 * dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WKBAttributeIO getWKBReader(GeometryFactory factory)
|
||||||
|
{
|
||||||
|
WKBAttributeIO reader = (WKBAttributeIO)this.wkbReader.get();
|
||||||
|
if (reader == null) {
|
||||||
|
reader = new WKBAttributeIO(factory);
|
||||||
|
this.wkbReader.set(reader);
|
||||||
|
} else {
|
||||||
|
reader.setGeometryFactory(factory);
|
||||||
|
}
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PreparedFilterToSQL createPreparedFilterToSQL()
|
||||||
|
{
|
||||||
|
return new NonSpatialFilterToSQL(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean lookupGeneratedValuesPostInsert()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSelect(PreparedStatement select, Connection cx, SimpleFeatureType featureType)
|
||||||
|
throws SQLException
|
||||||
|
{
|
||||||
|
select.setFetchSize(this.dataStore.getFetchSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDelete(PreparedStatement delete, Connection cx, SimpleFeatureType featureType) throws SQLException
|
||||||
|
{
|
||||||
|
delete.setFetchSize(this.dataStore.getFetchSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onInsert(PreparedStatement insert, Connection cx, SimpleFeatureType featureType) throws SQLException
|
||||||
|
{
|
||||||
|
insert.setFetchSize(this.dataStore.getFetchSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onUpdate(PreparedStatement update, Connection cx, SimpleFeatureType featureType) throws SQLException
|
||||||
|
{
|
||||||
|
update.setFetchSize(this.dataStore.getFetchSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeSchemaName(String raw, StringBuffer sql)
|
||||||
|
{
|
||||||
|
super.encodeSchemaName(raw, sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeTableName(String raw, StringBuffer sql)
|
||||||
|
{
|
||||||
|
if (sql.indexOf("?S?") != -1) {
|
||||||
|
int sIndex = sql.indexOf("?S?");
|
||||||
|
int eIndex = sql.indexOf("?E?") + "?E?".length();
|
||||||
|
String tableName = sql.substring(sIndex, eIndex);
|
||||||
|
tableName = tableName.replace("?S?", "");
|
||||||
|
tableName = tableName.replace("?E?", "");
|
||||||
|
|
||||||
|
sql.delete(sIndex, eIndex);
|
||||||
|
sql.append(tableName);
|
||||||
|
} else {
|
||||||
|
super.encodeTableName(raw, sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeColumnName(String prefix, String raw, StringBuffer sql)
|
||||||
|
{
|
||||||
|
if (prefix != null) {
|
||||||
|
sql.append(prefix).append(".");
|
||||||
|
}
|
||||||
|
sql.append(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameEscape()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public JDBCDataStore getDataStore()
|
||||||
|
{
|
||||||
|
return this.dataStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDbType()
|
||||||
|
{
|
||||||
|
return this.dbType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,303 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.geotools.data.Transaction;
|
||||||
|
import org.geotools.data.jdbc.FilterToSQL.FieldEncoder;
|
||||||
|
import org.geotools.filter.FilterCapabilities;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.jdbc.JDBCDataStore;
|
||||||
|
import org.geotools.jdbc.JoinPropertyName;
|
||||||
|
import org.geotools.jdbc.PreparedFilterToSQL;
|
||||||
|
import org.geotools.jdbc.PrimaryKey;
|
||||||
|
import org.geotools.jdbc.PrimaryKeyColumn;
|
||||||
|
import org.geotools.jdbc.SQLDialect;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.filter.expression.Literal;
|
||||||
|
import org.opengis.filter.expression.PropertyName;
|
||||||
|
import org.opengis.filter.spatial.BBOX;
|
||||||
|
import org.opengis.filter.spatial.BinarySpatialOperator;
|
||||||
|
import org.opengis.geometry.BoundingBox;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
|
public class NonSpatialFilterToSQL extends PreparedFilterToSQL
|
||||||
|
{
|
||||||
|
private NonSpatialDialect dsDialectNS;
|
||||||
|
|
||||||
|
public NonSpatialFilterToSQL(NonSpatialDialect dialect)
|
||||||
|
{
|
||||||
|
this.dsDialectNS = dialect;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected FilterCapabilities createFilterCapabilities()
|
||||||
|
{
|
||||||
|
FilterCapabilities caps = new FilterCapabilities();
|
||||||
|
caps.addAll(SQLDialect.BASE_DBMS_CAPABILITIES);
|
||||||
|
|
||||||
|
caps.addType(BBOX.class);
|
||||||
|
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object visitBinarySpatialOperator(BinarySpatialOperator filter, PropertyName property, Literal geometry, boolean swapped, Object extraData)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ((filter instanceof BBOX))
|
||||||
|
createBBox(filter, property);
|
||||||
|
else
|
||||||
|
throw new RuntimeException("Unsupported filter type " + filter.getClass());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Error to make BinarySpatialOperator", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return extraData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createBBox(BinarySpatialOperator filter, PropertyName property)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
BBOX bbox = (BBOX)filter;
|
||||||
|
Envelope envelop = ReferencedEnvelope.reference(bbox.getBounds());
|
||||||
|
envelop = intersectionBound(envelop);
|
||||||
|
|
||||||
|
if ((envelop == null) || (envelop.isNull())) {
|
||||||
|
this.out.append(" 1=0 ");
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "WHERE : " + this.out.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String propertyName = findPropertyName(property);
|
||||||
|
|
||||||
|
String indexName = new String();
|
||||||
|
if ((this.databaseSchema == null) || (this.databaseSchema.equals("")))
|
||||||
|
indexName = this.featureType.getTypeName() + "_" + propertyName + "_INDEX";
|
||||||
|
else {
|
||||||
|
indexName = this.databaseSchema + "." + this.featureType.getTypeName() + "_" + propertyName + "_INDEX";
|
||||||
|
}
|
||||||
|
indexName = indexName.toUpperCase();
|
||||||
|
|
||||||
|
String pkCloumn = ((PrimaryKeyColumn)this.primaryKey.getColumns().get(0)).getName().toUpperCase();
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
try {
|
||||||
|
GridRange gridRange = getIntersectRange(envelop, propertyName);
|
||||||
|
|
||||||
|
sql.append(" ").append(pkCloumn).append(" IN (");
|
||||||
|
sql.append(" SELECT ").append(pkCloumn).append(" FROM ").append(indexName);
|
||||||
|
sql.append(" WHERE ");
|
||||||
|
sql.append(" COL_NUMBER >= ").append(String.valueOf(gridRange.sc)).append(" AND");
|
||||||
|
sql.append(" COL_NUMBER <= ").append(String.valueOf(gridRange.ec)).append(" AND");
|
||||||
|
sql.append(" ROW_NUMBER >= ").append(String.valueOf(gridRange.sr)).append(" AND");
|
||||||
|
sql.append(" ROW_NUMBER <= ").append(String.valueOf(gridRange.er)).append(" AND");
|
||||||
|
sql.append(" MAX_1D >= ").append(String.valueOf(envelop.getMinX())).append(" AND");
|
||||||
|
sql.append(" MIN_1D <= ").append(String.valueOf(envelop.getMaxX())).append(" AND");
|
||||||
|
sql.append(" MAX_2D >= ").append(String.valueOf(envelop.getMinY())).append(" AND");
|
||||||
|
sql.append(" MIN_2D <= ").append(String.valueOf(envelop.getMaxY()));
|
||||||
|
sql.append(" )");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
sql = new StringBuffer();
|
||||||
|
sql.append(" ").append(pkCloumn).append(" IN (");
|
||||||
|
sql.append(" SELECT ").append(pkCloumn).append(" FROM ").append(indexName);
|
||||||
|
sql.append(" WHERE ");
|
||||||
|
sql.append(" MAX_1D >= ").append(String.valueOf(envelop.getMinX())).append(" AND");
|
||||||
|
sql.append(" MIN_1D <= ").append(String.valueOf(envelop.getMaxX())).append(" AND");
|
||||||
|
sql.append(" MAX_2D >= ").append(String.valueOf(envelop.getMinY())).append(" AND");
|
||||||
|
sql.append(" MIN_2D <= ").append(String.valueOf(envelop.getMaxY()));
|
||||||
|
sql.append(" )");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.out.append(sql);
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "WHERE : " + this.out.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String findPropertyName(PropertyName expression)
|
||||||
|
{
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
|
if ((expression instanceof JoinPropertyName))
|
||||||
|
{
|
||||||
|
sb.append(escapeName(((JoinPropertyName)expression).getAlias()));
|
||||||
|
sb.append(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
AttributeDescriptor attribute = null;
|
||||||
|
try {
|
||||||
|
attribute = (AttributeDescriptor)expression.evaluate(this.featureType);
|
||||||
|
}
|
||||||
|
catch (Exception localException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
String encodedField;
|
||||||
|
if (attribute != null)
|
||||||
|
encodedField = this.fieldEncoder.encode(escapeName(attribute.getLocalName()));
|
||||||
|
else {
|
||||||
|
encodedField = this.fieldEncoder.encode(escapeName(expression.getPropertyName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(encodedField);
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Envelope intersectionBound(Envelope envelop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ArrayList<Layer> layers = ServerContext.getMap().getAllLayers();
|
||||||
|
for (Layer layer : layers)
|
||||||
|
{
|
||||||
|
if ((layer instanceof FeatureLayer))
|
||||||
|
{
|
||||||
|
if ((layer.getServerName().equalsIgnoreCase(this.dsDialectNS.serverName)) &&
|
||||||
|
(layer.getSourceName().equalsIgnoreCase(this.featureType.getTypeName())))
|
||||||
|
{
|
||||||
|
return layer.getBBox().intersection(envelop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception localException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return envelop;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BoundingBox transformFilter(BoundingBox bound)
|
||||||
|
{
|
||||||
|
if (bound.getCoordinateReferenceSystem() == null) {
|
||||||
|
return bound;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem targetCRS = getCRS(this.featureType.getTypeName());
|
||||||
|
if (!CRS.equalsIgnoreMetadata(targetCRS, bound.getCoordinateReferenceSystem()))
|
||||||
|
return bound.toBounds(targetCRS);
|
||||||
|
}
|
||||||
|
catch (TransformException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CoordinateReferenceSystem getCRS(String typeName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ArrayList<Layer> layers = ServerContext.getMap().getAllLayers();
|
||||||
|
for (Layer layer : layers)
|
||||||
|
{
|
||||||
|
if ((layer instanceof FeatureLayer))
|
||||||
|
{
|
||||||
|
if (layer.getSourceName().equalsIgnoreCase(typeName))
|
||||||
|
return layer.getCRS();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception localException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return CRSMngr.getCRS(Integer.valueOf(4326));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Double getGridSize(String typeName, String columnName)
|
||||||
|
{
|
||||||
|
String schemaName = null;
|
||||||
|
if ((this.databaseSchema == null) || (this.databaseSchema.equals("")))
|
||||||
|
schemaName = "";
|
||||||
|
else {
|
||||||
|
schemaName = this.databaseSchema.toUpperCase() + ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
Connection cx = null;
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cx = this.dsDialectNS.getDataStore().getConnection(Transaction.AUTO_COMMIT);
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT GRID_SIZE FROM ");
|
||||||
|
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
|
sql.append(" WHERE TABLE_NAME = '").append(typeName.toUpperCase()).append("'");
|
||||||
|
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||||
|
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if ((rs != null) && (rs.next()))
|
||||||
|
return Double.valueOf(rs.getDouble(1));
|
||||||
|
} catch (Exception localException) {
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
this.dsDialectNS.getDataStore().closeSafe(cx);
|
||||||
|
this.dsDialectNS.getDataStore().closeSafe(rs);
|
||||||
|
this.dsDialectNS.getDataStore().closeSafe(stat);
|
||||||
|
}
|
||||||
|
this.dsDialectNS.getDataStore().closeSafe(cx);
|
||||||
|
this.dsDialectNS.getDataStore().closeSafe(rs);
|
||||||
|
this.dsDialectNS.getDataStore().closeSafe(stat);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GridRange getIntersectRange(Envelope envelop, String columnName) throws Exception
|
||||||
|
{
|
||||||
|
String gridKey = this.featureType.getTypeName() + "_" + columnName;
|
||||||
|
gridKey = gridKey.toUpperCase();
|
||||||
|
|
||||||
|
Double gridSize = (Double)this.dsDialectNS.gridStore.get(gridKey);
|
||||||
|
|
||||||
|
if (gridSize == null) {
|
||||||
|
gridSize = getGridSize(this.featureType.getTypeName(), columnName);
|
||||||
|
if (gridSize == null) return null;
|
||||||
|
this.dsDialectNS.gridStore.put(gridKey, gridSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return calIntersectRange(envelop, gridSize.doubleValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private GridRange calIntersectRange(Envelope envelop, double gridSize) {
|
||||||
|
if (gridSize <= 0.0D) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sc = (int)(envelop.getMinX() / gridSize);
|
||||||
|
int ec = (int)(envelop.getMinY() / gridSize);
|
||||||
|
int sr = (int)(envelop.getMaxX() / gridSize);
|
||||||
|
int er = (int)(envelop.getMaxY() / gridSize);
|
||||||
|
|
||||||
|
if (envelop.getMinX() < 0.0D) sc--;
|
||||||
|
if (envelop.getMinY() < 0.0D) ec--;
|
||||||
|
if (envelop.getMaxX() < 0.0D) sr--;
|
||||||
|
if (envelop.getMaxY() < 0.0D) er--;
|
||||||
|
|
||||||
|
return new GridRange(sc, ec, sr, er); }
|
||||||
|
private class GridRange { public int sc;
|
||||||
|
public int ec;
|
||||||
|
public int sr;
|
||||||
|
public int er;
|
||||||
|
|
||||||
|
public GridRange(int start_col, int end_col, int start_row, int end_row) { this.sc = start_col;
|
||||||
|
this.ec = end_col;
|
||||||
|
this.sr = start_row;
|
||||||
|
this.er = end_row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,13 +4,10 @@ import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.geotools.factory.GeoTools;
|
import org.geotools.factory.GeoTools;
|
||||||
|
|
@ -19,7 +16,6 @@ import org.geotools.metadata.iso.citation.Citations;
|
||||||
import org.geotools.referencing.NamedIdentifier;
|
import org.geotools.referencing.NamedIdentifier;
|
||||||
import org.geotools.referencing.factory.DirectAuthorityFactory;
|
import org.geotools.referencing.factory.DirectAuthorityFactory;
|
||||||
import org.geotools.referencing.factory.ReferencingFactoryContainer;
|
import org.geotools.referencing.factory.ReferencingFactoryContainer;
|
||||||
import org.geotools.referencing.wkt.Parser;
|
|
||||||
import org.geotools.referencing.wkt.Symbols;
|
import org.geotools.referencing.wkt.Symbols;
|
||||||
import org.geotools.util.SimpleInternationalString;
|
import org.geotools.util.SimpleInternationalString;
|
||||||
import org.opengis.metadata.Identifier;
|
import org.opengis.metadata.Identifier;
|
||||||
|
|
@ -31,487 +27,408 @@ import org.opengis.referencing.crs.CRSAuthorityFactory;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
import org.opengis.util.InternationalString;
|
import org.opengis.util.InternationalString;
|
||||||
|
|
||||||
public class O2CRSFactory extends DirectAuthorityFactory
|
public class O2CRSFactory
|
||||||
implements CRSAuthorityFactory
|
extends DirectAuthorityFactory
|
||||||
{
|
implements CRSAuthorityFactory {
|
||||||
private CitationImpl authority = new CitationImpl("O2CRS");
|
private CitationImpl authority = new CitationImpl((CharSequence)"O2CRS");
|
||||||
|
private final ConcurrentHashMap<String, CoordinateReferenceSystem> definitions = new ConcurrentHashMap();
|
||||||
|
private final Parser parser = new Parser();
|
||||||
|
|
||||||
private final ConcurrentHashMap<String, CoordinateReferenceSystem> definitions = new ConcurrentHashMap();
|
public O2CRSFactory() {
|
||||||
|
super(ReferencingFactoryContainer.instance(null), 99);
|
||||||
private final Parser parser = new Parser();
|
this.initCrsDefinitions();
|
||||||
|
|
||||||
public O2CRSFactory() {
|
|
||||||
super(ReferencingFactoryContainer.instance(null), 99);
|
|
||||||
|
|
||||||
initCrsDefinitions();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type)
|
|
||||||
throws FactoryException
|
|
||||||
{
|
|
||||||
Set codes = new HashSet();
|
|
||||||
|
|
||||||
synchronized (this.definitions)
|
|
||||||
{
|
|
||||||
Iterator iter = this.definitions.keySet().iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String key = (String)iter.next();
|
|
||||||
String[] tempKeys = key.split("\\.");
|
|
||||||
|
|
||||||
codes.add(tempKeys[1] + ":" + tempKeys[2]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return codes;
|
/*
|
||||||
}
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
public InternationalString getDescriptionText(String code)
|
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) throws FactoryException {
|
||||||
throws NoSuchAuthorityCodeException, FactoryException
|
HashSet<String> codes = new HashSet<String>();
|
||||||
{
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
CoordinateReferenceSystem crs = createCoordinateReferenceSystem(code);
|
synchronized (concurrentHashMap) {
|
||||||
return new SimpleInternationalString(crs.toWKT());
|
for (String key : this.definitions.keySet()) {
|
||||||
}
|
String[] tempKeys = key.split("\\.");
|
||||||
|
codes.add(String.valueOf(tempKeys[1]) + ":" + tempKeys[2]);
|
||||||
public Citation getAuthority()
|
}
|
||||||
{
|
|
||||||
return this.authority;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CoordinateReferenceSystem createCoordinateReferenceSystem(String code)
|
|
||||||
throws NoSuchAuthorityCodeException, FactoryException
|
|
||||||
{
|
|
||||||
if (ServerUtil.isNullString(code)) {
|
|
||||||
throw new FactoryException("CRS code is NULL.");
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] codes = code.split(":");
|
|
||||||
if (codes.length == 2)
|
|
||||||
{
|
|
||||||
SortedSet keys = new TreeSet(this.definitions.keySet());
|
|
||||||
Iterator iter = keys.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String key = (String)iter.next();
|
|
||||||
String[] keyCodes = key.split("\\.");
|
|
||||||
|
|
||||||
if ((keyCodes[1].equalsIgnoreCase(codes[0].trim())) &&
|
|
||||||
(keyCodes[2].equalsIgnoreCase(codes[1].trim()))) {
|
|
||||||
return (CoordinateReferenceSystem)this.definitions.get(key);
|
|
||||||
}
|
}
|
||||||
}
|
return codes;
|
||||||
}
|
|
||||||
else if (codes.length == 1)
|
|
||||||
{
|
|
||||||
SortedSet keys = new TreeSet(this.definitions.keySet());
|
|
||||||
Iterator iter = keys.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String key = (String)iter.next();
|
|
||||||
String[] keyCodes = key.split("\\.");
|
|
||||||
|
|
||||||
if (keyCodes[2].equalsIgnoreCase(codes[0].trim()))
|
|
||||||
return (CoordinateReferenceSystem)this.definitions.get(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NoSuchAuthorityCodeException("CRS code has problem : " + code, code, code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NoSuchAuthorityCodeException("Not exists authority or code : " + code, codes[0], codes[1]);
|
public InternationalString getDescriptionText(String code) throws NoSuchAuthorityCodeException, FactoryException {
|
||||||
}
|
CoordinateReferenceSystem crs = this.createCoordinateReferenceSystem(code);
|
||||||
|
return new SimpleInternationalString(crs.toWKT());
|
||||||
|
}
|
||||||
|
|
||||||
public void initCrsDefinitions()
|
public Citation getAuthority() {
|
||||||
{
|
return this.authority;
|
||||||
Connection conn = null;
|
}
|
||||||
Statement st = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
conn = ConnMngr.getInstance().openConn();
|
|
||||||
st = conn.createStatement();
|
|
||||||
|
|
||||||
String sql = "SELECT * FROM O2SERVER_COORDINATE_SYSTEM";
|
public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws NoSuchAuthorityCodeException, FactoryException {
|
||||||
rs = st.executeQuery(sql);
|
if (ServerUtil.isNullString((String)code)) {
|
||||||
|
throw new FactoryException("CRS code is NULL.");
|
||||||
|
}
|
||||||
|
String[] codes = code.split(":");
|
||||||
|
if (codes.length == 2) {
|
||||||
|
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||||
|
for (String key : keys) {
|
||||||
|
String[] keyCodes = key.split("\\.");
|
||||||
|
if (!keyCodes[1].equalsIgnoreCase(codes[0].trim()) || !keyCodes[2].equalsIgnoreCase(codes[1].trim())) continue;
|
||||||
|
return this.definitions.get(key);
|
||||||
|
}
|
||||||
|
} else if (codes.length == 1) {
|
||||||
|
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||||
|
for (String key : keys) {
|
||||||
|
String[] keyCodes = key.split("\\.");
|
||||||
|
if (!keyCodes[2].equalsIgnoreCase(codes[0].trim())) continue;
|
||||||
|
return this.definitions.get(key);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new NoSuchAuthorityCodeException("CRS code has problem : " + code, code, code);
|
||||||
|
}
|
||||||
|
throw new NoSuchAuthorityCodeException("Not exists authority or code : " + code, codes[0], codes[1]);
|
||||||
|
}
|
||||||
|
|
||||||
this.definitions.clear();
|
public void initCrsDefinitions() {
|
||||||
|
block11: {
|
||||||
|
Connection conn = null;
|
||||||
|
Statement st = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
conn = ConnMngr.getInstance().openConn();
|
||||||
|
st = conn.createStatement();
|
||||||
|
String sql = "SELECT * FROM O2SERVER_COORDINATE_SYSTEM";
|
||||||
|
rs = st.executeQuery(sql);
|
||||||
|
this.definitions.clear();
|
||||||
|
while (rs.next()) {
|
||||||
|
int srid = rs.getInt("SRID");
|
||||||
|
String auth = rs.getString("AUTH_NAME");
|
||||||
|
String code = rs.getString("AUTH_CODE");
|
||||||
|
try {
|
||||||
|
if (ServerUtil.isNullString((String)auth) || ServerUtil.isNullString((String)code)) {
|
||||||
|
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
if (this.isContainSRID(srid)) {
|
||||||
|
throw new FactoryException("SRID [" + srid + "] is already exist.");
|
||||||
|
}
|
||||||
|
if (this.isContainCRS(auth, code)) {
|
||||||
|
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
||||||
|
}
|
||||||
|
CoordinateReferenceSystem crs = this.parseWKT(auth, code, rs.getString("PARAMETER"));
|
||||||
|
this.definitions.put(String.valueOf(srid) + "." + auth + "." + code, crs);
|
||||||
|
this.addAuthority(auth);
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "Success to add CRS [" + srid + "." + auth + "." + code + "] :: " + crs.toWKT());
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "Fail to add CRS [" + srid + "." + auth + "." + code + "] :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "Can't access O2SERVER_COORDINATE_SYSTEM table :: " + e.getMessage());
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
|
ConnMngr.getInstance().closeSafe(st);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
break block11;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable throwable) {
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
|
ConnMngr.getInstance().closeSafe(st);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
|
ConnMngr.getInstance().closeSafe(st);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (rs.next())
|
/*
|
||||||
{
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
int srid = rs.getInt("SRID");
|
*/
|
||||||
String auth = rs.getString("AUTH_NAME");
|
public CoordinateReferenceSystem parseWKT(String auth, String code, String wkt) throws Exception {
|
||||||
String code = rs.getString("AUTH_CODE");
|
if (ServerUtil.isNullString((String)auth) || ServerUtil.isNullString((String)code)) {
|
||||||
try
|
|
||||||
{
|
|
||||||
if ((ServerUtil.isNullString(auth)) ||
|
|
||||||
(ServerUtil.isNullString(code))) {
|
|
||||||
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||||
}
|
}
|
||||||
auth = auth.trim().toUpperCase();
|
if (ServerUtil.isNullString((String)wkt)) {
|
||||||
code = code.trim().toUpperCase();
|
throw new FactoryException("CRS WKT is NULL.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
Parser parser = this.parser;
|
||||||
|
synchronized (parser) {
|
||||||
|
return this.parser.parseCoordinateReferenceSystem(auth, code, wkt.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isContainSRID(srid))
|
private void addAuthority(String auth) {
|
||||||
|
Citation cit = Citations.fromName((String)auth);
|
||||||
|
this.authority.getIdentifiers().addAll(cit.getIdentifiers());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isContainAuthority(String auth) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)auth)) {
|
||||||
|
throw new FactoryException("AUTHORITY is Null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
for (Identifier identifier : this.authority.getIdentifiers()) {
|
||||||
|
if (!identifier.getCode().equalsIgnoreCase(auth)) continue;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
* Enabled aggressive block sorting
|
||||||
|
* Enabled unnecessary exception pruning
|
||||||
|
* Enabled aggressive exception aggregation
|
||||||
|
*/
|
||||||
|
private boolean isContainSRID(int srid) throws Exception {
|
||||||
|
if (srid < 0) {
|
||||||
|
throw new FactoryException("SRID [" + srid + "] value is not available :: SRID >= 0");
|
||||||
|
}
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
String key;
|
||||||
|
String id = Integer.toString(srid);
|
||||||
|
Enumeration<String> keys = this.definitions.keys();
|
||||||
|
do {
|
||||||
|
if (keys.hasMoreElements()) continue;
|
||||||
|
return false;
|
||||||
|
} while (!(key = keys.nextElement()).split("\\.")[0].equalsIgnoreCase(id));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
* Enabled aggressive block sorting
|
||||||
|
* Enabled unnecessary exception pruning
|
||||||
|
* Enabled aggressive exception aggregation
|
||||||
|
*/
|
||||||
|
private boolean isContainCRS(String auth, String code) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)auth)) {
|
||||||
|
throw new FactoryException("AUTHORITY is Null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
if (ServerUtil.isNullString((String)code)) {
|
||||||
|
throw new FactoryException("CODE is Null.");
|
||||||
|
}
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
String key;
|
||||||
|
String[] codes;
|
||||||
|
Enumeration<String> keys = this.definitions.keys();
|
||||||
|
do {
|
||||||
|
if (keys.hasMoreElements()) continue;
|
||||||
|
return false;
|
||||||
|
} while (!(codes = (key = keys.nextElement()).split("\\."))[1].equalsIgnoreCase(auth) || !codes[2].equalsIgnoreCase(code));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public String getCRSKey(int srid) throws Exception {
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
String id = Integer.toString(srid);
|
||||||
|
Enumeration<String> keys = this.definitions.keys();
|
||||||
|
while (keys.hasMoreElements()) {
|
||||||
|
String key = keys.nextElement();
|
||||||
|
if (!key.split("\\.")[0].equalsIgnoreCase(id)) continue;
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new FactoryException("SRID [" + srid + "] is not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public void insertCRS(int srid, String auth, String code, CoordinateReferenceSystem crs, boolean write) throws Exception {
|
||||||
|
if (this.isContainSRID(srid)) {
|
||||||
throw new FactoryException("SRID [" + srid + "] is already exist.");
|
throw new FactoryException("SRID [" + srid + "] is already exist.");
|
||||||
if (isContainCRS(auth, code)) {
|
}
|
||||||
|
if (this.isContainCRS(auth, code)) {
|
||||||
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
||||||
}
|
}
|
||||||
|
if (crs == null) {
|
||||||
|
throw new FactoryException("CRS is Null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
if (write) {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append("INSERT INTO O2SERVER_COORDINATE_SYSTEM ( SRID, AUTH_NAME, AUTH_CODE, PARAMETER) VALUES ( ");
|
||||||
|
sb.append(srid).append(", ");
|
||||||
|
sb.append("'").append(auth).append("', ");
|
||||||
|
sb.append("'").append(code).append("', ");
|
||||||
|
sb.append("'").append(crs.toWKT()).append("'");
|
||||||
|
sb.append(" )");
|
||||||
|
this.executeSQL(sb.toString());
|
||||||
|
}
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
this.definitions.put(String.valueOf(srid) + "." + auth + "." + code, crs);
|
||||||
|
this.addAuthority(auth);
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CoordinateReferenceSystem crs = parseWKT(auth, code, rs.getString("PARAMETER"));
|
private boolean executeSQL(String sql) throws Exception {
|
||||||
this.definitions.put(srid + "." + auth + "." + code, crs);
|
Connection conn = null;
|
||||||
addAuthority(auth);
|
Statement st = null;
|
||||||
|
ResultSet rs = null;
|
||||||
LogMngr.getInstance().logInfo("[CRS]", "Success to add CRS [" + srid + "." + auth + "." + code + "] :: " + crs.toWKT());
|
try {
|
||||||
|
conn = ConnMngr.getInstance().openConn();
|
||||||
|
st = conn.createStatement();
|
||||||
|
boolean bl = st.execute(sql);
|
||||||
|
return bl;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
LogMngr.getInstance().logError("[CRS]", "Fail to add CRS [" + srid + "." + auth + "." + code + "] :: " + e);
|
LogMngr.getInstance().logError("[CRS]", "CRS execute fail :: " + e.getMessage());
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
finally {
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
}
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
catch (Exception e)
|
ConnMngr.getInstance().closeSafe(st);
|
||||||
{
|
|
||||||
LogMngr.getInstance().logError("[CRS]", "Can't access O2SERVER_COORDINATE_SYSTEM table :: " + e.getMessage());
|
|
||||||
} finally {
|
|
||||||
ConnMngr.getInstance().closeConn();
|
|
||||||
ConnMngr.getInstance().closeSafe(st);
|
|
||||||
ConnMngr.getInstance().closeSafe(rs);
|
|
||||||
|
|
||||||
GeoTools.fireConfigurationChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CoordinateReferenceSystem parseWKT(String auth, String code, String wkt)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
if ((ServerUtil.isNullString(auth)) || (ServerUtil.isNullString(code)))
|
|
||||||
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
|
||||||
if (ServerUtil.isNullString(wkt)) {
|
|
||||||
throw new FactoryException("CRS WKT is NULL.");
|
|
||||||
}
|
|
||||||
|
|
||||||
auth = auth.trim().toUpperCase();
|
|
||||||
code = code.trim().toUpperCase();
|
|
||||||
|
|
||||||
synchronized (this.parser) {
|
|
||||||
return this.parser.parseCoordinateReferenceSystem(auth, code, wkt.trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAuthority(String auth)
|
|
||||||
{
|
|
||||||
Citation cit = Citations.fromName(auth);
|
|
||||||
this.authority.getIdentifiers().addAll(cit.getIdentifiers());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isContainAuthority(String auth)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
if (ServerUtil.isNullString(auth)) {
|
|
||||||
throw new FactoryException("AUTHORITY is Null.");
|
|
||||||
}
|
|
||||||
auth = auth.trim().toUpperCase();
|
|
||||||
|
|
||||||
Iterator iter = this.authority.getIdentifiers().iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
Identifier identifier = (Identifier)iter.next();
|
|
||||||
if (identifier.getCode().equalsIgnoreCase(auth)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isContainSRID(int srid)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
if (srid < 0) {
|
|
||||||
throw new FactoryException("SRID [" + srid + "] value is not available :: SRID >= 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this.definitions) {
|
|
||||||
String id = Integer.toString(srid);
|
|
||||||
|
|
||||||
Enumeration keys = this.definitions.keys();
|
|
||||||
while (keys.hasMoreElements()) {
|
|
||||||
String key = (String)keys.nextElement();
|
|
||||||
|
|
||||||
if (key.split("\\.")[0].equalsIgnoreCase(id)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
/*
|
||||||
}
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
private boolean isContainCRS(String auth, String code)
|
public void updateCRS(int srid, String auth, String code, CoordinateReferenceSystem crs, boolean write) throws Exception {
|
||||||
throws Exception
|
if (ServerUtil.isNullString((String)auth)) {
|
||||||
{
|
throw new FactoryException("Authority value is Null.");
|
||||||
if (ServerUtil.isNullString(auth)) {
|
|
||||||
throw new FactoryException("AUTHORITY is Null.");
|
|
||||||
}
|
|
||||||
auth = auth.trim().toUpperCase();
|
|
||||||
|
|
||||||
if (ServerUtil.isNullString(code)) {
|
|
||||||
throw new FactoryException("CODE is Null.");
|
|
||||||
}
|
|
||||||
code = code.trim().toUpperCase();
|
|
||||||
|
|
||||||
synchronized (this.definitions) {
|
|
||||||
Enumeration keys = this.definitions.keys();
|
|
||||||
while (keys.hasMoreElements()) {
|
|
||||||
String key = (String)keys.nextElement();
|
|
||||||
|
|
||||||
String[] codes = key.split("\\.");
|
|
||||||
if ((codes[1].equalsIgnoreCase(auth)) &&
|
|
||||||
(codes[2].equalsIgnoreCase(code))) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
auth = auth.trim().toUpperCase();
|
||||||
}
|
if (ServerUtil.isNullString((String)code)) {
|
||||||
|
throw new FactoryException("Code value is Null.");
|
||||||
return false;
|
}
|
||||||
}
|
code = code.trim().toUpperCase();
|
||||||
|
if (crs == null) {
|
||||||
public String getCRSKey(int srid)
|
throw new FactoryException("CRS value is Null.");
|
||||||
throws Exception
|
}
|
||||||
{
|
String[] ids = this.getCRSKey(srid).split("\\.");
|
||||||
synchronized (this.definitions) {
|
if (!(ids[1].equals(auth) && ids[2].equals(code) || !this.isContainCRS(auth, code))) {
|
||||||
String id = Integer.toString(srid);
|
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
||||||
|
}
|
||||||
Enumeration keys = this.definitions.keys();
|
if (write) {
|
||||||
while (keys.hasMoreElements()) {
|
StringBuffer sb = new StringBuffer();
|
||||||
String key = (String)keys.nextElement();
|
sb.append("UPDATE O2SERVER_COORDINATE_SYSTEM SET ");
|
||||||
|
sb.append("AUTH_NAME=").append("'").append(auth).append("'").append(", ");
|
||||||
if (key.split("\\.")[0].equalsIgnoreCase(id)) {
|
sb.append("AUTH_CODE=").append("'").append(code).append("'").append(", ");
|
||||||
return key;
|
sb.append("PARAMETER=").append("'").append(crs.toWKT()).append("'").append(" ");
|
||||||
|
sb.append("WHERE SRID=").append(srid);
|
||||||
|
this.executeSQL(sb.toString());
|
||||||
|
}
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
String oldID = this.getCRSKey(srid);
|
||||||
|
this.definitions.remove(oldID);
|
||||||
|
this.definitions.put(String.valueOf(srid) + "." + auth + "." + code, crs);
|
||||||
|
this.addAuthority(auth);
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FactoryException("SRID [" + srid + "] is not exist.");
|
/*
|
||||||
}
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
public void insertCRS(int srid, String auth, String code, CoordinateReferenceSystem crs, boolean write)
|
public void removeCRS(int srid, boolean write) throws Exception {
|
||||||
throws Exception
|
if (!this.isContainSRID(srid)) {
|
||||||
{
|
throw new FactoryException("SRID [" + srid + "] is not exist.");
|
||||||
if (isContainSRID(srid))
|
}
|
||||||
throw new FactoryException("SRID [" + srid + "] is already exist.");
|
if (write) {
|
||||||
if (isContainCRS(auth, code))
|
StringBuffer sb = new StringBuffer();
|
||||||
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
sb.append("DELETE FROM O2SERVER_COORDINATE_SYSTEM ");
|
||||||
if (crs == null) {
|
sb.append("WHERE SRID=").append(srid);
|
||||||
throw new FactoryException("CRS is Null.");
|
this.executeSQL(sb.toString());
|
||||||
|
}
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
String id = Integer.toString(srid);
|
||||||
|
for (String key : this.definitions.keySet()) {
|
||||||
|
if (!key.split("\\.")[0].equalsIgnoreCase(id)) continue;
|
||||||
|
this.definitions.remove(key);
|
||||||
|
}
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auth = auth.trim().toUpperCase();
|
/*
|
||||||
code = code.trim().toUpperCase();
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
if (write) {
|
public CoordinateReferenceSystem getCRS(int srid) throws NoSuchAuthorityCodeException {
|
||||||
StringBuffer sb = new StringBuffer();
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
sb.append("INSERT INTO O2SERVER_COORDINATE_SYSTEM ( SRID, AUTH_NAME, AUTH_CODE, PARAMETER) VALUES ( ");
|
synchronized (concurrentHashMap) {
|
||||||
sb.append(srid).append(", ");
|
String id = Integer.toString(srid);
|
||||||
sb.append("'").append(auth).append("', ");
|
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||||
sb.append("'").append(code).append("', ");
|
for (String key : keys) {
|
||||||
sb.append("'").append(crs.toWKT()).append("'");
|
if (!key.split("\\.")[0].equalsIgnoreCase(id)) continue;
|
||||||
sb.append(" )");
|
return this.definitions.get(key);
|
||||||
|
}
|
||||||
executeSQL(sb.toString());
|
}
|
||||||
|
throw new NoSuchAuthorityCodeException("Not exists authority or code", "LayerCRS", String.valueOf(srid));
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (this.definitions)
|
/*
|
||||||
{
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
this.definitions.put(srid + "." + auth + "." + code, crs);
|
*/
|
||||||
|
public Set<String> getAuthorityCodes(String auth) {
|
||||||
addAuthority(auth);
|
TreeSet<String> codes = new TreeSet<String>();
|
||||||
|
if (ServerUtil.isNullString((String)auth)) {
|
||||||
GeoTools.fireConfigurationChanged();
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
}
|
synchronized (concurrentHashMap) {
|
||||||
}
|
for (String key : this.definitions.keySet()) {
|
||||||
|
String[] tempKeys = key.split("\\.");
|
||||||
private boolean executeSQL(String sql)
|
codes.add(String.valueOf(tempKeys[1]) + ":" + tempKeys[2]);
|
||||||
throws Exception
|
}
|
||||||
{
|
}
|
||||||
Connection conn = null;
|
}
|
||||||
Statement st = null;
|
auth = auth.trim().toUpperCase();
|
||||||
ResultSet rs = null;
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
try
|
synchronized (concurrentHashMap) {
|
||||||
{
|
for (String key : this.definitions.keySet()) {
|
||||||
conn = ConnMngr.getInstance().openConn();
|
String[] tempKeys = key.split("\\.");
|
||||||
st = conn.createStatement();
|
if (!tempKeys[1].equalsIgnoreCase(auth)) continue;
|
||||||
|
codes.add(String.valueOf(tempKeys[1]) + ":" + tempKeys[2]);
|
||||||
return st.execute(sql);
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
return codes;
|
||||||
LogMngr.getInstance().logError("[CRS]", "CRS execute fail :: " + e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
ConnMngr.getInstance().closeConn();
|
|
||||||
ConnMngr.getInstance().closeSafe(rs);
|
|
||||||
ConnMngr.getInstance().closeSafe(st);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateCRS(int srid, String auth, String code, CoordinateReferenceSystem crs, boolean write)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
if (ServerUtil.isNullString(auth)) {
|
|
||||||
throw new FactoryException("Authority value is Null.");
|
|
||||||
}
|
|
||||||
auth = auth.trim().toUpperCase();
|
|
||||||
|
|
||||||
if (ServerUtil.isNullString(code)) {
|
|
||||||
throw new FactoryException("Code value is Null.");
|
|
||||||
}
|
|
||||||
code = code.trim().toUpperCase();
|
|
||||||
|
|
||||||
if (crs == null) {
|
|
||||||
throw new FactoryException("CRS value is Null.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] ids = getCRSKey(srid).split("\\.");
|
private final class Parser
|
||||||
if (((!ids[1].equals(auth)) || (!ids[2].equals(code))) && (isContainCRS(auth, code))) {
|
extends org.geotools.referencing.wkt.Parser {
|
||||||
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
private static final long serialVersionUID = -5910561042299146066L;
|
||||||
}
|
private CitationImpl auth;
|
||||||
|
private String code;
|
||||||
|
|
||||||
if (write) {
|
public Parser() {
|
||||||
StringBuffer sb = new StringBuffer();
|
super(Symbols.DEFAULT, O2CRSFactory.this.factories);
|
||||||
sb.append("UPDATE O2SERVER_COORDINATE_SYSTEM SET ");
|
|
||||||
sb.append("AUTH_NAME=").append("'").append(auth).append("'").append(", ");
|
|
||||||
sb.append("AUTH_CODE=").append("'").append(code).append("'").append(", ");
|
|
||||||
sb.append("PARAMETER=").append("'").append(crs.toWKT()).append("'").append(" ");
|
|
||||||
sb.append("WHERE SRID=").append(srid);
|
|
||||||
|
|
||||||
executeSQL(sb.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this.definitions)
|
|
||||||
{
|
|
||||||
String oldID = getCRSKey(srid);
|
|
||||||
this.definitions.remove(oldID);
|
|
||||||
|
|
||||||
this.definitions.put(srid + "." + auth + "." + code, crs);
|
|
||||||
|
|
||||||
addAuthority(auth);
|
|
||||||
|
|
||||||
GeoTools.fireConfigurationChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCRS(int srid, boolean write)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
if (!isContainSRID(srid)) {
|
|
||||||
throw new FactoryException("SRID [" + srid + "] is not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (write) {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
sb.append("DELETE FROM O2SERVER_COORDINATE_SYSTEM ");
|
|
||||||
sb.append("WHERE SRID=").append(srid);
|
|
||||||
|
|
||||||
executeSQL(sb.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this.definitions)
|
|
||||||
{
|
|
||||||
String id = Integer.toString(srid);
|
|
||||||
|
|
||||||
Iterator iter = this.definitions.keySet().iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String key = (String)iter.next();
|
|
||||||
|
|
||||||
if (key.split("\\.")[0].equalsIgnoreCase(id)) {
|
|
||||||
this.definitions.remove(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String auth, String code, String wkt) throws ParseException {
|
||||||
|
this.auth = new CitationImpl(Citations.fromName((String)auth));
|
||||||
GeoTools.fireConfigurationChanged();
|
this.code = code;
|
||||||
}
|
return super.parseCoordinateReferenceSystem(wkt);
|
||||||
}
|
|
||||||
|
|
||||||
public CoordinateReferenceSystem getCRS(int srid)
|
|
||||||
throws NoSuchAuthorityCodeException
|
|
||||||
{
|
|
||||||
synchronized (this.definitions)
|
|
||||||
{
|
|
||||||
String id = Integer.toString(srid);
|
|
||||||
|
|
||||||
SortedSet keys = new TreeSet(this.definitions.keySet());
|
|
||||||
Iterator iter = keys.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String key = (String)iter.next();
|
|
||||||
|
|
||||||
if (key.split("\\.")[0].equalsIgnoreCase(id)) {
|
|
||||||
return (CoordinateReferenceSystem)this.definitions.get(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NoSuchAuthorityCodeException("Not exists authority or code", "LayerCRS", String.valueOf(srid));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getAuthorityCodes(String auth)
|
|
||||||
{
|
|
||||||
TreeSet codes = new TreeSet();
|
|
||||||
|
|
||||||
if (ServerUtil.isNullString(auth))
|
|
||||||
{
|
|
||||||
synchronized (this.definitions)
|
|
||||||
{
|
|
||||||
Iterator iter = this.definitions.keySet().iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String key = (String)iter.next();
|
|
||||||
String[] tempKeys = key.split("\\.");
|
|
||||||
|
|
||||||
codes.add(tempKeys[1] + ":" + tempKeys[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
auth = auth.trim().toUpperCase();
|
|
||||||
|
|
||||||
synchronized (this.definitions)
|
|
||||||
{
|
|
||||||
Iterator iter = this.definitions.keySet().iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String key = (String)iter.next();
|
|
||||||
String[] tempKeys = key.split("\\.");
|
|
||||||
|
|
||||||
if (tempKeys[1].equalsIgnoreCase(auth)) {
|
|
||||||
codes.add(tempKeys[1] + ":" + tempKeys[2]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
protected Map<String, Object> alterProperties(Map<String, Object> properties) {
|
||||||
|
properties.put("identifiers", new NamedIdentifier((Citation)this.auth, this.code));
|
||||||
|
return super.alterProperties(properties);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return codes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class Parser extends Parser {
|
|
||||||
private static final long serialVersionUID = -5910561042299146066L;
|
|
||||||
private CitationImpl auth;
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
public Parser() {
|
|
||||||
super(O2CRSFactory.this.factories);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String auth, String code, String wkt)
|
|
||||||
throws ParseException
|
|
||||||
{
|
|
||||||
this.auth = new CitationImpl(Citations.fromName(auth));
|
|
||||||
this.code = code;
|
|
||||||
|
|
||||||
return super.parseCoordinateReferenceSystem(wkt);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String, Object> alterProperties(Map<String, Object> properties)
|
|
||||||
{
|
|
||||||
properties.put("identifiers", new NamedIdentifier(this.auth, this.code));
|
|
||||||
return super.alterProperties(properties);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,423 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
//thkim 검증됨
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.geotools.factory.GeoTools;
|
||||||
|
import org.geotools.metadata.iso.citation.CitationImpl;
|
||||||
|
import org.geotools.metadata.iso.citation.Citations;
|
||||||
|
import org.geotools.referencing.NamedIdentifier;
|
||||||
|
import org.geotools.referencing.factory.DirectAuthorityFactory;
|
||||||
|
import org.geotools.referencing.factory.ReferencingFactoryContainer;
|
||||||
|
import org.geotools.referencing.wkt.Symbols;
|
||||||
|
import org.geotools.util.SimpleInternationalString;
|
||||||
|
import org.opengis.metadata.Identifier;
|
||||||
|
import org.opengis.metadata.citation.Citation;
|
||||||
|
import org.opengis.referencing.FactoryException;
|
||||||
|
import org.opengis.referencing.IdentifiedObject;
|
||||||
|
import org.opengis.referencing.NoSuchAuthorityCodeException;
|
||||||
|
import org.opengis.referencing.crs.CRSAuthorityFactory;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.opengis.util.InternationalString;
|
||||||
|
|
||||||
|
public class O2CRSOverrideFactory
|
||||||
|
extends DirectAuthorityFactory
|
||||||
|
implements CRSAuthorityFactory {
|
||||||
|
private CitationImpl authority = new CitationImpl((CharSequence)"O2CRS Override");
|
||||||
|
private final String o2crsFileName = "o2crs.properties";
|
||||||
|
private final ConcurrentHashMap<String, CoordinateReferenceSystem> definitions = new ConcurrentHashMap();
|
||||||
|
private final Parser parser = new Parser();
|
||||||
|
|
||||||
|
public O2CRSOverrideFactory() {
|
||||||
|
super(ReferencingFactoryContainer.instance(null), 100);
|
||||||
|
try {
|
||||||
|
this.initCrsDefinitions();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) throws FactoryException {
|
||||||
|
HashSet<String> codes = new HashSet<String>();
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
codes.addAll(this.definitions.keySet());
|
||||||
|
}
|
||||||
|
return codes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InternationalString getDescriptionText(String code) throws NoSuchAuthorityCodeException, FactoryException {
|
||||||
|
CoordinateReferenceSystem crs = this.createCoordinateReferenceSystem(code);
|
||||||
|
return new SimpleInternationalString(crs.toWKT());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Citation getAuthority() {
|
||||||
|
return this.authority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws NoSuchAuthorityCodeException, FactoryException {
|
||||||
|
if (ServerUtil.isNullString((String)code)) {
|
||||||
|
throw new FactoryException("CRS code is NULL.");
|
||||||
|
}
|
||||||
|
String[] codes = code.trim().toUpperCase().split(":");
|
||||||
|
if (codes.length == 2) {
|
||||||
|
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||||
|
for (String key : keys) {
|
||||||
|
String[] keyCodes = key.split(":");
|
||||||
|
if (!keyCodes[0].equalsIgnoreCase(codes[0].trim()) || !keyCodes[1].equalsIgnoreCase(codes[1].trim())) continue;
|
||||||
|
return this.definitions.get(key);
|
||||||
|
}
|
||||||
|
} else if (codes.length == 1) {
|
||||||
|
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||||
|
for (String key : keys) {
|
||||||
|
String[] keyCodes = key.split(":");
|
||||||
|
if (!keyCodes[1].equalsIgnoreCase(codes[0].trim())) continue;
|
||||||
|
return this.definitions.get(key);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new NoSuchAuthorityCodeException("CRS code has problem : " + code, code, code);
|
||||||
|
}
|
||||||
|
throw new NoSuchAuthorityCodeException("Not exists authority or code : " + code, codes[0], codes[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initCrsDefinitions() throws Exception {
|
||||||
|
try {
|
||||||
|
File file = ServerUtil.findFile((File)ServerContext.getConfFolder(), (String)"o2crs.properties");
|
||||||
|
if (file == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Properties properties = ServerUtil.getPropertiesFromFile((File)file, (String)"=");
|
||||||
|
Enumeration<Object> keys = properties.keys();
|
||||||
|
while (keys.hasMoreElements()) {
|
||||||
|
String pKey = (String)keys.nextElement();
|
||||||
|
try {
|
||||||
|
String[] codes = pKey.trim().toUpperCase().split(":");
|
||||||
|
if (codes.length != 2 || ServerUtil.isNullString((String)codes[0]) || ServerUtil.isNullString((String)codes[1])) {
|
||||||
|
throw new FactoryException("Parameter [Authority:Code] has problem.");
|
||||||
|
}
|
||||||
|
codes[0] = codes[0].trim().toUpperCase();
|
||||||
|
codes[1] = codes[1].trim().toUpperCase();
|
||||||
|
if (this.isContainCRS(codes[0], codes[1])) {
|
||||||
|
throw new FactoryException("CODE [" + codes[0] + ":" + codes[1] + "] is already exist.");
|
||||||
|
}
|
||||||
|
CoordinateReferenceSystem crs = this.parseWKT(codes[0], codes[1], properties.getProperty(pKey));
|
||||||
|
if (crs == null) continue;
|
||||||
|
pKey = String.valueOf(codes[0]) + ":" + codes[1];
|
||||||
|
this.definitions.put(pKey, crs);
|
||||||
|
this.addAuthority(codes[0]);
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "Success to add Override CRS [" + pKey + "] :: " + crs.toWKT());
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "Fail to add Override CRS [" + pKey + "] :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "Can't access O2CRS Configuration File :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public CoordinateReferenceSystem parseWKT(String auth, String code, String wkt) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)auth) || ServerUtil.isNullString((String)code)) {
|
||||||
|
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)wkt)) {
|
||||||
|
throw new FactoryException("CRS WKT is NULL.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
Parser parser = this.parser;
|
||||||
|
synchronized (parser) {
|
||||||
|
return this.parser.parseCoordinateReferenceSystem(auth, code, wkt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addAuthority(String auth) {
|
||||||
|
Citation cit = Citations.fromName((String)auth);
|
||||||
|
this.authority.getIdentifiers().addAll(cit.getIdentifiers());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isContainAuthority(String auth) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)auth)) {
|
||||||
|
throw new FactoryException("AUTHORITY is Null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
for (Identifier identifier : this.authority.getIdentifiers()) {
|
||||||
|
if (!identifier.getCode().equalsIgnoreCase(auth)) continue;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
* Enabled aggressive block sorting
|
||||||
|
* Enabled unnecessary exception pruning
|
||||||
|
* Enabled aggressive exception aggregation
|
||||||
|
*/
|
||||||
|
public boolean isContainCRS(String auth, String code) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)auth)) {
|
||||||
|
throw new FactoryException("AUTHORITY is Null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
if (ServerUtil.isNullString((String)code)) {
|
||||||
|
throw new FactoryException("CODE is Null.");
|
||||||
|
}
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
String key;
|
||||||
|
String[] codes;
|
||||||
|
Enumeration<String> keys = this.definitions.keys();
|
||||||
|
do {
|
||||||
|
if (keys.hasMoreElements()) continue;
|
||||||
|
return false;
|
||||||
|
} while (!(codes = (key = keys.nextElement()).split(":"))[0].equalsIgnoreCase(auth) || !codes[1].equalsIgnoreCase(code));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public void insertCRS(String auth, String code, CoordinateReferenceSystem crs, boolean write) throws Exception {
|
||||||
|
if (this.isContainCRS(auth, code)) {
|
||||||
|
throw new FactoryException("CODE [" + auth + ":" + code + "] is already exist.");
|
||||||
|
}
|
||||||
|
if (crs == null) {
|
||||||
|
throw new FactoryException("CRS is Null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
this.definitions.put(String.valueOf(auth) + ":" + code, crs);
|
||||||
|
this.addAuthority(auth);
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
if (write) {
|
||||||
|
this.writeDefinitions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public void updateCRS(String auth, String code, CoordinateReferenceSystem crs, boolean write) throws Exception {
|
||||||
|
if (!this.isContainCRS(auth, code)) {
|
||||||
|
throw new NoSuchAuthorityCodeException("Not exists authority or code ", auth, code);
|
||||||
|
}
|
||||||
|
if (crs == null) {
|
||||||
|
throw new FactoryException("CRS value is Null.");
|
||||||
|
}
|
||||||
|
String upKey = String.valueOf(auth.trim().toUpperCase()) + ":" + code.trim().toUpperCase();
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
this.definitions.put(upKey, crs);
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
if (write) {
|
||||||
|
this.writeDefinitions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public void removeCRS(String auth, String code, boolean write) throws Exception {
|
||||||
|
if (!this.isContainCRS(auth, code)) {
|
||||||
|
throw new NoSuchAuthorityCodeException("Not exists authority or code ", auth, code);
|
||||||
|
}
|
||||||
|
String rmKey = String.valueOf(auth.trim().toUpperCase()) + ":" + code.trim().toUpperCase();
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
this.definitions.remove(rmKey);
|
||||||
|
GeoTools.fireConfigurationChanged();
|
||||||
|
if (write) {
|
||||||
|
this.writeDefinitions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public CoordinateReferenceSystem getCRS(String auth, String code) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)auth) || ServerUtil.isNullString((String)code)) {
|
||||||
|
throw new FactoryException("Parameter [Authority:" + auth + "] or [Code:" + code + "] is null.");
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
code = code.trim().toUpperCase();
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
Enumeration<String> keys = this.definitions.keys();
|
||||||
|
while (keys.hasMoreElements()) {
|
||||||
|
String key = keys.nextElement();
|
||||||
|
String[] codes = key.split(":");
|
||||||
|
if (!codes[0].equalsIgnoreCase(auth) || !codes[1].equalsIgnoreCase(code)) continue;
|
||||||
|
return this.definitions.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NoSuchAuthorityCodeException("Not exists authority or code", auth, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public Set<String> getAuthorityCodes(String auth) {
|
||||||
|
TreeSet<String> codes = new TreeSet<String>();
|
||||||
|
if (ServerUtil.isNullString((String)auth)) {
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
codes.addAll(this.definitions.keySet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auth = auth.trim().toUpperCase();
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
for (String key : this.definitions.keySet()) {
|
||||||
|
String[] tempKeys = key.split(":");
|
||||||
|
if (!tempKeys[0].equalsIgnoreCase(auth)) continue;
|
||||||
|
codes.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return codes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
private void writeDefinitions() {
|
||||||
|
ConcurrentHashMap<String, CoordinateReferenceSystem> concurrentHashMap = this.definitions;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
block28: {
|
||||||
|
OutputStreamWriter writer = null;
|
||||||
|
BufferedWriter bWriter = null;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
File crsFile = new File(ServerContext.getConfFolder(), "o2crs.properties");
|
||||||
|
if (!crsFile.exists()) {
|
||||||
|
crsFile.createNewFile();
|
||||||
|
}
|
||||||
|
crsFile.setExecutable(true, false);
|
||||||
|
crsFile.setReadable(true);
|
||||||
|
crsFile.setWritable(true);
|
||||||
|
writer = new FileWriter(crsFile, false);
|
||||||
|
bWriter = new BufferedWriter(writer);
|
||||||
|
bWriter.append("# Additional CRS Definitions.").append("\n");
|
||||||
|
bWriter.append("# ").append("\n");
|
||||||
|
bWriter.append("# $AUTHORITY$ : CRS AUTHORITY").append("\n");
|
||||||
|
bWriter.append("# $CODE$ : CRS CODE").append("\n");
|
||||||
|
bWriter.append("# $WKT$ : CRS WKT").append("\n");
|
||||||
|
bWriter.append("# ").append("\n");
|
||||||
|
bWriter.append("# USE -> $AUTHORITY$:$CODE$=$WKT$").append("\n");
|
||||||
|
bWriter.append("").append("\n");
|
||||||
|
TreeSet<String> keys = new TreeSet<String>(this.definitions.keySet());
|
||||||
|
for (String key : keys) {
|
||||||
|
bWriter.append(key).append("=");
|
||||||
|
bWriter.append(this.definitions.get(key).toWKT()).append("\n");
|
||||||
|
}
|
||||||
|
bWriter.flush();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "Can't access O2CRS Configuration File :: " + e.getMessage());
|
||||||
|
if (writer != null) {
|
||||||
|
try {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bWriter != null) {
|
||||||
|
try {
|
||||||
|
bWriter.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {}
|
||||||
|
}
|
||||||
|
break block28;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable throwable) {
|
||||||
|
if (writer != null) {
|
||||||
|
try {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bWriter != null) {
|
||||||
|
try {
|
||||||
|
bWriter.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
if (writer != null) {
|
||||||
|
try {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bWriter != null) {
|
||||||
|
try {
|
||||||
|
bWriter.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class Parser
|
||||||
|
extends org.geotools.referencing.wkt.Parser {
|
||||||
|
private static final long serialVersionUID = -5910561042299146066L;
|
||||||
|
private CitationImpl auth;
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
public Parser() {
|
||||||
|
super(Symbols.DEFAULT, O2CRSOverrideFactory.this.factories);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String auth, String code, String wkt) throws ParseException {
|
||||||
|
this.auth = new CitationImpl(Citations.fromName((String)auth));
|
||||||
|
this.code = code;
|
||||||
|
return super.parseCoordinateReferenceSystem(wkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, Object> alterProperties(Map<String, Object> properties) {
|
||||||
|
properties.put("identifiers", new NamedIdentifier((Citation)this.auth, this.code));
|
||||||
|
return super.alterProperties(properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,272 +9,231 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
|
import org.geotools.data.DataAccessFactory;
|
||||||
import org.geotools.data.DataAccessFactory.Param;
|
import org.geotools.data.DataAccessFactory.Param;
|
||||||
import org.geotools.jdbc.JDBCDataStore;
|
import org.geotools.jdbc.JDBCDataStore;
|
||||||
import org.geotools.jdbc.JDBCDataStoreFactory;
|
import org.geotools.jdbc.JDBCDataStoreFactory;
|
||||||
import org.geotools.jdbc.SQLDialect;
|
import org.geotools.jdbc.SQLDialect;
|
||||||
|
|
||||||
public class O2DSFactory extends JDBCDataStoreFactory
|
import java.io.File;
|
||||||
{
|
import java.io.FileInputStream;
|
||||||
public static final DataAccessFactory.Param O2_SERVER_NAME = new DataAccessFactory.Param("o2map dbms server name", String.class,
|
import java.io.IOException;
|
||||||
"DBMS server name(alias)", true);
|
import java.io.InputStream;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
|
import org.geotools.data.DataAccessFactory;
|
||||||
|
import org.geotools.jdbc.JDBCDataStore;
|
||||||
|
import org.geotools.jdbc.JDBCDataStoreFactory;
|
||||||
|
import org.geotools.jdbc.PrimaryKeyFinder;
|
||||||
|
import org.geotools.jdbc.SQLDialect;
|
||||||
|
|
||||||
public static final DataAccessFactory.Param O2_PK_COLUMN_NAME = new DataAccessFactory.Param("o2map pk column name", String.class,
|
public class O2DSFactory
|
||||||
"Primary key column name (default is GID)", true);
|
extends JDBCDataStoreFactory {
|
||||||
|
public static final DataAccessFactory.Param O2_SERVER_NAME = new DataAccessFactory.Param("o2map dbms server name", String.class, "DBMS server name(alias)", true);
|
||||||
|
public static final DataAccessFactory.Param O2_PK_COLUMN_NAME = new DataAccessFactory.Param("o2map pk column name", String.class, "Primary key column name (default is GID)", true);
|
||||||
|
public static final DataAccessFactory.Param O2_USE_SPATIAL = new DataAccessFactory.Param("o2map use spatial datatype for dbms", Boolean.class, "Condition for use spatial datatype", true);
|
||||||
|
private final String sqlFileName = "/o2jdbcsql.properties";
|
||||||
|
private HashMap<String, Object> dsParams = new HashMap();
|
||||||
|
private SimpleSql dsSQL;
|
||||||
|
|
||||||
public static final DataAccessFactory.Param O2_USE_SPATIAL = new DataAccessFactory.Param("o2map use spatial datatype for dbms", Boolean.class,
|
public O2DSFactory(HashMap params) throws Exception {
|
||||||
"Condition for use spatial datatype", true);
|
this.dsParams = params;
|
||||||
|
this.refindParameter();
|
||||||
private final String sqlFileName = "/o2jdbcsql.properties";
|
this.createDSSql();
|
||||||
|
|
||||||
private HashMap<String, Object> dsParams = new HashMap();
|
|
||||||
private SimpleSql dsSQL;
|
|
||||||
|
|
||||||
public O2DSFactory(HashMap params)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
this.dsParams = params;
|
|
||||||
|
|
||||||
refindParameter();
|
|
||||||
|
|
||||||
createDSSql();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refindParameter()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
String dbType = (String)DBTYPE.lookUp(this.dsParams);
|
|
||||||
if (dbType == null) {
|
|
||||||
LogMngr.getInstance().logError("[DB]", "DBMS Type is Null");
|
|
||||||
throw new NullPointerException("DBMS Type is Null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBMSType.class.getField(dbType.toUpperCase()) == null) {
|
private void refindParameter() throws Exception {
|
||||||
LogMngr.getInstance().logError("[DB]", "Not supportd DBMS Type :: " + dbType);
|
|
||||||
throw new NullPointerException("Not supportd DBMS Type :: " + dbType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createDSSql()
|
|
||||||
throws IOException, URISyntaxException
|
|
||||||
{
|
|
||||||
String dbType = (String)DBTYPE.lookUp(this.dsParams);
|
|
||||||
|
|
||||||
if (dbType.equalsIgnoreCase(DBMSType.ORACLE.getTypeName())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties prop = new Properties();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File sqlFile = new File(ServerContext.getConfFolder(), "/o2jdbcsql.properties");
|
|
||||||
|
|
||||||
InputStream in = new FileInputStream(sqlFile);
|
|
||||||
prop.load(in);
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Can't access Spatial Query file :: " + e.getMessage());
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Please check Spatial Query file :: WEB-INF/conf/o2jdbcsql.properties");
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Now use default");
|
|
||||||
|
|
||||||
InputStream in = ServerContext.class.getResourceAsStream("/o2jdbcsql.properties");
|
|
||||||
prop.load(in);
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean useSpatial = (Boolean)O2_USE_SPATIAL.lookUp(this.dsParams);
|
|
||||||
if (useSpatial.booleanValue())
|
|
||||||
{
|
|
||||||
this.dsSQL = new SimpleSql(dbType);
|
|
||||||
|
|
||||||
this.dsSQL.setSqlEnvelope(prop.getProperty(dbType.toLowerCase() + ".spatial.envelope"));
|
|
||||||
this.dsSQL.setSqlBBox(prop.getProperty(dbType.toLowerCase() + ".spatial.bbox"));
|
|
||||||
|
|
||||||
this.dsSQL.setGeomToWKB(prop.getProperty(dbType.toLowerCase() + ".geometry.to.wkb"));
|
|
||||||
this.dsSQL.setGeomFromWKB(prop.getProperty(dbType.toLowerCase() + ".geometry.from.wkb"));
|
|
||||||
|
|
||||||
if (this.dsSQL.isValidate())
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "Crate Spatial Query :: " + this.dsSQL.toString());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.dsSQL = null;
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Spatial Query not avilable :: " + dbType);
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Please check Spatial Query file :: WEB-INF/conf/o2jdbcsql.properties");
|
|
||||||
|
|
||||||
throw new IOException("Spatial Query not avilable :: " + dbType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public JDBCDataStore getDataStore()
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
return createDataStore(this.dsParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore, Map params) throws IOException
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
String keyColumn = (String)O2_PK_COLUMN_NAME.lookUp(this.dsParams);
|
|
||||||
dataStore.setPrimaryKeyFinder(new O2DSPrimaryKeyFinder(keyColumn));
|
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "Find Primary Key Column :: " + keyColumn);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
dataStore.setPrimaryKeyFinder(new O2DSPrimaryKeyFinder("GID"));
|
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "Find Primary Key Column :: GID");
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicDataSource createDataSource(Map params)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
BasicDataSource dataSource = new BasicDataSource();
|
|
||||||
|
|
||||||
dataSource.setDriverClassName(getDriverClassName());
|
|
||||||
|
|
||||||
dataSource.setUrl(getJDBCUrl(params));
|
|
||||||
|
|
||||||
String user = (String)USER.lookUp(params);
|
|
||||||
dataSource.setUsername(user);
|
|
||||||
|
|
||||||
String passwd = (String)PASSWD.lookUp(params);
|
|
||||||
if (passwd != null) {
|
|
||||||
dataSource.setPassword(passwd);
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer minConn = (Integer)MINCONN.lookUp(params);
|
|
||||||
if (minConn != null) {
|
|
||||||
dataSource.setMinIdle(minConn.intValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer maxConn = (Integer)MAXCONN.lookUp(params);
|
|
||||||
if (maxConn != null) {
|
|
||||||
dataSource.setMaxActive(maxConn.intValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer maxWait = (Integer)MAXWAIT.lookUp(params);
|
|
||||||
if ((maxWait != null) && (maxWait.intValue() != -1)) {
|
|
||||||
dataSource.setMaxWait(maxWait.intValue() * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean validate = (Boolean)VALIDATECONN.lookUp(params);
|
|
||||||
if ((validate != null) && (validate.booleanValue()) && (getValidationQuery() != null)) {
|
|
||||||
dataSource.setTestOnBorrow(true);
|
|
||||||
dataSource.setValidationQuery(getValidationQuery());
|
|
||||||
}
|
|
||||||
|
|
||||||
dataSource.setAccessToUnderlyingConnectionAllowed(true);
|
|
||||||
return dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected SQLDialect createSQLDialect(JDBCDataStore dataStore)
|
|
||||||
{
|
|
||||||
boolean useSpatial = true;
|
|
||||||
try {
|
|
||||||
useSpatial = ((Boolean)O2_USE_SPATIAL.lookUp(this.dsParams)).booleanValue();
|
|
||||||
|
|
||||||
if (useSpatial)
|
|
||||||
{
|
|
||||||
String dbType = (String)DBTYPE.lookUp(this.dsParams);
|
String dbType = (String)DBTYPE.lookUp(this.dsParams);
|
||||||
|
if (dbType == null) {
|
||||||
if (dbType.equalsIgnoreCase(DBMSType.ORACLE.getTypeName())) {
|
LogMngr.getInstance().logError("[DB]", "DBMS Type is Null");
|
||||||
return new OracleDialect((String)O2_SERVER_NAME.lookUp(this.dsParams), dataStore);
|
throw new NullPointerException("DBMS Type is Null");
|
||||||
|
}
|
||||||
|
if (DBMSType.class.getField(dbType.toUpperCase()) == null) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Not supportd DBMS Type :: " + dbType);
|
||||||
|
throw new NullPointerException("Not supportd DBMS Type :: " + dbType);
|
||||||
}
|
}
|
||||||
return new SimpleDialect((String)O2_SERVER_NAME.lookUp(this.dsParams), dataStore, this.dsSQL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Fail :: To Make UseSpatial SQLDialect :: " + e.getMessage());
|
|
||||||
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Now Use Non-Spatial SQLDialect.");
|
|
||||||
try {
|
|
||||||
return new NonSpatialDialect((String)O2_SERVER_NAME.lookUp(this.dsParams), (String)DBTYPE.lookUp(this.dsParams), dataStore);
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Fail :: To Make Non-Spatial SQLDialect :: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getDriverClassName()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return ConnMngr.getInstance().getConnObj(getDatabaseID()).getDriverClassName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Can't find JDBC Object :: " + e.getMessage());
|
|
||||||
}return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getDatabaseID()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (String)DBTYPE.lookUp(this.dsParams); } catch (IOException e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDisplayName()
|
|
||||||
{
|
|
||||||
return getDescription();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getJDBCUrl(Map params) throws IOException
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return ConnMngr.getInstance().getConnObj(getDatabaseID())
|
|
||||||
.getJDBCUrl(
|
|
||||||
(String)HOST.lookUp(this.dsParams),
|
|
||||||
(Integer)PORT.lookUp(this.dsParams),
|
|
||||||
(String)DATABASE.lookUp(this.dsParams));
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Can't find JDBC Object :: " + e.getMessage());
|
|
||||||
throw new IOException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return (String)DBTYPE.lookUp(this.dsParams); } catch (IOException e) {
|
|
||||||
}
|
|
||||||
return "JDBC DATASTORE";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getValidationQuery()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum DBMSType
|
|
||||||
{
|
|
||||||
ORACLE("ORACLE"),
|
|
||||||
POSTGIS("POSTGIS"),
|
|
||||||
MYSQL("MYSQL"),
|
|
||||||
TIBERO("TIBERO"),
|
|
||||||
ALTIBASE("ALTIBASE"),
|
|
||||||
KAIROS("KAIROS");
|
|
||||||
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
private DBMSType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTypeName() {
|
private void createDSSql() throws IOException, URISyntaxException {
|
||||||
return this.type;
|
String dbType = (String)DBTYPE.lookUp(this.dsParams);
|
||||||
|
if (dbType.equalsIgnoreCase(DBMSType.ORACLE.getTypeName())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Properties prop = new Properties();
|
||||||
|
try {
|
||||||
|
File sqlFile = new File(ServerContext.getConfFolder(), "/o2jdbcsql.properties");
|
||||||
|
FileInputStream in = new FileInputStream(sqlFile);
|
||||||
|
prop.load(in);
|
||||||
|
((InputStream)in).close();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Can't access Spatial Query file :: " + e.getMessage());
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Please check Spatial Query file :: WEB-INF/conf/o2jdbcsql.properties");
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Now use default");
|
||||||
|
InputStream in = ServerContext.class.getResourceAsStream("/o2jdbcsql.properties");
|
||||||
|
prop.load(in);
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
Boolean useSpatial = (Boolean)O2_USE_SPATIAL.lookUp(this.dsParams);
|
||||||
|
if (useSpatial.booleanValue()) {
|
||||||
|
this.dsSQL = new SimpleSql(dbType);
|
||||||
|
this.dsSQL.setSqlEnvelope(prop.getProperty(String.valueOf(dbType.toLowerCase()) + ".spatial.envelope"));
|
||||||
|
this.dsSQL.setSqlBBox(prop.getProperty(String.valueOf(dbType.toLowerCase()) + ".spatial.bbox"));
|
||||||
|
this.dsSQL.setGeomToWKB(prop.getProperty(String.valueOf(dbType.toLowerCase()) + ".geometry.to.wkb"));
|
||||||
|
this.dsSQL.setGeomFromWKB(prop.getProperty(String.valueOf(dbType.toLowerCase()) + ".geometry.from.wkb"));
|
||||||
|
if (this.dsSQL.isValidate()) {
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Crate Spatial Query :: " + this.dsSQL.toString());
|
||||||
|
} else {
|
||||||
|
this.dsSQL = null;
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Spatial Query not avilable :: " + dbType);
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Please check Spatial Query file :: WEB-INF/conf/o2jdbcsql.properties");
|
||||||
|
throw new IOException("Spatial Query not avilable :: " + dbType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString()
|
public JDBCDataStore getDataStore() throws IOException {
|
||||||
{
|
return this.createDataStore(this.dsParams);
|
||||||
return getTypeName();
|
}
|
||||||
|
|
||||||
|
protected JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore, Map params) throws IOException {
|
||||||
|
try {
|
||||||
|
String keyColumn = (String)O2_PK_COLUMN_NAME.lookUp(this.dsParams);
|
||||||
|
dataStore.setPrimaryKeyFinder((PrimaryKeyFinder)new O2DSPrimaryKeyFinder(keyColumn));
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Find Primary Key Column :: " + keyColumn);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
dataStore.setPrimaryKeyFinder((PrimaryKeyFinder)new O2DSPrimaryKeyFinder("GID"));
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Find Primary Key Column :: GID");
|
||||||
|
}
|
||||||
|
return dataStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BasicDataSource createDataSource(Map params) throws IOException {
|
||||||
|
Boolean validate;
|
||||||
|
Integer maxWait;
|
||||||
|
Integer maxConn;
|
||||||
|
Integer minConn;
|
||||||
|
BasicDataSource dataSource = new BasicDataSource();
|
||||||
|
dataSource.setDriverClassName(this.getDriverClassName());
|
||||||
|
dataSource.setUrl(this.getJDBCUrl(params));
|
||||||
|
String user = (String)USER.lookUp(params);
|
||||||
|
dataSource.setUsername(user);
|
||||||
|
String passwd = (String)PASSWD.lookUp(params);
|
||||||
|
if (passwd != null) {
|
||||||
|
dataSource.setPassword(passwd);
|
||||||
|
}
|
||||||
|
if ((minConn = (Integer)MINCONN.lookUp(params)) != null) {
|
||||||
|
dataSource.setMinIdle(minConn.intValue());
|
||||||
|
}
|
||||||
|
if ((maxConn = (Integer)MAXCONN.lookUp(params)) != null) {
|
||||||
|
dataSource.setMaxActive(maxConn.intValue());
|
||||||
|
}
|
||||||
|
if ((maxWait = (Integer)MAXWAIT.lookUp(params)) != null && maxWait != -1) {
|
||||||
|
dataSource.setMaxWait((long)(maxWait * 1000));
|
||||||
|
}
|
||||||
|
if ((validate = (Boolean)VALIDATECONN.lookUp(params)) != null && validate.booleanValue() && this.getValidationQuery() != null) {
|
||||||
|
dataSource.setTestOnBorrow(true);
|
||||||
|
dataSource.setValidationQuery(this.getValidationQuery());
|
||||||
|
}
|
||||||
|
dataSource.setAccessToUnderlyingConnectionAllowed(true);
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SQLDialect createSQLDialect(JDBCDataStore dataStore) {
|
||||||
|
boolean useSpatial = true;
|
||||||
|
try {
|
||||||
|
useSpatial = (Boolean)O2_USE_SPATIAL.lookUp(this.dsParams);
|
||||||
|
if (useSpatial) {
|
||||||
|
String dbType = (String)DBTYPE.lookUp(this.dsParams);
|
||||||
|
if (dbType.equalsIgnoreCase(DBMSType.ORACLE.getTypeName())) {
|
||||||
|
return new OracleDialect((String)O2_SERVER_NAME.lookUp(this.dsParams), dataStore);
|
||||||
|
}
|
||||||
|
return new SimpleDialect((String)O2_SERVER_NAME.lookUp(this.dsParams), dataStore, this.dsSQL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Fail :: To Make UseSpatial SQLDialect :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Now Use Non-Spatial SQLDialect.");
|
||||||
|
try {
|
||||||
|
return new NonSpatialDialect((String)O2_SERVER_NAME.lookUp(this.dsParams), (String)DBTYPE.lookUp(this.dsParams), dataStore);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Fail :: To Make Non-Spatial SQLDialect :: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getDriverClassName() {
|
||||||
|
try {
|
||||||
|
return ConnMngr.getInstance().getConnObj(this.getDatabaseID()).getDriverClassName();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Can't find JDBC Object :: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getDatabaseID() {
|
||||||
|
try {
|
||||||
|
return (String)DBTYPE.lookUp(this.dsParams);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return this.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getJDBCUrl(Map params) throws IOException {
|
||||||
|
try {
|
||||||
|
return ConnMngr.getInstance().getConnObj(this.getDatabaseID()).getJDBCUrl((String)HOST.lookUp(this.dsParams), (Integer)PORT.lookUp(this.dsParams), (String)DATABASE.lookUp(this.dsParams));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Can't find JDBC Object :: " + e.getMessage());
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
try {
|
||||||
|
return (String)DBTYPE.lookUp(this.dsParams);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
return "JDBC DATASTORE";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getValidationQuery() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum DBMSType {
|
||||||
|
ORACLE("ORACLE"),
|
||||||
|
POSTGIS("POSTGIS"),
|
||||||
|
MYSQL("MYSQL"),
|
||||||
|
TIBERO("TIBERO"),
|
||||||
|
ALTIBASE("ALTIBASE"),
|
||||||
|
KAIROS("KAIROS");
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private DBMSType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTypeName() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return this.getTypeName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -7,284 +7,193 @@ import org.geotools.data.Query;
|
||||||
import org.geotools.data.collection.SpatialIndexFeatureCollection;
|
import org.geotools.data.collection.SpatialIndexFeatureCollection;
|
||||||
import org.geotools.data.collection.SpatialIndexFeatureSource;
|
import org.geotools.data.collection.SpatialIndexFeatureSource;
|
||||||
import org.geotools.data.shapefile.ShapefileDataStore;
|
import org.geotools.data.shapefile.ShapefileDataStore;
|
||||||
|
import org.geotools.data.shapefile.ShpDataStore;
|
||||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
import org.geotools.data.simple.SimpleFeatureIterator;
|
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||||
import org.geotools.data.simple.SimpleFeatureSource;
|
import org.geotools.data.simple.SimpleFeatureSource;
|
||||||
import org.geotools.data.store.ContentDataStoreRefinder;
|
|
||||||
import org.geotools.data.store.ContentDataStore;
|
import org.geotools.data.store.ContentDataStore;
|
||||||
|
import org.geotools.data.store.ContentDataStoreRefinder;
|
||||||
import org.geotools.data.store.ContentFeatureSource;
|
import org.geotools.data.store.ContentFeatureSource;
|
||||||
import org.geotools.factory.Hints;
|
import org.geotools.factory.Hints;
|
||||||
import org.geotools.jdbc.JDBCFeatureStore;
|
import org.geotools.jdbc.JDBCFeatureStore;
|
||||||
import org.opengis.feature.simple.SimpleFeature;
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
import org.opengis.filter.Filter;
|
import org.opengis.filter.Filter;
|
||||||
import org.opengis.filter.FilterFactory2;
|
|
||||||
import org.opengis.filter.Id;
|
import org.opengis.filter.Id;
|
||||||
import org.opengis.filter.identity.GmlObjectId;
|
import org.opengis.filter.identity.GmlObjectId;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
public class O2DSMngr
|
public class O2DSMngr {
|
||||||
{
|
private static HashMap<String, SpatialIndexFeatureSource> memoryStore = new HashMap<String, SpatialIndexFeatureSource>();
|
||||||
private static HashMap<String, SpatialIndexFeatureSource> memoryStore = new HashMap();
|
|
||||||
|
public static void putMemoryFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName, Filter filter) throws Exception {
|
||||||
public static void putMemoryFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName, Filter filter)
|
String key = String.valueOf(layerType.toString()) + "_" + serverName + "_" + tableName;
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
String key = layerType.toString() + "_" + serverName + "_" + tableName;
|
|
||||||
key = key.toUpperCase();
|
key = key.toUpperCase();
|
||||||
|
SpatialIndexFeatureSource featureSource = memoryStore.get(key);
|
||||||
SpatialIndexFeatureSource featureSource = (SpatialIndexFeatureSource)memoryStore.get(key);
|
if (featureSource != null)
|
||||||
|
throw new IOException("Memory store [" + key + "] is already exist.");
|
||||||
if (featureSource != null) {
|
|
||||||
throw new IOException("Memory store [" + key + "] is already exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
O2SpatialIndexFeatureCollection collection =
|
O2SpatialIndexFeatureCollection collection =
|
||||||
new O2SpatialIndexFeatureCollection(
|
new O2SpatialIndexFeatureCollection(
|
||||||
getFeatureSource(layerType, serverName, tableName).getFeatures(filter));
|
getFeatureSource(layerType, serverName, tableName).getFeatures(filter));
|
||||||
|
featureSource = new SpatialIndexFeatureSource((SpatialIndexFeatureCollection)collection);
|
||||||
featureSource = new SpatialIndexFeatureSource(collection);
|
|
||||||
|
|
||||||
memoryStore.put(key, featureSource);
|
memoryStore.put(key, featureSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearMemoryStore(LayerFactory.LayerType layerType, String serverName, String tableName) throws IOException
|
public static void clearMemoryStore(LayerFactory.LayerType layerType, String serverName, String tableName) throws IOException {
|
||||||
{
|
String key = String.valueOf(layerType.toString()) + "_" + serverName + "_" + tableName;
|
||||||
String key = layerType.toString() + "_" + serverName + "_" + tableName;
|
|
||||||
key = key.toUpperCase();
|
key = key.toUpperCase();
|
||||||
|
synchronized (memoryStore) {
|
||||||
synchronized (memoryStore)
|
|
||||||
{
|
|
||||||
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
||||||
|
if (featureSource == null)
|
||||||
if (featureSource == null) {
|
throw new IOException("Memory store [" + key + "] is not exist.");
|
||||||
throw new IOException("Memory store [" + key + "] is not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
((SpatialIndexFeatureCollection)featureSource.getFeatures()).clear();
|
((SpatialIndexFeatureCollection)featureSource.getFeatures()).clear();
|
||||||
featureSource = null;
|
featureSource = null;
|
||||||
memoryStore.remove(key);
|
memoryStore.remove(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearMemoryStore()
|
public static void clearMemoryStore() throws IOException {
|
||||||
throws IOException
|
synchronized (memoryStore) {
|
||||||
{
|
for (SimpleFeatureSource featureSource : memoryStore.values())
|
||||||
synchronized (memoryStore)
|
featureSource = null;
|
||||||
{
|
|
||||||
for (SimpleFeatureSource featureSource : memoryStore.values()) {
|
|
||||||
featureSource = null;
|
|
||||||
}
|
|
||||||
memoryStore.clear();
|
memoryStore.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JDBCFeatureStore getFeatureStore(LayerFactory.LayerType layerType, String serverName, String tableName)
|
public static JDBCFeatureStore getFeatureStore(LayerFactory.LayerType layerType, String serverName, String tableName) throws Exception {
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
if (layerType == null) {
|
|
||||||
throw new IllegalArgumentException("Parameter LayerType is NULL.");
|
|
||||||
}
|
|
||||||
if (ServerUtil.isNullString(serverName)) {
|
|
||||||
throw new IllegalArgumentException("Parameter ServerName is NULL.");
|
|
||||||
}
|
|
||||||
if (ServerUtil.isNullString(tableName)) {
|
|
||||||
throw new IllegalArgumentException("Parameter TableName is NULL.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layerType != LayerFactory.LayerType.JDBC) {
|
|
||||||
throw new Exception("DataStore type [" + layerType + "] is not support Transaction");
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleFeatureSource featureSource = getFeatureSource(layerType, serverName, tableName);
|
|
||||||
if ((featureSource instanceof SpatialIndexFeatureSource))
|
|
||||||
throw new Exception("Memory DataStore is not support Transaction");
|
|
||||||
JDBCFeatureStore featureStore;
|
JDBCFeatureStore featureStore;
|
||||||
if ((featureSource instanceof JDBCFeatureStore))
|
if (layerType == null)
|
||||||
|
throw new IllegalArgumentException("Parameter LayerType is NULL.");
|
||||||
|
if (ServerUtil.isNullString(serverName))
|
||||||
|
throw new IllegalArgumentException("Parameter ServerName is NULL.");
|
||||||
|
if (ServerUtil.isNullString(tableName))
|
||||||
|
throw new IllegalArgumentException("Parameter TableName is NULL.");
|
||||||
|
if (layerType != LayerFactory.LayerType.JDBC)
|
||||||
|
throw new Exception("DataStore type [" + layerType + "] is not support Transaction");
|
||||||
|
SimpleFeatureSource featureSource = getFeatureSource(layerType, serverName, tableName);
|
||||||
|
if (featureSource instanceof SpatialIndexFeatureSource)
|
||||||
|
throw new Exception("Memory DataStore is not support Transaction");
|
||||||
|
if (featureSource instanceof JDBCFeatureStore) {
|
||||||
featureStore = (JDBCFeatureStore)featureSource;
|
featureStore = (JDBCFeatureStore)featureSource;
|
||||||
else {
|
} else {
|
||||||
featureStore = new JDBCFeatureStore(((ContentFeatureSource)featureSource).getEntry(), null);
|
featureStore = new JDBCFeatureStore(((ContentFeatureSource)featureSource).getEntry(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return featureStore;
|
return featureStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleFeatureSource getFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName)
|
public static SimpleFeatureSource getFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName) throws Exception {
|
||||||
throws Exception
|
if (layerType == null)
|
||||||
{
|
throw new IllegalArgumentException("Parameter LayerType is NULL.");
|
||||||
if (layerType == null) {
|
if (ServerUtil.isNullString(serverName))
|
||||||
throw new IllegalArgumentException("Parameter LayerType is NULL.");
|
throw new IllegalArgumentException("Parameter ServerName is NULL.");
|
||||||
}
|
|
||||||
|
|
||||||
if (ServerUtil.isNullString(serverName)) {
|
|
||||||
throw new IllegalArgumentException("Parameter ServerName is NULL.");
|
|
||||||
}
|
|
||||||
serverName = serverName.trim().toUpperCase();
|
serverName = serverName.trim().toUpperCase();
|
||||||
|
if (ServerUtil.isNullString(tableName))
|
||||||
if (ServerUtil.isNullString(tableName)) {
|
throw new IllegalArgumentException("Parameter TableName is NULL.");
|
||||||
throw new IllegalArgumentException("Parameter TableName is NULL.");
|
|
||||||
}
|
|
||||||
tableName = tableName.trim().toUpperCase();
|
tableName = tableName.trim().toUpperCase();
|
||||||
try
|
try {
|
||||||
{
|
String key = String.valueOf(layerType.getType()) + "_" + serverName + "_" + tableName;
|
||||||
String key = layerType.getType() + "_" + serverName + "_" + tableName;
|
|
||||||
key = key.toUpperCase();
|
key = key.toUpperCase();
|
||||||
|
|
||||||
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
||||||
if (featureSource != null) {
|
if (featureSource != null)
|
||||||
return featureSource;
|
return featureSource;
|
||||||
}
|
} catch (Exception exception) {}
|
||||||
|
if (layerType == LayerFactory.LayerType.JDBC)
|
||||||
}
|
try {
|
||||||
catch (Exception localException)
|
return (SimpleFeatureSource)JdbcStoreMngr.getDataStore(serverName).getFeatureSource(tableName);
|
||||||
{
|
} catch (IOException e) {
|
||||||
if (layerType == LayerFactory.LayerType.JDBC)
|
return (SimpleFeatureSource)ContentDataStoreRefinder.refindJDBCFeatureSource((ContentDataStore)JdbcStoreMngr.getDataStore(serverName), tableName.toLowerCase());
|
||||||
{
|
}
|
||||||
try
|
if (layerType == LayerFactory.LayerType.GEOWAVE) {
|
||||||
{
|
GeoWaveDataStore store = GWaveStoreMngr.getDataStore(serverName);
|
||||||
return JdbcStoreMngr.getDataStore(serverName).getFeatureSource(tableName);
|
if (store == null)
|
||||||
}
|
throw new IOException("Schema '" + tableName + "' does not exist.");
|
||||||
catch (IOException e) {
|
return (SimpleFeatureSource)store.getFeatureSource(tableName);
|
||||||
return ContentDataStoreRefinder.refindJDBCFeatureSource(JdbcStoreMngr.getDataStore(serverName), tableName.toLowerCase());
|
}
|
||||||
}
|
if (layerType == LayerFactory.LayerType.SHAPE) {
|
||||||
}
|
ShpDataStore store = ShpStoreMngr.getDataStore(tableName);
|
||||||
|
if (store == null)
|
||||||
if (layerType == LayerFactory.LayerType.GEOWAVE) {
|
throw new IOException("Schema '" + tableName + "' does not exist.");
|
||||||
GeoWaveDataStore store = GWaveStoreMngr.getDataStore(serverName);
|
return (SimpleFeatureSource)store.getFeatureSource(tableName);
|
||||||
if (store == null) {
|
}
|
||||||
throw new IOException("Schema '" + tableName + "' does not exist.");
|
if (layerType == LayerFactory.LayerType.O2WPSVEC) {
|
||||||
}
|
ContentDataStore store = WpsVecStoreMngr.getShpDataStore(tableName);
|
||||||
return store.getFeatureSource(tableName);
|
if (store == null)
|
||||||
}
|
throw new IOException("Schema '" + tableName + "' does not exist.");
|
||||||
|
return (SimpleFeatureSource)store.getFeatureSource(tableName);
|
||||||
if (layerType == LayerFactory.LayerType.SHAPE)
|
}
|
||||||
{
|
|
||||||
ShpDataStore store = ShpStoreMngr.getDataStore(tableName);
|
|
||||||
if (store == null) {
|
|
||||||
throw new IOException("Schema '" + tableName + "' does not exist.");
|
|
||||||
}
|
|
||||||
return store.getFeatureSource(tableName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layerType == LayerFactory.LayerType.O2WPSVEC)
|
|
||||||
{
|
|
||||||
ContentDataStore store = WpsVecStoreMngr.getShpDataStore(tableName);
|
|
||||||
if (store == null) {
|
|
||||||
throw new IOException("Schema '" + tableName + "' does not exist.");
|
|
||||||
}
|
|
||||||
return store.getFeatureSource(tableName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception("DataStore type [" + layerType + "] is not support");
|
throw new Exception("DataStore type [" + layerType + "] is not support");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleFeatureSource changeCRSFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName, CoordinateReferenceSystem crs)
|
public static SimpleFeatureSource changeCRSFeatureSource(LayerFactory.LayerType layerType, String serverName, String tableName, CoordinateReferenceSystem crs) throws Exception {
|
||||||
throws Exception
|
if (ServerUtil.isNullString(tableName))
|
||||||
{
|
throw new IllegalArgumentException("Parameter TableName is NULL.");
|
||||||
if (ServerUtil.isNullString(tableName)) {
|
|
||||||
throw new IllegalArgumentException("Parameter TableName is NULL.");
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleFeatureSource featureSource = getFeatureSource(layerType, serverName, tableName);
|
SimpleFeatureSource featureSource = getFeatureSource(layerType, serverName, tableName);
|
||||||
|
if (featureSource.getDataStore() instanceof ShapefileDataStore) {
|
||||||
if ((featureSource.getDataStore() instanceof ShapefileDataStore)) {
|
|
||||||
ShapefileDataStore shapeStore = (ShapefileDataStore)featureSource.getDataStore();
|
ShapefileDataStore shapeStore = (ShapefileDataStore)featureSource.getDataStore();
|
||||||
shapeStore.forceSchemaCRS(crs);
|
shapeStore.forceSchemaCRS(crs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ContentDataStoreRefinder.changeCRSFeatureSource(featureSource, crs);
|
return ContentDataStoreRefinder.changeCRSFeatureSource(featureSource, crs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void disposeStores()
|
public static void disposeStores() {
|
||||||
{
|
|
||||||
JdbcStoreMngr.disposeDataStores();
|
JdbcStoreMngr.disposeDataStores();
|
||||||
GWaveStoreMngr.disposeDataStores();
|
GWaveStoreMngr.disposeDataStores();
|
||||||
ShpStoreMngr.disposeDataStores();
|
ShpStoreMngr.disposeDataStores();
|
||||||
WpsVecStoreMngr.disposeDataStores();
|
WpsVecStoreMngr.disposeDataStores();
|
||||||
|
for (SimpleFeatureSource source : memoryStore.values())
|
||||||
for (SimpleFeatureSource source : memoryStore.values()) {
|
source = null;
|
||||||
source = null;
|
|
||||||
}
|
|
||||||
memoryStore.clear();
|
memoryStore.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void disposeStore(String key)
|
public static void disposeStore(String key) {
|
||||||
{
|
|
||||||
JdbcStoreMngr.disposeDataStore(key);
|
JdbcStoreMngr.disposeDataStore(key);
|
||||||
GWaveStoreMngr.disposeDataStore(key);
|
GWaveStoreMngr.disposeDataStore(key);
|
||||||
ShpStoreMngr.disposeDataStore(key);
|
ShpStoreMngr.disposeDataStore(key);
|
||||||
WpsVecStoreMngr.disposeDataStore(key);
|
WpsVecStoreMngr.disposeDataStore(key);
|
||||||
|
|
||||||
SimpleFeatureSource source = (SimpleFeatureSource)memoryStore.remove(key);
|
SimpleFeatureSource source = (SimpleFeatureSource)memoryStore.remove(key);
|
||||||
source = null;
|
source = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleFeature getGmlObject(LayerFactory.LayerType layerType, String serverName, GmlObjectId id, Hints hints)
|
public static SimpleFeature getGmlObject(LayerFactory.LayerType layerType, String serverName, GmlObjectId id, Hints hints) throws Exception {
|
||||||
throws Exception
|
if (layerType == null)
|
||||||
{
|
throw new IllegalArgumentException("Parameter LayerType is NULL.");
|
||||||
if (layerType == null) {
|
if (ServerUtil.isNullString(serverName))
|
||||||
throw new IllegalArgumentException("Parameter LayerType is NULL.");
|
throw new IllegalArgumentException("Parameter ServerName is NULL.");
|
||||||
}
|
if (id == null)
|
||||||
if (ServerUtil.isNullString(serverName)) {
|
throw new IllegalArgumentException("Parameter GmlObjectId is NULL.");
|
||||||
throw new IllegalArgumentException("Parameter ServerName is NULL.");
|
try {
|
||||||
}
|
|
||||||
if (id == null) {
|
|
||||||
throw new IllegalArgumentException("Parameter GmlObjectId is NULL.");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String typeName = id.getID().substring(0, id.getID().lastIndexOf("."));
|
String typeName = id.getID().substring(0, id.getID().lastIndexOf("."));
|
||||||
|
String key = String.valueOf(layerType.toString()) + "_" + serverName + "_" + typeName;
|
||||||
String key = layerType.toString() + "_" + serverName + "_" + typeName;
|
|
||||||
key = key.toUpperCase();
|
key = key.toUpperCase();
|
||||||
|
|
||||||
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
SimpleFeatureSource featureSource = (SimpleFeatureSource)memoryStore.get(key);
|
||||||
if (featureSource != null) {
|
if (featureSource != null)
|
||||||
return getMemoryGmlObject(featureSource, id, hints);
|
return getMemoryGmlObject(featureSource, id, hints);
|
||||||
}
|
} catch (Exception exception) {}
|
||||||
|
if (layerType == LayerFactory.LayerType.JDBC)
|
||||||
}
|
return (SimpleFeature)JdbcStoreMngr.getDataStore(serverName).getGmlObject(id, hints);
|
||||||
catch (Exception localException)
|
if (layerType == LayerFactory.LayerType.GEOWAVE)
|
||||||
{
|
return (SimpleFeature)GWaveStoreMngr.getDataStore(serverName).getGmlObject(id, hints);
|
||||||
if (layerType == LayerFactory.LayerType.JDBC) {
|
if (layerType == LayerFactory.LayerType.SHAPE)
|
||||||
return (SimpleFeature)JdbcStoreMngr.getDataStore(serverName).getGmlObject(id, hints);
|
return (SimpleFeature)ShpStoreMngr.getGmlObject(id, hints);
|
||||||
}
|
if (layerType == LayerFactory.LayerType.O2WPSVEC)
|
||||||
if (layerType == LayerFactory.LayerType.GEOWAVE) {
|
return (SimpleFeature)WpsVecStoreMngr.getGmlObject(id, hints);
|
||||||
return (SimpleFeature)GWaveStoreMngr.getDataStore(serverName).getGmlObject(id, hints);
|
|
||||||
}
|
|
||||||
if (layerType == LayerFactory.LayerType.SHAPE) {
|
|
||||||
return (SimpleFeature)ShpStoreMngr.getGmlObject(id, hints);
|
|
||||||
}
|
|
||||||
if (layerType == LayerFactory.LayerType.O2WPSVEC) {
|
|
||||||
return (SimpleFeature)WpsVecStoreMngr.getGmlObject(id, hints);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Exception("DataStore type [" + layerType + "] is not support");
|
throw new Exception("DataStore type [" + layerType + "] is not support");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleFeature getMemoryGmlObject(SimpleFeatureSource featureSource, GmlObjectId id, Hints hints)
|
public static SimpleFeature getMemoryGmlObject(SimpleFeatureSource featureSource, GmlObjectId id, Hints hints) throws Exception {
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Id filter = StyleMngr.ff.id(Collections.singleton(id));
|
Id filter = StyleMngr.ff.id(Collections.singleton(id));
|
||||||
Query query = new Query();
|
Query query = new Query();
|
||||||
query.setFilter(filter);
|
query.setFilter((Filter)filter);
|
||||||
query.setHints(hints);
|
query.setHints(hints);
|
||||||
|
|
||||||
SimpleFeatureCollection features = featureSource.getFeatures(query);
|
SimpleFeatureCollection features = featureSource.getFeatures(query);
|
||||||
if (!features.isEmpty()) {
|
if (!features.isEmpty()) {
|
||||||
SimpleFeatureIterator fi = features.features();
|
SimpleFeatureIterator fi = features.features();
|
||||||
try {
|
try {
|
||||||
if (fi.hasNext()) {
|
if (fi.hasNext())
|
||||||
SimpleFeature localSimpleFeature = (SimpleFeature)fi.next(); return localSimpleFeature;
|
return (SimpleFeature)fi.next();
|
||||||
}
|
} finally {
|
||||||
}
|
|
||||||
finally {
|
|
||||||
fi.close();
|
fi.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,183 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class O2DemLayerMngr {
|
||||||
|
public static void initLayers() {
|
||||||
|
try {
|
||||||
|
File dir = ServerContext.getPluginsFolder();
|
||||||
|
String fileName = String.valueOf(ServerContext.getMap().getName()) + LayerFactory.LayerType.O2DEM.getPrefix();
|
||||||
|
File confFile = ServerUtil.findFile((File)dir, (String)fileName);
|
||||||
|
if (confFile == null) {
|
||||||
|
LogMngr.getInstance().logError("[O2DEM]", "Skip create O2DemLayer :: Layer Configuration File [" + confFile + "] is not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[O2DEM]", "[" + confFile.getName() + "] Now create O2DemLayer from this configuration");
|
||||||
|
ArrayList<O2LayerInfo> layerInfoList = O2DemLayerMngr.parseO2DemLayer(confFile);
|
||||||
|
if (layerInfoList == null || layerInfoList.isEmpty()) {
|
||||||
|
LogMngr.getInstance().logError("[O2DEM]", "[" + confFile.getName() + "] Fail to create O2DemLayer :: O2DemLayer size is ZERO[0] from this configuration");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (O2LayerInfo info : layerInfoList) {
|
||||||
|
LogMngr.getInstance().logDebug("[O2DEM]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Now create this O2DemLayer");
|
||||||
|
try {
|
||||||
|
O2DemLayerMngr.addLayer(info.getLayerPath(), info.getLayerName(), info.getLayerCRS(), info.getDesc(), info.getMinData(), info.getMaxData(), info.getNoData());
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Success :: " + "[Map:" + ServerContext.getMap().getName() + "/Layer:" + info.getLayerName() + "] : " + "[RefServer:" + LayerFactory.LayerType.O2IMG.getType() + "/RefSource:" + info.getLayerPath() + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2DEM]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Fail :: " + e);
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[O2DEM]", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2DEM]", "Create O2DemLayer Fail :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArrayList<O2LayerInfo> parseO2DemLayer(File conf) {
|
||||||
|
if (!conf.exists()) {
|
||||||
|
LogMngr.getInstance().logError("[O2DEM]", "[" + conf.getName() + "] Create O2DemLayer Fail :: O2DemLayer configuration is not exist");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArrayList<O2LayerInfo> layerInfoList = new ArrayList<O2LayerInfo>();
|
||||||
|
O2LayerInfo lInfo = null;
|
||||||
|
BufferedReader bReader = null;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
String line;
|
||||||
|
bReader = new BufferedReader(new FileReader(conf));
|
||||||
|
while ((line = bReader.readLine()) != null) {
|
||||||
|
if ((line = line.trim()).startsWith("#") || ServerUtil.isNullString((String)line)) continue;
|
||||||
|
try {
|
||||||
|
if (line.equalsIgnoreCase("[LAYER_CONFIG]")) {
|
||||||
|
lInfo = new O2LayerInfo();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.ACTIVATE")) {
|
||||||
|
lInfo.setActivate(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.NAME")) {
|
||||||
|
lInfo.setLayerName(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.CRS")) {
|
||||||
|
lInfo.setLayerCRS(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.PATH")) {
|
||||||
|
lInfo.setLayerPath(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.DESC")) {
|
||||||
|
lInfo.setDesc(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.DATA.MIN")) {
|
||||||
|
lInfo.setMinData(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.DATA.MAX")) {
|
||||||
|
lInfo.setMaxData(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.DATA.NODATA")) {
|
||||||
|
lInfo.setNoData(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!line.equalsIgnoreCase("[/LAYER_CONFIG]")) continue;
|
||||||
|
if (lInfo != null && lInfo.isAvailable()) {
|
||||||
|
layerInfoList.add(lInfo);
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logError("[O2DEM]", "[" + conf.getName() + "] Skip this O2DemLayer :: Layer info is not available [" + lInfo.getLayerName() + "]");
|
||||||
|
}
|
||||||
|
lInfo = null;
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2DEM]", "[" + conf.getName() + "] O2DemLayer configuration file is not valid :: " + e.getMessage());
|
||||||
|
try {
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e2) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return layerInfoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static O2DemLayer addLayer(File layerPath, String layerName, CoordinateReferenceSystem crs, String desc, Float min, Float max, Float noData) throws Exception {
|
||||||
|
if (layerPath == null || !layerPath.exists() || layerPath.isFile()) {
|
||||||
|
throw new IOException("O2DemLayer levelset is not exist [" + layerPath.getAbsolutePath() + "]");
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)layerName)) {
|
||||||
|
throw new IOException("O2DemLayer LayerName is null");
|
||||||
|
}
|
||||||
|
if (crs == null) {
|
||||||
|
throw new IOException("O2DemLayer LayerCRS is null");
|
||||||
|
}
|
||||||
|
O2LayerLevelSet lvlSet = O2LayerUtil.createLevelSet((LayerFactory.LayerType)LayerFactory.LayerType.O2DEM, (File)layerPath);
|
||||||
|
if (min != null) {
|
||||||
|
lvlSet.setMinData(min);
|
||||||
|
}
|
||||||
|
if (max != null) {
|
||||||
|
lvlSet.setMaxData(max);
|
||||||
|
}
|
||||||
|
if (noData != null) {
|
||||||
|
lvlSet.setNoData(noData);
|
||||||
|
}
|
||||||
|
AVList params = new AVList();
|
||||||
|
params.setValue("conf.service.map.name", (Object)ServerContext.getMap().getName());
|
||||||
|
params.setValue("conf.service.layer.name", (Object)layerName);
|
||||||
|
params.setValue("conf.service.ref.server", (Object)LayerFactory.LayerType.O2DEM.getType());
|
||||||
|
params.setValue("conf.service.ref.source", (Object)layerPath.getParent());
|
||||||
|
params.setValue("conf.service.ref.crs", (Object)crs);
|
||||||
|
params.setValue("conf.service.sld", null);
|
||||||
|
params.setValue("conf.service.use.cache", (Object)false);
|
||||||
|
params.setValue("conf.service.last.update", null);
|
||||||
|
params.setValue("conf.service.description", (Object)desc);
|
||||||
|
params.setValue("o2layer.conf.level.set", (Object)lvlSet);
|
||||||
|
Layer layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.O2DEM, (AVList)params);
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||||
|
return (O2DemLayer)layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void reloadLayer() throws Exception {
|
||||||
|
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.O2DEM);
|
||||||
|
try {
|
||||||
|
O2DemLayerMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[O2DEM]", "Success to reload O2DemLayers.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2DEM]", "Fail to reload O2DemLayers. Now use previous O2DemLayers :: " + e);
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayers(oldLayers, false);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,170 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.geotools.data.DataUtilities;
|
||||||
|
import org.geotools.data.FeatureReader;
|
||||||
|
import org.geotools.data.collection.DelegateFeatureReader;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||||
|
import org.geotools.feature.FeatureCollection;
|
||||||
|
import org.geotools.feature.FeatureIterator;
|
||||||
|
import org.geotools.feature.collection.DecoratingSimpleFeatureCollection;
|
||||||
|
import org.geotools.feature.simple.SimpleFeatureBuilder;
|
||||||
|
import org.geotools.feature.visitor.FeatureAttributeVisitor;
|
||||||
|
import org.geotools.filter.FilterAttributeExtractor;
|
||||||
|
import org.opengis.feature.FeatureVisitor;
|
||||||
|
import org.opengis.feature.IllegalAttributeException;
|
||||||
|
import org.opengis.feature.Property;
|
||||||
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.feature.type.FeatureType;
|
||||||
|
import org.opengis.filter.expression.Expression;
|
||||||
|
import org.opengis.filter.expression.ExpressionVisitor;
|
||||||
|
import org.opengis.filter.expression.PropertyName;
|
||||||
|
|
||||||
|
public class O2FeatureCollection
|
||||||
|
extends DecoratingSimpleFeatureCollection {
|
||||||
|
SimpleFeatureType featureType;
|
||||||
|
boolean isRetype = false;
|
||||||
|
boolean isInitNullValue = false;
|
||||||
|
|
||||||
|
public O2FeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> delegate, SimpleFeatureType featureType) {
|
||||||
|
this(DataUtilities.simple(delegate), featureType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public O2FeatureCollection(SimpleFeatureCollection delegate, SimpleFeatureType fType) {
|
||||||
|
super(delegate);
|
||||||
|
if (fType == null) {
|
||||||
|
fType = (SimpleFeatureType)delegate.getSchema();
|
||||||
|
} else {
|
||||||
|
this.isRetype = true;
|
||||||
|
}
|
||||||
|
this.featureType = fType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureType getSchema() {
|
||||||
|
return this.featureType;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean canDelegate(FeatureVisitor visitor) {
|
||||||
|
if (visitor instanceof FeatureAttributeVisitor) {
|
||||||
|
FilterAttributeExtractor extractor = new FilterAttributeExtractor(this.featureType);
|
||||||
|
for (Expression e : ((FeatureAttributeVisitor)visitor).getExpressions()) {
|
||||||
|
e.accept((ExpressionVisitor)extractor, null);
|
||||||
|
}
|
||||||
|
for (PropertyName pname : extractor.getPropertyNameSet()) {
|
||||||
|
AttributeDescriptor att = (AttributeDescriptor)pname.evaluate((Object)this.featureType);
|
||||||
|
if (att != null) continue;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FeatureReader<SimpleFeatureType, SimpleFeature> reader() throws IOException {
|
||||||
|
return new DelegateFeatureReader((FeatureType)this.getSchema(), (FeatureIterator)this.features());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRetype() {
|
||||||
|
return this.isRetype;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRetype(boolean bool) {
|
||||||
|
this.isRetype = bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInitNullValue() {
|
||||||
|
return this.isInitNullValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInitNullValue(boolean bool) {
|
||||||
|
this.isInitNullValue = bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureIterator features() {
|
||||||
|
return new O2ReTypingFeatureIterator(this.delegate, this.getSchema(), this.isRetype(), this.isInitNullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AttributeDescriptor[] typeAttributes(SimpleFeatureType original, SimpleFeatureType target) {
|
||||||
|
if (target.equals((Object)original)) {
|
||||||
|
throw new IllegalArgumentException("FeatureReader allready produces contents with the correct schema");
|
||||||
|
}
|
||||||
|
if (target.getAttributeCount() > original.getAttributeCount()) {
|
||||||
|
throw new IllegalArgumentException("Unable to retype FeatureReader<SimpleFeatureType, SimpleFeature> (origional does not cover requested type)");
|
||||||
|
}
|
||||||
|
AttributeDescriptor[] types = new AttributeDescriptor[target.getAttributeCount()];
|
||||||
|
int i = 0;
|
||||||
|
while (i < target.getAttributeCount()) {
|
||||||
|
AttributeDescriptor attrib = target.getDescriptor(i);
|
||||||
|
String xpath = attrib.getLocalName();
|
||||||
|
types[i] = attrib;
|
||||||
|
if (!attrib.equals(original.getDescriptor(xpath))) {
|
||||||
|
throw new IllegalArgumentException("Unable to retype FeatureReader<SimpleFeatureType, SimpleFeature> (origional does not cover " + xpath + ")");
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
class O2ReTypingFeatureIterator
|
||||||
|
implements SimpleFeatureIterator {
|
||||||
|
SimpleFeatureType source;
|
||||||
|
AttributeDescriptor[] types;
|
||||||
|
SimpleFeatureIterator delegate;
|
||||||
|
SimpleFeatureType target;
|
||||||
|
boolean retyping;
|
||||||
|
boolean initNullValue = false;
|
||||||
|
SimpleFeatureBuilder builder;
|
||||||
|
|
||||||
|
public O2ReTypingFeatureIterator(SimpleFeatureCollection featuresource, SimpleFeatureType target, boolean retype, boolean nullValue) {
|
||||||
|
boolean test = featuresource.isEmpty();
|
||||||
|
this.source = (SimpleFeatureType)featuresource.getSchema();
|
||||||
|
this.target = target;
|
||||||
|
this.delegate = featuresource.features();
|
||||||
|
this.retyping = retype;
|
||||||
|
this.initNullValue = nullValue;
|
||||||
|
this.builder = new SimpleFeatureBuilder(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureIterator getDelegate() {
|
||||||
|
return this.delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNext() {
|
||||||
|
return this.delegate.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeature next() {
|
||||||
|
SimpleFeature feature = (SimpleFeature)this.delegate.next();
|
||||||
|
if (this.initNullValue) {
|
||||||
|
for (Property property : feature.getValue()) {
|
||||||
|
if (property.getValue() != null) continue;
|
||||||
|
property.setValue((Object)"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.retyping) {
|
||||||
|
return feature;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String fid = feature.getID();
|
||||||
|
this.types = O2FeatureCollection.this.typeAttributes(this.source, this.target);
|
||||||
|
int i = 0;
|
||||||
|
while (i < this.types.length) {
|
||||||
|
String xpath = this.types[i].getLocalName();
|
||||||
|
this.builder.add(feature.getAttribute(xpath));
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
fid = fid.replace(feature.getType().getTypeName(), this.target.getTypeName());
|
||||||
|
return this.builder.buildFeature(fid);
|
||||||
|
}
|
||||||
|
catch (IllegalAttributeException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
this.delegate.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,259 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import net.opengis.wfs.FeatureCollectionType;
|
||||||
|
import net.opengis.wfs.WfsFactory;
|
||||||
|
import org.geotools.GML;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.gml.producer.FeatureTransformer;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.geotools.wfs.WFS;
|
||||||
|
import org.geotools.wfs.v1_0.WFSConfiguration;
|
||||||
|
import org.geotools.xml.Configuration;
|
||||||
|
import org.geotools.xml.Encoder;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.FeatureType;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.w3c.dom.Attr;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.helpers.NamespaceSupport;
|
||||||
|
|
||||||
|
public class O2GML {
|
||||||
|
private Charset encoding = Charset.forName("UTF-8");
|
||||||
|
private GML.Version version;
|
||||||
|
private String prefix;
|
||||||
|
private String namespace;
|
||||||
|
private boolean isUseNSPrefix = true;
|
||||||
|
private int indent = 4;
|
||||||
|
private String defaultPrefix = "wfs";
|
||||||
|
private String defaultNameSpace = "http://www.opengis.net/wfs";
|
||||||
|
|
||||||
|
public O2GML(GML.Version version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encode(HttpServletResponse resp, SimpleFeatureCollection collection) throws Exception {
|
||||||
|
if (this.version == GML.Version.GML2) {
|
||||||
|
this.encodeLegacyGML2(resp, collection);
|
||||||
|
} else if (this.version == GML.Version.GML3) {
|
||||||
|
this.encodeLegacyGML3(resp, collection);
|
||||||
|
} else if (this.version == GML.Version.WFS1_0) {
|
||||||
|
Encoder e = new Encoder((Configuration)new WFSConfiguration());
|
||||||
|
e.getNamespaces().declarePrefix(this.prefix, this.namespace);
|
||||||
|
e.setIndenting(true);
|
||||||
|
if (!this.isUseNSPrefix) {
|
||||||
|
e.setNamespaceAware(false);
|
||||||
|
}
|
||||||
|
FeatureCollectionType featureCollectionType = WfsFactory.eINSTANCE.createFeatureCollectionType();
|
||||||
|
featureCollectionType.getFeature().add((Object)collection);
|
||||||
|
e.encode((Object)featureCollectionType, WFS.FeatureCollection, (OutputStream)resp.getOutputStream());
|
||||||
|
} else if (this.version == GML.Version.WFS1_1) {
|
||||||
|
Encoder e = new Encoder((Configuration)new org.geotools.wfs.v1_1.WFSConfiguration());
|
||||||
|
e.getNamespaces().declarePrefix(this.prefix, this.namespace);
|
||||||
|
e.setIndenting(true);
|
||||||
|
if (!this.isUseNSPrefix) {
|
||||||
|
e.setNamespaceAware(false);
|
||||||
|
}
|
||||||
|
FeatureCollectionType featureCollectionType = WfsFactory.eINSTANCE.createFeatureCollectionType();
|
||||||
|
featureCollectionType.getFeature().add((Object)collection);
|
||||||
|
e.encode((Object)featureCollectionType, WFS.FeatureCollection, (OutputStream)resp.getOutputStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void encodeLegacyGML2(HttpServletResponse resp, SimpleFeatureCollection collection) throws Exception {
|
||||||
|
FeatureTransformer transform = new FeatureTransformer();
|
||||||
|
SimpleFeatureType TYPE = (SimpleFeatureType)collection.getSchema();
|
||||||
|
if (collection.size() > 0 && TYPE != null) {
|
||||||
|
if (TYPE.getName().getNamespaceURI() != null && TYPE.getUserData().get("prefix") != null) {
|
||||||
|
String typeNamespace = TYPE.getName().getNamespaceURI();
|
||||||
|
String typePrefix = (String)TYPE.getUserData().get("prefix");
|
||||||
|
transform.getFeatureTypeNamespaces().declareNamespace((FeatureType)TYPE, typePrefix, typeNamespace);
|
||||||
|
String srsName = CRS.toSRS((CoordinateReferenceSystem)TYPE.getCoordinateReferenceSystem());
|
||||||
|
if (srsName != null) {
|
||||||
|
transform.setSrsName(srsName);
|
||||||
|
}
|
||||||
|
} else if (this.prefix != null && this.namespace != null) {
|
||||||
|
transform.getFeatureTypeNamespaces().declareNamespace((FeatureType)TYPE, this.prefix, this.namespace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transform.setIndentation(this.indent);
|
||||||
|
transform.setNumDecimals(4);
|
||||||
|
transform.setGmlPrefixing(true);
|
||||||
|
if (this.prefix != null && this.namespace != null) {
|
||||||
|
transform.getFeatureTypeNamespaces().declareDefaultNamespace(this.prefix, this.namespace);
|
||||||
|
}
|
||||||
|
if (this.isUseNSPrefix) {
|
||||||
|
transform.setCollectionPrefix(this.defaultPrefix);
|
||||||
|
} else {
|
||||||
|
transform.setCollectionPrefix(null);
|
||||||
|
}
|
||||||
|
transform.setCollectionNamespace(this.defaultNameSpace);
|
||||||
|
transform.setCollectionBounding(true);
|
||||||
|
transform.setEncoding(this.encoding);
|
||||||
|
NamespaceSupport ns = transform.getFeatureNamespaces();
|
||||||
|
ns.declarePrefix(this.defaultPrefix, this.defaultNameSpace);
|
||||||
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||||
|
ServletOutputStream oStream = null;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
resp.setContentType("text/xml; charset=UTF-8");
|
||||||
|
oStream = resp.getOutputStream();
|
||||||
|
transform.transform((Object)collection, new StreamResult(bytes));
|
||||||
|
resp.setContentLength(bytes.size());
|
||||||
|
bytes.writeTo((OutputStream)oStream);
|
||||||
|
bytes.flush();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new Exception("OutputStream has problem.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (oStream != null) {
|
||||||
|
try {
|
||||||
|
oStream.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {}
|
||||||
|
}
|
||||||
|
if (bytes != null) {
|
||||||
|
try {
|
||||||
|
bytes.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void encodeLegacyGML3(HttpServletResponse resp, SimpleFeatureCollection collection) throws Exception {
|
||||||
|
NodeList nodeList;
|
||||||
|
Encoder e = new Encoder((Configuration)new org.geotools.wfs.v1_1.WFSConfiguration());
|
||||||
|
e.getNamespaces().declarePrefix(this.prefix, this.namespace);
|
||||||
|
e.getNamespaces().declarePrefix(this.defaultPrefix, this.defaultNameSpace);
|
||||||
|
if (!this.isUseNSPrefix) {
|
||||||
|
e.setNamespaceAware(false);
|
||||||
|
}
|
||||||
|
e.setIndenting(true);
|
||||||
|
e.setIndentSize(this.indent);
|
||||||
|
FeatureCollectionType featureCollectionType = WfsFactory.eINSTANCE.createFeatureCollectionType();
|
||||||
|
featureCollectionType.getFeature().add((Object)collection);
|
||||||
|
if (this.defaultPrefix.equalsIgnoreCase("wfs")) {
|
||||||
|
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||||
|
e.encode((Object)featureCollectionType, WFS.FeatureCollection, (OutputStream)result);
|
||||||
|
XMLUtil.writeToResponse((HttpServletResponse)resp, (Encoder)e, (ByteArrayOutputStream)result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
org.w3c.dom.Document doc = e.encodeAsDOM((Object)featureCollectionType, WFS.FeatureCollection);
|
||||||
|
Element rootElement = doc.getDocumentElement();
|
||||||
|
doc.renameNode(rootElement, this.defaultNameSpace, rootElement.getLocalName());
|
||||||
|
rootElement.setPrefix(this.defaultPrefix);
|
||||||
|
Attr attr = rootElement.getAttributeNode("xmlns:wfs");
|
||||||
|
if (attr != null) {
|
||||||
|
rootElement.removeAttributeNode(attr);
|
||||||
|
}
|
||||||
|
if (!this.isUseNSPrefix) {
|
||||||
|
rootElement.setPrefix(null);
|
||||||
|
}
|
||||||
|
if (this.defaultPrefix.equalsIgnoreCase("gml") && (nodeList = doc.getElementsByTagNameNS("http://www.geotwo.com", "*")) != null) {
|
||||||
|
int i = 0;
|
||||||
|
while (i < nodeList.getLength()) {
|
||||||
|
org.w3c.dom.Node node = nodeList.item(i);
|
||||||
|
if (node instanceof Element) {
|
||||||
|
doc.renameNode(node, this.defaultNameSpace, node.getLocalName());
|
||||||
|
node.setPrefix(this.defaultPrefix);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XMLUtil.writeToResponse((HttpServletResponse)resp, doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeLegacyGML3(OutputStream out, SimpleFeatureCollection collection) throws Exception {
|
||||||
|
Document doc = this.encodeLegacyGML3(collection);
|
||||||
|
XMLUtil.writeToResponse((OutputStream)out, (Document)doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Document encodeLegacyGML3(SimpleFeatureCollection collection) throws Exception {
|
||||||
|
NodeList nodeList;
|
||||||
|
Encoder e = new Encoder((Configuration)new org.geotools.wfs.v1_1.WFSConfiguration());
|
||||||
|
e.setNamespaceAware(true);
|
||||||
|
e.getNamespaces().declarePrefix(this.prefix, this.namespace);
|
||||||
|
e.getNamespaces().declarePrefix(this.defaultPrefix, this.defaultNameSpace);
|
||||||
|
e.setIndenting(true);
|
||||||
|
e.setIndentSize(this.indent);
|
||||||
|
FeatureCollectionType featureCollectionType = WfsFactory.eINSTANCE.createFeatureCollectionType();
|
||||||
|
featureCollectionType.getFeature().add((Object)collection);
|
||||||
|
NamespaceSupport ns = e.getNamespaces();
|
||||||
|
ns.declarePrefix("", this.defaultNameSpace);
|
||||||
|
Document doc = e.encodeAsDOM((Object)featureCollectionType, WFS.FeatureCollection);
|
||||||
|
Element rootElement = doc.getDocumentElement();
|
||||||
|
if (!this.defaultPrefix.equalsIgnoreCase("wfs")) {
|
||||||
|
doc.renameNode(rootElement, this.defaultNameSpace, rootElement.getLocalName());
|
||||||
|
rootElement.setPrefix(this.defaultPrefix);
|
||||||
|
Attr attr = rootElement.getAttributeNode("xmlns:wfs");
|
||||||
|
if (attr != null) {
|
||||||
|
rootElement.removeAttributeNode(attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.isUseNSPrefix) {
|
||||||
|
rootElement.setPrefix(null);
|
||||||
|
}
|
||||||
|
if (this.defaultPrefix.equalsIgnoreCase("gml") && (nodeList = doc.getElementsByTagNameNS("http://www.geotwo.com", "*")) != null) {
|
||||||
|
int i = 0;
|
||||||
|
while (i < nodeList.getLength()) {
|
||||||
|
org.w3c.dom.Node node = nodeList.item(i);
|
||||||
|
if (node instanceof Element) {
|
||||||
|
doc.renameNode(node, this.defaultNameSpace, node.getLocalName());
|
||||||
|
node.setPrefix(this.defaultPrefix);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEncoding(Charset encoding) {
|
||||||
|
this.encoding = encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNamespace(String prefix, String namespace) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.namespace = namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndent() {
|
||||||
|
return this.indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndent(int indent) {
|
||||||
|
this.indent = indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUseNSPrefix() {
|
||||||
|
return this.isUseNSPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseNSPrefix(boolean isUseDefaultNSPrefix) {
|
||||||
|
this.isUseNSPrefix = isUseDefaultNSPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDafaultNamespace(String defaultPrefix, String defaultNameSpace) {
|
||||||
|
this.defaultPrefix = defaultPrefix;
|
||||||
|
this.defaultNameSpace = defaultNameSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultPrefix() {
|
||||||
|
return this.defaultPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultNameSpace() {
|
||||||
|
return this.defaultNameSpace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,162 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class O2ImgLayerMngr {
|
||||||
|
public static void initLayers() {
|
||||||
|
try {
|
||||||
|
File dir = ServerContext.getPluginsFolder();
|
||||||
|
String fileName = String.valueOf(ServerContext.getMap().getName()) + LayerFactory.LayerType.O2IMG.getPrefix();
|
||||||
|
File confFile = ServerUtil.findFile((File)dir, (String)fileName);
|
||||||
|
if (confFile == null) {
|
||||||
|
LogMngr.getInstance().logError("[O2IMG]", "Skip create O2ImgLayer :: Layer Configuration File [" + confFile + "] is not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[O2IMG]", "[" + confFile.getName() + "] Now create O2ImgLayer from this configuration");
|
||||||
|
ArrayList<O2LayerInfo> layerInfoList = O2ImgLayerMngr.parseO2ImgLayer(confFile);
|
||||||
|
if (layerInfoList == null || layerInfoList.isEmpty()) {
|
||||||
|
LogMngr.getInstance().logError("[O2IMG]", "[" + confFile.getName() + "] Fail to create O2ImgLayer :: O2ImgLayer size is ZERO[0] from this configuration");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (O2LayerInfo info : layerInfoList) {
|
||||||
|
LogMngr.getInstance().logDebug("[O2IMG]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Now create this O2ImgLayer");
|
||||||
|
try {
|
||||||
|
O2ImgLayerMngr.addLayer(info.getLayerPath(), info.getLayerName(), info.getLayerCRS(), info.getDesc());
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Success :: " + "[Map:" + ServerContext.getMap().getName() + "/Layer:" + info.getLayerName() + "] : " + "[RefServer:" + LayerFactory.LayerType.O2IMG.getType() + "/RefSource:" + info.getLayerPath() + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2IMG]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Fail :: " + e);
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[O2IMG]", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2IMG]", "Create O2ImgLayer Fail :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArrayList<O2LayerInfo> parseO2ImgLayer(File conf) {
|
||||||
|
if (!conf.exists()) {
|
||||||
|
LogMngr.getInstance().logError("[O2IMG]", "[" + conf.getName() + "] Create O2ImgLayer Fail :: O2ImgLayer configuration is not exist");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArrayList<O2LayerInfo> layerInfoList = new ArrayList<O2LayerInfo>();
|
||||||
|
O2LayerInfo lInfo = null;
|
||||||
|
BufferedReader bReader = null;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
String line;
|
||||||
|
bReader = new BufferedReader(new FileReader(conf));
|
||||||
|
while ((line = bReader.readLine()) != null) {
|
||||||
|
if ((line = line.trim()).startsWith("#") || ServerUtil.isNullString((String)line)) continue;
|
||||||
|
try {
|
||||||
|
if (line.equalsIgnoreCase("[LAYER_CONFIG]")) {
|
||||||
|
lInfo = new O2LayerInfo();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.ACTIVATE")) {
|
||||||
|
lInfo.setActivate(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.NAME")) {
|
||||||
|
lInfo.setLayerName(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.CRS")) {
|
||||||
|
lInfo.setLayerCRS(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.PATH")) {
|
||||||
|
lInfo.setLayerPath(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.DESC")) {
|
||||||
|
lInfo.setDesc(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!line.equalsIgnoreCase("[/LAYER_CONFIG]")) continue;
|
||||||
|
if (lInfo != null && lInfo.isAvailable()) {
|
||||||
|
layerInfoList.add(lInfo);
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logError("[O2IMG]", "[" + conf.getName() + "] Skip this O2ImgLayer :: Layer info is not available [" + lInfo.getLayerName() + "]");
|
||||||
|
}
|
||||||
|
lInfo = null;
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2IMG]", "[" + conf.getName() + "] O2ImgLayer configuration file is not valid :: " + e.getMessage());
|
||||||
|
try {
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e2) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return layerInfoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static O2ImgLayer addLayer(File layerPath, String layerName, CoordinateReferenceSystem crs, String desc) throws Exception {
|
||||||
|
if (layerPath == null || !layerPath.exists() || layerPath.isFile()) {
|
||||||
|
throw new IOException("O2ImgLayer levelset is not exist [" + layerPath.getAbsolutePath() + "]");
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)layerName)) {
|
||||||
|
throw new IOException("O2ImgLayer LayerName is null");
|
||||||
|
}
|
||||||
|
if (crs == null) {
|
||||||
|
throw new IOException("O2ImgLayer LayerCRS is null");
|
||||||
|
}
|
||||||
|
O2LayerLevelSet lvlSet = O2LayerUtil.createLevelSet((LayerFactory.LayerType)LayerFactory.LayerType.O2IMG, (File)layerPath);
|
||||||
|
AVList params = new AVList();
|
||||||
|
params.setValue("conf.service.map.name", (Object)ServerContext.getMap().getName());
|
||||||
|
params.setValue("conf.service.layer.name", (Object)layerName);
|
||||||
|
params.setValue("conf.service.ref.server", (Object)LayerFactory.LayerType.O2IMG.getType());
|
||||||
|
params.setValue("conf.service.ref.source", (Object)layerPath.getParent());
|
||||||
|
params.setValue("conf.service.ref.crs", (Object)crs);
|
||||||
|
params.setValue("conf.service.sld", null);
|
||||||
|
params.setValue("conf.service.use.cache", (Object)false);
|
||||||
|
params.setValue("conf.service.last.update", null);
|
||||||
|
params.setValue("conf.service.description", (Object)desc);
|
||||||
|
params.setValue("o2layer.conf.level.set", (Object)lvlSet);
|
||||||
|
Layer layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.O2IMG, (AVList)params);
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||||
|
return (O2ImgLayer)layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void reloadLayer() throws Exception {
|
||||||
|
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.O2IMG);
|
||||||
|
try {
|
||||||
|
O2ImgLayerMngr.initLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[O2IMG]", "Success to reload O2ImgLayers.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[O2IMG]", "Fail to reload O2ImgLayers. Now use previous O2ImgLayers :: " + e);
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayers(oldLayers, false);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class O2LayerInfo {
|
||||||
|
private String layerName;
|
||||||
|
private boolean activate = false;
|
||||||
|
private CoordinateReferenceSystem layerCRS;
|
||||||
|
private File layerPath;
|
||||||
|
private String desc;
|
||||||
|
private Float minData = null;
|
||||||
|
private Float maxData = null;
|
||||||
|
private Float noData = null;
|
||||||
|
|
||||||
|
public String getLayerName() {
|
||||||
|
return this.layerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActivate() {
|
||||||
|
return this.activate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem getLayerCRS() {
|
||||||
|
return this.layerCRS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getLayerPath() {
|
||||||
|
return this.layerPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerName(String name) {
|
||||||
|
if (ServerUtil.isNullString((String)name)) {
|
||||||
|
this.layerName = null;
|
||||||
|
}
|
||||||
|
this.layerName = name.trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return this.desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivate(String actiStr) {
|
||||||
|
this.activate = ServerUtil.getBooleanValue((String)actiStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerCRS(String crsName) {
|
||||||
|
this.layerCRS = CRSMngr.getCRS((String)crsName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerPath(String path) {
|
||||||
|
if (ServerUtil.isNullString((String)path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file = new File(path.trim());
|
||||||
|
if (file.exists()) {
|
||||||
|
this.layerPath = file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.layerPath = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String desc) {
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinData(String min) {
|
||||||
|
try {
|
||||||
|
this.minData = Float.valueOf(min);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.minData = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxData(String max) {
|
||||||
|
try {
|
||||||
|
this.maxData = Float.valueOf(max);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.maxData = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNoData(String no) {
|
||||||
|
try {
|
||||||
|
this.noData = Float.valueOf(no);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.noData = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getMinData() {
|
||||||
|
return this.minData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getMaxData() {
|
||||||
|
return this.maxData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getNoData() {
|
||||||
|
return this.noData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAvailable() {
|
||||||
|
if (!this.activate) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.activate] is False");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)this.layerName)) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.name] is Empty");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.layerPath == null) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.path] is not exist");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.layerCRS == null) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.crs] is not available");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -379,7 +379,7 @@ public class O2WpsLayerSet
|
||||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type)
|
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
ArrayList layers = getLayers(type);
|
ArrayList<Layer> layers = getLayers(type);
|
||||||
|
|
||||||
for (Layer layer : layers) {
|
for (Layer layer : layers) {
|
||||||
this.layerStore.remove(layer.getName());
|
this.layerStore.remove(layer.getName());
|
||||||
|
|
@ -398,7 +398,7 @@ public class O2WpsLayerSet
|
||||||
|
|
||||||
ArrayList resultList = new ArrayList();
|
ArrayList resultList = new ArrayList();
|
||||||
|
|
||||||
ArrayList layers = getLayers(type);
|
ArrayList<Layer> layers = getLayers(type);
|
||||||
|
|
||||||
for (Layer layer : layers) {
|
for (Layer layer : layers) {
|
||||||
if (layer.getServerName().equalsIgnoreCase(serverName)) {
|
if (layer.getServerName().equalsIgnoreCase(serverName)) {
|
||||||
|
|
@ -424,7 +424,7 @@ public class O2WpsLayerSet
|
||||||
|
|
||||||
ArrayList resultList = new ArrayList();
|
ArrayList resultList = new ArrayList();
|
||||||
|
|
||||||
ArrayList layers = getLayers(type);
|
ArrayList<Layer> layers = getLayers(type);
|
||||||
|
|
||||||
for (Layer layer : layers) {
|
for (Layer layer : layers) {
|
||||||
if ((layer.getServerName().equalsIgnoreCase(serverName)) &&
|
if ((layer.getServerName().equalsIgnoreCase(serverName)) &&
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OWSConstants
|
||||||
|
{
|
||||||
|
public static final List<String> wfsRequests = Arrays.asList(new String[] { "GetCapabilities", "DescribeFeatureType", "GetFeature", "GetGmlObject", "Transaction", "LockFeature" });
|
||||||
|
public static final List<String> wfsRequests100 = Arrays.asList(new String[] { "GetCapabilities", "DescribeFeatureType", "GetFeature", "Transaction", "LockFeature" });
|
||||||
|
public static final List<String> wmsRequests = Arrays.asList(new String[] { "GetCapabilities", "GetFeatureInfo", "GetMap", "GetLegendGraphic" });
|
||||||
|
public static final List<String> wcsRequests = Arrays.asList(new String[] { "GetCapabilities", "DescribeCoverage", "GetCoverage" });
|
||||||
|
public static final List<String> wpsRequests = Arrays.asList(new String[] { "GetCapabilities", "DescribeProcess", "Execute" });
|
||||||
|
public static final List<String> wmtsRequests = Arrays.asList(new String[] { "GetCapabilities", "GetTile" });
|
||||||
|
|
||||||
|
public static final List<String> wfsVersions = Arrays.asList(new String[] { "1.1.0", "1.0.0" });
|
||||||
|
public static final List<String> wmsVersions = Arrays.asList(new String[] { "1.3.0" });
|
||||||
|
public static final List<String> wcsVersions = Arrays.asList(new String[] { "1.0.0" });
|
||||||
|
public static final List<String> wpsVersions = Arrays.asList(new String[] { "1.0.0" });
|
||||||
|
public static final List<String> wmtsVersions = Arrays.asList(new String[] { "1.0.0" });
|
||||||
|
|
||||||
|
public static final List<String> outputFormat = Arrays.asList(new String[] { "text/xml", "text/xml; subtype=gml/2.1.2", "text/xml; subtype=gml/3.1.1", "application/json" });
|
||||||
|
public static final List<String> outputFormat100 = Arrays.asList(new String[] { "XMLSCHEMA", "GML2", "GML3", "application/json" });
|
||||||
|
public static final List<String> featureInfooutputFormat = Arrays.asList(new String[] { "text/xml", "application/vnd.ogc.gml", "application/vnd.ogc.gml/3.1.1", "application/json" });
|
||||||
|
public static final List<String> imageOutputFormat = Arrays.asList(new String[] { "image/png", "image/jpeg", "image/jpg" });
|
||||||
|
public static final List<String> wmtsOutputFormat = Arrays.asList(new String[] { "image/png", "image/jpeg", "image/jpg" });
|
||||||
|
public static final List<String> wcsFormats = Arrays.asList(new String[] { "GeoTIFF", "O2FGRID", "O2IGRID" });
|
||||||
|
public static final String wfsDefaultVersion = "1.1.0";
|
||||||
|
public static final String wfsDefaultOutputformat = "text/xml; subtype=gml/3.1.1";
|
||||||
|
public static final String wfsDefaultOutputformatGetFeature100 = "GML2";
|
||||||
|
public static final String wfsDefaultOutputformatDescribeFeatureType100 = "XMLSCHEMA";
|
||||||
|
public static final int wfsLockFeatureDefaultExpiry = 5;
|
||||||
|
public static final String wmsDefaultVersion = "1.3.0";
|
||||||
|
public static final String wmsGetMapDefaultTransparent = "false";
|
||||||
|
public static final String wmsGetMapDefaultBGcolor = "0xFFFFFF";
|
||||||
|
public static final String wmsGetLegendGraphicDefaultWidth = "20";
|
||||||
|
public static final String wmsGetLegendGraphicDefaultHeight = "20";
|
||||||
|
public static final String wpsDefaultVersion = "1.0.0";
|
||||||
|
public static final String wmtsDefaultVersion = "1.0.0";
|
||||||
|
public static final String wcsDefaultVersion = "1.0.0";
|
||||||
|
public static final List<String> wpsProcessList = Arrays.asList(new String[] { "Buffer", "Contains", "Intersection", "Intersects" });
|
||||||
|
public static final List<String> upisProcessList = Arrays.asList(new String[] { "Sync", "VA_Export", "VA_AreaNCount" });
|
||||||
|
public static String wpsRepositoryDir = null;
|
||||||
|
|
||||||
|
public static boolean isContains(List<String> list, String target)
|
||||||
|
{
|
||||||
|
Iterator itr = list.iterator();
|
||||||
|
while (itr.hasNext())
|
||||||
|
{
|
||||||
|
String listEle = (String)itr.next();
|
||||||
|
if (listEle.equalsIgnoreCase(target)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,8 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
import org.xml.sax.helpers.NamespaceSupport;
|
import org.xml.sax.helpers.NamespaceSupport;
|
||||||
|
|
||||||
public class OWSServiceException extends Exception
|
public class OWSServiceException extends Exception
|
||||||
|
|
@ -76,7 +78,7 @@ public class OWSServiceException extends Exception
|
||||||
|
|
||||||
doc.appendChild(rootElement);
|
doc.appendChild(rootElement);
|
||||||
|
|
||||||
Element serviceExceptionElement = doc.createElementNS(support.getURI("ogc"), "ServiceException");
|
org.w3c.dom.Element serviceExceptionElement = doc.createElementNS(support.getURI("ogc"), "ServiceException");
|
||||||
|
|
||||||
if (this.exceptionCode != null) {
|
if (this.exceptionCode != null) {
|
||||||
serviceExceptionElement.setAttribute("code", this.exceptionCode);
|
serviceExceptionElement.setAttribute("code", this.exceptionCode);
|
||||||
|
|
@ -86,7 +88,7 @@ public class OWSServiceException extends Exception
|
||||||
serviceExceptionElement.setAttribute("locator", this.locator);
|
serviceExceptionElement.setAttribute("locator", this.locator);
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceExceptionElement.setTextContent(getMessage());
|
setElementTextContent(serviceExceptionElement,getMessage());
|
||||||
|
|
||||||
rootElement.appendChild(serviceExceptionElement);
|
rootElement.appendChild(serviceExceptionElement);
|
||||||
|
|
||||||
|
|
@ -97,5 +99,18 @@ public class OWSServiceException extends Exception
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Added by thkim
|
||||||
|
public static void setElementTextContent(Element element, String text) {
|
||||||
|
// 기존 자식 노드들을 모두 제거
|
||||||
|
Node child;
|
||||||
|
while ((child = element.getFirstChild()) != null) {
|
||||||
|
element.removeChild(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 새로운 텍스트 노드 생성 및 추가
|
||||||
|
Text textNode = element.getOwnerDocument().createTextNode(text);
|
||||||
|
element.appendChild(textNode);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,6 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import oracle.jdbc.OracleConnection;
|
import oracle.jdbc.OracleConnection;
|
||||||
import oracle.sql.STRUCT;
|
import oracle.sql.STRUCT;
|
||||||
import org.geotools.data.jdbc.datasource.DataSourceFinder;
|
import org.geotools.data.jdbc.datasource.DataSourceFinder;
|
||||||
|
|
@ -37,418 +36,313 @@ import org.geotools.jdbc.PreparedStatementSQLDialect;
|
||||||
import org.opengis.feature.simple.SimpleFeatureType;
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
import org.opengis.feature.type.AttributeDescriptor;
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
import org.opengis.feature.type.GeometryDescriptor;
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
import org.opengis.feature.type.GeometryType;
|
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
public class OracleDialect extends PreparedStatementSQLDialect
|
public class OracleDialect extends PreparedStatementSQLDialect implements O2SqlDialect {
|
||||||
implements O2SqlDialect
|
|
||||||
{
|
|
||||||
public final String ORACLE_NULL_SRID_KEY = "OracleNullSrid";
|
public final String ORACLE_NULL_SRID_KEY = "OracleNullSrid";
|
||||||
|
|
||||||
final String serverName;
|
final String serverName;
|
||||||
|
|
||||||
final Integer DEFAULT_CRS = Integer.valueOf(4326);
|
final Integer DEFAULT_CRS = Integer.valueOf(4326);
|
||||||
|
|
||||||
private HashMap<String, Integer> sridStore = new HashMap();
|
private HashMap<String, Integer> sridStore = new HashMap<String, Integer>();
|
||||||
|
|
||||||
UnWrapper uw;
|
UnWrapper uw;
|
||||||
|
|
||||||
public OracleDialect(String name, JDBCDataStore dataStore)
|
public OracleDialect(String name, JDBCDataStore dataStore) {
|
||||||
{
|
|
||||||
super(dataStore);
|
super(dataStore);
|
||||||
this.serverName = name;
|
this.serverName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> getMapping(ResultSet columnMetaData, Connection cx)
|
public Class<?> getMapping(ResultSet columnMetaData, Connection cx) throws SQLException {
|
||||||
throws SQLException
|
|
||||||
{
|
|
||||||
int TABLE_NAME = 3;
|
int TABLE_NAME = 3;
|
||||||
int COLUMN_NAME = 4;
|
int COLUMN_NAME = 4;
|
||||||
int TYPE_NAME = 6;
|
int TYPE_NAME = 6;
|
||||||
|
|
||||||
String typeName = columnMetaData.getString(6).toUpperCase();
|
String typeName = columnMetaData.getString(6).toUpperCase();
|
||||||
|
if (typeName.equals("SDO_GEOMETRY")) {
|
||||||
if (typeName.equals("SDO_GEOMETRY"))
|
Class<Geometry> gemetry = lookupGeometryType(columnMetaData, cx);
|
||||||
{
|
if (gemetry == null)
|
||||||
Class gemetry = lookupGeometryType(columnMetaData, cx);
|
gemetry = Geometry.class;
|
||||||
|
|
||||||
if (gemetry == null) {
|
|
||||||
gemetry = Geometry.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gemetry;
|
return gemetry;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Class lookupGeometryType(ResultSet columnMetaData, Connection cx)
|
private Class lookupGeometryType(ResultSet columnMetaData, Connection cx) throws SQLException {
|
||||||
throws SQLException
|
|
||||||
{
|
|
||||||
String schemaName = columnMetaData.getString("TABLE_SCHEM");
|
String schemaName = columnMetaData.getString("TABLE_SCHEM");
|
||||||
String tableName = columnMetaData.getString("TABLE_NAME");
|
String tableName = columnMetaData.getString("TABLE_NAME");
|
||||||
String columnName = columnMetaData.getString("COLUMN_NAME");
|
String columnName = columnMetaData.getString("COLUMN_NAME");
|
||||||
|
|
||||||
lookupDBSrid(cx, tableName, columnName);
|
lookupDBSrid(cx, tableName, columnName);
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "Lookup geometry type for [" + columnMetaData.getString("TABLE_NAME") + "]");
|
LogMngr.getInstance().logDebug("[DB]", "Lookup geometry type for [" + columnMetaData.getString("TABLE_NAME") + "]");
|
||||||
|
if (schemaName == null || schemaName.equals("")) {
|
||||||
if ((schemaName == null) || (schemaName.equals("")))
|
|
||||||
schemaName = "";
|
schemaName = "";
|
||||||
else {
|
} else {
|
||||||
schemaName = schemaName + ".";
|
schemaName = String.valueOf(schemaName) + ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
Statement stat = null;
|
Statement stat = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
stat = cx.createStatement();
|
stat = cx.createStatement();
|
||||||
stat.setFetchSize(1);
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
StringBuffer sql = new StringBuffer();
|
StringBuffer sql = new StringBuffer();
|
||||||
sql.append("SELECT GEOMETRY_TYPE FROM ");
|
sql.append("SELECT GEOMETRY_TYPE FROM ");
|
||||||
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||||
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
rs = stat.executeQuery(sql.toString());
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next())
|
||||||
if ((rs != null) && (rs.next()))
|
return O2GeometryTypeMap.lookUpMeta(Integer.valueOf(rs.getInt(1)));
|
||||||
return O2GeometryTypeMap.lookUpMeta(Integer.valueOf(rs.getInt(1)));
|
} catch (Exception exception) {
|
||||||
} catch (Exception localException1) {
|
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
this.dataStore.closeSafe(rs);
|
this.dataStore.closeSafe(rs);
|
||||||
this.dataStore.closeSafe(stat);
|
this.dataStore.closeSafe(stat);
|
||||||
}
|
}
|
||||||
this.dataStore.closeSafe(rs);
|
try {
|
||||||
this.dataStore.closeSafe(stat);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
stat = cx.createStatement();
|
stat = cx.createStatement();
|
||||||
stat.setFetchSize(1);
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
StringBuffer sql = new StringBuffer();
|
StringBuffer sql = new StringBuffer();
|
||||||
sql.append("SELECT ");
|
sql.append("SELECT ");
|
||||||
sql.append(columnName);
|
sql.append(columnName);
|
||||||
sql.append(" FROM ");
|
sql.append(" FROM ");
|
||||||
sql.append(schemaName).append(tableName);
|
sql.append(schemaName).append(tableName);
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
rs = stat.executeQuery(sql.toString());
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
if ((rs != null) && (rs.next())) {
|
|
||||||
STRUCT st = (STRUCT)rs.getObject(1);
|
STRUCT st = (STRUCT)rs.getObject(1);
|
||||||
Geometry geom = getGeometryFromStruct(st, null, cx);
|
Geometry geom = getGeometryFromStruct(st, (GeometryFactory)null, cx);
|
||||||
|
|
||||||
return O2GeometryTypeMap.lookUpGeometry(geom.getGeometryType());
|
return O2GeometryTypeMap.lookUpGeometry(geom.getGeometryType());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.dataStore.closeSafe(rs);
|
this.dataStore.closeSafe(rs);
|
||||||
this.dataStore.closeSafe(stat);
|
this.dataStore.closeSafe(stat);
|
||||||
}
|
}
|
||||||
this.dataStore.closeSafe(rs);
|
|
||||||
this.dataStore.closeSafe(stat);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSqlTypeNameToClassMappings(Map<String, Class<?>> mappings)
|
public void registerSqlTypeNameToClassMappings(Map<String, Class<?>> mappings) {
|
||||||
{
|
|
||||||
super.registerSqlTypeNameToClassMappings(mappings);
|
super.registerSqlTypeNameToClassMappings(mappings);
|
||||||
|
|
||||||
mappings.put("SDO_GEOMETRY", Geometry.class);
|
mappings.put("SDO_GEOMETRY", Geometry.class);
|
||||||
mappings.put("MDSYS.SDO_GEOMETRY", Geometry.class);
|
mappings.put("MDSYS.SDO_GEOMETRY", Geometry.class);
|
||||||
|
|
||||||
mappings.put("CHAR", String.class);
|
mappings.put("CHAR", String.class);
|
||||||
mappings.put("NCHAR", String.class);
|
mappings.put("NCHAR", String.class);
|
||||||
mappings.put("NVARCHAR", String.class);
|
mappings.put("NVARCHAR", String.class);
|
||||||
mappings.put("NVARCHAR2", String.class);
|
mappings.put("NVARCHAR2", String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSqlTypeToClassMappings(Map<Integer, Class<?>> mappings)
|
public void registerSqlTypeToClassMappings(Map<Integer, Class<?>> mappings) {
|
||||||
{
|
|
||||||
super.registerSqlTypeToClassMappings(mappings);
|
super.registerSqlTypeToClassMappings(mappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lookupDBSrid(Connection cx, String tableName, String columnName)
|
private void lookupDBSrid(Connection cx, String tableName, String columnName) {
|
||||||
{
|
|
||||||
LogMngr.getInstance().logDebug("[DB]",
|
LogMngr.getInstance().logDebug("[DB]",
|
||||||
"Lookup dbms srid value for [" + tableName + "/" + columnName + "]");
|
"Lookup dbms srid value for [" + tableName + "/" + columnName + "]");
|
||||||
|
String sridKey = String.valueOf(tableName.trim().toUpperCase()) + "_" + columnName.trim().toUpperCase();
|
||||||
String sridKey = tableName.trim().toUpperCase() + "_" + columnName.trim().toUpperCase();
|
if (this.sridStore.get(sridKey) != null)
|
||||||
|
return;
|
||||||
if (this.sridStore.get(sridKey) != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement stat = null;
|
Statement stat = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
stat = cx.createStatement();
|
stat = cx.createStatement();
|
||||||
|
|
||||||
StringBuffer sql = new StringBuffer();
|
StringBuffer sql = new StringBuffer();
|
||||||
sql.append("SELECT SRID FROM USER_SDO_GEOM_METADATA");
|
sql.append("SELECT SRID FROM USER_SDO_GEOM_METADATA");
|
||||||
sql.append(" WHERE TABLE_NAME = '").append(tableName).append("'");
|
sql.append(" WHERE TABLE_NAME = '").append(tableName).append("'");
|
||||||
sql.append(" AND COLUMN_NAME = '").append(columnName).append("'");
|
sql.append(" AND COLUMN_NAME = '").append(columnName).append("'");
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
rs = stat.executeQuery(sql.toString());
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
if ((rs != null) && (rs.next())) {
|
|
||||||
Integer srid = Integer.valueOf(rs.getInt(1));
|
Integer srid = Integer.valueOf(rs.getInt(1));
|
||||||
this.sridStore.put(sridKey, srid);
|
this.sridStore.put(sridKey, srid);
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logError("[DB]",
|
LogMngr.getInstance().logError("[DB]",
|
||||||
"Fail to lookup dbms srid value for [" + tableName + "/" + columnName + "] :: " + e);
|
"Fail to lookup dbms srid value for [" + tableName + "/" + columnName + "] :: " + e);
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
this.dataStore.closeSafe(rs);
|
this.dataStore.closeSafe(rs);
|
||||||
this.dataStore.closeSafe(stat);
|
this.dataStore.closeSafe(stat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDBSrid(String tableName, String columnName)
|
public Integer getDBSrid(String tableName, String columnName) {
|
||||||
{
|
String sridKey = String.valueOf(tableName.trim().toUpperCase()) + "_" + columnName.trim().toUpperCase();
|
||||||
String sridKey = tableName.trim().toUpperCase() + "_" + columnName.trim().toUpperCase();
|
return this.sridStore.get(sridKey);
|
||||||
return (Integer)this.sridStore.get(sridKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Geometry getGeometryFromStruct(STRUCT struct, GeometryFactory factory, Connection cx)
|
private Geometry getGeometryFromStruct(STRUCT struct, GeometryFactory factory, Connection cx) throws SQLException {
|
||||||
throws SQLException
|
if (struct == null)
|
||||||
{
|
return null;
|
||||||
if (struct == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
OracleConnection ocx = unwrapConnection(cx);
|
OracleConnection ocx = unwrapConnection(cx);
|
||||||
GeometryConverter converter =
|
GeometryConverter converter =
|
||||||
factory != null ? new GeometryConverter(ocx, factory) : new GeometryConverter(ocx);
|
(factory != null) ? new GeometryConverter(ocx, factory) : new GeometryConverter(ocx);
|
||||||
|
|
||||||
return converter.asGeometry(struct);
|
return converter.asGeometry(struct);
|
||||||
}
|
}
|
||||||
|
|
||||||
private STRUCT getStructFromGeometry(Geometry geometry, int srid, Connection cx) throws SQLException {
|
private STRUCT getStructFromGeometry(Geometry geometry, int srid, Connection cx) throws SQLException {
|
||||||
if (geometry == null) {
|
if (geometry == null)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
OracleConnection ocx = unwrapConnection(cx);
|
OracleConnection ocx = unwrapConnection(cx);
|
||||||
GeometryConverter converter = new GeometryConverter(ocx);
|
GeometryConverter converter = new GeometryConverter(ocx);
|
||||||
|
|
||||||
return converter.toSDO(geometry, srid);
|
return converter.toSDO(geometry, srid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getDimensionsFromGeometry(Geometry geom)
|
private int getDimensionsFromGeometry(Geometry geom) {
|
||||||
{
|
|
||||||
if (geom != null) {
|
if (geom != null) {
|
||||||
Coordinate coord = geom.getCoordinate();
|
Coordinate coord = geom.getCoordinate();
|
||||||
if (coord != null) {
|
if (coord != null) {
|
||||||
if (Double.isNaN(coord.x))
|
if (Double.isNaN(coord.x))
|
||||||
return 0;
|
return 0;
|
||||||
if (Double.isNaN(coord.y))
|
if (Double.isNaN(coord.y))
|
||||||
return 1;
|
return 1;
|
||||||
if (Double.isNaN(coord.z)) {
|
if (Double.isNaN(coord.z))
|
||||||
return 2;
|
return 2;
|
||||||
}
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OracleConnection unwrapConnection(Connection cx) throws SQLException
|
private OracleConnection unwrapConnection(Connection cx) throws SQLException {
|
||||||
{
|
if (cx == null)
|
||||||
if (cx == null) {
|
return null;
|
||||||
return null;
|
if (cx instanceof OracleConnection)
|
||||||
}
|
return (OracleConnection)cx;
|
||||||
if ((cx instanceof OracleConnection)) {
|
try {
|
||||||
return (OracleConnection)cx;
|
if (cx instanceof Wrapper && this.uw != null)
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (((cx instanceof Wrapper)) && (this.uw != null)) {
|
|
||||||
try {
|
try {
|
||||||
Wrapper w = cx;
|
Wrapper w = cx;
|
||||||
if (w.isWrapperFor(OracleConnection.class))
|
if (w.isWrapperFor(OracleConnection.class))
|
||||||
return (OracleConnection)w.unwrap(OracleConnection.class);
|
return w.<OracleConnection>unwrap(OracleConnection.class);
|
||||||
}
|
} catch (Throwable t) {
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.FINE, "Failed to unwrap connection using java 6 facilities", t);
|
LOGGER.log(Level.FINE, "Failed to unwrap connection using java 6 facilities", t);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (this.uw == null)
|
if (this.uw == null)
|
||||||
this.uw = DataSourceFinder.getUnWrapper(cx);
|
this.uw = DataSourceFinder.getUnWrapper(cx);
|
||||||
if (this.uw != null) {
|
if (this.uw != null) {
|
||||||
Connection uwcx = this.uw.unwrap(cx);
|
Connection uwcx = this.uw.unwrap(cx);
|
||||||
if ((uwcx != null) && ((uwcx instanceof OracleConnection)))
|
if (uwcx != null && uwcx instanceof OracleConnection)
|
||||||
return (OracleConnection)uwcx;
|
return (OracleConnection)uwcx;
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
throw (SQLException)(new SQLException(
|
||||||
throw ((SQLException)new SQLException(
|
"Could not obtain native oracle connection.")).initCause(e);
|
||||||
"Could not obtain native oracle connection.").initCause(e));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw new SQLException("Could not obtain native oracle connection for " + cx.getClass());
|
throw new SQLException("Could not obtain native oracle connection for " + cx.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Geometry convertGeometry(Geometry geom, GeometryDescriptor descriptor, GeometryFactory factory)
|
private Geometry convertGeometry(Geometry geom, GeometryDescriptor descriptor, GeometryFactory factory) {
|
||||||
{
|
if (geom == null)
|
||||||
if (geom == null) {
|
return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class targetClazz = descriptor.getType().getBinding();
|
Class targetClazz = descriptor.getType().getBinding();
|
||||||
|
if (targetClazz.equals(MultiPolygon.class) && geom instanceof Polygon)
|
||||||
if ((targetClazz.equals(MultiPolygon.class)) && ((geom instanceof Polygon))) {
|
return (Geometry)factory.createMultiPolygon(new Polygon[] { (Polygon)geom });
|
||||||
return factory.createMultiPolygon(new Polygon[] { (Polygon)geom });
|
if (targetClazz.equals(MultiPoint.class) && geom instanceof Point)
|
||||||
}
|
return (Geometry)factory.createMultiPoint(new Point[] { (Point)geom });
|
||||||
if ((targetClazz.equals(MultiPoint.class)) && ((geom instanceof Point))) {
|
if (targetClazz.equals(MultiLineString.class) && geom instanceof LineString)
|
||||||
return factory.createMultiPoint(new Point[] { (Point)geom });
|
return (Geometry)factory.createMultiLineString(new LineString[] { (LineString)geom });
|
||||||
}
|
if (targetClazz.equals(GeometryCollection.class))
|
||||||
if ((targetClazz.equals(MultiLineString.class)) && ((geom instanceof LineString))) {
|
return (Geometry)factory.createGeometryCollection(new Geometry[] { geom });
|
||||||
return factory.createMultiLineString(new LineString[] { (LineString)geom });
|
|
||||||
}
|
|
||||||
if (targetClazz.equals(GeometryCollection.class)) {
|
|
||||||
return factory.createGeometryCollection(new Geometry[] { geom });
|
|
||||||
}
|
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getGeometrySRID(String schemaName, String tableName, String columnName, Connection cx)
|
public Integer getGeometrySRID(String schemaName, String tableName, String columnName, Connection cx) throws SQLException {
|
||||||
throws SQLException
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "Get Geometry SRID value for [" + tableName.toUpperCase() + "]");
|
LogMngr.getInstance().logDebug("[DB]", "Get Geometry SRID value for [" + tableName.toUpperCase() + "]");
|
||||||
|
if (schemaName == null || schemaName.equals("")) {
|
||||||
if ((schemaName == null) || (schemaName.equals("")))
|
|
||||||
schemaName = "";
|
schemaName = "";
|
||||||
else {
|
} else {
|
||||||
schemaName = schemaName + ".";
|
schemaName = String.valueOf(schemaName) + ".";
|
||||||
}
|
}
|
||||||
Statement stat = null;
|
Statement stat = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Integer localInteger;
|
|
||||||
try {
|
try {
|
||||||
stat = cx.createStatement();
|
stat = cx.createStatement();
|
||||||
stat.setFetchSize(1);
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append("SELECT REF_SRID FROM ");
|
sb.append("SELECT REF_SRID FROM ");
|
||||||
sb.append(schemaName).append("O2MAP_SERVICE_INFO");
|
sb.append(schemaName).append("O2MAP_SERVICE_INFO");
|
||||||
sb.append(" WHERE REF_SOURCE = '").append(tableName.toUpperCase()).append("'");
|
sb.append(" WHERE REF_SOURCE = '").append(tableName.toUpperCase()).append("'");
|
||||||
sb.append(" OR REF_SOURCE = '").append(tableName.toLowerCase()).append("'");
|
sb.append(" OR REF_SOURCE = '").append(tableName.toLowerCase()).append("'");
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sb.toString());
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sb.toString());
|
||||||
rs = stat.executeQuery(sb.toString());
|
rs = stat.executeQuery(sb.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
if ((rs != null) && (rs.next())) {
|
|
||||||
Object obj = rs.getObject(1);
|
Object obj = rs.getObject(1);
|
||||||
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2MAP_SERVICE_INFO for [" +
|
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2MAP_SERVICE_INFO for [" +
|
||||||
tableName.toUpperCase() + "] :: " + e.getMessage());
|
tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
this.dataStore.closeSafe(rs);
|
this.dataStore.closeSafe(rs);
|
||||||
this.dataStore.closeSafe(stat);
|
this.dataStore.closeSafe(stat);
|
||||||
}
|
}
|
||||||
this.dataStore.closeSafe(rs);
|
try {
|
||||||
this.dataStore.closeSafe(stat);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
stat = cx.createStatement();
|
stat = cx.createStatement();
|
||||||
stat.setFetchSize(1);
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
StringBuffer sql = new StringBuffer();
|
StringBuffer sql = new StringBuffer();
|
||||||
sql.append("SELECT SRID FROM ");
|
sql.append("SELECT SRID FROM ");
|
||||||
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||||
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
rs = stat.executeQuery(sql.toString());
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
if ((rs != null) && (rs.next())) {
|
|
||||||
Object obj = rs.getObject(1);
|
Object obj = rs.getObject(1);
|
||||||
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2SERVER_GEOMETRY_LAYER for [" +
|
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2SERVER_GEOMETRY_LAYER for [" +
|
||||||
tableName.toUpperCase() + "] :: " + e.getMessage());
|
tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
this.dataStore.closeSafe(rs);
|
this.dataStore.closeSafe(rs);
|
||||||
this.dataStore.closeSafe(stat);
|
this.dataStore.closeSafe(stat);
|
||||||
}
|
}
|
||||||
this.dataStore.closeSafe(rs);
|
|
||||||
this.dataStore.closeSafe(stat);
|
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "Failed to get Geometry SRID value. Now Use Default [" + this.DEFAULT_CRS + "]");
|
LogMngr.getInstance().logDebug("[DB]", "Failed to get Geometry SRID value. Now Use Default [" + this.DEFAULT_CRS + "]");
|
||||||
return this.DEFAULT_CRS;
|
return this.DEFAULT_CRS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoordinateReferenceSystem createCRS(int srid, Connection cx) throws SQLException
|
public CoordinateReferenceSystem createCRS(int srid, Connection cx) throws SQLException {
|
||||||
{
|
try {
|
||||||
try
|
return CRSMngr.getLayerCRS(srid, true);
|
||||||
{
|
} catch (Exception e) {
|
||||||
return CRSMngr.getLayerCRS(srid, true); } catch (Exception e) {
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLimitOffsetSupported()
|
public boolean isLimitOffsetSupported() {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyLimitOffset(StringBuffer sql, int limit, int offset)
|
public void applyLimitOffset(StringBuffer sql, int limit, int offset) {
|
||||||
{
|
if (offset == 0) {
|
||||||
if (offset == 0)
|
|
||||||
{
|
|
||||||
sql.insert(0, "SELECT * FROM (");
|
sql.insert(0, "SELECT * FROM (");
|
||||||
sql.append(") WHERE ROWNUM <= " + limit);
|
sql.append(") WHERE ROWNUM <= " + limit);
|
||||||
}
|
} else {
|
||||||
else
|
long max = (limit == Integer.MAX_VALUE) ? Long.MAX_VALUE : (limit + offset);
|
||||||
{
|
|
||||||
long max = limit == 2147483647 ? 9223372036854775807L : limit + offset;
|
|
||||||
sql.insert(0, "SELECT * FROM (SELECT A.*, ROWNUM RNUM FROM ( ");
|
sql.insert(0, "SELECT * FROM (SELECT A.*, ROWNUM RNUM FROM ( ");
|
||||||
sql.append(") A WHERE ROWNUM <= " + max + ")");
|
sql.append(") A WHERE ROWNUM <= " + max + ")");
|
||||||
sql.append("WHERE RNUM > " + offset);
|
sql.append("WHERE RNUM > " + offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ReferencedEnvelope> getOptimizedBounds(String schemaName, SimpleFeatureType featureType, Connection cx)
|
public List<ReferencedEnvelope> getOptimizedBounds(String schemaName, SimpleFeatureType featureType, Connection cx) throws SQLException, IOException {
|
||||||
throws SQLException, IOException
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "Make optimal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
LogMngr.getInstance().logDebug("[DB]", "Make optimal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||||
|
List<ReferencedEnvelope> resultList = new ArrayList<ReferencedEnvelope>();
|
||||||
List resultList = new ArrayList();
|
|
||||||
|
|
||||||
Statement stat = null;
|
Statement stat = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
stat = cx.createStatement();
|
stat = cx.createStatement();
|
||||||
stat.setFetchSize(1);
|
stat.setFetchSize(1);
|
||||||
|
|
||||||
String schema = "";
|
String schema = "";
|
||||||
if ((schemaName == null) || (schemaName.equals("")))
|
if (schemaName == null || schemaName.equals("")) {
|
||||||
schema = "";
|
schema = "";
|
||||||
else {
|
} else {
|
||||||
schema = schemaName + ".";
|
schema = String.valueOf(schemaName) + ".";
|
||||||
}
|
}
|
||||||
schema = schema.toUpperCase();
|
schema = schema.toUpperCase();
|
||||||
|
|
||||||
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||||
if ((att instanceof GeometryDescriptor))
|
if (att instanceof GeometryDescriptor) {
|
||||||
{
|
|
||||||
StringBuffer sql = new StringBuffer();
|
StringBuffer sql = new StringBuffer();
|
||||||
sql.append("SELECT MIN_1D, MAX_1D, MIN_2D, MAX_2D FROM ");
|
sql.append("SELECT MIN_1D, MAX_1D, MIN_2D, MAX_2D FROM ");
|
||||||
sql.append(schema).append("O2SERVER_GEOMETRY_LAYER");
|
sql.append(schema).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
|
|
@ -456,265 +350,189 @@ Statement stat = null;
|
||||||
sql.append(" TABLE_NAME = ").append("'").append(featureType.getTypeName().toUpperCase()).append("'");
|
sql.append(" TABLE_NAME = ").append("'").append(featureType.getTypeName().toUpperCase()).append("'");
|
||||||
sql.append(" AND");
|
sql.append(" AND");
|
||||||
sql.append(" COLUMN_NAME = ").append("'").append(att.getLocalName().toUpperCase()).append("'");
|
sql.append(" COLUMN_NAME = ").append("'").append(att.getLocalName().toUpperCase()).append("'");
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
rs = stat.executeQuery(sql.toString());
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
if ((rs != null) && (rs.next())) {
|
|
||||||
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||||
double x1 = rs.getDouble(1);
|
double x1 = rs.getDouble(1);
|
||||||
double x2 = rs.getDouble(2);
|
double x2 = rs.getDouble(2);
|
||||||
double y1 = rs.getDouble(3);
|
double y1 = rs.getDouble(3);
|
||||||
double y2 = rs.getDouble(4);
|
double y2 = rs.getDouble(4);
|
||||||
|
|
||||||
resultList.add(new ReferencedEnvelope(x1, x2, y1, y2, crs));
|
resultList.add(new ReferencedEnvelope(x1, x2, y1, y2, crs));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultList;
|
return resultList;
|
||||||
}
|
} catch (SQLException e) {
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
List localList1;
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Failed to make optimal bounds, falling back intenal bounds.");
|
LogMngr.getInstance().logError("[DB]", "Failed to make optimal bounds, falling back intenal bounds.");
|
||||||
return getInternalBounds(schemaName, featureType, cx);
|
return getInternalBounds(schemaName, featureType, cx);
|
||||||
} finally {
|
} finally {
|
||||||
this.dataStore.closeSafe(rs);
|
this.dataStore.closeSafe(rs);
|
||||||
this.dataStore.closeSafe(stat);
|
this.dataStore.closeSafe(stat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ReferencedEnvelope> getInternalBounds(String schemaName, SimpleFeatureType featureType, Connection cx)
|
public List<ReferencedEnvelope> getInternalBounds(String schemaName, SimpleFeatureType featureType, Connection cx) {
|
||||||
{
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "Make internal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
LogMngr.getInstance().logDebug("[DB]", "Make internal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||||
|
List<ReferencedEnvelope> resultList = new ArrayList<ReferencedEnvelope>();
|
||||||
List resultList = new ArrayList();
|
|
||||||
|
|
||||||
Statement stat = null;
|
Statement stat = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
stat = cx.createStatement();
|
stat = cx.createStatement();
|
||||||
stat.setFetchSize(1);
|
stat.setFetchSize(1);
|
||||||
|
if (schemaName == null || schemaName.equals("")) {
|
||||||
if ((schemaName == null) || (schemaName.equals("")))
|
|
||||||
schemaName = "";
|
schemaName = "";
|
||||||
else {
|
} else {
|
||||||
schemaName = schemaName + ".";
|
schemaName = String.valueOf(schemaName) + ".";
|
||||||
}
|
}
|
||||||
schemaName = schemaName.toUpperCase();
|
schemaName = schemaName.toUpperCase();
|
||||||
|
|
||||||
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||||
if ((att instanceof GeometryDescriptor))
|
if (att instanceof GeometryDescriptor) {
|
||||||
{
|
|
||||||
StringBuffer sql = new StringBuffer();
|
StringBuffer sql = new StringBuffer();
|
||||||
sql.append("SELECT ");
|
sql.append("SELECT ");
|
||||||
|
encodeGeometryEnvelope((String)null, att.getLocalName().toUpperCase(), sql);
|
||||||
encodeGeometryEnvelope(null, att.getLocalName().toUpperCase(), sql);
|
|
||||||
|
|
||||||
sql.append(" FROM ");
|
sql.append(" FROM ");
|
||||||
sql.append(schemaName).append(featureType.getTypeName().toUpperCase());
|
sql.append(schemaName).append(featureType.getTypeName().toUpperCase());
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
rs = stat.executeQuery(sql.toString());
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
if ((rs != null) && (rs.next())) {
|
|
||||||
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||||
Envelope env = decodeGeometryEnvelope(rs, 1, cx);
|
Envelope env = decodeGeometryEnvelope(rs, 1, cx);
|
||||||
resultList.add(ReferencedEnvelope.create(env, crs));
|
resultList.add(ReferencedEnvelope.create(env, crs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return resultList;
|
return resultList;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[DB]", "Failed to make intenal bounds, falling back on envelope aggregation.");
|
LogMngr.getInstance().logError("[DB]", "Failed to make intenal bounds, falling back on envelope aggregation.");
|
||||||
} finally {
|
} finally {
|
||||||
this.dataStore.closeSafe(rs);
|
this.dataStore.closeSafe(rs);
|
||||||
this.dataStore.closeSafe(stat);
|
this.dataStore.closeSafe(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encodeGeometryEnvelope(String tableName, String geometryColumn, StringBuffer sql)
|
public void encodeGeometryEnvelope(String tableName, String geometryColumn, StringBuffer sql) {
|
||||||
{
|
|
||||||
sql.append("SDO_AGGR_MBR(");
|
sql.append("SDO_AGGR_MBR(");
|
||||||
encodeColumnName(null, geometryColumn, sql);
|
encodeColumnName((String)null, geometryColumn, sql);
|
||||||
sql.append(")");
|
sql.append(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx)
|
public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx) throws SQLException, IOException {
|
||||||
throws SQLException, IOException
|
try {
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
STRUCT st = (STRUCT)rs.getObject(column);
|
STRUCT st = (STRUCT)rs.getObject(column);
|
||||||
Geometry geom = getGeometryFromStruct(st, null, cx);
|
Geometry geom = getGeometryFromStruct(st, (GeometryFactory)null, cx);
|
||||||
|
|
||||||
return geom.getEnvelopeInternal();
|
return geom.getEnvelopeInternal();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogMngr.getInstance().logError("[DB]", "Fail to decode GeometryEnvelope : " + e.getMessage());
|
LogMngr.getInstance().logError("[DB]", "Fail to decode GeometryEnvelope : " + e.getMessage());
|
||||||
}
|
return new Envelope();
|
||||||
|
}
|
||||||
return new Envelope();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prepareGeometryValue(Geometry g, int dimension, int srid, Class binding, StringBuffer sql)
|
public void prepareGeometryValue(Geometry g, int dimension, int srid, Class binding, StringBuffer sql) {
|
||||||
{
|
|
||||||
super.prepareGeometryValue(g, dimension, srid, binding, sql);
|
super.prepareGeometryValue(g, dimension, srid, binding, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column)
|
public void setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column) throws SQLException {
|
||||||
throws SQLException
|
|
||||||
{
|
|
||||||
if (g != null) {
|
if (g != null) {
|
||||||
if ((g instanceof LinearRing))
|
LineString lineString = null;
|
||||||
{
|
if (g instanceof LinearRing)
|
||||||
g = g.getFactory().createLineString(((LinearRing)g).getCoordinateSequence());
|
lineString = g.getFactory().createLineString(((LinearRing)g).getCoordinateSequence());
|
||||||
}
|
if (isNullSridGeometry((Geometry)lineString))
|
||||||
|
srid = 0;
|
||||||
if (isNullSridGeometry(g)) {
|
STRUCT struct = getStructFromGeometry((Geometry)lineString, srid, ps.getConnection());
|
||||||
srid = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
STRUCT struct = getStructFromGeometry(g, srid, ps.getConnection());
|
|
||||||
ps.setObject(column, struct);
|
ps.setObject(column, struct);
|
||||||
} else {
|
} else {
|
||||||
ps.setNull(column, 2002, "MDSYS.SDO_GEOMETRY");
|
ps.setNull(column, 2002, "MDSYS.SDO_GEOMETRY");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNullSridGeometry(Geometry g)
|
private boolean isNullSridGeometry(Geometry g) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
String userData = (String)g.getUserData();
|
String userData = (String)g.getUserData();
|
||||||
|
if (userData.equalsIgnoreCase("OracleNullSrid"))
|
||||||
if (userData.equalsIgnoreCase("OracleNullSrid")) {
|
return true;
|
||||||
return true;
|
} catch (Exception exception) {}
|
||||||
}
|
for (int i = 0; i < g.getNumGeometries(); i++) {
|
||||||
}
|
Geometry innerGeom = g.getGeometryN(i);
|
||||||
catch (Exception localException)
|
try {
|
||||||
{
|
String userData = (String)innerGeom.getUserData();
|
||||||
for (int i = 0; i < g.getNumGeometries(); i++)
|
if (userData.equalsIgnoreCase("OracleNullSrid"))
|
||||||
{
|
return true;
|
||||||
Geometry innerGeom = g.getGeometryN(i);
|
} catch (Exception exception) {}
|
||||||
try
|
}
|
||||||
{
|
|
||||||
String userData = (String)innerGeom.getUserData();
|
|
||||||
|
|
||||||
if (userData.equalsIgnoreCase("OracleNullSrid")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception localException1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix, int srid, Hints hints, StringBuffer sql)
|
public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix, int srid, Hints hints, StringBuffer sql) {
|
||||||
{
|
|
||||||
String sqlStr = "";
|
String sqlStr = "";
|
||||||
|
if (prefix != null)
|
||||||
if (prefix != null) {
|
sqlStr = String.valueOf(prefix) + ".";
|
||||||
sqlStr = prefix + ".";
|
sqlStr = String.valueOf(sqlStr) + gatt.getLocalName();
|
||||||
}
|
|
||||||
|
|
||||||
sqlStr = sqlStr + gatt.getLocalName();
|
|
||||||
|
|
||||||
sql.append(sqlStr);
|
sql.append(sqlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Geometry decodeGeometryValue(GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx)
|
public Geometry decodeGeometryValue(GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx) throws IOException, SQLException {
|
||||||
throws IOException, SQLException
|
|
||||||
{
|
|
||||||
STRUCT struct = (STRUCT)rs.getObject(column);
|
STRUCT struct = (STRUCT)rs.getObject(column);
|
||||||
|
|
||||||
Geometry geom = getGeometryFromStruct(struct, factory, cx);
|
Geometry geom = getGeometryFromStruct(struct, factory, cx);
|
||||||
|
|
||||||
geom = convertGeometry(geom, descriptor, factory);
|
geom = convertGeometry(geom, descriptor, factory);
|
||||||
|
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedFilterToSQL createPreparedFilterToSQL()
|
public PreparedFilterToSQL createPreparedFilterToSQL() {
|
||||||
{
|
|
||||||
return new OracleFilterToSQL(this);
|
return new OracleFilterToSQL(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSelect(PreparedStatement select, Connection cx, SimpleFeatureType featureType)
|
public void onSelect(PreparedStatement select, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||||
throws SQLException
|
|
||||||
{
|
|
||||||
select.setFetchSize(this.dataStore.getFetchSize());
|
select.setFetchSize(this.dataStore.getFetchSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDelete(PreparedStatement delete, Connection cx, SimpleFeatureType featureType) throws SQLException
|
public void onDelete(PreparedStatement delete, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||||
{
|
|
||||||
delete.setFetchSize(this.dataStore.getFetchSize());
|
delete.setFetchSize(this.dataStore.getFetchSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onInsert(PreparedStatement insert, Connection cx, SimpleFeatureType featureType) throws SQLException
|
public void onInsert(PreparedStatement insert, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||||
{
|
|
||||||
insert.setFetchSize(this.dataStore.getFetchSize());
|
insert.setFetchSize(this.dataStore.getFetchSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUpdate(PreparedStatement update, Connection cx, SimpleFeatureType featureType) throws SQLException
|
public void onUpdate(PreparedStatement update, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||||
{
|
|
||||||
update.setFetchSize(this.dataStore.getFetchSize());
|
update.setFetchSize(this.dataStore.getFetchSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encodeTableName(String raw, StringBuffer sql)
|
public void encodeTableName(String raw, StringBuffer sql) {
|
||||||
{
|
|
||||||
raw = raw.toUpperCase();
|
raw = raw.toUpperCase();
|
||||||
if (raw.length() > 30)
|
if (raw.length() > 30)
|
||||||
raw = raw.substring(0, 30);
|
raw = raw.substring(0, 30);
|
||||||
sql.append(raw);
|
sql.append(raw);
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encodeColumnName(String prefix, String raw, StringBuffer sql)
|
public void encodeColumnName(String prefix, String raw, StringBuffer sql) {
|
||||||
{
|
|
||||||
if (prefix != null) {
|
if (prefix != null) {
|
||||||
prefix = prefix.toUpperCase();
|
prefix = prefix.toUpperCase();
|
||||||
if (prefix.length() > 30) {
|
if (prefix.length() > 30)
|
||||||
prefix = prefix.substring(0, 30);
|
prefix = prefix.substring(0, 30);
|
||||||
}
|
|
||||||
sql.append(prefix).append(".");
|
sql.append(prefix).append(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
raw = raw.toUpperCase();
|
raw = raw.toUpperCase();
|
||||||
if (raw.length() > 30)
|
if (raw.length() > 30)
|
||||||
raw = raw.substring(0, 30);
|
raw = raw.substring(0, 30);
|
||||||
sql.append(raw);
|
sql.append(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNameEscape()
|
public String getNameEscape() {
|
||||||
{
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGeometryTypeName(Integer type)
|
public String getGeometryTypeName(Integer type) {
|
||||||
{
|
|
||||||
return "MDSYS.SDO_GEOMETRY";
|
return "MDSYS.SDO_GEOMETRY";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean lookupGeneratedValuesPostInsert()
|
public boolean lookupGeneratedValuesPostInsert() {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDbType()
|
public String getDbType() {
|
||||||
{
|
|
||||||
return O2DSFactory.DBMSType.ORACLE.getTypeName();
|
return O2DSFactory.DBMSType.ORACLE.getTypeName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ public class OracleFilterToSQL extends PreparedFilterToSQL
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ArrayList layers = ServerContext.getMap().getAllLayers();
|
ArrayList<Layer> layers = ServerContext.getMap().getAllLayers();
|
||||||
for (Layer layer : layers)
|
for (Layer layer : layers)
|
||||||
{
|
{
|
||||||
if ((layer instanceof FeatureLayer))
|
if ((layer instanceof FeatureLayer))
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
public class PluginUtil
|
||||||
|
{
|
||||||
|
static NumberFormat f;
|
||||||
|
|
||||||
|
public static String getCurrentTime()
|
||||||
|
{
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||||
|
String strTime = dayTime.format(new Date(time));
|
||||||
|
|
||||||
|
return strTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toUTF8(String inputStr)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return URLDecoder.decode(inputStr, "UTF-8"); } catch (Exception e) {
|
||||||
|
}
|
||||||
|
return inputStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void refineRequestMap(HttpServletRequest req, Map<String, String> reqMap)
|
||||||
|
{
|
||||||
|
Set keyset = req.getParameterMap().keySet();
|
||||||
|
Iterator itr = keyset.iterator();
|
||||||
|
|
||||||
|
while (itr.hasNext())
|
||||||
|
{
|
||||||
|
String key = (String)itr.next();
|
||||||
|
reqMap.put(key.trim().toUpperCase(), toUTF8(req.getParameter(key).trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getClientIP(HttpServletRequest request)
|
||||||
|
{
|
||||||
|
String ip = request.getHeader("X-Forwarded-For");
|
||||||
|
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||||
|
ip = request.getHeader("Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||||
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||||
|
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||||
|
}
|
||||||
|
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||||
|
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||||
|
}
|
||||||
|
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
|
||||||
|
ip = request.getRemoteAddr();
|
||||||
|
}
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String refineNumber(Object number)
|
||||||
|
{
|
||||||
|
f = NumberFormat.getInstance();
|
||||||
|
f.setMaximumFractionDigits(4);
|
||||||
|
|
||||||
|
return f.format(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String refinePath(String path)
|
||||||
|
{
|
||||||
|
return path.replace(File.separator, "/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,241 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import org.geotools.data.DataUtilities;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.factory.CommonFactoryFinder;
|
||||||
|
import org.geotools.factory.GeoTools;
|
||||||
|
import org.geotools.filter.FilterDOMParser;
|
||||||
|
import org.geotools.filter.spatial.ReprojectingFilterVisitor;
|
||||||
|
import org.geotools.filter.v1_1.OGCConfiguration;
|
||||||
|
import org.geotools.filter.visitor.DuplicatingFilterVisitor;
|
||||||
|
import org.geotools.filter.visitor.ExtractBoundsFilterVisitor;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.geotools.xml.Configuration;
|
||||||
|
import org.geotools.xml.Parser;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.filter.FilterFactory2;
|
||||||
|
import org.opengis.filter.Id;
|
||||||
|
import org.opengis.filter.expression.PropertyName;
|
||||||
|
import org.opengis.filter.identity.Identifier;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class QueryMngr
|
||||||
|
{
|
||||||
|
private static final Configuration filterConfiguration = new OGCConfiguration();
|
||||||
|
public static final FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
|
||||||
|
|
||||||
|
public static Filter[] getFilters(String str)
|
||||||
|
throws ParserConfigurationException, SAXException, IOException
|
||||||
|
{
|
||||||
|
InputSource resource = new InputSource();
|
||||||
|
resource.setCharacterStream(new StringReader(str));
|
||||||
|
return parseFilters(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Filter[] getFilters(InputStream stream)
|
||||||
|
throws ParserConfigurationException, SAXException, IOException
|
||||||
|
{
|
||||||
|
InputSource resource = new InputSource(stream);
|
||||||
|
return parseFilters(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Filter[] parseFilters(InputSource resource)
|
||||||
|
throws ParserConfigurationException, SAXException, IOException
|
||||||
|
{
|
||||||
|
Filter[] filter = null;
|
||||||
|
|
||||||
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
|
dbf.setNamespaceAware(true);
|
||||||
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||||
|
Document dom = db.parse(resource);
|
||||||
|
|
||||||
|
NodeList nodes = dom.getElementsByTagNameNS("*", "Filter");
|
||||||
|
|
||||||
|
filter = new Filter[nodes.getLength()];
|
||||||
|
|
||||||
|
for (int j = 0; j < filter.length; j++) {
|
||||||
|
Element filterNode = (Element)nodes.item(j);
|
||||||
|
NodeList list = filterNode.getChildNodes();
|
||||||
|
Node child = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < list.getLength(); i++) {
|
||||||
|
child = list.item(i);
|
||||||
|
|
||||||
|
if ((child != null) && (child.getNodeType() == 1))
|
||||||
|
{
|
||||||
|
filter[j] = FilterDOMParser.parseFilter(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Filter getFilter(String str)
|
||||||
|
throws ParserConfigurationException, SAXException, IOException
|
||||||
|
{
|
||||||
|
InputSource resource = new InputSource();
|
||||||
|
resource.setCharacterStream(new StringReader(str));
|
||||||
|
return parseFilter(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Filter getFilter(InputStream stream)
|
||||||
|
throws ParserConfigurationException, SAXException, IOException
|
||||||
|
{
|
||||||
|
InputSource resource = new InputSource(stream);
|
||||||
|
return parseFilter(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Filter parseFilter(InputSource resource)
|
||||||
|
throws ParserConfigurationException, SAXException, IOException
|
||||||
|
{
|
||||||
|
Parser parser = new Parser(filterConfiguration);
|
||||||
|
return (Filter)parser.parse(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Filter reProjectionFilter(SimpleFeatureType schema, Filter filter)
|
||||||
|
{
|
||||||
|
ReprojectingFilterVisitor visitor = new ReprojectingFilterVisitor(filterFactory, schema);
|
||||||
|
return (Filter)filter.accept(visitor, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Filter upperCasePropertyNameFilter(Filter filter)
|
||||||
|
{
|
||||||
|
DuplicatingFilterVisitor fVisitor = new DuplicatingFilterVisitor()
|
||||||
|
{
|
||||||
|
public Object visit(PropertyName expression, Object extraData)
|
||||||
|
{
|
||||||
|
String pName = expression.getPropertyName().toUpperCase();
|
||||||
|
if (pName.contains(":")) {
|
||||||
|
pName = pName.substring(pName.lastIndexOf(":") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getFactory(extraData).property(pName, expression.getNamespaceContext());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (Filter)filter.accept(fVisitor, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Filter changeFIDFilter(SimpleFeatureType schema, Filter filter)
|
||||||
|
{
|
||||||
|
DuplicatingFilterVisitor fVisitor = new DuplicatingFilterVisitor()
|
||||||
|
{
|
||||||
|
public Object visit(Id filter, Object extraData)
|
||||||
|
{
|
||||||
|
Set fIDs = new HashSet();
|
||||||
|
for (Identifier fid : filter.getIdentifiers()) {
|
||||||
|
String str = fid.toString();
|
||||||
|
|
||||||
|
if (str.contains(".")) {
|
||||||
|
String pkStringVlaue = str.substring(str.indexOf(".") + 1);
|
||||||
|
//str = QueryMngr.this.getTypeName() + "." + pkStringVlaue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fIDs.add(getFactory(extraData).featureId(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
return getFactory(extraData).id(fIDs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (Filter)filter.accept(fVisitor, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Filter extractBBoxFilter(SimpleFeatureType schema, Filter filter)
|
||||||
|
{
|
||||||
|
Envelope bounds = (Envelope)filter.accept(ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||||
|
|
||||||
|
if ((bounds == null) || (bounds.isNull()))
|
||||||
|
return null;
|
||||||
|
if ((bounds.getMinX() == (-1.0D / 0.0D)) &&
|
||||||
|
(bounds.getMaxX() == (1.0D / 0.0D)) &&
|
||||||
|
(bounds.getMinY() == (-1.0D / 0.0D)) &&
|
||||||
|
(bounds.getMaxY() == (1.0D / 0.0D)))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReferencedEnvelope envelop = ReferencedEnvelope.reference(bounds);
|
||||||
|
String geomField = schema.getGeometryDescriptor().getLocalName();
|
||||||
|
Filter bbox = filterFactory.bbox(filterFactory.property(geomField), envelop);
|
||||||
|
|
||||||
|
return bbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Query reFineQuery(SimpleFeatureType schema, Query query)
|
||||||
|
{
|
||||||
|
query.setFilter(reFineFilter(schema, query.getFilter()));
|
||||||
|
|
||||||
|
Filter bboxFilter = extractBBoxFilter(schema, query.getFilter());
|
||||||
|
if (bboxFilter != null)
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem reprojCRS = query.getCoordinateSystemReproject();
|
||||||
|
|
||||||
|
Query bboxQuery = new Query(schema.getTypeName(), bboxFilter);
|
||||||
|
bboxQuery.setHints(query.getHints());
|
||||||
|
|
||||||
|
query = DataUtilities.mixQueries(query, bboxQuery, null);
|
||||||
|
|
||||||
|
if ((reprojCRS != null) && (!CRS.equalsIgnoreMetadata(schema.getCoordinateReferenceSystem(), reprojCRS))) {
|
||||||
|
query.setCoordinateSystemReproject(reprojCRS);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
query.setTypeName(schema.getTypeName());
|
||||||
|
|
||||||
|
if (query.getProperties() != null)
|
||||||
|
{
|
||||||
|
ArrayList propertys = new ArrayList();
|
||||||
|
|
||||||
|
String geom = schema.getGeometryDescriptor().getLocalName();
|
||||||
|
|
||||||
|
boolean isContain = false;
|
||||||
|
for (String pName : query.getPropertyNames())
|
||||||
|
{
|
||||||
|
pName = pName.trim().toUpperCase();
|
||||||
|
|
||||||
|
if (pName.equals(geom)) {
|
||||||
|
propertys.add(pName);
|
||||||
|
isContain = true;
|
||||||
|
}
|
||||||
|
else if (schema.getDescriptor(pName) != null) {
|
||||||
|
propertys.add(pName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
query.setPropertyNames(propertys);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Filter reFineFilter(SimpleFeatureType schema, Filter filter)
|
||||||
|
{
|
||||||
|
Filter uppercaseFilter = upperCasePropertyNameFilter(filter);
|
||||||
|
|
||||||
|
Filter transformFilter = reProjectionFilter(schema, uppercaseFilter);
|
||||||
|
|
||||||
|
Filter changeFidFilter = changeFIDFilter(schema, transformFilter);
|
||||||
|
|
||||||
|
return changeFidFilter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,199 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.geotools.data.DataUtilities;
|
||||||
|
import org.geotools.data.FeatureReader;
|
||||||
|
import org.geotools.data.collection.DelegateFeatureReader;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||||
|
import org.geotools.data.store.ContentFeatureStore;
|
||||||
|
import org.geotools.factory.Hints;
|
||||||
|
import org.geotools.feature.collection.DecoratingSimpleFeatureCollection;
|
||||||
|
import org.geotools.feature.simple.SimpleFeatureBuilder;
|
||||||
|
import org.geotools.feature.visitor.FeatureAttributeVisitor;
|
||||||
|
import org.geotools.filter.FilterAttributeExtractor;
|
||||||
|
import org.geotools.geometry.jts.JTS;
|
||||||
|
import org.geotools.jdbc.JDBCDataStore;
|
||||||
|
import org.geotools.jdbc.JDBCFeatureStore;
|
||||||
|
import org.geotools.jdbc.PrimaryKey;
|
||||||
|
import org.geotools.jdbc.PrimaryKeyColumn;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.opengis.feature.FeatureVisitor;
|
||||||
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
|
import org.opengis.filter.expression.Expression;
|
||||||
|
import org.opengis.filter.expression.PropertyName;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.opengis.referencing.operation.MathTransform;
|
||||||
|
|
||||||
|
public class RefindInsertFeatureCollection extends DecoratingSimpleFeatureCollection
|
||||||
|
{
|
||||||
|
ContentFeatureStore featureStore;
|
||||||
|
boolean useProvidedFid;
|
||||||
|
|
||||||
|
public RefindInsertFeatureCollection(SimpleFeature delegate, ContentFeatureStore fStore, boolean providedFid)
|
||||||
|
{
|
||||||
|
this(DataUtilities.collection(delegate), fStore, providedFid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RefindInsertFeatureCollection(SimpleFeatureCollection delegate, ContentFeatureStore fStore, boolean providedFid) {
|
||||||
|
super(delegate);
|
||||||
|
this.featureStore = fStore;
|
||||||
|
this.useProvidedFid = providedFid;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean canDelegate(FeatureVisitor visitor)
|
||||||
|
{
|
||||||
|
if ((visitor instanceof FeatureAttributeVisitor))
|
||||||
|
{
|
||||||
|
FilterAttributeExtractor extractor = new FilterAttributeExtractor(getSchema());
|
||||||
|
for (Expression e : ((FeatureAttributeVisitor)visitor).getExpressions()) {
|
||||||
|
e.accept(extractor, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PropertyName pname : extractor.getPropertyNameSet()) {
|
||||||
|
AttributeDescriptor att = (AttributeDescriptor)pname.evaluate(getSchema());
|
||||||
|
if (att == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentFeatureStore getFeatureStore()
|
||||||
|
{
|
||||||
|
return this.featureStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FeatureReader<SimpleFeatureType, SimpleFeature> reader() throws IOException
|
||||||
|
{
|
||||||
|
return new DelegateFeatureReader(getSchema(), features());
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureIterator features()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return new O2RefindFeatureIterator(this.delegate.features(), getFeatureStore()); } catch (IOException e) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
class O2RefindFeatureIterator implements SimpleFeatureIterator
|
||||||
|
{
|
||||||
|
SimpleFeatureIterator delegate;
|
||||||
|
ContentFeatureStore featureStore;
|
||||||
|
SimpleFeatureType featureType;
|
||||||
|
SimpleFeatureBuilder builder;
|
||||||
|
|
||||||
|
public O2RefindFeatureIterator(SimpleFeatureIterator delegate, ContentFeatureStore fStore) throws IOException
|
||||||
|
{
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.featureStore = fStore;
|
||||||
|
this.featureType = this.featureStore.getSchema();
|
||||||
|
this.builder = new SimpleFeatureBuilder(this.featureType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureIterator getDelegate() {
|
||||||
|
return this.delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNext() {
|
||||||
|
return this.delegate.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeature next()
|
||||||
|
{
|
||||||
|
SimpleFeature feature = (SimpleFeature)this.delegate.next();
|
||||||
|
|
||||||
|
String pkColumn = null;
|
||||||
|
if ((this.featureStore instanceof JDBCFeatureStore)) {
|
||||||
|
JDBCFeatureStore jdbcStore = (JDBCFeatureStore)this.featureStore;
|
||||||
|
if ((jdbcStore.getPrimaryKey() != null) &&
|
||||||
|
(jdbcStore.getPrimaryKey().getColumns().size() != 0)) {
|
||||||
|
pkColumn = ((PrimaryKeyColumn)jdbcStore.getPrimaryKey().getColumns().get(0)).getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String newID = null;
|
||||||
|
for (AttributeDescriptor att : this.featureType.getAttributeDescriptors())
|
||||||
|
{
|
||||||
|
Object value = feature.getAttribute(att.getLocalName());
|
||||||
|
if (value == null) {
|
||||||
|
value = feature.getAttribute(att.getLocalName().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((pkColumn != null) &&
|
||||||
|
(pkColumn.equalsIgnoreCase(att.getLocalName())) &&
|
||||||
|
(value != null)) {
|
||||||
|
newID = value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ((value != null) && (Geometry.class.isAssignableFrom(value.getClass())))
|
||||||
|
{
|
||||||
|
Geometry tGeom = (Geometry)value;
|
||||||
|
|
||||||
|
if ((tGeom.getUserData() != null) &&
|
||||||
|
((tGeom.getUserData() instanceof CoordinateReferenceSystem)) &&
|
||||||
|
(this.featureType.getCoordinateReferenceSystem() != null))
|
||||||
|
{
|
||||||
|
CoordinateReferenceSystem tCRS = (CoordinateReferenceSystem)tGeom.getUserData();
|
||||||
|
|
||||||
|
if (!CRS.equalsIgnoreMetadata(this.featureType.getCoordinateReferenceSystem(), tCRS))
|
||||||
|
{
|
||||||
|
MathTransform transform = CRS.findMathTransform(tCRS, this.featureType.getCoordinateReferenceSystem(), true);
|
||||||
|
value = JTS.transform(tGeom, transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((this.featureStore instanceof JDBCFeatureStore)) {
|
||||||
|
JDBCFeatureStore jdbcStore = (JDBCFeatureStore)this.featureStore;
|
||||||
|
|
||||||
|
if ((jdbcStore.getDataStore().getSQLDialect() instanceof OracleDialect))
|
||||||
|
{
|
||||||
|
OracleDialect oDialect = (OracleDialect)jdbcStore.getDataStore().getSQLDialect();
|
||||||
|
Integer srid = oDialect.getDBSrid(this.featureType.getTypeName(), this.featureType.getGeometryDescriptor().getLocalName());
|
||||||
|
|
||||||
|
if ((srid != null) && (srid.intValue() == 0)) {
|
||||||
|
oDialect.getClass(); ((Geometry)value).setUserData("OracleNullSrid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Fail to transform input geometry :: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.builder.set(att.getLocalName(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleFeature newFeature = this.builder.buildFeature(newID);
|
||||||
|
|
||||||
|
if (feature.getUserData().size() > 0) {
|
||||||
|
newFeature.getUserData().putAll(feature.getUserData());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((RefindInsertFeatureCollection.this.useProvidedFid) && (newID != null))
|
||||||
|
newFeature.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.valueOf(true));
|
||||||
|
else {
|
||||||
|
newFeature.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.valueOf(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return newFeature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
this.delegate.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,350 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Point;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import org.geotools.data.DataUtilities;
|
||||||
|
import org.geotools.data.FeatureReader;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||||
|
import org.geotools.feature.FeatureIterator;
|
||||||
|
import org.geotools.feature.FeatureTypes;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.opengis.feature.FeatureVisitor;
|
||||||
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
|
import org.opengis.feature.type.PropertyDescriptor;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.filter.sort.SortBy;
|
||||||
|
import org.opengis.geometry.BoundingBox;
|
||||||
|
import org.opengis.util.ProgressListener;
|
||||||
|
|
||||||
|
public class RenderFeatureCollection
|
||||||
|
implements SimpleFeatureCollection {
|
||||||
|
protected RenderFeatureSource featureSource;
|
||||||
|
protected Query query;
|
||||||
|
|
||||||
|
protected RenderFeatureCollection(RenderFeatureSource featureSource, Query query) {
|
||||||
|
this.featureSource = featureSource;
|
||||||
|
this.query = query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureType getSchema() {
|
||||||
|
return this.featureSource.getSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getID() {
|
||||||
|
return "Rendering FeatureCollection";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException {
|
||||||
|
this.featureSource.accepts(this.query, visitor, progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enabled aggressive block sorting
|
||||||
|
* Enabled unnecessary exception pruning
|
||||||
|
* Enabled aggressive exception aggregation
|
||||||
|
*/
|
||||||
|
public ReferencedEnvelope getBounds() {
|
||||||
|
FeatureReader<SimpleFeatureType, SimpleFeature> reader = null;
|
||||||
|
try {
|
||||||
|
ReferencedEnvelope result = this.featureSource.getBounds(this.query);
|
||||||
|
if (result != null) {
|
||||||
|
ReferencedEnvelope referencedEnvelope = result;
|
||||||
|
return referencedEnvelope;
|
||||||
|
}
|
||||||
|
Query q = new Query(this.query);
|
||||||
|
ArrayList<String> geometries = new ArrayList<String>();
|
||||||
|
Iterator iterator = this.getSchema().getAttributeDescriptors().iterator();
|
||||||
|
while (true) {
|
||||||
|
if (!iterator.hasNext()) {
|
||||||
|
if (geometries.size() != 0) break;
|
||||||
|
ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope();
|
||||||
|
return referencedEnvelope;
|
||||||
|
}
|
||||||
|
AttributeDescriptor ad = (AttributeDescriptor)iterator.next();
|
||||||
|
if (!(ad instanceof GeometryDescriptor)) continue;
|
||||||
|
geometries.add(ad.getLocalName());
|
||||||
|
}
|
||||||
|
q.setPropertyNames(geometries);
|
||||||
|
reader = this.featureSource.getReader(q);
|
||||||
|
while (true) {
|
||||||
|
if (!reader.hasNext()) {
|
||||||
|
if (result == null) break;
|
||||||
|
ReferencedEnvelope referencedEnvelope = result;
|
||||||
|
return referencedEnvelope;
|
||||||
|
}
|
||||||
|
SimpleFeature f = (SimpleFeature)reader.next();
|
||||||
|
ReferencedEnvelope featureBounds = ReferencedEnvelope.reference((BoundingBox)f.getBounds());
|
||||||
|
if (result == null) {
|
||||||
|
result = featureBounds;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (featureBounds == null) continue;
|
||||||
|
result.expandToInclude((Envelope)featureBounds);
|
||||||
|
}
|
||||||
|
ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(this.getSchema().getCoordinateReferenceSystem());
|
||||||
|
return referencedEnvelope;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (reader != null) {
|
||||||
|
try {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enabled aggressive block sorting
|
||||||
|
* Enabled unnecessary exception pruning
|
||||||
|
* Enabled aggressive exception aggregation
|
||||||
|
*/
|
||||||
|
public boolean contains(Object o) {
|
||||||
|
SimpleFeatureIterator e = null;
|
||||||
|
try {
|
||||||
|
e = this.features();
|
||||||
|
if (o == null) {
|
||||||
|
if (e.hasNext()) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (e.hasNext()) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (e != null) {
|
||||||
|
e.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsAll(Collection<?> c) {
|
||||||
|
Iterator<?> e = c.iterator();
|
||||||
|
try {
|
||||||
|
if (e.hasNext()) {
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (e instanceof FeatureIterator) {
|
||||||
|
((FeatureIterator)e).close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
boolean bl = false;
|
||||||
|
Query notEmptyQuery = new Query(this.query);
|
||||||
|
notEmptyQuery.setMaxFeatures(1);
|
||||||
|
AttributeDescriptor smallAttribute = this.getSmallAttributeInSchema();
|
||||||
|
if (smallAttribute != null) {
|
||||||
|
notEmptyQuery.setPropertyNames(Collections.singletonList(smallAttribute.getLocalName()));
|
||||||
|
}
|
||||||
|
FeatureReader<SimpleFeatureType, SimpleFeature> fr;
|
||||||
|
try {
|
||||||
|
fr = this.featureSource.getReader(notEmptyQuery);
|
||||||
|
try {
|
||||||
|
bl = !fr.hasNext();
|
||||||
|
}
|
||||||
|
catch (Throwable throwable) {
|
||||||
|
try {
|
||||||
|
fr.close();
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return bl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private AttributeDescriptor getSmallAttributeInSchema() {
|
||||||
|
AttributeDescriptor chosen = null;
|
||||||
|
for (AttributeDescriptor ad : this.getSchema().getAttributeDescriptors()) {
|
||||||
|
if (chosen != null && this.size(ad) >= this.size(chosen)) continue;
|
||||||
|
chosen = ad;
|
||||||
|
}
|
||||||
|
return chosen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
FeatureReader<SimpleFeatureType, SimpleFeature> fr = null;
|
||||||
|
try {
|
||||||
|
int size = this.featureSource.getCount(this.query);
|
||||||
|
if (size >= 0) {
|
||||||
|
int n = size;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
AttributeDescriptor chosen = this.getSmallAttributeInSchema();
|
||||||
|
Query q = new Query(this.query);
|
||||||
|
if (chosen != null) {
|
||||||
|
q.setPropertyNames(Collections.singletonList(chosen.getLocalName()));
|
||||||
|
}
|
||||||
|
fr = this.featureSource.getReader(q);
|
||||||
|
int count = 0;
|
||||||
|
while (fr.hasNext()) {
|
||||||
|
fr.next();
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
int n = count;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (fr != null) {
|
||||||
|
try {
|
||||||
|
fr.close();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int size(AttributeDescriptor ad) {
|
||||||
|
Class binding = ad.getType().getBinding();
|
||||||
|
if (binding.isPrimitive() || Number.class.isAssignableFrom(binding) || Date.class.isAssignableFrom(binding)) {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
if (binding.equals(String.class)) {
|
||||||
|
int fieldLen = FeatureTypes.getFieldLength((PropertyDescriptor)ad);
|
||||||
|
if (fieldLen > 0) {
|
||||||
|
return fieldLen * 2;
|
||||||
|
}
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
if (Point.class.isAssignableFrom(binding)) {
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] toArray() {
|
||||||
|
ArrayList<SimpleFeature> array = new ArrayList<SimpleFeature>();
|
||||||
|
SimpleFeatureIterator e = null;
|
||||||
|
try {
|
||||||
|
e = this.features();
|
||||||
|
while (e.hasNext()) {
|
||||||
|
array.add((SimpleFeature)e.next());
|
||||||
|
}
|
||||||
|
Object[] objectArray = array.toArray(new SimpleFeature[array.size()]);
|
||||||
|
return objectArray;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (e != null) {
|
||||||
|
e.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T[] toArray(T[] array) {
|
||||||
|
int size = this.size();
|
||||||
|
if (array.length < size) {
|
||||||
|
array = (T[])Array.newInstance(array.getClass().getComponentType(), size);
|
||||||
|
}
|
||||||
|
SimpleFeatureIterator it = this.features();
|
||||||
|
try {
|
||||||
|
T[] result = array;
|
||||||
|
int i = 0;
|
||||||
|
while (it.hasNext() && i < size) {
|
||||||
|
result[i] = (T) it.next();
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (array.length > size) {
|
||||||
|
array[size] = null;
|
||||||
|
}
|
||||||
|
Object[] objectArray = array;
|
||||||
|
return (T[]) objectArray;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (it != null) {
|
||||||
|
it.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureIterator features() {
|
||||||
|
try {
|
||||||
|
return new RenderFeatureIterator(this.featureSource.getReader(this.query));
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureCollection subCollection(Filter filter) {
|
||||||
|
Query query = new Query();
|
||||||
|
query.setFilter(filter);
|
||||||
|
query = DataUtilities.mixQueries((Query)this.query, (Query)query, null);
|
||||||
|
return new RenderFeatureCollection(this.featureSource, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureCollection sort(SortBy sort) {
|
||||||
|
Query query = new Query();
|
||||||
|
query.setSortBy(new SortBy[]{sort});
|
||||||
|
query = DataUtilities.mixQueries((Query)this.query, (Query)query, null);
|
||||||
|
return new RenderFeatureCollection(this.featureSource, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenderFeatureIterator
|
||||||
|
implements SimpleFeatureIterator {
|
||||||
|
FeatureReader<SimpleFeatureType, SimpleFeature> delegate;
|
||||||
|
|
||||||
|
public RenderFeatureIterator(FeatureReader<SimpleFeatureType, SimpleFeature> delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNext() {
|
||||||
|
try {
|
||||||
|
return this.delegate.hasNext();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeature next() {
|
||||||
|
try {
|
||||||
|
return (SimpleFeature)this.delegate.next();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.close();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
try {
|
||||||
|
this.delegate.close();
|
||||||
|
}
|
||||||
|
catch (IOException iOException) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,121 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import org.geotools.data.FeatureReader;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureSource;
|
||||||
|
import org.geotools.feature.FeatureIterator;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.renderer.ScreenMap;
|
||||||
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
|
||||||
|
class RenderFeatureReader
|
||||||
|
implements FeatureReader<SimpleFeatureType, SimpleFeature>
|
||||||
|
{
|
||||||
|
SimpleFeatureSource source;
|
||||||
|
FeatureIterator<SimpleFeature> featureIterator;
|
||||||
|
Query query;
|
||||||
|
double simplificationDistance = 0.0D;
|
||||||
|
ReferencedEnvelope targetBBox = null;
|
||||||
|
ScreenMap screenMap = null;
|
||||||
|
SimpleFeature nextFeature;
|
||||||
|
GeometryFactory geometryFactory = new GeometryFactory();
|
||||||
|
|
||||||
|
public RenderFeatureReader(SimpleFeatureSource source, Query query) throws IOException
|
||||||
|
{
|
||||||
|
this.source = source;
|
||||||
|
this.featureIterator = source.getFeatures(query).features();
|
||||||
|
this.query = query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
if (this.featureIterator != null)
|
||||||
|
try {
|
||||||
|
this.featureIterator.close();
|
||||||
|
} catch (Exception localException) {
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
this.featureIterator = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureType getFeatureType()
|
||||||
|
{
|
||||||
|
return (SimpleFeatureType)this.source.getSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeature next()
|
||||||
|
throws IOException, IllegalArgumentException, NoSuchElementException
|
||||||
|
{
|
||||||
|
if (this.featureIterator == null) {
|
||||||
|
throw new NoSuchElementException("Iterator has been closed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasNext()) {
|
||||||
|
SimpleFeature result = this.nextFeature;
|
||||||
|
this.nextFeature = null;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
close();
|
||||||
|
throw new NoSuchElementException("hasNext() returned false");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNext()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while ((this.nextFeature == null) && (this.featureIterator.hasNext()))
|
||||||
|
{
|
||||||
|
SimpleFeature feature = (SimpleFeature)this.featureIterator.next();
|
||||||
|
Geometry geometry = (Geometry)feature.getDefaultGeometry();
|
||||||
|
Envelope envelope = geometry.getEnvelopeInternal();
|
||||||
|
|
||||||
|
if ((this.targetBBox == null) ||
|
||||||
|
(this.targetBBox.isNull()) ||
|
||||||
|
(this.targetBBox.intersects(envelope)))
|
||||||
|
{
|
||||||
|
if ((this.simplificationDistance > 0.0D) &&
|
||||||
|
(envelope.getWidth() < this.simplificationDistance) &&
|
||||||
|
(envelope.getHeight() < this.simplificationDistance))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ((this.screenMap == null) || (!this.screenMap.checkAndSet(envelope)));
|
||||||
|
}
|
||||||
|
catch (Exception localException1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.nextFeature = feature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.nextFeature != null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
close();
|
||||||
|
}return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSimplificationDistance(double simplificationDistance)
|
||||||
|
{
|
||||||
|
this.simplificationDistance = simplificationDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetBBox(ReferencedEnvelope targetBBox)
|
||||||
|
{
|
||||||
|
this.targetBBox = targetBBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScreenMap(ScreenMap screenMap)
|
||||||
|
{
|
||||||
|
this.screenMap = screenMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,177 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Point;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.geotools.data.DataAccess;
|
||||||
|
import org.geotools.data.FeatureListener;
|
||||||
|
import org.geotools.data.FeatureReader;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.QueryCapabilities;
|
||||||
|
import org.geotools.data.ResourceInfo;
|
||||||
|
import org.geotools.data.shapefile.ShapefileDataStore ;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureSource;
|
||||||
|
import org.geotools.factory.Hints;
|
||||||
|
import org.geotools.filter.visitor.ExtractBoundsFilterVisitor;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.renderer.ScreenMap;
|
||||||
|
import org.geotools.renderer.ScreenMapRefinder;
|
||||||
|
import org.geotools.util.NullProgressListener;
|
||||||
|
import org.opengis.feature.Feature;
|
||||||
|
import org.opengis.feature.FeatureVisitor;
|
||||||
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.Name;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.filter.FilterVisitor;
|
||||||
|
import org.opengis.util.ProgressListener;
|
||||||
|
|
||||||
|
public class RenderFeatureSource
|
||||||
|
implements SimpleFeatureSource {
|
||||||
|
protected SimpleFeatureSource delegate;
|
||||||
|
protected Set<RenderingHints.Key> hints;
|
||||||
|
|
||||||
|
public RenderFeatureSource(SimpleFeatureSource delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
HashSet<RenderingHints.Key> hints = new HashSet<RenderingHints.Key>();
|
||||||
|
hints.add(Hints.FEATURE_DETACHED);
|
||||||
|
hints.add(Hints.JTS_GEOMETRY_FACTORY);
|
||||||
|
hints.add(Hints.JTS_COORDINATE_SEQUENCE_FACTORY);
|
||||||
|
hints.add(Hints.GEOMETRY_DISTANCE);
|
||||||
|
hints.add(Hints.SCREENMAP);
|
||||||
|
if (delegate.getSupportedHints() != null && delegate.getSupportedHints().size() != 0) {
|
||||||
|
hints.addAll(delegate.getSupportedHints());
|
||||||
|
}
|
||||||
|
this.hints = Collections.unmodifiableSet(hints);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFeatureListener(FeatureListener listener) {
|
||||||
|
this.delegate.addFeatureListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeFeatureListener(FeatureListener listener) {
|
||||||
|
this.delegate.removeFeatureListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataAccess<SimpleFeatureType, SimpleFeature> getDataStore() {
|
||||||
|
return this.delegate.getDataStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceInfo getInfo() {
|
||||||
|
return this.delegate.getInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name getName() {
|
||||||
|
return this.delegate.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryCapabilities getQueryCapabilities() {
|
||||||
|
return this.delegate.getQueryCapabilities();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureType getSchema() {
|
||||||
|
return (SimpleFeatureType)this.delegate.getSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<RenderingHints.Key> getSupportedHints() {
|
||||||
|
return this.hints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencedEnvelope getBounds() throws IOException {
|
||||||
|
return this.delegate.getBounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencedEnvelope getBounds(Query query) throws IOException {
|
||||||
|
return this.delegate.getBounds(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount(Query query) throws IOException {
|
||||||
|
return this.delegate.getCount(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureCollection getFeatures() throws IOException {
|
||||||
|
return this.getFeatures(Query.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureCollection getFeatures(Filter filter) throws IOException {
|
||||||
|
Query query = new Query(this.getSchema().getName().getLocalPart(), filter);
|
||||||
|
return this.getFeatures(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleFeatureCollection getFeatures(Query query) throws IOException {
|
||||||
|
if (this.delegate.getDataStore() instanceof ShapefileDataStore ) {
|
||||||
|
return this.delegate.getFeatures(query);
|
||||||
|
}
|
||||||
|
return new RenderFeatureCollection(this, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void accepts(Query query, FeatureVisitor visitor, ProgressListener progress) throws IOException {
|
||||||
|
if (progress == null) {
|
||||||
|
progress = new NullProgressListener();
|
||||||
|
}
|
||||||
|
FeatureReader<SimpleFeatureType, SimpleFeature> reader = this.getReader(query);
|
||||||
|
try {
|
||||||
|
float size = progress instanceof NullProgressListener ? 0.0f : (float)this.getCount(query);
|
||||||
|
float position = 0.0f;
|
||||||
|
progress.started();
|
||||||
|
while (reader.hasNext()) {
|
||||||
|
SimpleFeature feature = null;
|
||||||
|
if (size > 0.0f) {
|
||||||
|
float f = position;
|
||||||
|
position = f + 1.0f;
|
||||||
|
progress.progress(f / size);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
feature = (SimpleFeature)reader.next();
|
||||||
|
visitor.visit((Feature)feature);
|
||||||
|
}
|
||||||
|
catch (IOException erp) {
|
||||||
|
progress.exceptionOccurred((Throwable)erp);
|
||||||
|
throw erp;
|
||||||
|
}
|
||||||
|
catch (Exception unexpected) {
|
||||||
|
progress.exceptionOccurred((Throwable)unexpected);
|
||||||
|
String fid = feature == null ? "feature" : feature.getIdentifier().toString();
|
||||||
|
throw new IOException("Problem visiting " + query.getTypeName() + " visiting " + fid + ":" + unexpected, unexpected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
progress.complete();
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final FeatureReader<SimpleFeatureType, SimpleFeature> getReader(Query query) throws IOException {
|
||||||
|
RenderFeatureReader reader = new RenderFeatureReader(this.delegate, query);
|
||||||
|
if (query != null) {
|
||||||
|
Hints hints;
|
||||||
|
ReferencedEnvelope bbox = new ReferencedEnvelope();
|
||||||
|
if (query.getFilter() != null) {
|
||||||
|
Object boxObj = query.getFilter().accept((FilterVisitor)ExtractBoundsFilterVisitor.BOUNDS_VISITOR, (Object)bbox);
|
||||||
|
bbox = boxObj instanceof ReferencedEnvelope ? (ReferencedEnvelope)boxObj : ReferencedEnvelope.reference((Envelope)((Envelope)boxObj));
|
||||||
|
}
|
||||||
|
if (bbox != null && !bbox.isNull()) {
|
||||||
|
reader.setTargetBBox(bbox);
|
||||||
|
}
|
||||||
|
if ((hints = query.getHints()) != null) {
|
||||||
|
Number simplificationDistance = (Number)hints.get((Object)Hints.GEOMETRY_DISTANCE);
|
||||||
|
if (simplificationDistance != null) {
|
||||||
|
reader.setSimplificationDistance(simplificationDistance.doubleValue());
|
||||||
|
}
|
||||||
|
ScreenMap sMap = (ScreenMap)hints.get((Object)Hints.SCREENMAP);
|
||||||
|
if (Point.class.isAssignableFrom(((SimpleFeatureType)this.delegate.getSchema()).getGeometryDescriptor().getType().getBinding())) {
|
||||||
|
reader.setScreenMap(ScreenMapRefinder.refindScreenMap((ScreenMap)sMap, (ReferencedEnvelope)bbox, (double)0.5));
|
||||||
|
} else {
|
||||||
|
reader.setScreenMap(sMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
import com.vividsolutions.jts.geom.Coordinate;
|
import com.vividsolutions.jts.geom.Coordinate;
|
||||||
import com.vividsolutions.jts.geom.Envelope;
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
@ -12,16 +11,17 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import javax.media.jai.InterpolationBicubic2;
|
import javax.media.jai.InterpolationBicubic2;
|
||||||
import javax.media.jai.InterpolationBilinear;
|
import javax.media.jai.InterpolationBilinear;
|
||||||
import javax.media.jai.InterpolationNearest;
|
import javax.media.jai.InterpolationNearest;
|
||||||
import javax.media.jai.JAI;
|
import javax.media.jai.JAI;
|
||||||
|
import org.geotools.coverage.grid.GridCoverage2D;
|
||||||
import org.geotools.data.DataStore;
|
import org.geotools.data.DataStore;
|
||||||
import org.geotools.data.FeatureReader;
|
import org.geotools.data.FeatureReader;
|
||||||
|
import org.geotools.data.FeatureSource;
|
||||||
import org.geotools.data.Query;
|
import org.geotools.data.Query;
|
||||||
import org.geotools.data.Transaction;
|
import org.geotools.data.Transaction;
|
||||||
import org.geotools.data.crs.ForceCoordinateSystemFeatureReader;
|
import org.geotools.data.crs.ForceCoordinateSystemFeatureReader;
|
||||||
|
|
@ -31,15 +31,15 @@ import org.geotools.feature.NameImpl;
|
||||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
import org.geotools.map.GridCoverageLayer;
|
import org.geotools.map.GridCoverageLayer;
|
||||||
import org.geotools.map.MapContent;
|
import org.geotools.map.MapContent;
|
||||||
import org.geotools.map.MapViewport;
|
|
||||||
import org.geotools.referencing.CRS;
|
import org.geotools.referencing.CRS;
|
||||||
import org.geotools.renderer.label.LabelCacheImpl.LabelRenderingMode;
|
import org.geotools.renderer.label.LabelCacheImpl;
|
||||||
import org.geotools.renderer.lite.StreamingRenderer;
|
import org.geotools.renderer.lite.StreamingRenderer;
|
||||||
import org.geotools.styling.FeatureTypeStyle;
|
import org.geotools.styling.FeatureTypeStyle;
|
||||||
import org.geotools.styling.NamedLayer;
|
import org.geotools.styling.NamedLayer;
|
||||||
import org.geotools.styling.NamedStyle;
|
import org.geotools.styling.NamedStyle;
|
||||||
import org.geotools.styling.Rule;
|
import org.geotools.styling.Rule;
|
||||||
import org.geotools.styling.Style;
|
import org.geotools.styling.Style;
|
||||||
|
import org.geotools.styling.StyleVisitor;
|
||||||
import org.geotools.styling.StyledLayer;
|
import org.geotools.styling.StyledLayer;
|
||||||
import org.geotools.styling.StyledLayerDescriptor;
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
import org.geotools.styling.Symbolizer;
|
import org.geotools.styling.Symbolizer;
|
||||||
|
|
@ -51,115 +51,585 @@ import org.opengis.feature.type.Name;
|
||||||
import org.opengis.filter.Filter;
|
import org.opengis.filter.Filter;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
|
||||||
public class RenderMngr {
|
public class RenderMngr {
|
||||||
public static BufferedImage productMap(AVList params)
|
static boolean useImageAntialias = true;
|
||||||
throws Exception
|
static boolean useTextAntialias = true;
|
||||||
{
|
static Interpolation interpolationMethod = Interpolation.NN;
|
||||||
String[] layers = (String[])params.getValue("request.wms.layers");
|
static ThreadPoolExecutor RENDERING_POOL;
|
||||||
String[] styles = (String[])params.getValue("request.wms.styles");
|
|
||||||
StyledLayerDescriptor sld = (StyledLayerDescriptor)params.getValue("request.wms.sld");
|
|
||||||
|
|
||||||
Layer[] mapLayers = null;
|
public static BufferedImage productMap(AVList params) throws Exception {
|
||||||
|
String[] layers = (String[])params.getValue("request.wms.layers");
|
||||||
|
String[] styles = (String[])params.getValue("request.wms.styles");
|
||||||
|
StyledLayerDescriptor sld = (StyledLayerDescriptor)params.getValue("request.wms.sld");
|
||||||
|
Layer[] mapLayers = null;
|
||||||
|
if (layers == null || layers.length == 0) {
|
||||||
|
layers = null;
|
||||||
|
styles = null;
|
||||||
|
if (sld == null) {
|
||||||
|
throw new IllegalArgumentException("Rendering parameter must have [LAYERS or (SLD, SLD_BODY)] value.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mapLayers = new Layer[layers.length];
|
||||||
|
int i = 0;
|
||||||
|
while (i < layers.length) {
|
||||||
|
if (ServerUtil.isNullString((String)layers[i])) {
|
||||||
|
throw new IllegalArgumentException("Layers parameter [" + layers[i] + "] is not available.");
|
||||||
|
}
|
||||||
|
Layer mapLayer = ServerContext.getMap().getLayer(layers[i]);
|
||||||
|
if (mapLayer.getLayerType() == LayerFactory.LayerType.WCS) {
|
||||||
|
throw new IllegalArgumentException("Layer " + mapLayer.getName() + "(type:" + mapLayer.getLayerType() + ") is not support to render.");
|
||||||
|
}
|
||||||
|
mapLayers[i] = mapLayer;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (styles == null || styles.length == 0) {
|
||||||
|
styles = new String[mapLayers.length];
|
||||||
|
} else if (styles.length != mapLayers.length) {
|
||||||
|
throw new IllegalArgumentException("Parameter [LAYERS, STYLES] must configure the same length.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sld != null) {
|
||||||
|
RefineRenderStyleVisitor sVisitor = new RefineRenderStyleVisitor();
|
||||||
|
sld.accept((StyleVisitor)sVisitor);
|
||||||
|
sld = (StyledLayerDescriptor)sVisitor.getCopy();
|
||||||
|
}
|
||||||
|
ReferencedEnvelope bbox = (ReferencedEnvelope)params.getValue("request.wms.bbox");
|
||||||
|
int width = params.getIntegerValue("request.wms.width", Integer.valueOf(256));
|
||||||
|
int height = params.getIntegerValue("request.wms.height", Integer.valueOf(256));
|
||||||
|
boolean transparent = params.getBooleanValue("request.wms.transparent", Boolean.valueOf(false));
|
||||||
|
Color bgcolor = params.getColorValue("request.wms.bgcolor", Color.WHITE);
|
||||||
|
Rectangle paintArea = new Rectangle(0, 0, width, height);
|
||||||
|
ArrayList<org.geotools.map.Layer> targetLayers = new ArrayList<org.geotools.map.Layer>();
|
||||||
|
try {
|
||||||
|
if (mapLayers == null) {
|
||||||
|
RenderMngr.addRenderLayers(targetLayers, sld, params);
|
||||||
|
} else if (sld == null) {
|
||||||
|
RenderMngr.addRenderLayers(targetLayers, mapLayers, styles, params);
|
||||||
|
} else {
|
||||||
|
RenderMngr.addRenderLayers(targetLayers, mapLayers, styles, sld, params);
|
||||||
|
}
|
||||||
|
BufferedImage bufferedImage = RenderMngr.drawImage(targetLayers, paintArea, bbox, bgcolor, transparent);
|
||||||
|
return bufferedImage;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
targetLayers.clear();
|
||||||
|
targetLayers = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((layers == null) || (layers.length == 0))
|
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, Layer[] layers, String[] styles, AVList params) throws Exception {
|
||||||
{
|
int i = 0;
|
||||||
layers = null;
|
while (i < layers.length) {
|
||||||
styles = null;
|
RenderMngr.makeNamedLayer(targetLayers, layers[i], styles[i], params);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sld == null)
|
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, Layer[] layers, String[] styles, StyledLayerDescriptor sld, AVList params) throws Exception {
|
||||||
throw new IllegalArgumentException("Rendering parameter must have [LAYERS or (SLD, SLD_BODY)] value.");
|
int i = 0;
|
||||||
}
|
while (i < layers.length) {
|
||||||
else
|
ArrayList<Style> sldStyles = StyleMngr.getStylesFromSLD(layers[i].getName(), styles[i], sld);
|
||||||
{
|
if (sldStyles.isEmpty()) {
|
||||||
mapLayers = new Layer[layers.length];
|
RenderMngr.makeNamedLayer(targetLayers, layers[i], styles[i], params);
|
||||||
|
} else {
|
||||||
|
for (Style tempStyle : sldStyles) {
|
||||||
|
if (tempStyle instanceof NamedStyle) {
|
||||||
|
RenderMngr.makeNamedLayer(targetLayers, layers[i], tempStyle.getName(), params);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
RenderMngr.makeNamedLayer(targetLayers, layers[i], tempStyle, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < layers.length; i++) {
|
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, StyledLayerDescriptor sld, AVList params) throws Exception {
|
||||||
if (ServerUtil.isNullString(layers[i])) {
|
for (StyledLayer styledLayer : sld.layers()) {
|
||||||
throw new IllegalArgumentException("Layers parameter [" + layers[i] + "] is not available.");
|
if (styledLayer instanceof NamedLayer) {
|
||||||
}
|
if (ServerUtil.isNullString((String)styledLayer.getName())) {
|
||||||
|
throw new IllegalArgumentException("NamedLayer name is null.");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Layer mapLayer = ServerContext.getMap().getLayer(styledLayer.getName());
|
||||||
|
for (Style style : ((NamedLayer)styledLayer).styles()) {
|
||||||
|
if (style instanceof NamedStyle) {
|
||||||
|
RenderMngr.makeNamedLayer(targetLayers, mapLayer, style.getName(), params);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
RenderMngr.makeNamedLayer(targetLayers, mapLayer, style, params);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new NullPointerException("Layer [" + styledLayer.getName() + "] is not exits.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UserLayer userLayer = (UserLayer)styledLayer;
|
||||||
|
for (Style style : userLayer.userStyles()) {
|
||||||
|
RenderMngr.makeUserLayer(targetLayers, userLayer, style, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Layer mapLayer = ServerContext.getMap().getLayer(layers[i]);
|
private static void makeUserLayer(ArrayList<org.geotools.map.Layer> targetLayers, UserLayer userLayer, Style style, AVList params) throws Exception {
|
||||||
if (mapLayer.getLayerType() == LayerFactory.LayerType.WCS) {
|
if (userLayer.getInlineFeatureType() == null) {
|
||||||
throw new IllegalArgumentException("Layer " + mapLayer.getName() + "(type:" + mapLayer.getLayerType() + ") is not support to render.");
|
if (ServerUtil.isNullString((String)userLayer.getName())) {
|
||||||
}
|
throw new IllegalArgumentException("UserLayer has no renderable parameter[Name or InlineFeature].");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Layer mapLayer = ServerContext.getMap().getLayer(userLayer.getName());
|
||||||
|
RenderMngr.makeNamedLayer(targetLayers, mapLayer, style, params);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new NullPointerException("Layer [" + userLayer.getName() + "] is not exits.");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LinkedList<MapStyle> styleList = new LinkedList<MapStyle>();
|
||||||
|
for (FeatureTypeStyle fStyle : style.featureTypeStyles()) {
|
||||||
|
if (fStyle.featureTypeNames().isEmpty()) {
|
||||||
|
RenderMngr.addFeatureTypeStyleList(styleList, null, null, "INLINE", fStyle);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Layer mapLayer = ServerContext.getMap().getLayer(userLayer.getName());
|
||||||
|
if (mapLayer instanceof FeatureLayer) {
|
||||||
|
FeatureLayer fLayer = (FeatureLayer)mapLayer;
|
||||||
|
for (Name name : fStyle.featureTypeNames()) {
|
||||||
|
try {
|
||||||
|
String tempName = name.getLocalPart();
|
||||||
|
DuplicatingStyleVisitor visitor = new DuplicatingStyleVisitor();
|
||||||
|
visitor.visit(fStyle);
|
||||||
|
FeatureTypeStyle tempStyle = (FeatureTypeStyle)visitor.getCopy();
|
||||||
|
tempStyle.featureTypeNames().clear();
|
||||||
|
tempStyle.featureTypeNames().add(new NameImpl(tempName));
|
||||||
|
RenderMngr.addFeatureTypeStyleList(styleList, fLayer.getLayerType(), fLayer.getServerName(), tempName, tempStyle);
|
||||||
|
}
|
||||||
|
catch (Exception tempName) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Layer [" + userLayer.getName() + "] is not FeatureLayer.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new NullPointerException("Layer [" + userLayer.getName() + "] is not exits.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean isRendered = false;
|
||||||
|
for (MapStyle renderStyle : styleList) {
|
||||||
|
try {
|
||||||
|
SimpleFeatureSource featureSource;
|
||||||
|
if (renderStyle.getTypeName().equals("INLINE")) {
|
||||||
|
if (userLayer.getInlineFeatureType().getCoordinateReferenceSystem() == null) {
|
||||||
|
SimpleFeatureType currFt = userLayer.getInlineFeatureType();
|
||||||
|
Query q = new Query(currFt.getTypeName(), (Filter)Filter.INCLUDE);
|
||||||
|
DataStore inlineFeatureDatastore = userLayer.getInlineFeatureDatastore();
|
||||||
|
FeatureReader ilReader = inlineFeatureDatastore.getFeatureReader(q, Transaction.AUTO_COMMIT);
|
||||||
|
CoordinateReferenceSystem crs = CRSMngr.getCRS((Integer)4326);
|
||||||
|
ReferencedEnvelope bbox = (ReferencedEnvelope)params.getValue("request.wms.bbox");
|
||||||
|
if (bbox != null && bbox.getCoordinateReferenceSystem() != null) {
|
||||||
|
crs = bbox.getCoordinateReferenceSystem();
|
||||||
|
}
|
||||||
|
String typeName = inlineFeatureDatastore.getTypeNames()[0];
|
||||||
|
MemoryDataStore reTypedDS = new MemoryDataStore((FeatureReader)new ForceCoordinateSystemFeatureReader(ilReader, crs));
|
||||||
|
featureSource = reTypedDS.getFeatureSource(typeName);
|
||||||
|
} else {
|
||||||
|
DataStore inlineFeatureDatastore = userLayer.getInlineFeatureDatastore();
|
||||||
|
String typeName = inlineFeatureDatastore.getTypeNames()[0];
|
||||||
|
featureSource = inlineFeatureDatastore.getFeatureSource(typeName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)renderStyle.getLayerType(), (String)renderStyle.getServerName(), (String)renderStyle.getTypeName());
|
||||||
|
}
|
||||||
|
RenderFeatureSource renderSource = new RenderFeatureSource(featureSource);
|
||||||
|
targetLayers.add((org.geotools.map.Layer)new ExFeatureLayer((FeatureSource)renderSource, (Style)renderStyle));
|
||||||
|
isRendered = true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[STYLE]", "[RenderMngr.addUserLayer]" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isRendered) {
|
||||||
|
throw new IOException("This UserLayer [" + userLayer.getName() + "] has no available rendering features or styles.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mapLayers[i] = mapLayer;
|
private static void makeNamedLayer(ArrayList<org.geotools.map.Layer> targetLayers, Layer layer, String styleName, AVList params) throws Exception {
|
||||||
}
|
if (layer instanceof FeatureLayer) {
|
||||||
|
Filter filter = (Filter)params.getValue("request.wms.filter");
|
||||||
|
Style layerStyle = ((FeatureLayer)layer).getRenderStyle(styleName);
|
||||||
|
RenderMngr.addFeatureLayer(targetLayers, layerStyle, (FeatureLayer)layer, filter);
|
||||||
|
} else if (layer instanceof GroupLayer) {
|
||||||
|
GroupLayer groupLayer = (GroupLayer)layer;
|
||||||
|
Filter filter = (Filter)params.getValue("request.wms.filter");
|
||||||
|
for (FeatureLayer fLayer : groupLayer.getLayerList()) {
|
||||||
|
Style layerStyle = fLayer.getRenderStyle(styleName);
|
||||||
|
RenderMngr.addFeatureLayer(targetLayers, layerStyle, fLayer, filter);
|
||||||
|
}
|
||||||
|
} else if (layer instanceof WMSLayer) {
|
||||||
|
AVList wmsParams = params.copy();
|
||||||
|
wmsParams.setValue("request.wms.styles", (Object)styleName);
|
||||||
|
ExWMSLayer wmsLayer = new ExWMSLayer((LinkLayer)layer, wmsParams);
|
||||||
|
targetLayers.add((org.geotools.map.Layer)wmsLayer);
|
||||||
|
} else if (layer instanceof O2ImgLayer) {
|
||||||
|
AVList wmsParams = params.copy();
|
||||||
|
wmsParams.setValue("request.wms.styles", (Object)styleName);
|
||||||
|
ExO2ImgLayer o2Layer = new ExO2ImgLayer((O2ImgLayer)layer, wmsParams);
|
||||||
|
targetLayers.add((org.geotools.map.Layer)o2Layer);
|
||||||
|
} else if (layer instanceof O2DemLayer) {
|
||||||
|
O2DemLayer demLayer = (O2DemLayer)layer;
|
||||||
|
ReferencedEnvelope bbox = (ReferencedEnvelope)params.getValue("request.wms.bbox");
|
||||||
|
if (!CRS.equalsIgnoreMetadata((Object)demLayer.getCRS(), (Object)bbox.getCoordinateReferenceSystem())) {
|
||||||
|
bbox = bbox.transform(demLayer.getCRS(), true);
|
||||||
|
}
|
||||||
|
int width = params.getIntegerValue("request.wms.width");
|
||||||
|
int height = params.getIntegerValue("request.wms.height");
|
||||||
|
GridCoverage2D gc = O2LayerUtil.getCoverage((O2LayerLevelSet)demLayer.getLevelSet(), (ReferencedEnvelope)bbox, (int)width, (int)height);
|
||||||
|
targetLayers.add((org.geotools.map.Layer)new GridCoverageLayer(gc, demLayer.getRenderStyle(styleName)));
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Layer " + layer.getName() + "(type:" + layer.getLayerType() + ") is not support to render.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((styles == null) || (styles.length == 0))
|
private static void makeNamedLayer(ArrayList<org.geotools.map.Layer> targetLayers, Layer layer, Style style, AVList params) throws Exception {
|
||||||
styles = new String[mapLayers.length];
|
if (layer instanceof FeatureLayer) {
|
||||||
else if (styles.length != mapLayers.length) {
|
Filter filter = (Filter)params.getValue("request.wms.filter");
|
||||||
throw new IllegalArgumentException("Parameter [LAYERS, STYLES] must configure the same length.");
|
RenderMngr.addFeatureLayer(targetLayers, style, (FeatureLayer)layer, filter);
|
||||||
}
|
} else if (layer instanceof GroupLayer) {
|
||||||
|
GroupLayer groupLayer = (GroupLayer)layer;
|
||||||
|
Filter filter = (Filter)params.getValue("request.wms.filter");
|
||||||
|
for (FeatureLayer fLayer : groupLayer.getLayerList()) {
|
||||||
|
RenderMngr.addFeatureLayer(targetLayers, style, fLayer, filter);
|
||||||
|
}
|
||||||
|
} else if (layer instanceof WMSLayer) {
|
||||||
|
AVList wmsParams = params.copy();
|
||||||
|
wmsParams.setValue("request.wms.styles", (Object)"");
|
||||||
|
ExWMSLayer wmsLayer = new ExWMSLayer((LinkLayer)layer, wmsParams);
|
||||||
|
targetLayers.add((org.geotools.map.Layer)wmsLayer);
|
||||||
|
} else if (layer instanceof O2ImgLayer) {
|
||||||
|
AVList wmsParams = params.copy();
|
||||||
|
wmsParams.setValue("request.wms.styles", (Object)"");
|
||||||
|
ExO2ImgLayer o2Layer = new ExO2ImgLayer((O2ImgLayer)layer, wmsParams);
|
||||||
|
targetLayers.add((org.geotools.map.Layer)o2Layer);
|
||||||
|
} else if (layer instanceof O2DemLayer) {
|
||||||
|
O2DemLayer demLayer = (O2DemLayer)layer;
|
||||||
|
ReferencedEnvelope bbox = (ReferencedEnvelope)params.getValue("request.wms.bbox");
|
||||||
|
if (!CRS.equalsIgnoreMetadata((Object)demLayer.getCRS(), (Object)bbox.getCoordinateReferenceSystem())) {
|
||||||
|
bbox = bbox.transform(demLayer.getCRS(), true);
|
||||||
|
}
|
||||||
|
int width = params.getIntegerValue("request.wms.width");
|
||||||
|
int height = params.getIntegerValue("request.wms.height");
|
||||||
|
GridCoverage2D gc = O2LayerUtil.getCoverage((O2LayerLevelSet)demLayer.getLevelSet(), (ReferencedEnvelope)bbox, (int)width, (int)height);
|
||||||
|
targetLayers.add((org.geotools.map.Layer)new GridCoverageLayer(gc, style));
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Layer " + layer.getName() + "(type:" + layer.getLayerType() + ") is not support to render.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
private static void addFeatureLayer(ArrayList<org.geotools.map.Layer> targetLayers, Style style, FeatureLayer layer, Filter filter) throws Exception {
|
||||||
|
LinkedList<MapStyle> styleList = new LinkedList<MapStyle>();
|
||||||
|
for (FeatureTypeStyle fStyle : style.featureTypeStyles()) {
|
||||||
|
if (fStyle.featureTypeNames().isEmpty()) {
|
||||||
|
RenderMngr.addFeatureTypeStyleList(styleList, layer.getLayerType(), layer.getServerName(), layer.getSourceName(), fStyle);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Name name : fStyle.featureTypeNames()) {
|
||||||
|
try {
|
||||||
|
String tempName = name.getLocalPart();
|
||||||
|
DuplicatingStyleVisitor visitor = new DuplicatingStyleVisitor();
|
||||||
|
visitor.visit(fStyle);
|
||||||
|
FeatureTypeStyle tempStyle = (FeatureTypeStyle)visitor.getCopy();
|
||||||
|
tempStyle.featureTypeNames().clear();
|
||||||
|
tempStyle.featureTypeNames().add(new NameImpl(tempName));
|
||||||
|
RenderMngr.addFeatureTypeStyleList(styleList, layer.getLayerType(), layer.getServerName(), tempName, tempStyle);
|
||||||
|
}
|
||||||
|
catch (Exception tempName) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean isRendered = false;
|
||||||
|
for (MapStyle renderStyle : styleList) {
|
||||||
|
try {
|
||||||
|
System.out.println(
|
||||||
|
"renderStyle.getLayerType().getType(): [" + renderStyle.getLayerType().getType() + "]\n" +
|
||||||
|
"renderStyle.getServerName(): [" + renderStyle.getServerName() + "]\n" +
|
||||||
|
"renderStyle.getTypeName(): [" + renderStyle.getTypeName() + "]\n"
|
||||||
|
);
|
||||||
|
SimpleFeatureSource featureSource = O2DSMngr.getFeatureSource((LayerFactory.LayerType)renderStyle.getLayerType(), (String)renderStyle.getServerName(), (String)renderStyle.getTypeName());
|
||||||
|
RenderFeatureSource renderSource = new RenderFeatureSource(featureSource);
|
||||||
|
ExFeatureLayer exLayer = new ExFeatureLayer((FeatureSource)renderSource, (Style)renderStyle);
|
||||||
|
exLayer.setQuery(new Query(renderSource.getSchema().getTypeName(), filter));
|
||||||
|
targetLayers.add((org.geotools.map.Layer)exLayer);
|
||||||
|
isRendered = true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[STYLE]", "[RenderMngr.addFeatureLayer]" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isRendered) {
|
||||||
|
throw new IOException("This NamedLayer [" + layer.getName() + "] has no available rendering styles.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sld != null) {
|
private static void addFeatureTypeStyleList(LinkedList<MapStyle> styleList, LayerFactory.LayerType layerType, String serverName, String typeName, FeatureTypeStyle featureStyle) {
|
||||||
RefineRenderStyleVisitor sVisitor = new RefineRenderStyleVisitor();
|
DuplicatingStyleVisitor visitor = new DuplicatingStyleVisitor();
|
||||||
sld.accept(sVisitor);
|
visitor.visit(featureStyle);
|
||||||
sld = (StyledLayerDescriptor)sVisitor.getCopy();
|
FeatureTypeStyle copyStyle = (FeatureTypeStyle)visitor.getCopy();
|
||||||
}
|
Double wrapTileTextValue = RenderMngr.extractWrapTileTextVendorOption(copyStyle);
|
||||||
|
if (copyStyle.rules().size() != 0) {
|
||||||
|
if (!styleList.isEmpty() && styleList.getLast().getTypeName().equalsIgnoreCase(typeName)) {
|
||||||
|
styleList.getLast().featureTypeStyles().add(copyStyle);
|
||||||
|
} else {
|
||||||
|
MapStyle tempStyle = new MapStyle();
|
||||||
|
tempStyle.setLayerType(layerType);
|
||||||
|
tempStyle.setServerName(serverName);
|
||||||
|
tempStyle.setTypeName(typeName);
|
||||||
|
tempStyle.featureTypeStyles().add(copyStyle);
|
||||||
|
styleList.addLast(tempStyle);
|
||||||
|
}
|
||||||
|
if (wrapTileTextValue > styleList.getLast().getWrapTileText()) {
|
||||||
|
styleList.getLast().setWrapTileText(wrapTileTextValue.doubleValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ReferencedEnvelope bbox = (ReferencedEnvelope)params.getValue("request.wms.bbox");
|
private static Double extractWrapTileTextVendorOption(FeatureTypeStyle featureStyle) {
|
||||||
|
Double wrapValue = 0.0;
|
||||||
|
Iterator rules = featureStyle.rules().iterator();
|
||||||
|
while (rules.hasNext()) {
|
||||||
|
Rule rule = (Rule)rules.next();
|
||||||
|
for (Symbolizer symbolizer : rule.symbolizers()) {
|
||||||
|
Double tempValue;
|
||||||
|
if (!(symbolizer instanceof TextSymbolizer) || (tempValue = ServerUtil.getDoubleOption((Symbolizer)symbolizer, (String)"wrapTileText", null)) == null || !(0.0 < tempValue) || !(wrapValue < tempValue)) continue;
|
||||||
|
wrapValue = tempValue;
|
||||||
|
}
|
||||||
|
if (rule.symbolizers().size() != 0) continue;
|
||||||
|
rules.remove();
|
||||||
|
}
|
||||||
|
return wrapValue;
|
||||||
|
}
|
||||||
|
|
||||||
int width = params.getIntegerValue("request.wms.width", Integer.valueOf(256)).intValue();
|
private static BufferedImage drawImage(ArrayList<org.geotools.map.Layer> targetLayers, Rectangle paintArea, ReferencedEnvelope mapBounds, Color bgColor, boolean transparent) throws Exception {
|
||||||
int height = params.getIntegerValue("request.wms.height", Integer.valueOf(256)).intValue();
|
BufferedImage image = transparent ? new BufferedImage(paintArea.width, paintArea.height, 6) : new BufferedImage(paintArea.width, paintArea.height, 5);
|
||||||
|
Graphics2D graphic = image.createGraphics();
|
||||||
|
if (!transparent) {
|
||||||
|
graphic.setPaint(bgColor);
|
||||||
|
graphic.fill(paintArea);
|
||||||
|
}
|
||||||
|
LabelCacheEx labelCacheEx = new LabelCacheEx();
|
||||||
|
StreamingRenderer renderer = RenderMngr.initRenderer(graphic, labelCacheEx);
|
||||||
|
try {
|
||||||
|
double labelScale = 0.0;
|
||||||
|
for (org.geotools.map.Layer layer : targetLayers) {
|
||||||
|
if (layer instanceof ExFeatureLayer && ((ExFeatureLayer)layer).isWrapTileTextLayer()) {
|
||||||
|
double scale = ((ExFeatureLayer)layer).getWrapTileText();
|
||||||
|
RenderMngr.drawScaledLayer(renderer, layer, graphic, paintArea, mapBounds, scale);
|
||||||
|
if (!(labelScale < scale)) continue;
|
||||||
|
labelScale = scale;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
RenderMngr.drawNormalLayer(renderer, layer, graphic, paintArea, mapBounds);
|
||||||
|
}
|
||||||
|
labelCacheEx.paintLabelText(graphic, RenderMngr.getScaledArea(paintArea, labelScale));
|
||||||
|
BufferedImage bufferedImage = image;
|
||||||
|
return bufferedImage;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
targetLayers.clear();
|
||||||
|
targetLayers = null;
|
||||||
|
renderer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean transparent = params.getBooleanValue("request.wms.transparent", Boolean.valueOf(false)).booleanValue();
|
private static void drawScaledLayer(StreamingRenderer renderer, org.geotools.map.Layer layer, Graphics2D graphic, Rectangle paintArea, ReferencedEnvelope mapBounds, double scale) throws Exception {
|
||||||
Color bgcolor = params.getColorValue("request.wms.bgcolor", Color.WHITE);
|
Rectangle scalePaintArea = RenderMngr.getScaledArea(paintArea, scale);
|
||||||
|
double lonGap = mapBounds.getWidth() * scale;
|
||||||
|
double latGap = mapBounds.getHeight() * scale;
|
||||||
|
ReferencedEnvelope scaleMapBounds = ReferencedEnvelope.create((Envelope)new Envelope(new Coordinate(mapBounds.getMinX() - lonGap, mapBounds.getMinY() - latGap), new Coordinate(mapBounds.getMaxX() + lonGap, mapBounds.getMaxY() + latGap)), (CoordinateReferenceSystem)mapBounds.getCoordinateReferenceSystem());
|
||||||
|
MapContent mapContent = new MapContent();
|
||||||
|
mapContent.getViewport().setBounds(scaleMapBounds);
|
||||||
|
mapContent.getViewport().setCoordinateReferenceSystem(scaleMapBounds.getCoordinateReferenceSystem());
|
||||||
|
mapContent.getViewport().setScreenArea(scalePaintArea);
|
||||||
|
mapContent.getViewport().setMatchingAspectRatio(false);
|
||||||
|
mapContent.addLayer(layer);
|
||||||
|
try {
|
||||||
|
renderer.setMapContent(mapContent);
|
||||||
|
renderer.paint(graphic, scalePaintArea, scaleMapBounds);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
RenderMngr.disposeMapContents(mapContent);
|
||||||
|
mapContent.dispose();
|
||||||
|
mapContent = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle paintArea = new Rectangle(0, 0, width, height);
|
private static void drawWrapTileTextLayer(Graphics2D graphic, LabelCacheEx labelCacheEx, ExFeatureLayer layer, Rectangle paintArea, ReferencedEnvelope mapBounds) {
|
||||||
|
double scale = layer.getWrapTileText();
|
||||||
|
Rectangle scalePaintArea = RenderMngr.getScaledArea(paintArea, scale);
|
||||||
|
double lonGap = mapBounds.getWidth() * scale;
|
||||||
|
double latGap = mapBounds.getHeight() * scale;
|
||||||
|
ReferencedEnvelope scaleMapBounds = ReferencedEnvelope.create((Envelope)new Envelope(new Coordinate(mapBounds.getMinX() - lonGap, mapBounds.getMinY() - latGap), new Coordinate(mapBounds.getMaxX() + lonGap, mapBounds.getMaxY() + latGap)), (CoordinateReferenceSystem)mapBounds.getCoordinateReferenceSystem());
|
||||||
|
MapContent mapContent = new MapContent();
|
||||||
|
mapContent.addLayer((org.geotools.map.Layer)layer);
|
||||||
|
BufferedImage image = new BufferedImage(scalePaintArea.width, scalePaintArea.height, 6);
|
||||||
|
Graphics2D scaledGraphic = image.createGraphics();
|
||||||
|
scaledGraphic.setRenderingHints(graphic.getRenderingHints());
|
||||||
|
StreamingRenderer renderer = RenderMngr.initRenderer(scaledGraphic, labelCacheEx);
|
||||||
|
try {
|
||||||
|
renderer.setMapContent(mapContent);
|
||||||
|
renderer.paint(scaledGraphic, scalePaintArea, scaleMapBounds);
|
||||||
|
graphic.drawImage(image, 0, 0, paintArea.width, paintArea.height, 0, 0, paintArea.width, paintArea.height, null);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
RenderMngr.disposeMapContents(mapContent);
|
||||||
|
mapContent.dispose();
|
||||||
|
mapContent = null;
|
||||||
|
renderer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList targetLayers = new ArrayList();
|
private static Rectangle getScaledArea(Rectangle paintArea, double scale) {
|
||||||
try
|
int wGap = (int)((double)paintArea.width * scale);
|
||||||
{
|
int hGap = (int)((double)paintArea.height * scale);
|
||||||
if (mapLayers == null)
|
return new Rectangle(-wGap, -hGap, paintArea.width + wGap * 2, paintArea.height + hGap * 2);
|
||||||
addRenderLayers(targetLayers, sld, params);
|
}
|
||||||
else if (sld == null)
|
|
||||||
addRenderLayers(targetLayers, mapLayers, styles, params);
|
|
||||||
else {
|
|
||||||
addRenderLayers(targetLayers, mapLayers, styles, sld, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
return drawImage(targetLayers, paintArea, bbox, bgcolor, transparent);
|
private static void drawNormalLayer(StreamingRenderer renderer, org.geotools.map.Layer layer, Graphics2D graphic, Rectangle paintArea, ReferencedEnvelope mapBounds) throws Exception {
|
||||||
}
|
MapContent mapContent = new MapContent();
|
||||||
catch (Exception e) {
|
mapContent.getViewport().setBounds(mapBounds);
|
||||||
throw e;
|
mapContent.getViewport().setCoordinateReferenceSystem(mapBounds.getCoordinateReferenceSystem());
|
||||||
} finally {
|
mapContent.getViewport().setScreenArea(paintArea);
|
||||||
targetLayers.clear();
|
mapContent.getViewport().setMatchingAspectRatio(false);
|
||||||
targetLayers = null;
|
mapContent.addLayer(layer);
|
||||||
}
|
try {
|
||||||
}
|
renderer.setMapContent(mapContent);
|
||||||
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, Layer[] layers, String[] styles, AVList params)
|
renderer.paint(graphic, paintArea, mapBounds);
|
||||||
throws Exception
|
}
|
||||||
{
|
finally {
|
||||||
for (int i = 0; i < layers.length; i++)
|
RenderMngr.disposeMapContents(mapContent);
|
||||||
{
|
mapContent.dispose();
|
||||||
makeNamedLayer(targetLayers, layers[i], styles[i], params);
|
mapContent = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, Layer[] layers, String[] styles, StyledLayerDescriptor sld, AVList params)
|
private static void disposeMapContents(MapContent mapContent) {
|
||||||
throws Exception
|
if (mapContent == null) {
|
||||||
{
|
return;
|
||||||
for (int i = 0; i < layers.length; i++)
|
}
|
||||||
{
|
for (org.geotools.map.Layer layer : mapContent.layers()) {
|
||||||
ArrayList sldStyles = StyleMngr.getStylesFromSLD(layers[i].getName(), styles[i], sld);
|
layer.preDispose();
|
||||||
if (sldStyles.isEmpty()) {
|
}
|
||||||
makeNamedLayer(targetLayers, layers[i], styles[i], params);
|
mapContent.dispose();
|
||||||
}
|
mapContent = null;
|
||||||
else {
|
}
|
||||||
Iterator styleIter = sldStyles.iterator();
|
|
||||||
while (styleIter.hasNext()) {
|
|
||||||
Style tempStyle = (Style)styleIter.next();
|
|
||||||
|
|
||||||
if ((tempStyle instanceof NamedStyle))
|
private static StreamingRenderer initRenderer(Graphics2D graphic, LabelCacheEx labelCache) {
|
||||||
makeNamedLayer(targetLayers, layers[i], tempStyle.getName(), params);
|
HashMap<RenderingHints.Key, Object> hintsMap = new HashMap<RenderingHints.Key, Object>();
|
||||||
else
|
if (useImageAntialias) {
|
||||||
makeNamedLayer(targetLayers, layers[i], tempStyle, params);
|
hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
}
|
} else {
|
||||||
}
|
hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||||
}
|
}
|
||||||
}
|
if (useTextAntialias) {
|
||||||
}
|
hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
||||||
|
} else {
|
||||||
|
hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||||
|
}
|
||||||
|
hintsMap.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||||
|
hintsMap.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
|
||||||
|
switch (interpolationMethod) {
|
||||||
|
case NN: {
|
||||||
|
hintsMap.put(JAI.KEY_INTERPOLATION, new InterpolationNearest());
|
||||||
|
hintsMap.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BL: {
|
||||||
|
hintsMap.put(JAI.KEY_INTERPOLATION, new InterpolationBilinear());
|
||||||
|
hintsMap.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BC: {
|
||||||
|
hintsMap.put(JAI.KEY_INTERPOLATION, new InterpolationBicubic2(0));
|
||||||
|
hintsMap.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hintsMap.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||||
|
graphic.setRenderingHints(hintsMap);
|
||||||
|
StreamingRenderer renderer = new StreamingRenderer();
|
||||||
|
RenderingHints hints = new RenderingHints(hintsMap);
|
||||||
|
renderer.setJava2DHints(hints);
|
||||||
|
HashMap<String, Object> rendererParams = new HashMap<String, Object>();
|
||||||
|
rendererParams.put("optimizedDataLoadingEnabled", new Boolean(true));
|
||||||
|
rendererParams.put("renderingBuffer", new Integer(0));
|
||||||
|
rendererParams.put("optimizeFTSRendering", new Boolean(true));
|
||||||
|
rendererParams.put("dpi", new Double(96.0));
|
||||||
|
rendererParams.put("scaleComputationMethod", "ACCURATE");
|
||||||
|
if (useTextAntialias) {
|
||||||
|
rendererParams.put("textRenderingMethod", StreamingRenderer.TEXT_RENDERING_ADAPTIVE);
|
||||||
|
labelCache.setLabelRenderingMode(LabelCacheImpl.LabelRenderingMode.ADAPTIVE);
|
||||||
|
} else {
|
||||||
|
rendererParams.put("textRenderingMethod", StreamingRenderer.TEXT_RENDERING_STRING);
|
||||||
|
labelCache.setLabelRenderingMode(LabelCacheImpl.LabelRenderingMode.STRING);
|
||||||
|
}
|
||||||
|
rendererParams.put("labelCache", labelCache);
|
||||||
|
renderer.setRendererHints(rendererParams);
|
||||||
|
renderer.setGeneralizationDistance(1.0);
|
||||||
|
renderer.setThreadPool((ExecutorService)RenderMngr.getRenderingPool());
|
||||||
|
return renderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
* Enabled force condition propagation
|
||||||
|
* Lifted jumps to return sites
|
||||||
|
*/
|
||||||
|
private static ThreadPoolExecutor getRenderingPool() {
|
||||||
|
if (RENDERING_POOL != null) return RENDERING_POOL;
|
||||||
|
Class<RenderMngr> clazz = RenderMngr.class;
|
||||||
|
synchronized (RenderMngr.class) {
|
||||||
|
if (RENDERING_POOL != null) return RENDERING_POOL;
|
||||||
|
RENDERING_POOL = (ThreadPoolExecutor)Executors.newCachedThreadPool();
|
||||||
|
// ** MonitorExit[var0] (shouldn't be in output)
|
||||||
|
return RENDERING_POOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
* Enabled force condition propagation
|
||||||
|
* Lifted jumps to return sites
|
||||||
|
*/
|
||||||
|
public static void disposeRenderingPool() {
|
||||||
|
if (RENDERING_POOL == null) return;
|
||||||
|
Class<RenderMngr> clazz = RenderMngr.class;
|
||||||
|
synchronized (RenderMngr.class) {
|
||||||
|
if (RENDERING_POOL == null) return;
|
||||||
|
RENDERING_POOL.shutdown();
|
||||||
|
while (RENDERING_POOL.isTerminating()) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000L);
|
||||||
|
}
|
||||||
|
catch (InterruptedException interruptedException) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RENDERING_POOL = null;
|
||||||
|
// ** MonitorExit[var0] (shouldn't be in output)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static enum Interpolation {
|
||||||
|
NN,
|
||||||
|
BL,
|
||||||
|
BC;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,55 +1,62 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
import org.opengis.filter.Filter;
|
import org.opengis.filter.Filter;
|
||||||
|
|
||||||
public class Request
|
public class Request {
|
||||||
{
|
private String service = "WMS";
|
||||||
private String service = "WMS";
|
private String version = null;
|
||||||
private String version = null;
|
private String request = null;
|
||||||
private String request = null;
|
private String baseURL = null;
|
||||||
private String baseURL = null;
|
private String format = "image/jpeg";
|
||||||
private String format = "image/jpeg";
|
private Filter filter = null;
|
||||||
private Filter filter = null;
|
|
||||||
|
|
||||||
public String getService() {
|
public String getService() {
|
||||||
return this.service;
|
return this.service;
|
||||||
}
|
|
||||||
public void setService(String service) {
|
|
||||||
this.service = service;
|
|
||||||
}
|
|
||||||
public String getVersion() {
|
|
||||||
return this.version;
|
|
||||||
}
|
|
||||||
public void setVersion(String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
public String getRequest() {
|
|
||||||
return this.request;
|
|
||||||
}
|
|
||||||
public void setRequest(String request) {
|
|
||||||
this.request = request;
|
|
||||||
}
|
|
||||||
public String getBaseURL() {
|
|
||||||
return this.baseURL;
|
|
||||||
}
|
|
||||||
public void setBaseURL(String baseURL) {
|
|
||||||
this.baseURL = baseURL;
|
|
||||||
}
|
|
||||||
public String getFormat() {
|
|
||||||
return this.format;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFormat(String format) {
|
|
||||||
if (format.equals("image/jpg")) {
|
|
||||||
format = "image/jpeg";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.format = format;
|
public void setService(String service) {
|
||||||
}
|
this.service = service;
|
||||||
public Filter getFilter() {
|
}
|
||||||
return this.filter;
|
|
||||||
}
|
public String getVersion() {
|
||||||
public void setFilter(Filter filter) {
|
return this.version;
|
||||||
this.filter = filter;
|
}
|
||||||
}
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRequest() {
|
||||||
|
return this.request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequest(String request) {
|
||||||
|
this.request = request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBaseURL() {
|
||||||
|
return this.baseURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBaseURL(String baseURL) {
|
||||||
|
this.baseURL = baseURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormat() {
|
||||||
|
return this.format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormat(String format) {
|
||||||
|
if (format.equals("image/jpg")) {
|
||||||
|
format = "image/jpeg";
|
||||||
|
}
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Filter getFilter() {
|
||||||
|
return this.filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilter(Filter filter) {
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,176 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.CoordinateSequence;
|
||||||
|
import com.vividsolutions.jts.geom.CoordinateSequenceFactory;
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||||
|
import com.vividsolutions.jts.geom.LineString;
|
||||||
|
import com.vividsolutions.jts.geom.LinearRing;
|
||||||
|
import com.vividsolutions.jts.geom.MultiLineString;
|
||||||
|
import com.vividsolutions.jts.geom.MultiPoint;
|
||||||
|
import com.vividsolutions.jts.geom.MultiPolygon;
|
||||||
|
import com.vividsolutions.jts.geom.Point;
|
||||||
|
import com.vividsolutions.jts.geom.Polygon;
|
||||||
|
import org.opengis.referencing.operation.MathTransform;
|
||||||
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
|
public class ScreenMap {
|
||||||
|
double[] point = new double[2];
|
||||||
|
int[] pixels;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
private int minx;
|
||||||
|
private int miny;
|
||||||
|
MathTransform mt;
|
||||||
|
double spanX;
|
||||||
|
double spanY;
|
||||||
|
|
||||||
|
public ScreenMap(int x, int y, int width, int height, MathTransform mt) {
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.minx = x;
|
||||||
|
this.miny = y;
|
||||||
|
int arraySize = width * height / 32 + 1;
|
||||||
|
this.pixels = new int[arraySize];
|
||||||
|
this.mt = mt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScreenMap(ScreenMap original, int expandBy) {
|
||||||
|
this(original.minx - expandBy, original.miny - expandBy, original.width + expandBy * 2, original.height + expandBy * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScreenMap(int x, int y, int width, int height) {
|
||||||
|
this(x, y, width, height, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTransform(MathTransform mt) {
|
||||||
|
this.mt = mt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkAndSet(Envelope envelope) throws TransformException {
|
||||||
|
if (!this.canSimplify(envelope)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.point[0] = (envelope.getMinX() + envelope.getMaxX()) / 2.0;
|
||||||
|
this.point[1] = (envelope.getMinY() + envelope.getMaxY()) / 2.0;
|
||||||
|
this.mt.transform(this.point, 0, this.point, 0, 1);
|
||||||
|
int r = (int)this.point[0];
|
||||||
|
int c = (int)this.point[1];
|
||||||
|
return this.checkAndSet(r, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canSimplify(Envelope envelope) {
|
||||||
|
return envelope.getWidth() < this.spanX && envelope.getHeight() < this.spanY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpans(double spanX, double spanY) {
|
||||||
|
this.spanX = spanX;
|
||||||
|
this.spanY = spanY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkAndSet(int x, int y) {
|
||||||
|
if (x - this.minx < 0 || x - this.minx > this.width - 1 || y - this.miny < 0 || y - this.miny > this.height - 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int bit = this.bit(x - this.minx, y - this.miny);
|
||||||
|
int index = bit / 32;
|
||||||
|
int offset = bit % 32;
|
||||||
|
int mask = 1 << offset;
|
||||||
|
try {
|
||||||
|
if ((this.pixels[index] & mask) != 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this.pixels[index] = this.pixels[index] | mask;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean get(int x, int y) {
|
||||||
|
if (x - this.minx < 0 || x - this.minx > this.width - 1 || y - this.miny < 0 || y - this.miny > this.height - 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int bit = this.bit(x - this.minx, y - this.miny);
|
||||||
|
int index = bit / 32;
|
||||||
|
int offset = bit % 32;
|
||||||
|
int mask = 1 << offset;
|
||||||
|
try {
|
||||||
|
return (this.pixels[index] & mask) != 0;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int bit(int x, int y) {
|
||||||
|
return this.width * y + x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Geometry getSimplifiedShape(double minx, double miny, double maxx, double maxy, GeometryFactory geometryFactory, Class geometryType) {
|
||||||
|
CoordinateSequenceFactory csf = geometryFactory.getCoordinateSequenceFactory();
|
||||||
|
double midx = (minx + maxx) / 2.0;
|
||||||
|
double midy = (miny + maxy) / 2.0;
|
||||||
|
double x0 = midx - this.spanX / 2.0;
|
||||||
|
double x1 = midx + this.spanX / 2.0;
|
||||||
|
double y0 = midy - this.spanY / 2.0;
|
||||||
|
double y1 = midy + this.spanY / 2.0;
|
||||||
|
if (Point.class.isAssignableFrom(geometryType) || MultiPoint.class.isAssignableFrom(geometryType)) {
|
||||||
|
CoordinateSequence cs = csf.create(1, 2);
|
||||||
|
cs.setOrdinate(0, 0, midx);
|
||||||
|
cs.setOrdinate(0, 1, midy);
|
||||||
|
if (Point.class.isAssignableFrom(geometryType)) {
|
||||||
|
return geometryFactory.createPoint(cs);
|
||||||
|
}
|
||||||
|
return geometryFactory.createMultiPoint(new Point[]{geometryFactory.createPoint(cs)});
|
||||||
|
}
|
||||||
|
if (LineString.class.isAssignableFrom(geometryType) || MultiLineString.class.isAssignableFrom(geometryType)) {
|
||||||
|
CoordinateSequence cs = csf.create(2, 2);
|
||||||
|
cs.setOrdinate(0, 0, x0);
|
||||||
|
cs.setOrdinate(0, 1, y0);
|
||||||
|
cs.setOrdinate(1, 0, x1);
|
||||||
|
cs.setOrdinate(1, 1, y1);
|
||||||
|
if (MultiLineString.class.isAssignableFrom(geometryType)) {
|
||||||
|
return geometryFactory.createMultiLineString(new LineString[]{geometryFactory.createLineString(cs)});
|
||||||
|
}
|
||||||
|
return geometryFactory.createLineString(cs);
|
||||||
|
}
|
||||||
|
CoordinateSequence cs = csf.create(5, 2);
|
||||||
|
cs.setOrdinate(0, 0, x0);
|
||||||
|
cs.setOrdinate(0, 1, y0);
|
||||||
|
cs.setOrdinate(1, 0, x0);
|
||||||
|
cs.setOrdinate(1, 1, y1);
|
||||||
|
cs.setOrdinate(2, 0, x1);
|
||||||
|
cs.setOrdinate(2, 1, y1);
|
||||||
|
cs.setOrdinate(3, 0, x1);
|
||||||
|
cs.setOrdinate(3, 1, y0);
|
||||||
|
cs.setOrdinate(4, 0, x0);
|
||||||
|
cs.setOrdinate(4, 1, y0);
|
||||||
|
LinearRing ring = geometryFactory.createLinearRing(cs);
|
||||||
|
if (MultiPolygon.class.isAssignableFrom(geometryType)) {
|
||||||
|
return geometryFactory.createMultiPolygon(new Polygon[]{geometryFactory.createPolygon(ring, null)});
|
||||||
|
}
|
||||||
|
return geometryFactory.createPolygon(ring, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(int x, int y, boolean value) {
|
||||||
|
if (x - this.minx < 0 || x - this.minx > this.width - 1 || y - this.miny < 0 || y - this.miny > this.height - 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int bit = this.bit(x - this.minx, y - this.miny);
|
||||||
|
int index = bit / 32;
|
||||||
|
int offset = bit % 32;
|
||||||
|
int mask = 1;
|
||||||
|
mask <<= offset;
|
||||||
|
if (value) {
|
||||||
|
this.pixels[index] = this.pixels[index] | mask;
|
||||||
|
} else {
|
||||||
|
int tmp = this.pixels[index];
|
||||||
|
tmp ^= 0xFFFFFFFF;
|
||||||
|
tmp |= mask;
|
||||||
|
this.pixels[index] = tmp ^= 0xFFFFFFFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,6 @@ package geoinfo.map.myMap;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
@ -16,532 +15,401 @@ import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
public class ServerConfiguration
|
public class ServerConfiguration {
|
||||||
{
|
private static ServerConfiguration instance = null;
|
||||||
private static ServerConfiguration instance = null;
|
private HashMap<String, Object> confMap = null;
|
||||||
|
|
||||||
private HashMap<String, Object> confMap = null;
|
private ServerConfiguration() {
|
||||||
|
|
||||||
public static ServerConfiguration getInstance()
|
|
||||||
{
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new ServerConfiguration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
public static ServerConfiguration getInstance() {
|
||||||
}
|
if (instance == null) {
|
||||||
|
instance = new ServerConfiguration();
|
||||||
public boolean startServer()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
System.out.println("******************************");
|
|
||||||
System.out.println("Load server_conf.xml");
|
|
||||||
System.out.println("******************************");
|
|
||||||
|
|
||||||
loadConf();
|
|
||||||
System.out.println("Success :: Loading Configuration File :: WEB-INF/conf/server_conf.xml");
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException e) {
|
|
||||||
System.out.println("Fail :: Configuration Fil is not exist... :: " + e);
|
|
||||||
return false;
|
|
||||||
} catch (ParserConfigurationException e) {
|
|
||||||
System.out.println("Fail :: parsing Configuration File... :: " + e);
|
|
||||||
return false;
|
|
||||||
} catch (SAXException e) {
|
|
||||||
System.out.println("Fail :: parsing Configuration File... :: " + e);
|
|
||||||
return false;
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Fail :: loading Configuration File... :: " + e);
|
|
||||||
return false;
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("Fail :: can't access Configuration File... :: " + e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
System.out.println("");
|
|
||||||
System.out.println("******************************");
|
|
||||||
System.out.println("Init Logging Service");
|
|
||||||
System.out.println("******************************");
|
|
||||||
|
|
||||||
LogMngr.getInstance().initLog(this.confMap);
|
|
||||||
System.out.println("Success :: Starting Logging Service!!!");
|
|
||||||
|
|
||||||
if (LogMngr.getInstance().getLogDirctory() != null)
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logInfo("[CACHE]", "------------------------------");
|
|
||||||
LogMngr.getInstance().logInfo("[CACHE]", "Init log cache service");
|
|
||||||
LogMngr.getInstance().logInfo("[CACHE]", "------------------------------");
|
|
||||||
LogMngr.getInstance().logInfo("[CACHE]", "");
|
|
||||||
|
|
||||||
LogCacheManager.getInstance().start(this.confMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
System.out.println("Fail :: Stop Logging Service..." + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "");
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "Server loading... ");
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "");
|
|
||||||
|
|
||||||
LogMngr.getInstance().logInfo("[LICENSE]", "--------------------------------------");
|
|
||||||
LogMngr.getInstance().logInfo("[LICENSE]", "Check License");
|
|
||||||
LogMngr.getInstance().logInfo("[LICENSE]", "--------------------------------------");
|
|
||||||
if (!LicenseMngr.checkLicense()) {
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "========================================");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "Stop Server :: License Not Availiable...");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "========================================");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "");
|
|
||||||
|
|
||||||
stopServer();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LogMngr.getInstance().logInfo("[LICENSE]", "");
|
|
||||||
|
|
||||||
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
|
||||||
LogMngr.getInstance().logInfo("[MAP]", "Initialize ServiceMap");
|
|
||||||
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ServerContext.initMap(
|
|
||||||
(String)this.confMap.get("conf.xml.map.servicemap"),
|
|
||||||
(String)this.confMap.get("conf.xml.map.namespace"));
|
|
||||||
|
|
||||||
LogMngr.getInstance().logInfo("[MAP]", "Now use this ServiceMap :: [" + ServerContext.getMap().getName() + "]");
|
|
||||||
LogMngr.getInstance().logInfo("[MAP]", "Now use this NameSpace :: [" + ServerContext.getMap().getNameSpace() + "]");
|
|
||||||
LogMngr.getInstance().logInfo("[MAP]", "Now use this NameSpaceURI :: [" + ServerContext.getMap().getNameSpaceURI() + "]");
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "Stop Server :: ServiceMap is not availiable. ::" + e.getMessage());
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "");
|
|
||||||
|
|
||||||
stopServer();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LogMngr.getInstance().logInfo("[MAP]", "");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ServerContext.initLayers();
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "Stop Server :: Initializing Layer Fail ::" + e.getMessage());
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
|
||||||
LogMngr.getInstance().logError("[SERVER]", "");
|
|
||||||
|
|
||||||
stopServer();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "");
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "Server Starting...");
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
|
||||||
LogMngr.getInstance().logInfo("[SERVER]", "");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopServer()
|
|
||||||
{
|
|
||||||
ServerContext.initOptions();
|
|
||||||
|
|
||||||
O2DSMngr.disposeStores();
|
|
||||||
|
|
||||||
ConnMngr connMngr = ConnMngr.getInstance();
|
|
||||||
connMngr.closeConn();
|
|
||||||
|
|
||||||
LogCacheManager.getInstance().stop();
|
|
||||||
|
|
||||||
RenderMngr.disposeRenderingPool();
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void loadConf()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
if (this.confMap == null)
|
|
||||||
this.confMap = new HashMap();
|
|
||||||
else {
|
|
||||||
this.confMap.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerContext.initOptions();
|
|
||||||
|
|
||||||
File confFile = new File(ServerContext.getConfFolder(), "/server_conf.xml");
|
|
||||||
|
|
||||||
System.out.println("Configuration File Location :: " + confFile.getAbsolutePath());
|
|
||||||
|
|
||||||
if (confFile.exists())
|
|
||||||
{
|
|
||||||
System.out.println("Now try parse Configuration File");
|
|
||||||
|
|
||||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
|
||||||
SAXParser parser = factory.newSAXParser();
|
|
||||||
ConfParserHandler handler = new ConfParserHandler();
|
|
||||||
parser.parse(confFile, handler);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new FileNotFoundException("Configuration File is not exist [" + confFile.getAbsolutePath() + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashSet<String> getMapList()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
HashSet mapList = new HashSet();
|
|
||||||
|
|
||||||
Connection connection = null;
|
|
||||||
Statement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection = ConnMngr.getInstance().openConn();
|
|
||||||
stmt = connection.createStatement();
|
|
||||||
|
|
||||||
String sql = "SELECT MAP_NAME FROM O2MAP_SERVICE_INFO";
|
|
||||||
LogMngr.getInstance().logDebug("[MAP]", "Load MapList :: SQL > " + sql);
|
|
||||||
rs = stmt.executeQuery(sql);
|
|
||||||
|
|
||||||
if (rs != null) {
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
String mapName = rs.getString(1);
|
|
||||||
if (ServerUtil.isNullString(mapName)) {
|
|
||||||
LogMngr.getInstance().logDebug("[MAP]", "Skip this layer :: MAP_NAME is NULL");
|
|
||||||
}
|
|
||||||
else if (mapList.add(mapName.trim().toUpperCase())) {
|
|
||||||
LogMngr.getInstance().logDebug("[MAP]",
|
|
||||||
"Add MAP_NAME [" + mapList.size() + "/" + mapName.trim().toUpperCase() + "]");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
return instance;
|
||||||
|
|
||||||
if (mapList.size() == 0) {
|
|
||||||
throw new Exception("Map Count is [0]");
|
|
||||||
}
|
|
||||||
LogMngr.getInstance().logInfo("[MAP]",
|
|
||||||
"Success to load MapList :: Map Count is [" + mapList.size() + "]");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logError("[MAP]",
|
|
||||||
"Fail to load MapList :: " + e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
ConnMngr.getInstance().closeConn();
|
|
||||||
ConnMngr.getInstance().closeSafe(stmt);
|
|
||||||
ConnMngr.getInstance().closeSafe(rs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapList;
|
public boolean startServer() {
|
||||||
}
|
try {
|
||||||
|
System.out.println("******************************");
|
||||||
public HashMap<String, Object> getConfMap()
|
System.out.println("Load server_conf.xml");
|
||||||
{
|
System.out.println("******************************");
|
||||||
return this.confMap;
|
this.loadConf();
|
||||||
}
|
System.out.println("Success :: Loading Configuration File :: WEB-INF/conf/server_conf.xml");
|
||||||
|
|
||||||
class ConfParserHandler extends DefaultHandler
|
|
||||||
{
|
|
||||||
boolean isServer = false;
|
|
||||||
|
|
||||||
boolean isMap = false;
|
|
||||||
boolean isDbtype = false;
|
|
||||||
boolean isHost = false;
|
|
||||||
boolean isPort = false;
|
|
||||||
boolean isDatabase = false;
|
|
||||||
boolean isUser = false;
|
|
||||||
boolean isPasswd = false;
|
|
||||||
boolean isServicemap = false;
|
|
||||||
|
|
||||||
boolean isOption = false;
|
|
||||||
boolean isNamespace = false;
|
|
||||||
boolean isUseNS = false;
|
|
||||||
boolean isDocIndent = false;
|
|
||||||
boolean isDefaultMaxFeatures = false;
|
|
||||||
boolean isEncryption = false;
|
|
||||||
|
|
||||||
boolean isLog = false;
|
|
||||||
boolean isLogDir = false;
|
|
||||||
boolean isLogLevel = false;
|
|
||||||
boolean isLogRequest = false;
|
|
||||||
boolean isLogCache = false;
|
|
||||||
boolean isLogCacheType = false;
|
|
||||||
boolean isLogCacheValue = false;
|
|
||||||
|
|
||||||
boolean isAdmin = false;
|
|
||||||
boolean isSecure_key = false;
|
|
||||||
boolean isStyle_key = false;
|
|
||||||
|
|
||||||
ConfParserHandler() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
|
||||||
if (this.isServer)
|
|
||||||
{
|
|
||||||
if (this.isMap)
|
|
||||||
{
|
|
||||||
if (qName.equalsIgnoreCase("DBTYPE")) {
|
|
||||||
this.isDbtype = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("HOST")) {
|
|
||||||
this.isHost = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("PORT")) {
|
|
||||||
this.isPort = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("DATABASE")) {
|
|
||||||
this.isDatabase = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("USER")) {
|
|
||||||
this.isUser = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("PASSWD")) {
|
|
||||||
this.isPasswd = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("SERVICEMAP")) {
|
|
||||||
this.isServicemap = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("OPTION")) {
|
|
||||||
this.isOption = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("NAMESPACE")) {
|
|
||||||
this.isNamespace = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("USENS")) {
|
|
||||||
this.isUseNS = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("DOCINDENT")) {
|
|
||||||
this.isDocIndent = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("DEFAULTMAXFEATURES")) {
|
|
||||||
this.isDefaultMaxFeatures = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("ENCRYPTION")) {
|
|
||||||
this.isEncryption = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (this.isLog)
|
catch (FileNotFoundException e) {
|
||||||
{
|
System.out.println("Fail :: Configuration Fil is not exist... :: " + e);
|
||||||
if (qName.equalsIgnoreCase("DIR")) {
|
return false;
|
||||||
this.isLogDir = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("LEVEL")) {
|
|
||||||
this.isLogLevel = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("REQUEST")) {
|
|
||||||
this.isLogRequest = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("CACHE")) {
|
|
||||||
this.isLogCache = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("TYPE")) {
|
|
||||||
this.isLogCacheType = true;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("VALUE")) {
|
|
||||||
this.isLogCacheValue = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (this.isAdmin)
|
catch (ParserConfigurationException e) {
|
||||||
{
|
System.out.println("Fail :: parsing Configuration File... :: " + e);
|
||||||
if (qName.equalsIgnoreCase("SECUREKEY")) {
|
return false;
|
||||||
this.isSecure_key = true;
|
}
|
||||||
}
|
catch (SAXException e) {
|
||||||
else if (qName.equalsIgnoreCase("STYLEKEY")) {
|
System.out.println("Fail :: parsing Configuration File... :: " + e);
|
||||||
this.isStyle_key = true;
|
return false;
|
||||||
}
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.out.println("Fail :: loading Configuration File... :: " + e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("Fail :: can't access Configuration File... :: " + e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("******************************");
|
||||||
|
System.out.println("Init Logging Service");
|
||||||
|
System.out.println("******************************");
|
||||||
|
LogMngr.getInstance().initLog(this.confMap);
|
||||||
|
System.out.println("Success :: Starting Logging Service!!!");
|
||||||
|
if (LogMngr.getInstance().getLogDirctory() != null) {
|
||||||
|
LogMngr.getInstance().logInfo("[CACHE]", "------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[CACHE]", "Init log cache service");
|
||||||
|
LogMngr.getInstance().logInfo("[CACHE]", "------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[CACHE]", "");
|
||||||
|
LogCacheManager.getInstance().start(this.confMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("Fail :: Stop Logging Service..." + e.getMessage());
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "Server loading... ");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[LICENSE]", "--------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[LICENSE]", "Check License");
|
||||||
|
LogMngr.getInstance().logInfo("[LICENSE]", "--------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[LICENSE]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Initialize ServiceMap");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
||||||
|
try {
|
||||||
|
ServerContext.initMap((String)((String)this.confMap.get("conf.xml.map.servicemap")), (String)((String)this.confMap.get("conf.xml.map.namespace")));
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Now use this ServiceMap :: [" + ServerContext.getMap().getName() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Now use this NameSpace :: [" + ServerContext.getMap().getNameSpace() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Now use this NameSpaceURI :: [" + ServerContext.getMap().getNameSpaceURI() + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Stop Server :: ServiceMap is not availiable. ::" + e.getMessage());
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
this.stopServer();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "");
|
||||||
|
try {
|
||||||
|
ServerContext.initLayers();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Stop Server :: Initializing Layer Fail ::" + e.getMessage());
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "==========================================");
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "");
|
||||||
|
this.stopServer();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "Server Starting...");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopServer() {
|
||||||
|
ServerContext.initOptions();
|
||||||
|
O2DSMngr.disposeStores();
|
||||||
|
ConnMngr connMngr = ConnMngr.getInstance();
|
||||||
|
connMngr.closeConn();
|
||||||
|
LogCacheManager.getInstance().stop();
|
||||||
|
RenderMngr.disposeRenderingPool();
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void loadConf() throws Exception {
|
||||||
|
if (this.confMap == null) {
|
||||||
|
this.confMap = new HashMap();
|
||||||
|
} else {
|
||||||
|
this.confMap.clear();
|
||||||
|
}
|
||||||
|
ServerContext.initOptions();
|
||||||
|
File confFile = new File(ServerContext.getConfFolder(), "/server_conf.xml");
|
||||||
|
System.out.println("Configuration File Location :: " + confFile.getAbsolutePath());
|
||||||
|
if (!confFile.exists()) {
|
||||||
|
throw new FileNotFoundException("Configuration File is not exist [" + confFile.getAbsolutePath() + "]");
|
||||||
|
}
|
||||||
|
System.out.println("Now try parse Configuration File");
|
||||||
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
|
SAXParser parser = factory.newSAXParser();
|
||||||
|
ConfParserHandler handler = new ConfParserHandler();
|
||||||
|
parser.parse(confFile, (DefaultHandler)handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<String> getMapList() throws Exception {
|
||||||
|
HashSet<String> mapList = new HashSet<String>();
|
||||||
|
Connection connection = null;
|
||||||
|
Statement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
connection = ConnMngr.getInstance().openConn();
|
||||||
|
stmt = connection.createStatement();
|
||||||
|
String sql = "SELECT MAP_NAME FROM O2MAP_SERVICE_INFO";
|
||||||
|
LogMngr.getInstance().logDebug("[MAP]", "Load MapList :: SQL > " + sql);
|
||||||
|
rs = stmt.executeQuery(sql);
|
||||||
|
if (rs != null) {
|
||||||
|
while (rs.next()) {
|
||||||
|
String mapName = rs.getString(1);
|
||||||
|
if (ServerUtil.isNullString((String)mapName)) {
|
||||||
|
LogMngr.getInstance().logDebug("[MAP]", "Skip this layer :: MAP_NAME is NULL");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!mapList.add(mapName.trim().toUpperCase())) continue;
|
||||||
|
LogMngr.getInstance().logDebug("[MAP]", "Add MAP_NAME [" + mapList.size() + "/" + mapName.trim().toUpperCase() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mapList.size() == 0) {
|
||||||
|
throw new Exception("Map Count is [0]");
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Success to load MapList :: Map Count is [" + mapList.size() + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[MAP]", "Fail to load MapList :: " + e.getMessage());
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable throwable) {
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
|
ConnMngr.getInstance().closeSafe(stmt);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
ConnMngr.getInstance().closeConn();
|
||||||
|
ConnMngr.getInstance().closeSafe(stmt);
|
||||||
|
ConnMngr.getInstance().closeSafe(rs);
|
||||||
|
return mapList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Object> getConfMap() {
|
||||||
|
return this.confMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConfParserHandler
|
||||||
|
extends DefaultHandler {
|
||||||
|
boolean isServer = false;
|
||||||
|
boolean isMap = false;
|
||||||
|
boolean isDbtype = false;
|
||||||
|
boolean isHost = false;
|
||||||
|
boolean isPort = false;
|
||||||
|
boolean isDatabase = false;
|
||||||
|
boolean isUser = false;
|
||||||
|
boolean isPasswd = false;
|
||||||
|
boolean isServicemap = false;
|
||||||
|
boolean isOption = false;
|
||||||
|
boolean isNamespace = false;
|
||||||
|
boolean isUseNS = false;
|
||||||
|
boolean isDocIndent = false;
|
||||||
|
boolean isDefaultMaxFeatures = false;
|
||||||
|
boolean isEncryption = false;
|
||||||
|
boolean isLog = false;
|
||||||
|
boolean isLogDir = false;
|
||||||
|
boolean isLogLevel = false;
|
||||||
|
boolean isLogRequest = false;
|
||||||
|
boolean isLogCache = false;
|
||||||
|
boolean isLogCacheType = false;
|
||||||
|
boolean isLogCacheValue = false;
|
||||||
|
boolean isAdmin = false;
|
||||||
|
boolean isSecure_key = false;
|
||||||
|
boolean isStyle_key = false;
|
||||||
|
|
||||||
|
ConfParserHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qName.equalsIgnoreCase("MAP")) {
|
@Override
|
||||||
this.isMap = true;
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||||
}
|
if (this.isServer) {
|
||||||
else if (qName.equalsIgnoreCase("LOG")) {
|
if (this.isMap) {
|
||||||
this.isLog = true;
|
if (qName.equalsIgnoreCase("DBTYPE")) {
|
||||||
}
|
this.isDbtype = true;
|
||||||
else if (qName.equalsIgnoreCase("ADMIN")) {
|
} else if (qName.equalsIgnoreCase("HOST")) {
|
||||||
this.isAdmin = true;
|
this.isHost = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("PORT")) {
|
||||||
|
this.isPort = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("DATABASE")) {
|
||||||
|
this.isDatabase = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("USER")) {
|
||||||
|
this.isUser = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("PASSWD")) {
|
||||||
|
this.isPasswd = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("SERVICEMAP")) {
|
||||||
|
this.isServicemap = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("OPTION")) {
|
||||||
|
this.isOption = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("NAMESPACE")) {
|
||||||
|
this.isNamespace = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("USENS")) {
|
||||||
|
this.isUseNS = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("DOCINDENT")) {
|
||||||
|
this.isDocIndent = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("DEFAULTMAXFEATURES")) {
|
||||||
|
this.isDefaultMaxFeatures = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("ENCRYPTION")) {
|
||||||
|
this.isEncryption = true;
|
||||||
|
}
|
||||||
|
} else if (this.isLog) {
|
||||||
|
if (qName.equalsIgnoreCase("DIR")) {
|
||||||
|
this.isLogDir = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("LEVEL")) {
|
||||||
|
this.isLogLevel = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("REQUEST")) {
|
||||||
|
this.isLogRequest = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("CACHE")) {
|
||||||
|
this.isLogCache = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("TYPE")) {
|
||||||
|
this.isLogCacheType = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("VALUE")) {
|
||||||
|
this.isLogCacheValue = true;
|
||||||
|
}
|
||||||
|
} else if (this.isAdmin) {
|
||||||
|
if (qName.equalsIgnoreCase("SECUREKEY")) {
|
||||||
|
this.isSecure_key = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("STYLEKEY")) {
|
||||||
|
this.isStyle_key = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (qName.equalsIgnoreCase("MAP")) {
|
||||||
|
this.isMap = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("LOG")) {
|
||||||
|
this.isLog = true;
|
||||||
|
} else if (qName.equalsIgnoreCase("ADMIN")) {
|
||||||
|
this.isAdmin = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (qName.equalsIgnoreCase("SERVER")) {
|
||||||
|
this.isServer = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (this.isServer) {
|
||||||
|
if (this.isMap) {
|
||||||
|
if (qName.equalsIgnoreCase("DBTYPE")) {
|
||||||
|
this.isDbtype = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("HOST")) {
|
||||||
|
this.isHost = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("PORT")) {
|
||||||
|
this.isPort = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("DATABASE")) {
|
||||||
|
this.isDatabase = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("USER")) {
|
||||||
|
this.isUser = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("PASSWD")) {
|
||||||
|
this.isPasswd = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("SERVICEMAP")) {
|
||||||
|
this.isServicemap = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("OPTION")) {
|
||||||
|
this.isOption = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("NAMESPACE")) {
|
||||||
|
this.isNamespace = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("USENS")) {
|
||||||
|
this.isUseNS = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("DOCINDENT")) {
|
||||||
|
this.isDocIndent = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("DEFAULTMAXFEATURES")) {
|
||||||
|
this.isDefaultMaxFeatures = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("ENCRYPTION")) {
|
||||||
|
this.isEncryption = false;
|
||||||
|
}
|
||||||
|
} else if (this.isLog) {
|
||||||
|
if (qName.equalsIgnoreCase("DIR")) {
|
||||||
|
this.isLogDir = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("LEVEL")) {
|
||||||
|
this.isLogLevel = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("REQUEST")) {
|
||||||
|
this.isLogRequest = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("CACHE")) {
|
||||||
|
this.isLogCache = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("TYPE")) {
|
||||||
|
this.isLogCacheType = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("VALUE")) {
|
||||||
|
this.isLogCacheValue = false;
|
||||||
|
}
|
||||||
|
} else if (this.isAdmin) {
|
||||||
|
if (qName.equalsIgnoreCase("SECUREKEY")) {
|
||||||
|
this.isSecure_key = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("STYLEKEY")) {
|
||||||
|
this.isStyle_key = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (qName.equalsIgnoreCase("MAP")) {
|
||||||
|
this.isMap = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("LOG")) {
|
||||||
|
this.isLog = false;
|
||||||
|
} else if (qName.equalsIgnoreCase("ADMIN")) {
|
||||||
|
this.isAdmin = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (qName.equalsIgnoreCase("SERVER")) {
|
||||||
|
this.isServer = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (qName.equalsIgnoreCase("SERVER"))
|
@Override
|
||||||
this.isServer = true;
|
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||||
|
if (this.isServer) {
|
||||||
|
if (this.isMap) {
|
||||||
|
if (this.isDbtype) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.dbtype", new String(ch, start, length));
|
||||||
|
} else if (this.isHost) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.host", new String(ch, start, length));
|
||||||
|
} else if (this.isPort) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.port", new String(ch, start, length));
|
||||||
|
} else if (this.isDatabase) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.database", new String(ch, start, length));
|
||||||
|
} else if (this.isUser) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.user", new String(ch, start, length));
|
||||||
|
} else if (this.isPasswd) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.passwd", new String(ch, start, length));
|
||||||
|
} else if (this.isServicemap) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.servicemap", new String(ch, start, length));
|
||||||
|
} else if (this.isNamespace) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.namespace", new String(ch, start, length));
|
||||||
|
} else if (this.isUseNS) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.usedefaultnsprefix", new String(ch, start, length));
|
||||||
|
} else if (this.isDocIndent) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.docindent", new String(ch, start, length));
|
||||||
|
} else if (this.isDefaultMaxFeatures) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.default.max.features", new String(ch, start, length));
|
||||||
|
} else if (this.isEncryption) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.map.encryption", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
} else if (this.isLog) {
|
||||||
|
if (this.isLogDir) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.dir", new String(ch, start, length));
|
||||||
|
} else if (this.isLogLevel) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.level", new String(ch, start, length));
|
||||||
|
} else if (this.isLogRequest) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.request", new String(ch, start, length));
|
||||||
|
} else if (this.isLogCacheType) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.cache.type", new String(ch, start, length));
|
||||||
|
} else if (this.isLogCacheValue) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.log.cache.value", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
} else if (this.isAdmin) {
|
||||||
|
if (this.isSecure_key) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.admin.secure.key", new String(ch, start, length));
|
||||||
|
} else if (this.isStyle_key) {
|
||||||
|
ServerConfiguration.this.confMap.put("conf.xml.admin.style.key", new String(ch, start, length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endElement(String uri, String localName, String qName)
|
|
||||||
throws SAXException
|
|
||||||
{
|
|
||||||
if (this.isServer)
|
|
||||||
{
|
|
||||||
if (this.isMap)
|
|
||||||
{
|
|
||||||
if (qName.equalsIgnoreCase("DBTYPE")) {
|
|
||||||
this.isDbtype = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("HOST")) {
|
|
||||||
this.isHost = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("PORT")) {
|
|
||||||
this.isPort = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("DATABASE")) {
|
|
||||||
this.isDatabase = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("USER")) {
|
|
||||||
this.isUser = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("PASSWD")) {
|
|
||||||
this.isPasswd = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("SERVICEMAP")) {
|
|
||||||
this.isServicemap = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("OPTION")) {
|
|
||||||
this.isOption = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("NAMESPACE")) {
|
|
||||||
this.isNamespace = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("USENS")) {
|
|
||||||
this.isUseNS = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("DOCINDENT")) {
|
|
||||||
this.isDocIndent = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("DEFAULTMAXFEATURES")) {
|
|
||||||
this.isDefaultMaxFeatures = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("ENCRYPTION")) {
|
|
||||||
this.isEncryption = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.isLog)
|
|
||||||
{
|
|
||||||
if (qName.equalsIgnoreCase("DIR")) {
|
|
||||||
this.isLogDir = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("LEVEL")) {
|
|
||||||
this.isLogLevel = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("REQUEST")) {
|
|
||||||
this.isLogRequest = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("CACHE")) {
|
|
||||||
this.isLogCache = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("TYPE")) {
|
|
||||||
this.isLogCacheType = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("VALUE")) {
|
|
||||||
this.isLogCacheValue = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.isAdmin)
|
|
||||||
{
|
|
||||||
if (qName.equalsIgnoreCase("SECUREKEY")) {
|
|
||||||
this.isSecure_key = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("STYLEKEY")) {
|
|
||||||
this.isStyle_key = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qName.equalsIgnoreCase("MAP")) {
|
|
||||||
this.isMap = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("LOG")) {
|
|
||||||
this.isLog = false;
|
|
||||||
}
|
|
||||||
else if (qName.equalsIgnoreCase("ADMIN")) {
|
|
||||||
this.isAdmin = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qName.equalsIgnoreCase("SERVER"))
|
|
||||||
this.isServer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void characters(char[] ch, int start, int length)
|
|
||||||
throws SAXException
|
|
||||||
{
|
|
||||||
if (this.isServer)
|
|
||||||
{
|
|
||||||
if (this.isMap)
|
|
||||||
{
|
|
||||||
if (this.isDbtype) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.dbtype", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isHost) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.host", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isPort) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.port", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isDatabase) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.database", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isUser) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.user", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isPasswd) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.passwd", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isServicemap) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.servicemap", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isNamespace) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.namespace", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isUseNS) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.usedefaultnsprefix", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isDocIndent) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.docindent", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isDefaultMaxFeatures) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.default.max.features", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isEncryption) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.map.encryption", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.isLog)
|
|
||||||
{
|
|
||||||
if (this.isLogDir) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.log.dir", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isLogLevel) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.log.level", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isLogRequest) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.log.request", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isLogCacheType) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.log.cache.type", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isLogCacheValue) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.log.cache.value", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.isAdmin)
|
|
||||||
{
|
|
||||||
if (this.isSecure_key) {
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.admin.secure.key", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
else if (this.isStyle_key)
|
|
||||||
ServerConfiguration.this.confMap.put("conf.xml.admin.style.key", new String(ch, start, length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -314,7 +314,7 @@ public class ServerContext
|
||||||
layerName = layerName.trim().toUpperCase();
|
layerName = layerName.trim().toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList layers = getMap().getAllLayers();
|
ArrayList<Layer> layers = getMap().getAllLayers();
|
||||||
for (Layer layer : layers)
|
for (Layer layer : layers)
|
||||||
{
|
{
|
||||||
if ((layerName == null) ||
|
if ((layerName == null) ||
|
||||||
|
|
@ -511,9 +511,10 @@ public class ServerContext
|
||||||
|
|
||||||
public static boolean isUseNSPrefix()
|
public static boolean isUseNSPrefix()
|
||||||
{
|
{
|
||||||
if (useNSPrefix == null)
|
if (useNSPrefix == null) {
|
||||||
{
|
ServerConfiguration sc =ServerConfiguration.getInstance();
|
||||||
String useNS = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.map.usedefaultnsprefix");
|
HashMap<String, Object> confMap = sc.getConfMap();
|
||||||
|
String useNS = (String)confMap.get("conf.xml.map.usedefaultnsprefix");
|
||||||
|
|
||||||
if (ServerUtil.isNullString(useNS))
|
if (ServerUtil.isNullString(useNS))
|
||||||
useNSPrefix = Boolean.valueOf(true);
|
useNSPrefix = Boolean.valueOf(true);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,422 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
public class ServerInfoService
|
||||||
|
extends AbstractService {
|
||||||
|
private static final long serialVersionUID = 2014061020420430L;
|
||||||
|
private static final String INFO_FILE = "/info.xml";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String parseQuery(HttpServletRequest req) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String doProcess(String str) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
this.doPost(req, resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
HashMap<String, String> reqMap = new HashMap<String, String>();
|
||||||
|
PluginUtil.refineRequestMap((HttpServletRequest)req, reqMap);
|
||||||
|
String reqType = (String)reqMap.get("TYPE");
|
||||||
|
if (reqType == null) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Request Type is NULL.");
|
||||||
|
this.writeResponse((ServletResponse)resp, "Fail", "Request Type is NULL.");
|
||||||
|
} else if (reqType.equalsIgnoreCase("INFO")) {
|
||||||
|
this.doInfo((ServletResponse)resp);
|
||||||
|
} else if (reqType.equalsIgnoreCase("CHANGEMAP")) {
|
||||||
|
this.doChangeMap(reqMap, (ServletResponse)resp);
|
||||||
|
} else if (reqType.equalsIgnoreCase("CURRENTMAP")) {
|
||||||
|
this.doCurrentMap((ServletResponse)resp);
|
||||||
|
} else if (reqType.equalsIgnoreCase("RELOADLAYER")) {
|
||||||
|
this.doReloadLayer(reqMap, (ServletResponse)resp);
|
||||||
|
} else if (reqType.equalsIgnoreCase("RELOADCRS")) {
|
||||||
|
this.doReloadCRS(reqMap, (ServletResponse)resp);
|
||||||
|
} else if (reqType.equalsIgnoreCase("RESTARTSERVER")) {
|
||||||
|
try {
|
||||||
|
this.doRestartServer(reqMap, (ServletResponse)resp);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else if (reqType.equalsIgnoreCase("RELOADSTYLE")) {
|
||||||
|
this.doReloadStyle(reqMap, (ServletResponse)resp);
|
||||||
|
} else if (reqType.equalsIgnoreCase("REMOVEIMAGECACHE")) {
|
||||||
|
this.doRemoveImageCache(reqMap, (ServletResponse)resp);
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Request Type [" + reqType + "] is not support.");
|
||||||
|
this.writeResponse((ServletResponse)resp, "Fail", "Request Type [" + reqType + "] is not support.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doInfo(ServletResponse resp) {
|
||||||
|
if (!ServerInfo.getInstance().isStarted()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "O2Map Web is not ready. Please check up server configurations or start server.");
|
||||||
|
this.writeResponse(resp, "Fail", "O2Map Web is not ready. Please check up server configurations and restart server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ServerInfo.getInstance().isReStarting()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Server is busy to restart. Please wait to restart.");
|
||||||
|
this.writeResponse(resp, "Fail", "Server is busy to restart. Please wait to restart.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "Get Server Information");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "-------------------------------------------");
|
||||||
|
this.writeServerInfo(resp);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Fail to write Server Information. :: " + e);
|
||||||
|
this.writeResponse(resp, "Fail", "Fail to write Server Information. :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doChangeMap(Map<String, String> reqMap, ServletResponse resp) {
|
||||||
|
if (!ServerInfo.getInstance().isStarted()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "O2Map Web is not ready. Please check up server configurations or start server.");
|
||||||
|
this.writeResponse(resp, "Fail", "O2Map Web is not ready. Please check up server configurations and restart server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ServerInfo.getInstance().isReStarting()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Server is busy to restart. Please wait to restart.");
|
||||||
|
this.writeResponse(resp, "Fail", "Server is busy to restart. Please wait to restart.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.checkAdminSecureKey(reqMap.get("SECUREKEY")).booleanValue()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
this.writeResponse(resp, "Fail", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String serviceMap = reqMap.get("SERVICEMAP");
|
||||||
|
String nameSpace = reqMap.get("NAMESPACE");
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Change ServiceMap");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
||||||
|
ServerContext.changeMap((String)serviceMap, (String)nameSpace);
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Success to change ServiceMap.");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Now use this ServiceMap :: [" + ServerContext.getMap().getName() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Now use this NameSpace :: [" + ServerContext.getMap().getNameSpace() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Now use this NameSpaceURI :: [" + ServerContext.getMap().getNameSpaceURI() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "");
|
||||||
|
this.writeResponse(resp, "Success", "Success to change ServiceMap. Now use this serviceMap [" + ServerContext.getMap().getName() + "] :: NameSpace[" + ServerContext.getMap().getNameSpace() + " / " + ServerContext.getMap().getNameSpaceURI() + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[MAP]", "Fail to change ServiceMap. Now use previous serviceMap. :: " + e);
|
||||||
|
this.writeResponse(resp, "Fail", "Fail to change ServiceMap. Now use previous serviceMap. :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doCurrentMap(ServletResponse resp) {
|
||||||
|
if (!ServerInfo.getInstance().isStarted()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "O2Map Web is not ready. Please check up server configurations or start server.");
|
||||||
|
this.writeResponse(resp, "Fail", "O2Map Web is not ready. Please check up server configurations and restart server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ServerInfo.getInstance().isReStarting()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Server is busy to restart. Please wait to restart.");
|
||||||
|
this.writeResponse(resp, "Fail", "Server is busy to restart. Please wait to restart.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "Get Current Map Infomation");
|
||||||
|
LogMngr.getInstance().logInfo("[MAP]", "-------------------------------------------");
|
||||||
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||||
|
Document doc = docBuilder.newDocument();
|
||||||
|
Element rootElement = doc.createElement("SERVERINFO");
|
||||||
|
doc.appendChild(rootElement);
|
||||||
|
Element mapName = doc.createElement("MAPNAME");
|
||||||
|
mapName.appendChild(doc.createTextNode(ServerContext.getMap().getName()));
|
||||||
|
rootElement.appendChild(mapName);
|
||||||
|
Element nameSpace = doc.createElement("NAMESPACE");
|
||||||
|
nameSpace.appendChild(doc.createTextNode(String.valueOf(ServerContext.getMap().getNameSpace()) + " : " + ServerContext.getMap().getNameSpaceURI()));
|
||||||
|
rootElement.appendChild(nameSpace);
|
||||||
|
Transformer xformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
if (ServerContext.getDocIndent() > 0) {
|
||||||
|
xformer.setOutputProperty("indent", "yes");
|
||||||
|
xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", ServerContext.getDocIndent().toString());
|
||||||
|
}
|
||||||
|
resp.setContentType("text/xml; charset=UTF-8");
|
||||||
|
xformer.transform(new DOMSource(doc), new StreamResult((OutputStream)resp.getOutputStream()));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[MAP]", "Fail to write CurrentMap Information. :: " + e);
|
||||||
|
this.writeResponse(resp, "Fail", "Fail to write CurrentMap Information. :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doReloadLayer(Map<String, String> reqMap, ServletResponse resp) {
|
||||||
|
if (!ServerInfo.getInstance().isStarted()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "O2Map Web is not ready. Please check up server configurations or start server.");
|
||||||
|
this.writeResponse(resp, "Fail", "O2Map Web is not ready. Please check up server configurations and restart server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ServerInfo.getInstance().isReStarting()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Server is busy to restart. Please wait to restart.");
|
||||||
|
this.writeResponse(resp, "Fail", "Server is busy to restart. Please wait to restart.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.checkAdminSecureKey(reqMap.get("SECUREKEY")).booleanValue()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
this.writeResponse(resp, "Fail", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Reload ServiceLayer");
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Reload from this ServiceMap :: [" + ServerContext.getMap().getName() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Reload from this NameSpace :: [" + ServerContext.getMap().getNameSpace() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Reload from this NameSpaceURI :: [" + ServerContext.getMap().getNameSpaceURI() + "]");
|
||||||
|
ServerContext.reloadLayers();
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "Success to reload ServiceLayer.");
|
||||||
|
LogMngr.getInstance().logInfo("[LAYER]", "");
|
||||||
|
this.writeResponse(resp, "Success", "Success to reload ServiceLayer. Now use this serviceMap [" + ServerContext.getMap().getName() + "] :: NameSpace[" + ServerContext.getMap().getNameSpace() + " / " + ServerContext.getMap().getNameSpaceURI() + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Fail to reload ServiceLayer. Now use previous serviceLayer. :: " + e);
|
||||||
|
this.writeResponse(resp, "Fail", "Fail to reload ServiceLayer. Now use previous serviceLayer. :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doReloadCRS(Map<String, String> reqMap, ServletResponse resp) {
|
||||||
|
if (!ServerInfo.getInstance().isStarted()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "O2Map Web is not ready. Please check up server configurations or start server.");
|
||||||
|
this.writeResponse(resp, "Fail", "O2Map Web is not ready. Please check up server configurations and restart server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ServerInfo.getInstance().isReStarting()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Server is busy to restart. Please wait to restart.");
|
||||||
|
this.writeResponse(resp, "Fail", "Server is busy to restart. Please wait to restart.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.checkAdminSecureKey(reqMap.get("SECUREKEY")).booleanValue()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
this.writeResponse(resp, "Fail", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "Reload ServiceCRS");
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "-------------------------------------------");
|
||||||
|
CRSMngr.reloadServiceCRS((boolean)true);
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "Success to reload ServiceCRS.");
|
||||||
|
LogMngr.getInstance().logInfo("[CRS]", "");
|
||||||
|
this.writeResponse(resp, "Success", "Success to reload ServiceCRS.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[CRS]", "Fail to reload ServiceCRS. :: " + e);
|
||||||
|
this.writeResponse(resp, "Fail", "Fail to reload ServiceCRS. :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doRestartServer(Map<String, String> reqMap, ServletResponse resp) throws Exception {
|
||||||
|
if (ServerInfo.getInstance().isReStarting()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Server is busy to restart. Please wait to restart.");
|
||||||
|
this.writeResponse(resp, "Fail", "Server is busy to restart. Please wait to restart.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.checkAdminSecureKey(reqMap.get("SECUREKEY")).booleanValue()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
this.writeResponse(resp, "Fail", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ServerInfo.getInstance().setReStarting(true);
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "Restart Server");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "-------------------------------------------");
|
||||||
|
CRSMngr.reloadServiceCRS((boolean)false);
|
||||||
|
if (ServerConfiguration.getInstance().startServer()) {
|
||||||
|
ServerInfo.getInstance().setStarted(true);
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "Success to restart O2Map Web");
|
||||||
|
this.writeResponse(resp, "Success", "Success to restart O2Map Web");
|
||||||
|
} else {
|
||||||
|
ServerInfo.getInstance().setStarted(false);
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Fail to restart O2Map Web :: Please check up server configurations and restart server.");
|
||||||
|
this.writeResponse(resp, "Fail", "Fail to restart O2Map Web :: Please check up server configurations and restart server.");
|
||||||
|
}
|
||||||
|
ServiceMngr.initServices();
|
||||||
|
ServerInfo.getInstance().setReStarting(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doReloadStyle(Map<String, String> reqMap, ServletResponse resp) {
|
||||||
|
if (!ServerInfo.getInstance().isStarted()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "O2Map Web is not ready. Please check up server configurations or start server.");
|
||||||
|
this.writeResponse(resp, "Fail", "O2Map Web is not ready. Please check up server configurations and restart server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ServerInfo.getInstance().isReStarting()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Server is busy to restart. Please wait to restart.");
|
||||||
|
this.writeResponse(resp, "Fail", "Server is busy to restart. Please wait to restart.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.checkAdminStyleKey(reqMap.get("STYLEKEY")).booleanValue()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Not match or Null StyleKey. Please check up Parameter [StyleKey].");
|
||||||
|
this.writeResponse(resp, "Fail", "Not match or Null StyleKey. Please check up Parameter [StyleKey].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "Reload Style");
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "Reload from this ServiceMap :: [" + ServerContext.getMap().getName() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "Reload from this NameSpace :: [" + ServerContext.getMap().getNameSpace() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "Reload from this NameSpaceURI :: [" + ServerContext.getMap().getNameSpaceURI() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "");
|
||||||
|
String layerName = reqMap.get("LAYER");
|
||||||
|
ServerContext.reloadStyle((String)layerName);
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "Success to reload Style.");
|
||||||
|
LogMngr.getInstance().logInfo("[STYLE]", "");
|
||||||
|
this.writeResponse(resp, "Success", "Success to reload Style");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[STYLE]", "Fail to reload Style. Now use previous style. :: " + e);
|
||||||
|
this.writeResponse(resp, "Fail", "Fail to reload Style. Now use previous style. :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doRemoveImageCache(Map<String, String> reqMap, ServletResponse resp) {
|
||||||
|
if (!ServerInfo.getInstance().isStarted()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "O2Map Web is not ready. Please check up server configurations or start server.");
|
||||||
|
this.writeResponse(resp, "Fail", "O2Map Web is not ready. Please check up server configurations and restart server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ServerInfo.getInstance().isReStarting()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Server is busy to restart. Please wait to restart.");
|
||||||
|
this.writeResponse(resp, "Fail", "Server is busy to restart. Please wait to restart.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.checkAdminSecureKey(reqMap.get("SECUREKEY")).booleanValue()) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
this.writeResponse(resp, "Fail", "Not match or Null SecureKey. Please check up Parameter [SecureKey].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Remove ImageCache");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "-------------------------------------------");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Reload from this ServiceMap :: [" + ServerContext.getMap().getName() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Reload from this NameSpace :: [" + ServerContext.getMap().getNameSpace() + "]");
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Reload from this NameSpaceURI :: [" + ServerContext.getMap().getNameSpaceURI() + "]");
|
||||||
|
String layerName = reqMap.get("LAYER");
|
||||||
|
ImgCacheMngr.removeImgCache((String)layerName);
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "Success to remove ImageCache for this layer :: " + layerName);
|
||||||
|
LogMngr.getInstance().logInfo("[IMGCACHE]", "");
|
||||||
|
this.writeResponse(resp, "Success", "Success to remove ImageCache for this layer :: " + layerName);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[IMGCACHE]", "Fail to remove ImageCache. :: " + e);
|
||||||
|
this.writeResponse(resp, "Fail", "Fail to remove ImageCache. :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeServerInfo(ServletResponse resp) {
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||||
|
Document doc = docBuilder.parse(ServerInfoService.class.getResourceAsStream(INFO_FILE));
|
||||||
|
Transformer xformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
if (ServerContext.getDocIndent() > 0) {
|
||||||
|
xformer.setOutputProperty("indent", "yes");
|
||||||
|
xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", ServerContext.getDocIndent().toString());
|
||||||
|
}
|
||||||
|
resp.setContentType("text/xml; charset=UTF-8");
|
||||||
|
xformer.transform(new DOMSource(doc), new StreamResult((OutputStream)resp.getOutputStream()));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "Do not create XML : " + ServerInfoService.class + " / " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeResponse(ServletResponse resp, String resultStr, String infoStr) {
|
||||||
|
try {
|
||||||
|
Document doc = ServerInfoService.getDocument(resultStr, infoStr);
|
||||||
|
Transformer xformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
if (ServerContext.getDocIndent() > 0) {
|
||||||
|
xformer.setOutputProperty("indent", "yes");
|
||||||
|
xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", ServerContext.getDocIndent().toString());
|
||||||
|
}
|
||||||
|
resp.setContentType("text/xml; charset=UTF-8");
|
||||||
|
xformer.transform(new DOMSource(doc), new StreamResult((OutputStream)resp.getOutputStream()));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "Do not create XML : " + ServerInfoService.class + " / " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Document getDocument(String resultStr, String infoStr) throws ParserConfigurationException {
|
||||||
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||||
|
Document doc = docBuilder.newDocument();
|
||||||
|
Element rootElement = doc.createElement("SERVERINFO");
|
||||||
|
doc.appendChild(rootElement);
|
||||||
|
Element result = doc.createElement("RESULT");
|
||||||
|
result.appendChild(doc.createTextNode(resultStr));
|
||||||
|
rootElement.appendChild(result);
|
||||||
|
Element errorMessage = doc.createElement("INFO");
|
||||||
|
errorMessage.appendChild(doc.createTextNode(infoStr));
|
||||||
|
rootElement.appendChild(errorMessage);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean checkAdminSecureKey(String pwd) {
|
||||||
|
if (ServerUtil.isNullString((String)pwd)) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "ServerInfo Service needs a SecureKey Parameter [SecureKey].");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String key = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.admin.secure.key");
|
||||||
|
key = ServerUtil.isNullString((String)key) ? "O2MapAdminSecureKey" : key.trim();
|
||||||
|
if (key.equals(pwd)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean checkAdminStyleKey(String pwd) {
|
||||||
|
if (ServerUtil.isNullString((String)pwd)) {
|
||||||
|
LogMngr.getInstance().logError("[SERVER]", "ServerInfo Style needs a StyleKey Parameter [StyleKey].");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String key = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.admin.style.key");
|
||||||
|
key = ServerUtil.isNullString((String)key) ? "O2MapAdminStyleKey" : key.trim();
|
||||||
|
if (key.equals(pwd)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,181 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import javax.servlet.RequestDispatcher;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
public class Service
|
||||||
|
extends AbstractService {
|
||||||
|
private static final long serialVersionUID = 2014061008205121L;
|
||||||
|
private static final int SLEEP_TIME = 1000;
|
||||||
|
private static final int MAX_SLEEP_TIME = 20000;
|
||||||
|
|
||||||
|
public String parseQuery(HttpServletRequest req) throws Exception {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String doProcess(String str) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
|
||||||
|
long reqId;
|
||||||
|
block17: {
|
||||||
|
req.setCharacterEncoding("UTF-8");
|
||||||
|
String rootPath = ((HttpServletRequest)req).getContextPath();
|
||||||
|
String serviceName = ((HttpServletRequest)req).getRequestURI().replace(rootPath, "");
|
||||||
|
while (serviceName.endsWith("/")) {
|
||||||
|
serviceName = serviceName.substring(0, serviceName.length() - 1);
|
||||||
|
}
|
||||||
|
reqId = System.currentTimeMillis();
|
||||||
|
if (((HttpServletRequest)req).getMethod().equalsIgnoreCase("GET")) {
|
||||||
|
LogMngr.getInstance().reqInfo("[REQUEST]", "[" + reqId + "] GET, From " + PluginUtil.getClientIP((HttpServletRequest)((HttpServletRequest)req)) + " To " + (serviceName.length() == 0 ? "/" : serviceName) + " , Request : " + ((HttpServletRequest)req).getQueryString());
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().reqInfo("[REQUEST]", "[" + reqId + "] POST, From " + PluginUtil.getClientIP((HttpServletRequest)((HttpServletRequest)req)) + " To " + (serviceName.length() == 0 ? "/" : serviceName) + " , Request : " + ((HttpServletRequest)req).getQueryString());
|
||||||
|
}
|
||||||
|
if (serviceName.length() == 0) {
|
||||||
|
RequestDispatcher dispatcher = req.getRequestDispatcher("index.html");
|
||||||
|
dispatcher.forward(req, resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.isFileService(serviceName)) {
|
||||||
|
File file = new File(this.getServletContext().getRealPath(serviceName));
|
||||||
|
this.writeFileResponse(resp, file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AbstractService service = ServiceMngr.getService((String)serviceName);
|
||||||
|
if (service != null) {
|
||||||
|
if (service instanceof ServerInfoService) {
|
||||||
|
service.service(req, resp);
|
||||||
|
} else if (ServerInfo.getInstance().isStarted()) {
|
||||||
|
if (ServerInfo.getInstance().isReStarting()) {
|
||||||
|
long sleepTile = System.currentTimeMillis();
|
||||||
|
while (true) {
|
||||||
|
if (System.currentTimeMillis() - sleepTile > 20000L) {
|
||||||
|
this.writeFailResponse(resp, "O2Map Web is busy to restart. Waiting time for request has been exceeded. [20/sec]");
|
||||||
|
break block17;
|
||||||
|
}
|
||||||
|
if (!ServerInfo.getInstance().isReStarting()) {
|
||||||
|
service.service(req, resp);
|
||||||
|
break block17;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000L);
|
||||||
|
}
|
||||||
|
catch (InterruptedException interruptedException) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
service.service(req, resp);
|
||||||
|
} else {
|
||||||
|
this.writeFailResponse(resp, "O2Map Web is not ready. Please check up server configurations and restart server.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.writeFailResponse(resp, "Service [" + serviceName + "] is unregistered Service on O2Map Web.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().reqInfo("[RESPONSE]", "[" + reqId + "] is Finish." + "Time : " + new DecimalFormat(".##").format((double)(System.currentTimeMillis() - reqId) / 1000.0) + "/sec");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
super.doGet(req, resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
super.doPost(req, resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isFileService(String uri) {
|
||||||
|
try {
|
||||||
|
File file = new File(this.getServletContext().getRealPath(uri));
|
||||||
|
if (file.exists()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeFileResponse(ServletResponse resp, File file) {
|
||||||
|
try {
|
||||||
|
int length = 0;
|
||||||
|
ServletOutputStream outStream = resp.getOutputStream();
|
||||||
|
String mimetype = this.getServletContext().getMimeType(file.getAbsolutePath());
|
||||||
|
if (mimetype == null) {
|
||||||
|
mimetype = "application/octet-stream";
|
||||||
|
}
|
||||||
|
resp.setContentType(mimetype);
|
||||||
|
resp.setContentLength((int)file.length());
|
||||||
|
byte[] byteBuffer = new byte[1024];
|
||||||
|
FileInputStream in = new FileInputStream(file);
|
||||||
|
while (in != null && (length = in.read(byteBuffer)) != -1) {
|
||||||
|
outStream.write(byteBuffer, 0, length);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
outStream.close();
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "Request file not found. :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "Can't make response output stream. :: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeFailResponse(ServletResponse resp, String msg) {
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", msg);
|
||||||
|
Document doc = Service.getFailDocument(msg);
|
||||||
|
Transformer xformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
if (ServerContext.getDocIndent() > 0) {
|
||||||
|
xformer.setOutputProperty("indent", "yes");
|
||||||
|
xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", ServerContext.getDocIndent().toString());
|
||||||
|
}
|
||||||
|
resp.setContentType("text/xml; charset=UTF-8");
|
||||||
|
xformer.transform(new DOMSource(doc), new StreamResult((OutputStream)resp.getOutputStream()));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "Do not create XML : " + Service.class + " / " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Document getFailDocument(String msg) throws ParserConfigurationException {
|
||||||
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||||
|
Document doc = docBuilder.newDocument();
|
||||||
|
Element rootElement = doc.createElement("SERVER");
|
||||||
|
doc.appendChild(rootElement);
|
||||||
|
Element result = doc.createElement("RESULT");
|
||||||
|
result.appendChild(doc.createTextNode("Fail"));
|
||||||
|
rootElement.appendChild(result);
|
||||||
|
Element errorMessage = doc.createElement("INFO");
|
||||||
|
errorMessage.appendChild(doc.createTextNode(msg));
|
||||||
|
rootElement.appendChild(errorMessage);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroy() {
|
||||||
|
super.destroy();
|
||||||
|
ServerConfiguration.getInstance().stopServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class ServiceMngr {
|
||||||
|
private static ConcurrentHashMap<String, AbstractService> serviceMap = new ConcurrentHashMap<String, AbstractService>();
|
||||||
|
|
||||||
|
public static AbstractService getService(String serviceName) {
|
||||||
|
if (serviceName.contains("/services/wmts")) {
|
||||||
|
return serviceMap.get(serviceName.substring(0, serviceName.indexOf("/services/wmts") + 14));
|
||||||
|
}
|
||||||
|
if (serviceName.contains("/services/tms")) {
|
||||||
|
return serviceMap.get(serviceName.substring(0, serviceName.indexOf("/services/tms") + 13));
|
||||||
|
}
|
||||||
|
return serviceMap.get(serviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public static void addService(String serviceName, AbstractService service) {
|
||||||
|
ConcurrentHashMap<String, AbstractService> concurrentHashMap = serviceMap;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
serviceMap.put(serviceName, service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public static void removeService(String serviceName) {
|
||||||
|
ConcurrentHashMap<String, AbstractService> concurrentHashMap = serviceMap;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
serviceMap.remove(serviceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public static void clearService() {
|
||||||
|
ConcurrentHashMap<String, AbstractService> concurrentHashMap = serviceMap;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
serviceMap.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getServiceList() {
|
||||||
|
return new ArrayList<String>(serviceMap.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void initServices() {
|
||||||
|
LogMngr.getInstance().logInfo("[SERVICE]", "======================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVICE]", "Services Initialization");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVICE]", "======================================");
|
||||||
|
LogMngr.getInstance().logDebug("[SERVICE]", "Exist Services clear all");
|
||||||
|
ServiceMngr.clearService();
|
||||||
|
ServiceMngr.createService("/serverinfo", "geoinfo.map.myMap.ServerInfoService");
|
||||||
|
if (ServerInfo.getInstance().isStarted()) {
|
||||||
|
ServiceMngr.createService("/service", "geoinfo.map.myMap.ServicesService");
|
||||||
|
ServiceMngr.createService("/drilling/map/start.do", "geoinfo.map.myMap.WMSService");
|
||||||
|
ServiceMngr.createService("/drilling/map/wms.do", "geoinfo.map.myMap.WMSService");
|
||||||
|
ServiceMngr.createService("/services/wms", "geoinfo.map.myMap.WMSService");
|
||||||
|
ServiceMngr.createService("/services/wfs", "com.geotwo.webserver.plugin.ows.service.WFSService");
|
||||||
|
ServiceMngr.createService("/services/wcs", "com.geotwo.webserver.plugin.ows.service.WCSService");
|
||||||
|
ServiceMngr.createService("/services/wps", "com.geotwo.webserver.plugin.ows.service.WPSService");
|
||||||
|
ServiceMngr.createService("/services/wmts", "com.geotwo.webserver.plugin.ows.service.WMTSService");
|
||||||
|
ServiceMngr.createService("/services/tms", "com.geotwo.webserver.plugin.ows.service.TMSService");
|
||||||
|
ServiceMngr.createService("/services/uwes", "com.geotwo.webserver.plugin.uwes.service.UWESService");
|
||||||
|
ServiceMngr.createService("/services/o2wps", "com.geotwo.webserver.plugin.o2wps.service.O2WPSService");
|
||||||
|
ServiceMngr.createService("/services/icache", "com.geotwo.webserver.plugin.ows.service.ImgCacheService");
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logInfo("[SERVICE]", "");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "Services Starting...");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "=================================");
|
||||||
|
LogMngr.getInstance().logInfo("[SERVER]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createService(String servicePath, String serviceClass) {
|
||||||
|
Class<?> cls = null;
|
||||||
|
AbstractService inst = null;
|
||||||
|
try {
|
||||||
|
LogMngr.getInstance().logDebug("[SERVICE]", "Crate service :: " + servicePath + ", Class > " + serviceClass);
|
||||||
|
cls = Class.forName(serviceClass);
|
||||||
|
inst = (AbstractService)((Object)cls.newInstance());
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "The service [" + servicePath + "] is not ready :: " + e);
|
||||||
|
}
|
||||||
|
if (inst != null) {
|
||||||
|
ServiceMngr.addService(servicePath, inst);
|
||||||
|
LogMngr.getInstance().logInfo("[SERVICE]", "The service [" + servicePath + "] has been registered.");
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "The service [" + servicePath + "] is not ready :: Service [" + serviceClass + "] instance is null.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
public class ServicesService
|
||||||
|
extends AbstractService {
|
||||||
|
private static final long serialVersionUID = 2652607194424884107L;
|
||||||
|
|
||||||
|
public Object parseQuery(HttpServletRequest req) throws Exception {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String doProcess(String str) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
this.doPost(req, resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
String serviceName = null;
|
||||||
|
Set<String> keyset = req.getParameterMap().keySet();
|
||||||
|
for (String param : keyset) {
|
||||||
|
if (!param.equalsIgnoreCase("SERVICE") || ServerUtil.isNullString((String)(serviceName = req.getParameter(param)))) continue;
|
||||||
|
serviceName = serviceName.trim().toLowerCase();
|
||||||
|
}
|
||||||
|
if (serviceName == null) {
|
||||||
|
this.writeFailResponse((ServletResponse)resp, "Request Parameter [Service] is NULL.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AbstractService service = ServiceMngr.getService((String)("/services/" + serviceName));
|
||||||
|
if (service != null) {
|
||||||
|
service.service((ServletRequest)req, (ServletResponse)resp);
|
||||||
|
} else {
|
||||||
|
this.writeFailResponse((ServletResponse)resp, "Service [" + serviceName + "] is unregistered Service on O2Map Web.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeFailResponse(ServletResponse resp, String msg) {
|
||||||
|
try {
|
||||||
|
Document doc = ServicesService.getFailDocument(msg);
|
||||||
|
XMLUtil.writeToResponse((HttpServletResponse)((HttpServletResponse)resp), (Document)doc);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "Do not create XML : " + Service.class + " / " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Document getFailDocument(String msg) throws ParserConfigurationException {
|
||||||
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||||
|
Document doc = docBuilder.newDocument();
|
||||||
|
Element rootElement = doc.createElement("SERVER");
|
||||||
|
doc.appendChild(rootElement);
|
||||||
|
Element result = doc.createElement("RESULT");
|
||||||
|
result.appendChild(doc.createTextNode("Fail"));
|
||||||
|
rootElement.appendChild(result);
|
||||||
|
Element errorMessage = doc.createElement("INFO");
|
||||||
|
errorMessage.appendChild(doc.createTextNode(msg));
|
||||||
|
rootElement.appendChild(errorMessage);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,265 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import org.geotools.data.DataUtilities;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.shapefile.ShapefileDataStore;
|
||||||
|
import org.geotools.data.shapefile.files.FileReader;
|
||||||
|
import org.geotools.data.shapefile.files.FileWriter;
|
||||||
|
import org.geotools.data.shapefile.files.ShpFileType;
|
||||||
|
import org.geotools.data.shapefile.files.ShpFiles;
|
||||||
|
import org.geotools.data.shapefile.files.StorageFile;
|
||||||
|
import org.geotools.data.shapefile.index.quadtree.Node;
|
||||||
|
import org.geotools.data.shapefile.index.quadtree.QuadTree;
|
||||||
|
import org.geotools.data.shapefile.index.quadtree.StoreException;
|
||||||
|
import org.geotools.data.shapefile.index.quadtree.fs.FileSystemIndexStore;
|
||||||
|
import org.geotools.data.shapefile.shp.IndexFile;
|
||||||
|
import org.geotools.data.shapefile.shp.ShapefileHeader;
|
||||||
|
import org.geotools.data.shapefile.shp.ShapefileReader;
|
||||||
|
|
||||||
|
public class ShpIndexMngr {
|
||||||
|
private static int MAX_FEATURE_SIZE = 1000;
|
||||||
|
private static FileWriter writer = new FileWriter(){
|
||||||
|
|
||||||
|
public String id() {
|
||||||
|
return "ShapeIndexMngr";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static boolean isNeedToMakeIndex(File file) throws Exception {
|
||||||
|
ShpFiles shpFiles = new ShpFiles(file);
|
||||||
|
if (!shpFiles.isLocal()) {
|
||||||
|
throw new IllegalStateException("Only applies if the files are local and the file can be created");
|
||||||
|
}
|
||||||
|
URL indexURL = shpFiles.acquireRead(ShpFileType.QIX, (FileReader)writer);
|
||||||
|
URL shpURL = shpFiles.acquireRead(ShpFileType.SHP, (FileReader)writer);
|
||||||
|
try {
|
||||||
|
long shpLastModified;
|
||||||
|
boolean shpChangedMoreRecently;
|
||||||
|
if (indexURL == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!shpFiles.exists(ShpFileType.SHX) || !shpFiles.exists(ShpFileType.SHP)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
File indexFile = DataUtilities.urlToFile((URL)indexURL);
|
||||||
|
File shpFile = DataUtilities.urlToFile((URL)shpURL);
|
||||||
|
long indexLastModified = indexFile.lastModified();
|
||||||
|
boolean bl = shpChangedMoreRecently = indexLastModified < (shpLastModified = shpFile.lastModified());
|
||||||
|
if (new ShapefileDataStore(shpURL).getCount(Query.FIDS) < (long)MAX_FEATURE_SIZE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean bl2 = !indexFile.exists() || shpChangedMoreRecently;
|
||||||
|
return bl2;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (shpURL != null) {
|
||||||
|
shpFiles.unlockRead(shpURL, (FileReader)writer);
|
||||||
|
}
|
||||||
|
if (indexURL != null) {
|
||||||
|
shpFiles.unlockRead(indexURL, (FileReader)writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createIndex(File file) throws Exception {
|
||||||
|
ShpFiles shpFiles = new ShpFiles(file);
|
||||||
|
new ShapeIndexMaker(shpFiles).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ShapeIndexMaker
|
||||||
|
extends Thread {
|
||||||
|
private int max = -1;
|
||||||
|
private int leafSize = 16;
|
||||||
|
private String byteOrder = "NM";
|
||||||
|
private ShpFiles shpFiles;
|
||||||
|
|
||||||
|
public ShapeIndexMaker(ShpFiles sFiles) {
|
||||||
|
this.shpFiles = sFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "[" + this.shpFiles.getTypeName() + "] ------------------------------");
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "[" + this.shpFiles.getTypeName() + "] Now create ShapeIndex from " + startTime);
|
||||||
|
ShapefileReader reader = null;
|
||||||
|
StorageFile storage = this.shpFiles.getStorageFile(ShpFileType.QIX);
|
||||||
|
File treeFile = storage.getFile();
|
||||||
|
try {
|
||||||
|
reader = new ShapefileReader(this.shpFiles, true, false, new GeometryFactory());
|
||||||
|
if (this.max == -1) {
|
||||||
|
int features = reader.getCount(0);
|
||||||
|
this.max = 1;
|
||||||
|
int nodes = 1;
|
||||||
|
while (nodes * this.leafSize < features) {
|
||||||
|
++this.max;
|
||||||
|
nodes *= 4;
|
||||||
|
}
|
||||||
|
if (this.max < 10) {
|
||||||
|
this.max = 10;
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
reader = new ShapefileReader(this.shpFiles, true, false, new GeometryFactory());
|
||||||
|
}
|
||||||
|
this.buildQuadTree(reader, treeFile);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storage.replaceOriginal();
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "[" + this.shpFiles.getTypeName() + "] Success to create ShapeIndex to " + endTime + " while " + (endTime - startTime) / 1000L + "/sec");
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "[" + this.shpFiles.getTypeName() + "] Now available more faster");
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "[" + this.shpFiles.getTypeName() + "] ------------------------------");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "[" + this.shpFiles.getTypeName() + "] Fail to create ShapeIndex :: " + e);
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "[" + this.shpFiles.getTypeName() + "] Now use old QIX or not use ShapeIndex");
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "[" + this.shpFiles.getTypeName() + "] ------------------------------");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int buildQuadTree(ShapefileReader reader, File file) throws IOException, StoreException {
|
||||||
|
byte order = 0;
|
||||||
|
if (this.byteOrder == null || this.byteOrder.equalsIgnoreCase("NM")) {
|
||||||
|
order = 2;
|
||||||
|
} else if (this.byteOrder.equalsIgnoreCase("NL")) {
|
||||||
|
order = 1;
|
||||||
|
} else {
|
||||||
|
throw new StoreException("Asked byte order '" + this.byteOrder + "' must be 'NL' or 'NM'!");
|
||||||
|
}
|
||||||
|
IndexFile shpIndex = new IndexFile(this.shpFiles, false);
|
||||||
|
QuadTree tree = null;
|
||||||
|
int cnt = 0;
|
||||||
|
int numRecs = shpIndex.getRecordCount();
|
||||||
|
ShapefileHeader header = reader.getHeader();
|
||||||
|
Envelope bounds = new Envelope(header.minX(), header.maxX(), header.minY(), header.maxY());
|
||||||
|
tree = new QuadTree(numRecs, this.max, bounds, shpIndex);
|
||||||
|
try {
|
||||||
|
ShapefileReader.Record rec = null;
|
||||||
|
while (reader.hasNext()) {
|
||||||
|
rec = reader.nextRecord();
|
||||||
|
tree.insert(cnt++, new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY));
|
||||||
|
}
|
||||||
|
FileSystemIndexStore store = new FileSystemIndexStore(file, order);
|
||||||
|
if (this.leafSize > 0) {
|
||||||
|
this.optimizeTree(tree, tree.getRoot(), 0, reader, shpIndex);
|
||||||
|
}
|
||||||
|
store.store(tree);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tree.close();
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node optimizeTree(QuadTree tree, Node node, int level, ShapefileReader reader, IndexFile index) throws StoreException, IOException {
|
||||||
|
int i;
|
||||||
|
if (node.getNumShapeIds() > this.leafSize && node.getNumSubNodes() == 0 && level < this.max * 2) {
|
||||||
|
int[] shapeIds = node.getShapesId();
|
||||||
|
int numShapesId = node.getNumShapeIds();
|
||||||
|
node.clean();
|
||||||
|
int extraLevels = 2;
|
||||||
|
int nodes = 4;
|
||||||
|
while (nodes * this.leafSize < numShapesId) {
|
||||||
|
++extraLevels;
|
||||||
|
nodes *= 4;
|
||||||
|
}
|
||||||
|
int i2 = 0;
|
||||||
|
while (i2 < numShapesId) {
|
||||||
|
int shapeId = shapeIds[i2];
|
||||||
|
int offset = index.getOffsetInBytes(shapeId);
|
||||||
|
reader.goTo(offset);
|
||||||
|
ShapefileReader.Record rec = reader.nextRecord();
|
||||||
|
Envelope env = new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY);
|
||||||
|
tree.insert(node, shapeId, env, extraLevels);
|
||||||
|
++i2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.pack();
|
||||||
|
int i3 = 0;
|
||||||
|
while (i3 < node.getNumSubNodes()) {
|
||||||
|
this.optimizeTree(tree, node.getSubNode(i3), level + 1, reader, index);
|
||||||
|
++i3;
|
||||||
|
}
|
||||||
|
i3 = 0;
|
||||||
|
while (i3 < node.getNumSubNodes()) {
|
||||||
|
Node child = node.getSubNode(i3);
|
||||||
|
if (child != null && child.getNumShapeIds() == 0 && child.getNumSubNodes() == 0) {
|
||||||
|
node.removeSubNode(child);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++i3;
|
||||||
|
}
|
||||||
|
if (node.getNumSubNodes() == 1 && node.getNumShapeIds() == 0) {
|
||||||
|
Node subnode = node.getSubNode(0);
|
||||||
|
node.clearSubNodes();
|
||||||
|
node.setShapesId(subnode);
|
||||||
|
node.setBounds(subnode.getBounds());
|
||||||
|
i = 0;
|
||||||
|
while (i < subnode.getNumSubNodes()) {
|
||||||
|
node.addSubNode(subnode.getSubNode(i));
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int i4;
|
||||||
|
Envelope bounds = new Envelope();
|
||||||
|
if (node.getNumShapeIds() > 0) {
|
||||||
|
int[] shapeIds = node.getShapesId();
|
||||||
|
i4 = 0;
|
||||||
|
while (i4 < shapeIds.length) {
|
||||||
|
int shapeId = shapeIds[i4];
|
||||||
|
int offset = index.getOffsetInBytes(shapeId);
|
||||||
|
reader.goTo(offset);
|
||||||
|
ShapefileReader.Record rec = reader.nextRecord();
|
||||||
|
Envelope env = new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY);
|
||||||
|
bounds.expandToInclude(env);
|
||||||
|
++i4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (node.getNumSubNodes() > 0) {
|
||||||
|
i = 0;
|
||||||
|
while (i < node.getNumSubNodes()) {
|
||||||
|
bounds.expandToInclude(node.getSubNode(i).getBounds());
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.setBounds(bounds);
|
||||||
|
int count = node.getNumShapeIds();
|
||||||
|
i4 = 0;
|
||||||
|
while (i4 < node.getNumSubNodes()) {
|
||||||
|
Node child = node.getSubNode(i4);
|
||||||
|
if (child.getNumSubNodes() > 0) {
|
||||||
|
count = Integer.MAX_VALUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
count += child.getNumShapeIds();
|
||||||
|
++i4;
|
||||||
|
}
|
||||||
|
if (count < this.leafSize) {
|
||||||
|
i4 = 0;
|
||||||
|
while (i4 < node.getNumSubNodes()) {
|
||||||
|
Node child = node.getSubNode(i4);
|
||||||
|
int[] shapesId = child.getShapesId();
|
||||||
|
int j = 0;
|
||||||
|
while (j < child.getNumShapeIds()) {
|
||||||
|
node.addShapeId(shapesId[j]);
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
++i4;
|
||||||
|
}
|
||||||
|
node.clearSubNodes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class ShpLayerInfo {
|
||||||
|
private String layerName;
|
||||||
|
private boolean activate = false;
|
||||||
|
private CoordinateReferenceSystem layerCRS;
|
||||||
|
private File shapeFile;
|
||||||
|
private String desc;
|
||||||
|
|
||||||
|
public String getLayerName() {
|
||||||
|
return this.layerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActivate() {
|
||||||
|
return this.activate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem getLayerCRS() {
|
||||||
|
return this.layerCRS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getShapeFile() {
|
||||||
|
return this.shapeFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return this.desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerName(String name) {
|
||||||
|
if (ServerUtil.isNullString((String)name)) {
|
||||||
|
this.layerName = null;
|
||||||
|
}
|
||||||
|
this.layerName = name.trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivate(String actiStr) {
|
||||||
|
this.activate = ServerUtil.getBooleanValue((String)actiStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerCRS(String crsName) {
|
||||||
|
this.layerCRS = CRSMngr.getCRS((String)crsName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShapeFile(String shapeFileName) {
|
||||||
|
if (ServerUtil.isNullString((String)shapeFileName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file = new File(shapeFileName.trim());
|
||||||
|
if (file.exists()) {
|
||||||
|
this.shapeFile = file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.shapeFile = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String desc) {
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAvailable() {
|
||||||
|
if (!this.activate) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Layer info [layer.activate] is False");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)this.layerName)) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Layer info [layer.name] is Empty");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.shapeFile == null) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Layer info [layer.file] is not exist");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.layerCRS == null) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Layer info [layer.crs] is not available");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,341 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.shapefile.ShapefileDataStore;
|
||||||
|
import org.geotools.data.shapefile.ShpDataStore;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||||
|
import org.geotools.data.store.ContentFeatureCollection;
|
||||||
|
import org.geotools.factory.Hints;
|
||||||
|
import org.opengis.feature.Feature;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.filter.Id;
|
||||||
|
import org.opengis.filter.identity.GmlObjectId;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class ShpStoreMngr {
|
||||||
|
private static ConcurrentHashMap<String, ShpDataStore> dataStores = new ConcurrentHashMap<String, ShpDataStore>();
|
||||||
|
private static ConcurrentHashMap<String, ShpDataStore> dirtyDataStores;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public static synchronized void initLayers() {
|
||||||
|
ConcurrentHashMap<String, ShpDataStore> concurrentHashMap = dataStores = new ConcurrentHashMap();
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
try {
|
||||||
|
File dir = ServerContext.getPluginsFolder();
|
||||||
|
String fileName = String.valueOf(ServerContext.getMap().getName()) + LayerFactory.LayerType.SHAPE.getPrefix();
|
||||||
|
File confFile = ServerUtil.findFile((File)dir, (String)fileName);
|
||||||
|
if (confFile == null) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Skip create ShapeLayer :: Layer Configuration File [" + confFile + "] is not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "[" + confFile.getName() + "] Now create ShapeLayer from this configuration");
|
||||||
|
ArrayList<ShpLayerInfo> layerInfoList = ShpStoreMngr.parseShapeLayer(confFile);
|
||||||
|
if (layerInfoList == null || layerInfoList.isEmpty()) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "[" + confFile.getName() + "] Fail to create ShapeLayer :: ShapeLayer size is ZERO[0] from this configuration");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (ShpLayerInfo info : layerInfoList) {
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Now create this ShapeLayer");
|
||||||
|
try {
|
||||||
|
ShpStoreMngr.addLayer(info.getShapeFile(), info.getLayerName(), info.getLayerCRS(), info.getDesc());
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Success :: " + "[Map:" + ServerContext.getMap().getName() + "/Layer:" + info.getLayerName() + "] : " + "[RefServer:" + LayerFactory.LayerType.SHAPE.getType() + "/RefSource:" + info.getShapeFile() + "]");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "[" + confFile.getName() + "][" + info.getLayerName() + "] Add Layer Fail :: " + e);
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Create ShapeLayer Fail :: " + e);
|
||||||
|
}
|
||||||
|
if (dataStores.size() == 0) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Create ShapeLayer Fail :: ShapeLayer size is ZERO[0]");
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "Create ShapeLayer Success :: Layer Count is [" + dataStores.size() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FeatureLayer addLayer(File layerFile, String layerName, CoordinateReferenceSystem crs, String desc) throws Exception {
|
||||||
|
if (!layerFile.exists()) {
|
||||||
|
throw new IOException("ShapeLayer data file is not exist [" + layerFile.getAbsolutePath() + "]");
|
||||||
|
}
|
||||||
|
String dataFileName = ServerUtil.getFileName((File)layerFile);
|
||||||
|
if (ServerUtil.isNullString((String)dataFileName)) {
|
||||||
|
throw new IOException("ShapeLayer FileName is not valid [" + dataFileName + "]");
|
||||||
|
}
|
||||||
|
dataFileName = dataFileName.trim().toUpperCase();
|
||||||
|
if (ServerUtil.isNullString((String)layerName)) {
|
||||||
|
throw new IOException("ShapeLayer LayerName is null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ShpDataStore store = ShpStoreMngr.createShpDataStore(layerName, layerFile, crs);
|
||||||
|
dataStores.put(dataFileName, store);
|
||||||
|
AVList params = new AVList();
|
||||||
|
params.setValue("conf.service.map.name", (Object)ServerContext.getMap().getName());
|
||||||
|
params.setValue("conf.service.layer.name", (Object)layerName);
|
||||||
|
params.setValue("conf.service.ref.server", (Object)LayerFactory.LayerType.SHAPE.getType());
|
||||||
|
params.setValue("conf.service.ref.source", (Object)dataFileName);
|
||||||
|
params.setValue("conf.service.ref.crs", (Object)crs);
|
||||||
|
params.setValue("conf.service.sld", null);
|
||||||
|
params.setValue("conf.service.use.cache", (Object)false);
|
||||||
|
params.setValue("conf.service.last.update", null);
|
||||||
|
params.setValue("conf.service.description", (Object)desc);
|
||||||
|
Layer layer = LayerFactory.createLayer((LayerFactory.LayerType)LayerFactory.LayerType.SHAPE, (AVList)params);
|
||||||
|
if (ServerContext.getMap().getServiceLayerSet().isExistLayer(layer.getName())) {
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "[" + layerFile.getName() + "][" + dataFileName + "] Override exist FeatureLayer");
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "[" + layerFile.getName() + "][" + dataFileName + "] Add new FeatureLayer");
|
||||||
|
}
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayer(layer, true);
|
||||||
|
return (FeatureLayer)layer;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
dataStores.remove(dataFileName);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ShpDataStore createShpDataStore(String name, File file, CoordinateReferenceSystem crs) throws Exception {
|
||||||
|
ShpDataStore store = new ShpDataStore(name, file);
|
||||||
|
store.setCharset(Charset.forName("EUC-KR"));
|
||||||
|
store.setBufferCachingEnabled(true);
|
||||||
|
store.setMemoryMapped(false);
|
||||||
|
store.setIndexed(true);
|
||||||
|
store.setIndexCreationEnabled(false);
|
||||||
|
store.forceSchemaCRS(crs);
|
||||||
|
store.setNamespaceURI(ServerContext.getMap().getNameSpaceURI());
|
||||||
|
ContentDataStoreRefinder.refindShapefileDataStore((ShapefileDataStore)store);
|
||||||
|
if (ShpIndexMngr.isNeedToMakeIndex((File)file)) {
|
||||||
|
ShpIndexMngr.createIndex((File)file);
|
||||||
|
}
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArrayList<ShpLayerInfo> parseShapeLayer(File conf) {
|
||||||
|
if (!conf.exists()) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "[" + conf.getName() + "] Create ShapeLayer Fail :: ShapeLayer configuration is not exist");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArrayList<ShpLayerInfo> layerInfoList = new ArrayList<ShpLayerInfo>();
|
||||||
|
ShpLayerInfo lInfo = null;
|
||||||
|
BufferedReader bReader = null;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
String line;
|
||||||
|
bReader = new BufferedReader(new FileReader(conf));
|
||||||
|
while ((line = bReader.readLine()) != null) {
|
||||||
|
if ((line = line.trim()).startsWith("#") || ServerUtil.isNullString((String)line)) continue;
|
||||||
|
try {
|
||||||
|
if (line.equalsIgnoreCase("[LAYER_CONFIG]")) {
|
||||||
|
lInfo = new ShpLayerInfo();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.ACTIVATE")) {
|
||||||
|
lInfo.setActivate(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.NAME")) {
|
||||||
|
lInfo.setLayerName(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.CRS")) {
|
||||||
|
lInfo.setLayerCRS(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.FILE")) {
|
||||||
|
lInfo.setShapeFile(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.DESC")) {
|
||||||
|
lInfo.setDesc(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!line.equalsIgnoreCase("[/LAYER_CONFIG]")) continue;
|
||||||
|
if (lInfo != null && lInfo.isAvailable()) {
|
||||||
|
layerInfoList.add(lInfo);
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "[" + conf.getName() + "] Skip this ShpLayer :: Layer info is not available [" + lInfo.getLayerName() + "]");
|
||||||
|
}
|
||||||
|
lInfo = null;
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "[" + conf.getName() + "] ShapeLayer configuration file is not valid :: " + e.getMessage());
|
||||||
|
try {
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e2) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return layerInfoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void reloadLayer() throws Exception {
|
||||||
|
ArrayList oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.SHAPE);
|
||||||
|
try {
|
||||||
|
dirtyDataStores = dataStores;
|
||||||
|
ShpStoreMngr.initLayers();
|
||||||
|
ShpStoreMngr.disposeDirtyDataStores();
|
||||||
|
LogMngr.getInstance().logInfo("[SHAPE]", "Success to reload ShapeStore.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Fail to reload ShapeStore. Now use previous ShapeStore :: " + e);
|
||||||
|
dataStores = dirtyDataStores;
|
||||||
|
ServerContext.getMap().getServiceLayerSet().addLayers(oldLayers, true);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ShpDataStore getDataStore(String storeName) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)storeName)) {
|
||||||
|
throw new IllegalArgumentException("Parameter StoreName is NULL.");
|
||||||
|
}
|
||||||
|
if (dataStores.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return dataStores.get(storeName.trim().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static synchronized void disposeDirtyDataStores() {
|
||||||
|
if (dirtyDataStores == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (ShpDataStore store : dirtyDataStores.values()) {
|
||||||
|
store.dispose();
|
||||||
|
Object var1_1 = null;
|
||||||
|
}
|
||||||
|
dirtyDataStores.clear();
|
||||||
|
dirtyDataStores = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public static synchronized void disposeDataStores() {
|
||||||
|
if (dataStores.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ConcurrentHashMap<String, ShpDataStore> concurrentHashMap = dataStores;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
for (String storeName : dataStores.keySet()) {
|
||||||
|
ShpDataStore store = dataStores.get(storeName);
|
||||||
|
try {
|
||||||
|
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.SHAPE, LayerFactory.LayerType.SHAPE.getType(), storeName);
|
||||||
|
store.dispose();
|
||||||
|
store = null;
|
||||||
|
dataStores.remove(storeName);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Fail to dispose DataStore :: Can't remove layer linked this DataStore :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
* Enabled aggressive block sorting
|
||||||
|
* Enabled unnecessary exception pruning
|
||||||
|
* Enabled aggressive exception aggregation
|
||||||
|
*/
|
||||||
|
public static synchronized boolean disposeDataStore(String storeName) {
|
||||||
|
if (ServerUtil.isNullString((String)storeName)) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Parameter StoreName is NULL");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (dataStores.isEmpty()) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "DataStore is NULL");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
storeName = storeName.trim().toUpperCase();
|
||||||
|
ConcurrentHashMap<String, ShpDataStore> concurrentHashMap = dataStores;
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
ShpDataStore store = dataStores.get(storeName);
|
||||||
|
if (store == null) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "DataStore [" + storeName + "] is not exist");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.SHAPE, LayerFactory.LayerType.SHAPE.getType(), storeName);
|
||||||
|
store.dispose();
|
||||||
|
store = null;
|
||||||
|
dataStores.remove(storeName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[SHAPE]", "Fail to dispose DataStore :: Can't remove layer linked this DataStore :: " + e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getGmlObject(GmlObjectId id, Hints hints) throws Exception {
|
||||||
|
String[] fids = id.getID().split("\\.");
|
||||||
|
if (fids.length != 2) {
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "Unable to determine store type for GmlObjectId :" + id);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String storeName = fids[0].trim().toUpperCase();
|
||||||
|
ShpDataStore store = ShpStoreMngr.getDataStore(storeName);
|
||||||
|
if (store == null) {
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "DataStore is not exist for GmlObjectId ::" + storeName);
|
||||||
|
throw new IllegalArgumentException("DataStore is not exist for GmlObjectId ::" + storeName);
|
||||||
|
}
|
||||||
|
SimpleFeatureType featureType = store.getSchema(storeName);
|
||||||
|
if (featureType == null) {
|
||||||
|
LogMngr.getInstance().logDebug("[SHAPE]", "No such SHAPE type ::" + storeName);
|
||||||
|
throw new IllegalArgumentException("No such SHAPE type ::" + storeName);
|
||||||
|
}
|
||||||
|
Id filter = StyleMngr.ff.id(Collections.singleton(id));
|
||||||
|
Query query = new Query();
|
||||||
|
query.setFilter((Filter)filter);
|
||||||
|
query.setHints(hints);
|
||||||
|
ContentFeatureCollection features = store.getFeatureSource(storeName).getFeatures(query);
|
||||||
|
if (!features.isEmpty()) {
|
||||||
|
SimpleFeatureIterator fi = features.features();
|
||||||
|
try {
|
||||||
|
if (fi.hasNext()) {
|
||||||
|
Feature feature = fi.next();
|
||||||
|
return feature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
fi.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,453 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||||
|
import com.vividsolutions.jts.geom.LineString;
|
||||||
|
import com.vividsolutions.jts.geom.LinearRing;
|
||||||
|
import com.vividsolutions.jts.io.ParseException;
|
||||||
|
import com.vividsolutions.jts.io.WKBReader;
|
||||||
|
import com.vividsolutions.jts.io.WKBWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Vector;
|
||||||
|
import org.geotools.factory.Hints;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.jdbc.JDBCDataStore;
|
||||||
|
import org.geotools.jdbc.PreparedFilterToSQL;
|
||||||
|
import org.geotools.jdbc.PreparedStatementSQLDialect;
|
||||||
|
import org.opengis.feature.simple.SimpleFeatureType;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.feature.type.GeometryDescriptor;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
|
||||||
|
public class SimpleDialect extends PreparedStatementSQLDialect implements O2SqlDialect {
|
||||||
|
final Vector<String> GEOMETRY_TYPE_MAP = new Vector<String>() {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
final Integer DEFAULT_CRS = Integer.valueOf(4326);
|
||||||
|
|
||||||
|
final String serverName;
|
||||||
|
|
||||||
|
final SimpleSql simpleSQL;
|
||||||
|
|
||||||
|
ThreadLocal<WKBAttributeIO> wkbReader;
|
||||||
|
|
||||||
|
public SimpleDialect(String name, JDBCDataStore dataStore, SimpleSql sql) {
|
||||||
|
super(dataStore);
|
||||||
|
this.wkbReader = new ThreadLocal<WKBAttributeIO>();
|
||||||
|
this.serverName = name;
|
||||||
|
this.simpleSQL = sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> getMapping(ResultSet columnMetaData, Connection cx) throws SQLException {
|
||||||
|
int TABLE_NAME = 3;
|
||||||
|
int COLUMN_NAME = 4;
|
||||||
|
int TYPE_NAME = 6;
|
||||||
|
String typeName = columnMetaData.getString(6).toUpperCase();
|
||||||
|
if (this.GEOMETRY_TYPE_MAP.contains(typeName)) {
|
||||||
|
Class<Geometry> gemetry = lookupGeometryType(columnMetaData, cx);
|
||||||
|
if (gemetry == null)
|
||||||
|
gemetry = Geometry.class;
|
||||||
|
return gemetry;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Class lookupGeometryType(ResultSet columnMetaData, Connection cx) throws SQLException {
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Lookup geometry type for [" + columnMetaData.getString("TABLE_NAME") + "]");
|
||||||
|
String schemaName = columnMetaData.getString("TABLE_SCHEM");
|
||||||
|
String tableName = columnMetaData.getString("TABLE_NAME");
|
||||||
|
String columnName = columnMetaData.getString("COLUMN_NAME");
|
||||||
|
if (schemaName == null || schemaName.equals("")) {
|
||||||
|
schemaName = "";
|
||||||
|
} else {
|
||||||
|
schemaName = String.valueOf(schemaName) + ".";
|
||||||
|
}
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT GEOMETRY_TYPE FROM ");
|
||||||
|
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
|
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||||
|
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next())
|
||||||
|
return O2GeometryTypeMap.lookUpMeta(Integer.valueOf(rs.getInt(1)));
|
||||||
|
} catch (Exception exception) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT ");
|
||||||
|
this.simpleSQL.getClass();
|
||||||
|
sql.append(this.simpleSQL.getGeomToWKB().replace("?GEOMETRY?", columnName));
|
||||||
|
sql.append(" FROM ");
|
||||||
|
sql.append(schemaName).append(tableName);
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
|
byte[] bytes = rs.getBytes(1);
|
||||||
|
WKBReader reader = new WKBReader(new GeometryFactory());
|
||||||
|
Geometry geom = reader.read(bytes);
|
||||||
|
return O2GeometryTypeMap.lookUpGeometry(geom.getGeometryType());
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerSqlTypeNameToClassMappings(Map<String, Class<?>> mappings) {
|
||||||
|
super.registerSqlTypeNameToClassMappings(mappings);
|
||||||
|
mappings.put("TEXT", String.class);
|
||||||
|
mappings.put("text", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerSqlTypeToClassMappings(Map<Integer, Class<?>> mappings) {
|
||||||
|
super.registerSqlTypeToClassMappings(mappings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getGeometrySRID(String schemaName, String tableName, String columnName, Connection cx) throws SQLException {
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Get Geometry SRID value for [" + tableName.toUpperCase() + "]");
|
||||||
|
if (schemaName == null || schemaName.equals("")) {
|
||||||
|
schemaName = "";
|
||||||
|
} else {
|
||||||
|
schemaName = String.valueOf(schemaName) + ".";
|
||||||
|
}
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append("SELECT REF_SRID FROM ");
|
||||||
|
sb.append(schemaName).append("O2MAP_SERVICE_INFO");
|
||||||
|
sb.append(" WHERE REF_SOURCE = '").append(tableName.toUpperCase()).append("'");
|
||||||
|
sb.append(" OR REF_SOURCE = '").append(tableName.toLowerCase()).append("'");
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sb.toString());
|
||||||
|
rs = stat.executeQuery(sb.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
|
Object obj = rs.getObject(1);
|
||||||
|
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2MAP_SERVICE_INFO for [" + tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT SRID FROM ");
|
||||||
|
sql.append(schemaName).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
|
sql.append(" WHERE TABLE_NAME = '").append(tableName.toUpperCase()).append("'");
|
||||||
|
sql.append(" AND COLUMN_NAME = '").append(columnName.toUpperCase()).append("'");
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
|
Object obj = rs.getObject(1);
|
||||||
|
return Integer.valueOf(Integer.parseInt(obj.toString().trim()));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Failed to get Geometry SRID value from O2SERVER_GEOMETRY_LAYER for [" + tableName.toUpperCase() + "] :: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Failed to get Geometry SRID value. Now Use Default [" + this.DEFAULT_CRS + "]");
|
||||||
|
return this.DEFAULT_CRS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateReferenceSystem createCRS(int srid, Connection cx) throws SQLException {
|
||||||
|
try {
|
||||||
|
return CRSMngr.getLayerCRS(srid, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLimitOffsetSupported() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyLimitOffset(StringBuffer sql, int limit, int offset) {
|
||||||
|
if (this.simpleSQL.getDbType().equalsIgnoreCase(O2DSFactory.DBMSType.ALTIBASE.getTypeName())) {
|
||||||
|
if (limit >= 0 && limit < Integer.MAX_VALUE) {
|
||||||
|
sql.append(" LIMIT " + limit);
|
||||||
|
if (offset > 0)
|
||||||
|
sql.append(" OFFSET " + offset);
|
||||||
|
} else if (offset > 0) {
|
||||||
|
sql.append(" OFFSET " + offset);
|
||||||
|
}
|
||||||
|
} else if (this.simpleSQL.getDbType().equalsIgnoreCase(O2DSFactory.DBMSType.TIBERO.getTypeName())) {
|
||||||
|
if (offset == 0) {
|
||||||
|
sql.insert(0, "SELECT * FROM (");
|
||||||
|
sql.append(") WHERE ROWNUM <= " + limit);
|
||||||
|
} else {
|
||||||
|
long max = (limit == Integer.MAX_VALUE) ? Long.MAX_VALUE : (limit + offset);
|
||||||
|
sql.insert(0, "SELECT * FROM (SELECT A.*, ROWNUM RNUM FROM ( ");
|
||||||
|
sql.append(") A WHERE ROWNUM <= " + max + ")");
|
||||||
|
sql.append("WHERE RNUM > " + offset);
|
||||||
|
}
|
||||||
|
} else if (this.simpleSQL.getDbType().equalsIgnoreCase(O2DSFactory.DBMSType.ORACLE.getTypeName())) {
|
||||||
|
if (offset == 0) {
|
||||||
|
sql.insert(0, "SELECT * FROM (");
|
||||||
|
sql.append(") WHERE ROWNUM <= " + limit);
|
||||||
|
} else {
|
||||||
|
long max = (limit == Integer.MAX_VALUE) ? Long.MAX_VALUE : (limit + offset);
|
||||||
|
sql.insert(0, "SELECT * FROM (SELECT A.*, ROWNUM RNUM FROM ( ");
|
||||||
|
sql.append(") A WHERE ROWNUM <= " + max + ")");
|
||||||
|
sql.append("WHERE RNUM > " + offset);
|
||||||
|
}
|
||||||
|
} else if (this.simpleSQL.getDbType().equalsIgnoreCase(O2DSFactory.DBMSType.MYSQL.getTypeName())) {
|
||||||
|
if (limit >= 0 && limit < Integer.MAX_VALUE) {
|
||||||
|
if (offset > 0) {
|
||||||
|
sql.append(" LIMIT " + offset + ", " + limit);
|
||||||
|
} else {
|
||||||
|
sql.append(" LIMIT " + limit);
|
||||||
|
}
|
||||||
|
} else if (offset > 0) {
|
||||||
|
sql.append(" LIMIT " + offset + ", " + Long.MAX_VALUE);
|
||||||
|
}
|
||||||
|
} else if (this.simpleSQL.getDbType().equalsIgnoreCase(O2DSFactory.DBMSType.POSTGIS.getTypeName())) {
|
||||||
|
if (limit >= 0 && limit < Integer.MAX_VALUE) {
|
||||||
|
sql.append(" LIMIT " + limit);
|
||||||
|
if (offset > 0)
|
||||||
|
sql.append(" OFFSET " + offset);
|
||||||
|
} else if (offset > 0) {
|
||||||
|
sql.append(" OFFSET " + offset);
|
||||||
|
}
|
||||||
|
} else if (this.simpleSQL.getDbType().equalsIgnoreCase(O2DSFactory.DBMSType.KAIROS.getTypeName())) {
|
||||||
|
if (limit >= 0 && limit < Integer.MAX_VALUE) {
|
||||||
|
if (offset > 0) {
|
||||||
|
sql.append(" LIMIT " + offset + ", " + limit);
|
||||||
|
} else {
|
||||||
|
sql.append(" LIMIT " + limit);
|
||||||
|
}
|
||||||
|
} else if (offset > 0) {
|
||||||
|
sql.append(" LIMIT " + offset + ", " + Long.MAX_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReferencedEnvelope> getOptimizedBounds(String schemaName, SimpleFeatureType featureType, Connection cx) throws SQLException, IOException {
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Make optimal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||||
|
List<ReferencedEnvelope> resultList = new ArrayList<ReferencedEnvelope>();
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
String schema = "";
|
||||||
|
if (schemaName == null || schemaName.equals("")) {
|
||||||
|
schema = "";
|
||||||
|
} else {
|
||||||
|
schema = String.valueOf(schemaName) + ".";
|
||||||
|
}
|
||||||
|
schema = schema.toUpperCase();
|
||||||
|
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||||
|
if (att instanceof GeometryDescriptor) {
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT MIN_1D, MAX_1D, MIN_2D, MAX_2D FROM ");
|
||||||
|
sql.append(schema).append("O2SERVER_GEOMETRY_LAYER");
|
||||||
|
sql.append(" WHERE");
|
||||||
|
sql.append(" TABLE_NAME = ").append("'").append(featureType.getTypeName().toUpperCase()).append("'");
|
||||||
|
sql.append(" AND");
|
||||||
|
sql.append(" COLUMN_NAME = ").append("'").append(att.getLocalName().toUpperCase()).append("'");
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
|
double x1 = rs.getDouble(1);
|
||||||
|
double x2 = rs.getDouble(2);
|
||||||
|
double y1 = rs.getDouble(3);
|
||||||
|
double y2 = rs.getDouble(4);
|
||||||
|
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||||
|
resultList.add(new ReferencedEnvelope(x1, x2, y1, y2, crs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Failed to make optimal bounds, falling back intenal bounds.");
|
||||||
|
return getInternalBounds(schemaName, featureType, cx);
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReferencedEnvelope> getInternalBounds(String schemaName, SimpleFeatureType featureType, Connection cx) {
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "Make internal bounds for [" + featureType.getTypeName().toUpperCase() + "]");
|
||||||
|
List<ReferencedEnvelope> resultList = new ArrayList<ReferencedEnvelope>();
|
||||||
|
Statement stat = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
stat = cx.createStatement();
|
||||||
|
stat.setFetchSize(1);
|
||||||
|
if (schemaName == null || schemaName.equals("")) {
|
||||||
|
schemaName = "";
|
||||||
|
} else {
|
||||||
|
schemaName = String.valueOf(schemaName) + ".";
|
||||||
|
}
|
||||||
|
schemaName = schemaName.toUpperCase();
|
||||||
|
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
|
||||||
|
if (att instanceof GeometryDescriptor) {
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("SELECT ");
|
||||||
|
encodeGeometryEnvelope(null, att.getLocalName().toUpperCase(), sql);
|
||||||
|
sql.append(" FROM ");
|
||||||
|
sql.append(schemaName).append(featureType.getTypeName().toUpperCase());
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
rs = stat.executeQuery(sql.toString());
|
||||||
|
Envelope extent = new Envelope();
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
|
Envelope env = decodeGeometryEnvelope(rs, 1, cx);
|
||||||
|
if (!env.isNull())
|
||||||
|
extent.expandToInclude(env);
|
||||||
|
}
|
||||||
|
CoordinateReferenceSystem crs = ((GeometryDescriptor)att).getCoordinateReferenceSystem();
|
||||||
|
resultList.add(ReferencedEnvelope.create(extent, crs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Failed to make intenal bounds, falling back on envelope aggregation.");
|
||||||
|
} finally {
|
||||||
|
this.dataStore.closeSafe(rs);
|
||||||
|
this.dataStore.closeSafe(stat);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeGeometryEnvelope(String tableName, String geometryColumn, StringBuffer sql) {
|
||||||
|
this.simpleSQL.getClass();
|
||||||
|
this.simpleSQL.getClass();
|
||||||
|
sql.append(this.simpleSQL.getGeomToWKB().replace("?GEOMETRY?", this.simpleSQL.getSqlEnvelope().replace("?GEOMETRY?", geometryColumn)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx) throws SQLException, IOException {
|
||||||
|
try {
|
||||||
|
WKBAttributeIO reader = getWKBReader(new GeometryFactory());
|
||||||
|
Geometry geom = (Geometry)reader.read(rs, column);
|
||||||
|
return geom.getEnvelopeInternal();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[DB]", "Fail to decode GeometryEnvelope : " + e.getMessage());
|
||||||
|
return new Envelope();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void prepareGeometryValue(Geometry g, int dimension, int srid, Class binding, StringBuffer sql) {
|
||||||
|
this.simpleSQL.getClass();
|
||||||
|
this.simpleSQL.getClass();
|
||||||
|
sql.append(this.simpleSQL.getGeomFromWKB().replace("?WKB?", "?").replace("?SRID?", String.valueOf(srid)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column) throws SQLException {
|
||||||
|
if (g != null) {
|
||||||
|
LineString lineString = null;
|
||||||
|
if (g instanceof LinearRing)
|
||||||
|
lineString = g.getFactory().createLineString(((LinearRing)g).getCoordinateSequence());
|
||||||
|
WKBWriter wkbWriter = new WKBWriter(dimension);
|
||||||
|
byte[] bytes = wkbWriter.write((Geometry)lineString);
|
||||||
|
if (this.simpleSQL.getDbType().equalsIgnoreCase(O2DSFactory.DBMSType.ALTIBASE.getTypeName())) {
|
||||||
|
ps.setObject(column, bytes, 10003);
|
||||||
|
} else {
|
||||||
|
ps.setBytes(column, bytes);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ps.setNull(column, 1111, "GEOMETRY");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix, int srid, Hints hints, StringBuffer sql) {
|
||||||
|
String sqlStr = "";
|
||||||
|
if (prefix != null)
|
||||||
|
sqlStr = String.valueOf(prefix) + ".";
|
||||||
|
sqlStr = String.valueOf(sqlStr) + gatt.getLocalName();
|
||||||
|
this.simpleSQL.getClass();
|
||||||
|
sql.append(this.simpleSQL.getGeomToWKB().replace("?GEOMETRY?", sqlStr));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Geometry decodeGeometryValue(GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx) throws IOException, SQLException {
|
||||||
|
WKBAttributeIO reader = getWKBReader(factory);
|
||||||
|
Geometry geom = (Geometry)reader.read(rs, column);
|
||||||
|
return geom;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WKBAttributeIO getWKBReader(GeometryFactory factory) {
|
||||||
|
WKBAttributeIO reader = this.wkbReader.get();
|
||||||
|
if (reader == null) {
|
||||||
|
reader = new WKBAttributeIO(factory);
|
||||||
|
this.wkbReader.set(reader);
|
||||||
|
} else {
|
||||||
|
reader.setGeometryFactory(factory);
|
||||||
|
}
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PreparedFilterToSQL createPreparedFilterToSQL() {
|
||||||
|
return new SimpleFilterToSQL(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSelect(PreparedStatement select, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||||
|
select.setFetchSize(this.dataStore.getFetchSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDelete(PreparedStatement delete, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||||
|
delete.setFetchSize(this.dataStore.getFetchSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onInsert(PreparedStatement insert, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||||
|
insert.setFetchSize(this.dataStore.getFetchSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onUpdate(PreparedStatement update, Connection cx, SimpleFeatureType featureType) throws SQLException {
|
||||||
|
update.setFetchSize(this.dataStore.getFetchSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeTableName(String raw, StringBuffer sql) {
|
||||||
|
sql.append(raw);
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "QUERY : " + sql.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encodeColumnName(String prefix, String raw, StringBuffer sql) {
|
||||||
|
if (prefix != null)
|
||||||
|
sql.append(prefix).append(".");
|
||||||
|
sql.append(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameEscape() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean lookupGeneratedValuesPostInsert() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDbType() {
|
||||||
|
return this.simpleSQL.getDbType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,162 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import com.vividsolutions.jts.geom.Polygon;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.geotools.filter.FilterCapabilities;
|
||||||
|
import org.geotools.geometry.jts.JTS;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.jdbc.JoinPropertyName;
|
||||||
|
import org.geotools.jdbc.PreparedFilterToSQL;
|
||||||
|
import org.geotools.jdbc.SQLDialect;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.opengis.feature.type.AttributeDescriptor;
|
||||||
|
import org.opengis.filter.expression.Literal;
|
||||||
|
import org.opengis.filter.expression.PropertyName;
|
||||||
|
import org.opengis.filter.spatial.BBOX;
|
||||||
|
import org.opengis.filter.spatial.BinarySpatialOperator;
|
||||||
|
import org.opengis.geometry.BoundingBox;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
|
public class SimpleFilterToSQL
|
||||||
|
extends PreparedFilterToSQL {
|
||||||
|
private SimpleDialect dsDialect;
|
||||||
|
|
||||||
|
public SimpleFilterToSQL(SimpleDialect dialect) {
|
||||||
|
this.dsDialect = dialect;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected FilterCapabilities createFilterCapabilities() {
|
||||||
|
FilterCapabilities caps = new FilterCapabilities();
|
||||||
|
caps.addAll(SQLDialect.BASE_DBMS_CAPABILITIES);
|
||||||
|
caps.addType(BBOX.class);
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object visitBinarySpatialOperator(BinarySpatialOperator filter, PropertyName property, Literal geometry, boolean swapped, Object extraData) {
|
||||||
|
try {
|
||||||
|
ReferencedEnvelope envelop;
|
||||||
|
if (filter instanceof BBOX) {
|
||||||
|
BBOX bbox = (BBOX)filter;
|
||||||
|
envelop = ReferencedEnvelope.reference((BoundingBox)bbox.getBounds());
|
||||||
|
if ((envelop = (ReferencedEnvelope) this.intersectionBound((Envelope)envelop)) == null || envelop.isNull()) {
|
||||||
|
this.out.append(" 1=0 ");
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "WHERE : " + this.out.toString());
|
||||||
|
return extraData;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Unsupported filter type " + filter.getClass());
|
||||||
|
}
|
||||||
|
String bboxSQL = this.dsDialect.simpleSQL.getSqlBBox();
|
||||||
|
this.dsDialect.simpleSQL.getClass();
|
||||||
|
bboxSQL = ServerUtil.replaceFirst((String)bboxSQL, (String)"?GEOMETRY?", (String)this.findPropertyName(property));
|
||||||
|
this.dsDialect.simpleSQL.getClass();
|
||||||
|
bboxSQL = ServerUtil.replaceFirst((String)bboxSQL, (String)"?GEOMETRY?", (String)this.setLiteralBBox(bboxSQL, (Envelope)envelop, extraData));
|
||||||
|
this.out.append(bboxSQL);
|
||||||
|
LogMngr.getInstance().logDebug("[DB]", "WHERE : " + this.out.toString());
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new RuntimeException("Fail to create Filter SQL", e);
|
||||||
|
}
|
||||||
|
return extraData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String findPropertyName(PropertyName expression) {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
if (expression instanceof JoinPropertyName) {
|
||||||
|
sb.append(this.escapeName(((JoinPropertyName)expression).getAlias()));
|
||||||
|
sb.append(".");
|
||||||
|
}
|
||||||
|
AttributeDescriptor attribute = null;
|
||||||
|
try {
|
||||||
|
attribute = (AttributeDescriptor)expression.evaluate((Object)this.featureType);
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
String encodedField = attribute != null ? this.fieldEncoder.encode(this.escapeName(attribute.getLocalName())) : this.fieldEncoder.encode(this.escapeName(expression.getPropertyName()));
|
||||||
|
sb.append(encodedField);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setLiteralBBox(String bboxSQL, Envelope envelope, Object context) {
|
||||||
|
Geometry polygon = JTS.toGeometry((Envelope)envelope);
|
||||||
|
if (!polygon.isValid()) {
|
||||||
|
polygon = polygon.buffer(1.0E-5);
|
||||||
|
}
|
||||||
|
this.literalValues.add(polygon);
|
||||||
|
this.dimensions.add(this.currentDimension);
|
||||||
|
polygon.setSRID(this.currentSRID.intValue());
|
||||||
|
this.SRIDs.add(this.currentSRID);
|
||||||
|
Class<?> clazz = null;
|
||||||
|
if (context instanceof Class) {
|
||||||
|
clazz = (Class<?>)context;
|
||||||
|
} else if (polygon != null) {
|
||||||
|
clazz = polygon.getClass();
|
||||||
|
}
|
||||||
|
this.literalTypes.add(clazz);
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
if (polygon == null || this.dialect == null) {
|
||||||
|
sb.append("?");
|
||||||
|
} else if (Geometry.class.isAssignableFrom(polygon.getClass())) {
|
||||||
|
int srid = this.currentSRID != null ? this.currentSRID : -1;
|
||||||
|
int dimension = this.currentDimension != null ? this.currentDimension : -1;
|
||||||
|
this.dialect.prepareGeometryValue((Geometry)polygon, dimension, srid, Geometry.class, sb);
|
||||||
|
} else if (this.encodingFunction) {
|
||||||
|
this.dialect.prepareFunctionArgument(clazz, sb);
|
||||||
|
} else {
|
||||||
|
sb.append("?");
|
||||||
|
}
|
||||||
|
String string = this.dsDialect.simpleSQL.getGeomFromWKB();
|
||||||
|
this.dsDialect.simpleSQL.getClass();
|
||||||
|
String resultStr = ServerUtil.replaceFirst((String)string, (String)"?WKB?", (String)sb.toString());
|
||||||
|
this.dsDialect.simpleSQL.getClass();
|
||||||
|
return ServerUtil.replaceFirst((String)resultStr, (String)"?SRID?", (String)("" + this.currentSRID));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Envelope intersectionBound(Envelope envelop) {
|
||||||
|
try {
|
||||||
|
ArrayList<Layer> layers = ServerContext.getMap().getAllLayers();
|
||||||
|
for (Layer layer : layers) {
|
||||||
|
if (!(layer instanceof FeatureLayer) || !layer.getServerName().equalsIgnoreCase(this.dsDialect.serverName) || !layer.getSourceName().equalsIgnoreCase(this.featureType.getTypeName())) continue;
|
||||||
|
return layer.getBBox().intersection(envelop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
return envelop;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BoundingBox transformFilter(BoundingBox bound) {
|
||||||
|
if (bound.getCoordinateReferenceSystem() == null) {
|
||||||
|
return bound;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CoordinateReferenceSystem targetCRS = this.getCRS(this.featureType.getTypeName());
|
||||||
|
if (!CRS.equalsIgnoreMetadata((Object)targetCRS, (Object)bound.getCoordinateReferenceSystem())) {
|
||||||
|
return bound.toBounds(targetCRS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (TransformException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CoordinateReferenceSystem getCRS(String typeName) {
|
||||||
|
try {
|
||||||
|
ArrayList<Layer> layers = ServerContext.getMap().getAllLayers();
|
||||||
|
for (Layer layer : layers) {
|
||||||
|
if (!(layer instanceof FeatureLayer) || !layer.getSourceName().equalsIgnoreCase(typeName)) continue;
|
||||||
|
return layer.getCRS();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
return CRSMngr.getCRS((Integer)4326);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
import java.awt.AlphaComposite;
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.geom.Rectangle2D.Double;
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
|
@ -30,8 +31,11 @@ import org.geotools.renderer.style.MarkStyle2D;
|
||||||
import org.geotools.styling.FeatureTypeStyle;
|
import org.geotools.styling.FeatureTypeStyle;
|
||||||
import org.geotools.styling.Fill;
|
import org.geotools.styling.Fill;
|
||||||
import org.geotools.styling.Graphic;
|
import org.geotools.styling.Graphic;
|
||||||
|
import org.geotools.styling.LineSymbolizer;
|
||||||
import org.geotools.styling.Mark;
|
import org.geotools.styling.Mark;
|
||||||
import org.geotools.styling.NamedLayer;
|
import org.geotools.styling.NamedLayer;
|
||||||
|
import org.geotools.styling.PointSymbolizer;
|
||||||
|
import org.geotools.styling.PolygonSymbolizer;
|
||||||
import org.geotools.styling.RasterSymbolizerImpl;
|
import org.geotools.styling.RasterSymbolizerImpl;
|
||||||
import org.geotools.styling.Rule;
|
import org.geotools.styling.Rule;
|
||||||
import org.geotools.styling.SLDTransformer;
|
import org.geotools.styling.SLDTransformer;
|
||||||
|
|
@ -40,325 +44,213 @@ import org.geotools.styling.Stroke;
|
||||||
import org.geotools.styling.Style;
|
import org.geotools.styling.Style;
|
||||||
import org.geotools.styling.StyleBuilder;
|
import org.geotools.styling.StyleBuilder;
|
||||||
import org.geotools.styling.StyleFactory;
|
import org.geotools.styling.StyleFactory;
|
||||||
|
import org.geotools.styling.StyleVisitor;
|
||||||
import org.geotools.styling.StyledLayer;
|
import org.geotools.styling.StyledLayer;
|
||||||
import org.geotools.styling.StyledLayerDescriptor;
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
import org.geotools.styling.Symbolizer;
|
import org.geotools.styling.Symbolizer;
|
||||||
import org.geotools.styling.UserLayer;
|
import org.geotools.styling.UserLayer;
|
||||||
|
import org.geotools.xml.Configuration;
|
||||||
import org.geotools.xml.Parser;
|
import org.geotools.xml.Parser;
|
||||||
|
import org.opengis.filter.FilterFactory;
|
||||||
import org.opengis.filter.FilterFactory2;
|
import org.opengis.filter.FilterFactory2;
|
||||||
|
import org.opengis.filter.expression.Expression;
|
||||||
|
import org.opengis.style.ShadedRelief;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
public class StyleMngr {
|
||||||
import java.awt.BasicStroke;
|
static {
|
||||||
import java.awt.Color;
|
Hints.putSystemDefault((RenderingHints.Key)Hints.STYLE_FACTORY, O2StyleFactory.class);
|
||||||
import java.awt.geom.Rectangle2D.Double;
|
}
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
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.XPathExpressionException;
|
|
||||||
import javax.xml.xpath.XPathFactory;
|
|
||||||
import org.geotools.factory.CommonFactoryFinder;
|
|
||||||
import org.geotools.factory.GeoTools;
|
|
||||||
import org.geotools.factory.Hints;
|
|
||||||
import org.geotools.renderer.style.MarkStyle2D;
|
|
||||||
import org.geotools.styling.FeatureTypeStyle;
|
|
||||||
import org.geotools.styling.Fill;
|
|
||||||
import org.geotools.styling.Graphic;
|
|
||||||
import org.geotools.styling.Mark;
|
|
||||||
import org.geotools.styling.NamedLayer;
|
|
||||||
import org.geotools.styling.RasterSymbolizerImpl;
|
|
||||||
import org.geotools.styling.Rule;
|
|
||||||
import org.geotools.styling.SLDTransformer;
|
|
||||||
import org.geotools.styling.ShadedReliefImpl;
|
|
||||||
import org.geotools.styling.Stroke;
|
|
||||||
import org.geotools.styling.Style;
|
|
||||||
import org.geotools.styling.StyleBuilder;
|
|
||||||
import org.geotools.styling.StyleFactory;
|
|
||||||
import org.geotools.styling.StyledLayer;
|
|
||||||
import org.geotools.styling.StyledLayerDescriptor;
|
|
||||||
import org.geotools.styling.Symbolizer;
|
|
||||||
import org.geotools.styling.UserLayer;
|
|
||||||
import org.opengis.filter.FilterFactory2;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
public class StyleMngr
|
|
||||||
{
|
|
||||||
public static final StyleFactory sf = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());
|
public static final StyleFactory sf = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());
|
||||||
|
|
||||||
public static final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
|
public static final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
|
||||||
public static final StyleBuilder sb = new StyleBuilder(sf, ff);
|
|
||||||
|
public static final StyleBuilder sb = new StyleBuilder(sf, (FilterFactory)ff);
|
||||||
|
|
||||||
private static final Color LINE_COLOR = Color.BLUE;
|
private static final Color LINE_COLOR = Color.BLUE;
|
||||||
|
|
||||||
private static final Color FILL_COLOR = Color.CYAN;
|
private static final Color FILL_COLOR = Color.CYAN;
|
||||||
|
|
||||||
private static final float OPACITY = 1.0F;
|
private static final float OPACITY = 1.0F;
|
||||||
|
|
||||||
private static final float LINE_WIDTH = 1.0F;
|
private static final float LINE_WIDTH = 1.0F;
|
||||||
|
|
||||||
private static final float POINT_SIZE = 10.0F;
|
private static final float POINT_SIZE = 10.0F;
|
||||||
|
|
||||||
static
|
public static ArrayList<Style> getStylesFromSLD(StyledLayerDescriptor sld) {
|
||||||
{
|
ArrayList<Style> styles = new ArrayList<Style>();
|
||||||
Hints.putSystemDefault(Hints.STYLE_FACTORY, O2StyleFactory.class);
|
if (sld == null)
|
||||||
}
|
return styles;
|
||||||
|
Iterator<StyledLayer> sldLayerIter = sld.layers().iterator();
|
||||||
public static ArrayList<Style> getStylesFromSLD(StyledLayerDescriptor sld)
|
|
||||||
{
|
|
||||||
ArrayList styles = new ArrayList();
|
|
||||||
|
|
||||||
if (sld == null) {
|
|
||||||
return styles;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator sldLayerIter = sld.layers().iterator();
|
|
||||||
Iterator sldStyleIter;
|
|
||||||
for (; sldLayerIter.hasNext();
|
|
||||||
sldStyleIter.hasNext())
|
|
||||||
{
|
|
||||||
StyledLayer styledLayer = (StyledLayer)sldLayerIter.next();
|
|
||||||
|
|
||||||
sldStyleIter = getStylesIterator(styledLayer);
|
|
||||||
Style tempStyle = (Style)sldStyleIter.next();
|
|
||||||
styles.add(tempStyle);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return styles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<Style> getStylesFromSLD(String layerName, StyledLayerDescriptor sld)
|
|
||||||
{
|
|
||||||
ArrayList styles = new ArrayList();
|
|
||||||
|
|
||||||
if ((ServerUtil.isNullString(layerName)) || (sld == null)) {
|
|
||||||
return styles;
|
|
||||||
}
|
|
||||||
layerName = layerName.trim().toUpperCase();
|
|
||||||
|
|
||||||
Iterator sldLayerIter = sld.layers().iterator();
|
|
||||||
while (sldLayerIter.hasNext()) {
|
while (sldLayerIter.hasNext()) {
|
||||||
StyledLayer styledLayer = (StyledLayer)sldLayerIter.next();
|
StyledLayer styledLayer = sldLayerIter.next();
|
||||||
|
Iterator<Style> sldStyleIter = getStylesIterator(styledLayer);
|
||||||
if ((styledLayer.getName() != null) &&
|
while (sldStyleIter.hasNext()) {
|
||||||
(styledLayer.getName().equalsIgnoreCase(layerName)))
|
Style tempStyle = sldStyleIter.next();
|
||||||
{
|
styles.add(tempStyle);
|
||||||
styles.addAll(getStyles(styledLayer));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return styles;
|
return styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Style> getStylesFromSLD(String layerName, String styleName, StyledLayerDescriptor sld)
|
public static ArrayList<Style> getStylesFromSLD(String layerName, StyledLayerDescriptor sld) {
|
||||||
{
|
ArrayList<Style> styles = new ArrayList<Style>();
|
||||||
ArrayList styles = new ArrayList();
|
if (ServerUtil.isNullString(layerName) || sld == null)
|
||||||
|
return styles;
|
||||||
if ((ServerUtil.isNullString(layerName)) || (sld == null)) {
|
|
||||||
return styles;
|
|
||||||
}
|
|
||||||
layerName = layerName.trim().toUpperCase();
|
layerName = layerName.trim().toUpperCase();
|
||||||
|
Iterator<StyledLayer> sldLayerIter = sld.layers().iterator();
|
||||||
if (!ServerUtil.isNullString(styleName)) {
|
while (sldLayerIter.hasNext()) {
|
||||||
styleName = styleName.trim().toUpperCase();
|
StyledLayer styledLayer = sldLayerIter.next();
|
||||||
}
|
if (styledLayer.getName() != null &&
|
||||||
|
styledLayer.getName().equalsIgnoreCase(layerName))
|
||||||
Iterator sldLayerIter = sld.layers().iterator();
|
styles.addAll(getStyles(styledLayer));
|
||||||
Iterator sldStyleIter;
|
}
|
||||||
label188: for (; sldLayerIter.hasNext();
|
|
||||||
sldStyleIter.hasNext())
|
|
||||||
{
|
|
||||||
StyledLayer styledLayer = (StyledLayer)sldLayerIter.next();
|
|
||||||
|
|
||||||
if ((styledLayer.getName() == null) ||
|
|
||||||
(!styledLayer.getName().equalsIgnoreCase(layerName)))
|
|
||||||
break label188;
|
|
||||||
sldStyleIter = getStylesIterator(styledLayer);
|
|
||||||
//continue; thkim
|
|
||||||
Style tempStyle = (Style)sldStyleIter.next();
|
|
||||||
|
|
||||||
if ((ServerUtil.isNullString(styleName)) &&
|
|
||||||
(ServerUtil.isNullString(tempStyle.getName())))
|
|
||||||
{
|
|
||||||
tempStyle.setName("");
|
|
||||||
styles.add(tempStyle);
|
|
||||||
}
|
|
||||||
else if (tempStyle.getName().equalsIgnoreCase(styleName))
|
|
||||||
{
|
|
||||||
styles.add(tempStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return styles;
|
return styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Style> getStylesFromSLD(String layerName, String styleName, StyledLayerDescriptor sld) {
|
||||||
|
ArrayList<Style> styles = new ArrayList<Style>();
|
||||||
|
if (ServerUtil.isNullString(layerName) || sld == null)
|
||||||
|
return styles;
|
||||||
|
layerName = layerName.trim().toUpperCase();
|
||||||
|
if (!ServerUtil.isNullString(styleName))
|
||||||
|
styleName = styleName.trim().toUpperCase();
|
||||||
|
Iterator<StyledLayer> sldLayerIter = sld.layers().iterator();
|
||||||
|
while (sldLayerIter.hasNext()) {
|
||||||
|
StyledLayer styledLayer = sldLayerIter.next();
|
||||||
|
if (styledLayer.getName() != null &&
|
||||||
|
styledLayer.getName().equalsIgnoreCase(layerName)) {
|
||||||
|
Iterator<Style> sldStyleIter = getStylesIterator(styledLayer);
|
||||||
|
while (sldStyleIter.hasNext()) {
|
||||||
|
Style tempStyle = sldStyleIter.next();
|
||||||
|
if (ServerUtil.isNullString(styleName) &&
|
||||||
|
ServerUtil.isNullString(tempStyle.getName())) {
|
||||||
|
tempStyle.setName("");
|
||||||
|
styles.add(tempStyle);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (tempStyle.getName().equalsIgnoreCase(styleName))
|
||||||
|
styles.add(tempStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<Style> getStyles(StyledLayer layer) {
|
private static List<Style> getStyles(StyledLayer layer) {
|
||||||
if ((layer instanceof NamedLayer)) {
|
if (layer instanceof NamedLayer)
|
||||||
return ((NamedLayer)layer).styles();
|
return ((NamedLayer)layer).styles();
|
||||||
}
|
|
||||||
return ((UserLayer)layer).userStyles();
|
return ((UserLayer)layer).userStyles();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Iterator<Style> getStylesIterator(StyledLayer layer)
|
private static Iterator<Style> getStylesIterator(StyledLayer layer) {
|
||||||
{
|
if (layer instanceof NamedLayer)
|
||||||
if ((layer instanceof NamedLayer)) {
|
return ((NamedLayer)layer).styles().iterator();
|
||||||
return ((NamedLayer)layer).styles().iterator();
|
|
||||||
}
|
|
||||||
return ((UserLayer)layer).userStyles().iterator();
|
return ((UserLayer)layer).userStyles().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void writeServiceSLD100(StyledLayerDescriptor sld)
|
public static synchronized void writeServiceSLD100(StyledLayerDescriptor sld) {
|
||||||
{
|
try {
|
||||||
try
|
final String layerName = sld.getName();
|
||||||
{
|
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter() {
|
||||||
String layerName = sld.getName();
|
public boolean accept(File dir, String name) {
|
||||||
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter()
|
if (name.toUpperCase().equalsIgnoreCase(String.valueOf(layerName) + ".SLD"))
|
||||||
{
|
return true;
|
||||||
public boolean accept(File dir, String name)
|
return false;
|
||||||
{
|
}
|
||||||
|
});
|
||||||
if( false ) { // thkim
|
byte b;
|
||||||
if (name.toUpperCase().equalsIgnoreCase(StyleMngr.this + ".SLD")) {
|
int i;
|
||||||
return true;
|
File[] arrayOfFile1;
|
||||||
}
|
for (i = (arrayOfFile1 = files).length, b = 0; b < i; ) {
|
||||||
}
|
File file = arrayOfFile1[b];
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (File file : files) {
|
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
b++;
|
||||||
|
}
|
||||||
File writeFile = new File(ServerContext.getStylesFolder(), layerName + ".sld");
|
File writeFile = new File(ServerContext.getStylesFolder(), String.valueOf(layerName) + ".sld");
|
||||||
|
|
||||||
SLDTransformer styleTransform = new SLDTransformer();
|
SLDTransformer styleTransform = new SLDTransformer();
|
||||||
styleTransform.setEncoding(Charset.forName("EUC-KR"));
|
styleTransform.setEncoding(Charset.forName("EUC-KR"));
|
||||||
styleTransform.setIndentation(5);
|
styleTransform.setIndentation(5);
|
||||||
styleTransform.transform(sld, new FileOutputStream(writeFile));
|
styleTransform.transform(sld, new FileOutputStream(writeFile));
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logError("[STYLE]",
|
LogMngr.getInstance().logError("[STYLE]",
|
||||||
"[StyleMngr.writeServiceSLD]" +
|
"[StyleMngr.writeServiceSLD]" +
|
||||||
e.getMessage());
|
e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void writeServiceSLD110(StyledLayerDescriptor sld)
|
public static synchronized void writeServiceSLD110(StyledLayerDescriptor sld) {
|
||||||
{
|
try {
|
||||||
try
|
final String layerName = sld.getName();
|
||||||
{
|
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter() {
|
||||||
String layerName = sld.getName();
|
public boolean accept(File dir, String name) {
|
||||||
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter()
|
if (name.toUpperCase().equalsIgnoreCase(String.valueOf(layerName) + ".SLD"))
|
||||||
{
|
return true;
|
||||||
public boolean accept(File dir, String name)
|
return false;
|
||||||
{
|
|
||||||
if( false ) { // thkim
|
|
||||||
if (name.toUpperCase().equalsIgnoreCase(StyleMngr.this + ".SLD")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
return false;
|
byte b;
|
||||||
}
|
int i;
|
||||||
});
|
File[] arrayOfFile1;
|
||||||
for (File file : files) {
|
for (i = (arrayOfFile1 = files).length, b = 0; b < i; ) {
|
||||||
|
File file = arrayOfFile1[b];
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
b++;
|
||||||
|
}
|
||||||
File writeFile = new File(ServerContext.getStylesFolder(), layerName + ".sld");
|
File writeFile = new File(ServerContext.getStylesFolder(), String.valueOf(layerName) + ".sld");
|
||||||
|
|
||||||
SLDTransformer110 styleTransform = new SLDTransformer110();
|
SLDTransformer110 styleTransform = new SLDTransformer110();
|
||||||
styleTransform.setEncoding(Charset.forName("EUC-KR"));
|
styleTransform.setEncoding(Charset.forName("EUC-KR"));
|
||||||
styleTransform.setIndentation(5);
|
styleTransform.setIndentation(5);
|
||||||
styleTransform.transform(sld, new FileOutputStream(writeFile));
|
styleTransform.transform(sld, new FileOutputStream(writeFile));
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LogMngr.getInstance().logError("[STYLE]",
|
LogMngr.getInstance().logError("[STYLE]",
|
||||||
"[StyleMngr.writeServiceSLD]" +
|
"[StyleMngr.writeServiceSLD]" +
|
||||||
e.getMessage());
|
e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StyledLayerDescriptor readServiceSLD(String layerName)
|
public static StyledLayerDescriptor readServiceSLD(final String layerName) {
|
||||||
{
|
try {
|
||||||
try
|
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter() {
|
||||||
{
|
public boolean accept(File dir, String name) {
|
||||||
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter()
|
if (name.toUpperCase().equalsIgnoreCase(String.valueOf(layerName) + ".SLD"))
|
||||||
{
|
return true;
|
||||||
public boolean accept(File dir, String name)
|
return false;
|
||||||
{
|
|
||||||
if( false ) { // thkim
|
|
||||||
if (name.toUpperCase().equalsIgnoreCase(StyleMngr.this + ".SLD")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
return false;
|
if (files.length > 0)
|
||||||
}
|
return parseSLD(new FileInputStream(files[0]));
|
||||||
});
|
|
||||||
if (files.length > 0) {
|
|
||||||
return parseSLD(new FileInputStream(files[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
LogMngr.getInstance().logDebug("[STYLE]",
|
LogMngr.getInstance().logDebug("[STYLE]",
|
||||||
"[StyleMngr.readServiceSLD] " + layerName + ".sld is not exist");
|
"[StyleMngr.readServiceSLD] " + layerName + ".sld is not exist");
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[STYLE]",
|
LogMngr.getInstance().logError("[STYLE]",
|
||||||
"[StyleMngr.readServiceSLD]" +
|
"[StyleMngr.readServiceSLD]" +
|
||||||
e.getMessage());
|
e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StyledLayerDescriptor parseSLD(InputStream stream)
|
public static StyledLayerDescriptor parseSLD(InputStream stream) throws Exception {
|
||||||
throws Exception
|
try {
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
byte[] sldBytes = ServerUtil.cloneInputStream(stream);
|
byte[] sldBytes = ServerUtil.cloneInputStream(stream);
|
||||||
String version = getSLDVersion(new ByteArrayInputStream(sldBytes));
|
String version = getSLDVersion(new ByteArrayInputStream(sldBytes));
|
||||||
|
|
||||||
Object obj = null;
|
Object obj = null;
|
||||||
if (version.equals("1.1.0"))
|
if (version.equals("1.1.0")) {
|
||||||
{
|
|
||||||
SLDConfiguration110 config = new SLDConfiguration110();
|
SLDConfiguration110 config = new SLDConfiguration110();
|
||||||
Parser parser = new Parser(config);
|
Parser parser = new Parser((Configuration)config);
|
||||||
obj = parser.parse(new ByteArrayInputStream(sldBytes));
|
obj = parser.parse(new ByteArrayInputStream(sldBytes));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
SLDParser100 parser = new SLDParser100(sf, new ByteArrayInputStream(sldBytes));
|
SLDParser100 parser = new SLDParser100(sf, new ByteArrayInputStream(sldBytes));
|
||||||
obj = parser.parseSLD();
|
obj = parser.parseSLD();
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledLayerDescriptor sld = (StyledLayerDescriptor)obj;
|
StyledLayerDescriptor sld = (StyledLayerDescriptor)obj;
|
||||||
|
|
||||||
RefineStyleVisitor uVisitor = new RefineStyleVisitor();
|
RefineStyleVisitor uVisitor = new RefineStyleVisitor();
|
||||||
sld.accept(uVisitor);
|
sld.accept((StyleVisitor)uVisitor);
|
||||||
|
|
||||||
sld = (StyledLayerDescriptor)uVisitor.getCopy();
|
sld = (StyledLayerDescriptor)uVisitor.getCopy();
|
||||||
|
|
||||||
return sld;
|
return sld;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
LogMngr.getInstance().logError("[STYLE]", "[StyleMngr.parseSLD]" + e.getMessage());
|
LogMngr.getInstance().logError("[STYLE]", "[StyleMngr.parseSLD]" + e.getMessage());
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -368,149 +260,127 @@ public class StyleMngr
|
||||||
stream = null;
|
stream = null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
stream = null;
|
stream = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getSLDVersion(InputStream stream)
|
private static String getSLDVersion(InputStream stream) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
Document dDoc = builder.parse(stream);
|
Document dDoc = builder.parse(stream);
|
||||||
|
|
||||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||||
String version = (String)xPath.evaluate("//StyledLayerDescriptor/@version", dDoc, XPathConstants.STRING);
|
String version = (String)xPath.evaluate("//StyledLayerDescriptor/@version", dDoc, XPathConstants.STRING);
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
} catch (ParserConfigurationException localParserConfigurationException) {
|
} catch (ParserConfigurationException parserConfigurationException) {
|
||||||
} catch (SAXException localSAXException) {
|
|
||||||
} catch (IOException localIOException1) {
|
} catch (SAXException sAXException) {
|
||||||
} catch (XPathExpressionException localXPathExpressionException) {
|
|
||||||
|
} catch (IOException iOException) {
|
||||||
|
|
||||||
|
} catch (XPathExpressionException xPathExpressionException) {
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (stream != null) {
|
if (stream != null)
|
||||||
try {
|
try {
|
||||||
stream.close();
|
stream.close();
|
||||||
stream = null;
|
stream = null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
stream = null;
|
stream = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return "1.1.0";
|
return "1.1.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Style getDefaultUserStyle(LayerFactory.LayerType layerType, String serverName, String tableName, String layerName)
|
public static Style getDefaultUserStyle(LayerFactory.LayerType layerType, String serverName, String tableName, String layerName) {
|
||||||
{
|
|
||||||
Style uStyle = sf.createStyle();
|
Style uStyle = sf.createStyle();
|
||||||
uStyle.featureTypeStyles().add(getDefaultFeatureTypeStyle(layerType, serverName, tableName));
|
uStyle.featureTypeStyles().add(getDefaultFeatureTypeStyle(layerType, serverName, tableName));
|
||||||
uStyle.setDefault(true);
|
uStyle.setDefault(true);
|
||||||
uStyle.setName("");
|
uStyle.setName("");
|
||||||
|
if (!ServerUtil.isNullString(layerName))
|
||||||
if (!ServerUtil.isNullString(layerName)) {
|
uStyle.setName(layerName);
|
||||||
uStyle.setName(layerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return uStyle;
|
return uStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FeatureTypeStyle getDefaultFeatureTypeStyle(LayerFactory.LayerType layerType, String serverName, String tableName)
|
private static FeatureTypeStyle getDefaultFeatureTypeStyle(LayerFactory.LayerType layerType, String serverName, String tableName) {
|
||||||
{
|
|
||||||
Rule rule = null;
|
Rule rule = null;
|
||||||
if ((layerType == LayerFactory.LayerType.JDBC) ||
|
if (layerType == LayerFactory.LayerType.JDBC ||
|
||||||
(layerType == LayerFactory.LayerType.GEOWAVE) ||
|
layerType == LayerFactory.LayerType.GEOWAVE ||
|
||||||
(layerType == LayerFactory.LayerType.SHAPE) ||
|
layerType == LayerFactory.LayerType.SHAPE ||
|
||||||
(layerType == LayerFactory.LayerType.O2WPSVEC))
|
layerType == LayerFactory.LayerType.O2WPSVEC) {
|
||||||
{
|
|
||||||
GeometryMngr.GeomType geomType = GeometryMngr.GeomType.LINE;
|
GeometryMngr.GeomType geomType = GeometryMngr.GeomType.LINE;
|
||||||
String geomColumnName = null;
|
String geomColumnName = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
geomType = GeometryMngr.getGeometryType(layerType, serverName, tableName);
|
geomType = GeometryMngr.getGeometryType(layerType, serverName, tableName);
|
||||||
geomColumnName = GeometryMngr.getGeometryColumn(layerType, serverName, tableName);
|
geomColumnName = GeometryMngr.getGeometryColumn(layerType, serverName, tableName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogMngr.getInstance().logError("[STYLE]", "[StyleMngr.getDefaultFeatureTypeStyle]" + e);
|
LogMngr.getInstance().logError("[STYLE]", "[StyleMngr.getDefaultFeatureTypeStyle]" + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
rule = createFeatureTypeRule(geomType, geomColumnName);
|
rule = createFeatureTypeRule(geomType, geomColumnName);
|
||||||
}
|
} else if (layerType == LayerFactory.LayerType.O2DEM ||
|
||||||
else if ((layerType == LayerFactory.LayerType.O2DEM) ||
|
layerType == LayerFactory.LayerType.O2WPSCOV) {
|
||||||
(layerType == LayerFactory.LayerType.O2WPSCOV))
|
|
||||||
{
|
|
||||||
RasterSymbolizerImpl sym = new RasterSymbolizerImpl();
|
RasterSymbolizerImpl sym = new RasterSymbolizerImpl();
|
||||||
sym.setShadedRelief(new ShadedReliefImpl());
|
sym.setShadedRelief((ShadedRelief)new ShadedReliefImpl());
|
||||||
|
|
||||||
rule = sf.createRule();
|
rule = sf.createRule();
|
||||||
rule.setName("RULE");
|
rule.setName("RULE");
|
||||||
rule.symbolizers().add(sym);
|
rule.symbolizers().add(sym);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
rule = sf.createRule();
|
rule = sf.createRule();
|
||||||
rule.setName("RULE");
|
rule.setName("RULE");
|
||||||
rule.symbolizers().clear();
|
rule.symbolizers().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
FeatureTypeStyle ftStyle = sf.createFeatureTypeStyle();
|
FeatureTypeStyle ftStyle = sf.createFeatureTypeStyle();
|
||||||
ftStyle.rules().add(rule);
|
ftStyle.rules().add(rule);
|
||||||
ftStyle.setName("FEATURETYPESTYLE");
|
ftStyle.setName("FEATURETYPESTYLE");
|
||||||
|
|
||||||
return ftStyle;
|
return ftStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Rule createFeatureTypeRule(GeometryMngr.GeomType geomType, String geomColumnName) {
|
private static Rule createFeatureTypeRule(GeometryMngr.GeomType geomType, String geomColumnName) {
|
||||||
|
PolygonSymbolizer polygonSymbolizer;
|
||||||
|
LineSymbolizer lineSymbolizer;
|
||||||
|
PointSymbolizer pointSymbolizer = null;
|
||||||
|
Mark mark;
|
||||||
|
Graphic graphic;
|
||||||
Symbolizer symbolizer = null;
|
Symbolizer symbolizer = null;
|
||||||
Fill fill = null;
|
Fill fill = null;
|
||||||
Stroke stroke = sf.createStroke(ff.literal(LINE_COLOR), ff.literal(1.0F));
|
Stroke stroke = sf.createStroke((Expression)ff.literal(LINE_COLOR), (Expression)ff.literal(1.0F));
|
||||||
|
|
||||||
switch (geomType) {
|
switch (geomType) {
|
||||||
case POLYGON:
|
case POLYGON:
|
||||||
fill = sf.createFill(ff.literal(FILL_COLOR), ff.literal(1.0F));
|
fill = sf.createFill((Expression)ff.literal(FILL_COLOR), (Expression)ff.literal(1.0F));
|
||||||
symbolizer = sf.createPolygonSymbolizer(stroke, fill, geomColumnName);
|
polygonSymbolizer = sf.createPolygonSymbolizer(stroke, fill, geomColumnName);
|
||||||
symbolizer.setName("POLYGONSYMBOLIZER");
|
polygonSymbolizer.setName("POLYGONSYMBOLIZER");
|
||||||
break;
|
break;
|
||||||
case POINT:
|
case LINE:
|
||||||
symbolizer = sf.createLineSymbolizer(stroke, geomColumnName);
|
lineSymbolizer = sf.createLineSymbolizer(stroke, geomColumnName);
|
||||||
symbolizer.setName("LINESYMBOLIZER");
|
lineSymbolizer.setName("LINESYMBOLIZER");
|
||||||
break;
|
break;
|
||||||
case LINE:
|
case POINT:
|
||||||
fill = sf.createFill(ff.literal(FILL_COLOR), ff.literal(1.0F));
|
fill = sf.createFill((Expression)ff.literal(FILL_COLOR), (Expression)ff.literal(1.0F));
|
||||||
|
mark = sf.getCircleMark();
|
||||||
Mark mark = sf.getCircleMark();
|
mark.setFill((Fill)fill);
|
||||||
mark.setFill(fill);
|
mark.setStroke((Stroke)stroke);
|
||||||
mark.setStroke(stroke);
|
graphic = sf.createDefaultGraphic();
|
||||||
|
graphic.graphicalSymbols().clear();
|
||||||
Graphic graphic = sf.createDefaultGraphic();
|
graphic.graphicalSymbols().add(mark);
|
||||||
graphic.graphicalSymbols().clear();
|
graphic.setSize((Expression)ff.literal(10.0F));
|
||||||
graphic.graphicalSymbols().add(mark);
|
pointSymbolizer = sf.createPointSymbolizer(graphic, geomColumnName);
|
||||||
graphic.setSize(ff.literal(10.0F));
|
pointSymbolizer.setName("POINTSYMBOLIZER");
|
||||||
|
break;
|
||||||
symbolizer = sf.createPointSymbolizer(graphic, geomColumnName);
|
}
|
||||||
symbolizer.setName("POINTSYMBOLIZER");
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule rule = sf.createRule();
|
Rule rule = sf.createRule();
|
||||||
rule.setName("RULE");
|
rule.setName("RULE");
|
||||||
rule.symbolizers().add(symbolizer);
|
rule.symbolizers().add(pointSymbolizer);
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MarkStyle2D createDefaultMarkStyle()
|
public static MarkStyle2D createDefaultMarkStyle() {
|
||||||
{
|
|
||||||
MarkStyle2D mark = new MarkStyle2D();
|
MarkStyle2D mark = new MarkStyle2D();
|
||||||
mark.setShape(new Rectangle2D.Double(-0.5D, -0.5D, 1.0D, 1.0D));
|
mark.setShape(new Rectangle2D.Double(-0.5D, -0.5D, 1.0D, 1.0D));
|
||||||
|
|
||||||
mark.setFill(FILL_COLOR);
|
mark.setFill(FILL_COLOR);
|
||||||
mark.setFillComposite(AlphaComposite.getInstance(3, 1.0F));
|
mark.setFillComposite(AlphaComposite.getInstance(3, 1.0F));
|
||||||
|
|
||||||
mark.setStroke(new BasicStroke(1.0F, 2, 0, 1.0F));
|
mark.setStroke(new BasicStroke(1.0F, 2, 0, 1.0F));
|
||||||
|
|
||||||
mark.setContour(LINE_COLOR);
|
mark.setContour(LINE_COLOR);
|
||||||
mark.setContourComposite(AlphaComposite.getInstance(3, 1.0F));
|
mark.setContourComposite(AlphaComposite.getInstance(3, 1.0F));
|
||||||
|
|
||||||
mark.setSize(16.0D);
|
mark.setSize(16.0D);
|
||||||
|
|
||||||
return mark;
|
return mark;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class TMSInfo {
|
||||||
|
private boolean activate = false;
|
||||||
|
private String layerName;
|
||||||
|
private File layerPath;
|
||||||
|
|
||||||
|
public void setLayerName(String name) {
|
||||||
|
if (ServerUtil.isNullString((String)name)) {
|
||||||
|
this.layerName = null;
|
||||||
|
}
|
||||||
|
this.layerName = name.trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivate(String actiStr) {
|
||||||
|
this.activate = ServerUtil.getBooleanValue((String)actiStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerPath(String path) {
|
||||||
|
if (ServerUtil.isNullString((String)path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file = new File(path.trim());
|
||||||
|
if (file.exists()) {
|
||||||
|
this.layerPath = file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.layerPath = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActivate() {
|
||||||
|
return this.activate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerName() {
|
||||||
|
return this.layerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getLayerPath() {
|
||||||
|
return this.layerPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAvailable() {
|
||||||
|
if (!this.activate) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.activate] is False");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)this.layerName)) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.name] is Empty");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.layerPath == null) {
|
||||||
|
LogMngr.getInstance().logError("[LAYER]", "Layer info [layer.path] is not exist");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,160 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class TMSMngr {
|
||||||
|
private static ConcurrentHashMap<String, File> tmsStore = new ConcurrentHashMap();
|
||||||
|
private static ConcurrentHashMap<String, File> dirtyTmsStore;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING - Removed try catching itself - possible behaviour change.
|
||||||
|
*/
|
||||||
|
public static void initLayers() {
|
||||||
|
ConcurrentHashMap<String, File> concurrentHashMap = tmsStore = new ConcurrentHashMap();
|
||||||
|
synchronized (concurrentHashMap) {
|
||||||
|
try {
|
||||||
|
File dir = ServerContext.getPluginsFolder();
|
||||||
|
FilenameFilter filter = new FilenameFilter(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept(File directory, String fileName) {
|
||||||
|
return fileName.toUpperCase().equals("TMS.LAYERS");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
File[] files = dir.listFiles(filter);
|
||||||
|
LogMngr.getInstance().logDebug("[TMS]", "Size of TMS Layer configuration is " + files.length);
|
||||||
|
File[] fileArray = files;
|
||||||
|
int n = files.length;
|
||||||
|
int n2 = 0;
|
||||||
|
while (n2 < n) {
|
||||||
|
File file = fileArray[n2];
|
||||||
|
LogMngr.getInstance().logDebug("[TMS]", "[" + file.getName() + "] Now create this TMS Layer");
|
||||||
|
try {
|
||||||
|
ArrayList<TMSInfo> infoList = TMSMngr.parseTMSLayer(file);
|
||||||
|
for (TMSInfo info : infoList) {
|
||||||
|
tmsStore.put(info.getLayerName(), info.getLayerPath());
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "[" + file.getName() + "] Add TMS Layer Success :: ID = " + info.getLayerName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[TMS]", "[" + file.getName() + "] Add WMTS Layer Fail :: " + e);
|
||||||
|
}
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "");
|
||||||
|
++n2;
|
||||||
|
}
|
||||||
|
if (tmsStore.size() == 0) {
|
||||||
|
LogMngr.getInstance().logError("[TMS]", "Create TMS Layer Fail :: Layer Count is [0]");
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "Create TMS Layer Success :: Layer Count is [" + tmsStore.size() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[TMS]", "Create TMS Layer Fail :: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArrayList<TMSInfo> parseTMSLayer(File conf) {
|
||||||
|
if (!conf.exists()) {
|
||||||
|
LogMngr.getInstance().logError("[TMS]", "[" + conf.getName() + "] Create TMS Layer Fail :: TMS configuration is not exist");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArrayList<TMSInfo> layerInfoList = new ArrayList<TMSInfo>();
|
||||||
|
TMSInfo lInfo = null;
|
||||||
|
BufferedReader bReader = null;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
String line;
|
||||||
|
bReader = new BufferedReader(new FileReader(conf));
|
||||||
|
while ((line = bReader.readLine()) != null) {
|
||||||
|
if ((line = line.trim()).startsWith("#") || ServerUtil.isNullString((String)line)) continue;
|
||||||
|
try {
|
||||||
|
if (line.equalsIgnoreCase("[LAYER_CONFIG]")) {
|
||||||
|
lInfo = new TMSInfo();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.ACTIVATE")) {
|
||||||
|
lInfo.setActivate(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.NAME")) {
|
||||||
|
lInfo.setLayerName(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.toUpperCase().contains("LAYER.PATH")) {
|
||||||
|
lInfo.setLayerPath(line.split("\\=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!line.equalsIgnoreCase("[/LAYER_CONFIG]")) continue;
|
||||||
|
if (lInfo != null && lInfo.isAvailable()) {
|
||||||
|
layerInfoList.add(lInfo);
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().logError("[TMS]", "[" + conf.getName() + "] Skip this TMS Layer :: Layer info is not available [" + lInfo.getLayerName() + "]");
|
||||||
|
}
|
||||||
|
lInfo = null;
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[TMS]", "[" + conf.getName() + "] TMS Layer configuration file is not valid :: " + e);
|
||||||
|
try {
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e2) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (bReader != null) {
|
||||||
|
bReader.close();
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
bReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return layerInfoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void reloadLayer() throws Exception {
|
||||||
|
try {
|
||||||
|
dirtyTmsStore = tmsStore;
|
||||||
|
TMSMngr.initLayers();
|
||||||
|
dirtyTmsStore.clear();
|
||||||
|
dirtyTmsStore = null;
|
||||||
|
LogMngr.getInstance().logInfo("[TMS]", "Success to reload TMSLayer.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LogMngr.getInstance().logError("[TMS]", "Fail to reload TMSLayer. Now use previous TMSLayer :: " + e);
|
||||||
|
tmsStore = dirtyTmsStore;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getPath(String id) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)id)) {
|
||||||
|
throw new NullPointerException("ID value is NULL.");
|
||||||
|
}
|
||||||
|
File path = tmsStore.get(id.trim().toUpperCase());
|
||||||
|
if (path == null || !path.exists()) {
|
||||||
|
throw new NullPointerException("Layer [" + id.trim() + "] is not exist in TMS Service.");
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Coordinate;
|
||||||
|
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||||
|
import com.vividsolutions.jts.geom.Point;
|
||||||
|
import javax.management.modelmbean.XMLParseException;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.opengis.referencing.crs.GeographicCRS;
|
||||||
|
|
||||||
|
public class TileMatrix {
|
||||||
|
static final double OGC_DEGREE_TO_METER = 111319.49079327358;
|
||||||
|
static final double OGC_INCH_TO_METER = 0.0254;
|
||||||
|
private final int level;
|
||||||
|
private final String identifier;
|
||||||
|
private double dpi;
|
||||||
|
private Double resolution;
|
||||||
|
private Double scaleDenominator;
|
||||||
|
private boolean topLeft = false;
|
||||||
|
private ReferencedEnvelope extent;
|
||||||
|
private Point topleftCorner;
|
||||||
|
private int tileWidth;
|
||||||
|
private int tileHeight;
|
||||||
|
private int matrixWidth;
|
||||||
|
private int matrixHeight;
|
||||||
|
private TileMatrixRule.RuleType rule = TileMatrixRule.RuleType.COLUMN_FIRST;
|
||||||
|
|
||||||
|
public TileMatrix(Integer lv, String id, Double res, Double scale) throws Exception {
|
||||||
|
this.level = lv;
|
||||||
|
this.identifier = id.trim();
|
||||||
|
this.resolution = res;
|
||||||
|
this.scaleDenominator = scale;
|
||||||
|
if (this.resolution == null && this.scaleDenominator == null) {
|
||||||
|
throw new XMLParseException("<MATRIX> Attribute value [RESOLUTION or SCALE] is null. LEVEL [" + this.level + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return this.level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdentifier() {
|
||||||
|
return this.identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getResolution() {
|
||||||
|
return this.resolution;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getScaleDenominator() {
|
||||||
|
return this.scaleDenominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getTopLeftCorner() {
|
||||||
|
return this.topleftCorner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTileWidth() {
|
||||||
|
return this.tileWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTileHeight() {
|
||||||
|
return this.tileHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMatrixWidth() {
|
||||||
|
return this.matrixWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMatrixHeight() {
|
||||||
|
return this.matrixHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileMatrixRule.RuleType getRule() {
|
||||||
|
return this.rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTopLeft() {
|
||||||
|
return this.topLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refineTileMatrix(TileMatrixSet matrixSet) throws Exception {
|
||||||
|
this.rule = matrixSet.getRule();
|
||||||
|
this.extent = matrixSet.getTileExtent();
|
||||||
|
this.dpi = matrixSet.getDpi();
|
||||||
|
if (this.resolution == null) {
|
||||||
|
this.resolution = this.calResolution(this.scaleDenominator);
|
||||||
|
} else if (this.scaleDenominator == null) {
|
||||||
|
this.scaleDenominator = this.calScaleDenominator(this.resolution);
|
||||||
|
}
|
||||||
|
this.tileWidth = matrixSet.getTileWidth();
|
||||||
|
this.tileHeight = matrixSet.getTileHeight();
|
||||||
|
this.matrixWidth = (int)Math.round(this.extent.getWidth() / (this.resolution * (double)this.tileWidth));
|
||||||
|
this.matrixHeight = (int)Math.round(this.extent.getHeight() / (this.resolution * (double)this.tileHeight));
|
||||||
|
Coordinate coord = new Coordinate(this.extent.getMinX(), this.extent.getMaxY());
|
||||||
|
this.topleftCorner = new GeometryFactory().createPoint(coord);
|
||||||
|
this.topLeft = matrixSet.isTopLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calScaleDenominator(double res) {
|
||||||
|
if (this.extent.getCoordinateReferenceSystem() instanceof GeographicCRS) {
|
||||||
|
return res * 111319.49079327358 / (0.0254 / this.dpi);
|
||||||
|
}
|
||||||
|
return res / (0.0254 / this.dpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calResolution(double scale) {
|
||||||
|
if (this.extent.getCoordinateReferenceSystem() instanceof GeographicCRS) {
|
||||||
|
return scale * (0.0254 / this.dpi) * 8.983152841195214E-6;
|
||||||
|
}
|
||||||
|
return scale * (0.0254 / this.dpi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class TileMatrixRule {
|
||||||
|
public static String createPath(TileMatrix matrix, int col, int row, String format) {
|
||||||
|
if (!matrix.isTopLeft()) {
|
||||||
|
row = matrix.getMatrixHeight() - 1 - row;
|
||||||
|
}
|
||||||
|
switch (matrix.getRule()) {
|
||||||
|
case COLUMN_FIRST: {
|
||||||
|
return String.valueOf(matrix.getIdentifier()) + File.separatorChar + col + File.separatorChar + row + "." + format;
|
||||||
|
}
|
||||||
|
case ROW_FIRST: {
|
||||||
|
return String.valueOf(matrix.getIdentifier()) + File.separatorChar + row + File.separatorChar + col + "." + format;
|
||||||
|
}
|
||||||
|
case GWC: {
|
||||||
|
StringBuffer path = new StringBuffer();
|
||||||
|
path.append(matrix.getIdentifier());
|
||||||
|
path.append(File.separatorChar);
|
||||||
|
long shift = matrix.getLevel() / 2;
|
||||||
|
long half = 2 << (int)shift;
|
||||||
|
int digits = 1;
|
||||||
|
if (half > 10L) {
|
||||||
|
digits = (int)Math.log10(half) + 1;
|
||||||
|
}
|
||||||
|
long halfx = (long)col / half;
|
||||||
|
long halfy = (long)row / half;
|
||||||
|
TileMatrixRule.zeroPadder(halfx, digits, path);
|
||||||
|
path.append('_');
|
||||||
|
TileMatrixRule.zeroPadder(halfy, digits, path);
|
||||||
|
path.append(File.separatorChar);
|
||||||
|
TileMatrixRule.zeroPadder(col, 2 * digits, path);
|
||||||
|
path.append('_');
|
||||||
|
TileMatrixRule.zeroPadder(row, 2 * digits, path);
|
||||||
|
path.append('.');
|
||||||
|
path.append(format);
|
||||||
|
return path.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RuleType getRuleType(String rule) {
|
||||||
|
if (rule.equalsIgnoreCase("COLUMN") || rule.equalsIgnoreCase("COL") || rule.equalsIgnoreCase("C") || rule.equalsIgnoreCase("X")) {
|
||||||
|
return RuleType.COLUMN_FIRST;
|
||||||
|
}
|
||||||
|
if (rule.equalsIgnoreCase("ROW") || rule.equalsIgnoreCase("R") || rule.equalsIgnoreCase("Y")) {
|
||||||
|
return RuleType.ROW_FIRST;
|
||||||
|
}
|
||||||
|
if (rule.equalsIgnoreCase("GWC") || rule.equalsIgnoreCase("G") || rule.equalsIgnoreCase("GEOWEBCACHE")) {
|
||||||
|
return RuleType.GWC;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void zeroPadder(long number, int order, StringBuffer padding) {
|
||||||
|
int diffOrder;
|
||||||
|
int numberOrder = 1;
|
||||||
|
if (number > 9L) {
|
||||||
|
numberOrder = number > 11L ? (int)Math.ceil(Math.log10(number) - 0.001) : 2;
|
||||||
|
}
|
||||||
|
if ((diffOrder = order - numberOrder) > 0) {
|
||||||
|
while (diffOrder > 0) {
|
||||||
|
padding.append('0');
|
||||||
|
--diffOrder;
|
||||||
|
}
|
||||||
|
padding.append(number);
|
||||||
|
} else {
|
||||||
|
padding.append(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum RuleType {
|
||||||
|
COLUMN_FIRST,
|
||||||
|
ROW_FIRST,
|
||||||
|
GWC;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,159 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.opengis.referencing.ReferenceIdentifier;
|
||||||
|
|
||||||
|
public class TileMatrixSet {
|
||||||
|
private String identifier;
|
||||||
|
private TileMatrixRule.RuleType rule;
|
||||||
|
private String supportedCRS;
|
||||||
|
private String tileExtension;
|
||||||
|
private String tileFormat;
|
||||||
|
private int tileWidth;
|
||||||
|
private int tileHeight;
|
||||||
|
private double dpi = 90.7142857142857;
|
||||||
|
private boolean topLeft = false;
|
||||||
|
private File tileLocation;
|
||||||
|
private File emptyTile;
|
||||||
|
private ReferencedEnvelope tileExtent;
|
||||||
|
private HashMap<String, TileMatrix> matrixSet = new HashMap();
|
||||||
|
|
||||||
|
public TileMatrixSet(AVList params) throws Exception {
|
||||||
|
String sVal = params.getStringValue("wmts.conf.tile.id");
|
||||||
|
if (ServerUtil.isNullString((String)sVal)) {
|
||||||
|
throw new IllegalArgumentException("ID is NULL.");
|
||||||
|
}
|
||||||
|
this.identifier = sVal.trim();
|
||||||
|
TileMatrixRule.RuleType type = (TileMatrixRule.RuleType)params.getValue("wmts.conf.tile.rule");
|
||||||
|
if (type == null) {
|
||||||
|
throw new IllegalArgumentException("RULE is NULL.");
|
||||||
|
}
|
||||||
|
this.rule = type;
|
||||||
|
File dir = (File)params.getValue("wmts.conf.tile.location");
|
||||||
|
if (dir == null || !dir.exists() || dir.isFile()) {
|
||||||
|
throw new IllegalArgumentException("TileLocation is not exists.");
|
||||||
|
}
|
||||||
|
this.tileLocation = dir;
|
||||||
|
File file = (File)params.getValue("wmts.conf.empty.tile");
|
||||||
|
if (file != null && file.exists() && file.isFile()) {
|
||||||
|
try {
|
||||||
|
ImageIO.read(file);
|
||||||
|
this.emptyTile = file;
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
// empty catch block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ServerUtil.isNullString((String)(sVal = params.getStringValue("wmts.conf.tile.format.extension")))) {
|
||||||
|
throw new IllegalArgumentException("TileFormat Extension is NULL.");
|
||||||
|
}
|
||||||
|
this.tileExtension = sVal.trim();
|
||||||
|
if (this.tileExtension.startsWith(".")) {
|
||||||
|
this.tileExtension = this.tileExtension.substring(1);
|
||||||
|
}
|
||||||
|
this.tileFormat = ServerUtil.isNullString((String)(sVal = params.getStringValue("wmts.conf.tile.format"))) ? "image/" + this.tileExtension : sVal.trim();
|
||||||
|
Integer iVal = params.getIntegerValue("wmts.conf.tile.width");
|
||||||
|
if (iVal == null) {
|
||||||
|
throw new IllegalArgumentException("TileFormat Width is NULL.");
|
||||||
|
}
|
||||||
|
this.tileWidth = iVal;
|
||||||
|
iVal = params.getIntegerValue("wmts.conf.tile.height");
|
||||||
|
if (iVal == null) {
|
||||||
|
throw new IllegalArgumentException("TileFormat Height is NULL.");
|
||||||
|
}
|
||||||
|
this.tileHeight = iVal;
|
||||||
|
ArrayList<TileMatrix> list = (ArrayList)params.getValue("wmts.conf.tile.matrix");
|
||||||
|
if (list == null) {
|
||||||
|
throw new IllegalArgumentException("TileMatrix value is NULL.");
|
||||||
|
}
|
||||||
|
for (TileMatrix matrix : list) {
|
||||||
|
this.matrixSet.put(matrix.getIdentifier().trim().toUpperCase(), matrix);
|
||||||
|
}
|
||||||
|
ReferencedEnvelope bbox = (ReferencedEnvelope)params.getValue("wmts.conf.tile.extent");
|
||||||
|
if (bbox == null) {
|
||||||
|
throw new IllegalArgumentException("TileExtent value is NULL.");
|
||||||
|
}
|
||||||
|
this.tileExtent = bbox;
|
||||||
|
Double dVal = params.getDoubleValue("wmts.conf.tile.dpi");
|
||||||
|
if (dVal != null) {
|
||||||
|
this.dpi = dVal;
|
||||||
|
}
|
||||||
|
this.topLeft = params.getBooleanValue("wmts.conf.tile.dpi", Boolean.valueOf(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdentifier() {
|
||||||
|
return this.identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSupportedCRS() {
|
||||||
|
return this.supportedCRS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileMatrixRule.RuleType getRule() {
|
||||||
|
return this.rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTileFormat() {
|
||||||
|
return this.tileFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTileExtension() {
|
||||||
|
return this.tileExtension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTileWidth() {
|
||||||
|
return this.tileWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTileHeight() {
|
||||||
|
return this.tileHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getTileLocation() {
|
||||||
|
return this.tileLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getEmptyTile() {
|
||||||
|
return this.emptyTile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencedEnvelope getTileExtent() {
|
||||||
|
return this.tileExtent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDpi() {
|
||||||
|
return this.dpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTopLeft() {
|
||||||
|
return this.topLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileMatrix getTileMatrix(String id) throws Exception {
|
||||||
|
if (ServerUtil.isNullString((String)id)) {
|
||||||
|
throw new NullPointerException("ID value is NULL.");
|
||||||
|
}
|
||||||
|
return this.matrixSet.get(id.trim().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<TileMatrix> getTileMatrixList() {
|
||||||
|
ArrayList<TileMatrix> resultList = new ArrayList<TileMatrix>();
|
||||||
|
TreeSet<String> tSet = new TreeSet<String>(this.matrixSet.keySet());
|
||||||
|
for (String key : tSet) {
|
||||||
|
resultList.add(this.matrixSet.get(key));
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refineTileMatrixSet(WMTSLayer layer) throws Exception {
|
||||||
|
this.supportedCRS = ((ReferenceIdentifier)this.tileExtent.getCoordinateReferenceSystem().getIdentifiers().iterator().next()).toString();
|
||||||
|
for (TileMatrix tileMatrix : this.matrixSet.values()) {
|
||||||
|
tileMatrix.refineTileMatrix(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.jdom.Document;
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.input.SAXBuilder;
|
||||||
|
|
||||||
|
public class WCSLayer
|
||||||
|
extends LinkLayer {
|
||||||
|
private Envelope bbox;
|
||||||
|
|
||||||
|
public WCSLayer(AVList params) throws Exception {
|
||||||
|
super(params);
|
||||||
|
String[] layerNames;
|
||||||
|
HashMap<String, Envelope> serviceLayers = this.getServiceLayers();
|
||||||
|
Envelope layerBBox = null;
|
||||||
|
String[] stringArray = layerNames = this.getServiceLayerNames().split(",");
|
||||||
|
int n = layerNames.length;
|
||||||
|
int n2 = 0;
|
||||||
|
while (n2 < n) {
|
||||||
|
String name = stringArray[n2];
|
||||||
|
Envelope envelope = serviceLayers.get(name.trim());
|
||||||
|
if (envelope == null) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
if (layerBBox == null) {
|
||||||
|
layerBBox = envelope;
|
||||||
|
} else {
|
||||||
|
layerBBox.expandToInclude(envelope);
|
||||||
|
}
|
||||||
|
++n2;
|
||||||
|
}
|
||||||
|
this.bbox = layerBBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, Envelope> getServiceLayers() throws Exception {
|
||||||
|
try {
|
||||||
|
HashMap<String, Envelope> serviceLayers = new HashMap<String, Envelope>();
|
||||||
|
URL url = new URL(this.getServiceURL().toURI() + "?request=getlayerinfo");
|
||||||
|
URLConnection conn = url.openConnection();
|
||||||
|
conn.setConnectTimeout(5000);
|
||||||
|
conn.setReadTimeout(1000);
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
conn.connect();
|
||||||
|
SAXBuilder builder = new SAXBuilder();
|
||||||
|
Document document = builder.build(conn.getInputStream());
|
||||||
|
Element rootNode = document.getRootElement();
|
||||||
|
List list = rootNode.getChildren("layer");
|
||||||
|
int i = 0;
|
||||||
|
while (i < list.size()) {
|
||||||
|
Element layer = (Element)list.get(i);
|
||||||
|
String name = layer.getChild("layer_name").getTextTrim();
|
||||||
|
Boolean type = layer.getChild("layer_type").getTextTrim().toLowerCase().equals("o2map_dem");
|
||||||
|
if (type.booleanValue()) {
|
||||||
|
Element bbox = layer.getChild("service_info").getChild("envelope");
|
||||||
|
Double minx = Double.parseDouble(bbox.getChild("minx").getTextTrim());
|
||||||
|
Double miny = Double.parseDouble(bbox.getChild("miny").getTextTrim());
|
||||||
|
Double maxx = Double.parseDouble(bbox.getChild("maxx").getTextTrim());
|
||||||
|
Double maxy = Double.parseDouble(bbox.getChild("maxy").getTextTrim());
|
||||||
|
Envelope envelope = new Envelope(minx.doubleValue(), maxx.doubleValue(), miny.doubleValue(), maxy.doubleValue());
|
||||||
|
serviceLayers.put(name, envelope);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return serviceLayers;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencedEnvelope getBBox() {
|
||||||
|
return new ReferencedEnvelope(this.bbox, this.getCRS());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,106 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||||
|
import com.vividsolutions.jts.io.ByteArrayInStream;
|
||||||
|
import com.vividsolutions.jts.io.WKBReader;
|
||||||
|
import com.vividsolutions.jts.io.WKBWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import org.geotools.data.DataSourceException;
|
||||||
|
|
||||||
|
public class WKBAttributeIO
|
||||||
|
{
|
||||||
|
WKBReader wkbr;
|
||||||
|
ByteArrayInStream inStream = new ByteArrayInStream(new byte[0]);
|
||||||
|
GeometryFactory gf;
|
||||||
|
|
||||||
|
public WKBAttributeIO()
|
||||||
|
{
|
||||||
|
this(new GeometryFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
public WKBAttributeIO(GeometryFactory gf) {
|
||||||
|
this.wkbr = new WKBReader(gf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGeometryFactory(GeometryFactory gf) {
|
||||||
|
this.wkbr = new WKBReader(gf);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Geometry wkb2Geometry(byte[] wkbBytes) throws IOException
|
||||||
|
{
|
||||||
|
if (wkbBytes == null)
|
||||||
|
return null;
|
||||||
|
try {
|
||||||
|
this.inStream.setBytes(wkbBytes);
|
||||||
|
return this.wkbr.read(this.inStream);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DataSourceException("An exception occurred while parsing WKB data", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object read(ResultSet rs, String columnName) throws IOException {
|
||||||
|
try {
|
||||||
|
byte[] bytes = rs.getBytes(columnName);
|
||||||
|
if (bytes == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wkb2Geometry(bytes);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DataSourceException("SQL exception occurred while reading the geometry.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object read(ResultSet rs, int columnIndex) throws IOException {
|
||||||
|
try {
|
||||||
|
byte[] bytes = rs.getBytes(columnIndex);
|
||||||
|
if (bytes == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wkb2Geometry(bytes);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DataSourceException("SQL exception occurred while reading the geometry.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(PreparedStatement ps, int position, Object value) throws IOException {
|
||||||
|
try {
|
||||||
|
if (value == null)
|
||||||
|
ps.setNull(position, 1111);
|
||||||
|
else
|
||||||
|
ps.setBytes(position, new WKBWriter().write((Geometry)value));
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
throw new DataSourceException("SQL exception occurred while reading the geometry.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte getFromChar(char c)
|
||||||
|
{
|
||||||
|
if (c <= '9')
|
||||||
|
return (byte)(c - '0');
|
||||||
|
if (c <= 'F') {
|
||||||
|
return (byte)(c - 'A' + 10);
|
||||||
|
}
|
||||||
|
return (byte)(c - 'a' + 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Geometry read(byte[] wkbBytes) throws IOException
|
||||||
|
{
|
||||||
|
if (wkbBytes == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.inStream.setBytes(wkbBytes);
|
||||||
|
return this.wkbr.read(wkbBytes);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DataSourceException("An exception occurred while parsing WKB data", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class WMSController {
|
||||||
|
private static final long serialVersionUID = 2025061221213030L;
|
||||||
|
|
||||||
|
public Request parseQuery(HttpServletRequest req) throws OWSServiceException, Exception {
|
||||||
|
Request requestObj = new WMSParser(req).parseQuery(); // 이 부분은 중요하므로 아래에서 설명한다.
|
||||||
|
return requestObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(WMSController.class);
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/drilling/map/init.do", method = RequestMethod.GET)
|
||||||
|
public void drillingMapInit(HttpServletRequest req, HttpServletResponse resp) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
|
//아래 코드는 최초 1회만 호출되어야하는 코드임. 테스트로 여기에 넣고 호출 중..
|
||||||
|
if (ServerConfiguration.getInstance().startServer())
|
||||||
|
ServerInfo.getInstance().setStarted(true);
|
||||||
|
else {
|
||||||
|
ServerInfo.getInstance().setStarted(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceMngr.initServices();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/drilling/map/start.do", method = RequestMethod.GET)
|
||||||
|
public void drillingMapStart(HttpServletRequest req, HttpServletResponse resp) throws Exception {
|
||||||
|
|
||||||
|
Service svc = new Service();
|
||||||
|
svc.service(req, resp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/drilling/map/wms.do", method = RequestMethod.GET)
|
||||||
|
public void drillingMapWms(HttpServletRequest req, HttpServletResponse resp) throws Exception {
|
||||||
|
|
||||||
|
WMSService wmsSvc = new WMSService();
|
||||||
|
wmsSvc.doGet(req, resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,460 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.referencing.CRS;
|
||||||
|
import org.opengis.geometry.BoundingBox;
|
||||||
|
import org.opengis.referencing.FactoryException;
|
||||||
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.helpers.NamespaceSupport;
|
||||||
|
|
||||||
|
public class WMSGetCapabilities
|
||||||
|
{
|
||||||
|
private ArrayList<Layer> layerList = new ArrayList();
|
||||||
|
private GetCapabilitiesRequest requestObj = null;
|
||||||
|
private Document doc;
|
||||||
|
private NamespaceSupport support = new NamespaceSupport();
|
||||||
|
|
||||||
|
public WMSGetCapabilities(GetCapabilitiesRequest requestObj) {
|
||||||
|
this.requestObj = requestObj;
|
||||||
|
|
||||||
|
this.support.declarePrefix("wms", "http://www.opengis.net/wms");
|
||||||
|
|
||||||
|
this.support.declarePrefix("xlink", "http://www.w3.org/1999/xlink");
|
||||||
|
this.support.declarePrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
||||||
|
this.support.declarePrefix("schemaLocation", "http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Document getCapabilities()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ArrayList layers = ServerContext.getMap().getServiceLayerSet().getLayers();
|
||||||
|
this.layerList.addAll(layers);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
OWSServiceException ose = new OWSServiceException("WMS GetCapabilities Exception : Layers is not exist : " + e.getMessage());
|
||||||
|
this.doc = ose.getDocument();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "WMS GetCapabilities Exception : Layers is not exist : " + e.getMessage());
|
||||||
|
return this.doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.doc = writeCapabilities();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
OWSServiceException ose = new OWSServiceException("WMS GetCapabilities Exception : " + e.getMessage());
|
||||||
|
this.doc = ose.getDocument();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "WMS GetCapabilities Exception : " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Document writeCapabilities()
|
||||||
|
throws ParserConfigurationException, TransformException, FactoryException
|
||||||
|
{
|
||||||
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
docFactory.setNamespaceAware(true);
|
||||||
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||||
|
|
||||||
|
this.doc = docBuilder.newDocument();
|
||||||
|
|
||||||
|
Element rootElement = this.doc.createElementNS(this.support.getURI("wms"), "WMS_Capabilities");
|
||||||
|
rootElement.setAttribute("version", "1.3.0");
|
||||||
|
|
||||||
|
rootElement.setAttribute("xmlns:wms", this.support.getURI("wms"));
|
||||||
|
rootElement.setAttribute("xmlns:xlink", this.support.getURI("xlink"));
|
||||||
|
rootElement.setAttribute("xmlns:xsi", this.support.getURI("xsi"));
|
||||||
|
rootElement.setAttribute("xsi:schemaLocation", this.support.getURI("schemaLocation"));
|
||||||
|
|
||||||
|
this.doc.appendChild(rootElement);
|
||||||
|
|
||||||
|
writeService(rootElement);
|
||||||
|
|
||||||
|
writeCapability(rootElement);
|
||||||
|
|
||||||
|
if (ServerContext.isUseNSPrefix())
|
||||||
|
{
|
||||||
|
rootElement.setPrefix("wms");
|
||||||
|
rootElement.setAttribute("xmlns", this.support.getURI("wms"));
|
||||||
|
|
||||||
|
NodeList nodeList = rootElement.getElementsByTagNameNS(this.support.getURI("wms"), "*");
|
||||||
|
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||||
|
nodeList.item(i).setPrefix("wms");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeService(Element element)
|
||||||
|
{
|
||||||
|
Element serviceElement = this.doc.createElementNS(this.support.getURI("wms"), "Service");
|
||||||
|
element.appendChild(serviceElement);
|
||||||
|
|
||||||
|
Element onlineResourceElement = this.doc.createElementNS(this.support.getURI("wms"), "OnlineResource");
|
||||||
|
onlineResourceElement.setAttributeNS(this.support.getURI("xlink"), "xlink:type", "simple");
|
||||||
|
//onlineResourceElement.setAttributeNS(this.support.getURI("xlink"), "xlink:href", this.requestObj.getBaseURL());
|
||||||
|
serviceElement.appendChild(onlineResourceElement);
|
||||||
|
|
||||||
|
Element nameElement = this.doc.createElementNS(this.support.getURI("wms"), "Name");
|
||||||
|
//nameElement.setTextContent("WMS");
|
||||||
|
serviceElement.appendChild(nameElement);
|
||||||
|
|
||||||
|
Element titleElement = this.doc.createElementNS(this.support.getURI("wms"), "Title");
|
||||||
|
//titleElement.setTextContent("O2Map Web Map Service");
|
||||||
|
serviceElement.appendChild(titleElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeCapability(Element element)
|
||||||
|
throws TransformException, FactoryException
|
||||||
|
{
|
||||||
|
Element capabilityElement = this.doc.createElementNS(this.support.getURI("wms"), "Capability");
|
||||||
|
element.appendChild(capabilityElement);
|
||||||
|
|
||||||
|
Element requestElement = this.doc.createElementNS(this.support.getURI("wms"), "Request");
|
||||||
|
capabilityElement.appendChild(requestElement);
|
||||||
|
|
||||||
|
Element getCapabilitiesElement = this.doc.createElementNS(this.support.getURI("wms"), "GetCapabilities");
|
||||||
|
requestElement.appendChild(getCapabilitiesElement);
|
||||||
|
|
||||||
|
Element formatElement = this.doc.createElementNS(this.support.getURI("wms"), "Format");
|
||||||
|
//formatElement.setTextContent("text/xml");
|
||||||
|
getCapabilitiesElement.appendChild(formatElement);
|
||||||
|
|
||||||
|
Element dcpTypeElement = this.doc.createElementNS(this.support.getURI("wms"), "DCPType");
|
||||||
|
getCapabilitiesElement.appendChild(dcpTypeElement);
|
||||||
|
|
||||||
|
Element httpElement = this.doc.createElementNS(this.support.getURI("wms"), "HTTP");
|
||||||
|
dcpTypeElement.appendChild(httpElement);
|
||||||
|
|
||||||
|
Element getElement = this.doc.createElementNS(this.support.getURI("wms"), "Get");
|
||||||
|
httpElement.appendChild(getElement);
|
||||||
|
|
||||||
|
Element onlineResourceElement1 = this.doc.createElementNS(this.support.getURI("wms"), "OnlineResource");
|
||||||
|
onlineResourceElement1.setAttributeNS(this.support.getURI("xlink"), "xlink:type", "simple");
|
||||||
|
//onlineResourceElement1.setAttributeNS(this.support.getURI("xlink"), "xlink:href", this.requestObj.getBaseURL() + "?");
|
||||||
|
getElement.appendChild(onlineResourceElement1);
|
||||||
|
|
||||||
|
Element postElement = this.doc.createElementNS(this.support.getURI("wms"), "Post");
|
||||||
|
httpElement.appendChild(postElement);
|
||||||
|
|
||||||
|
Element onlineResourceElement2 = this.doc.createElementNS(this.support.getURI("wms"), "OnlineResource");
|
||||||
|
onlineResourceElement2.setAttributeNS(this.support.getURI("xlink"), "xlink:type", "simple");
|
||||||
|
//onlineResourceElement2.setAttributeNS(this.support.getURI("xlink"), "xlink:href", this.requestObj.getBaseURL());
|
||||||
|
postElement.appendChild(onlineResourceElement2);
|
||||||
|
|
||||||
|
Element getMapElement = this.doc.createElementNS(this.support.getURI("wms"), "GetMap");
|
||||||
|
requestElement.appendChild(getMapElement);
|
||||||
|
|
||||||
|
for (int i = 0; i < OWSConstants.imageOutputFormat.size(); i++)
|
||||||
|
{
|
||||||
|
Element formatElement1 = this.doc.createElementNS(this.support.getURI("wms"), "Format");
|
||||||
|
// formatElement1.setTextContent((String)OWSConstants.imageOutputFormat.get(i));
|
||||||
|
getMapElement.appendChild(formatElement1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Element dcpTypeElement1 = this.doc.createElementNS(this.support.getURI("wms"), "DCPType");
|
||||||
|
getMapElement.appendChild(dcpTypeElement1);
|
||||||
|
|
||||||
|
Element httpElement1 = this.doc.createElementNS(this.support.getURI("wms"), "HTTP");
|
||||||
|
dcpTypeElement1.appendChild(httpElement1);
|
||||||
|
|
||||||
|
Element getElement1 = this.doc.createElementNS(this.support.getURI("wms"), "Get");
|
||||||
|
httpElement1.appendChild(getElement1);
|
||||||
|
|
||||||
|
Element onlineResourceElement3 = this.doc.createElementNS(this.support.getURI("wms"), "OnlineResource");
|
||||||
|
onlineResourceElement3.setAttributeNS(this.support.getURI("xlink"), "xlink:type", "simple");
|
||||||
|
//onlineResourceElement3.setAttributeNS(this.support.getURI("xlink"), "xlink:href", this.requestObj.getBaseURL() + "?");
|
||||||
|
getElement1.appendChild(onlineResourceElement3);
|
||||||
|
|
||||||
|
Element postElement1 = this.doc.createElementNS(this.support.getURI("wms"), "Post");
|
||||||
|
httpElement1.appendChild(postElement1);
|
||||||
|
|
||||||
|
Element onlineResourceElement4 = this.doc.createElementNS(this.support.getURI("wms"), "OnlineResource");
|
||||||
|
onlineResourceElement4.setAttributeNS(this.support.getURI("xlink"), "xlink:type", "simple");
|
||||||
|
//onlineResourceElement4.setAttributeNS(this.support.getURI("xlink"), "xlink:href", this.requestObj.getBaseURL());
|
||||||
|
postElement1.appendChild(onlineResourceElement4);
|
||||||
|
|
||||||
|
Element getFeatureInfoElement = this.doc.createElementNS(this.support.getURI("wms"), "GetFeatureInfo");
|
||||||
|
requestElement.appendChild(getFeatureInfoElement);
|
||||||
|
|
||||||
|
for (int i = 0; i < OWSConstants.featureInfooutputFormat.size(); i++)
|
||||||
|
{
|
||||||
|
Element formatElement1 = this.doc.createElementNS(this.support.getURI("wms"), "Format");
|
||||||
|
//formatElement1.setTextContent((String)OWSConstants.featureInfooutputFormat.get(i));
|
||||||
|
getFeatureInfoElement.appendChild(formatElement1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Element dcpTypeElement2 = this.doc.createElementNS(this.support.getURI("wms"), "DCPType");
|
||||||
|
getFeatureInfoElement.appendChild(dcpTypeElement2);
|
||||||
|
|
||||||
|
Element httpElement2 = this.doc.createElementNS(this.support.getURI("wms"), "HTTP");
|
||||||
|
dcpTypeElement2.appendChild(httpElement2);
|
||||||
|
|
||||||
|
Element getElement2 = this.doc.createElementNS(this.support.getURI("wms"), "Get");
|
||||||
|
httpElement2.appendChild(getElement2);
|
||||||
|
|
||||||
|
Element onlineResourceElement5 = this.doc.createElementNS(this.support.getURI("wms"), "OnlineResource");
|
||||||
|
onlineResourceElement5.setAttributeNS(this.support.getURI("xlink"), "xlink:type", "simple");
|
||||||
|
//onlineResourceElement5.setAttributeNS(this.support.getURI("xlink"), "xlink:href", this.requestObj.getBaseURL() + "?");
|
||||||
|
getElement2.appendChild(onlineResourceElement5);
|
||||||
|
|
||||||
|
Element postElement2 = this.doc.createElementNS(this.support.getURI("wms"), "Post");
|
||||||
|
httpElement2.appendChild(postElement2);
|
||||||
|
|
||||||
|
Element onlineResourceElement6 = this.doc.createElementNS(this.support.getURI("wms"), "OnlineResource");
|
||||||
|
onlineResourceElement6.setAttributeNS(this.support.getURI("xlink"), "xlink:type", "simple");
|
||||||
|
// onlineResourceElement6.setAttributeNS(this.support.getURI("xlink"), "xlink:href", this.requestObj.getBaseURL());
|
||||||
|
postElement2.appendChild(onlineResourceElement6);
|
||||||
|
|
||||||
|
Element exceptionElement = this.doc.createElementNS(this.support.getURI("wms"), "Exception");
|
||||||
|
capabilityElement.appendChild(exceptionElement);
|
||||||
|
|
||||||
|
Element formatElement2 = this.doc.createElementNS(this.support.getURI("wms"), "Format");
|
||||||
|
//formatElement2.setTextContent("text/xml");
|
||||||
|
exceptionElement.appendChild(formatElement2);
|
||||||
|
|
||||||
|
if (this.layerList.size() != 0)
|
||||||
|
{
|
||||||
|
java.util.Map totlaLayrInfo = GetTotalLayerInfo();
|
||||||
|
BoundingBox wholeBoundingBox = (BoundingBox)totlaLayrInfo.get("wholeBoundingBox");
|
||||||
|
|
||||||
|
Element layerElement = this.doc.createElementNS(this.support.getURI("wms"), "Layer");
|
||||||
|
capabilityElement.appendChild(layerElement);
|
||||||
|
|
||||||
|
Element titleElement1 = this.doc.createElementNS(this.support.getURI("wms"), "Title");
|
||||||
|
//titleElement1.setTextContent("O2Map Web Map Service");
|
||||||
|
layerElement.appendChild(titleElement1);
|
||||||
|
|
||||||
|
List crsList = (List)totlaLayrInfo.get("crsList");
|
||||||
|
|
||||||
|
if (crsList != null)
|
||||||
|
{
|
||||||
|
Iterator crsListItr = crsList.iterator();
|
||||||
|
while (crsListItr.hasNext())
|
||||||
|
{
|
||||||
|
String crs = (String)crsListItr.next();
|
||||||
|
|
||||||
|
Element crsElement = this.doc.createElementNS(this.support.getURI("wms"), "CRS");
|
||||||
|
//crsElement.setTextContent(crs);
|
||||||
|
layerElement.appendChild(crsElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Element ex_GeographicBoundingBoxElement = this.doc.createElementNS(this.support.getURI("wms"), "EX_GeographicBoundingBox");
|
||||||
|
layerElement.appendChild(ex_GeographicBoundingBoxElement);
|
||||||
|
|
||||||
|
if (wholeBoundingBox != null)
|
||||||
|
{
|
||||||
|
Element westBoundLongitudeElement = this.doc.createElementNS(this.support.getURI("wms"), "westBoundLongitude");
|
||||||
|
//westBoundLongitudeElement.setTextContent(String.valueOf(wholeBoundingBox.getMinX()));
|
||||||
|
ex_GeographicBoundingBoxElement.appendChild(westBoundLongitudeElement);
|
||||||
|
|
||||||
|
Element eastBoundLongitudeElement = this.doc.createElementNS(this.support.getURI("wms"), "eastBoundLongitude");
|
||||||
|
//eastBoundLongitudeElement.setTextContent(String.valueOf(wholeBoundingBox.getMaxX()));
|
||||||
|
ex_GeographicBoundingBoxElement.appendChild(eastBoundLongitudeElement);
|
||||||
|
|
||||||
|
Element southBoundLatitudeElement = this.doc.createElementNS(this.support.getURI("wms"), "southBoundLatitude");
|
||||||
|
//southBoundLatitudeElement.setTextContent(String.valueOf(wholeBoundingBox.getMinY()));
|
||||||
|
ex_GeographicBoundingBoxElement.appendChild(southBoundLatitudeElement);
|
||||||
|
|
||||||
|
Element northBoundLatitudeElement = this.doc.createElementNS(this.support.getURI("wms"), "northBoundLatitude");
|
||||||
|
//northBoundLatitudeElement.setTextContent(String.valueOf(wholeBoundingBox.getMaxY()));
|
||||||
|
ex_GeographicBoundingBoxElement.appendChild(northBoundLatitudeElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
List bboxList = (List)totlaLayrInfo.get("bboxList");
|
||||||
|
|
||||||
|
if (bboxList != null)
|
||||||
|
{
|
||||||
|
Iterator bboxListItr = bboxList.iterator();
|
||||||
|
while (bboxListItr.hasNext())
|
||||||
|
{
|
||||||
|
ReferencedEnvelope bbox = (ReferencedEnvelope)bboxListItr.next();
|
||||||
|
|
||||||
|
Element boundingBoxElement = this.doc.createElementNS(this.support.getURI("wms"), "BoundingBox");
|
||||||
|
try {
|
||||||
|
boundingBoxElement.setAttribute("CRS", CRS.toSRS(bbox.getCoordinateReferenceSystem()));
|
||||||
|
} catch (Exception localException) {
|
||||||
|
}
|
||||||
|
boundingBoxElement.setAttribute("minx", String.valueOf(bbox.getMinX()));
|
||||||
|
boundingBoxElement.setAttribute("miny", String.valueOf(bbox.getMinY()));
|
||||||
|
boundingBoxElement.setAttribute("maxx", String.valueOf(bbox.getMaxX()));
|
||||||
|
boundingBoxElement.setAttribute("maxy", String.valueOf(bbox.getMaxY()));
|
||||||
|
layerElement.appendChild(boundingBoxElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < this.layerList.size(); i++)
|
||||||
|
{
|
||||||
|
Layer layer = (Layer)this.layerList.get(i);
|
||||||
|
if (layer != null)
|
||||||
|
{
|
||||||
|
Element layerElement1 = this.doc.createElementNS(this.support.getURI("wms"), "Layer");
|
||||||
|
layerElement.appendChild(layerElement1);
|
||||||
|
|
||||||
|
Element nameElement1 = this.doc.createElementNS(this.support.getURI("wms"), "Name");
|
||||||
|
//nameElement1.setTextContent(layer.getName());
|
||||||
|
layerElement1.appendChild(nameElement1);
|
||||||
|
|
||||||
|
Element titleElement2 = this.doc.createElementNS(this.support.getURI("wms"), "Title");
|
||||||
|
//titleElement2.setTextContent(layer.getTitle());
|
||||||
|
layerElement1.appendChild(titleElement2);
|
||||||
|
|
||||||
|
Element abstractElement = this.doc.createElementNS(this.support.getURI("wms"), "Abstract");
|
||||||
|
//abstractElement.setTextContent(layer.getAbstract());
|
||||||
|
layerElement1.appendChild(abstractElement);
|
||||||
|
|
||||||
|
Element crsElement1 = this.doc.createElementNS(this.support.getURI("wms"), "CRS");
|
||||||
|
//crsElement1.setTextContent(CRS.toSRS(layer.getCRS()));
|
||||||
|
layerElement1.appendChild(crsElement1);
|
||||||
|
|
||||||
|
ReferencedEnvelope bbox = layer.getBBox();
|
||||||
|
|
||||||
|
BoundingBox newBbox = bbox;
|
||||||
|
|
||||||
|
if (!CRS.equalsIgnoreMetadata(layer.getCRS(), CRSMngr.getCRS("EPSG:4326"))) {
|
||||||
|
newBbox = bbox.toBounds(CRSMngr.getCRS("EPSG:4326"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Element ex_GeographicBoundingBoxElement1 = this.doc.createElementNS(this.support.getURI("wms"), "EX_GeographicBoundingBox");
|
||||||
|
layerElement1.appendChild(ex_GeographicBoundingBoxElement1);
|
||||||
|
|
||||||
|
Element westBoundLongitudeElement1 = this.doc.createElementNS(this.support.getURI("wms"), "westBoundLongitude");
|
||||||
|
//westBoundLongitudeElement1.setTextContent(String.valueOf(newBbox.getMinX()));
|
||||||
|
ex_GeographicBoundingBoxElement1.appendChild(westBoundLongitudeElement1);
|
||||||
|
|
||||||
|
Element eastBoundLongitudeElement1 = this.doc.createElementNS(this.support.getURI("wms"), "eastBoundLongitude");
|
||||||
|
//eastBoundLongitudeElement1.setTextContent(String.valueOf(newBbox.getMaxX()));
|
||||||
|
ex_GeographicBoundingBoxElement1.appendChild(eastBoundLongitudeElement1);
|
||||||
|
|
||||||
|
Element southBoundLatitudeElement1 = this.doc.createElementNS(this.support.getURI("wms"), "southBoundLatitude");
|
||||||
|
//southBoundLatitudeElement1.setTextContent(String.valueOf(newBbox.getMinY()));
|
||||||
|
ex_GeographicBoundingBoxElement1.appendChild(southBoundLatitudeElement1);
|
||||||
|
|
||||||
|
Element northBoundLatitudeElement1 = this.doc.createElementNS(this.support.getURI("wms"), "northBoundLatitude");
|
||||||
|
//northBoundLatitudeElement1.setTextContent(String.valueOf(newBbox.getMaxY()));
|
||||||
|
ex_GeographicBoundingBoxElement1.appendChild(northBoundLatitudeElement1);
|
||||||
|
|
||||||
|
Element boundingBoxElement1 = this.doc.createElementNS(this.support.getURI("wms"), "BoundingBox");
|
||||||
|
boundingBoxElement1.setAttribute("CRS", CRS.toSRS(layer.getCRS()));
|
||||||
|
boundingBoxElement1.setAttribute("minx", String.valueOf(bbox.getMinX()));
|
||||||
|
boundingBoxElement1.setAttribute("miny", String.valueOf(bbox.getMinY()));
|
||||||
|
boundingBoxElement1.setAttribute("maxx", String.valueOf(bbox.getMaxX()));
|
||||||
|
boundingBoxElement1.setAttribute("maxy", String.valueOf(bbox.getMaxY()));
|
||||||
|
layerElement1.appendChild(boundingBoxElement1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private java.util.Map<String, Object> GetTotalLayerInfo()
|
||||||
|
throws TransformException, FactoryException
|
||||||
|
{
|
||||||
|
java.util.Map totalLayerInfo = new HashMap();
|
||||||
|
|
||||||
|
List crsList = new ArrayList();
|
||||||
|
java.util.Map map = new HashMap();
|
||||||
|
|
||||||
|
if (this.layerList.size() != 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < this.layerList.size(); i++)
|
||||||
|
{
|
||||||
|
Layer layer = (Layer)this.layerList.get(i);
|
||||||
|
if (layer != null)
|
||||||
|
{
|
||||||
|
String strCrs = CRS.toSRS(layer.getCRS());
|
||||||
|
|
||||||
|
if (!crsList.contains(strCrs)) {
|
||||||
|
crsList.add(strCrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReferencedEnvelope bbox = new ReferencedEnvelope(layer.getBBox());
|
||||||
|
String bboxCrs = CRS.toSRS(bbox.getCoordinateReferenceSystem());
|
||||||
|
|
||||||
|
if (map.get(bboxCrs) == null)
|
||||||
|
{
|
||||||
|
List list = new ArrayList();
|
||||||
|
list.add(bbox);
|
||||||
|
|
||||||
|
map.put(bboxCrs, list);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List list = (List)map.get(bboxCrs);
|
||||||
|
list.add(bbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Set s = map.keySet();
|
||||||
|
Iterator itr = s.iterator();
|
||||||
|
|
||||||
|
List bboxList = new ArrayList();
|
||||||
|
while (itr.hasNext())
|
||||||
|
{
|
||||||
|
String key = (String)itr.next();
|
||||||
|
|
||||||
|
List list = (List)map.get(key);
|
||||||
|
Iterator itr2 = list.iterator();
|
||||||
|
|
||||||
|
ReferencedEnvelope resultBbox = null;
|
||||||
|
while (itr2.hasNext())
|
||||||
|
{
|
||||||
|
ReferencedEnvelope bbox = (ReferencedEnvelope)itr2.next();
|
||||||
|
resultBbox = GeometryMngr.mergeEnvelope(resultBbox, bbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
bboxList.add(resultBbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator boundaryItr = bboxList.iterator();
|
||||||
|
ReferencedEnvelope resultBbox = null;
|
||||||
|
BoundingBox wholeBoundingBox = null;
|
||||||
|
while (boundaryItr.hasNext())
|
||||||
|
{
|
||||||
|
ReferencedEnvelope bbox = (ReferencedEnvelope)boundaryItr.next();
|
||||||
|
resultBbox = GeometryMngr.mergeEnvelope(resultBbox, bbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CRS.equalsIgnoreMetadata(resultBbox.getCoordinateReferenceSystem(), CRSMngr.getCRS("EPSG:4326")))
|
||||||
|
{
|
||||||
|
wholeBoundingBox = resultBbox.toBounds(CRSMngr.getCRS("EPSG:4326"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wholeBoundingBox = resultBbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalLayerInfo.put("crsList", crsList);
|
||||||
|
totalLayerInfo.put("bboxList", bboxList);
|
||||||
|
totalLayerInfo.put("wholeBoundingBox", wholeBoundingBox);
|
||||||
|
|
||||||
|
return totalLayerInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,249 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Polygon;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Vector;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import org.geotools.GML;
|
||||||
|
import org.geotools.data.Query;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
|
import org.geotools.data.simple.SimpleFeatureIterator;
|
||||||
|
import org.geotools.factory.CommonFactoryFinder;
|
||||||
|
import org.geotools.feature.DefaultFeatureCollection;
|
||||||
|
import org.geotools.geometry.jts.JTS;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.styling.LineSymbolizer;
|
||||||
|
import org.geotools.styling.LineSymbolizerImpl;
|
||||||
|
import org.geotools.styling.PointSymbolizer;
|
||||||
|
import org.geotools.styling.PointSymbolizerImpl;
|
||||||
|
import org.geotools.styling.Rule;
|
||||||
|
import org.geotools.styling.Style;
|
||||||
|
import org.geotools.styling.Symbolizer;
|
||||||
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.filter.And;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.filter.FilterFactory2;
|
||||||
|
import org.opengis.filter.expression.Expression;
|
||||||
|
import org.opengis.filter.spatial.BBOX;
|
||||||
|
import org.opengis.filter.spatial.Intersects;
|
||||||
|
import org.opengis.geometry.BoundingBox;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.xml.sax.helpers.NamespaceSupport;
|
||||||
|
|
||||||
|
public class WMSGetFeatureInfo {
|
||||||
|
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
|
||||||
|
private GetFeatureInfoRequest requestObj = null;
|
||||||
|
private DefaultFeatureCollection collection = new DefaultFeatureCollection();
|
||||||
|
private NamespaceSupport support = new NamespaceSupport();
|
||||||
|
|
||||||
|
public WMSGetFeatureInfo(GetFeatureInfoRequest requestObj) {
|
||||||
|
this.requestObj = requestObj;
|
||||||
|
this.support.declarePrefix("wms", "http://www.opengis.net/wms");
|
||||||
|
this.support.declarePrefix("gml", "http://www.opengis.net/gml");
|
||||||
|
this.support.declarePrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
||||||
|
this.support.declarePrefix("schemaLocation", "sf http://cite.opengeospatial.org/gmlsf");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Document getFeatureInfo(HttpServletResponse resp) {
|
||||||
|
Document doc = null;
|
||||||
|
try {
|
||||||
|
String[] queryLayers = this.requestObj.getQueryLayer();
|
||||||
|
if (queryLayers == null || queryLayers.length == 0) {
|
||||||
|
throw new Exception("QUERY_LAYERS parameter [] is not available.");
|
||||||
|
}
|
||||||
|
Vector<FeatureLayer> mapLayers = new Vector<FeatureLayer>();
|
||||||
|
String[] stringArray = queryLayers;
|
||||||
|
int n = queryLayers.length;
|
||||||
|
int n2 = 0;
|
||||||
|
while (n2 < n) {
|
||||||
|
String layerName = stringArray[n2];
|
||||||
|
try {
|
||||||
|
Layer mapLayer = ServerContext.getMap().getLayer(layerName);
|
||||||
|
if (mapLayer == null) {
|
||||||
|
throw new IllegalArgumentException("QUERY_LAYERS [" + layerName + "] is not exist.");
|
||||||
|
}
|
||||||
|
if (mapLayer instanceof LinkLayer) {
|
||||||
|
throw new IllegalArgumentException("[" + layerName + "] is not support this operation.");
|
||||||
|
}
|
||||||
|
if (mapLayer instanceof GroupLayer) {
|
||||||
|
throw new IllegalArgumentException("[" + layerName + "] is not support this operation.");
|
||||||
|
}
|
||||||
|
mapLayers.add((FeatureLayer)mapLayer);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new IllegalArgumentException("QUERY_LAYERS [" + layerName + "] is not exist.");
|
||||||
|
}
|
||||||
|
++n2;
|
||||||
|
}
|
||||||
|
for (FeatureLayer layer : mapLayers) {
|
||||||
|
Query query = new Query(layer.getName(), this.createFilter((Layer)layer));
|
||||||
|
query.setCoordinateSystemReproject(this.requestObj.getCRS());
|
||||||
|
query.setMaxFeatures(this.requestObj.getFeatureCount());
|
||||||
|
try {
|
||||||
|
O2FeatureCollection c = FeatureMngr.getFeatureCollectionByLayer((Query)query);
|
||||||
|
// 올바르지 않은 c를 리턴한다.
|
||||||
|
String testId = c.getID();
|
||||||
|
int testSize = c.size();
|
||||||
|
SimpleFeatureIterator iter = c.features();
|
||||||
|
try {
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
this.collection.add((SimpleFeature)iter.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
iter.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new Exception(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.createFeatureInfo(resp);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
OWSServiceException ose = new OWSServiceException("WMS GetFeatureInfo Exception : " + e.getMessage());
|
||||||
|
doc = ose.getDocument();
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "WMS GetFeatureInfo Exception : " + e.getMessage());
|
||||||
|
}
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Filter createFilter(Layer layer) throws Exception {
|
||||||
|
int pixelLength;
|
||||||
|
int pixJ;
|
||||||
|
int pixI;
|
||||||
|
int height;
|
||||||
|
int width;
|
||||||
|
double yLength;
|
||||||
|
double xLength;
|
||||||
|
ReferencedEnvelope bbox;
|
||||||
|
block17: {
|
||||||
|
bbox = this.requestObj.getBbox();
|
||||||
|
xLength = bbox.getMaxX() - bbox.getMinX();
|
||||||
|
yLength = bbox.getMaxY() - bbox.getMinY();
|
||||||
|
width = this.requestObj.getWidth();
|
||||||
|
height = this.requestObj.getHeight();
|
||||||
|
pixI = this.requestObj.getI();
|
||||||
|
pixJ = this.requestObj.getJ();
|
||||||
|
pixelLength = 0;
|
||||||
|
int defaultPixelLength = 4;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
if (layer instanceof FeatureLayer) {
|
||||||
|
FeatureLayer featureLayer = (FeatureLayer)layer;
|
||||||
|
Style style = this.requestObj.getStyles() != null && this.requestObj.getStyles()[0] != null ? featureLayer.getRenderStyle(this.requestObj.getStyles()[0]) : featureLayer.getRenderStyle(null);
|
||||||
|
if (style != null && style.getFeatureTypeStyles()[0].getRules() != null) {
|
||||||
|
Rule[] ruleArr = style.getFeatureTypeStyles()[0].getRules();
|
||||||
|
int i = 0;
|
||||||
|
while (i < ruleArr.length) {
|
||||||
|
Symbolizer[] symbolizerArr = ruleArr[i].getSymbolizers();
|
||||||
|
int j = 0;
|
||||||
|
while (j < symbolizerArr.length) {
|
||||||
|
LineSymbolizer lineSymbolizer;
|
||||||
|
Expression exp;
|
||||||
|
Symbolizer symbolizer = symbolizerArr[j];
|
||||||
|
if (symbolizer instanceof PointSymbolizerImpl) {
|
||||||
|
PointSymbolizer pointSymbolizer = (PointSymbolizer)symbolizer;
|
||||||
|
exp = pointSymbolizer.getGraphic().getSize();
|
||||||
|
if (exp != null) {
|
||||||
|
pixelLength = Math.max(pixelLength, Integer.valueOf(exp.toString()));
|
||||||
|
}
|
||||||
|
} else if (symbolizer instanceof LineSymbolizerImpl && (exp = (lineSymbolizer = (LineSymbolizer)symbolizer).getStroke().getWidth()) != null) {
|
||||||
|
pixelLength = Math.max(pixelLength, Integer.valueOf(exp.toString()));
|
||||||
|
}
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pixelLength = defaultPixelLength;
|
||||||
|
LogMngr.getInstance().logDebug("[SERVICE]", "Style is null. set fixel length : default " + defaultPixelLength + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
pixelLength = defaultPixelLength;
|
||||||
|
LogMngr.getInstance().logDebug("[SERVICE]", "Get buffer length from style failed. set fixel length : default " + defaultPixelLength + ". " + e.getMessage());
|
||||||
|
if (pixelLength < defaultPixelLength) {
|
||||||
|
LogMngr.getInstance().logDebug("[SERVICE]", "pixelLength(" + pixelLength + ") is smaller than defaultPixelLength(" + defaultPixelLength + "). " + "set fixel length : default " + defaultPixelLength + ".");
|
||||||
|
pixelLength = defaultPixelLength;
|
||||||
|
}
|
||||||
|
break block17;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable throwable) {
|
||||||
|
if (pixelLength < defaultPixelLength) {
|
||||||
|
LogMngr.getInstance().logDebug("[SERVICE]", "pixelLength(" + pixelLength + ") is smaller than defaultPixelLength(" + defaultPixelLength + "). " + "set fixel length : default " + defaultPixelLength + ".");
|
||||||
|
pixelLength = defaultPixelLength;
|
||||||
|
}
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
if (pixelLength < defaultPixelLength) {
|
||||||
|
LogMngr.getInstance().logDebug("[SERVICE]", "pixelLength(" + pixelLength + ") is smaller than defaultPixelLength(" + defaultPixelLength + "). " + "set fixel length : default " + defaultPixelLength + ".");
|
||||||
|
pixelLength = defaultPixelLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
double coorMinX = bbox.getMinX() + ((double)pixI - (double)pixelLength / 2.0) / (double)width * xLength;
|
||||||
|
double coorMinY = bbox.getMaxY() - ((double)pixJ + (double)pixelLength / 2.0) / (double)height * yLength;
|
||||||
|
double coorMaxX = bbox.getMinX() + ((double)pixI + (double)pixelLength / 2.0) / (double)width * xLength;
|
||||||
|
double coorMaxY = bbox.getMaxY() - ((double)pixJ - (double)pixelLength / 2.0) / (double)height * yLength;
|
||||||
|
ReferencedEnvelope mouseBbox = new ReferencedEnvelope(coorMinX, coorMaxX, coorMinY, coorMaxY, this.requestObj.getCRS());
|
||||||
|
LogMngr.getInstance().logDebug("[SERVICE]", "Mouse click position : " + mouseBbox.toString());
|
||||||
|
ArrayList<Filter> fList = new ArrayList<Filter>();
|
||||||
|
String geometryColumn = GeometryMngr.getGeometryColumnByLayer((Layer)layer);
|
||||||
|
BBOX filter1 = this.ff.bbox((Expression)this.ff.property(geometryColumn), (BoundingBox)bbox);
|
||||||
|
fList.add(filter1);
|
||||||
|
Polygon polygon = JTS.toGeometry((ReferencedEnvelope)mouseBbox);
|
||||||
|
polygon.setUserData((Object)this.requestObj.getCRS());
|
||||||
|
Intersects filter2 = this.ff.intersects((Expression)this.ff.property(geometryColumn), (Expression)this.ff.literal((Object)polygon));
|
||||||
|
fList.add(filter2);
|
||||||
|
And filter = this.ff.and(fList);
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createFeatureInfo(HttpServletResponse resp) throws Exception {
|
||||||
|
if (this.requestObj.getInfoFormat().equalsIgnoreCase("application/json")) {
|
||||||
|
JsonUtil.writeToResponse((HttpServletResponse)resp, (SimpleFeatureCollection)this.collection);
|
||||||
|
} else {
|
||||||
|
O2GML encode = null;
|
||||||
|
encode = this.requestObj.getInfoFormat() != null && this.requestObj.getInfoFormat().equalsIgnoreCase("application/vnd.ogc.gml") ? new O2GML(GML.Version.GML2) : (this.requestObj.getInfoFormat() != null && this.requestObj.getInfoFormat().equalsIgnoreCase("application/vnd.ogc.gml/3.1.1") ? new O2GML(GML.Version.GML3) : new O2GML(GML.Version.GML2));
|
||||||
|
encode.setEncoding(Charset.forName("UTF-8"));
|
||||||
|
encode.setNamespace(ServerContext.getMap().getNameSpace(), ServerContext.getMap().getNameSpaceURI());
|
||||||
|
encode.setUseNSPrefix(ServerContext.isUseNSPrefix());
|
||||||
|
encode.setIndent(ServerContext.getDocIndent().intValue());
|
||||||
|
encode.setDafaultNamespace("wms", "http://www.opengis.net/wms");
|
||||||
|
if (!this.collection.isEmpty()) {
|
||||||
|
encode.encode(resp, (SimpleFeatureCollection)this.collection);
|
||||||
|
} else {
|
||||||
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
docFactory.setNamespaceAware(true);
|
||||||
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||||
|
Document doc = docBuilder.newDocument();
|
||||||
|
Element rootElement = doc.createElementNS(this.support.getURI("wms"), "FeatureCollection");
|
||||||
|
if (ServerContext.isUseNSPrefix()) {
|
||||||
|
rootElement.setPrefix("wms");
|
||||||
|
}
|
||||||
|
rootElement.setAttribute("xmlns:" + ServerContext.getMap().getNameSpace(), ServerContext.getMap().getNameSpaceURI());
|
||||||
|
rootElement.setAttribute("xmlns:wms", this.support.getURI("wms"));
|
||||||
|
rootElement.setAttribute("xmlns:gml", this.support.getURI("gml"));
|
||||||
|
rootElement.setAttribute("xmlns:xsi", this.support.getURI("xsi"));
|
||||||
|
rootElement.setAttribute("xsi:schemaLocation", this.support.getURI("schemaLocation"));
|
||||||
|
doc.appendChild(rootElement);
|
||||||
|
Element boundedByElement = doc.createElementNS(this.support.getURI("gml"), "boundedBy");
|
||||||
|
boundedByElement.setPrefix("gml");
|
||||||
|
rootElement.appendChild(boundedByElement);
|
||||||
|
Element nullElement = doc.createElementNS(this.support.getURI("gml"), "null");
|
||||||
|
nullElement.setPrefix("gml");
|
||||||
|
nullElement.setTextContent("unknown");
|
||||||
|
boundedByElement.appendChild(nullElement);
|
||||||
|
XMLUtil.writeToResponse((HttpServletResponse)resp, (Document)doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.collection.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
|
public class WMSGetLegendGraphic
|
||||||
|
{
|
||||||
|
private GetLegendGraphicRequest requestObj = null;
|
||||||
|
|
||||||
|
public WMSGetLegendGraphic(GetLegendGraphicRequest requestObj) {
|
||||||
|
this.requestObj = requestObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Document getLegendGraphic(HttpServletResponse resp)
|
||||||
|
{
|
||||||
|
AVList params = new AVList();
|
||||||
|
|
||||||
|
params.setValue("legend.graphic.layer", this.requestObj.getLayer());
|
||||||
|
params.setValue("legend.graphic.style", this.requestObj.getStyle());
|
||||||
|
params.setValue("legend.graphic.rule", this.requestObj.getRule());
|
||||||
|
|
||||||
|
params.setValue("legend.graphic.width", this.requestObj.getWidth());
|
||||||
|
params.setValue("legend.graphic.height", this.requestObj.getHeight());
|
||||||
|
params.setValue("legend.graphic.scale", this.requestObj.getScale());
|
||||||
|
params.setValue("legend.graphic.option", this.requestObj.getOption());
|
||||||
|
params.setValue("legend.graphic.format", this.requestObj.getFormat());
|
||||||
|
|
||||||
|
if (this.requestObj.getSld() != null) {
|
||||||
|
params.setValue("legend.graphic.sld", this.requestObj.getSld());
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage image = null;
|
||||||
|
Document doc = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
image = new LegendGraphicBuilder(params).buildLegendGraphic();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
OWSServiceException ose = new OWSServiceException(
|
||||||
|
"WMS GetLegendGraphic Exception : Image process fails : " +
|
||||||
|
e.getMessage());
|
||||||
|
doc = ose.getDocument();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logError(
|
||||||
|
"[SERVICE]",
|
||||||
|
"WMS GetLegendGraphic Exception : Image process fails : " +
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (image != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
writeImage(image, resp);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
OWSServiceException ose = new OWSServiceException(
|
||||||
|
"WMS GetLegendGraphic Exception : Write IMAGE fails : " +
|
||||||
|
e.getMessage());
|
||||||
|
doc = ose.getDocument();
|
||||||
|
|
||||||
|
LogMngr.getInstance().logError(
|
||||||
|
"[SERVICE]",
|
||||||
|
"WMS GetLegendGraphic Exception : Write IMAGE fails : " +
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeImage(BufferedImage image, HttpServletResponse resp)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
OutputStream out = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String format = this.requestObj.getFormat();
|
||||||
|
String[] formatElement = format.split("/");
|
||||||
|
|
||||||
|
resp.setContentType(format);
|
||||||
|
out = resp.getOutputStream();
|
||||||
|
ImageIO.write(image, formatElement[1], out);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (out != null) {
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,97 +1,74 @@
|
||||||
package geoinfo.map.myMap;
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.RenderedImage;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
public class WMSGetMap
|
public class WMSGetMap {
|
||||||
{
|
GetMapRequest requestObj = null;
|
||||||
GetMapRequest requestObj = null;
|
|
||||||
|
|
||||||
public WMSGetMap(GetMapRequest requestObj)
|
public WMSGetMap(GetMapRequest requestObj) {
|
||||||
{
|
this.requestObj = requestObj;
|
||||||
this.requestObj = requestObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Document getMap(HttpServletResponse resp)
|
|
||||||
{
|
|
||||||
AVList params = new AVList();
|
|
||||||
|
|
||||||
params.setValue("request.wms.layers", this.requestObj.getLayers());
|
|
||||||
params.setValue("request.wms.bbox", this.requestObj.getBbox());
|
|
||||||
params.setValue("request.wms.width", Integer.valueOf(this.requestObj.getWidth()));
|
|
||||||
params.setValue("request.wms.height", Integer.valueOf(this.requestObj.getHeight()));
|
|
||||||
params.setValue("request.wms.format", this.requestObj.getFormat());
|
|
||||||
params.setValue("request.wms.transparent", Boolean.valueOf(this.requestObj.isTransparent()));
|
|
||||||
params.setValue("request.wms.bgcolor", this.requestObj.getBgcolor());
|
|
||||||
params.setValue("request.wms.styles", this.requestObj.getStyles());
|
|
||||||
params.setValue("request.wms.filter", this.requestObj.getFilter());
|
|
||||||
|
|
||||||
if (this.requestObj.getSld() != null) {
|
|
||||||
params.setValue("request.wms.sld", this.requestObj.getSld());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedImage image = null;
|
public Document getMap(HttpServletResponse resp) {
|
||||||
Document doc = null;
|
OWSServiceException ose;
|
||||||
try
|
AVList params = new AVList();
|
||||||
{
|
params.setValue("request.wms.layers", (Object)this.requestObj.getLayers());
|
||||||
image = RenderMngr.productMap(params);
|
params.setValue("request.wms.bbox", (Object)this.requestObj.getBbox());
|
||||||
}
|
params.setValue("request.wms.width", (Object)this.requestObj.getWidth());
|
||||||
catch (Exception e)
|
params.setValue("request.wms.height", (Object)this.requestObj.getHeight());
|
||||||
{
|
params.setValue("request.wms.format", (Object)this.requestObj.getFormat());
|
||||||
OWSServiceException ose = new OWSServiceException("WMS GetMap Exception : Image process fails : " + e.getMessage());
|
params.setValue("request.wms.transparent", (Object)this.requestObj.isTransparent());
|
||||||
doc = ose.getDocument();
|
params.setValue("request.wms.bgcolor", (Object)this.requestObj.getBgcolor());
|
||||||
|
params.setValue("request.wms.styles", (Object)this.requestObj.getStyles());
|
||||||
LogMngr.getInstance().logError("[SERVICE]", "WMS GetMap Exception : Image process fails : " + e.getMessage());
|
params.setValue("request.wms.filter", (Object)this.requestObj.getFilter());
|
||||||
|
if (this.requestObj.getSld() != null) {
|
||||||
|
params.setValue("request.wms.sld", (Object)this.requestObj.getSld());
|
||||||
|
}
|
||||||
|
BufferedImage image = null;
|
||||||
|
Document doc = null;
|
||||||
|
try {
|
||||||
|
image = RenderMngr.productMap((AVList)params);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
ose = new OWSServiceException("WMS GetMap Exception : Image process fails : " + e.getMessage());
|
||||||
|
doc = ose.getDocument();
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "WMS GetMap Exception : Image process fails : " + e.getMessage());
|
||||||
|
}
|
||||||
|
if (image != null) {
|
||||||
|
try {
|
||||||
|
this.writeImage(image, resp);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
ose = new OWSServiceException("WMS GetMap Exception : Write IMAGE fails : " + e.getMessage());
|
||||||
|
doc = ose.getDocument();
|
||||||
|
LogMngr.getInstance().logError("[SERVICE]", "WMS GetMap Exception : Write IMAGE fails : " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image != null)
|
private void writeImage(BufferedImage image, HttpServletResponse resp) throws Exception {
|
||||||
{
|
OutputStream out = null;
|
||||||
try
|
try {
|
||||||
{
|
String format = this.requestObj.getFormat();
|
||||||
writeImage(image, resp);
|
String[] formatElement = format.split("/");
|
||||||
}
|
resp.setContentType(format);
|
||||||
catch (Exception e)
|
out = resp.getOutputStream();
|
||||||
{
|
if (format.toUpperCase().contains("PNG")) {
|
||||||
OWSServiceException ose = new OWSServiceException("WMS GetMap Exception : Write IMAGE fails : " + e.getMessage());
|
O2PngWriter.writePNG((BufferedImage)image, (OutputStream)out);
|
||||||
doc = ose.getDocument();
|
} else {
|
||||||
|
ImageIO.write((RenderedImage)image, formatElement[1], out);
|
||||||
LogMngr.getInstance().logError("[SERVICE]", "WMS GetMap Exception : Write IMAGE fails : " + e.getMessage());
|
}
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
if (out != null) {
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeImage(BufferedImage image, HttpServletResponse resp)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
OutputStream out = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String format = this.requestObj.getFormat();
|
|
||||||
String[] formatElement = format.split("/");
|
|
||||||
|
|
||||||
resp.setContentType(format);
|
|
||||||
out = resp.getOutputStream();
|
|
||||||
|
|
||||||
if (format.toUpperCase().contains("PNG"))
|
|
||||||
O2PngWriter.writePNG(image, out);
|
|
||||||
else {
|
|
||||||
ImageIO.write(image, formatElement[1], out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
if (out != null) {
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,912 @@
|
||||||
|
package geoinfo.map.myMap;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerConfigurationException;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.geotools.filter.text.cql2.CQL;
|
||||||
|
import org.geotools.filter.v1_1.OGCConfiguration;
|
||||||
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
|
import org.geotools.styling.StyledLayerDescriptor;
|
||||||
|
import org.geotools.xml.Configuration;
|
||||||
|
import org.geotools.xml.Parser;
|
||||||
|
import org.opengis.filter.And;
|
||||||
|
import org.opengis.filter.Filter;
|
||||||
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.NamedNodeMap;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class WMSParser {
|
||||||
|
Map<String, String> reqMap = new HashMap<String, String>();
|
||||||
|
|
||||||
|
private HttpServletRequest req;
|
||||||
|
|
||||||
|
private String request;
|
||||||
|
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
private String service;
|
||||||
|
|
||||||
|
public WMSParser(HttpServletRequest req) throws OWSServiceException {
|
||||||
|
this.req = req;
|
||||||
|
PluginUtil.refineRequestMap(req, this.reqMap);
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "Refine Request Parameter : " + this.reqMap.toString());
|
||||||
|
this.request = this.reqMap.get("REQUEST");
|
||||||
|
this.version = this.reqMap.get("VERSION");
|
||||||
|
this.service = this.reqMap.get("SERVICE");
|
||||||
|
if (this.service == null)
|
||||||
|
this.service = "WMS";
|
||||||
|
if (this.version == null)
|
||||||
|
this.version = "1.3.0";
|
||||||
|
if (this.reqMap.get("SRS") != null || this.reqMap.get("CRS") != null)
|
||||||
|
if (this.reqMap.get("SRS") == null) {
|
||||||
|
this.reqMap.put("SRS", this.reqMap.get("CRS"));
|
||||||
|
} else if (this.reqMap.get("CRS") == null) {
|
||||||
|
this.reqMap.put("CRS", this.reqMap.get("SRS"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Request parseQuery() throws OWSServiceException, Exception {
|
||||||
|
Request requestObj = null;
|
||||||
|
if (this.reqMap.size() == 0 && this.req.getMethod().equalsIgnoreCase("POST")) {
|
||||||
|
byte[] reqBytes;
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "Method : Post, Input : XML");
|
||||||
|
try {
|
||||||
|
reqBytes = ServerUtil.cloneInputStream((InputStream)this.req.getInputStream());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOException("XML parsing error in POST Method : " + e.getMessage());
|
||||||
|
}
|
||||||
|
Document xmldoc = null;
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder xmlParser = dbf.newDocumentBuilder();
|
||||||
|
xmldoc = xmlParser.parse(new ByteArrayInputStream(reqBytes));
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
throw new ParserConfigurationException("XML parsing error in POST Method : " + e.getMessage());
|
||||||
|
} catch (SAXException e) {
|
||||||
|
throw new SAXException("XML parsing error in POST Method : " + e.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOException("XML parsing error in POST Method : " + e.getMessage());
|
||||||
|
}
|
||||||
|
String requestName = xmldoc.getDocumentElement().getNodeName();
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.wmsRequests, requestName))
|
||||||
|
throw new OWSServiceException("'" + requestName + "' request is not supported.", "OperationNotSupported", "REQUEST");
|
||||||
|
if (requestName.equalsIgnoreCase("GetCapabilities")) {
|
||||||
|
requestObj = postGetCapabilities(xmldoc);
|
||||||
|
} else if (requestName.equalsIgnoreCase("GetMap")) {
|
||||||
|
requestObj = postGetMap(xmldoc);
|
||||||
|
} else if (requestName.equalsIgnoreCase("GetFeatureInfo")) {
|
||||||
|
requestObj = postGetFeatureInfo(xmldoc);
|
||||||
|
} else {
|
||||||
|
throw new OWSServiceException("Required parameter 'REQUEST' is not " + OWSConstants.wmsRequests.toString() + " in WMS POST METHOD.", "OperationNotSupported", "REQUEST");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "Method : Get or Post, Input : KVP");
|
||||||
|
checkPreValidate();
|
||||||
|
if (this.request != null)
|
||||||
|
if (this.request.equalsIgnoreCase("GetCapabilities")) {
|
||||||
|
requestObj = getGetCapabilities();
|
||||||
|
} else if (this.request.equalsIgnoreCase("GetMap")) {
|
||||||
|
requestObj = getGetMap();
|
||||||
|
} else if (this.request.equalsIgnoreCase("GetFeatureInfo")) {
|
||||||
|
requestObj = getGetFeatureInfo();
|
||||||
|
} else if (this.request.equalsIgnoreCase("GetLegendGraphic")) {
|
||||||
|
requestObj = getGetLegendGraphic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (requestObj != null) {
|
||||||
|
requestObj.setRequest(this.request);
|
||||||
|
requestObj.setVersion(this.version);
|
||||||
|
requestObj.setService(this.service);
|
||||||
|
requestObj.setBaseURL(this.req.getRequestURL().toString());
|
||||||
|
}
|
||||||
|
checkValidate(requestObj);
|
||||||
|
return requestObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request getGetCapabilities() {
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.wmsVersions, this.version)) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "ver.'" + this.version + "' is not supported. Set to default value : " + "1.3.0");
|
||||||
|
this.version = "1.3.0";
|
||||||
|
}
|
||||||
|
GetCapabilitiesRequest typeRequest = new GetCapabilitiesRequest();
|
||||||
|
return (Request)typeRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request getGetMap() throws OWSServiceException, UnsupportedEncodingException, MalformedURLException {
|
||||||
|
String layers = this.reqMap.get("LAYERS");
|
||||||
|
checkNull("LAYERS", layers);
|
||||||
|
layers = layers.replaceAll(" ", "");
|
||||||
|
String[] layersArry = layers.split(",");
|
||||||
|
for (int i = 0; i < layersArry.length; i++) {
|
||||||
|
try {
|
||||||
|
Layer layer = ServerContext.getMap().getLayer(layersArry[i]);
|
||||||
|
if (layer == null)
|
||||||
|
throw new OWSServiceException("'" + layersArry[i] + "' layer is not exist.", "LayerNotDefined", "LAYERS");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("'" + layersArry[i] + "' layer is not exist. " + e.getMessage(), "LayerNotDefined", "LAYERS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String styles = this.reqMap.get("STYLES");
|
||||||
|
if (styles == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'STYLES' is missing.", "MissingParameterValue", "STYLES");
|
||||||
|
String[] stylesArry = null;
|
||||||
|
if (!styles.trim().equals("")) {
|
||||||
|
styles = styles.replaceAll(" ", "");
|
||||||
|
stylesArry = styles.split(",");
|
||||||
|
}
|
||||||
|
if (stylesArry != null)
|
||||||
|
if (layersArry.length != stylesArry.length)
|
||||||
|
throw new OWSServiceException("the number of LAYERS and the number of STYLES is not match. check the number of STYLES values. ", "InvalidParameterValue", "STYLES");
|
||||||
|
String sCrs = this.reqMap.get("CRS");
|
||||||
|
checkNull("CRS", sCrs);
|
||||||
|
CoordinateReferenceSystem crs = null;
|
||||||
|
try {
|
||||||
|
crs = CRSMngr.getCRS(sCrs);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sCrs + "' is not appropriate. " + e.getMessage(), "InvalidCRS", "CRS");
|
||||||
|
}
|
||||||
|
String sBBOX = this.reqMap.get("BBOX");
|
||||||
|
ReferencedEnvelope bbox = getBbox(sBBOX, crs);
|
||||||
|
String sWidth = this.reqMap.get("WIDTH");
|
||||||
|
checkNull("WIDTH", sWidth);
|
||||||
|
int width = 0;
|
||||||
|
try {
|
||||||
|
width = Integer.parseInt(sWidth);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sWidth + "' is not appropriate.", "InvalidParameterValue", "WIDTH");
|
||||||
|
}
|
||||||
|
String sHeight = this.reqMap.get("HEIGHT");
|
||||||
|
checkNull("HEIGHT", sHeight);
|
||||||
|
int height = 0;
|
||||||
|
try {
|
||||||
|
height = Integer.parseInt(sHeight);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sHeight + "' is not appropriate.", "InvalidParameterValue", "HEIGHT");
|
||||||
|
}
|
||||||
|
String format = this.reqMap.get("FORMAT");
|
||||||
|
checkNull("FORMAT", format);
|
||||||
|
format = format.toLowerCase();
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.imageOutputFormat, format))
|
||||||
|
throw new OWSServiceException("The value '" + format + "' is not appropriate.", "InvalidFormat", "FORMAT");
|
||||||
|
boolean transparent = false;
|
||||||
|
String sTransparent = this.reqMap.get("TRANSPARENT");
|
||||||
|
if (sTransparent != null)
|
||||||
|
try {
|
||||||
|
transparent = Boolean.parseBoolean(sTransparent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + sTransparent + "' is of not TRANSPARENT appropriate. Set to default value : " + "false" + ". " + e.getMessage());
|
||||||
|
}
|
||||||
|
String sBgcolor = this.reqMap.get("BGCOLOR");
|
||||||
|
Color bgcolor = null;
|
||||||
|
if (sBgcolor != null)
|
||||||
|
try {
|
||||||
|
bgcolor = ServerUtil.getColorFromHex(sBgcolor);
|
||||||
|
if (bgcolor == null) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + sBgcolor + "' of BGCOLOR is not appropriate. Set to default value : " + "0xFFFFFF");
|
||||||
|
bgcolor = ServerUtil.getColorFromHex("0xFFFFFF");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + sBgcolor + "' of BGCOLOR is not appropriate. Set to default value : " + "0xFFFFFF" + "." + e.getMessage());
|
||||||
|
bgcolor = ServerUtil.getColorFromHex("0xFFFFFF");
|
||||||
|
}
|
||||||
|
String sSld = this.reqMap.get("SLD");
|
||||||
|
StyledLayerDescriptor sld = null;
|
||||||
|
if (sSld != null) {
|
||||||
|
URL sldUrl = null;
|
||||||
|
try {
|
||||||
|
sldUrl = new URL(sSld);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + sSld + "' is of not SLD appropriate. Set to default style" + e.getMessage());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sld = StyleMngr.parseSLD(sldUrl.openStream());
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + sSld + "' is of not SLD appropriate. Set to default style. " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String sldBody = this.reqMap.get("SLD_BODY");
|
||||||
|
if (sld != null && sldBody != null)
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "SLD and SLD_BODY can not be used at the same tile.");
|
||||||
|
if (sldBody != null)
|
||||||
|
try {
|
||||||
|
sld = StyleMngr.parseSLD(IOUtils.toInputStream(sldBody, "UTF-8"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + sSld + "' of SLD_BODY is not appropriate. " + e.getMessage());
|
||||||
|
}
|
||||||
|
Filter filter = null;
|
||||||
|
try {
|
||||||
|
Filter fFilter = null;
|
||||||
|
String strFilter = this.reqMap.get("FILTER");
|
||||||
|
if (!ServerUtil.isNullString(strFilter)) {
|
||||||
|
strFilter = strFilter.trim().replace(" ", "");
|
||||||
|
if (strFilter.startsWith("("))
|
||||||
|
strFilter = strFilter.substring(1);
|
||||||
|
if (strFilter.endsWith(")"))
|
||||||
|
strFilter = strFilter.substring(0, strFilter.length() - 1);
|
||||||
|
fFilter = getFilter(strFilter);
|
||||||
|
}
|
||||||
|
Filter cFilter = null;
|
||||||
|
String strCql = this.reqMap.get("CQL");
|
||||||
|
if (!ServerUtil.isNullString(strCql))
|
||||||
|
cFilter = CQL.toFilter(strCql);
|
||||||
|
if (fFilter != null) {
|
||||||
|
if (cFilter != null) {
|
||||||
|
And and = QueryMngr.filterFactory.and(fFilter, cFilter);
|
||||||
|
} else {
|
||||||
|
filter = fFilter;
|
||||||
|
}
|
||||||
|
} else if (cFilter != null) {
|
||||||
|
filter = cFilter;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value of FILTER or CQL is not appropriate. " + e, "InvalidParameterValue", "FILTER");
|
||||||
|
}
|
||||||
|
GetMapRequest typeRequest = new GetMapRequest();
|
||||||
|
typeRequest.setBbox(bbox);
|
||||||
|
typeRequest.setBgcolor(bgcolor);
|
||||||
|
typeRequest.setLayers(layersArry);
|
||||||
|
typeRequest.setFormat(format);
|
||||||
|
typeRequest.setWidth(width);
|
||||||
|
typeRequest.setHeight(height);
|
||||||
|
typeRequest.setStyles(stylesArry);
|
||||||
|
typeRequest.setTransparent(transparent);
|
||||||
|
typeRequest.setSld(sld);
|
||||||
|
typeRequest.setFilter(filter);
|
||||||
|
return (Request)typeRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request getGetFeatureInfo() throws OWSServiceException, UnsupportedEncodingException {
|
||||||
|
String layers = this.reqMap.get("LAYERS");
|
||||||
|
checkNull("LAYERS", layers);
|
||||||
|
layers = layers.replaceAll(" ", "");
|
||||||
|
String[] layersArry = layers.split(",");
|
||||||
|
for (int i = 0; i < layersArry.length; i++) {
|
||||||
|
try {
|
||||||
|
Layer layer = ServerContext.getMap().getLayer(layersArry[i]);
|
||||||
|
if (layer == null)
|
||||||
|
throw new OWSServiceException("'" + layersArry[i] + "' layer is not exist.", "LayerNotDefined", "LAYERS");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("'" + layersArry[i] + "' layer is not exist. " + e.getMessage(), "LayerNotDefined", "LAYERS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String styles = this.reqMap.get("STYLES");
|
||||||
|
if (styles == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'STYLES' is missing.", "MissingParameterValue", "STYLES");
|
||||||
|
String[] stylesArry = null;
|
||||||
|
if (!styles.trim().equals("")) {
|
||||||
|
styles = styles.replaceAll(" ", "");
|
||||||
|
stylesArry = styles.split(",");
|
||||||
|
}
|
||||||
|
if (stylesArry != null &&
|
||||||
|
layersArry.length != stylesArry.length)
|
||||||
|
throw new OWSServiceException("the number of LAYERS and the number of STYLES is not match. check the number of STYLES values. ", "InvalidParameterValue", "STYLES");
|
||||||
|
String sCrs = this.reqMap.get("CRS");
|
||||||
|
checkNull("CRS", sCrs);
|
||||||
|
CoordinateReferenceSystem crs = null;
|
||||||
|
try {
|
||||||
|
crs = CRSMngr.getCRS(sCrs);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sCrs + "' is not appropriate. " + e.getMessage(), "InvalidCRS", "CRS");
|
||||||
|
}
|
||||||
|
String sBBOX = this.reqMap.get("BBOX");
|
||||||
|
ReferencedEnvelope bbox = getBbox(sBBOX, crs);
|
||||||
|
String sWidth = this.reqMap.get("WIDTH");
|
||||||
|
checkNull("WIDTH", sWidth);
|
||||||
|
int width = 0;
|
||||||
|
try {
|
||||||
|
width = Integer.parseInt(sWidth);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sWidth + "' is not appropriate.", "InvalidParameterValue", "WIDTH");
|
||||||
|
}
|
||||||
|
String sHeight = this.reqMap.get("HEIGHT");
|
||||||
|
checkNull("HEIGHT", sHeight);
|
||||||
|
int height = 0;
|
||||||
|
try {
|
||||||
|
height = Integer.parseInt(sHeight);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sHeight + "' is not appropriate.", "InvalidParameterValue", "HEIGHT");
|
||||||
|
}
|
||||||
|
String queryLayers = this.reqMap.get("QUERY_LAYERS");
|
||||||
|
checkNull("QUERY_LAYERS", queryLayers);
|
||||||
|
if (queryLayers.trim().equals(""))
|
||||||
|
throw new OWSServiceException("The value '" + queryLayers + "' is not appropriate.", "InvalidParameterValue", "QUERY_LAYERS");
|
||||||
|
queryLayers = queryLayers.replaceAll(" ", "");
|
||||||
|
String[] queryLayersArry = queryLayers.split(",");
|
||||||
|
for (int j = 0; j < queryLayersArry.length; j++) {
|
||||||
|
if (!Arrays.<String>asList(layersArry).contains(queryLayersArry[j]))
|
||||||
|
throw new OWSServiceException("LAYERS is not contain '" + queryLayersArry[j] + "' of QUERY_LAYERS.", "LayerNotDefined", "QUERYLAYER");
|
||||||
|
try {
|
||||||
|
Layer layer = ServerContext.getMap().getLayer(queryLayersArry[j]);
|
||||||
|
if (layer == null)
|
||||||
|
throw new OWSServiceException("'" + queryLayersArry[j] + "' querylayer is not exist.", "LayerNotDefined", "QUERY_LAYERS");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("'" + queryLayersArry[j] + "' querylayer is not exist. " + e.getMessage(), "LayerNotDefined", "QUERY_LAYERS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String infoFormat = this.reqMap.get("INFO_FORMAT");
|
||||||
|
checkNull("INFO_FORMAT", infoFormat);
|
||||||
|
infoFormat = infoFormat.toLowerCase();
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.featureInfooutputFormat, infoFormat))
|
||||||
|
throw new OWSServiceException("The value '" + infoFormat + "' is not appropriate.", "InvalidFormat", "INFO_FORMAT");
|
||||||
|
String stringI = this.reqMap.get("I");
|
||||||
|
checkNull("I", stringI);
|
||||||
|
int intI = 0;
|
||||||
|
try {
|
||||||
|
intI = Integer.parseInt(stringI);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + stringI + "' is not appropriate.", "InvalidPoint", "I");
|
||||||
|
}
|
||||||
|
String stringJ = this.reqMap.get("J");
|
||||||
|
checkNull("J", stringJ);
|
||||||
|
int intJ = 0;
|
||||||
|
try {
|
||||||
|
intJ = Integer.parseInt(stringJ);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + stringJ + "' is not appropriate.", "InvalidPoint", "J");
|
||||||
|
}
|
||||||
|
String strFeatureCount = this.reqMap.get("FEATURE_COUNT");
|
||||||
|
int featureCount = 1;
|
||||||
|
if (strFeatureCount == null || strFeatureCount.trim().equalsIgnoreCase("")) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "FEATURE_COUNT is null. Set default 1");
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
featureCount = Integer.parseInt(strFeatureCount);
|
||||||
|
if (featureCount < 1) {
|
||||||
|
featureCount = 1;
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "FEATURE_COUNT is not positive integer. Set default 1");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + strFeatureCount + "' is not appropriate.", "InvalidParameterValue", "FEATURE_COUNT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GetFeatureInfoRequest typeRequest = new GetFeatureInfoRequest();
|
||||||
|
typeRequest.setLayers(layersArry);
|
||||||
|
typeRequest.setStyles(stylesArry);
|
||||||
|
typeRequest.setCRS(crs);
|
||||||
|
typeRequest.setBbox(bbox);
|
||||||
|
typeRequest.setWidth(width);
|
||||||
|
typeRequest.setHeight(height);
|
||||||
|
typeRequest.setQueryLayer(queryLayersArry);
|
||||||
|
typeRequest.setInfoFormat(infoFormat);
|
||||||
|
typeRequest.setI(intI);
|
||||||
|
typeRequest.setJ(intJ);
|
||||||
|
typeRequest.setFeatureCount(featureCount);
|
||||||
|
return (Request)typeRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request getGetLegendGraphic() throws OWSServiceException {
|
||||||
|
if (this.reqMap.get("VERSION") == null)
|
||||||
|
this.version = "1.3.0";
|
||||||
|
this.request = "GetLegendGraphic";
|
||||||
|
String layer = this.reqMap.get("LAYER");
|
||||||
|
checkNull("layer", layer);
|
||||||
|
String style = this.reqMap.get("STYLE");
|
||||||
|
String rule = this.reqMap.get("RULE");
|
||||||
|
String sSld = this.reqMap.get("SLD");
|
||||||
|
StyledLayerDescriptor sld = null;
|
||||||
|
if (sSld != null) {
|
||||||
|
URL sldUrl = null;
|
||||||
|
try {
|
||||||
|
sldUrl = new URL(sSld);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "SLD parsing failed. Set to default value : " + e.getMessage());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sld = StyleMngr.parseSLD(sldUrl.openStream());
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "SLD parsing failed. Set to default value : " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String sldBody = this.reqMap.get("SLD_BODY");
|
||||||
|
if (sld != null && sldBody != null)
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "SLD and SLD_BODY can not be used at the time. Set to default value");
|
||||||
|
if (sldBody != null)
|
||||||
|
try {
|
||||||
|
sld = StyleMngr.parseSLD(IOUtils.toInputStream(sldBody));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "SLD_BODY parsing failed. Set to default value : " + e.getMessage());
|
||||||
|
}
|
||||||
|
String width = this.reqMap.get("WIDTH");
|
||||||
|
if (width == null) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + width + "' is of not WIDTH appropriate. Set to default value : " + "20");
|
||||||
|
width = "20";
|
||||||
|
}
|
||||||
|
String height = this.reqMap.get("HEIGHT");
|
||||||
|
if (height == null) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + height + "' is of not HEIGHT appropriate. Set to default value : " + "20");
|
||||||
|
height = "20";
|
||||||
|
}
|
||||||
|
String scale = this.reqMap.get("SCALE");
|
||||||
|
String option = this.reqMap.get("OPTION");
|
||||||
|
String format = this.reqMap.get("FORMAT");
|
||||||
|
checkNull("format", format);
|
||||||
|
format = format.toLowerCase();
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.imageOutputFormat, format))
|
||||||
|
throw new OWSServiceException("The value '" + format + "' is not appropriate.", "InvalidFormat", "FORMAT");
|
||||||
|
GetLegendGraphicRequest typeRequest = new GetLegendGraphicRequest();
|
||||||
|
typeRequest.setLayer(layer);
|
||||||
|
typeRequest.setStyle(style);
|
||||||
|
typeRequest.setRule(rule);
|
||||||
|
typeRequest.setSld(sld);
|
||||||
|
typeRequest.setWidth(width);
|
||||||
|
typeRequest.setHeight(height);
|
||||||
|
typeRequest.setScale(scale);
|
||||||
|
typeRequest.setOption(option);
|
||||||
|
typeRequest.setFormat(format);
|
||||||
|
return (Request)typeRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request postGetCapabilities(Document xmldoc) {
|
||||||
|
Element root = xmldoc.getDocumentElement();
|
||||||
|
this.request = "GetCapabilities";
|
||||||
|
NamedNodeMap arributeMap = root.getAttributes();
|
||||||
|
if (arributeMap.getNamedItem("service") != null)
|
||||||
|
this.service = arributeMap.getNamedItem("service").getNodeValue();
|
||||||
|
if (arributeMap.getNamedItem("version") != null)
|
||||||
|
this.version = arributeMap.getNamedItem("version").getNodeValue();
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.wmsVersions, this.version)) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "ver.'" + this.version + "' is not supported. Set to default value : " + "1.3.0");
|
||||||
|
this.version = "1.3.0";
|
||||||
|
}
|
||||||
|
GetCapabilitiesRequest typeRequest = new GetCapabilitiesRequest();
|
||||||
|
return (Request)typeRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request postGetMap(Document xmldoc) throws OWSServiceException, TransformerConfigurationException, TransformerException, Exception {
|
||||||
|
Element root = xmldoc.getDocumentElement();
|
||||||
|
this.request = "GetMap";
|
||||||
|
this.service = root.getAttribute("service");
|
||||||
|
this.version = root.getAttribute("version");
|
||||||
|
Node crsNode = xmldoc.getElementsByTagName("CRS").item(0);
|
||||||
|
if (crsNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'CRS' is missing.", "MissingParameterValue", "CRS");
|
||||||
|
String sCrs = crsNode.getTextContent();
|
||||||
|
checkNull("CRS", sCrs);
|
||||||
|
CoordinateReferenceSystem crs = null;
|
||||||
|
try {
|
||||||
|
crs = CRSMngr.getCRS(sCrs);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sCrs + "' is not appropriate. " + e.getMessage(), "InvalidCRS", "CRS");
|
||||||
|
}
|
||||||
|
Node bboxNode = xmldoc.getElementsByTagName("BoundingBox").item(0);
|
||||||
|
if (bboxNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'BBOX' is missing.", "MissingParameterValue", "BBOX");
|
||||||
|
String lowerCorner = null;
|
||||||
|
String upperCorner = null;
|
||||||
|
int k = 0;
|
||||||
|
for (int i = 0; i < bboxNode.getChildNodes().getLength(); i++) {
|
||||||
|
Node node = bboxNode.getChildNodes().item(i);
|
||||||
|
String nodeName = node.getNodeName().toUpperCase();
|
||||||
|
if (nodeName.contains("LOWERCORNER")) {
|
||||||
|
lowerCorner = node.getTextContent();
|
||||||
|
} else if (nodeName.contains("UPPERCORNER")) {
|
||||||
|
upperCorner = node.getTextContent();
|
||||||
|
}
|
||||||
|
if (nodeName.contains("COORD")) {
|
||||||
|
NodeList nodeList = node.getChildNodes();
|
||||||
|
for (int n = 0; n < nodeList.getLength(); n++) {
|
||||||
|
Node coordNode = nodeList.item(n);
|
||||||
|
String coordNodeName = coordNode.getNodeName().toUpperCase();
|
||||||
|
if (!coordNodeName.equals("#TEXT")) {
|
||||||
|
if (coordNodeName.contains("GML:X"))
|
||||||
|
if (k == 0) {
|
||||||
|
lowerCorner = coordNode.getTextContent();
|
||||||
|
} else {
|
||||||
|
upperCorner = coordNode.getTextContent();
|
||||||
|
}
|
||||||
|
if (coordNodeName.contains("GML:Y"))
|
||||||
|
if (k == 0) {
|
||||||
|
lowerCorner = String.valueOf(lowerCorner) + " " + coordNode.getTextContent();
|
||||||
|
} else {
|
||||||
|
upperCorner = String.valueOf(upperCorner) + " " + coordNode.getTextContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String sBBOX = String.valueOf(lowerCorner) + " " + upperCorner;
|
||||||
|
checkNull("BoundingBox", sBBOX);
|
||||||
|
sBBOX = sBBOX.replace(" ", ",");
|
||||||
|
ReferencedEnvelope bbox = getBbox(sBBOX, crs);
|
||||||
|
String sWidth = null;
|
||||||
|
String sHeight = null;
|
||||||
|
Node sizeNode = xmldoc.getElementsByTagName("Size").item(0);
|
||||||
|
if (sizeNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'Size' tag is missing.", "MissingParameterValue");
|
||||||
|
for (int j = 0; j < sizeNode.getChildNodes().getLength(); j++) {
|
||||||
|
Node node = sizeNode.getChildNodes().item(j);
|
||||||
|
String nodeName = node.getNodeName().toUpperCase();
|
||||||
|
if (nodeName.contains("WIDTH")) {
|
||||||
|
sWidth = node.getTextContent();
|
||||||
|
} else if (nodeName.contains("HEIGHT")) {
|
||||||
|
sHeight = node.getTextContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkNull("WIDTH", sWidth);
|
||||||
|
int width = 0;
|
||||||
|
try {
|
||||||
|
width = Integer.parseInt(sWidth);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sWidth + "' is not appropriate.", "InvalidParameterValue", "WIDTH");
|
||||||
|
}
|
||||||
|
checkNull("HEIGHT", sHeight);
|
||||||
|
int height = 0;
|
||||||
|
try {
|
||||||
|
height = Integer.parseInt(sHeight);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sHeight + "' is not appropriate.", "InvalidParameterValue", "HEIGHT");
|
||||||
|
}
|
||||||
|
Node formatNode = xmldoc.getElementsByTagName("Format").item(0);
|
||||||
|
if (formatNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'Format' is missing.", "MissingParameterValue", "FORMAT");
|
||||||
|
String format = formatNode.getTextContent();
|
||||||
|
checkNull("FORMAT", format);
|
||||||
|
format = format.toLowerCase();
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.imageOutputFormat, format))
|
||||||
|
throw new OWSServiceException("The value '" + format + "' is not appropriate.", "InvalidFormat", "FORMAT");
|
||||||
|
boolean transparent = false;
|
||||||
|
Node transparentNode = xmldoc.getElementsByTagName("Transparent").item(0);
|
||||||
|
if (transparentNode != null) {
|
||||||
|
String sTransparent = transparentNode.getTextContent();
|
||||||
|
if (sTransparent != null)
|
||||||
|
try {
|
||||||
|
transparent = Boolean.parseBoolean(sTransparent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + sTransparent + "' of TRANSPARENT is not appropriate. Set to default value : " + "false" + ". " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Color bgcolor = null;
|
||||||
|
Node bgcolorNode = xmldoc.getElementsByTagName("BGcolor").item(0);
|
||||||
|
if (bgcolorNode != null) {
|
||||||
|
String sBgcolor = bgcolorNode.getTextContent();
|
||||||
|
if (sBgcolor != null)
|
||||||
|
try {
|
||||||
|
bgcolor = ServerUtil.getColorFromHex(sBgcolor);
|
||||||
|
if (bgcolor == null) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + sBgcolor + "' of BGCOLOR is not appropriate. Set to default value : " + "0xFFFFFF");
|
||||||
|
bgcolor = ServerUtil.getColorFromHex("0xFFFFFF");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "The value '" + sBgcolor + "' is of BGCOLOR not appropriate. Set to default value : " + "0xFFFFFF" + ". " + e.getMessage());
|
||||||
|
bgcolor = ServerUtil.getColorFromHex("0xFFFFFF");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NamedNodeMap arributeMap = root.getAttributes();
|
||||||
|
arributeMap.removeNamedItem("version");
|
||||||
|
Node sldPart = xmldoc.getElementsByTagName("StyledLayerDescriptor").item(0);
|
||||||
|
if (sldPart == null)
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "'StyledLayerDescriptor' tag is missing.");
|
||||||
|
Element sldEle = (Element)sldPart;
|
||||||
|
for (int m = 0; m < arributeMap.getLength(); m++)
|
||||||
|
sldEle.setAttribute(arributeMap.item(m).getNodeName(), arributeMap.item(m).getNodeValue());
|
||||||
|
xmldoc.replaceChild(sldEle, root);
|
||||||
|
TransformerFactory tf = TransformerFactory.newInstance();
|
||||||
|
OutputStream out = null;
|
||||||
|
try {
|
||||||
|
Transformer transformer = tf.newTransformer();
|
||||||
|
transformer.setOutputProperty("encoding", "UTF-8");
|
||||||
|
transformer.setOutputProperty("indent", "yes");
|
||||||
|
DOMSource source = new DOMSource(xmldoc);
|
||||||
|
out = new ByteArrayOutputStream();
|
||||||
|
transformer.transform(source, new StreamResult(out));
|
||||||
|
} catch (TransformerConfigurationException e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "SLD parsing failed. " + e.getMessage());
|
||||||
|
} catch (TransformerException e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "SLD parsing failed. " + e.getMessage());
|
||||||
|
}
|
||||||
|
byte[] byteArray = ((ByteArrayOutputStream)out).toByteArray();
|
||||||
|
InputStream in = new ByteArrayInputStream(byteArray);
|
||||||
|
StyledLayerDescriptor sld = null;
|
||||||
|
try {
|
||||||
|
sld = StyleMngr.parseSLD(in);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "SLD parsing failed. " + e.getMessage());
|
||||||
|
}
|
||||||
|
GetMapRequest typeRequest = new GetMapRequest();
|
||||||
|
typeRequest.setBbox(bbox);
|
||||||
|
typeRequest.setBgcolor(bgcolor);
|
||||||
|
typeRequest.setFormat(format);
|
||||||
|
typeRequest.setWidth(width);
|
||||||
|
typeRequest.setHeight(height);
|
||||||
|
typeRequest.setTransparent(transparent);
|
||||||
|
typeRequest.setSld(sld);
|
||||||
|
return (Request)typeRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request postGetFeatureInfo(Document xmldoc) throws OWSServiceException {
|
||||||
|
Element root = xmldoc.getDocumentElement();
|
||||||
|
this.request = "GetFeatureInfo";
|
||||||
|
this.service = root.getAttribute("service");
|
||||||
|
this.version = root.getAttribute("version");
|
||||||
|
String[] layersArry = null;
|
||||||
|
NodeList namedLyaerNodeList = null;
|
||||||
|
namedLyaerNodeList = xmldoc.getElementsByTagName("NamedLayer");
|
||||||
|
if (namedLyaerNodeList.getLength() == 0)
|
||||||
|
throw new OWSServiceException("'NamedLayer' tag is missing.", "MissingParameterValue", "LAYERS");
|
||||||
|
layersArry = new String[namedLyaerNodeList.getLength()];
|
||||||
|
for (int i = 0; i < namedLyaerNodeList.getLength(); i++) {
|
||||||
|
Node namedLyaerNode = namedLyaerNodeList.item(i);
|
||||||
|
if (namedLyaerNode.getNodeType() == 1) {
|
||||||
|
Element namedLyaerElement = (Element)namedLyaerNode;
|
||||||
|
NodeList nameNodeList = namedLyaerElement.getElementsByTagName("Name");
|
||||||
|
layersArry[i] = nameNodeList.item(0).getTextContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (layersArry.length == 0)
|
||||||
|
throw new OWSServiceException("Required parameter 'LAYERS' is missing.", "MissingParameterValue", "LAYERS");
|
||||||
|
Node crsNode = xmldoc.getElementsByTagName("CRS").item(0);
|
||||||
|
if (crsNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'CRS' is missing.", "MissingParameterValue", "CRS");
|
||||||
|
String sCrs = crsNode.getTextContent();
|
||||||
|
checkNull("CRS", sCrs);
|
||||||
|
CoordinateReferenceSystem crs = CRSMngr.getCRS(sCrs);
|
||||||
|
if (crs == null)
|
||||||
|
throw new OWSServiceException("The value '" + sCrs + "' is not appropriate.", "InvalidCRS", "CRS");
|
||||||
|
Node bboxNode = xmldoc.getElementsByTagName("BoundingBox").item(0);
|
||||||
|
if (bboxNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'BoundingBox' is missing.", "MissingParameterValue", "BBOX");
|
||||||
|
String lowerCorner = null;
|
||||||
|
String upperCorner = null;
|
||||||
|
int k = 0;
|
||||||
|
for (int j = 0; j < bboxNode.getChildNodes().getLength(); j++) {
|
||||||
|
Node node = bboxNode.getChildNodes().item(j);
|
||||||
|
String nodeName = node.getNodeName().toUpperCase();
|
||||||
|
if (nodeName.contains("LOWERCORNER")) {
|
||||||
|
lowerCorner = node.getTextContent();
|
||||||
|
} else if (nodeName.contains("UPPERCORNER")) {
|
||||||
|
upperCorner = node.getTextContent();
|
||||||
|
}
|
||||||
|
if (nodeName.contains("COORD")) {
|
||||||
|
NodeList nodeList = node.getChildNodes();
|
||||||
|
for (int i1 = 0; i1 < nodeList.getLength(); i1++) {
|
||||||
|
Node coordNode = nodeList.item(i1);
|
||||||
|
String coordNodeName = coordNode.getNodeName().toUpperCase();
|
||||||
|
if (!coordNodeName.equals("#TEXT")) {
|
||||||
|
if (coordNodeName.contains("GML:X"))
|
||||||
|
if (k == 0) {
|
||||||
|
lowerCorner = coordNode.getTextContent();
|
||||||
|
} else {
|
||||||
|
upperCorner = coordNode.getTextContent();
|
||||||
|
}
|
||||||
|
if (coordNodeName.contains("GML:Y"))
|
||||||
|
if (k == 0) {
|
||||||
|
lowerCorner = String.valueOf(lowerCorner) + " " + coordNode.getTextContent();
|
||||||
|
} else {
|
||||||
|
upperCorner = String.valueOf(upperCorner) + " " + coordNode.getTextContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String sBBOX = String.valueOf(lowerCorner) + " " + upperCorner;
|
||||||
|
checkNull("BoundingBox", sBBOX);
|
||||||
|
sBBOX = sBBOX.replace(" ", ",");
|
||||||
|
ReferencedEnvelope bbox = getBbox(sBBOX, crs);
|
||||||
|
String sWidth = null;
|
||||||
|
String sHeight = null;
|
||||||
|
Node sizeNode = xmldoc.getElementsByTagName("Size").item(0);
|
||||||
|
if (sizeNode == null)
|
||||||
|
throw new OWSServiceException("'Size' tag is missing.", "MissingParameterValue");
|
||||||
|
for (int m = 0; m < sizeNode.getChildNodes().getLength(); m++) {
|
||||||
|
Node node = sizeNode.getChildNodes().item(m);
|
||||||
|
String nodeName = node.getNodeName().toUpperCase();
|
||||||
|
if (nodeName.contains("WIDTH")) {
|
||||||
|
sWidth = node.getTextContent();
|
||||||
|
} else if (nodeName.contains("HEIGHT")) {
|
||||||
|
sHeight = node.getTextContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkNull("WIDTH", sWidth);
|
||||||
|
int width = 0;
|
||||||
|
try {
|
||||||
|
width = Integer.parseInt(sWidth);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sWidth + "' is not appropriate.", "InvalidParameterValue", "WIDTH");
|
||||||
|
}
|
||||||
|
checkNull("HEIGHT", sHeight);
|
||||||
|
int height = 0;
|
||||||
|
try {
|
||||||
|
height = Integer.parseInt(sHeight);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sHeight + "' is not appropriate.", "InvalidParameterValue", "HEIGHT");
|
||||||
|
}
|
||||||
|
Node formatNode = xmldoc.getElementsByTagName("Format").item(0);
|
||||||
|
if (formatNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'FORAMT' is missing", "MissingParameterValue", "FORMAT");
|
||||||
|
String format = formatNode.getTextContent();
|
||||||
|
checkNull("FORMAT", format);
|
||||||
|
format = format.toLowerCase();
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.imageOutputFormat, format))
|
||||||
|
throw new OWSServiceException("The value '" + format + "' is not appropriate.", "InvalidFormat", "FORMAT");
|
||||||
|
Node queryLyaerNode = xmldoc.getElementsByTagName("Query_Layers").item(0);
|
||||||
|
if (queryLyaerNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'QUERYLAYER' is missing.", "MissingParameterValue", "QUERYLAYER");
|
||||||
|
String queryLayers = queryLyaerNode.getTextContent();
|
||||||
|
checkNull("QUERY_LAYERS", queryLayers);
|
||||||
|
String[] queryLayersArry = queryLayers.trim().split(",");
|
||||||
|
for (int n = 0; n < queryLayersArry.length; n++) {
|
||||||
|
if (!Arrays.<String>asList(layersArry).contains(queryLayersArry[n]))
|
||||||
|
throw new OWSServiceException("LAYERS is not contain '" + queryLayersArry[n] + "' of QUERY_LAYERS.", "LayerNotDefined", "QUERYLAYER");
|
||||||
|
}
|
||||||
|
Node infoFormatNode = xmldoc.getElementsByTagName("Info_Format").item(0);
|
||||||
|
if (infoFormatNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'INFOFORMAT' is missing.", "MissingParameterValue", "INFOFORMAT");
|
||||||
|
String infoFormat = infoFormatNode.getTextContent();
|
||||||
|
checkNull("INFOFORMAT", infoFormat);
|
||||||
|
infoFormat = infoFormat.toLowerCase();
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.featureInfooutputFormat, infoFormat) || infoFormat.trim().equals(""))
|
||||||
|
throw new OWSServiceException("The value '" + infoFormat + "' is not appropriate.", "InvalidFormat", "INFO_FORMAT");
|
||||||
|
Node iNode = xmldoc.getElementsByTagName("I").item(0);
|
||||||
|
if (iNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'I' is missing.", "MissingParameterValue", "I");
|
||||||
|
String stringI = iNode.getTextContent();
|
||||||
|
checkNull("I", stringI);
|
||||||
|
int intI = 0;
|
||||||
|
try {
|
||||||
|
intI = Integer.parseInt(stringI);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + stringI + "' is not appropriate.", "InvalidPoint", "I");
|
||||||
|
}
|
||||||
|
Node jNode = xmldoc.getElementsByTagName("J").item(0);
|
||||||
|
if (jNode == null)
|
||||||
|
throw new OWSServiceException("Required parameter 'J' is missing.", "MissingParameterValue", "J");
|
||||||
|
String stringJ = jNode.getTextContent();
|
||||||
|
checkNull("J", stringJ);
|
||||||
|
int intJ = 0;
|
||||||
|
try {
|
||||||
|
intJ = Integer.parseInt(stringJ);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + stringJ + "' is not appropriate.", "InvalidPoint", "J");
|
||||||
|
}
|
||||||
|
Node featureCountNode = xmldoc.getElementsByTagName("Feature_Count").item(0);
|
||||||
|
int featureCount = 1;
|
||||||
|
if (featureCountNode == null) {
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "FEATURE_COUNT is null. Set default 1");
|
||||||
|
} else {
|
||||||
|
String strFeatureCount = featureCountNode.getTextContent();
|
||||||
|
try {
|
||||||
|
featureCount = Integer.parseInt(strFeatureCount);
|
||||||
|
if (featureCount < 1) {
|
||||||
|
featureCount = 1;
|
||||||
|
LogMngr.getInstance().reqInfo("[SERVICE]", "FEATURE_COUNT is not positive integer. Set default 1");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + strFeatureCount + "' is not appropriate.", "InvalidParameterValue", "FEATURE_COUNT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GetFeatureInfoRequest typeRequest = new GetFeatureInfoRequest();
|
||||||
|
typeRequest.setLayers(layersArry);
|
||||||
|
typeRequest.setCRS(crs);
|
||||||
|
typeRequest.setBbox(bbox);
|
||||||
|
typeRequest.setWidth(width);
|
||||||
|
typeRequest.setHeight(height);
|
||||||
|
typeRequest.setQueryLayer(queryLayersArry);
|
||||||
|
typeRequest.setInfoFormat(infoFormat);
|
||||||
|
typeRequest.setI(intI);
|
||||||
|
typeRequest.setJ(intJ);
|
||||||
|
typeRequest.setFeatureCount(featureCount);
|
||||||
|
return (Request)typeRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkNull(String key, String value) throws OWSServiceException {
|
||||||
|
if (value == null)
|
||||||
|
throw new OWSServiceException("Required parameter '" + key + "' is missing.", "MissingParameterValue", key);
|
||||||
|
if (value.trim().equals(""))
|
||||||
|
throw new OWSServiceException("Required parameter '" + key + "' is missing.", "MissingParameterValue", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkPreValidate() throws OWSServiceException {
|
||||||
|
checkNull("REQUEST", this.request);
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.wmsRequests, this.request))
|
||||||
|
throw new OWSServiceException("'" + this.request + "' is not supported.", "OperationNotSupported", "REQUEST");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkValidate(Request requestObj) throws OWSServiceException {
|
||||||
|
if (requestObj != null) {
|
||||||
|
checkNull("SERVICE", requestObj.getService());
|
||||||
|
if (!requestObj.getService().equalsIgnoreCase("WMS"))
|
||||||
|
throw new OWSServiceException("The value '" + requestObj.getService() + "' is not appropriate.", "OperationNotSupported", "SERVICE");
|
||||||
|
checkNull("REQUEST", requestObj.getRequest());
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.wmsRequests, requestObj.getRequest()))
|
||||||
|
throw new OWSServiceException("The value '" + requestObj.getRequest() + "' is not appropriate.", "OperationNotSupported", "REQUEST");
|
||||||
|
if (!(requestObj instanceof GetCapabilitiesRequest))
|
||||||
|
if (requestObj instanceof GetFeatureInfoRequest) {
|
||||||
|
GetFeatureInfoRequest typeReq = (GetFeatureInfoRequest)requestObj;
|
||||||
|
checkNull("VERSION", typeReq.getVersion());
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.wmsVersions, requestObj.getVersion()))
|
||||||
|
throw new OWSServiceException("ver.'" + typeReq.getVersion() + "' is not supported.", "VersionNegotiationFailed", "VERSION");
|
||||||
|
int intI = typeReq.getI();
|
||||||
|
if (intI < 0)
|
||||||
|
throw new OWSServiceException("The value of I is less than 0", "InvalidPoint", "I");
|
||||||
|
if (intI > typeReq.getWidth())
|
||||||
|
throw new OWSServiceException("The value of I is larger than WIDTH", "InvalidPoint", "I");
|
||||||
|
int intJ = typeReq.getJ();
|
||||||
|
if (intJ < 0)
|
||||||
|
throw new OWSServiceException("The value of J is less than 0", "InvalidPoint", "J");
|
||||||
|
if (intJ > typeReq.getHeight())
|
||||||
|
throw new OWSServiceException("The value of J is larger than HEIGHT", "InvalidPoint", "J");
|
||||||
|
} else if (requestObj instanceof GetMapRequest) {
|
||||||
|
GetMapRequest typeReq = (GetMapRequest)requestObj;
|
||||||
|
checkNull("VERSION", typeReq.getVersion());
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.wmsVersions, requestObj.getVersion()))
|
||||||
|
throw new OWSServiceException("ver.'" + typeReq.getVersion() + "' is not supported.", "VersionNegotiationFailed", "VERSION");
|
||||||
|
} else if (requestObj instanceof GetLegendGraphicRequest) {
|
||||||
|
GetLegendGraphicRequest typeReq = (GetLegendGraphicRequest)requestObj;
|
||||||
|
checkNull("VERSION", typeReq.getVersion());
|
||||||
|
if (!OWSConstants.isContains(OWSConstants.wmsVersions, requestObj.getVersion()))
|
||||||
|
throw new OWSServiceException("ver.'" + typeReq.getVersion() + "' is not supported.", "VersionNegotiationFailed", "VERSION");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReferencedEnvelope getBbox(String sBBOX, CoordinateReferenceSystem crs) throws OWSServiceException {
|
||||||
|
checkNull("BBOX", sBBOX);
|
||||||
|
sBBOX = sBBOX.replaceAll(" ", "");
|
||||||
|
String[] bboxStrArr = sBBOX.split(",");
|
||||||
|
if (bboxStrArr.length != 4)
|
||||||
|
throw new OWSServiceException("The value '" + sBBOX + "' is not appropriate.", "InvalidParameterValue", "BBOX");
|
||||||
|
double minLon = 0.0D;
|
||||||
|
double minLat = 0.0D;
|
||||||
|
double maxLon = 0.0D;
|
||||||
|
double maxLat = 0.0D;
|
||||||
|
try {
|
||||||
|
minLon = Double.parseDouble(bboxStrArr[0]);
|
||||||
|
minLat = Double.parseDouble(bboxStrArr[1]);
|
||||||
|
maxLon = Double.parseDouble(bboxStrArr[2]);
|
||||||
|
maxLat = Double.parseDouble(bboxStrArr[3]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OWSServiceException("The value '" + sBBOX + "' is not appropriate.", "InvalidParameterValue", "BBOX");
|
||||||
|
}
|
||||||
|
if (minLon > maxLon)
|
||||||
|
throw new OWSServiceException("minLon is larger than maxLon.", "InvalidParameterValue", "BBOX");
|
||||||
|
if (minLat > maxLat)
|
||||||
|
throw new OWSServiceException("minLat is larger than maxLat.", "InvalidParameterValue", "BBOX");
|
||||||
|
ReferencedEnvelope bbox = new ReferencedEnvelope(minLon, maxLon, minLat, maxLat, crs);
|
||||||
|
return bbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Filter getFilter(String filterStr) throws Exception {
|
||||||
|
Filter filter = null;
|
||||||
|
InputSource resource = new InputSource();
|
||||||
|
resource.setCharacterStream(new StringReader(filterStr));
|
||||||
|
Parser parser = new Parser((Configuration)new OGCConfiguration());
|
||||||
|
try {
|
||||||
|
filter = (Filter)parser.parse(resource);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOException("Error Occurred While XML Parsing.", e);
|
||||||
|
} catch (SAXException e) {
|
||||||
|
throw new SAXException("Error Occurred While XML Parsing.", e);
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
throw new ParserConfigurationException("Error Occurred While XML Parsing.");
|
||||||
|
}
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue