annotate client/src/main/java/info/textgrid/middleware/digilib/clients/cli/DigilibCli.java @ 7:39c4892724ae

new version with maven modules for service and client.
author casties
date Thu, 16 Jun 2011 17:33:06 +0200
parents
children 99bd25677ba8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
1 /**
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
2 *
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
3 */
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
4 package info.textgrid.middleware.digilib.clients.cli;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
5
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
6 import java.io.File;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
7 import java.io.FileOutputStream;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
8 import java.io.IOException;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
9 import java.io.OutputStream;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
10
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
11 import javax.xml.ws.Holder;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
12
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
13 import info.textgrid.namespaces.middleware.digilib.services.digilibservice.DigilibService;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
14 import info.textgrid.namespaces.middleware.digilib.services.digilibservice.DigilibServicePortType;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
15
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
16 /**
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
17 * @author casties
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
18 *
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
19 */
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
20 public class DigilibCli {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
21
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
22 /**
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
23 * @param args
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
24 */
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
25 public static void main(String[] args) {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
26 if (args.length != 4) {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
27 System.err.println("use: DgibilibCli SID URI QUERY FILENAME");
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
28 System.exit(1);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
29 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
30 String sid = args[0];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
31 String uri = args[1];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
32 String query = args[2];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
33 String filename = args[3];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
34 // call service
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
35 byte[] imageData = getScaledImage(sid, uri, query);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
36 // try to copy to file
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
37 System.out.println("writing " + filename);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
38 File f = new File(filename);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
39 try {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
40 OutputStream ostream = new FileOutputStream(f);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
41 ostream.write(imageData);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
42 ostream.close();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
43 } catch (IOException e) {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
44 // TODO Auto-generated catch block
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
45 e.printStackTrace();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
46 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
47 System.out.println("Done.");
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
48 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
49
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
50 public static byte[] getScaledImage(String sid, String uri, String query) {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
51 DigilibService service = new DigilibService();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
52 DigilibServicePortType port = service.getDigilibServicePort();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
53 String logParam = null;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
54 // Holder for return data
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
55 Holder<String> mimeType = new Holder<String>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
56 Holder<byte[]> imageData = new Holder<byte[]>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
57 Holder<Integer> width = new Holder<Integer>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
58 Holder<Integer> height = new Holder<Integer>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
59 // call service -- fills Holder
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
60 port.getScaledImage(sid, uri, query, logParam, mimeType, imageData, width, height);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
61 System.out.println("mimeType="+mimeType.value);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
62 System.out.println("imageData="+imageData.value);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
63 System.out.println("width="+width.value);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
64 System.out.println("height="+height.value);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
65 return imageData.value;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
66 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
67
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
68 }