Revision 47472 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
CopyXML2dbImpl.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 | 4 |
import java.io.InputStream; |
5 |
import java.io.Reader; |
|
6 | 5 |
import java.nio.charset.Charset; |
7 | 6 |
import java.util.ArrayList; |
8 | 7 |
import java.util.HashMap; |
... | ... | |
15 | 14 |
import org.apache.commons.lang3.mutable.MutableInt; |
16 | 15 |
import org.gvsig.fmap.dal.DALLocator; |
17 | 16 |
import org.gvsig.fmap.dal.DataManager; |
18 |
import org.gvsig.fmap.dal.DataQuery; |
|
19 | 17 |
import org.gvsig.fmap.dal.DataStoreParameters; |
20 | 18 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
21 | 19 |
import org.gvsig.fmap.dal.feature.Feature; |
... | ... | |
31 | 29 |
import org.gvsig.tools.dispose.DisposeUtils; |
32 | 30 |
import org.gvsig.tools.i18n.I18nManager; |
33 | 31 |
import org.gvsig.tools.task.SimpleTaskStatus; |
34 |
import org.gvsig.xml2db.lib.impl.xmlinfo.XMLTableInfoImpl; |
|
35 | 32 |
import org.slf4j.Logger; |
36 | 33 |
import org.slf4j.LoggerFactory; |
37 | 34 |
import org.xml.sax.Attributes; |
... | ... | |
228 | 225 |
return this.featureType.getTags().getString("xml2db.path", null); |
229 | 226 |
} |
230 | 227 |
|
228 |
public String getTablePrefix() { |
|
229 |
return this.featureType.getTags().getString("xml2db.tableprefix", null); |
|
230 |
} |
|
231 |
|
|
231 | 232 |
public boolean containsAttr(String attrname) { |
232 | 233 |
return this.featureType.get(attrname) != null; |
233 | 234 |
} |
234 | 235 |
} |
235 | 236 |
|
236 |
public void copyData(InputSource is, JDBCServerExplorerParameters dbparams, long countLines, SimpleTaskStatus taskStatus) { |
|
237 |
public void copyData(InputSource is, JDBCServerExplorerParameters dbparams, long countLines, String tablesPrefix, SimpleTaskStatus taskStatus) {
|
|
237 | 238 |
if( is == null || is.getCharacterStream()==null ) { |
238 | 239 |
throw new IllegalArgumentException("reader is null"); |
239 | 240 |
} |
... | ... | |
296 | 297 |
try { |
297 | 298 |
path.add(localName); |
298 | 299 |
String path_s = StringUtils.join(path, "/"); |
299 |
TableInfo table1 = getTableByPath(tables, path_s); |
|
300 |
TableInfo table1 = getTableByPath(tablesPrefix, tables, path_s);
|
|
300 | 301 |
if( table1 != null ) { |
301 | 302 |
table1.createRow(); |
302 | 303 |
for (int i = 0; i < attributes.getLength(); i++) { |
... | ... | |
319 | 320 |
// taskStatus.setCurValue(line.intValue()); |
320 | 321 |
try { |
321 | 322 |
String path_s = StringUtils.join(path, "/"); |
322 |
TableInfo table1 = getTableByPath(tables, path_s); |
|
323 |
TableInfo table1 = getTableByPath(tablesPrefix, tables, path_s);
|
|
323 | 324 |
if(table1 != null) { |
324 | 325 |
if (this.valueBuilder != null) { |
325 | 326 |
String value = StringUtils.trimToNull(this.valueBuilder.toString()); |
... | ... | |
334 | 335 |
String parentpath_s = StringUtils.join(parentpath, "/"); |
335 | 336 |
String attrname = FilenameUtils.getBaseName(path_s); |
336 | 337 |
|
337 |
TableInfo table2 = getTableByPath(tables, parentpath_s); |
|
338 |
TableInfo table2 = getTableByPath(tablesPrefix, tables, parentpath_s);
|
|
338 | 339 |
if( table2!=null ) { |
339 | 340 |
if( this.valueBuilder!=null ) { |
340 | 341 |
String value = StringUtils.trimToNull(this.valueBuilder.toString()); |
... | ... | |
370 | 371 |
} |
371 | 372 |
} |
372 | 373 |
|
373 |
private TableInfo getTableByPath(Map<String,TableInfo> tables, String path) { |
|
374 |
private TableInfo getTableByPath(String tablesPrefix, Map<String,TableInfo> tables, String path) {
|
|
374 | 375 |
for (TableInfo table : tables.values()) { |
375 |
if(StringUtils.equalsIgnoreCase(path, table.getPath())){ |
|
376 |
if( StringUtils.equalsIgnoreCase(tablesPrefix, table.getTablePrefix()) && |
|
377 |
StringUtils.equalsIgnoreCase(path, table.getPath())){ |
|
376 | 378 |
return table; |
377 | 379 |
} |
378 | 380 |
} |
379 | 381 |
return null; |
380 | 382 |
} |
381 | 383 |
|
382 |
public void copyData(File xml, Charset charset, JDBCServerExplorerParameters dbparams, SimpleTaskStatus taskStatus) { |
|
384 |
public void copyData(File xml, Charset charset, JDBCServerExplorerParameters dbparams, String tablesPrefix, SimpleTaskStatus taskStatus) {
|
|
383 | 385 |
long count = Xml2dbCommons.countLines(xml, charset, taskStatus); |
384 | 386 |
|
385 | 387 |
InputSource is = Xml2dbCommons.openReader(xml, charset); |
386 |
copyData(is, dbparams, count, taskStatus); |
|
388 |
copyData(is, dbparams, count, tablesPrefix, taskStatus);
|
|
387 | 389 |
} |
388 | 390 |
|
389 |
public void copyData(InputStream xml, Charset charset, JDBCServerExplorerParameters dbparams, SimpleTaskStatus taskStatus) { |
|
391 |
public void copyData(InputStream xml, Charset charset, JDBCServerExplorerParameters dbparams, String tablesPrefix, SimpleTaskStatus taskStatus) {
|
|
390 | 392 |
long count = -1; //Xml2dbCommons.countLines(xml, charset, taskStatus); |
391 | 393 |
InputSource is = Xml2dbCommons.openReader(xml, charset); |
392 |
copyData(is, dbparams, count, taskStatus); |
|
394 |
copyData(is, dbparams, count, tablesPrefix, taskStatus);
|
|
393 | 395 |
} |
394 | 396 |
|
395 | 397 |
} |
Also available in: Unified diff