Revision 32307
trunk/libraries/libGeocoding/.classpath | ||
---|---|---|
3 | 3 |
<classpathentry kind="src" path="src"/> |
4 | 4 |
<classpathentry kind="src" path="src-test"/> |
5 | 5 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
6 |
<classpathentry kind="lib" path="lib/org.gvsig.tools.storage.jar"/> |
|
7 | 6 |
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/> |
8 | 7 |
<classpathentry kind="lib" path="/_fwAndami/lib/log4j-1.2.8.jar"/> |
9 | 8 |
<classpathentry kind="lib" path="/_fwAndami/lib/org.gvsig.exceptions.jar" sourcepath="/libExceptions/src"/> |
... | ... | |
13 | 12 |
<classpathentry kind="lib" path="/_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/lib/fmap.jar"/> |
14 | 13 |
<classpathentry kind="lib" path="lib/htmlparser.jar"/> |
15 | 14 |
<classpathentry kind="lib" path="/_fwAndami/lib/kxml2.jar"/> |
15 |
<classpathentry kind="lib" path="/_fwAndami/lib/castor-0.9.5.3-xml.jar"/> |
|
16 |
<classpathentry kind="lib" path="/_fwAndami/lib/iver-utiles.jar" sourcepath="/libIverUtiles"/> |
|
16 | 17 |
<classpathentry kind="output" path="bin"/> |
17 | 18 |
</classpath> |
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/patterns/TestPersistence.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
package org.gvsig.normalization.patterns; |
29 | 29 |
|
30 |
import java.io.File; |
|
31 |
import java.io.FileReader; |
|
32 |
import java.io.FileWriter; |
|
33 | 30 |
import java.io.IOException; |
34 | 31 |
import java.util.ArrayList; |
35 | 32 |
import java.util.List; |
36 | 33 |
|
37 | 34 |
import junit.framework.TestCase; |
38 | 35 |
|
39 |
import org.gvsig.tools.storage.IStorage;
|
|
40 |
import org.gvsig.tools.storage.StorageXML;
|
|
36 |
import com.iver.cit.gvsig.fmap.layers.XMLException;
|
|
37 |
import com.iver.utiles.XMLEntity;
|
|
41 | 38 |
|
42 | 39 |
/** |
43 | 40 |
* |
... | ... | |
47 | 44 |
*/ |
48 | 45 |
public class TestPersistence extends TestCase { |
49 | 46 |
|
50 |
// private static final Logger log = PluginServices.getLogger(); |
|
51 |
|
|
52 |
private File file = null; |
|
53 |
|
|
54 |
public TestPersistence (){ |
|
55 |
try { |
|
56 |
file = File.createTempFile("pat", "xml"); |
|
57 |
} catch (IOException e) { |
|
58 |
e.printStackTrace(); |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 | 47 |
/** |
63 | 48 |
* test |
49 |
* |
|
50 |
* @throws XMLException |
|
64 | 51 |
*/ |
65 |
public void testParseXML() throws IOException {
|
|
52 |
public void testParseLoadXML() throws IOException, XMLException {
|
|
66 | 53 |
|
67 |
Patternnormalization pat = new Patternnormalization();
|
|
54 |
NormalizationPattern pat = new NormalizationPattern();
|
|
68 | 55 |
pat.setPatternname("pruebaParseXML.xml"); |
69 | 56 |
pat.setNofirstrows(0); |
70 | 57 |
|
... | ... | |
124 | 111 |
|
125 | 112 |
pat.setElements(elems); |
126 | 113 |
|
127 |
IStorage storage = new StorageXML();
|
|
128 |
FileWriter writer = null;
|
|
114 |
XMLEntity xml = pat.getXMLEntity();
|
|
115 |
assertNotNull(xml);
|
|
129 | 116 |
|
130 |
pat.getstate(storage); |
|
131 |
|
|
132 |
try { |
|
133 |
writer = new FileWriter(this.file.getAbsolutePath()); |
|
134 |
storage.dump(writer); |
|
135 |
writer.close(); |
|
136 |
} catch (IOException e) { |
|
137 |
e.printStackTrace(); |
|
138 |
} |
|
117 |
// pat2 |
|
118 |
NormalizationPattern pat2 = new NormalizationPattern(); |
|
119 |
pat2.setXMLEntity(xml); |
|
139 | 120 |
|
140 |
}
|
|
121 |
assertEquals(0, pat2.getNofirstrows());
|
|
141 | 122 |
|
142 |
/** |
|
143 |
* |
|
144 |
*/ |
|
145 |
public void testLoadXML() { |
|
123 |
assertEquals("pruebaParseXML.xml", pat2.getPatternname()); |
|
124 |
assertEquals(0, pat2.getNofirstrows()); |
|
146 | 125 |
|
147 |
Patternnormalization pat = new Patternnormalization(); |
|
148 |
IStorage storage = new StorageXML(); |
|
149 |
FileReader reader = null; |
|
150 |
|
|
151 |
try { |
|
152 |
reader = new FileReader(this.file.getAbsolutePath()); |
|
153 |
storage.load(reader); |
|
154 |
pat.setstate(storage); |
|
155 |
} catch (Exception e) { |
|
156 |
e.printStackTrace(); |
|
157 |
} |
|
158 |
|
|
159 |
assertEquals(0, pat.getNofirstrows()); |
|
160 |
|
|
161 |
assertEquals("pruebaParseXML.xml", pat.getPatternname()); |
|
162 |
assertEquals(0, pat.getNofirstrows()); |
|
163 |
|
|
164 | 126 |
Element elem0 = ((Element) pat.getElements().get(0)); |
165 | 127 |
|
166 | 128 |
assertEquals("campo1", elem0.getFieldname()); |
167 | 129 |
assertEquals(true, elem0.getImportfield()); |
130 |
|
|
168 | 131 |
} |
132 |
|
|
169 | 133 |
} |
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestAllTypeData.java | ||
---|---|---|
28 | 28 |
package org.gvsig.normalization.operations; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.io.FileReader; |
|
32 | 31 |
import java.io.IOException; |
33 | 32 |
import java.util.ArrayList; |
34 | 33 |
|
35 | 34 |
import junit.framework.TestCase; |
36 | 35 |
|
37 | 36 |
import org.apache.log4j.Logger; |
38 |
import org.gvsig.normalization.patterns.Patternnormalization; |
|
39 |
import org.gvsig.tools.storage.IStorage; |
|
40 |
import org.gvsig.tools.storage.StorageXML; |
|
37 |
import org.gvsig.normalization.patterns.NormalizationPattern; |
|
41 | 38 |
|
42 | 39 |
import com.iver.andami.PluginServices; |
43 | 40 |
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver; |
... | ... | |
51 | 48 |
public class TestAllTypeData extends TestCase { |
52 | 49 |
|
53 | 50 |
private static final Logger log = PluginServices.getLogger(); |
54 |
Patternnormalization pat = new Patternnormalization();
|
|
51 |
NormalizationPattern pat = new NormalizationPattern();
|
|
55 | 52 |
ArrayList<String> chains = new ArrayList<String>(); |
56 | 53 |
File file; |
57 | 54 |
|
58 | 55 |
public void setUp() { |
59 | 56 |
File f = new File( |
60 | 57 |
"src-test/org/gvsig/normalization/operations/testdata/pattotal.xml"); |
61 |
IStorage storage = new StorageXML(); |
|
62 | 58 |
try { |
63 |
FileReader red = new FileReader(f); |
|
64 |
storage.load(red); |
|
65 |
pat.setstate(storage); |
|
59 |
pat.loadFromXML(f); |
|
66 | 60 |
} catch (Exception e) { |
67 |
log.error("Error parsing the xml pattern", e);
|
|
61 |
e.printStackTrace();
|
|
68 | 62 |
} |
69 | 63 |
|
70 | 64 |
chains.add("Javier#-7;-0.2578&01/10/2007&02/09&02-78"); |
... | ... | |
132 | 126 |
file.delete(); |
133 | 127 |
|
134 | 128 |
} catch (IOException e1) { |
135 |
// TODO Auto-generated catch block |
|
136 | 129 |
e1.printStackTrace(); |
137 | 130 |
} |
138 | 131 |
|
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestNormalizeTableAlterTable.java | ||
---|---|---|
28 | 28 |
package org.gvsig.normalization.operations; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.io.FileReader; |
|
32 | 31 |
|
33 | 32 |
import junit.framework.TestCase; |
34 | 33 |
|
35 | 34 |
import org.apache.log4j.Logger; |
36 |
import org.gvsig.normalization.patterns.Patternnormalization; |
|
37 |
import org.gvsig.tools.storage.IStorage; |
|
38 |
import org.gvsig.tools.storage.StorageXML; |
|
35 |
import org.gvsig.normalization.patterns.NormalizationPattern; |
|
39 | 36 |
|
40 | 37 |
import com.hardcode.gdbms.driver.exceptions.CloseDriverException; |
41 | 38 |
import com.hardcode.gdbms.engine.data.file.FileDataSource; |
... | ... | |
57 | 54 |
public class TestNormalizeTableAlterTable extends TestCase { |
58 | 55 |
|
59 | 56 |
private static final Logger log = PluginServices.getLogger(); |
60 |
Patternnormalization pat = new Patternnormalization();
|
|
57 |
NormalizationPattern pat = new NormalizationPattern();
|
|
61 | 58 |
File dbfFile = new File( |
62 | 59 |
"src-test/org/gvsig/normalization/operations/testdata/pro.dbf"); |
63 | 60 |
File patFile = new File( |
... | ... | |
67 | 64 |
DBFDriver driver = null; |
68 | 65 |
FileDataSource fiDatSource = null; |
69 | 66 |
|
70 |
// TODO |
|
71 | 67 |
|
72 | 68 |
public void setUp() { |
69 |
|
|
73 | 70 |
try { |
74 |
IStorage storage = new StorageXML(); |
|
75 |
FileReader red = new FileReader(patFile); |
|
76 |
|
|
77 |
storage.load(red); |
|
78 |
pat.setstate(storage); |
|
79 |
//pat = (Patternnormalization) Patternnormalization.unmarshal(red); |
|
80 |
} catch (Exception e) { |
|
81 |
log.error("Error parsing the xml pattern", e); |
|
71 |
pat.loadFromXML(patFile); |
|
72 |
} catch (Exception e1) { |
|
73 |
e1.printStackTrace(); |
|
82 | 74 |
} |
83 | 75 |
try { |
84 | 76 |
driver = new DBFDriver(); |
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestCreateNewPattern.java | ||
---|---|---|
39 | 39 |
import org.gvsig.normalization.patterns.Fieldseparator; |
40 | 40 |
import org.gvsig.normalization.patterns.Fieldtype; |
41 | 41 |
import org.gvsig.normalization.patterns.Infieldseparators; |
42 |
import org.gvsig.normalization.patterns.Patternnormalization;
|
|
42 |
import org.gvsig.normalization.patterns.NormalizationPattern;
|
|
43 | 43 |
import org.gvsig.normalization.patterns.Stringvalue; |
44 | 44 |
|
45 | 45 |
/* |
... | ... | |
55 | 55 |
|
56 | 56 |
public void testCreateNewPattern() { |
57 | 57 |
// Create object |
58 |
Patternnormalization pat = new Patternnormalization();
|
|
58 |
NormalizationPattern pat = new NormalizationPattern();
|
|
59 | 59 |
|
60 | 60 |
// Field Separators |
61 | 61 |
Fieldseparator filsep1 = new Fieldseparator(); |
... | ... | |
156 | 156 |
assertEquals(((Element) pat.getElements().get(0)).getImportfield(), |
157 | 157 |
true); |
158 | 158 |
assertEquals(((Element) pat.getElements().get(0)).getFieldwidth(), 0); |
159 |
assertEquals(((Stringvalue)((Element) pat.getElements().get(0)).getFieldtype()
|
|
160 |
.getStringvalue()).getStringvaluewidth(), 50); |
|
159 |
assertEquals(((Stringvalue) ((Element) pat.getElements().get(0))
|
|
160 |
.getFieldtype().getStringvalue()).getStringvaluewidth(), 50);
|
|
161 | 161 |
assertEquals(((Element) pat.getElements().get(0)).getFieldseparator() |
162 | 162 |
.getSemicolonsep(), true); |
163 | 163 |
assertEquals(((Element) pat.getElements().get(1)).getImportfield(), |
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestFilterString.java | ||
---|---|---|
28 | 28 |
package org.gvsig.normalization.operations; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.io.FileReader;
|
|
31 |
import java.io.FileNotFoundException;
|
|
32 | 32 |
import java.io.IOException; |
33 |
import java.io.UnsupportedEncodingException; |
|
33 | 34 |
import java.util.ArrayList; |
34 | 35 |
|
35 | 36 |
import junit.framework.TestCase; |
36 | 37 |
|
37 | 38 |
import org.apache.log4j.Logger; |
38 |
import org.gvsig.normalization.patterns.Patternnormalization;
|
|
39 |
import org.gvsig.tools.storage.IStorage;
|
|
40 |
import org.gvsig.tools.storage.StorageXML;
|
|
39 |
import org.exolab.castor.xml.MarshalException;
|
|
40 |
import org.exolab.castor.xml.ValidationException;
|
|
41 |
import org.gvsig.normalization.patterns.NormalizationPattern;
|
|
41 | 42 |
|
42 | 43 |
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver; |
44 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
43 | 45 |
|
44 | 46 |
/** |
45 | 47 |
* |
... | ... | |
51 | 53 |
|
52 | 54 |
private static final Logger log = Logger.getLogger(TestFilterString.class); |
53 | 55 |
|
54 |
public void testFilterString() { |
|
56 |
public void testFilterString() throws MarshalException, |
|
57 |
FileNotFoundException, UnsupportedEncodingException, |
|
58 |
ValidationException, XMLException { |
|
55 | 59 |
|
56 | 60 |
log.info("TestFilterString: start the test"); |
57 | 61 |
|
... | ... | |
63 | 67 |
|
64 | 68 |
assertNotNull(fPat); |
65 | 69 |
|
66 |
Patternnormalization pat = parserPat(fPat);
|
|
70 |
NormalizationPattern pat = parserPat(fPat);
|
|
67 | 71 |
assertNotNull(pat); |
68 | 72 |
|
69 | 73 |
File outputFile = null; |
... | ... | |
126 | 130 |
log.info("TestFilterString: test finished"); |
127 | 131 |
} |
128 | 132 |
|
129 |
private Patternnormalization parserPat(File f) { |
|
130 |
Patternnormalization pat = new Patternnormalization(); |
|
131 |
IStorage storage = new StorageXML(); |
|
132 |
try { |
|
133 |
FileReader red = new FileReader(f); |
|
134 |
storage.load(red); |
|
135 |
pat.setstate(storage); |
|
136 |
} catch (Exception e) { |
|
137 |
e.printStackTrace(); |
|
138 |
} |
|
133 |
private NormalizationPattern parserPat(File f) throws MarshalException, |
|
134 |
FileNotFoundException, UnsupportedEncodingException, |
|
135 |
ValidationException, XMLException { |
|
136 |
NormalizationPattern pat = new NormalizationPattern(); |
|
137 |
pat.loadFromXML(f); |
|
139 | 138 |
return pat; |
140 | 139 |
} |
141 | 140 |
|
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestNormalizeStringsFromFile.java | ||
---|---|---|
28 | 28 |
package org.gvsig.normalization.operations; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.io.FileReader; |
|
32 | 31 |
import java.io.IOException; |
33 | 32 |
import java.util.ArrayList; |
34 | 33 |
|
35 | 34 |
import junit.framework.TestCase; |
36 | 35 |
|
37 | 36 |
import org.apache.log4j.Logger; |
38 |
import org.gvsig.normalization.patterns.Patternnormalization; |
|
39 |
import org.gvsig.tools.storage.IStorage; |
|
40 |
import org.gvsig.tools.storage.StorageXML; |
|
37 |
import org.gvsig.normalization.patterns.NormalizationPattern; |
|
41 | 38 |
|
42 | 39 |
import com.hardcode.gdbms.driver.exceptions.CloseDriverException; |
43 | 40 |
import com.iver.andami.PluginServices; |
... | ... | |
51 | 48 |
public class TestNormalizeStringsFromFile extends TestCase { |
52 | 49 |
|
53 | 50 |
private static final Logger log = PluginServices.getLogger(); |
54 |
Patternnormalization pat = new Patternnormalization();
|
|
51 |
NormalizationPattern pat = new NormalizationPattern();
|
|
55 | 52 |
ArrayList<String> chains = new ArrayList<String>(); |
56 | 53 |
File file; |
57 | 54 |
DBFDriver test = null; |
... | ... | |
61 | 58 |
File f = new File( |
62 | 59 |
"./src-test/org/gvsig/normalization/operations/testdata/normFile.xml"); |
63 | 60 |
try { |
64 |
IStorage storage = new StorageXML(); |
|
65 |
FileReader red = new FileReader(f); |
|
66 |
storage.load(red); |
|
67 |
pat.setstate(storage); |
|
68 |
// pat = (Patternnormalization) Patternnormalization.unmarshal(red); |
|
61 |
pat.loadFromXML(f); |
|
69 | 62 |
} catch (Exception e) { |
70 |
log.error("Error parsing the xml pattern", e);
|
|
63 |
e.printStackTrace();
|
|
71 | 64 |
} |
65 |
|
|
72 | 66 |
chains.add("TEST1;TEST2;TEST3"); |
73 | 67 |
chains.add("TEST4;TEST5;TEST6"); |
74 | 68 |
chains.add("TEST7;TEST8;TEST9"); |
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestNormalizeTableJoinTable.java | ||
---|---|---|
28 | 28 |
package org.gvsig.normalization.operations; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.io.FileReader; |
|
32 | 31 |
import java.io.IOException; |
33 | 32 |
|
34 | 33 |
import junit.framework.TestCase; |
35 | 34 |
|
36 | 35 |
import org.apache.log4j.Logger; |
37 |
import org.gvsig.normalization.patterns.Patternnormalization; |
|
38 |
import org.gvsig.tools.storage.IStorage; |
|
39 |
import org.gvsig.tools.storage.StorageXML; |
|
36 |
import org.gvsig.normalization.patterns.NormalizationPattern; |
|
40 | 37 |
|
41 | 38 |
import com.hardcode.gdbms.driver.exceptions.CloseDriverException; |
42 | 39 |
import com.hardcode.gdbms.engine.data.file.FileDataSource; |
... | ... | |
56 | 53 |
public class TestNormalizeTableJoinTable extends TestCase { |
57 | 54 |
|
58 | 55 |
private static final Logger log = PluginServices.getLogger(); |
59 |
Patternnormalization pat = new Patternnormalization();
|
|
56 |
NormalizationPattern pat = new NormalizationPattern();
|
|
60 | 57 |
File dbfFile = new File( |
61 | 58 |
"src-test/org/gvsig/normalization/operations/testdata/pro.dbf"); |
62 | 59 |
File patFile = new File( |
... | ... | |
67 | 64 |
DBFDriver test = null; |
68 | 65 |
|
69 | 66 |
public void setUp() { |
70 |
try { |
|
71 |
IStorage storage = new StorageXML(); |
|
72 |
FileReader red = new FileReader(patFile); |
|
73 | 67 |
|
74 |
|
|
75 |
storage.load(red); |
|
76 |
pat.setstate(storage); |
|
77 |
|
|
78 |
//pat = (Patternnormalization) Patternnormalization.unmarshal(red); |
|
68 |
try { |
|
69 |
pat.loadFromXML(patFile); |
|
79 | 70 |
} catch (Exception e) { |
80 | 71 |
log.error("Error parsing the xml pattern", e); |
81 | 72 |
} |
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestNormAlgorithm.java | ||
---|---|---|
28 | 28 |
package org.gvsig.normalization.operations; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.io.FileReader; |
|
31 |
import java.io.FileNotFoundException; |
|
32 |
import java.io.UnsupportedEncodingException; |
|
32 | 33 |
import java.util.List; |
33 | 34 |
|
34 | 35 |
import junit.framework.TestCase; |
35 | 36 |
|
36 | 37 |
import org.apache.log4j.Logger; |
37 |
import org.gvsig.normalization.patterns.Patternnormalization;
|
|
38 |
import org.gvsig.tools.storage.IStorage;
|
|
39 |
import org.gvsig.tools.storage.StorageXML;
|
|
38 |
import org.exolab.castor.xml.MarshalException;
|
|
39 |
import org.exolab.castor.xml.ValidationException;
|
|
40 |
import org.gvsig.normalization.patterns.NormalizationPattern;
|
|
40 | 41 |
|
42 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
43 |
|
|
41 | 44 |
public class TestNormAlgorithm extends TestCase { |
42 | 45 |
|
43 | 46 |
private static final Logger log = Logger.getLogger(TestNormAlgorithm.class); |
... | ... | |
45 | 48 |
public void setUp() { |
46 | 49 |
} |
47 | 50 |
|
48 |
public void testSplitChain() { |
|
51 |
public void testSplitChain() throws MarshalException, FileNotFoundException, UnsupportedEncodingException, ValidationException, XMLException {
|
|
49 | 52 |
|
50 | 53 |
log.info("TestNormAlgorithm. Test splits strings"); |
51 | 54 |
|
... | ... | |
243 | 246 |
|
244 | 247 |
} |
245 | 248 |
|
246 |
private List<String> parser(File f, String chain) { |
|
247 |
Patternnormalization pat = new Patternnormalization(); |
|
248 |
IStorage storage = new StorageXML(); |
|
249 |
|
|
250 |
try { |
|
251 |
FileReader reader = new FileReader(f); |
|
252 |
storage.load(reader); |
|
253 |
pat.setstate(storage); |
|
254 |
} catch (Exception e) { |
|
255 |
e.printStackTrace(); |
|
256 |
} |
|
249 |
private List<String> parser(File f, String chain) throws MarshalException, FileNotFoundException, UnsupportedEncodingException, ValidationException, XMLException { |
|
250 |
NormalizationPattern pat = new NormalizationPattern(); |
|
251 |
pat.loadFromXML(f); |
|
257 | 252 |
NormAlgorithm na = new NormAlgorithm(pat); |
258 | 253 |
|
259 | 254 |
List<String> result = na.splitChain(chain); |
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestMarshall.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 | 31 |
import java.io.FileNotFoundException; |
32 |
import java.io.FileReader; |
|
33 |
import java.io.FileWriter; |
|
34 | 32 |
import java.io.IOException; |
33 |
import java.io.UnsupportedEncodingException; |
|
35 | 34 |
|
36 | 35 |
import junit.framework.TestCase; |
37 | 36 |
|
38 | 37 |
import org.apache.log4j.Logger; |
38 |
import org.exolab.castor.xml.MarshalException; |
|
39 |
import org.exolab.castor.xml.ValidationException; |
|
39 | 40 |
import org.gvsig.normalization.patterns.Element; |
40 |
import org.gvsig.normalization.patterns.Patternnormalization; |
|
41 |
import org.gvsig.tools.storage.IStorage; |
|
42 |
import org.gvsig.tools.storage.StorageXML; |
|
41 |
import org.gvsig.normalization.patterns.NormalizationPattern; |
|
43 | 42 |
|
44 | 43 |
import com.iver.andami.PluginServices; |
44 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
45 | 45 |
|
46 | 46 |
public class TestMarshall extends TestCase { |
47 | 47 |
|
48 | 48 |
private static final Logger log = PluginServices.getLogger(); |
49 | 49 |
|
50 |
public void testMarshallUnmarshall() { |
|
50 |
public void testMarshallUnmarshall() throws MarshalException, |
|
51 |
ValidationException, XMLException, IOException { |
|
51 | 52 |
|
52 | 53 |
log.info("testMarshallUnmarshall. start test"); |
53 |
Patternnormalization pat = new Patternnormalization();
|
|
54 |
Patternnormalization pat3 = new Patternnormalization();
|
|
54 |
NormalizationPattern pat = new NormalizationPattern();
|
|
55 |
NormalizationPattern pat3 = new NormalizationPattern();
|
|
55 | 56 |
File file = new File( |
56 | 57 |
"src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml"); |
57 | 58 |
|
58 |
FileReader reader = null; |
|
59 |
IStorage storage = new StorageXML(); |
|
60 |
|
|
61 |
Element elem1 = null; |
|
62 |
|
|
63 | 59 |
// PARSER |
64 |
try { |
|
65 |
reader = new FileReader(file); |
|
66 |
storage.load(reader); |
|
67 |
pat.setstate(storage); |
|
68 | 60 |
|
69 |
assertEquals(11, pat.getElements().size()); |
|
70 |
assertEquals(0, pat.getNofirstrows()); |
|
61 |
pat.loadFromXML(file); |
|
71 | 62 |
|
72 |
elem1 = (Element) pat.getElements().get(0); |
|
63 |
assertEquals(11, pat.getElements().size()); |
|
64 |
assertEquals(0, pat.getNofirstrows()); |
|
73 | 65 |
|
74 |
assertNotNull(elem1); |
|
75 |
assertEquals("NewField", elem1.getFieldname()); |
|
66 |
Element elem1 = (Element) pat.getElements().get(0); |
|
76 | 67 |
|
77 |
} catch (FileNotFoundException e) { |
|
78 |
log.error("Parsing and serializing the pattern", e); |
|
79 |
} catch (ClassNotFoundException e) { |
|
80 |
log.error("Parsing and serializing the pattern", e); |
|
81 |
} |
|
68 |
assertNotNull(elem1); |
|
69 |
assertEquals("NewField", elem1.getFieldname()); |
|
82 | 70 |
|
83 | 71 |
// SERIALIZER |
84 |
IStorage storage2 = new StorageXML(); |
|
85 |
pat.getstate(storage2); |
|
86 |
File ftemp = null; |
|
87 |
try { |
|
88 |
//ftemp = File.createTempFile("tem", "txt"); |
|
89 |
ftemp = new File("C:\\000.txt"); |
|
90 |
FileWriter writer2 = new FileWriter(ftemp); |
|
91 |
storage2.dump(writer2); |
|
92 |
writer2.close(); |
|
93 |
} catch (IOException e) { |
|
94 |
log.error("Parsing and serializing the pattern", e); |
|
95 |
} |
|
72 |
File ftemp = File.createTempFile("temp", "txt"); |
|
73 |
pat.saveToXML(ftemp); |
|
96 | 74 |
|
97 | 75 |
// PARSER |
98 |
IStorage storage3 = new StorageXML(); |
|
99 |
FileReader reader3; |
|
100 |
try { |
|
101 |
assertNotNull(ftemp); |
|
102 |
reader3 = new FileReader(ftemp); |
|
103 |
storage3.load(reader3); |
|
104 |
pat3.setstate(storage3); |
|
105 | 76 |
|
106 |
Element elem2 = (Element) pat3.getElements().get(0);
|
|
77 |
assertNotNull(ftemp);
|
|
107 | 78 |
|
108 |
assertNotNull(elem2);
|
|
79 |
pat3.loadFromXML(ftemp);
|
|
109 | 80 |
|
110 |
assertEquals(elem1.getImportfield(), elem2.getImportfield()); |
|
111 |
assertEquals(elem1.getFieldwidth(), elem2.getFieldwidth()); |
|
112 |
assertEquals(elem1.getFieldname(), elem2.getFieldname()); |
|
113 |
assertEquals(elem1.getInfieldseparators().getDecimalseparator(), |
|
114 |
elem2.getInfieldseparators().getDecimalseparator()); |
|
81 |
Element elem2 = (Element) pat3.getElements().get(0); |
|
115 | 82 |
|
116 |
} catch (FileNotFoundException e) { |
|
117 |
log.error("Parsing and serializing the pattern", e); |
|
118 |
} catch (ClassNotFoundException e) { |
|
119 |
log.error("Parsing and serializing the pattern", e); |
|
120 |
} |
|
83 |
assertNotNull(elem2); |
|
84 |
|
|
85 |
assertEquals(elem1.getImportfield(), elem2.getImportfield()); |
|
86 |
assertEquals(elem1.getFieldwidth(), elem2.getFieldwidth()); |
|
87 |
assertEquals(elem1.getFieldname(), elem2.getFieldname()); |
|
88 |
assertEquals(elem1.getInfieldseparators().getDecimalseparator(), elem2 |
|
89 |
.getInfieldseparators().getDecimalseparator()); |
|
90 |
|
|
121 | 91 |
} |
122 | 92 |
|
123 |
public void testUnmarshall() { |
|
93 |
public void testUnmarshall() throws MarshalException, |
|
94 |
FileNotFoundException, UnsupportedEncodingException, |
|
95 |
ValidationException, XMLException { |
|
124 | 96 |
|
125 | 97 |
log.info("testUnmarshall. start test"); |
126 |
// Create a Reader to the file to unmarshall from |
|
127 |
FileReader reader = null; |
|
128 |
try { |
|
129 |
reader = new FileReader( |
|
130 |
"src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml"); |
|
131 |
assertNotNull(reader); |
|
132 |
} catch (FileNotFoundException e) { |
|
133 |
log.error("File not found"); |
|
134 |
e.printStackTrace(); |
|
135 |
} |
|
136 |
|
|
98 |
File file = new File( |
|
99 |
"src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml"); |
|
137 | 100 |
// Marshal the person object |
138 |
Patternnormalization pat = new Patternnormalization(); |
|
139 |
IStorage storage = new StorageXML(); |
|
140 |
try { |
|
141 |
storage.load(reader); |
|
142 |
pat.setstate(storage); |
|
143 |
assertNotNull(pat); |
|
144 |
} catch (Exception e) { |
|
145 |
log.error("Unmarshall the pattern"); |
|
146 |
e.printStackTrace(); |
|
147 |
} |
|
101 |
NormalizationPattern pat = new NormalizationPattern(); |
|
102 |
pat.loadFromXML(file); |
|
103 |
|
|
148 | 104 |
log.info("pattern loaded"); |
149 | 105 |
// results |
150 | 106 |
assertEquals(11, pat.getElements().size()); |
trunk/libraries/libGeocoding/src/org/gvsig/normalization/patterns/Patternnormalization.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 Prodevelop S.L. main development |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.normalization.patterns; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a> |
|
33 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a> |
|
34 |
* |
|
35 |
*/ |
|
36 |
|
|
37 |
import java.util.ArrayList; |
|
38 |
import java.util.List; |
|
39 |
|
|
40 |
import org.apache.log4j.Logger; |
|
41 |
import org.gvsig.tools.storage.IStorable; |
|
42 |
import org.gvsig.tools.storage.IStorage; |
|
43 |
import org.gvsig.tools.storage.StorageCollection; |
|
44 |
|
|
45 |
/** |
|
46 |
* Class Patternnormalization. |
|
47 |
* |
|
48 |
* This class is the normalization pattern. This pattern has your name |
|
49 |
* (_patternname), your xml file path (_patternurl), the attribute |
|
50 |
* (_nofirstrows) that says the number of the rows in the text file that will |
|
51 |
* not be normalized and the list of elements (_elements) that make the pattern |
|
52 |
*/ |
|
53 |
public class Patternnormalization implements IStorable { |
|
54 |
|
|
55 |
private static final Logger log = Logger |
|
56 |
.getLogger(Patternnormalization.class); |
|
57 |
/** |
|
58 |
* Pattern name |
|
59 |
*/ |
|
60 |
private String _patternname; |
|
61 |
|
|
62 |
|
|
63 |
/** |
|
64 |
* number of file rows that they will not be normalized |
|
65 |
*/ |
|
66 |
private int _nofirstrows; |
|
67 |
|
|
68 |
/** |
|
69 |
* List of elements. Each element is one new field. One element has |
|
70 |
* attributes that they define the new field and split strings process. |
|
71 |
*/ |
|
72 |
private List<Element> _elements; |
|
73 |
|
|
74 |
/** |
|
75 |
* Constructor |
|
76 |
*/ |
|
77 |
public Patternnormalization() { |
|
78 |
super(); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Returns the value of field 'elements'. |
|
83 |
* |
|
84 |
* @return the value of field 'elements'. |
|
85 |
*/ |
|
86 |
|
|
87 |
public List<Element> getElements() { |
|
88 |
return this._elements; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Returns the value of field 'elements'. |
|
93 |
* |
|
94 |
* @return the value of field 'elements'. |
|
95 |
*/ |
|
96 |
public Element[] getArrayElements() { |
|
97 |
Element[] eles = new Element[this._elements.size()]; |
|
98 |
for (int i = 0; i < this._elements.size(); i++) { |
|
99 |
eles[i] = (Element) this._elements.get(i); |
|
100 |
} |
|
101 |
return eles; |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Returns the value of field 'nofirstrows'. |
|
106 |
* |
|
107 |
* @return the value of field 'nofirstrows'. |
|
108 |
*/ |
|
109 |
public int getNofirstrows() { |
|
110 |
return this._nofirstrows; |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Returns the value of field 'patternname'. |
|
115 |
* |
|
116 |
* @return the value of field 'patternname'. |
|
117 |
*/ |
|
118 |
public java.lang.String getPatternname() { |
|
119 |
return this._patternname; |
|
120 |
} |
|
121 |
|
|
122 |
|
|
123 |
/** |
|
124 |
* Sets the value of field 'elements'. |
|
125 |
* |
|
126 |
* @param elements |
|
127 |
* the value of field 'elements'. |
|
128 |
*/ |
|
129 |
|
|
130 |
public void setElements(List<Element> elements) { |
|
131 |
this._elements = elements; |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Sets the value of field 'nofirstrows'. |
|
136 |
* |
|
137 |
* @param nofirstrows |
|
138 |
* the value of field 'nofirstrows'. |
|
139 |
*/ |
|
140 |
public void setNofirstrows(int nofirstrows) { |
|
141 |
this._nofirstrows = nofirstrows; |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Sets the value of field 'patternname'. |
|
146 |
* |
|
147 |
* @param patternname |
|
148 |
* the value of field 'patternname'. |
|
149 |
*/ |
|
150 |
public void setPatternname(String patternname) { |
|
151 |
this._patternname = patternname; |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* This method serializes the pattern object |
|
156 |
* |
|
157 |
* @param state |
|
158 |
*/ |
|
159 |
public void getstate(IStorage state) { |
|
160 |
state.setName("patternnormalization"); |
|
161 |
state.setTheClass(this); |
|
162 |
state.put("patternname", this._patternname); |
|
163 |
state.put("nofirstrows", this._nofirstrows); |
|
164 |
state.put("elements", "element", this._elements); |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* This method parses the pattern object |
|
169 |
* |
|
170 |
* @param state |
|
171 |
*/ |
|
172 |
public void setstate(IStorage state) { |
|
173 |
this._patternname = ((String) state.get("patternname")).trim(); |
|
174 |
this._nofirstrows = state.getInt("nofirstrows"); |
|
175 |
try { |
|
176 |
StorageCollection sto = (StorageCollection) state |
|
177 |
.getObject("elements"); |
|
178 |
this._elements = new ArrayList<Element>(); |
|
179 |
for (int i = 0; i < sto.size(); i++) { |
|
180 |
Element elem = (Element) sto.get(i); |
|
181 |
this._elements.add(elem); |
|
182 |
} |
|
183 |
} catch (Exception e) { |
|
184 |
log.error("parsing pattern", e); |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 |
} |
trunk/libraries/libGeocoding/src/org/gvsig/normalization/patterns/Infieldseparators.java | ||
---|---|---|
34 | 34 |
* |
35 | 35 |
*/ |
36 | 36 |
|
37 |
import org.gvsig.tools.storage.IStorable;
|
|
38 |
import org.gvsig.tools.storage.IStorage;
|
|
37 |
import org.gvsig.normalization.persistence.GeocodingPersistence;
|
|
38 |
import org.gvsig.normalization.persistence.GeocodingTags;
|
|
39 | 39 |
|
40 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
41 |
import com.iver.utiles.XMLEntity; |
|
42 |
|
|
40 | 43 |
/** |
41 | 44 |
* Class Infieldseparators. |
42 | 45 |
* |
... | ... | |
44 | 47 |
* separator, the decimal separator and the text separator |
45 | 48 |
* |
46 | 49 |
*/ |
47 |
public class Infieldseparators implements IStorable {
|
|
50 |
public class Infieldseparators implements GeocodingPersistence {
|
|
48 | 51 |
|
49 | 52 |
/** |
50 | 53 |
* Thousand separator |
... | ... | |
65 | 68 |
* Constructor |
66 | 69 |
*/ |
67 | 70 |
public Infieldseparators() { |
68 |
super(); |
|
69 | 71 |
} |
70 | 72 |
|
71 | 73 |
/** |
... | ... | |
126 | 128 |
} |
127 | 129 |
|
128 | 130 |
/** |
129 |
* This method serializes the infieldseparators object |
|
130 |
* |
|
131 |
* @param state |
|
131 |
* Get class name |
|
132 | 132 |
*/ |
133 |
public void getstate(IStorage state) { |
|
134 |
state.setTheClass(this); |
|
135 |
state.put("thousandseparator", this._thousandseparator); |
|
136 |
state.put("decimalseparator", this._decimalseparator); |
|
137 |
state.put("textseparator", this._textseparator); |
|
133 |
public String getClassName() { |
|
134 |
return this.getClass().getName(); |
|
138 | 135 |
} |
139 | 136 |
|
140 | 137 |
/** |
141 |
* This method parses the infieldseparators object |
|
142 |
* |
|
143 |
* @param state |
|
138 |
* Persist object |
|
144 | 139 |
*/ |
145 |
public void setstate(IStorage state) { |
|
146 |
this._thousandseparator = (String) state.get("thousandseparator"); |
|
147 |
this._decimalseparator = (String) state.get("decimalseparator"); |
|
148 |
this._textseparator = (String) state.get("textseparator"); |
|
140 |
public XMLEntity getXMLEntity() throws XMLException { |
|
141 |
XMLEntity xml = new XMLEntity(); |
|
142 |
xml.setName(GeocodingTags.INFIELDSEPARATORS); |
|
143 |
xml.putProperty(GeocodingTags.THOUSANDSEPARATOR, |
|
144 |
this._thousandseparator); |
|
145 |
xml.putProperty(GeocodingTags.DECIMALSEPARATOR, this._decimalseparator); |
|
146 |
xml.putProperty(GeocodingTags.TEXTSEPARATOR, this._textseparator); |
|
147 |
|
|
148 |
return xml; |
|
149 | 149 |
} |
150 | 150 |
|
151 |
/** |
|
152 |
* Load object |
|
153 |
*/ |
|
154 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
|
155 |
this._thousandseparator = xml |
|
156 |
.getStringProperty(GeocodingTags.THOUSANDSEPARATOR); |
|
157 |
this._decimalseparator = xml |
|
158 |
.getStringProperty(GeocodingTags.DECIMALSEPARATOR); |
|
159 |
this._textseparator = xml |
|
160 |
.getStringProperty(GeocodingTags.TEXTSEPARATOR); |
|
161 |
|
|
162 |
} |
|
163 |
|
|
151 | 164 |
} |
trunk/libraries/libGeocoding/src/org/gvsig/normalization/patterns/Stringvalue.java | ||
---|---|---|
34 | 34 |
* |
35 | 35 |
*/ |
36 | 36 |
|
37 |
import org.gvsig.tools.storage.IStorable;
|
|
38 |
import org.gvsig.tools.storage.IStorage;
|
|
37 |
import org.gvsig.normalization.persistence.GeocodingPersistence;
|
|
38 |
import org.gvsig.normalization.persistence.GeocodingTags;
|
|
39 | 39 |
|
40 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
41 |
import com.iver.utiles.XMLEntity; |
|
42 |
|
|
40 | 43 |
/** |
41 | 44 |
* Class Stringvalue. |
42 | 45 |
* |
43 | 46 |
* This class defines the new field type like String |
44 | 47 |
*/ |
45 |
public class Stringvalue implements IStorable {
|
|
48 |
public class Stringvalue implements GeocodingPersistence {
|
|
46 | 49 |
|
47 | 50 |
/** |
48 | 51 |
* Width of the new String field |
... | ... | |
53 | 56 |
* Constructor |
54 | 57 |
*/ |
55 | 58 |
public Stringvalue() { |
56 |
super(); |
|
57 | 59 |
} |
58 | 60 |
|
59 | 61 |
/** |
60 |
* Returns the value of field 'stringvaluewidth'. |
|
61 |
* |
|
62 | 62 |
* @return the value of field 'stringvaluewidth'. |
63 | 63 |
*/ |
64 | 64 |
public int getStringvaluewidth() { |
... | ... | |
69 | 69 |
* Sets the value of field 'stringvaluewidth'. |
70 | 70 |
* |
71 | 71 |
* @param stringvaluewidth |
72 |
* the value of field 'stringvaluewidth' |
|
73 | 72 |
*/ |
74 | 73 |
public void setStringvaluewidth(int stringvaluewidth) { |
75 | 74 |
this._stringvaluewidth = stringvaluewidth; |
76 | 75 |
} |
77 | 76 |
|
78 | 77 |
/** |
79 |
* This method serializes the stringvalue object |
|
80 |
* |
|
81 |
* @param state |
|
78 |
* get class name |
|
82 | 79 |
*/ |
83 |
public void getstate(IStorage state) { |
|
84 |
state.setTheClass(this); |
|
85 |
state.put("stringvaluewidth", this._stringvaluewidth); |
|
80 |
public String getClassName() { |
|
81 |
return this.getClass().getName(); |
|
86 | 82 |
} |
87 | 83 |
|
88 | 84 |
/** |
89 |
* This method parses the stringvalue object |
|
90 |
* |
|
91 |
* @param state |
|
85 |
* Persist object |
|
92 | 86 |
*/ |
93 |
public void setstate(IStorage state) { |
|
94 |
this._stringvaluewidth = state.getInt("stringvaluewidth"); |
|
87 |
public XMLEntity getXMLEntity() throws XMLException { |
|
88 |
XMLEntity xml = new XMLEntity(); |
|
89 |
xml.setName(GeocodingTags.STRINGVALUE); |
|
90 |
xml.putProperty(GeocodingTags.STRINGVALUEWIDTH, this._stringvaluewidth); |
|
91 |
return xml; |
|
92 |
} |
|
95 | 93 |
|
94 |
/** |
|
95 |
* Load object |
|
96 |
*/ |
|
97 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
|
98 |
this._stringvaluewidth = xml |
|
99 |
.getIntProperty(GeocodingTags.STRINGVALUEWIDTH); |
|
100 |
|
|
96 | 101 |
} |
97 | 102 |
|
98 | 103 |
} |
trunk/libraries/libGeocoding/src/org/gvsig/normalization/patterns/Fieldseparator.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
package org.gvsig.normalization.patterns; |
29 | 29 |
|
30 |
import org.gvsig.tools.storage.IStorable;
|
|
31 |
import org.gvsig.tools.storage.IStorage;
|
|
30 |
import org.gvsig.normalization.persistence.GeocodingPersistence;
|
|
31 |
import org.gvsig.normalization.persistence.GeocodingTags;
|
|
32 | 32 |
import org.htmlparser.util.Translate; |
33 | 33 |
|
34 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
35 |
import com.iver.utiles.XMLEntity; |
|
36 |
|
|
34 | 37 |
/** |
35 | 38 |
* |
36 | 39 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a> |
... | ... | |
44 | 47 |
* This class has the separators between two fields and they are necessary for |
45 | 48 |
* the split string process |
46 | 49 |
*/ |
47 |
public class Fieldseparator implements IStorable {
|
|
50 |
public class Fieldseparator implements GeocodingPersistence {
|
|
48 | 51 |
|
49 | 52 |
/** |
50 | 53 |
* Split string by tab |
... | ... | |
80 | 83 |
* Constructor |
81 | 84 |
*/ |
82 | 85 |
public Fieldseparator() { |
83 |
super(); |
|
84 | 86 |
} |
85 | 87 |
|
86 | 88 |
/** |
... | ... | |
197 | 199 |
this._tabsep = tabsep; |
198 | 200 |
} |
199 | 201 |
|
202 |
// /** |
|
203 |
// * Saves the internal state of the object on the provided PersistentState |
|
204 |
// * object. |
|
205 |
// * |
|
206 |
// * @param state |
|
207 |
// */ |
|
208 |
// public void saveToState(PersistentState state) throws |
|
209 |
// PersistenceException { |
|
210 |
// |
|
211 |
// state.set("tabsep", this._tabsep); |
|
212 |
// state.set("spacesep", this._spacesep); |
|
213 |
// state.set("colonsep", this._colonsep); |
|
214 |
// state.set("semicolonsep", this._semicolonsep); |
|
215 |
// String ot = (String) this._othersep; |
|
216 |
// if (ot != null) { |
|
217 |
// String oth = Translate.encode(ot); |
|
218 |
// state.set("othersep", oth); |
|
219 |
// } else { |
|
220 |
// state.set("othersep", ""); |
|
221 |
// } |
|
222 |
// |
|
223 |
// state.set("joinsep", this._joinsep); |
|
224 |
// } |
|
225 |
// |
|
226 |
// /** |
|
227 |
// * Set the state of the object from the state passed as parameter. |
|
228 |
// * |
|
229 |
// * @param state |
|
230 |
// */ |
|
231 |
// public void loadFromState(PersistentState state) |
|
232 |
// throws PersistenceException { |
|
233 |
// this._tabsep = state.getBoolean("tabsep"); |
|
234 |
// this._spacesep = state.getBoolean("spacesep"); |
|
235 |
// this._colonsep = state.getBoolean("colonsep"); |
|
236 |
// this._semicolonsep = state.getBoolean("semicolonsep"); |
|
237 |
// this._othersep = null; |
|
238 |
// String ot = state.getString("othersep"); |
|
239 |
// if (ot != null) { |
|
240 |
// String oth = Translate.decode(ot); |
|
241 |
// this._othersep = oth; |
|
242 |
// } |
|
243 |
// this._joinsep = state.getBoolean("joinsep"); |
|
244 |
// } |
|
245 |
|
|
200 | 246 |
/** |
201 |
* This method serializes the fieldseparator object |
|
202 |
* |
|
203 |
* @param state |
|
247 |
* Get class name |
|
204 | 248 |
*/ |
205 |
public void getstate(IStorage state) { |
|
206 |
state.setTheClass(this); |
|
207 |
state.put("tabsep", this._tabsep ? "true" : "false"); |
|
208 |
state.put("spacesep", this._spacesep ? "true" : "false"); |
|
209 |
state.put("colonsep", this._colonsep ? "true" : "false"); |
|
210 |
state.put("semicolonsep", this._semicolonsep ? "true" : "false"); |
|
249 |
public String getClassName() { |
|
250 |
return this.getClass().getName(); |
|
251 |
} |
|
252 |
|
|
253 |
/** |
|
254 |
* Persist object |
|
255 |
*/ |
|
256 |
public XMLEntity getXMLEntity() throws XMLException { |
|
257 |
XMLEntity xml = new XMLEntity(); |
|
258 |
xml.setName(GeocodingTags.FIELDSEPARATOR); |
|
259 |
xml.putProperty(GeocodingTags.TABSEP, this._tabsep); |
|
260 |
xml.putProperty(GeocodingTags.SPACESEP, this._spacesep); |
|
261 |
xml.putProperty(GeocodingTags.COLONSEP, this._colonsep); |
|
262 |
xml.putProperty(GeocodingTags.SEMICOLONSEP, this._semicolonsep); |
|
263 |
xml.putProperty(GeocodingTags.OTHERSEP, this._othersep); |
|
211 | 264 |
String ot = (String) this._othersep; |
212 | 265 |
if (ot != null) { |
213 | 266 |
String oth = Translate.encode(ot); |
214 |
state.put("othersep", oth);
|
|
267 |
xml.putProperty(GeocodingTags.OTHERSEP, oth);
|
|
215 | 268 |
} else { |
216 |
state.put("othersep", "");
|
|
269 |
xml.putProperty(GeocodingTags.OTHERSEP, "");
|
|
217 | 270 |
} |
271 |
xml.putProperty(GeocodingTags.JOINSEP, this._joinsep); |
|
218 | 272 |
|
219 |
state.put("joinsep", this._joinsep ? "true" : "false"); |
|
220 |
|
|
273 |
return xml; |
|
221 | 274 |
} |
222 | 275 |
|
223 | 276 |
/** |
224 |
* This method parses the fieldseparator object |
|
225 |
* |
|
226 |
* @param state |
|
277 |
* Load object |
|
227 | 278 |
*/ |
228 |
public void setstate(IStorage state) { |
|
229 |
this._tabsep = ((String) state.get("tabsep")).compareTo("true") == 0 ? true |
|
230 |
: false; |
|
231 |
this._spacesep = ((String) state.get("spacesep")).compareTo("true") == 0 ? true |
|
232 |
: false; |
|
233 |
this._colonsep = ((String) state.get("colonsep")).compareTo("true") == 0 ? true |
|
234 |
: false; |
|
235 |
this._semicolonsep = ((String) state.get("semicolonsep")) |
|
236 |
.compareTo("true") == 0 ? true : false; |
|
237 |
this._othersep = null; |
|
238 |
String ot = (String) state.get("othersep"); |
|
279 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
|
280 |
this._tabsep = xml.getBooleanProperty(GeocodingTags.TABSEP); |
|
281 |
this._spacesep = xml.getBooleanProperty(GeocodingTags.SPACESEP); |
|
282 |
this._colonsep = xml.getBooleanProperty(GeocodingTags.COLONSEP); |
|
283 |
this._semicolonsep = xml.getBooleanProperty(GeocodingTags.SEMICOLONSEP); |
|
284 |
String ot = xml.getStringProperty(GeocodingTags.OTHERSEP); |
|
239 | 285 |
if (ot != null) { |
240 | 286 |
String oth = Translate.decode(ot); |
241 | 287 |
this._othersep = oth; |
242 | 288 |
} |
289 |
this._joinsep = xml.getBooleanProperty(GeocodingTags.JOINSEP); |
|
243 | 290 |
|
244 |
this._joinsep = ((String) state.get("joinsep")).compareTo("true") == 0 ? true |
|
245 |
: false; |
|
246 | 291 |
} |
247 | 292 |
} |
trunk/libraries/libGeocoding/src/org/gvsig/normalization/patterns/NormalizationPattern.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 Prodevelop S.L. main development |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.normalization.patterns; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a> |
|
33 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a> |
|
34 |
* |
|
35 |
*/ |
|
36 |
|
|
37 |
import java.io.File; |
|
38 |
import java.io.FileInputStream; |
|
39 |
import java.io.FileNotFoundException; |
|
40 |
import java.io.FileOutputStream; |
|
41 |
import java.io.IOException; |
|
42 |
import java.io.InputStream; |
|
43 |
import java.io.InputStreamReader; |
|
44 |
import java.io.OutputStream; |
|
45 |
import java.io.OutputStreamWriter; |
|
46 |
import java.io.UnsupportedEncodingException; |
|
47 |
import java.util.ArrayList; |
|
48 |
import java.util.Iterator; |
|
49 |
import java.util.List; |
|
50 |
|
|
51 |
import org.apache.log4j.Logger; |
|
52 |
import org.exolab.castor.xml.MarshalException; |
|
53 |
import org.exolab.castor.xml.Marshaller; |
|
54 |
import org.exolab.castor.xml.ValidationException; |
|
55 |
import org.gvsig.normalization.persistence.GeocodingPersistence; |
|
56 |
import org.gvsig.normalization.persistence.GeocodingTags; |
|
57 |
|
|
58 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
59 |
import com.iver.utiles.XMLEntity; |
|
60 |
import com.iver.utiles.xml.XMLEncodingUtils; |
|
61 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
|
62 |
|
|
63 |
/** |
|
64 |
* Class Patternnormalization. |
|
65 |
* |
|
66 |
* This class is the normalization pattern. This pattern has your name |
|
67 |
* (_patternname), your xml file path (_patternurl), the attribute |
|
68 |
* (_nofirstrows) that says the number of the rows in the text file that will |
|
69 |
* not be normalized and the list of elements (_elements) that make the pattern |
|
70 |
*/ |
|
71 |
public class NormalizationPattern implements GeocodingPersistence { |
|
72 |
|
|
73 |
@SuppressWarnings("unused") |
|
74 |
private static final Logger log = Logger |
|
75 |
.getLogger(NormalizationPattern.class); |
|
76 |
|
|
77 |
/** |
|
78 |
* Pattern name |
|
79 |
*/ |
|
80 |
private String _patternname; |
|
81 |
|
|
82 |
/** |
|
83 |
* number of file rows that they will not be normalized |
|
84 |
*/ |
|
85 |
private int _nofirstrows; |
|
86 |
|
|
87 |
/** |
|
88 |
* List of elements. Each element is one new field. One element has |
|
89 |
* attributes that they define the new field and split strings process. |
|
90 |
*/ |
|
91 |
private List<Element> _elements; |
|
92 |
|
|
93 |
/** |
|
94 |
* Constructor |
|
95 |
*/ |
|
96 |
public NormalizationPattern() { |
|
97 |
this._elements = new ArrayList<Element>(); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Returns the value of field 'elements'. |
|
102 |
* |
|
103 |
* @return the value of field 'elements'. |
|
104 |
*/ |
|
105 |
|
|
106 |
public List<Element> getElements() { |
|
107 |
return this._elements; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* Returns the value of field 'elements'. |
|
112 |
* |
|
113 |
* @return the value of field 'elements'. |
|
114 |
*/ |
|
115 |
public Element[] getArrayElements() { |
|
116 |
Element[] eles = new Element[this._elements.size()]; |
|
117 |
for (int i = 0; i < this._elements.size(); i++) { |
|
118 |
eles[i] = (Element) this._elements.get(i); |
|
119 |
} |
|
120 |
return eles; |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* Returns the value of field 'nofirstrows'. |
|
125 |
* |
|
126 |
* @return the value of field 'nofirstrows'. |
|
127 |
*/ |
|
128 |
public int getNofirstrows() { |
|
129 |
return this._nofirstrows; |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Returns the value of field 'patternname'. |
|
134 |
* |
|
135 |
* @return the value of field 'patternname'. |
|
136 |
*/ |
|
137 |
public java.lang.String getPatternname() { |
|
138 |
return this._patternname; |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* Sets the value of field 'elements'. |
|
143 |
* |
|
144 |
* @param elements |
|
145 |
* the value of field 'elements'. |
|
146 |
*/ |
|
147 |
|
|
148 |
public void setElements(List<Element> elements) { |
|
149 |
this._elements = elements; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Sets the value of field 'nofirstrows'. |
|
154 |
* |
|
155 |
* @param nofirstrows |
|
156 |
* the value of field 'nofirstrows'. |
|
157 |
*/ |
|
158 |
public void setNofirstrows(int nofirstrows) { |
|
159 |
this._nofirstrows = nofirstrows; |
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* Sets the value of field 'patternname'. |
|
164 |
* |
|
165 |
* @param patternname |
|
166 |
* the value of field 'patternname'. |
|
167 |
*/ |
|
168 |
public void setPatternname(String patternname) { |
|
169 |
this._patternname = patternname; |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* Save the pattern to XML file |
|
174 |
* |
|
175 |
* @param file |
|
176 |
* @throws XMLException |
|
177 |
* @throws IOException |
|
178 |
* @throws ValidationException |
|
179 |
* @throws MarshalException |
|
180 |
*/ |
|
181 |
public void saveToXML(File file) throws XMLException, IOException, |
|
182 |
MarshalException, ValidationException { |
|
183 |
OutputStream fos = new FileOutputStream(file.getAbsolutePath()); |
|
184 |
OutputStreamWriter writer = new OutputStreamWriter(fos, |
|
185 |
GeocodingTags.PROJECTENCODING); |
|
186 |
Marshaller m = new Marshaller(writer); |
|
187 |
m.setEncoding(GeocodingTags.PROJECTENCODING); |
|
188 |
|
|
189 |
XMLEntity xml = this.getXMLEntity(); |
|
190 |
xml.putProperty("followHeaderEncoding", true); |
|
191 |
m.marshal(xml.getXmlTag()); |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Load the pattern from XML file |
|
196 |
* |
|
197 |
* @param reader |
|
198 |
* @throws FileNotFoundException |
|
199 |
* @throws UnsupportedEncodingException |
|
200 |
* @throws ValidationException |
|
201 |
* @throws MarshalException |
|
202 |
* @throws XMLException |
|
203 |
*/ |
|
204 |
public void loadFromXML(File file) throws FileNotFoundException, |
|
205 |
UnsupportedEncodingException, MarshalException, |
|
206 |
ValidationException, XMLException { |
|
207 |
|
|
208 |
InputStream inStr = new FileInputStream(file); |
|
209 |
String encoding = XMLEncodingUtils.getEncoding(inStr); |
|
210 |
InputStreamReader reader = new InputStreamReader(inStr, encoding); |
|
211 |
XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
|
212 |
XMLEntity xml = new XMLEntity(tag); |
|
213 |
this.setXMLEntity(xml); |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Get class name |
|
218 |
*/ |
|
219 |
public String getClassName() { |
|
220 |
return this.getClass().getName(); |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* Persist object |
|
225 |
*/ |
|
226 |
public XMLEntity getXMLEntity() throws XMLException { |
|
227 |
XMLEntity xml = new XMLEntity(); |
|
228 |
xml.setName(GeocodingTags.NPATTERN); |
|
229 |
xml.putProperty(GeocodingTags.PATTERNNAME, this._patternname); |
|
230 |
xml.putProperty(GeocodingTags.NOFIRSTROWS, this._nofirstrows); |
|
231 |
Iterator<Element> it = _elements.iterator(); |
|
232 |
while (it.hasNext()) { |
|
233 |
Element el = it.next(); |
|
234 |
xml.addChild(el.getXMLEntity()); |
|
235 |
} |
|
236 |
return xml; |
|
237 |
} |
|
238 |
|
|
239 |
/** |
|
240 |
* Load object |
|
241 |
*/ |
|
242 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
|
243 |
this._patternname = xml.getStringProperty(GeocodingTags.PATTERNNAME); |
|
244 |
this._nofirstrows = xml.getIntProperty(GeocodingTags.NOFIRSTROWS); |
|
245 |
this._elements.clear(); |
|
246 |
int children = xml.getChildrenCount(); |
|
247 |
for (int i = 0; i < children; i++) { |
|
248 |
Element elem = new Element(); |
|
249 |
elem.setXMLEntity(xml.getChild(i)); |
|
250 |
this._elements.add(elem); |
|
251 |
} |
|
252 |
} |
|
253 |
|
|
254 |
} |
trunk/libraries/libGeocoding/src/org/gvsig/normalization/patterns/Fieldtype.java | ||
---|---|---|
35 | 35 |
*/ |
36 | 36 |
|
37 | 37 |
import org.apache.log4j.Logger; |
38 |
import org.gvsig.tools.storage.IStorable;
|
|
39 |
import org.gvsig.tools.storage.IStorage;
|
|
38 |
import org.gvsig.normalization.persistence.GeocodingPersistence;
|
|
39 |
import org.gvsig.normalization.persistence.GeocodingTags;
|
|
40 | 40 |
|
41 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
42 |
import com.iver.utiles.XMLEntity; |
|
43 |
|
|
41 | 44 |
/** |
42 | 45 |
* Class Fieldtype. |
43 | 46 |
* |
44 | 47 |
* This class defines the type of the one new field |
45 | 48 |
*/ |
46 |
public class Fieldtype implements IStorable { |
|
47 |
|
|
48 |
private static final Logger log = Logger |
|
49 |
.getLogger(Fieldtype.class); |
|
49 |
public class Fieldtype implements GeocodingPersistence { |
|
50 | 50 |
|
51 |
private static final Logger log = Logger.getLogger(Fieldtype.class); |
|
52 |
|
|
51 | 53 |
/** |
52 | 54 |
* new field of type String |
53 | 55 |
*/ |
... | ... | |
72 | 74 |
* Constructor |
73 | 75 |
*/ |
74 | 76 |
public Fieldtype() { |
75 |
super(); |
|
76 | 77 |
} |
77 | 78 |
|
78 | 79 |
/** |
79 |
* Returns the value of field 'datevalue'. |
|
80 |
* |
|
81 | 80 |
* @return the value of field 'datevalue'. |
82 | 81 |
*/ |
83 | 82 |
public Datevalue getDatevalue() { |
... | ... | |
85 | 84 |
} |
86 | 85 |
|
87 | 86 |
/** |
88 |
* Returns the value of field 'decimalvalue'. |
|
89 |
* |
|
90 | 87 |
* @return the value of field 'decimalvalue'. |
91 | 88 |
*/ |
92 | 89 |
public Decimalvalue getDecimalvalue() { |
Also available in: Unified diff