use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class GridColumnTag method lookupPropertyTag.
/**
* Checks for the nearest outer PropertyTag.
* Will set the 'label' on this tag, if not specified, with the value from the rules engine.
*/
private void lookupPropertyTag() {
if (m_label == null) {
PropertyTag propertyTag = (PropertyTag) findCustomTagAncestorWithClass(this, PropertyTag.class);
if (propertyTag != null) {
if (log.isDebugEnabled())
log.debug("Found Property Tag for Label. Field=" + propertyTag.getField());
IPropertyRuleIntrospector propertyRuleIntrospector = propertyTag.getPropertyRuleIntrospector();
if (propertyRuleIntrospector != null) {
try {
// Wrap the introspector with the FieldMetaData
FieldMetaData fieldMetaData = TagHelper.getFieldMetaData(propertyTag.getPropertyClass(), propertyTag.getPropertyName());
propertyRuleIntrospector = new PropertyRuleIntrospectorUsingFieldMetaData(propertyRuleIntrospector, fieldMetaData);
} catch (Exception e) {
// do nothing
}
if (log.isDebugEnabled())
log.debug("Found Label via Rules (Field=" + propertyTag.getField() + ") = " + propertyRuleIntrospector.getLabel());
String label = propertyRuleIntrospector.getLabel();
if (label == null)
label = LabelTag.ERROR_LABEL;
setLabel(label);
}
}
}
}
use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class SectionTag method lookupPropertyTag.
/**
* Checks for the nearest outer PropertyTag.
* Will set the 'label' on this tag, if not specified, with the value from the rules engine.
*/
private void lookupPropertyTag() {
if (m_label == null) {
PropertyTag propertyTag = (PropertyTag) findCustomTagAncestorWithClass(this, PropertyTag.class);
if (propertyTag != null) {
if (log.isDebugEnabled())
log.debug("Found Property Tag for Label. Field=" + propertyTag.getField());
IPropertyRuleIntrospector propertyRuleIntrospector = propertyTag.getPropertyRuleIntrospector();
if (propertyRuleIntrospector != null) {
try {
// Wrap the introspector with the FieldMetaData
FieldMetaData fieldMetaData = TagHelper.getFieldMetaData(propertyTag.getPropertyClass(), propertyTag.getPropertyName());
propertyRuleIntrospector = new PropertyRuleIntrospectorUsingFieldMetaData(propertyRuleIntrospector, fieldMetaData);
} catch (Exception e) {
// do nothing
}
if (log.isDebugEnabled())
log.debug("Found Label via Rules (Field=" + propertyTag.getField() + ") = " + propertyRuleIntrospector.getLabel());
String label = propertyRuleIntrospector.getLabel();
if (label == null)
label = LabelTag.ERROR_LABEL;
setLabel(label);
}
}
}
}
use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class StringHelper method formatDescription.
/**
* This method is invoked in cases where 'description' field is appended to a 'code' field.
* This method formats the input dexcriptionField based on the passed layout.
* The layout can be passed directly or can be determined from the parameters domainClassWithPackage and domainField, through the appropriate FieldMetaData object.
* It then truncates the formatted String to the input limit. If the String is truncated, then the truncateIndicator will be appended.
* No truncation will be performed if the limit <= 0
* Finally the String will be packaged between the beginMarker and endMarker.
* If the toHtml flag is true, then the result will made HTML safe.
* @param field The description of the field.
* @param layout The layout, if any to be used for formatting
* @param domainClassWithPackage The domainClass to determine the FieldMetaData object, to get a handle on the layout.
* @param domainField The domainField to determine the FieldMetaData object, to get a handle on the layout.
* @param toHtml if true, then the output will be converted to HTML.
* @param beginMarker The marker at the start of the output. Default is ' ('
* @param endMarker The marker at the end of the output. Default is ')'
* @param limit The limit for the formatted decription. Default is 25.
* @param truncateIndicator The string to append tot he formatted description, if exceeds the limit and is truncated.
* @return the formatted string packed between the markers. An empty String will be returned, in case the input field is null.
*/
public static String formatDescription(Object field, String layout, String domainClassWithPackage, String domainField, boolean toHtml, String beginMarker, String endMarker, int limit, String truncateIndicator) {
String out = null;
if (field == null)
out = "";
else {
StringBuffer buf = new StringBuffer();
String str = null;
if (layout == null && domainClassWithPackage != null && domainField != null) {
try {
IRulesEngine rulesEngine = RulesEngineFactory.getRulesEngine();
IPropertyRuleIntrospector propertyRuleIntrospector = null;
if (rulesEngine != null)
propertyRuleIntrospector = rulesEngine.getPropertyRuleIntrospector(Class.forName(domainClassWithPackage), domainField);
// Wrap the propertyRuleIntrospector with the FieldMetaData
FieldMetaData meta = PersistentHelper.getFieldMetaData(domainClassWithPackage, domainField);
propertyRuleIntrospector = new PropertyRuleIntrospectorUsingFieldMetaData(propertyRuleIntrospector, meta);
str = propertyRuleIntrospector.format(field);
} catch (Exception e) {
String s = "Exception thrown while formatting the field " + domainField;
log.error(s, e);
throw new RuntimeException(s, e);
}
} else if (layout != null)
str = Formatter.format(field, layout);
else
str = Formatter.format(field);
// Build the Output
if (str != null && str.length() > 0) {
if (beginMarker != null)
buf.append(beginMarker);
// Truncate the formatted string, if needed, and append the truncateIndicator
if (limit > 0 && str.length() > limit) {
buf.append(str.substring(0, limit - 1));
if (truncateIndicator != null)
buf.append(truncateIndicator);
} else {
buf.append(str);
}
if (endMarker != null)
buf.append(endMarker);
}
out = buf.toString();
if (toHtml)
out = org.jaffa.util.StringHelper.convertToHTML(out);
}
return out;
}
use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class FlexBean method findKeyValues.
/**
* Returns an array containing key values for the persistent object.
*/
private String[] findKeyValues() {
try {
Class persistentClass = persistentObject.getClass();
FieldMetaData[] keyFields = PersistentHelper.getKeyFields(persistentClass.getName());
if (keyFields == null || keyFields.length == 0) {
String s = "FlexFields cannot be supported on " + persistentClass + " since it has no key-fields";
log.error(s);
throw new IllegalArgumentException(s);
} else if (keyFields.length > 3) {
String s = "FlexFields cannot be supported on " + persistentClass + " since it has more than 3 key-fields";
log.error(s);
throw new IllegalArgumentException(s);
}
String[] keyValues = new String[keyFields.length];
keyValues[0] = (String) convertTo(BeanHelper.getField(persistentObject, keyFields[0].getName()), String.class, null);
if (keyFields.length > 1)
keyValues[1] = (String) convertTo(BeanHelper.getField(persistentObject, keyFields[1].getName()), String.class, null);
if (keyFields.length > 2)
keyValues[2] = (String) convertTo(BeanHelper.getField(persistentObject, keyFields[2].getName()), String.class, null);
return keyValues;
} catch (Exception e) {
String s = "Exception thrown while determining the key fields of " + persistentObject;
log.error(s, e);
throw new RuntimeException(s, e);
}
}
use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class EditBoxForm method getFieldLinkedToCCAndCachedWM.
public WidgetModel getFieldLinkedToCCAndCachedWM() {
if (w_fieldLinkedToCCAndCached == null) {
w_fieldLinkedToCCAndCached = (EditBoxModel) getWidgetCache().getModel("fieldLinkedToCCAndCached");
if (w_fieldLinkedToCCAndCached == null) {
FieldMetaData meta = new StringFieldMetaData("SomeName1", "SomeToken1", Boolean.FALSE, null, null, FieldMetaData.LOWER_CASE);
w_fieldLinkedToCCAndCached = new EditBoxModel(meta);
getWidgetCache().addModel("fieldLinkedToCCAndCached", w_fieldLinkedToCCAndCached);
w_fieldLinkedToCCAndCached.setValue(getFieldLinkedToCCAndCached());
}
}
return w_fieldLinkedToCCAndCached;
}
Aggregations