public void testTrim() throws Exception { TextScript script = new TextScript( " foo " ); script.trimWhitespace(); assertEquals( "foo", script.getText() ); script = new TextScript( " foo " ); script.trimWhitespace(); assertEquals( "foo", script.getText() ); script = new TextScript( "foo" ); script.trimWhitespace(); assertEquals( "foo", script.getText() ); }
public void testTrimEnd() throws Exception { TextScript script = new TextScript( " foo " ); script.trimEndWhitespace(); assertEquals( " foo", script.getText() ); script = new TextScript( " foo " ); script.trimEndWhitespace(); assertEquals( " foo", script.getText() ); script = new TextScript( "foo" ); script.trimEndWhitespace(); assertEquals( "foo", script.getText() ); } }
public void testTrimStart() throws Exception { TextScript script = new TextScript( " foo " ); script.trimStartWhitespace(); assertEquals( "foo ", script.getText() ); script = new TextScript( " foo " ); script.trimStartWhitespace(); assertEquals( "foo ", script.getText() ); script = new TextScript( "foo" ); script.trimStartWhitespace(); assertEquals( "foo", script.getText() ); }
/** * Trim the body of the script. * In this case, trim the whitespace from the start of the first element * and from the end of the last element. */ public void trimWhitespace() { List list = getScriptList(); int size = list.size(); if ( size > 0 ) { Script script = (Script) list.get(0); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimStartWhitespace(); } if ( size > 1 ) { script = (Script) list.get(size - 1); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimEndWhitespace(); } } } }
/** * Trim the body of the script. * In this case, trim all elements, removing any that are empty text. */ public void trimWhitespace() { List list = getScriptList(); for ( int i = list.size() - 1; i >= 0; i-- ) { Script script = (Script) list.get(i); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; String text = textScript.getText(); text = text.trim(); if ( text.length() == 0 ) { list.remove(i); } else { textScript.setText(text); } } } } }
/** * Adds the given Expression object to the current Script. */ protected void addExpressionScript(ScriptBlock script, Expression expression) { if ( expression instanceof ConstantExpression ) { ConstantExpression constantExpression = (ConstantExpression) expression; Object value = constantExpression.getValue(); if ( value != null ) { script.addScript(new TextScript( value.toString() )); } } else if ( expression instanceof CompositeExpression ) { CompositeTextScriptBlock newBlock = new CompositeTextScriptBlock(); script.addScript(newBlock); CompositeExpression compositeExpression = (CompositeExpression) expression; Iterator iter = compositeExpression.getExpressions().iterator(); while (iter.hasNext()) { addExpressionScript( newBlock, (Expression) iter.next() ); } } else { script.addScript(new ExpressionScript(expression)); } }
/** * Trim the body of the script. * In this case, trim the whitespace from the start of the first element * and from the end of the last element. */ public void trimWhitespace() { List list = getScriptList(); int size = list.size(); if ( size > 0 ) { Script script = (Script) list.get(0); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimWhitespace(); } if ( size > 1 ) { script = (Script) list.get(size - 1); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimWhitespace(); } } } }
/** * Trim the body of the script. * In this case, trim all elements, removing any that are empty text. */ public void trimWhitespace() { List list = getScriptList(); for ( int i = list.size() - 1; i >= 0; i-- ) { Script script = (Script) list.get(i); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; String text = textScript.getText(); text = text.trim(); if ( text.length() == 0 ) { list.remove(i); } } } } }
/** * Adds the given Expression object to the current Script. */ protected void addExpressionScript(ScriptBlock script, Expression expression) { if ( expression instanceof ConstantExpression ) { ConstantExpression constantExpression = (ConstantExpression) expression; Object value = constantExpression.getValue(); if ( value != null ) { script.addScript(new TextScript( value.toString() )); } } else if ( expression instanceof CompositeExpression ) { CompositeTextScriptBlock newBlock = new CompositeTextScriptBlock(); script.addScript(newBlock); CompositeExpression compositeExpression = (CompositeExpression) expression; Iterator iter = compositeExpression.getExpressions().iterator(); while (iter.hasNext()) { addExpressionScript( newBlock, (Expression) iter.next() ); } } else { if (escapeByDefault) expression = createEscapingExpression(expression); script.addScript(new ExpressionScript(expression)); } }
/** * Trim the body of the script. * In this case, trim the whitespace from the start of the first element * and from the end of the last element. */ public void trimWhitespace() { List list = getScriptList(); int size = list.size(); if ( size > 0 ) { Script script = (Script) list.get(0); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimWhitespace(); } if ( size > 1 ) { script = (Script) list.get(size - 1); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimWhitespace(); } } } }
/** * Trim the body of the script. * In this case, trim all elements, removing any that are empty text. */ public void trimWhitespace() { List list = getScriptList(); for ( int i = list.size() - 1; i >= 0; i-- ) { Script script = (Script) list.get(i); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; String text = textScript.getText(); text = text.trim(); if ( text.length() == 0 ) { list.remove(i); } } } } }
public void testTrimStartWhitespace() throws Exception { TextScript textScript = new TextScript(" "); textScript.trimStartWhitespace(); assertEquals("", textScript.getText()); textScript = new TextScript(""); textScript.trimStartWhitespace(); assertEquals("", textScript.getText()); textScript = new TextScript(" foo "); textScript.trimStartWhitespace(); assertEquals("foo ", textScript.getText()); textScript = new TextScript("foo"); textScript.trimStartWhitespace(); assertEquals("foo", textScript.getText()); } }
public void testTrimEndWhitespace() throws Exception { TextScript textScript = new TextScript(" "); textScript.trimEndWhitespace(); assertEquals("", textScript.getText()); textScript = new TextScript(""); textScript.trimEndWhitespace(); assertEquals("", textScript.getText()); textScript = new TextScript(" foo "); textScript.trimEndWhitespace(); assertEquals(" foo", textScript.getText()); textScript = new TextScript("foo"); textScript.trimEndWhitespace(); assertEquals("foo", textScript.getText()); }
/** * Adds the given Expression object to the current Script. */ protected void addExpressionScript(ScriptBlock script, Expression expression) { if ( expression instanceof ConstantExpression ) { ConstantExpression constantExpression = (ConstantExpression) expression; Object value = constantExpression.getValue(); if ( value != null ) { script.addScript(new TextScript( value.toString() )); } } else if ( expression instanceof CompositeExpression ) { CompositeTextScriptBlock newBlock = new CompositeTextScriptBlock(); script.addScript(newBlock); CompositeExpression compositeExpression = (CompositeExpression) expression; Iterator iter = compositeExpression.getExpressions().iterator(); while (iter.hasNext()) { addExpressionScript( newBlock, (Expression) iter.next() ); } } else { if (escapeByDefault) expression = new EscapingExpression(expression); script.addScript(new ExpressionScript(expression)); } }
/** * Trim the body of the script. * In this case, trim the whitespace from the start of the first element * and from the end of the last element. */ public void trimWhitespace() { List list = getScriptList(); int size = list.size(); if ( size > 0 ) { Script script = (Script) list.get(0); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimWhitespace(); } if ( size > 1 ) { script = (Script) list.get(size - 1); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimWhitespace(); } } } }
/** * Trim the body of the script. * In this case, trim all elements, removing any that are empty text. */ public void trimWhitespace() { List list = getScriptList(); for ( int i = list.size() - 1; i >= 0; i-- ) { Script script = (Script) list.get(i); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; String text = textScript.getText(); text = text.trim(); if ( text.length() == 0 ) { list.remove(i); } } } } }
/** * Adds the given Expression object to the current Script. */ protected void addExpressionScript(ScriptBlock script, Expression expression) { if ( expression instanceof ConstantExpression ) { ConstantExpression constantExpression = (ConstantExpression) expression; Object value = constantExpression.getValue(); if ( value != null ) { script.addScript(new TextScript( value.toString() )); } } else if ( expression instanceof CompositeExpression ) { CompositeTextScriptBlock newBlock = new CompositeTextScriptBlock(); script.addScript(newBlock); CompositeExpression compositeExpression = (CompositeExpression) expression; Iterator iter = compositeExpression.getExpressions().iterator(); while (iter.hasNext()) { addExpressionScript( newBlock, (Expression) iter.next() ); } } else { if (escapeByDefault) expression = new EscapingExpression(expression); script.addScript(new ExpressionScript(expression)); } }
/** Trims the whitespace from a script and its children. * */ public static void trimScript(Script body) { synchronized(body) { if ( body instanceof CompositeTextScriptBlock ) { CompositeTextScriptBlock block = (CompositeTextScriptBlock) body; block.trimWhitespace(); } else if ( body instanceof ScriptBlock ) { ScriptBlock block = (ScriptBlock) body; block.trimWhitespace(); } else if ( body instanceof TextScript ) { TextScript textScript = (TextScript) body; textScript.trimWhitespace(); } } }
} else if(innerText!=null) body = new TextScript(innerText);
/** Trims the whitespace from a script and its children. * */ public static void trimScript(Script body) { synchronized(body) { if ( body instanceof CompositeTextScriptBlock ) { CompositeTextScriptBlock block = (CompositeTextScriptBlock) body; block.trimWhitespace(); } else if ( body instanceof ScriptBlock ) { ScriptBlock block = (ScriptBlock) body; block.trimWhitespace(); } else if ( body instanceof TextScript ) { TextScript textScript = (TextScript) body; textScript.trimWhitespace(); } } }