Revision 45624

View differences:

tags/org.gvsig.desktop-2.0.321/license.txt
1
gvSIG. Desktop Geographic Information System.
2

  
3
Copyright (C) 2007-2020 gvSIG Association.
4

  
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 3
8
of the License, or (at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

  
15
 You should have received a copy of the GNU General Public License 
16
along with this program. If not, see <https://www.gnu.org/licenses/>. 
17

  
18
For any additional information, do not hesitate to contact us
19
at info AT gvsig.com, or visit our website www.gvsig.com.
tags/org.gvsig.desktop-2.0.321/org.gvsig.desktop.library/org.gvsig.exportto/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<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">
4
  <modelVersion>4.0.0</modelVersion>
5
  <artifactId>org.gvsig.exportto</artifactId>
6
  <packaging>pom</packaging>
7
  <name>${project.artifactId}</name>
8
  <description>Exportto project</description>
9
  
10
  <parent>
11
    <groupId>org.gvsig</groupId>
12
    <artifactId>org.gvsig.desktop.library</artifactId>
13
    <version>2.0.321</version>
14
  </parent>
15

  
16
  <dependencies>
17
    <dependency>
18
      <groupId>org.gvsig</groupId>
19
      <artifactId>org.gvsig.tools.lib</artifactId>
20
    </dependency>
21
    <dependency>
22
      <groupId>org.gvsig</groupId>
23
      <artifactId>org.gvsig.tools.lib</artifactId>
24
      <type>test-jar</type>
25
      <scope>test</scope>
26
    </dependency>
27
  </dependencies>
28
  
29
  <modules>
30
    <module>org.gvsig.exportto.lib</module>
31
    <module>org.gvsig.exportto.swing</module>
32
  </modules>
33
</project>
34

  
35

  
36

  
0 37

  
tags/org.gvsig.desktop-2.0.321/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.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.exportto.lib</artifactId>
6
  <packaging>pom</packaging>
7
  <name>${project.artifactId}</name>
8
  <parent>
9
    <groupId>org.gvsig</groupId>
10
    <artifactId>org.gvsig.exportto</artifactId>
11
    <version>2.0.321</version>
12
  </parent>
13

  
14
  <modules>
15
    <module>org.gvsig.exportto.lib.api</module>
16
    <module>org.gvsig.exportto.lib.impl</module>
17
  </modules>
18
</project>
19

  
20

  
21

  
22

  
0 23

  
tags/org.gvsig.desktop-2.0.321/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/ExportGeometryUtils.java
1
package org.gvsig.export.impl;
2

  
3
import org.cresques.cts.ICoordTrans;
4
import org.gvsig.export.ExportParametersGeometry;
5
import org.gvsig.export.spi.ExportServiceManager.FixGeometryStatus;
6
import org.gvsig.fmap.geom.Geometry;
7

  
8

  
9
/**
10
 *
11
 * @author jjdelcerro
12
 */
13
public class ExportGeometryUtils {
14

  
15
    public static class DefaultFixGeometryStatus
16
            implements FixGeometryStatus 
17
        {
18

  
19
        private Geometry geometry;
20
        private final int state;
21
        private String message;
22

  
23
        public DefaultFixGeometryStatus(Geometry geometry, int state) {
24
            this.geometry = geometry;
25
            this.state = state;
26
        }
27

  
28
        public DefaultFixGeometryStatus(Geometry geometry) {
29
            this.geometry = geometry;
30
            this.state = STATE_OK;
31
        }
32

  
33
        public DefaultFixGeometryStatus(int state) {
34
            this.geometry = null;
35
            this.state = state;
36
        }
37

  
38
        public DefaultFixGeometryStatus(int state, String message) {
39
            this.geometry = null;
40
            this.state = state;
41
            this.message = message;
42
        }
43

  
44
        private void setGeometry(Geometry geometry) {
45
            this.geometry = geometry;
46
        }
47

  
48
        @Override
49
        public Geometry getGeometry() {
50
            return this.geometry;
51
        }
52

  
53
        @Override
54
        public int getState() {
55
            return state;
56
        }
57

  
58
        @Override
59
        public String getMessage() {
60
            return this.message;
61
        }
62

  
63
    }
64

  
65
    public static FixGeometryStatus fixGeometry(
66
            ExportParametersGeometry options,
67
            ICoordTrans coord_trans,
68
            Geometry geometry
69
    ) {
70
        Geometry.ValidationStatus geometryCheck;
71
        DefaultFixGeometryStatus status;
72

  
73
        if (geometry == null) {
74
            return new DefaultFixGeometryStatus(geometry);
75
        }
76
        switch (options.getGeometryChecks()) {
77
            case ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_CORRUPT:
78
                geometryCheck = geometry.getValidationStatus();
79
                if (geometryCheck.isValid()) {
80
                    status = new DefaultFixGeometryStatus(geometry);
81
                    break;
82
                }
83
                switch (options.getGeometryChecksAction()) {
84
                    case ExportParametersGeometry.CHECKGEOMETRYACTION_SET_GEOMETRY_TO_NULL:
85
                        status = new DefaultFixGeometryStatus(null);
86
                        break;
87
                    case ExportParametersGeometry.CHECKGEOMETRYACTION_SKIP_FEATURE:
88
                        status = new DefaultFixGeometryStatus(FixGeometryStatus.STATE_SKIP, geometryCheck.getMessage());
89
                        break;
90
                    case ExportParametersGeometry.CHECKGEOMETRYACTION_ABORT:
91
                    default:
92
                        status = new DefaultFixGeometryStatus(FixGeometryStatus.STATE_ABORT, geometryCheck.getMessage());
93
                        break;
94
                }
95
                break;
96

  
97
            case ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_VALID:
98
                geometryCheck = geometry.getValidationStatus();
99
                if (geometryCheck.isValid()) {
100
                    status = new DefaultFixGeometryStatus(geometry);
101
                    break;
102
                }
103
                Geometry g;
104
                if (options.getTryToFixGeometry()) {
105
                    g = geometry.makeValid();
106
                    if (g != null) {
107
                        status = new DefaultFixGeometryStatus(g);
108
                        break;
109
                    }
110
                }
111
                switch (options.getGeometryChecksAction()) {
112
                    case ExportParametersGeometry.CHECKGEOMETRYACTION_SET_GEOMETRY_TO_NULL:
113
                        status = new DefaultFixGeometryStatus(null);
114
                        break;
115
                    case ExportParametersGeometry.CHECKGEOMETRYACTION_SKIP_FEATURE:
116
                        status = new DefaultFixGeometryStatus(FixGeometryStatus.STATE_SKIP, geometryCheck.getMessage());
117
                        break;
118
                    case ExportParametersGeometry.CHECKGEOMETRYACTION_ABORT:
119
                    default:
120
                        status = new DefaultFixGeometryStatus(FixGeometryStatus.STATE_ABORT, geometryCheck.getMessage());
121
                        break;
122
                }
123
                break;
124

  
125
            case ExportParametersGeometry.CHECKGEOMETRY_NONE:
126
            default:
127
                status = new DefaultFixGeometryStatus(geometry);
128
                break;
129
        }
130
        if (coord_trans != null) {
131
            if (status.getState() == FixGeometryStatus.STATE_OK) {
132
                if (status.getGeometry() != null) {
133
                    Geometry reproj_geom = status.getGeometry().cloneGeometry();
134
                    reproj_geom.reProject(coord_trans);
135
                    status.setGeometry(reproj_geom);
136
                }
137
            }
138
        }
139
        return status;
140
    }
141
}
tags/org.gvsig.desktop-2.0.321/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 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 3
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 html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
28
<html xmlns="http://www.w3.org/1999/xhtml">
29
<head>
30
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
31
<title>org.gvsig.exportto package documentation</title>
32
</head>
33
<body>
34

  
35
	<p>Exportto library API default implementation.</p>
36

  
37
</body>
38
</html>
0 39

  
tags/org.gvsig.desktop-2.0.321/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportGeometryHelper.java
1
package org.gvsig.export.impl.service;
2

  
3
import org.apache.commons.lang3.StringUtils;
4
import org.cresques.cts.ICoordTrans;
5
import org.cresques.cts.IProjection;
6
import org.gvsig.export.ExportLocator;
7
import org.gvsig.export.ExportParametersGeometry;
8
import org.gvsig.export.spi.ExportGeometryHelper;
9
import org.gvsig.export.spi.ExportServiceManager;
10
import org.gvsig.fmap.dal.DataTypes;
11
import org.gvsig.fmap.dal.feature.EditableFeature;
12
import org.gvsig.fmap.dal.feature.Feature;
13
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
14
import org.gvsig.fmap.dal.feature.FeatureType;
15
import org.gvsig.fmap.geom.Geometry;
16

  
17
/**
18
 *
19
 * @author jjdelcerro
20
 */
21
public class DefaultExportGeometryHelper implements ExportGeometryHelper {
22
        private final int targetGeometryIndex;
23
        private final int sourceGeometryIndex;
24
        private final ICoordTrans coord_trans;
25
        
26
        private final ExportServiceManager serviceManager;
27
        private final ExportParametersGeometry parameters;
28
        private String lastErrorMessage;
29

  
30
        public DefaultExportGeometryHelper(
31
            ExportParametersGeometry parameters,
32
            FeatureType theTargetFeatureType,
33
            FeatureType theSourceFeatureType
34
        ) {
35
            this.serviceManager = ExportLocator.getServiceManager();
36
            this.parameters = parameters;
37
                    
38
            FeatureAttributeDescriptor sourceGeomAtt = theSourceFeatureType.getDefaultGeometryAttribute();
39
            FeatureAttributeDescriptor targetGeomAtt;
40

  
41
            String sourceGeometryFieldName = this.parameters.getSourceGeometryFieldName();
42
            if( !StringUtils.isEmpty(sourceGeometryFieldName) ) {
43
                sourceGeomAtt = theSourceFeatureType.getAttributeDescriptor(sourceGeometryFieldName);
44
            }
45
            if (sourceGeomAtt == null) {
46
                // Si el origen no tiene geometria, no haremos nada con las
47
                // geometrias.
48
                this.targetGeometryIndex = -1;
49
                this.sourceGeometryIndex = -1;
50
                this.coord_trans = null;
51
                return;
52
            }
53
            switch( this.getGeometryColumnCount(theTargetFeatureType) ) {
54
                case 0:
55
                    // Si el destino no tiene campo geometry no haremos nada con 
56
                    // las geometrias.
57
                    this.targetGeometryIndex = -1;
58
                    this.sourceGeometryIndex = -1;
59
                    this.coord_trans = null;
60
                    return;
61
                case 1:
62
                    // Si solo hay una columna de geometria asignaremos las geometrias
63
                    // independientemente de como se llamen los campos.
64
                    targetGeomAtt = theTargetFeatureType.getDefaultGeometryAttribute();
65
                    break;
66
                default:
67
                    // Si hay mas de una geometria en el target y hay un campo de tipo
68
                    // geometria que coincida en nombre con el del source, usamos ese.
69
                    targetGeomAtt = theTargetFeatureType.getAttributeDescriptor(sourceGeomAtt.getName());
70
                    if( targetGeomAtt == null || targetGeomAtt.getType()!=DataTypes.GEOMETRY ) {
71
                        // Si no coinciden por nombre y tipo, pillaremos el primer campo
72
                        // geometry por defecto del target.
73
                        targetGeomAtt = theTargetFeatureType.getDefaultGeometryAttribute();
74
                        if( targetGeomAtt==null ) {
75
                            targetGeomAtt = this.getFirstGeometryColumn(theTargetFeatureType);
76
                            if( targetGeomAtt == null ) {
77
                                this.targetGeometryIndex = -1;
78
                                this.sourceGeometryIndex = -1;
79
                                this.coord_trans = null;
80
                                return;
81
                            }
82
                        }
83
                    }
84
            }
85

  
86
            IProjection targetProjection = this.parameters.getTargetProjection();
87
            IProjection sourceProjection = sourceGeomAtt.getSRS();
88
            if( targetProjection == null ) {
89
                targetProjection = sourceProjection;
90
            }
91
            // this comparison is perhaps too preventive
92
            // we could  have two instances of same projection
93
            // so we would do more computations than needed
94
            if (sourceProjection != null && targetProjection != null && sourceProjection != targetProjection) {
95
                this.coord_trans = sourceProjection.getCT(targetProjection);
96
            } else {
97
                this.coord_trans = null;
98
            }
99
            this.sourceGeometryIndex = sourceGeomAtt.getIndex();
100
            this.targetGeometryIndex = targetGeomAtt.getIndex();
101
        }
102

  
103
        private int getGeometryColumnCount(FeatureType featureType) {
104
            int count = 0;
105
            for( int i=0; i<featureType.size(); i++ ) {
106
                if( featureType.getAttributeDescriptor(i).getType()==DataTypes.GEOMETRY ) {
107
                    count++;
108
                }
109
            }
110
            return count;
111
        }
112

  
113
        @Override
114
        public String getLastErrorMessage() {
115
            return this.lastErrorMessage;
116
        }
117
        
118
        @Override
119
        public int copyGeometry(
120
                Feature sourceFeature, 
121
                EditableFeature targetFeature
122
            ) {
123
            if( this.sourceGeometryIndex<0 || this.targetGeometryIndex<0 ) {
124
                return ExportServiceManager.FixGeometryStatus.STATE_OK;
125
            }
126
            Geometry geometry = sourceFeature.getGeometry(this.sourceGeometryIndex);
127
            ExportServiceManager.FixGeometryStatus check = serviceManager.fixGeometry(
128
                    this.parameters, 
129
                    this.coord_trans, 
130
                    geometry
131
            );
132
            if( check.getState() == ExportServiceManager.FixGeometryStatus.STATE_OK ) {
133
                targetFeature.setGeometry(this.targetGeometryIndex, check.getGeometry());
134
            }
135
            this.lastErrorMessage = check.getMessage();
136
            return check.getState();
137
        }
138

  
139
        @Override
140
        public boolean canProcessGeometry() {
141
            return this.sourceGeometryIndex>=0 && this.targetGeometryIndex>=0 ;
142
        }
143

  
144
        private FeatureAttributeDescriptor getFirstGeometryColumn(FeatureType featureType) {
145
            for( int i=0; i<featureType.size(); i++ ) {
146
                FeatureAttributeDescriptor descriptor = featureType.getAttributeDescriptor(i);
147
                if( descriptor.getType()==DataTypes.GEOMETRY ) {
148
                    return descriptor;
149
                }
150
            }
151
            return null;
152
        }
153
        
154
    
155
}
tags/org.gvsig.desktop-2.0.321/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportServiceManager.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.export.impl.service;
7

  
8
import java.util.ArrayList;
9
import java.util.Collections;
10
import java.util.HashMap;
11
import java.util.List;
12
import java.util.Map;
13
import org.cresques.cts.ICoordTrans;
14
import org.gvsig.export.ExportAttributes;
15
import org.gvsig.export.ExportParameters;
16
import org.gvsig.export.ExportParametersGeometry;
17
import org.gvsig.export.Filter;
18
import org.gvsig.export.impl.ExportGeometryUtils;
19
import org.gvsig.export.spi.ExportGeometryHelper;
20
import org.gvsig.export.spi.ExportService;
21
import org.gvsig.export.spi.ExportServiceFactory;
22
import org.gvsig.export.spi.ExportServiceManager;
23
import org.gvsig.fmap.dal.feature.FeatureType;
24
import org.gvsig.fmap.geom.Geometry;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

  
28
/**
29
 *
30
 * @author jjdelcerro
31
 */
32
public class DefaultExportServiceManager implements ExportServiceManager {
33

  
34
    private static final Logger LOG = LoggerFactory.getLogger(DefaultExportServiceManager.class);
35

  
36
    private final Map<String, ExportServiceFactory> factories;
37
    
38
    public DefaultExportServiceManager() {
39
        super();
40
        this.factories = new HashMap<>();
41
    }
42

  
43
    @Override
44
    public ExportServiceFactory getServiceFactory(String name) {
45
        ExportServiceFactory factory = this.factories.get(name);
46
        if (factory == null) {
47
            throw new IllegalArgumentException("Don't exists export factory '" + name + "'.");
48
        }
49
        return factory;
50
    }
51

  
52
    @Override
53
    public ExportService createService(ExportParameters parameters) {
54
        return this.getServiceFactory(parameters.getServiceName()).createService(parameters);
55
    }
56

  
57
    @Override
58
    public ExportParameters createServiceParameters(String name) {
59
        return this.getServiceFactory(name).createParameters();
60
    }
61

  
62
    @Override
63
    public void register(ExportServiceFactory factory) {
64
        this.factories.put(factory.getName(), factory);
65
    }
66

  
67
    @Override
68
    public List<ExportServiceFactory> getAllServiceFactories() {
69
        List<ExportServiceFactory> result = new ArrayList<>();
70
        result.addAll(this.factories.values());
71
        return Collections.unmodifiableList(result);
72
    }
73

  
74
    @Override
75
    public List<ExportServiceFactory> getServiceFactories(Filter<ExportServiceFactory> filter) {
76
        List<ExportServiceFactory> result = new ArrayList<>();
77
        if (filter == null) {
78
            result.addAll(this.factories.values());
79
        } else {
80
            for (ExportServiceFactory factory : this.factories.values()) {
81
                if (factory.isEnabled() && filter.apply(factory)) {
82
                    result.add(factory);
83
                }
84
            }
85
        }
86
        return Collections.unmodifiableList(result);
87
    }
88

  
89
    @Override
90
    public FixGeometryStatus fixGeometry(
91
            ExportParametersGeometry parmeters,
92
            ICoordTrans coord_trans,
93
            Geometry geometry
94
    ) {
95
        return ExportGeometryUtils.fixGeometry(parmeters, coord_trans, geometry);
96
    }
97

  
98
    @Override
99
    public ExportGeometryHelper createGeometryHelper(ExportParametersGeometry parameters, FeatureType theTargetFeatureType, FeatureType theSourceFeatureType) {
100
        DefaultExportGeometryHelper helper = new DefaultExportGeometryHelper(
101
                parameters,
102
                theTargetFeatureType,
103
                theSourceFeatureType
104
        );
105
        return helper;
106

  
107
    }
108

  
109
    @Override
110
    public ExportAttributes createExportAttributes() {
111
        DefaultExportAttributes exp = new DefaultExportAttributes();
112
        return exp;
113
    }
114
}
tags/org.gvsig.desktop-2.0.321/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportAttribute.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.export.impl.service;
7

  
8
import org.gvsig.export.ExportAttributes;
9
import org.gvsig.export.ExportAttributes.ExportAttribute;
10
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
11
import org.gvsig.tools.ToolsLocator;
12
import org.gvsig.tools.dynobject.DynStruct;
13
import org.gvsig.tools.namestranslator.NamesTranslator;
14
import org.gvsig.tools.persistence.PersistenceManager;
15
import org.gvsig.tools.persistence.PersistentState;
16
import org.gvsig.tools.persistence.exception.PersistenceException;
17

  
18
public class DefaultExportAttribute implements ExportAttributes.ExportAttribute {
19

  
20
    private FeatureAttributeDescriptor fad;
21
    private int newDataType;
22
    private int size;
23
    private boolean exported;
24
    private boolean computed;
25
    private NamesTranslator translator;
26

  
27
    public DefaultExportAttribute(FeatureAttributeDescriptor fad, NamesTranslator namesTranslator) {
28
        this.fad = fad;
29
        this.translator = namesTranslator;
30
        this.computed = this.fad.isComputed();
31
    }
32

  
33
    public DefaultExportAttribute() {
34

  
35
    }
36

  
37
    @Override
38
    public FeatureAttributeDescriptor getDescriptor() {
39
        return this.fad;
40
    }
41

  
42
    @Override
43
    public String getName() {
44
        return this.fad.getName();
45
    }
46

  
47
    @Override
48
    public int getDataType() {
49
        return this.fad.getDataType().getType();
50
    }
51

  
52
    @Override
53
    public String getNewName() {
54
        if (translator==null) {
55
            return this.getName();
56
        }
57
        return translator.getTranslation(this.getName());
58
    }
59

  
60
    @Override
61
    public int getNewDataType() {
62

  
63
        return this.newDataType;
64
    }
65

  
66
    @Override
67
    public boolean isExported() {
68
        return this.exported;
69
    }
70

  
71
    @Override
72
    public boolean isComputed() {
73
        return this.computed;
74
    }
75
    
76
    @Override
77
    public int setNewName(String newName) {
78
        if (translator==null) {
79
            return -1;
80
        }
81
        int indexChanged = this.translator.setTranslation(this.getName(), newName);
82
        return indexChanged;
83
    }
84

  
85
    @Override
86
    public void setExported(boolean exported) {
87
        this.exported = exported;
88
    }
89

  
90
    @Override
91
    public void setComputed(boolean computed) {
92
        this.computed = computed;
93
    }
94
    
95
    @Override
96
    public void setNewType(int dataType) {
97
        this.newDataType = dataType;
98
    }
99

  
100
    @Override
101
    public int getSize() {
102
        return this.size;
103
    }
104

  
105
    @Override
106
    public void setSize(int size) {
107
        this.size = size;
108
    }
109

  
110
    @Override
111
    public ExportAttribute clone() throws CloneNotSupportedException {
112
        DefaultExportAttribute clone = (DefaultExportAttribute) super.clone();
113
        clone.fad = (FeatureAttributeDescriptor) fad.clone();
114
        return clone;
115
    }
116

  
117
    public static void registerPersistence() {
118
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
119
        if (manager.getDefinition("ExportAttribute") == null) {
120
            DynStruct definition = manager.addDefinition(DefaultExportAttribute.class,
121
                    "ExportAttribute", "ExportAttribute persistence definition", null, null);
122
            definition.addDynFieldObject("fad").setClassOfValue(FeatureAttributeDescriptor.class);
123
//            definition.addDynFieldString("newName").setMandatory(false);
124
            definition.addDynFieldInt("newDataType").setMandatory(false);
125
            definition.addDynFieldInt("size").setMandatory(false);
126
            definition.addDynFieldBoolean("exported").setMandatory(false);
127
            definition.addDynFieldBoolean("calculated").setMandatory(false);
128
        }
129
    }
130

  
131
    @Override
132
    public void saveToState(PersistentState state) throws PersistenceException {
133
        state.set("fad", this.fad);
134
        state.set("newDataType", this.newDataType);
135
        state.set("size", this.size);
136
        state.set("exported", this.exported);
137
        state.set("calculated", this.computed);
138
    }
139

  
140
    @Override
141
    public void loadFromState(PersistentState state) throws PersistenceException {
142
        FeatureAttributeDescriptor stateFad = (FeatureAttributeDescriptor) state.get("fad");
143
        this.fad = stateFad;
144
        this.newDataType = state.getInt("newDataType");
145
        this.size = state.getInt("size");
146
        this.exported = state.getBoolean("exported");
147
        this.computed = state.getBoolean("calculated");
148
    }
149

  
150
}
tags/org.gvsig.desktop-2.0.321/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportAttributes.java
1
package org.gvsig.export.impl.service;
2

  
3
import java.util.ArrayList;
4
import java.util.Iterator;
5
import java.util.List;
6
import java.util.function.Function;
7
import org.apache.commons.collections.CollectionUtils;
8
import org.apache.commons.lang3.StringUtils;
9
import org.gvsig.export.ExportAttributes;
10
import org.gvsig.fmap.dal.DALLocator;
11
import org.gvsig.fmap.dal.DataTypes;
12
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
13
import org.gvsig.fmap.dal.feature.EditableFeatureType;
14
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
15
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
16
import org.gvsig.fmap.dal.feature.FeatureQuery;
17
import org.gvsig.fmap.dal.feature.FeatureType;
18
import org.gvsig.tools.ToolsLocator;
19
import org.gvsig.tools.dataTypes.DataType;
20
import org.gvsig.tools.dataTypes.DataTypesManager;
21
import org.gvsig.tools.dynobject.DynStruct;
22
import org.gvsig.tools.namestranslator.NamesTranslator;
23
import org.gvsig.tools.persistence.PersistenceManager;
24
import org.gvsig.tools.persistence.PersistentState;
25
import org.gvsig.tools.persistence.exception.PersistenceException;
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

  
29
public final class DefaultExportAttributes implements ExportAttributes {
30

  
31
    private List<ExportAttribute> exportAttributes;
32
    private NamesTranslator namesTranslator = null;
33
    private FeatureType sourceFeatureType;
34
    static final Logger LOGGER = LoggerFactory.getLogger(DefaultExportAttributes.class);
35
    private boolean active;
36
    private FeatureQuery query = null;
37

  
38
    public DefaultExportAttributes() {
39
        this.namesTranslator = NamesTranslator.createBaseTranslator();
40
        this.active = false;
41
    }
42

  
43
    public void fillExportAttributes(FeatureType ftype, FeatureQuery query) {
44

  
45
        ArrayList attrs = new ArrayList();
46
        if (ftype != null) {
47
            for (FeatureAttributeDescriptor fad : ftype) {
48
                DefaultExportAttribute exportAttribute = new DefaultExportAttribute(fad.getCopy(), this.getNamesTranslator());
49
                exportAttribute.setNewType(fad.getDataType().getType());
50
                exportAttribute.setSize(fad.getSize());
51
                if (query == null || (query != null && query.getGroupByColumns().isEmpty())) {
52
                    exportAttribute.setExported(isShowableDataType(fad.getDataType()));
53
                } else {
54
                    if (query.getAggregate(fad.getName()) != null || query.getGroupByColumns().contains(fad.getName())) {
55
                        exportAttribute.setExported(isShowableDataType(fad.getDataType()));
56
                    } else {
57
                        exportAttribute.setExported(false);
58
                    }
59
                }
60
                attrs.add(exportAttribute);
61
            }
62
        }
63

  
64
        if (query != null && query.getExtraColumn().getColumns() != null && !query.getExtraColumn().getColumns().isEmpty()) {
65
            for (FeatureAttributeDescriptor fad : query.getExtraColumn().getColumns()) {
66
                DefaultExportAttribute exportAttribute = new DefaultExportAttribute(fad.getCopy(), this.getNamesTranslator());
67
                this.getNamesTranslator().addSource(fad.getName());
68
                exportAttribute.setNewType(fad.getDataType().getType());
69
                exportAttribute.setSize(fad.getSize());
70
                if (attributeAsComputedAndGroupBy(query, fad.getName())) {
71
                    exportAttribute.setComputed(false);
72
                }
73
                exportAttribute.setExported(isShowableDataType(fad.getDataType()));
74
                attrs.add(exportAttribute);
75
            }
76
        }
77
        this.setExportAttributes(attrs);
78

  
79
    }
80
    protected boolean attributeAsComputedAndGroupBy(FeatureQuery query, String attr) {
81
        if (!query.hasGroupByColumns()) {
82
            return false;
83
        }
84
        List<String> groupByCols = query.getGroupByColumns();
85
        if (groupByCols.isEmpty()) {
86
            return false;
87
        }
88
        return groupByCols.contains(attr);
89
    }
90
    
91
    protected boolean isShowableDataType(DataType dataType) {
92
        if ( dataType.getType() != DataTypes.GEOMETRY && (
93
                 dataType.isContainer()
94
                || dataType.isObject()
95
                || dataType.getType() == DataTypes.ARRAY)) {
96
            return false;
97

  
98
        } else {
99
            return true;
100
        }
101
    }
102
    
103

  
104
    @Override
105
    public void setNamesTranslator(NamesTranslator namesTranslator) {
106
        if (this.namesTranslator != namesTranslator) {
107
            this.namesTranslator = namesTranslator;
108
            if (this.sourceFeatureType != null) {
109
                this.namesTranslator.rebuild();
110
            }
111
        }
112
    }
113

  
114
    @Override
115
    public NamesTranslator getNamesTranslator() {
116
        return this.namesTranslator;
117
    }
118

  
119
    @Override
120
    public List<ExportAttribute> toList() {
121
        return this.exportAttributes;
122
    }
123

  
124
    @Override
125
    public boolean isEmpty() {
126
        return this.exportAttributes.isEmpty();
127
    }
128

  
129
    @Override
130
    public int size() {
131
        return this.exportAttributes.size();
132
    }
133

  
134
    @Override
135
    public Iterator<ExportAttribute> iterator() {
136
        return this.exportAttributes.iterator();
137
    }
138

  
139
    @Override
140
    public ExportAttribute get(int position) {
141
        return this.exportAttributes.get(position);
142
    }
143

  
144
    @Override
145
    public ExportAttribute getExportAttribute(String name) {
146
        for (ExportAttribute exportAttribute : this.exportAttributes) {
147
            if (StringUtils.equals(exportAttribute.getName(), name)) {
148
                return exportAttribute;
149
            }
150
        }
151
        return null;
152
    }
153

  
154
    @Override
155
    public FeatureType getTargetFeatureType() {
156
        EditableFeatureType targetFeatureType = DALLocator.getDataManager().createFeatureType();
157
        for (ExportAttribute exportAttribute : this.exportAttributes) {
158
            if (!exportAttribute.isExported()) {
159
                continue;
160
            }
161
            FeatureAttributeDescriptor descriptor = exportAttribute.getDescriptor().getCopy();
162
            EditableFeatureAttributeDescriptor targetDescriptor = DALLocator.getDataManager().createFeatureAttributeDescriptor();
163
            targetDescriptor.copyFrom(descriptor);
164

  
165
            targetDescriptor.setName(exportAttribute.getNewName());
166
            if (targetDescriptor.isComputed() && !exportAttribute.isComputed()) {
167
                targetDescriptor.setFeatureAttributeEmulator((FeatureAttributeEmulator) null);
168
            }
169
            if (targetDescriptor.getType() != exportAttribute.getNewDataType()) {
170
                targetDescriptor.setDefaultValue(null);
171
            }
172
            targetDescriptor.setDataType(exportAttribute.getNewDataType());
173

  
174
            targetDescriptor.setSize(exportAttribute.getSize());
175

  
176
            targetFeatureType.addLike(targetDescriptor);
177
        }
178

  
179
        return targetFeatureType.getNotEditableCopy();
180
    }
181

  
182
    @Override
183
    public void setSourceFeatureType(FeatureType sourceFeatureType, FeatureQuery query) {
184
        this.query = query;
185
        if (!sourceFeatureType.equals(this.sourceFeatureType)) {
186
            this.sourceFeatureType = sourceFeatureType;
187

  
188
            this.getNamesTranslator().updateSourceNames(sourceFeatureType, new Function() {
189
                @Override
190
                public Object apply(Object t) {
191
                    FeatureAttributeDescriptor attr = (FeatureAttributeDescriptor) t;
192
                    return attr.getName();
193
                }
194
            });
195
            this.fillExportAttributes(this.sourceFeatureType, query);
196
        }
197
    }
198

  
199
    @Override
200
    public FeatureType getSourceFeatureType() {
201
        return this.sourceFeatureType;
202
    }
203

  
204
    @Override
205
    public String getTargetName(String name) {
206
        for (int i = 0; i < exportAttributes.size(); i++) {
207
            ExportAttribute exportAttribute = exportAttributes.get(i);
208
            if (StringUtils.equals(exportAttribute.getName(), name)) {
209
                String newName = exportAttribute.getNewName();
210
                return newName;
211
            }
212
        }
213
        return null;
214
    }
215

  
216
    @Override
217
    public String getSourceName(String name) {
218
        for (ExportAttribute exportAttribute : this.exportAttributes) {
219
            if (StringUtils.equalsIgnoreCase(exportAttribute.getNewName(), name)) {
220
                return exportAttribute.getName();
221
            }
222
        }
223
        return null;
224
    }
225

  
226
    @Override
227
    public int getTargetType(String name) {
228
        for (ExportAttribute exportAttribute : this.exportAttributes) {
229
            if (StringUtils.equals(exportAttribute.getName(), name)) {
230
                return exportAttribute.getNewDataType();
231
            }
232
        }
233
        return 0;
234
    }
235

  
236
    @Override
237
    public int getSourceType(String name) {
238
        for (ExportAttribute exportAttribute : this.exportAttributes) {
239
            if (StringUtils.equals(exportAttribute.getNewName(), name)) {
240
                return exportAttribute.getDataType();
241
            }
242
        }
243
        return 0;
244
    }
245

  
246
    @Override
247
    public ExportAttributes clone() throws CloneNotSupportedException {
248
        DefaultExportAttributes clone = (DefaultExportAttributes) super.clone();
249
        clone.namesTranslator = this.namesTranslator.clone();
250
        List cloneListAttribute = new ArrayList();
251
        for (ExportAttribute exportAttribute : exportAttributes) {
252
            cloneListAttribute.add(exportAttribute.clone());
253
        }
254
        clone.setExportAttributes(cloneListAttribute);
255

  
256
        return clone;
257
    }
258

  
259
    @Override
260
    public void setExportAttributes(List<ExportAttribute> exportAttributes) {
261
        this.exportAttributes = exportAttributes;
262
    }
263

  
264
    @Override
265
    public void setActive(boolean active) {
266
        this.active = active;
267
    }
268

  
269
    @Override
270
    public boolean isActive() {
271
        return this.active;
272
    }
273

  
274
    public static void registerPersistence() {
275
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
276
        if (manager.getDefinition("ExportAttributes") == null) {
277
            DynStruct definition = manager.addDefinition(DefaultExportAttributes.class,
278
                    "ExportAttributes", "ExportAttributes persistence definition", null, null);
279
            definition.addDynFieldList("exportAttributes").setClassOfItems(ExportAttribute.class);
280
            definition.addDynFieldObject("namesTranslator").setClassOfValue(NamesTranslator.class);
281
            definition.addDynFieldObject("sourceFeatureType").setClassOfValue(FeatureType.class);
282
            definition.addDynFieldBoolean("active");
283
        }
284
    }
285

  
286
    @Override
287
    public void saveToState(PersistentState state) throws PersistenceException {
288
        state.set("exportAttributes", this.exportAttributes.iterator());
289
        state.set("namesTranslator", this.namesTranslator);
290
        state.set("sourceFeatureType", this.sourceFeatureType);
291
        state.set("active", this.active);
292
    }
293

  
294
    @Override
295
    public void loadFromState(PersistentState state) throws PersistenceException {
296
        Iterator it = state.getIterator("exportAttributes");
297
        List<ExportAttribute> data = new ArrayList<>();
298
        while (it.hasNext()) {
299
            ExportAttribute ref = (ExportAttribute) it.next();
300
            data.add(ref);
301
        }
302
        this.exportAttributes = data;
303

  
304
        NamesTranslator nameTranslatorState = (NamesTranslator) state.get("namesTranslator");
305
        if (nameTranslatorState != null) {
306
            this.namesTranslator = nameTranslatorState;
307
        }
308
        this.sourceFeatureType = (FeatureType) state.get("sourceFeatureType");
309
        this.active = state.getBoolean("active");
310
    }
311

  
312
}
tags/org.gvsig.desktop-2.0.321/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
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 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
 *
11
 * 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
 *
16
 * 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
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.export.impl;
24

  
25
import java.io.File;
26
import java.io.FileInputStream;
27
import java.io.FileOutputStream;
28
import java.io.IOException;
29
import java.util.ArrayList;
30
import java.util.HashMap;
31
import java.util.List;
32
import java.util.Map;
33
import java.util.Properties;
34
import org.apache.commons.io.IOUtils;
35
import org.cresques.cts.IProjection;
36

  
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

  
40
import org.gvsig.export.ExportManager;
41
import org.gvsig.export.ExportParameters;
42
import org.gvsig.export.ExportProcess;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
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

  
49
/**
50
 * Default {@link ExportManager} implementation.
51
 *
52
 * @author gvSIG Team
53
 * @version $Id$
54
 */
55
public class DefaultExportManager implements ExportManager {
56

  
57
    private static final Logger LOG = LoggerFactory.getLogger(DefaultExportManager.class);
58
    
59
    private static class DefaultExportFilter implements ExportFilter {
60

  
61
        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
    private File homeFolder = null;
82
    private final History<ExportParameters> history;
83
    private final Bookmarks<ExportParameters> bookmarks;
84

  
85

  
86
    public DefaultExportManager() {
87
        super();
88
        this.history = new BaseHistory<>(10);
89
        this.bookmarks = new BaseBookmarks<>();
90
    }
91

  
92
    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
                    }
107
                } catch (IOException ex) {
108
                    LOG.warn("Can't load filters file '" + filtersFile.getAbsolutePath() + "'.", ex);
109
                } finally {
110
                    IOUtils.closeQuietly(fis);
111
                }
112
            }
113
        }
114
    }
115

  
116
    public void saveFilters() {
117
        if (this.homeFolder != null) {
118
            Properties properties = new Properties();
119
            for (ExportFilter filter : this.filters.values()) {
120
                properties.setProperty(filter.getName(), filter.getExpression());
121
            }
122
            File filtersFile = new File(this.homeFolder, "filters");
123
            FileOutputStream fos = null;
124
            try {
125
                fos = new FileOutputStream(filtersFile);
126
                properties.store(fos, "");
127
            } catch (IOException ex) {
128
                LOG.warn("Can't load filters file '" + filtersFile.getAbsolutePath() + "'.", ex);
129
            } finally {
130
                IOUtils.closeQuietly(fos);
131
            }
132
        }
133
        
134
    }
135
    
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

  
150
    @Override
151
    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
    public void setHomeFolder(File homeFolder) {
164
        this.homeFolder = homeFolder;
165
    }
166

  
167
    @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

  
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
}
0 199

  
tags/org.gvsig.desktop-2.0.321/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/DefaultExportProcess.java
1
package org.gvsig.export.impl;
2

  
3
import java.util.List;
4
import java.util.Objects;
5
import javax.swing.JOptionPane;
6
import org.apache.commons.lang3.StringUtils;
7
import org.cresques.cts.ICoordTrans;
8
import org.cresques.cts.IProjection;
9
import org.gvsig.export.ExportException;
10
import org.gvsig.export.ExportLocator;
11
import org.gvsig.export.ExportParameters;
12
import org.gvsig.export.ExportParametersGeometry;
13
import org.gvsig.export.ExportProcess;
14
import org.gvsig.export.spi.ExportService;
15
import org.gvsig.export.spi.ExportServiceFactory;
16
import org.gvsig.export.spi.ExportServiceManager;
17
import org.gvsig.expressionevaluator.Expression;
18
import org.gvsig.expressionevaluator.ExpressionUtils;
19
import org.gvsig.fmap.dal.OpenDataStoreParameters;
20
import org.gvsig.fmap.dal.exception.DataException;
21
import org.gvsig.fmap.dal.feature.FeatureQuery;
22
import org.gvsig.fmap.dal.feature.FeatureSelection;
23
import org.gvsig.fmap.dal.feature.FeatureSet;
24
import org.gvsig.fmap.dal.feature.FeatureStore;
25
import org.gvsig.fmap.dal.feature.FeatureType;
26
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.swing.api.ToolsSwingLocator;
28
import org.gvsig.tools.task.SimpleTaskStatus;
29
import org.gvsig.tools.task.TaskStatus;
30

  
31
/**
32
 *
33
 * @author jjdelcerro
34
 */
