csw_patch.diff

Cesar Martinez Izquierdo, 10/03/2012 06:09 PM

Download (16.7 KB)

View differences:

src/es/gva/cit/catalog/csw/parsers/CSWConstants.java (working copy)
67 67
	public static final String OPERATIONS_METADATA= "OperationsMetadata";
68 68
	public static final String SERVICE_TYPE_VERSION = "ServiceTypeVersion";
69 69
	
70
	// Capabilities 2.0.1
71
	public static final String VERSION_2_0_2 = "2.0.2";
72
	public static final String CONSTRAINT_VERSION_2_0_2 = "1.1.0";
73
	
70 74
	//Service identification
71 75
	public static final String TITLE = "Title";	
72 76
	public static final String ABSTRACT = "Abstract";
src/es/gva/cit/catalog/csw/drivers/CSWCatalogServiceDriver.java (working copy)
45 45
import java.net.URL;
46 46
import java.util.Collection;
47 47

  
48
import org.apache.log4j.Logger;
49

  
48 50
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
49 51

  
50 52
import es.gva.cit.catalog.csw.drivers.profiles.CSWAbstractProfile;
......
121 123
					firstRecord);
122 124
		} catch (NotSupportedVersionException e) {
123 125
			//This exception never will be thrown
126
			Logger.getLogger(this.getClass()).error("Unsupported protocol version", e);
124 127
		}           	
125 128
		
126 129
		if (nodes == null) 
src/es/gva/cit/catalog/csw/messages/CSWMessagesFactory.java (working copy)
65 65
		messages.put(CSWConstants.VERSION_0_9_0, CSWMessages0_9_0.class);
66 66
		messages.put(CSWConstants.VERSION_2_0_0, CSWMessages2_0_0.class);
67 67
		messages.put(CSWConstants.VERSION_2_0_1, CSWMessages2_0_1.class);
68
		messages.put(CSWConstants.VERSION_2_0_2, CSWMessages2_0_2.class);
68 69
	}
69 70
	
70 71
	/**
src/es/gva/cit/catalog/csw/messages/CSWAbstractMessages.java (working copy)
130 130
				":" + CSWConstants.CSW_GET_RECORDS);
131 131
		buffer.append(" " + CSWConstants.CSW_SERVICE + "=\"" + ServerData.SERVER_SUBTYPE_CATALOG_CSW + "\" ");
132 132
		buffer.append(CSWConstants.CSW_VERSION + "=\"" + capabilities.getVersion() + "\" ");
133
		buffer.append(CatalogConstants.XML_NS + "=\"" +CSWConstants.CSW_NAMESPACE_URI + "\" ");
133
		buffer.append(CatalogConstants.XML_NS + "=\"" + getCswNamespace() + "\" ");
134 134
		buffer.append(CatalogConstants.XML_NS + ":" + CSWConstants.CSW_NAMESPACE + 
135
				"=\"" + CSWConstants.CSW_NAMESPACE_URI + "\" ");
135
				"=\"" + getCswNamespace() + "\" ");
136 136
		buffer.append(CatalogConstants.XML_NS + ":" + CSWConstants.OGC_NAMESPACE + 
137 137
				"=\"" + CSWConstants.OGC_NAMESPACE_URI + "\" ");
138 138
		buffer.append(CatalogConstants.XML_NS + ":" + CSWConstants.GML_NAMESPACE + 
......
155 155
	}
156 156

  
157 157
	/**
158
	 * Returns a common reslut type if the getCapabilities doesn't have
159
	 * one. Sometimes it works.
158
	 * Returns a common result type if the getCapabilities doesn't have
159
	 * one. If several result types are available, prefer "results" type.
160
	 * Otherwise, return the first available one. If none is declared, return
161
	 * "results" type, which sometimes works.
160 162
	 * 
161 163
	 * 
162 164
	 * @return Just one String
163 165
	 * @param resultType The array of result types parsed.
164 166
	 */
165 167
	protected String getResultType(String[] resultType) {        
166
		if (resultType == null)
168
		if (resultType == null || resultType.length==0)
167 169
			return "results";
168

  
169 170
		for (int i=0 ; i<resultType.length ; i++){
170

  
171
			if (resultType[i].toLowerCase().equals("results")) {
172
				return resultType[i];
173
			}
171 174
		}
172 175
		return resultType[0];
173 176
	} 
......
338 341
			return false;
339 342

  
340 343
		return true; 
341
	} 
344
	}
345
	
346
	protected String getCswNamespace() {
347
		return CSWConstants.CSW_NAMESPACE_URI;
348
	}
342 349
}
src/es/gva/cit/catalog/csw/messages/CSWMessages2_0_2.java (revision 0)
1
package es.gva.cit.catalog.csw.messages;
2

  
3
import com.iver.utiles.swing.jcomboServer.ServerData;
4

  
5
import es.gva.cit.catalog.csw.drivers.profiles.CSWAbstractProfile;
6
import es.gva.cit.catalog.csw.parsers.CSWConstants;
7
import es.gva.cit.catalog.utils.CatalogConstants;
8

  
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id$
52
 * $Log$
53
 *
54
 */
55
/**
56
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
57
 */
58
public class CSWMessages2_0_2 extends CSWAbstractMessages{
59
	public static final String CSW_NAMESPACE_URI = "http://www.opengis.net/cat/csw/2.0.2";
60
	
61
	public CSWMessages2_0_2(CSWAbstractProfile profile) {
62
		super(profile);		
63
	}
64

  
65
	/*
66
	 * (non-Javadoc)
67
	 * @see es.gva.cit.catalog.csw.messages.CSWAbstractMessages#getContraintVersion()
68
	 */
69
	protected String getContraintVersion() {
70
		return CSWConstants.CONSTRAINT_VERSION_2_0_2;
71
	}
72

  
73
	protected String getCswNamespace() {
74
		return CSW_NAMESPACE_URI;
75
	}
76

  
77
}
src/es/gva/cit/catalog/protocols/HTTPPostProtocol.java (working copy)
40 40
*   dac@iver.es
41 41
*/
42 42
package es.gva.cit.catalog.protocols;
43
import java.io.BufferedReader;
43 44
import java.io.ByteArrayInputStream;
44 45
import java.io.File;
45 46
import java.io.FileOutputStream;
46 47
import java.io.IOException;
47 48
import java.io.InputStream;
49
import java.io.InputStreamReader;
48 50
import java.io.OutputStreamWriter;
49 51
import java.net.HttpURLConnection;
50 52
import java.net.URL;
51 53
import java.util.Collection;
52 54

  
55
import org.apache.log4j.Logger;
56

  
57
import com.iver.utiles.xml.XMLEncodingUtils;
58

  
59
import es.gva.cit.catalog.metadataxml.XMLNode;
53 60
import es.gva.cit.catalog.metadataxml.XMLTree;
54
import es.gva.cit.catalog.utils.Strings;
55 61

  
56 62
/**
57 63
 * This class implement the HTTP Post protocol.
......
61 67
 */
