for (int i = 0; i < cupses.length; i++) {
try {
URI cupsuri = new URI(cupses[i]);
IppClient c = new IppClient(cupsuri);
IppRequest request;
IppResponse response;
IppAttributeGroup agroup;
Vector va = new Vector();
request = new IppRequest(1, 1,
IppOperation.TAG_CUPS_GET_DEFAULT, "utf-8", "en-us");
agroup = request
.getGroup(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES);
va.add("printer-uri-supported".getBytes());
agroup.add(new IppAttribute(IppAttribute.TAG_KEYWORD,
"requested-attributes", va));
response = c.request(request.getBytes());
IppAttributeGroup g = response
.getGroup(IppAttributeGroup.TAG_GET_PRINTER_ATTRIBUTES);
if (g != null) {
int ai = g.findAttribute("printer-uri-supported");
if (ai >= 0) {
IppAttribute a = (IppAttribute) g.get(ai);
Vector v = a.getValue();
if (v.size() > 0) {
serviceName = new String((byte[]) v.get(0));
break;
}
}
}
} catch (URISyntaxException e) {
//e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
//e.printStackTrace();
}
}
if (serviceName != null && !serviceName.equals("")) {
return serviceName;
}
String[] ippp = CUPSPrintServiceProvider.getIppPrintersByProperty();
for (int i = 0; i < ippp.length; i++) {
try {
URI ippuri = new URI(ippp[i]);
IppClient c = new IppClient(ippuri);
IppRequest request;
IppResponse response;
IppAttributeGroup agroup;
Vector va = new Vector();
request = new IppRequest(1, 1,
IppOperation.GET_PRINTER_ATTRIBUTES, "utf-8", "en-us");
agroup = request
.getGroup(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES);
va.add("printer-uri-supported".getBytes());
agroup.add(new IppAttribute(IppAttribute.TAG_KEYWORD,
"requested-attributes", va));
response = c.request(request.getBytes());
IppAttributeGroup g = response
.getGroup(IppAttributeGroup.TAG_GET_PRINTER_ATTRIBUTES);
if (g != null) {
int ai = g.findAttribute("printer-uri-supported");
if (ai >= 0) {