Revision 11158

View differences:

trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/GMLProjectionFactory.java
1
package org.gvsig.gpe.gml;
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42
/* CVS MESSAGES:
43
 *
44
 * $Id$
45
 * $Log$
46
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
47
 * Add some writers and the GPEXml parser
48
 *
49
 *
50
 */
51
/**
52
 * This class is used to convert a projection written 
53
 * using the EPSG projection to the GML projection
54
 * format
55
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
56
 */
57
public class GMLProjectionFactory {
58
	
59
	public static String getProjection(String srs){
60
		if (srs != null){
61
			String[] parts = srs.split(":");
62
			if (parts.length == 2){
63
				if (parts[0].compareTo(GMLTags.GML_SRS_EPSG) == 0){
64
					return "http://www.opengis.net/gml/srs/epsg.xml#" + parts[1];
65
				}
66
			}
67
		}		
68
		return null;		
69
	}
70
}
0 71

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/writer/geometries/GeometriesWriter.java
1
package org.gvsig.gpe.gml.writer.geometries;
2

  
3
import java.io.IOException;
4
import java.io.Writer;
5

  
6
import org.gvsig.gpe.gml.GMLProjectionFactory;
7
import org.gvsig.gpe.gml.GMLTags;
8

  
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id$
52
 * $Log$
53
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
54
 * Add some writers and the GPEXml parser
55
 *
56
 *
57
 */
58
/**
59
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
60
 */
61
public class GeometriesWriter {
62
	
63
	public static void startGeometry(Writer writer,String tagName,String id,String srs) throws IOException{
64
		writer.write("<" + GMLTags.GML_NAMESPACE + ":" + tagName);
65
		if (id != null){
66
			writer.write(" " + GMLTags.GML_GEOMETRIES_ID + "='" + id + "'");
67
		}
68
		if (srs != null){
69
			writer.write(" " + GMLTags.GML_SRS_NAME + "='");
70
			writer.write(GMLProjectionFactory.getProjection(srs));
71
			writer.write("'");
72
		}
73
		writer.write("'>");		
74
	}
75
	
76
	public static void endGeometry(Writer writer,String tagName) throws IOException{
77
		writer.write("</" + GMLTags.GML_NAMESPACE + ":" + tagName + ">");
78
	}
79
	
80
}
81

  
0 82

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/writer/geometries/PolygonWriter.java
1
package org.gvsig.gpe.gml.writer.geometries;
2

  
3
import java.io.IOException;
4
import java.io.Writer;
5

  
6
import org.gvsig.gpe.gml.GMLTags;
7

  
8
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *  Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib??ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *      +34 963862235
35
 *   gvsig@gva.es
36
 *      www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   IVER T.I. S.A
41
 *   Salamanca 50
42
 *   46005 Valencia
43
 *   Spain
44
 *
45
 *   +34 963163400
46
 *   dac@iver.es
47
 */
48
/* CVS MESSAGES:
49
 *
50
 * $Id$
51
 * $Log$
52
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
53
 * Add some writers and the GPEXml parser
54
 *
55
 *
56
 */
57
/**
58
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
59
 */
60
public class PolygonWriter {
61
	
62
	public static void start(Writer writer,double[] x, double[] y,
63
			double[] z, String srs, String id) throws IOException{
64
		GeometriesWriter.startGeometry(writer, GMLTags.GML_POLYGON, id, srs);
65
		
66
		CoordinatesWriter.write(writer, x, y, z);			
67
	}
68
	
69
	public static void end(Writer writer) throws IOException{
70
		GeometriesWriter.endGeometry(writer, GMLTags.GML_POLYGON);		
71
	}
72
}
0 73

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/writer/geometries/PointWriter.java
1
package org.gvsig.gpe.gml.writer.geometries;
2

  
3
import java.io.IOException;
4
import java.io.OutputStream;
5
import java.io.Writer;
6

  
7
import org.gvsig.gpe.gml.GMLProjectionFactory;
8
import org.gvsig.gpe.gml.GMLTags;
9

  
10
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
11
 *
12
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
13
 *
