01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.wfs.kvp;
06:
07: import org.geoserver.ows.FlatKvpParser;
08: import org.geoserver.wfs.WFSException;
09: import org.vfny.geoserver.global.Data;
10: import org.vfny.geoserver.global.NameSpaceInfo;
11:
12: import javax.xml.namespace.QName;
13:
14: /**
15: * Abstract kvp parser for parsing qualified names of the form "([prefix:]local)+".
16: * <p>
17: * This parser will parse strings of the above format into a list of
18: * {@link javax.xml.namespace.QName}
19: * </p>
20: * @author Justin Deoliveira, The Open Planning Project
21: *
22: */
23: public class QNameKvpParser extends FlatKvpParser {
24: /**
25: * catalog for namespace lookups.
26: */
27: Data catalog;
28:
29: public QNameKvpParser(String key, Data catalog) {
30: super (key, QName.class);
31: this .catalog = catalog;
32: }
33:
34: /**
35: * Parses the token representing a type name, ( <prefix>:<local>, or <local> )
36: * into a {@link QName }.
37: * <p>
38: * If the latter form is supplied the QName is given the default namespace
39: * as specified in the catalog.
40: * </p>
41: */
42: protected Object parseToken(String token) throws Exception {
43: int i = token.indexOf(':');
44:
45: if (i != -1) {
46: String prefix = token.substring(0, i);
47: String local = token.substring(i + 1);
48:
49: String uri = null;
50: if (prefix != null && !"".equals(prefix)) {
51: final NameSpaceInfo namespace = catalog
52: .getNameSpace(prefix);
53: if (namespace == null)
54: throw new WFSException("Unknown namespace ["
55: + prefix + "]");
56: uri = namespace.getURI();
57: }
58:
59: return new QName(uri, local, prefix);
60: } else {
61: String uri = catalog.getDefaultNameSpace().getURI();
62: String prefix = catalog.getDefaultPrefix();
63: String local = token;
64:
65: return new QName(uri, local, prefix);
66: }
67: }
68: }
|