Java Code Examples for java.awt.JobAttributes#getFileName()

The following examples show how to use java.awt.JobAttributes#getFileName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrintJob2D.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 2
Source File: PrintJob2D.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 3
Source File: PrintJob2D.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 4
Source File: PrintJob2D.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 5
Source File: PrintJob2D.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 6
Source File: PrintJob2D.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 7
Source File: PrintJob2D.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 8
Source File: PrintJob2D.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 9
Source File: PrintJob2D.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 10
Source File: PrintJob2D.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 11
Source File: PrintJob2D.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 12
Source File: PrintJob2D.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 13
Source File: PrintJob2D.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example 14
Source File: PrintJob2D.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}