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: /**
18: * @author Igor A. Pyankov
19: * @version $Revision: 1.2 $
20: */package javax.print;
21:
22: import java.io.InputStream;
23:
24: import javax.print.attribute.HashDocAttributeSet;
25: import javax.print.attribute.HashPrintRequestAttributeSet;
26: import javax.print.attribute.PrintRequestAttributeSet;
27: import javax.print.attribute.standard.Copies;
28: import javax.print.attribute.standard.MediaName;
29: import javax.print.attribute.standard.MediaSizeName;
30: import javax.print.attribute.standard.Sides;
31:
32: import junit.framework.TestCase;
33:
34: public class LookupDefaultPrintServiceTest extends TestCase {
35: public void testLookupDefaultPrintService() throws Exception {
36: System.out
37: .println("======= START LookupDefaultPrintServiceTest ======");
38:
39: DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
40: PrintService service;
41: InputStream fis;
42: PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
43: HashDocAttributeSet daset = new HashDocAttributeSet();
44: DocPrintJob pj;
45: Doc doc;
46:
47: aset.add(new Copies(2));
48: aset.add(MediaSizeName.ISO_A4);
49: daset.add(MediaName.ISO_A4_WHITE);
50: daset.add(Sides.TWO_SIDED_LONG_EDGE);
51:
52: service = PrintServiceLookup.lookupDefaultPrintService();
53: if (service != null) {
54: if (service.isDocFlavorSupported(psFlavor)) {
55: if (service.getUnsupportedAttributes(psFlavor, aset) == null) {
56: fis = this .getClass().getResourceAsStream(
57: "/Resources/GIF.gif");
58: doc = new SimpleDoc(fis, psFlavor, daset);
59:
60: pj = service.createPrintJob();
61: pj.print(doc, aset);
62: System.out.println(fis.toString() + " printed on "
63: + service.getName());
64: }
65: } else {
66: System.out.println("flavor is not supported");
67: }
68: } else {
69: System.out.println("service not found");
70: }
71:
72: System.out
73: .println("======= END LookupDefaultPrintServiceTest =======");
74: }
75:
76: }
|