boolean matchingService(PrintService service, PrintServiceAttributeSet serviceSet) {
   if (serviceSet != null) {
     Attribute[] attrs = serviceSet.toArray();
     Attribute serviceAttr;
     for (int i = 0; i < attrs.length; i++) {
       serviceAttr = service.getAttribute(attrs[i].getCategory());
       if (serviceAttr == null || !serviceAttr.equals(attrs[i])) {
         return false;
       }
     }
   }
   return true;
 }
Exemplo n.º 2
0
  private void getAttributeValues(DocFlavor flavor) throws PrintException {

    if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
      fidelity = true;
    } else {
      fidelity = false;
    }

    Class category;
    Attribute[] attrs = reqAttrSet.toArray();
    for (int i = 0; i < attrs.length; i++) {
      Attribute attr = attrs[i];
      category = attr.getCategory();
      if (fidelity == true) {
        if (!service.isAttributeCategorySupported(category)) {
          notifyEvent(PrintJobEvent.JOB_FAILED);
          throw new PrintJobAttributeException("unsupported category: " + category, category, null);
        } else if (!service.isAttributeValueSupported(attr, flavor, null)) {
          notifyEvent(PrintJobEvent.JOB_FAILED);
          throw new PrintJobAttributeException("unsupported attribute: " + attr, null, attr);
        }
      }
      if (category == Destination.class) {
        URI uri = ((Destination) attr).getURI();
        if (!"file".equals(uri.getScheme())) {
          notifyEvent(PrintJobEvent.JOB_FAILED);
          throw new PrintException("Not a file: URI");
        } else {
          try {
            mDestination = (new File(uri)).getPath();
          } catch (Exception e) {
            throw new PrintException(e);
          }
          // check write access
          SecurityManager security = System.getSecurityManager();
          if (security != null) {
            try {
              security.checkWrite(mDestination);
            } catch (SecurityException se) {
              notifyEvent(PrintJobEvent.JOB_FAILED);
              throw new PrintException(se);
            }
          }
        }
      } else if (category == JobName.class) {
        jobName = ((JobName) attr).getValue();
      } else if (category == Copies.class) {
        copies = ((Copies) attr).getValue();
      } else if (category == Media.class) {
        if (attr instanceof MediaSizeName) {
          mediaName = (MediaSizeName) attr;
          // If requested MediaSizeName is not supported,
          // get the corresponding media size - this will
          // be used to create a new PageFormat.
          if (!service.isAttributeValueSupported(attr, null, null)) {
            mediaSize = MediaSize.getMediaSizeForName(mediaName);
          }
        }
      } else if (category == OrientationRequested.class) {
        orient = (OrientationRequested) attr;
      }
    }
  }