Search in sources :

Example 96 with FacesContext

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) SelectItem(javax.faces.model.SelectItem) ResourceBundle(java.util.ResourceBundle)

Example 97 with FacesContext

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()]);
}
Also used : FacesContext(javax.faces.context.FacesContext) LanguagesConfigElement(org.alfresco.web.config.LanguagesConfigElement) Config(org.springframework.extensions.config.Config) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList)

Example 98 with FacesContext

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 }));
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) Node(org.alfresco.web.bean.repository.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 99 with FacesContext

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;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) Node(org.alfresco.web.bean.repository.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Example 100 with FacesContext

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickSort(org.alfresco.web.data.QuickSort) SelectItem(javax.faces.model.SelectItem) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node)

Aggregations

FacesContext (javax.faces.context.FacesContext)361 NodeRef (org.alfresco.service.cmr.repository.NodeRef)61 Node (org.alfresco.web.bean.repository.Node)44 UserTransaction (javax.transaction.UserTransaction)43 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)27 ExternalContext (javax.faces.context.ExternalContext)26 SelectItem (javax.faces.model.SelectItem)26 QName (org.alfresco.service.namespace.QName)25 FacesMessage (javax.faces.application.FacesMessage)24 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Map (java.util.Map)21 ResourceBundle (java.util.ResourceBundle)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 MapNode (org.alfresco.web.bean.repository.MapNode)18 UIViewRoot (javax.faces.component.UIViewRoot)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Serializable (java.io.Serializable)15