use of org.jaffa.metadata.PropertyRuleIntrospectorUsingFieldMetaData 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.PropertyRuleIntrospectorUsingFieldMetaData 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.PropertyRuleIntrospectorUsingFieldMetaData 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.PropertyRuleIntrospectorUsingFieldMetaData in project jaffa-framework by jaffa-projects.
the class FinderMetaDataHelper method determinePropertyMetaData.
/**
* Returns meta data for the input field.
*/
private static Map<String, String> determinePropertyMetaData(Class outputClass, Class domainClass, GraphMapping graphMapping, String fieldName) throws Exception {
IPropertyRuleIntrospector i = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(outputClass, fieldName);
// Apply an optional wrapper that also takes the FieldMetaData into account
try {
FieldMetaData fieldMetaData = PersistentHelper.getFieldMetaData(domainClass.getName(), graphMapping != null ? graphMapping.getDomainFieldName(fieldName) : fieldName);
i = new PropertyRuleIntrospectorUsingFieldMetaData(i, fieldMetaData);
} catch (Exception ignore) {
}
// A Map to hold the various attributes of the field
Map<String, String> m = new LinkedHashMap<String, String>();
// determine type
String type = toJsType(i.getPropertyType());
if (type == null) {
// A foreign-key on a Graph will typically be modelled as another Graph, in which case obtain the datatype for that field from the domainClass
type = toJsType(RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(domainClass, fieldName).getPropertyType());
}
// Ignore field having unsupported propertyType
if (type == null)
return null;
m.put("type", '\'' + type + '\'');
// determine label
String label = i.getLabel();
if (label == null) {
label = StringHelper.getSpace(StringHelper.getUpper1(fieldName));
} else {
String tmp = label.substring(1);
tmp = tmp.substring(0, tmp.length() - 1);
m.put("labelToken", '\'' + tmp + '\'');
label = StringHelper.escapeJavascript(MessageHelper.replaceTokens(label));
}
m.put("label", '\'' + label + '\'');
// determine maxLength
Integer maxLength = i.getMaxLength();
if (maxLength != null)
m.put("maxLength", maxLength.toString());
// sortable
m.put("sortable", "true");
// determine hidden
Boolean hidden = i.isHidden();
if (hidden) {
m.put("hidden", "true");
m.put("alwaysHidden", "true");
}
// determine caseType
String caseType = i.getCaseType();
if (caseType != null && caseType.toLowerCase().startsWith("upper"))
caseType = "UpperCase";
else if (caseType != null && caseType.toLowerCase().startsWith("lower"))
caseType = "LowerCase";
else
caseType = null;
if (caseType != null)
m.put("caseType", '\'' + caseType + '\'');
return m;
}
Aggregations