Revision 9705

View differences:

org.gvsig.report/tags/org.gvsig.report-1.0.179/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.report.lib.impl.ReportImplLibrary
org.gvsig.report/tags/org.gvsig.report-1.0.179/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/DefaultReportDataSet.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 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 3
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
package org.gvsig.report.lib.impl;
25

  
26
import java.io.File;
27
import java.io.IOException;
28
import java.util.List;
29
import org.apache.commons.lang3.StringUtils;
30
import org.gvsig.expressionevaluator.Expression;
31
import org.gvsig.expressionevaluator.ExpressionBuilder;
32
import org.gvsig.expressionevaluator.ExpressionUtils;
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataManager;
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
38
import org.gvsig.fmap.dal.feature.Feature;
39
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
40
import org.gvsig.fmap.dal.feature.FeatureQuery;
41
import org.gvsig.fmap.dal.feature.FeatureQueryOrder;
42
import org.gvsig.fmap.dal.feature.FeatureReference;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
import org.gvsig.fmap.dal.feature.FeatureType;
45
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
46
import org.gvsig.tools.visitor.Visitor;
47
import org.json.JSONObject;
48
import org.gvsig.report.lib.api.ReportDataSet;
49
import org.gvsig.report.lib.api.ReportServices;
50
import org.gvsig.tools.exception.BaseException;
51
import org.gvsig.tools.util.UnmodifiableBasicList64;
52
import org.gvsig.tools.util.UnmodifiableBasicList64Adapter;
53
import org.gvsig.tools.visitor.VisitCanceledException;
54
import org.json.JSONArray;
55

  
56
/**
57
 *
58
 * @author jjdelcerro
59
 */
