當前位置: 首頁>>代碼示例>>Java>>正文


Java PrintService.getAttribute方法代碼示例

本文整理匯總了Java中javax.print.PrintService.getAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java PrintService.getAttribute方法的具體用法?Java PrintService.getAttribute怎麽用?Java PrintService.getAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.print.PrintService的用法示例。


在下文中一共展示了PrintService.getAttribute方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addPrintServiceToList

import javax.print.PrintService; //導入方法依賴的package包/類
private int addPrintServiceToList(ArrayList<PrintService> printerList, PrintService ps) {
    int index = printerList.indexOf(ps);
    // Check if PrintService with same name is already in the list.
    if (CUPSPrinter.isCupsRunning() && index != -1) {
        // Bug in Linux: Duplicate entry of a remote printer
        // and treats it as local printer but it is returning wrong
        // information when queried using IPP. Workaround is to remove it.
        // Even CUPS ignores these entries as shown in lpstat or using
        // their web configuration.
        PrinterURI uri = ps.getAttribute(PrinterURI.class);
        if (uri.getURI().getHost().equals("localhost")) {
            IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, ignoring the new local printer: "+ps);
            return index;  // Do not add this.
        }
        PrintService oldPS = printerList.get(index);
        uri = oldPS.getAttribute(PrinterURI.class);
        if (uri.getURI().getHost().equals("localhost")) {
            IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, removing existing local printer: "+oldPS);
            printerList.remove(oldPS);
        } else {
            return index;
        }
    }
    printerList.add(ps);
    return (printerList.size() - 1);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:PrintServiceLookupProvider.java

示例2: matchingService

import javax.print.PrintService; //導入方法依賴的package包/類
@SuppressWarnings("unchecked") // Cast to Class<PrintServiceAttribute>
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((Class<PrintServiceAttribute>)attrs[i].getCategory());
            if (serviceAttr == null || !serviceAttr.equals(attrs[i])) {
                return false;
            }
        }
    }
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:PrintServiceLookupProvider.java

示例3: main

import javax.print.PrintService; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
        String serviceName = service.getName();
        PrinterName name = service.getAttribute(PrinterName.class);
        String printerName = name.getValue();

        PrintService serviceByName = lookupByName(printerName);
        System.out.println("service " + service);
        System.out.println("serviceByName " + serviceByName);
        if (!service.equals(serviceByName)) {
            throw new RuntimeException("NOK " + serviceName
                               + " expected: " + service.getClass().getName()
                               + " got: " + serviceByName.getClass().getName());
        }
    }
    System.out.println("Test PASSED");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:GetPrintServices.java

示例4: setPrintService

import javax.print.PrintService; //導入方法依賴的package包/類
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 2D printing or no longer available.
 */
public void setPrintService(PrintService service)
    throws PrinterException {
    if (service == null) {
        throw new PrinterException("Service cannot be null");
    } else if (!(service instanceof StreamPrintService) &&
               service.getName() == null) {
        throw new PrinterException("Null PrintService name.");
    } else {
        // Check the list of services.  This service may have been
        // deleted already
        PrinterState prnState = (PrinterState)service.getAttribute(
                                              PrinterState.class);
        if (prnState == PrinterState.STOPPED) {
            PrinterStateReasons prnStateReasons =
                (PrinterStateReasons)service.getAttribute(
                                             PrinterStateReasons.class);
            if ((prnStateReasons != null) &&
                (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
            {
                throw new PrinterException("PrintService is no longer available.");
            }
        }


        if (service.isDocFlavorSupported(
                                         DocFlavor.SERVICE_FORMATTED.PAGEABLE) &&
            service.isDocFlavorSupported(
                                         DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            myService = service;
        } else {
            throw new PrinterException("Not a 2D print service: " + service);
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:46,代碼來源:RasterPrinterJob.java

示例5: matchingService

import javax.print.PrintService; //導入方法依賴的package包/類
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((Class<PrintServiceAttribute>)attrs[i].getCategory());
            if (serviceAttr == null || !serviceAttr.equals(attrs[i])) {
                return false;
            }
        }
    }
    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:16,代碼來源:Win32PrintServiceLookup.java

示例6: matchesAttributes

import javax.print.PrintService; //導入方法依賴的package包/類
private boolean matchesAttributes(PrintService service,
                                  PrintServiceAttributeSet attributes) {

    Attribute [] attrs =  attributes.toArray();
    Attribute serviceAttr;
    for (int i=0; i<attrs.length; i++) {
        serviceAttr
            = service.getAttribute((Class<PrintServiceAttribute>)attrs[i].getCategory());
        if (serviceAttr == null || !serviceAttr.equals(attrs[i])) {
            return false;
        }
    }
    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:15,代碼來源:UnixPrintServiceLookup.java

示例7: getServiceByName

import javax.print.PrintService; //導入方法依賴的package包/類
private PrintService getServiceByName(PrinterName nameAttr) {
    String name = nameAttr.getValue();
    if (name == null || name.equals("") || !checkPrinterName(name)) {
        return null;
    }
    /* check if all printers are already available */
    if (printServices != null) {
        for (PrintService printService : printServices) {
            PrinterName printerName =
                (PrinterName)printService.getAttribute(PrinterName.class);
            if (printerName.getValue().equals(name)) {
                return printService;
            }
        }
    }
    /* take CUPS into account first */
    if (CUPSPrinter.isCupsRunning()) {
        try {
            return new IPPPrintService(name,
                                       new URL("http://"+
                                               CUPSPrinter.getServer()+":"+
                                               CUPSPrinter.getPort()+"/"+
                                               name));
        } catch (Exception e) {
            IPPPrintService.debug_println(debugPrefix+
                                          " getServiceByName Exception "+
                                          e);
        }
    }
    /* fallback if nothing not having a printer at this point */
    PrintService printer = null;
    if (isMac() || isSysV()) {
        printer = getNamedPrinterNameSysV(name);
    } else if (isAIX()) {
        printer = getNamedPrinterNameAIX(name);
    } else {
        printer = getNamedPrinterNameBSD(name);
    }
    return printer;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:41,代碼來源:UnixPrintServiceLookup.java

示例8: setPrintService

import javax.print.PrintService; //導入方法依賴的package包/類
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws {@code PrinterException} if the specified service
 * cannot support the {@code Pageable} and
 * {@code Printable} interfaces necessary to support 2D printing.
 * @param service print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 2D printing or no longer available.
 */
public void setPrintService(PrintService service)
    throws PrinterException {
    if (service == null) {
        throw new PrinterException("Service cannot be null");
    } else if (!(service instanceof StreamPrintService) &&
               service.getName() == null) {
        throw new PrinterException("Null PrintService name.");
    } else {
        // Check the list of services.  This service may have been
        // deleted already
        PrinterState prnState = service.getAttribute(PrinterState.class);
        if (prnState == PrinterState.STOPPED) {
            PrinterStateReasons prnStateReasons =
                service.getAttribute(PrinterStateReasons.class);
            if ((prnStateReasons != null) &&
                (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
            {
                throw new PrinterException("PrintService is no longer available.");
            }
        }


        if (service.isDocFlavorSupported(
                                         DocFlavor.SERVICE_FORMATTED.PAGEABLE) &&
            service.isDocFlavorSupported(
                                         DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            myService = service;
        } else {
            throw new PrinterException("Not a 2D print service: " + service);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:44,代碼來源:RasterPrinterJob.java

示例9: matchesAttributes

import javax.print.PrintService; //導入方法依賴的package包/類
private boolean matchesAttributes(PrintService service,
                                  PrintServiceAttributeSet attributes) {

    Attribute [] attrs =  attributes.toArray();
    for (int i=0; i<attrs.length; i++) {
        @SuppressWarnings("unchecked")
        Attribute serviceAttr
            = service.getAttribute((Class<PrintServiceAttribute>)attrs[i].getCategory());
        if (serviceAttr == null || !serviceAttr.equals(attrs[i])) {
            return false;
        }
    }
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:PrintServiceLookupProvider.java

示例10: getServiceByName

import javax.print.PrintService; //導入方法依賴的package包/類
private PrintService getServiceByName(PrinterName nameAttr) {
    String name = nameAttr.getValue();
    if (name == null || name.equals("") || !checkPrinterName(name)) {
        return null;
    }
    /* check if all printers are already available */
    if (printServices != null) {
        for (PrintService printService : printServices) {
            PrinterName printerName = printService.getAttribute(PrinterName.class);
            if (printerName.getValue().equals(name)) {
                return printService;
            }
        }
    }
    /* take CUPS into account first */
    if (CUPSPrinter.isCupsRunning()) {
        try {
            return new IPPPrintService(name,
                                       new URL("http://"+
                                               CUPSPrinter.getServer()+":"+
                                               CUPSPrinter.getPort()+"/"+
                                               name));
        } catch (Exception e) {
            IPPPrintService.debug_println(debugPrefix+
                                          " getServiceByName Exception "+
                                          e);
        }
    }
    /* fallback if nothing not having a printer at this point */
    PrintService printer = null;
    if (isMac() || isSysV()) {
        printer = getNamedPrinterNameSysV(name);
    } else if (isAIX()) {
        printer = getNamedPrinterNameAIX(name);
    } else {
        printer = getNamedPrinterNameBSD(name);
    }
    return printer;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:40,代碼來源:PrintServiceLookupProvider.java

示例11: getPrintServices

import javax.print.PrintService; //導入方法依賴的package包/類
private PrintService[]
    getPrintServices(PrintServiceAttributeSet serviceSet) {

    if (serviceSet == null || serviceSet.isEmpty()) {
        return getPrintServices();
    }

    /* Typically expect that if a service attribute is specified that
     * its a printer name and there ought to be only one match.
     * Directly retrieve that service and confirm
     * that it meets the other requirements.
     * If printer name isn't mentioned then go a slow path checking
     * all printers if they meet the reqiremements.
     */
    PrintService[] services;
    PrinterName name = (PrinterName)serviceSet.get(PrinterName.class);
    PrintService defService;
    if (name != null && (defService = getDefaultPrintService()) != null) {
        /* To avoid execing a unix command  see if the client is asking
         * for the default printer by name, since we already have that
         * initialised.
         */

        PrinterName defName =
            (PrinterName)defService.getAttribute(PrinterName.class);

        if (defName != null && name.equals(defName)) {
            if (matchesAttributes(defService, serviceSet)) {
                services = new PrintService[1];
                services[0] = defService;
                return services;
            } else {
                return new PrintService[0];
            }
        } else {
            /* Its not the default service */
            PrintService service = getServiceByName(name);
            if (service != null &&
                matchesAttributes(service, serviceSet)) {
                services = new PrintService[1];
                services[0] = service;
                return services;
            } else {
                return new PrintService[0];
            }
        }
    } else {
        /* specified service attributes don't include a name.*/
        Vector matchedServices = new Vector();
        services = getPrintServices();
        for (int i = 0; i< services.length; i++) {
            if (matchesAttributes(services[i], serviceSet)) {
                matchedServices.add(services[i]);
            }
        }
        services = new PrintService[matchedServices.size()];
        for (int i = 0; i< services.length; i++) {
            services[i] = (PrintService)matchedServices.elementAt(i);
        }
        return services;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:63,代碼來源:UnixPrintServiceLookup.java

示例12: getPrintServices

import javax.print.PrintService; //導入方法依賴的package包/類
private PrintService[]
    getPrintServices(PrintServiceAttributeSet serviceSet) {

    if (serviceSet == null || serviceSet.isEmpty()) {
        return getPrintServices();
    }

    /* Typically expect that if a service attribute is specified that
     * its a printer name and there ought to be only one match.
     * Directly retrieve that service and confirm
     * that it meets the other requirements.
     * If printer name isn't mentioned then go a slow path checking
     * all printers if they meet the reqiremements.
     */
    PrintService[] services;
    PrinterName name = (PrinterName)serviceSet.get(PrinterName.class);
    PrintService defService;
    if (name != null && (defService = getDefaultPrintService()) != null) {
        /* To avoid execing a unix command  see if the client is asking
         * for the default printer by name, since we already have that
         * initialised.
         */

        PrinterName defName = defService.getAttribute(PrinterName.class);

        if (defName != null && name.equals(defName)) {
            if (matchesAttributes(defService, serviceSet)) {
                services = new PrintService[1];
                services[0] = defService;
                return services;
            } else {
                return new PrintService[0];
            }
        } else {
            /* Its not the default service */
            PrintService service = getServiceByName(name);
            if (service != null &&
                matchesAttributes(service, serviceSet)) {
                services = new PrintService[1];
                services[0] = service;
                return services;
            } else {
                return new PrintService[0];
            }
        }
    } else {
        /* specified service attributes don't include a name.*/
        Vector<PrintService> matchedServices = new Vector<>();
        services = getPrintServices();
        for (int i = 0; i< services.length; i++) {
            if (matchesAttributes(services[i], serviceSet)) {
                matchedServices.add(services[i]);
            }
        }
        services = new PrintService[matchedServices.size()];
        for (int i = 0; i< services.length; i++) {
            services[i] = matchedServices.elementAt(i);
        }
        return services;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:62,代碼來源:PrintServiceLookupProvider.java


注:本文中的javax.print.PrintService.getAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。