
org.geoserver.wfs.response.TransactionResponse Maven / Gradle / Ivy
The newest version!
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.geoserver.wfs.response;
import net.opengis.wfs.ActionType;
import net.opengis.wfs.GetFeatureType;
import net.opengis.wfs.InsertResultsType;
import net.opengis.wfs.InsertedFeatureType;
import net.opengis.wfs.TransactionResponseType;
import net.opengis.wfs.TransactionResultsType;
import net.opengis.wfs.TransactionType;
import org.geoserver.ows.Response;
import org.geoserver.ows.util.RequestUtils;
import org.geoserver.ows.util.ResponseUtils;
import org.geoserver.platform.Operation;
import org.geoserver.platform.ServiceException;
import org.geoserver.wfs.WFS;
import org.geoserver.wfs.WFSException;
import org.geoserver.wfs.xml.v1_1_0.WFSConfiguration;
import org.geotools.util.Version;
import org.geotools.xml.Encoder;
import org.opengis.filter.identity.FeatureId;
import org.vfny.geoserver.global.Data;
import org.xml.sax.SAXException;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Iterator;
public class TransactionResponse extends WFS10Response {
private boolean verbose = false;
private String indent = " ";
private String offset = "";
WFS wfs;
Data catalog;
public TransactionResponse(WFS wfs, Data catalog) {
super(TransactionResponseType.class);
this.wfs = wfs;
this.catalog = catalog;
}
public String getMimeType(Object value, Operation operation)
throws ServiceException {
return "text/xml";
}
public void write(Object value, OutputStream output, Operation operation)
throws IOException, ServiceException {
TransactionResponseType response = (TransactionResponseType) value;
v_1_0(response, output, operation);
}
public void v_1_0(TransactionResponseType response, OutputStream output, Operation operation)
throws IOException, ServiceException {
TransactionResultsType result = response.getTransactionResults();
Writer writer = new OutputStreamWriter(output, wfs.getCharSet());
writer = new BufferedWriter(writer);
//boolean verbose = ConfigInfo.getInstance().formatOutput();
//String indent = ((verbose) ? "\n" + OFFSET : " ");
String encoding = wfs.getCharSet().name();
String xmlHeader = "";
writer.write(xmlHeader);
if (verbose) {
writer.write("\n");
}
writer.write("");
InsertResultsType insertResults = response.getInsertResults();
//JD: make sure we group insert results by handle, this is wfs 1.0 cite
// thing that conflicts with wfs 1.1 cite, i am pretty sure its just a
// problem with the 1.0 tests
String lastHandle = null;
boolean first = true;
if (insertResults != null) {
for (Iterator i = insertResults.getFeature().iterator(); i.hasNext();) {
InsertedFeatureType insertedFeature = (InsertedFeatureType) i.next();
String handle = insertedFeature.getHandle();
if (first || ((lastHandle == null) && (handle != null))
|| ((lastHandle != null) && (handle != null) && handle.equals(lastHandle))) {
if (!first) {
//close last one, if not the first time through
writer.write("");
}
writer.write("");
}
for (Iterator id = insertedFeature.getFeatureId().iterator(); id.hasNext();) {
FeatureId featureId = (FeatureId) id.next();
writer.write(" ");
}
first = false;
lastHandle = handle;
}
writer.write(" ");
}
writer.write(indent + "");
writer.write(indent + offset + "");
writer.write(indent + offset + offset);
//if there is an actino, that means we failed
if (!result.getAction().isEmpty()) {
writer.write(" ");
} else {
writer.write(" ");
}
writer.write(indent + offset + " ");
if (!result.getAction().isEmpty()) {
ActionType action = (ActionType) result.getAction().get(0);
if (action.getLocator() != null) {
writer.write(indent + offset + "");
writer.write(action.getLocator() + " ");
}
if (action.getMessage() != null) {
writer.write(indent + offset + "");
ResponseUtils.writeEscapedString(writer, action.getMessage());
writer.write(" ");
}
}
writer.write(indent + " ");
if (verbose) {
writer.write("\n");
}
writer.write(" ");
writer.flush();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy