Statistics
| Revision:

root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / remoteclient / wfs / exceptions / ExceptionsFactory.java @ 112

History | View | Annotate | Download (3.79 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
import org.xmlpull.v1.XmlPullParser;
33

    
34
/**
35
 * This class parses an exception and returns it
36
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
37
 */
38
public class ExceptionsFactory {
39
        
40
        public static WFSException parseServiceExceptionReport(KXmlParser parser) throws XmlPullParserException, IOException {
41
                int currentTag;
42
                boolean end = false;                
43
                
44
                currentTag = parser.next();
45
                
46
                while (!end) 
47
                {
48
                        switch(currentTag)
49
                        {
50
                        case KXmlParser.START_TAG:
51
                                if (parser.getName().compareToIgnoreCase(CapabilitiesTags.SERVICE_EXCEPTION)==0)
52
                                {
53
                                        for (int i=0 ; i<parser.getAttributeCount() ; i++){
54
                                                String attName = parser.getAttributeName(i);
55
                                                String code = null;
56
                                                if (attName.compareTo(CapabilitiesTags.CODE)==0){
57
                                                        code = parser.getAttributeValue(i);
58
                                                }
59
                                                if (code != null){
60
                                                        if (code.compareTo(CapabilitiesTags.INVALID_FORMAT)==0){
61
                                                                parser.next();
62
                                                                return new InvalidFormatException(parser.getText());
63
                                                        }
64
                                                        //Code unspecified
65
                                                        parser.next();
66
                                                        return new WFSException(code,parser.getText());
67
                                                }
68
                                        }
69
                                }                                         
70
                                break;
71
                        case KXmlParser.END_TAG:
72
                                if (parser.getName().compareTo(CapabilitiesTags.SERVICE_EXCEPTION_REPORT) == 0)
73
                                        end = true;
74
                                break;
75
                        case KXmlParser.TEXT:                   
76
                                break;
77
                        }
78
                        if (!end){
79
                                currentTag = parser.next();
80
                        }
81
                }   
82
                return new WFSException();
83
        }
84

    
85
    public static WFSException parseExceptionReport(KXmlParser parser) throws XmlPullParserException, IOException {
86
        String code = null;
87
        int eventType = parser.getEventType();
88

    
89
        while ( eventType != XmlPullParser.END_DOCUMENT) {
90
            switch (eventType) {
91
                case KXmlParser.START_TAG:
92
                    if (CapabilitiesTags.EXCEPTION.equals(parser.getName())) {
93
                        for (int i = 0; i < parser.getAttributeCount(); i++) {
94
                            String attName = parser.getAttributeName(i);
95
                            if (CapabilitiesTags.EXCEPTION_CODE.equals(attName)) {
96
                                code = parser.getAttributeValue(i);
97
                            }
98
                        }
99
                    } else if (CapabilitiesTags.EXCEPTION_TEXT.equals(parser.getName())) {
100
                        parser.next();
101
                        return new WFSException(code, parser.getText());
102
                    }
103
                    break;
104
                case KXmlParser.END_TAG:
105
                    break;
106
                case KXmlParser.TEXT:
107
                    break;
108
            }
109
            parser.nextTag();
110
            eventType = parser.getEventType();
111
        }
112
        return new WFSException();
113
    }
114
}