Init
commit
d750eeca8a
|
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/classes"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/UserLibrary"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/json-lib-2.4-jdk15.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/commons-lang-2.3.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/serializer.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/javaproj-1.0.6.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/xdoclet-1.2.1.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/ClipReport4.0-1.0.0.301.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/jxl.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/ClipReport4.0-Common.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/OpenXLS.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/OrgService.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/ICERTSecu_JDK18.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.5">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="jst.web"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/ojdbc6-11.2.0.4.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/pngj-2.1.1.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/picocontainer-1.2.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/tibero5-jdbc.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/geowave-driver-0.9.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/jdom-1.1.3.jar"/>
|
||||
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/wms.jar"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="ASCII"?>
|
||||
<properties:ProjectDescription xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:properties="properties.xmi" modelDir="" libraryDir="" profileDir="" templateDir="">
|
||||
<profiles id="org.eclipse.uml2.uml.resources.StandardL3Profile" description="StandardL3 Profile" uri="platform:/plugin/org.eclipse.uml2.uml.resources/profiles/StandardL3.profile.uml" exported="false" kind="system"/>
|
||||
<profiles id="com.soyatec.uml.JavaProfile" description="Java Profile" uri="platform:/plugin/com.soyatec.core/profiles/Java.profile.uml" exported="false" kind="system"/>
|
||||
<profiles id="com.soyatec.uml.SoyatecProfile" description="Soyatec Profile" uri="platform:/plugin/com.soyatec.core/profiles/Soyatec.profile.uml" exported="false" kind="system"/>
|
||||
<profiles id="com.soyatec.uml.ArchetypeProfile" description="Archetype Profile" uri="platform:/plugin/com.soyatec.core/profiles/Archetype.profile.uml" exported="false" kind="system"/>
|
||||
</properties:ProjectDescription>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="org.eclipse.wst.jsdt.core.javascriptValidator"/>
|
||||
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||
</launchConfiguration>
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/target
|
||||
.DS_Store
|
||||
._.DS_Store
|
||||
**/.DS_Store
|
||||
**/._.DS_Store
|
||||
|
||||
|
||||
HELP.md
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
|
||||
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
# Uncomment this line if you wish to ignore the project description file.
|
||||
# Typically, this file would be tracked if it contains build/dependency configurations:
|
||||
#.project
|
||||
|
||||
.svn
|
||||
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
#*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
.vs/
|
||||
|
||||
|
||||
# Added by thkim
|
||||
.classpath
|
||||
/src/main/resources/egovframework/egovProps/globals.properties
|
||||
/src/main/webapp/WEB-INF/clipreport4/DataConnection.properties
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>map</name>
|
||||
<comment>@key 32303037303533312D31302067656F696E666F5F65476F762F544B </comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>LaunchConfigHandle</key>
|
||||
<value><project>/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.soyatec.additional.Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>egovframework.dev.imp.ide.natures.egovnature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
<nature>com.soyatec.additional.Nature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1750384324665</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>map</name>
|
||||
<comment>@key 32303037303533312D31302067656F696E666F5F65476F762F544B </comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>LaunchConfigHandle</key>
|
||||
<value><project>/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.soyatec.additional.Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>egovframework.dev.imp.ide.natures.egovnature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
<nature>com.soyatec.additional.Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="ASCII"?>
|
||||
<properties:ProjectDescription xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:properties="properties.xmi" modelDir="" libraryDir="" profileDir="" templateDir="">
|
||||
<profiles id="org.eclipse.uml2.uml.resources.StandardL3Profile" description="StandardL3 Profile" uri="platform:/plugin/org.eclipse.uml2.uml.resources/profiles/StandardL3.profile.uml" exported="false" kind="system"/>
|
||||
<profiles id="com.soyatec.uml.JavaProfile" description="Java Profile" uri="platform:/plugin/com.soyatec.core/profiles/Java.profile.uml" exported="false" kind="system"/>
|
||||
<profiles id="com.soyatec.uml.SoyatecProfile" description="Soyatec Profile" uri="platform:/plugin/com.soyatec.core/profiles/Soyatec.profile.uml" exported="false" kind="system"/>
|
||||
<profiles id="com.soyatec.uml.ArchetypeProfile" description="Archetype Profile" uri="platform:/plugin/com.soyatec.core/profiles/Archetype.profile.uml" exported="false" kind="system"/>
|
||||
</properties:ProjectDescription>
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set source_prefix=src\main\webapp\
|
||||
set target_prefix=C:\Users\dbnt\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\geoinfo_eGov_work\
|
||||
set target_directory=C:\Users\dbnt\git\dbnt\geoinfo.or.kr\geoinfo_eGov_work\
|
||||
|
||||
set source_file=
|
||||
set target_file=
|
||||
|
||||
for /f "delims=" %%i in (list.txt) do (
|
||||
|
||||
echo %%i | findstr /v "^#" > nul
|
||||
if !errorlevel! == 0 (
|
||||
set "line=%%i"
|
||||
rem #으로 시작하지 않는 라인 처리
|
||||
echo !line!
|
||||
|
||||
|
||||
set line=%%i
|
||||
|
||||
if "!line:~-5!" == ".java" (
|
||||
echo Skip
|
||||
) else if "!line:~-4!" == ".xml" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
:: "src\main\resources\" 제거
|
||||
set relative_path=!relative_path:*src\main\resources\=!
|
||||
set target_file=%target_prefix%WEB-INF\classes\!relative_path!
|
||||
) else if "!line:~-4!" == ".jsp" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
) else if "!line:~-4!" == ".css" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
) else if "!line:~-4!" == ".png" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
) else if "!line:~-4!" == ".svg" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
) else if "!line:~-3!" == ".js" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
) else if "!line:~-4!" == ".reb" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
) else if "!line:~-6!" == ".woff2" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
) else if "!line:~-5!" == ".woff" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
) else if "!line:~-4!" == ".otf" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
) else if "!line:~-11!" == ".properties" (
|
||||
set source_file=%target_directory%!line!
|
||||
set relative_path=!line:%source_prefix%=!
|
||||
set target_file=%target_prefix%!relative_path!
|
||||
)
|
||||
|
||||
rem Copy the source file to the target location, overwriting if necessary
|
||||
echo Copying "!source_file!" to "!target_file!"
|
||||
xcopy /i /Y "!source_file!" "!target_file!"
|
||||
) else (
|
||||
echo #은 무시됩니다
|
||||
)
|
||||
|
||||
|
||||
)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,5 @@
|
|||
---- selectApproveLogCnt Matches (4 in 4 files) ----
|
||||
DownloadAppMapper.java (d:\egov_geoinfo\egovframedev-3.5.1-64bit\workspace\geoinfo_admin\src\main\java\geoinfo\admins\chlog\service): public EgovMap selectApproveLogCnt(String userId) throws Exception;
|
||||
DownloadAppServiceImpl.java (d:\egov_geoinfo\egovframedev-3.5.1-64bit\workspace\geoinfo_admin\src\main\java\geoinfo\admins\chlog\service\impl): EgovMap map = masterMapper.selectApproveLogCnt((String)params.get("userid"));
|
||||
DownloadApp_SQL.xml (d:\egov_geoinfo\egovframedev-3.5.1-64bit\workspace\geoinfo_admin\src\main\resources\geoinfo\sqlmap\mappers\admins\chlog): <select id="selectApproveLogCnt" parameterType="String" resultType="egovMap">
|
||||
DownloadApp_SQL.xml (d:\egov_geoinfo\egovframedev-3.5.1-64bit\workspace\geoinfo_admin\target\classes\geoinfo\sqlmap\mappers\admins\chlog): <select id="selectApproveLogCnt" parameterType="String" resultType="egovMap">
|
||||
Binary file not shown.
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<editmodel:ClassDiagramEditModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:editmodel="editmodel.xmi" xmlns:options="options.xmi" id="geoinfo.com" metadata="uml2-1.0" tag="10" key="32303037303533312D31302067656F696E666F5F65476F76">
|
||||
<diagramOptions xsi:type="options:ClassDiagramOptions" properties="wireOptions=1;Product=eUML2" autoName="false"/>
|
||||
<boardSetting snapToGeometry="true" gridEnabled="true" gridSpacing="15,15" gridOrigin="0,0" rulerUnit="pixel" gridVisibility="false">
|
||||
<leftRuler/>
|
||||
<topRuler/>
|
||||
</boardSetting>
|
||||
<classDiagramPreferences xsi:type="editmodel:UMLClassDiagramPreference" showPopupBars="true" showConnectionHandles="true" attributeSorter="Natural" methodSorter="Natural" showClassStereotype="true" showPackageStereotype="true" showDependencyStereotype="true" showInterfaceStereotype="true" innerClassSorter="Natural" showPublicAttributes="true" showPackageAttributes="true" showStaticAttributes="true" showPublicMethods="true" showPackageMethods="true" showStaticMethods="true" showPublicInnerClasses="true" showPackageInnerClasses="true" showStaticInnerClasses="true" packageIndication="3" showAttributeProperty="true"/>
|
||||
</editmodel:ClassDiagramEditModel>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<editmodel:ClassDiagramEditModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:editmodel="editmodel.xmi" xmlns:options="options.xmi" id="geoinfo.com" metadata="uml2-1.0" tag="10" key="32303037303533312D31302067656F696E666F5F65476F76">
|
||||
<diagramOptions xsi:type="options:ClassDiagramOptions" properties="wireOptions=1;Product=eUML2" autoName="false"/>
|
||||
<boardSetting snapToGeometry="true" gridEnabled="true" gridSpacing="15,15" gridOrigin="0,0" rulerUnit="pixel" gridVisibility="false">
|
||||
<leftRuler/>
|
||||
<topRuler/>
|
||||
</boardSetting>
|
||||
<classDiagramPreferences xsi:type="editmodel:UMLClassDiagramPreference" showPopupBars="true" showConnectionHandles="true" attributeSorter="Natural" methodSorter="Natural" showClassStereotype="true" showPackageStereotype="true" showDependencyStereotype="true" showInterfaceStereotype="true" innerClassSorter="Natural" showPublicAttributes="true" showPackageAttributes="true" showStaticAttributes="true" showPublicMethods="true" showPackageMethods="true" showStaticMethods="true" showPublicInnerClasses="true" showPackageInnerClasses="true" showStaticInnerClasses="true" packageIndication="3" showAttributeProperty="true"/>
|
||||
</editmodel:ClassDiagramEditModel>
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,15 @@
|
|||
#src\main\resources\egovframework\egovProps\globals.properties
|
||||
#src\main\java\geoinfo\regi\manageList\ManageExcelUploadProc01Controller.java
|
||||
#src\main\webapp\WEB-INF\views\web\input\excel_step00.jsp
|
||||
#src\main\webapp\WEB-INF\views\web\input\excel_step31.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\web\manage\list_reg.jsp
|
||||
|
||||
src\main\webapp\WEB-INF\views\drilling\inquiry\drilling_inquiry_project.jsp
|
||||
src\main\webapp\js\map\main\map.js
|
||||
src\main\webapp\js\map\main\left\left.js
|
||||
src\main\webapp\js\map\main\left\left_new.js
|
||||
src\main\resources\egovframework\sqlmap\mapper\map\MapLeft_SQL.xml
|
||||
|
||||
src\main\resources\egovframework\sqlmap\mapper\drilling\home\DrillingHomeMapper.xml
|
||||
|
|
@ -0,0 +1 @@
|
|||
explorer C:\Users\dbnt\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\geoinfo_eGov_work
|
||||
|
|
@ -0,0 +1,595 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>myMap</groupId>
|
||||
<artifactId>myMap</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>myMap</name>
|
||||
<url>http://www.egovframe.go.kr</url> <licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<properties>
|
||||
<java-version>1.7</java-version>
|
||||
|
||||
<org.springframework-version>3.2.4.RELEASE</org.springframework-version>
|
||||
<org.aspectj-version>1.7.3</org.aspectj-version>
|
||||
|
||||
<org.slf4j-version>1.6.6</org.slf4j-version>
|
||||
|
||||
<org.apache.tiles.version>3.0.3</org.apache.tiles.version>
|
||||
|
||||
<egovframework.rte.version>3.5.0</egovframework.rte.version>
|
||||
|
||||
<geotools.version>11.0</geotools.version>
|
||||
<jts.version>1.13</jts.version>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>https://repo.maven.apache.org/maven2/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>eclipse-oxygen-releases</id>
|
||||
<name>Eclipse Oxygen Releases</name>
|
||||
<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://maven.egovframe.go.kr/maven/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-websocket</artifactId>
|
||||
<version>4.1.2.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>aopalliance</groupId>
|
||||
<artifactId>aopalliance</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-dbcp</artifactId>
|
||||
<scope>provided</scope>
|
||||
<version>7.0.53</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.31</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>9.1-901.jdbc4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${org.aspectj-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>${org.aspectj-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjtools</artifactId>
|
||||
<version>${org.aspectj-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.websocket</groupId>
|
||||
<artifactId>javax.websocket-api</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${org.slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.jms</groupId>
|
||||
<artifactId>jms</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jdmk</groupId>
|
||||
<artifactId>jmxtools</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jmx</groupId>
|
||||
<artifactId>jmxri</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lazyluke</groupId>
|
||||
<artifactId>log4jdbc-remix</artifactId>
|
||||
<version>0.2.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-mapper-asl</artifactId>
|
||||
<version>1.9.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-core-asl</artifactId>
|
||||
<version>1.9.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20180813</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jfinal</groupId>
|
||||
<artifactId>cos</artifactId>
|
||||
<version>26Dec2008</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-jsp</artifactId>
|
||||
<version>${org.apache.tiles.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-core</artifactId>
|
||||
<version>${org.apache.tiles.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.jasperreports</groupId>
|
||||
<artifactId>jasperreports</artifactId>
|
||||
<version>5.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jdom</groupId>
|
||||
<artifactId>jdom</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.lucy</groupId>
|
||||
<artifactId>lucy-xss-servlet</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lowagie</groupId>
|
||||
<artifactId>itext</artifactId>
|
||||
<version>2.1.7.js2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xml-apis</groupId>
|
||||
<artifactId>xml-apis</artifactId>
|
||||
<version>1.0.b2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jdom</groupId>
|
||||
<artifactId>jdom</artifactId>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>8.4-701.jdbc3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-main</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-opengis</artifactId>
|
||||
<version>${geotools.version}</version> </dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-referencing</artifactId>
|
||||
<version>${geotools.version}</version> </dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-epsg-hsql</artifactId>
|
||||
<version>${geotools.version}</version> </dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-cql</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-data</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-api</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-metadata</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-xml</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-swing</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-render</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-shapefile</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.xsd</groupId>
|
||||
<artifactId>gt-xsd-sld</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-geojson</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-process</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-jdbc</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-postgis</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-oracle</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-h2</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-mysql</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-db2</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-sqlserver</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vividsolutions</groupId>
|
||||
<artifactId>jts</artifactId>
|
||||
<version>${jts.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-wms</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.emf</groupId>
|
||||
<artifactId>org.eclipse.emf.ecore</artifactId>
|
||||
<version>2.9.1-v20130827-0309</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<directory>${project.basedir}/target</directory> <finalName>myMap</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<configuration>
|
||||
<additionalProjectnatures>
|
||||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
|
||||
</additionalProjectnatures>
|
||||
<additionalBuildcommands>
|
||||
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
|
||||
</additionalBuildcommands>
|
||||
<downloadSources>true</downloadSources>
|
||||
<downloadJavadocs>true</downloadJavadocs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<configuration>
|
||||
<source>${java-version}</source>
|
||||
<target>${java-version}</target>
|
||||
<encoding>${project.build.sourceEncoding}</encoding> <compilerArgument>-Xlint:all</compilerArgument>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<configuration>
|
||||
<mainClass>org.test.int1.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# must be unique in a given SonarQube instance
|
||||
sonar.projectKey=geoinfo
|
||||
|
||||
# --- optional properties ---
|
||||
sonar.host.url=http://localhost:9000
|
||||
# defaults to project key
|
||||
#sonar.projectName=My project
|
||||
# defaults to 'not provided'
|
||||
#sonar.projectVersion=1.0
|
||||
|
||||
# Path is relative to the sonar-project.properties file. Defaults to .
|
||||
#sonar.sources=.
|
||||
sonar.sources=src/main/java,src/main/webapp
|
||||
sonar.exclusions=**/kendo-ui/**/*, **/ClipReport4/**/*, **/G-PIN/**/*, **/IPIN/**/*
|
||||
sonar.java.binaries=target/classes
|
||||
sonar.scm.exclusions.disabled=true
|
||||
# Encoding of the source code. Default is default system encoding
|
||||
sonar.sourceEncoding=euc-kr
|
||||
sonar.login=sqp_ab637361cfede0396764c018ea44c4f6773f858a
|
||||
|
|
@ -0,0 +1,435 @@
|
|||
package com.geotwo.webserver.core;
|
||||
|
||||
import com.geotwo.webserver.core.cache.ImgCacheMngr;
|
||||
import com.geotwo.webserver.core.coverage.O2DemLayerMngr;
|
||||
import com.geotwo.webserver.core.coverage.O2ImgLayerMngr;
|
||||
import com.geotwo.webserver.core.coverage.WpsCovStoreMngr;
|
||||
import com.geotwo.webserver.core.init.ServerConfiguration;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.Map;
|
||||
import com.geotwo.webserver.core.map.layer.FeatureLayer;
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.map.layer.O2DemLayer;
|
||||
import com.geotwo.webserver.core.tile.tms.TMSMngr;
|
||||
import com.geotwo.webserver.core.tile.wmts.WMTSMngr;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.GWaveStoreMngr;
|
||||
import com.geotwo.webserver.core.vector.JdbcStoreMngr;
|
||||
import com.geotwo.webserver.core.vector.ShpStoreMngr;
|
||||
import com.geotwo.webserver.core.vector.WpsVecStoreMngr;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ServerContext {
|
||||
private static Map serviceMap;
|
||||
|
||||
private static String CONF_FOLDER_NAME = "/conf";
|
||||
|
||||
private static File confFolder = null;
|
||||
|
||||
private static String STYLES_FOLDER_NAME = "/styles";
|
||||
|
||||
private static File stylesFolder;
|
||||
|
||||
private static String PLUGINS_FOLDER_NAME = "/plugins";
|
||||
|
||||
private static File pluginsFolder;
|
||||
|
||||
private static Integer docIndent = null;
|
||||
|
||||
private static Boolean useNSPrefix = null;
|
||||
|
||||
private static Integer defaultMaxFeatures = null;
|
||||
|
||||
private static Boolean encryption = null;
|
||||
|
||||
public static void initMap(String mapName, String nameSpace) throws Exception {
|
||||
if (ServerUtil.isNullString(mapName)) {
|
||||
LogMngr.getInstance().logError("[DB]",
|
||||
"ServiceMap Name is NULL. Now set default [O2MAP].");
|
||||
mapName = "O2MAP";
|
||||
}
|
||||
serviceMap = new Map(mapName, nameSpace);
|
||||
}
|
||||
|
||||
public static void changeMap(String mapName, String nameSpace) throws Exception {
|
||||
if (ServerUtil.isNullString(mapName))
|
||||
throw new NullPointerException("Parameter [ServiceMap] is NULL");
|
||||
LogMngr.getInstance().logDebug("[MAP]", "Get MapList");
|
||||
HashSet<String> mapList = ServerConfiguration.getInstance().getMapList();
|
||||
if (!mapList.contains(mapName.trim().toUpperCase()))
|
||||
throw new NullPointerException("Parameter [ServiceMap:" + mapName + "] is not exist in ServiceMap List.");
|
||||
if (ServerUtil.isNullString(nameSpace))
|
||||
nameSpace = serviceMap.getNameSpaceURI();
|
||||
if (serviceMap.getName().equalsIgnoreCase(mapName) &&
|
||||
serviceMap.getNameSpaceURI().equalsIgnoreCase(nameSpace))
|
||||
throw new IllegalArgumentException("Parameter [ServiceMap:" + mapName + "] is current Map.");
|
||||
Map dirtyMap = null;
|
||||
try {
|
||||
ServerInfo.getInstance().setReStarting(true);
|
||||
dirtyMap = serviceMap;
|
||||
serviceMap = new Map(mapName, nameSpace);
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "Create Service Layer");
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "-----------------------------------");
|
||||
initLayers();
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "");
|
||||
} catch (Exception e) {
|
||||
serviceMap = dirtyMap;
|
||||
throw e;
|
||||
} finally {
|
||||
dirtyMap = null;
|
||||
ServerInfo.getInstance().setReStarting(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static Map getMap() throws Exception {
|
||||
if (serviceMap == null)
|
||||
throw new NullPointerException("ServiceMap is NULL.");
|
||||
return serviceMap;
|
||||
}
|
||||
|
||||
public static void initLayers() {
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Create JDBC Layer");
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||
JdbcStoreMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "");
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "Create GeoWave Layer");
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "-----------------------------------");
|
||||
GWaveStoreMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "");
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "Create Shape Layer");
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "-----------------------------------");
|
||||
ShpStoreMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "");
|
||||
LogMngr.getInstance().logInfo("[WMTS]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[WMTS]", "Create WMTS Layer");
|
||||
LogMngr.getInstance().logInfo("[WMTS]", "-----------------------------------");
|
||||
WMTSMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[WMTS]", "");
|
||||
LogMngr.getInstance().logInfo("[TMS]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[TMS]", "Create TMS Layer");
|
||||
LogMngr.getInstance().logInfo("[TMS]", "-----------------------------------");
|
||||
TMSMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[TMS]", "");
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "Create ImgCache Layer");
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "-----------------------------------");
|
||||
ImgCacheMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "");
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "Create O2Img Layer");
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "-----------------------------------");
|
||||
O2ImgLayerMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "");
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "Create O2Dem Layer");
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "-----------------------------------");
|
||||
O2DemLayerMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "");
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "Create O2WPS Layer");
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "-----------------------------------");
|
||||
WpsVecStoreMngr.initLayers();
|
||||
WpsCovStoreMngr.initLayers();
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "");
|
||||
}
|
||||
|
||||
public static void reloadLayers() throws Exception {
|
||||
try {
|
||||
ServerInfo.getInstance().setReStarting(true);
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Relaod JDBC Layer");
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "-----------------------------------");
|
||||
JdbcStoreMngr.reloadLayer();
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "Success to reload JDBC Layer");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[JDBC]", "Fail to reload JDBC Layer :: " + e);
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[JDBC]", "");
|
||||
}
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "Relaod GeoWave Layer");
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "-----------------------------------");
|
||||
GWaveStoreMngr.reloadLayer();
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "Success to reload GeoWave Layer");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "Fail to reload GeoWave Layer :: " + e);
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[GWAVE]", "");
|
||||
}
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "Relaod Shape Layer");
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "-----------------------------------");
|
||||
ShpStoreMngr.reloadLayer();
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "Success to reload Shape Layer");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "Fail to reload Shape Layer :: " + e);
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[SHAPE]", "");
|
||||
}
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[WMTS]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[WMTS]", "Relaod WMTS Layer");
|
||||
LogMngr.getInstance().logInfo("[WMTS]", "-----------------------------------");
|
||||
WMTSMngr.reloadLayer();
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logInfo("[WMTS]", "Fail to reload WMTS Layer :: " + e);
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[WMTS]", "");
|
||||
}
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[TMS]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[TMS]", "Relaod TMS Layer");
|
||||
LogMngr.getInstance().logInfo("[TMS]", "-----------------------------------");
|
||||
TMSMngr.reloadLayer();
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logInfo("[TMS]", "Fail to reload TMS Layer :: " + e);
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[TMS]", "");
|
||||
}
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "Relaod ImgCache Layer");
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "-----------------------------------");
|
||||
ImgCacheMngr.reloadLayer();
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "Fail to reload ImgCache Layer :: " + e);
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[IMGCACHE]", "");
|
||||
}
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "Relaod O2Img Layer");
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "-----------------------------------");
|
||||
O2ImgLayerMngr.reloadLayer();
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "Fail to reload O2Img Layer :: " + e);
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[O2IMG]", "");
|
||||
}
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "Relaod O2Dem Layer");
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "-----------------------------------");
|
||||
O2DemLayerMngr.reloadLayer();
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "Fail to reload O2Dem Layer :: " + e);
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[O2DEM]", "");
|
||||
}
|
||||
try {
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "-----------------------------------");
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "Relaod O2WPS Layer");
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "-----------------------------------");
|
||||
WpsVecStoreMngr.reloadLayer();
|
||||
WpsCovStoreMngr.reloadLayer();
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "Success to reload O2WPS Layer");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "Fail to reload O2WPS Layer :: " + e);
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
ServerInfo.getInstance().setReStarting(false);
|
||||
LogMngr.getInstance().logInfo("[LAYER]", "");
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadStyle(String layerName) throws Exception {
|
||||
try {
|
||||
ServerInfo.getInstance().setReStarting(true);
|
||||
if (layerName != null)
|
||||
layerName = layerName.trim().toUpperCase();
|
||||
ArrayList<Layer> layers = getMap().getAllLayers();
|
||||
for (Layer layer : layers) {
|
||||
if (layerName != null &&
|
||||
!layerName.equalsIgnoreCase(layer.getName()))
|
||||
continue;
|
||||
try {
|
||||
if (layer instanceof FeatureLayer) {
|
||||
((FeatureLayer)layer).reloadServiceStyle();
|
||||
} else if (layer instanceof O2DemLayer) {
|
||||
((O2DemLayer)layer).reloadServiceStyle();
|
||||
}
|
||||
LogMngr.getInstance().logInfo("[STYLE]", "Success to reload Style for this layer [" + layer.getName() + "]");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logInfo("[STYLE]", "Fail to reload Style for this layer [" + layer.getName() + "] :: " + e);
|
||||
continue;
|
||||
} finally {
|
||||
LogMngr.getInstance().logInfo("[STYLE]", "");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
ServerInfo.getInstance().setReStarting(false);
|
||||
LogMngr.getInstance().logInfo("[STYLE]", "");
|
||||
}
|
||||
}
|
||||
|
||||
private static File getWebInfFolder() throws Exception {
|
||||
URL url = ServerContext.class.getResource("/");
|
||||
return (new File(url.toURI())).getParentFile();
|
||||
}
|
||||
|
||||
public static File getConfFolder() throws Exception {
|
||||
if (confFolder == null)
|
||||
try {
|
||||
confFolder = new File(getWebInfFolder(), CONF_FOLDER_NAME);
|
||||
if (!confFolder.exists())
|
||||
confFolder.mkdir();
|
||||
confFolder.setReadable(true, false);
|
||||
confFolder.setWritable(true, false);
|
||||
} catch (SecurityException e) {
|
||||
throw new SecurityException("Folder [WEB-INF" + CONF_FOLDER_NAME + "] is not accessible.", e);
|
||||
} catch (Exception e) {
|
||||
confFolder = null;
|
||||
throw new Exception("Folder [WEB-INF" + CONF_FOLDER_NAME + "] has problem.", e);
|
||||
}
|
||||
return confFolder;
|
||||
}
|
||||
|
||||
public static File setConfFolder(File path) throws Exception {
|
||||
if (path == null ||
|
||||
!path.exists() ||
|
||||
path.isFile())
|
||||
throw new IOException("Conf Folder is not exist.");
|
||||
confFolder = path;
|
||||
return path;
|
||||
}
|
||||
|
||||
public static File getStylesFolder() throws Exception {
|
||||
if (stylesFolder == null)
|
||||
try {
|
||||
stylesFolder = new File(getWebInfFolder(), STYLES_FOLDER_NAME);
|
||||
if (!stylesFolder.exists())
|
||||
stylesFolder.mkdir();
|
||||
stylesFolder.setReadable(true, false);
|
||||
stylesFolder.setWritable(true, false);
|
||||
} catch (SecurityException e) {
|
||||
LogMngr.getInstance().logError("[CONFIG]", "Folder [WEB-INF" + STYLES_FOLDER_NAME + "] is not accessible.");
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
stylesFolder = null;
|
||||
LogMngr.getInstance().logError("[CONFIG]", "Folder [WEB-INF" + STYLES_FOLDER_NAME + "] has problem.");
|
||||
throw e;
|
||||
}
|
||||
return stylesFolder;
|
||||
}
|
||||
|
||||
public static File setStylesFolder(File path) throws Exception {
|
||||
if (path == null ||
|
||||
!path.exists() ||
|
||||
path.isFile())
|
||||
throw new IOException("Styles Folder is not exist.");
|
||||
stylesFolder = path;
|
||||
return path;
|
||||
}
|
||||
|
||||
public static File getPluginsFolder() throws Exception {
|
||||
if (pluginsFolder == null)
|
||||
try {
|
||||
pluginsFolder = new File(getWebInfFolder(), PLUGINS_FOLDER_NAME);
|
||||
if (!pluginsFolder.exists())
|
||||
pluginsFolder.mkdir();
|
||||
pluginsFolder.setReadable(true, false);
|
||||
pluginsFolder.setWritable(true, false);
|
||||
} catch (SecurityException e) {
|
||||
LogMngr.getInstance().logError("[CONFIG]", "Folder [WEB-INF" + PLUGINS_FOLDER_NAME + "] is not accessible.");
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
pluginsFolder = null;
|
||||
LogMngr.getInstance().logError("[CONFIG]", "Folder [WEB-INF" + PLUGINS_FOLDER_NAME + "] has problem.");
|
||||
throw e;
|
||||
}
|
||||
return pluginsFolder;
|
||||
}
|
||||
|
||||
public static File setPluginsFolder(File path) throws Exception {
|
||||
if (path == null ||
|
||||
!path.exists() ||
|
||||
path.isFile())
|
||||
throw new IOException("Plugins Folder is not exist.");
|
||||
pluginsFolder = path;
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void initOptions() {
|
||||
docIndent = null;
|
||||
useNSPrefix = null;
|
||||
defaultMaxFeatures = null;
|
||||
}
|
||||
|
||||
public static Integer getDocIndent() {
|
||||
if (docIndent == null) {
|
||||
String indent = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.map.docindent");
|
||||
if (ServerUtil.isNullString(indent)) {
|
||||
docIndent = Integer.valueOf(2);
|
||||
} else {
|
||||
try {
|
||||
double value = Double.parseDouble(indent);
|
||||
docIndent = Integer.valueOf((int)value);
|
||||
if (docIndent.intValue() < 0)
|
||||
docIndent = Integer.valueOf(0);
|
||||
} catch (Exception e) {
|
||||
docIndent = Integer.valueOf(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return docIndent;
|
||||
}
|
||||
|
||||
public static boolean isUseNSPrefix() {
|
||||
if (useNSPrefix == null) {
|
||||
String useNS = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.map.usedefaultnsprefix");
|
||||
if (ServerUtil.isNullString(useNS)) {
|
||||
useNSPrefix = Boolean.valueOf(true);
|
||||
} else {
|
||||
useNSPrefix = Boolean.valueOf(ServerUtil.getBooleanValue(useNS));
|
||||
}
|
||||
}
|
||||
return useNSPrefix.booleanValue();
|
||||
}
|
||||
|
||||
public static Integer getDefaultMaxFeatrues() {
|
||||
if (defaultMaxFeatures == null) {
|
||||
String defaultValue = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.map.default.max.features");
|
||||
if (ServerUtil.isNullString(defaultValue)) {
|
||||
defaultMaxFeatures = Integer.valueOf(10000);
|
||||
} else {
|
||||
try {
|
||||
defaultMaxFeatures = Integer.valueOf(defaultValue.trim());
|
||||
if (defaultMaxFeatures.intValue() <= 0)
|
||||
defaultMaxFeatures = Integer.valueOf(2147483647);
|
||||
} catch (Exception e) {
|
||||
defaultMaxFeatures = Integer.valueOf(10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultMaxFeatures;
|
||||
}
|
||||
|
||||
public static boolean isEncryption() {
|
||||
if (encryption == null) {
|
||||
String useEncryption = (String)ServerConfiguration.getInstance().getConfMap().get("conf.xml.map.encryption");
|
||||
if (ServerUtil.isNullString(useEncryption)) {
|
||||
encryption = Boolean.valueOf(false);
|
||||
} else {
|
||||
encryption = Boolean.valueOf(ServerUtil.getBooleanValue(useEncryption));
|
||||
}
|
||||
}
|
||||
return encryption.booleanValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.geotwo.webserver.core;
|
||||
|
||||
public class ServerInfo
|
||||
{
|
||||
private static ServerInfo instance = null;
|
||||
|
||||
private boolean isStarted = false;
|
||||
private boolean isReStarting = false;
|
||||
|
||||
public static ServerInfo getInstance()
|
||||
{
|
||||
if (instance == null) {
|
||||
instance = new ServerInfo();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean isStarted()
|
||||
{
|
||||
return this.isStarted;
|
||||
}
|
||||
|
||||
public void setStarted(boolean isStarted) {
|
||||
this.isStarted = isStarted;
|
||||
}
|
||||
|
||||
public boolean isReStarting() {
|
||||
return this.isReStarting;
|
||||
}
|
||||
|
||||
public void setReStarting(boolean isReStarting) {
|
||||
this.isReStarting = isReStarting;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
package com.geotwo.webserver.core.cache;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.cache.ic.CacheFormat;
|
||||
import com.geotwo.webserver.core.cache.ic.CacheLevel;
|
||||
import com.geotwo.webserver.core.cache.ic.CacheLevelSet;
|
||||
import com.geotwo.webserver.core.cache.ic.ImgCacheLayer;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.crs.CRSMngr;
|
||||
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<String, ImgCacheLayer>();
|
||||
|
||||
private static ConcurrentHashMap<String, ImgCacheLayer> dirtyCacheLayerStore;
|
||||
|
||||
public static void initLayers() {
|
||||
cacheLayerStore = new ConcurrentHashMap<String, ImgCacheLayer>();
|
||||
synchronized (cacheLayerStore) {
|
||||
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 = 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<ImgCacheLayer>)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) {
|
||||
Element element = (Element)child;
|
||||
if (element.getName().equalsIgnoreCase("LAYERS")) {
|
||||
params.setValue("img.cache.conf.layers", parseLayers(element));
|
||||
continue;
|
||||
}
|
||||
if (element.getName().equalsIgnoreCase("CACHELOCATION")) {
|
||||
params.setValue("img.cache.conf.cache.location", parseLoc(element));
|
||||
continue;
|
||||
}
|
||||
if (element.getName().equalsIgnoreCase("CACHEFORMAT")) {
|
||||
CacheFormat cFormat = new CacheFormat();
|
||||
for (Object attr : element.getAttributes()) {
|
||||
if (attr instanceof Attribute) {
|
||||
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"))
|
||||
cFormat.setFormat(tileformatAttr.getValue().trim());
|
||||
}
|
||||
}
|
||||
params.setValue("img.cache.conf.cache.format", cFormat);
|
||||
continue;
|
||||
}
|
||||
if (element.getName().equalsIgnoreCase("LEVELSET")) {
|
||||
CacheLevelSet lvlSet = new CacheLevelSet();
|
||||
for (Object level : element.getChildren()) {
|
||||
if (level instanceof Element) {
|
||||
Element levelElement = (Element)level;
|
||||
if (levelElement.getName().equalsIgnoreCase("LEVEL"))
|
||||
lvlSet.addLevel(parseLevel(levelElement));
|
||||
}
|
||||
}
|
||||
params.setValue("img.cache.conf.cache.levelset", 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) {
|
||||
Attribute matrixAttr = (Attribute)attr;
|
||||
if (matrixAttr.getName().equalsIgnoreCase("LEVEL")) {
|
||||
level = Integer.valueOf(Integer.parseInt(matrixAttr.getValue().trim()));
|
||||
continue;
|
||||
}
|
||||
if (matrixAttr.getName().equalsIgnoreCase("RESOLUTION")) {
|
||||
resoltution = Double.valueOf(Double.parseDouble(matrixAttr.getValue().trim()));
|
||||
continue;
|
||||
}
|
||||
if (matrixAttr.getName().equalsIgnoreCase("SCALE"))
|
||||
scale = Double.valueOf(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()) {
|
||||
if (attr instanceof Attribute) {
|
||||
Attribute bboxAttr = (Attribute)attr;
|
||||
if (bboxAttr.getName().equalsIgnoreCase("CRS"))
|
||||
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.0D;
|
||||
double minY = 0.0D;
|
||||
double maxX = 0.0D;
|
||||
double maxY = 0.0D;
|
||||
for (Object subChild : bbox.getChildren()) {
|
||||
if (subChild instanceof Element) {
|
||||
Element subElement = (Element)subChild;
|
||||
if (subElement.getName().equalsIgnoreCase("LOWERCORNER")) {
|
||||
String[] 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")) {
|
||||
String[] 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()) {
|
||||
if (attr instanceof Attribute) {
|
||||
Attribute layerAttr = (Attribute)attr;
|
||||
if (layerAttr.getName().equalsIgnoreCase("CLEARBEFORE"))
|
||||
if (ServerUtil.getBooleanValue(layerAttr.getValue()))
|
||||
ServerUtil.removeFile(dir, 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()) {
|
||||
if (child instanceof Element) {
|
||||
Element layer = (Element)child;
|
||||
if (layer.getName().equalsIgnoreCase("LAYER")) {
|
||||
String name = null;
|
||||
String style = "DEFAULT";
|
||||
for (Object attr : layer.getAttributes()) {
|
||||
if (attr instanceof Attribute) {
|
||||
Attribute layerAttr = (Attribute)attr;
|
||||
if (layerAttr.getName().equalsIgnoreCase("NAME")) {
|
||||
name = layerAttr.getValue().trim();
|
||||
continue;
|
||||
}
|
||||
if (layerAttr.getName().equalsIgnoreCase("STYLE"))
|
||||
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;
|
||||
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(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;
|
||||
}
|
||||
|
||||
public static void removeImgCache(String id) throws Exception {
|
||||
synchronized (cacheLayerStore) {
|
||||
ImgCacheLayer layer = getImgCacheLayer(id);
|
||||
ServerUtil.removeFile(layer.getCacheDir(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
package com.geotwo.webserver.core.cache;
|
||||
|
||||
import com.geotwo.webserver.core.cache.util.FileComparator;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class LogCacheManager {
|
||||
private static LogCacheManager instance;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
private long timerRepeat;
|
||||
|
||||
private long cachePeriod;
|
||||
|
||||
private long folderSize;
|
||||
|
||||
private File logDir = null;
|
||||
|
||||
private String type = null;
|
||||
|
||||
private int value = 0;
|
||||
|
||||
private LogCacheManager() {
|
||||
this.timerRepeat = 60000L;
|
||||
this.timer = new Timer();
|
||||
}
|
||||
|
||||
public static LogCacheManager getInstance() {
|
||||
if (instance == null)
|
||||
instance = new LogCacheManager();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void start(HashMap<String, Object> map) {
|
||||
String dirValue = (String)map.get("conf.xml.log.dir");
|
||||
this.logDir = new File(dirValue.trim());
|
||||
if (!this.logDir.exists()) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Directory is not exist. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
if (this.logDir.isFile()) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Directory is not Directory. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
this.type = (String)map.get("conf.xml.log.cache.type");
|
||||
if (this.type == null || this.type.trim().equals("")) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Type is NULL. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
if (!this.type.trim().equalsIgnoreCase("SIZE") && !this.type.trim().equalsIgnoreCase("DAY")) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Type is support only SIZE/DAY. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
this.type = this.type.trim().toUpperCase();
|
||||
String sValue = (String)map.get("conf.xml.log.cache.value");
|
||||
try {
|
||||
if (sValue == null || sValue.trim().equals("")) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Value is NULL. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
this.value = Integer.parseInt(sValue);
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Log Cache Value is only support Integer[" + sValue + "]. Now log cache always saved.");
|
||||
return;
|
||||
}
|
||||
if (this.value < 1) {
|
||||
LogMngr.getInstance().logError("[CACHE]", "Now log cache always saved. :: Log cache value is " + this.value);
|
||||
return;
|
||||
}
|
||||
if (this.type.trim().equalsIgnoreCase("SIZE")) {
|
||||
this.folderSize = this.value;
|
||||
LogMngr.getInstance().logInfo("[CACHE]", "Log cache managed by Directory Volume. :: " + this.value + "/MB");
|
||||
} else if (this.type.trim().equalsIgnoreCase("DAY")) {
|
||||
this.cachePeriod = this.value;
|
||||
LogMngr.getInstance().logInfo("[CACHE]", "Log cache managed by creation period of File. :: " + this.value + "/Day");
|
||||
}
|
||||
this.timerRepeat = 21600000L;
|
||||
this.timer.cancel();
|
||||
this.timer = new Timer();
|
||||
this.timer.scheduleAtFixedRate(new CacheTimerTask(), 600000L, this.timerRepeat);
|
||||
LogMngr.getInstance().logInfo("[CACHE]", "");
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.timer.cancel();
|
||||
this.timer.purge();
|
||||
}
|
||||
|
||||
class CacheTimerTask extends TimerTask {
|
||||
public void run() {
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "------------------------------");
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Run log cache management");
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "------------------------------");
|
||||
if (LogCacheManager.this.type.equalsIgnoreCase("SIZE")) {
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Check Directory volume. Every " + (LogCacheManager.this.timerRepeat / 1000L / 60L) + "/min, Limits " + LogCacheManager.this.folderSize + "MB");
|
||||
ArrayList<File> fileList = new ArrayList<File>();
|
||||
readFile(fileList, LogCacheManager.this.logDir);
|
||||
double cacheSize = getFileSize(fileList);
|
||||
double size = (LogCacheManager.this.folderSize * 1024L * 1024L);
|
||||
if (size < cacheSize) {
|
||||
Collections.sort(fileList, (Comparator<? super File>)new FileComparator());
|
||||
for (int i = 0; i < fileList.size() &&
|
||||
fileList.size() > 4; i++) {
|
||||
File dFile = fileList.get(i);
|
||||
if (dFile.exists() && dFile.isFile()) {
|
||||
cacheSize -= ((File)fileList.get(i)).length();
|
||||
dFile.delete();
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Remove log cache by Size. [" + dFile + "]");
|
||||
fileList.remove(i);
|
||||
i--;
|
||||
if (dFile.getParentFile().isDirectory() && (dFile.getParentFile().list()).length == 0) {
|
||||
File pFile = dFile.getParentFile();
|
||||
dFile = null;
|
||||
pFile.delete();
|
||||
}
|
||||
}
|
||||
if (size > cacheSize)
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (LogCacheManager.this.type.equalsIgnoreCase("DAY")) {
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Check creation time of File. Every " + (LogCacheManager.this.timerRepeat / 1000L / 60L) + "/min, Limits " + LogCacheManager.this.cachePeriod + "Days");
|
||||
ArrayList<File> fileList = new ArrayList<File>();
|
||||
readFile(fileList, LogCacheManager.this.logDir);
|
||||
Collections.sort(fileList, (Comparator<? super File>)new FileComparator());
|
||||
long time = 86400000L * LogCacheManager.this.cachePeriod;
|
||||
for (int i = 0; i < fileList.size(); ) {
|
||||
if (fileList.size() <= 4)
|
||||
break;
|
||||
File dFile = fileList.get(i);
|
||||
if (time < System.currentTimeMillis() - dFile.lastModified()) {
|
||||
if (dFile.exists() && dFile.isFile()) {
|
||||
dFile.delete();
|
||||
LogMngr.getInstance().logDebug("[CACHE]", "Remove log cache by Day. [" + dFile + "]");
|
||||
fileList.remove(i);
|
||||
i--;
|
||||
if (dFile.getParentFile().isDirectory() && (dFile.getParentFile().list()).length == 0) {
|
||||
File pFile = dFile.getParentFile();
|
||||
dFile = null;
|
||||
pFile.delete();
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readFile(ArrayList<File> list, File file) {
|
||||
if (file.exists())
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
file.delete();
|
||||
} else {
|
||||
for (int i = 0; i < files.length; i++)
|
||||
readFile(list, files[i]);
|
||||
}
|
||||
} else {
|
||||
list.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
private double getFileSize(ArrayList<File> list) {
|
||||
double size = 0.0D;
|
||||
for (File file : list)
|
||||
size += file.length();
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.geotwo.webserver.core.cache.ic;
|
||||
|
||||
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 com.geotwo.webserver.core.cache.ic;
|
||||
|
||||
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 com.geotwo.webserver.core.cache.ic;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package com.geotwo.webserver.core.cache.ic;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
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(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,16 @@
|
|||
package com.geotwo.webserver.core.cache.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class FileComparator
|
||||
implements Comparator<File>
|
||||
{
|
||||
public int compare(File f1, File f2)
|
||||
{
|
||||
if (f1.lastModified() > f2.lastModified()) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,188 @@
|
|||
package com.geotwo.webserver.core.coverage;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerInfo;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerLevelSet;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerUtil;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.map.layer.O2DemLayer;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
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(dir, 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 = 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 {
|
||||
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 {
|
||||
bReader = new BufferedReader(new FileReader(conf));
|
||||
String line;
|
||||
while ((line = bReader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.startsWith("#") || ServerUtil.isNullString(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]")) {
|
||||
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) {}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2DEM]",
|
||||
"[" + conf.getName() + "] O2DemLayer configuration file is not valid :: " + e.getMessage());
|
||||
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(layerName))
|
||||
throw new IOException("O2DemLayer LayerName is null");
|
||||
if (crs == null)
|
||||
throw new IOException("O2DemLayer LayerCRS is null");
|
||||
try {
|
||||
O2LayerLevelSet lvlSet = O2LayerUtil.createLevelSet(LayerFactory.LayerType.O2DEM, 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", ServerContext.getMap().getName());
|
||||
params.setValue("conf.service.layer.name", layerName);
|
||||
params.setValue("conf.service.ref.server", LayerFactory.LayerType.O2DEM.getType());
|
||||
params.setValue("conf.service.ref.source", layerPath.getParent());
|
||||
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);
|
||||
params.setValue("o2layer.conf.level.set", lvlSet);
|
||||
Layer layer = LayerFactory.createLayer(LayerFactory.LayerType.O2DEM, params);
|
||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||
return (O2DemLayer)layer;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void reloadLayer() throws Exception {
|
||||
ArrayList<Layer> oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.O2DEM);
|
||||
try {
|
||||
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,169 @@
|
|||
package com.geotwo.webserver.core.coverage;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerInfo;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerLevelSet;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerUtil;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.map.layer.O2ImgLayer;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
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(dir, 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 = 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 {
|
||||
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 {
|
||||
bReader = new BufferedReader(new FileReader(conf));
|
||||
String line;
|
||||
while ((line = bReader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.startsWith("#") || ServerUtil.isNullString(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]")) {
|
||||
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) {}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2IMG]",
|
||||
"[" + conf.getName() + "] O2ImgLayer configuration file is not valid :: " + e.getMessage());
|
||||
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(layerName))
|
||||
throw new IOException("O2ImgLayer LayerName is null");
|
||||
if (crs == null)
|
||||
throw new IOException("O2ImgLayer LayerCRS is null");
|
||||
try {
|
||||
O2LayerLevelSet lvlSet = O2LayerUtil.createLevelSet(LayerFactory.LayerType.O2IMG, layerPath);
|
||||
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", LayerFactory.LayerType.O2IMG.getType());
|
||||
params.setValue("conf.service.ref.source", layerPath.getParent());
|
||||
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);
|
||||
params.setValue("o2layer.conf.level.set", lvlSet);
|
||||
Layer layer = LayerFactory.createLayer(LayerFactory.LayerType.O2IMG, params);
|
||||
ServerContext.getMap().getServiceLayerSet().addLayer(layer, false);
|
||||
return (O2ImgLayer)layer;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void reloadLayer() throws Exception {
|
||||
ArrayList<Layer> oldLayers = ServerContext.getMap().getServiceLayerSet().removeLayer(LayerFactory.LayerType.O2IMG);
|
||||
try {
|
||||
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,74 @@
|
|||
package com.geotwo.webserver.core.coverage;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerLevelSet;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerUtil;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.map.layer.O2DemLayer;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.WpsVecStoreMngr;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public class WpsCovStoreMngr {
|
||||
public static void initLayers() {}
|
||||
|
||||
public static O2DemLayer addLayer(File layerPath, String layerName, String layerType, CoordinateReferenceSystem crs, String hashTag, String desc, String authorId, WpsVecStoreMngr.O2WpsMetaTableType metaTblType, Float min, Float max, Float noData) throws Exception {
|
||||
if (layerPath == null ||
|
||||
!layerPath.exists() ||
|
||||
layerPath.isFile())
|
||||
throw new IOException("O2WPSCOVLayer levelset is not exist [" + layerPath.getAbsolutePath() + "]");
|
||||
if (ServerUtil.isNullString(layerName))
|
||||
throw new IOException("O2WPSCOVLayer LayerName is null");
|
||||
if (crs == null)
|
||||
throw new IOException("O2WPSCOVLayer LayerCRS is null");
|
||||
try {
|
||||
O2LayerLevelSet lvlSet = O2LayerUtil.createLevelSet(LayerFactory.LayerType.O2DEM, layerPath);
|
||||
lvlSet.setMinData(min);
|
||||
lvlSet.setMaxData(max);
|
||||
lvlSet.setNoData(noData);
|
||||
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", LayerFactory.LayerType.O2DEM.getType());
|
||||
params.setValue("conf.service.ref.source", layerPath.getParent());
|
||||
params.setValue("conf.service.o2wps.source.path", layerPath.toString());
|
||||
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.o2wps.hashtag", hashTag);
|
||||
params.setValue("conf.service.description", desc);
|
||||
params.setValue("conf.service.o2wps.source.type", "o2i");
|
||||
if (authorId == null) {
|
||||
params.setValue("conf.service.o2wps.author.id", "Anonymous");
|
||||
} else {
|
||||
params.setValue("conf.service.o2wps.author.id", authorId);
|
||||
}
|
||||
params.setValue("o2layer.conf.level.set", lvlSet);
|
||||
Layer layer = LayerFactory.createLayer(LayerFactory.LayerType.O2WPSCOV, params);
|
||||
ServerContext.getMap().getO2WpsLayerSet().addLayer(metaTblType.getName(), layer);
|
||||
return (O2DemLayer)layer;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void reloadLayer() throws Exception {
|
||||
ArrayList<Layer> oldLayers = ServerContext.getMap().getO2WpsLayerSet().removeLayer(LayerFactory.LayerType.O2WPSCOV);
|
||||
try {
|
||||
initLayers();
|
||||
LogMngr.getInstance().logInfo("[O2WPS]", "Success to reload O2DemLayers.");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2WPS]", "Fail to reload O2DemLayers. Now use previous O2DemLayers :: " + e);
|
||||
ServerContext.getMap().getO2WpsLayerSet().addLayers(oldLayers, false);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteCoverageFiles(File fileName) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.geotwo.webserver.core.coverage.o2layer;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
|
||||
public class O2LayerIndex
|
||||
{
|
||||
Envelope bbox;
|
||||
int row;
|
||||
int col;
|
||||
int blockIndex;
|
||||
long filePosition;
|
||||
|
||||
public O2LayerIndex(Envelope bbox, int row, int col)
|
||||
{
|
||||
this.bbox = bbox;
|
||||
this.row = row;
|
||||
this.col = col;
|
||||
}
|
||||
|
||||
public Envelope getBBox() {
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
return this.row;
|
||||
}
|
||||
|
||||
public int getCol() {
|
||||
return this.col;
|
||||
}
|
||||
|
||||
public void setBlockIndex(int idx) {
|
||||
this.blockIndex = idx;
|
||||
}
|
||||
|
||||
public int getBlockIndex() {
|
||||
return this.blockIndex;
|
||||
}
|
||||
|
||||
public void setFilePosition(long pos) {
|
||||
this.filePosition = pos;
|
||||
}
|
||||
|
||||
public long getFilePosition() {
|
||||
return this.filePosition;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
package com.geotwo.webserver.core.coverage.o2layer;
|
||||
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.crs.CRSMngr;
|
||||
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(name))
|
||||
this.layerName = null;
|
||||
this.layerName = name.trim().toUpperCase();
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
public void setActivate(String actiStr) {
|
||||
this.activate = ServerUtil.getBooleanValue(actiStr);
|
||||
}
|
||||
|
||||
public void setLayerCRS(String crsName) {
|
||||
this.layerCRS = CRSMngr.getCRS(crsName);
|
||||
}
|
||||
|
||||
public void setLayerPath(String path) {
|
||||
if (ServerUtil.isNullString(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(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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
package com.geotwo.webserver.core.coverage.o2layer;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.io.File;
|
||||
|
||||
public class O2LayerLevel
|
||||
{
|
||||
private final File levelPath;
|
||||
private String version;
|
||||
private String type;
|
||||
private int level;
|
||||
private Envelope bbox;
|
||||
private double minZ;
|
||||
private double maxZ;
|
||||
private double resolutionX;
|
||||
private double resolutionY;
|
||||
private int totalPixelSizeX;
|
||||
private int totalPixelSizeY;
|
||||
private int tileCountX;
|
||||
private int tileCountY;
|
||||
private int tileSizeX;
|
||||
private int tileSizeY;
|
||||
private int blockCount;
|
||||
private byte[] reserved = new byte[32];
|
||||
|
||||
public O2LayerLevel(File dir) throws Exception {
|
||||
this.levelPath = dir;
|
||||
}
|
||||
|
||||
public File getLevelPath() {
|
||||
return this.levelPath;
|
||||
}
|
||||
|
||||
void setVersion(String version) {
|
||||
if (version.length() != 8) {
|
||||
version = "O2I1.0.0";
|
||||
return;
|
||||
}
|
||||
|
||||
this.version = version.trim().toUpperCase();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
void setType(String type)
|
||||
{
|
||||
if (type.length() != 8) {
|
||||
type = "DEM/FLT ";
|
||||
return;
|
||||
}
|
||||
|
||||
this.type = type.trim().toUpperCase();
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
void setLevel(int lvl) {
|
||||
this.level = lvl;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
void setBBox(Envelope box) {
|
||||
this.bbox = box;
|
||||
}
|
||||
|
||||
public Envelope getBBox() {
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
void setZ(double min, double max) {
|
||||
this.minZ = min;
|
||||
this.maxZ = max;
|
||||
}
|
||||
|
||||
public double getMinZ() {
|
||||
return this.minZ;
|
||||
}
|
||||
|
||||
public double getMaxZ() {
|
||||
return this.maxZ;
|
||||
}
|
||||
|
||||
void setResolution(double x, double y) {
|
||||
this.resolutionX = Math.abs(x);
|
||||
this.resolutionY = Math.abs(y);
|
||||
}
|
||||
|
||||
public double getResolutionX() {
|
||||
return this.resolutionX;
|
||||
}
|
||||
|
||||
public double getResolutionY() {
|
||||
return this.resolutionY;
|
||||
}
|
||||
|
||||
void setTotalPixelSize(int x, int y) {
|
||||
this.totalPixelSizeX = x;
|
||||
this.totalPixelSizeY = y;
|
||||
}
|
||||
|
||||
public int getTotalPixelSizeX() {
|
||||
return this.totalPixelSizeX;
|
||||
}
|
||||
|
||||
public int getTotalPixelSizeY() {
|
||||
return this.totalPixelSizeY;
|
||||
}
|
||||
|
||||
void setTileCount(int x, int y) {
|
||||
this.tileCountX = x;
|
||||
this.tileCountY = y;
|
||||
}
|
||||
|
||||
public int getTileCountX() {
|
||||
return this.tileCountX;
|
||||
}
|
||||
|
||||
public int getTileCountY() {
|
||||
return this.tileCountY;
|
||||
}
|
||||
|
||||
void setTileSize(int x, int y) {
|
||||
this.tileSizeX = x;
|
||||
this.tileSizeY = y;
|
||||
}
|
||||
|
||||
public int getTileSizeX() {
|
||||
return this.tileSizeX;
|
||||
}
|
||||
|
||||
public int getTileSizeY() {
|
||||
return this.tileSizeY;
|
||||
}
|
||||
|
||||
void setBlockCount(int count) {
|
||||
this.blockCount = count;
|
||||
}
|
||||
|
||||
public int getBlockCount() {
|
||||
return this.blockCount;
|
||||
}
|
||||
|
||||
void setReserved(byte[] in) {
|
||||
if ((in == null) || (in.length != this.reserved.length)) {
|
||||
for (int i = 0; i < this.reserved.length; i++) {
|
||||
this.reserved[i] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.reserved = in;
|
||||
}
|
||||
|
||||
public byte[] getReserved() {
|
||||
return this.reserved;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.geotwo.webserver.core.coverage.o2layer;
|
||||
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.io.File;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class O2LayerLevelSet {
|
||||
private final File rootPath;
|
||||
|
||||
private final LayerFactory.LayerType layerType;
|
||||
|
||||
private Envelope bbox;
|
||||
|
||||
TreeMap<Integer, O2LayerLevel> levels = new TreeMap<Integer, O2LayerLevel>();
|
||||
|
||||
private Float minData;
|
||||
|
||||
private Float maxData;
|
||||
|
||||
private Float noData;
|
||||
|
||||
public O2LayerLevelSet(LayerFactory.LayerType type, File dir) {
|
||||
this.layerType = type;
|
||||
this.rootPath = dir;
|
||||
}
|
||||
|
||||
public File getRootPath() {
|
||||
return this.rootPath;
|
||||
}
|
||||
|
||||
public LayerFactory.LayerType getLayerType() {
|
||||
return this.layerType;
|
||||
}
|
||||
|
||||
void addLevel(O2LayerLevel level) {
|
||||
this.levels.put(Integer.valueOf(level.getLevel()), level);
|
||||
if (this.bbox == null) {
|
||||
this.bbox = level.getBBox();
|
||||
} else {
|
||||
this.bbox.expandToInclude(this.bbox);
|
||||
}
|
||||
}
|
||||
|
||||
public O2LayerLevel getLevelByResolution(double res) {
|
||||
O2LayerLevel level = null;
|
||||
for (O2LayerLevel lvl : this.levels.values()) {
|
||||
if (level == null) {
|
||||
level = lvl;
|
||||
continue;
|
||||
}
|
||||
if (Math.abs(level.getResolutionX() - res) >
|
||||
Math.abs(lvl.getResolutionX() - res))
|
||||
level = lvl;
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
public O2LayerLevel getLevelByIndex(int idx) {
|
||||
return this.levels.get(Integer.valueOf(idx));
|
||||
}
|
||||
|
||||
public O2LayerLevel getLevel(int idx) {
|
||||
return (O2LayerLevel)this.levels.values().toArray()[idx];
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.levels.size();
|
||||
}
|
||||
|
||||
public Envelope getBBox() {
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
public void setMinData(Float min) {
|
||||
this.minData = min;
|
||||
}
|
||||
|
||||
public void setMaxData(Float max) {
|
||||
this.maxData = max;
|
||||
}
|
||||
|
||||
public void setNoData(Float no) {
|
||||
this.noData = no;
|
||||
}
|
||||
|
||||
public Float getMinData() {
|
||||
return this.minData;
|
||||
}
|
||||
|
||||
public Float getMaxData() {
|
||||
return this.maxData;
|
||||
}
|
||||
|
||||
public Float getNoData() {
|
||||
return this.noData;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,461 @@
|
|||
package com.geotwo.webserver.core.coverage.o2layer;
|
||||
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.media.jai.RasterFactory;
|
||||
import org.geotools.coverage.GridSampleDimension;
|
||||
import org.geotools.coverage.grid.GridCoverage2D;
|
||||
import org.geotools.coverage.grid.GridCoverageFactory;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
public class O2LayerUtil {
|
||||
public static final String NODATA_PROPERTY_NAME = "GC_NODATA";
|
||||
|
||||
public static final String MINVALUE_PROPERTY_NAME = "GC_MINVALUE";
|
||||
|
||||
public static final String MAXVALUE_PROPERTY_NAME = "GC_MAXVALUE";
|
||||
|
||||
private static final int INDEX_HEADER_BYTE = 144;
|
||||
|
||||
private static final int INDEX_TILEINFO_BYTE = 20;
|
||||
|
||||
private static final GridCoverageFactory gcFactory = new GridCoverageFactory();
|
||||
|
||||
public static String readString(FileChannel fc, int capacity) throws Exception {
|
||||
ByteBuffer byteData = ByteBuffer.allocate(capacity);
|
||||
fc.read(byteData);
|
||||
byteData.flip();
|
||||
String result = new String(byteData.order(ByteOrder.nativeOrder()).array());
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int readInt(FileChannel fc) throws Exception {
|
||||
ByteBuffer byteData = ByteBuffer.allocate(4);
|
||||
fc.read(byteData);
|
||||
byteData.flip();
|
||||
int result = byteData.order(ByteOrder.nativeOrder()).getInt();
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static double readDouble(FileChannel fc) throws Exception {
|
||||
ByteBuffer byteData = ByteBuffer.allocate(8);
|
||||
fc.read(byteData);
|
||||
byteData.flip();
|
||||
double result = byteData.order(ByteOrder.nativeOrder()).getDouble();
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static O2LayerLevelSet createLevelSet(LayerFactory.LayerType type, File dir) throws Exception {
|
||||
if (dir == null ||
|
||||
!dir.exists() ||
|
||||
dir.isFile())
|
||||
throw new IOException("O2ImgLayer or O2DemLayer dataset is not exist [" + dir.getAbsolutePath() + "]");
|
||||
if (type == null)
|
||||
throw new IOException("O2ImgLayer or O2DemLayer type is Null");
|
||||
File[] levels = dir.listFiles(new FileFilter() {
|
||||
String regex = "^LEVEL[0-9]+";
|
||||
|
||||
public boolean accept(File path) {
|
||||
if (path.isDirectory() &&
|
||||
path.getName().toUpperCase().matches(this.regex))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
O2LayerLevelSet lvlSet = new O2LayerLevelSet(type, dir);
|
||||
findValueInfo(lvlSet);
|
||||
LogMngr.getInstance().logDebug("[O2INDEX]",
|
||||
"[" + dir.getName() + "] This layer has [" + levels.length + "] level. Now find index file for eatch level");
|
||||
byte b;
|
||||
int i;
|
||||
File[] arrayOfFile1;
|
||||
for (i = (arrayOfFile1 = levels).length, b = 0; b < i; ) {
|
||||
File level = arrayOfFile1[b];
|
||||
try {
|
||||
O2LayerLevel idx = createLevel(type, level);
|
||||
lvlSet.addLevel(idx);
|
||||
LogMngr.getInstance().logDebug("[O2INDEX]",
|
||||
"[" + dir.getName() + "] Success to add this Level [" + level.getName() + "]");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2INDEX]",
|
||||
"[" + dir.getName() + "] Fail to add this Level [" + level.getName() + "] :: " + e);
|
||||
}
|
||||
b++;
|
||||
}
|
||||
if (lvlSet.size() == 0)
|
||||
throw new IOException("[" + dir.getName() + "] This layer has no level.");
|
||||
return lvlSet;
|
||||
}
|
||||
|
||||
private static void findValueInfo(O2LayerLevelSet lvlSet) throws Exception {
|
||||
RandomAccessFile raf = null;
|
||||
try {
|
||||
File infoFile = new File(lvlSet.getRootPath(), "/info.o2img");
|
||||
LogMngr.getInstance().logDebug("[O2INFO]",
|
||||
"Now find info.o2img for O2IMG & O2DEM from here [" + infoFile.getAbsolutePath() + "]");
|
||||
raf = new RandomAccessFile(infoFile, "r");
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
String type = raf.readLine();
|
||||
type = type.trim().toUpperCase();
|
||||
if (lvlSet.getLayerType() == LayerFactory.LayerType.O2IMG) {
|
||||
if (!type.equalsIgnoreCase("IMAGE"))
|
||||
throw new Exception("This level is not O2IMG type");
|
||||
} else if (!type.equalsIgnoreCase("DEM")) {
|
||||
throw new Exception("This level is not O2DEM type");
|
||||
}
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
raf.readLine();
|
||||
String minmax = raf.readLine();
|
||||
if (minmax != null) {
|
||||
String[] value = minmax.split("\\s+");
|
||||
lvlSet.setMinData(Float.valueOf(value[0]));
|
||||
lvlSet.setMaxData(Float.valueOf(value[1]));
|
||||
}
|
||||
String nodata = raf.readLine();
|
||||
if (nodata != null)
|
||||
lvlSet.setNoData(Float.valueOf(nodata));
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2INFO]",
|
||||
"Fail to find info now use default or user setting");
|
||||
} finally {
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
} catch (IOException iOException) {}
|
||||
}
|
||||
}
|
||||
|
||||
private static O2LayerLevel createLevel(LayerFactory.LayerType type, File dir) throws Exception {
|
||||
RandomAccessFile raf = null;
|
||||
FileChannel channel = null;
|
||||
try {
|
||||
File idxFile = new File(dir, "/index.o2img");
|
||||
raf = new RandomAccessFile(idxFile, "r");
|
||||
channel = raf.getChannel();
|
||||
O2LayerLevel o2Level = new O2LayerLevel(dir);
|
||||
o2Level.setVersion(readString(channel, 8));
|
||||
o2Level.setType(readString(channel, 8));
|
||||
if (type == LayerFactory.LayerType.O2IMG) {
|
||||
if (!o2Level.getType().contains("IMG"))
|
||||
throw new Exception("This level is not O2IMG type");
|
||||
} else if (!o2Level.getType().contains("DEM")) {
|
||||
throw new Exception("This level is not O2DEM type");
|
||||
}
|
||||
o2Level.setLevel(readInt(channel));
|
||||
double minx = readDouble(channel);
|
||||
double maxx = readDouble(channel);
|
||||
double miny = readDouble(channel);
|
||||
double maxy = readDouble(channel);
|
||||
o2Level.setBBox(new Envelope(minx, maxx, miny, maxy));
|
||||
double minz = readDouble(channel);
|
||||
double maxz = readDouble(channel);
|
||||
o2Level.setZ(minz, maxz);
|
||||
double resX = readDouble(channel);
|
||||
double resY = readDouble(channel);
|
||||
o2Level.setResolution(resX, resY);
|
||||
int tPixelSizeX = readInt(channel);
|
||||
int tPixelSizeY = readInt(channel);
|
||||
o2Level.setTotalPixelSize(tPixelSizeX, tPixelSizeY);
|
||||
int tileCountY = readInt(channel);
|
||||
int tileCountX = readInt(channel);
|
||||
o2Level.setTileCount(tileCountX, tileCountY);
|
||||
int tileSizeX = readInt(channel);
|
||||
int tileSizeY = readInt(channel);
|
||||
o2Level.setTileSize(tileSizeX, tileSizeY);
|
||||
o2Level.setBlockCount(readInt(channel));
|
||||
return o2Level;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (channel != null && channel.isOpen())
|
||||
try {
|
||||
channel.close();
|
||||
} catch (IOException iOException) {}
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
} catch (IOException iOException) {}
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage getO2Img(File levelPath, int blockIdx, long bPos) throws Exception {
|
||||
RandomAccessFile raf = null;
|
||||
FileChannel channel = null;
|
||||
ByteBuffer byteData = null;
|
||||
ByteArrayInputStream inStream = null;
|
||||
try {
|
||||
File blockFile = new File(levelPath, "/block" + blockIdx + ".o2blk");
|
||||
raf = new RandomAccessFile(blockFile, "r");
|
||||
channel = raf.getChannel();
|
||||
channel.position(bPos);
|
||||
int size = readInt(channel);
|
||||
raf.skipBytes(8);
|
||||
byteData = ByteBuffer.allocate(size - 12);
|
||||
channel.read(byteData);
|
||||
byteData.flip();
|
||||
inStream = new ByteArrayInputStream(byteData.order(ByteOrder.nativeOrder()).array());
|
||||
BufferedImage bImage = ImageIO.read(inStream);
|
||||
return bImage;
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "[O2LayerUtil] getO2Img fail :: " + e);
|
||||
throw e;
|
||||
} finally {
|
||||
if (channel != null && channel.isOpen())
|
||||
try {
|
||||
channel.close();
|
||||
} catch (IOException iOException) {}
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
} catch (IOException iOException) {}
|
||||
if (byteData != null) {
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
}
|
||||
if (inStream != null) {
|
||||
inStream.close();
|
||||
inStream = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static float[][] getO2Dem(File levelPath, int blockIdx, long bPos, int width, int height, Float min, Float max, Float noData) throws Exception {
|
||||
RandomAccessFile raf = null;
|
||||
FileChannel channel = null;
|
||||
ByteBuffer byteData = null;
|
||||
ByteArrayInputStream inStream = null;
|
||||
try {
|
||||
File blockFile = new File(levelPath, "/block" + blockIdx + ".o2blk");
|
||||
raf = new RandomAccessFile(blockFile, "r");
|
||||
channel = raf.getChannel();
|
||||
channel.position(bPos);
|
||||
int size = readInt(channel);
|
||||
int matrixSize = size - 12;
|
||||
raf.skipBytes(8);
|
||||
byteData = ByteBuffer.allocate(matrixSize);
|
||||
channel.read(byteData);
|
||||
byteData.flip();
|
||||
inStream = new ByteArrayInputStream(byteData.array());
|
||||
float[][] data = new float[height][width];
|
||||
byte[] read = new byte[4];
|
||||
if (noData == null)
|
||||
noData = Float.valueOf(Float.NaN);
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
inStream.read(read);
|
||||
float dem = ByteBuffer.wrap(read).order(ByteOrder.nativeOrder()).getFloat();
|
||||
if (min != null && dem < min.floatValue()) {
|
||||
data[y][x] = noData.floatValue();
|
||||
} else if (max != null && max.floatValue() < dem) {
|
||||
data[y][x] = noData.floatValue();
|
||||
} else {
|
||||
data[y][x] = dem;
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[O2IMG]", "[O2LayerUtil] getO2Img fail :: " + e);
|
||||
throw e;
|
||||
} finally {
|
||||
if (channel != null && channel.isOpen())
|
||||
try {
|
||||
channel.close();
|
||||
} catch (IOException iOException) {}
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
} catch (IOException iOException) {}
|
||||
if (byteData != null) {
|
||||
byteData.clear();
|
||||
byteData = null;
|
||||
}
|
||||
if (inStream != null) {
|
||||
inStream.close();
|
||||
inStream = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage getMap(O2LayerLevelSet levelSet, ReferencedEnvelope bbox, int width, int height) throws Exception {
|
||||
BufferedImage image = new BufferedImage(width, height, 6);
|
||||
Envelope targetBBox = bbox.intersection(levelSet.getBBox());
|
||||
if (targetBBox == null || targetBBox.isNull())
|
||||
return image;
|
||||
double resX = bbox.getWidth() / width;
|
||||
double resY = bbox.getHeight() / height;
|
||||
double res = Math.max(resX, resY);
|
||||
O2LayerLevel level = levelSet.getLevelByResolution(res);
|
||||
ArrayList<O2LayerIndex> idxs = calBlockIndex(level, (Envelope)bbox);
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
for (O2LayerIndex idx : idxs) {
|
||||
BufferedImage o2img = getO2Img(level.getLevelPath(), idx.getBlockIndex(), idx.getFilePosition());
|
||||
Rectangle tileArea = ServerUtil.calPaintArea(new Rectangle(width, height), (Envelope)bbox, idx.getBBox());
|
||||
int startX = (tileArea.x < 0) ? 0 : tileArea.x;
|
||||
int startY = (tileArea.y < 0) ? 0 : tileArea.y;
|
||||
int endX = (tileArea.getMaxX() > width) ? width : (int)tileArea.getMaxX();
|
||||
int endY = (tileArea.getMaxY() > height) ? height : (int)tileArea.getMaxY();
|
||||
double scaleX = level.getTileSizeX() / tileArea.width;
|
||||
double scaleY = level.getTileSizeY() / tileArea.height;
|
||||
graphics.drawImage(o2img,
|
||||
startX, startY, endX, endY,
|
||||
(int)(Math.abs(tileArea.x - startX) * scaleX),
|
||||
(int)(Math.abs(tileArea.y - startY) * scaleY),
|
||||
(int)(Math.abs(tileArea.x - endX) * scaleX),
|
||||
(int)(Math.abs(tileArea.y - endY) * scaleY),
|
||||
null);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public static GridCoverage2D getCoverage(O2LayerLevelSet levelSet, ReferencedEnvelope bbox, int width, int height) throws Exception {
|
||||
WritableRaster raster =
|
||||
RasterFactory.createBandedRaster(4, width, height, 1, new Point(0, 0));
|
||||
Float noData = levelSet.getNoData();
|
||||
if (noData == null)
|
||||
noData = Float.valueOf(Float.NaN);
|
||||
for (int c = 0; c < width; c++) {
|
||||
for (int r = 0; r < height; r++)
|
||||
raster.setSample(c, r, 0, noData.floatValue());
|
||||
}
|
||||
Envelope targetBBox = bbox.intersection(levelSet.getBBox());
|
||||
if (targetBBox == null || targetBBox.isNull())
|
||||
return gcFactory.create("DEM", raster, (Envelope)bbox);
|
||||
double resX = bbox.getWidth() / width;
|
||||
double resY = bbox.getHeight() / height;
|
||||
double res = Math.max(resX, resY);
|
||||
O2LayerLevel level = levelSet.getLevelByResolution(res);
|
||||
ArrayList<O2LayerIndex> idxs = calBlockIndex(level, (Envelope)bbox);
|
||||
for (O2LayerIndex idx : idxs) {
|
||||
float[][] o2dem = getO2Dem(
|
||||
level.getLevelPath(), idx.getBlockIndex(), idx.getFilePosition(),
|
||||
level.getTileSizeX() + 1, level.getTileSizeY() + 1,
|
||||
levelSet.getMinData(), levelSet.getMaxData(), noData);
|
||||
Rectangle tileArea = ServerUtil.calPaintArea(new Rectangle(width, height), (Envelope)bbox, idx.getBBox());
|
||||
int startX = (tileArea.x < 0) ? 0 : tileArea.x;
|
||||
int startY = (tileArea.y < 0) ? 0 : tileArea.y;
|
||||
int endX = (tileArea.getMaxX() > width) ? width : (int)tileArea.getMaxX();
|
||||
int endY = (tileArea.getMaxY() > height) ? height : (int)tileArea.getMaxY();
|
||||
double scaleX = (level.getTileSizeX() + 1) / tileArea.width;
|
||||
double scaleY = (level.getTileSizeY() + 1) / tileArea.height;
|
||||
for (int row = startY; row < endY; row++) {
|
||||
for (int col = startX; col < endX; col++) {
|
||||
int getRow = (int)(Math.abs(tileArea.y - row) * scaleY);
|
||||
int getCol = (int)(Math.abs(tileArea.x - col) * scaleX);
|
||||
int size = 1;
|
||||
float avr = o2dem[getRow][getCol];
|
||||
if (getRow - 1 >= 0) {
|
||||
avr += o2dem[getRow - 1][getCol];
|
||||
size++;
|
||||
}
|
||||
if (getRow + 1 < level.getTileSizeY() + 1) {
|
||||
avr += o2dem[getRow + 1][getCol];
|
||||
size++;
|
||||
}
|
||||
if (getCol - 1 >= 0) {
|
||||
avr += o2dem[getRow][getCol - 1];
|
||||
size++;
|
||||
}
|
||||
if (getCol + 1 < level.getTileSizeX() + 1) {
|
||||
avr += o2dem[getRow][getCol + 1];
|
||||
size++;
|
||||
}
|
||||
raster.setSample(col, row, 0, avr / size);
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Object> propMap = new HashMap<String, Object>();
|
||||
propMap.put("GC_MINVALUE", levelSet.getMinData());
|
||||
propMap.put("GC_MAXVALUE", levelSet.getMaxData());
|
||||
propMap.put("GC_NODATA", levelSet.getNoData());
|
||||
GridSampleDimension[] bands = new GridSampleDimension[raster.getNumBands()];
|
||||
ColorModel model = bands[0].getColorModel(0, bands.length, raster.getSampleModel().getDataType());
|
||||
RenderedImage image = new BufferedImage(model, raster, false, null);
|
||||
return (new GridCoverageFactory()).create("DEM", image, (Envelope)bbox, null, null, propMap);
|
||||
}
|
||||
|
||||
public static ArrayList<O2LayerIndex> calBlockIndex(O2LayerLevel level, Envelope cBBox) throws Exception {
|
||||
ArrayList<O2LayerIndex> result = new ArrayList<O2LayerIndex>();
|
||||
Envelope pBBox = level.getBBox();
|
||||
double width = level.getTileSizeX() * level.getResolutionX();
|
||||
double height = level.getTileSizeY() * level.getResolutionY();
|
||||
int nROffX = (int)((cBBox.getMinX() - pBBox.getMinX()) / level.getResolutionX());
|
||||
int nROffY = (int)((pBBox.getMaxY() - cBBox.getMaxY()) / level.getResolutionY());
|
||||
int nRWidth = (int)((cBBox.getMaxX() - pBBox.getMinX()) / level.getResolutionX()) - nROffX + 1;
|
||||
int nRHeight = (int)((pBBox.getMaxY() - cBBox.getMinY()) / level.getResolutionY()) - nROffY + 1;
|
||||
int sCol = nROffX / level.getTileSizeX();
|
||||
int eCol = (nROffX + nRWidth) / level.getTileSizeX();
|
||||
int sRow = nROffY / level.getTileSizeY();
|
||||
int eRow = (nROffY + nRHeight) / level.getTileSizeY();
|
||||
sCol = (sCol < 0) ? 0 : sCol;
|
||||
eCol = (level.getTileCountX() <= eCol) ? (level.getTileCountX() - 1) : eCol;
|
||||
sRow = (sRow < 0) ? 0 : sRow;
|
||||
eRow = (level.getTileCountY() <= eRow) ? (level.getTileCountY() - 1) : eRow;
|
||||
RandomAccessFile raf = null;
|
||||
FileChannel channel = null;
|
||||
try {
|
||||
File idxFile = new File(level.getLevelPath(), "/index.o2img");
|
||||
raf = new RandomAccessFile(idxFile, "r");
|
||||
channel = raf.getChannel();
|
||||
for (int r = sRow; r <= eRow; r++) {
|
||||
for (int c = sCol; c <= eCol; c++) {
|
||||
Envelope bbox = new Envelope(
|
||||
pBBox.getMinX() + width * c,
|
||||
pBBox.getMinX() + width * (c + 1),
|
||||
pBBox.getMaxY() - height * (r + 1),
|
||||
pBBox.getMaxY() - height * r);
|
||||
O2LayerIndex idx = new O2LayerIndex(bbox, r, c);
|
||||
channel.position((144 + (
|
||||
level.getTileCountX() * r + c) * 20));
|
||||
idx.setBlockIndex(readInt(channel));
|
||||
idx.setFilePosition(readInt(channel));
|
||||
result.add(idx);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (channel != null && channel.isOpen())
|
||||
try {
|
||||
channel.close();
|
||||
} catch (IOException iOException) {}
|
||||
if (raf != null)
|
||||
try {
|
||||
raf.close();
|
||||
} catch (IOException iOException) {}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,81 @@
|
|||
package com.geotwo.webserver.core.feature;
|
||||
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import com.geotwo.webserver.core.map.layer.FeatureLayer;
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.vector.O2DSMngr;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
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.referencing.FactoryException;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
public class GeometryMngr {
|
||||
public enum GeomType {
|
||||
POINT, LINE, POLYGON;
|
||||
}
|
||||
|
||||
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((Envelope)base);
|
||||
return merge;
|
||||
}
|
||||
if (crsMerge == null) {
|
||||
base.expandToInclude((Envelope)merge);
|
||||
return base;
|
||||
}
|
||||
if (!CRS.equalsIgnoreMetadata(crsBase, crsMerge))
|
||||
merge = merge.transform(crsBase, true);
|
||||
base.expandToInclude((Envelope)merge);
|
||||
return base;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.geotwo.webserver.core.feature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.opengis.filter.identity.FeatureId;
|
||||
|
||||
class InsertParams {
|
||||
public String sqlString;
|
||||
|
||||
public Double maxValue;
|
||||
|
||||
public ArrayList<FeatureId> featureIDs = new ArrayList<FeatureId>();
|
||||
|
||||
public InsertParams(String sql, Double max) {
|
||||
this.sqlString = sql;
|
||||
this.maxValue = max;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,175 @@
|
|||
package com.geotwo.webserver.core.feature;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
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.Feature;
|
||||
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(this.featureType);
|
||||
if (att == null)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public FeatureReader<SimpleFeatureType, SimpleFeature> reader() throws IOException {
|
||||
return (FeatureReader<SimpleFeatureType, SimpleFeature>)new DelegateFeatureReader((FeatureType)getSchema(), (FeatureIterator)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, getSchema(), isRetype(), isInitNullValue());
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
Iterator<? extends Property> valueItr = feature.getValue().iterator();
|
||||
while (valueItr.hasNext()) {
|
||||
Property property = valueItr.next();
|
||||
if (property.getValue() == null)
|
||||
property.setValue("");
|
||||
}
|
||||
}
|
||||
if (!this.retyping)
|
||||
return feature;
|
||||
try {
|
||||
String fid = feature.getID();
|
||||
this.types = O2FeatureCollection.this.typeAttributes(this.source, this.target);
|
||||
for (int i = 0; i < this.types.length; i++) {
|
||||
String xpath = this.types[i].getLocalName();
|
||||
this.builder.add(feature.getAttribute(xpath));
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
protected AttributeDescriptor[] typeAttributes(SimpleFeatureType original, SimpleFeatureType target) {
|
||||
if (target.equals(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()];
|
||||
for (int i = 0; i < target.getAttributeCount(); i++) {
|
||||
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 + ")");
|
||||
}
|
||||
return types;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
package com.geotwo.webserver.core.feature;
|
||||
|
||||
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.FeatureType;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.FilterFactory2;
|
||||
import org.opengis.filter.FilterVisitor;
|
||||
import org.opengis.filter.Id;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
import org.opengis.filter.expression.PropertyName;
|
||||
import org.opengis.filter.identity.Identifier;
|
||||
import org.opengis.geometry.BoundingBox;
|
||||
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 = (Configuration)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, (FeatureType)schema);
|
||||
return (Filter)filter.accept((FilterVisitor)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((FilterVisitor)fVisitor, null);
|
||||
}
|
||||
|
||||
private static Filter changeFIDFilter(final SimpleFeatureType schema, Filter filter) {
|
||||
DuplicatingFilterVisitor fVisitor = new DuplicatingFilterVisitor() {
|
||||
public Object visit(Id filter, Object extraData) {
|
||||
Set<Identifier> fIDs = new HashSet<Identifier>();
|
||||
for (Identifier fid : filter.getIdentifiers()) {
|
||||
String str = fid.toString();
|
||||
if (str.contains(".")) {
|
||||
String pkStringVlaue = str.substring(str.indexOf(".") + 1);
|
||||
str = String.valueOf(schema.getTypeName()) + "." + pkStringVlaue;
|
||||
}
|
||||
fIDs.add(getFactory(extraData).featureId(str));
|
||||
}
|
||||
return getFactory(extraData).id(fIDs);
|
||||
}
|
||||
};
|
||||
return (Filter)filter.accept((FilterVisitor)fVisitor, null);
|
||||
}
|
||||
|
||||
private static Filter extractBBoxFilter(SimpleFeatureType schema, Filter filter) {
|
||||
Envelope bounds = (Envelope)filter.accept((FilterVisitor)ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
|
||||
if (bounds == null || bounds.isNull())
|
||||
return null;
|
||||
if (bounds.getMinX() == Double.NEGATIVE_INFINITY &&
|
||||
bounds.getMaxX() == Double.POSITIVE_INFINITY &&
|
||||
bounds.getMinY() == Double.NEGATIVE_INFINITY &&
|
||||
bounds.getMaxY() == Double.POSITIVE_INFINITY)
|
||||
return null;
|
||||
ReferencedEnvelope envelop = ReferencedEnvelope.reference(bounds);
|
||||
String geomField = schema.getGeometryDescriptor().getLocalName();
|
||||
return (Filter)filterFactory.bbox((Expression)filterFactory.property(geomField), (BoundingBox)envelop);
|
||||
}
|
||||
|
||||
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<String> propertys = new ArrayList<String>();
|
||||
String geom = schema.getGeometryDescriptor().getLocalName();
|
||||
boolean isContain = false;
|
||||
byte b;
|
||||
int i;
|
||||
String[] arrayOfString;
|
||||
for (i = (arrayOfString = query.getPropertyNames()).length, b = 0; b < i; ) {
|
||||
String pName = arrayOfString[b];
|
||||
pName = pName.trim().toUpperCase();
|
||||
if (pName.equals(geom)) {
|
||||
propertys.add(pName);
|
||||
isContain = true;
|
||||
} else if (schema.getDescriptor(pName) != null) {
|
||||
propertys.add(pName);
|
||||
}
|
||||
b++;
|
||||
}
|
||||
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,167 @@
|
|||
package com.geotwo.webserver.core.feature;
|
||||
|
||||
import com.geotwo.webserver.core.vector.jdbc.oracle.OracleDialect;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import java.io.IOException;
|
||||
import java.util.NoSuchElementException;
|
||||
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.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.geotools.geometry.jts.JTS;
|
||||
import org.geotools.jdbc.JDBCFeatureStore;
|
||||
import org.geotools.jdbc.PrimaryKeyColumn;
|
||||
import org.geotools.referencing.CRS;
|
||||
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.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;
|
||||
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((ExpressionVisitor)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 (FeatureReader<SimpleFeatureType, SimpleFeature>)new DelegateFeatureReader((FeatureType)getSchema(), (FeatureIterator)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,106 @@
|
|||
package com.geotwo.webserver.core.init;
|
||||
|
||||
import com.geotwo.webserver.core.init.conn.ConnAltibase;
|
||||
import com.geotwo.webserver.core.init.conn.ConnJDBC;
|
||||
import com.geotwo.webserver.core.init.conn.ConnKairos;
|
||||
import com.geotwo.webserver.core.init.conn.ConnMySQL;
|
||||
import com.geotwo.webserver.core.init.conn.ConnOracle;
|
||||
import com.geotwo.webserver.core.init.conn.ConnPostGIS;
|
||||
import com.geotwo.webserver.core.init.conn.ConnTibero;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.vector.jdbc.O2DSFactory;
|
||||
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("altibase"))
|
||||
return (ConnJDBC)new ConnAltibase();
|
||||
if (dbType != null && dbType.toLowerCase().equals("oracle"))
|
||||
return (ConnJDBC)new ConnOracle();
|
||||
if (dbType != null && dbType.toLowerCase().equals("mysql"))
|
||||
return (ConnJDBC)new ConnMySQL();
|
||||
if (dbType != null && dbType.toLowerCase().equals("postgis"))
|
||||
return (ConnJDBC)new ConnPostGIS();
|
||||
if (dbType != null && dbType.toLowerCase().equals("tibero"))
|
||||
return (ConnJDBC)new ConnTibero();
|
||||
if (dbType != null && dbType.toLowerCase().equals("kairos"))
|
||||
return (ConnJDBC)new ConnKairos();
|
||||
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.ALTIBASE)
|
||||
return (ConnJDBC)new ConnAltibase();
|
||||
if (dbType != null && dbType == O2DSFactory.DBMSType.ORACLE)
|
||||
return (ConnJDBC)new ConnOracle();
|
||||
if (dbType != null && dbType == O2DSFactory.DBMSType.MYSQL)
|
||||
return (ConnJDBC)new ConnMySQL();
|
||||
if (dbType != null && dbType == O2DSFactory.DBMSType.POSTGIS)
|
||||
return (ConnJDBC)new ConnPostGIS();
|
||||
if (dbType != null && dbType == O2DSFactory.DBMSType.TIBERO)
|
||||
return (ConnJDBC)new ConnTibero();
|
||||
if (dbType != null && dbType == O2DSFactory.DBMSType.KAIROS)
|
||||
return (ConnJDBC)new ConnKairos();
|
||||
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<String, Object> map = ServerConfiguration.getInstance().getConfMap();
|
||||
String dbType = (String)map.get("conf.xml.map.dbtype");
|
||||
dbType = dbType.trim();
|
||||
if (dbType != null && dbType.toLowerCase().equals("altibase")) {
|
||||
this.connJDBC = (ConnJDBC)new ConnAltibase();
|
||||
} else if (dbType != null && dbType.toLowerCase().equals("oracle")) {
|
||||
this.connJDBC = (ConnJDBC)new ConnOracle();
|
||||
} else if (dbType != null && dbType.toLowerCase().equals("mysql")) {
|
||||
this.connJDBC = (ConnJDBC)new ConnMySQL();
|
||||
} else if (dbType != null && dbType.toLowerCase().equals("postgis")) {
|
||||
this.connJDBC = (ConnJDBC)new ConnPostGIS();
|
||||
} else if (dbType != null && dbType.toLowerCase().equals("tibero")) {
|
||||
this.connJDBC = (ConnJDBC)new ConnTibero();
|
||||
} else if (dbType != null && dbType.toLowerCase().equals("kairos")) {
|
||||
this.connJDBC = (ConnJDBC)new ConnKairos();
|
||||
} 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 sQLException) {}
|
||||
}
|
||||
|
||||
public void closeSafe(ResultSet rs) {
|
||||
if (rs == null)
|
||||
return;
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException sQLException) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,418 @@
|
|||
package com.geotwo.webserver.core.init;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.cache.LogCacheManager;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.render.RenderMngr;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.O2DSMngr;
|
||||
|
||||
public class ServerConfiguration {
|
||||
private static ServerConfiguration instance = null;
|
||||
private HashMap<String, Object> confMap = null;
|
||||
|
||||
private ServerConfiguration() {
|
||||
}
|
||||
|
||||
public static ServerConfiguration getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ServerConfiguration();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean startServer() {
|
||||
try {
|
||||
System.out.println("******************************");
|
||||
System.out.println("Load server_conf.xml");
|
||||
System.out.println("******************************");
|
||||
this.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("[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() {
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.geotwo.webserver.core.init.conn;
|
||||
|
||||
import com.geotwo.webserver.core.init.conn.util.FieldSQL;
|
||||
import com.geotwo.webserver.core.vector.jdbc.O2DSFactory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnAltibase extends ConnJDBC {
|
||||
public String getDriverClassName() {
|
||||
return "Altibase.jdbc.driver.AltibaseDriver";
|
||||
}
|
||||
|
||||
public String getJDBCUrl(String host, Integer port, String database) {
|
||||
String sURL = "jdbc:Altibase://";
|
||||
sURL = String.valueOf(sURL) + host + ":" + port + "/" + database;
|
||||
return sURL;
|
||||
}
|
||||
|
||||
public FieldSQL getFieldSQL() {
|
||||
HashMap<FieldSQL.FieldType, String> fields = new HashMap<FieldSQL.FieldType, String>();
|
||||
fields.put(FieldSQL.FieldType.GEOMETRY, "GEOMETRY");
|
||||
fields.put(FieldSQL.FieldType.CHARACTER, "VARCHAR");
|
||||
fields.put(FieldSQL.FieldType.NUMERIC, "NUMERIC");
|
||||
fields.put(FieldSQL.FieldType.BOOLEAN, "SMALLINT");
|
||||
fields.put(FieldSQL.FieldType.DATE, "DATE");
|
||||
fields.put(FieldSQL.FieldType.BLOB, "BLOB");
|
||||
fields.put(FieldSQL.FieldType.UNKNOWN, "VARCHAR(100)");
|
||||
return new FieldSQL(O2DSFactory.DBMSType.ALTIBASE, fields, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package com.geotwo.webserver.core.init.conn;
|
||||
|
||||
import com.geotwo.webserver.core.init.ServerConfiguration;
|
||||
import com.geotwo.webserver.core.init.conn.util.FieldSQL;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
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<String, Object> map = ServerConfiguration.getInstance().getConfMap();
|
||||
String sURL = getJDBCUrl();
|
||||
String user = (String)map.get("conf.xml.map.user");
|
||||
String passwd = (String)map.get("conf.xml.map.passwd");
|
||||
try {
|
||||
Class.forName(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<String, Object> 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 getJDBCUrl(host, Integer.valueOf(port), database);
|
||||
}
|
||||
|
||||
public abstract String getDriverClassName();
|
||||
|
||||
public abstract String getJDBCUrl(String paramString1, Integer paramInteger, String paramString2);
|
||||
|
||||
public abstract FieldSQL getFieldSQL();
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.geotwo.webserver.core.init.conn;
|
||||
|
||||
import com.geotwo.webserver.core.init.conn.util.FieldSQL;
|
||||
import com.geotwo.webserver.core.vector.jdbc.O2DSFactory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnKairos extends ConnJDBC {
|
||||
public String getDriverClassName() {
|
||||
return "kr.co.realtimetech.kairos.jdbc.kairosDriver";
|
||||
}
|
||||
|
||||
public String getJDBCUrl(String host, Integer port, String database) {
|
||||
String sURL = "jdbc:kairos://";
|
||||
sURL = String.valueOf(sURL) + host + ":" + port + "/" + database;
|
||||
return sURL;
|
||||
}
|
||||
|
||||
public FieldSQL getFieldSQL() {
|
||||
HashMap<FieldSQL.FieldType, String> fields = new HashMap<FieldSQL.FieldType, String>();
|
||||
fields.put(FieldSQL.FieldType.GEOMETRY, "GEOMETRY");
|
||||
fields.put(FieldSQL.FieldType.NUMERIC, "NUMERIC");
|
||||
fields.put(FieldSQL.FieldType.BOOLEAN, "TINYINT");
|
||||
fields.put(FieldSQL.FieldType.DATE, "DATE");
|
||||
fields.put(FieldSQL.FieldType.BLOB, "BLOB");
|
||||
fields.put(FieldSQL.FieldType.UNKNOWN, "VARCHAR(100)");
|
||||
return new FieldSQL(O2DSFactory.DBMSType.KAIROS, fields, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.geotwo.webserver.core.init.conn;
|
||||
|
||||
import com.geotwo.webserver.core.init.conn.util.FieldSQL;
|
||||
import com.geotwo.webserver.core.vector.jdbc.O2DSFactory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnMySQL extends ConnJDBC {
|
||||
public String getDriverClassName() {
|
||||
return "com.mysql.jdbc.Driver";
|
||||
}
|
||||
|
||||
public String getJDBCUrl(String host, Integer port, String database) {
|
||||
String sURL = "jdbc:mysql://";
|
||||
sURL = String.valueOf(sURL) + host + ":" + port + "/" + database;
|
||||
return sURL;
|
||||
}
|
||||
|
||||
public FieldSQL getFieldSQL() {
|
||||
HashMap<FieldSQL.FieldType, String> fields = new HashMap<FieldSQL.FieldType, String>();
|
||||
fields.put(FieldSQL.FieldType.GEOMETRY, "GEOMETRY");
|
||||
fields.put(FieldSQL.FieldType.CHARACTER, "VARCHAR");
|
||||
fields.put(FieldSQL.FieldType.NUMERIC, "NUMERIC");
|
||||
fields.put(FieldSQL.FieldType.BOOLEAN, "TINYINT");
|
||||
fields.put(FieldSQL.FieldType.DATE, "DATE");
|
||||
fields.put(FieldSQL.FieldType.BLOB, "BLOB");
|
||||
fields.put(FieldSQL.FieldType.UNKNOWN, "VARCHAR(100)");
|
||||
return new FieldSQL(O2DSFactory.DBMSType.MYSQL, fields, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.geotwo.webserver.core.init.conn;
|
||||
|
||||
import com.geotwo.webserver.core.init.conn.util.FieldSQL;
|
||||
import com.geotwo.webserver.core.vector.jdbc.O2DSFactory;
|
||||
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 = String.valueOf(sURL) + host + ":" + port + ":" + database;
|
||||
return sURL;
|
||||
}
|
||||
|
||||
public FieldSQL getFieldSQL() {
|
||||
HashMap<FieldSQL.FieldType, String> fields = new HashMap<FieldSQL.FieldType, String>();
|
||||
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,29 @@
|
|||
package com.geotwo.webserver.core.init.conn;
|
||||
|
||||
import com.geotwo.webserver.core.init.conn.util.FieldSQL;
|
||||
import com.geotwo.webserver.core.vector.jdbc.O2DSFactory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnPostGIS extends ConnJDBC {
|
||||
public String getDriverClassName() {
|
||||
return "org.postgresql.Driver";
|
||||
}
|
||||
|
||||
public String getJDBCUrl(String host, Integer port, String database) {
|
||||
String sURL = "jdbc:postgresql://";
|
||||
sURL = String.valueOf(sURL) + host + ":" + port + "/" + database;
|
||||
return sURL;
|
||||
}
|
||||
|
||||
public FieldSQL getFieldSQL() {
|
||||
HashMap<FieldSQL.FieldType, String> fields = new HashMap<FieldSQL.FieldType, String>();
|
||||
fields.put(FieldSQL.FieldType.GEOMETRY, "GEOMETRY");
|
||||
fields.put(FieldSQL.FieldType.CHARACTER, "VARCHAR");
|
||||
fields.put(FieldSQL.FieldType.NUMERIC, "NUMERIC");
|
||||
fields.put(FieldSQL.FieldType.BOOLEAN, "BOOLEAN");
|
||||
fields.put(FieldSQL.FieldType.DATE, "DATE");
|
||||
fields.put(FieldSQL.FieldType.BLOB, "BYTEA");
|
||||
fields.put(FieldSQL.FieldType.UNKNOWN, "VARCHAR(100)");
|
||||
return new FieldSQL(O2DSFactory.DBMSType.POSTGIS, fields, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.geotwo.webserver.core.init.conn;
|
||||
|
||||
import com.geotwo.webserver.core.init.conn.util.FieldSQL;
|
||||
import com.geotwo.webserver.core.vector.jdbc.O2DSFactory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnTibero extends ConnJDBC {
|
||||
public String getDriverClassName() {
|
||||
return "com.tmax.tibero.jdbc.TbDriver";
|
||||
}
|
||||
|
||||
public String getJDBCUrl(String host, Integer port, String database) {
|
||||
String sURL = "jdbc:tibero:thin:@";
|
||||
sURL = String.valueOf(sURL) + host + ":" + port + ":" + database;
|
||||
return sURL;
|
||||
}
|
||||
|
||||
public FieldSQL getFieldSQL() {
|
||||
HashMap<FieldSQL.FieldType, String> fields = new HashMap<FieldSQL.FieldType, String>();
|
||||
fields.put(FieldSQL.FieldType.GEOMETRY, "GEOMETRY");
|
||||
fields.put(FieldSQL.FieldType.CHARACTER, "VARCHAR");
|
||||
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, "VARCHAR(100)");
|
||||
return new FieldSQL(O2DSFactory.DBMSType.TIBERO, fields, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package com.geotwo.webserver.core.init.conn.util;
|
||||
|
||||
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,127 @@
|
|||
package com.geotwo.webserver.core.init.conn.util;
|
||||
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.vector.jdbc.O2DSFactory;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
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 enum FieldType {
|
||||
GEOMETRY("GEOMETRY", new Class[] { Geometry.class, 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[] { Byte[].class }),
|
||||
UNKNOWN("VARCHAR", new Class[] { Object.class });
|
||||
|
||||
private final Class[] fieldTypes;
|
||||
|
||||
private final String fieldSql;
|
||||
|
||||
FieldType(String sql, Class... types) {
|
||||
this.fieldSql = sql;
|
||||
this.fieldTypes = types;
|
||||
}
|
||||
}
|
||||
|
||||
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 = 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;
|
||||
byte b;
|
||||
int i;
|
||||
FieldType[] arrayOfFieldType;
|
||||
for (i = (arrayOfFieldType = FieldType.values()).length, b = 0; b < i; ) {
|
||||
FieldType value = arrayOfFieldType[b];
|
||||
byte b1;
|
||||
int j;
|
||||
Class[] arrayOfClass;
|
||||
for (j = (arrayOfClass = value.fieldTypes).length, b1 = 0; b1 < j; ) {
|
||||
Class cls = arrayOfClass[b1];
|
||||
if (cls.isAssignableFrom(clazz))
|
||||
return getFieldType(value, precision, scale);
|
||||
b1++;
|
||||
}
|
||||
b++;
|
||||
}
|
||||
return getFieldType(type, precision, scale);
|
||||
}
|
||||
|
||||
public String getFieldType(FieldType fType, int precision, int scale) throws Exception {
|
||||
String sql = 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
package com.geotwo.webserver.core.log;
|
||||
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
|
||||
public class LogMngr {
|
||||
public static final String LOG_TYPE_CONFIG = "[CONFIG]";
|
||||
|
||||
public static final String LOG_TYPE_LICENSE = "[LICENSE]";
|
||||
|
||||
public static final String LOG_TYPE_DB = "[DB]";
|
||||
|
||||
public static final String LOG_TYPE_SERVER = "[SERVER]";
|
||||
|
||||
public static final String LOG_TYPE_MAP = "[MAP]";
|
||||
|
||||
public static final String LOG_TYPE_LAYER = "[LAYER]";
|
||||
|
||||
public static final String LOG_TYPE_JDBC = "[JDBC]";
|
||||
|
||||
public static final String LOG_TYPE_SHP = "[SHAPE]";
|
||||
|
||||
public static final String LOG_TYPE_GML = "[GML]";
|
||||
|
||||
public static final String LOG_TYPE_GWAVE = "[GWAVE]";
|
||||
|
||||
public static final String LOG_TYPE_WMTS = "[WMTS]";
|
||||
|
||||
public static final String LOG_TYPE_TMS = "[TMS]";
|
||||
|
||||
public static final String LOG_TYPE_O2WPS = "[O2WPS]";
|
||||
|
||||
public static final String LOG_TYPE_IMGCACHE = "[IMGCACHE]";
|
||||
|
||||
public static final String LOG_TYPE_O2IMG = "[O2IMG]";
|
||||
|
||||
public static final String LOG_TYPE_O2DEM = "[O2DEM]";
|
||||
|
||||
public static final String LOG_TYPE_O2INFO = "[O2INFO]";
|
||||
|
||||
public static final String LOG_TYPE_O2INDEX = "[O2INDEX]";
|
||||
|
||||
public static final String LOG_TYPE_SERVICE = "[SERVICE]";
|
||||
|
||||
public static final String LOG_TYPE_REQUEST = "[REQUEST]";
|
||||
|
||||
public static final String LOG_TYPE_RESPONSE = "[RESPONSE]";
|
||||
|
||||
public static final String LOG_TYPE_FILE = "[FILE]";
|
||||
|
||||
public static final String LOG_TYPE_CACHE = "[CACHE]";
|
||||
|
||||
public static final String LOG_TYPE_FEATURE = "[FEATURE]";
|
||||
|
||||
public static final String LOG_TYPE_RENDER = "[RENDER]";
|
||||
|
||||
public static final String LOG_TYPE_STYLE = "[STYLE]";
|
||||
|
||||
public static final String LOG_TYPE_CRS = "[CRS]";
|
||||
|
||||
private static LogMngr instance = null;
|
||||
|
||||
private File logDir = null;
|
||||
|
||||
private Level logLevel = null;
|
||||
|
||||
private Level reqLevel = null;
|
||||
|
||||
private Logger logger = null;
|
||||
|
||||
private Logger loggerRequest = null;
|
||||
|
||||
private LogMngr() {
|
||||
initLog(null);
|
||||
}
|
||||
|
||||
public static LogMngr getInstance() {
|
||||
if (instance == null)
|
||||
instance = new LogMngr();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void initLog(HashMap<String, Object> map) {
|
||||
this.logDir = null;
|
||||
if (map == null) {
|
||||
System.out.println("*********************************");
|
||||
System.out.println("Init LogMngr");
|
||||
System.out.println("*********************************");
|
||||
map = new HashMap<String, Object>();
|
||||
} else {
|
||||
System.out.println("*********************************");
|
||||
System.out.println("Setup logging option for LogMngr");
|
||||
System.out.println("*********************************");
|
||||
}
|
||||
String lValue = (String)map.get("conf.xml.log.level");
|
||||
if (ServerUtil.isNullString(lValue)) {
|
||||
this.logLevel = Level.INFO;
|
||||
System.out.println("- Log level value is null. Setup Logging basic [IFNO] level.");
|
||||
} else {
|
||||
lValue = lValue.trim().toUpperCase();
|
||||
if (lValue.equalsIgnoreCase("DEBUG")) {
|
||||
this.logLevel = Level.DEBUG;
|
||||
System.out.println("- Now Logging DEBUG level.");
|
||||
} else if (lValue.equalsIgnoreCase("INFO")) {
|
||||
this.logLevel = Level.INFO;
|
||||
System.out.println("- Now Logging INFO level.");
|
||||
} else if (lValue.equalsIgnoreCase("ERROR")) {
|
||||
this.logLevel = Level.ERROR;
|
||||
System.out.println("- Now Logging ERROR level.");
|
||||
} else if (lValue.equalsIgnoreCase("FATAL")) {
|
||||
this.logLevel = Level.FATAL;
|
||||
System.out.println("- Now Logging FATAL level.");
|
||||
} else {
|
||||
this.logLevel = Level.INFO;
|
||||
System.out.println("- Now Logging basic [IFNO] level.");
|
||||
}
|
||||
}
|
||||
String rValue = (String)map.get("conf.xml.log.request");
|
||||
if (ServerUtil.getBooleanValue(rValue)) {
|
||||
this.reqLevel = Level.INFO;
|
||||
System.out.println("- Request log level value is TRUE.");
|
||||
} else {
|
||||
this.reqLevel = Level.ERROR;
|
||||
System.out.println("- Request log level value is FALSE.");
|
||||
}
|
||||
String dValue = (String)map.get("conf.xml.log.dir");
|
||||
if (ServerUtil.isNullString(dValue)) {
|
||||
this.logDir = null;
|
||||
System.out.println("- Log file location[Directory name] is null. Now use only console logging.");
|
||||
} else {
|
||||
this.logDir = new File(dValue.trim());
|
||||
if (this.logDir.exists()) {
|
||||
if (this.logDir.isDirectory()) {
|
||||
this.logDir.setExecutable(true, false);
|
||||
this.logDir.setReadable(true);
|
||||
this.logDir.setWritable(true);
|
||||
System.out.println("- Log file location[" + this.logDir.getAbsolutePath() + "] is activate.");
|
||||
} else {
|
||||
System.out.println("- Log file location[" + this.logDir.getAbsolutePath() + "] is not Directory. Now use only console logging.");
|
||||
this.logDir = null;
|
||||
}
|
||||
} else if (this.logDir.mkdirs()) {
|
||||
this.logDir.setExecutable(true, false);
|
||||
this.logDir.setReadable(true);
|
||||
this.logDir.setWritable(true);
|
||||
System.out.println("- Log file location[" + this.logDir.getAbsolutePath() + "] is activate.");
|
||||
} else {
|
||||
System.out.println("- Log file location[" + this.logDir.getAbsolutePath() + "] is not available. Now use only console logging.");
|
||||
this.logDir = null;
|
||||
}
|
||||
}
|
||||
initLogger();
|
||||
}
|
||||
|
||||
private void initLogger() {
|
||||
Properties prop = new Properties();
|
||||
prop.setProperty("log4j.rootLogger", "OFF");
|
||||
prop.setProperty("log4j.logger.o2map.log", "INFO,stdout");
|
||||
prop.setProperty("log4j.logger.o2map.request", "INFO,stdout");
|
||||
prop.setProperty("log4j.appender.stdout", "org.apache.log4j.ConsoleAppender");
|
||||
prop.setProperty("log4j.appender.stdout.layout", "org.apache.log4j.PatternLayout");
|
||||
prop.setProperty("log4j.appender.stdout.layout.ConversionPattern", "%d{MMM dd HH:mm:ss} [%c{1}] > %p - %m%n");
|
||||
if (this.logDir != null) {
|
||||
prop.setProperty("log4j.appender.o2log", "org.apache.log4j.DailyRollingFileAppender");
|
||||
prop.setProperty("log4j.appender.o2log.File", String.valueOf(this.logDir.getAbsolutePath()) + "/" + "o2map.log");
|
||||
prop.setProperty("log4j.appender.o2log.Append", "true");
|
||||
prop.setProperty("log4j.appender.o2log.DatePattern", "'.'yyyy-MM-dd-HH");
|
||||
prop.setProperty("log4j.appender.o2log.layout", "org.apache.log4j.PatternLayout");
|
||||
prop.setProperty("log4j.appender.o2log.layout.ConversionPattern", "%d{MMM dd HH:mm:ss} > %p - %m%n");
|
||||
prop.setProperty("log4j.appender.request", "org.apache.log4j.DailyRollingFileAppender");
|
||||
prop.setProperty("log4j.appender.request.File", String.valueOf(this.logDir.getAbsolutePath()) + "/" + "o2map_request.log");
|
||||
prop.setProperty("log4j.appender.request.Append", "true");
|
||||
prop.setProperty("log4j.appender.request.DatePattern", "'.'yyyy-MM-dd-HH");
|
||||
prop.setProperty("log4j.appender.request.layout", "org.apache.log4j.PatternLayout");
|
||||
prop.setProperty("log4j.appender.request.layout.ConversionPattern", "%d{MMM dd HH:mm:ss} > %p - %m%n");
|
||||
prop.setProperty("log4j.logger.o2map.log", "INFO,stdout,o2log");
|
||||
if (this.reqLevel == Level.INFO)
|
||||
prop.setProperty("log4j.logger.o2map.request", "INFO,stdout,request");
|
||||
}
|
||||
PropertyConfigurator.configure(prop);
|
||||
this.logger = Logger.getLogger("o2map.log");
|
||||
this.loggerRequest = Logger.getLogger("o2map.request");
|
||||
this.logger.setLevel(this.logLevel);
|
||||
this.loggerRequest.setLevel(this.reqLevel);
|
||||
}
|
||||
|
||||
public void reqInfo(String logType, String message) {
|
||||
this.loggerRequest.info(String.valueOf(logType) + " " + message);
|
||||
}
|
||||
|
||||
public void logDebug(String logType, String message) {
|
||||
this.logger.debug(String.valueOf(logType) + " " + message);
|
||||
}
|
||||
|
||||
public void logInfo(String logType, String message) {
|
||||
this.logger.info(String.valueOf(logType) + " " + message);
|
||||
}
|
||||
|
||||
public void logWarn(String logType, String message) {
|
||||
this.logger.warn(String.valueOf(logType) + " " + message);
|
||||
}
|
||||
|
||||
public void logError(String logType, String message) {
|
||||
this.logger.error(String.valueOf(logType) + " " + message);
|
||||
}
|
||||
|
||||
public void logFatal(String logType, String message) {
|
||||
this.logger.fatal(String.valueOf(logType) + " " + message);
|
||||
}
|
||||
|
||||
public File getLogDirctory() {
|
||||
return this.logDir;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package com.geotwo.webserver.core.map;
|
||||
|
||||
import com.geotwo.webserver.core.map.layer.FeatureLayer;
|
||||
import com.geotwo.webserver.core.map.layer.GroupLayer;
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.map.layer.O2DemLayer;
|
||||
import com.geotwo.webserver.core.map.layer.O2ImgLayer;
|
||||
import com.geotwo.webserver.core.map.layer.WCSLayer;
|
||||
import com.geotwo.webserver.core.map.layer.WMSLayer;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
|
||||
public class LayerFactory {
|
||||
public enum LayerType {
|
||||
JDBC("VECTOR_JDBC", ".jdbc"),
|
||||
SHAPE("VECTOR_SHAPE", ".shape"),
|
||||
GEOWAVE("VECTOR_GEOWAVE", ".gwave"),
|
||||
GROUP("VECTOR_GROUP", ".group"),
|
||||
O2WPSVEC("VECTOR_O2WPS", ".o2wpsvec"),
|
||||
O2WPSCOV("COVERAGE_O2WPS", ".o2wpscov"),
|
||||
WMS("LINK_WMS", ".wms"),
|
||||
WCS("LINK_WCS", ".wcs"),
|
||||
O2IMG("RASTER_O2IMG", ".o2img"),
|
||||
O2DEM("RASTER_O2DEM", ".o2dem");
|
||||
|
||||
private String type;
|
||||
|
||||
private String pre;
|
||||
|
||||
LayerType(String type, String pre) {
|
||||
this.type = type;
|
||||
this.pre = pre;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.pre;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
package com.geotwo.webserver.core.map;
|
||||
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LayerSet {
|
||||
private final Map serviceMap;
|
||||
|
||||
private HashMap<String, Layer> layerStore = new HashMap<String, Layer>();
|
||||
|
||||
public LayerSet(Map map) {
|
||||
this.serviceMap = map;
|
||||
}
|
||||
|
||||
public void addLayer(Layer layer, boolean overWrite) throws Exception {
|
||||
if (layer == null || ServerUtil.isNullString(layer.getName()))
|
||||
throw new IllegalArgumentException("Layer object or Layer name is NULL.");
|
||||
if (!overWrite && this.layerStore.containsKey(layer.getName()))
|
||||
throw new IllegalArgumentException("Layer [" + layer.getName() + "] is already exist.");
|
||||
this.layerStore.put(layer.getName(), layer);
|
||||
}
|
||||
|
||||
public void addLayers(ArrayList<Layer> layers, boolean overWrite) throws Exception {
|
||||
if (layers == null)
|
||||
throw new IllegalArgumentException("Layers object is NULL.");
|
||||
for (Layer layer : layers) {
|
||||
if (!overWrite && this.layerStore.containsKey(layer.getName()))
|
||||
continue;
|
||||
this.layerStore.put(layer.getName(), layer);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExistLayer(String name) {
|
||||
if (ServerUtil.isNullString(name))
|
||||
return false;
|
||||
name = name.trim().toUpperCase();
|
||||
return this.layerStore.containsKey(name);
|
||||
}
|
||||
|
||||
public Layer getLayer(String name) throws Exception {
|
||||
if (ServerUtil.isNullString(name))
|
||||
throw new IllegalArgumentException("Layer Name [" + name + "] is NULL.");
|
||||
name = name.trim().toUpperCase();
|
||||
Layer layer = this.layerStore.get(name);
|
||||
if (layer == null)
|
||||
throw new NullPointerException("Layer [" + name + "] is not exist in ServiceMap [" + this.serviceMap.getName() + "]");
|
||||
return layer;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> getLayers() {
|
||||
return new ArrayList<Layer>(this.layerStore.values());
|
||||
}
|
||||
|
||||
public ArrayList<Layer> getLayers(LayerFactory.LayerType type) {
|
||||
ArrayList<Layer> layers = new ArrayList<Layer>();
|
||||
for (Layer layer : this.layerStore.values()) {
|
||||
if (layer.getLayerType() == type)
|
||||
layers.add(layer);
|
||||
}
|
||||
return layers;
|
||||
}
|
||||
|
||||
public void removeLayers() {
|
||||
this.layerStore.clear();
|
||||
}
|
||||
|
||||
public Layer removeLayer(String name) throws Exception {
|
||||
Layer layer = getLayer(name);
|
||||
this.layerStore.remove(layer.getName());
|
||||
return layer;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type) throws Exception {
|
||||
ArrayList<Layer> layers = getLayers(type);
|
||||
for (Layer layer : layers)
|
||||
this.layerStore.remove(layer.getName());
|
||||
return layers;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type, String serverName) throws Exception {
|
||||
if (ServerUtil.isNullString(serverName))
|
||||
throw new IllegalArgumentException("Server Name [" + serverName + "] is NULL.");
|
||||
serverName = serverName.trim();
|
||||
ArrayList<Layer> resultList = new ArrayList<Layer>();
|
||||
ArrayList<Layer> layers = getLayers(type);
|
||||
for (Layer layer : layers) {
|
||||
if (layer.getServerName().equalsIgnoreCase(serverName)) {
|
||||
this.layerStore.remove(layer.getName());
|
||||
resultList.add(layer);
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> removeLayer(LayerFactory.LayerType type, String serverName, String sourceName) throws Exception {
|
||||
if (ServerUtil.isNullString(serverName))
|
||||
throw new IllegalArgumentException("Server Name [" + serverName + "] is NULL.");
|
||||
serverName = serverName.trim();
|
||||
if (ServerUtil.isNullString(sourceName))
|
||||
throw new IllegalArgumentException("Source Name [" + sourceName + "] is NULL.");
|
||||
sourceName = sourceName.trim();
|
||||
ArrayList<Layer> resultList = new ArrayList<Layer>();
|
||||
ArrayList<Layer> layers = getLayers(type);
|
||||
for (Layer layer : layers) {
|
||||
if (layer.getServerName().equalsIgnoreCase(serverName) &&
|
||||
layer.getSourceName().equalsIgnoreCase(sourceName)) {
|
||||
this.layerStore.remove(layer.getName());
|
||||
resultList.add(layer);
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package com.geotwo.webserver.core.map;
|
||||
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.WpsVecStoreMngr;
|
||||
import com.geotwo.webserver.core.vector.o2wps.O2WpsLayerSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Map {
|
||||
private final String mapName;
|
||||
|
||||
private final String mapNameSpace;
|
||||
|
||||
private LayerSet serviceLayerSet;
|
||||
|
||||
private O2WpsLayerSet o2wpsLayerSet;
|
||||
|
||||
public Map(String name, String ns) throws Exception {
|
||||
if (ServerUtil.isNullString(name))
|
||||
throw new IllegalArgumentException("Map Name [" + name + "] is NULL.");
|
||||
this.mapName = name.trim().toUpperCase();
|
||||
if (!ServerUtil.isNullString(ns)) {
|
||||
ns = ns.trim();
|
||||
if (ns.equalsIgnoreCase("NULL") || ns.equalsIgnoreCase("DEFAULT")) {
|
||||
this.mapNameSpace = null;
|
||||
} else {
|
||||
this.mapNameSpace = ns;
|
||||
}
|
||||
} else {
|
||||
this.mapNameSpace = null;
|
||||
}
|
||||
this.serviceLayerSet = new LayerSet(this);
|
||||
this.o2wpsLayerSet = new O2WpsLayerSet(WpsVecStoreMngr.O2WpsMetaTableType.LAYERINFO_TBL.toString());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.mapName;
|
||||
}
|
||||
|
||||
public boolean useNameSpace() {
|
||||
if (ServerUtil.isNullString(this.mapNameSpace))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getNameSpace() {
|
||||
if (useNameSpace())
|
||||
return this.mapName.toLowerCase();
|
||||
return "sf";
|
||||
}
|
||||
|
||||
public String getNameSpaceURI() {
|
||||
if (useNameSpace())
|
||||
return this.mapNameSpace;
|
||||
return "http://cite.opengeospatial.org/gmlsf";
|
||||
}
|
||||
|
||||
public LayerSet getServiceLayerSet() {
|
||||
return this.serviceLayerSet;
|
||||
}
|
||||
|
||||
public O2WpsLayerSet getO2WpsLayerSet() {
|
||||
return this.o2wpsLayerSet;
|
||||
}
|
||||
|
||||
public ArrayList<Layer> getAllLayers() {
|
||||
ArrayList<Layer> layers = new ArrayList<Layer>();
|
||||
layers.addAll(this.serviceLayerSet.getLayers());
|
||||
layers.addAll(this.o2wpsLayerSet.getLayers());
|
||||
return layers;
|
||||
}
|
||||
|
||||
public Layer getLayer(String name) throws Exception {
|
||||
try {
|
||||
return this.serviceLayerSet.getLayer(name);
|
||||
} catch (Exception e) {
|
||||
Layer layer = this.o2wpsLayerSet.getLayer(name);
|
||||
if (layer != null)
|
||||
return layer;
|
||||
layer = this.o2wpsLayerSet.getLayer(WpsVecStoreMngr.O2WpsMetaTableType.STORELYRINFO_TBL.getName(), name);
|
||||
if (layer != null)
|
||||
return layer;
|
||||
layer = this.o2wpsLayerSet.getLayer(WpsVecStoreMngr.O2WpsMetaTableType.SHARELYRINFO_TBL.getName(), name);
|
||||
return layer;
|
||||
}
|
||||
}
|
||||
|
||||
public Layer getLayer(String storeTableName, String name) throws Exception {
|
||||
try {
|
||||
return this.o2wpsLayerSet.getLayer(storeTableName, name);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,357 @@
|
|||
package com.geotwo.webserver.core.map.layer;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.render.RefineRenderStyleVisitor;
|
||||
import com.geotwo.webserver.core.render.StyleMngr;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.O2DSMngr;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleVisitor;
|
||||
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 {
|
||||
private final String sourceName;
|
||||
|
||||
private ReferencedEnvelope bbox;
|
||||
|
||||
private ConcurrentHashMap<String, Style> styleStore = new ConcurrentHashMap<String, Style>();
|
||||
|
||||
private Style currentStyle;
|
||||
|
||||
private ConcurrentHashMap<String, Style> renderStyles = new ConcurrentHashMap<String, Style>();
|
||||
|
||||
public FeatureLayer(AVList params) throws Exception {
|
||||
super(params);
|
||||
try {
|
||||
String sVal = params.getStringValue("conf.service.ref.source");
|
||||
sVal = sVal.trim().toUpperCase();
|
||||
this.sourceName = sVal;
|
||||
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 styledLayerDescriptor = (StyledLayerDescriptor)params.getValue("conf.service.sld");
|
||||
initServiceStyle(styledLayerDescriptor, 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)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<String, Style> tempStore = new ConcurrentHashMap<String, Style>();
|
||||
Iterator<StyledLayer> iterLayer = sld.layers().iterator();
|
||||
while (iterLayer.hasNext()) {
|
||||
StyledLayer styledLayer = iterLayer.next();
|
||||
if (!ServerUtil.isNullString(styledLayer.getName()) &&
|
||||
!styledLayer.getName().equalsIgnoreCase(getName()))
|
||||
continue;
|
||||
Iterator<Style> iterStyle = getStyleIterator(styledLayer);
|
||||
while (iterStyle.hasNext()) {
|
||||
Style style = iterStyle.next();
|
||||
if (style instanceof org.geotools.styling.NamedStyle)
|
||||
continue;
|
||||
if (ServerUtil.isNullString(style.getName())) {
|
||||
style.setName(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()) {
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = style;
|
||||
continue;
|
||||
}
|
||||
defaultStyle.setDefault(false);
|
||||
defaultStyle = style;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (defaultStyle == null)
|
||||
if (getCurrentStyle() == null) {
|
||||
if (tempStore.isEmpty()) {
|
||||
defaultStyle = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
||||
} else {
|
||||
defaultStyle = tempStore.get(getName());
|
||||
if (defaultStyle == null)
|
||||
defaultStyle = tempStore.values().iterator().next();
|
||||
}
|
||||
} else {
|
||||
defaultStyle = tempStore.get(getCurrentStyle().getName());
|
||||
if (defaultStyle == null)
|
||||
defaultStyle = getCurrentStyle();
|
||||
}
|
||||
setCurrentStyle(defaultStyle);
|
||||
this.styleStore.putAll(tempStore);
|
||||
if (write)
|
||||
StyleMngr.writeServiceSLD110(getStyleSLD());
|
||||
}
|
||||
|
||||
public synchronized void initServiceStyle(StyledLayer styledLayer, boolean write) {
|
||||
Style defaultStyle = null;
|
||||
ConcurrentHashMap<String, Style> tempStore = new ConcurrentHashMap<String, Style>();
|
||||
if (!ServerUtil.isNullString(styledLayer.getName()) &&
|
||||
!styledLayer.getName().equalsIgnoreCase(getName()))
|
||||
return;
|
||||
Iterator<Style> iterStyle = getStyleIterator(styledLayer);
|
||||
while (iterStyle.hasNext()) {
|
||||
Style style = iterStyle.next();
|
||||
if (style instanceof org.geotools.styling.NamedStyle)
|
||||
continue;
|
||||
if (ServerUtil.isNullString(style.getName())) {
|
||||
style.setName(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()) {
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = style;
|
||||
continue;
|
||||
}
|
||||
defaultStyle.setDefault(false);
|
||||
defaultStyle = style;
|
||||
}
|
||||
}
|
||||
if (defaultStyle == null)
|
||||
if (getCurrentStyle() == null) {
|
||||
if (tempStore.isEmpty()) {
|
||||
defaultStyle = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
||||
} else {
|
||||
defaultStyle = tempStore.get(getName());
|
||||
if (defaultStyle == null)
|
||||
defaultStyle = tempStore.values().iterator().next();
|
||||
}
|
||||
} else {
|
||||
defaultStyle = tempStore.get(getCurrentStyle().getName());
|
||||
if (defaultStyle == null)
|
||||
defaultStyle = getCurrentStyle();
|
||||
}
|
||||
setCurrentStyle(defaultStyle);
|
||||
this.styleStore.putAll(tempStore);
|
||||
if (write)
|
||||
StyleMngr.writeServiceSLD110(getStyleSLD());
|
||||
}
|
||||
|
||||
public synchronized void initServiceStyle(Style style, boolean write) {
|
||||
if (style == null || style instanceof org.geotools.styling.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 this.renderStyles.get(styleName);
|
||||
Style style = getStyle(styleName);
|
||||
if (style == null)
|
||||
style = 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(styleName))
|
||||
return 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<Style> styles = new ArrayList<Style>();
|
||||
byte b;
|
||||
int i;
|
||||
String[] arrayOfString;
|
||||
for (i = (arrayOfString = styleNames).length, b = 0; b < i; ) {
|
||||
String styleName = arrayOfString[b];
|
||||
if (!ServerUtil.isNullString(styleName)) {
|
||||
styleName = styleName.trim().toUpperCase();
|
||||
if (this.styleStore.containsKey(styleName))
|
||||
styles.add(this.styleStore.get(styleName));
|
||||
}
|
||||
b++;
|
||||
}
|
||||
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
||||
layer.setName(getName());
|
||||
layer.styles().addAll(styles);
|
||||
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
||||
sld.addStyledLayer((StyledLayer)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((StyledLayer)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;
|
||||
this.currentStyle.setDefault(true);
|
||||
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 = this.styleStore.values().iterator().next();
|
||||
}
|
||||
setCurrentStyle(style);
|
||||
}
|
||||
if (write)
|
||||
StyleMngr.writeServiceSLD110(getStyleSLD());
|
||||
}
|
||||
|
||||
public void clearAllStyle(boolean write) {
|
||||
if (this.styleStore.isEmpty())
|
||||
return;
|
||||
this.styleStore.clear();
|
||||
this.renderStyles.clear();
|
||||
setCurrentStyle(StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName()));
|
||||
if (write)
|
||||
StyleMngr.writeServiceSLD110(getStyleSLD());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
package com.geotwo.webserver.core.map.layer;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.util.ArrayList;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
public class GroupLayer extends Layer {
|
||||
private ReferencedEnvelope bbox;
|
||||
|
||||
private String sourceName;
|
||||
|
||||
private ArrayList<FeatureLayer> layerList = new ArrayList<FeatureLayer>();
|
||||
|
||||
public GroupLayer(AVList params) throws Exception {
|
||||
super(params);
|
||||
try {
|
||||
this.sourceName = params.getStringValue("conf.service.ref.source");
|
||||
String[] layers = this.sourceName.split(",");
|
||||
ReferencedEnvelope layerBBox = null;
|
||||
for (int i = 0; i < layers.length; i++) {
|
||||
try {
|
||||
FeatureLayer layer = (FeatureLayer)ServerContext.getMap().getLayer(layers[i]);
|
||||
if (layerBBox == null) {
|
||||
layerBBox = layer.getBBox();
|
||||
} else {
|
||||
layerBBox.expandToInclude((Envelope)layer.getBBox());
|
||||
}
|
||||
this.layerList.add(i, layer);
|
||||
} catch (Exception e) {
|
||||
throw new NullPointerException("Layer [" + layers[i].trim() + "] is not exits.");
|
||||
}
|
||||
}
|
||||
this.bbox = layerBBox;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox() {
|
||||
return this.bbox;
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return super.getServerName().toUpperCase();
|
||||
}
|
||||
|
||||
public String getSourceName() {
|
||||
return this.sourceName;
|
||||
}
|
||||
|
||||
public ArrayList<FeatureLayer> getLayerList() {
|
||||
return this.layerList;
|
||||
}
|
||||
|
||||
public void updateCRS() {
|
||||
super.updateCRS();
|
||||
updateBBox();
|
||||
}
|
||||
|
||||
public void updateBBox() {
|
||||
try {
|
||||
ReferencedEnvelope layerBBox = null;
|
||||
for (int i = 0; i < this.layerList.size(); i++) {
|
||||
FeatureLayer layer = this.layerList.get(i);
|
||||
if (layerBBox == null) {
|
||||
layerBBox = layer.getBBox();
|
||||
} else {
|
||||
layerBBox.expandToInclude((Envelope)layer.getBBox());
|
||||
}
|
||||
}
|
||||
this.bbox = layerBBox;
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
package com.geotwo.webserver.core.map.layer;
|
||||
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.crs.CRSMngr;
|
||||
import java.util.Date;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
public abstract class Layer {
|
||||
private final LayerFactory.LayerType layerType;
|
||||
|
||||
private String mapName;
|
||||
|
||||
private String layerName;
|
||||
|
||||
private String serverName;
|
||||
|
||||
private CoordinateReferenceSystem layerCRS;
|
||||
|
||||
private Boolean layerUseCache;
|
||||
|
||||
private Date layerLastUpdate;
|
||||
|
||||
private String layerTitle;
|
||||
|
||||
private String layerAbstract;
|
||||
|
||||
private String autorID;
|
||||
|
||||
private String sourceType;
|
||||
|
||||
private String hashTag;
|
||||
|
||||
private String sourcPath;
|
||||
|
||||
protected Layer(AVList params) throws Exception {
|
||||
this.layerType = (LayerFactory.LayerType)params.getValue("conf.service.layer.type");
|
||||
if (this.layerType == null)
|
||||
throw new IllegalArgumentException("LayerType is NULL.");
|
||||
String sVal = params.getStringValue("conf.service.map.name");
|
||||
if (ServerUtil.isNullString(sVal))
|
||||
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");
|
||||
if (bVal == null) {
|
||||
this.layerUseCache = Boolean.valueOf(false);
|
||||
} else {
|
||||
this.layerUseCache = bVal;
|
||||
}
|
||||
Date dateVal = params.getDateValue("conf.service.last.update");
|
||||
if (dateVal == null) {
|
||||
this.layerLastUpdate = new Date();
|
||||
} else {
|
||||
this.layerLastUpdate = dateVal;
|
||||
}
|
||||
this.layerTitle = "O2Map Web Layer : " + this.layerName;
|
||||
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");
|
||||
if (ServerUtil.isNullString(sVal)) {
|
||||
this.sourcPath = "";
|
||||
} else {
|
||||
this.sourcPath = sVal.trim();
|
||||
}
|
||||
sVal = params.getStringValue("conf.service.o2wps.hashtag");
|
||||
if (ServerUtil.isNullString(sVal)) {
|
||||
this.hashTag = "";
|
||||
} else {
|
||||
this.hashTag = sVal.trim();
|
||||
}
|
||||
sVal = params.getStringValue("conf.service.o2wps.author.id");
|
||||
if (ServerUtil.isNullString(sVal)) {
|
||||
this.autorID = "Anonymous";
|
||||
} else {
|
||||
this.autorID = sVal.trim();
|
||||
}
|
||||
sVal = params.getStringValue("conf.service.o2wps.source.type");
|
||||
if (ServerUtil.isNullString(sVal)) {
|
||||
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();
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.geotwo.webserver.core.map.layer;
|
||||
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import java.net.URL;
|
||||
|
||||
public abstract class LinkLayer extends Layer {
|
||||
private URL serviceURL;
|
||||
|
||||
private String serviceLayerNames;
|
||||
|
||||
protected LinkLayer(AVList params) throws Exception {
|
||||
super(params);
|
||||
try {
|
||||
URL urlVal = params.getURLValue("conf.service.ref.server");
|
||||
this.serviceURL = urlVal;
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Remote Server URL is not available. :: " + e.getMessage());
|
||||
}
|
||||
String sVal = params.getStringValue("conf.service.ref.source");
|
||||
if (ServerUtil.isNullString(sVal))
|
||||
throw new Exception("Remote Service Layers value is NULL.");
|
||||
this.serviceLayerNames = sVal.trim();
|
||||
}
|
||||
|
||||
public String getSourceName() {
|
||||
return this.serviceLayerNames;
|
||||
}
|
||||
|
||||
public URL getServiceURL() {
|
||||
return this.serviceURL;
|
||||
}
|
||||
|
||||
public String getServiceLayerNames() {
|
||||
return this.serviceLayerNames;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
package com.geotwo.webserver.core.map.layer;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerLevelSet;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.render.ExtractRasterStyleVisitor;
|
||||
import com.geotwo.webserver.core.render.StyleMngr;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleVisitor;
|
||||
import org.geotools.styling.StyledLayer;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.StyledLayerDescriptorImpl;
|
||||
import org.geotools.styling.UserLayer;
|
||||
|
||||
public class O2DemLayer extends Layer {
|
||||
final O2LayerLevelSet levelSet;
|
||||
|
||||
private ConcurrentHashMap<String, Style> styleStore = new ConcurrentHashMap<String, Style>();
|
||||
|
||||
private Style currentStyle;
|
||||
|
||||
public O2DemLayer(AVList params) throws Exception {
|
||||
super(params);
|
||||
try {
|
||||
this.levelSet = (O2LayerLevelSet)params.getValue("o2layer.conf.level.set");
|
||||
if (this.levelSet == null || this.levelSet.size() == 0)
|
||||
throw new IOException("LevelSet has no level");
|
||||
} catch (Exception e) {
|
||||
throw new Exception("O2Layer levelset is not available. :: " + e);
|
||||
}
|
||||
Style style = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
||||
setCurrentStyle(style);
|
||||
LogMngr.getInstance().logDebug("[LAYER]",
|
||||
"Set Style Use Default :: [Map:" + ServerContext.getMap().getName() + "/Layer:" + getName() + "]");
|
||||
StyledLayerDescriptor sld = StyleMngr.readServiceSLD(getName());
|
||||
if (sld != null) {
|
||||
initServiceStyle(sld, false);
|
||||
LogMngr.getInstance().logDebug("[LAYER]",
|
||||
"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() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public O2LayerLevelSet getLevelSet() {
|
||||
return this.levelSet;
|
||||
}
|
||||
|
||||
public String getSourceName() {
|
||||
return this.levelSet.getRootPath().getAbsolutePath();
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox() {
|
||||
return new ReferencedEnvelope(this.levelSet.getBBox(), getCRS());
|
||||
}
|
||||
|
||||
public synchronized void initServiceStyle(StyledLayerDescriptor sld, boolean write) {
|
||||
Style defaultStyle = null;
|
||||
ConcurrentHashMap<String, Style> tempStore = new ConcurrentHashMap<String, Style>();
|
||||
ExtractRasterStyleVisitor sVisitor = new ExtractRasterStyleVisitor();
|
||||
sld.accept((StyleVisitor)sVisitor);
|
||||
StyledLayerDescriptorImpl styledLayerDescriptorImpl = (StyledLayerDescriptorImpl)sVisitor.getCopy();
|
||||
Iterator<StyledLayer> iterLayer = styledLayerDescriptorImpl.layers().iterator();
|
||||
while (iterLayer.hasNext()) {
|
||||
StyledLayer styledLayer = iterLayer.next();
|
||||
if (!ServerUtil.isNullString(styledLayer.getName()) &&
|
||||
!styledLayer.getName().equalsIgnoreCase(getName()))
|
||||
continue;
|
||||
Iterator<Style> iterStyle = getStyleIterator(styledLayer);
|
||||
while (iterStyle.hasNext()) {
|
||||
Style style = iterStyle.next();
|
||||
if (style instanceof org.geotools.styling.NamedStyle)
|
||||
continue;
|
||||
if (ServerUtil.isNullString(style.getName())) {
|
||||
style.setName(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()) {
|
||||
if (defaultStyle == null) {
|
||||
defaultStyle = style;
|
||||
continue;
|
||||
}
|
||||
defaultStyle.setDefault(false);
|
||||
defaultStyle = style;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (defaultStyle == null)
|
||||
if (getCurrentStyle() == null) {
|
||||
if (tempStore.isEmpty()) {
|
||||
defaultStyle = StyleMngr.getDefaultUserStyle(getLayerType(), getServerName(), getSourceName(), getName());
|
||||
} else {
|
||||
defaultStyle = tempStore.get(getName());
|
||||
if (defaultStyle == null)
|
||||
defaultStyle = tempStore.values().iterator().next();
|
||||
}
|
||||
} else {
|
||||
defaultStyle = tempStore.get(getCurrentStyle().getName());
|
||||
if (defaultStyle == null)
|
||||
defaultStyle = getCurrentStyle();
|
||||
}
|
||||
setCurrentStyle(defaultStyle);
|
||||
this.styleStore.putAll(tempStore);
|
||||
if (write)
|
||||
StyleMngr.writeServiceSLD100(getStyleSLD());
|
||||
}
|
||||
|
||||
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 Style getRenderStyle(String styleName) {
|
||||
Style style = getStyle(styleName);
|
||||
if (style == null)
|
||||
style = getCurrentStyle();
|
||||
return style;
|
||||
}
|
||||
|
||||
public Style getStyle(String styleName) {
|
||||
if (!ServerUtil.isNullString(styleName))
|
||||
return this.styleStore.get(styleName.trim().toUpperCase());
|
||||
return null;
|
||||
}
|
||||
|
||||
public Style getCurrentStyle() {
|
||||
return this.currentStyle;
|
||||
}
|
||||
|
||||
private Style setCurrentStyle(Style style) {
|
||||
if (this.currentStyle != null)
|
||||
this.currentStyle.setDefault(false);
|
||||
this.currentStyle = style;
|
||||
this.currentStyle.setDefault(true);
|
||||
return this.currentStyle;
|
||||
}
|
||||
|
||||
private Iterator<Style> getStyleIterator(StyledLayer layer) {
|
||||
if (layer instanceof NamedLayer)
|
||||
return ((NamedLayer)layer).styles().iterator();
|
||||
return ((UserLayer)layer).userStyles().iterator();
|
||||
}
|
||||
|
||||
public StyledLayerDescriptor getStyleSLD() {
|
||||
NamedLayer layer = StyleMngr.sf.createNamedLayer();
|
||||
layer.setName(getName());
|
||||
layer.styles().addAll(this.styleStore.values());
|
||||
StyledLayerDescriptor sld = StyleMngr.sf.createStyledLayerDescriptor();
|
||||
sld.addStyledLayer((StyledLayer)layer);
|
||||
sld.setName(getName());
|
||||
return sld;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.geotwo.webserver.core.map.layer;
|
||||
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerLevelSet;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import java.io.IOException;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
public class O2ImgLayer extends Layer {
|
||||
final O2LayerLevelSet levelSet;
|
||||
|
||||
public O2ImgLayer(AVList params) throws Exception {
|
||||
super(params);
|
||||
try {
|
||||
this.levelSet = (O2LayerLevelSet)params.getValue("o2layer.conf.level.set");
|
||||
if (this.levelSet == null || this.levelSet.size() == 0)
|
||||
throw new IOException("LevelSet has no level");
|
||||
} catch (Exception e) {
|
||||
throw new Exception("O2ImgLayer levelset is not available. :: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public O2LayerLevelSet getLevelSet() {
|
||||
return this.levelSet;
|
||||
}
|
||||
|
||||
public String getSourceName() {
|
||||
return this.levelSet.getRootPath().getAbsolutePath();
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox() {
|
||||
return new ReferencedEnvelope(this.levelSet.getBBox(), getCRS());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package com.geotwo.webserver.core.map.layer;
|
||||
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
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);
|
||||
try {
|
||||
HashMap<String, Envelope> serviceLayers = getServiceLayers();
|
||||
Envelope layerBBox = null;
|
||||
String[] layerNames = getServiceLayerNames().split(",");
|
||||
byte b;
|
||||
int i;
|
||||
String[] arrayOfString1;
|
||||
for (i = (arrayOfString1 = layerNames).length, b = 0; b < i; ) {
|
||||
String name = arrayOfString1[b];
|
||||
Envelope envelope = serviceLayers.get(name.trim());
|
||||
if (envelope == null)
|
||||
throw new IllegalArgumentException();
|
||||
if (layerBBox == null) {
|
||||
layerBBox = envelope;
|
||||
} else {
|
||||
layerBBox.expandToInclude(envelope);
|
||||
}
|
||||
b++;
|
||||
}
|
||||
this.bbox = layerBBox;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, Envelope> getServiceLayers() throws Exception {
|
||||
try {
|
||||
HashMap<String, Envelope> serviceLayers = new HashMap<String, Envelope>();
|
||||
URL url = new URL(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<Element> list = rootNode.getChildren("layer");
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Element layer = list.get(i);
|
||||
String name = layer.getChild("layer_name").getTextTrim();
|
||||
Boolean type = Boolean.valueOf(layer.getChild("layer_type").getTextTrim().toLowerCase().equals("o2map_dem"));
|
||||
if (type.booleanValue()) {
|
||||
Element bbox = layer.getChild("service_info").getChild("envelope");
|
||||
Double minx = Double.valueOf(Double.parseDouble(bbox.getChild("minx").getTextTrim()));
|
||||
Double miny = Double.valueOf(Double.parseDouble(bbox.getChild("miny").getTextTrim()));
|
||||
Double maxx = Double.valueOf(Double.parseDouble(bbox.getChild("maxx").getTextTrim()));
|
||||
Double maxy = Double.valueOf(Double.parseDouble(bbox.getChild("maxy").getTextTrim()));
|
||||
Envelope envelope = new Envelope(minx.doubleValue(), maxx.doubleValue(), miny.doubleValue(), maxy.doubleValue());
|
||||
serviceLayers.put(name, envelope);
|
||||
}
|
||||
}
|
||||
return serviceLayers;
|
||||
} catch (Exception e) {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox() {
|
||||
return new ReferencedEnvelope(this.bbox, getCRS());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package com.geotwo.webserver.core.map.layer;
|
||||
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
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 WMSLayer extends LinkLayer {
|
||||
private Envelope bbox;
|
||||
|
||||
public WMSLayer(AVList params) throws Exception {
|
||||
super(params);
|
||||
try {
|
||||
HashMap<String, Envelope> serviceLayers = getServiceLayers();
|
||||
Envelope layerBBox = null;
|
||||
String[] layerNames = getServiceLayerNames().split(",");
|
||||
byte b;
|
||||
int i;
|
||||
String[] arrayOfString1;
|
||||
for (i = (arrayOfString1 = layerNames).length, b = 0; b < i; ) {
|
||||
String name = arrayOfString1[b];
|
||||
Envelope envelope = serviceLayers.get(name.trim());
|
||||
if (envelope == null)
|
||||
throw new IllegalArgumentException();
|
||||
if (layerBBox == null) {
|
||||
layerBBox = envelope;
|
||||
} else {
|
||||
layerBBox.expandToInclude(envelope);
|
||||
}
|
||||
b++;
|
||||
}
|
||||
this.bbox = layerBBox;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, Envelope> getServiceLayers() throws Exception {
|
||||
try {
|
||||
HashMap<String, Envelope> serviceLayers = new HashMap<String, Envelope>();
|
||||
URL url = new URL(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<Element> list = rootNode.getChildren("layer");
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Element layer = list.get(i);
|
||||
String name = layer.getChild("layer_name").getTextTrim();
|
||||
Boolean type = Boolean.valueOf(layer.getChild("layer_type").getTextTrim().toLowerCase().equals("o2map_image"));
|
||||
if (type.booleanValue()) {
|
||||
Element bbox = layer.getChild("service_info").getChild("envelope");
|
||||
Double minx = Double.valueOf(Double.parseDouble(bbox.getChild("minx").getTextTrim()));
|
||||
Double miny = Double.valueOf(Double.parseDouble(bbox.getChild("miny").getTextTrim()));
|
||||
Double maxx = Double.valueOf(Double.parseDouble(bbox.getChild("maxx").getTextTrim()));
|
||||
Double maxy = Double.valueOf(Double.parseDouble(bbox.getChild("maxy").getTextTrim()));
|
||||
Envelope envelope = new Envelope(minx.doubleValue(), maxx.doubleValue(), miny.doubleValue(), maxy.doubleValue());
|
||||
serviceLayers.put(name, envelope);
|
||||
}
|
||||
}
|
||||
return serviceLayers;
|
||||
} catch (Exception e) {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBBox() {
|
||||
return new ReferencedEnvelope(this.bbox, getCRS());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.geotwo.webserver.core.render;
|
||||
|
||||
import org.geotools.styling.Description;
|
||||
import org.geotools.styling.Rule;
|
||||
import org.geotools.styling.Symbolizer;
|
||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.style.GraphicLegend;
|
||||
|
||||
public class ExtractRasterStyleVisitor extends DuplicatingStyleVisitor {
|
||||
public void visit(Rule rule) {
|
||||
Rule copy = this.sf.createRule();
|
||||
Symbolizer[] symsCopy = rule.getSymbolizers();
|
||||
for (int i = 0; i < symsCopy.length; i++) {
|
||||
if (symsCopy[i] instanceof org.geotools.styling.RasterSymbolizerImpl)
|
||||
copy.symbolizers().add(copy(symsCopy[i]));
|
||||
}
|
||||
Filter filterCopy = null;
|
||||
if (rule.getFilter() != null) {
|
||||
Filter filter = rule.getFilter();
|
||||
filterCopy = copy(filter);
|
||||
}
|
||||
copy.setFilter(filterCopy);
|
||||
copy.setElseFilter(rule.isElseFilter());
|
||||
copy.setMaxScaleDenominator(rule.getMaxScaleDenominator());
|
||||
copy.setMinScaleDenominator(rule.getMinScaleDenominator());
|
||||
GraphicLegend legendCopy = rule.getLegend();
|
||||
if (legendCopy != null)
|
||||
copy.setLegend(legendCopy);
|
||||
Description description = rule.getDescription();
|
||||
copy.setDescription(copy((Description)description));
|
||||
copy.setName(rule.getName());
|
||||
if (this.STRICT && !copy.equals(rule))
|
||||
throw new IllegalStateException("Was unable to duplicate provided Rule:" + rule);
|
||||
this.pages.push(copy);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,213 @@
|
|||
package com.geotwo.webserver.core.render;
|
||||
|
||||
import org.geotools.styling.ChannelSelection;
|
||||
import org.geotools.styling.ColorMap;
|
||||
import org.geotools.styling.ContrastEnhancement;
|
||||
import org.geotools.styling.FeatureTypeStyle;
|
||||
import org.geotools.styling.Fill;
|
||||
import org.geotools.styling.Font;
|
||||
import org.geotools.styling.Graphic;
|
||||
import org.geotools.styling.Halo;
|
||||
import org.geotools.styling.LabelPlacement;
|
||||
import org.geotools.styling.LineSymbolizer;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
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.ShadedRelief;
|
||||
import org.geotools.styling.Stroke;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleFactoryImpl;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.Symbolizer;
|
||||
import org.geotools.styling.TextSymbolizer;
|
||||
import org.geotools.styling.TextSymbolizer2;
|
||||
import org.geotools.styling.UserLayer;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
|
||||
public class O2StyleFactory extends StyleFactoryImpl {
|
||||
public StyledLayerDescriptor createStyledLayerDescriptor() {
|
||||
StyledLayerDescriptor sld = super.createStyledLayerDescriptor();
|
||||
sld.setName("");
|
||||
sld.setTitle("");
|
||||
sld.setAbstract("");
|
||||
return sld;
|
||||
}
|
||||
|
||||
public UserLayer createUserLayer() {
|
||||
UserLayer layer = super.createUserLayer();
|
||||
layer.setName("");
|
||||
return layer;
|
||||
}
|
||||
|
||||
public NamedLayer createNamedLayer() {
|
||||
NamedLayer layer = super.createNamedLayer();
|
||||
layer.setName("");
|
||||
return layer;
|
||||
}
|
||||
|
||||
public NamedStyle createNamedStyle() {
|
||||
NamedStyle style = super.createNamedStyle();
|
||||
style.setName("");
|
||||
if (style.getDescription() != null) {
|
||||
style.getDescription().setTitle("");
|
||||
style.getDescription().setAbstract("");
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
public Style createStyle() {
|
||||
Style style = super.createStyle();
|
||||
style.setName("");
|
||||
if (style.getDescription() != null) {
|
||||
style.getDescription().setTitle("");
|
||||
style.getDescription().setAbstract("");
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
public FeatureTypeStyle createFeatureTypeStyle() {
|
||||
FeatureTypeStyle ftStyle = super.createFeatureTypeStyle();
|
||||
ftStyle.setName("");
|
||||
if (ftStyle.getDescription() != null) {
|
||||
ftStyle.getDescription().setTitle("");
|
||||
ftStyle.getDescription().setAbstract("");
|
||||
}
|
||||
return ftStyle;
|
||||
}
|
||||
|
||||
public FeatureTypeStyle createFeatureTypeStyle(Rule[] rules) {
|
||||
FeatureTypeStyle ftStyle = super.createFeatureTypeStyle(rules);
|
||||
ftStyle.setName("");
|
||||
if (ftStyle.getDescription() != null) {
|
||||
ftStyle.getDescription().setTitle("");
|
||||
ftStyle.getDescription().setAbstract("");
|
||||
}
|
||||
return ftStyle;
|
||||
}
|
||||
|
||||
public Rule createRule() {
|
||||
Rule rule = super.createRule();
|
||||
rule.setName("");
|
||||
if (rule.getDescription() != null) {
|
||||
rule.getDescription().setTitle("");
|
||||
rule.getDescription().setAbstract("");
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
public PointSymbolizer createPointSymbolizer() {
|
||||
PointSymbolizer symbol = super.createPointSymbolizer();
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public PointSymbolizer createPointSymbolizer(Graphic graphic, String geometryPropertyName) {
|
||||
PointSymbolizer symbol = super.createPointSymbolizer(graphic, geometryPropertyName);
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public LineSymbolizer createLineSymbolizer() {
|
||||
LineSymbolizer symbol = super.createLineSymbolizer();
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public LineSymbolizer createLineSymbolizer(Stroke stroke, String geometryPropertyName) {
|
||||
LineSymbolizer symbol = super.createLineSymbolizer(stroke, geometryPropertyName);
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public PolygonSymbolizer createPolygonSymbolizer() {
|
||||
PolygonSymbolizer symbol = super.createPolygonSymbolizer();
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public PolygonSymbolizer createPolygonSymbolizer(Stroke stroke, Fill fill, String geometryPropertyName) {
|
||||
PolygonSymbolizer symbol = super.createPolygonSymbolizer(stroke, fill, geometryPropertyName);
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public TextSymbolizer createTextSymbolizer() {
|
||||
TextSymbolizer symbol = super.createTextSymbolizer();
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public TextSymbolizer createTextSymbolizer(Fill fill, Font[] fonts, Halo halo, Expression label, LabelPlacement labelPlacement, String geometryPropertyName) {
|
||||
TextSymbolizer symbol = super.createTextSymbolizer(fill, fonts, halo, label, labelPlacement,
|
||||
geometryPropertyName);
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public TextSymbolizer2 createTextSymbolizer(Fill fill, Font[] fonts, Halo halo, Expression label, LabelPlacement labelPlacement, String geometryPropertyName, Graphic graphic) {
|
||||
TextSymbolizer2 symbol = super.createTextSymbolizer(fill, fonts, halo, label, labelPlacement,
|
||||
geometryPropertyName, graphic);
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public RasterSymbolizer createRasterSymbolizer() {
|
||||
RasterSymbolizer symbol = super.createRasterSymbolizer();
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public RasterSymbolizer createRasterSymbolizer(String geometryPropertyName, Expression opacity, ChannelSelection channel, Expression overlap, ColorMap colorMap, ContrastEnhancement cenhancement, ShadedRelief relief, Symbolizer outline) {
|
||||
RasterSymbolizer symbol = super.createRasterSymbolizer(geometryPropertyName, opacity, channel,
|
||||
overlap, colorMap, cenhancement, relief, outline);
|
||||
symbol.setName("");
|
||||
if (symbol.getDescription() != null) {
|
||||
symbol.getDescription().setTitle("");
|
||||
symbol.getDescription().setAbstract("");
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
package com.geotwo.webserver.core.render;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
import javax.swing.ImageIcon;
|
||||
import org.geotools.geometry.jts.TransformedShape;
|
||||
import org.geotools.renderer.style.GraphicStyle2D;
|
||||
import org.geotools.renderer.style.MarkStyle2D;
|
||||
import org.geotools.renderer.style.SLDStyleFactory;
|
||||
import org.geotools.renderer.style.Style2D;
|
||||
import org.geotools.styling.AnchorPoint;
|
||||
import org.geotools.styling.Displacement;
|
||||
import org.geotools.styling.ExternalGraphicImpl;
|
||||
import org.geotools.styling.PointSymbolizer;
|
||||
import org.geotools.styling.PolygonSymbolizer;
|
||||
import org.geotools.styling.StrokeImpl;
|
||||
import org.geotools.styling.Symbolizer;
|
||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||
import org.geotools.util.NumberRange;
|
||||
import org.geotools.util.Range;
|
||||
import org.opengis.style.Fill;
|
||||
import org.opengis.style.Graphic;
|
||||
import org.opengis.style.Stroke;
|
||||
|
||||
public class RefineRenderStyleVisitor extends DuplicatingStyleVisitor {
|
||||
SLDStyleFactory sldStyleFactory = new SLDStyleFactory();
|
||||
|
||||
final NumberRange scaleRange = NumberRange.create(0.0D, Double.MAX_VALUE);
|
||||
|
||||
RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
public void visit(PointSymbolizer ps) {
|
||||
PointSymbolizer copy = this.sf.getDefaultPointSymbolizer();
|
||||
copy.setGeometry(copy(ps.getGeometry()));
|
||||
copy.setUnitOfMeasure(ps.getUnitOfMeasure());
|
||||
copy.getOptions().putAll(ps.getOptions());
|
||||
copy.setGraphic((Graphic)copy(ps.getGraphic()));
|
||||
if (this.STRICT &&
|
||||
!copy.equals(ps))
|
||||
throw new IllegalStateException("Was unable to duplicate provided Graphic:" + ps);
|
||||
ExternalGraphicImpl outputGraphic = new ExternalGraphicImpl();
|
||||
outputGraphic.setFormat("png");
|
||||
int size = ((Integer)copy.getGraphic().getSize().evaluate(null, Integer.class)).intValue();
|
||||
Style2D style2D = this.sldStyleFactory.createStyle(null, (Symbolizer)copy, (Range)this.scaleRange);
|
||||
if (style2D instanceof MarkStyle2D) {
|
||||
MarkStyle2D markStyle = (MarkStyle2D)style2D;
|
||||
TransformedShape tShape = new TransformedShape();
|
||||
tShape.shape = markStyle.getShape();
|
||||
tShape.translate((size / 2), (size / 2));
|
||||
tShape.scale(size * 0.99D, -size * 0.99D);
|
||||
BufferedImage image = new BufferedImage(size, size, 6);
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
graphics.setRenderingHints(this.renderingHints);
|
||||
if (markStyle.getFill() != null) {
|
||||
graphics.setPaint(markStyle.getFill());
|
||||
graphics.setComposite(markStyle.getFillComposite());
|
||||
graphics.fill((Shape)tShape);
|
||||
}
|
||||
if (markStyle.getContour() != null)
|
||||
if (markStyle.getStroke() instanceof BasicStroke) {
|
||||
float width = ((BasicStroke)markStyle.getStroke()).getLineWidth();
|
||||
if (width != 0.0F) {
|
||||
graphics.setPaint(markStyle.getContour());
|
||||
graphics.setStroke(markStyle.getStroke());
|
||||
graphics.setComposite(markStyle.getContourComposite());
|
||||
graphics.draw((Shape)tShape);
|
||||
}
|
||||
} else {
|
||||
graphics.setPaint(markStyle.getContour());
|
||||
graphics.setStroke(markStyle.getStroke());
|
||||
graphics.setComposite(markStyle.getContourComposite());
|
||||
graphics.draw((Shape)tShape);
|
||||
}
|
||||
graphics.dispose();
|
||||
outputGraphic.setInlineContent(refineImageIcon(image, size, ps.getGraphic().getAnchorPoint(), ps.getGraphic().getDisplacement()));
|
||||
} else if (style2D instanceof GraphicStyle2D) {
|
||||
GraphicStyle2D graphicStyle = (GraphicStyle2D)style2D;
|
||||
outputGraphic.setInlineContent(refineImageIcon(graphicStyle.getImage(), size, ps.getGraphic().getAnchorPoint(), ps.getGraphic().getDisplacement()));
|
||||
}
|
||||
copy.getGraphic().graphicalSymbols().clear();
|
||||
copy.getGraphic().graphicalSymbols().add(outputGraphic);
|
||||
this.pages.push(copy);
|
||||
}
|
||||
|
||||
private ImageIcon refineImageIcon(BufferedImage image, int size, AnchorPoint anchorCopy, Displacement displacementCopy) {
|
||||
double tPointX = 0.0D;
|
||||
double tPointY = 0.0D;
|
||||
if (anchorCopy != null) {
|
||||
double aPointX = 0.5D;
|
||||
double aPointY = 0.5D;
|
||||
if (anchorCopy.getAnchorPointX() != null) {
|
||||
aPointX = ((Double)anchorCopy.getAnchorPointX().evaluate(null, Double.class)).doubleValue();
|
||||
if (aPointX < 0.0D)
|
||||
aPointX = 0.0D;
|
||||
if (aPointX > 1.0D)
|
||||
aPointX = 1.0D;
|
||||
}
|
||||
if (anchorCopy.getAnchorPointY() != null) {
|
||||
aPointY = ((Double)anchorCopy.getAnchorPointY().evaluate(null, Double.class)).doubleValue();
|
||||
if (aPointY < 0.0D)
|
||||
aPointY = 0.0D;
|
||||
if (aPointY > 1.0D)
|
||||
aPointY = 1.0D;
|
||||
}
|
||||
double cPoint = (size / 2);
|
||||
tPointX = size * aPointX - cPoint;
|
||||
tPointY = size * aPointY - cPoint;
|
||||
}
|
||||
if (displacementCopy != null) {
|
||||
int dPointX = 0;
|
||||
int dPointY = 0;
|
||||
if (displacementCopy.getDisplacementX() != null) {
|
||||
dPointX = ((Integer)displacementCopy.getDisplacementX().evaluate(null, Integer.class)).intValue();
|
||||
if (dPointX < -100)
|
||||
dPointX = -100;
|
||||
if (dPointX > 100)
|
||||
dPointX = 100;
|
||||
}
|
||||
if (displacementCopy.getDisplacementY() != null) {
|
||||
dPointY = ((Integer)displacementCopy.getDisplacementY().evaluate(null, Integer.class)).intValue();
|
||||
if (dPointY < -100)
|
||||
dPointY = -100;
|
||||
if (dPointY > 100)
|
||||
dPointY = 100;
|
||||
}
|
||||
tPointX += dPointX;
|
||||
tPointY += dPointY;
|
||||
}
|
||||
int imgSizeW = (int)Math.round(Math.max(Math.abs(tPointX), Math.abs(tPointY)) * 2.0D + image.getWidth());
|
||||
int imgSizeH = (int)Math.round(Math.max(Math.abs(tPointX), Math.abs(tPointY)) * 2.0D + image.getHeight());
|
||||
double imgCenterW = (imgSizeW / 2);
|
||||
double imgCenterH = (imgSizeH / 2);
|
||||
BufferedImage resultImg = new BufferedImage(imgSizeW, imgSizeH, 6);
|
||||
Graphics2D graphics = resultImg.createGraphics();
|
||||
graphics.setRenderingHints(this.renderingHints);
|
||||
graphics.drawImage(image, (int)Math.round(imgCenterW - (image.getWidth() / 2) + tPointX), (int)Math.round(imgCenterH - (image.getHeight() / 2) + tPointY), (ImageObserver)null);
|
||||
graphics.dispose();
|
||||
return new ImageIcon(resultImg);
|
||||
}
|
||||
|
||||
public void visit(PolygonSymbolizer poly) {
|
||||
PolygonSymbolizer copy = this.sf.createPolygonSymbolizer();
|
||||
copy.setGeometry(copy(poly.getGeometry()));
|
||||
copy.setUnitOfMeasure(poly.getUnitOfMeasure());
|
||||
copy.getOptions().putAll(poly.getOptions());
|
||||
copy.setFill((Fill)copy(poly.getFill()));
|
||||
copy.setStroke((Stroke)copy(poly.getStroke()));
|
||||
if (copy.getStroke() == null && copy.getFill() != null) {
|
||||
StrokeImpl stroke = (StrokeImpl)StyleMngr.sf.createStroke(null, null);
|
||||
stroke.setColor(copy.getFill().getColor());
|
||||
copy.setStroke((Stroke)stroke);
|
||||
}
|
||||
if (this.STRICT && !copy.equals(poly))
|
||||
throw new IllegalStateException("Was unable to duplicate provided PolygonSymbolizer:" + poly);
|
||||
this.pages.push(copy);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
package com.geotwo.webserver.core.render;
|
||||
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.geotools.feature.NameImpl;
|
||||
import org.geotools.filter.visitor.DuplicatingFilterVisitor;
|
||||
import org.geotools.styling.Extent;
|
||||
import org.geotools.styling.FeatureTypeStyle;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
import org.geotools.styling.NamedStyle;
|
||||
import org.geotools.styling.Rule;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleVisitor;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.UserLayer;
|
||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||
import org.opengis.feature.type.Name;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.FilterFactory2;
|
||||
import org.opengis.filter.FilterVisitor;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
import org.opengis.filter.expression.ExpressionVisitor;
|
||||
import org.opengis.filter.expression.PropertyName;
|
||||
|
||||
public class RefineStyleVisitor extends DuplicatingStyleVisitor {
|
||||
DuplicatingFilterVisitor fVisitor = new DuplicatingFilterVisitor(this.ff) {
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
public void visit(StyledLayerDescriptor sld) {
|
||||
if (!ServerUtil.isNullString(sld.getName()))
|
||||
sld.setName(sld.getName().trim().toUpperCase());
|
||||
super.visit(sld);
|
||||
}
|
||||
|
||||
public void visit(NamedLayer layer) {
|
||||
if (!ServerUtil.isNullString(layer.getName()))
|
||||
layer.setName(layer.getName().trim().toUpperCase());
|
||||
super.visit(layer);
|
||||
}
|
||||
|
||||
public void visit(UserLayer layer) {
|
||||
if (!ServerUtil.isNullString(layer.getName()))
|
||||
layer.setName(layer.getName().trim().toUpperCase());
|
||||
super.visit(layer);
|
||||
}
|
||||
|
||||
public void visit(Style style) {
|
||||
if (!ServerUtil.isNullString(style.getName()))
|
||||
style.setName(style.getName().trim().toUpperCase());
|
||||
List<FeatureTypeStyle> ftStyles = style.featureTypeStyles();
|
||||
ArrayList<FeatureTypeStyle> ftsCopy = new ArrayList<FeatureTypeStyle>();
|
||||
if (ftStyles.size() > 0)
|
||||
for (FeatureTypeStyle fts : ftStyles) {
|
||||
if (fts != null) {
|
||||
fts.accept((StyleVisitor)this);
|
||||
ftsCopy.add((FeatureTypeStyle)this.pages.pop());
|
||||
}
|
||||
}
|
||||
Style copy = null;
|
||||
if (style instanceof NamedStyle) {
|
||||
NamedStyle namedStyle = this.sf.createNamedStyle();
|
||||
} else {
|
||||
copy = this.sf.createStyle();
|
||||
copy.setDefault(style.isDefault());
|
||||
}
|
||||
copy.featureTypeStyles().addAll(ftsCopy);
|
||||
copy.setName(style.getName());
|
||||
copy.getDescription().setAbstract(style.getDescription().getAbstract());
|
||||
copy.getDescription().setTitle(style.getDescription().getTitle());
|
||||
if (this.STRICT && !copy.equals(style))
|
||||
throw new IllegalStateException("Was unable to duplicate provided Style:" + style);
|
||||
this.pages.push(copy);
|
||||
}
|
||||
|
||||
public void visit(FeatureTypeStyle fts) {
|
||||
if (!ServerUtil.isNullString(fts.getName()))
|
||||
fts.setName(fts.getName().trim().toUpperCase());
|
||||
Set<Name> typeNames = new HashSet<Name>();
|
||||
Iterator<Name> names = fts.featureTypeNames().iterator();
|
||||
while (names.hasNext()) {
|
||||
Name name = names.next();
|
||||
if (!ServerUtil.isNullString(name.getLocalPart())) {
|
||||
String typeNameList = name.getLocalPart().trim().toUpperCase();
|
||||
String[] tempNames = typeNameList.split("\\,");
|
||||
byte b;
|
||||
int i;
|
||||
String[] arrayOfString1;
|
||||
for (i = (arrayOfString1 = tempNames).length, b = 0; b < i; ) {
|
||||
String typeName = arrayOfString1[b];
|
||||
typeName = typeName.trim();
|
||||
String[] codes = typeName.split(":");
|
||||
if (codes.length == 1) {
|
||||
typeNames.add(new NameImpl(codes[0].trim()));
|
||||
} else if (codes.length == 2) {
|
||||
typeNames.add(new NameImpl(codes[1].trim()));
|
||||
}
|
||||
b++;
|
||||
}
|
||||
}
|
||||
}
|
||||
fts.featureTypeNames().clear();
|
||||
fts.featureTypeNames().addAll(typeNames);
|
||||
super.visit(fts);
|
||||
}
|
||||
|
||||
public void visit(Rule rule) {
|
||||
if (!ServerUtil.isNullString(rule.getName()))
|
||||
rule.setName(rule.getName().trim().toUpperCase());
|
||||
super.visit(rule);
|
||||
}
|
||||
|
||||
protected Extent copy(Extent extent) {
|
||||
String name = extent.getName();
|
||||
String value = extent.getValue();
|
||||
Extent copy = this.sf.createExtent(name.toUpperCase(), value);
|
||||
return copy;
|
||||
}
|
||||
|
||||
protected Filter copy(Filter filter) {
|
||||
if (filter == null)
|
||||
return null;
|
||||
return (Filter)filter.accept((FilterVisitor)this.fVisitor, this.ff);
|
||||
}
|
||||
|
||||
protected Expression copy(Expression expression) {
|
||||
if (expression == null)
|
||||
return null;
|
||||
return (Expression)expression.accept((ExpressionVisitor)this.fVisitor, this.ff);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,658 @@
|
|||
package com.geotwo.webserver.core.render;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerLevelSet;
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerUtil;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import com.geotwo.webserver.core.map.layer.FeatureLayer;
|
||||
import com.geotwo.webserver.core.map.layer.GroupLayer;
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.map.layer.LinkLayer;
|
||||
import com.geotwo.webserver.core.map.layer.O2DemLayer;
|
||||
import com.geotwo.webserver.core.map.layer.O2ImgLayer;
|
||||
import com.geotwo.webserver.core.map.layer.WMSLayer;
|
||||
import com.geotwo.webserver.core.render.io.RenderFeatureSource;
|
||||
import com.geotwo.webserver.core.render.layer.ExFeatureLayer;
|
||||
import com.geotwo.webserver.core.render.layer.ExO2ImgLayer;
|
||||
import com.geotwo.webserver.core.render.layer.ExWMSLayer;
|
||||
import com.geotwo.webserver.core.render.style.MapStyle;
|
||||
import com.geotwo.webserver.core.render.style.label.LabelCacheEx;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.O2DSMngr;
|
||||
import com.geotwo.webserver.core.vector.crs.CRSMngr;
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import javax.media.jai.InterpolationBicubic2;
|
||||
import javax.media.jai.InterpolationBilinear;
|
||||
import javax.media.jai.InterpolationNearest;
|
||||
import javax.media.jai.JAI;
|
||||
import org.geotools.coverage.grid.GridCoverage2D;
|
||||
import org.geotools.data.DataStore;
|
||||
import org.geotools.data.FeatureReader;
|
||||
import org.geotools.data.FeatureSource;
|
||||
import org.geotools.data.Query;
|
||||
import org.geotools.data.Transaction;
|
||||
import org.geotools.data.crs.ForceCoordinateSystemFeatureReader;
|
||||
import org.geotools.data.memory.MemoryDataStore;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.feature.NameImpl;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.map.GridCoverageLayer;
|
||||
import org.geotools.map.MapContent;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.renderer.label.LabelCacheImpl;
|
||||
import org.geotools.renderer.lite.StreamingRenderer;
|
||||
import org.geotools.styling.FeatureTypeStyle;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
import org.geotools.styling.NamedStyle;
|
||||
import org.geotools.styling.Rule;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.styling.StyleVisitor;
|
||||
import org.geotools.styling.StyledLayer;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.Symbolizer;
|
||||
import org.geotools.styling.TextSymbolizer;
|
||||
import org.geotools.styling.UserLayer;
|
||||
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
|
||||
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.referencing.crs.CoordinateReferenceSystem;
|
||||
public class RenderMngr {
|
||||
static boolean useImageAntialias = true;
|
||||
static boolean useTextAntialias = true;
|
||||
static Interpolation interpolationMethod = Interpolation.NN;
|
||||
static ThreadPoolExecutor RENDERING_POOL;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, Layer[] layers, String[] styles, AVList params) throws Exception {
|
||||
int i = 0;
|
||||
while (i < layers.length) {
|
||||
RenderMngr.makeNamedLayer(targetLayers, layers[i], styles[i], params);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, Layer[] layers, String[] styles, StyledLayerDescriptor sld, AVList params) throws Exception {
|
||||
int i = 0;
|
||||
while (i < layers.length) {
|
||||
ArrayList<Style> sldStyles = StyleMngr.getStylesFromSLD(layers[i].getName(), styles[i], sld);
|
||||
if (sldStyles.isEmpty()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static void addRenderLayers(ArrayList<org.geotools.map.Layer> targetLayers, StyledLayerDescriptor sld, AVList params) throws Exception {
|
||||
for (StyledLayer styledLayer : sld.layers()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void makeUserLayer(ArrayList<org.geotools.map.Layer> targetLayers, UserLayer userLayer, Style style, AVList params) throws Exception {
|
||||
if (userLayer.getInlineFeatureType() == null) {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void makeNamedLayer(ArrayList<org.geotools.map.Layer> targetLayers, Layer layer, Style style, AVList params) throws Exception {
|
||||
if (layer instanceof FeatureLayer) {
|
||||
Filter filter = (Filter)params.getValue("request.wms.filter");
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void addFeatureTypeStyleList(LinkedList<MapStyle> styleList, LayerFactory.LayerType layerType, String serverName, String typeName, FeatureTypeStyle featureStyle) {
|
||||
DuplicatingStyleVisitor visitor = new DuplicatingStyleVisitor();
|
||||
visitor.visit(featureStyle);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static BufferedImage drawImage(ArrayList<org.geotools.map.Layer> targetLayers, Rectangle paintArea, ReferencedEnvelope mapBounds, Color bgColor, boolean transparent) throws Exception {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawScaledLayer(StreamingRenderer renderer, org.geotools.map.Layer layer, Graphics2D graphic, Rectangle paintArea, ReferencedEnvelope mapBounds, double scale) throws Exception {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static Rectangle getScaledArea(Rectangle paintArea, double scale) {
|
||||
int wGap = (int)((double)paintArea.width * scale);
|
||||
int hGap = (int)((double)paintArea.height * scale);
|
||||
return new Rectangle(-wGap, -hGap, paintArea.width + wGap * 2, paintArea.height + hGap * 2);
|
||||
}
|
||||
|
||||
private static void drawNormalLayer(StreamingRenderer renderer, org.geotools.map.Layer layer, Graphics2D graphic, Rectangle paintArea, ReferencedEnvelope mapBounds) throws Exception {
|
||||
MapContent mapContent = new MapContent();
|
||||
mapContent.getViewport().setBounds(mapBounds);
|
||||
mapContent.getViewport().setCoordinateReferenceSystem(mapBounds.getCoordinateReferenceSystem());
|
||||
mapContent.getViewport().setScreenArea(paintArea);
|
||||
mapContent.getViewport().setMatchingAspectRatio(false);
|
||||
mapContent.addLayer(layer);
|
||||
try {
|
||||
renderer.setMapContent(mapContent);
|
||||
renderer.paint(graphic, paintArea, mapBounds);
|
||||
}
|
||||
finally {
|
||||
RenderMngr.disposeMapContents(mapContent);
|
||||
mapContent.dispose();
|
||||
mapContent = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void disposeMapContents(MapContent mapContent) {
|
||||
if (mapContent == null) {
|
||||
return;
|
||||
}
|
||||
for (org.geotools.map.Layer layer : mapContent.layers()) {
|
||||
layer.preDispose();
|
||||
}
|
||||
mapContent.dispose();
|
||||
mapContent = null;
|
||||
}
|
||||
|
||||
private static StreamingRenderer initRenderer(Graphics2D graphic, LabelCacheEx labelCache) {
|
||||
HashMap<RenderingHints.Key, Object> hintsMap = new HashMap<RenderingHints.Key, Object>();
|
||||
if (useImageAntialias) {
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,395 @@
|
|||
package com.geotwo.webserver.core.render;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.feature.GeometryMngr;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import com.geotwo.webserver.core.render.sld.SLDConfiguration110;
|
||||
import com.geotwo.webserver.core.render.sld.SLDParser100;
|
||||
import com.geotwo.webserver.core.render.sld.SLDTransformer110;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
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.LineSymbolizer;
|
||||
import org.geotools.styling.Mark;
|
||||
import org.geotools.styling.NamedLayer;
|
||||
import org.geotools.styling.PointSymbolizer;
|
||||
import org.geotools.styling.PolygonSymbolizer;
|
||||
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.StyleVisitor;
|
||||
import org.geotools.styling.StyledLayer;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.styling.Symbolizer;
|
||||
import org.geotools.styling.UserLayer;
|
||||
import org.geotools.xml.Configuration;
|
||||
import org.geotools.xml.Parser;
|
||||
import org.opengis.filter.FilterFactory;
|
||||
import org.opengis.filter.FilterFactory2;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
import org.opengis.style.ShadedRelief;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class StyleMngr {
|
||||
static {
|
||||
Hints.putSystemDefault((RenderingHints.Key)Hints.STYLE_FACTORY, O2StyleFactory.class);
|
||||
}
|
||||
|
||||
public static final StyleFactory sf = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());
|
||||
|
||||
public static final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
|
||||
|
||||
public static final StyleBuilder sb = new StyleBuilder(sf, (FilterFactory)ff);
|
||||
|
||||
private static final Color LINE_COLOR = Color.BLUE;
|
||||
|
||||
private static final Color FILL_COLOR = Color.CYAN;
|
||||
|
||||
private static final float OPACITY = 1.0F;
|
||||
|
||||
private static final float LINE_WIDTH = 1.0F;
|
||||
|
||||
private static final float POINT_SIZE = 10.0F;
|
||||
|
||||
public static ArrayList<Style> getStylesFromSLD(StyledLayerDescriptor sld) {
|
||||
ArrayList<Style> styles = new ArrayList<Style>();
|
||||
if (sld == null)
|
||||
return styles;
|
||||
Iterator<StyledLayer> sldLayerIter = sld.layers().iterator();
|
||||
while (sldLayerIter.hasNext()) {
|
||||
StyledLayer styledLayer = sldLayerIter.next();
|
||||
Iterator<Style> sldStyleIter = getStylesIterator(styledLayer);
|
||||
while (sldStyleIter.hasNext()) {
|
||||
Style tempStyle = sldStyleIter.next();
|
||||
styles.add(tempStyle);
|
||||
}
|
||||
}
|
||||
return styles;
|
||||
}
|
||||
|
||||
public static ArrayList<Style> getStylesFromSLD(String layerName, StyledLayerDescriptor sld) {
|
||||
ArrayList<Style> styles = new ArrayList<Style>();
|
||||
if (ServerUtil.isNullString(layerName) || sld == null)
|
||||
return styles;
|
||||
layerName = layerName.trim().toUpperCase();
|
||||
Iterator<StyledLayer> sldLayerIter = sld.layers().iterator();
|
||||
while (sldLayerIter.hasNext()) {
|
||||
StyledLayer styledLayer = sldLayerIter.next();
|
||||
if (styledLayer.getName() != null &&
|
||||
styledLayer.getName().equalsIgnoreCase(layerName))
|
||||
styles.addAll(getStyles(styledLayer));
|
||||
}
|
||||
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) {
|
||||
if (layer instanceof NamedLayer)
|
||||
return ((NamedLayer)layer).styles();
|
||||
return ((UserLayer)layer).userStyles();
|
||||
}
|
||||
|
||||
private static Iterator<Style> getStylesIterator(StyledLayer layer) {
|
||||
if (layer instanceof NamedLayer)
|
||||
return ((NamedLayer)layer).styles().iterator();
|
||||
return ((UserLayer)layer).userStyles().iterator();
|
||||
}
|
||||
|
||||
public static synchronized void writeServiceSLD100(StyledLayerDescriptor sld) {
|
||||
try {
|
||||
final String layerName = sld.getName();
|
||||
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
if (name.toUpperCase().equalsIgnoreCase(String.valueOf(layerName) + ".SLD"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
byte b;
|
||||
int i;
|
||||
File[] arrayOfFile1;
|
||||
for (i = (arrayOfFile1 = files).length, b = 0; b < i; ) {
|
||||
File file = arrayOfFile1[b];
|
||||
file.delete();
|
||||
b++;
|
||||
}
|
||||
File writeFile = new File(ServerContext.getStylesFolder(), String.valueOf(layerName) + ".sld");
|
||||
SLDTransformer styleTransform = new SLDTransformer();
|
||||
styleTransform.setEncoding(Charset.forName("EUC-KR"));
|
||||
styleTransform.setIndentation(5);
|
||||
styleTransform.transform(sld, new FileOutputStream(writeFile));
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[STYLE]",
|
||||
"[StyleMngr.writeServiceSLD]" +
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void writeServiceSLD110(StyledLayerDescriptor sld) {
|
||||
try {
|
||||
final String layerName = sld.getName();
|
||||
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
if (name.toUpperCase().equalsIgnoreCase(String.valueOf(layerName) + ".SLD"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
byte b;
|
||||
int i;
|
||||
File[] arrayOfFile1;
|
||||
for (i = (arrayOfFile1 = files).length, b = 0; b < i; ) {
|
||||
File file = arrayOfFile1[b];
|
||||
file.delete();
|
||||
b++;
|
||||
}
|
||||
File writeFile = new File(ServerContext.getStylesFolder(), String.valueOf(layerName) + ".sld");
|
||||
SLDTransformer110 styleTransform = new SLDTransformer110();
|
||||
styleTransform.setEncoding(Charset.forName("EUC-KR"));
|
||||
styleTransform.setIndentation(5);
|
||||
styleTransform.transform(sld, new FileOutputStream(writeFile));
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[STYLE]",
|
||||
"[StyleMngr.writeServiceSLD]" +
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static StyledLayerDescriptor readServiceSLD(final String layerName) {
|
||||
try {
|
||||
File[] files = ServerContext.getStylesFolder().listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
if (name.toUpperCase().equalsIgnoreCase(String.valueOf(layerName) + ".SLD"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (files.length > 0)
|
||||
return parseSLD(new FileInputStream(files[0]));
|
||||
LogMngr.getInstance().logDebug("[STYLE]",
|
||||
"[StyleMngr.readServiceSLD] " + layerName + ".sld is not exist");
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[STYLE]",
|
||||
"[StyleMngr.readServiceSLD]" +
|
||||
e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static StyledLayerDescriptor parseSLD(InputStream stream) throws Exception {
|
||||
try {
|
||||
byte[] sldBytes = ServerUtil.cloneInputStream(stream);
|
||||
String version = getSLDVersion(new ByteArrayInputStream(sldBytes));
|
||||
Object obj = null;
|
||||
if (version.equals("1.1.0")) {
|
||||
SLDConfiguration110 config = new SLDConfiguration110();
|
||||
Parser parser = new Parser((Configuration)config);
|
||||
String thkimTest = new String(sldBytes);
|
||||
System.out.println("thkim XML:\n" + thkimTest);
|
||||
obj = parser.parse(new ByteArrayInputStream(sldBytes));
|
||||
} else {
|
||||
SLDParser100 parser = new SLDParser100(sf, new ByteArrayInputStream(sldBytes));
|
||||
obj = parser.parseSLD();
|
||||
}
|
||||
StyledLayerDescriptor sld = (StyledLayerDescriptor)obj;
|
||||
RefineStyleVisitor uVisitor = new RefineStyleVisitor();
|
||||
sld.accept((StyleVisitor)uVisitor);
|
||||
sld = (StyledLayerDescriptor)uVisitor.getCopy();
|
||||
return sld;
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[STYLE]", "[StyleMngr.parseSLD]" + e.getMessage());
|
||||
throw e;
|
||||
} finally {
|
||||
if (stream != null)
|
||||
try {
|
||||
stream.close();
|
||||
stream = null;
|
||||
} catch (IOException e) {
|
||||
stream = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getSLDVersion(InputStream stream) {
|
||||
try {
|
||||
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document dDoc = builder.parse(stream);
|
||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
String version = (String)xPath.evaluate("//StyledLayerDescriptor/@version", dDoc, XPathConstants.STRING);
|
||||
return version;
|
||||
} catch (ParserConfigurationException parserConfigurationException) {
|
||||
|
||||
} catch (SAXException sAXException) {
|
||||
|
||||
} catch (IOException iOException) {
|
||||
|
||||
} catch (XPathExpressionException xPathExpressionException) {
|
||||
|
||||
} finally {
|
||||
if (stream != null)
|
||||
try {
|
||||
stream.close();
|
||||
stream = null;
|
||||
} catch (IOException e) {
|
||||
stream = null;
|
||||
}
|
||||
}
|
||||
return "1.1.0";
|
||||
}
|
||||
|
||||
public static Style getDefaultUserStyle(LayerFactory.LayerType layerType, String serverName, String tableName, String layerName) {
|
||||
Style uStyle = sf.createStyle();
|
||||
uStyle.featureTypeStyles().add(getDefaultFeatureTypeStyle(layerType, serverName, tableName));
|
||||
uStyle.setDefault(true);
|
||||
uStyle.setName("");
|
||||
if (!ServerUtil.isNullString(layerName))
|
||||
uStyle.setName(layerName);
|
||||
return uStyle;
|
||||
}
|
||||
|
||||
private static FeatureTypeStyle getDefaultFeatureTypeStyle(LayerFactory.LayerType layerType, String serverName, String tableName) {
|
||||
Rule rule = null;
|
||||
if (layerType == LayerFactory.LayerType.JDBC ||
|
||||
layerType == LayerFactory.LayerType.GEOWAVE ||
|
||||
layerType == LayerFactory.LayerType.SHAPE ||
|
||||
layerType == LayerFactory.LayerType.O2WPSVEC) {
|
||||
GeometryMngr.GeomType geomType = GeometryMngr.GeomType.LINE;
|
||||
String geomColumnName = null;
|
||||
try {
|
||||
geomType = GeometryMngr.getGeometryType(layerType, serverName, tableName);
|
||||
geomColumnName = GeometryMngr.getGeometryColumn(layerType, serverName, tableName);
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[STYLE]", "[StyleMngr.getDefaultFeatureTypeStyle]" + e);
|
||||
}
|
||||
rule = createFeatureTypeRule(geomType, geomColumnName);
|
||||
} else if (layerType == LayerFactory.LayerType.O2DEM ||
|
||||
layerType == LayerFactory.LayerType.O2WPSCOV) {
|
||||
RasterSymbolizerImpl sym = new RasterSymbolizerImpl();
|
||||
sym.setShadedRelief((ShadedRelief)new ShadedReliefImpl());
|
||||
rule = sf.createRule();
|
||||
rule.setName("RULE");
|
||||
rule.symbolizers().add(sym);
|
||||
} else {
|
||||
rule = sf.createRule();
|
||||
rule.setName("RULE");
|
||||
rule.symbolizers().clear();
|
||||
}
|
||||
FeatureTypeStyle ftStyle = sf.createFeatureTypeStyle();
|
||||
ftStyle.rules().add(rule);
|
||||
ftStyle.setName("FEATURETYPESTYLE");
|
||||
return ftStyle;
|
||||
}
|
||||
|
||||
private static Rule createFeatureTypeRule(GeometryMngr.GeomType geomType, String geomColumnName) {
|
||||
PolygonSymbolizer polygonSymbolizer;
|
||||
LineSymbolizer lineSymbolizer;
|
||||
PointSymbolizer pointSymbolizer = null;
|
||||
Mark mark;
|
||||
Graphic graphic;
|
||||
Symbolizer symbolizer = null;
|
||||
Fill fill = null;
|
||||
Stroke stroke = sf.createStroke((Expression)ff.literal(LINE_COLOR), (Expression)ff.literal(1.0F));
|
||||
switch (geomType) {
|
||||
case POLYGON:
|
||||
fill = sf.createFill((Expression)ff.literal(FILL_COLOR), (Expression)ff.literal(1.0F));
|
||||
polygonSymbolizer = sf.createPolygonSymbolizer(stroke, fill, geomColumnName);
|
||||
polygonSymbolizer.setName("POLYGONSYMBOLIZER");
|
||||
break;
|
||||
case LINE:
|
||||
lineSymbolizer = sf.createLineSymbolizer(stroke, geomColumnName);
|
||||
lineSymbolizer.setName("LINESYMBOLIZER");
|
||||
break;
|
||||
case POINT:
|
||||
fill = sf.createFill((Expression)ff.literal(FILL_COLOR), (Expression)ff.literal(1.0F));
|
||||
mark = sf.getCircleMark();
|
||||
mark.setFill((Fill)fill);
|
||||
mark.setStroke((Stroke)stroke);
|
||||
graphic = sf.createDefaultGraphic();
|
||||
graphic.graphicalSymbols().clear();
|
||||
graphic.graphicalSymbols().add(mark);
|
||||
graphic.setSize((Expression)ff.literal(10.0F));
|
||||
pointSymbolizer = sf.createPointSymbolizer(graphic, geomColumnName);
|
||||
pointSymbolizer.setName("POINTSYMBOLIZER");
|
||||
break;
|
||||
}
|
||||
Rule rule = sf.createRule();
|
||||
rule.setName("RULE");
|
||||
rule.symbolizers().add(pointSymbolizer);
|
||||
return rule;
|
||||
}
|
||||
|
||||
public static MarkStyle2D createDefaultMarkStyle() {
|
||||
MarkStyle2D mark = new MarkStyle2D();
|
||||
mark.setShape(new Rectangle2D.Double(-0.5D, -0.5D, 1.0D, 1.0D));
|
||||
mark.setFill(FILL_COLOR);
|
||||
mark.setFillComposite(AlphaComposite.getInstance(3, 1.0F));
|
||||
mark.setStroke(new BasicStroke(1.0F, 2, 0, 1.0F));
|
||||
mark.setContour(LINE_COLOR);
|
||||
mark.setContourComposite(AlphaComposite.getInstance(3, 1.0F));
|
||||
mark.setSize(16.0D);
|
||||
return mark;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
package com.geotwo.webserver.core.render.io;
|
||||
|
||||
import ar.com.hjg.pngj.FilterType;
|
||||
import ar.com.hjg.pngj.IImageLine;
|
||||
import ar.com.hjg.pngj.ImageInfo;
|
||||
import ar.com.hjg.pngj.ImageLineByte;
|
||||
import ar.com.hjg.pngj.ImageLineHelper;
|
||||
import ar.com.hjg.pngj.ImageLineInt;
|
||||
import ar.com.hjg.pngj.PngWriter;
|
||||
import ar.com.hjg.pngj.PngjException;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ComponentSampleModel;
|
||||
import java.awt.image.DataBufferByte;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.SinglePixelPackedSampleModel;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class O2PngWriter {
|
||||
public static void writeRgb8(BufferedImage buf, OutputStream os) {
|
||||
ImageInfo imi = getImageInfo(buf);
|
||||
PngWriter pngw = new PngWriter(os, imi);
|
||||
pngw.setCompLevel(1);
|
||||
pngw.setFilterType(FilterType.FILTER_ADAPTIVE_FAST);
|
||||
ImageLineInt line = new ImageLineInt(imi);
|
||||
buf.getRaster();
|
||||
for (int row = 0; row < imi.rows; row++) {
|
||||
for (int col = 0; col < imi.cols; col++) {
|
||||
int p = buf.getRGB(col, row);
|
||||
if (imi.alpha) {
|
||||
ImageLineHelper.setPixelRGBA8(line, col, p);
|
||||
} else {
|
||||
ImageLineHelper.setPixelRGB8(line, col, p);
|
||||
}
|
||||
}
|
||||
pngw.writeRow((IImageLine)line, row);
|
||||
}
|
||||
pngw.end();
|
||||
}
|
||||
|
||||
public static void writeRgb8Ori(BufferedImage buf, OutputStream os) {
|
||||
ImageInfo imi = getImageInfo(buf);
|
||||
PngWriter pngw = new PngWriter(os, imi);
|
||||
pngw.setCompLevel(1);
|
||||
pngw.setFilterType(FilterType.FILTER_ADAPTIVE_FAST);
|
||||
ImageLineInt line = new ImageLineInt(imi);
|
||||
for (int row = 0; row < imi.rows; row++) {
|
||||
for (int col = 0; col < imi.cols; col++) {
|
||||
int p = buf.getRGB(col, row);
|
||||
if (imi.alpha) {
|
||||
ImageLineHelper.setPixelRGBA8(line, col, p);
|
||||
} else {
|
||||
ImageLineHelper.setPixelRGB8(line, col, p);
|
||||
}
|
||||
}
|
||||
pngw.writeRow((IImageLine)line, row);
|
||||
}
|
||||
pngw.end();
|
||||
}
|
||||
|
||||
public static void writePNG(BufferedImage bi, OutputStream os) {
|
||||
if (bi.getType() == 2) {
|
||||
writeTYPE_INT_ARGB(bi, os);
|
||||
} else if (bi.getType() == 6) {
|
||||
writeTYPE_4BYTE_ABGR(bi, os);
|
||||
} else {
|
||||
writeRgb8(bi, os);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeTYPE_INT_ARGB(BufferedImage bi, OutputStream os) {
|
||||
if (bi.getType() != 2)
|
||||
throw new PngjException("This method expects BufferedImage.TYPE_INT_ARGB");
|
||||
ImageInfo imi = getImageInfo(bi);
|
||||
PngWriter pngw = new PngWriter(os, imi);
|
||||
pngw.setCompLevel(1);
|
||||
pngw.setFilterType(FilterType.FILTER_ADAPTIVE_FAST);
|
||||
DataBufferInt db = (DataBufferInt)bi.getRaster().getDataBuffer();
|
||||
if (db.getNumBanks() != 1)
|
||||
throw new PngjException("This method expects one bank");
|
||||
SinglePixelPackedSampleModel samplemodel = (SinglePixelPackedSampleModel)bi.getSampleModel();
|
||||
ImageLineByte line = new ImageLineByte(imi);
|
||||
int[] dbbuf = db.getData();
|
||||
byte[] scanline = line.getScanline();
|
||||
for (int row = 0; row < imi.rows; row++) {
|
||||
int elem = samplemodel.getOffset(0, row);
|
||||
for (int col = 0, j = 0; col < imi.cols; col++) {
|
||||
int sample = dbbuf[elem++];
|
||||
scanline[j++] = (byte)((sample & 0xFF0000) >> 16);
|
||||
scanline[j++] = (byte)((sample & 0xFF00) >> 8);
|
||||
scanline[j++] = (byte)(sample & 0xFF);
|
||||
scanline[j++] = (byte)((sample & 0xFF000000) >> 24 & 0xFF);
|
||||
}
|
||||
pngw.writeRow((IImageLine)line, row);
|
||||
}
|
||||
pngw.end();
|
||||
}
|
||||
|
||||
public static void writeTYPE_4BYTE_ABGR(BufferedImage bi, OutputStream os) {
|
||||
if (bi.getType() != 6)
|
||||
throw new PngjException("This method expects BufferedImage.TYPE_4BYTE_ABGR");
|
||||
ImageInfo imi = getImageInfo(bi);
|
||||
PngWriter pngw = new PngWriter(os, imi);
|
||||
pngw.setCompLevel(1);
|
||||
pngw.setFilterType(FilterType.FILTER_ADAPTIVE_FAST);
|
||||
DataBufferByte db = (DataBufferByte)bi.getRaster().getDataBuffer();
|
||||
ComponentSampleModel samplemodel = (ComponentSampleModel)bi.getSampleModel();
|
||||
ImageLineByte line = new ImageLineByte(imi);
|
||||
if (db.getNumBanks() != 1)
|
||||
throw new PngjException("This method expects one bank");
|
||||
byte[] dbbuf = db.getData();
|
||||
byte[] scanline = line.getScanline();
|
||||
for (int row = 0; row < imi.rows; row++) {
|
||||
int elem = samplemodel.getOffset(0, row);
|
||||
for (int col = 0, j = 0; col < imi.cols; col++, elem += 7) {
|
||||
scanline[j++] = dbbuf[elem--];
|
||||
scanline[j++] = dbbuf[elem--];
|
||||
scanline[j++] = dbbuf[elem--];
|
||||
scanline[j++] = dbbuf[elem];
|
||||
}
|
||||
pngw.writeRow((IImageLine)line, row);
|
||||
}
|
||||
pngw.end();
|
||||
}
|
||||
|
||||
private static ImageInfo getImageInfo(BufferedImage buf) {
|
||||
int buftype = buf.getType();
|
||||
boolean alpha = false, indexed = false, alphapre = false, gray = false, depth16 = false;
|
||||
switch (buftype) {
|
||||
case 2:
|
||||
case 6:
|
||||
alpha = true;
|
||||
case 3:
|
||||
case 7:
|
||||
alphapre = true;
|
||||
break;
|
||||
case 10:
|
||||
case 12:
|
||||
gray = true;
|
||||
case 11:
|
||||
depth16 = true;
|
||||
break;
|
||||
case 13:
|
||||
if (buf.getColorModel() instanceof java.awt.image.IndexColorModel)
|
||||
indexed = true;
|
||||
break;
|
||||
}
|
||||
return new ImageInfo(buf.getWidth(), buf.getHeight(), depth16 ? 16 : 8, alpha, gray, indexed);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,284 @@
|
|||
package com.geotwo.webserver.core.render.io;
|
||||
|
||||
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 java.util.List;
|
||||
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.PropertyDescriptor;
|
||||
import org.opengis.filter.Filter;
|
||||
import org.opengis.filter.sort.SortBy;
|
||||
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);
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBounds() {
|
||||
FeatureReader<SimpleFeatureType, SimpleFeature> reader = null;
|
||||
try {
|
||||
ReferencedEnvelope result = this.featureSource.getBounds(this.query);
|
||||
if (result != null)
|
||||
return result;
|
||||
Query q = new Query(this.query);
|
||||
List<String> geometries = new ArrayList<String>();
|
||||
for (AttributeDescriptor ad : getSchema().getAttributeDescriptors()) {
|
||||
if (ad instanceof org.opengis.feature.type.GeometryDescriptor)
|
||||
geometries.add(ad.getLocalName());
|
||||
}
|
||||
if (geometries.size() == 0)
|
||||
return new ReferencedEnvelope();
|
||||
q.setPropertyNames(geometries);
|
||||
reader = this.featureSource.getReader(q);
|
||||
while (reader.hasNext()) {
|
||||
SimpleFeature f = (SimpleFeature)reader.next();
|
||||
ReferencedEnvelope featureBounds = ReferencedEnvelope.reference(f.getBounds());
|
||||
if (result == null) {
|
||||
result = featureBounds;
|
||||
continue;
|
||||
}
|
||||
if (featureBounds != null)
|
||||
result.expandToInclude((Envelope)featureBounds);
|
||||
}
|
||||
if (result != null)
|
||||
return result;
|
||||
return new ReferencedEnvelope(getSchema().getCoordinateReferenceSystem());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException iOException) {}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(Object o) {
|
||||
SimpleFeatureIterator e = null;
|
||||
try {
|
||||
e = features();
|
||||
if (o == null) {
|
||||
while (e.hasNext()) {
|
||||
if (e.next() == null)
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
while (e.hasNext()) {
|
||||
if (o.equals(e.next()))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
if (e != null)
|
||||
e.close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
Iterator<?> e = c.iterator();
|
||||
try {
|
||||
while (e.hasNext()) {
|
||||
if (!contains(e.next()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
if (e instanceof FeatureIterator)
|
||||
((FeatureIterator)e).close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
Query notEmptyQuery = new Query(this.query);
|
||||
notEmptyQuery.setMaxFeatures(1);
|
||||
AttributeDescriptor smallAttribute = getSmallAttributeInSchema();
|
||||
if (smallAttribute != null)
|
||||
notEmptyQuery.setPropertyNames(Collections.singletonList(smallAttribute.getLocalName()));
|
||||
try {
|
||||
FeatureReader<?, ?> fr = this.featureSource.getReader(notEmptyQuery);
|
||||
try {
|
||||
return !fr.hasNext();
|
||||
} finally {
|
||||
fr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private AttributeDescriptor getSmallAttributeInSchema() {
|
||||
AttributeDescriptor chosen = null;
|
||||
for (AttributeDescriptor ad : getSchema().getAttributeDescriptors()) {
|
||||
if (chosen == null || size(ad) < size(chosen))
|
||||
chosen = ad;
|
||||
}
|
||||
return chosen;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
FeatureReader<?, ?> fr = null;
|
||||
try {
|
||||
int size = this.featureSource.getCount(this.query);
|
||||
if (size >= 0)
|
||||
return size;
|
||||
AttributeDescriptor chosen = 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++;
|
||||
}
|
||||
return count;
|
||||
} 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() {
|
||||
SimpleFeatureIterator simpleFeatureIterator = null;
|
||||
ArrayList<SimpleFeature> array = new ArrayList<SimpleFeature>();
|
||||
FeatureIterator<SimpleFeature> e = null;
|
||||
try {
|
||||
simpleFeatureIterator = features();
|
||||
while (simpleFeatureIterator.hasNext())
|
||||
array.add((SimpleFeature)simpleFeatureIterator.next());
|
||||
return array.toArray((Object[])new SimpleFeature[array.size()]);
|
||||
} finally {
|
||||
if (simpleFeatureIterator != null)
|
||||
simpleFeatureIterator.close();
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
int size = size();
|
||||
if (array.length < size)
|
||||
array = (T[])Array.newInstance(array.getClass().getComponentType(), size);
|
||||
SimpleFeatureIterator simpleFeatureIterator = features();
|
||||
try {
|
||||
Object[] result = array;
|
||||
for (int i = 0; simpleFeatureIterator.hasNext() && i < size; i++)
|
||||
result[i] = simpleFeatureIterator.next();
|
||||
if (array.length > size)
|
||||
array[size] = null;
|
||||
return (T[])array;
|
||||
} finally {
|
||||
if (simpleFeatureIterator != null)
|
||||
simpleFeatureIterator.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(this.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(this.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) {
|
||||
close();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
this.delegate.close();
|
||||
} catch (IOException iOException) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
package com.geotwo.webserver.core.render.io;
|
||||
|
||||
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.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 {
|
||||
if( source == null ) {
|
||||
System.out.println("thkim test source is null");
|
||||
}
|
||||
if( query == null ) {
|
||||
System.out.println("thkim test query is null");
|
||||
}
|
||||
|
||||
|
||||
System.out.println("thkim test query.toString()\n:" + query.toString());
|
||||
System.out.println("thkim test source.toString()\n:" + source.toString());
|
||||
this.source = source;
|
||||
this.featureIterator = (FeatureIterator<SimpleFeature>)source.getFeatures(query).features();
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (this.featureIterator != null)
|
||||
try {
|
||||
this.featureIterator.close();
|
||||
} catch (Exception exception) {
|
||||
|
||||
} 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))
|
||||
continue;
|
||||
if (this.simplificationDistance > 0.0D &&
|
||||
envelope.getWidth() < this.simplificationDistance &&
|
||||
envelope.getHeight() < this.simplificationDistance)
|
||||
try {
|
||||
if (this.screenMap != null && this.screenMap.checkAndSet(envelope))
|
||||
continue;
|
||||
} catch (Exception exception) {}
|
||||
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,176 @@
|
|||
package com.geotwo.webserver.core.render.io;
|
||||
|
||||
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.simple.SimpleFeatureCollection;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.factory.Hints;
|
||||
import org.geotools.feature.FeatureCollection;
|
||||
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.FeatureType;
|
||||
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 getFeatures(Query.ALL);
|
||||
}
|
||||
|
||||
public SimpleFeatureCollection getFeatures(Filter filter) throws IOException {
|
||||
Query query = new Query(getSchema().getName().getLocalPart(), filter);
|
||||
return getFeatures(query);
|
||||
}
|
||||
|
||||
public SimpleFeatureCollection getFeatures(Query query) throws IOException {
|
||||
if (this.delegate.getDataStore() instanceof org.geotools.data.shapefile.ShpDataStore)
|
||||
return this.delegate.getFeatures(query);
|
||||
return new RenderFeatureCollection(this, query);
|
||||
}
|
||||
|
||||
public void accepts(Query query, FeatureVisitor visitor, ProgressListener progress) throws IOException {
|
||||
NullProgressListener nullProgressListener;
|
||||
if (progress == null)
|
||||
nullProgressListener = new NullProgressListener();
|
||||
FeatureReader<SimpleFeatureType, SimpleFeature> reader = getReader(query);
|
||||
try {
|
||||
float size = (nullProgressListener instanceof NullProgressListener) ? 0.0F : getCount(query);
|
||||
float position = 0.0F;
|
||||
nullProgressListener.started();
|
||||
while (reader.hasNext()) {
|
||||
SimpleFeature feature = null;
|
||||
if (size > 0.0F)
|
||||
nullProgressListener.progress(position++ / size);
|
||||
try {
|
||||
feature = (SimpleFeature)reader.next();
|
||||
visitor.visit((Feature)feature);
|
||||
} catch (IOException erp) {
|
||||
nullProgressListener.exceptionOccurred(erp);
|
||||
throw erp;
|
||||
} catch (Exception unexpected) {
|
||||
nullProgressListener.exceptionOccurred(unexpected);
|
||||
String fid = (feature == null) ? "feature" : feature.getIdentifier().toString();
|
||||
throw new IOException("Problem visiting " + query.getTypeName() + " visiting " + fid +
|
||||
":" + unexpected, unexpected);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
nullProgressListener.complete();
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public final FeatureReader<SimpleFeatureType, SimpleFeature> getReader(Query query) throws IOException {
|
||||
System.out.println("thkim RenderFeatureSource.getReader() called with query: " + query);
|
||||
RenderFeatureReader reader = new RenderFeatureReader(this.delegate, query);
|
||||
if (query != null) {
|
||||
ReferencedEnvelope bbox = new ReferencedEnvelope();
|
||||
if (query.getFilter() != null) {
|
||||
Object boxObj = query.getFilter().accept((FilterVisitor)ExtractBoundsFilterVisitor.BOUNDS_VISITOR, bbox);
|
||||
if (boxObj instanceof ReferencedEnvelope) {
|
||||
bbox = (ReferencedEnvelope)boxObj;
|
||||
} else {
|
||||
bbox = ReferencedEnvelope.reference((Envelope)boxObj);
|
||||
}
|
||||
}
|
||||
if (bbox != null && !bbox.isNull())
|
||||
reader.setTargetBBox(bbox);
|
||||
Hints hints = query.getHints();
|
||||
if (hints != null) {
|
||||
Number simplificationDistance = (Number)hints.get(Hints.GEOMETRY_DISTANCE);
|
||||
if (simplificationDistance != null)
|
||||
reader.setSimplificationDistance(simplificationDistance.doubleValue());
|
||||
ScreenMap sMap = (ScreenMap)hints.get(Hints.SCREENMAP);
|
||||
if (Point.class.isAssignableFrom((
|
||||
(SimpleFeatureType)this.delegate.getSchema()).getGeometryDescriptor().getType().getBinding())) {
|
||||
reader.setScreenMap(ScreenMapRefinder.refindScreenMap(sMap, bbox, 0.5D));
|
||||
} else {
|
||||
reader.setScreenMap(sMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.geotwo.webserver.core.render.layer;
|
||||
|
||||
import com.geotwo.webserver.core.render.style.MapStyle;
|
||||
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)getStyle()).isWrapTileTextStyle();
|
||||
}
|
||||
|
||||
public double getWrapTileText() {
|
||||
return ((MapStyle)getStyle()).getWrapTileText();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.geotwo.webserver.core.render.layer;
|
||||
|
||||
import com.geotwo.webserver.core.coverage.o2layer.O2LayerUtil;
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.layer.O2ImgLayer;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.map.DirectLayer;
|
||||
import org.geotools.map.MapContent;
|
||||
import org.geotools.map.MapViewport;
|
||||
import org.geotools.referencing.CRS;
|
||||
|
||||
public class ExO2ImgLayer extends DirectLayer {
|
||||
private O2ImgLayer imgLayer;
|
||||
|
||||
private ReferencedEnvelope WMS_BBOX;
|
||||
|
||||
private int WMS_WIDTH;
|
||||
|
||||
private int WMS_HEIGHT;
|
||||
|
||||
public ExO2ImgLayer(O2ImgLayer layer, AVList params) throws Exception {
|
||||
this.imgLayer = layer;
|
||||
this.WMS_BBOX = (ReferencedEnvelope)params.getValue("request.wms.bbox");
|
||||
if (!CRS.equalsIgnoreMetadata(
|
||||
layer.getCRS(),
|
||||
this.WMS_BBOX.getCoordinateReferenceSystem()))
|
||||
this.WMS_BBOX = this.WMS_BBOX.transform(layer.getCRS(), true);
|
||||
this.WMS_WIDTH = params.getIntegerValue("request.wms.width").intValue();
|
||||
this.WMS_HEIGHT = params.getIntegerValue("request.wms.height").intValue();
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBounds() {
|
||||
return this.imgLayer.getBBox();
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphics, MapContent map, MapViewport viewport) {
|
||||
try {
|
||||
BufferedImage img = O2LayerUtil.getMap(this.imgLayer.getLevelSet(), this.WMS_BBOX, this.WMS_WIDTH, this.WMS_HEIGHT);
|
||||
graphics.drawImage(img, null, 0, 0);
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[RENDER]", "Fail to render O2ImgLayer :: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
package com.geotwo.webserver.core.render.layer;
|
||||
|
||||
import com.geotwo.webserver.core.log.LogMngr;
|
||||
import com.geotwo.webserver.core.map.layer.LinkLayer;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.geotools.data.ows.HTTPResponse;
|
||||
import org.geotools.data.ows.SimpleHttpClient;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.map.DirectLayer;
|
||||
import org.geotools.map.MapContent;
|
||||
import org.geotools.map.MapViewport;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
|
||||
public class ExWMSLayer extends DirectLayer {
|
||||
final String WMS_LAYERS;
|
||||
|
||||
ReferencedEnvelope WMS_BBOX;
|
||||
|
||||
int WMS_WIDTH;
|
||||
|
||||
int WMS_HEIGHT;
|
||||
|
||||
final String WMS_FORMAT;
|
||||
|
||||
final String WMS_SERVICE;
|
||||
|
||||
final String WMS_VERSION;
|
||||
|
||||
final String WMS_REQUEST;
|
||||
|
||||
final boolean WMS_TRANSPARENT;
|
||||
|
||||
final Color WMS_BGCOLOR;
|
||||
|
||||
final String WMS_STYLES;
|
||||
|
||||
final StyledLayerDescriptor WMS_SLD;
|
||||
|
||||
private final URL layerURL;
|
||||
|
||||
private final ReferencedEnvelope layerBounds;
|
||||
|
||||
public ExWMSLayer(LinkLayer layer, AVList params) throws Exception {
|
||||
if (layer == null || params == null)
|
||||
throw new IllegalArgumentException("WMS request parameter is null.");
|
||||
this.layerBounds = layer.getBBox();
|
||||
this.layerURL = layer.getServiceURL();
|
||||
this.WMS_LAYERS = layer.getServiceLayerNames();
|
||||
this.WMS_BBOX = (ReferencedEnvelope)params.getValue("request.wms.bbox");
|
||||
if (!CRS.equalsIgnoreMetadata(this.layerBounds.getCoordinateReferenceSystem(),
|
||||
this.WMS_BBOX.getCoordinateReferenceSystem()))
|
||||
this.WMS_BBOX = this.WMS_BBOX.transform(this.layerBounds.getCoordinateReferenceSystem(), true);
|
||||
this.WMS_WIDTH = params.getIntegerValue("request.wms.width").intValue();
|
||||
this.WMS_HEIGHT = params.getIntegerValue("request.wms.height").intValue();
|
||||
this.WMS_SERVICE = params.getStringValue("request.wms.service", "WMS");
|
||||
this.WMS_FORMAT = params.getStringValue("request.wms.format", "image/jpeg");
|
||||
this.WMS_VERSION = params.getStringValue("request.wms.version", "1.3.0");
|
||||
this.WMS_REQUEST = params.getStringValue("request.wms.request", "GetMap");
|
||||
this.WMS_TRANSPARENT = params.getBooleanValue("request.wms.transparent", Boolean.valueOf(false)).booleanValue();
|
||||
this.WMS_BGCOLOR = params.getColorValue("request.wms.bgcolor", Color.WHITE);
|
||||
if (ServerUtil.isNullString(params.getStringValue("request.wms.styles"))) {
|
||||
String[] layerNames = this.WMS_LAYERS.split(",");
|
||||
if (layerNames.length == 1) {
|
||||
this.WMS_STYLES = "";
|
||||
} else {
|
||||
String styles = "";
|
||||
for (int i = 1; i < layerNames.length; i++)
|
||||
styles = styles.concat(",");
|
||||
this.WMS_STYLES = styles;
|
||||
}
|
||||
} else {
|
||||
String styleStr = params.getStringValue("request.wms.styles");
|
||||
String[] layerNames = this.WMS_LAYERS.split(",");
|
||||
if (layerNames.length == 1) {
|
||||
this.WMS_STYLES = styleStr;
|
||||
} else {
|
||||
String styles = styleStr;
|
||||
for (int i = 1; i < layerNames.length; i++) {
|
||||
styles = styles.concat(",");
|
||||
styles = styles.concat(styleStr);
|
||||
}
|
||||
this.WMS_STYLES = styles;
|
||||
}
|
||||
}
|
||||
this.WMS_SLD = (StyledLayerDescriptor)params.getValue("request.wms.sld");
|
||||
}
|
||||
|
||||
private URL getRequest() throws MalformedURLException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("?");
|
||||
sb.append("SERVICE=").append(this.WMS_SERVICE).append("&");
|
||||
sb.append("VERSION=").append(this.WMS_VERSION).append("&");
|
||||
sb.append("REQUEST=").append(this.WMS_REQUEST).append("&");
|
||||
sb.append("LAYERS=").append(this.WMS_LAYERS).append("&");
|
||||
sb.append("STYLES=").append(this.WMS_STYLES).append("&");
|
||||
if (this.WMS_VERSION.compareTo("1.3.0") >= 0) {
|
||||
sb.append("CRS=").append(this.WMS_BBOX.getCoordinateReferenceSystem().getIdentifiers().toArray()[0]).append("&");
|
||||
} else {
|
||||
sb.append("SRS=").append(this.WMS_BBOX.getCoordinateReferenceSystem().getIdentifiers().toArray()[0]).append("&");
|
||||
}
|
||||
sb.append("BBOX=").append(this.WMS_BBOX.getMinX()).append(",").append(this.WMS_BBOX.getMinY()).append(",")
|
||||
.append(this.WMS_BBOX.getMaxX()).append(",").append(this.WMS_BBOX.getMaxY()).append("&");
|
||||
sb.append("WIDTH=").append(this.WMS_WIDTH).append("&");
|
||||
sb.append("HEIGHT=").append(this.WMS_HEIGHT).append("&");
|
||||
sb.append("FORMAT=").append(this.WMS_FORMAT).append("&");
|
||||
sb.append("TRANSPARENT=").append(this.WMS_TRANSPARENT).append("&");
|
||||
sb.append("BGCOLOR=").append(ServerUtil.getHexFromColor(this.WMS_BGCOLOR));
|
||||
return new URL(this.layerURL, sb.toString());
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphics, MapContent map, MapViewport viewport) {
|
||||
try {
|
||||
URL url = getRequest();
|
||||
SimpleHttpClient client = new SimpleHttpClient();
|
||||
HTTPResponse reponse = client.get(url);
|
||||
BufferedImage image = ImageIO.read(reponse.getResponseStream());
|
||||
graphics.drawImage(image, 0, 0, null);
|
||||
} catch (Exception e) {
|
||||
LogMngr.getInstance().logError("[RENDER]",
|
||||
"Fail to render WMSLayer :: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public ReferencedEnvelope getBounds() {
|
||||
return this.layerBounds;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,678 @@
|
|||
package com.geotwo.webserver.core.render.legend;
|
||||
|
||||
import com.geotwo.webserver.core.ServerContext;
|
||||
import com.geotwo.webserver.core.map.layer.FeatureLayer;
|
||||
import com.geotwo.webserver.core.map.layer.GroupLayer;
|
||||
import com.geotwo.webserver.core.map.layer.Layer;
|
||||
import com.geotwo.webserver.core.render.StyleMngr;
|
||||
import com.geotwo.webserver.core.util.AVList;
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import com.geotwo.webserver.core.vector.O2DSMngr;
|
||||
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.RenderingHints;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
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.PointSymbolizer;
|
||||
import org.geotools.styling.PolygonSymbolizer;
|
||||
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.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.style.GraphicLegend;
|
||||
import org.opengis.util.InternationalString;
|
||||
|
||||
public class LegendGraphicBuilder {
|
||||
public static final double TOLERANCE = 1.0E-6D;
|
||||
|
||||
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.0D;
|
||||
|
||||
private final int DEFAULT_WIDTH = 32;
|
||||
|
||||
private final int DEFAULT_HEIGHT = 32;
|
||||
|
||||
private final double DEFAULT_SCALE = -1.0D;
|
||||
|
||||
private final AVList parameters;
|
||||
|
||||
private final HashMap<String, String> legendOption;
|
||||
|
||||
public LegendGraphicBuilder(AVList params) {
|
||||
this.parameters = params;
|
||||
this.legendOption = new HashMap<String, String>();
|
||||
String optionStr = this.parameters.getStringValue("legend.graphic.option");
|
||||
if (optionStr != null) {
|
||||
optionStr = optionStr.toUpperCase();
|
||||
String[] options = optionStr.split(";");
|
||||
byte b;
|
||||
int i;
|
||||
String[] arrayOfString1;
|
||||
for (i = (arrayOfString1 = options).length, b = 0; b < i; ) {
|
||||
String kvStr = arrayOfString1[b];
|
||||
String[] kv = kvStr.trim().split(":");
|
||||
if (kv.length >= 2)
|
||||
this.legendOption.put(kv[0].trim().toUpperCase(), kv[1].trim().toUpperCase());
|
||||
b++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage buildLegendGraphic() throws Exception {
|
||||
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(layerName))
|
||||
throw new IllegalArgumentException("Layer parameter [" + layerName + "] is not available.");
|
||||
List<FeatureType> layers = new ArrayList<FeatureType>();
|
||||
List<Style> styles = new ArrayList<Style>();
|
||||
Layer serviceLayer = ServerContext.getMap().getLayer(layerName);
|
||||
if (serviceLayer instanceof FeatureLayer) {
|
||||
FeatureLayer fLayer = (FeatureLayer)serviceLayer;
|
||||
SimpleFeatureSource featureSource =
|
||||
O2DSMngr.getFeatureSource(fLayer.getLayerType(), fLayer.getServerName(), fLayer.getSourceName());
|
||||
layers.add(featureSource.getSchema());
|
||||
Style style = getRenderedStyle(fLayer, styleName, sld);
|
||||
styles.add(style);
|
||||
} else if (serviceLayer instanceof GroupLayer) {
|
||||
GroupLayer gLayer = (GroupLayer)serviceLayer;
|
||||
for (FeatureLayer gfLayer : gLayer.getLayerList()) {
|
||||
FeatureLayer fLayer = gfLayer;
|
||||
SimpleFeatureSource featureSource =
|
||||
O2DSMngr.getFeatureSource(fLayer.getLayerType(), fLayer.getServerName(), fLayer.getSourceName());
|
||||
layers.add(featureSource.getSchema());
|
||||
Style style = getRenderedStyle(fLayer, styleName, sld);
|
||||
styles.add(style);
|
||||
}
|
||||
} 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.valueOf(Double.parseDouble(this.legendOption.get("DPI")));
|
||||
double standardDpi = RendererUtilities.getDpi(Collections.emptyMap());
|
||||
if (dpi.doubleValue() != standardDpi) {
|
||||
scaleFactor = Double.valueOf(dpi.doubleValue() / standardDpi);
|
||||
width = Integer.valueOf((int)Math.round(width.intValue() * scaleFactor.doubleValue()));
|
||||
height = Integer.valueOf((int)Math.round(height.intValue() * scaleFactor.doubleValue()));
|
||||
}
|
||||
} 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.0D));
|
||||
Double pixelsPerMeters = null;
|
||||
try {
|
||||
if (scale.doubleValue() > 0.0D) {
|
||||
Map<String, Double> dpiMap = Collections.EMPTY_MAP;
|
||||
if (dpi != null)
|
||||
dpiMap.put("dpi", dpi);
|
||||
pixelsPerMeters = Double.valueOf(RendererUtilities.calculatePixelsPerMeterRatio(scale.doubleValue(), 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) {
|
||||
String forceLabelsOpt = this.legendOption.get("FORCELABELS");
|
||||
if (forceLabelsOpt.equalsIgnoreCase("ON") || forceLabelsOpt.equalsIgnoreCase("YES") ||
|
||||
forceLabelsOpt.equalsIgnoreCase("TRUE") || forceLabelsOpt.equalsIgnoreCase("1"))
|
||||
forceLabelsOn = true;
|
||||
}
|
||||
boolean forceTitlesOn = false;
|
||||
if (this.legendOption.get("FORCETITLES") instanceof String) {
|
||||
String forceTitlesOpt = this.legendOption.get("FORCETITLES");
|
||||
if (forceTitlesOpt.equalsIgnoreCase("ON") || forceTitlesOpt.equalsIgnoreCase("YES") ||
|
||||
forceTitlesOpt.equalsIgnoreCase("TRUE") || forceTitlesOpt.equalsIgnoreCase("1"))
|
||||
forceTitlesOn = true;
|
||||
}
|
||||
double minimumSymbolSize = 3.0D;
|
||||
try {
|
||||
String minSymbolSizeOpt = this.legendOption.get("MINSYMBOLSIZE");
|
||||
minimumSymbolSize = Double.parseDouble(minSymbolSizeOpt);
|
||||
} catch (Exception exception) {}
|
||||
List<RenderedImage> layersImages = new ArrayList<RenderedImage>();
|
||||
if (forceTitlesOn) {
|
||||
RenderedImage titleImage = getLayerTitle(serviceLayer.getName(), width.intValue(), height.intValue(), transparent);
|
||||
if (titleImage != null)
|
||||
layersImages.add(titleImage);
|
||||
}
|
||||
for (int pos = 0; pos < layers.size(); pos++) {
|
||||
Feature sampleFeature;
|
||||
Rule[] applicableRules;
|
||||
FeatureType renderLayer = layers.get(pos);
|
||||
Style renderStyle = 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<FeatureTypeStyle> ftsList = renderStyle.featureTypeStyles();
|
||||
for (int i = 0; i < ftsList.size(); i++) {
|
||||
FeatureTypeStyle fts = ftsList.get(i);
|
||||
Expression exp = fts.getTransformation();
|
||||
if (exp != null) {
|
||||
ProcessFunction processFunction = (ProcessFunction)exp;
|
||||
Name processName = processFunction.getProcessName();
|
||||
Map<String, Parameter<?>> outputs = Processors.getResultInfo(processName, null);
|
||||
if (!outputs.isEmpty()) {
|
||||
Parameter<?> output = outputs.values().iterator().next();
|
||||
if (SimpleFeatureCollection.class.isAssignableFrom(output.getType())) {
|
||||
hasVectorTransformation = true;
|
||||
break;
|
||||
}
|
||||
if (GridCoverage2D.class.isAssignableFrom(output.getType())) {
|
||||
hasRasterTransformation = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasVectorTransformation) {
|
||||
SimpleFeature simpleFeature = createSampleFeature();
|
||||
} else {
|
||||
sampleFeature = createSampleFeature(renderLayer);
|
||||
}
|
||||
FeatureTypeStyle[] ftStyles = (FeatureTypeStyle[])renderStyle.featureTypeStyles().toArray((Object[])new FeatureTypeStyle[0]);
|
||||
if (ruleName != null) {
|
||||
Rule rule = LegendUtils.getRule(ftStyles, 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(ftStyles, scale.doubleValue());
|
||||
}
|
||||
SLDStyleFactory styleFactory = new SLDStyleFactory();
|
||||
NumberRange<Double> scaleRange = NumberRange.create(scale.doubleValue(), scale.doubleValue());
|
||||
double symbolScale = calcSymbolScale(width.intValue(), height.intValue(), renderLayer, sampleFeature, applicableRules, minimumSymbolSize);
|
||||
List<RenderedImage> legendsStack = new ArrayList<RenderedImage>(applicableRules.length);
|
||||
for (int j = 0; j < applicableRules.length; j++) {
|
||||
BufferedImage bufferedImage = createImage(width.intValue(), height.intValue(), transparent);
|
||||
Color backgroundColor = LegendUtils.getBackgroundColor(this.legendOption);
|
||||
Graphics2D graphics = prepareTransparency(transparent, backgroundColor, bufferedImage);
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
Feature sample = getSampleFeatureForRule(renderLayer, sampleFeature, applicableRules[j]);
|
||||
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
|
||||
Symbolizer[] symbolizers = applicableRules[j].getSymbolizers();
|
||||
GraphicLegend legend = applicableRules[j].getLegend();
|
||||
if (legend != null) {
|
||||
if (this.samplePoint == null) {
|
||||
Coordinate coord = new Coordinate((width.intValue() / 2), (height.intValue() / 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 {
|
||||
for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
|
||||
PointSymbolizer pointSymbolizer;
|
||||
Symbolizer symbolizer = symbolizers[sIdx];
|
||||
if (symbolizer instanceof org.geotools.styling.RasterSymbolizer)
|
||||
throw new IllegalStateException("It is not legal to have a RasterSymbolizer here");
|
||||
if (symbolScale > 1.0D && symbolizer instanceof PointSymbolizer) {
|
||||
PointSymbolizer pointSymbolizer1 = cloneSymbolizer(symbolizer);
|
||||
if (pointSymbolizer1.getGraphic() != null) {
|
||||
double size = getPointSymbolizerSize(sample, pointSymbolizer1, Math.min(width.intValue(), height.intValue()) - 4);
|
||||
pointSymbolizer1.getGraphic().setSize((Expression)ff.literal(size / symbolScale + minimumSymbolSize));
|
||||
pointSymbolizer = pointSymbolizer1;
|
||||
}
|
||||
}
|
||||
Style2D style2d = styleFactory.createStyle(sample, (Symbolizer)pointSymbolizer, (Range)scaleRange);
|
||||
LiteShape2 shape = getSampleShape((Symbolizer)pointSymbolizer, width.intValue(), height.intValue());
|
||||
if (style2d != null)
|
||||
shapePainter.paint(graphics, shape, style2d, scale.doubleValue());
|
||||
}
|
||||
}
|
||||
legendsStack.add(bufferedImage);
|
||||
graphics.dispose();
|
||||
}
|
||||
BufferedImage image = mergeLegends(legendsStack, applicableRules, forceLabelsOn, transparent);
|
||||
if (image != null)
|
||||
layersImages.add(image);
|
||||
}
|
||||
BufferedImage finalLegend = 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) {
|
||||
ArrayList<Style> styleList;
|
||||
if (ServerUtil.isNullString(styleName)) {
|
||||
styleList = StyleMngr.getStylesFromSLD(layer.getName(), sld);
|
||||
} else {
|
||||
styleList = StyleMngr.getStylesFromSLD(layer.getName(), styleName, sld);
|
||||
}
|
||||
if (styleList.size() == 0)
|
||||
return layer.getRenderStyle(styleName);
|
||||
for (Style style1 : styleList) {
|
||||
if (style1.isDefault()) {
|
||||
if (style1 instanceof org.geotools.styling.NamedStyle)
|
||||
return layer.getRenderStyle(style1.getName());
|
||||
return style1;
|
||||
}
|
||||
}
|
||||
Style style = styleList.get(0);
|
||||
if (style instanceof org.geotools.styling.NamedStyle)
|
||||
return layer.getRenderStyle(style.getName());
|
||||
return style;
|
||||
}
|
||||
|
||||
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();
|
||||
Map<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 = createImage(w, h, transparent);
|
||||
return 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(label, graphics, this.legendOption);
|
||||
}
|
||||
|
||||
private SimpleFeature createSampleFeature() {
|
||||
SimpleFeatureType type;
|
||||
try {
|
||||
type = DataUtilities.createType("Sample", "the_geom:Geometry");
|
||||
} catch (SchemaException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return SimpleFeatureBuilder.template(type, null);
|
||||
}
|
||||
|
||||
private Feature createSampleFeature(FeatureType schema) {
|
||||
Feature sampleFeature;
|
||||
try {
|
||||
if (schema instanceof SimpleFeatureType) {
|
||||
if (hasMixedGeometry((SimpleFeatureType)schema)) {
|
||||
sampleFeature = null;
|
||||
} else {
|
||||
SimpleFeature simpleFeature = SimpleFeatureBuilder.template((SimpleFeatureType)schema, null);
|
||||
}
|
||||
} else {
|
||||
sampleFeature = DataUtilities.templateFeature(schema);
|
||||
}
|
||||
} catch (IllegalAttributeException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return sampleFeature;
|
||||
}
|
||||
|
||||
private boolean hasMixedGeometry(SimpleFeatureType schema) {
|
||||
for (AttributeDescriptor attDesc : schema.getAttributeDescriptors()) {
|
||||
if (isMixedGeometry(attDesc))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isMixedGeometry(AttributeDescriptor attDesc) {
|
||||
if (attDesc instanceof GeometryDescriptor &&
|
||||
attDesc.getType().getBinding() == Geometry.class)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private double calcSymbolScale(int width, int height, FeatureType featureType, Feature feature, Rule[] rules, double minimumSymbolsSize) {
|
||||
double minSize = Double.MAX_VALUE;
|
||||
double maxSize = 0.0D;
|
||||
int ruleCount = rules.length;
|
||||
for (int i = 0; i < ruleCount; i++) {
|
||||
Feature sample = getSampleFeatureForRule(featureType, feature, rules[i]);
|
||||
Symbolizer[] symbolizers = rules[i].getSymbolizers();
|
||||
for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
|
||||
Symbolizer symbolizer = symbolizers[sIdx];
|
||||
if (symbolizer instanceof PointSymbolizer) {
|
||||
double size = getPointSymbolizerSize(sample,
|
||||
(PointSymbolizer)symbolizer, Math.min(width, height));
|
||||
if (size < minSize)
|
||||
minSize = size;
|
||||
if (size > maxSize)
|
||||
maxSize = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (minSize != maxSize)
|
||||
return (maxSize - minSize + 1.0D) / (Math.min(width, height) - minimumSymbolsSize);
|
||||
return maxSize / (Math.min(width, height) - minimumSymbolsSize);
|
||||
}
|
||||
|
||||
private Feature getSampleFeatureForRule(FeatureType featureType, Feature sample, Rule rule) {
|
||||
Symbolizer[] symbolizers = rule.getSymbolizers();
|
||||
if (sample == null) {
|
||||
int dimensionality = 1;
|
||||
for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
|
||||
Symbolizer symbolizer = symbolizers[sIdx];
|
||||
if (LineSymbolizer.class.isAssignableFrom(symbolizer.getClass()))
|
||||
dimensionality = 2;
|
||||
if (PolygonSymbolizer.class.isAssignableFrom(symbolizer.getClass()))
|
||||
dimensionality = 3;
|
||||
}
|
||||
return createSampleFeature(featureType, dimensionality);
|
||||
}
|
||||
return sample;
|
||||
}
|
||||
|
||||
private Feature createSampleFeature(FeatureType schema, int dimensionality) {
|
||||
if (schema instanceof SimpleFeatureType)
|
||||
schema = cloneWithDimensionality(schema, dimensionality);
|
||||
return 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 (isMixedGeometry(desc)) {
|
||||
GeometryDescriptor geomDescriptor = (GeometryDescriptor)desc;
|
||||
GeometryType geomType = geomDescriptor.getType();
|
||||
Class<?> geometryClass = getGeometryForDimensionality(dimensionality);
|
||||
GeometryTypeImpl geometryTypeImpl = new GeometryTypeImpl(geomType.getName(),
|
||||
geometryClass, geomType.getCoordinateReferenceSystem(),
|
||||
geomType.isIdentified(), geomType.isAbstract(),
|
||||
geomType.getRestrictions(), geomType.getSuper(),
|
||||
geomType.getDescription());
|
||||
builder.add((AttributeDescriptor)new GeometryDescriptorImpl((GeometryType)geometryTypeImpl,
|
||||
geomDescriptor.getName(), geomDescriptor.getMinOccurs(),
|
||||
geomDescriptor.getMaxOccurs(), geomDescriptor.isNillable(),
|
||||
geomDescriptor.getDefaultValue()));
|
||||
continue;
|
||||
}
|
||||
builder.add(desc);
|
||||
}
|
||||
return (FeatureType)builder.buildFeatureType();
|
||||
}
|
||||
|
||||
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) {
|
||||
if (pointSymbolizer.getGraphic() != null) {
|
||||
Expression sizeExp = pointSymbolizer.getGraphic().getSize();
|
||||
if (sizeExp instanceof org.opengis.filter.expression.Literal) {
|
||||
Object size = sizeExp.evaluate(feature);
|
||||
if (size != null) {
|
||||
if (size instanceof Double)
|
||||
return ((Double)size).doubleValue();
|
||||
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 = legendWidth * 0.15F;
|
||||
float vpad = legendHeight * 0.15F;
|
||||
if (symbolizer instanceof LineSymbolizer) {
|
||||
if (this.sampleLine == null) {
|
||||
Coordinate[] coords = { new Coordinate(hpad, (legendHeight - vpad - 1.0F)),
|
||||
new Coordinate((legendWidth - hpad - 1.0F), 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 org.geotools.styling.RasterSymbolizer) {
|
||||
if (this.sampleRect == null) {
|
||||
float w = legendWidth - 2.0F * hpad - 1.0F;
|
||||
float h = legendHeight - 2.0F * vpad - 1.0F;
|
||||
Coordinate[] coords = { new Coordinate(hpad, vpad), new Coordinate(hpad, (vpad + h)),
|
||||
new Coordinate((hpad + w), (vpad + h)), new Coordinate((hpad + w), vpad),
|
||||
new Coordinate(hpad, 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 org.geotools.styling.TextSymbolizer) {
|
||||
if (this.samplePoint == null) {
|
||||
Coordinate coord = new Coordinate((legendWidth / 2), (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];
|
||||
for (int i = 0; i < imgCount; i++) {
|
||||
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 {
|
||||
Rule rule = rules[i];
|
||||
Description description = rule.getDescription();
|
||||
if (description != null && description.getTitle() != null) {
|
||||
InternationalString title = description.getTitle();
|
||||
if (!ServerUtil.isNullString(title.toString()))
|
||||
labels[i] = title.toString();
|
||||
}
|
||||
if (ServerUtil.isNullString(labels[i]))
|
||||
if (ServerUtil.isNullString(rule.getName())) {
|
||||
labels[i] = "RULE " + i;
|
||||
} else {
|
||||
labels[i] = rule.getName();
|
||||
}
|
||||
if (labels[i] != null && labels[i].length() > 0) {
|
||||
BufferedImage renderedLabel = getRenderedLabel(img, labels[i]);
|
||||
labelsGraphics[i] = renderedLabel;
|
||||
Rectangle2D bounds = new Rectangle2D.Double(0.0D, 0.0D,
|
||||
renderedLabel.getWidth(),
|
||||
renderedLabel.getHeight());
|
||||
totalWidth = (int)Math.ceil(Math.max(img.getWidth() + bounds.getWidth(), totalWidth));
|
||||
rowHeights[i] = (int)Math.ceil(Math.max(img.getHeight(), 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];
|
||||
}
|
||||
}
|
||||
totalWidth += 2;
|
||||
finalLegend = createImage(totalWidth, totalHeight, transparent);
|
||||
Color backgroundColor = LegendUtils.getBackgroundColor(this.legendOption);
|
||||
Graphics2D finalGraphics = prepareTransparency(transparent, backgroundColor, finalLegend);
|
||||
int topOfRow = 0;
|
||||
for (int j = 0; j < imgCount; j++) {
|
||||
img = (BufferedImage)imageStack.get(j);
|
||||
int y = topOfRow;
|
||||
if (img.getHeight() < rowHeights[j])
|
||||
y += (int)((rowHeights[j] - img.getHeight()) / 2.0D);
|
||||
finalGraphics.drawImage(img, 0, y, (ImageObserver)null);
|
||||
if (!forceLabelsOn || rules == null) {
|
||||
topOfRow += rowHeights[j];
|
||||
} 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[j] != null && labels[j].length() > 0) {
|
||||
BufferedImage renderedLabel = labelsGraphics[j];
|
||||
y = topOfRow;
|
||||
if (renderedLabel.getHeight() < rowHeights[j])
|
||||
y += (int)((rowHeights[j] - renderedLabel.getHeight()) / 2.0D);
|
||||
finalGraphics.drawImage(renderedLabel, img.getWidth(), y, (ImageObserver)null);
|
||||
renderedLabel.flush();
|
||||
labelsGraphics[j] = null;
|
||||
}
|
||||
topOfRow += rowHeights[j];
|
||||
}
|
||||
}
|
||||
finalGraphics.dispose();
|
||||
}
|
||||
return finalLegend;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
package com.geotwo.webserver.core.render.legend;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
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 enum VAlign {
|
||||
TOP, MIDDLE, BOTTOM;
|
||||
}
|
||||
|
||||
public enum HAlign {
|
||||
LEFT, CENTERED, RIGHT, JUSTIFIED;
|
||||
}
|
||||
|
||||
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) {
|
||||
BufferedImage renderedLabel;
|
||||
Color labelColor = getLabelFontColor(legendOption);
|
||||
if (label.indexOf("\n") != -1 || label.indexOf("\\n") != -1) {
|
||||
Rectangle2D bounds = new Rectangle2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
|
||||
ArrayList<Integer> lineHeight = new ArrayList<Integer>();
|
||||
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<Rule> ruleList = new ArrayList<Rule>();
|
||||
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 ruleList.<Rule>toArray(new Rule[ruleList.size()]);
|
||||
}
|
||||
|
||||
public static boolean isWithInScale(Rule r, double scaleDenominator) {
|
||||
return !(scaleDenominator != -1.0D && (
|
||||
r.getMinScaleDenominator() - 1.0E-6D > scaleDenominator ||
|
||||
r.getMaxScaleDenominator() + 1.0E-6D <= 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.geotwo.webserver.core.render.sld;
|
||||
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import javax.xml.namespace.QName;
|
||||
import org.geotools.se.v1_1.SE;
|
||||
import org.geotools.styling.ColorMap;
|
||||
import org.geotools.styling.ColorMapEntry;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.xml.AbstractComplexBinding;
|
||||
import org.geotools.xml.ElementInstance;
|
||||
import org.geotools.xml.Node;
|
||||
import org.opengis.filter.FilterFactory;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
|
||||
public class CategorizeBinding110 extends AbstractComplexBinding {
|
||||
StyleFactory styleFactory;
|
||||
|
||||
FilterFactory filterFactory;
|
||||
|
||||
public CategorizeBinding110(StyleFactory styleFactory, FilterFactory filterFactory) {
|
||||
this.styleFactory = styleFactory;
|
||||
this.filterFactory = filterFactory;
|
||||
}
|
||||
|
||||
public QName getTarget() {
|
||||
return SE.Categorize;
|
||||
}
|
||||
|
||||
public Class getType() {
|
||||
return ColorMap.class;
|
||||
}
|
||||
|
||||
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
|
||||
ColorMap map = this.styleFactory.createColorMap();
|
||||
String type = (String)node.getAttributeValue("type");
|
||||
if (type == null || type.equalsIgnoreCase("intervals")) {
|
||||
map.setType(2);
|
||||
} else {
|
||||
map.setType(3);
|
||||
}
|
||||
List<Node> children = node.getChildren();
|
||||
int i = 0;
|
||||
while (!"Threshold".equals(((Node)children.get(i)).getComponent().getName()))
|
||||
i++;
|
||||
while (i < children.size()) {
|
||||
ColorMapEntry entry = this.styleFactory.createColorMapEntry();
|
||||
double quantity = Double.parseDouble(((Node)children.get(i)).getValue().toString());
|
||||
entry.setQuantity((Expression)this.filterFactory.literal(quantity));
|
||||
if (i + 1 >= children.size())
|
||||
throw new IllegalArgumentException("Incorrectly specified color map Threshold/Value pair");
|
||||
String colorStr = ((Node)children.get(i + 1)).getValue().toString();
|
||||
Color color = ServerUtil.getColorFromHex(colorStr);
|
||||
double opacity = color.getAlpha() / 255.0D;
|
||||
entry.setOpacity((Expression)this.filterFactory.literal(String.format("%.2f", new Object[] { Double.valueOf(opacity) })));
|
||||
entry.setColor((Expression)this.filterFactory.literal(ServerUtil.getHexFromColor(color)));
|
||||
map.addColorMapEntry(entry);
|
||||
i += 2;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.geotwo.webserver.core.render.sld;
|
||||
|
||||
import com.geotwo.webserver.core.util.ServerUtil;
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import javax.xml.namespace.QName;
|
||||
import org.geotools.se.v1_1.SE;
|
||||
import org.geotools.styling.ColorMap;
|
||||
import org.geotools.styling.ColorMapEntry;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.xml.AbstractComplexBinding;
|
||||
import org.geotools.xml.ElementInstance;
|
||||
import org.geotools.xml.Node;
|
||||
import org.opengis.filter.FilterFactory;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
|
||||
public class InterpolateBinding110 extends AbstractComplexBinding {
|
||||
StyleFactory styleFactory;
|
||||
|
||||
FilterFactory filterFactory;
|
||||
|
||||
public InterpolateBinding110(StyleFactory styleFactory, FilterFactory filterFactory) {
|
||||
this.styleFactory = styleFactory;
|
||||
this.filterFactory = filterFactory;
|
||||
}
|
||||
|
||||
public QName getTarget() {
|
||||
return SE.Interpolate;
|
||||
}
|
||||
|
||||
public Class getType() {
|
||||
return ColorMap.class;
|
||||
}
|
||||
|
||||
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
|
||||
ColorMap map = this.styleFactory.createColorMap();
|
||||
List<Node> children = node.getChildren("InterpolationPoint");
|
||||
for (Node child : children) {
|
||||
ColorMapEntry entry = this.styleFactory.createColorMapEntry();
|
||||
double quantity = Double.parseDouble(child.getChildValue("Data").toString());
|
||||
entry.setQuantity((Expression)this.filterFactory.literal(quantity));
|
||||
String colorStr = child.getChildValue("Value").toString();
|
||||
Color color = ServerUtil.getColorFromHex(colorStr);
|
||||
double opacity = color.getAlpha() / 255.0D;
|
||||
entry.setOpacity((Expression)this.filterFactory.literal(String.format("%.2f", new Object[] { Double.valueOf(opacity) })));
|
||||
entry.setColor((Expression)this.filterFactory.literal(ServerUtil.getHexFromColor(color)));
|
||||
map.addColorMapEntry(entry);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.geotwo.webserver.core.render.sld;
|
||||
|
||||
import com.geotwo.webserver.core.render.O2StyleFactory;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.QName;
|
||||
import org.geotools.se.v1_1.SE;
|
||||
import org.geotools.se.v1_1.SEConfiguration;
|
||||
import org.geotools.sld.v1_1.SLD;
|
||||
import org.geotools.sld.v1_1.bindings.NamedLayerBinding;
|
||||
import org.geotools.sld.v1_1.bindings.NamedStyleBinding;
|
||||
import org.geotools.sld.v1_1.bindings.RemoteOWSBinding;
|
||||
import org.geotools.sld.v1_1.bindings.UserLayerBinding;
|
||||
import org.geotools.sld.v1_1.bindings.UserStyleBinding;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.xml.Configuration;
|
||||
import org.geotools.xml.XSD;
|
||||
import org.geotools.xs.XS;
|
||||
import org.picocontainer.MutablePicoContainer;
|
||||
|
||||
public class SLDConfiguration110 extends Configuration {
|
||||
public SLDConfiguration110() {
|
||||
super((XSD)SLD.getInstance());
|
||||
addDependency((Configuration)new SEConfiguration());
|
||||
}
|
||||
|
||||
protected void registerBindings(Map bindings) {
|
||||
bindings.put(SLD.StyledLayerDescriptor, StyledLayerDescriptorBinding110.class);
|
||||
bindings.put(SLD.NamedLayer, NamedLayerBinding.class);
|
||||
bindings.put(SLD.UserLayer, UserLayerBinding.class);
|
||||
bindings.put(SLD.NamedStyle, NamedStyleBinding.class);
|
||||
bindings.put(SLD.UserStyle, UserStyleBinding.class);
|
||||
bindings.put(SLD.RemoteOWS, RemoteOWSBinding.class);
|
||||
bindings.put(SE.Categorize, CategorizeBinding110.class);
|
||||
bindings.put(SE.Interpolate, InterpolateBinding110.class);
|
||||
bindings.put(XS.BOOLEAN, XSBooleanBinding110.class);
|
||||
}
|
||||
|
||||
protected void configureContext(MutablePicoContainer container) {
|
||||
super.configureContext(container);
|
||||
container.registerComponentImplementation(StyleFactory.class, O2StyleFactory.class);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,35 @@
|
|||
package com.geotwo.webserver.core.render.sld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.geotools.sld.v1_1.bindings.StyledLayerDescriptorBinding;
|
||||
import org.geotools.styling.StyleFactory;
|
||||
import org.geotools.styling.StyledLayer;
|
||||
import org.geotools.styling.StyledLayerDescriptor;
|
||||
import org.geotools.xml.ElementInstance;
|
||||
import org.geotools.xml.Node;
|
||||
|
||||
public class StyledLayerDescriptorBinding110 extends StyledLayerDescriptorBinding {
|
||||
public StyledLayerDescriptorBinding110(StyleFactory styleFactory) {
|
||||
super(styleFactory);
|
||||
}
|
||||
|
||||
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
|
||||
StyledLayerDescriptor sld = (StyledLayerDescriptor)super.parse(instance, node, value);
|
||||
ArrayList<StyledLayer> layers = new ArrayList<StyledLayer>();
|
||||
List<Node> list = node.getChildren();
|
||||
Iterator<Node> iter = list.iterator();
|
||||
while (iter.hasNext()) {
|
||||
org.geotools.xml.Node child = iter.next();
|
||||
if (child.getValue() instanceof org.geotools.styling.NamedLayer) {
|
||||
layers.add((StyledLayer)child.getValue());
|
||||
continue;
|
||||
}
|
||||
if (child.getValue() instanceof org.geotools.styling.UserLayer)
|
||||
layers.add((StyledLayer)child.getValue());
|
||||
}
|
||||
sld.setStyledLayers(layers.<StyledLayer>toArray(new StyledLayer[layers.size()]));
|
||||
return sld;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.geotwo.webserver.core.render.sld;
|
||||
|
||||
import org.geotools.xml.InstanceComponent;
|
||||
import org.geotools.xs.bindings.XSBooleanBinding;
|
||||
|
||||
public class XSBooleanBinding110 extends XSBooleanBinding {
|
||||
public Object parse(InstanceComponent instance, Object value) throws Exception {
|
||||
String bStr = value.toString();
|
||||
if ("1".equalsIgnoreCase(bStr) || "TRUE".equalsIgnoreCase(bStr) || "Y".equalsIgnoreCase(bStr))
|
||||
return Boolean.TRUE;
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package com.geotwo.webserver.core.render.style;
|
||||
|
||||
import com.geotwo.webserver.core.map.LayerFactory;
|
||||
import org.geotools.styling.StyleImpl;
|
||||
|
||||
public class MapStyle extends StyleImpl {
|
||||
private LayerFactory.LayerType layerType;
|
||||
|
||||
private String serverName;
|
||||
|
||||
private String typeName;
|
||||
|
||||
private Double wrapTileText;
|
||||
|
||||
public MapStyle() {
|
||||
setName("");
|
||||
if (getDescription() != null) {
|
||||
getDescription().setTitle("");
|
||||
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 double getWrapTileText() {
|
||||
if (this.wrapTileText == null || this.wrapTileText.doubleValue() <= 0.0D)
|
||||
return 0.0D;
|
||||
return this.wrapTileText.doubleValue();
|
||||
}
|
||||
|
||||
public void setWrapTileText(double dValue) {
|
||||
if (dValue > 1.0D)
|
||||
dValue = 1.0D;
|
||||
if (this.wrapTileText == null || this.wrapTileText.doubleValue() <= 0.0D) {
|
||||
this.wrapTileText = Double.valueOf(dValue);
|
||||
} else if (this.wrapTileText.doubleValue() < dValue) {
|
||||
this.wrapTileText = Double.valueOf(dValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.geotwo.webserver.core.render.style;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
import org.geotools.renderer.style.MarkFactory;
|
||||
import org.opengis.feature.Feature;
|
||||
import org.opengis.filter.expression.Expression;
|
||||
|
||||
public class O2WellKnownMarkFactory implements MarkFactory {
|
||||
public Shape getShape(Graphics2D graphics, Expression symbolUrl, Feature feature) throws Exception {
|
||||
if (symbolUrl == null)
|
||||
return null;
|
||||
String wellKnownName = (String)symbolUrl.evaluate(feature, String.class);
|
||||
if (wellKnownName.equalsIgnoreCase("o2circle"))
|
||||
return new Ellipse2D.Double(-0.4D, -0.4D, 0.8D, 0.8D);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,74 @@
|
|||
package com.geotwo.webserver.core.render.style.label;
|
||||
|
||||
import org.geotools.geometry.jts.LiteShape2;
|
||||
import org.geotools.renderer.label.LabelCacheItem;
|
||||
import org.geotools.renderer.style.TextStyle2D;
|
||||
import org.geotools.styling.TextSymbolizer;
|
||||
|
||||
public class LabelCacheItemEx extends LabelCacheItem {
|
||||
private TextSymbolizer.PolygonAlignOptions polygonAlign = TextSymbolizer.PolygonAlignOptions.NONE;
|
||||
|
||||
public static final String KEY_SPLIT_MULTIGEOMETRY = "splitMultiGeometry";
|
||||
|
||||
private boolean isSplitMultiGeometry = false;
|
||||
|
||||
public static final String KEY_MIN_FONT_SIZE = "minFontSize";
|
||||
|
||||
private int minFontSize = 3;
|
||||
|
||||
public static final String KEY_POLYGON_ALIGN_TEXT = "polygonAlignText";
|
||||
|
||||
public enum PolygonAlignTextOptions {
|
||||
NONE, MANUAL, ORTHO, MBR;
|
||||
}
|
||||
|
||||
private PolygonAlignTextOptions polygonAlignText = PolygonAlignTextOptions.NONE;
|
||||
|
||||
public static final String KEY_WRAP_TILE_TEXT = "wrapTileText";
|
||||
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX = "textGraphicBox";
|
||||
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX_MARGIN = "textGraphicBox-margin";
|
||||
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX_FILL = "textGraphicBox-fill";
|
||||
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX_STROKE = "textGraphicBox-stroke";
|
||||
|
||||
public static final String KEY_TEXT_GRAPHIC_BOX_STROKE_WIDTH = "textGraphicBox-strokeWidth";
|
||||
|
||||
public LabelCacheItemEx(String layerId, TextStyle2D textStyle, LiteShape2 shape, String label, TextSymbolizer symbolizer) {
|
||||
super(layerId, textStyle, shape, label, symbolizer);
|
||||
}
|
||||
|
||||
public void setPolygonAlignText(PolygonAlignTextOptions polygonAlign) {
|
||||
this.polygonAlignText = polygonAlign;
|
||||
}
|
||||
|
||||
public PolygonAlignTextOptions getPolygonAlignText() {
|
||||
return this.polygonAlignText;
|
||||
}
|
||||
|
||||
public void setPolygonAlign(TextSymbolizer.PolygonAlignOptions polygonAlign) {
|
||||
this.polygonAlign = polygonAlign;
|
||||
}
|
||||
|
||||
public TextSymbolizer.PolygonAlignOptions getPolygonAlign() {
|
||||
return this.polygonAlign;
|
||||
}
|
||||
|
||||
public void setMinFontSize(int size) {
|
||||
this.minFontSize = size;
|
||||
}
|
||||
|
||||
public int getMinFontSize() {
|
||||
return this.minFontSize;
|
||||
}
|
||||
|
||||
public void setSplitMultiGeometry(boolean split) {
|
||||
this.isSplitMultiGeometry = split;
|
||||
}
|
||||
|
||||
public boolean isSplitMultiGeometry() {
|
||||
return this.isSplitMultiGeometry;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package com.geotwo.webserver.core.render.style.label;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
import java.awt.Font;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
public class LabelInfo {
|
||||
public final LabelPainterEx labelPainter;
|
||||
|
||||
public final Polygon polygon;
|
||||
|
||||
public final GeneralPath generalPath;
|
||||
|
||||
public final Font font;
|
||||
|
||||
public final double anchorX;
|
||||
|
||||
public final double anchorY;
|
||||
|
||||
public final double displacementX;
|
||||
|
||||
public final double displacementY;
|
||||
|
||||
public Point2D center;
|
||||
|
||||
public Point2D rCenter;
|
||||
|
||||
public double rotation = 0.0D;
|
||||
|
||||
public LabelInfo(LabelPainterEx painter, Polygon poly, LabelCacheItemEx labelItem) {
|
||||
this.labelPainter = painter;
|
||||
this.polygon = poly;
|
||||
this.generalPath = toGeneralPath(poly);
|
||||
this.font = painter.getLabel().getTextStyle().getFont().deriveFont(new AffineTransform());
|
||||
if (labelItem.getPolygonAlignText() == LabelCacheItemEx.PolygonAlignTextOptions.MANUAL) {
|
||||
this.anchorX = labelItem.getTextStyle().getAnchorX();
|
||||
this.anchorY = labelItem.getTextStyle().getAnchorY();
|
||||
this.displacementX = labelItem.getTextStyle().getDisplacementX();
|
||||
this.displacementY = labelItem.getTextStyle().getDisplacementY();
|
||||
this.rotation = labelItem.getTextStyle().getRotation();
|
||||
if (Double.isNaN(this.rotation) ||
|
||||
Double.isInfinite(this.rotation)) {
|
||||
this.rotation = 0.0D;
|
||||
} else {
|
||||
this.rotation = Math.toRadians(this.rotation);
|
||||
}
|
||||
} else {
|
||||
this.anchorX = 0.5D;
|
||||
this.anchorY = 0.5D;
|
||||
this.displacementX = 0.0D;
|
||||
this.displacementY = 0.0D;
|
||||
}
|
||||
}
|
||||
|
||||
private GeneralPath toGeneralPath(Polygon polygon) {
|
||||
GeneralPath path = new GeneralPath();
|
||||
Coordinate[] shell = polygon.getExteriorRing().getCoordinates();
|
||||
path.moveTo((shell[0]).x, (shell[0]).y);
|
||||
for (int i = 1; i < shell.length; i++)
|
||||
path.lineTo((shell[i]).x, (shell[i]).y);
|
||||
int interiorRing = polygon.getNumInteriorRing();
|
||||
for (int j = 0; j < interiorRing; j++) {
|
||||
Coordinate[] holes = polygon.getInteriorRingN(j).getCoordinates();
|
||||
path.moveTo((holes[0]).x, (holes[0]).y);
|
||||
for (int k = 1; k < holes.length; k++)
|
||||
path.lineTo((holes[k]).x, (holes[k]).y);
|
||||
}
|
||||
path.closePath();
|
||||
return path;
|
||||
}
|
||||
|
||||
public boolean isConvexPolygon() {
|
||||
Coordinate[] coords = this.polygon.getExteriorRing().getCoordinates();
|
||||
int n = coords.length;
|
||||
if (n < 4)
|
||||
return true;
|
||||
boolean sign = false;
|
||||
for (int i = 0; i < n; i++) {
|
||||
double dx1 = (coords[(i + 2) % n]).x - (coords[(i + 1) % n]).x;
|
||||
double dy1 = (coords[(i + 2) % n]).y - (coords[(i + 1) % n]).y;
|
||||
double dx2 = (coords[i]).x - (coords[(i + 1) % n]).x;
|
||||
double dy2 = (coords[i]).y - (coords[(i + 1) % n]).y;
|
||||
double zcrossproduct = dx1 * dy2 - dy1 * dx2;
|
||||
if (i == 0) {
|
||||
sign = (zcrossproduct > 0.0D);
|
||||
} else if (sign != ((zcrossproduct > 0.0D))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,508 @@
|
|||
package com.geotwo.webserver.core.render.style.label;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Paint;
|
||||
import java.awt.Shape;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.font.LineBreakMeasurer;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.font.TextLayout;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
import java.text.Bidi;
|
||||
import java.text.BreakIterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.swing.Icon;
|
||||
import org.geotools.geometry.jts.LiteShape2;
|
||||
import org.geotools.geometry.jts.TransformedShape;
|
||||
import org.geotools.renderer.label.LabelCacheImpl;
|
||||
import org.geotools.renderer.label.LabelCacheItem;
|
||||
import org.geotools.renderer.label.LineStringCursor;
|
||||
import org.geotools.renderer.lite.StyledShapePainter;
|
||||
import org.geotools.renderer.style.GraphicStyle2D;
|
||||
import org.geotools.renderer.style.IconStyle2D;
|
||||
import org.geotools.renderer.style.MarkStyle2D;
|
||||
import org.geotools.renderer.style.Style2D;
|
||||
import org.geotools.renderer.style.TextStyle2D;
|
||||
|
||||
public class LabelPainterEx {
|
||||
static final double EPS = 1.0E-6D;
|
||||
|
||||
StyledShapePainter shapePainter = new StyledShapePainter();
|
||||
|
||||
LabelCacheItem labelItem;
|
||||
|
||||
List<LineInfo> lines;
|
||||
|
||||
public Graphics2D graphics;
|
||||
|
||||
LabelCacheImpl.LabelRenderingMode labelRenderingMode;
|
||||
|
||||
GeometryFactory gf = new GeometryFactory();
|
||||
|
||||
Rectangle2D labelBounds;
|
||||
|
||||
public LabelPainterEx(Graphics2D graphics, LabelCacheImpl.LabelRenderingMode labelRenderingMode) {
|
||||
this.graphics = graphics;
|
||||
this.labelRenderingMode = labelRenderingMode;
|
||||
}
|
||||
|
||||
public void setLabel(LabelCacheItem labelItem) {
|
||||
this.labelItem = labelItem;
|
||||
labelItem.getTextStyle().setLabel(labelItem.getLabel());
|
||||
this.labelBounds = null;
|
||||
this.lines = null;
|
||||
String text = labelItem.getLabel();
|
||||
if ((!text.contains("\n") && labelItem.getAutoWrap() <= 0) ||
|
||||
labelItem.isFollowLineEnabled()) {
|
||||
FontRenderContext frc = this.graphics.getFontRenderContext();
|
||||
TextLayout layout = new TextLayout(text, labelItem.getTextStyle().getFont(), frc);
|
||||
LineInfo line = new LineInfo(text, layoutSentence(text, labelItem), layout);
|
||||
this.labelBounds = line.gv.getVisualBounds();
|
||||
normalizeBounds(this.labelBounds);
|
||||
this.lines = Collections.singletonList(line);
|
||||
return;
|
||||
}
|
||||
String[] splitted = text.split("\\n");
|
||||
this.lines = new ArrayList<LineInfo>();
|
||||
if (labelItem.getAutoWrap() <= 0) {
|
||||
byte b;
|
||||
int i;
|
||||
String[] arrayOfString;
|
||||
for (i = (arrayOfString = splitted).length, b = 0; b < i; ) {
|
||||
String line = arrayOfString[b];
|
||||
FontRenderContext frc = this.graphics.getFontRenderContext();
|
||||
TextLayout layout = new TextLayout(line, labelItem.getTextStyle().getFont(), frc);
|
||||
LineInfo info = new LineInfo(line, layoutSentence(line, labelItem), layout);
|
||||
this.lines.add(info);
|
||||
b++;
|
||||
}
|
||||
} else {
|
||||
Map<TextAttribute, Object> map = new HashMap<TextAttribute, Object>();
|
||||
map.put(TextAttribute.FONT, labelItem.getTextStyle().getFont());
|
||||
for (int i = 0; i < splitted.length; i++) {
|
||||
String line = splitted[i];
|
||||
AttributedString attributed = new AttributedString(line, (Map)map);
|
||||
AttributedCharacterIterator iter = attributed.getIterator();
|
||||
LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(iter,
|
||||
BreakIterator.getWordInstance(), this.graphics.getFontRenderContext());
|
||||
BreakIterator breaks = BreakIterator.getWordInstance();
|
||||
breaks.setText(line);
|
||||
int prevPosition = 0;
|
||||
while (lineMeasurer.getPosition() < iter.getEndIndex()) {
|
||||
TextLayout layout = lineMeasurer.nextLayout(labelItem.getAutoWrap(), line.length(), true);
|
||||
int newPosition = prevPosition;
|
||||
if (layout != null) {
|
||||
newPosition = lineMeasurer.getPosition();
|
||||
} else {
|
||||
int nextBoundary = breaks.following(prevPosition);
|
||||
if (nextBoundary == -1) {
|
||||
newPosition = line.length();
|
||||
} else {
|
||||
newPosition = nextBoundary;
|
||||
}
|
||||
AttributedCharacterIterator subIter = attributed.getIterator(null, prevPosition, newPosition);
|
||||
layout = new TextLayout(subIter, this.graphics.getFontRenderContext());
|
||||
lineMeasurer.setPosition(newPosition);
|
||||
}
|
||||
String extracted = line.substring(prevPosition, newPosition).trim();
|
||||
if (!"".equals(extracted)) {
|
||||
LineInfo info = new LineInfo(extracted, layoutSentence(extracted, labelItem),
|
||||
layout);
|
||||
this.lines.add(info);
|
||||
}
|
||||
prevPosition = newPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
double maxWidth = 0.0D;
|
||||
for (LineInfo line : this.lines)
|
||||
maxWidth = Math.max(line.gv.getVisualBounds().getWidth(), maxWidth);
|
||||
double boundsY = 0.0D;
|
||||
double labelY = 0.0D;
|
||||
for (LineInfo info : this.lines) {
|
||||
Rectangle2D currBounds = info.gv.getVisualBounds();
|
||||
TextLayout layout = info.layout;
|
||||
double minX = (maxWidth - currBounds.getWidth()) *
|
||||
labelItem.getTextStyle().getAnchorX() - currBounds.getMinX();
|
||||
info.x = minX;
|
||||
if (this.labelBounds == null) {
|
||||
this.labelBounds = currBounds;
|
||||
boundsY = currBounds.getMinY() + layout.getAscent() + layout.getDescent() +
|
||||
layout.getLeading();
|
||||
} else {
|
||||
Rectangle2D translated = new Rectangle2D.Double(minX, boundsY, currBounds
|
||||
.getWidth(), currBounds.getHeight());
|
||||
boundsY += (layout.getAscent() + layout.getDescent() + layout.getLeading());
|
||||
labelY += (layout.getAscent() + layout.getDescent() + layout.getLeading());
|
||||
this.labelBounds = this.labelBounds.createUnion(translated);
|
||||
}
|
||||
info.y = labelY;
|
||||
}
|
||||
normalizeBounds(this.labelBounds);
|
||||
}
|
||||
|
||||
void normalizeBounds(Rectangle2D bounds) {
|
||||
if (bounds.isEmpty())
|
||||
bounds.setRect(bounds.getCenterX() - 1.0D, bounds.getCenterY() - 1.0D, 2.0D, 2.0D);
|
||||
}
|
||||
|
||||
GlyphVector layoutSentence(String label, LabelCacheItem item) {
|
||||
Font font = item.getTextStyle().getFont();
|
||||
char[] chars = label.toCharArray();
|
||||
int length = label.length();
|
||||
if (Bidi.requiresBidi(chars, 0, length)) {
|
||||
Bidi bidi = new Bidi(label, -2);
|
||||
if (bidi.isRightToLeft())
|
||||
return font.layoutGlyphVector(this.graphics.getFontRenderContext(), chars, 0, length,
|
||||
1);
|
||||
if (bidi.isMixed()) {
|
||||
String r = "";
|
||||
for (int i = 0; i < bidi.getRunCount(); i++) {
|
||||
String s1 = label.substring(bidi.getRunStart(i), bidi.getRunLimit(i));
|
||||
if (bidi.getRunLevel(i) % 2 == 0)
|
||||
s1 = (new StringBuffer(s1)).reverse().toString();
|
||||
r = String.valueOf(r) + s1;
|
||||
}
|
||||
char[] chars2 = r.toCharArray();
|
||||
return font.layoutGlyphVector(this.graphics.getFontRenderContext(), chars2, 0, length,
|
||||
1);
|
||||
}
|
||||
}
|
||||
return font.createGlyphVector(this.graphics.getFontRenderContext(), chars);
|
||||
}
|
||||
|
||||
public LabelCacheItem getLabel() {
|
||||
return this.labelItem;
|
||||
}
|
||||
|
||||
public double getLineHeight() {
|
||||
return ((LineInfo)this.lines.get(0)).gv.getVisualBounds().getHeight() - ((LineInfo)this.lines.get(0)).layout.getDescent();
|
||||
}
|
||||
|
||||
public double getAscent() {
|
||||
return ((LineInfo)this.lines.get(0)).layout.getAscent();
|
||||
}
|
||||
|
||||
public int getStraightLabelWidth() {
|
||||
return (int)Math.round(getLabelBounds().getWidth());
|
||||
}
|
||||
|
||||
public int getLineCount() {
|
||||
return this.lines.size();
|
||||
}
|
||||
|
||||
public Rectangle2D getFullLabelBounds() {
|
||||
Rectangle2D bounds = (Rectangle2D)getLabelBounds().clone();
|
||||
int haloRadius = Math.round((this.labelItem.getTextStyle().getHaloFill() != null) ? this.labelItem
|
||||
.getTextStyle().getHaloRadius() : 0.0F);
|
||||
bounds.add(bounds.getMinX() - haloRadius, bounds.getMinY() - haloRadius);
|
||||
bounds.add(bounds.getMaxX() + haloRadius, bounds.getMaxY() + haloRadius);
|
||||
if (this.labelItem.getTextStyle().getGraphic() != null) {
|
||||
Rectangle2D shieldBounds, area = this.labelItem.getTextStyle().getGraphicDimensions();
|
||||
int[] margin = this.labelItem.getGraphicMargin();
|
||||
LabelCacheItem.GraphicResize mode = this.labelItem.getGraphicsResize();
|
||||
if (mode == LabelCacheItem.GraphicResize.STRETCH) {
|
||||
shieldBounds = applyMargins(margin, bounds);
|
||||
} else if (mode == LabelCacheItem.GraphicResize.PROPORTIONAL) {
|
||||
double factor = 1.0D;
|
||||
if (bounds.getWidth() > bounds.getHeight()) {
|
||||
factor = bounds.getWidth() / area.getWidth();
|
||||
} else {
|
||||
factor = bounds.getHeight() / area.getHeight();
|
||||
}
|
||||
double width = area.getWidth() * factor;
|
||||
double height = area.getHeight() * factor;
|
||||
shieldBounds = new Rectangle2D.Double(width / 2.0D + bounds.getMinX() - bounds.getWidth() / 2.0D,
|
||||
height / 2.0D + bounds.getMinY() - bounds.getHeight() / 2.0D, width, height);
|
||||
shieldBounds = applyMargins(margin, shieldBounds);
|
||||
} else {
|
||||
shieldBounds = new Rectangle2D.Double(-area.getWidth() / 2.0D + bounds.getMinX() -
|
||||
bounds.getWidth() / 2.0D, -area.getHeight() / 2.0D + bounds.getMinY() -
|
||||
bounds.getHeight() / 2.0D, area.getWidth(), area.getHeight());
|
||||
}
|
||||
bounds = bounds.createUnion(shieldBounds);
|
||||
}
|
||||
normalizeBounds(bounds);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
Rectangle2D applyMargins(int[] margin, Rectangle2D bounds) {
|
||||
if (bounds != null) {
|
||||
double xmin = bounds.getMinX() - margin[3];
|
||||
double ymin = bounds.getMinY() - margin[0];
|
||||
double width = bounds.getWidth() + margin[1] + margin[3];
|
||||
double height = bounds.getHeight() + margin[0] + margin[2];
|
||||
return new Rectangle2D.Double(xmin, ymin, width, height);
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public Rectangle2D getLabelBounds() {
|
||||
return this.labelBounds;
|
||||
}
|
||||
|
||||
public void paintStraightLabel(AffineTransform transform) throws Exception {
|
||||
AffineTransform oldTransform = this.graphics.getTransform();
|
||||
try {
|
||||
AffineTransform newTransform = new AffineTransform(oldTransform);
|
||||
newTransform.concatenate(transform);
|
||||
this.graphics.setTransform(newTransform);
|
||||
Style2D graphic = this.labelItem.getTextStyle().getGraphic();
|
||||
if (graphic != null) {
|
||||
Rectangle2D rect = getFullLabelBounds();
|
||||
LiteShape2 tempShape = new LiteShape2(
|
||||
(Geometry)this.gf.createPoint(new Coordinate(rect.getCenterX(), rect.getCenterY())),
|
||||
null, null, false, false);
|
||||
graphic = resizeGraphic(graphic);
|
||||
this.shapePainter.paint(this.graphics, tempShape, graphic, graphic.getMaxScale());
|
||||
}
|
||||
if (this.labelItem.getTextStyle().getFont().getSize() == 0)
|
||||
return;
|
||||
if (this.lines.size() == 1) {
|
||||
drawGlyphVector(((LineInfo)this.lines.get(0)).gv);
|
||||
} else {
|
||||
AffineTransform lineTx = new AffineTransform(transform);
|
||||
for (LineInfo line : this.lines) {
|
||||
lineTx.setTransform(transform);
|
||||
lineTx.translate(line.x, line.y);
|
||||
this.graphics.setTransform(lineTx);
|
||||
drawGlyphVector(line.gv);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.graphics.setTransform(oldTransform);
|
||||
}
|
||||
}
|
||||
|
||||
private Style2D resizeGraphic(Style2D graphic) {
|
||||
LabelCacheItem.GraphicResize mode = this.labelItem.getGraphicsResize();
|
||||
if (mode == LabelCacheItem.GraphicResize.NONE || mode == null)
|
||||
return graphic;
|
||||
double width = this.labelBounds.getWidth();
|
||||
double height = this.labelBounds.getHeight();
|
||||
int[] margin = this.labelItem.getGraphicMargin();
|
||||
if (margin != null) {
|
||||
width += (margin[1] + margin[3]);
|
||||
height += (margin[0] + margin[2]);
|
||||
}
|
||||
width = Math.round(width);
|
||||
height = Math.round(height);
|
||||
if (width <= 0.0D || height <= 0.0D)
|
||||
return null;
|
||||
if (graphic instanceof MarkStyle2D) {
|
||||
MarkStyle2D mark = (MarkStyle2D)graphic;
|
||||
Shape original = mark.getShape();
|
||||
Rectangle2D bounds = original.getBounds2D();
|
||||
MarkStyle2D resized = (MarkStyle2D)mark.clone();
|
||||
if (mode == LabelCacheItem.GraphicResize.PROPORTIONAL) {
|
||||
if (width > height) {
|
||||
resized.setSize(Math.round(bounds.getHeight() * width / bounds.getWidth()));
|
||||
} else {
|
||||
resized.setSize(height);
|
||||
}
|
||||
} else {
|
||||
TransformedShape tss = new TransformedShape();
|
||||
tss.shape = original;
|
||||
tss.setTransform(AffineTransform.getScaleInstance(width / bounds.getWidth(), height / bounds.getHeight()));
|
||||
resized.setShape((Shape)tss);
|
||||
resized.setSize(height);
|
||||
}
|
||||
return (Style2D)resized;
|
||||
}
|
||||
if (graphic instanceof IconStyle2D) {
|
||||
AffineTransform at;
|
||||
IconStyle2D iconStyle = (IconStyle2D)graphic;
|
||||
IconStyle2D resized = (IconStyle2D)iconStyle.clone();
|
||||
Icon icon = iconStyle.getIcon();
|
||||
if (mode == LabelCacheItem.GraphicResize.PROPORTIONAL) {
|
||||
double factor;
|
||||
if (width > height) {
|
||||
factor = width / icon.getIconWidth();
|
||||
} else {
|
||||
factor = height / icon.getIconHeight();
|
||||
}
|
||||
at = AffineTransform.getScaleInstance(factor, factor);
|
||||
} else {
|
||||
at = AffineTransform.getScaleInstance(width / icon.getIconWidth(), height / icon.getIconHeight());
|
||||
}
|
||||
resized.setIcon(new TransformedIconEx(icon, at));
|
||||
return (Style2D)resized;
|
||||
}
|
||||
if (graphic instanceof GraphicStyle2D) {
|
||||
AffineTransform at;
|
||||
GraphicStyle2D gstyle = (GraphicStyle2D)graphic;
|
||||
GraphicStyle2D resized = (GraphicStyle2D)graphic.clone();
|
||||
BufferedImage image = gstyle.getImage();
|
||||
if (mode == LabelCacheItem.GraphicResize.PROPORTIONAL) {
|
||||
double factor;
|
||||
if (width > height) {
|
||||
factor = width / image.getWidth();
|
||||
} else {
|
||||
factor = height / image.getHeight();
|
||||
}
|
||||
at = AffineTransform.getScaleInstance(factor, factor);
|
||||
} else {
|
||||
at = AffineTransform.getScaleInstance(width / image.getWidth(), height / image.getHeight());
|
||||
}
|
||||
AffineTransformOp ato = new AffineTransformOp(at, 2);
|
||||
image = ato.filter(image, (BufferedImage)null);
|
||||
resized.setImage(image);
|
||||
return (Style2D)resized;
|
||||
}
|
||||
return graphic;
|
||||
}
|
||||
|
||||
private void drawGlyphVector(GlyphVector gv) {
|
||||
Shape outline = gv.getOutline();
|
||||
if (this.labelItem.getTextStyle().getHaloFill() != null) {
|
||||
configureHalo();
|
||||
this.graphics.draw(outline);
|
||||
}
|
||||
configureLabelStyle();
|
||||
if (this.labelRenderingMode == LabelCacheImpl.LabelRenderingMode.STRING) {
|
||||
this.graphics.drawGlyphVector(gv, 0.0F, 0.0F);
|
||||
} else if (this.labelRenderingMode == LabelCacheImpl.LabelRenderingMode.OUTLINE) {
|
||||
this.graphics.fill(outline);
|
||||
} else {
|
||||
AffineTransform tx = this.graphics.getTransform();
|
||||
if (Math.abs(tx.getShearX()) >= 1.0E-6D || Math.abs(tx.getShearY()) > 1.0E-6D) {
|
||||
this.graphics.fill(outline);
|
||||
} else {
|
||||
this.graphics.drawGlyphVector(gv, 0.0F, 0.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void configureHalo() {
|
||||
this.graphics.setPaint(this.labelItem.getTextStyle().getHaloFill());
|
||||
this.graphics.setComposite(this.labelItem.getTextStyle().getHaloComposite());
|
||||
float haloRadius = (this.labelItem.getTextStyle().getHaloFill() != null) ? this.labelItem.getTextStyle().getHaloRadius() : 0.0F;
|
||||
this.graphics.setStroke(new BasicStroke(2.0F * haloRadius, 1, 1));
|
||||
}
|
||||
|
||||
private void configureLabelStyle() {
|
||||
Paint fill = this.labelItem.getTextStyle().getFill();
|
||||
Composite comp = this.labelItem.getTextStyle().getComposite();
|
||||
if (fill == null) {
|
||||
fill = Color.BLACK;
|
||||
comp = AlphaComposite.getInstance(3, 1.0F);
|
||||
}
|
||||
this.graphics.setPaint(fill);
|
||||
this.graphics.setComposite(comp);
|
||||
}
|
||||
|
||||
public void paintCurvedLabel(LineStringCursor cursor) {
|
||||
if (this.labelItem.getTextStyle().getFont().getSize() == 0)
|
||||
return;
|
||||
GlyphVector glyphVector = ((LineInfo)this.lines.get(0)).gv;
|
||||
AffineTransform oldTransform = this.graphics.getTransform();
|
||||
try {
|
||||
if (!isLabelUpwards(cursor) && this.labelItem.isForceLeftToRightEnabled()) {
|
||||
LineStringCursor reverse = cursor.reverse();
|
||||
reverse.moveTo(cursor.getLineStringLength() - cursor.getCurrentOrdinate());
|
||||
cursor = reverse;
|
||||
}
|
||||
double anchorY = getLinePlacementYAnchor();
|
||||
double mid = cursor.getCurrentOrdinate();
|
||||
Coordinate c = new Coordinate();
|
||||
c = cursor.getCurrentPosition(c);
|
||||
this.graphics.setPaint(Color.BLACK);
|
||||
double startOrdinate = mid - (getStraightLabelWidth() / 2);
|
||||
if (startOrdinate < 0.0D)
|
||||
startOrdinate = 0.0D;
|
||||
cursor.moveTo(startOrdinate);
|
||||
int numGlyphs = glyphVector.getNumGlyphs();
|
||||
float nextAdvance = glyphVector.getGlyphMetrics(0).getAdvance() * 0.5F;
|
||||
Shape[] outlines = new Shape[numGlyphs];
|
||||
AffineTransform[] transforms = new AffineTransform[numGlyphs];
|
||||
int i;
|
||||
for (i = 0; i < numGlyphs; i++) {
|
||||
outlines[i] = glyphVector.getGlyphOutline(i);
|
||||
Point2D p = glyphVector.getGlyphPosition(i);
|
||||
float advance = nextAdvance;
|
||||
nextAdvance = (i < numGlyphs - 1) ? (glyphVector.getGlyphMetrics(i + 1).getAdvance() * 0.5F) :
|
||||
0.0F;
|
||||
c = cursor.getCurrentPosition(c);
|
||||
AffineTransform t = new AffineTransform();
|
||||
t.setToTranslation(c.x, c.y);
|
||||
t.rotate(cursor.getCurrentAngle());
|
||||
t.translate(-p.getX() - advance, -p.getY() + getLineHeight() * anchorY);
|
||||
transforms[i] = t;
|
||||
cursor.moveTo(cursor.getCurrentOrdinate() + advance + nextAdvance);
|
||||
}
|
||||
if (this.labelItem.getTextStyle().getHaloFill() != null) {
|
||||
configureHalo();
|
||||
for (i = 0; i < numGlyphs; i++) {
|
||||
this.graphics.setTransform(transforms[i]);
|
||||
this.graphics.draw(outlines[i]);
|
||||
}
|
||||
}
|
||||
configureLabelStyle();
|
||||
for (i = 0; i < numGlyphs; i++) {
|
||||
this.graphics.setTransform(transforms[i]);
|
||||
this.graphics.fill(outlines[i]);
|
||||
}
|
||||
} finally {
|
||||
this.graphics.setTransform(oldTransform);
|
||||
}
|
||||
}
|
||||
|
||||
public double getLinePlacementYAnchor() {
|
||||
TextStyle2D textStyle = getLabel().getTextStyle();
|
||||
LineMetrics lm = textStyle.getFont().getLineMetrics(textStyle.getLabel(),
|
||||
this.graphics.getFontRenderContext());
|
||||
if (lm.getHeight() > 0.0F)
|
||||
return ((Math.abs(lm.getStrikethroughOffset()) + lm.getDescent() + lm.getLeading()) /
|
||||
lm.getHeight());
|
||||
return 0.0D;
|
||||
}
|
||||
|
||||
boolean isLabelUpwards(LineStringCursor cursor) {
|
||||
double labelAngle = cursor.getCurrentAngle() + 1.5707963267948966D;
|
||||
labelAngle %= 6.283185307179586D;
|
||||
return (labelAngle >= 0.0D && labelAngle < Math.PI);
|
||||
}
|
||||
|
||||
private static class LineInfo {
|
||||
double x;
|
||||
|
||||
double y;
|
||||
|
||||
String text;
|
||||
|
||||
GlyphVector gv;
|
||||
|
||||
TextLayout layout;
|
||||
|
||||
public LineInfo(String text, GlyphVector gv, TextLayout layout) {
|
||||
this.text = text;
|
||||
this.gv = gv;
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
public LineInfo(String text, GlyphVector gv) {
|
||||
this.text = text;
|
||||
this.gv = gv;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue