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

📄 ippprintservice.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                flavors.add(DocFlavor.CHAR_ARRAY.TEXT_HTML);                flavors.add(DocFlavor.READER.TEXT_HTML);                flavors.add(DocFlavor.STRING.TEXT_HTML);                                // add utf-8                mimeType = mimeType + "; charset=utf-8";              }                        // Process the predefined DocFlavors and if mimetype is            // equal put them into the flavors array - otherwise            // just build them as binarie class representation.            boolean changed = false;            try              {                Class[] clazzes = new Class[] { DocFlavor.BYTE_ARRAY.class,                                                DocFlavor.INPUT_STREAM.class,                                                DocFlavor.URL.class };                                                 for (int j = 0; j < clazzes.length; j++)                  {                    Field[] fields = clazzes[j].getDeclaredFields();                    for (int i = 0; i < fields.length; i++)                      {                        if (fields[i].getType().equals(clazzes[j]))                          {                            DocFlavor flavor = (DocFlavor) fields[i].get(null);                            if (flavor.getMimeType().equals(mimeType))                              changed = flavors.add(flavor);                          }                      }                  }                if (!changed) // not in predefined constants of DocFlavor                  {                                        // everything should be supported as binary stuff                    flavors.add(new DocFlavor(mimeType, "[B"));                    flavors.add(new DocFlavor(mimeType, "java.io.InputStream"));                    flavors.add(new DocFlavor(mimeType, "java.net.URL"));                  }              }            catch (SecurityException e)              {                // should not happen              }            catch (IllegalArgumentException e)              {                // should not happen              }            catch (IllegalAccessException e)              {                // should not happen, all fields are public              }          }      }        // printer uris    Set uris = getPrinterAttributeSet(PrinterUriSupported.class);    printerUris = new ArrayList(uris.size());    Iterator it = uris.iterator();    while (it.hasNext())      {        PrinterUriSupported uri = (PrinterUriSupported) it.next();        printerUris.add( new PrinterURI(uri.getURI()));      }  }  /**   * We always return a implementation implementing CancelablePrintJob.   *    * @see javax.print.PrintService#createPrintJob()   */  public DocPrintJob createPrintJob()  {    return new DocPrintJobImpl(this, user, passwd);  }    /**   * @see javax.print.PrintService#getAttribute(java.lang.Class)   */  public PrintServiceAttribute getAttribute(Class category)  {    if (category == null)      throw new NullPointerException("category may not be null");        if (! PrintServiceAttribute.class.isAssignableFrom(category))      throw new IllegalArgumentException(         "category must be of type PrintServiceAttribute");        Set set = getPrinterAttributeSet(category);    if (set != null && set.size() > 0)             return (PrintServiceAttribute) set.toArray()[0];            return null;  }  /**   * @see javax.print.PrintService#getAttributes()   */  public PrintServiceAttributeSet getAttributes()  {    PrintServiceAttributeSet set = new HashPrintServiceAttributeSet();        Iterator it = printerAttr.values().iterator();    while (it.hasNext())      {                Iterator it2 = ((Set) it.next()).iterator();        while (it2.hasNext())          {            Attribute attr = (Attribute) it2.next();            if (attr instanceof PrintServiceAttribute)              set.add(attr);          }      }        return AttributeSetUtilities.unmodifiableView(set);  }  /**   * @see javax.print.PrintService#getDefaultAttributeValue(java.lang.Class)   */  public Object getDefaultAttributeValue(Class category)  {     // required attributes    if (category.equals(Fidelity.class))      return Fidelity.FIDELITY_FALSE;        if (category.equals(JobName.class))      return JOB_NAME;    if (category.equals(RequestingUserName.class))      return REQUESTING_USER_NAME;        // optional attributes    if (category.equals(JobPriority.class)         && printerAttr.containsKey(JobPriorityDefault.class))      return getPrinterDefaultAttribute(JobPriorityDefault.class);    if (category.equals(JobHoldUntil.class)         && printerAttr.containsKey(JobHoldUntilDefault.class))      return getPrinterDefaultAttribute(JobHoldUntilDefault.class);    if (category.equals(JobSheets.class)         && printerAttr.containsKey(JobSheetsDefault.class))      return getPrinterDefaultAttribute(JobSheetsDefault .class);    if (category.equals(MultipleDocumentHandling.class)         && printerAttr.containsKey(MultipleDocumentHandlingDefault.class))      return getPrinterDefaultAttribute(MultipleDocumentHandlingDefault.class);    if (category.equals(Copies.class)         && printerAttr.containsKey(CopiesDefault.class))      return getPrinterDefaultAttribute(CopiesDefault.class);    if (category.equals(Finishings.class)         && printerAttr.containsKey(FinishingsDefault.class))      return getPrinterDefaultAttribute(FinishingsDefault.class);    if (category.equals(Sides.class)         && printerAttr.containsKey(SidesDefault.class))      return getPrinterDefaultAttribute(SidesDefault.class);    if (category.equals(NumberUp.class)         && printerAttr.containsKey(NumberUpDefault.class))      return getPrinterDefaultAttribute(NumberUpDefault.class);    if (category.equals(OrientationRequested.class)         && printerAttr.containsKey(OrientationRequestedDefault.class))      return getPrinterDefaultAttribute(OrientationRequestedDefault.class);    if (category.equals(Media.class)         && printerAttr.containsKey(MediaDefault.class))      return getPrinterDefaultAttribute(MediaDefault.class);    if (category.equals(PrinterResolution.class)         && printerAttr.containsKey(PrinterResolutionDefault.class))      return getPrinterDefaultAttribute(PrinterResolutionDefault.class);    if (category.equals(PrintQuality.class)         && printerAttr.containsKey(PrintQualityDefault.class))      return getPrinterDefaultAttribute(PrintQualityDefault.class);    if (category.equals(Compression.class)         && printerAttr.containsKey(CompressionSupported.class))      return Compression.NONE;    if (category.equals(PageRanges.class))      return new PageRanges(1, Integer.MAX_VALUE);    return null;   }    /**   * We return the value of <code>PrinterName</code> here.   * @see javax.print.PrintService#getName()   */  public String getName()  {    return name;  }  /**   * We currently provide no factories - just returns null.   * @see javax.print.PrintService#getServiceUIFactory()   */  public ServiceUIFactory getServiceUIFactory()  {    // SUN does not provide any service factory for    // print services (tested on linux/windows)        // for the moment we do the same - just return null    // later on we could provide at least the about UI dialog    return null;  }  /**   * @see javax.print.PrintService#getSupportedAttributeCategories()   */  public Class[] getSupportedAttributeCategories()  {    Set categories = new HashSet();        // Should only be job template attributes as of section 4.2        if (printerAttr.containsKey(JobPrioritySupported.class))      categories.add(JobPriority.class);    if (printerAttr.containsKey(JobHoldUntilSupported.class))      categories.add(JobHoldUntil.class);    if (printerAttr.containsKey(JobSheetsSupported.class))      categories.add(JobSheets.class);    if (printerAttr.containsKey(MultipleDocumentHandlingSupported.class))      categories.add(MultipleDocumentHandling.class);        if (printerAttr.containsKey(CopiesSupported.class))      categories.add(Copies.class);    if (printerAttr.containsKey(FinishingsSupported.class))      {        // if only none finishing is supported - it does not count as supported        Set set = getPrinterAttributeSet(FinishingsSupported.class);                if (! (set.size() == 1 && set.contains(FinishingsSupported.NONE)))                    categories.add(Finishings.class);      }    if (printerAttr.containsKey(PageRangesSupported.class))      categories.add(PageRanges.class);    if (printerAttr.containsKey(SidesSupported.class))      categories.add(Sides.class);    if (printerAttr.containsKey(NumberUpSupported.class))      categories.add(NumberUp.class);    if (printerAttr.containsKey(OrientationRequestedSupported.class))      categories.add(OrientationRequested.class);    if (printerAttr.containsKey(MediaSupported.class))      categories.add(Media.class);    if (printerAttr.containsKey(PrinterResolutionSupported.class))      categories.add(PrinterResolution.class);    if (printerAttr.containsKey(PrintQualitySupported.class))      categories.add(PrintQuality.class);          // Chromaticity, Destination, MediaPrintableArea,     // SheetCollate, PresentationDirection - not IPP attributes        // attributes outside section 4.2       if (printerAttr.containsKey(CompressionSupported.class))      categories.add(Compression.class);    if (printerAttr.containsKey(JobImpressionsSupported.class))      categories.add(JobImpressions.class);    if (printerAttr.containsKey(JobKOctetsSupported.class))      categories.add(JobKOctets.class);    if (printerAttr.containsKey(JobMediaSheetsSupported.class))      categories.add(JobMediaSheets.class);        // always supported as required by IPP specification    categories.add(Fidelity.class);    categories.add(JobName.class);    categories.add(RequestingUserName.class);    return (Class[]) categories.toArray(new Class[categories.size()]);  }  /**   * Implemented by a GetPrinterAttributes request. Subclasses providing supported   * attribute values totally different may override this methods. Subclass only in   * need of handling the response differently may override the method   * <code>handleSupportedAttributeValuesResponse(IppResponse, Class)</code> only.   *    * @see PrintService#getSupportedAttributeValues(Class, DocFlavor, AttributeSet)   * @see #handleSupportedAttributeValuesResponse(IppResponse, Class)   */  public Object getSupportedAttributeValues(Class category, DocFlavor flavor,                                            AttributeSet attributes)  {    // We currently ignore the attribute set - there is nothing in the IPP    // specification which would come closer to what we do here.    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");    if (flavor != null && !isDocFlavorSupported(flavor))      throw new IllegalArgumentException("flavor is not supported");    if (!isAttributeCategorySupported(category))      return null;    // always supported    if (category.equals(Fidelity.class))      return new Fidelity[] { Fidelity.FIDELITY_FALSE, Fidelity.FIDELITY_TRUE };    if (category.equals(JobName.class))      return JOB_NAME;    if (category.equals(RequestingUserName.class))      return REQUESTING_USER_NAME;    // map category to category-supported    String categoryName = IppUtilities.getSupportedAttrName(category);    IppResponse response = null;    try      {        IppRequest request = new IppRequest(printerUri.getURI(), user, passwd);        request.setOperationID(          (short) OperationsSupported.GET_PRINTER_ATTRIBUTES.getValue());        request.setOperationAttributeDefaults();        request.addOperationAttribute(new RequestedAttributes(categoryName));

⌨️ 快捷键说明

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