if (dynamicTag && tok.getNameSpace() == null) {
tok.setNameSpace(node.getNameSpace());
}
Attribute element = null;
StringBuilder textContent = new StringBuilder();
textContent.append(tok.getActualValue());
boolean dynamic = false;
boolean staticAttribute = false;
String namespaceUri = getNamespaceUri(tok.getNameSpace());
if (namespaceUri != null && bindings.isRegisteredNamespace(namespaceUri)) {
dynamic = true;
if (bindings.isStaticAttribute(namespaceUri, tok.getAttributeName())) {
staticAttribute = true;
element = new StaticAttribute(namespaceUri, tok.getLineNo(), tok.getColumn());
} else {
element = new DynamicAttribute(namespaceUri, tok.getLineNo(), tok.getColumn());
}
}
while (true) {
if (peek(1).getType() == TokenType.EOF
|| peek(1).getType() == TokenType.TAG_END
|| peek(1).getType() == TokenType.EXPRESSION
|| peek(1).getType() == TokenType.EXTENSION
) {
break;
}
nextToken();
boolean exitLoop = false;
switch (currentToken.getType()) {
case WS:
case EOL:
case ASSIGN:
textContent.append(currentToken.getActualValue());
break;
case ATTRIBUTE_VALUE:
textContent.append(currentToken.getActualValue());
if (dynamic) {
if (staticAttribute) {
((StaticAttribute) element).setValue(currentToken.value);
} else {
((DynamicAttribute) element).setValue(currentToken.value, expressionLanguage.parse(currentToken.value, currentToken.getLineNo(), currentToken.getColumn()));
}
exitLoop = true;
break;
}
TemplateTokenizer at = new TemplateTokenizer(new StringReader(currentToken.getValue()));
ArrayList<AttributeFragment> fragments = new ArrayList<AttributeFragment>();
while (at.hasMoreTokens()) {
Token attrToken = at.nextToken();
switch (attrToken.getType()) {
case EXPRESSION:
ExpressionToken expTok = (ExpressionToken) attrToken;
try {
ExpressionNode expNode = new ExpressionNode(attrToken.value, expressionLanguage.parse(attrToken.value, attrToken.getLineNo(), attrToken.getColumn()), expTok.isRawExpression());
if (expTok.getFilters() != null) {
expNode.setFilters(expTok.getFilters());
}
fragments.add(expNode);
} catch (ExpressionParsingException e1) {
throw new TemplateParsingException("Error parsing expression", e1, currentToken.getLineNo(), currentToken.getColumn());
}
break;
case EXTENSION:
ExtensionToken extensionToken = (ExtensionToken) attrToken;
ExtensionNode extensionNode = extensionToken.createNode(expressionLanguage);
fragments.add(extensionNode);
break;
case WS:
case STRING:
StaticFragment st = new StaticFragment(attrToken.value);
fragments.add(st);
break;
}
}
if (fragments.size() == 0 || fragments.size() == 1 && fragments.get(0) instanceof StaticFragment) {
element = new SimpleAttribute(currentToken.getLineNo(), currentToken.getColumn());
((SimpleAttribute) element).setValue(currentToken.value);
} else {
element = new ComplexAttribute(currentToken.getLineNo(), currentToken.getColumn());
((ComplexAttribute) element).setFragments(fragments);
AttributeValueToken aTok = (AttributeValueToken) currentToken;
if (aTok.getQuotes() == -2) {
((ComplexAttribute) element).setQuote('"');
} else if (aTok.getQuotes() == -3) {
((ComplexAttribute) element).setQuote('\'');
}
}
exitLoop = true;
break;
}
if (exitLoop) break;
}
if (element == null) {
throw new TemplateParsingException("Error parsing template file. Unterminated tag?", currentToken.getLineNo(), currentToken.getColumn());
}
element.setAttributeName(tok.getAttributeName());
element.setAttributeNameSpace(tok.getNameSpace());
element.setTextContent(textContent.toString());
int s = node.getTagParts().size();
if (s > 0) {
TagPart te = node.getTagParts().get(s - 1);
if (te instanceof TextTagPart) {
if (te.isWhiteSpace()) {
node.getTagParts().remove(s - 1);
}
}
}
if (firstTag && "xmlns".equalsIgnoreCase(element.getAttributeNameSpace())) {
putNamespaceMapping(element.getAttributeName(), element.getValue());
}
node.addAttribute(element);
break;
case EXPRESSION: