Revision 5273

View differences:

branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/WMSException.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers;
42

  
43
import com.iver.andami.PluginServices;
44

  
45
/**
46
 * Excepci?n provocada por el WMS.
47
 *
48
 * @author Vicente Caballero Navarro
49
 */
50
public class WMSException extends Exception {
51
	String message;
52
	
53
	public String getMessage() {
54
		return PluginServices.getText(this, "wms_server_error")+"\n"+format(message, 200);
55
	}
56

  
57
	/**
58
	 *
59
	 */
60
	public WMSException() {
61
		super();
62
	}
63

  
64
	/**
65
	 * Crea WMSException.
66
	 *
67
	 * @param message
68
	 */
69
	public WMSException(String message) {
70
        super();
71
        this.message = message;
72
	}
73

  
74
	/**
75
	 * Crea WMSException.
76
	 *
77
	 * @param message
78
	 * @param cause
79
	 */
80
	public WMSException(String message, Throwable cause) {
81
		super(format(message, 200), cause);
82
	}
83

  
84
	/**
85
	  * Crea WMSException.
86
	 *
87
	 * @param cause
88
	 */
89
	public WMSException(Throwable cause) {
90
		super(cause);
91
	}
92
    
93
    /**
94
     * Cuts the message text to force its lines to be shorter or equal to 
95
     * lineLength.
96
     * @param message, the message.
97
     * @param lineLength, the max line length in number of characters.
98
     * @return the formated message.
99
     */
100
    private static String format(String message, int lineLength){
101
        if (message.length() <= lineLength) return message;
102
        String[] lines = message.split("\n");
103
        String theMessage = "";
104
        for (int i = 0; i < lines.length; i++) {
105
            String line = lines[i].trim();
106
            if (line.length()<lineLength)
107
                theMessage += line+"\n";
108
            else {
109
                String[] chunks = line.split(" ");
110
                String newLine = "";
111
                for (int j = 0; j < chunks.length; j++) {
112
                    int currentLength = newLine.length();
113
                    chunks[j] = chunks[j].trim();
114
                    if (chunks[j].length()==0)
115
                        continue;
116
                    if ((currentLength + chunks[j].length() + " ".length()) <= lineLength)
117
                        newLine += chunks[j] + " ";
118
                    else {
119
                        newLine += "\n"+chunks[j]+" ";
120
                        theMessage += newLine;
121
                        newLine = "";
122
                    }
123
                }
124
                
125
            }
126
        }
127
        return theMessage;
128
    }
129
}
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/WMSListener.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
/* CVS MESSAGES:
43
*
44
* $Id$
45
* $Log$
46
* Revision 1.1.2.3  2006-05-18 17:20:42  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.1.2.2  2006/05/17 17:21:06  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1.2.1  2006/05/16 17:09:37  jaume
53
* *** empty log message ***
54
*
55
*
56
*/
57
package com.iver.cit.gvsig.fmap.drivers;
58

  
59
import java.io.File;
60

  
61
public interface WMSListener {
62
	public abstract void getMap(int eventType, File mapFile, String message);
63
	public abstract void getCapabilities(int eventType, String message);
64
	public abstract void getFeatureInfo(int eventType, String message);
65
}
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/WMSDriver.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers;
42

  
43
import java.io.File;
44
import java.io.IOException;
45
import java.net.ProtocolException;
46
import java.net.URL;
47

  
48
import org.gvsig.remoteClient.wms.WMSStatus;
49

  
50

  
51
/**
52
 * Interfaz Driver para WMS.
53
 *
54
 * @author $author$
55
 */
56
public interface WMSDriver {
57
	/**
58
	 * Obtiene las posibilidades del servidor a partir de una URL.
59
	 *
60
	 * @param server URL.
61
	 *
62
	 * @throws WMSException 
63
	 * @throws IOException 
64
	 * @throws ProtocolException 
65
	 */
66
	void getCapabilities(URL server)
67
		throws WMSException, IOException, ProtocolException;
68

  
69
	/**
70
	 * Devuelve la imagen a partir de MapQuery.
71
	 *
72
	 * @param mapQuery MapQuery.
73
	 *
74
	 * @return Image.
75
	 *
76
	 * @throws WMSException 
77
	 * @throws IOException 
78
	 * @throws ProtocolException 
79
	 */
80
	File getMap(WMSStatus mapQuery)
81
		throws WMSException, IOException, ProtocolException;
82

  
83
	//String getFeatureInfo(InfoQuery infoQuery) throws WMSException, IOException, ProtocolException;
84
}
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/FMapWMSDriver.java
62 62
import org.gvsig.remoteClient.wms.WMSProtocolHandler.ServiceInformation;
63 63

  
64 64
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException;
65
import com.iver.cit.gvsig.fmap.drivers.WMSDriver;
66
import com.iver.cit.gvsig.fmap.drivers.WMSException;
67
import com.iver.cit.gvsig.fmap.drivers.WMSListener;
68 65
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
69 66
/**
70 67
 * Driver WMS.
71 68
 *
72 69
 * @author Jaume Dominguez Faus
73 70
 */
