Package javax.print

Examples of javax.print.PrintException


            throws PrintException {
        if (response.getStatusCode() != 0) {
            String status = Integer.toHexString(response.getStatusCode());
            String id = Integer.toHexString(response.getRequestId());

            throw new PrintException(prefix
                    + "\n================ IPP response id: 0x" + id
                    + " =====================" + "\nresponse status code: 0x"
                    + status + "\n" + response.toString()
                    + "\n================ end IPP response 0x" + id
                    + " =====================");
View Full Code Here


     * Starts parsing of source postscript and rendering
     * to print service's device context.
     */
    public void interpret() throws PrintException {
        if (serviceID < 0) {
            throw new PrintException(
                    "Unrecoverable internal error in GDI client.");
        }
        try {
            currentLine = source.readLine();
            while (currentLine != null) {
                if (currentLine.startsWith("%%EOF")) {
//                    /*
//                     * Code for debug. Prints additional page.
//                     */
//                    startPage(serviceID);
//                    setRGBColor(serviceID, 0.5, 0.5, 0.5);
//                    moveTo(serviceID, 50, 50);
//                    drawText(serviceID, "TEXT TEXT TEXT");
//                    endPage(serviceID);
                    if (!endDocument(serviceID)) {
                        releaseServiceID(serviceID);
                        serviceID = -1;
                        throw new PrintException(
                                "Unable to finish document printing.");
                    }
                    releaseServiceID(serviceID);
                    serviceID = -1;
                    return;
                } else if (currentLine.startsWith("%%")) {
                    interpretComment();
                } else if (currentLine.startsWith("%") ||
                           currentLine.startsWith("/")) {
                    // Nothing to do - simple comment.
                } else {
                    String lexem = getNextLexem();
                    while (lexem != null) {
//                        System.out.println("Lexem: " + lexem);
                        queue.add(lexem);
                        for (int i = 0; i < commands.length; i++) {
                            if (lexem.equals(commands[i])) {
                                interpretCommand(i);
                            }
                        }
                        lexem = getNextLexem();
                    }
                }
                currentLine = source.readLine();
                lineIndex = 0;
            }
            endDocument(serviceID);
        } catch (IOException ioe) {
            throw new PrintException(
                    "Unrecoverable internal error in GDI client.");
        }
    }
View Full Code Here

                String pageName = getNextLexem(currentLine, 7);
                String pageNumber = getNextLexem(currentLine, searchingIndex);
                int number = Integer.parseInt(pageNumber);
                if (!startPage(serviceID)) {
                    endDocument(serviceID);
                    throw new PrintException("Unable to start page printing.");
                }
            } catch (NumberFormatException nfe) {
                System.out.println("NumberFormatException occured: " + nfe);
                nfe.printStackTrace(System.out);
            }
        } else if (currentLine.startsWith("%%EndPage:")) {
            try {
                String pageName = getNextLexem(currentLine, 10);
                String pageNumber = getNextLexem(currentLine, searchingIndex);
                int number = Integer.parseInt(pageNumber);
                if (pathOpened) {
                    closePath(serviceID);
                    pathOpened = false;
                }
                endPage(serviceID);
            } catch (NumberFormatException nfe) {
                System.out.println("NumberFormatException occured: " + nfe);
                nfe.printStackTrace(System.out);
            }
        } else if (currentLine.startsWith("%%EndSetup") ||
                   currentLine.startsWith("%%EndComments")) {
            if (!startDocument(service, serviceID, client.convertAttributes(
                    attributes,
                    new DocFlavor.INPUT_STREAM("INTERNAL/postscript")),
                    client.getJobName(attributes),
                    client.getDestination(attributes))) {
                throw new PrintException("Unable to start document printing.");
            }
        }
    }
View Full Code Here

                        data = ((URL)doc.getPrintData()).openStream();
                    } else {
                        data = doc.getStreamForBytes();
                    }
                } catch (IOException ioe) {
                    throw new PrintException(
                            "Can't read data from document souce");
                }
                int printerID = startDocPrinter(serviceName,
                        convertAttributes(attributes, flavor),
                        getJobName(attributes), getDestination(attributes));
                if (printerID != 0) {
                    byte[] buffer = new byte[10240];
                    try {
                        int bytesRead = data.read(buffer);
                        while (bytesRead >= 0) {
                            if (!writePrinter(buffer, bytesRead, printerID)) {
                                endDocPrinter(printerID);
                                throw new PrintException(
                                        "Can't send data to printer");
                            }
                            bytesRead = data.read(buffer);
                        }
                    } catch (IOException ioe) {
                        throw new PrintException(
                                "Can't read print data from Doc");
                    }
                    if (!endDocPrinter(printerID)) {
                        throw new PrintException("Can't finish job normally");
                    }
                } else {
                    throw new PrintException("Can't start printing");
                }
            } else if (flavor.getMimeType().toLowerCase().equals(
                           "internal/postscript") &&
                       flavor.getRepresentationClassName().equals(
                           "java.io.InputStream")) {
                InputStream data = null;
                try {
                    data = (InputStream)doc.getPrintData();
                } catch (IOException ioe) {
                    throw new PrintException(
                            "Can't read data from document souce");
                }
                PSInterpreter interpreter = new PSInterpreter(data, serviceName,
                        this, attributes);
                interpreter.interpret();
            } else {
                throw new PrintException("DocFlavor is not supported");
            }
        }
    }
View Full Code Here

        if (attrs != null) {
            if (attrs.containsKey(Destination.class)) {
                Destination destination =
                    (Destination)attrs.get(Destination.class);
                if (!destination.getURI().getScheme().equals("file")) {
                    throw new PrintException(
                            "Only files supported as destinations.");
                }
                String file = destination.getURI().getPath();
                if (file.startsWith("/")) {
                    file = file.substring(1);
View Full Code Here

    public void print(Doc userDoc, PrintRequestAttributeSet printRequestAS)
            throws PrintException {

        synchronized (this) {
            if (busyFlag) {
                throw new PrintException(
                        "Already printed. Need to create new DocPrintJob.");
            }
            busyFlag = true;
        }
       
        DocFlavor userDocDF = userDoc.getDocFlavor();

        /*
         * Checking if doc.DocFlavor is supported by the current
         * PrintService
         */
        if (!printService.isDocFlavorSupported(userDocDF)) {
            throw new PrintException("Doc flavor \'" + userDocDF
                    + "\' is not supported");
        }

        /*
         * Checking if doc.DocFlavor is supported directly by osClent. If it
         * is not: - get StereamPrintServiceFactory for doc.DocFlavor -
         * instantiate StreamPrintService - get PrintJob from it - run this
         * PrintJob in separate thread
         */
        printClient = printService.getPrintClient();
        if (printService.isDocFlavorSupportedByClient(userDocDF)) {
            printClient.print(userDoc, printRequestAS);
        } else {
            try {
                Doc clientDoc = userDoc;
                PipedOutputStream spsOutStream = new PipedOutputStream();
                PipedInputStream clientInputStream = new PipedInputStream(
                        spsOutStream);

                DocFlavor newFlavor = null;
                StreamPrintServiceFactory spsf = null;
                DocFlavor clientFlavors[] = printClient
                        .getSupportedDocFlavors();

                for (int i = 0; i < clientFlavors.length; i++) {
                    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                            .lookupStreamPrintServiceFactories(userDocDF,
                                    clientFlavors[i].getMimeType());
                    if (factories.length > 0
                            && Class.forName(
                                    clientFlavors[i]
                                            .getRepresentationClassName())
                                    .isInstance(clientInputStream)) {
                        spsf = factories[0];
                        newFlavor = clientFlavors[i];
                        break;
                    }
                }

                if (spsf != null) {
                    StreamPrintService sps = spsf.getPrintService(spsOutStream);

                    /*
                     * Constructing new Doc object for client: - connecting
                     * InputStream of client with OutputStream of
                     * StreamPrintSrevice - constructing DocFlavor for
                     * StreamPrintSrevice output - creating new SimpleDoc
                     * for client
                     */
                    clientDoc = new SimpleDoc(clientInputStream, newFlavor,
                            userDoc.getAttributes());

                    PrintJobThread printThread = new PrintJobThread(this,
                            userDoc, printRequestAS, sps);
                    printThread.start();
                    printClient.print(clientDoc, printRequestAS);

                    if (printThread.exceptionOccured()) {
                        throw new PrintException(printThread
                                .getPrintException());
                    }
                } else {
                    throw new PrintException("Doc flavor "
                            + userDocDF.getRepresentationClassName()
                            + " is not supported");
                }
            } catch (ClassNotFoundException e) {
                throw new PrintException(e);
            } catch (IOException e) {
                throw new PrintException(e);
            } catch (PrintException e) {
                throw e;
            }
        }
    }
View Full Code Here

        try {
            this.printeruri = new URI(name);
            this.printer = new IppPrinter(printeruri);
            this.attributeset = new HashPrintServiceAttributeSet();
        } catch (Exception e) {
            throw new PrintException(e);
        }
    }
View Full Code Here

                if (!(df instanceof DocFlavor.INPUT_STREAM
                        || df instanceof DocFlavor.BYTE_ARRAY
                        || df instanceof DocFlavor.CHAR_ARRAY
                        || df instanceof DocFlavor.STRING
                        || df instanceof DocFlavor.READER || df instanceof DocFlavor.URL)) {
                    throw new PrintException("Doc flavor "
                            + df.getRepresentationClassName()
                            + " is not supported yet");
                }

                HashAttributeSet as = new HashAttributeSet();
                DocAttributeSet das;
                das = doc.getAttributes();

                // construct attributes
                if (das != null) {
                    as.addAll(das);
                }
                if (attributes != null) {
                    as.addAll(attributes);
                }
                as.addAll(attributeset);

                // print
                if (as.containsKey(Destination.class)) {
                    print2destination(doc, (Destination) as
                            .get(Destination.class));
                } else {
                    printsimple(doc, as);
                }
            } catch (PrintException e) {
                throw e;
            } catch (Exception e) {
                throw new PrintException(e);
            }
        }
    }
View Full Code Here

            }

            bw.flush();
            bw.close();
        } catch (Exception e) {
            throw new PrintException(e);
        }
    }
View Full Code Here

            throw e;
        } catch (Exception e) {
            if (getVerbose() > 1) {
                e.printStackTrace();
            }
            throw new PrintException(e);
        }
    }
View Full Code Here

TOP

Related Classes of javax.print.PrintException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.