Skip to content

Commit f349ca2

Browse files
author
jdeolive
committed
ensuring that parser delegates rinheirent namespace prefix mappings, see GEOS-5298
1 parent 12556f3 commit f349ca2

File tree

6 files changed

+105
-2
lines changed

6 files changed

+105
-2
lines changed

modules/extension/xsd/xsd-core/src/main/java/org/geotools/xml/impl/DelegatingHandler.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public void endDocument() throws SAXException {
104104
delegate.endDocument();
105105
}
106106

107+
@Override
108+
public void startPrefixMapping(String prefix, String uri) throws SAXException {
109+
delegate.startPrefixMapping(prefix, uri);
110+
}
111+
107112
public void startElement(QName name, Attributes attributes)
108113
throws SAXException {
109114

@@ -123,7 +128,11 @@ public void characters(char[] ch, int start, int length)
123128
public void endElement(QName name) throws SAXException {
124129
delegate.endElement( name.getNamespaceURI(), name.getLocalPart(), qname( name ) );
125130
}
126-
131+
132+
public void endPrefixMapping(String prefix) throws SAXException {
133+
delegate.endPrefixMapping(prefix);
134+
}
135+
127136
String qname( QName name ) {
128137
return name.getNamespaceURI() != null ? name.getPrefix() + ":" + name.getLocalPart() : name.getLocalPart();
129138
}

modules/extension/xsd/xsd-core/src/main/java/org/geotools/xml/impl/Handler.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.eclipse.xsd.XSDSchemaContent;
2020
import org.picocontainer.MutablePicoContainer;
21+
import org.xml.sax.SAXException;
22+
2123
import java.util.List;
2224
import javax.xml.namespace.QName;
2325
import org.geotools.xml.InstanceComponent;
@@ -127,4 +129,20 @@ public interface Handler {
127129
* @param child The executing child handler.
128130
*/
129131
void endChildHandler(Handler child);
132+
133+
/**
134+
* Called when a prefix mapping is registred with ParserHandler.
135+
*
136+
* @param prefix Namespace prefix.
137+
* @param uri Namespace uri.
138+
*
139+
*/
140+
void startPrefixMapping (String prefix, String uri) throws SAXException;
141+
142+
/**
143+
* Called when a prefix mapping is de-registred with ParserHandler.
144+
*
145+
* @param prefix Namespace prefix.
146+
*/
147+
void endPrefixMapping (String prefix) throws SAXException;
130148
}

modules/extension/xsd/xsd-core/src/main/java/org/geotools/xml/impl/HandlerImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.geotools.xml.impl;
1818

1919
import org.picocontainer.MutablePicoContainer;
20+
import org.xml.sax.SAXException;
2021

2122

2223
/**
@@ -34,4 +35,12 @@ public MutablePicoContainer getContext() {
3435
public void setContext(MutablePicoContainer context) {
3536
this.context = context;
3637
}
38+
39+
@Override
40+
public void startPrefixMapping(String prefix, String uri) throws SAXException {
41+
}
42+
43+
@Override
44+
public void endPrefixMapping(String prefix) throws SAXException {
45+
}
3746
}

modules/extension/xsd/xsd-core/src/main/java/org/geotools/xml/impl/ParserHandler.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
22+
import java.util.Enumeration;
2223
import java.util.Iterator;
2324
import java.util.List;
2425
import java.util.Map;
@@ -236,6 +237,10 @@ public List<URIHandler> getURIHandlers() {
236237
public void startPrefixMapping(String prefix, String uri)
237238
throws SAXException {
238239
namespaces.declarePrefix(prefix, uri);
240+
if (!handlers.isEmpty()) {
241+
Handler h = (Handler) handlers.peek();
242+
h.startPrefixMapping(prefix, uri);
243+
}
239244
}
240245

241246
public void startDocument() throws SAXException {
@@ -546,7 +551,16 @@ public void startElement(String uri, String localName, String qName, Attributes
546551
if (canHandle) {
547552
//found one
548553
handler = new DelegatingHandler( delegate, qualifiedName, parent );
549-
((DelegatingHandler)handler).startDocument();
554+
555+
DelegatingHandler dh = (DelegatingHandler) handler;
556+
dh.startDocument();
557+
558+
//inject the current namespace context
559+
Enumeration e = namespaces.getPrefixes();
560+
while(e.hasMoreElements()) {
561+
String pre = (String) e.nextElement();
562+
dh.startPrefixMapping(pre, namespaces.getURI(pre));
563+
}
550564
}
551565

552566
}
@@ -703,6 +717,14 @@ protected void endElementInternal(ElementHandler handler) {
703717
//do nothing
704718
}
705719

720+
@Override
721+
public void endPrefixMapping(String prefix) throws SAXException {
722+
if (!handlers.isEmpty()) {
723+
Handler h = (Handler) handlers.peek();
724+
h.endPrefixMapping(prefix);
725+
}
726+
}
727+
706728
public void endDocument() throws SAXException {
707729
validator.endDocument();
708730

modules/extension/xsd/xsd-wps/src/test/java/org/geotools/wps/ExecuteTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@
1616
*/
1717
package org.geotools.wps;
1818

19+
import javax.xml.namespace.QName;
20+
1921
import junit.framework.TestCase;
2022
import net.opengis.ows11.CodeType;
2123
import net.opengis.ows11.LanguageStringType;
2224
import net.opengis.ows11.Ows11Factory;
25+
import net.opengis.wfs.GetFeatureType;
26+
import net.opengis.wfs.QueryType;
2327
import net.opengis.wps10.ComplexDataType;
2428
import net.opengis.wps10.DataInputsType1;
2529
import net.opengis.wps10.DataType;
2630
import net.opengis.wps10.ExecuteResponseType;
2731
import net.opengis.wps10.ExecuteType;
32+
import net.opengis.wps10.InputReferenceType;
2833
import net.opengis.wps10.InputType;
2934
import net.opengis.wps10.OutputDataType;
3035
import net.opengis.wps10.ProcessOutputsType1;
3136
import net.opengis.wps10.Wps10Factory;
3237

3338
import org.geotools.xml.Encoder;
39+
import org.geotools.xml.Parser;
3440

3541
import com.vividsolutions.jts.geom.Coordinate;
3642
import com.vividsolutions.jts.geom.GeometryFactory;
@@ -94,4 +100,23 @@ public void testExecuteResponse() throws Exception {
94100
e.setIndenting(true);
95101
e.encode(response, WPS.ExecuteResponse, System.out);
96102
}
103+
104+
public void testParserDelegateNamespaces() throws Exception {
105+
Parser p = new Parser(new WPSConfiguration());
106+
ExecuteType exec = (ExecuteType)
107+
p.parse(getClass().getResourceAsStream("wpsExecute_inlineGetFeature_request.xml"));
108+
assertNotNull(exec);
109+
assertEquals(1, exec.getDataInputs().getInput().size());
110+
111+
InputType in = (InputType) exec.getDataInputs().getInput().get(0);
112+
InputReferenceType ref = in.getReference();
113+
assertNotNull(ref);
114+
115+
assertTrue(ref.getBody() instanceof GetFeatureType);
116+
GetFeatureType gft = (GetFeatureType) ref.getBody();
117+
118+
QName typeName = (QName) ((QueryType)gft.getQuery().get(0)).getTypeName().get(0);
119+
assertEquals("states", typeName.getLocalPart());
120+
assertEquals("http://usa.org", typeName.getNamespaceURI());
121+
}
97122
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?><wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
2+
<ows:Identifier>gs:Centroid</ows:Identifier>
3+
<wps:DataInputs>
4+
<wps:Input>
5+
<ows:Identifier>features</ows:Identifier>
6+
<wps:Reference mimeType="text/xml; subtype=wfs-collection/1.0" xlink:href="http://geoserver/wfs" method="POST">
7+
<wps:Body>
8+
<wfs:GetFeature xmlns:usa="http://usa.org" service="WFS" version="1.0.0" outputFormat="GML2">
9+
<wfs:Query typeName="usa:states"/>
10+
</wfs:GetFeature>
11+
</wps:Body>
12+
</wps:Reference>
13+
</wps:Input>
14+
</wps:DataInputs>
15+
<wps:ResponseForm>
16+
<wps:RawDataOutput mimeType="application/json">
17+
<ows:Identifier>result</ows:Identifier>
18+
</wps:RawDataOutput>
19+
</wps:ResponseForm>
20+
</wps:Execute>

0 commit comments

Comments
 (0)