harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r454289 [19/22] - in /incubator/harmony/enhanced/classlib/trunk/modules/H-1609: ./ modules/ modules/applet/ modules/applet/src/ modules/applet/src/main/ modules/applet/src/main/java/ modules/applet/src/main/java/java/ modules/applet/src/mai...
Date Mon, 09 Oct 2006 05:33:21 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.cpp?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.cpp (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.cpp Sun Oct  8 22:33:09 2006
@@ -0,0 +1,1062 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Aleksei V. Ivaschenko 
+ * @version $Revision: 1.3 $ 
+ */ 
+
+/*
+ * This file contains implementations of native methods of
+ * GDIClient and PSInterpreter.
+ * Defines the entry point for the DLL application.
+ */
+
+#include "print.h"
+#include "org_apache_harmony_x_print_GDIClient.h"
+#include "org_apache_harmony_x_print_PSInterpreter.h"
+#include "org_apache_harmony_x_print_Win32PrintServiceProvider.h"
+
+BOOL APIENTRY DllMain( HANDLE hModule, 
+                       DWORD  ul_reason_for_call, 
+                       LPVOID lpReserved
+                     )
+{
+    return TRUE;
+}
+
+//----------------- ServiceFinder functions -----------------------------------
+
+/*
+ * TODO:   support older systems.
+ */
+char * GetDefaultPrintService() {
+    char *buffer = new char[MAX_PATH];
+    DWORD buffer_size = MAX_PATH;
+
+    if (GetDefaultPrinter(buffer, &buffer_size)) {
+        return buffer;
+    } else {
+        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+            free(buffer);
+            buffer = new char[buffer_size];
+            if (GetDefaultPrinter(buffer, &buffer_size)) {
+                return buffer;
+            }
+        }
+    }
+    return NULL;
+}
+
+char ** GetPrintServices(DWORD *count) {
+    unsigned char * pPrinterEnum = NULL;
+    DWORD cbNeeded, cReturned;
+
+    if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
+                      NULL, 4, pPrinterEnum, 0, &cbNeeded, &cReturned)) {
+        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+            pPrinterEnum = new unsigned char[cbNeeded];
+            if (EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
+                             NULL, 4, pPrinterEnum, cbNeeded, &cbNeeded, &cReturned)) {
+                PRINTER_INFO_4 *printers = (PRINTER_INFO_4 *)pPrinterEnum;
+                char ** names = new char *[cReturned];
+                for (DWORD i = 0; i < cReturned; i++) {
+                    names[i] = new char[strlen(printers[i].pPrinterName) + 1];
+                    strcpy(names[i], printers[i].pPrinterName);
+                }
+                *count = cReturned;
+                return names;
+            }
+        }
+    }
+    return NULL;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_x_print_Win32PrintServiceProvider_findPrintServices
+(JNIEnv *env, jclass owner) {
+    jobjectArray result = NULL;
+    DWORD services = 0;
+    char ** names = GetPrintServices(&services);
+    if (services > 0) {
+        jclass jstring_class = env->FindClass("java/lang/String");
+        result = env->NewObjectArray(services, jstring_class, jstring());
+        for (DWORD i = 0; i < services; i++) {
+            jstring name = env->NewStringUTF(names[i]); 
+            env->SetObjectArrayElement(result, i, name);
+            env->DeleteLocalRef(name);
+        }
+    }
+    return result;
+}
+
+JNIEXPORT jstring JNICALL Java_org_apache_harmony_x_print_Win32PrintServiceProvider_findDefaultPrintService
+(JNIEnv *env, jclass owner) {
+    char *serviceUTF = GetDefaultPrintService();
+    jstring service = NULL;
+    if (serviceUTF != NULL) {
+        service = env->NewStringUTF(serviceUTF);
+        free(serviceUTF);
+    }
+    return service;
+}
+
+//----------------- PrintService flavors --------------------------------------
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_GDIClient_checkPostScript
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *printer = env->GetStringUTFChars(printerName, 0);
+    jboolean res = JNI_FALSE;
+
+    HDC prndc = CreateDC(NULL, printer, NULL, NULL);
+    if (prndc != NULL) {
+        DWORD esc = POSTSCRIPT_PASSTHROUGH;
+        if (ExtEscape(prndc, QUERYESCSUPPORT, sizeof(esc), (LPCSTR)&esc, 0, NULL) != 0) {
+            return JNI_TRUE;
+        }
+        esc = GETTECHNOLOGY;
+        if (ExtEscape(prndc, QUERYESCSUPPORT, sizeof(esc), (LPCSTR)&esc, 0, NULL) != 0) {
+            char *tech = new char[MAX_PATH + 1];
+            if (ExtEscape(prndc, esc, 0, NULL, MAX_PATH, tech) > 0) {
+                char *lower = strlwr(tech);
+                if (strstr(lower, "postscript") != NULL) {
+                    return JNI_TRUE;
+                }
+            }
+        }
+    }
+    DeleteDC(prndc);
+
+    return res;
+}
+
+//----------------- PrintService attribute functions --------------------------
+
+PRINTER_INFO_2 *GetPrinterInfo(const char *name) {
+    PRINTER_INFO_2 *result = NULL;
+    char *editableName = new char[strlen(name) + 1];
+    strcpy(editableName, name);
+
+    HANDLE hPrinter;
+    if (OpenPrinter(editableName, &hPrinter, NULL)) {
+        unsigned char *buffer = NULL;
+        DWORD cbNeeded;
+        if (!GetPrinter(hPrinter, 2, buffer, 0, &cbNeeded)) {
+            if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+                buffer = new unsigned char[cbNeeded];
+                if (GetPrinter(hPrinter, 2, buffer, cbNeeded, &cbNeeded)) {
+                    result = (PRINTER_INFO_2 *)buffer;
+                }
+            }
+        }
+    }
+    free(editableName);
+    return result;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_GDIClient_getColorSupported
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jboolean result = JNI_FALSE;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        if (DeviceCapabilities(name, info->pPortName, DC_COLORDEVICE, NULL, NULL) == 1) {
+            result = JNI_TRUE;
+        }
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_getPagesPerMinute
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jint result = 0;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        info->pDevMode->dmColor = DMCOLOR_MONOCHROME;
+        result = DeviceCapabilities(name, info->pPortName, DC_PRINTRATEPPM, NULL, info->pDevMode);
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_getPagesPerMinuteColor
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jint result = 0;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        info->pDevMode->dmColor = DMCOLOR_COLOR;
+        result = DeviceCapabilities(name, info->pPortName, DC_PRINTRATEPPM, NULL, info->pDevMode);
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_getPrinterIsAcceptingJobs
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jint result = -1;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        if (info->Status & (PRINTER_STATUS_ERROR |
+                            PRINTER_STATUS_NO_TONER |
+                            PRINTER_STATUS_NOT_AVAILABLE |
+                            PRINTER_STATUS_OFFLINE |
+                            PRINTER_STATUS_OUT_OF_MEMORY |
+                            PRINTER_STATUS_OUTPUT_BIN_FULL |
+                            PRINTER_STATUS_PAPER_JAM |
+                            PRINTER_STATUS_PAGE_PUNT |
+                            PRINTER_STATUS_PAPER_OUT |
+                            PRINTER_STATUS_PAPER_PROBLEM |
+                            PRINTER_STATUS_PAUSED |
+                            PRINTER_STATUS_PENDING_DELETION |
+                            PRINTER_STATUS_USER_INTERVENTION)) {
+            result = 0;
+        } else {
+            result = 1;
+        }
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jstring JNICALL Java_org_apache_harmony_x_print_GDIClient_getPrinterLocation
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jstring result = NULL;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        if (info->pLocation != NULL && strcmp(info->pLocation, "") != 0) {
+            result = env->NewStringUTF(info->pLocation);
+        }
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_getQueuedJobCount
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jint result = -1;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        result = info->cJobs;
+        free(info);
+    }
+    return result;
+}
+
+//----------------- Print request attribute functions -------------------------
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_getCopiesSupported
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jint result = 0;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        result = DeviceCapabilities(name, info->pPortName, DC_COPIES, NULL, NULL);
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_GDIClient_getSidesSupported
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jboolean result = JNI_FALSE;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        if (DeviceCapabilities(name, info->pPortName, DC_DUPLEX, NULL, NULL) == 1) {
+            result = JNI_TRUE;
+        }
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_x_print_GDIClient_getMediaSizesSupported
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jobjectArray result = NULL;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        int numSizes = DeviceCapabilities(name, info->pPortName, DC_PAPERSIZE, NULL, NULL);
+        if (numSizes > 0) {
+            POINT *sizes = new POINT[numSizes];
+            int numSizes = DeviceCapabilities(name, info->pPortName, DC_PAPERSIZE, (LPSTR)sizes, NULL);
+            if (numSizes > 0) {
+                jclass IntArrayClass = env->FindClass("[I");
+                result = env->NewObjectArray(numSizes, IntArrayClass, NULL);
+                for (int i = 0; i < numSizes; i++) {
+                    jintArray size = env->NewIntArray(2);
+                    int *nativeArray = new int[2];
+                    nativeArray[0] = sizes[i].x;
+                    nativeArray[1] = sizes[i].y;
+                    env->SetIntArrayRegion(size, 0, 2, (jint *)nativeArray);
+                    env->SetObjectArrayElement(result, i, size);
+                }
+            }
+        }
+
+#ifdef PRINTING_DEBUG
+        int count = DeviceCapabilities(name, info->pPortName, DC_PAPERS, NULL, NULL);
+        if( count > 0 ) {
+            printf("\n\n");
+            WORD *papers = new WORD[count];
+            count = DeviceCapabilities(name, info->pPortName, DC_PAPERS, (LPSTR)papers, NULL);
+            printf("Found %d paper types.\n", count);
+            for (int i = 0; i < count; i++) {
+                printf("%d: %d\n", i+1, papers[i]);
+            }
+            delete [] papers;
+        }
+        
+        int cnames = DeviceCapabilities(name, info->pPortName, DC_PAPERNAMES, NULL, NULL);
+        if( cnames > 0 ) {
+            printf("\n\n");
+            char (*papernames)[64] = new char[cnames][64];
+            cnames = DeviceCapabilities(name, info->pPortName, DC_PAPERNAMES, (LPSTR)papernames, NULL);
+            printf("Found %d paper names.\n", cnames);
+            for (int i = 0; i < cnames; i++) {
+                printf("%d: %s\n", i+1, papernames[i]);
+            }
+            delete [] papernames;
+        }
+#endif /* PRINTING_DEBUG */
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_x_print_GDIClient_getMediaNames
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jobjectArray result = NULL;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        int numNamesFirst = DeviceCapabilities(name, info->pPortName, DC_PAPERNAMES, NULL, NULL);
+        if (numNamesFirst > 0) {
+            char *buffer = new char[65 * numNamesFirst];
+            int numNames = DeviceCapabilities(name, info->pPortName, DC_PAPERNAMES, (LPSTR)buffer, NULL);
+            if (numNames == numNamesFirst) {
+                jclass jstring_class = env->FindClass("java/lang/String");
+                result = env->NewObjectArray(numNames, jstring_class, jstring());
+                for (int i = 0; i < numNames; i++) {
+                    char *name = buffer + i*64;
+                    jstring jname = env->NewStringUTF(name); 
+                    env->SetObjectArrayElement(result, i, jname);
+                    env->DeleteLocalRef(jname);
+                }
+            }
+            free(buffer);
+        }
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jintArray JNICALL Java_org_apache_harmony_x_print_GDIClient_getMediaIDs
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jintArray result = NULL;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        int numPapersFirst = DeviceCapabilities(name, info->pPortName, DC_PAPERS, NULL, NULL);
+        if (numPapersFirst > 0) {
+            WORD *ids = new WORD[numPapersFirst];
+            int numPapers = DeviceCapabilities(name, info->pPortName, DC_PAPERS, (LPSTR)ids, NULL);
+            if (numPapers == numPapersFirst) {
+                result = env->NewIntArray(numPapers);
+                int *intIDs = new int[numPapers];
+                for (int i = 0; i < numPapers; i++) {
+                    intIDs[i] = (int)ids[i];
+                }
+                env->SetIntArrayRegion(result, 0, numPapers, (jint *)intIDs);
+                free(intIDs);
+            }
+            free(ids);
+        }
+        free(info);
+    }
+    return result;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_GDIClient_getCollateSupported
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jboolean result = JNI_FALSE;
+
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        if (DeviceCapabilities(name, info->pPortName, DC_COLLATE, NULL, NULL) == 1) {
+            result = JNI_TRUE;
+        }
+        free(info);
+    }
+    return result;
+}
+
+
+JNIEXPORT jintArray JNICALL Java_org_apache_harmony_x_print_GDIClient_getResolutionsSupported
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jintArray resolutions = NULL;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        int count = DeviceCapabilities(name, info->pPortName, DC_ENUMRESOLUTIONS, NULL, NULL);
+        if (count > 0) {
+            LONG *nativeArray = new LONG[count * 2];
+            jint *intArray = new jint[count * 2];
+            resolutions = env->NewIntArray(count * 2);
+            if (DeviceCapabilities(name, info->pPortName, DC_ENUMRESOLUTIONS, (LPSTR)nativeArray, NULL) > 0) {
+                for (int i = 0; i < count * 2; i++) {
+                    intArray[i] = (jint)((int)nativeArray[i]);
+                }
+                env->SetIntArrayRegion(resolutions, 0, count * 2, intArray);
+                free(nativeArray);
+                free(intArray);
+            }
+        }
+        free(info);
+    }
+    return resolutions;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_GDIClient_getOrientationSupported
+(JNIEnv *env, jclass owner, jstring printerName) {
+    const char *name = env->GetStringUTFChars(printerName, 0);
+    jboolean result = JNI_FALSE;
+    
+    PRINTER_INFO_2 *info = GetPrinterInfo(name);
+    if (info != NULL) {
+        int orientation = DeviceCapabilities(name, info->pPortName, DC_ORIENTATION, NULL, NULL);
+        if (orientation == 0 || orientation == 90 || orientation == 270) {
+            result = JNI_TRUE;
+        }
+        free(info);
+    }
+    return result;
+}
+
+//----------------- Common DocPrintJob and PS interpreter structures ----------
+
+#define ATTRIBUTE_UNION_SIZE    8
+
+typedef struct _PrintRequestAttributes {
+    int Copies;
+    int Sides;
+    int PaperID;
+    int Collate;
+    int Chromaticity;
+    int Orientation;
+    int XResolution;
+    int YResolution;
+} PrintRequestAttributes;
+
+typedef union _AttributesUnion {
+    int numbers[ATTRIBUTE_UNION_SIZE];
+    PrintRequestAttributes fields;
+} AttributesUnion;
+
+//----------------- DocPrintJob functions -------------------------------------
+
+#ifdef PRINTING_DEBUG
+FILE *file = NULL;
+#endif /* PRINTING_DEBUG */
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_startDocPrinter
+(JNIEnv *env, jclass owner, jstring printerName, jintArray printAttributes, jstring jobName, jstring destination) {
+    const char *printer = env->GetStringUTFChars(printerName, 0);
+    const char *jn = env->GetStringUTFChars(jobName, 0);
+    char *jname = new char[strlen(jn) + 1];
+    char *fname = NULL;
+    strcpy(jname, jn);
+    if (destination != NULL) {
+        const char *fn = env->GetStringUTFChars(destination, 0);
+        fname = new char[strlen(fn) + 1];
+        strcpy(fname, fn);
+    }
+    AttributesUnion attributes;
+    jboolean isCopy = JNI_FALSE;
+    int *numbers = (int *)env->GetIntArrayElements(printAttributes, &isCopy);
+    for (int i = 0; i < ATTRIBUTE_UNION_SIZE; i++) {
+        attributes.numbers[i] = numbers[i];
+    }
+
+    jint res = 0;
+    HANDLE hPrinter = NULL;
+
+    if (OpenPrinter((LPTSTR)printer, &hPrinter, NULL) != 0) {
+        DOC_INFO_1 dinfo;
+        dinfo.pDocName = jname;
+        dinfo.pDatatype = "RAW";
+        dinfo.pOutputFile = fname;
+
+        DEVMODE *pDevMode = NULL;
+        int size = DocumentProperties(NULL, hPrinter, NULL, pDevMode, NULL, 0);
+        pDevMode = (DEVMODE *)malloc(size);
+//        if (DocumentProperties(NULL, hPrinter, NULL, pDevMode, NULL, DM_PROMPT) == IDOK) {
+        if (DocumentProperties(NULL, hPrinter, NULL, pDevMode, NULL, DM_OUT_BUFFER) == IDOK) {
+
+#ifdef PRINTING_DEBUG
+            printf("DEVMODE received successfuly!\n");
+#endif /* PRINTING_DEBUG */
+
+            if (attributes.fields.Copies > 0) {
+                pDevMode->dmCopies = (short)attributes.fields.Copies;
+                pDevMode->dmFields |= DM_COPIES;
+            }
+            if (attributes.fields.Sides > 0) {
+                pDevMode->dmDuplex = (short)attributes.fields.Sides;
+                pDevMode->dmFields |= DM_DUPLEX;
+            }
+            if (attributes.fields.PaperID > 0) {
+                pDevMode->dmPaperSize = (short)attributes.fields.PaperID;
+                pDevMode->dmFields |= DM_PAPERSIZE;
+            }
+            if (DocumentProperties(NULL, hPrinter, NULL,
+                                   pDevMode, pDevMode,
+                                   DM_IN_BUFFER | DM_OUT_BUFFER) == IDOK) {
+            }
+        } else {
+
+#ifdef PRINTING_DEBUG
+            printf("Can't get initial DEVMODE.\n");
+#endif /* PRINTING_DEBUG */
+
+        }
+
+        if (StartDocPrinter(hPrinter, 1, (LPBYTE)&dinfo) != 0) {
+            res = *((int *)&hPrinter);
+        }
+    }
+
+#ifdef PRINTING_DEBUG
+    if (res == 0) {
+        DWORD error = GetLastError();
+        printf("Error occurred while starting: %d.\n", error);
+    }
+    if (res != 0) {
+        file = fopen("C:\\from_Native.ps", "wb+");
+    }
+#endif /* PRINTING_DEBUG */
+
+    return res;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_GDIClient_writePrinter
+(JNIEnv *env, jclass owner, jbyteArray array, jint size, jint printerID) {
+    HANDLE hPrinter = *((HANDLE *)&printerID);
+    if (hPrinter != NULL) {
+        signed char *data;
+        data = (signed char *)env->GetByteArrayElements(array, NULL);
+#ifdef PRINTING_DEBUG
+        if (file != NULL) {
+            fwrite(data, sizeof(signed char), size, file);
+        }
+#endif /* PRINTING_DEBUG */
+        DWORD written = 0;
+        if (WritePrinter(hPrinter, data, size, &written) != 0) {
+            env->ReleaseByteArrayElements(array, (jbyte *)data, JNI_ABORT);
+            return JNI_TRUE;
+        }
+    }
+#ifdef PRINTING_DEBUG
+    if (res == JNI_FALSE) {
+        DWORD error = GetLastError();
+        printf("Error occurred while transfering data to printer: %d.\n", error);
+    }
+#endif /* PRINTING_DEBUG */
+    return JNI_FALSE;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_GDIClient_endDocPrinter
+(JNIEnv *env, jclass owner, jint printerID) {
+    HANDLE hPrinter = *((HANDLE *)&printerID);
+#ifdef PRINTING_DEBUG
+    if (file != NULL) {
+        fclose(file);
+        file = NULL;
+    }
+#endif /* PRINTING_DEBUG */
+    if (hPrinter != NULL) {
+        if (EndDocPrinter(hPrinter) != 0) {
+            ClosePrinter(hPrinter);
+            hPrinter = NULL;
+            return JNI_TRUE;
+        }
+    }
+#ifdef PRINTING_DEBUG
+    if (res == JNI_FALSE) {
+        DWORD error = GetLastError();
+        printf("Error occurred while ending: %d.\n", error);
+    }
+#endif /* PRINTING_DEBUG */
+    return JNI_FALSE;
+}
+
+//----------------- Interpreter functions -------------------------------------
+
+#define MAX_PRINTER_CONTEXTS 20
+HDC printerDCs[] = { NULL, NULL, NULL, NULL, NULL,
+                     NULL, NULL, NULL, NULL, NULL,
+                     NULL, NULL, NULL, NULL, NULL,
+                     NULL, NULL, NULL, NULL, NULL };
+
+int psWidths[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+int psHeights[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+int getFreePDCID() {
+    for (int i = 0; i < MAX_PRINTER_CONTEXTS; i++) {
+        if (printerDCs[i] == NULL) {
+            return i;
+        }
+    }
+    return -1;
+}
+
+int obtainPrinterDC(const char *printer, int psWidth, int psHeight) {
+    int pdcID = getFreePDCID();
+    if (pdcID < 0) {
+        return -1;
+    }
+    printerDCs[pdcID] = CreateDC("WINSPOOL", printer, NULL, NULL);    // In win 9x/Me "WINSPOOL" should not be used.
+    if (printerDCs[pdcID] == NULL) {
+        return -1;
+    }
+    psWidths[pdcID] = psWidth;
+    psHeights[pdcID] = psHeight;
+    return pdcID;
+}
+
+void releasePrinterDC(const int pdcID) {
+    if (pdcID >= 0) {
+        DeleteDC(printerDCs[pdcID]);
+        printerDCs[pdcID] = NULL;
+        psWidths[pdcID] = 0;
+        psHeights[pdcID] = 0;
+    }
+}
+
+void setAttributes(const char *printer, const int pdcID, AttributesUnion attributes) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        DEVMODE *pDevMode = NULL;
+        HANDLE hPrinter;
+        if (OpenPrinter((LPTSTR)printer, &hPrinter, NULL) != 0) {
+            int size = DocumentProperties(NULL, hPrinter, NULL, pDevMode, NULL, 0);
+            pDevMode = (DEVMODE *)malloc(size);
+            if (DocumentProperties(NULL, hPrinter, NULL, pDevMode, NULL, DM_OUT_BUFFER) == IDOK) {
+                pDevMode->dmFields = 0;
+                if (attributes.fields.PaperID > 0) {
+                    pDevMode->dmPaperSize = (short)attributes.fields.PaperID;
+                    pDevMode->dmFields |= DM_PAPERSIZE;
+                }
+
+                if (attributes.fields.Copies > 0) {
+                    pDevMode->dmCopies = (short)attributes.fields.Copies;
+                    pDevMode->dmFields |= DM_COPIES;
+                }
+
+                if (attributes.fields.Collate > 0) {
+                    if (attributes.fields.Collate == 1) {
+                        pDevMode->dmCollate = DMCOLLATE_TRUE;
+                    } else {
+                        pDevMode->dmCollate = DMCOLLATE_FALSE;
+                    }
+                    pDevMode->dmFields |= DM_COLLATE;
+                }
+
+                if (attributes.fields.Sides > 0) {
+                    pDevMode->dmDuplex = (short)attributes.fields.Sides;
+                    pDevMode->dmFields |= DM_DUPLEX;
+                }
+
+                if (attributes.fields.Chromaticity > 0) {
+                    if (attributes.fields.Chromaticity == 1) {
+                        pDevMode->dmColor = DMCOLOR_MONOCHROME;
+                    } else {
+                        pDevMode->dmColor = DMCOLOR_COLOR;
+                    }
+                    pDevMode->dmFields |= DM_COLOR;
+                }
+
+                if (attributes.fields.Orientation > 0) {
+                    if (attributes.fields.Orientation == 2) {
+                        pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
+                    } else {
+                        pDevMode->dmOrientation = DMORIENT_PORTRAIT;
+                    }
+                    pDevMode->dmFields |= DM_ORIENTATION;
+                }
+
+                if (attributes.fields.XResolution > 0) {
+                    pDevMode->dmPrintQuality = (short)attributes.fields.XResolution;
+                    pDevMode->dmFields |= DM_PRINTQUALITY;
+                }
+
+                if (attributes.fields.YResolution > 0) {
+                    pDevMode->dmYResolution = (short)attributes.fields.YResolution;
+                    pDevMode->dmFields |= DM_YRESOLUTION;
+                }
+
+                if (pDevMode->dmFields != 0) {
+#ifdef PRINTING_DEBUG
+                    printf("Setting up print attributes.\n");
+#endif /* PRINTING_DEBUG */
+                    ResetDC(pdc, pDevMode);
+                }
+            }
+            ClosePrinter(hPrinter);
+        }
+    }
+}
+
+int startDocument(const int pdcID, const char *jname, const char *fname) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        DOCINFO info;
+        info.cbSize = sizeof(DOCINFO);
+        
+        info.lpszDocName = jname;
+        info.lpszDatatype = NULL;
+        info.lpszOutput = fname;
+        info.fwType = 0;
+        if (StartDoc(pdc, &info) > 0) {
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int startPage(const int pdcID) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (StartPage(pdc) > 0) {
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int finishPage(const int pdcID) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (EndPage(pdc) > 0) {
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int finishDocument(const int pdcID) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (EndDoc(pdc) > 0) {
+            releasePrinterDC(pdcID);
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int transDoubleX(const int pdcID, jdouble x) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        double width = (double)GetDeviceCaps(pdc, HORZRES);
+        double k = width / psWidths[pdcID];
+        return (int)(x * k);
+    }
+    return (int)x;
+}
+
+int transDoubleY(const int pdcID, jdouble y) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        double height = (double)GetDeviceCaps(pdc, VERTRES);
+        double k = height / psHeights[pdcID];
+        return (int)(y * k);
+    }
+    return (int)y;
+}
+
+int client_LineTo(const int pdcID, int x, int y) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (LineTo(pdc, x, y) > 0) {
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int client_MoveTo(const int pdcID, int x, int y) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (MoveToEx(pdc, x, y, NULL) > 0) {
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int client_Arc(const int pdcID, int x, int y, int r, float alpha, float beta) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (AngleArc(pdc, x, y, r, alpha, beta) > 0) {
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int client_SetColor(const int pdcID, double red, double green, double blue) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        int r = (int)(255.0 * red);
+        int g = (int)(255.0 * green);
+        int b = (int)(255.0 * blue);
+        HPEN pen = CreatePen(PS_SOLID, 0, RGB(r, g, b));
+        HPEN oldPen = (HPEN)SelectObject(pdc, pen);
+        if (oldPen != NULL) {
+            DeleteObject(oldPen);
+            HBRUSH brush = CreateSolidBrush(RGB(r, g, b));
+            HBRUSH oldBrush = (HBRUSH)SelectObject(pdc, brush);
+            if (oldBrush != NULL) {
+                DeleteObject(oldBrush);
+                if (SetTextColor(pdc, RGB(r, g, b)) != CLR_INVALID) {
+                    return JNI_TRUE;
+                }
+            }
+        }
+    }
+    return JNI_FALSE;
+}
+
+int client_BeginPath(const int pdcID) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (BeginPath(pdc)) {
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int client_ClosePath(const int pdcID) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (CloseFigure(pdc)) {
+            if (EndPath(pdc)) {
+                return JNI_TRUE;
+            }
+        }
+    }
+    return JNI_FALSE;
+}
+
+int client_StrokePath(const int pdcID) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (StrokePath(pdc)) {
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int client_FillPath(const int pdcID) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        if (FillPath(pdc)) {
+            return JNI_TRUE;
+        }
+    }
+    return JNI_FALSE;
+}
+
+int client_DrawImage(const int pdcID, int x, int y, int sw, int sh, int *data, int w, int h) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        HDC screen = GetDC(NULL);
+        HDC bmpdc = CreateCompatibleDC(screen);
+        HBITMAP bmp = NULL;
+        if ((bmp = CreateBitmap(w, h, 1, 32, (void *)data)) != NULL) {
+            SelectObject(bmpdc, bmp);
+//            SetStretchBltMode(pdc, COLORONCOLOR);
+            if (StretchBlt(pdc, x, y,
+                sw, sh,
+                bmpdc, 0, 0, w, h, SRCCOPY) != 0) {
+                DeleteObject(bmp);
+                DeleteDC(bmpdc);
+                return JNI_TRUE;
+            }
+        }
+    }
+    return JNI_FALSE;
+}
+
+int client_DrawText(const int pdcID, const char *text) {
+    HDC pdc = printerDCs[pdcID];
+    if (pdc != NULL) {
+        POINT point;
+        if (MoveToEx(pdc, 0, 0, &point)) {
+            if (TextOut(pdc, point.x, point.y, text, (int)strlen(text))) {
+                if (MoveToEx(pdc, point.x, point.y, NULL)) {
+                    return JNI_TRUE;
+                }
+            }
+        }
+    }
+    return JNI_FALSE;
+}
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_PSInterpreter_obtainServiceID
+(JNIEnv *env, jclass owner, jstring printerName, jint width, jint height) {
+    const char *printer = env->GetStringUTFChars(printerName, 0);
+    return obtainPrinterDC(printer, (int)width, (int)height);
+}
+
+JNIEXPORT void JNICALL Java_org_apache_harmony_x_print_PSInterpreter_releaseServiceID
+(JNIEnv *env, jclass owner, jint serviceID) {
+    releasePrinterDC((int)serviceID);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_startDocument
+(JNIEnv *env, jclass owner, jstring printerName, jint serviceID,
+ jintArray printAttributes, jstring jobName, jstring destination) {
+    const char *printer = env->GetStringUTFChars(printerName, 0);
+    const char *jname = env->GetStringUTFChars(jobName, 0);
+    const char *fname = NULL;
+    if (destination != NULL) {
+        fname = env->GetStringUTFChars(destination, 0);
+    }
+    AttributesUnion attributes;
+    jboolean isCopy = JNI_FALSE;
+    int *numbers = (int *)env->GetIntArrayElements(printAttributes, &isCopy);
+    for (int i = 0; i < ATTRIBUTE_UNION_SIZE; i++) {
+        attributes.numbers[i] = numbers[i];
+    }
+    setAttributes(printer, (int)serviceID, attributes);
+    return (jboolean)startDocument((int)serviceID, jname, fname);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_startPage
+(JNIEnv *env, jclass owner, jint serviceID) {
+    return (jboolean)startPage((int)serviceID);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_endPage
+(JNIEnv *env, jclass owner, jint serviceID) {
+    return (jboolean)finishPage((int)serviceID);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_endDocument
+(JNIEnv *env, jclass owner, jint serviceID) {
+    return (jboolean)finishDocument((int)serviceID);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_setRGBColor
+(JNIEnv *env, jclass owner, jint serviceID, jdouble red, jdouble green, jdouble blue) {
+    return (jboolean)client_SetColor((int)serviceID, (double)red, (double)green, (double)blue);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_moveTo
+(JNIEnv *env, jclass owner, jint serviceID, jdouble x, jdouble y) {
+    return (jboolean)client_MoveTo((int)serviceID, transDoubleX(serviceID, x), transDoubleY(serviceID, psHeights[(int)serviceID] - y));
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_lineTo
+(JNIEnv *env, jclass owner, jint serviceID, jdouble x, jdouble y) {
+    return (jboolean)client_LineTo((int)serviceID, transDoubleX(serviceID, x), transDoubleY(serviceID, psHeights[(int)serviceID] - y));
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_drawArc
+(JNIEnv *env, jclass owner, jint serviceID, jdouble x, jdouble y, jdouble r, jdouble alpha, jdouble beta) {
+    return (jboolean)client_Arc((int)serviceID, transDoubleX(serviceID, x), transDoubleY(serviceID, psHeights[(int)serviceID] - y),
+        transDoubleX(serviceID, r), (float)alpha, (float)beta);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_beginPath
+(JNIEnv *env, jclass owner, jint serviceID) {
+    return (jboolean)client_BeginPath((int)serviceID);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_closePath
+(JNIEnv *env, jclass owner, jint serviceID) {
+    return (jboolean)client_ClosePath((int)serviceID);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_strokePath
+(JNIEnv *env, jclass owner, jint serviceID) {
+    return (jboolean)client_StrokePath((int)serviceID);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_fillPath
+(JNIEnv *env, jclass owner, jint serviceID) {
+    return (jboolean)client_FillPath((int)serviceID);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_drawImage
+(JNIEnv *env, jclass owner, jint serviceID, jdouble x, jdouble y,
+        jdouble sw, jdouble sh, jintArray data, jint w, jint h) {
+    int *bits;
+    if (data != NULL) {
+        bits = (int *)env->GetIntArrayElements(data, NULL);
+    } else {
+        return JNI_FALSE;
+    }
+    jboolean result = (jboolean)client_DrawImage((int)serviceID,
+        transDoubleX(serviceID, x), transDoubleY(serviceID, psHeights[(int)serviceID] - y),
+        transDoubleX(serviceID, sw), transDoubleY(serviceID, sh),
+        bits, (int)w, (int)h);
+    env->ReleaseIntArrayElements(data, (jint *)bits, JNI_ABORT);
+    return result;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_drawText
+(JNIEnv *env, jclass owner, jint serviceID, jstring text) {
+    const char *string = env->GetStringUTFChars(text, 0);
+    return client_DrawText((int)serviceID, string);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_clipPath
+(JNIEnv *env, jclass owner, jint serviceID) {
+    return JNI_TRUE;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_rotate
+(JNIEnv *env, jclass owner, jint serviceID, jdouble alpha) {
+    return JNI_TRUE;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_PSInterpreter_setFont
+(JNIEnv *env, jclass owner, jint serviceID, jstring font) {
+    const char *name = env->GetStringUTFChars(font, 0);
+    return JNI_TRUE;
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.cpp
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.h?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.h (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.h Sun Oct  8 22:33:09 2006
@@ -0,0 +1,31 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Aleksei V. Ivaschenko 
+ * @version $Revision: 1.3 $ 
+ */ 
+
+/*
+ * Main header file. Includes required headers of Windows API.
+ */
+
+#pragma once
+
+#define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
+
+#include <malloc.h>
+#include <windows.h>
+#include <winspool.h>

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/print.h
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/ui.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/ui.cpp?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/ui.cpp (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/ui.cpp Sun Oct  8 22:33:09 2006
@@ -0,0 +1,210 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Irina A. Arkhipets 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+// 
+// ui.cpp : Defines the entry point for the DLL application.
+// Created at January, 20, 2005
+// Author - Irina Arkhipets
+//
+// Things to do - update changed printing attributes in 
+// java.awt.PrinterJob class
+// Waiting while all attrs supported by our product &
+// native Alexey's native function for getting 
+// java attributes from the printer DEVMODE structure
+//
+
+//#include "stdafx.h"
+#include <Windows.h>
+
+#include "org_apache_harmony_x_print_awt_PSPrinterJob.h"
+
+#include <commdlg.h>
+#include <wingdi.h>
+#include <malloc.h>
+#include <Windef.h>
+#include <winspool.h>
+
+BOOL getPrinterStructures(char*, HGLOBAL*, HGLOBAL*);
+
+//-----------------------------------------------------------------------------
+
+// This function calls PrintDlg Windows GDI API function which shows 
+// standard native Windows dialog for the printer selecting.
+//
+// Returns: 
+// Printer name if user clicked OK
+// NULL if user cancelled the dialog
+//
+// If user clicked OK, this function also calls setCopies(int) method 
+// of the DefaultPrinterJob class
+// Please, update this function if you need to change some other attributes
+// (for example, probably we need to set Collate attribute)
+//
+
+JNIEXPORT jstring JNICALL Java_org_apache_harmony_x_print_DefaultPrinterJob_getPrinter
+(JNIEnv * env, jobject obj, jstring service, jint copies) {
+    PRINTDLG pd;
+    HWND hwnd=NULL;
+    char *prnName=NULL;
+
+    ZeroMemory(&pd, sizeof(pd));
+    pd.lStructSize = sizeof(pd);
+    pd.hwndOwner   = hwnd;
+    pd.hDevNames   = NULL;    
+    pd.hDevMode    = NULL;    
+    pd.Flags       = PD_RETURNDC | PD_HIDEPRINTTOFILE | 
+                     PD_NOPAGENUMS | PD_NOSELECTION; 
+    pd.nCopies     = (WORD)copies;
+
+    // Get correct DEVMODE and DEVNAMES structures for the selected printer
+    getPrinterStructures((char *)env->GetStringUTFChars(service,0),
+        &(pd.hDevNames),&(pd.hDevMode));
+
+    if (PrintDlg(&pd)==TRUE) {
+        jclass jCls = (env)->GetObjectClass(obj);
+        jmethodID jMetID = env->GetMethodID(jCls, "setCopies", "(I)V"); 
+        LPDEVNAMES lpdn = (LPDEVNAMES)GlobalLock(pd.hDevNames);
+        prnName=(char*)
+            (calloc(lpdn->wOutputOffset-lpdn->wDeviceOffset+1,sizeof(char)));
+        if(prnName!=NULL) {
+            LPDEVMODE dm = (LPDEVMODE)GlobalLock(pd.hDevMode);
+            env->CallVoidMethod(obj,jMetID, dm->dmCopies);
+            GlobalUnlock(pd.hDevMode); 
+            CopyMemory((LPBYTE)prnName, ((LPBYTE)lpdn+lpdn->wDeviceOffset),
+                lpdn->wOutputOffset-lpdn->wDeviceOffset);
+        }
+
+        DeleteDC(pd.hDC);
+        GlobalUnlock(pd.hDevNames); 
+        GlobalFree(pd.hDevNames); 
+        GlobalFree(pd.hDevMode);   
+        return env->NewStringUTF(prnName);
+    }
+    
+    return NULL;
+}
+
+// This is duplicate for PSPrinterJob class
+JNIEXPORT jstring JNICALL Java_org_apache_harmony_x_print_awt_PSPrinterJob_getPrinter
+(JNIEnv * env, jobject obj, jstring service, jint copies) {
+    return Java_org_apache_harmony_x_print_DefaultPrinterJob_getPrinter(env, obj, service, copies);
+}
+
+//-----------------------------------------------------------------------------
+
+// returns DEVMODE and DEVNAMES for the printer
+BOOL getPrinterStructures(char* printerName, 
+                          HGLOBAL* devNames, HGLOBAL* devMode) {
+    HANDLE printerHandle;
+    PRINTER_INFO_2 *printerInfo = NULL;
+
+    // Open printer
+    if (!OpenPrinter(printerName, &printerHandle, NULL)) 
+        return FALSE;
+    
+    // Get PRINTER_INFO_STRUCTURE size
+    DWORD byteNeeded, byteUsed;
+    GetPrinter(printerHandle, 2, NULL, 0, &byteNeeded);
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
+        ClosePrinter(printerHandle);
+        return FALSE;
+    }       
+
+    // Allocate PRINTER_INFO_2 structure
+    printerInfo = (PRINTER_INFO_2 *)malloc(byteNeeded);
+    if (!printerInfo){
+        ClosePrinter(printerHandle);
+        return FALSE;
+    }
+
+    // Get PRINTER_INFO_2 structure for the printer
+    if (!GetPrinter(printerHandle, 2, 
+        (unsigned char *)printerInfo, byteNeeded, &byteUsed)) {
+        free(printerInfo);
+        ClosePrinter(printerHandle);
+        return FALSE;
+    }
+
+    // Close printer
+    ClosePrinter(printerHandle);
+
+    // Allocate global handle for the DEVMODE structure
+    HGLOBAL hDevMode = GlobalAlloc(GHND, sizeof(*printerInfo->pDevMode) +
+        printerInfo->pDevMode->dmDriverExtra);
+    if(hDevMode==NULL) {
+        free(printerInfo);
+        return FALSE;
+    }   
+
+    // Cope DEVMODE from PRINTER_INFO_2 structure to the allocated memory
+    DEVMODE* pDevMode = (DEVMODE*)GlobalLock(hDevMode);
+    memcpy(pDevMode, printerInfo->pDevMode, 
+        sizeof(*printerInfo->pDevMode) + printerInfo->pDevMode->dmDriverExtra);
+    GlobalUnlock(hDevMode);
+
+    // Driver name length in chars
+    DWORD driverNameLen = lstrlen(printerInfo->pDriverName)+1;
+    // Printer name length
+    DWORD printerNameLen = lstrlen(printerInfo->pPrinterName)+1;
+    // Port name length
+    DWORD portNameLen = lstrlen(printerInfo->pPortName)+1;
+
+    // Allocate global handle for the DEVNAMES
+    HGLOBAL hDevNames = GlobalAlloc(GHND, sizeof(DEVNAMES)+
+        (driverNameLen + printerNameLen + portNameLen)*sizeof(TCHAR));
+    if(hDevNames==NULL) {
+        free(printerInfo);
+        GlobalFree(hDevMode);
+        return FALSE;
+    }
+
+    // Current offset for the names fields in DEVNAMES
+    int offset = sizeof(DEVNAMES);
+
+    DEVNAMES* pDevNames=(DEVNAMES*)GlobalLock(hDevNames);
+
+    // Copy driver name to global DEVNAMES
+    pDevNames->wDriverOffset = offset;
+    memcpy((LPSTR)pDevNames+offset, 
+        printerInfo->pDriverName, driverNameLen*sizeof(TCHAR));
+    offset+=driverNameLen*sizeof(TCHAR);
+
+    // Copy printer name to global DEVNAMES
+    pDevNames->wDeviceOffset=offset;
+    memcpy((LPSTR)pDevNames+offset, 
+        printerInfo->pPrinterName, printerNameLen*sizeof(TCHAR));
+    offset+=printerNameLen;
+
+    // Copy port name to global DEVNAMES
+    pDevNames->wOutputOffset=offset;
+    memcpy((LPSTR)pDevNames+offset, 
+        printerInfo->pPortName, portNameLen*sizeof(TCHAR));
+
+    // Default printer flag
+    pDevNames->wDefault = 0;
+
+    GlobalUnlock(hDevNames);
+    free(printerInfo);
+
+    *devMode = hDevMode;
+    *devNames = hDevNames;
+    
+    return TRUE;
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/native/print/windows/ui.cpp
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/DocFlavorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/DocFlavorTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/DocFlavorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/DocFlavorTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,124 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Irina A. Arkhipets 
+ * @version $Revision: 1.3 $ 
+ */ 
+
+/*
+ * DocFlavorTest.java
+ * 
+ * JUnit tests for javax.print.DocFlavor class.
+ * 
+ */
+
+package javax.print;
+
+import junit.framework.TestCase;
+
+public class DocFlavorTest extends TestCase {
+
+static public void testStatic() {
+    System.out.println("----------------------------------------");
+    System.out.println("Static variables testing...");
+    try {
+        String encoding = System.getProperty("file.encoding");
+        if ((encoding != null) && (encoding.length() > 0)) {
+            assertEquals(DocFlavor.hostEncoding, encoding);
+        } else {
+            System.out.println(
+                    "WARNING: Can not get system file.encoding property!");
+        }
+    } catch (Exception e) {
+        System.out.println(
+                "WARNING: Can not get system file.encoding property!");
+        e.printStackTrace();
+    }
+}
+
+public void testHashCode() {
+    DocFlavor f1 = new DocFlavor("text/plain; charset=us-ascii", "[B");
+    DocFlavor f2 = 
+            new DocFlavor("text/plain; charset=us-ascii (comments)", "[B");
+    assertEquals(f1.hashCode(), f1.hashCode());
+    assertEquals(f1.hashCode(), f2.hashCode());
+}
+
+public void testMyDocFlavor() {
+    tryNullPointer(null, "[B");
+    tryNullPointer("text/plain", null);
+}
+
+public void testEqualsObject() {
+    DocFlavor f1 = new DocFlavor("text/plain; charset=us-ascii", "[B");
+    DocFlavor f2 = 
+            new DocFlavor("text/plain; charset=us-ascii (comments)", "[B");
+    DocFlavor f3 = new DocFlavor("image/gif", "[B");
+    DocFlavor f4 = new DocFlavor("text/plain", "[B");
+    DocFlavor f5 = new DocFlavor("text/plain; charset=us-ascii", "[C");
+    assertTrue(f1.equals(f1));
+    assertTrue(f1.equals(f2));
+    assertFalse(f1.equals(f3));
+    assertFalse(f1.equals(f4));
+    assertFalse(f1.equals(f5));
+}
+
+public void testGetMediaSubtype() {
+    DocFlavor f = new DocFlavor("text/plain; charset=us-ascii", "[B");
+    assertTrue(f.getMediaSubtype().equals(new String("plain")));
+}
+
+public void testGetMediaType() {
+    DocFlavor f = new DocFlavor("text/plain; charset=us-ascii", "[B");
+    assertTrue(f.getMediaType().equals(new String("text")));
+}
+
+public void testGetMimeType() {
+    DocFlavor f = 
+            new DocFlavor("TEXT/plain; BBB=par1; aaa=par2 (comments)", "[B");
+    assertTrue((f.getMimeType()).equals(
+            new String("text/plain; aaa=\"par2\"; bbb=\"par1\"")));
+}
+
+public void testGetParameter() {
+    DocFlavor f =
+            new DocFlavor("TEXT/plain; BBB=par1; aaa=par2 (comments)", "[B");
+    assertEquals(f.getParameter("bbb"), new String("par1"));
+    assertEquals(f.getParameter("absent"), null);
+}
+
+public void testGetRepresentationClassName() {
+    DocFlavor f = 
+            new DocFlavor("TEXT/plain; BBB=par1; aaa=par2 (comments)", "[B");
+    assertEquals(f.getRepresentationClassName(), new String("[B"));
+}
+
+public void testToString() {
+    DocFlavor f = 
+            new DocFlavor("TEXT/plain; BBB=par1; aaa=par2 (comments)", "[B");
+    assertEquals(f.toString(), new String(
+            "text/plain; aaa=\"par2\"; bbb=\"par1\"; class=\"[B\""));
+}
+
+void tryNullPointer(String s1, String s2) {
+    try {
+        new DocFlavor(s1, s2);
+        fail();
+    } catch (NullPointerException e) {
+        /* NullPointerException is expected here, so the test passes */
+    }
+}
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/DocFlavorTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributeTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributeTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributeTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributeTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,80 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package javax.print;
+
+import javax.print.attribute.PrintServiceAttribute;
+import javax.print.attribute.standard.Copies;
+import javax.print.attribute.standard.Destination;
+import javax.print.attribute.standard.JobName;
+import javax.print.attribute.standard.PrinterIsAcceptingJobs;
+import javax.print.attribute.standard.PrinterState;
+import javax.print.attribute.standard.QueuedJobCount;
+import javax.print.attribute.standard.RequestingUserName;
+
+import junit.framework.TestCase;
+
+public class GetAttributeTest extends TestCase {
+
+    public void testGetAttribute() {
+        System.out
+                .println("============= START testGetAttribute ================");
+
+        PrintService[] services;
+        Object probe;
+        Class[] clazz = new Class[] { PrinterIsAcceptingJobs.ACCEPTING_JOBS
+                .getCategory(),
+                PrinterState.IDLE.getCategory(),
+                QueuedJobCount.class,
+                Destination.class,
+                JobName.class,
+                RequestingUserName.class };
+        services = PrintServiceLookup.lookupPrintServices(null, null);
+        TestUtil.checkServices(services);
+
+        for (int i = 0, ii = services.length; i < ii; i++) {
+            System.out.println("----" + services[i].getName() + "----");
+            for (int j = 0, jj = clazz.length; j < jj; j++) {
+                if (PrintServiceAttribute.class.isAssignableFrom(clazz[j])) {
+                    probe = services[i].getAttribute(clazz[j]);
+                    System.out.println(clazz[j] + ": " + probe);
+                }
+            }
+            try {
+                probe = services[i].getAttribute(null);
+                fail("NullPointerException must be thrown - the category is null");
+            } catch (NullPointerException e) {
+                // OK
+            }
+            try {
+                probe = services[i].getAttribute(Copies.class);
+                fail("IllegalArgumentException must be thrown - category is not a Class that implements interface PrintServiceAttribute.");
+            } catch (IllegalArgumentException e) {
+                // OK
+            } catch (Exception e) {
+                fail("Exception " + e + "is thrown - something is wrong");
+            }
+        }
+
+        System.out
+                .println("============= END testGetAttribute ================");
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributeTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributesTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributesTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributesTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributesTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,53 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package javax.print;
+
+import javax.print.attribute.Attribute;
+import javax.print.attribute.PrintServiceAttributeSet;
+
+import junit.framework.TestCase;
+
+public class GetAttributesTest extends TestCase {
+
+    public void testGetAttributes() {
+        System.out
+                .println("============= START testGetAttributes ================");
+
+        PrintService[] services;
+        PrintServiceAttributeSet as;
+        Attribute[] aa;
+        services = PrintServiceLookup.lookupPrintServices(null, null);
+        TestUtil.checkServices(services);
+        
+        for (int i = 0, ii = services.length; i < ii; i++) {
+            System.out.println("----" + services[i].getName() + "----");
+            as = services[i].getAttributes();
+            aa = as.toArray();
+            for (int j = 0; j < aa.length; j++) {
+                System.out.println(aa[j].getName() + ": " + aa[j].toString());
+            }
+        }
+
+        System.out
+                .println("============= END testGetAttributes ================");
+    }
+    
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetAttributesTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetDefaultAttributeValueTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetDefaultAttributeValueTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetDefaultAttributeValueTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetDefaultAttributeValueTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,75 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package javax.print;
+
+import javax.print.attribute.standard.Destination;
+import javax.print.attribute.standard.DocumentName;
+import javax.print.attribute.standard.JobName;
+import javax.print.attribute.standard.Media;
+import javax.print.attribute.standard.RequestingUserName;
+
+import junit.framework.TestCase;
+
+public class GetDefaultAttributeValueTest extends TestCase {
+
+    public void testGetDefaultAttributeValue() {
+        System.out.println("============= START testGetDefaultAttributeValue ================");
+
+        PrintService[] services;
+        Object probe;
+        Class claz;
+        services = PrintServiceLookup.lookupPrintServices(null, null);
+        TestUtil.checkServices(services);
+        try {
+            for (int i = 0, ii = services.length; i < ii; i++) {
+                System.out.println("------------------" + services[i].getName()
+                        + "-------------------");
+                probe = services[i].getDefaultAttributeValue(claz = Media.class);
+                System.out.println(claz + ": " + probe);
+                probe = services[i].getDefaultAttributeValue(claz = Destination.class);
+                System.out.println(claz + ": " + probe);
+                probe = services[i].getDefaultAttributeValue(claz = JobName.class);
+                System.out.println(claz + ": " + probe);
+                probe = services[i].getDefaultAttributeValue(claz = RequestingUserName.class);
+                System.out.println(claz + ": " + probe);
+                probe = services[i].getDefaultAttributeValue(claz = DocumentName.class);
+                System.out.println(claz + ": " + probe);
+                try {
+                    probe = services[i].getDefaultAttributeValue(null);
+                    fail("NullPointerException must be thrown - the category is null");
+                } catch (Exception e) {
+                    // OK
+                }
+                try {
+                    probe = services[i].getDefaultAttributeValue(this.getClass());
+                    fail("IllegalArgumentException must be thrown - category is not a Class that implements interface Attribute.");
+                } catch (IllegalArgumentException e) {
+                    // OK
+                }
+            }
+        } catch (RuntimeException e) {
+            fail("Exception "+e+" thrown");
+        }
+
+        System.out.println("============= END testGetDefaultAttributeValue ================");
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetDefaultAttributeValueTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeCategoriesTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeCategoriesTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeCategoriesTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeCategoriesTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,46 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package javax.print;
+
+import junit.framework.TestCase;
+
+public class GetSupportedAttributeCategoriesTest extends TestCase {
+
+    public void testGetSupportedAttributeCategories() {
+        System.out.println("============= START testGetSupportedAttributeCategories ================");
+
+        PrintService[] services;
+        Class[] claz;
+        services = PrintServiceLookup.lookupPrintServices(null, null);
+        TestUtil.checkServices(services);
+        for (int i = 0, ii = services.length; i < ii; i++) {
+            System.out.println("------------------" + services[i].getName()
+                    + "-------------------");
+            claz = services[i].getSupportedAttributeCategories();
+            for (int j = 0, jj = claz.length; j < jj; j++) {
+                System.out.println(claz[j]);
+            }
+        }
+
+        System.out.println("============= END testGetSupportedAttributeCategories ================");
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeCategoriesTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeValuesTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeValuesTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeValuesTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeValuesTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,79 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package javax.print;
+
+import javax.print.attribute.HashAttributeSet;
+import javax.print.attribute.standard.Finishings;
+import javax.print.attribute.standard.MediaSizeName;
+import javax.print.attribute.standard.OrientationRequested;
+
+import junit.framework.TestCase;
+
+public class GetSupportedAttributeValuesTest extends TestCase {
+
+    public void testGetSupportedAttributeValues() {
+        System.out
+                .println("============= START testGetSupportedAttributeValues ================");
+
+        PrintService[] services;
+        DocFlavor[] flavors = new DocFlavor[] { DocFlavor.INPUT_STREAM.GIF,
+                DocFlavor.INPUT_STREAM.POSTSCRIPT,
+                DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII };
+
+        services = PrintServiceLookup.lookupPrintServices(null, null);
+        TestUtil.checkServices(services);
+        for (int i = 0, ii = services.length; i < ii; i++) {
+            System.out.println("\n----------- " + services[i].getName()
+                    + "----------");
+
+            Class[] cats = services[i].getSupportedAttributeCategories();
+            HashAttributeSet aset = new HashAttributeSet();
+            aset.add(MediaSizeName.ISO_A0);
+            aset.add(OrientationRequested.LANDSCAPE);
+            aset.add(Finishings.SADDLE_STITCH);
+
+            for (int l = 0, ll = flavors.length; l < ll; l++) {
+                if (services[i].isDocFlavorSupported(flavors[l])) {
+                    System.out.println("    " + flavors[l]);
+
+                    for (int j = 0, jj = cats.length; j < jj; j++) {
+                        System.out.println("        " + cats[j]);
+
+                        Object obj = services[i].getSupportedAttributeValues(
+                                cats[j], flavors[l], aset);
+                        if (obj != null && obj.getClass().isArray()) {
+                            Object[] a = (Object[]) obj;
+                            for (int k = 0, kk = a.length; k < kk; k++) {
+                                System.out.println("            " + a[k]);
+                            }
+                        } else {
+                            System.out.println("            " + obj);
+                        }
+                    }
+                }
+            }
+        }
+
+        System.out
+                .println("============= END testGetSupportedAttributeValues ================");
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedAttributeValuesTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedDocFlavorsTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedDocFlavorsTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedDocFlavorsTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedDocFlavorsTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,51 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package javax.print;
+
+import junit.framework.TestCase;
+
+public class GetSupportedDocFlavorsTest extends TestCase {
+
+    public void testGetSupportedDocFlavors() {
+        System.out
+                .println("============= START testGetSupportedDocFlavors ================");
+
+        PrintService[] services;
+        DocFlavor[] df;
+        services = PrintServiceLookup.lookupPrintServices(null, null);
+        TestUtil.checkServices(services);
+        for (int i = 0, ii = services.length; i < ii; i++) {
+            System.out.println("------------------" + services[i].getName()
+                    + "-------------------");
+            df = services[i].getSupportedDocFlavors();
+            if (df.length == 0) {
+                fail("Array of supported doc flavors should have at least one element");
+            }
+            for (int j = 0; j < df.length; j++) {
+                System.out.println(df[j]);
+            }
+        }
+
+        System.out
+                .println("============= END testGetSupportedDocFlavors ================");
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetSupportedDocFlavorsTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetUnsupportedAttributesTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetUnsupportedAttributesTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetUnsupportedAttributesTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetUnsupportedAttributesTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,97 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package javax.print;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Locale;
+
+import javax.print.attribute.Attribute;
+import javax.print.attribute.AttributeSet;
+import javax.print.attribute.HashAttributeSet;
+import javax.print.attribute.standard.Destination;
+import javax.print.attribute.standard.DocumentName;
+import javax.print.attribute.standard.Finishings;
+import javax.print.attribute.standard.JobName;
+import javax.print.attribute.standard.MediaSizeName;
+import javax.print.attribute.standard.RequestingUserName;
+
+import junit.framework.TestCase;
+
+public class GetUnsupportedAttributesTest extends TestCase {
+    public void testIsAttributeValueSupported() throws Exception {
+        System.out
+                .println("============= START GetUnsupportedAttributesTest ================");
+
+        PrintService[] services;
+        DocFlavor[] flavors = new DocFlavor[] { DocFlavor.INPUT_STREAM.GIF,
+                DocFlavor.INPUT_STREAM.POSTSCRIPT,
+                DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII };
+
+        services = PrintServiceLookup.lookupPrintServices(null, null);
+        TestUtil.checkServices(services);
+        if (services.length > 0) {
+            for (int i = 0, ii = services.length; i < ii; i++) {
+                System.out.println("----------- " + services[i].getName()
+                        + "----------");
+
+                URI uri = null;
+                try {
+                    uri = new URI("file:///c:/no/such/dir/print.out");
+                    //uri = File.createTempFile("xxx", null).toURI();
+                } catch (URISyntaxException e) {
+                    fail();
+                }
+
+                AttributeSet attrs = new HashAttributeSet();
+                attrs.add(Finishings.EDGE_STITCH);
+                attrs.add(MediaSizeName.JAPANESE_DOUBLE_POSTCARD);
+                attrs.add(new Destination(uri));
+                attrs.add(new DocumentName("Doc X", Locale.US));
+                attrs.add(new JobName("Job Y", Locale.US));
+                attrs.add(new RequestingUserName("User Z", Locale.US));
+
+                for (int j = 0; j < flavors.length; j++) {
+                    if (services[i].isDocFlavorSupported(flavors[j])) {
+                        AttributeSet aset = services[i]
+                                .getUnsupportedAttributes(flavors[j], attrs);
+                        if (aset == null) {
+                            fail("At least one attribute is unsupported");
+                        }
+                        if (aset != null) {
+                            Attribute[] aarr = aset.toArray();
+                            System.out
+                                    .println("Usupported attributes fo DocFlavor "
+                                            + flavors[j]);
+                            for (int k = 0, kk = aarr.length; k < kk; k++) {
+                                System.out.println("\t" + aarr[k]);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        System.out
+                .println("============= END GetUnsupportedAttributesTest ================");
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/GetUnsupportedAttributesTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeCategorySupportedTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeCategorySupportedTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeCategorySupportedTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeCategorySupportedTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,67 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package javax.print;
+
+import javax.print.attribute.standard.JobStateReason;
+
+import junit.framework.TestCase;
+
+public class IsAttributeCategorySupportedTest extends TestCase {
+
+    public void testIsAttributeCategorySupported() {
+        System.out
+                .println("============= START testIsAttributeCategorySupported ================");
+
+        PrintService[] services;
+        Class[] claz;
+        boolean supported;
+
+        services = PrintServiceLookup.lookupPrintServices(null, null);
+        TestUtil.checkServices(services);
+        for (int i = 0, ii = services.length; i < ii; i++) {
+            System.out.println("------------------" + services[i].getName()
+                    + "-------------------");
+            claz = services[i].getSupportedAttributeCategories();
+            for (int j = 0, jj = claz.length; j < jj; j++) {
+                supported = services[i].isAttributeCategorySupported(claz[j]);
+                if (!supported) {
+                    fail("Category " + claz[j] + " must be supported.");
+                }
+                System.out.println(claz[j] + ": " + supported);
+            }
+
+            supported = services[i]
+                    .isAttributeCategorySupported(JobStateReason.ABORTED_BY_SYSTEM
+                            .getCategory());
+            if (supported) {
+                fail("Category "
+                        + JobStateReason.ABORTED_BY_SYSTEM.getCategory()
+                        + " must not be supported.");
+            }
+            System.out.println(JobStateReason.ABORTED_BY_SYSTEM.getCategory()
+                    + ": " + supported);
+        }
+
+        System.out
+                .println("============= END testIsAttributeCategorySupported ================");
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeCategorySupportedTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeValueSupportedTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeValueSupportedTest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeValueSupportedTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeValueSupportedTest.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,105 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package javax.print;
+
+import java.net.URI;
+import java.util.Locale;
+
+import javax.print.attribute.Attribute;
+import javax.print.attribute.standard.Destination;
+import javax.print.attribute.standard.DocumentName;
+import javax.print.attribute.standard.Finishings;
+import javax.print.attribute.standard.JobName;
+import javax.print.attribute.standard.MediaSizeName;
+import javax.print.attribute.standard.RequestingUserName;
+import javax.print.attribute.standard.Sides;
+
+import junit.framework.TestCase;
+
+public class IsAttributeValueSupportedTest extends TestCase {
+    public void testIsAttributeValueSupported() throws Exception {
+        System.out
+                .println("============= START testIsAttributeValueSupported ================");
+
+        PrintService[] services;
+        URI uri1, uri2, uri3;
+        boolean supported = false;
+
+        services = PrintServiceLookup.lookupPrintServices(null, null);
+        TestUtil.checkServices(services);
+        for (int i = 0, ii = services.length; i < ii; i++) {
+            System.out.println("----------- " + services[i].getName()
+                    + "----------");
+
+            try {
+                uri1 = new URI("file:///foo/bar");
+                uri2 = new URI("file:///F:/printing/tmp/print.out");
+                uri3 = new URI("file:///F:/printing/tmp/xxx/print.out");
+
+                Attribute[] attrs = { MediaSizeName.ISO_A0,
+                        Finishings.NONE,
+                        Finishings.EDGE_STITCH,
+                        MediaSizeName.ISO_A2,
+                        MediaSizeName.ISO_A3,
+                        new Destination(uri1),
+                        new Destination(uri2),
+                        new Destination(uri3),
+                        new DocumentName("xyz", Locale.US),
+                        new JobName("xyz", Locale.US),
+                        new RequestingUserName("xyz", Locale.US),
+                        Sides.DUPLEX,
+                        Sides.ONE_SIDED,
+                        Sides.TUMBLE,
+                        Sides.TWO_SIDED_LONG_EDGE,
+                        Sides.TWO_SIDED_SHORT_EDGE,
+                        null };
+                for (int a = 0, ac = attrs.length; a < ac; a++) {
+                    try {
+                        supported = services[i].isAttributeValueSupported(
+                                attrs[a], DocFlavor.INPUT_STREAM.GIF, null);
+                    } catch (NullPointerException e1) {
+                        if (attrs[a] != null) {
+                            fail(e1.toString());
+                        }
+                    } catch (IllegalArgumentException e) {
+                        if (services[i]
+                                .isDocFlavorSupported(DocFlavor.INPUT_STREAM.GIF)) {
+                            fail(e.toString());
+                        }
+                    } catch (Exception e) {
+                        fail(e.toString());
+                    }
+                    System.out.println(attrs[a]
+
+                            + (attrs[a] == null ? "" : "("
+                                    + attrs[a].getCategory().toString() + ")")
+                            + " : " + supported);
+                }
+            } catch (Exception e) {
+                fail(e.toString());
+            }
+        }
+
+        System.out
+                .println("============= END testIsAttributeValueSupported ================");
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/test/api/java/common/javax/print/IsAttributeValueSupportedTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message