60
@SuppressWarnings("EqualsAndHashcode")
61
public class DefaultReportDataSet implements ReportDataSet {
62

  
63
    private final ReportServices services;
64
    private String name;
65
    private FeatureStore store;
66
    private String fullName;
67
    private File path;
68
    private int limit;
69
    private Expression filter;
70
    private boolean exposeGeometry;
71
    private final DefaultSelectionOfFeatures selectionOfFeatures;
72
    private FeatureQuery query;
73

  
74
    public DefaultReportDataSet(ReportServices services, String name, FeatureStore store) {
75
        this.services = services;
76
        this.name = name;
77
        this.store = store;
78
        this.selectionOfFeatures = new DefaultSelectionOfFeatures(this);
79
        if (store != null) {
80
            this.fullName = store.getFullName();
81
            DataStoreParameters parameters = this.store.getParameters();
82
            if (parameters instanceof FilesystemStoreParameters) {
83
                this.path = ((FilesystemStoreParameters) parameters).getFile();
84
            }
85
        }
86
        this.limit = FeatureQuery.NO_LIMIT;
87
        this.query = store.createFeatureQuery();
88
    }
89

  
90
    public DefaultReportDataSet(ReportServices services, String name, FeatureStore store, FeatureQuery query) {
91
        this(services, name, store);
92
        if (query == null) {
93
            this.query = store.createFeatureQuery();
94
        } else {
95
            this.query = query;
96
        }
97
    }
98

  
99
    public DefaultReportDataSet(ReportServices services, JSONObject jsonDataSet) {
100
        this.services = services;
101
        this.selectionOfFeatures = new DefaultSelectionOfFeatures(this);
102
        this.name = jsonDataSet.getString("name");
103
        this.fullName = jsonDataSet.getString("fullName");
104
        this.limit = jsonDataSet.getInt("limit");
105
        if (jsonDataSet.has("filter")) {
106
            this.filter = ExpressionUtils.createExpression();
107
            this.filter.fromJSON(jsonDataSet.getString("filter"));
108
        } else {
109
            this.filter = null;
110
        }
111
        this.exposeGeometry = jsonDataSet.getBoolean("exposeGeometry");
112
        if (jsonDataSet.has("path")) {
113
            this.path = this.services.derelativizeFile(
114
                    new File(jsonDataSet.getString("path"))
115
            );
116
        }
117
        this.store = null;
118
        if (jsonDataSet.has("features")) {
119
            JSONArray jsonFeatures = jsonDataSet.getJSONArray("features");
120
            for (Object x : jsonFeatures) {
121
                String referenceCode = (String) x;
122
                this.selectionOfFeatures.add(referenceCode);
123
            }
124
        }
125
    }
126

  
127
    JSONObject toJSON() {
128
        JSONObject jsonDataSet = new JSONObject();
129
        jsonDataSet.put("name", this.name);
130
        jsonDataSet.put("limit", this.limit);
131
        jsonDataSet.put("filter", this.filter);
132
        jsonDataSet.put("fullName", this.fullName);
133
        jsonDataSet.put("exposeGeometry", this.exposeGeometry);
134
        if (this.path != null) {
135
            jsonDataSet.put("path", this.services.relativizeFile(this.path).getPath());
136
        }
137
        if (!this.selectionOfFeatures.isEmpty()) {
138
            JSONArray jsonFeatures = new JSONArray();
139
            for (int i = 0; i < this.selectionOfFeatures.size64(); i++) {
140
                FeatureReference reference = this.selectionOfFeatures.getReference(i);
141
                jsonFeatures.put(reference.getCode());
142
            }
143
            jsonDataSet.put("features", jsonFeatures);
144
        }
145
        return jsonDataSet;
146
    }
147

  
148
    @Override
149
    public boolean equals(Object obj) {
150
        if (!(obj instanceof DefaultReportDataSet)) {
151
            return false;
152
        }
153
        DefaultReportDataSet other = (DefaultReportDataSet) obj;
154
        if (this.store != other.store) {
155
            return false;
156
        }
157
        if (!StringUtils.equals(this.getName(), other.getName())) {
158
            return false;
159
        }
160
        return true;
161
    }
162

  
163
    @Override
164
    public String getName() {
165
        return this.name;
166
    }
167

  
168
    @Override
169
    public void setName(String name) {
170
        this.name = name;
171
    }
172

  
173
    @Override
174
    @SuppressWarnings("UseSpecificCatch")
175
    public String toString() {
176
        try {
177
            FeatureAttributeDescriptor attr = this.getStore().getDefaultFeatureType().getDefaultGeometryAttribute();
178
            String geomType = attr.getGeomType().getName();
179
            return this.name + " (" + geomType + ")";
180
        } catch (Exception ex) {
181
            return this.name;
182
        }
183
    }
184

  
185
    @Override
186
    public FeatureStore getStore() {
187
        if (this.store == null) {
188
            this.store = this.services.getFeatureStore(this);
189
        }
190
        if (this.store != null) {
191
            DataStoreParameters parameters = this.store.getParameters();
192
            if (parameters instanceof FilesystemStoreParameters) {
193
                this.path = ((FilesystemStoreParameters) parameters).getFile();
194
            }
195
        }
196
        return this.store;
197
    }
198

  
199
    @Override
200
    public FeatureType getFeatureType() {
201
        FeatureStore theStore = this.getStore();
202
        try {
203
            return theStore.getDefaultFeatureType();
204
        } catch (DataException ex) {
205
            return null;
206
        }
207
    }
208

  
209
    @Override
210
    public boolean hasThisStore(FeatureStore store) {
211
        if (store == null) {
212
            return false;
213
        }
214
        if (this.path != null) {
215
            try {
216
                DataStoreParameters parameters = store.getParameters();
217
                if (parameters instanceof FilesystemStoreParameters) {
218
                    File thePath = ((FilesystemStoreParameters) parameters).getFile();
219
                    if (this.path.getCanonicalPath().equals(thePath.getCanonicalPath())) {
220
                        return true;
221
                    }
222
                }
223
            } catch (IOException ex) {
224
            }
225
        }
226
        return StringUtils.equals(this.fullName, store.getFullName());
227
    }
228

  
229
    @Override
230
    public void accept(Visitor visitor) {
231
        this.accept(visitor, (Expression) null, null, true);
232
    }
233

  
234
    @Override
235
    public void accept(Visitor visitor, Expression filter) {
236
        this.accept(visitor, filter, null, true);
237
    }
238

  
239
    @Override
240
    public void accept(final Visitor visitor, String filter, String sortfields, boolean ascending) {
241
        this.accept(visitor, ExpressionUtils.createExpression(filter), sortfields, ascending);
242
    }
243

  
244
    @Override
245
    @SuppressWarnings("UseSpecificCatch")
246
    public void accept(final Visitor visitor, final Expression filter, String sortfields, boolean ascending) {
247
        try {
248
            if (this.selectionOfFeatures.isEmpty()) {
249
                FeatureQuery dataQuery = this.getQuery();
250
                if (filter != null) {
251
                    dataQuery.addFilter(filter);
252
                    dataQuery.retrievesAllAttributes();
253
                }
254
                if (!StringUtils.isEmpty(sortfields)) {
255
                    FeatureQueryOrder order = dataQuery.getOrder();
256
                    for (String field : StringUtils.split(sortfields, ',')) {
257
                        order.add(field, ascending);
258
                    }
259
                }
260
                FeatureStore st = this.getStore();
261
                st.accept(visitor, dataQuery);
262
                return;
263
            }
264
            if (filter == null) {
265
                this.selectionOfFeatures.accept(visitor);
266
                return;
267
            }
268
            DataManager manager = DALLocator.getDataManager();
269
            final FeatureSymbolTable featureSymbolTable = manager.createFeatureSymbolTable();
270
            this.selectionOfFeatures.accept(new Visitor() {
271
                @Override
272
                public void visit(Object o) throws VisitCanceledException, BaseException {
273
                    featureSymbolTable.setFeature((Feature) o);
274
                    Boolean r = (Boolean) filter.execute(featureSymbolTable);
275
                    if (r) {
276
                        visitor.visit(o);
277
                    }
278
                }
279
            });
280
        } catch (Exception ex) {
281
            throw new RuntimeException(ex);
282
        }
283
    }
284

  
285
    @Override
286
    public FeatureQuery getQuery() {
287
        return this.getQuery(null);
288
    }
289

  
290
    public FeatureQuery getQuery(Expression filter) {
291
        FeatureQuery dataQuery = this.query; 
292
        if (!ExpressionUtils.isPhraseEmpty(this.filter) && !ExpressionUtils.isPhraseEmpty(filter)) {
293
            ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
294
            Expression f = ExpressionUtils.createExpression(
295
                    builder.and(filter, this.filter).toString()
296
            );
297
            dataQuery.addFilter(f);
298
            dataQuery.retrievesAllAttributes();
299
        } else if (!ExpressionUtils.isPhraseEmpty(this.filter)) {
300
            dataQuery.addFilter(this.filter);
301
            dataQuery.retrievesAllAttributes();
302
        } else if (!ExpressionUtils.isPhraseEmpty(filter)) {
303
            dataQuery.addFilter(filter);
304
            dataQuery.retrievesAllAttributes();
305
        }
306
        dataQuery.setLimit(limit);
307
        return dataQuery;
308
    }
309

  
310
    @Override
311
    public SelectionOfFeatures getSelectionOfFeatures() {
312
        return this.selectionOfFeatures;
313
    }
314

  
315
    @Override
316
    public UnmodifiableBasicList64<Feature> getFeatures() {
317
        return this.getFeatures(null);
318
    }
319

  
320
    @Override
321
    public UnmodifiableBasicList64<Feature> getFeatures(Expression filter) {
322
        List<Feature> r;
323
        if (this.selectionOfFeatures.isEmpty()) {
324
            FeatureStore theStore = this.getStore();
325
            FeatureQuery query = this.getQuery(filter);
326
            r = theStore.getFeatures(query);
327
            return new UnmodifiableBasicList64Adapter<>(r);
328
        }
329
        return this.getSelectionOfFeatures();
330
    }
331

  
332
    @Override
333
    public int getLimit() {
334
        return this.limit;
335
    }
336

  
337
    @Override
338
    public Expression getFilter() {
339
        return this.filter;
340
    }
341

  
342
    @Override
343
    public void setLimit(int limit) {
344
        this.limit = limit;
345
    }
346

  
347
    @Override
348
    public void setFilter(Expression filter) {
349
        this.filter = filter;
350
    }
351

  
352
    @Override
353
    public boolean getExposeGeometry() {
354
        return this.exposeGeometry;
355
    }
356

  
357
    @Override
358
    public void setExposeGeometry(boolean selected) {
359
        this.exposeGeometry = selected;
360
    }
361

  
362
    @Override
363
    public String getURLPath() {
364
        String p = "/dataset/" + this.getName();
365
        return p;
366
    }
367
}
org.gvsig.report/tags/org.gvsig.report-1.0.179/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/ResourcesRepositoryService.java
1
package org.gvsig.report.lib.impl;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.OutputStream;
7
import java.net.URL;
8
import net.sf.jasperreports.engine.JRRuntimeException;
9
import net.sf.jasperreports.engine.util.JRLoader;
10
import net.sf.jasperreports.repo.InputStreamResource;
11
import net.sf.jasperreports.repo.ObjectResource;
12
import net.sf.jasperreports.repo.Resource;
13
import net.sf.jasperreports.repo.StreamRepositoryService;
14
import org.gvsig.report.lib.impl.commands.GetImage;
15
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
16

  
17
/**
18
 *
19
 * @author jjdelcerro
20
 */
21
@SuppressWarnings("UseSpecificCatch")
22
public class ResourcesRepositoryService implements StreamRepositoryService {
23

  
24
    private final ResourcesStorage resources;
25
    private final GetImage fetchFromField;
26

  
27
    private class GVResourceToJRInputStreamResourceAdapter extends InputStreamResource {
28
        private final ResourcesStorage.Resource resource;
29
        
30
        public GVResourceToJRInputStreamResourceAdapter(ResourcesStorage.Resource resource) {
31
            this.resource = resource;
32
        }
33

  
34
        @Override
35
        public InputStream getValue() {
36
            try {
37
                return this.resource.asInputStream();
38
            } catch (IOException ex) {
39
                return null;
40
            }
41
        }
42
    }
43
    
44
    private class URLToJRInputStreamResourceAdapter extends InputStreamResource {
45
        private final URL url;
46
        
47
        public URLToJRInputStreamResourceAdapter(URL url) {
48
            this.url = url;
49
        }
50

  
51
        @Override
52
        public InputStream getValue() {
53
            try {
54
                return this.url.openStream();
55
            } catch (IOException ex) {
56
                return null;
57
            }
58
        }
59
    }
60

  
61
    private class ByteArrayToJRInputStreamResourceAdapter extends InputStreamResource {
62
        private final byte[] data;
63
        
64
        public ByteArrayToJRInputStreamResourceAdapter(byte[] data) {
65
            this.data = data;
66
        }
67

  
68
        @Override
69
        public InputStream getValue() {
70
          ByteArrayInputStream is = new ByteArrayInputStream(this.data);
71
          return is;
72
        }
73
    }
74

  
75
    
76
    public ResourcesRepositoryService(ResourcesStorage resources) {
77
        this.resources = resources;
78
        this.fetchFromField = new GetImage();
79
    }
80

  
81
    @Override
82
    public InputStream getInputStream(String uri) {
83
        try {
84
            InputStream is;
85
            ResourcesStorage.Resource resource = this.resources.getResource(uri);
86
            if (resource != null) {
87
                is = resource.asInputStream();
88
            } else {
89
                URL url = new URL(uri);
90
                if( this.fetchFromField.canUse(url) ) {
91
                  byte[] image = this.fetchFromField.fetch(url);
92
                  is = new ByteArrayInputStream(image);
93
                } else {
94
                  is = url.openStream();
95
                }
96
            }
97
            return is;
98
        } catch (Exception ex) {
99
            throw new JRRuntimeException(ex);
100
        }
101
    }
102

  
103
    @Override
104
    public OutputStream getOutputStream(String uri) {
105
        return null;
106
    }
107

  
108
    @Override
109
    public Resource getResource(String uri) {
110
        try {
111
            Resource r;
112
            ResourcesStorage.Resource resource = this.resources.getResource(uri);
113
            if (resource != null) {
114
                r = new GVResourceToJRInputStreamResourceAdapter(resource);
115
                return r;
116
            } else {
117
                URL url = new URL(uri);
118
                if( this.fetchFromField.canUse(url) ) {
119
                  byte[] image = this.fetchFromField.fetch(url);
120
                  r = new ByteArrayToJRInputStreamResourceAdapter(image);
121
                } else {
122
                  r = new URLToJRInputStreamResourceAdapter(url);
123
                }
124
            }
125
            return r;
126
        } catch (Exception ex) {
127
            throw new JRRuntimeException(ex);
128
        }
129
    }
130

  
131
    @Override
132
    public void saveResource(String uri, Resource resource) {
133
        
134
    }
135

  
136
    @Override
137
    public <K extends Resource> K getResource(String uri, Class<K> resourceType) {
138
        try {
139
            ObjectResource r = (ObjectResource) resourceType.newInstance();
140
            r.setName(uri);
141
            ResourcesStorage.Resource resource = this.resources.getResource(uri);
142
            if (resource != null) {
143
                InputStream is = resource.asInputStream();
144
                if (is!=null) {
145
                    Object v = JRLoader.loadObject(is);
146
                    r.setValue(v);
147
                    return (K) r;
148
                }
149
            }
150
            URL url = new URL(uri);
151
            if (this.fetchFromField.canUse(url)) {
152
                byte[] image = this.fetchFromField.fetch(url);
153
                ByteArrayInputStream is = new ByteArrayInputStream(image);
154
                r.setValue(is);
155
            } else {
156
                r.setValue(url.openStream());
157
            }
158
            
159
            return (K) r;
160
        } catch (Throwable th) {
161
            return null;
162
        }
163
    }
164
}
org.gvsig.report/tags/org.gvsig.report-1.0.179/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/DefaultReportServerConfig.java
1
package org.gvsig.report.lib.impl;
2

  
3
import java.beans.PropertyChangeEvent;
4
import java.beans.PropertyChangeListener;
5
import java.beans.PropertyChangeSupport;
6
import java.util.List;
7
import org.apache.commons.lang3.StringUtils;
8
import org.gvsig.fmap.dal.DALLocator;
9
import org.gvsig.fmap.dal.DataManager;
10
import org.gvsig.fmap.dal.DataStore;
11
import org.gvsig.fmap.dal.feature.FeatureStore;
12
import org.json.JSONArray;
13
import org.json.JSONObject;
14
import org.gvsig.report.lib.api.ReportDataSet;
15
import org.gvsig.report.lib.api.ReportDataSets;
16
import org.gvsig.report.lib.api.ReportManager;
17
import org.gvsig.report.lib.api.ReportServerConfig;
18
import org.gvsig.report.lib.api.ReportServices;
19
import org.gvsig.report.lib.api.ReportViewCapture;
20

  
21
/**
22
 *
23
 * @author jjdelcerro
24
 */
