jobNameAttr = null;
userNameAttr = null;
destinationAttr = null;
collateAttReq = false;
PrintService service = getPrintService();
if (attributes == null || service == null) {
return;
}
boolean fidelity = false;
Fidelity attrFidelity = (Fidelity)attributes.get(Fidelity.class);
if (attrFidelity != null && attrFidelity == Fidelity.FIDELITY_TRUE) {
fidelity = true;
}
if (fidelity == true) {
AttributeSet unsupported =
service.getUnsupportedAttributes(
DocFlavor.SERVICE_FORMATTED.PAGEABLE,
attributes);
if (unsupported != null) {
throw new PrinterException("Fidelity cannot be satisfied");
}
}
/*
* Since we have verified supported values if fidelity is true,
* we can either ignore unsupported values, or substitute a
* reasonable alternative
*/
SheetCollate collateAttr =
(SheetCollate)attributes.get(SheetCollate.class);
if (isSupportedValue(collateAttr, attributes)) {
setCollated(collateAttr == SheetCollate.COLLATED);
}
sidesAttr = (Sides)attributes.get(Sides.class);
if (!isSupportedValue(sidesAttr, attributes)) {
sidesAttr = Sides.ONE_SIDED;
}
pageRangesAttr = (PageRanges)attributes.get(PageRanges.class);
if (!isSupportedValue(pageRangesAttr, attributes)) {
pageRangesAttr = null;
} else {
if ((SunPageSelection)attributes.get(SunPageSelection.class)
== SunPageSelection.RANGE) {
// get to, from, min, max page ranges
int[][] range = pageRangesAttr.getMembers();
// setPageRanges uses 0-based indexing so we subtract 1
setPageRange(range[0][0] - 1, range[0][1] - 1);
} else {
setPageRange(-1, - 1);
}
}
Copies copies = (Copies)attributes.get(Copies.class);
if (isSupportedValue(copies, attributes) ||
(!fidelity && copies != null)) {
copiesAttr = copies.getValue();
setCopies(copiesAttr);
} else {
copiesAttr = getCopies();
}
Destination destination =
(Destination)attributes.get(Destination.class);
if (isSupportedValue(destination, attributes)) {
try {
// Old code (new File(destination.getURI())).getPath()
// would generate a "URI is not hierarchical" IAE
// for "file:out.prn" so we use getSchemeSpecificPart instead
destinationAttr = "" + new File(destination.getURI().
getSchemeSpecificPart());
} catch (Exception e) { // paranoid exception
Destination defaultDest = (Destination)service.
getDefaultAttributeValue(Destination.class);
if (defaultDest != null) {
destinationAttr = "" + new File(defaultDest.getURI().
getSchemeSpecificPart());
}
}
}
JobSheets jobSheets = (JobSheets)attributes.get(JobSheets.class);
if (jobSheets != null) {
noJobSheet = jobSheets == JobSheets.NONE;
}
JobName jobName = (JobName)attributes.get(JobName.class);
if (isSupportedValue(jobName, attributes) ||
(!fidelity && jobName != null)) {
jobNameAttr = jobName.getValue();
setJobName(jobNameAttr);
} else {
jobNameAttr = getJobName();
}
RequestingUserName userName =
(RequestingUserName)attributes.get(RequestingUserName.class);
if (isSupportedValue(userName, attributes) ||
(!fidelity && userName != null)) {
userNameAttr = userName.getValue();
} else {
try {
userNameAttr = getUserName();
} catch (SecurityException e) {
userNameAttr = "";
}
}
/* OpenBook is used internally only when app uses Printable.
* This is the case when we use the values from the attribute set.
*/
Media media = (Media)attributes.get(Media.class);
OrientationRequested orientReq =
(OrientationRequested)attributes.get(OrientationRequested.class);
MediaPrintableArea mpa =
(MediaPrintableArea)attributes.get(MediaPrintableArea.class);
if ((orientReq != null || media != null || mpa != null) &&
getPageable() instanceof OpenBook) {
/* We could almost(!) use PrinterJob.getPageFormat() except
* here we need to start with the PageFormat from the OpenBook :
*/
Pageable pageable = getPageable();
Printable printable = pageable.getPrintable(0);
PageFormat pf = (PageFormat)pageable.getPageFormat(0).clone();
Paper paper = pf.getPaper();
/* If there's a media but no media printable area, we can try
* to retrieve the default value for mpa and use that.
*/
if (mpa == null && media != null &&
service.
isAttributeCategorySupported(MediaPrintableArea.class)) {
Object mpaVals = service.
getSupportedAttributeValues(MediaPrintableArea.class,
null, attributes);
if (mpaVals instanceof MediaPrintableArea[] &&
((MediaPrintableArea[])mpaVals).length > 0) {
mpa = ((MediaPrintableArea[])mpaVals)[0];