Revision 47335
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.lib/org.gvsig.xml2db.lib.api/src/main/java/org/gvsig/xml2db/lib/api/xmlinfo/XMLAttributeInfo.java | ||
---|---|---|
36 | 36 |
int getType(); |
37 | 37 |
|
38 | 38 |
boolean hasChilds(); |
39 |
|
|
40 |
public int getChildsCount(String name); |
|
39 | 41 |
|
40 | 42 |
boolean isAggregate(); |
41 | 43 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.lib/org.gvsig.xml2db.lib.impl/src/main/java/org/gvsig/xml2db/lib/impl/xmlinfo/XMLInfoImpl.java | ||
---|---|---|
86 | 86 |
return null; |
87 | 87 |
} |
88 | 88 |
|
89 |
// public XMLTableInfo getByOriginalName(String name) { |
|
90 |
// for (XMLTableInfo tableInfo : this) { |
|
91 |
// if( StringUtils.equals(name, ((XMLTableInfoImpl)tableInfo).getOriginalName()) ) { |
|
92 |
// return tableInfo; |
|
93 |
// } |
|
94 |
// } |
|
95 |
// return null; |
|
96 |
// } |
|
97 |
// |
|
89 | 98 |
@Override |
90 | 99 |
public List<String> getKeys() { |
91 | 100 |
List<String> names = new ArrayList<>(this.tables.keySet()); |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.lib/org.gvsig.xml2db.lib.impl/src/main/java/org/gvsig/xml2db/lib/impl/xmlinfo/XMLAttributeInfoImpl.java | ||
---|---|---|
300 | 300 |
|
301 | 301 |
@Override |
302 | 302 |
public boolean hasChilds() { |
303 |
return this.childCounts.isEmpty(); |
|
303 |
return !this.childCounts.isEmpty();
|
|
304 | 304 |
} |
305 |
|
|
306 |
@Override |
|
307 |
public int getChildsCount(String name) { |
|
308 |
MutableInt count = this.childCounts.get(name); |
|
309 |
if(count == null){ |
|
310 |
return 0; |
|
311 |
} |
|
312 |
return count.getValue(); |
|
313 |
} |
|
305 | 314 |
|
306 | 315 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.lib/org.gvsig.xml2db.lib.impl/src/main/java/org/gvsig/xml2db/lib/impl/xmlinfo/XMLTableInfoImpl.java | ||
---|---|---|
28 | 28 |
private final XMLAttributeInfoImpl tagInfo; |
29 | 29 |
private String name; |
30 | 30 |
private EditableFeatureType featureType; |
31 |
private String originalName; |
|
31 | 32 |
|
32 | 33 |
public XMLTableInfoImpl(String path, XMLAttributeInfoImpl tagInfo) { |
33 | 34 |
this.tagInfo = tagInfo; |
... | ... | |
74 | 75 |
this.name = name; |
75 | 76 |
} |
76 | 77 |
|
78 |
public void rename(String name) { |
|
79 |
this.originalName = this.name; |
|
80 |
this.name = name; |
|
81 |
} |
|
82 |
|
|
83 |
public String getOriginalName() { |
|
84 |
return this.originalName; |
|
85 |
} |
|
86 |
|
|
77 | 87 |
@Override |
78 | 88 |
public int size() { |
79 | 89 |
return this.attributes.size(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.lib/org.gvsig.xml2db.lib.impl/src/main/java/org/gvsig/xml2db/lib/impl/StructureExtractorImpl.java | ||
---|---|---|
17 | 17 |
import java.util.List; |
18 | 18 |
import javax.xml.parsers.SAXParser; |
19 | 19 |
import javax.xml.parsers.SAXParserFactory; |
20 |
import org.apache.commons.lang3.ArrayUtils; |
|
20 | 21 |
import org.apache.commons.lang3.StringUtils; |
21 | 22 |
import org.apache.tika.utils.CharsetUtils; |
22 | 23 |
import org.cresques.cts.IProjection; |
... | ... | |
110 | 111 |
info.incrChildCount(infoChild.getName()); |
111 | 112 |
info.setLastChildID(infoChild.getName(), idvalueChild); |
112 | 113 |
infoChild.addValue(value); |
113 |
if( StringUtils.containsIgnoreCase(infoChild.getName(), "srid") ) { |
|
114 |
if( xmlinfo.getSrid() == null && StringUtils.containsIgnoreCase(infoChild.getName(), "srid") ) {
|
|
114 | 115 |
IProjection proj = getProyection(value); |
115 | 116 |
if( proj!=null ) { |
116 | 117 |
xmlinfo.setSrid(proj); |
... | ... | |
132 | 133 |
info = new XMLAttributeInfoImpl(path_s); |
133 | 134 |
xmlinfo.addTag(info); |
134 | 135 |
} |
135 |
if( info.hasChilds() ) { |
|
136 |
|
|
137 |
XMLAttributeInfoImpl parentinfo = null; |
|
138 |
if( path.size()>1 ) { |
|
139 |
List<String> parentpath = path.subList(0, path.size()-1); |
|
140 |
String parentpath_s = StringUtils.join(parentpath, "/"); |
|
141 |
parentinfo = xmlinfo.getTag(parentpath_s); |
|
142 |
} |
|
143 |
|
|
144 |
if( info.hasChilds() || (parentinfo != null && (parentinfo.getChildsCount(localName)>1))) { |
|
136 | 145 |
String value = this.chars.toString(); |
137 |
info.addValue(value); |
|
138 |
if( StringUtils.containsIgnoreCase(info.getName(), "srid") ) { |
|
139 |
IProjection proj = getProyection(value); |
|
140 |
if( proj!=null ) { |
|
141 |
xmlinfo.setSrid(proj); |
|
142 |
} |
|
143 |
} |
|
144 |
} else { |
|
145 |
String value = this.chars.toString(); |
|
146 | 146 |
if( StringUtils.isNotBlank(value) ) { |
147 | 147 |
String name = info.getName()+"$v"; |
148 | 148 |
String idvalueChild = dataManager.createUniqueID(); |
... | ... | |
155 | 155 |
info.setLastChildID(infoChild.getName(), idvalueChild); |
156 | 156 |
infoChild.addValue(value); |
157 | 157 |
} |
158 |
} else { |
|
159 |
String value = this.chars.toString(); |
|
160 |
info.addValue(value); |
|
161 |
if( StringUtils.containsIgnoreCase(info.getName(), "srid") ) { |
|
162 |
IProjection proj = getProyection(value); |
|
163 |
if( proj!=null ) { |
|
164 |
xmlinfo.setSrid(proj); |
|
165 |
} |
|
166 |
} |
|
158 | 167 |
} |
159 | 168 |
info.consolidateChildCounters(); |
160 | 169 |
// if( StringUtils.equalsIgnoreCase("LUGAR_CIRCULABA", info.getName()) ) { |
... | ... | |
201 | 210 |
return proj; |
202 | 211 |
} |
203 | 212 |
|
204 |
public XMLInfo extractStructure(File xml, Charset charset, SimpleTaskStatus status) throws FileNotFoundException, IOException { |
|
213 |
public XMLInfo extractStructure(File xml, Charset charset, IProjection projection, SimpleTaskStatus status) throws FileNotFoundException, IOException {
|
|
205 | 214 |
XMLInfoImpl xmlinfo = new XMLInfoImpl(); |
215 |
xmlinfo.setSrid(projection); |
|
206 | 216 |
long count = Xml2dbCommons.countLines(xml, charset, status); |
207 | 217 |
xmlinfo.setCountLines(count); |
208 | 218 |
InputSource is = Xml2dbCommons.openReader(xml,charset); |
209 | 219 |
return extractStructure(is, xmlinfo, status); |
210 | 220 |
} |
211 | 221 |
|
212 |
public XMLInfo extractStructure(InputStream xml, Charset charset, SimpleTaskStatus status) throws IOException { |
|
222 |
public XMLInfo extractStructure(InputStream xml, Charset charset, IProjection projection, SimpleTaskStatus status) throws IOException {
|
|
213 | 223 |
XMLInfoImpl xmlinfo = new XMLInfoImpl(); |
224 |
xmlinfo.setSrid(projection); |
|
214 | 225 |
long count = Xml2dbCommons.countLines(xml, charset, status); |
215 | 226 |
xmlinfo.setCountLines(count); |
216 | 227 |
InputSource is = Xml2dbCommons.openReader(xml, charset); |
217 | 228 |
return extractStructure(is, xmlinfo, status); |
218 | 229 |
} |
219 | 230 |
|
220 |
public XMLInfo extractStructure(Reader reader, SimpleTaskStatus status) { |
|
231 |
public XMLInfo extractStructure(Reader reader, IProjection projection, SimpleTaskStatus status) {
|
|
221 | 232 |
XMLInfoImpl xmlinfo = new XMLInfoImpl(); |
233 |
xmlinfo.setSrid(projection); |
|
222 | 234 |
InputSource is = new InputSource(reader); |
223 | 235 |
return extractStructure(is, xmlinfo, status); |
224 | 236 |
} |
... | ... | |
257 | 269 |
|
258 | 270 |
for (String tagPath : xmlinfo.getTagsPaths()) { |
259 | 271 |
XMLAttributeInfoImpl tag1Info = xmlinfo.getTagInfo(tagPath); |
272 |
System.out.println(tag1Info.getPath()); |
|
260 | 273 |
XMLTableInfoImpl tableInfo = new XMLTableInfoImpl(tagPath, tag1Info); |
261 | 274 |
for (String tagPath2 : xmlinfo.getTagsPaths()) { |
262 | 275 |
if( tagPath.equals(tagPath2) ) { |
... | ... | |
298 | 311 |
String[] path_ss = tableInfo2.getPath().split("/"); |
299 | 312 |
int l = path_ss.length; |
300 | 313 |
String name = path_ss[l-1]+"_"+path_ss[l-2]; |
301 |
tableInfo2.setName(name);
|
|
314 |
tableInfo2.rename(name);
|
|
302 | 315 |
renombrar = true; |
303 | 316 |
// System.out.println("###: Tablas con el mismo nombre, renombrado a "+name); |
304 | 317 |
// System.out.println("###: "+tableInfo1.getPath()); |
... | ... | |
310 | 323 |
String[] path_ss = tableInfo1.getPath().split("/"); |
311 | 324 |
int l = path_ss.length; |
312 | 325 |
String name = path_ss[l-1]+"_"+path_ss[l-2]; |
313 |
tableInfo1.setName(name);
|
|
326 |
tableInfo1.rename(name);
|
|
314 | 327 |
} |
315 | 328 |
status.incrementCurrentValue(); |
316 | 329 |
} |
... | ... | |
329 | 342 |
for (int i = 0; i < fieldkeys.length; i++) { |
330 | 343 |
String fieldkey = fieldkeys[i]; |
331 | 344 |
if( i==fieldkeys.length-1 ) { |
332 |
tableInfo.add(new XMLAttributeInfoImpl("$ID_"+fieldkey, DataTypes.INT).setPk(true));
|
|
345 |
tableInfo.add(new XMLAttributeInfoImpl("$ID_"+tableInfo.getName(), DataTypes.INT).setPk(true));
|
|
333 | 346 |
} else { |
334 | 347 |
// TODO es una relacion 1:1 |
335 |
tableInfo.add(new XMLAttributeInfoImpl("$ID_"+fieldkey, DataTypes.INT) |
|
348 |
XMLTableInfo tableInfo2 = xmlinfo.getTableByPath(StringUtils.join(ArrayUtils.subarray(fieldkeys, 0, i+1),"/")); |
|
349 |
tableInfo.add(new XMLAttributeInfoImpl("$ID_"+tableInfo2.getName(), DataTypes.INT) |
|
336 | 350 |
.setFk(true) |
337 | 351 |
.setFkCodeName("$ID_"+fieldkey) |
338 | 352 |
.setFkTableName(fieldkey) |
... | ... | |
394 | 408 |
continue; |
395 | 409 |
} |
396 | 410 |
EditableFeatureAttributeDescriptor attrdesc; |
397 |
if( attrinfo.getName().startsWith("$") ) { |
|
411 |
if( attrinfo.getName().startsWith("$ID") ) {
|
|
398 | 412 |
attrdesc = ft.add(attrinfo.getName(), attrinfo.getType()); |
413 |
attrdesc.setLabel("Id. "+attrinfo.getName().substring(4)); |
|
399 | 414 |
attrdesc.setSize(attrinfo.getSize()); |
415 |
} else if( attrinfo.getName().endsWith("$v") ) { |
|
416 |
attrdesc = ft.add(attrinfo.getName(), attrinfo.getType()); |
|
417 |
attrdesc.setLabel(StringUtils.left(attrinfo.getName(),attrinfo.getName().length()-2)); |
|
418 |
attrdesc.setSize(attrinfo.getSize()); |
|
400 | 419 |
} else { |
401 | 420 |
attrdesc = ft.add(attrinfo.getName(), attrinfo.getType()); |
402 | 421 |
attrdesc.setSize(attrinfo.getSize()); |
... | ... | |
423 | 442 |
for (XMLAttributeInfo attrinfo0 : tableInfo) { |
424 | 443 |
XMLAttributeInfoImpl attrinfo = (XMLAttributeInfoImpl) attrinfo0; |
425 | 444 |
if( attrinfo.isAggregate() ) { |
426 |
EditableFeatureAttributeDescriptor attrdesc = ft.add(plural(attrinfo.getName()), attrinfo.getType()); |
|
445 |
EditableFeatureAttributeDescriptor attrdesc = ft.add("$List_"+attrinfo.getName(), attrinfo.getType()); |
|
446 |
attrdesc.setLabel(plural(attrinfo.getName())); |
|
427 | 447 |
attrdesc.getTags().set("dal.relatedfeatures.table", attrinfo.getFkTableName()); |
428 | 448 |
attrdesc.getTags().set("dal.relatedfeatures.unique.field.name", attrinfo.getFkCodeName()); |
429 | 449 |
attrdesc.getTags().set("dynform.label.empty", true); |
430 | 450 |
attrdesc.getTags().set("dynform.resizeWeight", 100); |
431 | 451 |
attrdesc.setFeatureAttributeEmulator( |
432 |
"SELECT * FROM \""+attrinfo.getFkTableName() + "\" WHERE ( (\""+tableInfo.getName()+"\".\""+pk.getName()+"\") = (\""+attrinfo.getFkTableName() + "\".\""+pk.getName()+"\") )"
|
|
452 |
"SELECT * FROM \""+attrinfo.getFkTableName() + "\" WHERE ( (\""+pk.getName()+"\") = (\""+attrinfo.getFkTableName() + "\".\""+pk.getName()+"\") )" |
|
433 | 453 |
); |
434 | 454 |
attrdesc.setRelationType(DynField_v2.RELATION_TYPE_AGGREGATE); |
435 | 455 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.lib/org.gvsig.xml2db.lib.impl/src/main/java/org/gvsig/xml2db/lib/impl/Xml2dbCommons.java | ||
---|---|---|
88 | 88 |
is.setCharacterStream(reader); |
89 | 89 |
is.setEncoding(reader.getCharset().name()); |
90 | 90 |
} else { |
91 |
BOMInputStream bomIs = new BOMInputStream(is.getByteStream()); |
|
92 |
is.setByteStream(bomIs); |
|
91 | 93 |
InputStreamReader reader = new InputStreamReader( |
92 | 94 |
is.getByteStream(), |
93 | 95 |
is.getEncoding() |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.lib/org.gvsig.xml2db.lib.impl/src/main/java/org/gvsig/xml2db/lib/impl/CopyXML2dbImpl.java | ||
---|---|---|
51 | 51 |
private FeatureStore store; |
52 | 52 |
private EditableFeature current_row; |
53 | 53 |
private int pkcounter; |
54 |
private EditableFeature last_row; |
|
54 | 55 |
|
55 | 56 |
|
56 | 57 |
private TableInfo(Map<String,TableInfo> tables, JDBCStoreParameters openStoreParams) { |
... | ... | |
103 | 104 |
FeatureStore theStore = this.getStore(); |
104 | 105 |
// System.out.println("###: create row("+this.tableName+")"); |
105 | 106 |
this.current_row = theStore.createNewFeature(); |
107 |
this.last_row = this.current_row; |
|
106 | 108 |
FeatureType ft = this.current_row.getType(); |
107 | 109 |
for (FeatureAttributeDescriptor attrdesc : ft) { |
108 | 110 |
if( attrdesc.isPrimaryKey() ) { |
109 | 111 |
this.set(attrdesc.getName(), this.pkcounter++); |
110 | 112 |
} else if( attrdesc.isForeingKey() ) { |
111 | 113 |
ForeingKey fk = attrdesc.getForeingKey(); |
112 |
TableInfo table = this.tables.get(fk.getTableName()); |
|
114 |
TableInfo table = this.tables.get(fk.getTableName().toLowerCase());
|
|
113 | 115 |
if( table != null ) { |
114 | 116 |
this.set(attrdesc.getName(), table.getPkValue()); |
115 | 117 |
} |
... | ... | |
138 | 140 |
private void insert() { |
139 | 141 |
if( this.store!=null && this.current_row!=null ) { |
140 | 142 |
try { |
143 |
|
|
144 |
FeatureType ft = this.current_row.getType(); |
|
145 |
for (FeatureAttributeDescriptor attrdesc : ft) { |
|
146 |
if( attrdesc.isForeingKey() ) { |
|
147 |
ForeingKey fk = attrdesc.getForeingKey(); |
|
148 |
TableInfo table = this.tables.get(fk.getTableName().toLowerCase()); |
|
149 |
if( table != null ) { |
|
150 |
if( current_row.isNull(attrdesc.getName())){ |
|
151 |
this.set(attrdesc.getName(), table.getPkValue()); |
|
152 |
} |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
141 | 157 |
// System.out.println("###: insert("+this.tableName+")"); |
142 | 158 |
this.store.insert(current_row); |
143 | 159 |
} catch(Throwable t) { |
... | ... | |
148 | 164 |
} |
149 | 165 |
|
150 | 166 |
private Object getPkValue() { |
151 |
if( this.current_row==null ) {
|
|
167 |
if( this.last_row==null ) {
|
|
152 | 168 |
return null; |
153 | 169 |
} |
154 |
FeatureAttributeDescriptor[] attrdescs = this.current_row.getType().getPrimaryKey();
|
|
155 |
return this.current_row.get(attrdescs[0].getName());
|
|
170 |
FeatureAttributeDescriptor[] attrdescs = this.last_row.getType().getPrimaryKey();
|
|
171 |
return this.last_row.get(attrdescs[0].getName());
|
|
156 | 172 |
} |
157 | 173 |
} |
158 | 174 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.lib/org.gvsig.xml2db.lib.impl/src/main/java/org/gvsig/xml2db/lib/impl/DefaultXml2dbManager.java | ||
---|---|---|
59 | 59 |
@Override |
60 | 60 |
public XMLInfo extractStructure(File xml, Charset encoding, IProjection projection, SimpleTaskStatus status) throws IOException, FileNotFoundException { |
61 | 61 |
StructureExtractorImpl extractor = new StructureExtractorImpl(); |
62 |
XMLInfo xmlinfo = extractor.extractStructure(xml, encoding, SimpleTaskStatus.get(status)); |
|
62 |
XMLInfo xmlinfo = extractor.extractStructure(xml, encoding, projection, SimpleTaskStatus.get(status));
|
|
63 | 63 |
return xmlinfo; |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
@Override |
67 | 67 |
public XMLInfo extractStructure(InputStream xml, Charset encoding, IProjection projection, SimpleTaskStatus status) throws IOException { |
68 | 68 |
StructureExtractorImpl extractor = new StructureExtractorImpl(); |
69 |
XMLInfo xmlinfo = extractor.extractStructure(xml, encoding, SimpleTaskStatus.get(status)); |
|
69 |
XMLInfo xmlinfo = extractor.extractStructure(xml, encoding, projection, SimpleTaskStatus.get(status));
|
|
70 | 70 |
return xmlinfo; |
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
@Override |
74 | 74 |
public XMLInfo extractStructure(Reader xml, IProjection projection, SimpleTaskStatus status) throws IOException { |
75 | 75 |
StructureExtractorImpl extractor = new StructureExtractorImpl(); |
76 |
XMLInfo xmlinfo = extractor.extractStructure(xml, SimpleTaskStatus.get(status)); |
|
76 |
XMLInfo xmlinfo = extractor.extractStructure(xml, projection, SimpleTaskStatus.get(status));
|
|
77 | 77 |
return xmlinfo; |
78 | 78 |
} |
79 | 79 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.swing/org.gvsig.xml2db.swing.impl/src/main/java/org/gvsig/xml2db/swing/impl/importxml2db/ImportXML2dbPanel.java | ||
---|---|---|
109 | 109 |
null, |
110 | 110 |
this.cboCharset |
111 | 111 |
); |
112 |
this.pickerCharset.set(Charset.defaultCharset());
|
|
112 |
this.pickerCharset.set(null);
|
|
113 | 113 |
|
114 | 114 |
this.pickerConnection = dataSwingManager.createJDBCConnectionPickerController( |
115 | 115 |
this.cboConnection, |
Also available in: Unified diff