Refine search
public String render(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); write(wr, locale); return out.toString(); }
/** * Write out a string literal or attribute expression or expression element. * <p> * If doing line wrap, then check {@code wrap} before emitting {@code str}. * If at or beyond desired line width then emit a {@link #newline} and any * indentation before spitting out {@code str}.</p> */ @Override public int write(String str, String wrap) throws IOException { int n = writeWrap(wrap); return n + write(str); }
protected String toString(STWriter out, ST self, Object value) { if ( value!=null ) { if ( value.getClass()==String.class ) return (String)value; // if not string already, must evaluate it StringWriter sw = new StringWriter(); STWriter stw = null; try { Class writerClass = out.getClass(); Constructor ctor = writerClass.getConstructor(new Class[] {Writer.class}); stw = (STWriter)ctor.newInstance(sw); } catch (Exception e) { stw = new AutoIndentWriter(sw); errMgr.runTimeError(this, self, current_ip, ErrorType.WRITER_CTOR_ISSUE, out.getClass().getSimpleName()); } writeObjectNoOptions(stw, self, value); return sw.toString(); } return null; }
public List<InterpEvent> getEvents(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); Interpreter interp = new Interpreter(groupThatCreatedThisInstance, locale, true); interp.exec(wr, this); // render and track events return interp.getEvents(); }
public int write(File outputFile, STErrorListener listener, String encoding, Locale locale, int lineWidth) throws IOException { Writer bw = null; try { FileOutputStream fos = new FileOutputStream(outputFile); OutputStreamWriter osw = new OutputStreamWriter(fos, encoding); bw = new BufferedWriter(osw); AutoIndentWriter w = new AutoIndentWriter(bw); w.setLineWidth(lineWidth); int n = write(w, locale, listener); bw.close(); bw = null; return n; } finally { if (bw != null) bw.close(); } }
public void write(ST code, String fileName) throws IOException { //long start = System.currentTimeMillis(); Writer w = tool.getOutputFile(grammar, fileName); // Write the output to a StringWriter STWriter wr = new AutoIndentWriter(w); wr.setLineWidth(lineWidth); code.write(wr); w.close(); //long stop = System.currentTimeMillis(); //System.out.println("render time for "+fileName+": "+(int)(stop-start)+"ms"); }
ST template = group.getInstanceOf("YourTemplate"); OutputStreamWriter osWriter = new OutputStreamWriter(stream); STWriter stWriter = new AutoIndentWriter(osWriter); template.write(stWriter); osWriter.flush();
@Override public int writeSeparator(String str) throws IOException { return write(str); }
protected String toString(STWriter out, InstanceScope scope, Object value) { if ( value!=null ) { if ( value.getClass()==String.class ) return (String)value; // if not string already, must evaluate it StringWriter sw = new StringWriter(); STWriter stw; try { Class<? extends STWriter> writerClass = out.getClass(); Constructor<? extends STWriter> ctor = writerClass.getConstructor(Writer.class); stw = ctor.newInstance(sw); } catch (Exception e) { stw = new AutoIndentWriter(sw); errMgr.runTimeError(this, scope, ErrorType.WRITER_CTOR_ISSUE, out.getClass().getSimpleName()); } if (debug && !scope.earlyEval) { scope = new InstanceScope(scope, scope.st); scope.earlyEval = true; } writeObjectNoOptions(stw, scope, value); return sw.toString(); } return null; }
public List<InterpEvent> getEvents(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); Interpreter interp = new Interpreter(groupThatCreatedThisInstance, locale, true); InstanceScope scope = new InstanceScope(null, this); interp.exec(wr, scope); // render and track events return interp.getEvents(); }
public int write(File outputFile, STErrorListener listener, String encoding, Locale locale, int lineWidth) throws IOException { Writer bw = null; try { FileOutputStream fos = new FileOutputStream(outputFile); OutputStreamWriter osw = new OutputStreamWriter(fos, encoding); bw = new BufferedWriter(osw); AutoIndentWriter w = new AutoIndentWriter(bw); w.setLineWidth(lineWidth); int n = write(w, locale, listener); bw.close(); bw = null; return n; } finally { if (bw != null) bw.close(); } }
public void write(ST code, String fileName) throws IOException { //long start = System.currentTimeMillis(); Writer w = tool.getOutputFile(grammar, fileName); // Write the output to a StringWriter STWriter wr = new AutoIndentWriter(w); wr.setLineWidth(lineWidth); code.write(wr); w.close(); //long stop = System.currentTimeMillis(); //System.out.println("render time for "+fileName+": "+(int)(stop-start)+"ms"); }
template.write(new AutoIndentWriter(writer), Locale.US);
@Override public int writeSeparator(String str) throws IOException { return write(str); }
public String render(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); write(wr, locale); return out.toString(); }
protected String toString(STWriter out, InstanceScope scope, Object value) { if ( value!=null ) { if ( value.getClass()==String.class ) return (String)value; // if not string already, must evaluate it StringWriter sw = new StringWriter(); STWriter stw; try { Class<? extends STWriter> writerClass = out.getClass(); Constructor<? extends STWriter> ctor = writerClass.getConstructor(Writer.class); stw = ctor.newInstance(sw); } catch (Exception e) { stw = new AutoIndentWriter(sw); errMgr.runTimeError(this, scope, ErrorType.WRITER_CTOR_ISSUE, out.getClass().getSimpleName()); } if (debug && !scope.earlyEval) { scope = new InstanceScope(scope, scope.st); scope.earlyEval = true; } writeObjectNoOptions(stw, scope, value); return sw.toString(); } return null; }
public List<InterpEvent> getEvents(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); Interpreter interp = new Interpreter(groupThatCreatedThisInstance, locale, true); InstanceScope scope = new InstanceScope(null, this); interp.exec(wr, scope); // render and track events return interp.getEvents(); }