Generic method to emit text for an object. It differentiates between templates, iterable objects, and plain old Java objects (POJOs)
(STWriter out, InstanceScope scope, Object o, String[] options)
| 680 | */ |
| 681 | |
| 682 | protected int writeObject(STWriter out, InstanceScope scope, Object o, String[] options) { |
| 683 | int n = 0; |
| 684 | if ( o==null ) { |
| 685 | if ( options!=null && options[Option.NULL.ordinal()] !=null ) { |
| 686 | o = options[Option.NULL.ordinal()]; |
| 687 | } |
| 688 | else return 0; |
| 689 | } |
| 690 | if ( o instanceof ST ) { |
| 691 | scope = new InstanceScope(scope, (ST)o); |
| 692 | if ( options!=null && options[Option.WRAP.ordinal()] !=null ) { |
| 693 | // if we have a wrap string, then inform writer it |
| 694 | // might need to wrap |
| 695 | try { |
| 696 | out.writeWrap(options[Option.WRAP.ordinal()]); |
| 697 | } |
| 698 | catch (IOException ioe) { |
| 699 | errMgr.IOError(scope.st, ErrorType.WRITE_IO_ERROR, ioe); |
| 700 | } |
| 701 | } |
| 702 | n = exec(out, scope); |
| 703 | } |
| 704 | else { |
| 705 | o = convertAnythingIteratableToIterator(scope, o); // normalize |
| 706 | try { |
| 707 | if ( o instanceof Iterator ) n = writeIterator(out, scope, o, options); |
| 708 | else n = writePOJO(out, scope, o, options); |
| 709 | } |
| 710 | catch (IOException ioe) { |
| 711 | errMgr.IOError(scope.st, ErrorType.WRITE_IO_ERROR, ioe, o); |
| 712 | } |
| 713 | } |
| 714 | return n; |
| 715 | } |
| 716 | |
| 717 | protected int writeIterator(STWriter out, InstanceScope scope, Object o, String[] options) throws IOException { |
| 718 | if ( o==null ) return 0; |
no test coverage detected