public void configureWOOgnl(NSNotification n) { WOOgnl.factory().configureWOForOgnl(); NSNotificationCenter.defaultCenter().removeObserver(this); _retainerArray.remove(this); } }
public static WOOgnl factory() { if (_factory == null) { _factory = new WOOgnl(); } return _factory; }
public Hashtable newDefaultContext() { Hashtable h = new Hashtable(); if (classResolver() != null) { h.put("classResolver", classResolver()); } return h; }
public double computeFromRawRecords(NSArray rawRecords) { String totalKey = keyPath(); double doubleValue = 0.0; if(totalKey.indexOf("~") == 0) { Object result = WOOgnl.factory().getValue(totalKey.substring(1), rawRecords); doubleValue = DRValueConverter.converter().doubleForValue(result); } else if(totalKey.indexOf("@") == 0) { Object result = rawRecords.valueForKeyPath(totalKey); doubleValue = DRValueConverter.converter().doubleForValue(result); if(doubleValue == 0.0 && totalKey.indexOf("@count") == 0) { // FIXME: ak, we should return "-" on not found... probably possible via a formatter return 0.0; } } return doubleValue; } }
protected void processDeclaration(WODeclaration declaration) { NSMutableDictionary associations = (NSMutableDictionary) declaration.associations(); Enumeration bindingNameEnum = associations.keyEnumerator(); while (bindingNameEnum.hasMoreElements()) { String bindingName = (String) bindingNameEnum.nextElement(); WOAssociation association = (WOAssociation) associations.valueForKey(bindingName); WOAssociation helperAssociation = parserHelperAssociation(association); if (helperAssociation != association) { associations.setObjectForKey(helperAssociation, bindingName); } } // This will replace constant associations with ognl associations // when needed. WOOgnl.factory().convertOgnlConstantAssociations(associations); }
@Override public void setValue(Object object, WOComponent component) { WOAssociation.Event event = _markStartOfEventIfNeeded("takeValueForKeyPath", keyPath(), component); try { // not sure how to manage validation or whether the current // implementation is enough... WOOgnl.factory().setValue(keyPath(), component, object); } catch (Exception e) { if (shouldThrowException()) { throw new NSForwardException(e); } log.error("Exception invoking setValue on WOOgnlAssociation: '{}'.", keyPath(), e); } if (event != null) { EOEventCenter.markEndOfEvent(event); } if (_debugEnabled) { _logPushValue(object, component); } }
if (c != null) { String postfix = name.substring(index + 1); WOAssociation newAssociation = createAssociationForClass(c, keyPath, isConstant); associations.removeObjectForKey(name); associations.setObjectForKey(newAssociation, postfix); if (isConstant && keyPath.startsWith(ognlBindingFlag())) { String ognlExpression = keyPath.substring(ognlBindingFlag().length(), keyPath.length()); if (ognlExpression.length() > 0) { WOAssociation newAssociation = new WOOgnlAssociation(ognlExpression);
public void setValue(String expression, Object obj, Object value) { try { Ognl.setValue(expression, newDefaultContext(), obj, value); } catch (OgnlException ex) { throw new RuntimeException("Failed to set value '" + expression + "' on " + obj, ex); } }
public void configureWOForOgnl() { // Configure runtime. // Configure foundation classes. OgnlRuntime.setPropertyAccessor(Object.class, new NSObjectPropertyAccessor()); OgnlRuntime.setPropertyAccessor(NSArray.class, new NSArrayPropertyAccessor()); OgnlRuntime.setPropertyAccessor(NSDictionary.class, new NSDictionaryPropertyAccessor()); NSFoundationElementsAccessor e = new NSFoundationElementsAccessor(); OgnlRuntime.setElementsAccessor(NSArray.class, e); OgnlRuntime.setElementsAccessor(NSDictionary.class, e); OgnlRuntime.setElementsAccessor(NSSet.class, e); // Register template parser if (hasProperty("ognl.active", "true")) { String parserClassName = System.getProperty("ognl.parserClassName", "ognl.helperfunction.WOHelperFunctionParser54"); WOComponentTemplateParser.setWOHTMLTemplateParserClassName(parserClassName); if (hasProperty("ognl.inlineBindings", "false")) { WOHelperFunctionTagRegistry.setAllowInlineBindings(true); } if (hasProperty("ognl.parseStandardTags", "false")) { WOHelperFunctionHTMLParser.setParseStandardTags(true); } if (hasProperty("ognl.debugSupport", "false")) { WOHelperFunctionParser._debugSupport = true; } } }
@Override public Object valueInComponent(WOComponent component) { WOAssociation.Event event = _markStartOfEventIfNeeded("valueForKeyPath", keyPath(), component); Object value = null; try { value = WOOgnl.factory().getValue(keyPath(), component); } catch (Exception e) { if (shouldThrowException()) { throw new NSForwardException(e); } log.error("Exception invoking valueInComponent on WOOgnlAssociation with keyPath '{}'", keyPath(), e); } if (event != null) { EOEventCenter.markEndOfEvent(event); } if (_debugEnabled) { _logPullValue(value, component); } return value; }
public Object getValue(String expression, Object obj) { Object value = null; try { value = Ognl.getValue(expression, newDefaultContext(), obj); } catch (OgnlException ex) { String message = ex.getMessage(); // MS: This is SUPER SUPER LAME, but I don't see any other way in OGNL to // make keypaths with null components behave like NSKVC (i.e. returning null // vs throwing an exception). They have something called nullHandlers // in OGNL, but it appears that you have to register it per-class and you // can't override the factory. if (message == null || !message.startsWith("source is null for getProperty(null, ")) { throw new RuntimeException("Failed to get value '" + expression + "' on " + obj, ex); } } return value; }