14
 * This program is free software; you can redistribute it and/or
15
 * modify it under the terms of the GNU General Public License
16
 * as published by the Free Software Foundation; either version 2
17
 * of the License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU General Public License
25
 * along with this program; if not, write to the Free Software
26
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
27
 *
28
 * For more information, contact:
29
 *
30
 *  Generalitat Valenciana
31
 *   Conselleria d'Infraestructures i Transport
32
 *   Av. Blasco Ib??ez, 50
33
 *   46010 VALENCIA
34
 *   SPAIN
35
 *
36
 *      +34 963862235
37
 *   gvsig@gva.es
38
 *      www.gvsig.gva.es
39
 *
40
 *    or
41
 *
42
 *   IVER T.I. S.A
43
 *   Salamanca 50
44
 *   46005 Valencia
45
 *   Spain
46
 *
47
 *   +34 963163400
48
 *   dac@iver.es
49
 */
50
/* CVS MESSAGES:
51
 *
52
 * $Id$
53
 * $Log$
54
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
55
 * Add some writers and the GPEXml parser
56
 *
57
 *
58
 */
59
/**
60
 * It writes a GML Point label. 
61
 * Example:
62
 * <gml:Point srsName='http://www.opengis.net/gml/srs/epsg.xml#23030'>
63
 * 		<gml:coordinates>x y z</gml:coordinates>
64
 * </gml:Point>
65
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
66
 */
67
public class PointWriter {
68
	
69
	public static void start(Writer writer,double x, double y,
70
			double z, String srs, String id) throws IOException{
71
		GeometriesWriter.startGeometry(writer, GMLTags.GML_POINT, id, srs);
72
		CoordinatesWriter.write(writer, x, y, z);			
73
	}
74
	
75
	public static void end(Writer writer) throws IOException{
76
		GeometriesWriter.endGeometry(writer, GMLTags.GML_POINT);		
77
	}
78
}
0 79

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/writer/geometries/CoordinatesWriter.java
1
package org.gvsig.gpe.gml.writer.geometries;
2

  
3
import java.io.IOException;
4
import java.io.Writer;
5

  
6
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
7
 *
8
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
23
 *
24
 * For more information, contact:
25
 *
26
 *  Generalitat Valenciana
27
 *   Conselleria d'Infraestructures i Transport
28
 *   Av. Blasco Ib??ez, 50
29
 *   46010 VALENCIA
30
 *   SPAIN
31
 *
32
 *      +34 963862235
33
 *   gvsig@gva.es
34
 *      www.gvsig.gva.es
35
 *
36
 *    or
37
 *
38
 *   IVER T.I. S.A
39
 *   Salamanca 50
40
 *   46005 Valencia
41
 *   Spain
42
 *
43
 *   +34 963163400
44
 *   dac@iver.es
45
 */
46
/* CVS MESSAGES:
47
 *
48
 * $Id$
49
 * $Log$
50
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
51
 * Add some writers and the GPEXml parser
52
 *
53
 *
54
 */
55
/**
56
 * It writes a GML Coordinates label. 
57
 * Example:
58
 * <gml:coordinates>x y z</gml:coordinates>
59
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
60
 */
61
public class CoordinatesWriter {
62
	
63
	public static void write(Writer writer,double x, double y,
64
			double z) throws IOException{
65
			writer.write("<gml:coordinates>");
66
		writer.write(new Double(x).toString());
67
		writer.write(" ");
68
		writer.write(new Double(y).toString());
69
		writer.write(" ");
70
		writer.write(new Double(z).toString());
71
		writer.write("</gml:coordinates>");
72
	}
73
	
74
	public static void write(Writer writer,double[] x, double[] y,
75
			double[] z) throws IOException{
76
		writer.write("<gml:coordinates>");
77
		for (int i=0 ; i<x.length ; i++){
78
			write(writer,x[i],y[i],z[i]);
79
			
80
		}
81
		writer.write("</gml:coordinates>");
82
	}
83
}
0 84

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/writer/geometries/LinearRingWriter.java
1
package org.gvsig.gpe.gml.writer.geometries;
2

  
3
import java.io.IOException;
4
import java.io.Writer;
5

  
6
import org.gvsig.gpe.gml.GMLTags;
7

  
8
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *  Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib??ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *      +34 963862235
35
 *   gvsig@gva.es