25
public class DefaultReportServerConfig implements ReportServerConfig {
26

  
27
    private int port;
28
    private int timeout;
29
    private String serverInfo;
30
    private ReportDataSets datasets;
31
    private boolean locked;
32
    private DefaultReportViewCaptures viewCaptures;
33
    private final PropertyChangeSupport propertyChangeSupport;
34
    private final ReportServices services;
35
    private final ReportManager manager;
36
    private boolean autostart;
37

  
38
    public DefaultReportServerConfig(ReportManager manager, ReportServices services) {
39
        this.services = services;
40
        this.manager = manager;
41

  
42
        this.port = 9876;
43
        this.timeout = 15000;
44
        this.serverInfo = "Test/1.1";
45
        this.locked = false;
46
        this.autostart = false;
47
        this.propertyChangeSupport = new PropertyChangeSupport(this);
48

  
49
        this.viewCaptures = new DefaultReportViewCaptures();
50
        this.viewCaptures.addPropertyChangeListener(new PropertyChangeListener() {
51
            @Override
52
            public void propertyChange(PropertyChangeEvent evt) {
53
                propertyChangeSupport.firePropertyChange("viewCaptures", null, null);
54
            }
55
        });
56
                
57
        this.datasets = new DefaultReportDataSets(manager, services);
58
        this.datasets.addPropertyChangeListener(new PropertyChangeListener() {
59
            @Override
60
            public void propertyChange(PropertyChangeEvent evt) {
61
                propertyChangeSupport.firePropertyChange("datasets", null, null);
62
            }
63
        });
64
    }
65

  
66
    @Override
67
    public ReportServices getServices() {
68
        return this.services;
69
    }
70

  
71
    public boolean isLocked() {
72
        return locked;
73
    }
74

  
75
    public void setLocked(boolean locked) {
76
        this.locked = locked;
77
    }
78

  
79
    @Override
80
    public int getPort() {
81
        return this.port;
82
    }
83

  
84
    @Override
85
    public ReportServerConfig setPort(int port) {
86
        int oldValue = this.port;
87
        this.port = port;
88
        this.propertyChangeSupport.firePropertyChange("port", oldValue, port);
89
        return this;
90
    }
91

  
92
    @Override
93
    public int getTimeout() {
94
        return this.timeout;
95
    }
96

  
97
    @Override
98
    public ReportServerConfig setTimeout(int timeout) {
99
        int oldValue = this.timeout;
100
        this.timeout = timeout;
101
        this.propertyChangeSupport.firePropertyChange("timeout", oldValue, timeout);
102
        return this;
103
    }
104

  
105
    @Override
106
    public String getServerInfo() {
107
        return this.serverInfo;
108
    }
109

  
110
    @Override
111
    public ReportServerConfig setServerInfo(String serverInfo) {
112
        String oldValue = this.serverInfo;
113
        this.serverInfo = serverInfo;
114
        this.propertyChangeSupport.firePropertyChange("serverInfo", oldValue, serverInfo);
115
        return this;
116
    }
117

  
118
    @Override
119
    public ReportDataSets getDatasets() {
120
        return this.datasets;
121
    }
122

  
123
    @Override
124
    public ReportDataSet getDataset(String name) {
125
        ReportDataSet dataset = this.datasets.get(name);
126
        if( dataset == null ) {
127
          DataManager dataManager = DALLocator.getDataManager();
128
          DataStore store = dataManager.getStoresRepository().getStore(name);
129
          if( store == null || !(store instanceof FeatureStore)) {
130
            return null;
131
          }
132
          dataset = new DefaultReportDataSet(services, name, (FeatureStore) store, null);
133
        }
134
        return dataset;
135
    }
136

  
137
    @Override
138
    public String toJSON() {
139
        JSONObject jsonconfig = new JSONObject();
140

  
141
        jsonconfig.put("port", this.port);
142
        jsonconfig.put("timeout", this.timeout);
143
        jsonconfig.put("serverInfo", this.serverInfo);
144
        jsonconfig.put("autostart", this.autostart);
145
        
146
        JSONArray jsondatasets = new JSONArray();
147
        jsonconfig.put("datasets", jsondatasets);
148
        for (ReportDataSet dataset : this.datasets) {
149
            jsondatasets.put(((DefaultReportDataSet) dataset).toJSON());
150
        }
151

  
152
        JSONArray jsonviewcaptures = new JSONArray();
153
        jsonconfig.put("viewcaptures", jsonviewcaptures);
154
        for (ReportViewCapture viewcapture : this.viewCaptures) {
155
            jsonviewcaptures.put(((DefaultReportViewCapture) viewcapture).toJSON());
156
        }
157
        return jsonconfig.toString();
158
    }
159

  
160
    public void fromJSON(JSONObject jsonConfig) {
161
        DefaultReportDataSets theDatasets = new DefaultReportDataSets(manager, services);
162
        DefaultReportViewCaptures theViewCaptures = new DefaultReportViewCaptures();
163
        
164
        if (jsonConfig.has("port")) {
165
            this.port = jsonConfig.getInt("port");
166
        }
167
        if (jsonConfig.has("timeout")) {
168
            this.timeout = jsonConfig.getInt("timeout");
169
        }
170
        if (jsonConfig.has("serverInfo")) {
171
            this.serverInfo = jsonConfig.getString("serverInfo");
172
        }
173
        if (jsonConfig.has("autostart")) {
174
            this.autostart = jsonConfig.getBoolean("autostart");
175
        }
176
        if (jsonConfig.has("datasets")) {
177
            JSONArray jsonDatasets = jsonConfig.getJSONArray("datasets");
178
            for (Object jsonDataset : jsonDatasets) {
179
                if( !(jsonDataset instanceof JSONObject) ) {
180
                    jsonDataset = new JSONObject(jsonDataset.toString());
181
                }
182
                ReportDataSet dataset = new DefaultReportDataSet(
183
                        this.getServices(),
184
                        (JSONObject) jsonDataset
185
                );
186
                theDatasets.add(dataset);
187
            }
188
        }
189
        theDatasets.addPropertyChangeListener(new PropertyChangeListener() {
190
            @Override
191
            public void propertyChange(PropertyChangeEvent evt) {
192
                propertyChangeSupport.firePropertyChange("datasets", null, null);
193
            }
194
        });
195
        this.datasets = theDatasets;
196

  
197
        if (jsonConfig.has("viewcaptures")) {
198
            JSONArray jsonViewCaptures = jsonConfig.getJSONArray("viewcaptures");
199
            for (Object jsonViewCapture : jsonViewCaptures) {
200
                if( !(jsonViewCapture instanceof JSONObject) ) {
201
                    jsonViewCapture = new JSONObject(jsonViewCapture.toString());
202
                }
203
                ReportViewCapture viewCapture = new DefaultReportViewCapture(
204
                        this,
205
                        (JSONObject) jsonViewCapture
206
                );
207
                theViewCaptures.add(viewCapture);
208
            }
209
        }
210
        theViewCaptures.addPropertyChangeListener(new PropertyChangeListener() {
211
            @Override
212
            public void propertyChange(PropertyChangeEvent evt) {
213
                propertyChangeSupport.firePropertyChange("viewcaptures", null, null);
214
            }
215
        });
216
        this.viewCaptures = theViewCaptures;
217
        
218
    }
219

  
220
    @Override
221
    public List<ReportViewCapture> getViewCaptures() {
222
        return this.viewCaptures;
223
    }
224

  
225
    @Override
226
    public ReportViewCapture getViewCapture(String name) {
227
        for (ReportViewCapture viewCapture : viewCaptures) {
228
            if( StringUtils.equalsIgnoreCase(name, viewCapture.getName()) ) {
229
                return viewCapture;
230
            }
231
        }
232
        return null;
233
    }
234
    
235
    @Override
236
    public void addPropertyChangeListener(PropertyChangeListener listener) {
237
        this.propertyChangeSupport.addPropertyChangeListener(listener);
238
    }
239

  
240
    @Override
241
    public void removePropertyChangeListener(PropertyChangeListener listener) {
242
        this.propertyChangeSupport.removePropertyChangeListener(listener);
243
    }
244

  
245
    @Override
246
    public boolean getAutostart() {
247
        return this.autostart;
248
    }
249

  
250
    @Override
251
    public void setAutostart(boolean autostart) {
252
        boolean oldValue = this.autostart;
253
        this.autostart = autostart;
254
        this.propertyChangeSupport.firePropertyChange("autostart", oldValue, this.autostart);
255
    }
256

  
257
}
org.gvsig.report/tags/org.gvsig.report-1.0.179/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/DefaultReportViewCapture.java
1
package org.gvsig.report.lib.impl;
2

  
3
import java.awt.Dimension;
4
import java.beans.PropertyChangeEvent;
5
import java.beans.PropertyChangeListener;
6
import java.beans.PropertyChangeSupport;
7
import java.io.UnsupportedEncodingException;
8
import java.net.URLEncoder;
9
import org.apache.commons.lang3.StringUtils;
10
import org.gvsig.expressionevaluator.Expression;
11
import org.gvsig.expressionevaluator.ExpressionUtils;
12
import org.gvsig.expressionevaluator.Formatter;
13
import org.gvsig.report.lib.api.ReportDataSet;
14
import org.gvsig.report.lib.api.ReportServerConfig;
15
import org.gvsig.report.lib.api.ReportViewCapture;
16
import org.json.JSONObject;
17

  
18
/**
19
 *
20
 * @author jjdelcerro
21
 */
