Package javax.print

Examples of javax.print.DocFlavor$READER


      SwingUtilities.invokeLater(new Runnable() {
          public void run() {

            // Set the document type
            final DocFlavor messageFormat = DocFlavor.SERVICE_FORMATTED.PRINTABLE;

            // bring up a dialog.
            PrintService[] services = PrintServiceLookup.lookupPrintServices(messageFormat, null);

            PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
View Full Code Here


            baos.flush();
            baos.close();

            // Print is sent
            DocFlavor psInFormat = new DocFlavor.INPUT_STREAM(printerContentType);
            InputStream bais = new ByteArrayInputStream(baos.toByteArray());

            DocAttributeSet docAttributeSet = new HashDocAttributeSet();
            List<Object> docAttributes = UtilGenerics.checkList(serviceContext.remove("docAttributes"));
            if (UtilValidate.isNotEmpty(docAttributes)) {
View Full Code Here

        }
        if (flavor == null) {
            flavor = "DocFlavor.BYTE_ARRAY";
        }
       
        DocFlavor d = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        DocFlavorAssigner docFlavorAssigner = new DocFlavorAssigner();
        if (mimeType.equalsIgnoreCase("AUTOSENSE")) {
            d = docFlavorAssigner.forMimeTypeAUTOSENSE(flavor);
        } else if (mimeType.equalsIgnoreCase("GIF")) {
            d = docFlavorAssigner.forMimeTypeGIF(flavor);
View Full Code Here

   */
  public static void saveImage(final JComponent comp, String fileName)
    throws IOException, PrintException
  {
    if ( fileName.endsWith(".ps") || fileName.endsWith(".eps") ) {
      DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
      String mimeType = "application/postscript";
      StreamPrintServiceFactory[] factories =
        StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
      System.out.println(Arrays.toString(factories));
      if (factories.length > 0) {
View Full Code Here

     * javax.print.attribute.PrintRequestAttributeSet)
     */
    public void print(Doc doc, PrintRequestAttributeSet attributes)
            throws PrintException {
        synchronized (this) {
            DocFlavor flavor = doc.getDocFlavor();
            if (flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
                flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT) ||
                flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
                flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
                flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
                flavor.equals(DocFlavor.URL.AUTOSENSE)) {
                InputStream data = null;
                try {
                    if (flavor.equals(DocFlavor.URL.POSTSCRIPT)) {
                        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) {
View Full Code Here

public class parseMimeType implements Testlet
{
  public void test(TestHarness h)
  {
    // Check simple mimetype
    DocFlavor simple = new DocFlavor("text/plain; charset=us-ascii",
                                     "java.io.InputStream");

    h.checkPoint("Simple mimetype");
    h.check(simple.getMediaType().equals("text"));
    h.check(simple.getMediaSubtype().equals("plain"));
    h.check(simple.getParameter("charset").equals("us-ascii"));
    h.check(simple.getRepresentationClassName().equals("java.io.InputStream"));
    // Check if mimetype can be correctly built together again.
    h.check(simple.getMimeType().equals("text/plain; charset=\"us-ascii\""));
    h.check(simple.toString().equals("text/plain; charset=\"us-ascii\"; " +
                                     "class=\"java.io.InputStream\""));

    // Check for mimetype with quoted parameter value
    DocFlavor quoted = new DocFlavor("text/plain; charset=\"us-ascii\"",
                                     "java.io.InputStream");

    h.checkPoint("Mimetype with quoted param values");
    h.check(quoted.getParameter("charset").equals("us-ascii"));
    // Check if mimetype can be correctly built together again.
    h.check(quoted.getMimeType().equals("text/plain; charset=\"us-ascii\""));
    h.check(simple.toString().equals("text/plain; charset=\"us-ascii\"; " +
                                     "class=\"java.io.InputStream\""));

    // Check for mimetype with multiple parameters
    DocFlavor multipleParam = new DocFlavor("text/plain; " +
      "charset=\"us-ascii\"; param=paramValue", "java.io.InputStream");

    h.checkPoint("Mimetype with multiple parameters");
    h.check(multipleParam.getParameter("charset").equals("us-ascii"));
    h.check(multipleParam.getParameter("param").equals("paramValue"));
    // Check if mimetype can be correctly built together again.
    h.check(multipleParam.getMimeType().equals("text/plain; " +
      "charset=\"us-ascii\"; param=\"paramValue\""));
    h.check(multipleParam.toString().equals("text/plain; charset=\"us-ascii\";" +
      " param=\"paramValue\"; class=\"java.io.InputStream\""));

    // Check natural order for mimetype with multiple parameters
    DocFlavor paramOrder = new DocFlavor("text/plain; " +
      "charset=\"us-ascii\"; another=paramValue; charset3=something",
      "java.io.InputStream");

    h.checkPoint("Multiple parameters output order");
    // parameters are returned in natural key order
    // therefore another -> charset -> charset3
    h.check(paramOrder.getMimeType().equals("text/plain; " +
      "another=\"paramValue\"; charset=\"us-ascii\"; charset3=\"something\""));

    // Check charset treatment
    DocFlavor charset = new DocFlavor("text/plain; charset=US-ascii; " +
      "nocharset=UoUo", "java.io.InputStream");

    h.checkPoint("Test charset treatment");
    h.check(charset.getParameter("charset").equals("us-ascii"));
    h.check(charset.getParameter("nocharset").equals("UoUo"));

    // Check for mimetype with comments
    DocFlavor comments = new DocFlavor("text/plain(Comment); " +
    "charset=\"us-ascii\" (Comment2)(Comment1)", "java.io.InputStream");

    h.checkPoint("Mimetype with comments");
    h.check(comments.getMediaSubtype().equals("plain"));
    h.check(comments.getParameter("charset").equals("us-ascii"));

    // Syntax checks
    h.checkPoint("Syntax checks");
   
    // Lowercase treatment of media type and media subtype
    DocFlavor lowercase = new DocFlavor("teXt/Plain; charset=US-ascii; " +
      "nocharset=UoUo", "java.io.InputStream");
   
    h.check(lowercase.getMediaType().equals("text"));
    h.check(lowercase.getMediaSubtype().equals("plain"));
   
    try
      {
        // wrongly quoted value
        new DocFlavor("text/plain; charset=us-ascii\"", "java.io.InputStream");
        h.check(false);
      }
    catch (IllegalArgumentException e)
      {
        h.check(true);
      }
    try
      {
        // wrong character
        new DocFlavor(" te,xt/plain; charset=us-ascii", "java.io.InputStream");
        h.check(false);
      }
    catch (IllegalArgumentException e)
      {       
        h.check(true);
      }
    try
      {
        // only values may be quoted
        new DocFlavor("text/plain; \"charset\"=us-ascii", "java.io.InputStream");
        h.check(false);
      }
    catch (IllegalArgumentException e)
      {
        h.check(true);
      }
    try
      {
        // ' is an allowed character
        new DocFlavor(" text/plain; charset=us-asc'ii", "java.io.InputStream");
        h.check(true);
      }
    catch (IllegalArgumentException e)
      {
        h.check(false);
      }
    try
      {
        // wrongly character in unqouted value
        new DocFlavor("text/plain; charset=?us-ascii", "java.io.InputStream");
        h.check(false);
      }
    catch (IllegalArgumentException e)
      {
        h.check(true);
      }
    try
      {
        // character in qouted value
        DocFlavor syntax = new DocFlavor("text/plain; param=\"?value.\"",
            "java.io.InputStream");
        h.check(syntax.getParameter("param").equals("?value."));
      }
    catch (IllegalArgumentException e)
      {
        h.check(false);
      }
    try
      {
        // character in qouted value
        new DocFlavor("text/plain; param=\"?vöal ue.\"", "java.io.InputStream");
        h.check(true);
      }
    catch (IllegalArgumentException e)
      {
        h.check(false);
      }
    try
      {
        // special characters in mime type
        DocFlavor syntax = new DocFlavor("application/vnd.cups-command",
            "java.io.InputStream");
        h.check(syntax.getMediaSubtype().equals("vnd.cups-command"));
      }
    catch (IllegalArgumentException e)
      {
        h.check(false);
      }
View Full Code Here

        } catch (IOException e) {
            throw new ViewHandlerException("Unable write to browser OutputStream", e);
        }
        */

        DocFlavor docFlavor = DocFlavor.BYTE_ARRAY.PDF;
        Doc myDoc = new SimpleDoc(out.toByteArray(), docFlavor, null);
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        aset.add(new Copies(1));
        //aset.add(MediaSize.A4);
        aset.add(Sides.ONE_SIDED);
View Full Code Here

   */
  public static String[] listPrinters(){
    String[] printerNames = new String[0];
    try {
      PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
      DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
      PrintService printService[] =  PrintServiceLookup.lookupPrintServices(flavor, pras);
      printerNames = new String[printService.length];
      for(int i=0;i<printService.length;i++){
        String name = "Error";
        PrintService service = printService[i];
View Full Code Here

      String hardTokenSN, String copyOfHardTokenSN) throws PrinterException{
    if(currentService == null
       || currentPrinterName == null
       || !printerName.equals(currentPrinterName)){
      PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
      DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
      PrintService printService[] =  PrintServiceLookup.lookupPrintServices(flavor, pras);
      int i = 0;
      String trimemdPrinterName = printerName.trim();
      while ( i<printService.length && !trimemdPrinterName.equalsIgnoreCase(printService[i].getName()) ){
        i++;
View Full Code Here

        }     
      }
    }
   
    //check if the selected printer support the required doc flavor
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    if (!printService_.isDocFlavorSupported(flavor))
    {
      throw new RuntimeException("print: required doc flavor is not supported");
    }
   
View Full Code Here

TOP

Related Classes of javax.print.DocFlavor$READER

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.