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)
| 713 | */ |
| 714 | |
| 715 | protected int writeObject(STWriter out, InstanceScope scope, Object o, String[] options) { |
| 716 | int n = 0; |
| 717 | if ( o==null ) { |
| 718 | if ( options !=null && options[Option.NULL.ordinal()]!=null ) { |
| 719 | o = options[Option.NULL.ordinal()]; |
| 720 | } |
| 721 | else return 0; |
| 722 | } |
| 723 | if ( o instanceof ST) { |
| 724 | scope = new InstanceScope(scope, (ST)o); |
| 725 | if ( options !=null && options[Option.WRAP.ordinal()]!=null ) { |
| 726 | // if we have a wrap string, then inform writer it |
| 727 | // might need to wrap |
| 728 | try { |
| 729 | out.writeWrap(options[Option.WRAP.ordinal()]); |
| 730 | } |
| 731 | catch (IOException ioe) { |
| 732 | errMgr.IOError(scope.st, ErrorType.WRITE_IO_ERROR, ioe); |
| 733 | } |
| 734 | } |
| 735 | n = exec(out, scope); |
| 736 | } |
| 737 | else { |
| 738 | o = convertAnythingIteratableToIterator(scope, o); // normalize |
| 739 | try { |
| 740 | if ( o instanceof Iterator) n = writeIterator(out, scope, o, options); |
| 741 | else n = writePOJO(out, scope, o, options); |
| 742 | } |
| 743 | catch (IOException ioe) { |
| 744 | errMgr.IOError(scope.st, ErrorType.WRITE_IO_ERROR, ioe, o); |
| 745 | } |
| 746 | } |
| 747 | return n; |
| 748 | } |
| 749 | |
| 750 | protected int writeIterator(STWriter out, InstanceScope scope, Object o, String[] options) throws IOException { |
| 751 | if ( o==null ) return 0; |
no test coverage detected