22
public class DefaultReportViewCapture implements ReportViewCapture {
23

  
24
    private static int counter = 0;
25
    
26
    private class DefaultReportViewCaptureFilter implements ReportViewCaptureFilter {
27

  
28
        private Expression expression;
29
        private String datasetName;
30
        private final PropertyChangeSupport propertyChangeSupport;
31

  
32
        public DefaultReportViewCaptureFilter() {
33
            this.propertyChangeSupport = new PropertyChangeSupport(this);
34
        }
35

  
36
        public DefaultReportViewCaptureFilter(JSONObject json) {
37
            this();
38
            if( json.has("expression") ) {
39
                this.expression = ExpressionUtils.createExpressionFromJSON(
40
                        json.getString("expression")
41
                );
42
            }
43
            if( json.has("datasetName") ) {
44
                this.datasetName = json.getString("datasetName");
45
            }
46
        }
47

  
48
        public JSONObject toJSON() {
49
            JSONObject me = new JSONObject();
50

  
51
            if( this.expression!=null ) {
52
                me.put("expression", this.expression.toJSON());
53
            }
54
            me.put("datasetName", StringUtils.defaultIfEmpty(this.datasetName,null));
55

  
56
            return me;
57
        }
58

  
59
        public String getURLPart() {
60
            if( StringUtils.isBlank(reportDataSetName) ) {
61
                return null;
62
            }
63
            ReportDataSet dataset = config.getDataset(reportDataSetName);
64
            if( dataset == null ) {
65
                return null;
66
            }
67
            Formatter reportformatter = new ReportExpressionCodeFormatter(
68
                    dataset.getFeatureType()
69
            );
70
            String s = expression.getCode().toString(reportformatter);
71
            s = s.replace(" ","+");
72
            return s;
73
        }
74
        
75
        @Override
76
        public String getDataSet() {
77
            return this.datasetName;
78
        }
79

  
80
        @Override
81
        public Expression getExpression() {
82
            return this.expression;
83
        }
84

  
85
        @Override
86
        public void setDataSet(String dataset) {
87
            this.datasetName = dataset;
88
            this.propertyChangeSupport.firePropertyChange("dataset", null, null);
89
        }
90

  
91
        @Override
92
        public void setDataSet(ReportDataSet dataset) {
93
            if( dataset == null ) {
94
                this.datasetName = null;
95
            } else {
96
                this.datasetName = dataset.getName();
97
            }
98
            this.propertyChangeSupport.firePropertyChange("dataset", null, null);
99
        }
100

  
101
        @Override
102
        public void setExpression(Expression expression) {
103
            this.expression = expression;
104
            this.propertyChangeSupport.firePropertyChange("expression", null, null);
105
        }
106

  
107
        @Override
108
        public boolean isEmpty() {
109
            return StringUtils.isEmpty(this.datasetName) || 
110
                    ExpressionUtils.isPhraseEmpty(this.expression);
111
        }
112

  
113
        public void addPropertyChangeListener(PropertyChangeListener listener) {
114
            this.propertyChangeSupport.addPropertyChangeListener(listener);
115
        }
116

  
117
        public void removePropertyChangeListener(PropertyChangeListener listener) {
118
            this.propertyChangeSupport.removePropertyChangeListener(listener);
119
        }
120

  
121
    }
122

  
123
    private DefaultReportViewCaptureFilter zoomFilter;
124
    private DefaultReportViewCaptureFilter centerFilter;
125
    private DefaultReportViewCaptureFilter selectFilter;
126
    private String name;
127
    private String viewName;
128
    private String reportDataSetName;
129
    private int margins;
130
    private boolean clearSelection;
131
    private Dimension dimensions;
132
    private int resolution;
133
    private final PropertyChangeSupport propertyChangeSupport;
134
    private final ReportServerConfig config;
135

  
136
    public DefaultReportViewCapture(ReportServerConfig config) {
137
        this.config = config;
138
        this.centerFilter = new DefaultReportViewCaptureFilter();
139
        this.centerFilter.addPropertyChangeListener(new PropertyChangeListener() {
140
            @Override
141
            public void propertyChange(PropertyChangeEvent evt) {
142
                propertyChangeSupport.firePropertyChange("centerFilter", null, null);
143
            }
144
        });
145
        this.zoomFilter = new DefaultReportViewCaptureFilter();
146
        this.zoomFilter.addPropertyChangeListener(new PropertyChangeListener() {
147
            @Override
148
            public void propertyChange(PropertyChangeEvent evt) {
149
                propertyChangeSupport.firePropertyChange("zoomFilter", null, null);
150
            }
151
        });
152
        this.selectFilter = new DefaultReportViewCaptureFilter();
153
        this.selectFilter.addPropertyChangeListener(new PropertyChangeListener() {
154
            @Override
155
            public void propertyChange(PropertyChangeEvent evt) {
156
                propertyChangeSupport.firePropertyChange("selectFilter", null, null);
157
            }
158
        });
159
        this.resolution = 72;
160
        this.clearSelection = false;
161
        this.name = "capture"+counter++;
162
        this.viewName = null;
163
        this.margins = 0;
164
        this.dimensions = new Dimension();
165
        this.propertyChangeSupport = new PropertyChangeSupport(this);
166
    }
167

  
168
    public DefaultReportViewCapture(ReportServerConfig config, JSONObject json) {
169
        this(config);
170
        this.fromJSON(json);
171
    }
172

  
173
    @Override
174
    public boolean isEmpty() {
175
        return StringUtils.isBlank(this.viewName);
176
    }
177

  
178
    @Override
179
    public String getReportDataSet() {
180
        return reportDataSetName;
181
    }
182
    
183
    @Override
184
    public void setReportDataSet(String reportDataSet) {
185
        this.reportDataSetName = reportDataSet;
186
    }
187
    
188
    @Override
189
    public String toString() {
190
        return this.getName();
191
    }
192

  
193
    @Override
194
    public String getName() {
195
        return this.name;
196
    }
197

  
198
    @Override
199
    public void setName(String name) {
200
        this.name = name;
201
        this.propertyChangeSupport.firePropertyChange("name", null, null);
202
    }
203

  
204
    @Override
205
    public String getView() {
206
        return this.viewName;
207
    }
208

  
209
    @Override
210
    public void setView(String view) {
211
        this.viewName = view;
212
        this.propertyChangeSupport.firePropertyChange("view", null, null);
213
    }
214
   
215
    private static String encodeForURL(String s) {
216
        try {
217
            return URLEncoder.encode(s, "UTF8");
218
        } catch (UnsupportedEncodingException ex) {
219
            return s;
220
        }
221
    }
222
    
223
    @Override
224
    public String getFullURLPath() {
225
        StringBuilder builder = new StringBuilder();
226
        builder.append("/captureview/captureName/");
227
        builder.append(encodeForURL(this.name));
228
        builder.append("/viewName/");
229
        builder.append(encodeForURL(this.viewName));
230
        if( this.getResolution()>0 ) {
231
            builder.append("/DPI/");
232
            builder.append(this.getResolution());
233
        }
234
        if (!this.centerFilter.isEmpty()) {
235
            builder.append("/center/");
236
            builder.append(this.centerFilter.getDataSet());
237
            builder.append("/");
238
            builder.append(this.centerFilter.getURLPart());
239
        }
240
        if (!this.zoomFilter.isEmpty()) {
241
            builder.append("/zoom/");
242
            builder.append(this.zoomFilter.getDataSet());
243
            builder.append("/");
244
            builder.append(this.zoomFilter.getURLPart());
245
        }
246
        if (!this.selectFilter.isEmpty()) {
247
            builder.append("/select/");
248
            builder.append(this.selectFilter.getDataSet());
249
            builder.append("/");
250
            builder.append(this.selectFilter.getURLPart());
251
        }
252
        if (this.margins > 0) {
253
            builder.append("/margins/");
254
            builder.append(this.margins);
255
        }
256
        if (this.clearSelection) {
257
            builder.append("/clearselection");
258
        }
259
        if (this.hasDimensions()) {
260
            builder.append("/width/");
261
            builder.append(this.dimensions.width);
262
            builder.append("/height/");
263
            builder.append(this.dimensions.height);
264
        }
265
        return builder.toString();
266
    }
267
    
268
    @Override
269
    public boolean hasDimensions() {
270
        return this.dimensions.height > 0 || this.dimensions.width > 0;
271
    }
272

  
273
    @Override
274
    public Dimension getDimensions() {
275
        return this.dimensions;
276
    }
277

  
278
    @Override
279
    public ReportViewCaptureFilter getZoomFilter() {
280
        return this.zoomFilter;
281
    }
282

  
283
    @Override
284
    public ReportViewCaptureFilter getCenterFilter() {
285
        return this.centerFilter;
286
    }
287

  
288
    @Override
289
    public ReportViewCaptureFilter getSelectionFilter() {
290
        return this.selectFilter;
291
    }
292

  
293
    @Override
294
    public int getMargins() {
295
        return this.margins;
296
    }
297

  
298
    @Override
299
    public void setMargins(int margins) {
300
        this.margins = margins;
301
        this.propertyChangeSupport.firePropertyChange("margins", null, null);
302
    }
303

  
304
    @Override
305
    public boolean getClearSelection() {
306
        return this.clearSelection;
307
    }
308

  
309
    @Override
310
    public void setClearSelection(boolean clearSelection) {
311
        this.clearSelection = clearSelection;
312
        this.propertyChangeSupport.firePropertyChange("clearSelection", null, null);
313
    }
314

  
315
    public void addPropertyChangeListener(PropertyChangeListener listener) {
316
        this.propertyChangeSupport.addPropertyChangeListener(listener);
317
    }
318

  
319
    public void removePropertyChangeListener(PropertyChangeListener listener) {
320
        this.propertyChangeSupport.removePropertyChangeListener(listener);
321
    }
322

  
323
    public JSONObject toJSON() {
324
        JSONObject me = new JSONObject();
325

  
326
        me.put("zoomFilter", this.zoomFilter.toJSON());
327
        me.put("centerFilter", this.centerFilter.toJSON());
328
        me.put("selectFilter", this.selectFilter.toJSON());
329
        me.put("viewName", this.viewName);
330
        me.put("reportDataSetName", this.reportDataSetName);
331
        me.put("clearSelection", this.clearSelection);
332
        me.put("dimension.width", this.dimensions.width);
333
        me.put("dimension.height", this.dimensions.height);
334

  
335
        return me;
336
    }
337

  
338
    public void fromJSON(JSONObject json) {
339
        this.zoomFilter = new DefaultReportViewCaptureFilter(json.getJSONObject("zoomFilter"));
340
        this.centerFilter = new DefaultReportViewCaptureFilter(json.getJSONObject("centerFilter"));
341
        this.selectFilter = new DefaultReportViewCaptureFilter(json.getJSONObject("selectFilter"));
342
        if( json.has("viewName") ) {
343
            this.viewName = json.getString("viewName");
344
        }
345
        if( json.has("reportDataSetName") ) {
346
            this.reportDataSetName = json.getString("reportDataSetName");
347
        }
348
        if( json.has("clearSelection") ) {
349
            this.clearSelection = json.getBoolean("clearSelection");
350
        }
351
        int width = 0;
352
        int height = 0;
353
        if( json.has("dimension.width") ) {
354
            width = json.getInt("dimension.width");
355
        }
356
        if( json.has("dimension.height") ) {
357
            height = json.getInt("dimension.height");
358
        }
359
        this.dimensions = new Dimension(width, height);
360
    }
361
    @Override
362
    public int getResolution() {
363
        return this.resolution;
364
    }
365

  
366
    @Override
367
    public void setResolution(int resolution) {
368
        this.resolution = resolution;
369
    }
370

  
371
}
org.gvsig.report/tags/org.gvsig.report-1.0.179/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/JRFeatureStoreDataSource1.java
1
package org.gvsig.report.lib.impl;
2

  
3
import ar.com.fdvs.dj.domain.CustomExpression;
4
import java.util.HashMap;
5
import java.util.Map;
6
import java.util.Objects;
7
import net.sf.jasperreports.engine.JREmptyDataSource;
8
import net.sf.jasperreports.engine.JRException;
9
import net.sf.jasperreports.engine.JRField;
10
import net.sf.jasperreports.engine.JRRewindableDataSource;
11
import net.sf.jasperreports.engine.JasperReportsContext;
12
import static net.sf.jasperreports.engine.data.JRTableModelDataSource.EXCEPTION_MESSAGE_KEY_UNKNOWN_COLUMN_NAME;
13
import net.sf.jasperreports.engine.data.JsonData;
14
import org.apache.commons.lang3.StringUtils;
15
import org.gvsig.expressionevaluator.Expression;
16
import org.gvsig.expressionevaluator.ExpressionUtils;
17
import org.gvsig.fmap.dal.DALLocator;
18
import org.gvsig.fmap.dal.StoresRepository;
19
import org.gvsig.fmap.dal.feature.Feature;
20
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
21
import org.gvsig.fmap.dal.feature.FeatureStore;
22
import org.gvsig.fmap.dal.feature.FeatureType;
23
import org.gvsig.fmap.dal.feature.LabelsCacheForFieldValues;
24
import static org.gvsig.report.lib.impl.ReportImplLibrary.TAG_REPORT_ATTR_LABEL;
25
import org.gvsig.tools.ToolsLocator;
26
import org.gvsig.tools.dataTypes.CoercionException;
27
import org.gvsig.tools.dataTypes.DataType;
28
import org.gvsig.tools.dataTypes.DataTypesManager;
29
import org.gvsig.tools.dataTypes.Coercion;
30
import org.gvsig.tools.dataTypes.CoercionContext;
31
import org.gvsig.tools.util.GetItem;
32
import org.gvsig.tools.util.GetItem64;
33
import org.gvsig.tools.util.Size;
34
import org.gvsig.tools.util.Size64;
35
import org.gvsig.tools.util.UnmodifiableBasicList64;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

  
39
/**
40
 *
41
 * @author jjdelcerro
42
 */
