< prev index next >

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

Print this page




  42 import javax.print.event.PrintServiceAttributeListener;
  43 
  44 import java.net.URI;
  45 import java.net.URISyntaxException;
  46 import java.net.URL;
  47 import java.net.URLConnection;
  48 import java.net.HttpURLConnection;
  49 import java.io.File;
  50 import java.io.InputStream;
  51 import java.io.OutputStream;
  52 import java.io.OutputStreamWriter;
  53 import java.io.DataInputStream;
  54 import java.io.ByteArrayOutputStream;
  55 import java.io.ByteArrayInputStream;
  56 import java.io.BufferedReader;
  57 import java.io.InputStreamReader;
  58 import java.nio.charset.Charset;
  59 
  60 import java.util.Iterator;
  61 import java.util.HashSet;

  62 
  63 
  64 public class IPPPrintService implements PrintService, SunPrinterJobService {
  65 
  66     public static final boolean debugPrint;
  67     private static final String debugPrefix = "IPPPrintService>> ";
  68     protected static void debug_println(String str) {
  69         if (debugPrint) {
  70             System.out.println(str);
  71         }
  72     }
  73 
  74     private static final String FORCE_PIPE_PROP = "sun.print.ippdebug";
  75 
  76     static {
  77         String debugStr = java.security.AccessController.doPrivileged(
  78                   new sun.security.action.GetPropertyAction(FORCE_PIPE_PROP));
  79 
  80         debugPrint = "true".equalsIgnoreCase(debugStr);
  81     }


1748                         } catch (Exception e) {
1749                         }
1750                         return null;
1751                     }
1752                 });
1753 
1754             if (os == null) {
1755                 return;
1756             }
1757 
1758             boolean success = (myURI == null) ?
1759                 writeIPPRequest(os, OP_GET_ATTRIBUTES, attClNoUri) :
1760                 writeIPPRequest(os, OP_GET_ATTRIBUTES, attCl);
1761             if (success) {
1762                 InputStream is = null;
1763                 if ((is = urlConnection.getInputStream())!=null) {
1764                     HashMap<String, AttributeClass>[] responseMap = readIPPResponse(is);
1765 
1766                     if (responseMap != null && responseMap.length > 0) {
1767                         getAttMap = responseMap[0];













1768                     }
1769                 } else {
1770                     debug_println(debugPrefix+"opGetAttributes - null input stream");
1771                 }
1772                 is.close();
1773             }
1774             os.close();
1775         } catch (java.io.IOException e) {
1776             debug_println(debugPrefix+"opGetAttributes - input/output stream: "+e);
1777         }
1778     }
1779 
1780 
1781     public static boolean writeIPPRequest(OutputStream os,
1782                                            String operCode,
1783                                            AttributeClass[] attCl) {
1784         OutputStreamWriter osw;
1785         try {
1786             osw = new OutputStreamWriter(os, "UTF-8");
1787         } catch (java.io.UnsupportedEncodingException exc) {




  42 import javax.print.event.PrintServiceAttributeListener;
  43 
  44 import java.net.URI;
  45 import java.net.URISyntaxException;
  46 import java.net.URL;
  47 import java.net.URLConnection;
  48 import java.net.HttpURLConnection;
  49 import java.io.File;
  50 import java.io.InputStream;
  51 import java.io.OutputStream;
  52 import java.io.OutputStreamWriter;
  53 import java.io.DataInputStream;
  54 import java.io.ByteArrayOutputStream;
  55 import java.io.ByteArrayInputStream;
  56 import java.io.BufferedReader;
  57 import java.io.InputStreamReader;
  58 import java.nio.charset.Charset;
  59 
  60 import java.util.Iterator;
  61 import java.util.HashSet;
  62 import java.util.Map;
  63 
  64 
  65 public class IPPPrintService implements PrintService, SunPrinterJobService {
  66 
  67     public static final boolean debugPrint;
  68     private static final String debugPrefix = "IPPPrintService>> ";
  69     protected static void debug_println(String str) {
  70         if (debugPrint) {
  71             System.out.println(str);
  72         }
  73     }
  74 
  75     private static final String FORCE_PIPE_PROP = "sun.print.ippdebug";
  76 
  77     static {
  78         String debugStr = java.security.AccessController.doPrivileged(
  79                   new sun.security.action.GetPropertyAction(FORCE_PIPE_PROP));
  80 
  81         debugPrint = "true".equalsIgnoreCase(debugStr);
  82     }


1749                         } catch (Exception e) {
1750                         }
1751                         return null;
1752                     }
1753                 });
1754 
1755             if (os == null) {
1756                 return;
1757             }
1758 
1759             boolean success = (myURI == null) ?
1760                 writeIPPRequest(os, OP_GET_ATTRIBUTES, attClNoUri) :
1761                 writeIPPRequest(os, OP_GET_ATTRIBUTES, attCl);
1762             if (success) {
1763                 InputStream is = null;
1764                 if ((is = urlConnection.getInputStream())!=null) {
1765                     HashMap<String, AttributeClass>[] responseMap = readIPPResponse(is);
1766 
1767                     if (responseMap != null && responseMap.length > 0) {
1768                         getAttMap = responseMap[0];
1769                         // If there is extra hashmap created due to duplicate
1770                         // key/attribute present in IPPresponse, then use that
1771                         // map too by appending to getAttMap after removing the
1772                         // duplicate key/value
1773                         if (responseMap.length > 1) {
1774                             for (int i = 1; i < responseMap.length; i++) {
1775                                 for (Map.Entry<String, AttributeClass> entry : responseMap[i].entrySet()) {
1776                                     if (!getAttMap.containsKey(entry.getValue())) {
1777                                         getAttMap.put(entry.getKey(), entry.getValue());
1778                                     }
1779                                 }                                
1780                             }
1781                         }
1782                     }
1783                 } else {
1784                     debug_println(debugPrefix+"opGetAttributes - null input stream");
1785                 }
1786                 is.close();
1787             }
1788             os.close();
1789         } catch (java.io.IOException e) {
1790             debug_println(debugPrefix+"opGetAttributes - input/output stream: "+e);
1791         }
1792     }
1793 
1794 
1795     public static boolean writeIPPRequest(OutputStream os,
1796                                            String operCode,
1797                                            AttributeClass[] attCl) {
1798         OutputStreamWriter osw;
1799         try {
1800             osw = new OutputStreamWriter(os, "UTF-8");
1801         } catch (java.io.UnsupportedEncodingException exc) {


< prev index next >