Revision 9917
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/GMLException.java | ||
---|---|---|
1 |
package org.gvsig.remoteClient.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 2006-08-10 12:00:49 jorpiell |
|
47 |
* Primer commit del driver de Gml |
|
48 |
* |
|
49 |
* |
|
50 |
*/ |
|
51 |
/** |
|
52 |
* GML Exception. |
|
53 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
54 |
*/ |
|
55 |
public class GMLException extends Exception { |
|
56 |
public static final int EXC_NO_SCHEMA = 0; |
|
57 |
public static final int EXC_ATTRIB_WITH_INVALID_FORMAT = 1; |
|
58 |
public static final int EXC_PARSE = 2; |
|
59 |
public static final int EXC_READ_FILE = 3; |
|
60 |
public static final int EXC_NO_GEOMETRY = 4; |
|
61 |
|
|
62 |
|
|
63 |
private int exceptionType; |
|
64 |
|
|
65 |
public GMLException(int exceptionType) { |
|
66 |
super(); |
|
67 |
this.exceptionType = exceptionType; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* @return Returns the exceptionType. |
|
72 |
*/ |
|
73 |
public int getExceptionType() { |
|
74 |
return exceptionType; |
|
75 |
} |
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
} |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/XMLComplexType.java | ||
---|---|---|
1 |
package org.gvsig.remoteClient.gml.schemas; |
|
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
import java.util.LinkedHashMap; |
|
5 |
import java.util.Map; |
|
6 |
import java.util.Set; |
|
7 |
import java.util.Vector; |
|
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.2.2.3 2006-11-17 11:38:03 ppiqueras |
|
54 |
* Corregidos bugs y añadida nueva funcionalidad. Del HEAD. |
|
55 |
* |
|
56 |
* Revision 1.7 2006/10/31 13:52:37 ppiqueras |
|
57 |
* Mejoras para uso de features complejas |
|
58 |
* |
|
59 |
* Revision 1.6 2006/10/31 12:24:33 jorpiell |
|
60 |
* En caso de que el elemento forme parte de un tipo complejo tiene que tener un enlace al tipo del objeto padre |
|
61 |
* |
|
62 |
* Revision 1.5 2006/10/10 12:52:28 jorpiell |
|
63 |
* Soporte para features complejas. |
|
64 |
* |
|
65 |
* Revision 1.4 2006/10/02 08:33:49 jorpiell |
|
66 |
* Cambios del 10 copiados al head |
|
67 |
* |
|
68 |
* Revision 1.2.2.1 2006/09/19 12:23:15 jorpiell |
|
69 |
* Ya no se depende de geotools |
|
70 |
* |
|
71 |
* Revision 1.3 2006/09/18 12:08:55 jorpiell |
|
72 |
* Se han hecho algunas modificaciones que necesitaba el WFS |
|
73 |
* |
|
74 |
* Revision 1.2 2006/08/29 08:43:13 jorpiell |
|
75 |
* Dos peque?os cambios para tener en cuenta las referencias |
|
76 |
* |
|
77 |
* Revision 1.1 2006/08/10 12:00:49 jorpiell |
|
78 |
* Primer commit del driver de Gml |
|
79 |
* |
|
80 |
* |
|
81 |
*/ |
|
82 |
/** |
|
83 |
* This class implements an XSD complex type |
|
84 |
* |
|
85 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
86 |
*/ |
|
87 |
public class XMLComplexType implements IXMLType { |
|
88 |
private String type = null; |
|
89 |
private LinkedHashMap attributes = null; |
|
90 |
|
|
91 |
public XMLComplexType(String type) { |
|
92 |
super(); |
|
93 |
this.type = type; |
|
94 |
attributes = new LinkedHashMap(); |
|
95 |
} |
|
96 |
|
|
97 |
/* |
|
98 |
* (non-Javadoc) |
|
99 |
* @see org.gvsig.remoteClient.gml.schemas.IXMLType#getType() |
|
100 |
*/ |
|
101 |
public int getType() { |
|
102 |
return IXMLType.COMPLEX; |
|
103 |
} |
|
104 |
|
|
105 |
/* |
|
106 |
* (non-Javadoc) |
|
107 |
* @see org.gvsig.remoteClient.gml.schemas.IXMLType#getName() |
|
108 |
*/ |
|
109 |
public String getName() { |
|
110 |
return type; |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* @return Returns the subtypes. |
|
115 |
*/ |
|
116 |
public Map getSubtypes() { |
|
117 |
return attributes; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* @param subtypes The subtypes to set. |
|
122 |
*/ |
|
123 |
public void addSubtypes(XMLElement element) { |
|
124 |
if (element.getName() != null){ |
|
125 |
this.attributes.put(element.getName(),element); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* |
|
131 |
* @param name |
|
132 |
* @return |
|
133 |
*/ |
|
134 |
public XMLElement getAttribute(String name){ |
|
135 |
return (XMLElement)attributes.get(name); |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* @return Returns the vElements. |
|
140 |
*/ |
|
141 |
public Vector getAttributes() { |
|
142 |
Set keys = attributes.keySet(); |
|
143 |
Iterator it = keys.iterator(); |
|
144 |
Vector vector = new Vector(); |
|
145 |
while(it.hasNext()){ |
|
146 |
vector.add(attributes.get((String)it.next())); |
|
147 |
} |
|
148 |
return vector; |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
} |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/IXMLType.java | ||
---|---|---|
1 |
package org.gvsig.remoteClient.gml.schemas; |
|
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 2006-08-10 12:00:49 jorpiell |
|
47 |
* Primer commit del driver de Gml |
|
48 |
* |
|
49 |
* |
|
50 |
*/ |
|
51 |
/** |
|
52 |
* It represent an object type. All the simple and complex |
|
53 |
* XML types and the GML geometry types must be implement |
|
54 |
* this nterface |
|
55 |
* |
|
56 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
57 |
*/ |
|
58 |
public interface IXMLType { |
|
59 |
public static final int UNDEFINED = 0; |
|
60 |
public static final int COMPLEX = 1; |
|
61 |
public static final int SIMPLE = 2; |
|
62 |
public static final int GML_GEOMETRY = 3; |
|
63 |
|
|
64 |
/** |
|
65 |
* Gets the object type |
|
66 |
* @return |
|
67 |
*/ |
|
68 |
public int getType(); |
|
69 |
|
|
70 |
/** |
|
71 |
* Gets the object name |
|
72 |
* @return |
|
73 |
*/ |
|
74 |
public String getName(); |
|
75 |
|
|
76 |
|
|
77 |
} |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/XMLSimpleType.java | ||
---|---|---|
1 |
package org.gvsig.remoteClient.gml.schemas; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.remoteClient.gml.GMLException; |
|
6 |
import org.gvsig.remoteClient.utils.CapabilitiesTags; |
|
7 |
import org.kxml2.io.KXmlParser; |
|
8 |
import org.xmlpull.v1.XmlPullParserException; |
|
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.2.5 2006-11-27 11:11:03 jorpiell |
|
55 |
* A?adido el INT y el LONG como tipo num?rico |
|
56 |
* |
|
57 |
* Revision 1.1.2.4 2006/11/17 11:38:03 ppiqueras |
|
58 |
* Corregidos bugs y añadida nueva funcionalidad. Del HEAD. |
|
59 |
* |
|
60 |
* Revision 1.5 2006/10/11 11:21:00 jorpiell |
|
61 |
* Se escriben los tipos correctamente (no en mayusculas) para que las traducciones funcionen |
|
62 |
* |
|
63 |
* Revision 1.4 2006/10/10 12:52:28 jorpiell |
|
64 |
* Soporte para features complejas. |
|
65 |
* |
|
66 |
* Revision 1.3 2006/10/02 08:33:49 jorpiell |
|
67 |
* Cambios del 10 copiados al head |
|
68 |
* |
|
69 |
* Revision 1.1.2.1 2006/09/19 12:23:15 jorpiell |
|
70 |
* Ya no se depende de geotools |
|
71 |
* |
|
72 |
* Revision 1.2 2006/09/18 12:08:55 jorpiell |
|
73 |
* Se han hecho algunas modificaciones que necesitaba el WFS |
|
74 |
* |
|
75 |
* Revision 1.1 2006/08/10 12:00:49 jorpiell |
|
76 |
* Primer commit del driver de Gml |
|
77 |
* |
|
78 |
* |
|
79 |
*/ |
|
80 |
/** |
|
81 |
* A XS simple data type. |
|
82 |
* |
|
83 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
84 |
*/ |
|
85 |
public class XMLSimpleType implements IXMLType{ |
|
86 |
public static final String STRING = "xs:string"; |
|
87 |
public static final String INTEGER = "xs:integer"; |
|
88 |
public static final String DOUBLE = "xs:double"; |
|
89 |
public static final String FLOAT = "xs:float"; |
|
90 |
public static final String BOOLEAN = "xs:boolean"; |
|
91 |
public static final String LONG = "xs:long"; |
|
92 |
public static final String INT = "xs:int"; |
|
93 |
|
|
94 |
private String type = null; |
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
public XMLSimpleType(String type) { |
|
99 |
super(); |
|
100 |
this.type = type; |
|
101 |
} |
|
102 |
|
|
103 |
/* |
|
104 |
* (non-Javadoc) |
|
105 |
* @see org.gvsig.remoteClient.gml.IXMLType#getName() |
|
106 |
*/ |
|
107 |
public String getName() { |
|
108 |
return type; |
|
109 |
} |
|
110 |
|
|
111 |
/* |
|
112 |
* (non-Javadoc) |
|
113 |
* @see org.gvsig.remoteClient.gml.IXMLType#getType() |
|
114 |
*/ |
|
115 |
public int getType() { |
|
116 |
return IXMLType.SIMPLE; |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* @param type The type to set. |
|
121 |
*/ |
|
122 |
public void setType(String type) { |
|
123 |
this.type = type; |
|
124 |
} |
|
125 |
|
|
126 |
public Object getObject(String value)throws GMLException{ |
|
127 |
try{ |
|
128 |
if (type.equals(STRING)){ |
|
129 |
return value; |
|
130 |
}else if (type.equals(INTEGER)){ |
|
131 |
return new Integer(value); |
|
132 |
}else if (type.equals(INT)){ |
|
133 |
return new Integer(value); |
|
134 |
}else if (type.equals(DOUBLE)){ |
|
135 |
return new Double(value); |
|
136 |
}else if (type.equals(FLOAT)){ |
|
137 |
return new Float(value); |
|
138 |
}else if (type.equals(BOOLEAN)){ |
|
139 |
return new Boolean(value); |
|
140 |
}else if (type.equals(LONG)){ |
|
141 |
return new Long(value); |
|
142 |
} |
|
143 |
}catch (Exception e){ |
|
144 |
throw new GMLException(GMLException.EXC_ATTRIB_WITH_INVALID_FORMAT); |
|
145 |
} |
|
146 |
return value; |
|
147 |
} |
|
148 |
|
|
149 |
|
|
150 |
} |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/GMLGeometryType.java | ||
---|---|---|
1 |
package org.gvsig.remoteClient.gml.schemas; |
|
2 |
|
|
3 |
|
|
4 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id$ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.1.2.3 2006-11-27 11:10:32 jorpiell |
|
49 |
* A?adido el Poligono como tipo |
|
50 |
* |
|
51 |
* Revision 1.1.2.2 2006/11/17 11:38:03 ppiqueras |
|
52 |
* Corregidos bugs y añadida nueva funcionalidad. Del HEAD. |
|
53 |
* |
|
54 |
* Revision 1.2 2006/10/11 11:21:00 jorpiell |
|
55 |
* Se escriben los tipos correctamente (no en mayusculas) para que las traducciones funcionen |
|
56 |
* |
|
57 |
* Revision 1.1 2006/08/10 12:00:49 jorpiell |
|
58 |
* Primer commit del driver de Gml |
|
59 |
* |
|
60 |
* |
|
61 |
*/ |
|
62 |
/** |
|
63 |
* All the GML geometries must be here |
|
64 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
65 |
*/ |
|
66 |
public class GMLGeometryType implements IXMLType { |
|
67 |
private String type = null; |
|
68 |
|
|
69 |
public static final String POINT = "gml:PointPropertyType"; |
|
70 |
public static final String LINE = "gml:MultiLineStringPropertyType"; |
|
71 |
public static final String MULTIPOINT = "gml:MultiPointPropertyType"; |
|
72 |
public static final String MULTIPOLYGON = "gml:MultiPolygonPropertyType"; |
|
73 |
public static final String GEOMETRY = "gml:GeometryPropertyType"; |
|
74 |
public static final String POLYGON = "gml:PolygonPropertyType"; |
|
75 |
|
|
76 |
public GMLGeometryType(String type) { |
|
77 |
super(); |
|
78 |
this.type = type; |
|
79 |
} |
|
80 |
|
|
81 |
/* |
|
82 |
* (non-Javadoc) |
|
83 |
* @see org.gvsig.remoteClient.gml.model.IXMLType#getType() |
|
84 |
*/ |
|
85 |
public int getType() { |
|
86 |
return IXMLType.GML_GEOMETRY; |
|
87 |
} |
|
88 |
|
|
89 |
/* |
|
90 |
* (non-Javadoc) |
|
91 |
* @see org.gvsig.remoteClient.gml.model.IXMLType#getName() |
|
92 |
*/ |
|
93 |
public String getName() { |
|
94 |
return type; |
|
95 |
} |
|
96 |
|
|
97 |
|
|
98 |
} |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/XMLSchemasManager.java | ||
---|---|---|
1 |
package org.gvsig.remoteClient.gml.schemas; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
import java.io.File; |
|
5 |
import java.io.IOException; |
|
6 |
import java.net.ConnectException; |
|
7 |
import java.net.MalformedURLException; |
|
8 |
import java.net.URL; |
|
9 |
import java.net.UnknownHostException; |
|
10 |
import java.util.Hashtable; |
|
11 |
import java.util.StringTokenizer; |
|
12 |
|
|
13 |
import org.gvsig.remoteClient.gml.GMLException; |
|
14 |
import org.gvsig.remoteClient.gml.GMLTags; |
|
15 |
import org.gvsig.remoteClient.gml.factories.XMLSchemasFactory; |
|
16 |
import org.gvsig.remoteClient.utils.Utilities; |
|
17 |
import org.kxml2.io.KXmlParser; |
|
18 |
import org.xmlpull.v1.XmlPullParserException; |
|
19 |
|
|
20 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
21 |
* |
|
22 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
23 |
* |
|
24 |
* This program is free software; you can redistribute it and/or |
|
25 |
* modify it under the terms of the GNU General Public License |
|
26 |
* as published by the Free Software Foundation; either version 2 |
|
27 |
* of the License, or (at your option) any later version. |
|
28 |
* |
|
29 |
* This program is distributed in the hope that it will be useful, |
|
30 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
31 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
32 |
* GNU General Public License for more details. |
|
33 |
* |
|
34 |
* You should have received a copy of the GNU General Public License |
|
35 |
* along with this program; if not, write to the Free Software |
|
36 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
37 |
* |
|
38 |
* For more information, contact: |
|
39 |
* |
|
40 |
* Generalitat Valenciana |
|
41 |
* Conselleria d'Infraestructures i Transport |
|
42 |
* Av. Blasco Ib��ez, 50 |
|
43 |
* 46010 VALENCIA |
|
44 |
* SPAIN |
|
45 |
* |
|
46 |
* +34 963862235 |
|
47 |
* gvsig@gva.es |
|
48 |
* www.gvsig.gva.es |
|
49 |
* |
|
50 |
* or |
|
51 |
* |
|
52 |
* IVER T.I. S.A |
|
53 |
* Salamanca 50 |
|
54 |
* 46005 Valencia |
|
55 |
* Spain |
|
56 |
* |
|
57 |
* +34 963163400 |
|
58 |
* dac@iver.es |
|
59 |
*/ |
|
60 |
/* CVS MESSAGES: |
|
61 |
* |
|
62 |
* $Id$ |
|
63 |
* $Log$ |
|
64 |
* Revision 1.2 2006-08-30 10:47:36 jorpiell |
|
65 |
* Añadido un File.separator en lugar de unas barras que impedia que funcioanra en linux |
|
66 |
* |
|
67 |
* Revision 1.1 2006/08/10 12:00:49 jorpiell |
|
68 |
* Primer commit del driver de Gml |
|
69 |
* |
|
70 |
* |
|
71 |
*/ |
|
72 |
/** |
|
73 |
* This class represents a GML file header. It has |
|
74 |
* methods to parses the GML file header and retrieve |
|
75 |
* the namespaces and the attributes. If there is an schema |
|
76 |
* on the GML file, it has to manage it. It has to retrieve |
|
77 |
* the GML file version |
|
78 |
* |
|
79 |
* @author Jorge Piera Llodr� (piera_jor@gva.es) |
|
80 |
*/ |
|
81 |
public class XMLSchemasManager { |
|
82 |
private String version = null; |
|
83 |
private File file = null; |
|
84 |
private String targetNameSpace = null; |
|
85 |
|
|
86 |
public XMLSchemasManager(File file) { |
|
87 |
super(); |
|
88 |
this.file = file; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* It parses the GML header and returns the attributes |
|
93 |
* @param parser |
|
94 |
* Reader for the GML file |
|
95 |
* @throws IOException |
|
96 |
* @throws XmlPullParserException |
|
97 |
* @throws GMLException |
|
98 |
*/ |
|
99 |
public void parse(XMLSchemaParser parser) throws XmlPullParserException, IOException, GMLException{ |
|
100 |
parser.nextTag(); |
|
101 |
|
|
102 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
|
103 |
String attName = parser.getAttributeName(i); |
|
104 |
String attValue = parser.getAttributeValue(i); |
|
105 |
if (attName.compareTo(GMLTags.VERSION)==0){ |
|
106 |
version = attValue; |
|
107 |
break; |
|
108 |
} |
|
109 |
if (attName.compareTo(GMLTags.XML_TARGET_NAMESPACE)==0){ |
|
110 |
targetNameSpace = attValue; |
|
111 |
break; |
|
112 |
} |
|
113 |
String[] ns = attName.split(":"); |
|
114 |
if ((ns.length>1) && (ns[0].compareTo(GMLTags.XML_NAMESPACE)==0)){ |
|
115 |
parseNameSpace(ns[1],attValue); |
|
116 |
} |
|
117 |
if ((ns.length>1) && (ns[1].compareTo(GMLTags.XML_SCHEMA_LOCATION)==0)){ |
|
118 |
parseSchemaLocation(ns[0],attValue); |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* It parses an XML namespace tag |
|
126 |
* @param sNameSPace |
|
127 |
*/ |
|
128 |
private void parseNameSpace(String xmlnsName,String xmlnsValue){ |
|
129 |
XMLSchemasFactory.addType(xmlnsName,xmlnsValue); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Parses the schema location attribute |
|
134 |
* @param schemas |
|
135 |
* XML attribute than contain the schema location info |
|
136 |
* @throws GMLException |
|
137 |
*/ |
|
138 |
private void parseSchemaLocation(String namespace,String schemas) throws GMLException{ |
|
139 |
StringTokenizer tokenizer = new StringTokenizer(schemas, " \t"); |
|
140 |
while (tokenizer.hasMoreTokens()){ |
|
141 |
String parent = tokenizer.nextToken(); |
|
142 |
if (!tokenizer.hasMoreTokens()){ |
|
143 |
throw new GMLException(GMLException.EXC_NO_SCHEMA); |
|
144 |
} |
|
145 |
String schema = tokenizer.nextToken(); |
|
146 |
String name = XMLSchemasFactory.addSchemaLocation(namespace,parent,schema); |
|
147 |
parseSchema(schema,name); |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* It Downloads the schemas and parses them |
|
153 |
* @param urlString |
|
154 |
* Schema to parse |
|
155 |
* @return |
|
156 |
*/ |
|
157 |
private void parseSchema(String urlString,String nameSpace){ |
|
158 |
if (urlString.indexOf("http://") != 0){ |
|
159 |
File f = new File(urlString); |
|
160 |
if (!(f.isAbsolute())){ |
|
161 |
urlString = file.getParentFile().getAbsolutePath() + File.separator + urlString; |
|
162 |
f = new File(urlString); |
|
163 |
} |
|
164 |
new XMLSchemaParser().parse(f,nameSpace); |
|
165 |
}else{ |
|
166 |
URL url; |
|
167 |
try { |
|
168 |
url = new URL(urlString); |
|
169 |
File f = Utilities.downloadFile(url,"gml_schmema.xsd", null); |
|
170 |
if (f == null){ |
|
171 |
return; |
|
172 |
}else{ |
|
173 |
new XMLSchemaParser().parse(f,nameSpace); |
|
174 |
} |
|
175 |
}catch (MalformedURLException e1) { |
|
176 |
// TODO Auto-generated catch block |
|
177 |
e1.printStackTrace(); |
|
178 |
} catch (ConnectException e) { |
|
179 |
// TODO Auto-generated catch block |
|
180 |
e.printStackTrace(); |
|
181 |
} catch (UnknownHostException e) { |
|
182 |
// TODO Auto-generated catch block |
|
183 |
e.printStackTrace(); |
|
184 |
} catch (IOException e) { |
|
185 |
// TODO Auto-generated catch block |
|
186 |
e.printStackTrace(); |
|
187 |
} |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* @return Returns the targetNameSpace. |
|
193 |
*/ |
|
194 |
public String getTargetNameSpace() { |
|
195 |
return targetNameSpace; |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* @return Returns the version. |
|
200 |
* TODO: Manage the different versions |
|
201 |
*/ |
|
202 |
public String getVersion() { |
|
203 |
if (version == null){ |
|
204 |
return "2.1.2"; |
|
205 |
} |
|
206 |
return version; |
|
207 |
} |
|
208 |
|
|
209 |
} |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/XMLSchema.java | ||
---|---|---|
1 |
package org.gvsig.remoteClient.gml.schemas; |
|
2 |
|
|
3 |
import java.util.Vector; |
|
4 |
|
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
6 |
* |
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 |
|
12 |
* of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
22 |
* |
|
23 |
* For more information, contact: |
|
24 |
* |
|
25 |
* Generalitat Valenciana |
|
26 |
* Conselleria d'Infraestructures i Transport |
|
27 |
* Av. Blasco Ib??ez, 50 |
|
28 |
* 46010 VALENCIA |
|
29 |
* SPAIN |
|
30 |
* |
|
31 |
* +34 963862235 |
|
32 |
* gvsig@gva.es |
|
33 |
* www.gvsig.gva.es |
|
34 |
* |
|
35 |
* or |
|
36 |
* |
|
37 |
* IVER T.I. S.A |
|
38 |
* Salamanca 50 |
|
39 |
* 46005 Valencia |
|
40 |
* Spain |
|
41 |
* |
|
42 |
* +34 963163400 |
|
43 |
* dac@iver.es |
|
44 |
*/ |
|
45 |
/* CVS MESSAGES: |
|
46 |
* |
|
47 |
* $Id$ |
|
48 |
* $Log$ |
|
49 |
* Revision 1.1 2006-08-10 12:00:49 jorpiell |
|
50 |
* Primer commit del driver de Gml |
|
51 |
* |
|
52 |
* |
|
53 |
*/ |
|
54 |
/** |
|
55 |
* This class represent a XSD schema file |
|
56 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
57 |
*/ |
|
58 |
public class XMLSchema { |
|
59 |
private XMLSchema parent = null; |
|
60 |
private Vector children = null; |
|
61 |
private String name = null; |
|
62 |
private String location = null; |
|
63 |
|
|
64 |
public XMLSchema(String name,String location) { |
|
65 |
super(); |
|
66 |
this.name = name; |
|
67 |
this.location = location; |
|
68 |
children = new Vector(); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* @return Returns the children. |
|
73 |
*/ |
|
74 |
public Vector getChildren() { |
|
75 |
return children; |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* @return Returns the location. |
|
80 |
*/ |
|
81 |
public String getLocation() { |
|
82 |
return location; |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* @return Returns the name. |
|
87 |
*/ |
|
88 |
public String getName() { |
|
89 |
return name; |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* @return Returns the parent. |
|
94 |
*/ |
|
95 |
public XMLSchema getParent() { |
|
96 |
return parent; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* @param location The location to set. |
|
101 |
*/ |
|
102 |
public void setLocation(String location) { |
|
103 |
this.location = location; |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* @param parent The parent to set. |
|
108 |
*/ |
|
109 |
public void setParent(XMLSchema parent) { |
|
110 |
this.parent = parent; |
|
111 |
} |
|
112 |
|
|
113 |
public void addChidren(XMLSchema schema){ |
|
114 |
this.children.add(schema); |
|
115 |
} |
|
116 |
} |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/XMLElement.java | ||
---|---|---|
3 | 3 |
import java.io.IOException; |
4 | 4 |
import java.util.Vector; |
5 | 5 |
|
6 |
import org.gvsig.remoteClient.gml.GMLTags; |
|
7 |
import org.gvsig.remoteClient.gml.factories.XMLElementsFactory; |
|
8 | 6 |
import org.gvsig.remoteClient.gml.factories.XMLTypesFactory; |
7 |
import org.gvsig.remoteClient.gml.types.IXMLType; |
|
8 |
import org.gvsig.remoteClient.gml.types.XMLComplexType; |
|
9 | 9 |
import org.gvsig.remoteClient.utils.CapabilitiesTags; |
10 | 10 |
import org.kxml2.io.KXmlParser; |
11 | 11 |
import org.xmlpull.v1.XmlPullParserException; |
... | ... | |
54 | 54 |
* |
55 | 55 |
* $Id$ |
56 | 56 |
* $Log$ |
57 |
* Revision 1.2.2.3 2006-11-17 11:38:03 ppiqueras
|
|
58 |
* Corregidos bugs y añadida nueva funcionalidad. Del HEAD.
|
|
57 |
* Revision 1.2.2.4 2007-01-25 16:12:59 jorpiell
|
|
58 |
* Se han sustituido las clases por las que hay en el nuevo driver de GML.
|
|
59 | 59 |
* |
60 |
* Revision 1.10 2006/12/29 17:15:48 jorpiell |
|
61 |
* Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples |
|
62 |
* |
|
63 |
* Revision 1.9 2006/12/22 11:25:44 csanchez |
|
64 |
* Nuevo parser GML 2.x para gml's sin esquema |
|
65 |
* |
|
60 | 66 |
* Revision 1.8 2006/11/16 13:27:42 jorpiell |
61 | 67 |
* El XML Element tiene un m?todo para recuperar a los hijos de un elemento determinado |
62 | 68 |
* |
... | ... | |
86 | 92 |
/** |
87 | 93 |
* A simple XSD element that represent an object |
88 | 94 |
* with a type of data. |
95 |
* |
|
89 | 96 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
97 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es) |
|
98 |
* |
|
90 | 99 |
*/ |
91 | 100 |
public class XMLElement { |
92 | 101 |
private String name = null; |
... | ... | |
153 | 162 |
if (type != null){ |
154 | 163 |
return type; |
155 | 164 |
} |
156 |
if (typeUnknown != null){ |
|
165 |
if (typeUnknown != null){
|
|
157 | 166 |
this.type = XMLTypesFactory.getType(typeUnknown); |
158 | 167 |
} |
159 | 168 |
if ((type == null) && (typeUnknown != null)){ |
160 | 169 |
if (typeUnknown.split(":").length > 1){ |
161 | 170 |
this.type = XMLTypesFactory.getType(null + ":" + typeUnknown.split(":")[1]); |
171 |
if (type == null){ |
|
172 |
this.type = XMLTypesFactory.getType(typeUnknown.split(":")[1]); |
|
173 |
} |
|
162 | 174 |
} |
163 | 175 |
} |
164 | 176 |
return type; |
... | ... | |
200 | 212 |
* |
201 | 213 |
*/ |
202 | 214 |
private void parse(XMLSchemaParser parser) throws XmlPullParserException, IOException{ |
215 |
//con kxml contamos cuantos argumentos tiene la etiqueta gml para parsear |
|
203 | 216 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
217 |
//detecta los atributos del elemento y los salva |
|
218 |
//puede ser que se sepa antes el atributo que el tipo al que pertenece o viceversa |
|
204 | 219 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_NAME) == 0){ |
205 | 220 |
setName(parser.getAttributeValue(i)); |
206 | 221 |
}else if (parser.getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_TYPE) == 0){ |
... | ... | |
209 | 224 |
try{ |
210 | 225 |
setMaxOccurs(Integer.parseInt(parser.getAttributeValue(i))); |
211 | 226 |
}catch(NumberFormatException e){ |
212 |
setMaxOccurs(0);
|
|
227 |
setMaxOccurs(-1);
|
|
213 | 228 |
} |
214 | 229 |
}else if (parser.getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_MINOCCURS) == 0){ |
215 | 230 |
try{ |
216 | 231 |
setMinOccurs(Integer.parseInt(parser.getAttributeValue(i))); |
217 | 232 |
}catch(NumberFormatException e){ |
218 |
setMinOccurs(0);
|
|
233 |
setMinOccurs(-1);
|
|
219 | 234 |
} |
220 | 235 |
}else if (parser.getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_REF) == 0){ |
221 | 236 |
setReference(parser.getAttributeValue(i)); |
... | ... | |
224 | 239 |
|
225 | 240 |
} |
226 | 241 |
|
227 |
private void parseSimpleType(XMLSchemaParser parser) throws IOException, XmlPullParserException
|
|
242 |
public void parseSimpleType(XMLSchemaParser parser) throws IOException, XmlPullParserException
|
|
228 | 243 |
{ |
229 | 244 |
int currentTag; |
230 | 245 |
boolean end = false; |
... | ... | |
410 | 425 |
} |
411 | 426 |
return new Vector(); |
412 | 427 |
} |
428 |
|
|
429 |
/** |
|
430 |
* Returns if the attribute is multiple or not |
|
431 |
* @return |
|
432 |
*/ |
|
433 |
public boolean isMultiple(){ |
|
434 |
if (maxOccurs == 1){ |
|
435 |
return false; |
|
436 |
} |
|
437 |
return true; |
|
438 |
} |
|
413 | 439 |
} |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/XMLSchemaManager.java | ||
---|---|---|
8 | 8 |
import java.net.UnknownHostException; |
9 | 9 |
import java.util.StringTokenizer; |
10 | 10 |
|
11 |
import org.gvsig.exceptions.BaseException; |
|
12 | 11 |
import org.gvsig.remoteClient.gml.GMLTags; |
12 |
import org.gvsig.remoteClient.gml.exceptions.BaseException; |
|
13 | 13 |
import org.gvsig.remoteClient.gml.factories.XMLSchemasFactory; |
14 | 14 |
import org.gvsig.remoteClient.gml.warnings.GMLWarningInfo; |
15 | 15 |
import org.gvsig.remoteClient.gml.warnings.GMLWarningMalformed; |
... | ... | |
62 | 62 |
* |
63 | 63 |
* $Id$ |
64 | 64 |
* $Log$ |
65 |
* Revision 1.2 2007-01-15 13:11:00 csanchez |
|
65 |
* Revision 1.2.2.1 2007-01-25 16:12:59 jorpiell |
|
66 |
* Se han sustituido las clases por las que hay en el nuevo driver de GML. |
|
67 |
* |
|
68 |
* Revision 1.2 2007/01/15 13:11:00 csanchez |
|
66 | 69 |
* Sistema de Warnings y Excepciones adaptado a BasicException |
67 | 70 |
* |
68 | 71 |
* Revision 1.1 2006/12/22 11:25:04 csanchez |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/XMLNameSpace.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.2 2007-01-15 13:11:00 csanchez |
|
48 |
* Revision 1.2.2.1 2007-01-25 16:12:59 jorpiell |
|
49 |
* Se han sustituido las clases por las que hay en el nuevo driver de GML. |
|
50 |
* |
|
51 |
* Revision 1.2 2007/01/15 13:11:00 csanchez |
|
49 | 52 |
* Sistema de Warnings y Excepciones adaptado a BasicException |
50 | 53 |
* |
51 | 54 |
* Revision 1.1 2006/12/22 11:25:04 csanchez |
branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/schemas/XMLSchemaParser.java | ||
---|---|---|
3 | 3 |
import java.io.BufferedReader; |
4 | 4 |
import java.io.File; |
5 | 5 |
import java.io.FileInputStream; |
6 |
import java.io.FileNotFoundException; |
|
7 | 6 |
import java.io.FileReader; |
8 | 7 |
import java.io.IOException; |
9 | 8 |
import java.util.Hashtable; |
... | ... | |
14 | 13 |
import org.gvsig.remoteClient.gml.GMLTags; |
15 | 14 |
import org.gvsig.remoteClient.gml.factories.XMLElementsFactory; |
16 | 15 |
import org.gvsig.remoteClient.gml.factories.XMLTypesFactory; |
16 |
import org.gvsig.remoteClient.gml.types.XMLComplexType; |
|
17 | 17 |
import org.gvsig.remoteClient.utils.CapabilitiesTags; |
18 | 18 |
import org.kxml2.io.KXmlParser; |
19 | 19 |
import org.xmlpull.v1.XmlPullParserException; |
... | ... | |
62 | 62 |
* |
63 | 63 |
* $Id$ |
64 | 64 |
* $Log$ |
65 |
* Revision 1.1.2.3 2006-11-17 11:38:03 ppiqueras
|
|
66 |
* Corregidos bugs y añadida nueva funcionalidad. Del HEAD.
|
|
65 |
* Revision 1.1.2.4 2007-01-25 16:12:59 jorpiell
|
|
66 |
* Se han sustituido las clases por las que hay en el nuevo driver de GML.
|
|
67 | 67 |
* |
68 |
* Revision 1.7 2007/01/15 13:11:00 csanchez |
|
69 |
* Sistema de Warnings y Excepciones adaptado a BasicException |
|
70 |
* |
|
71 |
* Revision 1.6 2006/12/29 17:15:48 jorpiell |
|
72 |
* Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples |
|
73 |
* |
|
74 |
* Revision 1.5 2006/12/22 11:25:44 csanchez |
|
75 |
* Nuevo parser GML 2.x para gml's sin esquema |
|
76 |
* |
|
68 | 77 |
* Revision 1.4 2006/10/10 12:52:28 jorpiell |
69 | 78 |
* Soporte para features complejas. |
70 | 79 |
* |
... | ... | |
82 | 91 |
* |
83 | 92 |
* Revision 1.1 2006/05/16 14:12:56 jorpiell |
84 | 93 |
* A?adido el parseador de Esquemas |
85 |
* |
|
86 |
* |
|
94 |
*
|
|
95 |
*
|
|
87 | 96 |
*/ |
88 | 97 |
/** |
89 | 98 |
* Thas class is used to parse a schema XSD |
99 |
* |
|
90 | 100 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
101 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es) |
|
102 |
* |
|
91 | 103 |
*/ |
92 | 104 |
public class XMLSchemaParser extends KXmlParser { |
105 |
private String targetNameSpace = null; |
|
93 | 106 |
private String schema = ""; |
94 | 107 |
private String encoding = "UTF-8"; |
95 | 108 |
private String nameSpace = ""; |
96 | 109 |
private Hashtable attributes = null; |
110 |
private String version = null; |
|
97 | 111 |
|
112 |
|
|
98 | 113 |
public XMLSchemaParser(){ |
99 | 114 |
super(); |
115 |
//initializes a new hash table for many namespace to store the defined types |
|
100 | 116 |
attributes = new Hashtable(); |
101 | 117 |
} |
102 | 118 |
|
103 | 119 |
public XMLSchemaParser(String schema){ |
104 | 120 |
super(); |
121 |
//schema instace is named with the string in "schema" |
|
105 | 122 |
this.schema = schema; |
106 | 123 |
attributes = new Hashtable(); |
107 | 124 |
} |
... | ... | |
112 | 129 |
* @param tag |
113 | 130 |
*/ |
114 | 131 |
public void setSchemaFromMainTag(String tag){ |
132 |
//set the name string of the namespace. |
|
115 | 133 |
int pos = tag.indexOf(":"); |
116 | 134 |
if (pos > 0){ |
117 | 135 |
this.schema = tag.substring(0,pos); |
... | ... | |
140 | 158 |
* @return SCHEMA:TAG |
141 | 159 |
*/ |
142 | 160 |
private String getTag(String tag){ |
161 |
//get the tag without the namespace |
|
143 | 162 |
if (tag == null){ |
144 | 163 |
return null; |
145 | 164 |
} |
... | ... | |
174 | 193 |
} |
175 | 194 |
} |
176 | 195 |
|
177 |
public void parse(File f,String nameSpace) { |
|
196 |
/* |
|
197 |
* (non-Javadoc) |
|
198 |
* @see org.xmlpull.v1.XmlPullParser#getName() |
|
199 |
*/ |
|
200 |
public String getNameSpace(){ |
|
201 |
try{ |
|
202 |
String name = super.getName(); |
|
203 |
if ((name!=null)&&(name.split(":").length > 1)){ |
|
204 |
return name.split(":")[0]; |
|
205 |
} |
|
206 |
return ""; |
|
207 |
}catch (NullPointerException e){ |
|
208 |
return ""; |
|
209 |
} |
|
210 |
} |
|
211 |
|
|
212 |
/******************************************************************************** |
|
213 |
* FUNCTION PARSE(FILE,NAMESPACE) PARSING THE XML SCHEMA ".xsd" * |
|
214 |
* * |
|
215 |
* -gml version * |
|
216 |
* -elementFormDefault {qualified,non-qualified} (not implemented yet) * |
|
217 |
* -namespaces "xmlns" (nor implemented,only in gml file) * |
|
218 |
* -targetNamespace (the name of this schema) * |
|
219 |
* -imports (not implemented) * |
|
220 |
* -features -> "elements"="types" * |
|
221 |
* * |
|
222 |
* @param f (file ".xsd" to parse) * |
|
223 |
* @param nameSpace (Schemas name) * |
|
224 |
* @throws IOException * |
|
225 |
* @throws XmlPullParserException * |
|
226 |
* * |
|
227 |
********************************************************************************/ |
|
228 |
public void parse(File f,String nameSpace) throws XmlPullParserException, IOException{ |
|
178 | 229 |
this.nameSpace = nameSpace; |
179 | 230 |
FileReader reader = null; |
180 |
try |
|
181 |
{ |
|
182 |
reader = new FileReader(f); |
|
183 |
BufferedReader br = new BufferedReader(reader); |
|
184 |
char[] buffer = new char[100]; |
|
185 |
br.read(buffer); |
|
186 |
StringBuffer st = new StringBuffer(new String(buffer)); |
|
187 |
String searchText = "encoding=\""; |
|
188 |
int index = st.indexOf(searchText); |
|
189 |
if (index>-1) { |
|
190 |
st.delete(0, index+searchText.length()); |
|
191 |
encoding = st.substring(0, st.indexOf("\"")); |
|
192 |
} |
|
193 |
} catch (FileNotFoundException ex) { |
|
194 |
ex.printStackTrace(); |
|
195 |
} catch (IOException e) { |
|
196 |
e.printStackTrace(); |
|
231 |
int tag; |
|
232 |
|
|
233 |
//opening the schemas file with the right encoding |
|
234 |
//default encoding = UTF-8 |
|
235 |
reader = new FileReader(f); |
|
236 |
BufferedReader br = new BufferedReader(reader); |
|
237 |
char[] buffer = new char[100]; |
|
238 |
br.read(buffer); |
|
239 |
StringBuffer st = new StringBuffer(new String(buffer)); |
|
240 |
String searchText = "encoding=\""; |
|
241 |
int index = st.indexOf(searchText); |
|
242 |
if (index>-1) { |
|
243 |
st.delete(0, index+searchText.length()); |
|
244 |
encoding = st.substring(0, st.indexOf("\"")); |
|
197 | 245 |
} |
198 | 246 |
|
199 |
int tag; |
|
200 |
|
|
201 |
try |
|
202 |
{ |
|
203 |
setInput(new FileInputStream(f), encoding); |
|
204 |
nextTag(); |
|
247 |
//Open the file with the KXML parser |
|
248 |
setInput(new FileInputStream(f), encoding); |
|
249 |
nextTag(); |
|
205 | 250 |
|
206 |
if ( getEventType() != KXmlParser.END_DOCUMENT ) |
|
207 |
{ |
|
208 |
setSchemaFromMainTag(getName()); |
|
209 |
|
|
210 |
require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_SCHEMAROOT); |
|
211 |
tag = nextTag(); |
|
212 |
while(tag != KXmlParser.END_DOCUMENT) |
|
251 |
//Parsing attributes from the head tag... |
|
252 |
if ( getEventType() != KXmlParser.END_DOCUMENT ) |
|
253 |
{ |
|
254 |
/************************ |
|
255 |
* Etiqueta <schema> * |
|
256 |
************************/ |
|
257 |
setSchemaFromMainTag(getName()); |
|
258 |
//Searching the init tag "schema" |
|
259 |
require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_SCHEMAROOT); |
|
260 |
for (int i=0 ; i<getAttributeCount() ; i++){ |
|
261 |
//getting attributes and values |
|
262 |
String attName = getAttributeName(i); |
|
263 |
String attValue = getAttributeValue(i); |
|
264 |
|
|
265 |
/******************************** |
|
266 |
* Atributo <targetNamespace> * |
|
267 |
********************************/ |
|
268 |
//Target Namespace (URI) |
|
269 |
//this is the namespace of all components in the schema |
|
270 |
//setTargetNamespace(); |
|
271 |
if (attName.compareTo(GMLTags.XML_TARGET_NAMESPACE)==0){ |
|
272 |
targetNameSpace = attValue; |
|
273 |
} |
|
274 |
|
|
275 |
/************************************ |
|
276 |
* Atributo <elementFormDefault> * |
|
277 |
************************************/ |
|
278 |
//Qualified--> Los elementos del espacio de nombres de destino deben cualificarse |
|
279 |
//con el prefijo del espacio de nombres. |
|
280 |
//Unqualified--> No es necesario que los elementos del |
|
281 |
//espacio de nombres de destino est?n cualificados con el prefijo del espacio de nombres. |
|
282 |
//(Espacion_de_Nombres:Elemento) |
|
283 |
//elementFormDefault(); |
|
284 |
if (attName.compareTo(GMLTags.XML_ELEMENT_FORM_DEFAULT)==0){ |
|
285 |
} |
|
286 |
|
|
287 |
/************************************ |
|
288 |
* Atributo <attributeFormDefault> * |
|
289 |
************************************/ |
|
290 |
//Lo mismo que el anterior pero con los atributos... |
|
291 |
//(Espacio_de_Nombres:Atributo) |
|
292 |
//attributeFormDefault(); |
|
293 |
if (attName.compareTo(GMLTags.XML_ATTRIBUTE_FORM_DEFAULT)==0){ |
|
294 |
} |
|
295 |
|
|
296 |
/************************ |
|
297 |
* Atributo <Version> * |
|
298 |
************************/ |
|
299 |
//Gets gml version to parse by the right parser. |
|
300 |
//getversion(); |
|
301 |
if (attName.compareTo(GMLTags.VERSION)==0){ |
|
302 |
version=attValue; |
|
303 |
} |
|
304 |
} |
|
305 |
tag = nextTag(); |
|
306 |
|
|
307 |
while(tag != KXmlParser.END_DOCUMENT) |
|
308 |
{ |
|
309 |
switch(tag) |
|
213 | 310 |
{ |
214 |
switch(tag) |
|
215 |
{ |
|
216 |
case KXmlParser.START_TAG: |
|
217 |
if (getName().compareTo(CapabilitiesTags.COMPLEXTYPE)==0){ |
|
218 |
for (int i=0 ; i<getAttributeCount() ; i++){ |
|
219 |
if (getAttributeName(i).compareTo(GMLTags.GML_NAME) == 0){ |
|
220 |
XMLComplexType complexType = XMLTypesFactory.addComplexType(nameSpace,getAttributeValue(i)); |
|
221 |
parseComplexType(complexType); |
|
222 |
attributes.put(complexType.getName(),complexType); |
|
223 |
} |
|
224 |
|
|
225 |
} |
|
226 |
} else if (getName().compareTo(CapabilitiesTags.ELEMENT)==0){ |
|
227 |
XMLElement entity = XMLElementsFactory.addType(this); |
|
228 |
try{ |
|
229 |
attributes.put(entity.getName(),entity.getEntityType()); |
|
230 |
}catch(NullPointerException e){ |
|
231 |
//Type not defined |
|
232 |
} |
|
233 |
|
|
311 |
case KXmlParser.START_TAG: |
|
312 |
|
|
313 |
/************************ |
|
314 |
* Etiqueta <import> * |
|
315 |
************************/ |
|
316 |
//imports elements from other schemas (other schema ".xsd" files) |
|
317 |
|
|
318 |
/**************************** |
|
319 |
* Etiqueta <complexType> * |
|
320 |
****************************/ |
|
321 |
if (getName().compareTo(CapabilitiesTags.COMPLEXTYPE)==0){ |
|
322 |
for (int i=0 ; i<getAttributeCount() ; i++){ |
|
323 |
/******************** |
|
324 |
* Atributo <name> * |
|
325 |
********************/ |
|
326 |
if (getAttributeName(i).compareTo(GMLTags.GML_NAME) == 0){ |
|
327 |
// inserts a new complex type inside the namespace |
|
328 |
XMLComplexType complexType = XMLTypesFactory.addComplexType(nameSpace,getAttributeValue(i)); |
|
329 |
parseComplexType(complexType); |
|
330 |
attributes.put(complexType.getName(),complexType); |
|
331 |
} |
|
332 |
|
|
234 | 333 |
} |
235 |
break; |
|
334 |
} |
|
335 |
/**************************** |
|
336 |
* Etiqueta <simpleType> * |
|
337 |
****************************/ |
|
338 |
// SIMPLE TYPE elements like enumerations not implemented |
|
339 |
else if (getName().compareTo(CapabilitiesTags.SIMPLETYPE)==0){ |
|
340 |
parseSimpleType(); |
|
341 |
} |
|
342 |
/************************ |
|
343 |
* Etiqueta <element> * |
|
344 |
************************/ |
|
345 |
else if (getName().compareTo(CapabilitiesTags.ELEMENT)==0){ |
|
346 |
XMLElement entity = XMLElementsFactory.addType(this); |
|
347 |
try{ |
|
348 |
//Sets the name and type of one element |
|
349 |
attributes.put(entity.getName(),entity.getEntityType()); |
|
350 |
}catch(NullPointerException e){ |
|
351 |
//Type not defined yet, do nothing here because the type will be declared later |
|
352 |
} |
|
353 |
} |
|
354 |
break; |
|
236 | 355 |
case KXmlParser.END_TAG: |
237 | 356 |
break; |
357 |
//Show the Text on the screen |
|
238 | 358 |
case KXmlParser.TEXT: |
239 | 359 |
if (getName()!=null) |
240 | 360 |
System.out.println("[TEXT]["+getText().trim()+"]"); |
241 | 361 |
break; |
242 |
} |
|
243 |
tag = next(); |
|
244 | 362 |
} |
245 |
require(KXmlParser.END_DOCUMENT, null, null);
|
|
363 |
tag = next();
|
|
246 | 364 |
} |
365 |
require(KXmlParser.END_DOCUMENT, null, null); |
|
247 | 366 |
} |
248 |
catch(XmlPullParserException parser_ex){ |
|
249 |
System.out.println(parser_ex.getMessage()); |
|
250 |
parser_ex.printStackTrace(); |
|
251 |
return; |
|
367 |
} |
|
368 |
|
|
369 |
/**************************************************** |
|
370 |
* FUNCTION PARSE SIMPLE TYPE() * |
|
371 |
* * |
|
372 |
* Parse simple types and its restrictions * |
|
373 |
* * |
|
374 |
****************************************************/ |
|
375 |
private void parseSimpleType() throws IOException, XmlPullParserException{ |
|
376 |
int currentTag; |
|
377 |
boolean end = false; |
|
378 |
currentTag = getEventType(); |
|
379 |
|
|
380 |
String typeName = null; |
|
381 |
String typeValue = null; |
|
382 |
|
|
383 |
for (int i=0 ; i<getAttributeCount() ; i++){ |
|
384 |
if (getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_NAME) == 0){ |
|
385 |
typeName = getAttributeValue(i); |
|
386 |
} |
|
252 | 387 |
} |
253 |
catch (IOException ioe) { |
|
254 |
ioe.printStackTrace(); |
|
255 |
return; |
|
256 |
} |
|
388 |
|
|
389 |
while (!end){ |
|
390 |
switch(currentTag){ |
|
391 |
case KXmlParser.START_TAG: |
|
392 |
if (getName().compareTo(CapabilitiesTags.RESTRICTION)==0){ |
|
393 |
for (int i=0 ; i<getAttributeCount() ; i++){ |
|
394 |
if (getAttributeName(i).compareTo(CapabilitiesTags.BASE) == 0){ |
|
395 |
typeValue = getAttributeValue(i); |
|
396 |
} |
|
397 |
} |
|
398 |
} |
|
399 |
//Falta parsear los tipos enumerados |
|
400 |
break; |
|
401 |
case KXmlParser.END_TAG: |
|
402 |
if (getName().compareTo(CapabilitiesTags.SIMPLETYPE) == 0) |
|
403 |
end = true; |
|
404 |
break; |
|
405 |
case KXmlParser.TEXT: |
|
406 |
break; |
|
407 |
} |
|
408 |
if (!end){ |
|
409 |
currentTag = next(); |
|
410 |
} |
|
411 |
} |
|
412 |
if ((typeName != null) && (typeValue != null)){ |
|
413 |
XMLTypesFactory.addSimpleType(typeName,typeValue); |
|
414 |
} |
|
257 | 415 |
} |
416 |
|
|
417 |
/**************************************************** |
|
418 |
* FUNCTION PARSE COMPLEX TYPE(COMPLEX TYPE) * |
|
419 |
* * |
|
420 |
* Parse the attributes from a complex type * |
|
421 |
* * |
|
422 |
* @param complexType * |
|
423 |
* * |
|
424 |
****************************************************/ |
|
258 | 425 |
|
259 | 426 |
private void parseComplexType(XMLComplexType complexType) throws IOException, XmlPullParserException{ |
260 | 427 |
int currentTag; |
... | ... | |
268 | 435 |
switch(currentTag) |
269 | 436 |
{ |
270 | 437 |
case KXmlParser.START_TAG: |
438 |
/******************************** |
|
439 |
* Etiqueta <complexContent> * |
|
440 |
********************************/ |
|
271 | 441 |
if (getName().compareTo(CapabilitiesTags.COMPLEXCONTENT)==0){ |
272 | 442 |
parseComplexContent(complexType); |
273 |
}else if(getName().compareTo(CapabilitiesTags.SEQUENCE)==0){ |
|
443 |
} |
|
444 |
/************************ |
|
445 |
* Etiqueta <sequence> * |
|
446 |
************************/ |
|
447 |
else if(getName().compareTo(CapabilitiesTags.SEQUENCE)==0){ |
|
274 | 448 |
parseSequence(complexType); |
275 | 449 |
} |
450 |
/************************ |
|
451 |
* Etiqueta <choice> * |
|
452 |
************************/ |
|
453 |
else if(getName().compareTo(CapabilitiesTags.CHOICE)==0){ |
|
454 |
parseChoice(complexType); |
|
455 |
} |
|
276 | 456 |
break; |
277 | 457 |
case KXmlParser.END_TAG: |
278 | 458 |
if (getName().compareTo(CapabilitiesTags.COMPLEXTYPE) == 0) |
... | ... | |
287 | 467 |
} |
288 | 468 |
} |
289 | 469 |
|
470 |
/************************************************************************************ |
|
471 |
* FUNCION PARSE COMPLEX CONTENT(COMPLEX TYPE) * |
|
472 |
* * |
|
473 |
* Parsea los atributos que componen un contenido complejo * |
Also available in: Unified diff