<%
int severity=0;
StringBuffer errors = new StringBuffer();
Entry[] entries = (Entry[] )pageContext.getAttribute("entries");
if(entries==null) {
	severity=4;
	errors.append("out of service");
}
for(int i=0; entries!=null && i<entries.length; i++) {

        Entry entry = entries[i];
if(!(entry instanceof net.jini.print.lookup.AttributeEntry)) continue;
AttributeEntry attrE = (AttributeEntry )entry;
Attribute attr = attrE.value;
if(severity<1) {
    if(attr instanceof PrinterState) {
        PrinterState state = (PrinterState )attr;
        if(state.equals(PrinterState.IDLE)) {
                                severity=1;
                                errors.append(state+"·");
                        }
    }
    if(attr instanceof PrinterStateReasons) {
        PrinterStateReasons reasons = (PrinterStateReasons )attr;
        if(reasons.printerStateReasonSet(Severity.REPORT).size()>0) {
                                severity=1;
                                errors.append("info="+reasons.printerStateReasonSet(Severity.REPORT)+"·");
                        }
    }
}
if(severity<2) {
    if(attr instanceof PrinterState) {
        PrinterState state = (PrinterState )attr;
        if(state.equals(PrinterState.PROCESSING)) {
                                severity=2;
                                errors.append(state+"·");
                        }
    }
}
if(severity<3) {
    if(attr instanceof PrinterStateReasons) {
        PrinterStateReasons reasons = (PrinterStateReasons )attr;
        if(reasons.printerStateReasonSet(Severity.WARNING).size()>0) {
                                severity=3;
                                errors.append("warning="+reasons.printerStateReasonSet(Severity.WARNING)+"·");
                        }
    }
}
if(severity<4) {
    if(attr instanceof PrinterState) {
        PrinterState state = (PrinterState )attr;
        if(state.equals(PrinterState.STOPPED)) {
                                severity=4;
                                errors.append(state+"\n");
                        }
    }
    if(attr instanceof PrinterStateReasons) {
        PrinterStateReasons reasons = (PrinterStateReasons )attr;
        if(reasons.printerStateReasonSet(Severity.ERROR).size()>0) {
                                severity=4;
                                errors.append("error="+reasons.printerStateReasonSet(Severity.ERROR)+"·");
                        }
    }
}
}
        String color = "black";
        switch(severity) {
        case 1: color="lime"; break;
        case 2: color="green"; break;
        case 3: color="yellow"; break;
        case 4: color="red"; break;
        }
        pageContext.setAttribute("color", color);
        pageContext.setAttribute("errors", errors+"");
%>
