01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.harmony.x.print;
18:
19: import java.util.Vector;
20:
21: import javax.print.DocFlavor;
22: import javax.print.MultiDocPrintService;
23: import javax.print.PrintException;
24: import javax.print.PrintService;
25: import javax.print.PrintServiceLookup;
26: import javax.print.attribute.AttributeSet;
27:
28: public class WinPrintServiceLookup extends PrintServiceLookup {
29:
30: @Override
31: public PrintService getDefaultPrintService() {
32: try {
33: final String name = WinPrinterFactory
34: .getDefaultPrinterName();
35: return (name != null) ? new WinPrintService(name) : null;
36: } catch (PrintException e) {
37: return null;
38: }
39: }
40:
41: @Override
42: public MultiDocPrintService[] getMultiDocPrintServices(
43: final DocFlavor[] flavors, final AttributeSet attributes) {
44: return new MultiDocPrintService[0];
45: }
46:
47: @Override
48: public PrintService[] getPrintServices() {
49: try {
50: final String[] names = WinPrinterFactory
51: .getConnectedPrinterNames();
52: final PrintService[] srv = new PrintService[names.length];
53:
54: for (int i = 0; i < names.length; i++) {
55: srv[i] = new WinPrintService(names[i]);
56: }
57:
58: return srv;
59: } catch (PrintException e) {
60: return new PrintService[0];
61: }
62: }
63:
64: @Override
65: public PrintService[] getPrintServices(final DocFlavor flavor,
66: final AttributeSet attributes) {
67: final PrintService[] matchingServices;
68: final PrintService[] allServices = getPrintServices();
69: final Vector<PrintService> v = new Vector<PrintService>(
70: allServices.length);
71:
72: for (PrintService srv : allServices) {
73: if (((flavor == null) || srv.isDocFlavorSupported(flavor))
74: && (srv
75: .getUnsupportedAttributes(flavor,
76: attributes) == null)) {
77: v.add(srv);
78: }
79: }
80:
81: matchingServices = new PrintService[v.size()];
82: return v.toArray(matchingServices);
83: }
84: }
|