use of org.jaffa.rules.IPropertyRuleIntrospector 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.rules.IPropertyRuleIntrospector in project jaffa-framework by jaffa-projects.
the class TextTag method otherDoStartTagOperations.
// //////////////////////////////////////////////////////////////
// / ///
// / User methods. ///
// / ///
// / Modify these methods to customize your tag handler. ///
// / ///
// //////////////////////////////////////////////////////////////
//
// methods called from doStartTag()
//
/**
* This generates the HTML for the tag.
*/
public void otherDoStartTagOperations() {
try {
super.otherDoStartTagOperations();
} catch (JspException e) {
log.error("TextTag.otherDoStartTagOperations(): error=" + e);
}
// Preprocess if within a Property widget
IPropertyRuleIntrospector propertyRuleIntrospector = lookupPropertyTag();
// raise an error, if the 'field' is null
if (getField() == null) {
String str = "The " + TAG_NAME + " requires 'field' parameter to be supplied or it should be within a PropertyTag";
log.error(str);
throw new MissingParametersRuntimeException(str);
}
// Get the formtag from the page & register the widget
FormTag formTag = TagHelper.getFormTag(pageContext);
if (formTag == null) {
String str = "The " + TAG_NAME + " should be inside a FormTag";
log.error(str);
throw new OuterFormTagMissingRuntimeException(str);
}
// Get the value
Object value = null;
// Check for an IPropertyRuleIntrospector, if this tag is not within a Property widget
if (propertyRuleIntrospector == null)
try {
propertyRuleIntrospector = TagHelper.getPropertyRuleIntrospector(pageContext, getField());
} catch (JspException e) {
log.error("TextTag.otherDoStartTagOperations() error getting property inspector=" + e);
}
if (propertyRuleIntrospector != null && propertyRuleIntrospector.isHidden()) {
// Display the (Restricted) text for a hidden field
value = TagHelper.getTextForHiddenField(pageContext);
} else {
// Use introspection to obtain the field-value from an IModelMap or the FormBase
value = TagHelper.getFieldValue(pageContext, getField(), TAG_NAME);
// format the value
if (value != null) {
// Determine the layout to be used for formatting the value
// The highest precedence goes to the rules definition
String layout = propertyRuleIntrospector != null ? propertyRuleIntrospector.getLayout() : null;
if (layout == null) {
// Use the layout attribute, if specified
if (m_layout != null) {
layout = m_layout;
} else {
// Use the domain and domain attributes, if specified
if (m_domain != null && m_domainField != null)
layout = obtainLayoutUsingFieldMetaData(m_domain, m_domainField);
// Finally try to use the Form and Field to determine the appropriate FieldMetaData
// Do it only if they differ from the domain/domainField
String formClass = TagHelper.getFormBase(pageContext).getClass().getName();
if (layout == null && (m_domain == null || m_domainField == null || !m_domain.equals(formClass) || !m_domainField.equals(getField())))
layout = obtainLayoutUsingFieldMetaData(formClass, getField());
}
}
// Now Format the value
String formattedValue = null;
if (layout != null)
formattedValue = Formatter.format(value, layout);
else
formattedValue = Formatter.format(value);
if (formattedValue != null) {
if (formattedValue.length() == 0)
formattedValue = null;
else {
if (getType() == null || !getType().equalsIgnoreCase("HTML")) {
formattedValue = StringHelper.convertToHTML(formattedValue);
formattedValue = StringHelper.replace(formattedValue, "\r\n", "<BR>");
formattedValue = StringHelper.replace(formattedValue, "\n\r", "<BR>");
formattedValue = StringHelper.replace(formattedValue, "\r", "<BR>");
formattedValue = StringHelper.replace(formattedValue, "\n", "<BR>");
// formattedValue = StringHelper.replace(formattedValue, " ", TagHelper.HTML_SPACE_CHARACTER);
}
if (getMaxLength() != null)
formattedValue = processMaxLength(formattedValue);
formattedValue = generateHyperlink(formattedValue, propertyRuleIntrospector);
}
}
value = formattedValue;
}
}
if (value != null) {
// wrap <pre> tag arround the value if it is a comment property
if (isPreFormated(propertyRuleIntrospector)) {
value = "<pre>" + value + "</pre>";
}
// Write the HTML
JspWriter out = pageContext.getOut();
try {
out.print(value);
} catch (IOException e) {
String str = "Exception in writing the " + TAG_NAME;
log.error(str, e);
throw new JspWriteRuntimeException(str, e);
}
}
}
use of org.jaffa.rules.IPropertyRuleIntrospector 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.rules.IPropertyRuleIntrospector in project jaffa-framework by jaffa-projects.
the class AuditTransactionViewService method addExtraInfo.
private void addExtraInfo(String className, String propertyName, Properties p) throws FrameworkException {
IPropertyRuleIntrospector introspector = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(className, propertyName, null);
// Add the label
String label = introspector.getLabel();
if (label != null)
p.put("label", MessageHelper.replaceTokens(label));
// Add the JsType
Class type = introspector.getPropertyType();
if (type != null)
p.put("type", toJsType(type));
}
use of org.jaffa.rules.IPropertyRuleIntrospector in project jaffa-framework by jaffa-projects.
the class FinderMetaDataHelper method getParameters.
/**
* Returns a Map containing the parameters needed for generating the metaData.
*/
private static Map<String, String> getParameters(HttpServletRequest request) throws Exception {
// Create a Map and load it with non-null request parameters
Map<String, String> m = new HashMap<String, String>();
String component = request.getParameter("component");
if (component != null)
m.put("component", component);
String bypassCriteriaScreen = request.getParameter("bypassCriteriaScreen");
if (bypassCriteriaScreen != null)
m.put("bypassCriteriaScreen", bypassCriteriaScreen);
String dynamicParameters = request.getParameter("dynamicParameters");
if (dynamicParameters != null)
m.put("dynamicParameters", dynamicParameters);
String staticParameters = request.getParameter("staticParameters");
if (staticParameters != null)
m.put("staticParameters", staticParameters);
String targetFields = request.getParameter("targetFields");
if (targetFields != null)
m.put("targetFields", targetFields);
// Use the PropertyRuleIntrospector to determine the parameters which were not passed in the request
String className = request.getParameter("className");
String propertyName = request.getParameter("propertyName");
if (className != null && propertyName != null) {
IPropertyRuleIntrospector i = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(className, propertyName, null);
Properties p = i.getForeignKeyInfo();
if (p != null && !p.isEmpty()) {
// Add the parameter if it doesn't already exist in the Map, but exists in the foreign-key rule
if (!m.containsKey("component") && p.containsKey("component"))
m.put("component", p.getProperty("component"));
if (!m.containsKey("bypassCriteriaScreen") && p.containsKey("bypassCriteriaScreen"))
m.put("bypassCriteriaScreen", p.getProperty("bypassCriteriaScreen"));
if (!m.containsKey("dynamicParameters") && p.containsKey("dynamicParameters"))
m.put("dynamicParameters", p.getProperty("dynamicParameters"));
if (!m.containsKey("staticParameters") && p.containsKey("staticParameters"))
m.put("staticParameters", p.getProperty("staticParameters"));
if (!m.containsKey("targetFields") && p.containsKey("targetFields"))
m.put("targetFields", p.getProperty("targetFields"));
}
}
return !m.isEmpty() && m.containsKey("component") ? m : null;
}
Aggregations