use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class UserPreferencesBean method getContentFilterLanguages.
/**
* @param includeAllLanguages if true, the list must include the label 'all languages'
* @return list of items for the content filtering language selection
*/
public SelectItem[] getContentFilterLanguages(boolean includeAllLanguages) {
FacesContext fc = FacesContext.getCurrentInstance();
ResourceBundle msg = Application.getBundle(fc);
// get the list of filter languages
List<String> languages = getContentFilterLanguagesService().getFilterLanguages();
// set the item selection list
SelectItem[] items = new SelectItem[(includeAllLanguages) ? languages.size() + 1 : languages.size()];
int idx = 0;
// include the <All Languages> item if needed
if (includeAllLanguages) {
String allLanguagesStr = msg.getString(MSG_CONTENTALLLANGUAGES);
items[idx] = new SelectItem(MSG_CONTENTALLLANGUAGES, allLanguagesStr);
idx++;
}
for (String lang : languages) {
String label = getContentFilterLanguagesService().getLabelByCode(lang);
items[idx] = new SelectItem(lang, label);
idx++;
}
return items;
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class UserPreferencesBean method getLanguageItems.
/**
* Helper to return the available language items
*
* @return Array of SelectItem objects
*/
private static SelectItem[] getLanguageItems() {
FacesContext fc = FacesContext.getCurrentInstance();
Config config = Application.getConfigService(fc).getConfig("Languages");
LanguagesConfigElement langConfig = (LanguagesConfigElement) config.getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);
List<String> languages = langConfig.getLanguages();
List<SelectItem> items = new ArrayList<SelectItem>(10);
for (String locale : languages) {
// get label associated to the locale
String label = langConfig.getLabelForLanguage(locale);
items.add(new SelectItem(locale, label));
}
return items.toArray(new SelectItem[items.size()]);
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class UserShortcutsBean method createShortcut.
// ------------------------------------------------------------------------------
// Action method handlers
/**
* Action handler called when a new shortcut is to be added to the list
*/
public void createShortcut(ActionEvent event) {
// TODO: add this action to the Details screen for Space and Document
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
if (id != null && id.length() != 0) {
try {
NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
Node node = new Node(ref);
boolean foundShortcut = false;
for (int i = 0; i < getShortcuts().size(); i++) {
if (node.getId().equals(getShortcuts().get(i).getId())) {
// found same node already in the list - so we don't need to add it again
foundShortcut = true;
break;
}
}
if (foundShortcut == false) {
// add to persistent store
UserTransaction tx = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
List<String> shortcuts = getShortcutList(context);
shortcuts.add(node.getNodeRef().getId());
PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable) shortcuts);
// commit the transaction
tx.commit();
// add our new shortcut Node to the in-memory list
getShortcuts().add(node);
if (logger.isDebugEnabled())
logger.debug("Added node: " + node.getName() + " to the user shortcuts list.");
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
}
}
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class UserShortcutsBean method getShortcuts.
/**
* @return the List of shortcut Nodes
*/
public List<Node> getShortcuts() {
if (this.shortcuts == null) {
List<String> shortcuts = null;
NodeRef prefRef = null;
UserTransaction tx = null;
boolean rollback = false;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
// get the shortcuts from the preferences for this user
shortcuts = getShortcutList(context);
if (shortcuts.size() != 0) {
// each shortcut node ID is persisted as a list item in a well known property
this.shortcuts = new ArrayList<Node>(shortcuts.size());
for (int i = 0; i < shortcuts.size(); i++) {
NodeRef ref = new NodeRef(Repository.getStoreRef(), shortcuts.get(i));
try {
if (this.getNodeService().exists(ref) == true) {
Node node = new Node(ref);
// quick init properties while in the usertransaction
node.getProperties();
// save ref to the Node for rendering
this.shortcuts.add(node);
} else {
// we write the node list back again afterwards to correct this
if (logger.isDebugEnabled())
logger.debug("Found invalid shortcut node Id: " + ref.getId());
}
} catch (AccessDeniedException accessErr) {
// we write the node list back again afterwards to correct this
if (logger.isDebugEnabled())
logger.debug("Found invalid shortcut node Id: " + ref.getId());
rollback = true;
}
}
} else {
this.shortcuts = new ArrayList<Node>(5);
}
if (rollback == false) {
tx.commit();
} else {
tx.rollback();
}
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
// write the valid shortcut IDs back to correct invalid node refs
if (shortcuts != null && shortcuts.size() != this.shortcuts.size()) {
try {
shortcuts = new ArrayList<String>(this.shortcuts.size());
for (int i = 0; i < this.shortcuts.size(); i++) {
shortcuts.add(this.shortcuts.get(i).getId());
}
PreferencesService.getPreferences().setValue(PREF_SHORTCUTS, (Serializable) shortcuts);
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
}
}
}
return this.shortcuts;
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class CreateSpaceWizard method getTemplateSpaces.
/**
* @return Returns a list of template spaces currently in the system
*/
public List<SelectItem> getTemplateSpaces() {
if (this.templates == null) {
this.templates = new ArrayList<SelectItem>();
FacesContext context = FacesContext.getCurrentInstance();
String xpath = Application.getRootPath(context) + "/" + Application.getGlossaryFolderName(context) + "/" + Application.getSpaceTemplatesFolderName(context) + "/*";
NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, xpath, null, this.getNamespaceService(), false);
if (results.size() != 0) {
// show templates of the type relating to the space we are creating
QName spaceType = QName.createQName(this.spaceType);
for (NodeRef assocRef : results) {
Node childNode = new Node(assocRef);
if (this.getDictionaryService().isSubClass(childNode.getType(), spaceType)) {
this.templates.add(new SelectItem(childNode.getId(), childNode.getName()));
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.templates, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
// add an entry (at the start) to instruct the user to select a template
this.templates.add(0, new SelectItem("none", Application.getMessage(FacesContext.getCurrentInstance(), "select_a_template")));
}
return this.templates;
}
Aggregations