36
 *      www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   IVER T.I. S.A
41
 *   Salamanca 50
42
 *   46005 Valencia
43
 *   Spain
44
 *
45
 *   +34 963163400
46
 *   dac@iver.es
47
 */
48
/* CVS MESSAGES:
49
 *
50
 * $Id$
51
 * $Log$
52
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
53
 * Add some writers and the GPEXml parser
54
 *
55
 *
56
 */
57
/**
58
 * It writes a GML LinearRing label. 
59
 * Example:
60
 *  <gml:LinearRing srsName='http://www.opengis.net/gml/srs/epsg.xml#23030'>
61
 *    <gml:coordinates>x1,y1,z1
62
 *    					x2,y2,z2
63
 *    					x3,y3,z3
64
 *    					x1,y1,z1
65
 * 	  </gml:coordinates>
66
 * </gml:LinearRing>
67
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
68
 */
69
public class LinearRingWriter {
70
	
71
	public static void start(Writer writer,double[] x, double[] y,
72
			double[] z, String srs, String id) throws IOException{
73
		GeometriesWriter.startGeometry(writer, GMLTags.GML_LINEARRING, id, srs);
74
		CoordinatesWriter.write(writer, x, y, z);		
75
	}
76
	
77
	public static void end(Writer writer) throws IOException{
78
		GeometriesWriter.endGeometry(writer, GMLTags.GML_LINEARRING);
79
	}
80
}
0 81

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/writer/geometries/LineStringWriter.java
1
package org.gvsig.gpe.gml.writer.geometries;
2

  
3
import java.io.IOException;
4
import java.io.Writer;
5

  
6
import org.gvsig.gpe.gml.GMLProjectionFactory;
7
import org.gvsig.gpe.gml.GMLTags;
8

  
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id$
52
 * $Log$
53
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
54
 * Add some writers and the GPEXml parser
55
 *
56
 *
57
 */
58
/**
59
 * It writes a GML LineString label. 
60
 * Example:
61
 *  <gml:LineString srsName='http://www.opengis.net/gml/srs/epsg.xml#23030'>
62
 *    <gml:coordinates>x1,y1,z1
63
 *    					x2,y2,z2
64
 * 	  </gml:coordinates>
65
 * </gml:LineString>
66
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
67
 */
68
public class LineStringWriter {
69
	
70
	public static void write(Writer writer,double[] x, double[] y,
71
			double[] z, String srs, String id) throws IOException{
72
		GeometriesWriter.startGeometry(writer, GMLTags.GML_LINESTRING, id, srs);
73
		CoordinatesWriter.write(writer, x, y, z);		
74
	}
75
	
76
	public static void end(Writer writer) throws IOException{
77
		GeometriesWriter.endGeometry(writer, GMLTags.GML_LINESTRING);	
78
	}
79
}
0 80

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/writer/geometries/OuterBoundaryIsWriter.java
1
package org.gvsig.gpe.gml.writer.geometries;
2

  
3
import java.io.IOException;
4
import java.io.Writer;
5

  
6
import org.gvsig.gpe.gml.GMLTags;
7

  
8
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *  Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib??ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *      +34 963862235
35
 *   gvsig@gva.es
36
 *      www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   IVER T.I. S.A
41
 *   Salamanca 50
42
 *   46005 Valencia
43
 *   Spain
44
 *
45
 *   +34 963163400
46
 *   dac@iver.es
47
 */
48
/* CVS MESSAGES:
49
 *
50
 * $Id$
51
 * $Log$
52
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
53
 * Add some writers and the GPEXml parser
54
 *
55
 *
56
 */
57
/**
58
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
59
 */
