Revision 1005
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/README.txt | ||
---|---|---|
1 |
=============== |
|
2 |
gvSIG Educa |
|
3 |
=============== |
|
4 |
|
|
5 |
--------------------- |
|
6 |
Portable View |
|
7 |
--------------------- |
|
8 |
|
|
9 |
Description |
|
10 |
============== |
|
11 |
|
|
12 |
This folder contains the sources of the Portable View functionality. |
|
13 |
|
|
14 |
Requirements |
|
15 |
============== |
|
16 |
|
|
17 |
* Maven 2.6 or higher |
|
18 |
|
|
19 |
* Java JDK 1.5 or higher |
|
20 |
|
|
21 |
For eclipse |
|
22 |
------------- |
|
23 |
|
|
24 |
See `developer guide at gvSIG.org <http://www.gvsig.org/plone/projects/gvsig-desktop/docs/devel/gvsig-devel-guide/2-1-0/introduccion>`_ and the file ``REAME-ECLIPSE.txt`` |
|
25 |
|
|
26 |
|
|
27 |
Contents |
|
28 |
========== |
|
29 |
|
|
30 |
org.gvsig.educa.portableview.lib |
|
31 |
--------------------------------- |
|
32 |
|
|
33 |
Functionality sources. This project just contain the main process and the logic without any dependency with User Interface. |
|
34 |
|
|
35 |
org.gvsig.educa.portableview.swing |
|
36 |
------------------------------------- |
|
37 |
|
|
38 |
User Interface components to access a manage the application services. |
|
39 |
|
|
40 |
org.gvsig.educa.portableview.main |
|
41 |
----------------------------------- |
|
42 |
|
|
43 |
Little test application which allow run the main functionality of application. |
|
44 |
|
|
45 |
See `Execute little test application`_ to know how run it. |
|
46 |
|
|
47 |
pom.xml |
|
48 |
--------- |
|
49 |
|
|
50 |
Maven project definition file |
|
51 |
|
|
52 |
README.rst |
|
53 |
-------------- |
|
54 |
|
|
55 |
This file (in reStructureText format, for more info this format look at `gvSIG portal <https://gvsig.org/web/projects/gvsig-desktop/docs/devel/guia-para-documentar/el-formato-restructuredtext>`_ or at `docUtils reference <http://docutils.sourceforge.net/rst.html>`_) |
|
56 |
|
|
57 |
|
|
58 |
Compilation |
|
59 |
================ |
|
60 |
|
|
61 |
From shell |
|
62 |
------------ |
|
63 |
|
|
64 |
Execute this command:: |
|
65 |
|
|
66 |
org.gvsig.educa.portableview$ mvn clean install |
|
67 |
|
|
68 |
|
|
69 |
From eclipse |
|
70 |
-------------- |
|
71 |
|
|
72 |
See `work in a proyect of the developer guide at gvSIG.org <https://gvsig.org/web/projects/gvsig-desktop/docs/devel/gvsig-devel-guide/2.0.0/trabajar-con-un-proyecto>`_ |
|
73 |
|
|
74 |
In some project, could be better use ``mvn eclipse:clean eclipse:eclipse`` than import project as a *Maven project*. Maven plugin of eclipse does not set classpath correctly in some project. |
|
75 |
|
|
76 |
|
|
77 |
Packing |
|
78 |
======== |
|
79 |
|
|
80 |
This functionality has no stand-alone packing process. |
|
81 |
|
|
82 |
Version |
|
83 |
--------------- |
|
84 |
|
|
85 |
To changes version number just set in in ``project/version`` tag of *pom.xml* in this folder. Sub-projects will inherit it. |
|
86 |
|
|
87 |
Version polity is the standard in project. Changes in version number: |
|
88 |
|
|
89 |
* third number: Bug fixes and minors improvements. API must have no changes from previous version. |
|
90 |
* second number: Bug fixes and mayor improvements. API can have minor changes. Previously deprecated classes could be removed. No architectural changes. |
|
91 |
* first number: Mayor changes. |
|
92 |
|
|
93 |
Create a tag |
|
94 |
------------------ |
|
95 |
|
|
96 |
TODO: use *maven release* plugin |
|
97 |
|
|
98 |
Use svn copy command to copy version in server. Process could be like this: |
|
99 |
|
|
100 |
|
|
101 |
#. Check that there ins no changes in workspace:: |
|
102 |
|
|
103 |
svn up ; svn status |
|
104 |
|
|
105 |
#. Check that project compiles and passes all test. |
|
106 |
|
|
107 |
mvn clean install |
|
108 |
|
|
109 |
#. Update *pom.xml* to set version of tag (usually removing *-SNAPSHOT*) |
|
110 |
#. create tag folder on server:: |
|
111 |
|
|
112 |
svn mkdir -m "Create {version} tag folder" https://devel.gvsig.org/svn/gvsig-educa/org.gvsig.educa.portablewview/tags/{version} |
|
113 |
|
|
114 |
#. Copy current workcopy to tag folder:: |
|
115 |
|
|
116 |
svn copy -m "Create {version} tag" * https://devel.gvsig.org/svn/gvsig-educa/org.gvsig.educa.portablewview/tags/{version} |
|
117 |
|
|
118 |
#. Update *pom.xml* to next version |
|
119 |
#. Commit *pom.xml* changes:: |
|
120 |
|
|
121 |
svn commit -m "Set new version {version}-SNAPSHOT" pom.xml |
|
122 |
|
|
123 |
|
|
124 |
i18n |
|
125 |
====== |
|
126 |
|
|
127 |
The files for internationalization can be found in this folders: |
|
128 |
|
|
129 |
+ *org.gvsig.educa.portablewview.app.viewer/src/main/resources-plugin* |
|
130 |
+ *org.gvsig.educa.portablewview.app.editor/src/main/resources-plugin* |
|
131 |
|
|
132 |
The internationalization of this application is based on standard java resource bundle mechanism. So, to add a new language just add the file with the language code to every related folder. |
|
133 |
|
|
134 |
Execute little test application |
|
135 |
================================= |
|
136 |
|
|
137 |
From shell |
|
138 |
------------ |
|
139 |
|
|
140 |
After compile the application, execute this command:: |
|
141 |
|
|
142 |
org.gvsig.educa.portablewview$ cd org.gvsig.educa.thematicmap.main |
|
143 |
org.gvsig.educa.portablewview/org.gvsig.educa.portablewview.main$ mvn exec:java |
|
144 |
|
|
145 |
Form eclipse |
|
146 |
------------------ |
|
147 |
|
|
148 |
Select ``org.gvsig.educa.portableview.main`` project in *Project tree* using *Java perspective*, click with right mouse button and select ``Run as.../Java application``. Select ``Main`` class for project. |
|
149 |
|
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<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/xsd/maven-4.0.0.xsd"> |
|
3 |
|
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.educa.portableview.lib</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<name>org.gvsig.educa.portableview.lib</name> |
|
8 |
<parent> |
|
9 |
<groupId>org.gvsig</groupId> |
|
10 |
<artifactId>org.gvsig.educa.portableview</artifactId> |
|
11 |
<version>1.0.143</version> |
|
12 |
</parent> |
|
13 |
<modules> |
|
14 |
<module>org.gvsig.educa.portableview.lib.api</module> |
|
15 |
<module>org.gvsig.educa.portableview.lib.impl</module> |
|
16 |
<module>org.gvsig.educa.portableview.lib.prov.installer</module> |
|
17 |
</modules> |
|
18 |
</project> |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/test/resources/README.txt | ||
---|---|---|
1 |
==== |
|
2 |
gvSIG. Desktop Geographic Information System. |
|
3 |
|
|
4 |
Copyright (C) 2007-2012 gvSIG Association. |
|
5 |
|
|
6 |
This program is free software; you can redistribute it and/or |
|
7 |
modify it under the terms of the GNU General Public License |
|
8 |
as published by the Free Software Foundation; either version 2 |
|
9 |
of the License, or (at your option) any later version. |
|
10 |
|
|
11 |
This program is distributed in the hope that it will be useful, |
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
GNU General Public License for more details. |
|
15 |
|
|
16 |
You should have received a copy of the GNU General Public License |
|
17 |
along with this program; if not, write to the Free Software |
|
18 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
MA 02110-1301, USA. |
|
20 |
|
|
21 |
For any additional information, do not hesitate to contact us |
|
22 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
==== |
|
24 |
|
|
25 |
Put into this folder the resources needed by your test classes. |
|
26 |
|
|
27 |
This folder is added to the Tests classpath, so you can load any resources |
|
28 |
through the ClassLoader. |
|
29 |
|
|
30 |
By default, in this folder you can find an example of log4j configuration, |
|
31 |
prepared to log messages through the console, so logging works when you |
|
32 |
run your tests classes. |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!-- |
|
3 |
|
|
4 |
gvSIG. Desktop Geographic Information System. |
|
5 |
|
|
6 |
Copyright (C) 2007-2012 gvSIG Association. |
|
7 |
|
|
8 |
This program is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU General Public License |
|
10 |
as published by the Free Software Foundation; either version 2 |
|
11 |
of the License, or (at your option) any later version. |
|
12 |
|
|
13 |
This program is distributed in the hope that it will be useful, |
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
GNU General Public License for more details. |
|
17 |
|
|
18 |
You should have received a copy of the GNU General Public License |
|
19 |
along with this program; if not, write to the Free Software |
|
20 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
MA 02110-1301, USA. |
|
22 |
|
|
23 |
For any additional information, do not hesitate to contact us |
|
24 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
25 |
|
|
26 |
--> |
|
27 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
28 |
|
|
29 |
<!-- |
|
30 |
Log4J configuration file for unit tests execution. |
|
31 |
--> |
|
32 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
33 |
|
|
34 |
<!-- Appender configuration to show logging messages through the console --> |
|
35 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
36 |
<layout class="org.apache.log4j.PatternLayout"> |
|
37 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
38 |
</layout> |
|
39 |
</appender> |
|
40 |
|
|
41 |
<!-- |
|
42 |
Activate logging messages of DEBUG level of higher only for the |
|
43 |
org.gvsig.tools packages. |
|
44 |
You can put full classes names or packages instead, to configure |
|
45 |
logging for all the classes and subpackages of the package. |
|
46 |
--> |
|
47 |
<category name="org.gvsig.tools"> |
|
48 |
<priority value="DEBUG" /> |
|
49 |
</category> |
|
50 |
<category name="org.gvsig.educa.portableview"> |
|
51 |
<priority value="DEBUG" /> |
|
52 |
</category> |
|
53 |
|
|
54 |
<!-- |
|
55 |
By default, show only logging messages of INFO level or higher, |
|
56 |
through the previously configured CONSOLE appender. |
|
57 |
--> |
|
58 |
<root> |
|
59 |
<priority value="DEBUG" /> |
|
60 |
<appender-ref ref="CONSOLE" /> |
|
61 |
</root> |
|
62 |
</log4j:configuration> |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/main/java/org/gvsig/educa/portableview/impl/PortableViewFileFilter.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.impl; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.io.FileFilter; |
|
26 |
|
|
27 |
/** |
|
28 |
* <p> |
|
29 |
* {@link FileFilter} implementation which identifies files that can be a |
|
30 |
* Portable View |
|
31 |
* </p> |
|
32 |
* <p> |
|
33 |
* This checks: |
|
34 |
* <ul> |
|
35 |
* <li>file exists</li> |
|
36 |
* <li>is a file</li> |
|
37 |
* <li>ends in "." + Portable view extension</li> |
|
38 |
* </ul> |
|
39 |
* </p> |
|
40 |
* |
|
41 |
* @author gvSIG Team |
|
42 |
* @version $Id$ |
|
43 |
* |
|
44 |
*/ |
|
45 |
public class PortableViewFileFilter implements FileFilter { |
|
46 |
|
|
47 |
private final String fileNameEnding; |
|
48 |
private final String fileExtension; |
|
49 |
|
|
50 |
public PortableViewFileFilter(String fileExtension) { |
|
51 |
this.fileExtension = fileExtension; |
|
52 |
fileNameEnding = ".".concat(fileExtension); |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Returns "."+{@link #getFileExtension()} |
|
57 |
* |
|
58 |
* @return |
|
59 |
*/ |
|
60 |
public String getFileNameEnding() { |
|
61 |
return fileNameEnding; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Returns file name extension used to match files |
|
66 |
* |
|
67 |
* @return |
|
68 |
*/ |
|
69 |
public String getFileExtension() { |
|
70 |
return fileExtension; |
|
71 |
} |
|
72 |
|
|
73 |
/** {@inheridDoc} */ |
|
74 |
public boolean accept(File pathname) { |
|
75 |
return pathname.exists() && pathname.isFile() |
|
76 |
&& pathname.getName().endsWith(fileNameEnding); |
|
77 |
} |
|
78 |
|
|
79 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/main/java/org/gvsig/educa/portableview/impl/DefaultPortableViewFileServices.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.impl; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.io.IOException; |
|
26 |
import java.io.InputStream; |
|
27 |
import java.util.zip.ZipException; |
|
28 |
|
|
29 |
import org.gvsig.educa.portableview.PortableViewFileServices; |
|
30 |
import org.gvsig.educa.portableview.impl.util.FileUtils; |
|
31 |
import org.gvsig.educa.portableview.impl.util.FilenameUtils; |
|
32 |
import org.gvsig.educa.portableview.impl.util.IOUtils; |
|
33 |
import org.gvsig.educa.portableview.impl.util.PersistenceUtils; |
|
34 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
35 |
import org.gvsig.tools.ToolsLocator; |
|
36 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
37 |
import org.gvsig.tools.persistence.PersistentState; |
|
38 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
39 |
|
|
40 |
/** |
|
41 |
* <p> |
|
42 |
* Default implementation of {@link PortableViewFileServices} |
|
43 |
* </p> |
|
44 |
* <p> |
|
45 |
* Delegates almost all methods in {@link FilenameUtils} |
|
46 |
* </p> |
|
47 |
* |
|
48 |
* @author gvSIG Team |
|
49 |
* @version $Id$ |
|
50 |
* |
|
51 |
*/ |
|
52 |
public class DefaultPortableViewFileServices implements PortableViewFileServices { |
|
53 |
|
|
54 |
private final PersistenceManager persistenceManager; |
|
55 |
|
|
56 |
/** |
|
57 |
* |
|
58 |
*/ |
|
59 |
public DefaultPortableViewFileServices() { |
|
60 |
persistenceManager = ToolsLocator.getPersistenceManager(); |
|
61 |
} |
|
62 |
|
|
63 |
/** {@inheridDoc} */ |
|
64 |
public void unzipFile(File zipFile, File outputFloder) throws ZipException, |
|
65 |
IOException { |
|
66 |
FileUtils.unzipFile(zipFile, outputFloder); |
|
67 |
} |
|
68 |
|
|
69 |
/** {@inheridDoc} */ |
|
70 |
public void zipFolder(File rootFolder, File targetFile) throws IOException { |
|
71 |
FileUtils.zipFolder(rootFolder, targetFile); |
|
72 |
} |
|
73 |
|
|
74 |
/** {@inheridDoc} */ |
|
75 |
public boolean isWritableFolder(File folder) { |
|
76 |
return FileUtils.isWritableFolder(folder); |
|
77 |
} |
|
78 |
|
|
79 |
/** {@inheridDoc} */ |
|
80 |
public boolean isReadableFolder(File folder) { |
|
81 |
return FileUtils.isReadableFolder(folder); |
|
82 |
} |
|
83 |
|
|
84 |
/** {@inheridDoc} */ |
|
85 |
public boolean isReadableFile(File file) { |
|
86 |
return FileUtils.isReadableFile(file); |
|
87 |
} |
|
88 |
|
|
89 |
/** {@inheridDoc} */ |
|
90 |
public File getWritableFolder(File baseFolder, String baseName) { |
|
91 |
return FileUtils.getWritableFolder(baseFolder, baseName); |
|
92 |
} |
|
93 |
|
|
94 |
/** {@inheridDoc} */ |
|
95 |
public File getNewWritableFolder(File baseFolder, String baseName) { |
|
96 |
return FileUtils.getNewWritableFolder(baseFolder, baseName); |
|
97 |
} |
|
98 |
|
|
99 |
/** {@inheridDoc} */ |
|
100 |
public File getNewFileName(File baseFolder, String name) { |
|
101 |
return FileUtils.getNewFileName(baseFolder, name); |
|
102 |
} |
|
103 |
|
|
104 |
/** {@inheridDoc} */ |
|
105 |
public File getRelativeTo(File path, File basePath) { |
|
106 |
return FileUtils.getRelativeTo(path, basePath); |
|
107 |
} |
|
108 |
|
|
109 |
/** {@inheridDoc} */ |
|
110 |
public MapContext loadMapContext(File mapContext, File relativaPathFolder) |
|
111 |
throws IOException, PersistenceException { |
|
112 |
InputStream is = null; |
|
113 |
try { |
|
114 |
// open file |
|
115 |
is = FileUtils.openInputStream(mapContext); |
|
116 |
|
|
117 |
// load Persistence status from file |
|
118 |
PersistentState persistenceStatus = |
|
119 |
persistenceManager.loadState(is); |
|
120 |
|
|
121 |
// Adjust all path in persistence status to deploy folder |
|
122 |
PersistenceUtils.fixMapContextFilePaths(persistenceStatus, |
|
123 |
relativaPathFolder); |
|
124 |
|
|
125 |
// Create a new mapContext Instance and load it form persistence |
|
126 |
// status |
|
127 |
return (MapContext) persistenceManager.create(persistenceStatus); |
|
128 |
|
|
129 |
} finally { |
|
130 |
IOUtils.closeQuietly(is); |
|
131 |
} |
|
132 |
} |
|
133 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/main/java/org/gvsig/educa/portableview/impl/map/DefaultPortableView.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.impl.map; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.io.IOException; |
|
26 |
|
|
27 |
import org.slf4j.Logger; |
|
28 |
import org.slf4j.LoggerFactory; |
|
29 |
import org.gvsig.educa.portableview.impl.MapResoucesManager; |
|
30 |
import org.gvsig.educa.portableview.map.CantLoadContextException; |
|
31 |
import org.gvsig.educa.portableview.map.InvalidPortableViewFormatException; |
|
32 |
import org.gvsig.educa.portableview.map.PortableView; |
|
33 |
import org.gvsig.educa.portableview.map.PortableViewInformation; |
|
34 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
35 |
import org.gvsig.tools.ToolsLocator; |
|
36 |
import org.gvsig.tools.dispose.DisposableManager; |
|
37 |
|
|
38 |
/** |
|
39 |
* <p> |
|
40 |
* Default {@link PortableView} implementation |
|
41 |
* </p> |
|
42 |
* <p> |
|
43 |
* Delegates open/close operation on the {@link MapResoucesManager} |
|
44 |
* </p> |
|
45 |
* |
|
46 |
* @author gvSIG Team |
|
47 |
* @version $Id$ |
|
48 |
* |
|
49 |
*/ |
|
50 |
public class DefaultPortableView implements PortableView { |
|
51 |
|
|
52 |
private static final Logger LOG = LoggerFactory |
|
53 |
.getLogger(DefaultPortableView.class); |
|
54 |
|
|
55 |
private final DisposableManager disposableManager; |
|
56 |
private final File file; |
|
57 |
private final PortableViewInformation info; |
|
58 |
private final MapResoucesManager resourceManager; |
|
59 |
private MapContext mapContext; |
|
60 |
|
|
61 |
public DefaultPortableView(File file, PortableViewInformation info, |
|
62 |
MapResoucesManager resourceManager) { |
|
63 |
this.file = file; |
|
64 |
this.info = info; |
|
65 |
this.resourceManager = resourceManager; |
|
66 |
disposableManager = ToolsLocator.getDisposableManager(); |
|
67 |
disposableManager.bind(this); |
|
68 |
resourceManager.addResource(this); |
|
69 |
} |
|
70 |
|
|
71 |
/** {@inheridDoc} */ |
|
72 |
public PortableViewInformation getInformation() { |
|
73 |
return info; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Returns source map file |
|
78 |
* |
|
79 |
* @return |
|
80 |
*/ |
|
81 |
public File getSourceFile() { |
|
82 |
return file; |
|
83 |
} |
|
84 |
|
|
85 |
/** {@inheridDoc} */ |
|
86 |
public void open() throws IOException, InvalidPortableViewFormatException, |
|
87 |
CantLoadContextException { |
|
88 |
if (isOpen()) { |
|
89 |
throw new IllegalStateException("Map is already opened"); |
|
90 |
} |
|
91 |
mapContext = resourceManager.openMap(this); |
|
92 |
} |
|
93 |
|
|
94 |
/** {@inheridDoc} */ |
|
95 |
public boolean isOpen() { |
|
96 |
return resourceManager.isOpen(this); |
|
97 |
} |
|
98 |
|
|
99 |
/** {@inheridDoc} */ |
|
100 |
public void close() throws IOException { |
|
101 |
if (!isOpen()) { |
|
102 |
// Nothing to do |
|
103 |
return; |
|
104 |
} |
|
105 |
resourceManager.closeMap(this); |
|
106 |
mapContext.dispose(); |
|
107 |
mapContext = null; |
|
108 |
} |
|
109 |
|
|
110 |
/** {@inheridDoc} */ |
|
111 |
public MapContext getMapContext() { |
|
112 |
if (!isOpen()) { |
|
113 |
throw new IllegalStateException("Map not open"); |
|
114 |
} |
|
115 |
return mapContext; |
|
116 |
} |
|
117 |
|
|
118 |
/** {@inheridDoc} */ |
|
119 |
public String getSourceFilePath() { |
|
120 |
return file.getAbsolutePath(); |
|
121 |
} |
|
122 |
|
|
123 |
public void dispose() { |
|
124 |
disposableManager.release(this); |
|
125 |
try { |
|
126 |
close(); |
|
127 |
} catch (IOException e) { |
|
128 |
LOG.warn("Problem dispossing PortableView", e); |
|
129 |
} |
|
130 |
|
|
131 |
} |
|
132 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/main/java/org/gvsig/educa/portableview/impl/map/PortableViewLoader.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.impl.map; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.io.IOException; |
|
26 |
import java.io.InputStream; |
|
27 |
import java.util.Enumeration; |
|
28 |
import java.util.zip.ZipEntry; |
|
29 |
import java.util.zip.ZipException; |
|
30 |
import java.util.zip.ZipFile; |
|
31 |
|
|
32 |
import org.slf4j.Logger; |
|
33 |
import org.slf4j.LoggerFactory; |
|
34 |
import org.gvsig.educa.portableview.PortableViewFileServices; |
|
35 |
import org.gvsig.educa.portableview.PortableViewLocator; |
|
36 |
import org.gvsig.educa.portableview.impl.util.FileUtils; |
|
37 |
import org.gvsig.educa.portableview.impl.util.IOUtils; |
|
38 |
import org.gvsig.educa.portableview.map.CantLoadContextException; |
|
39 |
import org.gvsig.educa.portableview.map.InvalidInstalledPortableViewException; |
|
40 |
import org.gvsig.educa.portableview.map.InvalidPortableViewFormatException; |
|
41 |
import org.gvsig.educa.portableview.map.PortableViewInformation; |
|
42 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
43 |
import org.gvsig.installer.lib.api.InstallerLocator; |
|
44 |
import org.gvsig.installer.lib.api.InstallerManager; |
|
45 |
import org.gvsig.installer.lib.api.PackageInfo; |
|
46 |
import org.gvsig.installer.lib.api.PackageInfoReader; |
|
47 |
import org.gvsig.tools.ToolsLocator; |
|
48 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
49 |
import org.gvsig.tools.persistence.PersistentState; |
|
50 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
51 |
|
|
52 |
/** |
|
53 |
* Utility class which contain methods to load data from a PortableView file |
|
54 |
* |
|
55 |
* @author gvSIG Team |
|
56 |
* @version $Id$ |
|
57 |
* |
|
58 |
*/ |
|
59 |
public class PortableViewLoader { |
|
60 |
|
|
61 |
@SuppressWarnings("unused") |
|
62 |
private static final Logger LOG = LoggerFactory |
|
63 |
.getLogger(PortableViewLoader.class); |
|
64 |
|
|
65 |
private final InstallerManager installerManager; |
|
66 |
|
|
67 |
private final PackageInfoReader packageInfoReader; |
|
68 |
|
|
69 |
private final PortableViewFileServices fileServices; |
|
70 |
|
|
71 |
/** |
|
72 |
* |
|
73 |
*/ |
|
74 |
public PortableViewLoader() { |
|
75 |
installerManager = InstallerLocator.getInstallerManager(); |
|
76 |
packageInfoReader = installerManager.getDefaultPackageInfoReader(); |
|
77 |
fileServices = PortableViewLocator.getFileServices(); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Loads the mapContext definition form the deploy folder of a portable view |
|
82 |
* |
|
83 |
* @param mapFile |
|
84 |
* portable view file name (for problems messages) |
|
85 |
* @param deployFolder |
|
86 |
* portable view deploy folder |
|
87 |
* @return |
|
88 |
* @throws InvalidPortableViewFormatException |
|
89 |
* @throws CantLoadContextException |
|
90 |
*/ |
|
91 |
public MapContext loadMapContextFromMapDeployFolder(File mapFile, |
|
92 |
File deployFolder) throws InvalidPortableViewFormatException, |
|
93 |
CantLoadContextException { |
|
94 |
|
|
95 |
// Prepares file path |
|
96 |
File mapContextFile = |
|
97 |
new File(deployFolder, "mapContext/mapContext.xml"); |
|
98 |
|
|
99 |
// Check if file exists |
|
100 |
if (!mapContextFile.exists()) { |
|
101 |
throw new InvalidPortableViewFormatException(mapFile, |
|
102 |
"Missing mapContext/mapContext.xml file in deployed map: " |
|
103 |
.concat(mapContextFile.getAbsolutePath())); |
|
104 |
} |
|
105 |
if (!mapContextFile.isFile()) { |
|
106 |
throw new InvalidPortableViewFormatException(mapFile, |
|
107 |
"mapContext/mapContext.xml file in deployed map is not a file: " |
|
108 |
.concat(mapContextFile.getAbsolutePath())); |
|
109 |
} |
|
110 |
|
|
111 |
// Load map context |
|
112 |
MapContext mapContext; |
|
113 |
try { |
|
114 |
|
|
115 |
mapContext = |
|
116 |
fileServices.loadMapContext(mapContextFile, deployFolder); |
|
117 |
|
|
118 |
if (mapContext == null) { |
|
119 |
throw new CantLoadContextException(mapFile, mapContextFile, |
|
120 |
"mapContext not loaded", null); |
|
121 |
} |
|
122 |
|
|
123 |
return mapContext; |
|
124 |
} catch (Exception e) { |
|
125 |
throw new CantLoadContextException(mapFile, mapContextFile, e); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* Gets information from a portableViewFile without uncompress it |
|
131 |
* |
|
132 |
* @param portableViewfile |
|
133 |
* @return |
|
134 |
* @throws InvalidPortableViewFormatException |
|
135 |
*/ |
|
136 |
public PortableViewInformation getInformationFromMapFile(File portableViewfile) |
|
137 |
throws InvalidPortableViewFormatException { |
|
138 |
|
|
139 |
PersistenceManager persistenceManager = |
|
140 |
ToolsLocator.getPersistenceManager(); |
|
141 |
|
|
142 |
// Try to open file |
|
143 |
ZipFile zipFile; |
|
144 |
try { |
|
145 |
zipFile = new ZipFile(portableViewfile); |
|
146 |
} catch (ZipException e1) { |
|
147 |
throw new InvalidPortableViewFormatException(portableViewfile, |
|
148 |
"Zip format problem", e1); |
|
149 |
} catch (IOException e1) { |
|
150 |
throw new InvalidPortableViewFormatException(portableViewfile, e1); |
|
151 |
} |
|
152 |
|
|
153 |
PersistentState pState = null; |
|
154 |
try { |
|
155 |
// gets zip file entries |
|
156 |
Enumeration<? extends ZipEntry> entries = zipFile.entries(); |
|
157 |
ZipEntry entry; |
|
158 |
|
|
159 |
// look for MapInfo entry |
|
160 |
while (entries.hasMoreElements()) { |
|
161 |
entry = entries.nextElement(); |
|
162 |
if (!entry.getName().equals("MapInfo.xml")) { |
|
163 |
continue; |
|
164 |
} |
|
165 |
|
|
166 |
// Check it's a file |
|
167 |
if (entry.isDirectory()) { |
|
168 |
throw new InvalidPortableViewFormatException( |
|
169 |
portableViewfile, "MapInfo.xml is a directory"); |
|
170 |
} |
|
171 |
|
|
172 |
// Load file into a persistence state |
|
173 |
InputStream is = null; |
|
174 |
try { |
|
175 |
try { |
|
176 |
is = zipFile.getInputStream(entry); |
|
177 |
pState = persistenceManager.loadState(is); |
|
178 |
} catch (IOException e) { |
|
179 |
throw new InvalidPortableViewFormatException( |
|
180 |
portableViewfile, "problem opening MapInfo.xml", e); |
|
181 |
} catch (PersistenceException e) { |
|
182 |
throw new InvalidPortableViewFormatException( |
|
183 |
portableViewfile, "problem loading MapInfo.xml", e); |
|
184 |
} |
|
185 |
} finally { |
|
186 |
IOUtils.closeQuietly(is); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
} finally { |
|
191 |
// Close zip file |
|
192 |
IOUtils.closeQuietly(zipFile); |
|
193 |
} |
|
194 |
|
|
195 |
// If MapInfo file not found |
|
196 |
if (pState == null) { |
|
197 |
throw new IllegalArgumentException("Missing MapInfo.xml"); |
|
198 |
} |
|
199 |
|
|
200 |
// Load data form persistence state |
|
201 |
DefaultPortableViewInformation info = |
|
202 |
new DefaultPortableViewInformation(); |
|
203 |
try { |
|
204 |
info.loadFromState(pState); |
|
205 |
} catch (PersistenceException e) { |
|
206 |
throw new IllegalArgumentException("Invalid MapInfo.xml format", e); |
|
207 |
} |
|
208 |
return info; |
|
209 |
|
|
210 |
} |
|
211 |
|
|
212 |
public PackageInfo getPackageInfoFromInstalledPortableView(File folder) |
|
213 |
throws InvalidInstalledPortableViewException { |
|
214 |
// Check for package.info file |
|
215 |
File packageInfoFile = new File(folder, "package.info"); |
|
216 |
if (!FileUtils.isReadableFile(packageInfoFile)) { |
|
217 |
return null; |
|
218 |
} |
|
219 |
|
|
220 |
PackageInfo packageInfo = installerManager.createPackageInfo(); |
|
221 |
InputStream in = null; |
|
222 |
try { |
|
223 |
in = FileUtils.openInputStream(packageInfoFile); |
|
224 |
packageInfoReader.read(packageInfo, in); |
|
225 |
} catch (Exception ex) { |
|
226 |
throw new InvalidInstalledPortableViewException(folder, ex); |
|
227 |
} finally { |
|
228 |
IOUtils.closeQuietly(in); |
|
229 |
} |
|
230 |
return packageInfo; |
|
231 |
} |
|
232 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/main/java/org/gvsig/educa/portableview/impl/map/DefaultPortableViewInformation.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.impl.map; |
|
23 |
|
|
24 |
import java.text.DateFormat; |
|
25 |
import java.text.ParseException; |
|
26 |
import java.util.Date; |
|
27 |
|
|
28 |
import org.cresques.cts.IProjection; |
|
29 |
import org.gvsig.educa.portableview.map.PortableViewInformation; |
|
30 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
31 |
import org.gvsig.tools.ToolsLocator; |
|
32 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
33 |
import org.gvsig.tools.dynobject.DynObject; |
|
34 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
35 |
import org.gvsig.tools.dynobject.DynStruct; |
|
36 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
37 |
import org.gvsig.tools.persistence.Persistent; |
|
38 |
import org.gvsig.tools.persistence.PersistentState; |
|
39 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
40 |
|
|
41 |
/** |
|
42 |
* Default implementation of {@link PortableViewInformation} |
|
43 |
* |
|
44 |
* @author gvSIG Team |
|
45 |
* @version $Id$ |
|
46 |
* |
|
47 |
*/ |
|
48 |
public class DefaultPortableViewInformation implements PortableViewInformation, |
|
49 |
Persistent { |
|
50 |
|
|
51 |
public static DynStruct dynDefinition; |
|
52 |
|
|
53 |
private String id; |
|
54 |
private String name; |
|
55 |
private String description; |
|
56 |
private int version; |
|
57 |
private int buildNumber; |
|
58 |
private Date creationTimestamp; |
|
59 |
private Envelope envelope; |
|
60 |
private IProjection crs; |
|
61 |
|
|
62 |
/** {@inheridDoc} */ |
|
63 |
public String getId() { |
|
64 |
return id; |
|
65 |
} |
|
66 |
|
|
67 |
/** {@inheridDoc} */ |
|
68 |
public String getName() { |
|
69 |
return name; |
|
70 |
} |
|
71 |
|
|
72 |
/** {@inheridDoc} */ |
|
73 |
public String getDescription() { |
|
74 |
return description; |
|
75 |
} |
|
76 |
|
|
77 |
/** {@inheridDoc} */ |
|
78 |
public int getVersion() { |
|
79 |
return version; |
|
80 |
} |
|
81 |
|
|
82 |
/** {@inheridDoc} */ |
|
83 |
public int getBuildNumber() { |
|
84 |
return buildNumber; |
|
85 |
} |
|
86 |
|
|
87 |
/** {@inheridDoc} */ |
|
88 |
public Date getCreationTimestamp() { |
|
89 |
return creationTimestamp; |
|
90 |
} |
|
91 |
|
|
92 |
/** {@inheridDoc} */ |
|
93 |
public Envelope getFullEnvelope() { |
|
94 |
if (envelope == null) { |
|
95 |
return null; |
|
96 |
} |
|
97 |
try { |
|
98 |
return (Envelope) envelope.clone(); |
|
99 |
} catch (CloneNotSupportedException e) { |
|
100 |
throw new IllegalStateException(e); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
/** {@inheridDoc} */ |
|
105 |
public IProjection getCRS() { |
|
106 |
return crs; |
|
107 |
} |
|
108 |
|
|
109 |
/** {@inheridDoc} */ |
|
110 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
111 |
state.set("id", id); |
|
112 |
state.set("name", name); |
|
113 |
state.set("description", description); |
|
114 |
state.set("version", version); |
|
115 |
state.set("buildNumber", buildNumber); |
|
116 |
state.set("creationTimestamp", creationTimestamp); |
|
117 |
state.set("envelope", envelope); |
|
118 |
state.set("crs", crs); |
|
119 |
} |
|
120 |
|
|
121 |
/** {@inheridDoc} */ |
|
122 |
public DynObject getDynObject() { |
|
123 |
DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
|
124 |
DynObject obj = manager.createDynObject(dynDefinition); |
|
125 |
obj.setDynValue("id", id); |
|
126 |
obj.setDynValue("name", name); |
|
127 |
obj.setDynValue("description", description); |
|
128 |
obj.setDynValue("version", version); |
|
129 |
obj.setDynValue("buildNumber", buildNumber); |
|
130 |
obj.setDynValue("creationTimestamp", creationTimestamp); |
|
131 |
obj.setDynValue("envelope", envelope); |
|
132 |
obj.setDynValue("crs", crs); |
|
133 |
|
|
134 |
return obj; |
|
135 |
} |
|
136 |
|
|
137 |
/** {@inheridDoc} */ |
|
138 |
public void loadFromState(PersistentState state) |
|
139 |
throws PersistenceException { |
|
140 |
id = state.getString("id"); |
|
141 |
name = state.getString("name"); |
|
142 |
description = state.getString("description"); |
|
143 |
version = state.getInt("version"); |
|
144 |
buildNumber = state.getInt("buildNumber"); |
|
145 |
creationTimestamp = state.getDate("creationTimestamp"); |
|
146 |
envelope = (Envelope) state.get("envelope"); |
|
147 |
crs = (IProjection) state.get("crs"); |
|
148 |
} |
|
149 |
|
|
150 |
protected void setId(String id) { |
|
151 |
this.id = id; |
|
152 |
} |
|
153 |
|
|
154 |
protected void setName(String name) { |
|
155 |
this.name = name; |
|
156 |
} |
|
157 |
|
|
158 |
protected void setDescription(String description) { |
|
159 |
this.description = description; |
|
160 |
} |
|
161 |
|
|
162 |
protected void setVersion(int version) { |
|
163 |
this.version = version; |
|
164 |
} |
|
165 |
|
|
166 |
protected void setBuildNumber(int buildNumber) { |
|
167 |
this.buildNumber = buildNumber; |
|
168 |
} |
|
169 |
|
|
170 |
protected void setCreationTimestamp(Date creationTimestamp) { |
|
171 |
this.creationTimestamp = creationTimestamp; |
|
172 |
} |
|
173 |
|
|
174 |
protected void setFullEnvelope(Envelope envelope) { |
|
175 |
try { |
|
176 |
this.envelope = (Envelope) envelope.clone(); |
|
177 |
} catch (CloneNotSupportedException e) { |
|
178 |
throw new IllegalArgumentException(e); |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
protected void setCrs(IProjection crs) { |
|
183 |
this.crs = crs; |
|
184 |
} |
|
185 |
|
|
186 |
public DynStruct getDynDefinition() { |
|
187 |
return dynDefinition; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* Utility method to register {@link PortableViewInformation} definition in |
|
192 |
* the {@link PersistenceManager} |
|
193 |
*/ |
|
194 |
public static void registerPersistent() { |
|
195 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
196 |
DynStruct definition = |
|
197 |
manager.addDefinition(DefaultPortableViewInformation.class, |
|
198 |
PortableViewInformation.DYN_DEFINITION_NAME, |
|
199 |
"Portable View information", null, null); |
|
200 |
|
|
201 |
definition.addDynFieldString("id").setMandatory(true); |
|
202 |
definition.addDynFieldString("name").setMandatory(true); |
|
203 |
definition.addDynFieldString("description").setMandatory(true); |
|
204 |
definition.addDynFieldInt("version").setMandatory(true); |
|
205 |
definition.addDynFieldInt("buildNumber").setMandatory(true); |
|
206 |
definition.addDynFieldDate("creationTimestamp").setMandatory(true); |
|
207 |
definition.addDynFieldObject("envelope") |
|
208 |
.setClassOfValue(Envelope.class).setMandatory(true); |
|
209 |
definition.addDynFieldObject("crs").setClassOfValue(IProjection.class) |
|
210 |
.setMandatory(true); |
|
211 |
|
|
212 |
dynDefinition = definition; |
|
213 |
|
|
214 |
} |
|
215 |
|
|
216 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/main/java/org/gvsig/educa/portableview/impl/util/IOUtils.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.impl.util; |
|
23 |
|
|
24 |
import java.io.IOException; |
|
25 |
import java.util.zip.ZipFile; |
|
26 |
|
|
27 |
/** |
|
28 |
* <p> |
|
29 |
* File utilities. Extends the provides by <i>apache-common-IO</i> |
|
30 |
* </p> |
|
31 |
* |
|
32 |
* @author gvSIG Team |
|
33 |
* @version $Id$ |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class IOUtils extends org.apache.commons.io.IOUtils { |
|
37 |
|
|
38 |
/** |
|
39 |
* Unconditionally close an <code>ZipFile</code>. |
|
40 |
* <p> |
|
41 |
* Equivalent to {@link ZipFile#close()}, except any exceptions will be ignored. |
|
42 |
* This is typically used in finally blocks. |
|
43 |
* |
|
44 |
* @param zipFile the ZipFile to close, may be null or already closed |
|
45 |
*/ |
|
46 |
public static void closeQuietly(ZipFile zipFile) { |
|
47 |
if (zipFile != null) { |
|
48 |
try { |
|
49 |
zipFile.close(); |
|
50 |
} catch (IOException e) { |
|
51 |
// ignore |
|
52 |
} |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.143/org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/main/java/org/gvsig/educa/portableview/impl/util/FileUtils.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.impl.util; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.io.IOException; |
|
26 |
import java.io.InputStream; |
|
27 |
import java.io.OutputStream; |
|
28 |
import java.util.Collection; |
|
29 |
import java.util.Enumeration; |
|
30 |
import java.util.zip.ZipEntry; |
|
31 |
import java.util.zip.ZipException; |
|
32 |
import java.util.zip.ZipFile; |
|
33 |
import java.util.zip.ZipOutputStream; |
|
34 |
|
|
35 |
import org.apache.commons.io.DirectoryWalker; |
|
36 |
import org.apache.commons.lang3.StringUtils; |
|
37 |
import org.slf4j.Logger; |
|
38 |
import org.slf4j.LoggerFactory; |
|
39 |
|
|
40 |
/** |
|
41 |
* <p> |
|
42 |
* File utilities. Extends the provides by <i>apache-common-IO</i> |
|
43 |
* </p> |
|
44 |
* |
|
45 |
* @author gvSIG Team |
|
46 |
* @version $Id$ |
|
47 |
* |
|
48 |
*/ |
|
49 |
public abstract class FileUtils extends org.apache.commons.io.FileUtils { |
|
50 |
|
|
51 |
private static final Logger LOG = LoggerFactory.getLogger(FileUtils.class); |
|
52 |
|
|
53 |
public static final boolean UNIXLIKE_FILESYSTEM = File.separatorChar == '/'; |
|
54 |
|
|
55 |
/** |
|
56 |
* <p> |
|
57 |
* Unzip a file into a folder |
|
58 |
* </p> |
|
59 |
* |
|
60 |
* @param zipFile |
|
61 |
* @param outputFloder |
|
62 |
* must exists. WARNING: <b>Contents will be removed before |
|
63 |
* unzip</b> |
|
64 |
* @throws IOException |
|
65 |
* @throws ZipException |
|
66 |
* @throws IllegalArgumentException |
|
67 |
* if zipFile is not a file or outputFloder doesn't exists or is |
|
68 |
* read-only |
|
69 |
*/ |
|
70 |
public static void unzipFile(File zipFile, File outputFloder) |
|
71 |
throws ZipException, IOException { |
|
72 |
|
|
73 |
if (LOG.isDebugEnabled()) { |
|
74 |
LOG.debug( |
|
75 |
"Unzip {} --> {}", |
|
76 |
new Object[] { zipFile.getAbsolutePath(), |
|
77 |
outputFloder.getAbsolutePath() }); |
|
78 |
} |
|
79 |
|
|
80 |
// basic checks input file |
|
81 |
if (!zipFile.exists()) { |
|
82 |
throw new IllegalArgumentException("File '".concat( |
|
83 |
zipFile.getAbsolutePath()).concat("' no exists")); |
|
84 |
} |
|
85 |
if (!zipFile.isFile()) { |
|
86 |
throw new IllegalArgumentException("'".concat( |
|
87 |
zipFile.getAbsolutePath()).concat("' is not a file")); |
|
88 |
} |
|
89 |
if (!zipFile.canRead()) { |
|
90 |
throw new IllegalArgumentException("File '".concat( |
|
91 |
zipFile.getAbsolutePath()).concat("' can not be readed")); |
|
92 |
} |
|
93 |
|
|
94 |
// basic checks output file |
|
95 |
if (!outputFloder.exists()) { |
|
96 |
throw new IllegalArgumentException("Folder '".concat( |
|
97 |
outputFloder.getAbsolutePath()).concat("' not exists.")); |
|
98 |
} |
|
99 |
if (!outputFloder.isDirectory()) { |
|
100 |
throw new IllegalArgumentException("'".concat( |
|
101 |
outputFloder.getAbsolutePath()) |
|
102 |
.concat("' is not a folder.")); |
|
103 |
} |
|
104 |
if (!outputFloder.canWrite()) { |
|
105 |
throw new IllegalArgumentException("Can't write on'".concat( |
|
106 |
outputFloder.getAbsolutePath()).concat("' folder.")); |
|
107 |
} |
|
108 |
|
|
109 |
if (LOG.isTraceEnabled()) { |
|
110 |
LOG.trace("cleaning directory {}", outputFloder.getAbsolutePath()); |
|
111 |
} |
|
112 |
|
|
113 |
cleanDirectory(outputFloder); |
|
114 |
|
|
115 |
// Extract file |
|
116 |
ZipFile openedZipFile = null; |
|
117 |
try { |
|
118 |
openedZipFile = new ZipFile(zipFile); |
|
119 |
Enumeration<? extends ZipEntry> entries = openedZipFile.entries(); |
|
120 |
ZipEntry entry; |
|
121 |
File targetFile; |
|
122 |
// iterate over entries |
|
123 |
while (entries.hasMoreElements()) { |
|
124 |
entry = entries.nextElement(); |
|
125 |
|
|
126 |
// compound target path |
|
127 |
targetFile = new File(outputFloder, entry.getName()); |
|
128 |
|
|
129 |
if (entry.isDirectory()) { |
|
130 |
// Create folder |
|
131 |
if (LOG.isTraceEnabled()) { |
|
132 |
LOG.trace("creating folder {}", |
|
133 |
targetFile.getAbsolutePath()); |
|
134 |
} |
|
135 |
|
|
136 |
if (!targetFile.mkdirs()) { |
|
137 |
throw new IOException("Can't create '".concat( |
|
138 |
targetFile.getAbsolutePath()).concat( |
|
139 |
"' folder.")); |
|
140 |
} |
|
141 |
} else { |
|
142 |
// extract file from zip |
|
143 |
if (LOG.isTraceEnabled()) { |
|
144 |
LOG.trace("extracting file {}", |
|
145 |
targetFile.getAbsolutePath()); |
|
146 |
} |
|
147 |
extractZipEntry(openedZipFile, entry, targetFile); |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
} finally { |
|
152 |
IOUtils.closeQuietly(openedZipFile); |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Extract a zipEntry into a file |
|
158 |
* |
|
159 |
* @param zipFile |
|
160 |
* @param entry |
|
161 |
* @param target |
|
162 |
* (if exists will be overwrite) |
|
163 |
* @throws IOException |
|
164 |
*/ |
|
165 |
private static void extractZipEntry(ZipFile zipFile, ZipEntry entry, |
|
166 |
File target) throws IOException { |
|
167 |
InputStream is = null; |
|
168 |
OutputStream os = null; |
|
169 |
try { |
|
170 |
is = zipFile.getInputStream(entry); |
|
171 |
os = openOutputStream(target); |
|
172 |
IOUtils.copy(is, os); |
|
173 |
} finally { |
|
174 |
IOUtils.closeQuietly(is); |
|
175 |
IOUtils.closeQuietly(os); |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* <p> |
|
181 |
* Create a zip file which will contains all contents of a folder |
|
182 |
* </p> |
|
183 |
* <p> |
|
184 |
* Files will be use relative path to <code>rootFolder</code> |
|
185 |
* </p> |
|
186 |
* |
|
187 |
* @param rootFolder |
|
188 |
* rootFolder (must be an existing folder) |
|
189 |
* @param targetFile |
|
190 |
* final file (must not exists) |
|
191 |
* @throws IOException |
|
192 |
* @throws IllegalArgumentException |
|
193 |
* if there are any problem in parameters |
|
194 |
*/ |
|
195 |
public static void zipFolder(File rootFolder, File targetFile) |
|
196 |
throws IOException { |
|
197 |
if (LOG.isDebugEnabled()) { |
|
198 |
LOG.debug( |
|
199 |
"zip {} --> {}", |
|
200 |
new Object[] { rootFolder.getAbsolutePath(), |
|
201 |
targetFile.getAbsolutePath() }); |
|
202 |
} |
|
203 |
|
|
204 |
if (!isReadableFolder(rootFolder)) { |
|
205 |
throw new IllegalArgumentException("Invalid folder"); |
|
206 |
} |
|
207 |
if (targetFile.exists()) { |
|
208 |
throw new IllegalArgumentException("Target file already exists"); |
|
209 |
} |
|
210 |
if (!isWritableFolder(targetFile.getParentFile())) { |
|
211 |
throw new IllegalArgumentException("Can't write in target folder"); |
|
212 |
} |
|
213 |
RelativePathFolderZipper zipper = new RelativePathFolderZipper( |
|
214 |
rootFolder, targetFile); |
|
215 |
|
|
216 |
zipper.zip(); |
|
217 |
|
|
218 |
} |
|
219 |
|
|
220 |
/** |
|
221 |
* Informs if <code>folder</code> is a writable folder( exists & isDir & |
|
222 |
* canWrite) |
|
223 |
* |
|
224 |
* @param folder |
|
225 |
* @return |
|
226 |
*/ |
|
227 |
public static boolean isWritableFolder(File folder) { |
|
228 |
return folder.exists() && folder.isDirectory() && folder.canWrite(); |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Informs if <code>folder</code> is a readable folder( exists & isDir & |
|
233 |
* canRead) |
|
234 |
* |
|
235 |
* @param folder |
Also available in: Unified diff