/** * 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); } } } } }
/** * Process notification of the beginning of the document being reached. * * @exception SAXException if a parsing error is to be reported */ public void startDocument() throws SAXException { script = new ScriptBlock(); textBuffer = new StringBuffer(); tagScript = null; scriptStack.clear(); tagScriptStack.clear(); }
textBuffer.setLength(0); script.addScript(tagScript); script = new ScriptBlock(); tagScript.setTagBody(script);
@Override protected void addExpressionScript(ScriptBlock script, Expression exp) { try { if (exp instanceof InternationalizedStringExpression && escapeByDefaultField.getBoolean(this)) { script.addScript(new ExpressionScript(((InternationalizedStringExpression) exp).escape())); return; // stick with our escaped+internationalized script } } catch (Exception e) { // fall back to original behaviour... } super.addExpressionScript(script, exp); }
/** 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(); } } }
textBuffer.setLength(0); script.addScript(tagScript); script = new ScriptBlock(); tagScript.setTagBody(script);
/** * 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)); } }
/** 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(); } } }
textBuffer.setLength(0); script.addScript(tagScript); script = new ScriptBlock(); tagScript.setTagBody(script);
/** * 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)); } }
/** * Process notification of the beginning of the document being reached. * * @exception SAXException if a parsing error is to be reported */ public void startDocument() throws SAXException { script = new ScriptBlock(); textBuffer = new StringBuffer(); tagScript = null; scriptStack.clear(); tagScriptStack.clear(); preserveWhitespace.clear(); preserveWhitespace.push(false); }
/** 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(); } } }
textBuffer.setLength(0); script.addScript(tagScript); script = new ScriptBlock(); tagScript.setTagBody(script);
/** * 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)); } }
/** * Process notification of the beginning of the document being reached. * * @exception SAXException if a parsing error is to be reported */ public void startDocument() throws SAXException { script = new ScriptBlock(); textBuffer = new StringBuffer(); tagScript = null; scriptStack.clear(); tagScriptStack.clear(); preserveWhitespace.clear(); preserveWhitespace.push(false); }
/** 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(); } } }
/** * Helper method to determin if nested body needs to be parsed by (an * xml parser, i.e. its only text) to generate SAX events or not * * @return True if tag body should be parsed or false if invoked only * @throws JellyTagException */ private boolean shouldParseBody() throws JellyTagException { boolean result = false; // check to see if we need to parse the body or just invoke it Script bodyScript = this.tag.getBody(); if (bodyScript instanceof ScriptBlock) { ScriptBlock scriptBlock = (ScriptBlock) bodyScript; List scriptList = scriptBlock.getScriptList(); for (Iterator iter = scriptList.iterator(); iter.hasNext(); ) { Script script = (Script) iter.next(); if (script instanceof StaticTagScript) { result = true; break; } } } return result; }
/** * 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)); } }