svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.lib / org.gvsig.exportto.lib.impl / src / main / java / org / gvsig / export / impl / DefaultExportManager.java @ 44390
History | View | Annotate | Download (6.23 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | 41537 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40435 | jjdelcerro | *
|
11 | 41537 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40435 | jjdelcerro | *
|
16 | 41537 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40435 | jjdelcerro | *
|
20 | 41537 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | 43925 | jjdelcerro | package org.gvsig.export.impl; |
24 | 40435 | jjdelcerro | |
25 | import java.io.File; |
||
26 | import java.io.FileInputStream; |
||
27 | import java.io.FileOutputStream; |
||
28 | import java.io.IOException; |
||
29 | 43925 | jjdelcerro | import java.util.ArrayList; |
30 | 40435 | jjdelcerro | import java.util.HashMap; |
31 | 43925 | jjdelcerro | import java.util.List; |
32 | 40435 | jjdelcerro | import java.util.Map; |
33 | import java.util.Properties; |
||
34 | 43925 | jjdelcerro | import org.apache.commons.io.IOUtils; |
35 | import org.cresques.cts.IProjection; |
||
36 | 40435 | jjdelcerro | |
37 | import org.slf4j.Logger; |
||
38 | import org.slf4j.LoggerFactory; |
||
39 | |||
40 | 43925 | jjdelcerro | import org.gvsig.export.ExportManager; |
41 | 44390 | jjdelcerro | import org.gvsig.export.ExportParameters; |
42 | 43925 | jjdelcerro | import org.gvsig.export.ExportProcess; |
43 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
44 | 44390 | jjdelcerro | import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
45 | import org.gvsig.tools.bookmarksandhistory.History; |
||
46 | import org.gvsig.tools.bookmarksandhistory.impl.BaseBookmarks; |
||
47 | import org.gvsig.tools.bookmarksandhistory.impl.BaseHistory; |
||
48 | 40435 | jjdelcerro | |
49 | /**
|
||
50 | 43925 | jjdelcerro | * Default {@link ExportManager} implementation.
|
51 | 41537 | jjdelcerro | *
|
52 | 40435 | jjdelcerro | * @author gvSIG Team
|
53 | * @version $Id$
|
||
54 | */
|
||
55 | 43925 | jjdelcerro | public class DefaultExportManager implements ExportManager { |
56 | 40435 | jjdelcerro | |
57 | 43925 | jjdelcerro | private static final Logger LOG = LoggerFactory.getLogger(DefaultExportManager.class); |
58 | |||
59 | private static class DefaultExportFilter implements ExportFilter { |
||
60 | 40435 | jjdelcerro | |
61 | 43925 | jjdelcerro | private final String name; |
62 | private final String expression; |
||
63 | |||
64 | public DefaultExportFilter(String name, String expression) { |
||
65 | this.name = name;
|
||
66 | this.expression = expression;
|
||
67 | } |
||
68 | |||
69 | @Override
|
||
70 | public String getName() { |
||
71 | return name;
|
||
72 | } |
||
73 | |||
74 | @Override
|
||
75 | public String getExpression() { |
||
76 | return expression;
|
||
77 | } |
||
78 | } |
||
79 | |||
80 | private Map<String, ExportFilter> filters = null; |
||
81 | 41537 | jjdelcerro | private File homeFolder = null; |
82 | 44390 | jjdelcerro | private final History<ExportParameters> history; |
83 | private final Bookmarks<ExportParameters> bookmarks; |
||
84 | 40435 | jjdelcerro | |
85 | 44390 | jjdelcerro | |
86 | 43925 | jjdelcerro | public DefaultExportManager() {
|
87 | 40435 | jjdelcerro | super();
|
88 | 44390 | jjdelcerro | this.history = new BaseHistory<>(10); |
89 | this.bookmarks = new BaseBookmarks<>(); |
||
90 | 40435 | jjdelcerro | } |
91 | |||
92 | 43925 | jjdelcerro | private void loadFilters() { |
93 | this.filters = new HashMap<>(); |
||
94 | if (this.homeFolder != null) { |
||
95 | File filtersFile = new File(this.homeFolder, "filters"); |
||
96 | if (filtersFile.exists()) {
|
||
97 | FileInputStream fis = null; |
||
98 | try {
|
||
99 | fis = new FileInputStream(filtersFile); |
||
100 | Properties properties = new Properties(); |
||
101 | properties.load(fis); |
||
102 | for (Object name : properties.keySet()) { |
||
103 | String value = (String) properties.get(name); |
||
104 | ExportFilter filter = new DefaultExportFilter((String) name, value); |
||
105 | this.filters.put(filter.getName(), filter);
|
||
106 | 41537 | jjdelcerro | } |
107 | 43925 | jjdelcerro | } catch (IOException ex) { |
108 | LOG.warn("Can't load filters file '" + filtersFile.getAbsolutePath() + "'.", ex); |
||
109 | } finally {
|
||
110 | IOUtils.closeQuietly(fis); |
||
111 | 41537 | jjdelcerro | } |
112 | } |
||
113 | } |
||
114 | 40435 | jjdelcerro | } |
115 | |||
116 | 43925 | jjdelcerro | public void saveFilters() { |
117 | 41537 | jjdelcerro | if (this.homeFolder != null) { |
118 | Properties properties = new Properties(); |
||
119 | 43925 | jjdelcerro | for (ExportFilter filter : this.filters.values()) { |
120 | properties.setProperty(filter.getName(), filter.getExpression()); |
||
121 | 41537 | jjdelcerro | } |
122 | File filtersFile = new File(this.homeFolder, "filters"); |
||
123 | 43925 | jjdelcerro | FileOutputStream fos = null; |
124 | 41537 | jjdelcerro | try {
|
125 | 43925 | jjdelcerro | fos = new FileOutputStream(filtersFile); |
126 | properties.store(fos, "");
|
||
127 | 41537 | jjdelcerro | } catch (IOException ex) { |
128 | LOG.warn("Can't load filters file '" + filtersFile.getAbsolutePath() + "'.", ex); |
||
129 | 43925 | jjdelcerro | } finally {
|
130 | IOUtils.closeQuietly(fos); |
||
131 | 41537 | jjdelcerro | } |
132 | } |
||
133 | 43925 | jjdelcerro | |
134 | 41537 | jjdelcerro | } |
135 | 43925 | jjdelcerro | |
136 | public Map<String,ExportFilter> getFiltersAsMap() { |
||
137 | if (this.filters == null) { |
||
138 | loadFilters(); |
||
139 | } |
||
140 | return this.filters; |
||
141 | } |
||
142 | |||
143 | @Override
|
||
144 | public List<ExportFilter> getFilters() { |
||
145 | List<ExportFilter> l = new ArrayList<>(); |
||
146 | l.addAll(this.getFiltersAsMap().values());
|
||
147 | return l;
|
||
148 | } |
||
149 | 41537 | jjdelcerro | |
150 | 43364 | jjdelcerro | @Override
|
151 | 43925 | jjdelcerro | public ExportFilter getFilter(String filterName) { |
152 | return this.getFiltersAsMap().get(filterName); |
||
153 | } |
||
154 | |||
155 | @Override
|
||
156 | public ExportFilter addFilter(String name, String expression) { |
||
157 | ExportFilter filter = new DefaultExportFilter(name, expression);
|
||
158 | this.filters.put(filter.getName(), filter);
|
||
159 | return filter;
|
||
160 | } |
||
161 | |||
162 | @Override
|
||
163 | 41537 | jjdelcerro | public void setHomeFolder(File homeFolder) { |
164 | this.homeFolder = homeFolder;
|
||
165 | } |
||
166 | |||
167 | 43925 | jjdelcerro | @Override
|
168 | public ExportProcess createProcess() {
|
||
169 | ExportProcess process = new DefaultExportProcess();
|
||
170 | return process;
|
||
171 | } |
||
172 | |||
173 | @Override
|
||
174 | public ExportProcess createProcess(FeatureStore store) {
|
||
175 | ExportProcess process = new DefaultExportProcess();
|
||
176 | process.setSourceFeatureStore(store); |
||
177 | return process;
|
||
178 | } |
||
179 | |||
180 | @Override
|
||
181 | public ExportProcess createProcess(FeatureStore store, IProjection contextProjection) {
|
||
182 | ExportProcess process = new DefaultExportProcess();
|
||
183 | process.setSourceFeatureStore(store); |
||
184 | process.setContextProjection(contextProjection); |
||
185 | return process;
|
||
186 | } |
||
187 | |||
188 | 44390 | jjdelcerro | |
189 | @Override
|
||
190 | public History<ExportParameters> getHistory() {
|
||
191 | return this.history; |
||
192 | } |
||
193 | |||
194 | @Override
|
||
195 | public Bookmarks<ExportParameters> getBookmarks() {
|
||
196 | return this.bookmarks; |
||
197 | } |
||
198 | 40435 | jjdelcerro | } |