001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Igor A. Pyankov
019: * @version $Revision: 1.2 $
020: */package org.apache.harmony.x.print.ipp;
021:
022: import java.io.InputStream;
023: import java.io.Reader;
024: import java.net.URL;
025: import java.security.AccessController;
026: import java.security.PrivilegedAction;
027:
028: import org.apache.harmony.x.print.ipp.util.IppMimeType;
029:
030: public class IppDocument {
031: static int doccount;
032:
033: protected String docname;
034: protected String format; /* MIME type */
035: protected Object document; /* String or DataInputStream */
036: protected IppAttributeGroupSet agroups; /* all attributes as in IppRequest */
037:
038: public IppDocument(String name, String mime, Object data)
039: throws IppException {
040: if (data != null
041: && mime != null
042: && (data instanceof InputStream
043: || data instanceof byte[]
044: || data instanceof char[]
045: || data instanceof String
046: || data instanceof Reader || data instanceof URL)) {
047: this .document = data;
048: this .format = new IppMimeType(mime).getIppSpecificForm();
049:
050: if (name == null || name.equals("")) {
051: this .docname = new String((String) AccessController
052: .doPrivileged(new PrivilegedAction() {
053: public Object run() {
054: return System.getProperty("user.name");
055: }
056: })
057: + "-" + doccount);
058: } else {
059: this .docname = name;
060: }
061:
062: this .agroups = new IppAttributeGroupSet();
063: } else {
064: throw new IppException("Wrong argument(s) for IPP document");
065: }
066: }
067:
068: public IppAttributeGroupSet getAgroups() {
069: return agroups;
070: }
071:
072: public void setAgroups(IppAttributeGroupSet attrgroups) {
073: this .agroups = attrgroups;
074: }
075:
076: public String getName() {
077: return docname;
078: }
079:
080: public void setName(String name) {
081: this .docname = name;
082: }
083:
084: public Object getDocument() {
085: return document;
086: }
087:
088: public void setDocument(Object data) throws IppException {
089: if (data instanceof InputStream || data instanceof byte[]
090: || data instanceof char[] || data instanceof String
091: || data instanceof Reader || data instanceof URL) {
092: this .document = data;
093: } else {
094: throw new IppException("Wrong type for IPP document");
095: }
096: }
097:
098: public String getFormat() {
099: return format;
100: }
101:
102: public void setFormat(String mime) {
103: this .format = new IppMimeType(mime).getIppSpecificForm();
104: }
105:
106: public boolean setAttribute(String aname, int avalue) {
107: return setAttribute(aname, new Integer(avalue));
108: }
109:
110: public boolean setAttribute(String aname, String avalue) {
111: return setAttribute(aname, (Object) avalue);
112: }
113:
114: public boolean setAttribute(String aname, Object avalue) {
115: return agroups.setAttribute(aname, avalue);
116: }
117:
118: }
|