svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wfs / wfs_1_0_0 / request / WFSTransactionRequest1_0_0.java @ 40559
History | View | Annotate | Download (7.71 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.wfs_1_0_0.request; |
25 |
|
26 |
import java.util.Iterator; |
27 |
|
28 |
import org.gvsig.remoteclient.utils.CapabilitiesTags; |
29 |
import org.gvsig.remoteclient.wfs.WFSProtocolHandler; |
30 |
import org.gvsig.remoteclient.wfs.WFSStatus; |
31 |
import org.gvsig.remoteclient.wfs.edition.IWFSTOperation; |
32 |
import org.gvsig.remoteclient.wfs.edition.WFSTInsertOperation; |
33 |
import org.gvsig.remoteclient.wfs.edition.WFSTTags; |
34 |
import org.gvsig.remoteclient.wfs.edition.WFSTTransaction; |
35 |
import org.gvsig.remoteclient.wfs.edition.WFSTUpdateOperation; |
36 |
import org.gvsig.remoteclient.wfs.filters.filterencoding.FilterEncoding; |
37 |
import org.gvsig.remoteclient.wfs.request.WFSTransactionRequest; |
38 |
|
39 |
|
40 |
/**
|
41 |
* @author gvSIG Team
|
42 |
* @version $Id$
|
43 |
*
|
44 |
*/
|
45 |
public class WFSTransactionRequest1_0_0 extends WFSTransactionRequest{ |
46 |
|
47 |
/**
|
48 |
* @param status
|
49 |
* @param protocolHandler
|
50 |
*/
|
51 |
public WFSTransactionRequest1_0_0(WFSStatus status,
|
52 |
WFSProtocolHandler protocolHandler) { |
53 |
super(status, protocolHandler);
|
54 |
} |
55 |
|
56 |
protected String getHttpGetRequest(String onlineResource) { |
57 |
// TODO Auto-generated method stub
|
58 |
return null; |
59 |
} |
60 |
|
61 |
protected String getHttpPostRequest(String onlineResource) { |
62 |
StringBuffer request = new StringBuffer(); |
63 |
addHttpPostHeaderRequest(request); |
64 |
//Add the operations
|
65 |
WFSTTransaction transaction = status.getTransaction(); |
66 |
|
67 |
//Insert operations
|
68 |
for (int i=0 ; i<transaction.getInsertOperationSize() ; i++){ |
69 |
addInsertOperation(transaction.getInseOperationAt(i), request); |
70 |
} |
71 |
|
72 |
//Update operations
|
73 |
for (int i=0 ; i<transaction.getUpdateOperationSize() ; i++){ |
74 |
addUpdateOperation(transaction.getUpdateOperationAt(i), request); |
75 |
} |
76 |
|
77 |
//Delete operations. All of them in just one operation
|
78 |
if (transaction.getDeleteOperationSize() > 0){ |
79 |
IWFSTOperation firstOperation = transaction.getDeleteOperationAt(0);
|
80 |
addOperationHeader(firstOperation, request); |
81 |
|
82 |
FilterEncoding filterEncoding = new FilterEncoding(status);
|
83 |
filterEncoding.setQualified(true);
|
84 |
for (int i=0 ; i<transaction.getDeleteOperationSize() ; i++){ |
85 |
filterEncoding.addFeatureById(transaction.getDeleteOperationAt(i).getId()); |
86 |
} |
87 |
request.append(filterEncoding.toString(protocolHandler.getVersion())); |
88 |
addOperationEnd(firstOperation, request); |
89 |
} |
90 |
addHttpPostEndRequest(request); |
91 |
return request.toString();
|
92 |
} |
93 |
|
94 |
private void addOperationHeader(IWFSTOperation operation, StringBuffer request){ |
95 |
request.append("<" + CapabilitiesTags.WFS_NAMESPACE_PREFIX + ":"); |
96 |
request.append(operation.getOperationName()); |
97 |
if (operation.hasTypeName()){
|
98 |
request.append(" typeName=\"" + status.getFeatureFullName() + "\""); |
99 |
} |
100 |
request.append(">");
|
101 |
} |
102 |
|
103 |
private void addOperationEnd(IWFSTOperation operation, StringBuffer request){ |
104 |
request.append("</" + CapabilitiesTags.WFS_NAMESPACE_PREFIX + ":"); |
105 |
request.append(operation.getOperationName() + ">");
|
106 |
} |
107 |
|
108 |
private void addInsertOperation(WFSTInsertOperation insertOperation, StringBuffer request){ |
109 |
addOperationHeader(insertOperation, request); |
110 |
request.append(createXMLStartTag(status.getFeatureFullName())); |
111 |
Iterator it = insertOperation.getKeysIterator();
|
112 |
while (it.hasNext()){
|
113 |
String attName = (String)it.next(); |
114 |
request.append(createXMLStartTag(status.getNamespacePrefix() + ":" + attName));
|
115 |
request.append(insertOperation.getValue(attName)); |
116 |
request.append(createXMLEndtTag(status.getNamespacePrefix() + ":" + attName));
|
117 |
} |
118 |
request.append(createXMLEndtTag(status.getFeatureFullName())); |
119 |
addOperationEnd(insertOperation, request); |
120 |
} |
121 |
|
122 |
private void addUpdateOperation(WFSTUpdateOperation updateOperation, StringBuffer request){ |
123 |
addOperationHeader(updateOperation, request); |
124 |
Iterator it = updateOperation.getKeysIterator();
|
125 |
while (it.hasNext()){
|
126 |
String attName = (String)it.next(); |
127 |
request.append(createXMLStartTag(UPDATE_PROPERTY_TAG)); |
128 |
request.append(createXMLStartTag(UPDATE_NAME_TAG)); |
129 |
request.append(status.getNamespacePrefix() + ":" + attName);
|
130 |
request.append(createXMLEndtTag(UPDATE_NAME_TAG)); |
131 |
request.append(createXMLStartTag(UPDATE_VALUE_TAG)); |
132 |
request.append(updateOperation.getValue(attName)); |
133 |
request.append(createXMLEndtTag(UPDATE_VALUE_TAG)); |
134 |
request.append(createXMLEndtTag(UPDATE_PROPERTY_TAG)); |
135 |
} |
136 |
//Add the filter encoding
|
137 |
FilterEncoding filterEncoding = new FilterEncoding(status);
|
138 |
filterEncoding.setQualified(true);
|
139 |
filterEncoding.addFeatureById(updateOperation.getId()); |
140 |
request.append(filterEncoding.toString(protocolHandler.getVersion())); |
141 |
addOperationEnd(updateOperation, request); |
142 |
} |
143 |
|
144 |
private void addHttpPostHeaderRequest(StringBuffer request){ |
145 |
request.append(WFSTTags.XML_ROOT); |
146 |
request.append("<" + WFSTTags.WFS_NAMESPACE_PREFIX + ":"); |
147 |
request.append(CapabilitiesTags.WFS_TRANSACTION + " ");
|
148 |
request.append(CapabilitiesTags.VERSION + "=\"" + protocolHandler.getVersion() + "\" "); |
149 |
request.append(WFSTTags.WFST_RELEASEACTION + "=\"ALL\" ");
|
150 |
request.append(WFSTTags.WFST_SERVICE + "=\"WFS\" ");
|
151 |
request.append(WFSTTags.XMLNS + ":" + WFSTTags.OGC_NAMESPACE_PREFIX);
|
152 |
request.append("=\"" + WFSTTags.OGC_NAMESPACE + "\" "); |
153 |
request.append(WFSTTags.XMLNS + ":" + WFSTTags.WFS_NAMESPACE_PREFIX);
|
154 |
request.append("=\"" + WFSTTags.WFS_NAMESPACE + "\" "); |
155 |
request.append(WFSTTags.XMLNS + ":" + WFSTTags.XML_NAMESPACE_PREFIX);
|
156 |
request.append("=\"" + WFSTTags.XML_NAMESPACE + "\" "); |
157 |
request.append(WFSTTags.XMLNS + ":" + WFSTTags.GML_NAMESPACE_PREFIX);
|
158 |
request.append("=\"" + WFSTTags.GML_NAMESPACE + "\" "); |
159 |
request.append(WFSTTags.XMLNS + ":" + status.getNamespacePrefix());
|
160 |
request.append("=\"" + status.getNamespaceLocation() + "\" "); |
161 |
request.append(WFSTTags.XML_NAMESPACE_PREFIX + ":" + WFSTTags.XML_SCHEMALOCATION);
|
162 |
request.append("=\"" + WFSTTags.WFS_NAMESPACE + " "); |
163 |
request.append(getSchemaLocation()); |
164 |
request.append("\">");
|
165 |
} |
166 |
|
167 |
private void addHttpPostEndRequest(StringBuffer request){ |
168 |
request.append("</" + WFSTTags.WFS_NAMESPACE_PREFIX + ":"); |
169 |
request.append(CapabilitiesTags.WFS_TRANSACTION + ">");
|
170 |
} |
171 |
|
172 |
protected String getSchemaLocation() { |
173 |
return "../wfs/1.0.0/WFS-transaction.xsd"; |
174 |
} |
175 |
} |