60
public class OuterBoundaryIsWriter {
61
	
62
	public static void start(Writer writer,double[] x, double[] y,
63
			double[] z, String srs, String id) throws IOException{
64
		GeometriesWriter.startGeometry(writer, GMLTags.GML_POLYGON, id, srs);
65
		
66
		CoordinatesWriter.write(writer, x, y, z);			
67
	}
68
	
69
	public static void end(Writer writer) throws IOException{
70
		GeometriesWriter.endGeometry(writer, GMLTags.GML_POLYGON);		
71
	}
72
}
0 73

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/writer/GPEGmlWriterHandler.java
1
package org.gvsig.gpe.gml.writer;
2

  
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.FileOutputStream;
6
import java.io.FileWriter;
7
import java.io.IOException;
8
import java.io.OutputStream;
9
import java.io.OutputStreamWriter;
10
import java.io.Writer;
11

  
12
import org.gvsig.gpe.writer.GPEWriterHandler;
13
import org.gvsig.gpe.xml.writer.GPEXmlWriterHandler;
14

  
15
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
16
 *
17
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
18
 *
19
 * This program is free software; you can redistribute it and/or
20
 * modify it under the terms of the GNU General Public License
21
 * as published by the Free Software Foundation; either version 2
22
 * of the License, or (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU General Public License
30
 * along with this program; if not, write to the Free Software
31
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
32
 *
33
 * For more information, contact:
34
 *
35
 *  Generalitat Valenciana
36
 *   Conselleria d'Infraestructures i Transport
37
 *   Av. Blasco Ib??ez, 50
38
 *   46010 VALENCIA
39
 *   SPAIN
40
 *
41
 *      +34 963862235
42
 *   gvsig@gva.es
43
 *      www.gvsig.gva.es
44
 *
45
 *    or
46
 *
47
 *   IVER T.I. S.A
48
 *   Salamanca 50
49
 *   46005 Valencia
50
 *   Spain
51
 *
52
 *   +34 963163400
53
 *   dac@iver.es
54
 */
55
/* CVS MESSAGES:
56
 *
57
 * $Id$
58
 * $Log$
59
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
60
 * Add some writers and the GPEXml parser
61
 *
62
 *
63
 */
64
/**
65
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
66
 */
67
public class GPEGmlWriterHandler extends GPEXmlWriterHandler{
68

  
69
	public GPEGmlWriterHandler(String format, File file) throws IOException {
70
		super(format, file);		
71
	}
72

  
73
	/*
74
	 * (non-Javadoc)
75
	 * @see org.gvsig.gpe.xml.writer.GPEXmlWriterHandler#createOutputStream()
76
	 */
77
	protected Writer createWriter() throws IOException {
78
		return new FileWriter(getFile());
79
	}
80

  
81
}
0 82

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/GMLTags.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.1  2007-02-28 11:48:31  csanchez
46
 * Revision 1.2  2007-04-12 10:23:41  jorpiell
47
 * Add some writers and the GPEXml parser
48
 *
49
 * Revision 1.1  2007/02/28 11:48:31  csanchez
47 50
 * *** empty log message ***
48 51
 *
49 52
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
......
72 75
 * 
73 76
 */
74 77
public class GMLTags {
78
	public static final String GML_NAMESPACE_URI = "http://www.opengis.net/gml";	
75 79
	public static final String VERSION = "version";
76 80
	public static final String XML_TARGET_NAMESPACE = "targetNamespace";
77 81
	public static final String XML_ELEMENT_FORM_DEFAULT = "elementFormDefault";
......
90 94
	public static final String GML_COORDINATES_CS = "cs";
91 95
	public static final String GML_COORDINATES_TS = "ts";
92 96
	public static final String GML_SRS_NAME = "srsName";
97
	public static final String GML_SRS_EPSG = "EPSG";
98
	public static final String GML_GEOMETRIES_ID = "gid";
99
	public static final String GML_NAMESPACE = "gml";
93 100
	
94
	//GML types
101
	//Geometries
95 102
	public static final String GML_POINT = "Point";
96
	public static final String GML_MUNTILINE = "MultiLineString";
103
	public static final String GML_LINESTRING = "LineString";
104
	public static final String GML_LINEARRING = "LinearRing";
105
	public static final String GML_POLYGON = "Polygon";
106
	
107
	public static final String GML_POLYGON = "outerBo";
97 108
}
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/xml/writer/GPEXmlWriterHandler.java
1
package org.gvsig.gpe.xml.writer;
2

  
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.FileWriter;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.io.OutputStream;
9
import java.io.Writer;
10

  
11
import org.gvsig.gpe.writer.GPEWriterHandler;
12

  
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id$
56
 * $Log$
57
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
58
 * Add some writers and the GPEXml parser
59
 *
60
 *
61
 */
62
/**
63
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
64
 */
65
public abstract class GPEXmlWriterHandler extends GPEWriterHandler {
66
	private Writer writer = null;
67
	
68
	public GPEXmlWriterHandler(String format, File file) throws IOException {
69
		super(format, file);
70
		writer = createWriter();
71
	}
72
 
73
	/**
74
	 * Creates an input stream from a file. 
75
	 * @param file
76
	 * @return
77
	 * @throws FileNotFoundException 
78
	 * @throws FileNotFoundException 
79
	 */
80
	protected abstract Writer createWriter() throws IOException;
81
	
82
	/**
83
	 * @return the outputStream
84
	 */
85
	protected Writer getWriter() {
86
		return writer;
87
	}
88
	
89
}
0 90

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/xml/GPEXmlParserFactory.java
1
package org.gvsig.gpe.xml;
2

  
3
import java.lang.reflect.InvocationTargetException;
4

  
5
import org.gvsig.gpe.GPEParser;
6
import org.kxml2.io.KXmlParser;
7
import org.xmlpull.v1.XmlPullParser;
8

  
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id$
52
 * $Log$
53
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
54
 * Add some writers and the GPEXml parser
55
 *
56
 *
57
 */
58
/**
59
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
60
 */
61
public class GPEXmlParserFactory {
62
	private static String className = null;
63
	
64
	/**
65
	 * @return the parser
66
	 * @throws NoSuchMethodException 
67
	 * @throws InvocationTargetException 
68
	 * @throws IllegalAccessException 
69
	 * @throws InstantiationException 
70
	 * @throws SecurityException 
71
	 * @throws IllegalArgumentException 
72
	 * @throws ClassNotFoundException 
73
	 */
74
	public static XmlPullParser getParser() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
75
		if (className==null){
76
			className = "org.kxml2.io.KXmlParse";
77
		}
78
		Class clazz = Class.forName(className);
79
		if (clazz != null){
80
			return (XmlPullParser)clazz.getConstructor(null).newInstance(null);
81
		}
82
		return null;
83
	}
84

  
85
	/**
86
	 * @param parser the parser to set
87
	 */
88
	public static void registerParser(String className) {
89
		GPEXmlParserFactory.className = className;
90
	}
91
	
92
	
93
}
0 94

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/xml/header/bindings/HeaderBinding.java
1
package org.gvsig.gpe.xml.header.bindings;
2

  
3
import java.io.IOException;
4
import java.util.StringTokenizer;
5

  
6
import org.apache.xml.utils.NameSpace;
7
import org.gvsig.gpe.gml.GMLTags;
8
import org.gvsig.gpe.xml.header.impl.Header;
9
import org.xmlpull.v1.XmlPullParser;
10
import org.xmlpull.v1.XmlPullParserException;
11

  
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52
/* CVS MESSAGES:
53
 *
54
 * $Id$
55
 * $Log$
56
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
57
 * Add some writers and the GPEXml parser
58
 *
59
 *
60
 */
61
/**
62
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
63
 */
64
public class HeaderBinding {
65
		
66
	public Object parse(XmlPullParser parser,NameSpace namespace) throws XmlPullParserException, IOException {
67
		Header header = new Header();
68
		for (int i=0 ; i<parser.getAttributeCount() ; i++){
69
			//getting attributes and values
70
			String attName = parser.getAttributeName(i);
71
			String attValue = parser.getAttributeValue(i);
72
			//it splits the attributes names at the both sides from ":"
73
			String[] ns = attName.split(":");
74
			
75
			/********************************
76
			 * Attributte <targetNamespace>	*
77
			 ********************************/
78
			//Target Namespace (URI)
79
			//this is the namespace of all components in the schema
80
			//setTargetNamespace(); 
81
			if (attName.compareTo(GMLTags.XML_TARGET_NAMESPACE)==0){
82
				header.setTargetNamespace(attValue);
83
			}
84
			
85
			/********************************
86
			 * Attributte <xmlns:namespace>	*
87
			 ********************************/
88
			if ((ns.length>1) && (ns[0].compareTo(GMLTags.XML_NAMESPACE)==0)){
89
//				NamespacesFactory.addNamespace(ns[1],attValue);
90
			}
91
			
92
			/****************************************
93
			 * Attributte <namespace:schemaLocation>*
94
			 ****************************************/
95
			if ((ns.length>1) && (ns[1].compareTo(GMLTags.XML_SCHEMA_LOCATION)==0)){
96
				parseSchemaLocation(attValue);
97
			}			
98
			
99
			/************************************
100
			 * Attributte <elementFormDefault>	*
101
			 ************************************/
102
			//Qualified--> Los elementos del espacio de nombres de destino deben cualificarse 
103
			//con el prefijo del espacio de nombres.
104
			//Unqualified--> No es necesario que los elementos del 
105
			//espacio de nombres de destino est?n cualificados con el prefijo del espacio de nombres.
106
			//(Espacion_de_Nombres:Elemento)
107
			//elementFormDefault(); 
108
			if (attName.compareTo(GMLTags.XML_ELEMENT_FORM_DEFAULT)==0){
109
			}
110
			
111
			/************************************
112
			 * Attributte <attributeFormDefault>	*
113
			 ************************************/
114
			//Lo mismo que el anterior pero con los atributos...
115
			//(Espacio_de_Nombres:Atributo)
116
			//attributeFormDefault();
117
			if (attName.compareTo(GMLTags.XML_ATTRIBUTE_FORM_DEFAULT)==0){
118
			}
119
			
120
			/************************
121
			 * Attributte <Version>	*
122
			 ************************/
123
			//Gets gml version to parse by the right parser.
124
			//getversion();
125
			if (attName.compareTo(GMLTags.VERSION)==0){
126
				header.setVersion(attValue);
127
			}
128
		}
129
		return header;
130
	}
131
	
132
	/**
133
	 * Parses the schema location attribute
134
	 * XML attribute that contains the schema location info
135
	 * 
136
	 * @param schemas
137
	 **/
138
	public void parseSchemaLocation(String schemas){
139
		// It take the name of the schemas file to open or downlad 
140
		StringTokenizer tokenizer = new StringTokenizer(schemas, " \t");
141
        while (tokenizer.hasMoreTokens()){
142
            String URI = tokenizer.nextToken();
143
            if (!tokenizer.hasMoreTokens()){
144
            	//If it hasn't the name of the schemas file or dont find it,
145
            	//it exits, and tries to parse without schema
146
            	//warnings.setElement(new GMLWarningNotFound(null,null));
147
            }else{
148
            	String schema = tokenizer.nextToken();
149
//               	try {
150
//					//SchemasParser.parseSchema(schema);
151
//				} catch (XmlPullParserException e) {
152
//					// TODO Auto-generated catch block
153
//					e.printStackTrace();
154
//				} catch (IOException e) {
155
//					// TODO Auto-generated catch block
156
//					e.printStackTrace();
157
//				}			
158
            }
159
        }
160
	}	
161
}
0 162

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/xml/header/impl/Header.java
1
package org.gvsig.gpe.xml.header.impl;
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42
/* CVS MESSAGES:
43
 *
44
 * $Id$
45
 * $Log$
46
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
47
 * Add some writers and the GPEXml parser
48
 *
49
 *
50
 */
