use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.
the class BaseActionWizard method getTransformers.
/**
* Returns the transformers that are available
*
* @return List of SelectItem objects representing the available transformers
*/
public List<SelectItem> getTransformers() {
if ((this.transformers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
Config wizardCfg = svc.getConfig("Action Wizards");
if (wizardCfg != null) {
ConfigElement transformersCfg = wizardCfg.getConfigElement("transformers");
if (transformersCfg != null) {
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> mimeTypes = this.getMimetypeService().getDisplaysByMimetype();
this.transformers = new ArrayList<SelectItem>();
for (ConfigElement child : transformersCfg.getChildren()) {
String id = child.getAttribute("name");
// try and get the display label from config
String label = Utils.getDisplayLabel(context, child);
// if there wasn't a client based label get it from the mime type service
if (label == null) {
label = mimeTypes.get(id);
}
// if there is still no label use the raw mimetype
if (label == null) {
label = id;
}
this.transformers.add(new SelectItem(id, label));
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.transformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
} else {
logger.warn("Could not find 'transformers' configuration element");
}
} else {
logger.warn("Could not find 'Action Wizards' configuration section");
}
}
return this.transformers;
}
use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.
the class ImportDialog method getEncoding.
/**
* @return Returns the encoding currently selected
*/
public String getEncoding() {
if (encoding == null) {
ConfigService configSvc = Application.getConfigService(FacesContext.getCurrentInstance());
Config config = configSvc.getConfig("Import Dialog");
if (config != null) {
ConfigElement defaultEncCfg = config.getConfigElement("default-encoding");
if (defaultEncCfg != null) {
String value = defaultEncCfg.getValue();
if (value != null) {
encoding = value.trim();
}
}
}
if (encoding == null || encoding.length() == 0) {
// if not configured, set to a sensible default for most character sets
encoding = "UTF-8";
}
}
return encoding;
}
use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.
the class ImportDialog method getEncodings.
public List<SelectItem> getEncodings() {
if ((this.encodings == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
FacesContext context = FacesContext.getCurrentInstance();
this.encodings = new ArrayList<SelectItem>(3);
ConfigService svc = Application.getConfigService(context);
Config cfg = svc.getConfig("Import Dialog");
if (cfg != null) {
ConfigElement typesCfg = cfg.getConfigElement("encodings");
if (typesCfg != null) {
for (ConfigElement child : typesCfg.getChildren()) {
String encoding = child.getAttribute("name");
if (encoding != null) {
this.encodings.add(new SelectItem(encoding, encoding));
}
}
} else {
logger.warn("Could not find 'encodings' configuration element");
}
} else {
encodings = UICharsetSelector.getCharsetEncodingList();
}
}
return this.encodings;
}
use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.
the class UIActions method encodeBegin.
/**
* @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
*/
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
if (isRendered() == false) {
return;
}
if (logger.isDebugEnabled())
logger.debug("encodeBegin() for <r:actions/> Id: " + getId() + " groupId: " + getValue());
// put the context object into the requestMap so it is accessable
// by any child component value binding expressions
Object actionContext = getContext();
Map requestMap = getFacesContext().getExternalContext().getRequestMap();
requestMap.put(ACTION_CONTEXT, actionContext);
String contextId;
if (actionContext instanceof Node) {
contextId = ((Node) actionContext).getType().toString();
if (this.groups.contains(contextId)) {
if (logger.isDebugEnabled())
logger.debug("---already built component tree for actions contextId: " + contextId);
return;
}
} else {
contextId = CONTEXTID_DEFAULT;
if (this.groups.contains(contextId)) {
if (logger.isDebugEnabled())
logger.debug("---already built component tree for default actions.");
return;
}
}
// this will need removing from the child component set to ensure that it does not grow endlessly
for (Iterator i = getChildren().iterator(); i.hasNext(); ) /**/
{
UIComponent child = (UIComponent) i.next();
if (contextId.equals(child.getAttributes().get("contextId"))) {
if (logger.isDebugEnabled())
logger.debug("***removing old child component set for contextId: " + contextId);
i.remove();
break;
}
}
String groupId = getValue();
if (groupId != null && groupId.length() != 0) {
Config config;
if (actionContext instanceof Node) {
config = Application.getConfigService(context).getConfig(actionContext);
} else {
config = Application.getConfigService(context).getGlobalConfig();
}
if (config != null) {
// find the Actions specific config element
ActionsConfigElement actionConfig = (ActionsConfigElement) config.getConfigElement(ActionsConfigElement.CONFIG_ELEMENT_ID);
if (actionConfig != null) {
// and lookup our ActionGroup by Id
ActionGroup actionGroup = actionConfig.getActionGroup(groupId);
if (actionGroup != null) {
// render the action group component tree
if (logger.isDebugEnabled())
logger.debug("-constructing ActionGroup: " + groupId + " for ContextId: " + contextId);
buildActionGroup(context, actionConfig, actionGroup, contextId);
} else {
logger.warn("Unable to find specified Action Group config ID: " + groupId);
}
}
}
}
}
use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.
the class Application method getLanguage.
/**
* Return the language Locale for the current user context
*
* @param fc FacesContext for the current user
*
* @return Current language Locale set or the VM default if none set - never null
*/
public static Locale getLanguage(FacesContext fc) {
boolean useInterfaceLanguage = Application.getClientConfig(fc).isLanguageSelect();
Map sessionMap = fc.getExternalContext().getSessionMap();
Boolean useSessionLocale = (Boolean) sessionMap.get(USE_SESSION_LOCALE);
if (useSessionLocale == null) {
useSessionLocale = Boolean.TRUE;
sessionMap.put(USE_SESSION_LOCALE, useSessionLocale);
}
Locale locale = (Locale) sessionMap.get(LOCALE);
if (locale == null || (!locale.equals(I18NUtil.getLocale()) && !useInterfaceLanguage)) {
if (useSessionLocale && useInterfaceLanguage) {
// first check saved user preferences
String strLocale = null;
if (getCurrentUser(fc) != null) {
strLocale = (String) PreferencesService.getPreferences(fc).getValue(UserPreferencesBean.PREF_INTERFACELANGUAGE);
if (strLocale != null) {
locale = I18NUtil.parseLocale(strLocale);
} else {
// failing that, use the server default locale
locale = Locale.getDefault();
}
} else {
// else get from web-client config - the first item in the configured list of languages
Config config = Application.getConfigService(fc).getConfig("Languages");
LanguagesConfigElement langConfig = (LanguagesConfigElement) config.getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);
List<String> languages = langConfig.getLanguages();
if (languages != null && languages.size() != 0) {
locale = I18NUtil.parseLocale(languages.get(0));
} else {
// failing that, use the server default locale
locale = Locale.getDefault();
}
}
// save in user session
sessionMap.put(LOCALE, locale);
} else {
// Get the request default, already decoded from the request headers
locale = I18NUtil.getLocale();
}
}
return locale;
}
Aggregations