public Tag addAttribute(Attribute a) { if (attributes == null) { attributes = new HashMap<AttributeKey, Attribute>(); } AttributeKey key = new AttributeKey(a.getAttributeNameSpace(), a.getAttributeName()); attributes.put(key, a); if ("id".equals(a.getAttributeName())) { id = a.getValue(); } Cambridge bindings = Cambridge.getInstance(); tagParts.add(a); if (a.isDynamic()) { DynamicAttributeKey attributeKey = new DynamicAttributeKey(a.getNamespaceUri(), a.getAttributeNameSpace(), a.getAttributeName()); if (bindings.getStaticBehavior(attributeKey) == null) { dynamic = true; } } return this; }
private void assignBehaviors() throws BehaviorInstantiationException { Cambridge bindings = Cambridge.getInstance(); if (attributes != null) { for (Attribute a : attributes.values()) { if (a.isDynamic()) { DynamicAttributeKey key = new DynamicAttributeKey(a.getNamespaceUri(), a.getAttributeNameSpace(), a.getAttributeName()); TagBehavior behavior; try { behavior = bindings.getBehavior(key, attributes, a.getLine(), a.getColumn()); } catch (ExpressionParsingException e) { throw new BehaviorInstantiationException("Error in parsing expression", e, getBeginLine(), getBeginColumn()); } if (behavior != null) { addBehavior(behavior); } } } } }
public Attribute getDynamicAttribute(DynamicAttributeKey key) { for (Attribute a : attributes.values()) { if (a.getAttributeName().equals(key.getAttribute()) && key.getUri().equals(a.getNamespaceUri())) { return a; } } return null; }
element.setAttributeName(tok.getAttributeName()); element.setAttributeNameSpace(tok.getNameSpace()); element.setTextContent(textContent.toString()); if (firstTag && "xmlns".equalsIgnoreCase(element.getAttributeNameSpace())) { putNamespaceMapping(element.getAttributeName(), element.getValue());
public ForeachBehavior get(DynamicAttribute keyAttribute, Map<AttributeKey, Attribute> attributes, int line, int col) throws ExpressionParsingException, BehaviorInstantiationException { AttributeKey asKey = new AttributeKey(keyAttribute.getAttributeNameSpace(), "as"); Attribute asAttribute = attributes.get(asKey); AttributeKey iterKey = new AttributeKey(keyAttribute.getAttributeNameSpace(), "iter"); Attribute iterAttribute = attributes.get(iterKey); Expression e = keyAttribute.getExpression(); return new ForeachBehavior(e, asAttribute == null ? null : asAttribute.getValue(), iterAttribute == null ? null : iterAttribute.getValue(), line, col); } };
public void modify(ExpressionContext context, ModifyableTag tag) throws ExpressionEvaluationException { if (!expression.asBoolean(context)) { int remove = -1; boolean next = false; for (int i = 0; i < tag.getTagParts().size(); i++) { TagPart t = tag.getTagParts().get(i); if (t == attribute) { next = true; } else { if (next) { if (t instanceof Attribute) { Attribute a = (Attribute) t; if (!a.isDynamic()) { remove = i; } } } } } if (remove != -1) { tag.getTagParts().remove(remove); } } }
public WithBehavior get(DynamicAttribute keyAttribute, Map<AttributeKey, Attribute> attributes, int line, int col) throws ExpressionParsingException, BehaviorInstantiationException { AttributeKey asKey = new AttributeKey(keyAttribute.getAttributeNameSpace(), "as"); Attribute asAttribute = attributes.get(asKey); return new WithBehavior(keyAttribute.getExpression(), asAttribute == null ? null : asAttribute.getValue(), line, col); } };
if (a.isDynamic()) { DynamicAttributeKey key = new DynamicAttributeKey(a.getNamespaceUri(), a.getAttributeNameSpace(), a.getAttributeName()); StaticBehavior sb = bindings.getStaticBehavior(key); if (sb != null) { sb.modify(doc, a.getValue(), this); staticAttributes.add(new AttributeKey(a.getAttributeNameSpace(), a.getAttributeName())); if (sb.shouldRemove()) { remove = true;
if (a.isDynamic()) { DynamicAttributeKey key = new DynamicAttributeKey(a.getNamespaceUri(), a.getAttributeNameSpace(), a.getAttributeName()); StaticBehavior sb = bindings.getStaticBehavior(key); if (sb != null) { sb.modify(doc, a.getValue(), this); staticAttributes.add(new AttributeKey(a.getAttributeNameSpace(), a.getAttributeName())); if (sb.shouldRemove()) { remove = true;