| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.commons.jelly; |
| 18 |
|
|
| 19 |
|
import java.io.File; |
| 20 |
|
import java.util.HashMap; |
| 21 |
|
import java.util.Map; |
| 22 |
|
|
| 23 |
|
import org.apache.commons.beanutils.ConvertUtils; |
| 24 |
|
import org.apache.commons.beanutils.Converter; |
| 25 |
|
|
| 26 |
|
import org.apache.commons.jelly.expression.CompositeExpression; |
| 27 |
|
import org.apache.commons.jelly.expression.ConstantExpression; |
| 28 |
|
import org.apache.commons.jelly.expression.Expression; |
| 29 |
|
import org.apache.commons.jelly.expression.ExpressionFactory; |
| 30 |
|
import org.apache.commons.jelly.impl.TagFactory; |
| 31 |
|
import org.apache.commons.jelly.impl.TagScript; |
| 32 |
|
|
| 33 |
|
import org.xml.sax.Attributes; |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
public abstract class TagLibrary { |
| 42 |
|
|
| 43 |
988 |
private Map tags = new HashMap(); |
| 44 |
|
|
| 45 |
|
static { |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
273 |
ConvertUtils.register( |
| 50 |
|
new Converter() { |
| 51 |
|
public Object convert(Class type, Object value) { |
| 52 |
|
if ( value instanceof File ) { |
| 53 |
|
return (File) value; |
| 54 |
|
} |
| 55 |
|
else if ( value != null ) { |
| 56 |
|
String text = value.toString(); |
| 57 |
|
return new File( text ); |
| 58 |
|
} |
| 59 |
|
return null; |
| 60 |
|
} |
| 61 |
|
}, |
| 62 |
273 |
File.class |
| 63 |
|
); |
| 64 |
273 |
} |
| 65 |
|
|
| 66 |
988 |
public TagLibrary() { |
| 67 |
988 |
} |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
public TagScript createTagScript(String name, Attributes attributes) |
| 71 |
|
throws JellyException { |
| 72 |
|
|
| 73 |
19721 |
Object value = tags.get(name); |
| 74 |
19721 |
if (value instanceof Class) { |
| 75 |
19721 |
Class type = (Class) value; |
| 76 |
19721 |
return TagScript.newInstance(type); |
| 77 |
|
} |
| 78 |
0 |
else if (value instanceof TagFactory) { |
| 79 |
0 |
return new TagScript( (TagFactory) value ); |
| 80 |
|
} |
| 81 |
0 |
return null; |
| 82 |
|
|
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
public Tag createTag(String name, Attributes attributes) |
| 87 |
|
throws JellyException { |
| 88 |
|
|
| 89 |
0 |
Object value = tags.get(name); |
| 90 |
0 |
if (value instanceof Class) { |
| 91 |
0 |
Class type = (Class) value; |
| 92 |
|
try { |
| 93 |
0 |
return (Tag) type.newInstance(); |
| 94 |
0 |
} catch (InstantiationException e) { |
| 95 |
0 |
throw new JellyException(e.toString()); |
| 96 |
0 |
} catch (IllegalAccessException e) { |
| 97 |
0 |
throw new JellyException(e.toString()); |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
0 |
else if (value instanceof TagFactory) { |
| 101 |
0 |
TagFactory factory = (TagFactory) value; |
| 102 |
0 |
return factory.createTag(name, attributes); |
| 103 |
|
} |
| 104 |
0 |
return null; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
|
| 108 |
|
public Expression createExpression( |
| 109 |
|
ExpressionFactory factory, |
| 110 |
|
TagScript tagScript, |
| 111 |
|
String attributeName, |
| 112 |
|
String attributeValue) |
| 113 |
|
throws JellyException { |
| 114 |
|
|
| 115 |
26026 |
ExpressionFactory myFactory = getExpressionFactory(); |
| 116 |
26026 |
if (myFactory == null) { |
| 117 |
26026 |
myFactory = factory; |
| 118 |
|
} |
| 119 |
26026 |
if (myFactory != null) { |
| 120 |
26026 |
return CompositeExpression.parse(attributeValue, myFactory); |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
0 |
return new ConstantExpression(attributeValue); |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
protected void registerTag(String name, Class type) { |
| 135 |
31395 |
tags.put(name, type); |
| 136 |
31395 |
} |
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
protected void registerTagFactory(String name, TagFactory tagFactory) { |
| 142 |
0 |
tags.put(name, tagFactory); |
| 143 |
0 |
} |
| 144 |
|
|
| 145 |
|
|
| 146 |
|
protected ExpressionFactory getExpressionFactory() { |
| 147 |
26026 |
return null; |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
protected Map getTagClasses() { |
| 151 |
0 |
return tags; |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
} |