43
@SuppressWarnings("UseSpecificCatch")
44
public class JRFeatureStoreDataSource1
45
        implements JRRewindableDataSource, JsonData, Size64, Size, GetItem<Feature>, GetItem64<Feature> {
46

  
47
    protected static final Logger LOGGER = LoggerFactory.getLogger(JRFeatureStoreDataSource1.class);
48

  
49
    private UnmodifiableBasicList64<Feature> features;
50
    private long index;
51
    private final StoresRepository storesRepository;
52
    private final JasperReportsContext context;
53
    protected String name;
54
    private Map<String, Coercion> coercions;
55
    private final FeatureType featureType;
56
    private final LabelsCacheForFieldValues labelsCacheForFieldValues;
57

  
58
    public JRFeatureStoreDataSource1(JasperReportsContext context, UnmodifiableBasicList64<Feature> features, StoresRepository storesRepository, FeatureType featureType) {
59
        this.context = context;
60
        this.features = features;
61
        this.storesRepository = storesRepository;
62
        this.index = -1;
63
        this.name = "<unknown>";
64
        this.coercions = new HashMap<>();
65
        this.featureType = featureType;
66
        this.labelsCacheForFieldValues = DALLocator.getDataManager()
67
                .createLabelsCacheForFieldValues((Object... args) -> {
68
                    // FeatureType, Feature, String(fieldName)
69
                    FeatureAttributeDescriptor attr = ((FeatureType)args[0]).getAttributeDescriptor((String)args[2]);
70
                    String labelFormula = attr.getTags().getString(TAG_REPORT_ATTR_LABEL, null);
71
                    return labelFormula;
72
        },null);
73
        LOGGER.info("DataSource(" + this.name + ")");
74
    }
75

  
76
    public JRFeatureStoreDataSource1(JasperReportsContext context, FeatureStore store, Expression filter) {
77
        this(
78
                context,
79
                (UnmodifiableBasicList64<Feature>) store.getFeatures(filter),
80
                store.getStoresRepository(),
81
                store.getDefaultFeatureTypeQuietly()
82
        );
83
        this.name = store.getName();
84
    }
85
    
86
    
87
    @Override
88
    public boolean next() throws JRException {
89
        this.index++;
90
        boolean n = this.index < this.features.size64();
91
        return n;
92
    }
93
    
94
    public String getLabel(Feature feature, String fieldName) {
95
        return this.labelsCacheForFieldValues.getLabelForFieldValue(feature, fieldName);
96
    }
97

  
98
    @Override
99
    public Object getFieldValue(JRField jrField) throws JRException {
100
        String fieldName = jrField.getName();
101
//        System.out.println("DataSurce("+this.name+") ["+this.index+"] getFieldValue("+fieldName+").");
102
        try {
103
            Feature feature = this.features.get64(index);
104
            Object value;
105
            if (fieldName.startsWith("COLUMN_")) {
106
                value = feature.get(Integer.parseInt(fieldName.substring(7)));
107
            } else if (fieldName.endsWith("@label")) {
108
                fieldName = StringUtils.removeEnd(fieldName, "@label");
109
                value = this.getLabel(feature, fieldName);
110
            } else {
111
                value = feature.get(fieldName);
112
            }
113
            if (jrField.getValueClass() != null && !jrField.getValueClass().isInstance(value)) {
114
                Coercion coercion = this.coercions.get(fieldName);
115
                if (coercion == null) {
116
                    DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
117
                    DataType dataType = dataTypesManager.getDataType(jrField.getValueClass());
118
                    if (dataType == null) {
119
                        coercion = new DummyCoercion();
120
                    } else {
121
                        coercion = dataType.getCoercion();
122
                    }
123
                    this.coercions.put(fieldName, coercion);
124
                }
125
                try {
126
                    value = coercion.coerce(value);
127
                } catch (CoercionException ex) {
128
                }
129
            }
130
            return value;
131
        } catch (Exception ex) {
132
            if (CustomExpression.class.isAssignableFrom(jrField.getValueClass())) {
133
                return null;
134
            }
135
            throw new JRException(
136
                    EXCEPTION_MESSAGE_KEY_UNKNOWN_COLUMN_NAME,
137
                    new Object[]{fieldName},
138
                    ex
139
            );
140
        }
141
    }
142

  
143
    @Override
144
    public void moveFirst() throws JRException {
145
        this.index = -1;
146
//        System.out.println("DataSurce("+this.name+") ["+this.index+"] moveFirst().");
147
    }
148

  
149
    @Override
150
    public long size64() {
151
        return this.features.size64();
152
    }
153

  
154
    @Override
155
    public int size() {
156
        long sz = this.features.size64();
157
        if (sz > Integer.MAX_VALUE) {
158
            return Integer.MAX_VALUE;
159
        }
160
        return (int) sz;
161
    }
162

  
163
    @Override
164
    public Feature get(int position) {
165
        return this.features.get64(position);
166
    }
167

  
168
    @Override
169
    public Feature get64(long position) {
170
        return this.features.get64(position);
171
    }
172

  
173
    @Override
174
    public JsonData subDataSource() throws JRException {
175
        return new JRFeatureStoreDataSource1(this.context, this.features, this.storesRepository, this.featureType);
176
    }
177

  
178
    @Override
179
    public JsonData subDataSource(String selectExpression) throws JRException {
180
        LOGGER.info("DataSurce(" + this.name + ").subDataSource(" + Objects.toString(selectExpression, "null") + ").");
181
        if (StringUtils.isBlank(selectExpression)) {
182
            return new JREmptyJSonData(1, this.storesRepository);
183
        }
184
        String storeName;
185
        Expression filter = null;
186

  
187
        selectExpression = selectExpression.trim();
188
        if (selectExpression.toUpperCase().startsWith("SELECT ")) {
189
            selectExpression = selectExpression.substring(7).trim();
190
            if (selectExpression.startsWith("* ")) {
191
                selectExpression = selectExpression.substring(2).trim();
192
            }
193
            if (selectExpression.toUpperCase().startsWith("FROM ")) {
194
                selectExpression = selectExpression.substring(5).trim();
195
            }
196
        }
197
        int n = selectExpression.indexOf(" WHERE ");
198
        if (n < 0) {
199
            storeName = selectExpression.trim();
200
        } else {
201
            storeName = selectExpression.substring(0, n).trim();
202
            filter = ExpressionUtils.createExpression(selectExpression.substring(n + 6).trim());
203
        }
204
        if (this.storesRepository.get(storeName) == null) {
205
            return new JREmptyJSonData(1, this.storesRepository);
206
        }
207
        JRFeatureStoreDataSource1 x = new JRFeatureStoreDataSource1(
208
                this.context,
209
                (FeatureStore) this.storesRepository.getStore(storeName),
210
                filter
211
        );
212
        return x;
213
    }
214

  
215
    private class JREmptyJSonData extends JREmptyDataSource implements JsonData {
216

  
217
        JREmptyJSonData(int rows, StoresRepository storesRepository) {
218
            super(rows);
219
        }
220

  
221
        @Override
222
        public JsonData subDataSource() throws JRException {
223
            return JRFeatureStoreDataSource1.this.subDataSource();
224
        }
225

  
226
        @Override
227
        public JsonData subDataSource(String selectExpression) throws JRException {
228
            LOGGER.info("DataSurce(<Empty>) subDataSource(" + Objects.toString(selectExpression, "null") + ")");
229
            return JRFeatureStoreDataSource1.this.subDataSource(selectExpression);
230
        }
231
    }
232

  
233
    private static class DummyCoercion implements Coercion {
234

  
235
        @Override
236
        public Object coerce(Object o) throws CoercionException {
237
            return o;
238
        }
239

  
240
        @Override
241
        public Object coerce(Object value, CoercionContext context) throws CoercionException {
242
            return value;
243
        }
244

  
245
    }
246
}
org.gvsig.report/tags/org.gvsig.report-1.0.179/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/reportbuilder/DefaultMargins.java
1
package org.gvsig.report.lib.impl.reportbuilder;
2

  
3
import org.gvsig.report.lib.api.ReportBuilder;
4
import org.gvsig.tools.persistence.PersistentState;
5
import org.gvsig.tools.persistence.exception.PersistenceException;
6

  
7
/**
8
 *
9
 * @author jjdelcerro
10
 */
11
public class DefaultMargins implements ReportBuilder.Margins {
12

  
13
    private int top;
14
    private int bottom;
15
    private int left;
16
    private int right;
17
    
18
    public DefaultMargins() {
19
    }
20

  
21
    @Override
22
    public void copyFrom(ReportBuilder.Margins other) {
23
        this.top = other.getTop();
24
        this.bottom = other.getBottom();
25
        this.left = other.getLeft();
26
        this.right = other.getRight();
27
    }
28
    
29
    @Override
30
    public int getTop() {
31
        return this.top;
32
    }
33

  
34
    @Override
35
    public int getBottom() {
36
        return this.bottom;
37
    }
38

  
39
    @Override
40
    public int getLeft() {
41
        return this.left;
42
    }
43

  
44
    @Override
45
    public int getRight() {
46
        return this.right;
47
    }
48

  
49
    @Override
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff