Revision 44386
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/DefaultExportProcess.java | ||
---|---|---|
38 | 38 |
private Object context; |
39 | 39 |
private Expression filterExpression; |
40 | 40 |
private int featuresToUse; |
41 |
private AttributeNamesTranslator attributeNamesTranslator; |
|
41 |
// private AttributeNamesTranslator attributeNamesTranslator;
|
|
42 | 42 |
|
43 | 43 |
public DefaultExportProcess() { |
44 | 44 |
|
... | ... | |
46 | 46 |
|
47 | 47 |
@Override |
48 | 48 |
public void setOutputFormat(String serviceName) throws ExportException { |
49 |
|
|
49 | 50 |
if (this.factory != null && StringUtils.equalsIgnoreCase(serviceName, this.factory.getName())) { |
50 | 51 |
return; |
51 | 52 |
} |
52 | 53 |
ExportServiceManager serviceManager = ExportLocator.getServiceManager(); |
53 | 54 |
this.factory = serviceManager.getServiceFactory(serviceName); |
54 | 55 |
this.parameters = this.factory.createParameters(); |
55 |
ExportAttributes expAttrs = ExportLocator.getServiceManager() |
|
56 |
.createExportAttributes(this.parameters.getSourceFeatureType()); |
|
57 |
this.attributeNamesTranslator = this.factory.createAttributeNamesTranslator(); |
|
58 |
expAttrs.setNamesTranslator(this.attributeNamesTranslator); |
|
59 |
this.parameters.setExportAttributes(expAttrs); |
|
60 | 56 |
this.service = this.factory.createService(this.parameters); |
61 | 57 |
this.parameters.setSourceFeatureStore(this.sourceFeatureStore); |
62 | 58 |
if (this.parameters instanceof ExportParametersGeometry) { |
... | ... | |
72 | 68 |
} |
73 | 69 |
|
74 | 70 |
@Override |
71 |
public void setParameters(ExportParameters params) { |
|
72 |
this.parameters = params; |
|
73 |
this.factory = this.parameters.getFactory(); |
|
74 |
this.service = this.factory.createService(this.parameters); |
|
75 |
this.parameters.setSourceFeatureStore(this.sourceFeatureStore); |
|
76 |
this.parameters.setContext(this.context); |
|
77 |
|
|
78 |
this.featuresToUse = this.parameters.getFeaturesToUse(); |
|
79 |
this.filterExpression = this.parameters.getFilterExpresion(); |
|
80 |
if (this.parameters instanceof ExportParametersGeometry) { |
|
81 |
ExportParametersGeometry pa = (ExportParametersGeometry) this.parameters; |
|
82 |
this.contextProjection = pa.getContextProjection(); |
|
83 |
this.sourceProjection = pa.getSourceProjection(); |
|
84 |
this.sourceTransformation = pa.getSourceTransformation(); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
75 | 89 |
public void setSourceFeatureStore(FeatureStore store) { |
76 | 90 |
this.sourceFeatureStore = store; |
77 | 91 |
if (this.parameters != null) { |
... | ... | |
189 | 203 |
this.parameters.setFeaturesToUse(featuresToUse); |
190 | 204 |
} |
191 | 205 |
} |
206 |
|
|
192 | 207 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultAttributeNamesTranslator.java | ||
---|---|---|
1 |
package org.gvsig.export.impl.service; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Map; |
|
7 |
import org.gvsig.export.ExportAttributes; |
|
8 |
import org.gvsig.export.ExportAttributes.ExportAttribute; |
|
9 |
import org.gvsig.export.spi.AttributeNamesTranslator; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
12 |
|
|
13 |
public class DefaultAttributeNamesTranslator implements AttributeNamesTranslator { |
|
14 |
|
|
15 |
private final int maxNameLen; |
|
16 |
|
|
17 |
public DefaultAttributeNamesTranslator(int maxNameLen) { |
|
18 |
this.maxNameLen = maxNameLen; |
|
19 |
} |
|
20 |
|
|
21 |
private String buildTranslatedName(String source_name, Collection<String> current_names) { |
|
22 |
|
|
23 |
int len = source_name.length(); |
|
24 |
if (source_name.isEmpty()) { |
|
25 |
source_name = "Field"; |
|
26 |
} |
|
27 |
if (len <= this.maxNameLen && !current_names.contains(source_name)) { |
|
28 |
/* |
|
29 |
* Should not happen |
|
30 |
*/ |
|
31 |
return source_name; |
|
32 |
} |
|
33 |
String target_name = source_name; |
|
34 |
/* |
|
35 |
* GDAL field name truncation method (extended from 100 to 255) |
|
36 |
* THISISAVERYLONGNAME => THISISAVER, THISISAV_1 ... THISISAV_9, |
|
37 |
* THISISAV10 ... THISISAV99, THISISA100 ... THISISA255 |
|
38 |
* (255 = max number of fields in a SHP) |
|
39 |
*/ |
|
40 |
for (int i = 0; i < 255; i++) { |
|
41 |
if (len <= this.maxNameLen) { |
|
42 |
if (i <= 9) { |
|
43 |
if (len == this.maxNameLen) { |
|
44 |
target_name = source_name.substring(0, 8) + "_" + i; |
|
45 |
} else { |
|
46 |
target_name = source_name + "_" + i; |
|
47 |
} |
|
48 |
} else if (i <= 99) { |
|
49 |
if (len == this.maxNameLen) { |
|
50 |
target_name = source_name.substring(0, 8) + i;; |
|
51 |
} else { |
|
52 |
target_name = source_name + i; |
|
53 |
} |
|
54 |
} else { |
|
55 |
if (len == this.maxNameLen-1) { |
|
56 |
target_name = source_name.substring(0, 7) + i;; |
|
57 |
} else { |
|
58 |
target_name = source_name + i; |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
} else { |
|
63 |
if (i == 0) { |
|
64 |
target_name = source_name.substring(0, 10); |
|
65 |
} else if (i <= 9) { |
|
66 |
target_name = source_name.substring(0, 8) + "_" + i; |
|
67 |
} else if (i <= 99) { |
|
68 |
target_name = source_name.substring(0, 8) + i; |
|
69 |
} else { |
|
70 |
target_name = source_name.substring(0, 7) + i; |
|
71 |
} |
|
72 |
} |
|
73 |
if (!current_names.contains(target_name)) { |
|
74 |
return target_name; |
|
75 |
} |
|
76 |
|
|
77 |
} |
|
78 |
/* |
|
79 |
* Should not get here |
|
80 |
*/ |
|
81 |
return source_name.substring(0, 4) + "_" + (System.currentTimeMillis() % 1000000); |
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
85 |
public boolean isValidName(ExportAttributes attributes, int index, String name) { |
|
86 |
ExportAttribute selectedAttr = attributes.get(index); |
|
87 |
// |
|
88 |
String selfName = this.getNameSuggestion(attributes, index, name); |
|
89 |
if (!selfName.equals(name)) { |
|
90 |
return false; |
|
91 |
} |
|
92 |
|
|
93 |
// check with others values |
|
94 |
boolean valid = true; |
|
95 |
for (int i = 0; i < attributes.size(); i++) { |
|
96 |
if (i == index) { |
|
97 |
continue; |
|
98 |
} |
|
99 |
ExportAttribute attr = attributes.get(i); |
|
100 |
String newName = attr.getNewName(); |
|
101 |
if (newName.isEmpty()) { |
|
102 |
return false; |
|
103 |
} |
|
104 |
if (newName.equals(name)) { |
|
105 |
return false; |
|
106 |
} |
|
107 |
if (newName.equals(this.getNameSuggestion(attributes, index, name))) { |
|
108 |
return false; |
|
109 |
} |
|
110 |
} |
|
111 |
return valid; |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public String getNameSuggestion(ExportAttributes attributes, int index, String name) { |
|
116 |
ArrayList names = new ArrayList(); |
|
117 |
boolean oneTime = true; |
|
118 |
for (ExportAttribute attribute : attributes) { |
|
119 |
if (attribute.getNewName().equals(name) && oneTime) { |
|
120 |
oneTime = false; |
|
121 |
continue; |
|
122 |
} |
|
123 |
names.add(attribute.getNewName()); |
|
124 |
} |
|
125 |
String target_name = buildTranslatedName(name, names); |
|
126 |
return target_name; |
|
127 |
} |
|
128 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/ExportEntriesHistoric.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.List; |
|
11 |
import org.apache.commons.lang3.StringUtils; |
|
12 |
import org.gvsig.export.ExportEntries; |
|
13 |
import org.gvsig.export.ExportEntry; |
|
14 |
import org.gvsig.expressionevaluator.Bookmark; |
|
15 |
import org.gvsig.expressionevaluator.Expression; |
|
16 |
|
|
17 |
/** |
|
18 |
* |
|
19 |
* @author osc |
|
20 |
*/ |
|
21 |
public class ExportEntriesHistoric implements ExportEntries { |
|
22 |
|
|
23 |
public List<ExportEntry> history; |
|
24 |
public int maxsize = 10; |
|
25 |
|
|
26 |
public ExportEntriesHistoric() { |
|
27 |
this.history = new ArrayList<>(); |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public List<ExportEntry> toList() { |
|
32 |
return Collections.unmodifiableList(this.history); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public boolean add(ExportEntry element) { |
|
37 |
if (element == null) { |
|
38 |
return true; |
|
39 |
} |
|
40 |
if (!this.history.isEmpty()) { |
|
41 |
ExportEntry last = this.history.get(0); |
|
42 |
String lastPhrase = StringUtils.normalizeSpace(last.getName()); |
|
43 |
String curPhrase = StringUtils.normalizeSpace(element.getName()); |
|
44 |
if (StringUtils.equals(curPhrase, lastPhrase)) { |
|
45 |
return true; |
|
46 |
} |
|
47 |
} |
|
48 |
this.history.add(0, element); |
|
49 |
if (this.history.size() > this.maxsize) { |
|
50 |
this.history.remove(this.history.size() - 1); |
|
51 |
} |
|
52 |
return true; |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public boolean remove(String entry) { |
|
57 |
for (int i = 0; i < this.history.size(); i++) { |
|
58 |
ExportEntry bookmark = this.history.get(i); |
|
59 |
if( StringUtils.equalsIgnoreCase(entry, bookmark.getName()) ) { |
|
60 |
this.history.remove(i); |
|
61 |
return true; |
|
62 |
} |
|
63 |
} |
|
64 |
return false; |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
68 |
public boolean remove(ExportEntry entry) { |
|
69 |
return this.history.remove(entry); |
|
70 |
} |
|
71 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportServiceManager.java | ||
---|---|---|
23 | 23 |
import org.gvsig.export.spi.ExportServiceManager; |
24 | 24 |
import org.gvsig.fmap.dal.feature.FeatureType; |
25 | 25 |
import org.gvsig.fmap.geom.Geometry; |
26 |
import org.gvsig.tools.bookmarksandhistory.Bookmark; |
|
27 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
|
28 |
import org.gvsig.tools.bookmarksandhistory.History; |
|
29 |
import org.gvsig.tools.bookmarksandhistory.impl.BaseBookmarks; |
|
30 |
import org.gvsig.tools.bookmarksandhistory.impl.BaseHistory; |
|
26 | 31 |
import org.slf4j.Logger; |
27 | 32 |
import org.slf4j.LoggerFactory; |
28 | 33 |
|
... | ... | |
33 | 38 |
public class DefaultExportServiceManager implements ExportServiceManager { |
34 | 39 |
|
35 | 40 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultExportServiceManager.class); |
41 |
|
|
42 |
private final Map<String, ExportServiceFactory> factories; |
|
36 | 43 |
|
37 |
private final Map<String,ExportServiceFactory> factories; |
|
44 |
private final History<ExportParameters> history; |
|
45 |
private final Bookmarks<ExportParameters> bookmarks; |
|
38 | 46 |
|
39 | 47 |
public DefaultExportServiceManager() { |
40 | 48 |
super(); |
41 | 49 |
this.factories = new HashMap<>(); |
50 |
this.history = new BaseHistory<ExportParameters>(10); |
|
51 |
this.bookmarks = new BaseBookmarks<ExportParameters>(); |
|
42 | 52 |
} |
43 | 53 |
|
44 | 54 |
@Override |
45 |
public AttributeNamesTranslator createAttributeNamesTranslator(int maxNameLen) { |
|
46 |
return new DefaultAttributeNamesTranslator(maxNameLen); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public AttributeNamesTranslator createAttributeNamesTranslator() { |
|
51 |
return new DefaultAttributeNamesTranslator(10); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 | 55 |
public ExportServiceFactory getServiceFactory(String name) { |
56 | 56 |
ExportServiceFactory factory = this.factories.get(name); |
57 |
if( factory == null ) {
|
|
58 |
throw new IllegalArgumentException("Don't exists export factory '"+name+"'.");
|
|
57 |
if (factory == null) {
|
|
58 |
throw new IllegalArgumentException("Don't exists export factory '" + name + "'.");
|
|
59 | 59 |
} |
60 | 60 |
return factory; |
61 | 61 |
} |
62 |
|
|
62 |
|
|
63 | 63 |
@Override |
64 | 64 |
public ExportService createService(ExportParameters parameters) { |
65 | 65 |
return this.getServiceFactory(parameters.getServiceName()).createService(parameters); |
... | ... | |
81 | 81 |
result.addAll(this.factories.values()); |
82 | 82 |
return Collections.unmodifiableList(result); |
83 | 83 |
} |
84 |
|
|
84 |
|
|
85 | 85 |
@Override |
86 | 86 |
public List<ExportServiceFactory> getServiceFactories(Filter<ExportServiceFactory> filter) { |
87 | 87 |
List<ExportServiceFactory> result = new ArrayList<>(); |
88 |
if( filter == null ) {
|
|
88 |
if (filter == null) {
|
|
89 | 89 |
result.addAll(this.factories.values()); |
90 | 90 |
} else { |
91 | 91 |
for (ExportServiceFactory factory : this.factories.values()) { |
92 |
if( factory.isEnabled() && filter.apply(factory) ) {
|
|
92 |
if (factory.isEnabled() && filter.apply(factory)) {
|
|
93 | 93 |
result.add(factory); |
94 | 94 |
} |
95 | 95 |
} |
... | ... | |
104 | 104 |
Geometry geometry |
105 | 105 |
) { |
106 | 106 |
return ExportGeometryUtils.fixGeometry(parmeters, coord_trans, geometry); |
107 |
}
|
|
107 |
} |
|
108 | 108 |
|
109 | 109 |
@Override |
110 | 110 |
public ExportGeometryHelper createGeometryHelper(ExportParametersGeometry parameters, FeatureType theTargetFeatureType, FeatureType theSourceFeatureType) { |
111 | 111 |
DefaultExportGeometryHelper helper = new DefaultExportGeometryHelper( |
112 | 112 |
parameters, |
113 |
theTargetFeatureType,
|
|
113 |
theTargetFeatureType, |
|
114 | 114 |
theSourceFeatureType |
115 | 115 |
); |
116 | 116 |
return helper; |
117 |
|
|
117 |
|
|
118 | 118 |
} |
119 | 119 |
|
120 | 120 |
@Override |
121 |
public ExportAttributes createExportAttributes(FeatureType featureType) {
|
|
122 |
DefaultExportAttributes exp = new DefaultExportAttributes(featureType);
|
|
121 |
public ExportAttributes createExportAttributes() { |
|
122 |
DefaultExportAttributes exp = new DefaultExportAttributes(); |
|
123 | 123 |
return exp; |
124 | 124 |
} |
125 |
|
|
126 |
@Override |
|
127 |
public History<ExportParameters> getHistory() { |
|
128 |
return this.history; |
|
129 |
} |
|
130 |
|
|
131 |
@Override |
|
132 |
public Bookmarks<ExportParameters> getBookmarks() { |
|
133 |
return this.bookmarks; |
|
134 |
} |
|
125 | 135 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/ExportEntriesBookmarks.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.List; |
|
11 |
import org.apache.commons.lang3.StringUtils; |
|
12 |
import org.gvsig.export.ExportEntries; |
|
13 |
import org.gvsig.export.ExportEntry; |
|
14 |
import org.gvsig.expressionevaluator.Bookmark; |
|
15 |
import org.gvsig.expressionevaluator.Expression; |
|
16 |
|
|
17 |
/** |
|
18 |
* |
|
19 |
* @author osc |
|
20 |
*/ |
|
21 |
public class ExportEntriesBookmarks implements ExportEntries { |
|
22 |
|
|
23 |
public List<ExportEntry> bookmarks; |
|
24 |
|
|
25 |
public ExportEntriesBookmarks() { |
|
26 |
this.bookmarks = new ArrayList<>(); |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
public List<ExportEntry> toList() { |
|
31 |
return Collections.unmodifiableList(this.bookmarks); |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public boolean add(ExportEntry element) { |
|
36 |
if (element == null) { |
|
37 |
return true; |
|
38 |
} |
|
39 |
if (!this.bookmarks.isEmpty()) { |
|
40 |
ExportEntry last = this.bookmarks.get(0); |
|
41 |
String lastPhrase = StringUtils.normalizeSpace(last.getName()); |
|
42 |
String curPhrase = StringUtils.normalizeSpace(element.getName()); |
|
43 |
if (StringUtils.equals(curPhrase, lastPhrase)) { |
|
44 |
return true; |
|
45 |
} |
|
46 |
} |
|
47 |
this.bookmarks.add(0, element); |
|
48 |
return true; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public boolean remove(String entryName) { |
|
53 |
for (int i = 0; i < this.bookmarks.size(); i++) { |
|
54 |
ExportEntry bookmark = this.bookmarks.get(i); |
|
55 |
if( StringUtils.equalsIgnoreCase(entryName, bookmark.getName()) ) { |
|
56 |
this.bookmarks.remove(i); |
|
57 |
return true; |
|
58 |
} |
|
59 |
} |
|
60 |
return false; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public boolean remove(ExportEntry entry) { |
|
65 |
return this.bookmarks.remove(entry); |
|
66 |
} |
|
67 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/ExportEntryHistoric.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.ExportParameters; |
|
9 |
import org.gvsig.export.ExportEntry; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author osc |
|
14 |
*/ |
|
15 |
public class ExportEntryHistoric implements ExportEntry { |
|
16 |
|
|
17 |
private String serviceName; |
|
18 |
private final ExportParameters params; |
|
19 |
private String name; |
|
20 |
|
|
21 |
public ExportEntryHistoric(String serviceName, String name, ExportParameters params) { |
|
22 |
this.serviceName = serviceName; |
|
23 |
this.name = name; |
|
24 |
this.params = params; |
|
25 |
} |
|
26 |
|
|
27 |
public String getServiceName() { |
|
28 |
return this.serviceName; |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public String getName() { |
|
33 |
return this.name; |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public void setName(String name) { |
|
38 |
this.name = name; |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public String toString() { |
|
43 |
return this.getName(); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public ExportParameters getParameters() { |
|
48 |
return this.params; |
|
49 |
} |
|
50 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/ExportEntryBookmark.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.ExportParameters; |
|
9 |
import org.gvsig.export.ExportEntry; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author osc |
|
14 |
*/ |
|
15 |
public class ExportEntryBookmark implements ExportEntry { |
|
16 |
|
|
17 |
private String serviceName; |
|
18 |
private final ExportParameters params; |
|
19 |
private String name; |
|
20 |
|
|
21 |
public ExportEntryBookmark(String serviceName, String name, ExportParameters params) { |
|
22 |
this.serviceName = serviceName; |
|
23 |
this.params = params; |
|
24 |
this.name = name; |
|
25 |
} |
|
26 |
|
|
27 |
public String getServiceName() { |
|
28 |
return this.serviceName; |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public String getName() { |
|
33 |
return this.name; |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public void setName(String name) { |
|
38 |
this.name = name; |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public String toString() { |
|
43 |
return this.getName(); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public ExportParameters getParameters() { |
|
48 |
return this.params; |
|
49 |
} |
|
50 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportAttribute.java | ||
---|---|---|
6 | 6 |
package org.gvsig.export.impl.service; |
7 | 7 |
|
8 | 8 |
import org.gvsig.export.ExportAttributes; |
9 |
import org.gvsig.export.ExportAttributes.ExportAttribute; |
|
9 | 10 |
import org.gvsig.export.spi.AttributeNamesTranslator; |
10 | 11 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
11 | 12 |
|
... | ... | |
16 | 17 |
private int newDataType; |
17 | 18 |
private int size; |
18 | 19 |
private boolean exported; |
19 |
private AttributeNamesTranslator translator = null; |
|
20 |
// private AttributeNamesTranslator translator = null;
|
|
20 | 21 |
|
21 | 22 |
public DefaultExportAttribute(FeatureAttributeDescriptor fad) { |
22 | 23 |
this.fad = fad; |
... | ... | |
80 | 81 |
public void setSize(int size) { |
81 | 82 |
this.size = size; |
82 | 83 |
} |
84 |
|
|
85 |
@Override |
|
86 |
public ExportAttribute clone() throws CloneNotSupportedException { |
|
87 |
DefaultExportAttribute clone = new DefaultExportAttribute((FeatureAttributeDescriptor) fad.clone()); |
|
88 |
clone.setExported(this.exported); |
|
89 |
clone.setNewName(this.newName); |
|
90 |
clone.setNewType(this.newDataType); |
|
91 |
clone.setSize(this.size); |
|
92 |
return clone; |
|
93 |
} |
|
83 | 94 |
|
84 | 95 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportAttributes.java | ||
---|---|---|
8 | 8 |
import java.util.ArrayList; |
9 | 9 |
import java.util.Iterator; |
10 | 10 |
import java.util.List; |
11 |
import java.util.logging.Level; |
|
11 | 12 |
import org.apache.commons.collections.ListUtils; |
12 | 13 |
import org.apache.commons.lang3.StringUtils; |
13 | 14 |
import org.gvsig.export.ExportAttributes; |
14 | 15 |
import org.gvsig.export.ExportLocator; |
15 | 16 |
import org.gvsig.export.spi.AttributeNamesTranslator; |
17 |
import org.gvsig.export.spi.DummyAttributeNamesTranslator; |
|
16 | 18 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
17 | 19 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
18 | 20 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
29 | 31 |
private FeatureType sourceFeatureType; |
30 | 32 |
static final Logger LOGGER = LoggerFactory.getLogger(DefaultExportAttributes.class); |
31 | 33 |
|
32 |
|
|
33 |
public DefaultExportAttributes(FeatureType ftype) {
|
|
34 |
this.setSourceFeatureType(ftype);
|
|
34 |
public DefaultExportAttributes() { //FeatureType ftype) { |
|
35 |
// this.setSourceFeatureType(ftype);
|
|
36 |
this.namesTranslator = new DummyAttributeNamesTranslator();
|
|
35 | 37 |
} |
36 | 38 |
|
37 | 39 |
public void fillExportAttributes(FeatureType ftype) { |
... | ... | |
39 | 41 |
if (ftype != null) { |
40 | 42 |
for (FeatureAttributeDescriptor fad : ftype) { |
41 | 43 |
DefaultExportAttribute exportAttribute = new DefaultExportAttribute(fad); |
42 |
exportAttribute.setNewName(fad.getName()); |
|
44 |
String newName = this.getNamesTranslator().getNameSuggestion(fad.getName()); |
|
45 |
exportAttribute.setNewName(newName); |
|
43 | 46 |
exportAttribute.setNewType(fad.getDataType().getType()); |
44 | 47 |
exportAttribute.setSize(fad.getSize()); |
45 | 48 |
exportAttribute.setExported(true); |
46 | 49 |
attrs.add(exportAttribute); |
47 | 50 |
} |
48 | 51 |
} |
49 |
this.exportAttributes = attrs; |
|
52 |
this.setExportAttributes(attrs); |
|
53 |
this.fixAttributeNames(); |
|
50 | 54 |
|
51 | 55 |
} |
52 | 56 |
|
53 | 57 |
@Override |
54 | 58 |
public void setNamesTranslator(AttributeNamesTranslator namesTranslator) { |
55 | 59 |
this.namesTranslator = namesTranslator; |
56 |
//this.fixAttributeNames(); |
|
60 |
if (this.sourceFeatureType != null) { |
|
61 |
this.fillExportAttributes(sourceFeatureType); |
|
62 |
} |
|
57 | 63 |
} |
58 | 64 |
|
59 | 65 |
@Override |
... | ... | |
100 | 106 |
public FeatureType getTargetFeatureType() { |
101 | 107 |
if (!this.isAttributeNamesValid()) { |
102 | 108 |
this.fixAttributeNames(); |
109 |
LOGGER.warn("An extra fix attributes names in the feature type has been made"); |
|
103 | 110 |
} |
104 | 111 |
EditableFeatureType targetFeatureType = this.getSourceFeatureType().getCopy().getEditable(); |
105 | 112 |
for (FeatureAttributeDescriptor attrSource : this.getSourceFeatureType()) { |
... | ... | |
128 | 135 |
|
129 | 136 |
@Override |
130 | 137 |
public void setSourceFeatureType(FeatureType sourceFeatureType) { |
131 |
this.sourceFeatureType = sourceFeatureType; |
|
132 |
this.fillExportAttributes(sourceFeatureType); |
|
138 |
if (sourceFeatureType != this.sourceFeatureType) { |
|
139 |
this.sourceFeatureType = sourceFeatureType; |
|
140 |
this.fillExportAttributes(this.sourceFeatureType); |
|
141 |
} |
|
133 | 142 |
} |
134 | 143 |
|
135 | 144 |
@Override |
... | ... | |
186 | 195 |
|
187 | 196 |
@Override |
188 | 197 |
public boolean isAttributeNamesValid() { |
189 |
if (this.namesTranslator==null) {
|
|
198 |
if (this.namesTranslator == null) {
|
|
190 | 199 |
return true; |
191 | 200 |
} |
192 | 201 |
for (int i = 0; i < exportAttributes.size(); i++) { |
... | ... | |
203 | 212 |
if (this.isAttributeNamesValid() == true) { |
204 | 213 |
return; |
205 | 214 |
} |
206 |
if (this.namesTranslator==null) {
|
|
215 |
if (this.namesTranslator == null) {
|
|
207 | 216 |
return; |
208 | 217 |
} |
209 | 218 |
int n = 0; |
... | ... | |
216 | 225 |
attr.setNewName(sug); |
217 | 226 |
} |
218 | 227 |
} |
219 |
if (n>5000) {
|
|
228 |
if (n > 5000) {
|
|
220 | 229 |
LOGGER.warn("Not been able to fix attribute field names, it will require a manual operation"); |
221 | 230 |
break; |
222 | 231 |
} |
... | ... | |
225 | 234 |
|
226 | 235 |
} |
227 | 236 |
|
237 |
@Override |
|
238 |
public ExportAttributes clone() throws CloneNotSupportedException { |
|
239 |
DefaultExportAttributes clone = (DefaultExportAttributes) super.clone(); |
|
240 |
//clone.setSourceFeatureType(this.sourceFeatureType.getCopy()); |
|
241 |
this.namesTranslator.clone(); |
|
242 |
clone.setNamesTranslator(this.namesTranslator.clone()); |
|
243 |
|
|
244 |
List cloneListAttribute = new ArrayList(); |
|
245 |
for (ExportAttribute exportAttribute : exportAttributes) { |
|
246 |
cloneListAttribute.add(exportAttribute.clone()); |
|
247 |
} |
|
248 |
clone.setExportAttributes(cloneListAttribute); |
|
249 |
|
|
250 |
return clone; |
|
251 |
} |
|
252 |
// private List<ExportAttribute> exportAttributes; |
|
253 |
// private AttributeNamesTranslator namesTranslator = null; |
|
254 |
// private FeatureType sourceFeatureType; |
|
255 |
|
|
256 |
@Override |
|
257 |
public void setExportAttributes(List<ExportAttribute> exportAttributes) { |
|
258 |
this.exportAttributes = exportAttributes; |
|
259 |
} |
|
228 | 260 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/ExportProcess.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
public void setFeaturesToUse(int featuresToUse); |
30 | 30 |
|
31 |
public void setParameters(ExportParameters params); |
|
32 |
|
|
31 | 33 |
public Object getContext(); |
32 | 34 |
|
33 | 35 |
public void setContext(Object context); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/ExportEntry.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; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* @author osc |
|
11 |
*/ |
|
12 |
public interface ExportEntry { |
|
13 |
|
|
14 |
public String getServiceName(); |
|
15 |
|
|
16 |
public String getName(); |
|
17 |
|
|
18 |
public void setName(String name); |
|
19 |
|
|
20 |
public ExportParameters getParameters(); |
|
21 |
|
|
22 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/ExportLocator.java | ||
---|---|---|
39 | 39 |
|
40 | 40 |
public static final String MANAGER_NAME = "Export.manager"; |
41 | 41 |
public static final String MANAGER_DESCRIPTION = "Export Manager"; |
42 |
|
|
42 |
|
|
43 |
public static final String ENTRIES_MANAGER_NAME = "Export.entriesManager"; |
|
44 |
public static final String ENTRIES_MANAGER_DESCRIPTION = "Export Entries Manager"; |
|
45 |
|
|
43 | 46 |
public static final String SERVICE_MANAGER_NAME = "Export.serviceManager"; |
44 | 47 |
public static final String SERVICE_MANAGER_DESCRIPTION = "Export Service Manager"; |
45 | 48 |
|
... | ... | |
114 | 117 |
public static void registerServiceManager(Class<? extends ExportServiceManager> clazz) { |
115 | 118 |
getInstance().register(SERVICE_MANAGER_NAME, SERVICE_MANAGER_DESCRIPTION, clazz); |
116 | 119 |
} |
117 |
|
|
120 |
|
|
118 | 121 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/ExportParameters.java | ||
---|---|---|
1 | 1 |
package org.gvsig.export; |
2 | 2 |
|
3 |
import org.cresques.cts.IProjection; |
|
3 |
import java.util.Date; |
|
4 |
import org.gvsig.export.spi.ExportServiceFactory; |
|
4 | 5 |
import org.gvsig.expressionevaluator.Expression; |
5 | 6 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
6 | 7 |
import org.gvsig.fmap.dal.feature.FeatureType; |
7 |
import org.gvsig.tools.evaluator.Evaluator;
|
|
8 |
import org.gvsig.tools.util.LabeledValue;
|
|
8 | 9 |
|
9 | 10 |
/** |
10 | 11 |
* |
11 | 12 |
* @author jjdelcerro |
12 | 13 |
*/ |
13 |
public interface ExportParameters { |
|
14 |
|
|
14 |
public interface ExportParameters extends Cloneable, LabeledValue {
|
|
15 |
|
|
15 | 16 |
public static final int USE_ALL_FEATURES = 0; |
16 | 17 |
public static final int USE_SELECTED_FEATURES = 1; |
17 | 18 |
public static final int USE_FILTERED_FEATURES = 2; |
18 |
|
|
19 |
|
|
19 | 20 |
public String getServiceName(); |
20 |
|
|
21 |
|
|
21 | 22 |
public boolean needsSelectTargetProjection(); |
22 |
|
|
23 |
|
|
23 | 24 |
public FeatureType getSourceFeatureType(); |
24 |
|
|
25 |
|
|
25 | 26 |
public void setSourceFeatureType(FeatureType sourceFeatureType); |
26 |
|
|
27 |
|
|
27 | 28 |
public void setSourceFeatureStore(FeatureStore sourceFeatureStore); |
28 |
|
|
29 |
|
|
29 | 30 |
public FeatureStore getSourceFeatureStore(); |
30 |
|
|
31 |
|
|
31 | 32 |
public int getFeaturesToUse(); |
32 | 33 |
|
33 | 34 |
public void setFeaturesToUse(int feturesToUse); |
34 |
|
|
35 |
|
|
35 | 36 |
public Expression getFilterExpresion(); |
36 | 37 |
|
37 | 38 |
public void setFilterExpresion(Expression expression); |
38 |
|
|
39 |
|
|
39 | 40 |
public Object getContext(); |
40 |
|
|
41 |
|
|
41 | 42 |
public void setContext(Object context); |
42 |
|
|
43 |
|
|
43 | 44 |
public ExportAttributes getExportAttributes(); |
44 |
|
|
45 |
|
|
45 | 46 |
public void setExportAttributes(ExportAttributes exportAttributes); |
46 | 47 |
|
48 |
public Date getCreationDate(); |
|
49 |
|
|
50 |
public void setCreationDate(Date date); |
|
51 |
|
|
52 |
public ExportParameters clone() throws CloneNotSupportedException; |
|
53 |
|
|
54 |
public ExportServiceFactory getFactory(); |
|
55 |
|
|
47 | 56 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/ExportAttributes.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.export; |
7 | 7 |
|
8 |
import java.util.List; |
|
8 | 9 |
import org.gvsig.export.ExportAttributes.ExportAttribute; |
9 | 10 |
import org.gvsig.export.spi.AttributeNamesTranslator; |
10 | 11 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
15 | 16 |
* |
16 | 17 |
* @author osc |
17 | 18 |
*/ |
18 |
public interface ExportAttributes extends UnmodifiableBasicList<ExportAttribute> { |
|
19 |
public interface ExportAttributes extends UnmodifiableBasicList<ExportAttribute>, Cloneable {
|
|
19 | 20 |
|
20 |
public interface ExportAttribute {
|
|
21 |
public ExportAttributes clone() throws CloneNotSupportedException;
|
|
21 | 22 |
|
23 |
public interface ExportAttribute extends Cloneable { |
|
24 |
|
|
22 | 25 |
public FeatureAttributeDescriptor getDescriptor(); |
23 | 26 |
|
24 | 27 |
public String getName(); |
... | ... | |
40 | 43 |
public void setNewType(int dataType); |
41 | 44 |
|
42 | 45 |
public void setExported(boolean exported); |
46 |
|
|
47 |
public ExportAttribute clone() throws CloneNotSupportedException; |
|
43 | 48 |
} |
44 | 49 |
|
45 | 50 |
public ExportAttribute getExportAttribute(String name); |
... | ... | |
65 | 70 |
public boolean isAttributeNamesValid(); |
66 | 71 |
|
67 | 72 |
public void fixAttributeNames(); |
73 |
|
|
74 |
public void setExportAttributes(List<ExportAttribute> exportAttributes); |
|
68 | 75 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/ExportEntries.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; |
|
7 |
|
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
/** |
|
11 |
* |
|
12 |
* @author osc |
|
13 |
*/ |
|
14 |
public interface ExportEntries { |
|
15 |
|
|
16 |
public List<ExportEntry> toList(); |
|
17 |
|
|
18 |
public boolean add(ExportEntry element); |
|
19 |
|
|
20 |
public boolean remove(String bookmarkName) ; |
|
21 |
|
|
22 |
public boolean remove(ExportEntry entry); |
|
23 |
|
|
24 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportParametersGeometry.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
import org.cresques.cts.ICoordTrans; |
9 | 9 |
import org.cresques.cts.IProjection; |
10 |
import org.gvsig.export.ExportParameters; |
|
10 | 11 |
import org.gvsig.fmap.geom.GeometryLocator; |
11 | 12 |
import org.gvsig.fmap.geom.GeometryManager; |
12 | 13 |
import org.gvsig.fmap.geom.type.GeometryType; |
... | ... | |
34 | 35 |
private String geometryFieldName; |
35 | 36 |
private int geometryType; |
36 | 37 |
private int geometrySubtype; |
38 |
|
|
39 |
public AbstractExportParametersGeometry(ExportServiceFactory factory) { |
|
40 |
super(factory); |
|
41 |
} |
|
37 | 42 |
|
38 | 43 |
@Override |
39 | 44 |
public boolean needsSelectTargetProjection() { |
... | ... | |
173 | 178 |
} |
174 | 179 |
} |
175 | 180 |
|
181 |
public ExportParameters clone() throws CloneNotSupportedException { |
|
182 |
return super.clone(); |
|
183 |
} |
|
176 | 184 |
|
177 |
|
|
178 | 185 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportService.java | ||
---|---|---|
40 | 40 |
|
41 | 41 |
private final ExportParameters parameters; |
42 | 42 |
private final Set<ExportFinishListener> finishListeners; |
43 |
protected AttributeNamesTranslator attributeNamesTranslator; |
|
43 |
// protected AttributeNamesTranslator attributeNamesTranslator;
|
|
44 | 44 |
private SimpleTaskStatus taskStatus; |
45 | 45 |
private final ExportServiceFactory factory; |
46 | 46 |
|
... | ... | |
103 | 103 |
this.getTaskStatus().cancelRequest(); |
104 | 104 |
} |
105 | 105 |
|
106 |
@Override |
|
107 |
public AttributeNamesTranslator getAttributeNamesTranslator() { |
|
108 |
if (attributeNamesTranslator == null) { |
|
109 |
this.attributeNamesTranslator = ExportLocator.getServiceManager().createAttributeNamesTranslator(); |
|
110 |
} |
|
111 |
return this.attributeNamesTranslator; |
|
112 |
} |
|
106 |
// @Override
|
|
107 |
// public AttributeNamesTranslator getAttributeNamesTranslator() {
|
|
108 |
// if (attributeNamesTranslator == null) {
|
|
109 |
// this.attributeNamesTranslator = ExportLocator.getServiceManager().createAttributeNamesTranslator();
|
|
110 |
// }
|
|
111 |
// return this.attributeNamesTranslator;
|
|
112 |
// }
|
|
113 | 113 |
|
114 | 114 |
@Override |
115 | 115 |
public List<OpenDataStoreParameters> getTargetOpenStoreParameters() throws ExportException { |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/ExportServiceFactory.java | ||
---|---|---|
16 | 16 |
|
17 | 17 |
public ExportService createService(ExportParameters parameters); |
18 | 18 |
|
19 |
public AttributeNamesTranslator createAttributeNamesTranslator(); |
|
20 |
|
|
21 | 19 |
public ExportParameters createParameters(); |
22 | 20 |
|
23 | 21 |
public void setEnabled(boolean enabled); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/CutAttributeNamesTranslator.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.logging.Level; |
|
6 |
import java.util.logging.Logger; |
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
import org.gvsig.export.ExportAttributes; |
|
9 |
import org.gvsig.export.ExportAttributes.ExportAttribute; |
|
10 |
|
|
11 |
public class CutAttributeNamesTranslator implements AttributeNamesTranslator { |
|
12 |
|
|
13 |
public final int maxNameLen; |
|
14 |
|
|
15 |
public CutAttributeNamesTranslator(int maxNameLen) { |
|
16 |
this.maxNameLen = maxNameLen; |
|
17 |
} |
|
18 |
|
|
19 |
private String buildTranslatedName(String source_name, Collection<String> current_names) { |
|
20 |
|
|
21 |
int len = source_name.length(); |
|
22 |
if (source_name.isEmpty()) { |
|
23 |
source_name = "Field"; |
|
24 |
} |
|
25 |
if (len <= this.maxNameLen && !current_names.contains(source_name)) { |
|
26 |
/* |
|
27 |
* Should not happen |
|
28 |
*/ |
|
29 |
return source_name; |
|
30 |
} |
|
31 |
String target_name = source_name; |
|
32 |
/* |
|
33 |
* GDAL field name truncation method (extended from 100 to 255) |
|
34 |
* THISISAVERYLONGNAME => THISISAVER, THISISAV_1 ... THISISAV_9, |
|
35 |
* THISISAV10 ... THISISAV99, THISISA100 ... THISISA255 |
|
36 |
* (255 = max number of fields in a SHP) |
|
37 |
*/ |
|
38 |
for (int i = 0; i < 255; i++) { |
|
39 |
if (len <= this.maxNameLen) { |
|
40 |
if (i <= 9) { |
|
41 |
if (len == this.maxNameLen) { |
|
42 |
target_name = source_name.substring(0, 8) + "_" + i; |
|
43 |
} else { |
|
44 |
target_name = source_name + "_" + i; |
|
45 |
} |
|
46 |
} else if (i <= 99) { |
|
47 |
if (len == this.maxNameLen) { |
|
48 |
target_name = source_name.substring(0, 8) + i;; |
|
49 |
} else { |
|
50 |
target_name = source_name + i; |
|
51 |
} |
|
52 |
} else { |
|
53 |
if (len == this.maxNameLen-1) { |
|
54 |
target_name = source_name.substring(0, 7) + i;; |
|
55 |
} else { |
|
56 |
target_name = source_name + i; |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
} else { |
|
61 |
if (i == 0) { |
|
62 |
target_name = source_name.substring(0, 10); |
|
63 |
} else if (i <= 9) { |
|
64 |
target_name = source_name.substring(0, 8) + "_" + i; |
|
65 |
} else if (i <= 99) { |
|
66 |
target_name = source_name.substring(0, 8) + i; |
|
67 |
} else { |
|
68 |
target_name = source_name.substring(0, 7) + i; |
|
69 |
} |
|
70 |
} |
|
71 |
if (!current_names.contains(target_name)) { |
|
72 |
return target_name; |
|
73 |
} |
|
74 |
|
|
75 |
} |
|
76 |
/* |
|
77 |
* Should not get here |
|
78 |
*/ |
|
79 |
return source_name.substring(0, 4) + "_" + (System.currentTimeMillis() % 1000000); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public boolean isValidName(ExportAttributes attributes, int index, String name) { |
|
84 |
ExportAttribute selectedAttr = attributes.get(index); |
|
85 |
// |
|
86 |
String selfName = this.getNameSuggestion(attributes, index, name); |
|
87 |
if (!selfName.equals(name)) { |
|
88 |
return false; |
|
89 |
} |
|
90 |
|
|
91 |
// check with others values |
|
92 |
boolean valid = true; |
|
93 |
for (int i = 0; i < attributes.size(); i++) { |
|
94 |
if (i == index) { |
|
95 |
continue; |
|
96 |
} |
|
97 |
ExportAttribute attr = attributes.get(i); |
|
98 |
String newName = attr.getNewName(); |
|
99 |
if (newName.isEmpty()) { |
|
100 |
return false; |
|
101 |
} |
|
102 |
if (newName.equals(name)) { |
|
103 |
return false; |
|
104 |
} |
|
105 |
if (newName.equals(this.getNameSuggestion(attributes, index, name))) { |
|
106 |
return false; |
|
107 |
} |
|
108 |
} |
|
109 |
return valid; |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public String getNameSuggestion(ExportAttributes attributes, int index, String name) { |
|
114 |
ArrayList names = new ArrayList(); |
|
115 |
boolean oneTime = true; |
|
116 |
for (ExportAttribute attribute : attributes) { |
|
117 |
if (attribute.getNewName().equals(name) && oneTime) { |
|
118 |
oneTime = false; |
|
119 |
continue; |
|
120 |
} |
|
121 |
names.add(attribute.getNewName()); |
|
122 |
} |
|
123 |
String target_name = buildTranslatedName(name, names); |
|
124 |
return target_name; |
|
125 |
} |
|
126 |
|
|
127 |
@Override |
|
128 |
public CutAttributeNamesTranslator clone() { |
|
129 |
CutAttributeNamesTranslator clone = null; |
|
130 |
try { |
|
131 |
clone = ( CutAttributeNamesTranslator)super.clone(); |
|
132 |
} catch (CloneNotSupportedException ex) { |
|
133 |
Logger.getLogger(CutAttributeNamesTranslator.class.getName()).log(Level.SEVERE, null, ex); |
|
134 |
} |
|
135 |
|
|
136 |
return clone; |
|
137 |
|
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
public String getNameSuggestion(String name) { |
|
142 |
String s = StringUtils.left(name, maxNameLen); |
|
143 |
return s; |
|
144 |
} |
|
145 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/DummyAttributeNamesTranslator.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import org.gvsig.export.ExportAttributes; |
|
4 |
|
|
5 |
public class DummyAttributeNamesTranslator implements AttributeNamesTranslator { |
|
6 |
|
|
7 |
public DummyAttributeNamesTranslator() { |
|
8 |
|
|
9 |
} |
|
10 |
|
|
11 |
@Override |
|
12 |
public boolean isValidName(ExportAttributes attributes, int index, String name) { |
|
13 |
return true; |
|
14 |
} |
|
15 |
|
|
16 |
@Override |
|
17 |
public String getNameSuggestion(ExportAttributes attributes, int index, String name) { |
|
18 |
return name; |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
public AttributeNamesTranslator clone() throws CloneNotSupportedException { |
|
23 |
return (AttributeNamesTranslator) super.clone(); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public String getNameSuggestion(String name) { |
|
28 |
return name; |
|
29 |
} |
|
30 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/ExportServiceManager.java | ||
---|---|---|
8 | 8 |
import org.gvsig.export.Filter; |
9 | 9 |
import org.gvsig.fmap.dal.feature.FeatureType; |
10 | 10 |
import org.gvsig.fmap.geom.Geometry; |
11 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
|
12 |
import org.gvsig.tools.bookmarksandhistory.History; |
|
11 | 13 |
|
12 | 14 |
/** |
13 | 15 |
* |
... | ... | |
37 | 39 |
|
38 | 40 |
public void register(ExportServiceFactory factory); |
39 | 41 |
|
40 |
public AttributeNamesTranslator createAttributeNamesTranslator(); |
|
41 |
|
|
42 |
public AttributeNamesTranslator createAttributeNamesTranslator( |
|
43 |
int maxNameLen |
|
44 |
); |
|
45 |
|
|
46 | 42 |
public FixGeometryStatus fixGeometry( |
47 | 43 |
ExportParametersGeometry parameters, |
48 | 44 |
ICoordTrans coord_trans, |
... | ... | |
55 | 51 |
FeatureType theSourceFeatureType |
56 | 52 |
); |
57 | 53 |
|
58 |
public ExportAttributes createExportAttributes(FeatureType featureType); |
|
54 |
public ExportAttributes createExportAttributes(); |
|
55 |
|
|
56 |
public History<ExportParameters> getHistory(); |
|
57 |
|
|
58 |
public Bookmarks<ExportParameters> getBookmarks(); |
|
59 | 59 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AttributeNamesTranslator.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.gvsig.export.ExportAttributes; |
4 | 4 |
|
5 |
public interface AttributeNamesTranslator { |
|
5 |
/** |
|
6 |
* This class provide the methods to translate the name of the fields |
|
7 |
* to the target store. |
|
8 |
* This class should be state-less. |
|
9 |
* @author osc |
|
10 |
*/ |
|
11 |
public interface AttributeNamesTranslator extends Cloneable { |
|
6 | 12 |
|
7 | 13 |
boolean isValidName(ExportAttributes attributes, int index, String newName); |
8 | 14 |
|
9 |
public String getNameSuggestion(ExportAttributes attributes, int index, String newName); |
|
15 |
public String getNameSuggestion(ExportAttributes attributes, int index, String name); |
|
16 |
|
|
17 |
public String getNameSuggestion(String name); |
|
10 | 18 |
|
19 |
public AttributeNamesTranslator clone() throws CloneNotSupportedException ; |
|
20 |
|
|
11 | 21 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/ExportService.java | ||
---|---|---|
60 | 60 |
|
61 | 61 |
public void addFinishListener(ExportFinishListener listener); |
62 | 62 |
|
63 |
public AttributeNamesTranslator getAttributeNamesTranslator(); |
|
63 |
// public AttributeNamesTranslator getAttributeNamesTranslator();
|
|
64 | 64 |
|
65 | 65 |
public void export(FeatureSet featureSet) throws ExportException; |
66 | 66 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/export/jdbc/swing/panels/PostCreatingStatementPanel.java | ||
---|---|---|
91 | 91 |
} else { |
92 | 92 |
this.chkUsePostCreatingStatement.setEnabled(false); |
93 | 93 |
} |
94 |
// set params |
|
95 |
if (this.parameters.getPostCreatingStatement()!=null) { |
|
96 |
String statement = this.parameters.getPostCreatingStatement(); |
|
97 |
this.chkUsePostCreatingStatement.setSelected(true); |
|
98 |
this.txtPostCreatingStatement.setText(statement); |
|
99 |
} |
|
94 | 100 |
} |
95 | 101 |
|
96 | 102 |
@Override |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/export/jdbc/swing/panels/SelectTableNamePanel.java | ||
---|---|---|
37 | 37 |
import org.apache.commons.lang3.StringUtils; |
38 | 38 |
import org.gvsig.export.jdbc.service.ExportJDBCAttributeNamesTranslator; |
39 | 39 |
import org.gvsig.export.jdbc.service.ExportJDBCParameters; |
40 |
import org.gvsig.export.spi.AttributeNamesTranslator; |
|
41 |
//import org.gvsig.app.ApplicationLocator; |
|
42 |
//import org.gvsig.app.ApplicationManager; |
|
43 | 40 |
import org.gvsig.fmap.dal.DALLocator; |
44 | 41 |
import org.gvsig.fmap.dal.DataManager; |
45 | 42 |
import org.gvsig.fmap.dal.SQLBuilder; |
... | ... | |
64 | 61 |
* @version $Id$ |
65 | 62 |
* |
66 | 63 |
*/ |
67 |
public class SelectTableNamePanel |
|
68 |
extends SelectTableNamePanelLayout |
|
69 |
implements ExportPanel |
|
70 |
{ |
|
64 |
public class SelectTableNamePanel |
|
65 |
extends SelectTableNamePanelLayout |
|
66 |
implements ExportPanel { |
|
71 | 67 |
|
72 | 68 |
private static final Logger logger = LoggerFactory.getLogger(SelectTableNamePanel.class); |
73 | 69 |
|
... | ... | |
84 | 80 |
} |
85 | 81 |
|
86 | 82 |
public TableItem(JDBCStoreParameters params) { |
87 |
this( StringUtils.isEmpty(params.getSchema())?
|
|
88 |
params.getTable() : params.getSchema() + "." + params.getTable(),
|
|
89 |
params); |
|
83 |
this(StringUtils.isEmpty(params.getSchema())
|
|
84 |
? params.getTable() : params.getSchema() + "." + params.getTable(),
|
|
85 |
params);
|
|
90 | 86 |
} |
91 | 87 |
|
92 | 88 |
@Override |
... | ... | |
106 | 102 |
|
107 | 103 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
108 | 104 |
public SelectTableNamePanel( |
109 |
JExportProcessPanel processPanel,
|
|
105 |
JExportProcessPanel processPanel, |
|
110 | 106 |
ExportJDBCParameters parameters |
111 |
) {
|
|
107 |
) { |
|
112 | 108 |
this.processPanel = processPanel; |
113 | 109 |
this.parameters = parameters; |
114 | 110 |
initComponents(); |
... | ... | |
205 | 201 |
return tableParameter.getTable(); |
206 | 202 |
} |
207 | 203 |
|
208 |
|
|
209 | 204 |
@Override |
210 | 205 |
public String getIdPanel() { |
211 | 206 |
return this.getClass().getCanonicalName(); |
... | ... | |
241 | 236 |
); |
242 | 237 |
} |
243 | 238 |
String schema = this.getSchema(); |
244 |
if( sqlbuilder.support_schemas() ) {
|
|
239 |
if (sqlbuilder.support_schemas()) {
|
|
245 | 240 |
if (schema == null) { |
246 | 241 |
throw new ExportPanelValidationException( |
247 | 242 |
i18nManager.getTranslation( |
... | ... | |
251 | 246 |
} |
252 | 247 |
} |
253 | 248 |
if (this.rdoCreateTable.isSelected()) { |
254 |
String tablename_tr = tablename; |
|
255 |
ExportJDBCAttributeNamesTranslator nameTranslator = |
|
256 |
(ExportJDBCAttributeNamesTranslator) this.parameters.getExportAttributes().getNamesTranslator(); |
|
257 |
if( nameTranslator.getTranslateIdentifiersToLowerCase() ) { |
|
258 |
tablename_tr = tablename_tr.toLowerCase(); |
|
259 |
} |
|
260 |
if( nameTranslator.getTranslateHyphens()) { |
|
261 |
tablename_tr = tablename_tr.replace("-", "_"); |
|
262 |
tablename_tr = tablename_tr.replace(".", "_"); |
|
263 |
} |
|
264 |
if( nameTranslator.getRemoveSpacesInIdentifiers() ) { |
|
265 |
tablename_tr = StringUtils.normalizeSpace(tablename_tr).replace(" ", "_"); |
|
266 |
} |
|
267 |
if( !tablename_tr.equals(tablename) ) { |
|
249 |
ExportJDBCAttributeNamesTranslator nameTranslator |
|
250 |
= (ExportJDBCAttributeNamesTranslator) this.parameters.getExportAttributes().getNamesTranslator(); |
|
251 |
String tablename_tr = nameTranslator.getNameSuggestion(tablename); |
|
252 |
if (!tablename_tr.equals(tablename)) { |
|
268 | 253 |
String msg = i18nManager.getTranslation( |
269 | 254 |
"Ha_utilizado_espacios_en_blanco_o_mayusculas_en_el_nombre_de_la_tabla_Desea_que_se_corrija_de_forma_automatica" |
270 | 255 |
); |
271 | 256 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
272 | 257 |
int resp = dialogs.confirmDialog( |
273 |
msg,
|
|
258 |
msg, |
|
274 | 259 |
i18nManager.getTranslation("_Warning"), |
275 |
JOptionPane.YES_NO_OPTION,
|
|
260 |
JOptionPane.YES_NO_OPTION, |
|
276 | 261 |
JOptionPane.WARNING_MESSAGE, |
277 | 262 |
"Exportto_Table_name_with_spaces_or_mixed_case" |
278 | 263 |
); |
279 |
if( resp != JOptionPane.YES_OPTION ) {
|
|
264 |
if (resp != JOptionPane.YES_OPTION) {
|
|
280 | 265 |
msg = i18nManager.getTranslation( |
281 | 266 |
"El_nombre_de_tabla_contiene_caracteres no_validos" |
282 | 267 |
); |
... | ... | |
288 | 273 |
ListModel model = this.lstTables.getModel(); |
289 | 274 |
for (int i = 0; i < model.getSize(); i++) { |
290 | 275 |
TableItem item = (TableItem) model.getElementAt(i); |
291 |
if ( StringUtils.equals(schema,item.getParams().getSchema())
|
|
292 |
&& StringUtils.equals(tablename,item.getParams().getTable())) { |
|
276 |
if (StringUtils.equals(schema, item.getParams().getSchema())
|
|
277 |
&& StringUtils.equals(tablename, item.getParams().getTable())) {
|
|
293 | 278 |
String msg = i18nManager.getTranslation( |
294 | 279 |
"_La_tabla_{0}_{1}_ya_existe_en_la_base_de_datos_Seleccione_la_opcion_de_insertar_registros_en_una_tabla_existente_para_a?adir_los_datos_a_esta_o_indique_otro_nombre", |
295 | 280 |
new String[]{schema, tablename} |
... | ... | |
312 | 297 |
try { |
313 | 298 |
DataManager dataManager = DALLocator.getDataManager(); |
314 | 299 |
JDBCServerExplorer explorer = (JDBCServerExplorer) dataManager.openServerExplorer( |
315 |
explorerParameters.getExplorerName(), |
|
316 |
explorerParameters |
|
300 |
explorerParameters.getExplorerName(),
|
|
301 |
explorerParameters
|
|
317 | 302 |
); |
318 | 303 |
this.sqlbuilder = explorer.createSQLBuilder(); |
319 | 304 |
} catch (Exception ex) { |
320 | 305 |
throw new RuntimeException("Can't retrieve the sqlbuilder", ex); |
321 | 306 |
} |
322 | 307 |
this.fillTablesList(); |
308 |
|
|
309 |
// set values from params |
|
310 |
this.rdoCreateTable.setSelected(this.parameters.canCreatetable()); |
|
311 |
if (this.parameters.canCreatetable() == true) { |
|
312 |
if (this.parameters.getSchema() != null) { |
|
313 |
this.txtSchema.setText(this.parameters.getSchema()); |
|
314 |
this.txtTableName.setText(this.parameters.getTableName()); |
|
315 |
} |
|
316 |
} else { |
|
317 |
String schema = this.parameters.getSchema(); |
|
318 |
if (schema != null) { |
|
319 |
//this.lstTables; |
|
320 |
for (int i = 0; i < this.lstTables.getModel().getSize(); i++) { |
|
321 |
TableItem item = (TableItem) this.lstTables.getModel().getElementAt(i); |
|
322 |
JDBCStoreParameters tableParameter = item.getParams(); |
|
323 |
if (tableParameter.getSchema() == null ? schema == null : tableParameter.getSchema().equals(schema)) { |
|
324 |
this.lstTables.setSelectedIndex(i); |
|
325 |
} |
|
326 |
} |
|
327 |
} |
|
328 |
} |
|
323 | 329 |
} |
324 | 330 |
|
325 | 331 |
@Override |
... | ... | |
385 | 391 |
|
386 | 392 |
@Override |
387 | 393 |
public void run() { |
388 |
if( sqlbuilder.support_schemas() ) {
|
|
394 |
if (sqlbuilder.support_schemas()) {
|
|
389 | 395 |
txtSchema.setText(sqlbuilder.default_schema()); |
390 | 396 |
} else { |
391 | 397 |
txtSchema.setText(""); |
... | ... | |
426 | 432 |
if (status.isCancellationRequested()) { |
427 | 433 |
status.cancel(); |
428 | 434 |
} |
429 |
if (status.isRunning()) {
|
|
435 |
if (status.isRunning()) { |
|
430 | 436 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
431 | 437 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
432 | 438 |
dialogs.messageDialog( |
433 | 439 |
i18nManager.getTranslation("_There_have_been_problems_filling_data_in_panel") |
434 |
+ " (" + getTitlePanel() + ")",
|
|
435 |
null,
|
|
440 |
+ " (" + getTitlePanel() + ")", |
|
441 |
null, |
|
436 | 442 |
i18nManager.getTranslation("_Warning"), |
437 |
JOptionPane.WARNING_MESSAGE,
|
|
443 |
JOptionPane.WARNING_MESSAGE, |
|
438 | 444 |
"ProblemsFillingTableNamePanel" |
439 | 445 |
); |
Also available in: Unified diff