⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ippprintservice.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        request.addOperationAttribute(printerUri);                if (flavor != null)          {            DocumentFormat f = DocumentFormat.createDocumentFormat(flavor);            request.addOperationAttribute(f);          }        response = request.send();                int status = response.getStatusCode();        if (! (status == IppStatusCode.SUCCESSFUL_OK             || status == IppStatusCode.SUCCESSFUL_OK_IGNORED_OR_SUBSTITUED_ATTRIBUTES             || status == IppStatusCode.SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES) )          {            logger.log(Component.IPP, "Statuscode not OK - got:" + status);          }      }    catch (IOException e)      {        // method cannot throw exception - just log        logger.log(Component.IPP, "IOException", e);      }    catch (IppException e)      {        // method cannot throw exception - just log        logger.log(Component.IPP, "IPPException", e);      }        return handleSupportedAttributeValuesResponse(response, category);  }    /**   * Called to handle the supported attribute values response for the given   * category. This might be overridden by subclasses with different requirements   * for parsing/handling the response from the GetPrinterAttributes.   *    * @param response the response of the GetPrinterAttributes IPP request   * @param category the category for which the supported values are requested   * @return A object indicating the supported values for the given attribute    * category, or <code>null</code> if this print service doesn't support the    * given attribute category at all.   *    * @see #getSupportedAttributeValues(Class, DocFlavor, AttributeSet)   */  protected Object handleSupportedAttributeValuesResponse(IppResponse response,     Class category)  {    List printerAtts = response.getPrinterAttributes();       // only one will be returned    Map printerAttribute = (Map) printerAtts.get(0);    Class suppCategory = IppUtilities.getSupportedCategory(category);    Set attr = (Set) printerAttribute.get(suppCategory);        // We sometime assume its a single instance with arbritrary value just indicating     // support or an array which is returned. This is because I sometimes just choosed    // what sounds right to me - as I have yet to find a printer which supports every     // special category in the SUN implementation to see what they return :-)        //  Map whats in the JSP API    if (suppCategory.equals(JobPrioritySupported.class))      return (JobPrioritySupported) attr.toArray(new JobPrioritySupported[1])[0];    if (suppCategory.equals(JobHoldUntilSupported.class))      return new JobHoldUntil(new Date());    if (suppCategory.equals(JobSheetsSupported.class))      return JobSheetsSupported.getAssociatedAttributeArray(attr);    if (suppCategory.equals(MultipleDocumentHandlingSupported.class))      return MultipleDocumentHandlingSupported.getAssociatedAttributeArray(attr);    if (suppCategory.equals(CopiesSupported.class))      return (CopiesSupported) attr.toArray(new CopiesSupported[1])[0];    if (suppCategory.equals(FinishingsSupported.class))      return FinishingsSupported.getAssociatedAttributeArray(attr);    if (suppCategory.equals(PageRangesSupported.class))      return new PageRanges[] { new PageRanges(1, Integer.MAX_VALUE) };        if (suppCategory.equals(OrientationRequestedSupported.class))      return OrientationRequestedSupported.getAssociatedAttributeArray(attr);    if (suppCategory.equals(MediaSupported.class))      return MediaSupported.getAssociatedAttributeArray(attr);    if (suppCategory.equals(PrinterResolutionSupported.class))      return PrinterResolutionSupported.getAssociatedAttributeArray(attr);    if (suppCategory.equals(PrintQualitySupported.class))      return PrintQualitySupported.getAssociatedAttributeArray(attr);    if (suppCategory.equals(CompressionSupported.class))      return CompressionSupported.getAssociatedAttributeArray(attr);    // Special handling as it might also be in range of integers    if (suppCategory.equals(NumberUpSupported.class))      {        NumberUpSupported[] tmp = (NumberUpSupported[])           attr.toArray(new NumberUpSupported[attr.size()]);        if (attr.size() == 1) // number-up maybe in rangeofintegers          return tmp[0];        int[][] members = new int[attr.size()][2];        for (int j = 0; j < attr.size(); j++)          {            int value = tmp[j].getMembers()[0][0];            members[j] = new int[] { value, value };          }        NumberUpSupported supported = new NumberUpSupported(members);        return supported;      }            return null;  }      /**   * @see javax.print.PrintService#getSupportedDocFlavors()   */  public DocFlavor[] getSupportedDocFlavors()  {    return (DocFlavor[]) flavors.toArray(new DocFlavor[flavors.size()]);  }  /**   * This is done by a validate-job operation and actually implemented in    * this generic IPP reference implementation. Subclasses which does   * not correctly support Validate-Job operation might want to override this.   *   * @see PrintService#getUnsupportedAttributes(DocFlavor, AttributeSet)   */  public AttributeSet getUnsupportedAttributes(DocFlavor flavor,                                               AttributeSet attributes)  {        if (flavor != null && !isDocFlavorSupported(flavor))      throw new IllegalArgumentException("flavor is not supported");    IppResponse response = null;    try      {        IppRequest request = new IppRequest(printerUri.getURI(), user, passwd);        short operationId = (short) OperationsSupported.VALIDATE_JOB.getValue();        request.setOperationID(operationId);        request.setOperationAttributeDefaults();        request.addOperationAttribute(printerUri);        request.addOperationAttribute(Fidelity.FIDELITY_TRUE);                if (attributes != null && attributes.size() > 0)          {            request.addAndFilterJobOperationAttributes(attributes);            request.addAndFilterJobTemplateAttributes(attributes);          }                if (flavor != null)          {            DocumentFormat f = DocumentFormat.createDocumentFormat(flavor);            request.addOperationAttribute(f);          }                response = request.send();                int status = response.getStatusCode();        if (! (status == IppStatusCode.SUCCESSFUL_OK             || status == IppStatusCode.SUCCESSFUL_OK_IGNORED_OR_SUBSTITUED_ATTRIBUTES             || status == IppStatusCode.SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES) )          {            logger.log(Component.IPP, "Statuscode not OK - got:" + status);          }      }    catch (IOException e)      {        // method cannot throw exception - just log        logger.log(Component.IPP, "IOException", e);      }    catch (IppException e)      {        // method cannot throw exception - just log        logger.log(Component.IPP, "IPPException", e);      }    // Validate Jobs returns only Unsupported and Operation      List unsupportedMaps = response.getUnsupportedAttributes();        if (unsupportedMaps.size() == 0)      return  null;        Map unsupportedAttr = (Map) unsupportedMaps.get(0);    if (unsupportedAttr.size() == 0)      return null;        // Convert the return map with unsupported attributes     // into an AttribueSet instance    HashAttributeSet set = new HashAttributeSet();    Iterator it = unsupportedAttr.values().iterator();    while (it.hasNext())      {        Set unsupported = (Set) it.next();        Iterator it2 = unsupported.iterator();        while (it2.hasNext())          set.add((Attribute) it2.next());              }        return set;  }  /**   * @see PrintService#isAttributeCategorySupported(Class)   */  public boolean isAttributeCategorySupported(Class category)  {    if (category == null)      throw new NullPointerException("category may not be null");        if (! Attribute.class.isAssignableFrom(category))      throw new IllegalArgumentException("category must be of type Attribute");        return Arrays.asList(getSupportedAttributeCategories()).contains(category);  }  /**   * @see PrintService#isAttributeValueSupported(Attribute, DocFlavor, AttributeSet)   */  public boolean isAttributeValueSupported(Attribute attrval, DocFlavor flavor,                                           AttributeSet attributes)  {    // just redirect to getSupportedAttributeValues        Object values = getSupportedAttributeValues(attrval.getCategory(),                                                 flavor, attributes);        // null means none supported    if (values == null)      return false;        // object may be an array    if (values.getClass().isArray())      return Arrays.asList((Object[]) values).contains(attrval);        // may be a single instance of the category (value is irrelevant)    if (values.getClass().equals(attrval.getCategory()))      return true;           // a single instance of another class to give the bounds        // copies    if (values.getClass().equals(CopiesSupported.class))      return ((CopiesSupported) values).contains((IntegerSyntax) attrval);        // number up    if (values.getClass().equals(NumberUpSupported.class))      return ((NumberUpSupported) values).contains((IntegerSyntax) attrval);        // job priority    if (values.getClass().equals(JobPrioritySupported.class))      {        JobPriority priority = (JobPriority) attrval;        JobPrioritySupported maxSupported = (JobPrioritySupported) values;        if (priority.getValue() < maxSupported.getValue())          return true;      }        // I am unsure if these might also show up - not yet found a printer where     // Suns implementation supports them:     // JobImpressionsSupported, JobKOctetsSupported, JobMediaSheetsSupported        return false;  }   /**   * @see javax.print.PrintService#isDocFlavorSupported(DocFlavor)   */  public boolean isDocFlavorSupported(DocFlavor flavor)  {    if (flavor == null)      throw new NullPointerException("DocFlavor may not be null.");        return flavors.contains(flavor);  }    /**   * @see PrintService#addPrintServiceAttributeListener(PrintServiceAttributeListener)   */  public void addPrintServiceAttributeListener(    PrintServiceAttributeListener listener)  {    printServiceAttributeListener.add(listener);  }    /**   * @see PrintService#removePrintServiceAttributeListener(PrintServiceAttributeListener)   */  public void removePrintServiceAttributeListener(    PrintServiceAttributeListener listener)  {    printServiceAttributeListener.remove(listener);  }    /**   * Returns "IppPrinter: " + <code>getName()</code>   * @return The string representation.   */  public String toString()  {    return "IppPrinter: " + getName();  }     /**   * Returns the printer-uri of this print service.   *    * @return The printer-uri attribute.   */  public PrinterURI getPrinterURI()  {    return printerUri;  }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -