397 debug_println(debugPrefix+"initAttributes, NULL urlConnection ");
398 init = true;
399 return;
400 }
401
402 // get all supported attributes through IPP
403 opGetAttributes();
404
405 if (isCupsPrinter) {
406 // note, it is possible to query media in CUPS using IPP
407 // right now we always get it from PPD.
408 // maybe use "&& (usePPD)" later?
409 // Another reason why we use PPD is because
410 // IPP currently does not support it but PPD does.
411
412 try {
413 cps = new CUPSPrinter(printer);
414 mediaSizeNames = cps.getMediaSizeNames();
415 mediaTrays = cps.getMediaTrays();
416 customMediaSizeNames = cps.getCustomMediaSizeNames();
417 urlConnection.disconnect();
418 init = true;
419 return;
420 } catch (Exception e) {
421 IPPPrintService.debug_println(debugPrefix+
422 "initAttributes, error creating CUPSPrinter e="+e);
423 }
424 }
425
426 // use IPP to get all media,
427 Media[] allMedia = (Media[])getSupportedMedia();
428 ArrayList sizeList = new ArrayList();
429 ArrayList trayList = new ArrayList();
430 for (int i=0; i<allMedia.length; i++) {
431 if (allMedia[i] instanceof MediaSizeName) {
432 sizeList.add(allMedia[i]);
433 } else if (allMedia[i] instanceof MediaTray) {
434 trayList.add(allMedia[i]);
435 }
436 }
1415 try {
1416 return new Destination(new URI("file:out.ps"));
1417 } catch (URISyntaxException e) {
1418 return null;
1419 }
1420 }
1421 } else if (category == Fidelity.class) {
1422 return Fidelity.FIDELITY_FALSE;
1423 } else if (category == Finishings.class) {
1424 return Finishings.NONE;
1425 } else if (category == JobName.class) {
1426 return new JobName("Java Printing", null);
1427 } else if (category == JobSheets.class) {
1428 if (attribClass != null &&
1429 attribClass.getStringValue().equals("none")) {
1430 return JobSheets.NONE;
1431 } else {
1432 return JobSheets.STANDARD;
1433 }
1434 } else if (category == Media.class) {
1435 defaultMediaIndex = 0;
1436 if (mediaSizeNames.length == 0) {
1437 String defaultCountry = Locale.getDefault().getCountry();
1438 if (defaultCountry != null &&
1439 (defaultCountry.equals("") ||
1440 defaultCountry.equals(Locale.US.getCountry()) ||
1441 defaultCountry.equals(Locale.CANADA.getCountry()))) {
1442 return MediaSizeName.NA_LETTER;
1443 } else {
1444 return MediaSizeName.ISO_A4;
1445 }
1446 }
1447
1448 if (attribClass != null) {
1449 String name = attribClass.getStringValue();
1450 if (isCupsPrinter) {
1451 for (int i=0; i< customMediaSizeNames.length; i++) {
1452 //REMIND: get default from PPD. In native _getMedia,
1453 // move default (ppd_option_t->defchoice) to index 0.
1454 // In the meantime, use indexOf because PPD name
1455 // may be different from the IPP attribute name.
1456 if (customMediaSizeNames[i].toString().indexOf(name)
1457 != -1) {
1458 defaultMediaIndex = i;
1459 return mediaSizeNames[defaultMediaIndex];
1460 }
1461 }
1462 } else {
1463 for (int i=0; i< mediaSizeNames.length; i++) {
1464 if (mediaSizeNames[i].toString().indexOf(name) != -1) {
1465 defaultMediaIndex = i;
1466 return mediaSizeNames[defaultMediaIndex];
1467 }
1468 }
1469 }
1470 }
1471 return mediaSizeNames[defaultMediaIndex];
1472
1473 } else if (category == MediaPrintableArea.class) {
1474 MediaPrintableArea[] mpas;
1475 if ((cps != null) &&
1476 ((mpas = cps.getMediaPrintableArea()) != null)) {
1477 if (defaultMediaIndex == -1) {
1478 // initializes value of defaultMediaIndex
1479 getDefaultAttributeValue(Media.class);
1480 }
1481 return mpas[defaultMediaIndex];
|
397 debug_println(debugPrefix+"initAttributes, NULL urlConnection ");
398 init = true;
399 return;
400 }
401
402 // get all supported attributes through IPP
403 opGetAttributes();
404
405 if (isCupsPrinter) {
406 // note, it is possible to query media in CUPS using IPP
407 // right now we always get it from PPD.
408 // maybe use "&& (usePPD)" later?
409 // Another reason why we use PPD is because
410 // IPP currently does not support it but PPD does.
411
412 try {
413 cps = new CUPSPrinter(printer);
414 mediaSizeNames = cps.getMediaSizeNames();
415 mediaTrays = cps.getMediaTrays();
416 customMediaSizeNames = cps.getCustomMediaSizeNames();
417 defaultMediaIndex = cps.getDefaultMediaIndex();
418 urlConnection.disconnect();
419 init = true;
420 return;
421 } catch (Exception e) {
422 IPPPrintService.debug_println(debugPrefix+
423 "initAttributes, error creating CUPSPrinter e="+e);
424 }
425 }
426
427 // use IPP to get all media,
428 Media[] allMedia = (Media[])getSupportedMedia();
429 ArrayList sizeList = new ArrayList();
430 ArrayList trayList = new ArrayList();
431 for (int i=0; i<allMedia.length; i++) {
432 if (allMedia[i] instanceof MediaSizeName) {
433 sizeList.add(allMedia[i]);
434 } else if (allMedia[i] instanceof MediaTray) {
435 trayList.add(allMedia[i]);
436 }
437 }
1416 try {
1417 return new Destination(new URI("file:out.ps"));
1418 } catch (URISyntaxException e) {
1419 return null;
1420 }
1421 }
1422 } else if (category == Fidelity.class) {
1423 return Fidelity.FIDELITY_FALSE;
1424 } else if (category == Finishings.class) {
1425 return Finishings.NONE;
1426 } else if (category == JobName.class) {
1427 return new JobName("Java Printing", null);
1428 } else if (category == JobSheets.class) {
1429 if (attribClass != null &&
1430 attribClass.getStringValue().equals("none")) {
1431 return JobSheets.NONE;
1432 } else {
1433 return JobSheets.STANDARD;
1434 }
1435 } else if (category == Media.class) {
1436 if (defaultMediaIndex == -1) {
1437 defaultMediaIndex = 0;
1438 }
1439 if (mediaSizeNames.length == 0) {
1440 String defaultCountry = Locale.getDefault().getCountry();
1441 if (defaultCountry != null &&
1442 (defaultCountry.equals("") ||
1443 defaultCountry.equals(Locale.US.getCountry()) ||
1444 defaultCountry.equals(Locale.CANADA.getCountry()))) {
1445 return MediaSizeName.NA_LETTER;
1446 } else {
1447 return MediaSizeName.ISO_A4;
1448 }
1449 }
1450
1451 if (attribClass != null) {
1452 String name = attribClass.getStringValue();
1453 if (isCupsPrinter) {
1454 return mediaSizeNames[defaultMediaIndex];
1455 } else {
1456 for (int i=0; i< mediaSizeNames.length; i++) {
1457 if (mediaSizeNames[i].toString().indexOf(name) != -1) {
1458 defaultMediaIndex = i;
1459 return mediaSizeNames[defaultMediaIndex];
1460 }
1461 }
1462 }
1463 }
1464 return mediaSizeNames[defaultMediaIndex];
1465
1466 } else if (category == MediaPrintableArea.class) {
1467 MediaPrintableArea[] mpas;
1468 if ((cps != null) &&
1469 ((mpas = cps.getMediaPrintableArea()) != null)) {
1470 if (defaultMediaIndex == -1) {
1471 // initializes value of defaultMediaIndex
1472 getDefaultAttributeValue(Media.class);
1473 }
1474 return mpas[defaultMediaIndex];
|