74
public class FMapWMSDriver implements WMSDriver {
75
	public static final int GET_CAPABILITIES		= WMSClient.GET_CAPABILITIES;
76
	public static final int GET_MAP 				= WMSClient.GET_MAP;
77
	public static final int GET_FEATURE_INFO 		= WMSClient.GET_FEATURE_INFO;
78
	public static final int REQUEST_FINISHED 		= RetrieveEvent.REQUEST_FINISHED;
79
	public static final int REQUEST_CANCELLED 		= RetrieveEvent.REQUEST_CANCELLED;
80
	public static final int REQUEST_FAILED 			= RetrieveEvent.REQUEST_FAILED;
81
	public static final int REQUEST_STARTED 		= RetrieveEvent.CONNECTING;
82
	public static final int REQUEST_TRANSFERRING	= RetrieveEvent.TRANSFERRING;
71
public class FMapWMSDriver implements WMSEventListener {
83 72
	
73
	
84 74
	private WMSClient client;
85 75
    private WMSLayerNode fmapRootLayer;
86 76
    private TreeMap layers = new TreeMap();
87
    private ArrayList listeners = new ArrayList();
77
    private Vector listeners = new Vector();
88 78
    
89
    private WMSEventListener monitor = new WMSEventListener() {
90
    	public void newEvent(int idRequest, RetrieveEvent event) {
91
    		int eventType = event.getType();
92
    		if (idRequest == FMapWMSDriver.GET_CAPABILITIES) {
79
   
80
    public void newEvent(int idRequest, RetrieveEvent event) {
81
    	int eventType = event.getType();
82
    	if (idRequest == WMSOperations.GET_CAPABILITIES) {
83
    		
84
    		if (eventType == WMSOperations.REQUEST_FINISHED) {
85
    			WMSLayer clientRoot = client.getLayersRoot();
86
    			fmapRootLayer = parseTree(clientRoot, null);
93 87
    			
94
    			if (eventType == REQUEST_FINISHED) {
95
    				WMSLayer clientRoot = client.getLayersRoot();
96
    				fmapRootLayer = parseTree(clientRoot, null);
97
    				
98
    			}
99
    			for (int i = 0; i < listeners.size(); i++) {
100
    				WMSListener l = (WMSListener) listeners.get(i);
101
    				l.getCapabilities(eventType, event.getMessage());
102
    			}
103
    		} else if (idRequest == FMapWMSDriver.GET_MAP) {
104
    			String fileName = event.getFileName();
105
        		
106
    			for (int i = 0; i < listeners.size(); i++) {
107
    				WMSListener l = (WMSListener) listeners.get(i);
108
    				l.getMap(eventType, new File(fileName), event.getMessage());
109
    			}
110 88
    		}
89
    		for (int i = 0; i < listeners.size(); i++) {
90
    			WMSOperations l = (WMSOperations) listeners.get(i);
91
    			l.getCapabilities(eventType, event.getMessage());
92
    		}
93
    	} else if (idRequest == WMSOperations.GET_MAP) {
94
    		String fileName = event.getFileName();
95
    		System.out.println("GetMap al driver");
96
    		for (int i = 0; i < listeners.size(); i++) {
97
    			System.out.println("getMap enviat al listener: "+i);
98
    			WMSOperations l = (WMSOperations) listeners.get(i);
99
    			l.getMap(eventType, new File(fileName), event.getMessage());
100
    		}
111 101
    	}
112
    };
113
    
114
    public FMapWMSDriver(WMSListener listener) {
115
    	listeners.add(listener);
116 102
    }
117
    /*
118
     *  (non-Javadoc)
119
     * @see com.iver.cit.gvsig.fmap.drivers.WMSDriver#getCapabilities(java.net.URL)
120
     */
121
	public void getCapabilities(URL server)
122
		throws WMSException {
123
		// Unused
103
    
104
	FMapWMSDriver(URL host) {
105
		try {
106
			client = new WMSClient(host.toString(), this);
107
		} catch (ConnectException e) {
108
			e.printStackTrace();
109
		} catch (IOException e) {
110
			e.printStackTrace();
111
		}
124 112
	}
125 113

  
126 114
	/*
127 115
	 *  (non-Javadoc)
128 116
	 * @see com.iver.cit.gvsig.fmap.drivers.WMSDriver#getMap(org.gvsig.remoteClient.wms.WMSStatus)
129 117
	 */
130
    public File getMap(WMSStatus status) throws WMSException {
118
    public void getMap(WMSStatus status) throws WMSException {
131 119
        try {
132
            return client.getMap(status);
120
            client.getMap(status);
133 121
        } catch (org.gvsig.remoteClient.exceptions.WMSException e) {
134 122
            throw new WMSException(e.getMessage());
135 123
        } catch (ServerErrorException e) {
......
137 125
        }
138 126
    }
139 127
    
140
	/**
141
	 * Devuelve WMSClient a partir de su URL.
142
	 *
143
	 * @param url URL.
144
	 *
145
	 * @return WMSClient.
146
	 * @throws IOException 
147
	 * @throws ConnectException 
148
	 *
149
	 * @throws UnsupportedVersionException
150
	 * @throws IOException
151
	 */
152
	public WMSClient getClient(URL url) throws ConnectException, IOException {
153
		if (client == null) {
154
			client = new WMSClient(url.toString(), monitor);
155
		}
156

  
157
		return client;
158
	}
159
    
160
    
161 128
    /**
162
     * Creates a new instance of a WMSClient.
163
     * @param host
164
     * @throws IOException 
165
     * @throws ConnectException 
166
     */
167
    public void createClient(URL host) throws ConnectException, IOException{
168
        client = new WMSClient(host.toString(), monitor);
169
    }
170

  
171
    /**
172 129
     * Establishes the connection.
173 130
     * @param override, if true the previous downloaded data will be overridden
174 131
     * @return <b>true</b> if the connection was successful, or <b>false</b> if it was no possible
......
361 318
        return client.getHost();
362 319
    }
363 320
    
364
    public void addListener(WMSListener listener) {
365
    	listeners.add(listener);
321
    public void addListener(WMSOperations listener) {
322
    	if (!listeners.contains(listener))
323
    		listeners.add(listener);
366 324
    }
367 325
    
368 326
	public void cancel(int opCode) {
369
		client.cancel(GET_CAPABILITIES);
327
		client.cancel(WMSOperations.GET_CAPABILITIES);
370 328
	}
371 329
    
372 330
}
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/WMSOperations.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
/* CVS MESSAGES:
43
*
44
* $Id$
45
* $Log$
46
* Revision 1.1.2.1  2006-05-18 22:50:44  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.1.2.3  2006/05/18 17:20:42  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1.2.2  2006/05/17 17:21:06  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.1.2.1  2006/05/16 17:09:37  jaume
56
* *** empty log message ***
57
*
58
*
59
*/
60
package com.iver.cit.gvsig.fmap.drivers.wms;
61

  
62
import java.io.File;
63

  
64
import org.gvsig.remoteClient.taskplanning.retrieving.RetrieveEvent;
65
import org.gvsig.remoteClient.wms.WMSClient;
66

  
67
public interface WMSOperations {
68
	public static final int GET_CAPABILITIES		= WMSClient.GET_CAPABILITIES;
69
	public static final int GET_MAP 				= WMSClient.GET_MAP;
70
	public static final int GET_FEATURE_INFO 		= WMSClient.GET_FEATURE_INFO;
71
	public static final int REQUEST_FINISHED 		= RetrieveEvent.REQUEST_FINISHED;
72
	public static final int REQUEST_CANCELLED 		= RetrieveEvent.REQUEST_CANCELLED;
73
	public static final int REQUEST_FAILED 			= RetrieveEvent.REQUEST_FAILED;
74
	public static final int REQUEST_STARTED 		= RetrieveEvent.CONNECTING;
75
	public static final int REQUEST_TRANSFERRING	= RetrieveEvent.TRANSFERRING;
76
	public abstract void getMap(int eventType, File mapFile, String message);
77
	public abstract void getCapabilities(int eventType, String message);
78
	public abstract void getFeatureInfo(int eventType, String message);
79
}
0 80

  
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/FMapWMSDriverFactory.java
1
package com.iver.cit.gvsig.fmap.drivers.wms;
2

  
3
import java.net.URL;
4
import java.util.Hashtable;
5

  
6
import com.sun.rsasign.d;
7

  
8
public class FMapWMSDriverFactory {
9
	private static Hashtable drivers = new Hashtable();
10
	private FMapWMSDriverFactory() {} // Avoid instantiation
11
	
12
	public static FMapWMSDriver getDriverForHost(URL host) {
13
		FMapWMSDriver drv = (FMapWMSDriver) drivers.get(host);
14
		if (drv == null) {
15
			drv = new FMapWMSDriver(host);
16
			drivers.put(host, drv);
17
		}
18
		return drv;
19
	}
20
}
0 21

  
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/WMSException.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers.wms;
42

  
43
import com.iver.andami.PluginServices;
44

  
45
/**
46
 * Excepci?n provocada por el WMS.
47
 *
48
 * @author Vicente Caballero Navarro
49
 */
50
public class WMSException extends Exception {
51
	String message;
52
	
53
	public String getMessage() {
54
		return PluginServices.getText(this, "wms_server_error")+"\n"+format(message, 200);
55
	}
56

  
57
	/**
58
	 *
59
	 */
60
	public WMSException() {
61
		super();
62
	}
63

  
64
	/**
65
	 * Crea WMSException.
66
	 *
67
	 * @param message
68
	 */
69
	public WMSException(String message) {
70
        super();
71
        this.message = message;
72
	}
73

  
74
	/**
75
	 * Crea WMSException.
76
	 *
77
	 * @param message
78
	 * @param cause
79
	 */
80
	public WMSException(String message, Throwable cause) {
81
		super(format(message, 200), cause);
82
	}
83

  
84
	/**
85
	  * Crea WMSException.
86
	 *
87
	 * @param cause
88
	 */
89
	public WMSException(Throwable cause) {
90
		super(cause);
91
	}
92
    
93
    /**
94
     * Cuts the message text to force its lines to be shorter or equal to 
95
     * lineLength.
96
     * @param message, the message.
97
     * @param lineLength, the max line length in number of characters.
98
     * @return the formated message.
99
     */
100
    private static String format(String message, int lineLength){
101
        if (message.length() <= lineLength) return message;
102
        String[] lines = message.split("\n");
103
        String theMessage = "";
104
        for (int i = 0; i < lines.length; i++) {
105
            String line = lines[i].trim();
106
            if (line.length()<lineLength)
107
                theMessage += line+"\n";
108
            else {
109
                String[] chunks = line.split(" ");
110
                String newLine = "";
111
                for (int j = 0; j < chunks.length; j++) {
112
                    int currentLength = newLine.length();
113
                    chunks[j] = chunks[j].trim();
114
                    if (chunks[j].length()==0)
115
                        continue;
116
                    if ((currentLength + chunks[j].length() + " ".length()) <= lineLength)
117
                        newLine += chunks[j] + " ";
118
                    else {
119
                        newLine += "\n"+chunks[j]+" ";
120
                        theMessage += newLine;
121
                        newLine = "";
122
                    }
123
                }
124
                
125
            }
126
        }
127
        return theMessage;
128
    }
129
}
0 130

  
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/layers/FLyrWMS.java
84 84
import com.iver.cit.gvsig.fmap.ViewPort;
85 85
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
86 86
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException;
87
import com.iver.cit.gvsig.fmap.drivers.WMSException;
88
import com.iver.cit.gvsig.fmap.drivers.WMSListener;
89 87
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver;
88
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriverFactory;
89
import com.iver.cit.gvsig.fmap.drivers.wms.WMSException;
90
import com.iver.cit.gvsig.fmap.drivers.wms.WMSOperations;
90 91
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode.FMapWMSStyle;
91 92
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint;
92 93
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem;
......
104 105
* 		  Nacho Brodin
105 106
* 
106 107
*/
107
public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations {
108
public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations, WMSOperations {
108 109
	private boolean 					isPrinting = false;
109 110
	private boolean 					mustTileDraw = false;
110 111
	private boolean 					mustTilePrint = true;
......
121 122
	private String 						infoLayerQuery;
122 123
	private FMapWMSDriver 				wms;
123 124
	private WMSStatus 					wmsStatus = new WMSStatus();
124
	private EventMonitor				monitor = new EventMonitor(); 
125 125
	private Rectangle2D 				fullExtent;
126 126
	private boolean						wmsTransparency;
127 127
    private Vector 						styles;
......
141 141
	private Dimension 					fixedSize;
142 142
	private boolean 					queryable = true;
143 143
	private VisualStatusWMS				visualStatus = new VisualStatusWMS();
144
	private DrawingProperties			dProperties = new DrawingProperties();
144 145
	
145 146
	public FLyrWMS(){
146 147
		super();
......
581 582
			wmsStatus.setTransparency(wmsTransparency);
582 583
			wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
583 584
			
584
			File f = getDriver().getMap(wmsStatus);
585
			String nameWorldFile = f.getPath() + getExtensionWorldFile();
586
			com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
587 585
			
588
			if(status!=null && firstLoad){
589
				status.applyStatus(this);
590
				firstLoad = false;
591
			}
586
			dProperties.bBox = bBox;
587
			dProperties.graphics = g;
588
			dProperties.sz = fixedSize;
589
			dProperties.viewPort = vp;
590
			getDriver().getMap(wmsStatus);
591
//			String nameWorldFile = f.getPath() + getExtensionWorldFile();
592
//			com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
593
//			
594
//			if(status!=null && firstLoad){
595
//				status.applyStatus(this);
596
//				firstLoad = false;
597
//			}
598
//			
599
//			// And finally, obtain the extent intersecting the view and the BBox
600
//			// to draw to.
601
//			Rectangle2D extent = new Rectangle2D.Double();
602
//			Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
603
//			
604
//			ViewPortData vpData = new ViewPortData(
605
//				vp.getProjection(), new Extent(extent), fixedSize );
606
//			vpData.setMat(vp.getAffineTransform());
607
//
608
//			rasterProcess(g, vpData, f);
592 609
			
593
			// And finally, obtain the extent intersecting the view and the BBox
594
			// to draw to.
595
			Rectangle2D extent = new Rectangle2D.Double();
596
			Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
597
			
598
			ViewPortData vpData = new ViewPortData(
599
				vp.getProjection(), new Extent(extent), fixedSize );
600
			vpData.setMat(vp.getAffineTransform());
601

  
602
			rasterProcess(g, vpData, f);
603
			
604 610
		} catch (ValidationException e) {
605 611
			throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
606 612
		} catch (UnsupportedVersionException e) {
......
657 663
			wmsStatus.setTransparency(wmsTransparency);
658 664
			wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
659 665
			
660
			File f = getDriver().getMap(wmsStatus);
661
			String nameWordFile = f.getPath() + getExtensionWorldFile();
662
			com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
663 666
			
664
			if(status!=null && firstLoad){
665
				status.applyStatus(this);
666
				firstLoad = false;
667
			}
668
			ViewPortData vpData = new ViewPortData(
669
				vp.getProjection(), new Extent(bBox), sz );
670
			vpData.setMat(vp.getAffineTransform());
671

  
672
			rasterProcess(g, vpData, f);
667
			dProperties.bBox = bBox;
668
			dProperties.graphics = g;
669
			dProperties.sz = sz;
670
			dProperties.viewPort = vp;
671
			getDriver().getMap(wmsStatus);
672
//			String nameWordFile = f.getPath() + getExtensionWorldFile();
673
//			com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
674
//			
675
//			if(status!=null && firstLoad){
676
//				status.applyStatus(this);
677
//				firstLoad = false;
678
//			}
679
//			ViewPortData vpData = new ViewPortData(
680
//				vp.getProjection(), new Extent(bBox), sz );
681
//			vpData.setMat(vp.getAffineTransform());
682
//
683
//			rasterProcess(g, vpData, f);
673 684
			
674 685
		} catch (ValidationException e) {
675 686
			throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
......
774 785
	 * 		com.iver.cit.gvsig.fmap.operations.Cancellable)
775 786
	 */
776 787
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
777
		throws DriverException {
788
	throws DriverException {
778 789
		if (isVisible() && isWithinScale(scale)){	
779
		isPrinting = true;
780
		if (!mustTilePrint) {
781
			draw(null, g, viewPort, cancel,scale);
782
		} else {
783
	        // Para no pedir imagenes demasiado grandes, vamos
784
	        // a hacer lo mismo que hace EcwFile: chunkear.
785
	        // Llamamos a drawView con cuadraditos m�s peque�os
786
	        // del BufferedImage ni caso, cuando se imprime viene con null
787
			
788
			Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
789
			tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
790
			for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
791
	    		// Parte que dibuja
792
	    		try {
793
	        		ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
794
	        		drawTile(g, vp, cancel);
795
				} catch (NoninvertibleTransformException e) {
796
					e.printStackTrace();
790
			isPrinting = true;
791
			if (!mustTilePrint) {
792
				draw(null, g, viewPort, cancel,scale);
793
			} else {
794
				// Para no pedir imagenes demasiado grandes, vamos
795
				// a hacer lo mismo que hace EcwFile: chunkear.
796
				// Llamamos a drawView con cuadraditos m�s peque�os
797
				// del BufferedImage ni caso, cuando se imprime viene con null
798
				
799
				Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
800
				tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
801
				for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
802
					// Parte que dibuja
803
					try {
804
						ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
805
						drawTile(g, vp, cancel);
806
					} catch (NoninvertibleTransformException e) {
807
						e.printStackTrace();
808
					}
797 809
				}
798
	        }
810
			}
811
			isPrinting = false;
799 812
		}
800
	    isPrinting = false;
801
		}
802 813
	}
803
	
804
	public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
805
		throws DriverException {
806
		draw(null, g, viewPort, cancel,scale);
807
	}
808 814

  
809 815
	/**
810 816
	 * Devuelve el FMapWMSDriver.
......
820 826
		throws IllegalStateException, ValidationException, 
821 827
			UnsupportedVersionException, IOException {
822 828
		if (wms == null) {
823
			//wmsClient = WMSClientFactory.getClient(host);
824
			wms = new FMapWMSDriver(monitor);
825
			
826
            wms.createClient(host);
827
            
829
			wms = FMapWMSDriverFactory.getDriverForHost(host); 
830
			wms.addListener(this);
828 831
		}
829 832

  
830 833
		return wms;
......
1391 1394
		public void run() {
1392 1395
			while (!cancel.isCanceled()) {}
1393 1396
			try {
1394
				getDriver().cancel(FMapWMSDriver.GET_MAP);
1397
				getDriver().cancel(WMSOperations.GET_MAP);
1395 1398
			} catch (IllegalStateException e) {
1396 1399
				// TODO Auto-generated catch block
1397 1400
				e.printStackTrace();
......
1408 1411
		}
1409 1412
	}
1410 1413
	
1411
	private class EventMonitor implements WMSListener {
1412
		public void getCapabilities(int eventType, String message) { /* Nothing */ }
1413
		public void getFeatureInfo(int eventType, String message)  { /* Nothing */ }
1414
		public void getMap(int eventType, File mapFile, String message) {
1415
			// TODO Auto-generated method stub
1416
			
1414
	private class DrawingProperties {
1415
		Graphics2D graphics;
1416
		Rectangle2D bBox;
1417
		Dimension sz;
1418
		ViewPort viewPort;
1419
	}
1420
	
1421
	public void getCapabilities(int eventType, String message) { /* Nothing */ }
1422
	public void getFeatureInfo(int eventType, String message)  { /* Nothing */ }
1423
	public void getMap(int eventType, File mapFile, String message) {
1424
		System.out.println("getMap at the layer");
1425
		File f = mapFile;
1426
		Graphics2D g = dProperties.graphics;
1427
		ViewPort vp = dProperties.viewPort;
1428
		Rectangle2D bBox = dProperties.bBox;
1429
		
1430
		String nameWorldFile = f.getPath() + getExtensionWorldFile();
1431
		try {
1432
			com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
1433
		} catch (IOException e) {
1434
			NotificationManager.addError(PluginServices.getText(this, "failed_creating_world_file"), e);
1417 1435
		}
1436
		
1437
		if(status!=null && firstLoad){
1438
			status.applyStatus(this);
1439
			firstLoad = false;
1440
		}
1441
		
1442
		// And finally, obtain the extent intersecting the view and the BBox
1443
		// to draw to.
1444
		Rectangle2D extent = new Rectangle2D.Double();
1445
		Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
1446
		
1447
		ViewPortData vpData = new ViewPortData(
1448
			vp.getProjection(), new Extent(extent), fixedSize );
1449
		vpData.setMat(vp.getAffineTransform());
1418 1450

  
1419
			
1451
		rasterProcess(g, vpData, f);
1420 1452
	}
1421
}
1422

  
1423

  
1424
///**
1425
//* FMap's WMS Layer class.
1426
//*
1427
//* @author Jaume Dominguez Faus
1428
//* 		  Nacho Brodin
1429
//* 
1430
//*/
1431
//public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations {
1432
//	private boolean 					isPrinting = false;
1433
//	private boolean 					mustTileDraw = false;
1434
//	private boolean 					mustTilePrint = true;
1435
//	private final int 					maxTileDrawWidth = -1;
1436
//	private final int 					maxTileDrawHeight = -1;
1437
//	private final int 					maxTilePrintWidth = 1200;
1438
//	private final int 					maxTilePrintHeight = 1200;
1439
//    
1440
//    public URL 							host;
1441
//    public String 						m_Format;
1442
//    
1443
//	private String 						m_SRS;
1444
//	private String 						layerQuery;
1445
//	private String 						infoLayerQuery;
1446
//	private FMapWMSDriver 				wms;
1447
//	private WMSStatus 					wmsStatus = new WMSStatus();
1448
//	private Rectangle2D 				fullExtent;
1449
//	private boolean						wmsTransparency;
1450
//    private Vector 						styles;
1451
//    private Vector 						dimensions;
1452
//	private StatusRasterInterface		status = null;
1453
//	private int 						posX = 0, posY = 0;
1454
//	private double 						posXWC = 0, posYWC = 0;
1455
//	private int 						r = 0, g = 0, b = 0;
1456
//	private GeoRasterFile 				rasterFile = null;
1457
//	private PxRaster 					raster = null;
1458
//	private RasterFilterStack 			filterStack = null;
1459
//	private boolean						firstLoad = false;
1460
//	private int 						transparency = -1;
1461
//	private int 						rband = 0, gband = 1, bband = 2;
1462
//	private RasterFilterStackManager	stackManager = null;
1463
//	private Hashtable 					onlineResources = new Hashtable();
1464
//	private Dimension 					fixedSize;
1465
//	private boolean 					queryable = true;
1466
//	private VisualStatusWMS				visualStatus = new VisualStatusWMS();
1467
//	
1468
//	public FLyrWMS(){
1469
//		super();
1470
//	}
1471
//	
1472
//	public FLyrWMS(Map args) throws DriverIOException{
1473
//		FMapWMSDriver drv = null;
1474
//		String host = (String)args.get("host");
1475
//		String sLayer = (String)args.get("layer");
1476
//		Rectangle2D fullExtent = (Rectangle2D)args.get("FullExtent");
1477
//		String sSRS = (String)args.get("SRS");
1478
//		String sFormat = (String)args.get("Format");
1479
//		String[] sLayers = sLayer.split(",");
1480
//		
1481
//		try {
1482
//			this.setHost(new URL(host));
1483
//		} catch (MalformedURLException e) {
1484
//			//e.printStackTrace();
1485
//			throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ").");			
1486
//		}
1487
//		try {
1488
//			drv = this.getDriver();
1489
//		} catch (Exception e) {
1490
//			// e.printStackTrace();
1491
//			throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ").");			
1492
//		}
1493
//		if( sFormat == null || sSRS == null || fullExtent == null ) {
1494
//			if (!drv.connect())
1495
//				throw new DriverIOException("Can't connect to host '" + host + "'."); 
1496
//			
1497
//			WMSLayerNode wmsNode = drv.getLayer(sLayer);
1498
//							
1499
//			if (wmsNode == null){
1500
//				throw new DriverIOException("The server '" + host + "' doesn't has the layer '" + sLayer + "'.");
1501
//			}		
1502
//			if( sFormat == null ) {
1503
//				sFormat = this.getGreatFormat(drv.getFormats());
1504
//			}
1505
//     		if( sSRS == null ) {
1506
//     			sSRS = (String)wmsNode.getAllSrs().get(0);
1507
//     		}
1508
//			if( fullExtent == null ) {
1509
//				fullExtent = drv.getLayersExtent(sLayers,(String)wmsNode.getAllSrs().get(0));
1510
//			}
1511
//		}
1512
//		
1513
//				
1514
//		this.setFullExtent(fullExtent);
1515
//		this.setFormat(sFormat);
1516
//		this.setLayerQuery(sLayer);
1517
//		this.setInfoLayerQuery("");
1518
//		this.setSRS(sSRS);
1519
//		this.setName(sLayer);
1520
//	}
1521
//	
1522
//	/**
1523
//	 * It choose the best format to load different maps if the server 
1524
//	 * supports it. This format could be png, because it supports 
1525
//	 * transparency.
1526
//	 * @param formats
1527
//	 * Arraywith all the formats supported by the server
1528
//	 * @return
1529
//	 */	
1530
//	private String getGreatFormat(Vector formats){
1531
//	    for (int i=0 ; i<formats.size() ; i++){
1532
//	        String format = (String) formats.get(i);
1533
//	    	if (format.equals("image/jpg")){
1534
//	            return format;
1535
//	    	}
1536
//	    	if (format.equals("image/jpeg")){
1537
//	            return format;
1538
//	    	}
1539
//	    }
1540
//		    
1541
//	    return (String)formats.get(0);
1542
//	}
1543
//	
1544
//	/**
1545
//	 * Clase que contiene los datos de visualizaci?n de WMS.
1546
//	 * @author Nacho Brodin (brodin_ign@gva.es)
1547
//	 */
1548
//	private class VisualStatusWMS{
1549
//		/**
1550
//		 * Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con 
1551
//		 * el ancho y alto del viewPort
1552
//		 */
1553
//		private	int							width = 0, height = 0;
1554
//		private double						minX = 0D, minY = 0D, maxX = 0D, maxY = 0D;
1555
//		private int 						bandCount = 0;
1556
//		private int							dataType = DataBuffer.TYPE_UNDEFINED;
1557
//	}
1558
//	 
1559
//
1560
//	/**
1561
//	 * Devuelve el XMLEntity con la informaci?n necesaria para reproducir la
1562
//	 * capa.
1563
//	 *
1564
//	 * @return XMLEntity.
1565
//	 * @throws XMLException
1566
//	 */
1567
//	public XMLEntity getXMLEntity() throws XMLException {
1568
//		XMLEntity xml = super.getXMLEntity();
1569
//
1570
//		// Full extent
1571
//		xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent));
1572
//		
1573
//		// Host
1574
//		xml.putProperty("host", host.toExternalForm());
1575
//		
1576
//		// Part of the query that is not the host, or the
1577
//		// layer names, or other not listed bellow
1578
//		xml.putProperty("infoLayerQuery", infoLayerQuery);
1579
//		
1580
//		// Part of the query containing the layer names
1581
//		xml.putProperty("layerQuery", layerQuery);
1582
//		
1583
//		// Format
1584
//		xml.putProperty("format", m_Format);
1585
//		
1586
//		// SRS
1587
//		xml.putProperty("srs", m_SRS);
1588
//		if (status!=null)
1589
//			status.getXMLEntity(xml, true, this);
1590
//		else{
1591
//			status = new StatusLayerRaster();
1592
//			status.getXMLEntity(xml, true, this);
1593
//		}
1594
//		
1595
//        // Transparency
1596
//        xml.putProperty("wms_transparency", wmsTransparency);
1597
//        
1598
//        // Styles
1599
//        if (styles!=null){
1600
//            String stylePr = "";
1601
//            for (int i = 0; i < styles.size(); i++) {
1602
//                stylePr += (String) styles.get(i);
1603
//                if (i<styles.size()-1)
1604
//                    stylePr += ",";
1605
//            }
1606
//            if (stylePr.endsWith(","))
1607
//            	stylePr += " ";
1608
//            xml.putProperty("styles", stylePr);
1609
//        }
1610
//        
1611
//        // Dimensions 
1612
//        if (dimensions!=null){
1613
//            String dim = "";
1614
//            for (int i = 0; i < dimensions.size(); i++) {
1615
//                dim += (String) dimensions.get(i);
1616
//                if (i<dimensions.size()-1)
1617
//                    dim += ",";
1618
//            }
1619
//            if (dim.endsWith(","))
1620
//            	dim += " ";
1621
//            xml.putProperty("dimensions", dim);
1622
//        }
1623
//        
1624
//        // OnlineResources
1625
//        Iterator it = onlineResources.keySet().iterator();
1626
//        String strOnlines = "";
1627
//        while (it.hasNext()) {
1628
//        	String key = (String) it.next();
1629
//        	String value = (String) onlineResources.get(key);
1630
//        	strOnlines = key+"~##SEP2##~"+value;
1631
//        	if (it.hasNext())
1632
//        		strOnlines += "~##SEP1##~";
1633
//        }
1634
//        xml.putProperty("onlineResources", strOnlines);
1635
//        
1636
//        // Queryable
1637
//        xml.putProperty("queryable", queryable);
1638
//        
1639
//        // fixedSize
1640
//        if (isSizeFixed()) {
1641
//        	xml.putProperty("fixedSize", true);
1642
//        	xml.putProperty("fixedWidth", fixedSize.width);
1643
//        	xml.putProperty("fixedHeight", fixedSize.height);
1644
//        }
1645
//        return xml;
1646
//	}
1647
//
1648
//	/**
1649
//	 * A partir del XMLEntity reproduce la capa.
1650
//	 *
1651
//	 * @param xml XMLEntity
1652
//	 *
1653
//	 * @throws XMLException
1654
//	 * @throws DriverException
1655
//	 * @throws DriverIOException
1656
//	 */
1657
//	public void setXMLEntity03(XMLEntity xml)
1658
//		throws XMLException {
1659
//		super.setXMLEntity(xml);
1660
//		fullExtent = StringUtilities.string2Rect(xml.getStringProperty(
1661
//					"fullExtent"));
1662
//
1663
//		try {
1664
//			host = new URL(xml.getStringProperty("host"));
1665
//		} catch (MalformedURLException e) {
1666
//			throw new XMLException(e);
1667
//		}
1668
//
1669
//		infoLayerQuery = xml.getStringProperty("infoLayerQuery");
1670
//		layerQuery = xml.getStringProperty("layerQuery");
1671
//		m_Format = xml.getStringProperty("format");
1672
//		m_SRS = xml.getStringProperty("srs");
1673
//	}
1674
//
1675
//	/**
1676
//	 * A partir del XMLEntity reproduce la capa.
1677
//	 *
1678
//	 * @param xml XMLEntity
1679
//	 *
1680
//	 * @throws XMLException
1681
//	 * @throws DriverException
1682
//	 * @throws DriverIOException
1683
//	 */
1684
//	public void setXMLEntity(XMLEntity xml)
1685
//		throws XMLException {
1686
//		super.setXMLEntity(xml);
1687
//		fullExtent = StringUtilities.string2Rect(xml.getStringProperty(
1688
//					"fullExtent"));
1689
//		
1690
//		// Host
1691
//		try {
1692
//			host = new URL(xml.getStringProperty("host"));
1693
//		} catch (MalformedURLException e) {
1694
//			throw new XMLException(e);
1695
//		}
1696
//
1697
//		// Part of the query that is not the host, or the
1698
//		// layer names, or other not listed bellow
1699
//		infoLayerQuery = xml.getStringProperty("infoLayerQuery");
1700
//
1701
//		// Part of the query containing the layer names
1702
//		layerQuery = xml.getStringProperty("layerQuery");
1703
//		
1704
//		// Format
1705
//		m_Format = xml.getStringProperty("format");
1706
//		
1707
//		// SRS
1708
//		m_SRS = xml.getStringProperty("srs");
1709
//		
1710
//		String claseStr = StatusLayerRaster.defaultClass;
1711
//		if (xml.contains("raster.class")) {
1712
//			claseStr = xml.getStringProperty("raster.class");
1713
//		}
1714
//		
1715
//		// Transparency
1716
//        if (xml.contains("wms_transparency"))
1717
//            wmsTransparency = xml.getBooleanProperty("wms_transparency");
1718
//        
1719
//        // Styles
1720
//        if (xml.contains("styles")){
1721
//            styles = new Vector();
1722
//            String[] stl = xml.getStringProperty("styles").split(",");
1723
//            
1724
//            for (int i = 0; i < stl.length; i++) {
1725
//            	if (stl[i].equals(" "))
1726
//            		stl[i]="";
1727
//                styles.add(stl[i]);
1728
//            }
1729
//        }
1730
//        
1731
//        // Dimensions
1732
//        if (xml.contains("dimensions")){
1733
//            dimensions = new Vector();
1734
//            String[] dims = xml.getStringProperty("dimensions").split(",");
1735
//            for (int i = 0; i < dims.length; i++){
1736
//            	if (dims[i].equals(" "))
1737
//            		dims[i]="";
1738
//                
1739
//                dimensions.add(dims[i]);
1740
//            }
1741
//        }
1742
//        
1743
//        // OnlineResources
1744
//        if (xml.contains("onlineResources")) {
1745
//        	String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~");
1746
//        	for (int i = 0; i < operations.length; i++) {
1747
//				String[] resources = operations[i].split("~##SEP2##~");
1748
//				if (resources.length==2 && resources[1]!="")
1749
//					onlineResources.put(resources[0], resources[1]);
1750
//			}
1751
//        }
1752
//        
1753
//        // Queryable
1754
//        queryable = true; // let's assume that the layer is queryable by default
1755
//        if (xml.contains("queryable"))
1756
//        	queryable = xml.getBooleanProperty("queryable");
1757
//        
1758
//        // fixedSize
1759
//        if (xml.contains("fixedSize")) {
1760
//        	fixedSize = new Dimension(xml.getIntProperty("fixedWidth"), 
1761
//        			                  xml.getIntProperty("fixedHeight"));
1762
//        }
1763
//        
1764
//		if(status!=null)
1765
//			status.setXMLEntity(xml, this);
1766
//		else{
1767
//			if(claseStr!=null && !claseStr.equals("")){
1768
//				try{
1769
//					Class clase = Class.forName(claseStr);
1770
//					Constructor constr = clase.getConstructor(null);
1771
//					status = (StatusRasterInterface)constr.newInstance(null);
1772
//					if(status!=null)
1773
//						status.setXMLEntity(xml, this);
1774
//				}catch(ClassNotFoundException exc){
1775
//					exc.printStackTrace();
1776
//				}catch(InstantiationException exc){
1777
//					exc.printStackTrace();
1778
//				}catch(IllegalAccessException exc){
1779
//					exc.printStackTrace();
1780
//				}catch(NoSuchMethodException exc){
1781
//					exc.printStackTrace();
1782
//				}catch(InvocationTargetException exc){
1783
//					exc.printStackTrace();
1784
//				}					
1785
//			}
1786
//		}
1787
//		firstLoad = true;
1788
//	}
1789
//
1790
//	/**
1791
//	 * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
1792
//	 */
1793
//	public String queryByPoint(Point p) throws DriverException {
1794
//		try {
1795
//			if (queryable)
1796
//			{
1797
//				//TODO
1798
//				// check if there are layers which are not queryable
1799
//				ViewPort viewPort = getFMap().getViewPort();
1800
//
1801
//				Point tiledPoint = new Point((int) p.getX() % maxTilePrintWidth, (int) p.getY() % maxTilePrintHeight);
1802
//				Rectangle rect = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1);
1803
//				Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, rect);
1804
//				tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
1805
//				int nCols = tiles.getNumCols();
1806
//
1807
//				int col = (int) p.getX() / maxTilePrintWidth;
1808
//				int row = (int) p.getY() / maxTilePrintHeight;
1809
//				int tileIndex = (row*nCols) + col;
1810
//				
1811
//				ViewPort vp = tiles.getTileViewPort(viewPort, tileIndex);
1812
//				wmsStatus.setExtent(vp.getExtent());
1813
//				wmsStatus.setHeight(vp.getImageHeight());
1814
//				wmsStatus.setWidth(vp.getImageWidth());
1815
//				wmsStatus.setOnlineResource((String) onlineResources.get("GetFeatureInfo"));
1816
//				return new String(getDriver()
1817
//						.getFeatureInfo(wmsStatus, (int) tiledPoint.getX(), (int) tiledPoint.getY(), Integer.MAX_VALUE));
1818
//			}
1819
//			else
1820
//			{
1821
//				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
1822
//						PluginServices.getText(this, "wms_not_queryable"));
1823
//				return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><info></info>";
1824
//			}
1825
//		} catch (WMSException  e) {
1826
//			return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" +
1827
//			e.getMessage() + "</exception>";
1828
//		} catch (ValidationException e) {
1829
//			throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
1830
//		} catch (UnsupportedVersionException e) {
1831
//			throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
1832
//		} catch (IOException e) {
1833
//			throw new DriverException(PluginServices.getText(this, "connect_error"), e);
1834
//		} catch (NoninvertibleTransformException e) {
1835
//			NotificationManager.addError("NotinvertibleTransform", e);
1836
//		}
1837
//		return null;
1838
//	}
1839
//
1840
//	/**
1841
//	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
1842
//	 */
1843
//	public Rectangle2D getFullExtent() {
1844
//		return fullExtent;
1845
//	}
1846
//
1847
//	/**
1848
//	 * 
1849
//	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
1850
//	 * 		java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
1851
//	 * 		com.iver.cit.gvsig.fmap.operations.Cancellable)
1852
//	 */
1853
//	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
1854
//			Cancellable cancel,double scale) throws DriverException {
1855
//		
1856
//		if (isWithinScale(scale)){
1857
//			Point2D p = viewPort.getOffset();
1858
//			// p will be (0, 0) when drawing a view or other when painting onto
1859
//			// the Layout.
1860
//			visualStatus.width =  viewPort.getImageWidth();
1861
//			visualStatus.height =  viewPort.getImageHeight();
1862
//			visualStatus.minX = viewPort.getAdjustedExtent().getMinX();
1863
//			visualStatus.minY = viewPort.getAdjustedExtent().getMinY();
1864
//			visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX();
1865
//			visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY();
1866
//			if (isSizeFixed()) {
1867
//				// This condition handles those situations in which the server can
1868
//				// only give static extent and resolution maps despite we need
1869
//				// a specific BBOX and pixel WIDTH and HEIGHT
1870
//				drawFixedSize(g, viewPort, cancel);
1871
//
1872
//			} else {
1873
//				Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1);
1874
//				Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, r);
1875
//				tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
1876
//				for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
1877
//					// drawing part
1878
//					try {
1879
//						ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
1880
//						drawTile(g, vp, cancel);
1881
//					} catch (NoninvertibleTransformException e) {
1882
//						e.printStackTrace();
1883
//					}
1884
//				}
1885
//			}
1886
//		}
1887
//	}
1888
//	
1889
//	private void drawFixedSize(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException {
1890
//		// This is the extent that will be requested
1891
//		Rectangle2D bBox = getFullExtent();
1892
//		
1893
//		try {			
1894
//			wmsStatus.setExtent( bBox );
1895
//			wmsStatus.setFormat( m_Format );
1896
//			wmsStatus.setHeight( fixedSize.height );
1897
//			wmsStatus.setWidth( fixedSize.width );
1898
//			wmsStatus.setLayerNames(Utilities.createVector(layerQuery,","));
1899
//			wmsStatus.setSrs(m_SRS);
1900
//			wmsStatus.setStyles(styles);
1901
//			wmsStatus.setDimensions(dimensions);
1902
//			wmsStatus.setTransparency(wmsTransparency);
1903
//			wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
1904
//			
1905
//			File f = getDriver().getMap(wmsStatus);
1906
//			String nameWorldFile = f.getPath() + getExtensionWorldFile();
1907
//			com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
1908
//			
1909
//			if(status!=null && firstLoad){
1910
//				status.applyStatus(this);
1911
//				firstLoad = false;
1912
//			}
1913
//			
1914
//			// And finally, obtain the extent intersecting the view and the BBox
1915
//			// to draw to.
1916
//			Rectangle2D extent = new Rectangle2D.Double();
1917
//			Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
1918
//			
1919
//			ViewPortData vpData = new ViewPortData(
1920
//				vp.getProjection(), new Extent(extent), fixedSize );
1921
//			vpData.setMat(vp.getAffineTransform());
1922
//
1923
//			rasterProcess(g, vpData, f);
1924
//			
1925
//		} catch (ValidationException e) {
1926
//			throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
1927
//		} catch (UnsupportedVersionException e) {
1928
//			throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
1929
//		} catch (IOException e) {
1930
//			throw new DriverException(PluginServices.getText(this, "connect_error"), e);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff