Author: hgilde Date: Sun Nov 13 13:03:01 2005 New Revision: 340580 URL: http://svn.apache.org/viewcvs?rev=340580&view=rev Log: remove useless ExpressionAttribute class.
StaticTag now uses the SAX attributes directly, rather than the attributes set by XMLParser. Modified: jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/StaticTagScript.java jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/TagScript.java jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/parser/XMLParser.java jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/test/org/apache/commons/jelly/core/TestFileTag.java Modified: jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/StaticTagScript.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/StaticTagScript.java?rev=340580&r1=340579&r2=340580&view=diff ============================================================================== --- jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/StaticTagScript.java (original) +++ jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/StaticTagScript.java Sun Nov 13 13:03:01 2005 @@ -15,6 +15,8 @@ */ package org.apache.commons.jelly.impl; +import java.net.URL; + import org.apache.commons.jelly.DynaTag; import org.apache.commons.jelly.JellyContext; import org.apache.commons.jelly.JellyException; @@ -22,13 +24,12 @@ import org.apache.commons.jelly.Tag; import org.apache.commons.jelly.TagLibrary; import org.apache.commons.jelly.XMLOutput; +import org.apache.commons.jelly.expression.CompositeExpression; import org.apache.commons.jelly.expression.Expression; +import org.apache.commons.jelly.expression.jexl.JexlExpressionFactory; +import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import java.net.URL; -import java.util.Iterator; -import java.util.Map; - /** * <p><code>StaticTagScript</code> is a script that evaluates a StaticTag, a piece of static XML * though its attributes or element content may contain dynamic expressions. @@ -81,32 +82,48 @@ setContextURLs(context); DynaTag dynaTag = (DynaTag) tag; - - // ### probably compiling this to 2 arrays might be quicker and smaller - for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = (Map.Entry) iter.next(); - String name = (String) entry.getKey(); - if(name.indexOf(':')!=-1) - name = name.substring(name.indexOf(':')+1); - ExpressionAttribute expat = (ExpressionAttribute) entry.getValue(); - Expression expression = expat.exp; - + + Attributes attrs = getSaxAttributes(); + + for (int i=0;i<attrs.getLength(); i++) { + + String xmlValue = attrs.getValue(i); + + String xmlName = attrs.getQName(i); + String name; + String prefix = null; + + int indexOfColon = xmlName.indexOf(':'); + if(indexOfColon!=-1) { + name = xmlName.substring(indexOfColon+1); + prefix = xmlName.substring(0, indexOfColon); + } else { + name = xmlName; + } + + //FIXME Currently creates a new ExpressionFactory each time, this is terrible. + //TODO this parsing must be factored out to the compile stage + Expression expression = CompositeExpression.parse( + xmlValue, new JexlExpressionFactory() + ); + Object value; - + if ( Expression.class.isAssignableFrom( dynaTag.getAttributeType(name) ) ) { value = expression; } else { value = expression.evaluate(context); } - - if( expat.prefix != null && expat.prefix.length() > 0 && tag instanceof StaticTag ) + + if( prefix != null && tag instanceof StaticTag ) { - ((StaticTag) dynaTag).setAttribute(name,expat.prefix, expat.nsURI,value); + ((StaticTag) dynaTag).setAttribute(name, prefix, attrs.getURI(i),value); } else { dynaTag.setAttribute(name, value); } + } tag.doTag(output); @@ -115,6 +132,8 @@ handleException(e); } catch (RuntimeException e) { + handleException(e); + } catch (JellyException e) { handleException(e); } finally { context.setCurrentURL(currentURL); Modified: jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/TagScript.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/TagScript.java?rev=340580&r1=340579&r2=340580&view=diff ============================================================================== --- jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/TagScript.java (original) +++ jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/impl/TagScript.java Sun Nov 13 13:03:01 2005 @@ -170,19 +170,7 @@ if (log.isDebugEnabled()) { log.debug("adding attribute name: " + name + " expression: " + expression); } - attributes.put(name, new ExpressionAttribute(name,expression)); - } - - /** Add an initialization attribute for the tag. - * This method must be called after the setTag() method - */ - public void addAttribute(String name, String prefix, String nsURI, Expression expression) { - if (log.isDebugEnabled()) { - log.debug("adding attribute name: " + name + " expression: " + expression); - } - if(name.indexOf(':')==-1) - name = prefix + ':' + name; - attributes.put(name, new ExpressionAttribute(name,prefix,nsURI,expression)); + attributes.put(name, expression); } /** @@ -221,7 +209,7 @@ for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String name = (String) entry.getKey(); - Expression expression = ((ExpressionAttribute) entry.getValue()).exp; + Expression expression = (Expression) entry.getValue(); Class type = dynaTag.getAttributeType(name); Object value = null; @@ -240,7 +228,7 @@ for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String name = (String) entry.getKey(); - Expression expression = ((ExpressionAttribute) entry.getValue()).exp; + Expression expression = (Expression) entry.getValue(); DynaProperty property = dynaBean.getDynaClass().getDynaProperty(name); if (property == null) { @@ -712,21 +700,3 @@ throw new JellyTagException(e, fileName, elementName, columnNumber, lineNumber); } } - - -class ExpressionAttribute { - public ExpressionAttribute(String name, Expression exp) { - this(name,"","",exp); - } - public ExpressionAttribute(String name, String prefix, String nsURI, Expression exp) { - this.name = name; - this.prefix = prefix; - this.nsURI = nsURI; - this.exp = exp; - } - - String name; - String prefix; - String nsURI; - Expression exp; -} \ No newline at end of file Modified: jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/parser/XMLParser.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/parser/XMLParser.java?rev=340580&r1=340579&r2=340580&view=diff ============================================================================== --- jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/parser/XMLParser.java (original) +++ jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/java/org/apache/commons/jelly/parser/XMLParser.java Sun Nov 13 13:03:01 2005 @@ -1045,25 +1045,13 @@ } ); configureTagScript(script); - - // now iterate through through the expressions - int size = list.getLength(); - for (int i = 0; i < size; i++) { - String attributeValue = list.getValue(i); - Expression expression = CompositeExpression.parse( - attributeValue, getExpressionFactory() - ); - String attrQName = list.getQName(i); - int p = attrQName.indexOf(':'); - String prefix = p>=0 ? - attrQName.substring(0,p): - ""; - script.addAttribute(list.getLocalName(i), - prefix, list.getURI(i), expression); - } + + //clone the attributes to keep them around after this parse + script.setSaxAttributes(new AttributesImpl(list)); + return script; } - catch (Exception e) { + catch (RuntimeException e) { log.warn( "Could not create static tag for URI: " + namespaceURI Modified: jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/test/org/apache/commons/jelly/core/TestFileTag.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/test/org/apache/commons/jelly/core/TestFileTag.java?rev=340580&r1=340579&r2=340580&view=diff ============================================================================== --- jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/test/org/apache/commons/jelly/core/TestFileTag.java (original) +++ jakarta/commons/proper/jelly/branches/hans-speed-improvement/src/test/org/apache/commons/jelly/core/TestFileTag.java Sun Nov 13 13:03:01 2005 @@ -52,10 +52,10 @@ script.run(getJellyContext(), getXMLOutput()); String data = (String)getJellyContext().getVariable("testFileTag"); - + //FIXME This doesn't take into account attribute ordering assertEquals("fully qualified attributes not passed", - "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\"></html>", + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"></html>", data); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]