Skip to content

Commit

Permalink
ensuring that parser delegates rinheirent namespace prefix mappings, …
Browse files Browse the repository at this point in the history
…see GEOS-5298
  • Loading branch information
jdeolive committed Sep 7, 2012
1 parent 34aae55 commit 619ea24
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public void endDocument() throws SAXException {
delegate.endDocument();
}

@Override
public void startPrefixMapping(String prefix, String uri) throws SAXException {
delegate.startPrefixMapping(prefix, uri);
}

public void startElement(QName name, Attributes attributes)
throws SAXException {

Expand All @@ -123,7 +128,11 @@ public void characters(char[] ch, int start, int length)
public void endElement(QName name) throws SAXException {
delegate.endElement( name.getNamespaceURI(), name.getLocalPart(), qname( name ) );
}


public void endPrefixMapping(String prefix) throws SAXException {
delegate.endPrefixMapping(prefix);
}

String qname( QName name ) {
return name.getNamespaceURI() != null ? name.getPrefix() + ":" + name.getLocalPart() : name.getLocalPart();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.eclipse.xsd.XSDSchemaContent;
import org.picocontainer.MutablePicoContainer;
import org.xml.sax.SAXException;

import java.util.List;
import javax.xml.namespace.QName;
import org.geotools.xml.InstanceComponent;
Expand Down Expand Up @@ -127,4 +129,20 @@ public interface Handler {
* @param child The executing child handler.
*/
void endChildHandler(Handler child);

/**
* Called when a prefix mapping is registred with ParserHandler.
*
* @param prefix Namespace prefix.
* @param uri Namespace uri.
*
*/
void startPrefixMapping (String prefix, String uri) throws SAXException;

/**
* Called when a prefix mapping is de-registred with ParserHandler.
*
* @param prefix Namespace prefix.
*/
void endPrefixMapping (String prefix) throws SAXException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.geotools.xml.impl;

import org.picocontainer.MutablePicoContainer;
import org.xml.sax.SAXException;


/**
Expand All @@ -34,4 +35,12 @@ public MutablePicoContainer getContext() {
public void setContext(MutablePicoContainer context) {
this.context = context;
}

@Override
public void startPrefixMapping(String prefix, String uri) throws SAXException {
}

@Override
public void endPrefixMapping(String prefix) throws SAXException {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -235,6 +236,10 @@ public List<URIHandler> getURIHandlers() {
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
namespaces.declarePrefix(prefix, uri);
if (!handlers.isEmpty()) {
Handler h = (Handler) handlers.peek();
h.startPrefixMapping(prefix, uri);
}
}

public void startDocument() throws SAXException {
Expand Down Expand Up @@ -545,7 +550,16 @@ public void startElement(String uri, String localName, String qName, Attributes
if (canHandle) {
//found one
handler = new DelegatingHandler( delegate, qualifiedName, parent );
((DelegatingHandler)handler).startDocument();

DelegatingHandler dh = (DelegatingHandler) handler;
dh.startDocument();

//inject the current namespace context
Enumeration e = namespaces.getPrefixes();
while(e.hasMoreElements()) {
String pre = (String) e.nextElement();
dh.startPrefixMapping(pre, namespaces.getURI(pre));
}
}

}
Expand Down Expand Up @@ -702,6 +716,14 @@ protected void endElementInternal(ElementHandler handler) {
//do nothing
}

@Override
public void endPrefixMapping(String prefix) throws SAXException {
if (!handlers.isEmpty()) {
Handler h = (Handler) handlers.peek();
h.endPrefixMapping(prefix);
}
}

public void endDocument() throws SAXException {
validator.endDocument();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@
*/
package org.geotools.wps;

import javax.xml.namespace.QName;

import junit.framework.TestCase;
import net.opengis.ows11.CodeType;
import net.opengis.ows11.LanguageStringType;
import net.opengis.ows11.Ows11Factory;
import net.opengis.wfs.GetFeatureType;
import net.opengis.wfs.QueryType;
import net.opengis.wps10.ComplexDataType;
import net.opengis.wps10.DataInputsType1;
import net.opengis.wps10.DataType;
import net.opengis.wps10.ExecuteResponseType;
import net.opengis.wps10.ExecuteType;
import net.opengis.wps10.InputReferenceType;
import net.opengis.wps10.InputType;
import net.opengis.wps10.OutputDataType;
import net.opengis.wps10.ProcessOutputsType1;
import net.opengis.wps10.Wps10Factory;

import org.geotools.xml.Encoder;
import org.geotools.xml.Parser;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
Expand Down Expand Up @@ -94,4 +100,23 @@ public void testExecuteResponse() throws Exception {
e.setIndenting(true);
e.encode(response, WPS.ExecuteResponse, System.out);
}

public void testParserDelegateNamespaces() throws Exception {
Parser p = new Parser(new WPSConfiguration());
ExecuteType exec = (ExecuteType)
p.parse(getClass().getResourceAsStream("wpsExecute_inlineGetFeature_request.xml"));
assertNotNull(exec);
assertEquals(1, exec.getDataInputs().getInput().size());

InputType in = (InputType) exec.getDataInputs().getInput().get(0);
InputReferenceType ref = in.getReference();
assertNotNull(ref);

assertTrue(ref.getBody() instanceof GetFeatureType);
GetFeatureType gft = (GetFeatureType) ref.getBody();

QName typeName = (QName) ((QueryType)gft.getQuery().get(0)).getTypeName().get(0);
assertEquals("states", typeName.getLocalPart());
assertEquals("http://usa.org", typeName.getNamespaceURI());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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">
<ows:Identifier>gs:Centroid</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>features</ows:Identifier>
<wps:Reference mimeType="text/xml; subtype=wfs-collection/1.0" xlink:href="http://geoserver/wfs" method="POST">
<wps:Body>
<wfs:GetFeature xmlns:usa="http://usa.org" service="WFS" version="1.0.0" outputFormat="GML2">
<wfs:Query typeName="usa:states"/>
</wfs:GetFeature>
</wps:Body>
</wps:Reference>
</wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput mimeType="application/json">
<ows:Identifier>result</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>

0 comments on commit 619ea24

Please sign in to comment.