51
/**
52
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
53
 */
54
public class Header {
55
	private String version = null;
56
	private String targetNamespace = null;
57
	
58
	/**
59
	 * @return the targetNamespace
60
	 */
61
	public String getTargetNamespace() {
62
		return targetNamespace;
63
	}
64
	
65
	/**
66
	 * @param targetNamespace the targetNamespace to set
67
	 */
68
	public void setTargetNamespace(String targetNamespace) {
69
		this.targetNamespace = targetNamespace;
70
	}
71
	
72
	/**
73
	 * @return the version
74
	 */
75
	public String getVersion() {
76
		return version;
77
	}
78
	
79
	/**
80
	 * @param version the version to set
81
	 */
82
	public void setVersion(String version) {
83
		this.version = version;
84
	}
85
	
86
	
87
}
0 88

  
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/xml/GPEXmlParser.java
1
package org.gvsig.gpe.xml;
2

  
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.IOException;
6
import java.io.InputStream;
7

  
8
import org.gvsig.gpe.GPEContentHandler;
9
import org.gvsig.gpe.GPEErrorHandler;
10
import org.gvsig.gpe.GPEParser;
11
import org.xmlpull.v1.XmlPullParser;
12

  
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id$
56
 * $Log$
57
 * Revision 1.1  2007-04-12 10:23:41  jorpiell
58
 * Add some writers and the GPEXml parser
59
 *
60
 *
61
 */
62
/**
63
 * This class can be implemented by all the classes that 
64
 * implements a GPE driver based on the XML format.
65
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
66
 */
67
public abstract class GPEXmlParser extends GPEParser {
68
	private InputStream inputStream = null;
69
	
70
	public GPEXmlParser(GPEContentHandler contents, GPEErrorHandler errors) {
71
		super(contents, errors);		
72
	}
73
	
74
	/*
75
	 * (non-Javadoc)
76
	 * @see org.gvsig.gpe.GPEParser#parse(java.io.File)
77
	 */
78
	public void parse(File file) throws Exception{
79
		inputStream = createInputStream(file);
80
		XmlPullParser parser = GPEXmlParserFactory.getParser();
81
		parser.setInput(getInputStream(), getEncoding());
82
		initParse();
83
	}
84
	
85
	/**
86
	 * Creates an input stream from a file. 
87
	 * @param file
88
	 * @return
89
	 * @throws FileNotFoundException 
90
	 */
91
	protected abstract InputStream createInputStream(File file) throws FileNotFoundException;
92
	
93
	/**
94
	 * This method start the parse process. It is called
95
	 * before the XML parser is initialized
96
	 */
97
	protected abstract void initParse();
98
	
99
	/**
100
	 * @return Returns the encoding.
101
	 * @throws IOException 
102
	 * @throws KmlException 
103
	 */
104
	private String getEncoding() throws IOException {
105
		String encoding = "UTF-8";
106
		InputStream is = getInputStream();		
107
		int index = -1;
108
		int endIndex = -1;
109
		String header = "";
110
		boolean endHeader = false;
111

  
112
		int i = 1;
113
		while((!endHeader) && (i < 100)){
114
			byte[] buffer = new byte[1];
115
			is.read(buffer);
116
			header = header + new String(buffer);
117
			//This if is to locate the encoding string
118
			if (index == -1) { 
119
				String searchText = "encoding=\"";
120
				index = header.indexOf(searchText);
121
				if (index > -1){
122
					header = "";
123
				}
124
			}
125
			//This if is to locate the encoding value
126
			if (index > -1){
127
				String searchText = "\"";
128
				endIndex = header.indexOf(searchText);
129
				if (endIndex > -1){
130
					encoding = header.substring(0, endIndex);
131
				}
132
			}
133
			//To finish to parse the header
134
			if (endIndex > -1){
135
				String searchText = ">";
136
				int headerEndIndex = header.indexOf(searchText);
137
				if (headerEndIndex > -1){
138
					endHeader = true;
139
				}
140
			}
141
			i++;
142
		}				
143
		return encoding;
144
	}
145

  
146
	/**
147
	 * @return the inputStream
148
	 */
149
	private InputStream getInputStream() {
150
		return inputStream;
151
	}	
152

  
153
}
0 154

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff