Revision 5262
trunk/libraries/libUI/src/org/gvsig/gui/beans/CancellableComponent.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 2006-05-17 17:20:11 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* |
|
50 |
*/ |
|
51 |
package org.gvsig.gui.beans; |
|
52 |
/** |
|
53 |
* Interface implemented by those components that can cancel an action at anytime. |
|
54 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
55 |
* |
|
56 |
*/ |
|
57 |
public interface CancellableComponent { |
|
58 |
/** |
|
59 |
* Invoked to cancel the current executing action. |
|
60 |
*/ |
|
61 |
public abstract void cancel(); |
|
62 |
} |
|
0 | 63 |
trunk/libraries/libUI/src/org/gvsig/gui/beans/ProgressDialog.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 2006-05-17 17:20:11 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* |
|
50 |
*/ |
|
51 |
package org.gvsig.gui.beans; |
|
52 |
|
|
53 |
import javax.swing.JButton; |
|
54 |
import javax.swing.JDialog; |
|
55 |
import javax.swing.JLabel; |
|
56 |
import javax.swing.JProgressBar; |
|
57 |
|
|
58 |
import com.iver.andami.PluginServices; |
|
59 |
import com.iver.andami.messages.NotificationManager; |
|
60 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
|
61 |
/** |
|
62 |
* @author jaume |
|
63 |
* |
|
64 |
*/ |
|
65 |
public class ProgressDialog extends JDialog { |
|
66 |
|
|
67 |
private JProgressBar jProgressBar = null; |
|
68 |
private JButton btnCancel = null; |
|
69 |
private JLabel lblStatus = null; |
|
70 |
private JLabel lblTask = null; |
|
71 |
private String jobName; |
|
72 |
private CancellableComponent cc; |
|
73 |
|
|
74 |
/** |
|
75 |
* This is the default constructor |
|
76 |
*/ |
|
77 |
public ProgressDialog(CancellableComponent owner, String jobName, int stepAmount) { |
|
78 |
super(); |
|
79 |
this.jobName = jobName; |
|
80 |
getJProgressBar().setMinimum(0); |
|
81 |
getJProgressBar().setMaximum(stepAmount); |
|
82 |
initialize(); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* This method initializes this |
|
87 |
* |
|
88 |
* @return void |
|
89 |
*/ |
|
90 |
private void initialize() { |
|
91 |
lblTask = new JLabel(); |
|
92 |
lblTask.setBounds(10, 12, 280, 20); |
|
93 |
lblTask.setFont(new java.awt.Font("MS Sans Serif", java.awt.Font.BOLD, 11)); |
|
94 |
lblTask.setText(jobName); |
|
95 |
lblStatus = new JLabel(); |
|
96 |
lblStatus.setBounds(10, 63, 280, 20); |
|
97 |
this.getContentPane().setLayout(null); |
|
98 |
this.setSize(308, 168); |
|
99 |
this.getContentPane().add(getJProgressBar(), null); |
|
100 |
this.getContentPane().add(getBtnCancel(), null); |
|
101 |
this.getContentPane().add(lblStatus, null); |
|
102 |
this.getContentPane().add(lblTask, null); |
|
103 |
this.setModal(false); |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* This method initializes jProgressBar |
|
108 |
* |
|
109 |
* @return javax.swing.JProgressBar |
|
110 |
*/ |
|
111 |
private JProgressBar getJProgressBar() { |
|
112 |
if (jProgressBar == null) { |
|
113 |
jProgressBar = new JProgressBar(); |
|
114 |
jProgressBar.setBounds(10, 38, 280, 20); |
|
115 |
} |
|
116 |
return jProgressBar; |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* This method initializes btnCancel |
|
121 |
* |
|
122 |
* @return javax.swing.JButton |
|
123 |
*/ |
|
124 |
private JButton getBtnCancel() { |
|
125 |
if (btnCancel == null) { |
|
126 |
btnCancel = new JButton(); |
|
127 |
btnCancel.setBounds(210, 96, 80, 20); |
|
128 |
btnCancel.addActionListener(new java.awt.event.ActionListener() { |
|
129 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
130 |
NotificationManager.addInfo("The job was cancelled", null); |
|
131 |
if (cc!=null) |
|
132 |
cc.cancel(); |
|
133 |
} |
|
134 |
}); |
|
135 |
btnCancel.setText(PluginServices.getText(this, "cancel")); |
|
136 |
} |
|
137 |
return btnCancel; |
|
138 |
} |
|
139 |
|
|
140 |
public void setProgress(int step) { |
|
141 |
jProgressBar.setValue(step); |
|
142 |
} |
|
143 |
|
|
144 |
public void setStatusMessage(String message) { |
|
145 |
lblStatus.setText(message); |
|
146 |
} |
|
147 |
} // @jve:decl-index=0:visual-constraint="10,10" |
|
0 | 148 |
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/.classpath | ||
---|---|---|
15 | 15 |
<classpathentry sourcepath="ECLIPSE_HOME/plugins/org.eclipse.jdt.source_3.1.1/src/org.junit_3.8.1/junitsrc.zip" kind="var" path="JUNIT_HOME/junit.jar"/> |
16 | 16 |
<classpathentry kind="src" path="test"/> |
17 | 17 |
<classpathentry kind="lib" path="/libFMap/lib/driver-manager-1.1.jar"/> |
18 |
<classpathentry kind="lib" path="/_fwAndami/lib/beans.jar"/> |
|
19 | 18 |
<classpathentry kind="lib" path="/libFMap/lib/kxml2.jar"/> |
19 |
<classpathentry sourcepath="/libUI" kind="lib" path="/_fwAndami/lib/beans.jar"/> |
|
20 | 20 |
<classpathentry kind="output" path="bin"/> |
21 | 21 |
</classpath> |
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/FMapWMSDriver.java | ||
---|---|---|
52 | 52 |
import java.util.Vector; |
53 | 53 |
|
54 | 54 |
import org.gvsig.remoteClient.exceptions.ServerErrorException; |
55 |
import org.gvsig.remoteClient.taskplanning.retrieving.RetrieveEvent; |
|
55 | 56 |
import org.gvsig.remoteClient.wms.WMSClient; |
56 | 57 |
import org.gvsig.remoteClient.wms.WMSDimension; |
57 | 58 |
import org.gvsig.remoteClient.wms.WMSEventListener; |
... | ... | |
71 | 72 |
* @author Jaume Dominguez Faus |
72 | 73 |
*/ |
73 | 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 |
|
|
74 | 79 |
private WMSClient client; |
75 | 80 |
private WMSLayerNode fmapRootLayer; |
76 | 81 |
private TreeMap layers = new TreeMap(); |
... | ... | |
78 | 83 |
|
79 | 84 |
private WMSEventListener monitor = new WMSEventListener() { |
80 | 85 |
public void newEvent(int idRequest, int eventType) { |
81 |
if (eventType == WMSEventListener.FINISHED) { |
|
86 |
int message = 0; |
|
87 |
if (eventType == RetrieveEvent.REQUEST_FINISHED) { |
|
88 |
message = WMSListener.FINISHED; |
|
82 | 89 |
if (idRequest == WMSEventListener.CAPABILITIES) { |
83 | 90 |
WMSLayer clientRoot = client.getLayersRoot(); |
84 | 91 |
fmapRootLayer = parseTree(clientRoot, null); |
92 |
eventType = WMSEventListener.CAPABILITIES; |
|
85 | 93 |
} |
94 |
|
|
95 |
} else if (eventType == RetrieveEvent.REQUEST_CANCELLED){ |
|
96 |
message = WMSListener.CANCELLED; |
|
97 |
} else if (eventType == RetrieveEvent.REQUEST_FAILED){ |
|
98 |
message = WMSListener.FAILED; |
|
99 |
} else if (eventType == RetrieveEvent.CONNECTING){ |
|
100 |
message = WMSListener.STARTED; |
|
101 |
} else if (eventType == RetrieveEvent.TRANSFERRING){ |
|
102 |
message = WMSListener.TRANSFERRING; |
|
86 | 103 |
} |
104 |
|
|
87 | 105 |
for (int i = 0; i < listeners.size(); i++) { |
106 |
System.out.println("comunique a wizard data"); |
|
88 | 107 |
WMSListener l = (WMSListener) listeners.get(i); |
89 |
l.newEvent(idRequest, eventType);
|
|
108 |
l.newEvent(idRequest, message);
|
|
90 | 109 |
} |
91 | 110 |
} |
92 | 111 |
}; |
... | ... | |
350 | 369 |
listeners.add(listener); |
351 | 370 |
} |
352 | 371 |
|
372 |
public void cancel(int opCode) { |
|
373 |
client.cancel(GET_CAPABILITIES); |
|
374 |
} |
|
375 |
|
|
353 | 376 |
} |
354 | 377 |
|
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/WMSListener.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.1.2.1 2006-05-16 17:09:37 jaume
|
|
46 |
* Revision 1.1.2.2 2006-05-17 17:21:06 jaume
|
|
47 | 47 |
* *** empty log message *** |
48 | 48 |
* |
49 |
* Revision 1.1.2.1 2006/05/16 17:09:37 jaume |
|
50 |
* *** empty log message *** |
|
49 | 51 |
* |
52 |
* |
|
50 | 53 |
*/ |
51 | 54 |
package com.iver.cit.gvsig.fmap.drivers; |
52 | 55 |
|
53 | 56 |
public interface WMSListener { |
54 | 57 |
public static final int CAPABILITIES = 1; |
55 | 58 |
public static final int MAP = 2; |
56 |
public static final int FEATURE_INFO = 2;
|
|
59 |
public static final int FEATURE_INFO = 3;
|
|
57 | 60 |
public static final int FINISHED = -1; |
58 | 61 |
public static final int STARTED = -2; |
59 | 62 |
public static final int TRANSFERRING = -3; |
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/gui/wizards/WMSWizardData.java | ||
---|---|---|
47 | 47 |
import java.net.URL; |
48 | 48 |
import java.util.ArrayList; |
49 | 49 |
import java.util.Hashtable; |
50 |
import java.util.NoSuchElementException; |
|
50 | 51 |
import java.util.Vector; |
51 | 52 |
|
52 | 53 |
import javax.swing.JOptionPane; |
53 | 54 |
|
55 |
import org.gvsig.gui.beans.ProgressDialog; |
|
56 |
|
|
54 | 57 |
import com.iver.andami.PluginServices; |
55 | 58 |
import com.iver.cit.gvsig.fmap.DriverException; |
56 | 59 |
import com.iver.cit.gvsig.fmap.drivers.WMSListener; |
... | ... | |
66 | 69 |
public class WMSWizardData { // should implemement any kind of wizard data interface? |
67 | 70 |
private String title; |
68 | 71 |
private String theAbstract; |
69 |
private WMSLayerNode layer; |
|
72 |
private WMSLayerNode layers;
|
|
70 | 73 |
private String[] formats; |
71 | 74 |
private String serverVersion; |
72 | 75 |
private FMapWMSDriver wms = null; |
73 | 76 |
private Hashtable onlineResources = null; |
74 | 77 |
private EventListener listener = new EventListener(); |
75 | 78 |
private WMSListener wizardListener; |
79 |
|
|
76 | 80 |
/** |
77 | 81 |
* @return Returns the serverVersion. |
78 | 82 |
*/ |
... | ... | |
101 | 105 |
e.printStackTrace(); |
102 | 106 |
return; |
103 | 107 |
} |
104 |
|
|
105 | 108 |
} |
106 | 109 |
|
107 | 110 |
/** |
... | ... | |
134 | 137 |
} |
135 | 138 |
|
136 | 139 |
public WMSLayerNode getLayer() { |
137 |
return layer; |
|
140 |
return layers;
|
|
138 | 141 |
} |
139 | 142 |
|
140 | 143 |
public String getTitle() { |
... | ... | |
164 | 167 |
|
165 | 168 |
private class EventListener implements WMSListener { |
166 | 169 |
public void newEvent(int idRequest, int eventType) { |
167 |
if (idRequest == EventListener.CAPABILITIES && eventType == EventListener.FINISHED) { |
|
168 |
if (wms.getAbstract() != null) |
|
169 |
theAbstract = wms.getAbstract(); |
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
Vector f = wms.getFormats(); |
|
174 |
ArrayList formatos = new ArrayList(); |
|
175 |
for (int i = 0; i < f.size(); i++) { |
|
176 |
if (isValidFormat((String)f.elementAt(i))) { |
|
177 |
formatos.add(f.elementAt(i)); |
|
178 |
} |
|
179 |
} |
|
180 |
formats = (String[]) formatos.toArray(new String[0]); |
|
181 |
serverVersion = (wms.getVersion() == null) ? "" : wms.getVersion(); |
|
182 |
onlineResources = wms.getOnlineResources(); |
|
183 |
layer = wms.getLayersTree(); // LayersTree as they are defined in the Capabilities document |
|
184 |
|
|
185 |
if (wizardListener!=null) |
|
186 |
wizardListener.newEvent(idRequest, eventType); |
|
170 |
if (idRequest == EventListener.CAPABILITIES) { |
|
171 |
|
|
172 |
if(eventType == EventListener.FINISHED) { |
|
173 |
// Transfer complete -> initialize properties. |
|
174 |
if (wms.getAbstract() != null) |
|
175 |
theAbstract = wms.getAbstract(); |
|
176 |
|
|
177 |
Vector f = wms.getFormats(); |
|
178 |
ArrayList formatos = new ArrayList(); |
|
179 |
for (int i = 0; i < f.size(); i++) { |
|
180 |
if (isValidFormat((String)f.elementAt(i))) { |
|
181 |
formatos.add(f.elementAt(i)); |
|
182 |
} |
|
183 |
} |
|
184 |
formats = (String[]) formatos.toArray(new String[0]); |
|
185 |
serverVersion = (wms.getVersion() == null) ? "" : wms.getVersion(); |
|
186 |
onlineResources = wms.getOnlineResources(); |
|
187 |
layers = wms.getLayersTree(); // LayersTree as they are defined in the Capabilities document |
|
188 |
} |
|
189 |
if (wizardListener!=null) |
|
190 |
// Notify WMSWizard that the data is ready. |
|
191 |
wizardListener.newEvent(idRequest, eventType); |
|
192 |
|
|
187 | 193 |
} |
188 | 194 |
} |
189 | 195 |
} |
... | ... | |
191 | 197 |
public void setWizardListener(WMSListener listener) { |
192 | 198 |
this.wizardListener = listener; |
193 | 199 |
} |
200 |
|
|
201 |
public void cancelTransfer() { |
|
202 |
wms.cancel(FMapWMSDriver.GET_CAPABILITIES); |
|
203 |
} |
|
194 | 204 |
} |
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/gui/wizards/WMSWizard.java | ||
---|---|---|
57 | 57 |
import javax.swing.tree.TreePath; |
58 | 58 |
|
59 | 59 |
import org.apache.log4j.Logger; |
60 |
import org.gvsig.gui.beans.CancellableComponent; |
|
61 |
import org.gvsig.gui.beans.ProgressDialog; |
|
60 | 62 |
|
61 | 63 |
import com.iver.andami.PluginServices; |
62 | 64 |
import com.iver.andami.persistence.serverData.ServerDataPersistence; |
63 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
64 | 65 |
import com.iver.cit.gvsig.fmap.drivers.WMSListener; |
65 | 66 |
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver; |
66 | 67 |
import com.iver.cit.gvsig.fmap.exceptions.CannotReprojectException; |
... | ... | |
82 | 83 |
* |
83 | 84 |
* @author Jaume Dominguez Faus |
84 | 85 |
*/ |
85 |
public class WMSWizard extends WizardPanel { |
|
86 |
public class WMSWizard extends WizardPanel implements CancellableComponent {
|
|
86 | 87 |
private static Logger logger = Logger.getLogger(WMSWizard.class.getName()); |
87 | 88 |
protected int page; |
88 | 89 |
protected boolean connected = false; |
... | ... | |
106 | 107 |
private static Preferences fPrefs = Preferences.userRoot().node( "gvsig.wms-wizard" ); |
107 | 108 |
private boolean refreshing = fPrefs.getBoolean("refresh_capabilities", false); |
108 | 109 |
protected int firstPage; |
109 |
|
|
110 |
private ProgressDialog dlg = new ProgressDialog(this, PluginServices.getText(this, "progress"), 3); |
|
111 |
|
|
110 | 112 |
public WMSWizard (WMSParamsPanel params){ |
111 | 113 |
|
112 | 114 |
super(); |
... | ... | |
137 | 139 |
new java.awt.event.MouseAdapter() { |
138 | 140 |
public void mouseClicked(java.awt.event.MouseEvent e) { |
139 | 141 |
page = wmsParamsPanel.currentPage() + 1; |
140 |
activarVisualizarBotones();
|
|
142 |
activeAndShowButtons();
|
|
141 | 143 |
} |
142 | 144 |
}); |
143 | 145 |
this.add(wmsParamsPanel, null); |
... | ... | |
182 | 184 |
this.add(getBtnSiguiente(), null); |
183 | 185 |
this.add(lblServerType, null); |
184 | 186 |
this.add(lblServerTypeValue, null); |
185 |
activarVisualizarBotones();
|
|
187 |
activeAndShowButtons();
|
|
186 | 188 |
} |
187 | 189 |
|
188 | 190 |
|
... | ... | |
195 | 197 |
new java.awt.event.MouseAdapter() { |
196 | 198 |
public void mouseClicked(java.awt.event.MouseEvent e) { |
197 | 199 |
page = wmsParamsPanel.currentPage() + 1; |
198 |
activarVisualizarBotones();
|
|
200 |
activeAndShowButtons();
|
|
199 | 201 |
} |
200 | 202 |
}); |
201 | 203 |
} |
... | ... | |
208 | 210 |
*/ |
209 | 211 |
private void addHost(String host) { |
210 | 212 |
host = host.trim(); |
211 |
|
|
212 |
// DefaultComboBoxModel model = (DefaultComboBoxModel) getTxtHost() |
|
213 |
// .getModel(); |
|
214 |
|
|
215 |
// if (model.getIndexOf(host) < 0) { |
|
216 |
// model.addElement(host); |
|
217 |
|
|
218 |
// PluginServices ps = PluginServices.getPluginServices(this); |
|
219 |
// XMLEntity xml = ps.getPersistentXML(); |
|
220 |
|
|
221 |
// try { |
|
222 |
// String[] servers = xml.getStringArrayProperty("wms-servers"); |
|
223 |
// String[] newServers = new String[servers.length + 1]; |
|
224 |
// System.arraycopy(servers, 0, newServers, 0, servers.length); |
|
225 |
// newServers[servers.length] = host; |
|
226 |
// xml.putProperty("wms-servers", newServers); |
|
227 |
// } catch (NotExistInXMLEntity e) { |
|
228 |
// xml.putProperty("wms-servers", new String[] { host }); |
|
229 |
// } |
|
230 |
|
|
231 |
// ps.setPersistentXML(xml); |
|
232 |
// } |
|
233 |
|
|
234 | 213 |
ServerDataPersistence persistence = new ServerDataPersistence(this,ServerData.SERVER_TYPE_WMS); |
235 | 214 |
persistence.addServerData(new ServerData(host, ServerData.SERVER_TYPE_WMS)); |
236 |
|
|
237 |
|
|
238 | 215 |
} |
239 | 216 |
|
240 | 217 |
private void connect() { |
241 | 218 |
String host = cmbHost.getModel().getSelectedItem().toString(); |
242 | 219 |
|
243 | 220 |
try { |
221 |
getBtnSiguiente().setEnabled(false); |
|
222 |
dlg.setVisible(true); |
|
223 |
dlg.setBounds(300, 300, dlg.getWidth(), dlg.getHeight()); |
|
244 | 224 |
dataSource.setHost(new URL(host), refreshing); |
245 | 225 |
dataSource.setWizardListener(new WMSListener() { |
246 | 226 |
|
247 | 227 |
public void newEvent(int idRequest, int eventType) { |
248 |
if (idRequest == WMSListener.CAPABILITIES && eventType == WMSListener.FINISHED) |
|
249 |
rellenarControles(); |
|
228 |
if (idRequest == WMSListener.CAPABILITIES) { |
|
229 |
int progress=0; |
|
230 |
if (eventType == WMSListener.FINISHED) { |
|
231 |
fillupControls(); |
|
232 |
progress = 3; |
|
233 |
dlg.setVisible(false); |
|
234 |
} else if (eventType == WMSListener.CANCELLED) { |
|
235 |
progress = 3; |
|
236 |
dlg.setStatusMessage(PluginServices.getText(this, "cancelled")); |
|
237 |
dlg.setVisible(false); |
|
238 |
} else if (eventType == WMSListener.FAILED) { |
|
239 |
progress = 3; |
|
240 |
dlg.setStatusMessage(PluginServices.getText(this, "failed")); |
|
241 |
} else if (eventType == WMSListener.STARTED) { |
|
242 |
dlg.setStatusMessage(PluginServices.getText(this, "starting")); |
|
243 |
progress = 1; |
|
244 |
} else if (eventType == WMSListener.TRANSFERRING) { |
|
245 |
progress = 2; |
|
246 |
dlg.setStatusMessage(PluginServices.getText(this, "transferring")); |
|
247 |
} |
|
248 |
dlg.setProgress(progress); |
|
249 |
} |
|
250 | 250 |
} |
251 |
|
|
252 | 251 |
}); |
253 | 252 |
} catch (Exception e) { |
254 | 253 |
listenerSupport.callError(e); |
... | ... | |
259 | 258 |
/** |
260 | 259 |
* DOCUMENT ME! |
261 | 260 |
*/ |
262 |
private void rellenarControles() {
|
|
261 |
private void fillupControls() {
|
|
263 | 262 |
try { |
264 | 263 |
String host = cmbHost.getModel().getSelectedItem().toString(); |
265 | 264 |
|
... | ... | |
270 | 269 |
addHost(host); |
271 | 270 |
wmsParamsPanel.setWizardData(dataSource); |
272 | 271 |
connected = true; |
273 |
activarVisualizarBotones();
|
|
272 |
activeAndShowButtons();
|
|
274 | 273 |
} catch (Exception e) { |
275 | 274 |
listenerSupport.callError(e); |
276 | 275 |
e.printStackTrace(); |
... | ... | |
280 | 279 |
/** |
281 | 280 |
* DOCUMENT ME! |
282 | 281 |
*/ |
283 |
protected void activarVisualizarBotones() {
|
|
282 |
protected void activeAndShowButtons() {
|
|
284 | 283 |
if (page == firstPage) { |
285 | 284 |
getBtnAnterior().setEnabled(false); |
286 | 285 |
getBtnSiguiente().setVisible(true); |
... | ... | |
567 | 566 |
page++; |
568 | 567 |
getPanelPage1().setVisible(false); |
569 | 568 |
getPanelPage2().setVisible(true); |
570 |
activarVisualizarBotones();
|
|
569 |
activeAndShowButtons();
|
|
571 | 570 |
} |
572 | 571 |
}); |
573 | 572 |
} |
... | ... | |
592 | 591 |
// Tenemos que retroceder en el wcsParamsPanel |
593 | 592 |
wmsParamsPanel.retrocedeTab(); |
594 | 593 |
page = wmsParamsPanel.currentPage() + 1; |
595 |
activarVisualizarBotones();
|
|
594 |
activeAndShowButtons();
|
|
596 | 595 |
} else if (page==firstPage){ |
597 |
activarVisualizarBotones();
|
|
596 |
activeAndShowButtons();
|
|
598 | 597 |
page = firstPage +1; |
599 | 598 |
//wmsParamsPanel.limpiaWizard(); |
600 | 599 |
getLblTitle().setText("-"); |
... | ... | |
960 | 959 |
} |
961 | 960 |
return chkCaching; |
962 | 961 |
} |
962 |
|
|
963 |
public void cancel() { |
|
964 |
dataSource.cancelTransfer(); |
|
965 |
} |
|
963 | 966 |
} // @jve:decl-index=0:visual-constraint="10,10" |
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/WMSClient.java | ||
---|---|---|
18 | 18 |
* |
19 | 19 |
*/ |
20 | 20 |
public class WMSClient extends org.gvsig.remoteClient.RasterClient { |
21 |
public static final int GET_CAPABILITIES = 1; |
|
22 |
public static final int GET_MAP = 2; |
|
23 |
public static final int GET_FEATURE_INFO = 3; |
|
24 |
|
|
21 | 25 |
private org.gvsig.remoteClient.wms.WMSProtocolHandler handler; |
22 |
private TreeMap layers = new TreeMap(); |
|
23 |
private WMSLayer rootLayer; |
|
26 |
// private TreeMap layers = new TreeMap();
|
|
27 |
// private WMSLayer rootLayer;
|
|
24 | 28 |
|
25 | 29 |
/** |
26 | 30 |
* @return Returns the rootLayer. |
27 | 31 |
*/ |
28 | 32 |
public WMSLayer getRootLayer() { |
29 |
return rootLayer; |
|
33 |
return handler.rootLayer;
|
|
30 | 34 |
} |
31 |
|
|
35 |
|
|
32 | 36 |
/** |
33 |
* @param rootLayer The rootLayer to set. |
|
34 |
*/ |
|
35 |
public void setRootLayer(WMSLayer rootLayer) { |
|
36 |
this.rootLayer = rootLayer; |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
/** |
|
41 | 37 |
* Constructor. |
42 | 38 |
* the parameter host, indicates the WMS host to connect. |
43 | 39 |
* */ |
... | ... | |
100 | 96 |
*/ |
101 | 97 |
public void getCapabilities(WMSStatus status, boolean override) { |
102 | 98 |
handler.getCapabilities(status, override); |
103 |
layers = handler.layers; |
|
104 |
rootLayer = handler.rootLayer; |
|
105 | 99 |
} |
106 | 100 |
|
107 | 101 |
/** |
... | ... | |
117 | 111 |
* @return a TreeMap with the available layers in the WMS |
118 | 112 |
*/ |
119 | 113 |
public TreeMap getLayers() { |
120 |
return layers; |
|
114 |
return handler.layers;
|
|
121 | 115 |
} |
122 | 116 |
|
123 | 117 |
/** |
... | ... | |
125 | 119 |
* @return, number of layers available |
126 | 120 |
*/ |
127 | 121 |
public int getNumberOfLayers() { |
128 |
if (layers != null) |
|
122 |
if (handler.layers != null)
|
|
129 | 123 |
{ |
130 |
return layers.size(); |
|
124 |
return handler.layers.size();
|
|
131 | 125 |
} |
132 | 126 |
return 0; |
133 | 127 |
} |
... | ... | |
139 | 133 |
* @return the layer with this name |
140 | 134 |
*/ |
141 | 135 |
public WMSLayer getLayer(String _name) { |
142 |
if (layers.get(_name) != null) |
|
136 |
if (handler.layers.get(_name) != null)
|
|
143 | 137 |
{ |
144 |
return (WMSLayer)layers.get(_name); |
|
138 |
return (WMSLayer)handler.layers.get(_name);
|
|
145 | 139 |
} |
146 | 140 |
|
147 | 141 |
return null; |
... | ... | |
151 | 145 |
{ |
152 | 146 |
WMSLayer[] lyrs; |
153 | 147 |
|
154 |
lyrs = (WMSLayer[])layers.values().toArray(new WMSLayer[0]); |
|
148 |
lyrs = (WMSLayer[])handler.layers.values().toArray(new WMSLayer[0]);
|
|
155 | 149 |
|
156 | 150 |
String[] names = new String[lyrs.length]; |
157 | 151 |
|
... | ... | |
274 | 268 |
|
275 | 269 |
//TODO Check this out: Always 1 layer at first level... |
276 | 270 |
public WMSLayer getLayersRoot() { |
277 |
return rootLayer; |
|
271 |
return handler.rootLayer;
|
|
278 | 272 |
} |
279 | 273 |
|
280 | 274 |
public boolean connect() { |
281 | 275 |
return connect(false); |
282 | 276 |
} |
277 |
|
|
278 |
public void cancel(int opCode) { |
|
279 |
handler.cancel(opCode); |
|
280 |
} |
|
283 | 281 |
} |
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/WMSProtocolHandler.java | ||
---|---|---|
66 | 66 |
public WMSLayer rootLayer; |
67 | 67 |
public Vector srs; |
68 | 68 |
|
69 |
private URLRequest capabilitiesRequest, mapRequest, featureInfo; |
|
69 | 70 |
|
70 |
private URLRetrieveTask getCapabilitiesTask, getMapTask, getFeatureInfoTask; |
|
71 |
private File fGetCapabilitiesTask, fGetMapTask, fGetFeatureInfoTask; |
|
72 | 71 |
/** |
73 | 72 |
* The listener that a driver must implement to receive the events. |
74 | 73 |
*/ |
... | ... | |
83 | 82 |
int type = event.getType(); |
84 | 83 |
|
85 | 84 |
if (type == RetrieveEvent.REQUEST_FINISHED) { |
86 |
// ESTO NO DEURIA DE SER NECESSARI SI EN EL REQUEST MANAGER PUGUERA TORNAR UNA TASCA |
|
87 |
// QUE JA HA SIGUT REALITZADA |
|
88 |
if (getCapabilitiesTask!=null) |
|
89 |
fGetCapabilitiesTask = new File(getCapabilitiesTask.getRequest().getFileName()); |
|
90 |
parse(fGetCapabilitiesTask); |
|
85 |
System.out.println("parsing "+capabilitiesRequest.getFileName()); |
|
86 |
parse(new File(capabilitiesRequest.getFileName())); |
|
91 | 87 |
|
92 | 88 |
} |
93 |
if (theListener!=null) |
|
89 |
if (theListener!=null) {
|
|
94 | 90 |
theListener.newEvent(WMSEventListener.CAPABILITIES, type); |
91 |
} |
|
95 | 92 |
|
96 | 93 |
} |
97 | 94 |
|
... | ... | |
157 | 154 |
*/ |
158 | 155 |
public void getCapabilities(WMSStatus status, boolean override) |
159 | 156 |
{ |
160 |
URLRequest request = null; |
|
157 |
|
|
161 | 158 |
try |
162 | 159 |
{ |
163 | 160 |
//request = new URL(buildCapabilitiesRequest(status)); |
164 |
request = buildCapabilitiesRequest(status);
|
|
165 |
request.setFileName("wmsCapabilities");
|
|
161 |
capabilitiesRequest = buildCapabilitiesRequest(status);
|
|
162 |
capabilitiesRequest.setFileName("wmsCapabilities");
|
|
166 | 163 |
if (override) |
167 |
RequestManager.getInstance().removeURLRequest(request);
|
|
168 |
getCapabilitiesTask = RequestManager.getInstance().addURLRequest(request, getCapabilitiesListener);
|
|
164 |
RequestManager.getInstance().removeURLRequest(capabilitiesRequest);
|
|
165 |
capabilitiesRequest = RequestManager.getInstance().addURLRequest(capabilitiesRequest, getCapabilitiesListener);
|
|
169 | 166 |
|
170 | 167 |
} catch(Exception e) |
171 | 168 |
{ |
... | ... | |
238 | 235 |
{ |
239 | 236 |
return output.toString(); |
240 | 237 |
} |
241 |
|
|
242 |
// while(tag != KXmlParser.END_DOCUMENT) |
|
243 |
// { |
|
244 |
// switch(tag) |
|
245 |
// { |
|
246 |
// case KXmlParser.START_TAG: |
|
247 |
// if (kxmlParser.getName().compareTo(ServiceException)==0) |
|
248 |
// { |
|
249 |
// sb.append("<INFO>").append(parseException( output.toString().getBytes())).append("</INFO>"); |
|
250 |
// return sb.toString(); |
|
251 |
// } |
|
252 |
// else if (kxmlParser.getName().compareToIgnoreCase("ERROR")==0) |
|
253 |
// return output.toString(); |
|
254 |
// else |
|
255 |
// sb.append("<" + kxmlParser.getName() + ">\n"); |
|
256 |
// break; |
|
257 |
// case KXmlParser.END_TAG: |
|
258 |
// sb.append("</" + kxmlParser.getName() + ">\n"); |
|
259 |
// break; |
|
260 |
// case KXmlParser.TEXT: |
|
261 |
// sb.append(kxmlParser.getText()); |
|
262 |
// break; |
|
263 |
// } |
|
264 |
// tag = kxmlParser.next(); |
|
265 |
// } |
|
266 |
//return sb.toString(); |
|
267 | 238 |
} |
268 | 239 |
else |
269 | 240 |
{ |
... | ... | |
373 | 344 |
|
374 | 345 |
File f = com.iver.andami.Utilities.downloadFile(request, "wmsGetMap"); |
375 | 346 |
|
376 |
// if ((type !=null && !type.subSequence(0,5).equals("image")) |
|
377 |
// ||(Utilities.isTextFile(f))) { |
|
378 | 347 |
if (Utilities.isTextFile(f)) { |
379 | 348 |
FileInputStream fis = new FileInputStream(f); |
380 | 349 |
FileChannel fc = fis.getChannel(); |
... | ... | |
393 | 362 |
{ |
394 | 363 |
String xml = error.substring(pos,error.length()); |
395 | 364 |
exceptionMessage = parseException(xml.getBytes()); |
396 |
// if (exceptionMessage == null) |
|
397 |
// exceptionMessage = new String(data); |
|
398 | 365 |
} |
399 | 366 |
if (exceptionMessage == null) |
400 | 367 |
exceptionMessage = new String(data); |
... | ... | |
510 | 477 |
if (myPort != -1 && myPort != 80 ) |
511 | 478 |
req.setPort(myPort); |
512 | 479 |
|
513 |
// symbol = getSymbol(onlineResource); |
|
514 |
// |
|
515 |
// req.append(onlineResource).append(symbol).append("REQUEST=GetCapabilities&SERVICE=WMS&"); |
|
516 |
// req.append("VERSION=").append(getVersion()).append("&EXCEPTIONS=XML"); |
|
517 | 480 |
return req; |
518 | 481 |
} |
519 |
|
|
520 |
/** |
|
521 |
* Builds the GetCapabilitiesRequest according to the OGC WMS Specifications |
|
522 |
* @param WMSStatus |
|
523 |
* @deprecated |
|
524 |
*/ |
|
525 |
private String _buildCapabilitiesRequest(WMSStatus status) |
|
526 |
{ |
|
527 |
StringBuffer req = new StringBuffer(); |
|
528 |
String symbol = null; |
|
529 |
|
|
530 |
String onlineResource; |
|
531 |
if (status == null || status.getOnlineResource() == null) |
|
532 |
onlineResource = getHost(); |
|
533 |
else |
|
534 |
onlineResource = status.getOnlineResource(); |
|
535 |
symbol = getSymbol(onlineResource); |
|
536 |
|
|
537 |
req.append(onlineResource).append(symbol).append("REQUEST=GetCapabilities&SERVICE=WMS&"); |
|
538 |
req.append("VERSION=").append(getVersion()).append("&EXCEPTIONS=XML"); |
|
539 |
return req.toString(); |
|
540 |
} |
|
541 | 482 |
|
542 | 483 |
/** |
543 | 484 |
* Builds the GetFeatureInfoRequest according to the OGC WMS Specifications |
... | ... | |
583 | 524 |
|
584 | 525 |
req.append(onlineResource + symbol + "REQUEST=GetMap&SERVICE=WMS&VERSION=").append(getVersion()).append("&"); |
585 | 526 |
req.append(getPartialQuery(status)); |
586 |
// if (status.getExceptionFormat() != null) {
|
|
587 |
// req.append("&EXCEPTIONS=" + status.getExceptionFormat());
|
|
588 |
// } else {
|
|
589 |
// req.append("&EXCEPTIONS=XML");
|
|
590 |
// }
|
|
527 |
if (status.getExceptionFormat() != null) { |
|
528 |
req.append("&EXCEPTIONS=" + status.getExceptionFormat()); |
|
529 |
} else { |
|
530 |
req.append("&EXCEPTIONS=XML"); |
|
531 |
} |
|
591 | 532 |
return req.toString().replaceAll(" ", "%20"); |
592 | 533 |
} |
593 | 534 |
|
... | ... | |
713 | 654 |
public void setListener(WMSEventListener listener) { |
714 | 655 |
if (listener!=null) |
715 | 656 |
this.theListener = listener; |
657 |
} |
|
658 |
|
|
659 |
public void cancel(int opCode) { |
|
660 |
if (opCode == WMSClient.GET_CAPABILITIES) { |
|
661 |
|
|
662 |
} |
|
716 | 663 |
} |
717 | 664 |
} |
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/taskplanning/retrieving/RequestManager.java | ||
---|---|---|
30 | 30 |
} |
31 | 31 |
|
32 | 32 |
|
33 |
public URLRetrieveTask addURLRequest(URLRequest request, RetrieveListener listener) {
|
|
33 |
public URLRequest addURLRequest(URLRequest request, RetrieveListener listener) {
|
|
34 | 34 |
try { |
35 |
|
|
36 |
|
|
37 | 35 |
if (downloadedFiles.contains(request)) { |
38 | 36 |
for (int i = 0; i < downloadedFiles.size(); i++) { |
39 | 37 |
URLRequest r = (URLRequest) downloadedFiles.get(i); |
40 | 38 |
if (r.equals(request)) { |
39 |
System.out.println(request.getUrl()+" is cached at '"+r.getFileName()+"'"); |
|
40 |
request.setFileName(r.getFileName()); /* Uaaah! |
|
41 |
* Si no pose a?? l'event es |
|
42 |
* dispara abans que haja |
|
43 |
* retornat el request |
|
44 |
* reasignat i confon el |
|
45 |
* sufixe. |
|
46 |
*/ |
|
41 | 47 |
request = r; |
42 | 48 |
break; |
43 | 49 |
} |
44 | 50 |
} |
45 | 51 |
|
46 |
System.out.println(request.getUrl()+" is cached at '"+request.getFileName()+"'"); |
|
47 | 52 |
|
48 | 53 |
synchronized (this) { |
49 |
if (request.getStatus() == RetrieveEvent.REQUEST_FINISHED) { |
|
54 |
if (request.getStatus() == RetrieveEvent.REQUEST_CANCELLED || |
|
55 |
request.getStatus() == RetrieveEvent.REQUEST_FAILED) { |
|
56 |
// The last requested URL was cancelled or it failed but now it is required again |
|
57 |
// so, I have to remove it and add again. |
|
58 |
removeURLRequest(request); |
|
59 |
return addURLRequest(request, listener); |
|
60 |
} else if (request.getStatus() == RetrieveEvent.REQUEST_FINISHED) { |
|
50 | 61 |
if (debug) |
51 |
System.err.println("done job found: "+request.getUrl());
|
|
62 |
System.err.println("done job found ("+request.getFileName()+")");
|
|
52 | 63 |
RetrieveEvent event = new RetrieveEvent(); |
53 | 64 |
event.setType(RetrieveEvent.REQUEST_FINISHED); |
54 | 65 |
listener.transferEventReceived(event); |
55 |
} else if (request.getStatus() == RetrieveEvent.REQUEST_CANCELLED) { |
|
56 |
removeURLRequest(request); |
|
57 |
return addURLRequest(request, listener); |
|
58 | 66 |
} else { |
59 | 67 |
if (debug) |
60 |
System.err.println("working job found: "+request.getUrl());
|
|
68 |
System.err.println("working job found ("+request.getFileName()+")");
|
|
61 | 69 |
request.lock(); |
62 | 70 |
request.addRetrieveListener(listener); |
63 | 71 |
request.unlock(); |
... | ... | |
112 | 120 |
// Enqueue the request and the listener will be notified when done. |
113 | 121 |
request.addRetrieveListener(listener); |
114 | 122 |
URLRetrieveTask task = new URLRetrieveTask(request); |
115 |
return (URLRetrieveTask) serverQueue.put(task);
|
|
123 |
serverQueue.put(task); |
|
116 | 124 |
} |
117 | 125 |
} catch (MalformedURLException e) { |
118 | 126 |
e.printStackTrace(); |
119 | 127 |
} |
120 |
return null;
|
|
128 |
return request;
|
|
121 | 129 |
} |
122 | 130 |
|
123 | 131 |
private IQueue getQueue(String hostName) { |
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/taskplanning/retrieving/URLRequest.java | ||
---|---|---|
27 | 27 |
private int status; |
28 | 28 |
private Vector listeners = new Vector(); |
29 | 29 |
private RetrieveEvent event = new RetrieveEvent(); |
30 |
private URLRetrieveTask worker; |
|
30 | 31 |
|
31 | 32 |
public URL getUrl() throws MalformedURLException { |
32 | 33 |
String u = protocol; |
... | ... | |
184 | 185 |
listeners.add(l); |
185 | 186 |
} |
186 | 187 |
|
188 |
public void removeRetrieveListener(RetrieveListener l) { |
|
189 |
listeners.remove(l); |
|
190 |
if (listeners.size()==0) |
|
191 |
// If no body listens then no body cares about the result; |
|
192 |
// cancel the job |
|
193 |
worker.cancel(); |
|
194 |
} |
|
195 |
|
|
187 | 196 |
private void fireEvent() { |
188 | 197 |
while (locked) { /* wait*/System.out.println("I'm locked"); } |
189 | 198 |
|
... | ... | |
193 | 202 |
listener.transferEventReceived(event); |
194 | 203 |
} |
195 | 204 |
} |
205 |
|
|
206 |
protected void setWorker(URLRetrieveTask worker) { |
|
207 |
this.worker = worker; |
|
208 |
} |
|
196 | 209 |
} |
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/taskplanning/retrieving/URLRetrieveTask.java | ||
---|---|---|
33 | 33 |
*/ |
34 | 34 |
public URLRetrieveTask(URLRequest request) { |
35 | 35 |
this.request = request; |
36 |
request.setWorker(this); |
|
36 | 37 |
running = cancelled = false; |
37 | 38 |
} |
38 | 39 |
|
... | ... | |
74 | 75 |
// Bad incomplete file, delete it. |
75 | 76 |
System.out.println("download cancelled ("+url+")"); |
76 | 77 |
f.delete(); |
77 |
} else { |
|
78 |
// register job in the cache |
|
79 |
// TODO aix? deuria d'estar al principi per a poder capturar |
|
80 |
// treballs que s'estan fent per? que encara no s'han acabat |
|
81 |
// synchronized (this) { |
|
82 |
// RequestManager.getInstance().addDownloadedURLRequest(request); |
|
83 |
// } |
|
84 | 78 |
} |
85 | 79 |
|
86 | 80 |
running = false; |
... | ... | |
98 | 92 |
} |
99 | 93 |
} |
100 | 94 |
|
101 |
// private void fireEvent() { |
|
102 |
// Iterator it = listeners.iterator(); |
|
103 |
// while (it.hasNext()) { |
|
104 |
// RetrieveListener listener = (RetrieveListener) it.next(); |
|
105 |
// listener.transferEventReceived(event); |
|
106 |
// } |
|
107 |
// } |
|
108 |
|
|
109 | 95 |
public void cancel() { |
110 | 96 |
cancelled = true; |
111 | 97 |
try { |
... | ... | |
127 | 113 |
return request; |
128 | 114 |
} |
129 | 115 |
} |
130 |
|
|
131 |
|
|
132 |
//static private String makeSuffix(String contentType) { |
|
133 |
// contentType = contentType.toLowerCase(); |
|
134 |
// if (contentType.indexOf("png") >= 0) |
|
135 |
// return ".png"; |
|
136 |
// |
|
137 |
// if (contentType.indexOf("xml") >= 0) |
|
138 |
// return ".xml"; |
|
139 |
// |
|
140 |
// if (contentType.indexOf("gif") >= 0) |
|
141 |
// return ".gif"; |
|
142 |
// |
|
143 |
// if (contentType.indexOf("tif") >= 0) |
|
144 |
// return ".tif"; |
|
145 |
// |
|
146 |
// if (contentType.indexOf("jpg") >= 0 |
|
147 |
// || contentType.indexOf("jpeg") >= 0) |
|
148 |
// return ".jpg"; |
|
149 |
// |
|
150 |
// if (contentType.indexOf("html") >= 0) |
|
151 |
// return ".html"; |
|
152 |
// |
|
153 |
// return ""; |
|
154 |
//} |
|
155 |
///** |
|
156 |
// * |
|
157 |
// */ |
|
158 |
//private void end() { |
|
159 |
//} |
|
160 |
// |
|
161 |
///** |
|
162 |
// * |
|
163 |
// */ |
|
164 |
//private void inThreadEnd() { |
|
165 |
//} |
|
166 |
// |
|
167 |
///** |
|
168 |
// * |
|
169 |
// */ |
|
170 |
//private void update() { |
|
171 |
//} |
|
172 |
// |
|
173 |
///** |
|
174 |
// * |
|
175 |
// */ |
|
176 |
//private void begin() { |
|
177 |
//} |
|
178 |
|
|
179 |
//public void start() { |
|
180 |
//// this.reset(); |
|
181 |
//this.thread = new Thread(this); |
|
182 |
//this.thread.start(); |
|
183 |
//} |
|
184 |
|
|
185 |
/* (non-Javadoc) |
|
186 |
* @see java.lang.Runnable#run() |
|
187 |
* / |
|
188 |
public void run() { |
|
189 |
try { |
|
190 |
URL url = request.getUrl(); |
|
191 |
this.status = Status.CONNECTING; |
|
192 |
this.begin(); |
|
193 |
|
|
194 |
{ |
|
195 |
// Retrieve the contents. |
|
196 |
int numBytesRead = 0; |
|
197 |
// System.out.println("File being retrieved. " + this.getUrl().toString()); |
|
198 |
java.net.URLConnection connection = url.openConnection(); |
|
199 |
connection.setAllowUserInteraction(true); |
|
200 |
java.io.InputStream incoming = connection.getInputStream(); |
|
201 |
this.contentLength = connection.getContentLength(); |
|
202 |
this.contentType = connection.getContentType(); |
|
203 |
|
|
204 |
java.io.File destFile = java.io.File.createTempFile("Cq_", makeSuffix(this.contentType)); |
|
205 |
destFile.deleteOnExit(); // It's copied later if it's to be persisted. |
|
206 |
this.destination = destFile.getPath(); |
|
207 |
java.io.FileOutputStream outgoing = new java.io.FileOutputStream(destFile); |
|
208 |
|
|
209 |
this.status = Status.RETRIEVING; |
|
210 |
|
|
211 |
byte[] buffer = new byte[4096]; |
|
212 |
|
|
213 |
try { |
|
214 |
while (!Thread.currentThread().isInterrupted() && numBytesRead >= 0) { |
|
215 |
numBytesRead = incoming.read(buffer); |
|
216 |
if (numBytesRead > 0) { |
|
217 |
this.bytesRead += numBytesRead; |
|
218 |
outgoing.write(buffer, 0, numBytesRead); |
|
219 |
this.update(); |
|
220 |
} |
|
221 |
} |
|
222 |
} finally { |
|
223 |
if (incoming != null) |
|
224 |
try {incoming.close();} catch (java.io.IOException e) {}; // TODO: log it maybe |
|
225 |
if (outgoing != null) |
|
226 |
try {outgoing.close();} catch (java.io.IOException e) {}; // TODO: log it maybe |
|
227 |
} |
|
228 |
this.status = Status.POSTPROCESSING; |
|
229 |
} |
|
230 |
} catch (Exception e) { |
|
231 |
this.status = Status.ERROR; |
|
232 |
this.error = e; |
|
233 |
e.printStackTrace(); |
|
234 |
} finally { |
|
235 |
if (Thread.currentThread().isInterrupted()) |
|
236 |
this.status = Status.INTERRUPTED; |
|
237 |
this.update(); |
|
238 |
this.inThreadEnd(); |
|
239 |
if (this.status == Status.POSTPROCESSING) |
|
240 |
this.status = Status.DONE; |
|
241 |
this.end(); |
|
242 |
} |
|
243 |
}*/ |
|
244 |
|
|
245 |
//File tempDirectory = new File(tempDirectoryPath); |
|
246 |
//if (!tempDirectory.exists()) |
|
247 |
//tempDirectory.mkdir(); |
|
248 |
// |
|
249 |
//f = new File(tempDirectoryPath+"/"+name+System.currentTimeMillis()); |
|
250 |
//if (cancelled) |
|
251 |
//throw new TaskCancelledException(); |
|
252 |
//addDownloadedURL(url, f.getAbsolutePath()); |
|
253 |
//try { |
|
254 |
//URL url = request.getUrl(); |
|
255 |
//System.out.println(url); |
|
256 |
//this.status = Status.CONNECTING; |
|
257 |
//this.begin(); |
|
258 |
// |
|
259 |
//{ |
|
260 |
//// Retrieve the contents. |
|
261 |
//int numBytesRead = 0; |
|
262 |
////System.out.println("File being retrieved. " + this.getUrl().toString()); |
|
263 |
//java.net.URLConnection connection = url.openConnection(); |
|
264 |
//connection.setAllowUserInteraction(true); |
|
265 |
//java.io.InputStream incoming = connection.getInputStream(); |
|
266 |
//this.contentLength = connection.getContentLength(); |
|
267 |
//this.contentType = connection.getContentType(); |
|
268 |
// |
|
269 |
//java.io.File destFile = java.io.File.createTempFile("Cq_", makeSuffix(this.contentType)); |
|
270 |
//System.out.println(destFile.getAbsolutePath()); |
|
271 |
////destFile.deleteOnExit(); // It's copied later if it's to be persisted. |
|
272 |
//this.destination = destFile.getPath(); |
|
273 |
//java.io.FileOutputStream outgoing = new java.io.FileOutputStream(destFile); |
|
274 |
// |
|
275 |
//this.status = Status.RETRIEVING; |
|
276 |
// |
|
277 |
//byte[] buffer = new byte[4096]; |
|
278 |
// |
|
279 |
//try { |
|
280 |
//while (!Thread.currentThread().isInterrupted() && numBytesRead >= 0) { |
|
281 |
//numBytesRead = incoming.read(buffer); |
|
282 |
//if (numBytesRead > 0) { |
|
283 |
//this.bytesRead += numBytesRead; |
|
284 |
//outgoing.write(buffer, 0, numBytesRead); |
|
285 |
//this.update(); |
|
286 |
//} |
|
287 |
//} |
|
288 |
//} finally { |
|
289 |
//if (incoming != null) |
|
290 |
//try {incoming.close();} catch (java.io.IOException e) {}; // TODO: log it maybe |
|
291 |
//if (outgoing != null) |
|
292 |
//try {outgoing.close();} catch (java.io.IOException e) {}; // TODO: log it maybe |
|
293 |
//} |
|
294 |
//this.status = Status.POSTPROCESSING; |
|
295 |
//} |
|
296 |
//} catch (Exception e) { |
|
297 |
//this.status = Status.ERROR; |
|
298 |
//this.error = e; |
|
299 |
//e.printStackTrace(); |
|
300 |
//} finally { |
|
301 |
//if (Thread.currentThread().isInterrupted()) |
|
302 |
//this.status = Status.INTERRUPTED; |
|
303 |
//this.update(); |
|
304 |
//this.inThreadEnd(); |
|
305 |
//if (this.status == Status.POSTPROCESSING) |
|
306 |
//this.status = Status.DONE; |
|
307 |
//this.end(); |
|
308 |
//} |
|
309 |
|
Also available in: Unified diff