use of org.alfresco.web.config.AdvancedSearchConfigElement in project acs-community-packaging by Alfresco.
the class UISearchCustomProperties method createComponentsFromConfig.
/**
* Build the components from the Advanced Search config entries
*
* @param context FacesContext
*/
@SuppressWarnings("unchecked")
private void createComponentsFromConfig(FacesContext context) {
DictionaryService dd = Repository.getServiceRegistry(context).getDictionaryService();
AdvancedSearchConfigElement config = (AdvancedSearchConfigElement) Application.getConfigService(context).getConfig("Advanced Search").getConfigElement(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID);
// create an appropriate component for each custom property
// using the DataDictionary to look-up labels and value types
String beanBinding = (String) getAttributes().get("bean") + '.' + (String) getAttributes().get("var");
List<CustomProperty> props = config.getCustomProperties();
if (props != null) {
for (CustomProperty property : props) {
try {
// try to find the Property definition for the specified Type or Aspect
PropertyDefinition propDef = null;
if (property.Type != null) {
QName type = Repository.resolveToQName(property.Type);
TypeDefinition typeDef = dd.getType(type);
if (typeDef == null) {
logger.warn("No Type Definition found for: " + property.Type + " - Was an Aspect expected?");
continue;
}
propDef = typeDef.getProperties().get(Repository.resolveToQName(property.Property));
} else if (property.Aspect != null) {
QName aspect = Repository.resolveToQName(property.Aspect);
AspectDefinition aspectDef = dd.getAspect(aspect);
if (aspectDef == null) {
logger.warn("No Aspect Definition found for: " + property.Aspect + " - Was a Type expected?");
continue;
}
propDef = aspectDef.getProperties().get(Repository.resolveToQName(property.Property));
}
// if we found a def, then we can build components to represent it
if (propDef != null) {
// resolve display label I18N message
String label;
if (property.LabelId != null && property.LabelId.length() != 0) {
label = Application.getMessage(context, property.LabelId);
} else {
// or use dictionary label or QName as last resort
label = propDef.getTitle(dd) != null ? propDef.getTitle(dd) : propDef.getName().getLocalName();
}
// special handling for Date and DateTime
DataTypeDefinition dataTypeDef = propDef.getDataType();
if (DataTypeDefinition.DATE.equals(dataTypeDef.getName()) || DataTypeDefinition.DATETIME.equals(dataTypeDef.getName())) {
getChildren().add(generateControl(context, propDef, label, beanBinding));
} else {
// add ListOfValues constraint components
ListOfValuesConstraint constraint = getListOfValuesConstraint(propDef);
if (constraint != null && propDef != null && propDef.isProtected() == false) {
getChildren().add(generateCheck(context, propDef, beanBinding));
getChildren().add(generateLabel(context, label + ": "));
} else {
getChildren().add(generateLabel(context, ""));
getChildren().add(generateLabel(context, label + ": "));
}
getChildren().add(generateControl(context, propDef, null, beanBinding));
}
}
} catch (DictionaryException ddErr) {
logger.warn("Error building custom properties for Advanced Search: " + ddErr.getMessage());
}
}
}
}
Aggregations