1 package org.hardcode.juf.sample;
2
3 import java.awt.Dimension;
4 import java.io.IOException;
5
6 import javax.swing.JDialog;
7
8 import org.hardcode.juf.BadConfigurationException;
9 import org.hardcode.juf.ClientStatusException;
10 import org.hardcode.juf.DownloadException;
11 import org.hardcode.juf.InstallException;
12 import org.hardcode.juf.JUpdate;
13 import org.hardcode.juf.status.UpdateInfo;
14 import org.hardcode.juf.ui.UpdatePanel;
15 import org.hardcode.juf.update.Update;
16
17 /***
18 *
19 */
20 public class JUpdateClientSample {
21
22 public static void main(String[] args) {
23 JUpdateClientSample jus = new JUpdateClientSample();
24 jus.run();
25 }
26
27 public void run(){
28 JUpdate update = new JUpdate();
29 UpdateInfo clientUpdateInfo = null;
30 try {
31 clientUpdateInfo = update.getClientUpdateInformation("sample");
32 if (clientUpdateInfo == null) {
33 clientUpdateInfo = new UpdateInfo();
34 clientUpdateInfo.setUrlPrefix("http://127.0.0.1/juf/updates.xml");
35 }
36 } catch (IOException e) {
37 System.err.println("No se pudo obtener la información de la actualización");
38 System.exit(-1);
39 }
40
41 Update[] actualizaciones = null;
42 try {
43 actualizaciones = update.checkUpdates("sample", clientUpdateInfo, null);
44 UpdatePanel up = new UpdatePanel();
45 up.setModel(actualizaciones);
46 JDialog jf = new JDialog();
47 jf.setModal(true);
48 jf.getContentPane().add(up);
49 jf.setSize(new Dimension(400, 400));
50 jf.show();
51 actualizaciones = up.getSelectedUpdates();
52 } catch (DownloadException e1) {
53
54 e1.printStackTrace();
55 } catch (ClientStatusException e1) {
56
57 e1.printStackTrace();
58 } catch (IOException e1) {
59
60 e1.printStackTrace();
61 }
62
63 try {
64 for (int i = 0; i < actualizaciones.length; i++) {
65 update.doUpdate(null, clientUpdateInfo, "sample", actualizaciones[i], null);
66 }
67 } catch (BadConfigurationException e2) {
68
69 e2.printStackTrace();
70 } catch (ClientStatusException e2) {
71
72 e2.printStackTrace();
73 } catch (IOException e2) {
74
75 e2.printStackTrace();
76 } catch (InstallException e) {
77
78 e.printStackTrace();
79 }
80
81 System.exit(0);
82 }
83 }