62 68
public class HTTPPostProtocol implements IProtocols {
63 69

  
70
	private static Logger logger = Logger.getLogger(HTTPPostProtocol.class);
64 71
/**
65 72
 * @return 
66 73
 * @param url 
67 74
 * @param message 
68 75
 * @param firstRecord 
69 76
 */
70
    public Collection doQuery(URL url, Object message, int firstRecord) {        
71
        String body = (String) message;
72
        ByteArrayInputStream output = null;
73
            
74
        try {
75
            HttpURLConnection c = (HttpURLConnection) url.openConnection();
76
            
77
         c.setRequestProperty("SOAPAction","post");
78
         c.setRequestMethod("POST");
79
         c.setDoOutput(true);
80
         c.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
81
                 
82
        // Write the request.
83
        OutputStreamWriter w =
84
            new OutputStreamWriter(c.getOutputStream(), "UTF-8");
85
        
86
        w.write(body);
87
        w.flush();
88
              
89
        InputStream is = c.getInputStream();
90
        byte[] buf = new byte[1024];
91
        int len;
92
        String str = "";
93
        
94
        while ((len = is.read(buf)) > 0) {
95
            str = str + new String(buf, 0, len);
96
        }
97
            
98
        str = Strings.replace(str,
99
				  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
100
		  "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
101
        System.out.println(str);
102
        output = new ByteArrayInputStream(str.getBytes());
103
            
104
        }  catch (IOException e) {
105
            // TODO Auto-generated catch block
106
            //e.printStackTrace();
107
            return null;
108
        } 
109
        
110
        Collection col = new java.util.ArrayList();
111
        col.add(XMLTree.xmlToTree(output));
112
        return col;            
113
    }    
77
	public Collection doQuery(URL url, Object message, int firstRecord) {        
78
		String body = (String) message;
79
		Collection col = new java.util.ArrayList();;
80
		try {
81
			HttpURLConnection c = (HttpURLConnection) url.openConnection();
114 82

  
83
			c.setRequestProperty("SOAPAction","post");
84
			c.setRequestMethod("POST");
85
			c.setDoOutput(true);
86
			c.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
87

  
88
			// Write the request.
89
			OutputStreamWriter w =
90
					new OutputStreamWriter(c.getOutputStream(), "UTF-8");
91

  
92
			w.write(body);
93
			w.flush();
94

  
95
			if (logger.isDebugEnabled()) {
96
				// read the stream as a String to allow logging it before parsing it to XMLTree object
97
				InputStream is = c.getInputStream();
98
				char[] buf = new char[1024];
99
				int len;
100
				StringBuilder strBuilder = new StringBuilder();
101

  
102
				XMLEncodingUtils xmlEnc = new XMLEncodingUtils(is);
103
				InputStreamReader isReader = xmlEnc.getReader();
104
				String encoding = isReader.getEncoding();
105
				BufferedReader bufReader = new BufferedReader(isReader);
106
				strBuilder.append(xmlEnc.getBytesRead());
107

  
108
				while ((len = bufReader.read(buf))>0) {
109
					strBuilder.append(buf, 0, len);
110
				}
111

  
112
				String str = strBuilder.toString();
113
				System.out.println(str);
114
				ByteArrayInputStream output = new ByteArrayInputStream(str.getBytes(encoding));
115

  
116
				col.add(XMLTree.xmlToTree(output));
117
			}
118
			else {
119
				// when no logging is necessary, we can directly pass the connection IS to the parser, which will deal with encodings
120
				XMLNode node = XMLTree.xmlToTree(c.getInputStream());
121
				col.add(node);
122
			}
123
		}  catch (IOException e) {
124
			logger.error(e.getMessage(), e);
125
		} 
126
		return col;            
127
	}    
128

  
115 129
    public void doQuery(URL url, Object message, int firstRecord, String fileName) {        
116 130
    	String body = (String) message;
117 131
    	FileOutputStream output = null;
......
147 161
    	
148 162
    		
149 163
    	}  catch (IOException e) {
150
    		e.printStackTrace();           
164
    		logger.error(e.getMessage(), e);    
151 165
    	}           
152 166
             
153 167
    }    
src/com/iver/utiles/xml/XMLEncodingUtils.java (working copy)
53 53
import java.io.InputStream;
54 54
import java.io.InputStreamReader;
55 55
import java.io.UnsupportedEncodingException;
56
import java.nio.charset.Charset;
56 57

  
57 58
/**
58 59
 * A set of methods to detect XML encoding. The class is able to autodetect
......
62 63
 *
63 64
 */
64 65
public class XMLEncodingUtils {
65
	InputStream _is;
66
	protected InputStream _is;
67
	protected String bytesRead = null;
66 68
	
67 69
	/**
68 70
	 * Creates a new XMLEncodingUtils object.
......
185 187
		catch (IOException ex) {
186 188
			return null;
187 189
		}
190

  
188 191
		return enc;
189 192
	}
190 193
	
191 194
	/**
195
	 * Gets the encoding of the XML file.
196
	 * 
197
	 * The following encodings can be detected: UTF-32BE, UTF-32LE,
198
	 * UTF-16BE, UTF-16-LE, UTF-8. The rest of the encodings are
199
	 * read from the XML header.
200
	 * 
201
	 * @return Returns the encoding of the XML file, or null if the
202
	 * encoding couldn't be correctly detected or read from the XML
203
	 * header.
204
	 */
205
	private String getEncodingSavingBytes() {
206
		int srcCount = 0;
207
		String enc=null;
208
		char[] srcBuf = new char[128];
209
		
210
		// read four bytes 
211
		int chk = 0;
212
		try {
213
			while (srcCount < 4) {
214
				int i = _is.read();
215
				if (i == -1)
216
					break;
217
				chk = (chk << 8) | i;
218
				srcBuf[srcCount++] = (char) i;
219
			}
220
			
221
			if (srcCount == 4) {
222
				switch (chk) {
223
				case 0x00000FEFF :
224
					enc = "UTF-32BE";
225
					srcCount = 0;
226
					break;
227
					
228
				case 0x0FFFE0000 :
229
					enc = "UTF-32LE";
230
					srcCount = 0;
231
					break;
232
					
233
				case 0x03c :
234
					enc = "UTF-32BE";
235
					srcBuf[0] = '<';
236
					srcCount = 1;
237
					break;
238
					
239
				case 0x03c000000 :
240
					enc = "UTF-32LE";
241
					srcBuf[0] = '<';
242
					srcCount = 1;
243
					break;
244
					
245
				case 0x0003c003f :
246
					enc = "UTF-16BE";
247
					srcBuf[0] = '<';
248
					srcBuf[1] = '?';
249
					srcCount = 2;
250
					break;
251
					
252
				case 0x03c003f00 :
253
					enc = "UTF-16LE";
254
					srcBuf[0] = '<';
255
					srcBuf[1] = '?';
256
					srcCount = 2;
257
					break;
258
					
259
				case 0x03c3f786d :
260
					while (true) {
261
						int i = _is.read();
262
						if (i == -1)
263
							break;
264
						srcBuf[srcCount++] = (char) i;
265
						if (i == '>') {
266
							String s = new String(srcBuf, 0, srcCount);
267
							int i0 = s.indexOf("encoding");
268
							if (i0 != -1) {
269
								while (s.charAt(i0) != '"'
270
									&& s.charAt(i0) != '\'')
271
									i0++;
272
								char deli = s.charAt(i0++);
273
								int i1 = s.indexOf(deli, i0);
274
								enc = s.substring(i0, i1);
275
							}
276
							break;
277
						}
278
					}
279
					
280
				default :
281
					if ((chk & 0x0ffff0000) == 0x0FEFF0000) {
282
						enc = "UTF-16BE";
283
						srcBuf[0] =
284
							(char) ((srcBuf[2] << 8) | srcBuf[3]);
285
						srcCount = 1;
286
					}
287
					else if ((chk & 0x0ffff0000) == 0x0fffe0000) {
288
						enc = "UTF-16LE";
289
						srcBuf[0] =
290
							(char) ((srcBuf[3] << 8) | srcBuf[2]);
291
						srcCount = 1;
292
					}
293
					else if ((chk & 0x0ffffff00) == 0x0EFBBBF00) {
294
						enc = "UTF-8";
295
						srcBuf[0] = srcBuf[3];
296
						srcCount = 1;
297
					}
298
				}
299
			}
300
		}
301
		catch (IOException ex) {
302
			return null;
303
		}
304
		
305
		if (!enc.equals(Charset.defaultCharset())) {
306
			/**
307
			 * Now we need to convert back the read chars to bytes, to read
308
			 * them again as String using the right character set
309
			 */
310
			byte[] bytes = new byte[srcBuf.length];
311
			for(int i = 0; i < srcBuf.length; i++) {
312
				bytes[i] = (byte) srcBuf[i];
313
			}
314
			try {
315
				bytesRead = new String(bytes, 0, srcCount, enc);
316
			} catch (UnsupportedEncodingException e) {
317
				// TODO Auto-generated catch block
318
				e.printStackTrace();
319
			}
320
		}
321
		return enc;
322
	}
323
	
324
	/**
325
	 * Some bytes are read to detect the encoding. Those bytes are not
326
	 * available on the reader anymore, so they are stored and made available
327
	 * on this method.
328
	 * 
329
	 * @return
330
	 */
331
	public String getBytesRead() {
332
		return bytesRead;
333
	}
334
	
335
	/**
192 336
	 * Gets an InputStreamReader for the provided XML file.
193 337
	 * The reader uses the right encoding, as specified in
194 338
	 * the XML header (or autodetected). 
......
198 342
	 * from the XML header.
199 343
	 */
200 344
	public InputStreamReader getReader() {
201
		String encoding = getEncoding();
345
		String encoding = getEncodingSavingBytes();
202 346
		if (encoding==null)
203 347
			return null;
204 348
		try {
src/es/gva/cit/gvsig/catalog/loaders/WCSLayerLoader.java (working copy)
46 46

  
47 47
import org.gvsig.i18n.Messages;
48 48

  
49
import com.iver.andami.PluginServices;
49 50
import com.iver.cit.gvsig.fmap.layers.FLayer;
51
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
50 52
import com.iver.utiles.extensionPoints.ExtensionPoint;
51 53
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
52 54

  
......
122 124
		if ((name != null) && (!name.equals(""))){
123 125
			map.put("COVERAGE",name);
124 126
		}
127
		BaseView activeView = 
128
				(BaseView) PluginServices.getMDIManager().getActiveWindow();
129
		map.put("CRS", activeView.getProjection().getAbrev());
130
		map.put("FORMAT", "GEOTIFF");
125 131
		return map;
126 132
	}	
127 133