| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.apache.commons.jelly.impl; |
| 17 |
|
|
| 18 |
|
import java.net.URL; |
| 19 |
|
import java.util.Iterator; |
| 20 |
|
import java.util.Map; |
| 21 |
|
|
| 22 |
|
import org.apache.commons.jelly.DynaTag; |
| 23 |
|
import org.apache.commons.jelly.JellyContext; |
| 24 |
|
import org.apache.commons.jelly.JellyException; |
| 25 |
|
import org.apache.commons.jelly.JellyTagException; |
| 26 |
|
import org.apache.commons.jelly.Tag; |
| 27 |
|
import org.apache.commons.jelly.TagLibrary; |
| 28 |
|
import org.apache.commons.jelly.XMLOutput; |
| 29 |
|
import org.apache.commons.jelly.expression.Expression; |
| 30 |
|
import org.xml.sax.SAXException; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
public class StaticTagScript extends TagScript { |
| 42 |
|
|
| 43 |
0 |
public StaticTagScript() { |
| 44 |
0 |
} |
| 45 |
|
|
| 46 |
|
public StaticTagScript(TagFactory tagFactory) { |
| 47 |
247 |
super(tagFactory); |
| 48 |
247 |
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
public void run(JellyContext context, XMLOutput output) throws JellyTagException { |
| 54 |
|
try { |
| 55 |
156 |
startNamespacePrefixes(output); |
| 56 |
0 |
} catch (SAXException e) { |
| 57 |
0 |
throw new JellyTagException("could not start namespace prefixes",e); |
| 58 |
156 |
} |
| 59 |
|
|
| 60 |
156 |
Tag tag = null; |
| 61 |
|
try { |
| 62 |
156 |
tag = getTag(context); |
| 63 |
|
|
| 64 |
|
|
| 65 |
156 |
if (tag instanceof StaticTag) { |
| 66 |
156 |
tag = findDynamicTag(context, (StaticTag) tag); |
| 67 |
|
} |
| 68 |
|
|
| 69 |
156 |
setTag(tag,context); |
| 70 |
0 |
} catch (JellyException e) { |
| 71 |
0 |
throw new JellyTagException(e); |
| 72 |
156 |
} |
| 73 |
|
|
| 74 |
156 |
URL rootURL = context.getRootURL(); |
| 75 |
156 |
URL currentURL = context.getCurrentURL(); |
| 76 |
|
try { |
| 77 |
156 |
if ( tag == null ) { |
| 78 |
|
return; |
| 79 |
|
} |
| 80 |
156 |
tag.setContext(context); |
| 81 |
156 |
setContextURLs(context); |
| 82 |
|
|
| 83 |
156 |
DynaTag dynaTag = (DynaTag) tag; |
| 84 |
|
|
| 85 |
|
|
| 86 |
156 |
for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { |
| 87 |
104 |
Map.Entry entry = (Map.Entry) iter.next(); |
| 88 |
104 |
String name = (String) entry.getKey(); |
| 89 |
104 |
Expression expression = (Expression) entry.getValue(); |
| 90 |
|
|
| 91 |
104 |
Object value = null; |
| 92 |
|
|
| 93 |
156 |
if ( Expression.class.isAssignableFrom( dynaTag.getAttributeType(name) ) ) { |
| 94 |
0 |
value = expression; |
| 95 |
0 |
} else { |
| 96 |
104 |
value = expression.evaluate(context); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
104 |
dynaTag.setAttribute(name, value); |
| 100 |
104 |
} |
| 101 |
|
|
| 102 |
156 |
tag.doTag(output); |
| 103 |
|
} |
| 104 |
0 |
catch (JellyTagException e) { |
| 105 |
0 |
handleException(e); |
| 106 |
|
} |
| 107 |
0 |
catch (RuntimeException e) { |
| 108 |
0 |
handleException(e); |
| 109 |
|
} finally { |
| 110 |
156 |
context.setCurrentURL(currentURL); |
| 111 |
156 |
context.setRootURL(rootURL); |
| 112 |
156 |
} |
| 113 |
|
|
| 114 |
|
try { |
| 115 |
156 |
endNamespacePrefixes(output); |
| 116 |
0 |
} catch (SAXException e) { |
| 117 |
0 |
throw new JellyTagException("could not end namespace prefixes",e); |
| 118 |
156 |
} |
| 119 |
156 |
} |
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
protected Tag findDynamicTag(JellyContext context, StaticTag tag) throws JellyException { |
| 126 |
|
|
| 127 |
156 |
TagLibrary taglib = context.getTagLibrary( tag.getUri() ); |
| 128 |
156 |
if ( taglib != null ) { |
| 129 |
0 |
Tag newTag = taglib.createTag( tag.getLocalName(), getSaxAttributes() ); |
| 130 |
0 |
if ( newTag != null ) { |
| 131 |
0 |
newTag.setParent( tag.getParent() ); |
| 132 |
0 |
newTag.setBody( tag.getBody() ); |
| 133 |
0 |
return newTag; |
| 134 |
|
} |
| 135 |
|
} |
| 136 |
156 |
return tag; |
| 137 |
|
} |
| 138 |
|
} |