public void setFilters(ArrayList<String> f) { filters = new ArrayList<Filter>(); for (String s : f) { String name; String params; int i = s.indexOf(':'); if (i != -1) { name = s.substring(0, i); params = s.substring(i + 1).trim(); } else { name = s; params = null; } Filter filter = Cambridge.getInstance().getFilter(name, line, col); if (filter != null) { filter.init(params); filters.add(filter); } } if (filters.size() == 0) { filters = null; } }
/** * @return Returns the Cambridge singleton. */ public static Cambridge getInstance() { if (instance != null) { return instance; } synchronized (Cambridge.class) { if (instance == null) { instance = new Cambridge(); } return instance; } }
private String getNamespaceUri(String name) { if (name == null) { return null; } if (namespaceMappings != null) { String uri = namespaceMappings.get(name); if (uri != null) { return uri; } } return Cambridge.getInstance().getDefaultNamespace(name); }
public FunctionExpression(String functionName) { this.functionName = functionName; runner = Cambridge.getInstance().getFunctionRunner(functionName); }
mapNamespace(DefaultNamespaceURI, "a", "cambridge"); registerFunction("text", new ResourceBundleFunction()); registerFunction("if", new IfFunction()); registerFunction("format", new StaticMethodCaller(String.class.getMethod("format", String.class, Object[].class))); } catch (NoSuchMethodException e) { registerFilter("lower", LowerCaseFilter.class); registerFilter("upper", UpperCaseFilter.class); registerFilter("dateformat", SimpleDateFormatFilter.class); bind(DefaultNamespaceURI, "if").to(IfBehavior.getProvider()); bind(DefaultNamespaceURI, "elseif").to(ElseIfBehavior.getProvider()); bind(DefaultNamespaceURI, "else").to(ElseBehavior.getProvider()); bind(DefaultNamespaceURI, "foreach").to(ForeachBehavior.getProvider()); bind(DefaultNamespaceURI, "while").to(WhileBehavior.getProvider()); bind(DefaultNamespaceURI, "with").to(WithBehavior.getProvider()); bind(DefaultNamespaceURI, "from").to(FromBehavior.getProvider()); bind(DefaultNamespaceURI, "repeat").to(RepeatBehavior.getProvider()); bind(DefaultNamespaceURI, "selectedIf").to(SelectedBehavior.getProvider()); bind(DefaultNamespaceURI, "next").to(ConditionalAttributeBehavior.getProvider()); bindStatic(DefaultNamespaceURI, "addAlt").to(AltAdderStaticBehavior.class); bindStatic(DefaultNamespaceURI, "hide").to(HideBehavior.class); bindStatic(DefaultNamespaceURI, "overrides").to(OverridesStaticBehavior.class); bindTag(DefaultNamespaceURI, "hidden", "span").to(DummyTag.class);
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 TagNode tag() throws IOException, TemplateParsingException { OpenTagToken token = (OpenTagToken) currentToken; Cambridge bindings = Cambridge.getInstance(); String namespaceUri = getNamespaceUri(token.getNameSpace()); if (namespaceUri != null) { node = bindings.getDynamicTag(new DynamicAttributeKey(namespaceUri, token.getNameSpace(), token.getTagName())); if (namespaceUri != null && bindings.isRegisteredNamespace(namespaceUri)) { if (bindings.isStaticAttribute(namespaceUri, tok.getAttributeName())) { staticAttribute = true; element = new StaticAttribute(namespaceUri, tok.getLineNo(), tok.getColumn());
"</div>"; Cambridge.getInstance().bindTag(Cambridge.DefaultNamespaceURI, "form").toProvider(new FormTagProvider());
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); } } } } }
@Override void normalize(TemplateDocument doc, FragmentList f) throws BehaviorInstantiationException { if (attributes != null) { Cambridge bindings = Cambridge.getInstance(); boolean remove = false; HashSet<AttributeKey> staticAttributes = new HashSet<AttributeKey>(); 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);
} else { if (attributes != null) { Cambridge bindings = Cambridge.getInstance(); boolean remove = false; HashSet<AttributeKey> staticAttributes = new HashSet<AttributeKey>(); 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);
public void setFilters(ArrayList<String> f) { filters = new ArrayList<Filter>(); for (String s : f) { String name; String params; int i = s.indexOf(':'); if (i != -1) { name = s.substring(0, i); params = s.substring(i + 1).trim(); } else { name = s; params = null; } Filter filter = Cambridge.getInstance().getFilter(name, getBeginLine(), getBeginColumn()); if (filter != null) { filter.init(params); filters.add(filter); } } if (filters.size() == 0) { filters = null; } }