svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wfs / exceptions / ExceptionsFactory.java @ 40769
History | View | Annotate | Download (4 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.remoteclient.wfs.exceptions; |
25 |
|
26 |
import java.io.IOException; |
27 |
|
28 |
import org.kxml2.io.KXmlParser; |
29 |
import org.xmlpull.v1.XmlPullParserException; |
30 |
|
31 |
import org.gvsig.remoteclient.utils.CapabilitiesTags; |
32 |
|
33 |
/**
|
34 |
* This class parses an exception and returns it
|
35 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
36 |
*/
|
37 |
public class ExceptionsFactory { |
38 |
|
39 |
public static WFSException parseServiceExceptionReport(KXmlParser parser) throws XmlPullParserException, IOException { |
40 |
int currentTag;
|
41 |
boolean end = false; |
42 |
|
43 |
currentTag = parser.next(); |
44 |
|
45 |
while (!end)
|
46 |
{ |
47 |
switch(currentTag)
|
48 |
{ |
49 |
case KXmlParser.START_TAG:
|
50 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.SERVICE_EXCEPTION)==0) |
51 |
{ |
52 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
53 |
String attName = parser.getAttributeName(i);
|
54 |
String code = null; |
55 |
if (attName.compareTo(CapabilitiesTags.CODE)==0){ |
56 |
code = parser.getAttributeValue(i); |
57 |
} |
58 |
if (code != null){ |
59 |
if (code.compareTo(CapabilitiesTags.INVALID_FORMAT)==0){ |
60 |
parser.next(); |
61 |
return new InvalidFormatException(parser.getText()); |
62 |
} |
63 |
//Code unspecified
|
64 |
parser.next(); |
65 |
return new WFSException(code,parser.getText()); |
66 |
} |
67 |
} |
68 |
} |
69 |
break;
|
70 |
case KXmlParser.END_TAG:
|
71 |
if (parser.getName().compareTo(CapabilitiesTags.SERVICE_EXCEPTION_REPORT) == 0) |
72 |
end = true;
|
73 |
break;
|
74 |
case KXmlParser.TEXT:
|
75 |
break;
|
76 |
} |
77 |
if (!end){
|
78 |
currentTag = parser.next(); |
79 |
} |
80 |
} |
81 |
return new WFSException(); |
82 |
} |
83 |
|
84 |
public static WFSException parseExceptionReport(KXmlParser parser) throws XmlPullParserException, IOException { |
85 |
int currentTag;
|
86 |
boolean end = false; |
87 |
|
88 |
currentTag = parser.next(); |
89 |
|
90 |
String code = null; |
91 |
|
92 |
while (!end)
|
93 |
{ |
94 |
switch(currentTag)
|
95 |
{ |
96 |
case KXmlParser.START_TAG:
|
97 |
if (CapabilitiesTags.EXCEPTION.equals(parser.getName()))
|
98 |
{ |
99 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
100 |
String attName = parser.getAttributeName(i);
|
101 |
if (CapabilitiesTags.EXCEPTION_CODE.equals(attName)){
|
102 |
code = parser.getAttributeValue(i); |
103 |
} |
104 |
} |
105 |
} else if (CapabilitiesTags.EXCEPTION_TEXT.equals(parser.getName())){ |
106 |
parser.next(); |
107 |
return new WFSException(code, parser.getText()); |
108 |
} |
109 |
break;
|
110 |
case KXmlParser.END_TAG:
|
111 |
if (CapabilitiesTags.EXCEPTION_REPORT.equals(parser.getName()))
|
112 |
end = true;
|
113 |
break;
|
114 |
case KXmlParser.TEXT:
|
115 |
break;
|
116 |
} |
117 |
if (!end){
|
118 |
currentTag = parser.next(); |
119 |
} |
120 |
} |
121 |
return new WFSException(); |
122 |
} |
123 |
} |