You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/10/09 07:33:21 UTC
svn commit: r454289 [16/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...
Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppPrinter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppPrinter.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppPrinter.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppPrinter.java Sun Oct 8 22:33:09 2006
@@ -0,0 +1,390 @@
+/*
+ * 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 org.apache.harmony.x.print.ipp;
+
+import java.net.URI;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Vector;
+
+public class IppPrinter {
+ protected static int verbose = 0;
+ protected URI printeruri;
+ protected IppAttributeGroupSet agroups; /* all attributes as in IppRequest */
+
+ public static int getVerbose() {
+ return verbose;
+ }
+
+ public static void setVerbose(int newverbose) {
+ verbose = newverbose;
+ IppClient.setVerbose(verbose);
+ }
+
+ public static void doVerbose(String v) {
+ System.out.println(v);
+ }
+
+ public static void doVerbose(int level, String v) {
+ if (verbose >= level) {
+ System.out.println(v);
+ }
+ }
+
+ public IppPrinter(URI uri) throws Exception {
+ this.printeruri = uri;
+
+ IppClient c = new IppClient(this.printeruri);
+ IppRequest request;
+ IppResponse response;
+ IppAttributeGroup agroup;
+ Vector va = new Vector();
+
+ request = new IppRequest();
+ request.setVersion(1, 1);
+ request.setOperationId(IppOperation.GET_PRINTER_ATTRIBUTES);
+ agroup = request.newGroup(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES);
+ agroup.add(new IppAttribute(IppAttribute.TAG_CHARSET,
+ "attributes-charset", "utf-8"));
+ agroup.add(new IppAttribute(IppAttribute.TAG_NATURAL_LANGUAGE,
+ "attributes-natural-language", "en-us"));
+ agroup.add(new IppAttribute(IppAttribute.TAG_URI, "printer-uri", uri
+ .toString()));
+ va.add("printer-uri-supported".getBytes());
+ va.add("ipp-versions-supported".getBytes());
+ agroup.add(new IppAttribute(IppAttribute.TAG_KEYWORD,
+ "requested-attributes", va));
+
+ response = c.request(request.getBytes());
+
+ if (response.operationid >= 0x0000 && response.operationid <= 0x00FF) {
+ if (response.ippversion[0] != 1 || response.ippversion[1] != 1) {
+ throw new IppException("Can't use ipp protocol version "
+ + response.ippversion[0] + "." + response.ippversion[1]
+ + " of printer <" + uri.toString() + ">");
+ }
+ } else {
+ throw new IppException("Can't use ipp printer <" + uri.toString()
+ + ">" + "\n" + response.toString());
+ }
+ this.agroups = new IppAttributeGroupSet();
+ }
+
+ public URI getURI() {
+ return printeruri;
+ }
+
+ public IppResponse requestPrinterAttributes() throws Exception {
+ return requestPrinterAttributes("all", null);
+ }
+
+ public IppResponse requestJobTemplateAttributes() throws Exception {
+ return requestPrinterAttributes("job-template", null);
+ }
+
+ public IppResponse requestPrinterDescriptionAttributes() throws Exception {
+ //return requestPrinterAttributes("printer-description", null);
+ return requestPrinterAttributes("all", null);
+ }
+
+ public IppResponse requestPrinterAttributes(String what, String mimetype)
+ throws Exception {
+ IppClient c = new IppClient(printeruri);
+ IppRequest request;
+ IppResponse response;
+ IppAttributeGroup agroup;
+ Vector va = new Vector();
+
+ request = new IppRequest();
+ request.setVersion(1, 1);
+ request.setOperationId(IppOperation.GET_PRINTER_ATTRIBUTES);
+ agroup = request.newGroup(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES);
+ agroup.add(new IppAttribute(IppAttribute.TAG_CHARSET,
+ "attributes-charset", "utf-8"));
+ agroup.add(new IppAttribute(IppAttribute.TAG_NATURAL_LANGUAGE,
+ "attributes-natural-language", "en-us"));
+ agroup.add(new IppAttribute(IppAttribute.TAG_URI, "printer-uri",
+ printeruri.toString()));
+ va = new Vector();
+ va.add(what.getBytes());
+ agroup.add(new IppAttribute(IppAttribute.TAG_KEYWORD,
+ "requested-attributes", va));
+ agroup.add(new IppAttribute(IppAttribute.TAG_BOOLEAN,
+ "ipp-attribute-fidelity", 0x01));
+ if (mimetype != null && mimetype.length() > 0) {
+ agroup.add(new IppAttribute(IppAttribute.TAG_MIMEMEDIATYPE,
+ "document-format", mimetype));
+ }
+
+ response = c.request(request.getBytes());
+
+ if (response.operationid >= 0x0000 && response.operationid <= 0x00FF) {
+ return response;
+ }
+ return null;
+ }
+
+ public boolean setAttribute(String aname, Object avalue) {
+ return agroups.setAttribute(aname, avalue);
+ }
+
+ public IppResponse requestValidateJob(String jobname, IppDocument document,
+ IppAttributeGroupSet agset) throws Exception {
+ IppClient c = new IppClient(printeruri);
+ IppRequest request;
+ IppResponse response;
+ IppAttributeGroup opa, joba;
+
+ request = new IppRequest();
+ request.setVersion(1, 1);
+ request.setOperationId(IppOperation.VALIDATE_JOB);
+
+ opa = request.newGroup(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES);
+ opa.add(new IppAttribute(IppAttribute.TAG_CHARSET,
+ "attributes-charset", "utf-8"));
+ opa.add(new IppAttribute(IppAttribute.TAG_NATURAL_LANGUAGE,
+ "attributes-natural-language", "en-us"));
+ opa.add(new IppAttribute(IppAttribute.TAG_URI, "printer-uri",
+ printeruri.toString()));
+ opa.add(new IppAttribute(IppAttribute.TAG_MIMEMEDIATYPE,
+ "document-format", document.getFormat()));
+ opa.add(new IppAttribute(IppAttribute.TAG_NAMEWITHOUTLANGUAGE,
+ "requesting-user-name", (String) AccessController
+ .doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty("user.name");
+ }
+ })));
+ opa.add(new IppAttribute(IppAttribute.TAG_NAMEWITHOUTLANGUAGE,
+ "job-name", jobname));
+ opa.add(new IppAttribute(IppAttribute.TAG_NAMEWITHOUTLANGUAGE,
+ "document-name", document.getName()));
+ opa.add(new IppAttribute(IppAttribute.TAG_BOOLEAN,
+ "ipp-attribute-fidelity", 0x01));
+ opa.set((IppAttributeGroup) document.getAgroups().get(
+ new Integer(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES)));
+ if (agset != null) {
+ opa.set((IppAttributeGroup) agset.get(new Integer(
+ IppAttributeGroup.TAG_OPERATION_ATTRIBUTES)));
+ }
+
+ joba = request.newGroup(IppAttributeGroup.TAG_JOB_TEMPLATE_ATTRIBUTES);
+ joba.set((IppAttributeGroup) document.getAgroups().get(
+ new Integer(IppAttributeGroup.TAG_JOB_TEMPLATE_ATTRIBUTES)));
+ if (agset != null) {
+ joba.set((IppAttributeGroup) agset.get(new Integer(
+ IppAttributeGroup.TAG_JOB_TEMPLATE_ATTRIBUTES)));
+ }
+
+ response = c.request(request);
+
+ return response;
+ }
+
+ /*
+ * The method validate mimetypes.
+ * Returned array is the same as parameter,
+ * just with null in position of unsupported mimetypes.
+ * This method created for perfomance issue
+ */
+ public String[] requestGetSupportedMimeTypes(String[] mimetypes)
+ throws Exception {
+ IppClient c = new IppClient(printeruri);
+ IppRequest request;
+ IppResponse response;
+ IppAttributeGroup opa;
+
+ request = new IppRequest();
+ request.setVersion(1, 1);
+ request.setOperationId(IppOperation.VALIDATE_JOB);
+
+ opa = request.newGroup(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES);
+ opa.add(new IppAttribute(IppAttribute.TAG_CHARSET,
+ "attributes-charset", "utf-8"));
+ opa.add(new IppAttribute(IppAttribute.TAG_NATURAL_LANGUAGE,
+ "attributes-natural-language", "en-us"));
+ opa.add(new IppAttribute(IppAttribute.TAG_URI, "printer-uri",
+ printeruri.toString()));
+ opa.add(new IppAttribute(IppAttribute.TAG_NAMEWITHOUTLANGUAGE,
+ "requesting-user-name", (String) AccessController
+ .doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty("user.name");
+ }
+ })));
+ opa.add(new IppAttribute(IppAttribute.TAG_NAMEWITHOUTLANGUAGE,
+ "job-name", "validatemimetypes"));
+ opa.add(new IppAttribute(IppAttribute.TAG_NAMEWITHOUTLANGUAGE,
+ "document-name", "validatemimetypes"));
+ opa.add(new IppAttribute(IppAttribute.TAG_BOOLEAN,
+ "ipp-attribute-fidelity", 0x01));
+ opa.add(new IppAttribute(IppAttribute.TAG_MIMEMEDIATYPE,
+ "document-format", ""));
+
+ String[] validmimes = new String[mimetypes.length];
+ int mimeattrindex = opa.findAttribute("document-format");
+ for (int i = 0, ii = mimetypes.length; i < ii; i++) {
+ opa.set(mimeattrindex, new IppAttribute(
+ IppAttribute.TAG_MIMEMEDIATYPE, "document-format",
+ mimetypes[i]));
+
+ response = c.request(request);
+
+ if (response.getStatusCode() == 0) {
+ validmimes[i] = mimetypes[i];
+ } else {
+ validmimes[i] = null;
+ }
+ }
+
+ return validmimes;
+ }
+
+ public IppResponse requestPrintJob(String jobname, IppDocument document,
+ IppAttributeGroupSet agset) throws Exception {
+ IppClient c = new IppClient(printeruri);
+ IppRequest request;
+ IppResponse response;
+ IppAttributeGroup opa, joba;
+
+ request = new IppRequest();
+ request.setVersion(1, 1);
+ request.setOperationId(IppOperation.PRINT_JOB);
+
+ opa = request.newGroup(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES);
+ opa.add(new IppAttribute(IppAttribute.TAG_CHARSET,
+ "attributes-charset", "utf-8"));
+ opa.add(new IppAttribute(IppAttribute.TAG_NATURAL_LANGUAGE,
+ "attributes-natural-language", "en-us"));
+ opa.add(new IppAttribute(IppAttribute.TAG_URI, "printer-uri",
+ printeruri.toString()));
+ opa.add(new IppAttribute(IppAttribute.TAG_NAMEWITHOUTLANGUAGE,
+ "requesting-user-name", (String) AccessController
+ .doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty("user.name");
+ }
+ })));
+ opa.add(new IppAttribute(IppAttribute.TAG_NAMEWITHOUTLANGUAGE,
+ "job-name", jobname));
+ opa.add(new IppAttribute(IppAttribute.TAG_NAMEWITHOUTLANGUAGE,
+ "document-name", document.getName()));
+ opa.add(new IppAttribute(IppAttribute.TAG_MIMEMEDIATYPE,
+ "document-format", document.getFormat()));
+ opa.add(new IppAttribute(IppAttribute.TAG_BOOLEAN,
+ "ipp-attribute-fidelity", 0x01));
+ opa.set((IppAttributeGroup) document.getAgroups().get(
+ new Integer(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES)));
+
+ joba = request.newGroup(IppAttributeGroup.TAG_JOB_TEMPLATE_ATTRIBUTES);
+ joba.set((IppAttributeGroup) document.getAgroups().get(
+ new Integer(IppAttributeGroup.TAG_JOB_TEMPLATE_ATTRIBUTES)));
+ if (agset != null) {
+ joba.set((IppAttributeGroup) agset.get(new Integer(
+ IppAttributeGroup.TAG_JOB_TEMPLATE_ATTRIBUTES)));
+ }
+
+ request.setDocument(document.getDocument());
+
+ DoIppRequest job = new DoIppRequest(c, request);
+ response = job.getResponse();
+ if (job.exceptionOccured()) {
+ throw new IppException(job.getException().getMessage());
+ }
+
+ return response;
+ }
+
+ private class DoIppRequest extends Thread {
+ Object lock;
+ IppClient client;
+ IppRequest request;
+ IppResponse response;
+ Exception exception;
+ boolean exceptionisnotnull;
+ boolean requestisdone = false;
+
+ public DoIppRequest(IppClient ippclient, IppRequest ipprequest) {
+ this.client = ippclient;
+ this.request = ipprequest;
+ this.response = null;
+ this.exception = null;
+ this.exceptionisnotnull = false;
+ this.requestisdone = false;
+ lock = new Object();
+
+ start();
+ }
+
+ public void run() {
+ synchronized (lock) {
+ try {
+ response = client.request(request);
+ } catch (Exception e) {
+ if (verbose > 1) {
+ doVerbose(2,
+ "IppPrinter.java: run(): Exception thrown: "
+ + e.toString());
+ e.printStackTrace();
+ }
+ response = null;
+ exception = e;
+ exceptionisnotnull = true;
+ }
+
+ requestisdone = true;
+ lock.notifyAll();
+ }
+ }
+
+ /**
+ * Returns the deserialized object. This method will block until the
+ * object is actually available.
+ */
+ IppResponse getResponse() {
+ try {
+ synchronized (lock) {
+ if (requestisdone) {
+ return response;
+ }
+ lock.wait();
+ }
+ } catch (InterruptedException ie) {
+ if (verbose > 1) {
+ doVerbose(2,
+ "IppPrinter.java: getResponse(): Exception thrown: "
+ + ie.toString());
+ ie.printStackTrace();
+ }
+ return null;
+ }
+ return response;
+ }
+
+ boolean exceptionOccured() {
+ return exceptionisnotnull;
+ }
+
+ Exception getException() {
+ return exception;
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppPrinter.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppRequest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppRequest.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppRequest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppRequest.java Sun Oct 8 22:33:09 2006
@@ -0,0 +1,384 @@
+/*
+ * 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 org.apache.harmony.x.print.ipp;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * This class represents request encoding
+ * described in RFC 2910 (http://ietf.org/rfc/rfc2910.txt?number=2910)
+ */
+
+/*
+ *
+ * <pre>
+ *
+ *
+ * An operation request or response is encoded as follows:
+ *
+ * -----------------------------------------------
+ * | version-number | 2 bytes - required
+ * -----------------------------------------------
+ * | operation-id (request) |
+ * | or | 2 bytes - required
+ * | status-code (response) |
+ * -----------------------------------------------
+ * | request-id | 4 bytes - required
+ * -----------------------------------------------
+ * | attribute-group | n bytes - 0 or more
+ * -----------------------------------------------
+ * | end-of-attributes-tag | 1 byte - required
+ * -----------------------------------------------
+ * | data | q bytes - optional
+ * -----------------------------------------------
+ *
+ *
+ * </pre>
+ */
+public class IppRequest {
+ static int requestcount;
+
+ static protected void sortAttributes(Vector vaa) {
+ IppAttributeGroup g1, g2;
+ boolean the_end = false;
+
+ while (!the_end) {
+ the_end = true;
+ for (int ii = vaa.size(), i = 0; i < (ii - 1); i++) {
+ g1 = (IppAttributeGroup) vaa.get(i);
+ g2 = (IppAttributeGroup) vaa.get(i + 1);
+ if (g1.agroupid > g2.agroupid) {
+ the_end = false;
+ vaa.set(i, g2);
+ vaa.set(i + 1, g1);
+ }
+ }
+ }
+ }
+
+ protected byte[] ippversion = { 1, 1 };
+ protected short operationid;
+ protected int requestid;
+ protected IppAttributeGroupSet agroups;
+ protected Object document;
+
+ public IppRequest() {
+ requestid = ++requestcount;
+ agroups = new IppAttributeGroupSet();
+ }
+
+ public IppRequest(int version_major, int version_minor, short opid,
+ String charset, String natural_language) {
+ IppAttributeGroup agroup;
+
+ requestid = ++requestcount;
+ agroups = new IppAttributeGroupSet();
+
+ this.setVersion(version_major, version_minor);
+ this.setOperationId(opid);
+ agroup = this.newGroup(IppAttributeGroup.TAG_OPERATION_ATTRIBUTES);
+ agroup.add(new IppAttribute(IppAttribute.TAG_CHARSET,
+ "attributes-charset", charset));
+ agroup.add(new IppAttribute(IppAttribute.TAG_NATURAL_LANGUAGE,
+ "attributes-natural-language", natural_language));
+ }
+
+ public IppRequest(byte[] request) throws Exception {
+ ByteArrayInputStream ab = new ByteArrayInputStream(request);
+ DataInputStream ba = new DataInputStream(ab);
+
+ boolean the_end = false;
+ byte tag;
+ IppAttributeGroup agroup = null;
+ IppAttribute attr;
+ short name_length;
+ String name = "";
+ short value_length;
+ Vector value = new Vector();
+
+ agroups = new IppAttributeGroupSet();
+ ba.read(ippversion, 0, 2);
+ operationid = ba.readShort();
+ requestid = ba.readInt();
+
+ while (!the_end) {
+ tag = ba.readByte();
+ if (isAttributeGroupTag(tag)) {
+ switch (tag) {
+ case IppAttributeGroup.TAG_END_OF_ATTRIBUTES:
+ the_end = true;
+ continue;
+ case IppAttributeGroup.TAG_OPERATION_ATTRIBUTES:
+ case IppAttributeGroup.TAG_JOB_ATTRIBUTES:
+ case IppAttributeGroup.TAG_PRINTER_ATTRIBUTES:
+ case IppAttributeGroup.TAG_UNSUPPORTED_ATTRIBUTES:
+ default:
+ agroup = newGroup(tag, -1);
+ break;
+ }
+ } else {
+ name_length = ba.readShort();
+ byte[] bname = new byte[name_length];
+ if (name_length != 0) {
+ ba.read(bname, 0, name_length);
+ name = new String(bname);
+ value = new Vector();
+ attr = new IppAttribute(tag, name, value);
+ agroup.add(attr);
+ }
+ value_length = ba.readShort();
+
+ switch (tag) {
+ case IppAttribute.TAG_INTEGER:
+ value.add(new Integer(ba.readInt()));
+ break;
+ case IppAttribute.TAG_BOOLEAN:
+ value.add(new Integer(ba.readByte()));
+ break;
+ case IppAttribute.TAG_ENUM:
+ value.add(new Integer(ba.readInt()));
+ break;
+ case IppAttribute.TAG_OCTETSTRINGUNSPECIFIEDFORMAT:
+ case IppAttribute.TAG_DATETIME:
+ case IppAttribute.TAG_RESOLUTION:
+ case IppAttribute.TAG_RANGEOFINTEGER:
+ case IppAttribute.TAG_TEXTWITHLANGUAGE:
+ case IppAttribute.TAG_NAMEWITHLANGUAGE: {
+ byte[] b = new byte[value_length];
+ ba.read(b, 0, value_length);
+ value.add(b);
+ }
+ break;
+ case IppAttribute.TAG_TEXTWITHOUTLANGUAGE:
+ case IppAttribute.TAG_NAMEWITHOUTLANGUAGE:
+ case IppAttribute.TAG_KEYWORD:
+ case IppAttribute.TAG_URI:
+ case IppAttribute.TAG_URISCHEME:
+ case IppAttribute.TAG_CHARSET:
+ case IppAttribute.TAG_NATURAL_LANGUAGE:
+ case IppAttribute.TAG_MIMEMEDIATYPE:
+ case IppAttribute.TAG_UNSUPPORTED:
+ case IppAttribute.TAG_UNKNOWN:
+ case IppAttribute.TAG_NO_VALUE: {
+ byte[] b = new byte[value_length];
+ ba.read(b, 0, value_length);
+ value.add(b);
+ }
+ break;
+ default: {
+ byte[] b = new byte[value_length];
+ ba.read(b, 0, value_length);
+ value.add(b);
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ public static boolean isAttributeGroupTag(byte tag) {
+ return (tag < 0x10);
+ }
+
+ public void setVersion(int major, int minor) {
+ ippversion[0] = (byte) major;
+ ippversion[1] = (byte) minor;
+ }
+
+ public byte[] getVersion() {
+ return ippversion;
+ }
+
+ public void setOperationId(short opid) {
+ operationid = opid;
+ }
+
+ public short getOperationId() {
+ return operationid;
+ }
+
+ public short getStatusCode() {
+ return getOperationId();
+ }
+
+ public void setRequestId(int rid) {
+ requestid = rid;
+ }
+
+ public int getRequestId() {
+ return requestid;
+ }
+
+ public IppAttributeGroupSet getAgroups() {
+ return agroups;
+ }
+
+ public IppAttributeGroup newGroup(int agid) {
+ Vector v = (Vector) agroups.get(new Integer(agid));
+ IppAttributeGroup g = new IppAttributeGroup(agid);
+
+ if (v == null) {
+ v = new Vector();
+ agroups.put(new Integer(agid), v);
+ v.add(g);
+ } else {
+ v.set(0, g);
+ }
+
+ return g;
+ }
+
+ public IppAttributeGroup newGroup(int agid, int index) {
+ Vector v = (Vector) agroups.get(new Integer(agid));
+ IppAttributeGroup g = new IppAttributeGroup(agid);
+
+ if (v == null) {
+ v = new Vector();
+ agroups.put(new Integer(agid), v);
+ v.add(g);
+ } else {
+ if (index < 0) {
+ v.add(g);
+ } else {
+ v.set(index, g);
+ }
+ }
+
+ return g;
+ }
+
+ public Vector newGroupVector(int agid, Vector v) {
+ agroups.put(new Integer(agid), v);
+
+ return getGroupVector(agid);
+ }
+
+ public IppAttributeGroup getGroup(int agid) {
+ Vector v = (Vector) agroups.get(new Integer(agid));
+ if (v != null) {
+ return (IppAttributeGroup) v.get(0);
+ }
+ return null;
+ }
+
+ public IppAttributeGroup getGroup(int agid, int gid) {
+ Vector v = (Vector) agroups.get(new Integer(agid));
+ if (v != null) {
+ return (IppAttributeGroup) v.get(gid);
+ }
+ return null;
+ }
+
+ public Vector getGroupVector(int agid) {
+ return (Vector) agroups.get(new Integer(agid));
+ }
+
+ public void setDocument(Object data) throws IppException {
+ if (data instanceof InputStream || data instanceof byte[]
+ || data instanceof char[] || data instanceof String
+ || data instanceof Reader || data instanceof URL) {
+ this.document = data;
+ } else {
+ throw new IppException("Wrong type for IPP document");
+ }
+ }
+
+ public Object getDocument() {
+ return document;
+ }
+
+ public byte[] getBytes() throws Exception {
+ ByteArrayOutputStream ab = new ByteArrayOutputStream();
+ DataOutputStream ba;
+ Iterator ag = agroups.values().iterator();
+ IppAttributeGroup aa;
+ byte[] b;
+ Vector vaa = new Vector();
+
+ for (; ag.hasNext();) {
+ vaa.addAll((Vector) ag.next());
+ }
+ sortAttributes(vaa);
+
+ ba = new DataOutputStream(ab);
+
+ ba.write(ippversion);
+ ba.writeShort(operationid);
+ ba.writeInt(requestid);
+ for (int ii = vaa.size(), i = 0; i < ii; i++) {
+ aa = (IppAttributeGroup) vaa.get(i);
+ b = aa.getBytes();
+ ba.write(b);
+ }
+ ba.write(IppAttributeGroup.TAG_END_OF_ATTRIBUTES);
+ ba.flush();
+ ba.close();
+
+ return ab.toByteArray();
+ }
+
+ public String toString() {
+ ByteArrayOutputStream ab = new ByteArrayOutputStream();
+ DataOutputStream ba;
+ Iterator ag = agroups.values().iterator();
+ IppAttributeGroup aa;
+ String s;
+ Vector vaa = new Vector();
+
+ try {
+ for (; ag.hasNext();) {
+ vaa.addAll((Vector) ag.next());
+ }
+
+ ba = new DataOutputStream(ab);
+
+ ba.writeBytes("IPP version: " + ippversion[0] + "." + ippversion[1]
+ + "\n");
+ ba.writeBytes("Operation id/Status code: 0x"
+ + Integer.toHexString(operationid) + "\n");
+ ba.writeBytes("Request id: 0x" + Integer.toHexString(requestid)
+ + "\n");
+
+ for (int ii = vaa.size(), i = 0; i < ii; i++) {
+ aa = (IppAttributeGroup) vaa.get(i);
+ s = aa.toString();
+ ba.writeBytes(s + "\n");
+ }
+ ba.flush();
+ ba.close();
+ } catch (IOException e) {
+ // IGNORE exception
+ e.printStackTrace();
+ }
+
+ return ab.toString();
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppRequest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResources.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResources.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResources.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResources.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 org.apache.harmony.x.print.ipp;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class IppResources {
+ private static String IppStrings_BUNDLE_NAME;
+ private static ResourceBundle IppStrings_RESOURCE_BUNDLE;
+
+ static {
+ try {
+ IppStrings_BUNDLE_NAME = IppResources.class.getPackage().getName()
+ + ".resources.IppStrings";
+ IppStrings_RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(IppStrings_BUNDLE_NAME);
+ } catch (RuntimeException e) {
+ IppStrings_RESOURCE_BUNDLE = null;
+ }
+ }
+
+ public static String getString(String key) {
+ try {
+ if (IppStrings_RESOURCE_BUNDLE != null) {
+ return IppStrings_RESOURCE_BUNDLE.getString(key);
+ }
+ } catch (MissingResourceException e) {
+ return null;
+ }
+ return null;
+ }
+}
\ No newline at end of file
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResources.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResponse.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResponse.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResponse.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResponse.java Sun Oct 8 22:33:09 2006
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.harmony.x.print.ipp;
+
+public class IppResponse extends IppRequest {
+
+ public IppResponse() {
+ super();
+ }
+
+ public IppResponse(byte[] request) throws Exception {
+ super(request);
+ }
+}
\ No newline at end of file
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/IppResponse.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStatusCode.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStatusCode.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStatusCode.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStatusCode.java Sun Oct 8 22:33:09 2006
@@ -0,0 +1,116 @@
+/*
+ * 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.3 $
+ */
+
+package org.apache.harmony.x.print.ipp.resources;
+
+import java.util.ListResourceBundle;
+
+/** This class represents status codes
+ * described in RFC 2911 (http://ietf.org/rfc/rfc2911.txt?number=2911)
+ */
+
+public class IppStatusCode extends ListResourceBundle {
+
+ public Object[][] getContents() {
+ return statuscode;
+ }
+
+ /*
+ * The status code values range from 0x0000 to 0x7FFF. The value ranges for each status code class are as follows:
+ *
+ * "successful" - 0x0000 to 0x00FF
+ * "informational" - 0x0100 to 0x01FF
+ * "redirection" - 0x0200 to 0x02FF
+ * "client-error" - 0x0400 to 0x04FF
+ * "server-error" - 0x0500 to 0x05FF
+ *
+ * The top half (128 values) of each range (0x0n40 to 0x0nFF, for n = 0
+ * to 5) is reserved for vendor use within each status code class.
+ * Values 0x0600 to 0x7FFF are reserved for future assignment by IETF
+ * standards track documents and MUST NOT be used.
+ */
+ static final Object[][] statuscode = {
+ /*
+ * Informational
+ * This class of status code indicates a provisional response and is to be used
+ * for informational purposes only.
+ * There are no status codes defined in IPP/1.1 for this class of status code.
+ *
+ *
+ * Successful Status Codes
+ * This class of status code indicates that the client's request was
+ * successfully received, understood, and accepted.
+ */
+ { "successful-ok", new Integer(0x0000) },
+ { "successful-ok-ignored-or-substituted-attributes",
+ new Integer(0x0001) },
+ { "successful-ok-conflicting-attributes", new Integer(0x0002) },
+
+ /*
+ * Redirection Status Codes
+ * This class of status code indicates that further action needs to be taken to
+ * fulfill the request.
+ * There are no status codes defined in IPP/1.1 for this class of status code.
+ *
+ * Client Error Status Codes
+ * This class of status code is intended for cases in which the client seems to
+ * have erred. The IPP object SHOULD return a message containing an explanation of
+ * the error situation and whether it is a temporary or permanent condition.
+ */
+ { "client-error-bad-request", new Integer(0x0400) },
+ { "client-error-forbidden", new Integer(0x0401) },
+ { "client-error-not-authenticated", new Integer(0x0402) },
+ { "client-error-not-authorized", new Integer(0x0403) },
+ { "client-error-not-possible", new Integer(0x0404) },
+ { "client-error-timeout", new Integer(0x0405) },
+ { "client-error-not-found", new Integer(0x0406) },
+ { "client-error-gone", new Integer(0x0407) },
+ { "client-error-request-entity-too-large", new Integer(0x0408) },
+ { "client-error-request-value-too-long", new Integer(0x0409) },
+ { "client-error-document-format-not-supported", new Integer(0x040A) },
+ { "client-error-attributes-or-values-not-supported",
+ new Integer(0x040B) },
+ { "client-error-uri-scheme-not-supported", new Integer(0x040C) },
+ { "client-error-charset-not-supported", new Integer(0x040D) },
+ { "client-error-conflicting-attributes", new Integer(0x040E) },
+ { "client-error-compression-not-supported", new Integer(0x040F) },
+ { "client-error-compression-error", new Integer(0x0410) },
+ { "client-error-document-format-error", new Integer(0x0411) },
+ { "client-error-document-access-error", new Integer(0x0412) },
+
+ /*
+ * Server Error Status Codes
+ * This class of status codes indicates cases in which the IPP object is aware
+ * that it has erred or is incapable of performing the request. The IPP object
+ * SHOULD include a message containing an explanation of the error situation, and
+ * whether it is a temporary or permanent condition.
+ */
+ { "server-error-internal-error", new Integer(0x0500) },
+ { "server-error-operation-not-supported", new Integer(0x0501) },
+ { "server-error-service-unavailable", new Integer(0x0502) },
+ { "server-error-version-not-supported", new Integer(0x0503) },
+ { "server-error-device-error", new Integer(0x0504) },
+ { "server-error-temporary-error", new Integer(0x0505) },
+ { "server-error-not-accepting-jobs", new Integer(0x0506) },
+ { "server-error-busy", new Integer(0x0507) },
+ { "server-error-job-canceled", new Integer(0x0508) },
+ { "server-error-multiple-document-jobs-not-supported",
+ new Integer(0x0509) } };
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStatusCode.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStrings.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStrings.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStrings.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStrings.java Sun Oct 8 22:33:09 2006
@@ -0,0 +1,71 @@
+/*
+ * 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 org.apache.harmony.x.print.ipp.resources;
+
+import java.util.ListResourceBundle;
+
+/** This class contains messages that are used in IppOperation and related classes.
+ * Most of messages can be found in RFC 2911/2910/3380
+ * http://ietf.org/rfc/rfc2911.txt?number=2911
+ * http://ietf.org/rfc/rfc2910.txt?number=2910
+ * http://ietf.org/rfc/rfc3380.txt?number=3380
+ */
+
+public class IppStrings extends ListResourceBundle {
+
+ public Object[][] getContents() {
+ return strings;
+ }
+
+ static final Object[][] strings = { { "IppOperation.PRINT_JOB", "Print-Job" },
+ { "IppOperation.PRINT_URI", "Print-URI" },
+ { "IppOperation.VALIDATE_JOB", "Validate-Job" },
+ { "IppOperation.CREATE_JOB", "Create-Job" },
+ { "IppOperation.SEND_DOCUMENT", "Send-Document" },
+ { "IppOperation.SEND_URI", "Send-URI" },
+ { "IppOperation.CANCEL_JOB", "Cancel-Job" },
+ { "IppOperation.GET_JOB_ATTRIBUTES", "Get-Job-Attributes" },
+ { "IppOperation.GET_JOBS", "Get-Jobs" },
+ { "IppOperation.GET_PRINTER_ATTRIBUTES", "Get-Printer-Attributes" },
+ { "IppOperation.HOLD_JOB", "Hold-Job" },
+ { "IppOperation.RELEASE_JOB", "Release-Job" },
+ { "IppOperation.RESTART_JOB", "Restart-Job" },
+ { "IppOperation.RESERVED_FOR_A_FUTURE_OPERATION",
+ "reserved for a future operation" },
+ { "IppOperation.PAUSE_PRINTER", "Pause-Printer" },
+ { "IppOperation.RESUME_PRINTER", "Resume-Printer" },
+ { "IppOperation.PURGE_JOBS", "Purge-Jobs" },
+ { "IppOperation.TAG_CUPS_GET_DEFAULT", "CUPS Get default printer" },
+ { "IppOperation.TAG_CUPS_GET_PRINTERS", "CUPS Get all printers" },
+
+ { "IppAttributesGroup.OPERATION_ATTRIBUTES", "Operation Attributes" },
+ { "IppAttributesGroup.JOB_TEMPLATE_ATTRIBUTES",
+ "Job Template Attributes" },
+ { "IppAttributesGroup.JOB_OBJECT_ATTRIBUTES",
+ "Job Object Attributes" },
+ { "IppAttributesGroup.GET_JOB_ATTRIBUTES", "Get Job Attributes" },
+ { "IppAttributesGroup.GET_PRINTER_ATTRIBUTES",
+ "Get Printer Attributes" },
+ { "IppAttributesGroup.RESERVED", "Reserved For Future" },
+ { "IppAttributesGroup.END_OF_ATTRIBUTES", "end-of-attributes-tag" },
+ { "IppAttributesGroup.UNSUPPORTED_ATTRIBUTES",
+ "unsupported-attributes-tag" } };
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/resources/IppStrings.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/Ipp2Java.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/Ipp2Java.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/Ipp2Java.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/Ipp2Java.java Sun Oct 8 22:33:09 2006
@@ -0,0 +1,620 @@
+/*
+ * 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 org.apache.harmony.x.print.ipp.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Vector;
+
+import javax.print.attribute.Attribute;
+import javax.print.attribute.standard.ColorSupported;
+import javax.print.attribute.standard.Compression;
+import javax.print.attribute.standard.Copies;
+import javax.print.attribute.standard.CopiesSupported;
+import javax.print.attribute.standard.DocumentName;
+import javax.print.attribute.standard.Finishings;
+import javax.print.attribute.standard.JobHoldUntil;
+import javax.print.attribute.standard.JobImpressions;
+import javax.print.attribute.standard.JobImpressionsCompleted;
+import javax.print.attribute.standard.JobImpressionsSupported;
+import javax.print.attribute.standard.JobKOctets;
+import javax.print.attribute.standard.JobKOctetsProcessed;
+import javax.print.attribute.standard.JobKOctetsSupported;
+import javax.print.attribute.standard.JobMediaSheets;
+import javax.print.attribute.standard.JobMediaSheetsCompleted;
+import javax.print.attribute.standard.JobMediaSheetsSupported;
+import javax.print.attribute.standard.JobName;
+import javax.print.attribute.standard.JobPriority;
+import javax.print.attribute.standard.JobPrioritySupported;
+import javax.print.attribute.standard.JobSheets;
+import javax.print.attribute.standard.Media;
+import javax.print.attribute.standard.MediaName;
+import javax.print.attribute.standard.MediaSizeName;
+import javax.print.attribute.standard.MediaTray;
+import javax.print.attribute.standard.MultipleDocumentHandling;
+import javax.print.attribute.standard.NumberUp;
+import javax.print.attribute.standard.NumberUpSupported;
+import javax.print.attribute.standard.OrientationRequested;
+import javax.print.attribute.standard.PDLOverrideSupported;
+import javax.print.attribute.standard.PageRanges;
+import javax.print.attribute.standard.PagesPerMinute;
+import javax.print.attribute.standard.PagesPerMinuteColor;
+import javax.print.attribute.standard.PrintQuality;
+import javax.print.attribute.standard.PrinterInfo;
+import javax.print.attribute.standard.PrinterIsAcceptingJobs;
+import javax.print.attribute.standard.PrinterLocation;
+import javax.print.attribute.standard.PrinterMakeAndModel;
+import javax.print.attribute.standard.PrinterMessageFromOperator;
+import javax.print.attribute.standard.PrinterMoreInfo;
+import javax.print.attribute.standard.PrinterMoreInfoManufacturer;
+import javax.print.attribute.standard.PrinterName;
+import javax.print.attribute.standard.PrinterResolution;
+import javax.print.attribute.standard.PrinterState;
+import javax.print.attribute.standard.PrinterStateReason;
+import javax.print.attribute.standard.PrinterStateReasons;
+import javax.print.attribute.standard.PrinterURI;
+import javax.print.attribute.standard.QueuedJobCount;
+import javax.print.attribute.standard.ReferenceUriSchemesSupported;
+import javax.print.attribute.standard.RequestingUserName;
+import javax.print.attribute.standard.Severity;
+import javax.print.attribute.standard.Sides;
+
+import org.apache.harmony.x.print.attributes.PPDMediaSizeName;
+import org.apache.harmony.x.print.ipp.IppAttribute;
+import org.apache.harmony.x.print.ipp.IppDefs;
+
+
+/**
+ * This class make dependencies between Ipp attributes (RFC 2910) and corresponding classes
+ */
+
+public class Ipp2Java {
+ static Object[][] ipp2attr = { { "job-priority",
+ new JobPriority(1).getCategory() },
+ { "job-priority-default", new JobPriority(1).getCategory() },
+ { "job-priority-supported",
+ new JobPrioritySupported(1).getCategory() },
+ { "job-hold-until", new JobHoldUntil(new Date()).getCategory() },
+ { "job-hold-until-default",
+ new JobHoldUntil(new Date()).getCategory() },
+ { "job-hold-until-supported",
+ new JobHoldUntil(new Date()).getCategory() },
+ { "job-sheets", JobSheets.NONE.getCategory() },
+ { "job-sheets-default", JobSheets.NONE.getCategory() },
+ { "job-sheets-supported", JobSheets.NONE.getCategory() },
+ { "multiple-document-handling",
+ MultipleDocumentHandling.SINGLE_DOCUMENT.getCategory() },
+ { "multiple-document-handling-default",
+ MultipleDocumentHandling.SINGLE_DOCUMENT.getCategory() },
+ { "multiple-document-handling-supported",
+ MultipleDocumentHandling.SINGLE_DOCUMENT.getCategory() },
+ { "copies", new Copies(1).getCategory() },
+ { "copies-default", new Copies(1).getCategory() },
+ { "copies-supported", new CopiesSupported(1).getCategory() },
+ { "finishings", Finishings.NONE.getCategory() },
+ { "finishings-default", Finishings.NONE.getCategory() },
+ { "finishings-supported", Finishings.NONE.getCategory() },
+ { "page-ranges", new PageRanges(1).getCategory() },
+ // NO in RFC3380
+ // {"page-ranges-default", new PageRanges(1) },
+ { "page-ranges-supported", new PageRanges(1).getCategory() },
+ { "sides", Sides.ONE_SIDED.getCategory() },
+ { "sides-default", Sides.ONE_SIDED.getCategory() },
+ { "sides-supported", Sides.ONE_SIDED.getCategory() },
+ { "number-up", new NumberUp(1).getCategory() },
+ { "number-up-default", new NumberUp(1).getCategory() },
+ { "number-up-supported", new NumberUpSupported(1).getCategory() },
+ { "orientation-requested",
+ OrientationRequested.PORTRAIT.getCategory() },
+ { "orientation-requested-default",
+ OrientationRequested.PORTRAIT.getCategory() },
+ { "orientation-requested-supported",
+ OrientationRequested.PORTRAIT.getCategory() },
+
+ { "media", Media.class },
+ { "media-default", Media.class },
+ { "media-supported", Media.class },
+
+ { "printer-resolution",
+ new PrinterResolution(1, 1, 1).getCategory() },
+ { "printer-resolution-default",
+ new PrinterResolution(1, 1, 1).getCategory() },
+ { "printer-resolution-supported",
+ new PrinterResolution(1, 1, 1).getCategory() },
+ { "printer-uri-supported",
+ new PrinterURI(URI.create("http://localhost:631")).getCategory() },
+ { "printer-name",
+ new PrinterName("ipp-printer", Locale.US).getCategory() },
+ { "printer-location",
+ new PrinterLocation("Earth", Locale.US).getCategory() },
+ { "printer-make-and-model",
+ new PrinterMakeAndModel("ipp-printer", Locale.US).getCategory() },
+ { "printer-message-from-operator",
+ new PrinterMessageFromOperator("ipp-printer", Locale.US).getCategory() },
+ { "printer-more-info",
+ new PrinterMoreInfo(URI.create("http://localhost")).getCategory() },
+ { "printer-more-info-manufacturer",
+ new PrinterMoreInfoManufacturer(
+ URI.create("http://localhost")).getCategory() },
+ { "printer-info", new PrinterInfo("info", Locale.US).getCategory() },
+ { "print-quality", PrintQuality.NORMAL.getCategory() },
+ { "print-quality-default", PrintQuality.NORMAL.getCategory() },
+ { "print-quality-supported", PrintQuality.NORMAL.getCategory() },
+ { "color-supported", ColorSupported.SUPPORTED.getCategory() },
+ { "compression", Compression.NONE.getCategory() },
+ { "compression-supported", Compression.NONE.getCategory() },
+ { "job-k-octets", new JobKOctets(1).getCategory() },
+ { "job-k-octets-supported",
+ new JobKOctetsSupported(1, 2).getCategory() },
+ { "job-k-octets-processed ",
+ new JobKOctetsProcessed(1).getCategory() },
+ { "job-impressions", new JobImpressions(1).getCategory() },
+ { "job-impressions-supported",
+ new JobImpressionsSupported(1, 2).getCategory() },
+ { "job-impressions-completed",
+ new JobImpressionsCompleted(1).getCategory() },
+ { "job-media-sheets", new JobMediaSheets(1).getCategory() },
+ { "job-media-sheets-supported",
+ new JobMediaSheetsSupported(1, 2).getCategory() },
+ { "job-media-completed",
+ new JobMediaSheetsCompleted(1).getCategory() },
+ { "pdl-override-supported",
+ PDLOverrideSupported.ATTEMPTED.getCategory() },
+ { "reference-uri-schemes-supported",
+ ReferenceUriSchemesSupported.HTTP.getCategory() },
+ { "job-name", new JobName("jobname", Locale.US).getCategory() },
+ { "color-supported", ColorSupported.SUPPORTED.getCategory() },
+ { "printer-state", PrinterState.UNKNOWN.getCategory() },
+ { "printer-state-reasons", new PrinterStateReasons().getCategory() },
+ { "printer-is-accepting-jobs",
+ PrinterIsAcceptingJobs.ACCEPTING_JOBS.getCategory() },
+ { "queued-job-count", new QueuedJobCount(1).getCategory() },
+ { "requesting-user-name",
+ new RequestingUserName("username", Locale.US).getCategory() },
+ { "job-name", new JobName("jobname", Locale.US).getCategory() },
+ { "document-name",
+ new DocumentName("docname", Locale.US).getCategory() },
+ { "color-supported", ColorSupported.NOT_SUPPORTED.getCategory() },
+ { "pdl-override-supported",
+ PDLOverrideSupported.ATTEMPTED.getCategory() },
+ { "pages-per-minute", new PagesPerMinute(1).getCategory() },
+ { "pages-per-minute-color",
+ new PagesPerMinuteColor(1).getCategory() } };
+
+ public static Class getClassByIppAttributeName(String attribute) {
+ for (int i = 0, ii = ipp2attr.length; i < ii; i++) {
+ if (attribute.equals(ipp2attr[i][0])) {
+ return (Class) ipp2attr[i][1];
+ }
+ }
+ return null;
+ }
+
+ public static String getIppAttributeNameByClass(Class claz) {
+ return getIppAttributeNameByClass(claz, -1);
+ }
+
+ /**
+ * if ippsfx==-1 -> first found <br>
+ * if ippsfx==0 -> simple attr <br>
+ * if ippsfx==1 -> default attr <br>
+ * if ippsfx==2 -> supported attr <br>
+ */
+ public static String getIppAttributeNameByClass(Class claz, int ippsfx) {
+ String aname = null;
+
+ for (int i = 0, ii = ipp2attr.length; i < ii; i++) {
+ if (((Class) ipp2attr[i][1]).isAssignableFrom(claz)) {
+ aname = (String) ipp2attr[i][0];
+ if (ippsfx == -1) {
+ return aname;
+ } else if (ippsfx == 0 && !aname.endsWith("-default")
+ && !aname.endsWith("-supported")) {
+ return aname;
+ } else if (ippsfx == 1 && aname.endsWith("-default")) {
+ return aname;
+ } else if (ippsfx == 2 && aname.endsWith("-supported")) {
+ return aname;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static Object[] getJavaByIpp(IppAttribute attr) {
+ Vector attrx = new Vector();
+ Class claz;
+ String aname;
+ byte atag;
+ Vector avalue;
+ Attribute a = null;
+
+ aname = new String(attr.getName());
+ claz = getClassByIppAttributeName(aname);
+ atag = attr.getTag();
+ avalue = attr.getValue();
+
+ if (aname.equals("printer-state")
+ || aname.equals("printer-is-accepting-jobs")
+ || aname.equals("finishings")
+ || aname.equals("finishings-default")
+ || aname.equals("finishings-supported")
+ || aname.equals("orientation-requested")
+ || aname.equals("orientation-requested-default")
+ || aname.equals("orientation-requested-supported")
+ || aname.equals("color-supported")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = (Attribute) IppAttributeUtils.getObject(claz,
+ ((Integer) avalue.get(i)).intValue());
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("multiple-document-handling")
+ || aname.equals("multiple-document-handling-default")
+ || aname.equals("multiple-document-handling-supported")
+ || aname.equals("compression")
+ || aname.equals("compression-default")
+ || aname.equals("compression-supported")
+ || aname.equals("job-sheets")
+ || aname.equals("job-sheets-default")
+ || aname.equals("job-sheets-supported")
+ || aname.equals("pdl-override-supported")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ Object o = avalue.get(i);
+ a = (Attribute) IppAttributeUtils.getObject(claz, new String(
+ (byte[]) o));
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("printer-info")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ // TODO need to set locale corresponded to
+ // attributes-charset/attributes-natural-language
+ a = new PrinterInfo(new String((byte[]) avalue.get(i)),
+ Locale.US);
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("sides") || aname.equals("sides-default")
+ || aname.equals("sides-supported")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = (Attribute) IppAttributeUtils.getObject(claz, new String(
+ (byte[]) avalue.get(i)));
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ /* SPECIAL case for Sides* attributes
+ *
+ * CUPS returns "one", "two-long-edge", "two-short-edge"
+ * instead of "one-sided", "two-sided-long-edge", "two-sided-short-edge"
+ */
+ if (attrx.isEmpty() && avalue.size() > 0) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ String sz = new String((byte[]) avalue.get(i));
+ if (sz.indexOf("sided") == -1) {
+ int ind = sz.indexOf("-");
+ if (ind == -1) {
+ ind = sz.length();
+ }
+ sz = sz.substring(0, ind) + "-sided"
+ + sz.substring(ind);
+ }
+ a = (Attribute) IppAttributeUtils.getObject(claz, sz);
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ }
+ } else if (aname.equals("pages-per-minute")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = new PagesPerMinute(((Integer) avalue.get(i)).intValue());
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("pages-per-minute-color")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = new PagesPerMinuteColor(
+ ((Integer) avalue.get(i)).intValue());
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("job-priority")
+ || aname.equals("job-priority-default")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = new JobPriority(((Integer) avalue.get(i)).intValue());
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("job-priority-supported")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = new JobPrioritySupported(
+ ((Integer) avalue.get(i)).intValue());
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("queued-job-count")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = new QueuedJobCount(((Integer) avalue.get(i)).intValue());
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("printer-state-reason")
+ || aname.equals("printer-state-reasons")) {
+ PrinterStateReasons rs = new PrinterStateReasons();
+ String r;
+ Severity s;
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ r = new String((byte[]) avalue.get(i));
+ if (r.endsWith("-error")) {
+ r = r.substring(0, r.indexOf("-error"));
+ s = Severity.ERROR;
+ } else if (r.endsWith("-warning")) {
+ r = r.substring(0, r.indexOf("-warning"));
+ s = Severity.WARNING;
+ } else if (r.endsWith("-report")) {
+ r = r.substring(0, r.indexOf("-report"));
+ s = Severity.WARNING;
+ } else {
+ s = Severity.ERROR;
+ }
+ a = (Attribute) IppAttributeUtils.getObject(
+ PrinterStateReason.class, r);
+ if (a != null) {
+ rs.put(a, s);
+ }
+ }
+ if (rs.size() > 0) {
+ attrx.add(rs);
+ }
+ } else if (aname.equals("copies") || aname.equals("copies-default")
+ || aname.equals("copies-supported")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ if (atag == IppAttribute.TAG_RANGEOFINTEGER) {
+ DataInputStream di = new DataInputStream(
+ new ByteArrayInputStream((byte[]) avalue.get(i)));
+ try {
+ a = new CopiesSupported(di.readInt(), di.readInt());
+ } catch (IOException e) {
+ // IGNORE exception
+ a = null;
+ e.printStackTrace();
+ }
+ } else if (atag == IppAttribute.TAG_INTEGER) {
+ a = new Copies(((Integer) avalue.get(i)).intValue());
+ }
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("page-ranges-supported")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = new PageRanges(((Integer) avalue.get(i)).intValue());
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("number-up")
+ || aname.equals("number-up-default")
+ || aname.equals("number-up-supported")) {
+ Vector v = new Vector();
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ if (atag == IppAttribute.TAG_INTEGER) {
+ v.add(new int[] { ((Integer) avalue.get(i)).intValue() });
+ } else if (atag == IppAttribute.TAG_RANGEOFINTEGER) {
+ DataInputStream di = new DataInputStream(
+ new ByteArrayInputStream((byte[]) avalue.get(i)));
+ try {
+ v.add(new int[] { di.readInt(), di.readInt() });
+ } catch (IOException e) {
+ // IGNORE exception
+ e.printStackTrace();
+ }
+ }
+ }
+ int[][] x = new int[v.size()][];
+ for (int j = 0, jj = v.size(); j < jj; j++) {
+ x[j] = (int[]) v.get(j);
+ }
+ a = new NumberUpSupported(x);
+ if (a != null) {
+ attrx.add(a);
+ }
+ } else if (aname.equals("job-hold-until")
+ || aname.equals("job-hold-until-default")
+ || aname.equals("job-hold-until-supported")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = new JobHoldUntil(new Date(0L));
+ if (a != null) {
+ attrx.add(a);
+ break;
+ }
+ }
+ } else if (aname.equals("media-supported")
+ || aname.equals("media-default") || aname.equals("media")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ a = (Attribute) IppAttributeUtils.getObject(
+ MediaSizeName.class, new String((byte[]) avalue.get(i)));
+ if (a != null) {
+ attrx.add(a);
+ }
+ a = (Attribute) IppAttributeUtils.getObject(MediaTray.class,
+ new String((byte[]) avalue.get(i)));
+ if (a != null) {
+ attrx.add(a);
+ }
+ a = (Attribute) IppAttributeUtils.getObject(MediaName.class,
+ new String((byte[]) avalue.get(i)));
+ if (a != null) {
+ attrx.add(a);
+ }
+ a = (Attribute) IppAttributeUtils.getObject(
+ PPDMediaSizeName.class, new String(
+ (byte[]) avalue.get(i)));
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("printer-uri-supported")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ try {
+ a = new PrinterURI(new URI(new String(
+ (byte[]) avalue.get(i))));
+ if (a != null) {
+ attrx.add(a);
+ }
+ } catch (URISyntaxException e) {
+ // IGNORE exception for bad URI
+ e.printStackTrace();
+ }
+ }
+ } else if (aname.equals("printer-name")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ // TODO need to set locale corresponded to
+ // attributes-charset/attributes-natural-language
+ a = new PrinterName(new String((byte[]) avalue.get(i)),
+ Locale.US);
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("printer-make-and-model")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ // TODO need to set locale corresponded to
+ // attributes-charset/attributes-natural-language
+ a = new PrinterMakeAndModel(new String((byte[]) avalue.get(i)),
+ Locale.US);
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("printer-location")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ // TODO need to set locale corresponded to
+ // attributes-charset/attributes-natural-language
+ a = new PrinterLocation(new String((byte[]) avalue.get(i)),
+ Locale.US);
+ if (a != null) {
+ attrx.add(a);
+ }
+ }
+ } else if (aname.equals("printer-more-info")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ try {
+ a = new PrinterMoreInfo(new URI(new String(
+ (byte[]) avalue.get(i))));
+ if (a != null) {
+ attrx.add(a);
+ }
+ } catch (URISyntaxException e) {
+ // IGNORE exception for bad URI
+ e.printStackTrace();
+ }
+ }
+ } else if (aname.equals("printer-more-info-manufacturer")) {
+ for (int i = 0, ii = avalue.size(); i < ii; i++) {
+ try {
+ a = new PrinterMoreInfoManufacturer(new URI(new String(
+ (byte[]) avalue.get(i))));
+ if (a != null) {
+ attrx.add(a);
+ }
+ } catch (URISyntaxException e) {
+ // IGNORE exception for bad URI
+ e.printStackTrace();
+ }
+ }
+ } else if (aname.equals("printer-up-time")
+ || aname.equals("printer-state-time")
+ || aname.equals("printer-current-time")
+ || aname.equals("uri-security-supported")
+ || aname.equals("operations-supported")
+ || aname.equals("charset-configured")
+ || aname.equals("charset-supported")
+ || aname.equals("natural-language-configured")
+ || aname.equals("generated-natural-language-supported")
+ || aname.equals("document-format-default")
+ || aname.equals("document-format-supported")
+ || aname.equals("printer-state-message")
+ || aname.equals("printer-state-message-default")
+ || aname.equals("printer-state-message-supported")
+ || aname.equals("ipp-versions-supported")
+ || aname.equals("uri-authentication-supported")
+ || aname.equals("job-quota-period")
+ || aname.equals("job-k-limit")
+ || aname.equals("job-page-limit") || aname.equals("device-uri")
+ || aname.equals("printer-type")
+ || aname.equals("multiple-document-jobs-supported")
+ || aname.equals("multiple-operation-time-out")
+ || aname.equals("printer-state-history")
+ || aname.equals("media-ready")
+ || aname.equals("output-bin-supported")) {
+ // IGNORE - no such java-attributes
+ } else {
+ // TODO need to implement other attributes
+ System.err.println("Not yet implemented: " + aname);
+ }
+
+ return attrx.toArray();
+ }
+
+ public static IppAttribute getIppByJava(Attribute attr) {
+ IppAttribute a = null;
+ String aname = getIppAttributeNameByClass(attr.getClass());
+ byte vtag;
+
+ if (aname != null) {
+ vtag = IppDefs.getAttributeVtag(aname);
+
+ if (vtag != -1) {
+ Object o = IppAttributeUtils.getIppValue(attr, vtag);
+ if (o != null) {
+ if (o instanceof Integer) {
+ a = new IppAttribute(vtag, aname,
+ ((Integer) o).intValue());
+ } else if (o instanceof String) {
+ a = new IppAttribute(vtag, aname, (String) o);
+ } else if (o instanceof byte[]) {
+ a = new IppAttribute(vtag, aname, (byte[]) o);
+ } else if (o instanceof Vector) {
+ a = new IppAttribute(vtag, aname, (Vector) o);
+ }
+ }
+ }
+ }
+
+ return a;
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/Ipp2Java.java
------------------------------------------------------------------------------
svn:executable = *