35
public class DefaultExportProcess
36
        implements ExportProcess {
37

  
38
    private ExportServiceFactory factory;
39
    private List<OpenDataStoreParameters> targetOpenStoreParameters;
40
    private ExportParameters parameters;
41
    private FeatureStore sourceFeatureStore;
42

  
43
    private IProjection contextProjection;
44
    private ICoordTrans sourceTransformation;
45
    private IProjection sourceProjection;
46
    private Object context;
47
    private Expression filterExpression;
48
    private int featuresToUse;
49
    private SimpleTaskStatus taskStatus;
50
    private FeatureQuery featureQuery;
51

  
52
    public DefaultExportProcess() {
53

  
54
    }
55

  
56
    @Override
57
    public void setOutputFormat(String serviceName) throws ExportException {
58

  
59
        ExportServiceManager serviceManager = ExportLocator.getServiceManager();
60
        this.factory = serviceManager.getServiceFactory(serviceName);
61
        this.parameters = this.factory.createParameters();
62
        this.parameters.setFeatureQuery(featureQuery);
63
//        this.service = this.factory.createService(this.parameters);
64
        this.parameters.setSourceFeatureStore(this.sourceFeatureStore);
65
        this.parameters.setFeaturesToUse(featuresToUse);
66
        if (this.parameters instanceof ExportParametersGeometry) {
67
            ExportParametersGeometry params = (ExportParametersGeometry) this.parameters;
68
            params.setContextProjection(this.contextProjection);
69
            params.setSourceProjection(this.sourceProjection);
70
            params.setSourceTransformation(this.sourceTransformation);
71
            params.setTargetProjection(this.contextProjection);
72
            params.setContext(this.context);
73

  
74
            if (this.sourceFeatureStore != null) {
75
                try {
76
                    FeatureType ftype = this.sourceFeatureStore.getDefaultFeatureType();
77
                    if (ftype != null) {
78
                        params.setSourceGeometryFieldName(ftype.getDefaultGeometryAttributeName());
79
                    }
80
                } catch (DataException ex) {
81
                    //
82
                }
83
            }
84
        }
85
        this.setFilterExpression(this.filterExpression); //set features to use and expression
86

  
87
    }
88

  
89
    @Override
90
    public void setParameters(ExportParameters params) {
91
        this.parameters = params;
92
        this.factory = this.parameters.getFactory();
93
        this.parameters.setSourceFeatureStore(this.sourceFeatureStore);
94
        this.parameters.setContext(this.context);
95

  
96
        this.featuresToUse = this.parameters.getFeaturesToUse();
97
        if (ExpressionUtils.isEmpty(filterExpression)) {
98
            this.filterExpression = this.parameters.getFilterExpresion();
99
        } else if (!Objects.equals(this.filterExpression, this.parameters.getFilterExpresion())) {
100
            StringBuilder message = new StringBuilder();
101
            message.append(ToolsLocator.getI18nManager().getTranslation("_A_filter_is_already_applied_to_this_export_process"));
102
            message.append(":\n");
103
            message.append(StringUtils.abbreviate(this.filterExpression.getPhrase(), 30));
104
            message.append("\n");
105
            message.append(ToolsLocator.getI18nManager().getTranslation("_Its_going_to_be_replace_by_the_filter_in_the_parameters"));
106
            message.append(":\n");
107
            if (this.parameters.getFilterExpresion() != null) {
108
                message.append(StringUtils.abbreviate(this.parameters.getFilterExpresion().getPhrase(), 30));
109
            } else {
110
                message.append("empty filter");
111
            }
112
            message.append("\n");
113
            message.append(ToolsLocator.getI18nManager().getTranslation("_Do_you_want_to_keep_the_applied_filter"));
114
            int keepFilter = ToolsSwingLocator.getThreadSafeDialogsManager().confirmDialog(
115
                    message.toString(),//ToolsLocator.getI18nManager().getTranslation("_Do_you_want_to_keep_the_applied_filter_and_not_use_the_one_in_the_parameters"),
116
                    ToolsLocator.getI18nManager().getTranslation("_Filter_to_apply"),
117
                    JOptionPane.YES_NO_OPTION,
118
                    JOptionPane.WARNING_MESSAGE,
119
                    "exporto-overwrite-expression-parameters");
120
            if (keepFilter == JOptionPane.YES_OPTION) {
121
                this.parameters.setFilterExpresion(this.filterExpression);
122
            }
123
        }
124

  
125
        if (this.parameters instanceof ExportParametersGeometry) {
126
            ExportParametersGeometry pa = (ExportParametersGeometry) this.parameters;
127
            this.contextProjection = pa.getContextProjection();
128
            this.sourceProjection = pa.getSourceProjection();
129
            this.sourceTransformation = pa.getSourceTransformation();
130

  
131
        }
132
    }
133

  
134
    @Override
135
    public void setSourceFeatureStore(FeatureStore store
136
    ) {
137
        this.sourceFeatureStore = store;
138
        if (this.parameters != null) {
139
            this.parameters.setSourceFeatureStore(sourceFeatureStore);
140
        }
141
    }
142

  
143
    @Override
144
    public void setContextProjection(IProjection projection
145
    ) {
146
        this.contextProjection = projection;
147
        if (this.parameters instanceof ExportParametersGeometry) {
148
            ((ExportParametersGeometry) this.parameters).setContextProjection(projection);
149
        }
150
    }
151

  
152
    @Override
153
    public void setSourceTransformation(ICoordTrans transformation
154
    ) {
155
        this.sourceTransformation = transformation;
156
        if (this.parameters instanceof ExportParametersGeometry) {
157
            ((ExportParametersGeometry) this.parameters).setSourceTransformation(transformation);
158
        }
159
    }
160

  
161
    @Override
162
    public void setSourceProjection(IProjection projection
163
    ) {
164
        this.sourceProjection = projection;
165
        if (this.parameters instanceof ExportParametersGeometry) {
166
            ((ExportParametersGeometry) this.parameters).setSourceProjection(projection);
167
        }
168
    }
169

  
170
    @Override
171
    public Object getContext() {
172
        return context;
173
    }
174

  
175
    @Override
176
    public void setContext(Object context
177
    ) {
178
        this.context = context;
179
        if (this.parameters != null) {
180
            this.parameters.setContext(context);
181
        }
182
    }
183

  
184
    @Override
185
    public ExportParameters getParameters() {
186
        return this.parameters;
187
    }
188

  
189
    @Override
190
    public TaskStatus getTaskStatus() {
191
        if (this.taskStatus == null) {
192
            this.taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Export");
193
        }
194
        return this.taskStatus;
195
    }
196

  
197
    @Override
198
    public void run() {
199
        if (this.factory == null) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff