< prev index next >

src/java.desktop/unix/classes/sun/print/IPPPrintService.java

Print this page

   1 /*
   2  * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any

 439 
 440             if ((urlConnection = getIPPConnection(myURL)) == null) {
 441                 mediaSizeNames = new MediaSizeName[0];
 442                 mediaTrays = new MediaTray[0];
 443                 debug_println(debugPrefix+"initAttributes, NULL urlConnection ");
 444                 init = true;
 445                 return;
 446             }
 447 
 448             // get all supported attributes through IPP
 449             opGetAttributes();
 450 
 451             if (isCupsPrinter) {
 452                 // note, it is possible to query media in CUPS using IPP
 453                 // right now we always get it from PPD.
 454                 // maybe use "&& (usePPD)" later?
 455                 // Another reason why we use PPD is because
 456                 // IPP currently does not support it but PPD does.
 457 
 458                 try {
 459                     cps = new CUPSPrinter(printer);
 460                     mediaSizeNames = cps.getMediaSizeNames();
 461                     mediaTrays = cps.getMediaTrays();
 462                     customMediaSizeNames = cps.getCustomMediaSizeNames();
 463                     defaultMediaIndex = cps.getDefaultMediaIndex();
 464                     rawResolutions = cps.getRawResolutions();


 465                     urlConnection.disconnect();
 466                     init = true;
 467                     return;
 468                 } catch (Exception e) {
 469                     IPPPrintService.debug_println(debugPrefix+
 470                                        "initAttributes, error creating CUPSPrinter e="+e);
 471                 }
 472             }
 473 
 474             // use IPP to get all media,
 475             Media[] allMedia = getSupportedMedia();
 476             ArrayList<Media> sizeList = new ArrayList<>();
 477             ArrayList<Media> trayList = new ArrayList<>();
 478             for (int i=0; i<allMedia.length; i++) {
 479                 if (allMedia[i] instanceof MediaSizeName) {
 480                     sizeList.add(allMedia[i]);
 481                 } else if (allMedia[i] instanceof MediaTray) {
 482                     trayList.add(allMedia[i]);
 483                 }
 484             }

 994      */
 995     public CustomMediaSizeName findCustomMedia(MediaSizeName media) {
 996         if (customMediaSizeNames == null) {
 997             return null;
 998         }
 999         for (int i=0; i< customMediaSizeNames.length; i++) {
1000             CustomMediaSizeName custom = customMediaSizeNames[i];
1001             MediaSizeName msn = custom.getStandardMedia();
1002             if (media.equals(msn)) {
1003                 return customMediaSizeNames[i];
1004             }
1005         }
1006         return null;
1007     }
1008 
1009 
1010     /**
1011      * Returns the matching standard Media using string comparison of names.
1012      */
1013     private Media getIPPMedia(String mediaName) {
1014         CustomMediaSizeName sampleSize = new CustomMediaSizeName("sample", "",
1015                                                                  0, 0);
1016         Media[] sizes = sampleSize.getSuperEnumTable();
1017         for (int i=0; i<sizes.length; i++) {
1018             if (mediaName.equals(""+sizes[i])) {
1019                 return sizes[i];
1020             }
1021         }
1022         CustomMediaTray sampleTray = new CustomMediaTray("sample", "");
1023         Media[] trays = sampleTray.getSuperEnumTable();
1024         for (int i=0; i<trays.length; i++) {
1025             if (mediaName.equals(""+trays[i])) {
1026                 return trays[i];
1027             }
1028         }
1029         return null;
1030     }
1031 
1032     private Media[] getSupportedMedia() {
1033         if ((getAttMap != null) &&
1034             getAttMap.containsKey("media-supported")) {
1035 
1036             AttributeClass attribClass = getAttMap.get("media-supported");
1037 
1038             if (attribClass != null) {
1039                 String[] mediaVals = attribClass.getArrayOfStringValues();
1040                 Media msn;
1041                 Media[] mediaNames =
1042                     new Media[mediaVals.length];

1208             }
1209             return (T)cs;
1210         } else if (category == PDLOverrideSupported.class) {
1211 
1212             if (isCupsPrinter) {
1213                 // Documented: For CUPS this will always be false
1214                 return (T)PDLOverrideSupported.NOT_ATTEMPTED;
1215             } else {
1216                 // REMIND: check attribute values
1217                 return (T)PDLOverrideSupported.NOT_ATTEMPTED;
1218             }
1219         } else if (category == PrinterURI.class) {
1220             return (T)(new PrinterURI(myURI));
1221         } else {
1222             return null;
1223         }
1224     }
1225 
1226 
1227     public synchronized PrintServiceAttributeSet getAttributes() {
1228         // update getAttMap by sending again get-attributes IPP request
1229         init = false;
1230         initAttributes();








1231 
1232         HashPrintServiceAttributeSet attrs =
1233             new HashPrintServiceAttributeSet();
1234 
1235         for (int i=0; i < serviceAttributes.length; i++) {
1236             String name = (String)serviceAttributes[i][1];
1237             if (getAttMap != null && getAttMap.containsKey(name)) {
1238                 @SuppressWarnings("unchecked")
1239                 Class<PrintServiceAttribute> c = (Class<PrintServiceAttribute>)serviceAttributes[i][0];
1240                 PrintServiceAttribute psa = getAttribute(c);
1241                 if (psa != null) {
1242                     attrs.add(psa);
1243                 }
1244             }
1245         }
1246         return AttributeSetUtilities.unmodifiableView(attrs);
1247     }
1248 
1249     public boolean isIPPSupportedImages(String mimeType) {
1250         if (supportedDocFlavors == null) {

   1 /*
   2  * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any

 439 
 440             if ((urlConnection = getIPPConnection(myURL)) == null) {
 441                 mediaSizeNames = new MediaSizeName[0];
 442                 mediaTrays = new MediaTray[0];
 443                 debug_println(debugPrefix+"initAttributes, NULL urlConnection ");
 444                 init = true;
 445                 return;
 446             }
 447 
 448             // get all supported attributes through IPP
 449             opGetAttributes();
 450 
 451             if (isCupsPrinter) {
 452                 // note, it is possible to query media in CUPS using IPP
 453                 // right now we always get it from PPD.
 454                 // maybe use "&& (usePPD)" later?
 455                 // Another reason why we use PPD is because
 456                 // IPP currently does not support it but PPD does.
 457 
 458                 try {
 459                     if (cps == null) {
 460                         cps = new CUPSPrinter(printer);
 461                         mediaSizeNames = cps.getMediaSizeNames();
 462                         mediaTrays = cps.getMediaTrays();
 463                         customMediaSizeNames = cps.getCustomMediaSizeNames();
 464                         defaultMediaIndex = cps.getDefaultMediaIndex();
 465                         rawResolutions = cps.getRawResolutions();
 466                     }
 467                     urlConnection.disconnect();
 468                     init = true;
 469                     return;
 470                 } catch (Exception e) {
 471                     IPPPrintService.debug_println(debugPrefix+
 472                                        "initAttributes, error creating CUPSPrinter e="+e);
 473                 }
 474             }
 475 
 476             // use IPP to get all media,
 477             Media[] allMedia = getSupportedMedia();
 478             ArrayList<Media> sizeList = new ArrayList<>();
 479             ArrayList<Media> trayList = new ArrayList<>();
 480             for (int i=0; i<allMedia.length; i++) {
 481                 if (allMedia[i] instanceof MediaSizeName) {
 482                     sizeList.add(allMedia[i]);
 483                 } else if (allMedia[i] instanceof MediaTray) {
 484                     trayList.add(allMedia[i]);
 485                 }
 486             }

 996      */
 997     public CustomMediaSizeName findCustomMedia(MediaSizeName media) {
 998         if (customMediaSizeNames == null) {
 999             return null;
1000         }
1001         for (int i=0; i< customMediaSizeNames.length; i++) {
1002             CustomMediaSizeName custom = customMediaSizeNames[i];
1003             MediaSizeName msn = custom.getStandardMedia();
1004             if (media.equals(msn)) {
1005                 return customMediaSizeNames[i];
1006             }
1007         }
1008         return null;
1009     }
1010 
1011 
1012     /**
1013      * Returns the matching standard Media using string comparison of names.
1014      */
1015     private Media getIPPMedia(String mediaName) {
1016         CustomMediaSizeName sampleSize =
1017                 CustomMediaSizeName.create("sample", "", 0, 0);
1018         Media[] sizes = sampleSize.getSuperEnumTable();
1019         for (int i=0; i<sizes.length; i++) {
1020             if (mediaName.equals(""+sizes[i])) {
1021                 return sizes[i];
1022             }
1023         }
1024         CustomMediaTray sampleTray = CustomMediaTray.create("sample", "");
1025         Media[] trays = sampleTray.getSuperEnumTable();
1026         for (int i=0; i<trays.length; i++) {
1027             if (mediaName.equals(""+trays[i])) {
1028                 return trays[i];
1029             }
1030         }
1031         return null;
1032     }
1033 
1034     private Media[] getSupportedMedia() {
1035         if ((getAttMap != null) &&
1036             getAttMap.containsKey("media-supported")) {
1037 
1038             AttributeClass attribClass = getAttMap.get("media-supported");
1039 
1040             if (attribClass != null) {
1041                 String[] mediaVals = attribClass.getArrayOfStringValues();
1042                 Media msn;
1043                 Media[] mediaNames =
1044                     new Media[mediaVals.length];

1210             }
1211             return (T)cs;
1212         } else if (category == PDLOverrideSupported.class) {
1213 
1214             if (isCupsPrinter) {
1215                 // Documented: For CUPS this will always be false
1216                 return (T)PDLOverrideSupported.NOT_ATTEMPTED;
1217             } else {
1218                 // REMIND: check attribute values
1219                 return (T)PDLOverrideSupported.NOT_ATTEMPTED;
1220             }
1221         } else if (category == PrinterURI.class) {
1222             return (T)(new PrinterURI(myURI));
1223         } else {
1224             return null;
1225         }
1226     }
1227 
1228 
1229     public synchronized PrintServiceAttributeSet getAttributes() {
1230         if (!init) {
1231             // get all attributes for the first time.
1232             initAttributes();
1233         } else {
1234             // only need service attributes updated.
1235             // update getAttMap by sending again get-attributes IPP request
1236             if ((urlConnection = getIPPConnection(myURL)) != null) {
1237                 opGetAttributes();
1238                 urlConnection.disconnect();
1239             }
1240         }
1241 
1242         HashPrintServiceAttributeSet attrs =
1243             new HashPrintServiceAttributeSet();
1244 
1245         for (int i=0; i < serviceAttributes.length; i++) {
1246             String name = (String)serviceAttributes[i][1];
1247             if (getAttMap != null && getAttMap.containsKey(name)) {
1248                 @SuppressWarnings("unchecked")
1249                 Class<PrintServiceAttribute> c = (Class<PrintServiceAttribute>)serviceAttributes[i][0];
1250                 PrintServiceAttribute psa = getAttribute(c);
1251                 if (psa != null) {
1252                     attrs.add(psa);
1253                 }
1254             }
1255         }
1256         return AttributeSetUtilities.unmodifiableView(attrs);
1257     }
1258 
1259     public boolean isIPPSupportedImages(String mimeType) {
1260         if (supportedDocFlavors == null) {
< prev index next >