in core/src/main/java/org/apache/commons/jelly/parser/XMLParser.java [464:539]
protected TagScript createTag(
String namespaceURI,
String localName,
Attributes list)
throws SAXException {
try {
// use the URI to load a taglib
TagLibrary taglib = context.getTagLibrary(namespaceURI);
if (taglib == null) {
if (namespaceURI != null && namespaceURI.startsWith("jelly:")) {
String uri = namespaceURI.substring(6);
// try to find the class on the classpath
try {
Class taglibClass = getClassLoader().loadClass(uri);
taglib = (TagLibrary) taglibClass.getConstructor().newInstance();
context.registerTagLibrary(namespaceURI, taglib);
}
catch (ClassNotFoundException e) {
throw createSAXException("Could not load class: " + uri + " so taglib instantiation failed", e);
}
catch (IllegalAccessException e) {
throw createSAXException("Constructor for class is not accessible: " + uri + " so taglib instantiation failed", e);
}
catch (InstantiationException e) {
throw createSAXException("Class could not be instantiated: " + uri + " so taglib instantiation failed", e);
}
catch (ClassCastException e) {
throw createSAXException("Class is not a TagLibrary: " + uri + " so taglib instantiation failed", e);
}
}
}
if (taglib != null) {
TagScript script = taglib.createTagScript(localName, list);
if ( script != null ) {
configureTagScript(taglib, script);
// clone the attributes to keep them around after this parse
script.setSaxAttributes(new AttributesImpl(list));
// now iterate through through the expressions
int size = list.getLength();
for (int i = 0; i < size; i++) {
String attributeName = list.getLocalName(i);
// Fix for JELLY-184 where the xmlns attributes have a blank name and cause
// an exception later on
if (attributeName.length() == 0)
continue;
String attributeValue = list.getValue(i);
Expression expression =
createExpression(script,
attributeName,
attributeValue);
// Expression expression =
// taglib.createExpression(
// getExpressionFactory(),
// script,
// attributeName,
// attributeValue);
if (expression == null) {
expression = createConstantExpression(localName, attributeName, attributeValue);
}
script.addAttribute(attributeName, expression);
}
} else if (!taglib.isAllowUnknownTags())
throw new JellyException("Unrecognized tag called " + localName + " in TagLibrary " + namespaceURI);
return script;
}
return null;
}
catch (Exception e) {
log.warn(
"Could not create taglib or URI: " + namespaceURI + " tag name: " + localName,
e);
throw createSAXException(e);
}
}