Search in sources :

Example 1 with NavigationBean

use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.

the class WorkspaceClipboardItem method paste.

/**
 * @see org.alfresco.web.bean.clipboard.ClipboardItem#paste(javax.faces.context.FacesContext, java.lang.String, int)
 */
public boolean paste(final FacesContext fc, String viewId, final int action) {
    final ServiceRegistry serviceRegistry = getServiceRegistry();
    final RetryingTransactionHelper retryingTransactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
    if (super.canCopyToViewId(viewId) || WORKSPACE_PASTE_VIEW_ID.equals(viewId) || FORUMS_PASTE_VIEW_ID.equals(viewId) || FORUM_PASTE_VIEW_ID.equals(viewId)) {
        NavigationBean navigator = (NavigationBean) FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME);
        final NodeRef destRef = new NodeRef(Repository.getStoreRef(), navigator.getCurrentNodeId());
        final DictionaryService dd = serviceRegistry.getDictionaryService();
        final NodeService nodeService = serviceRegistry.getNodeService();
        final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
        final CopyService copyService = serviceRegistry.getCopyService();
        final MultilingualContentService multilingualContentService = serviceRegistry.getMultilingualContentService();
        final boolean isPrimaryParent;
        final ChildAssociationRef assocRef;
        if (getParent() == null) {
            assocRef = nodeService.getPrimaryParent(getNodeRef());
            isPrimaryParent = true;
        } else {
            NodeRef parentNodeRef = getParent();
            List<ChildAssociationRef> assocList = nodeService.getParentAssocs(getNodeRef());
            ChildAssociationRef foundRef = null;
            if (assocList != null) {
                for (ChildAssociationRef assocListEntry : assocList) {
                    if (parentNodeRef.equals(assocListEntry.getParentRef())) {
                        foundRef = assocListEntry;
                        break;
                    }
                }
            }
            assocRef = foundRef;
            isPrimaryParent = parentNodeRef.equals(nodeService.getPrimaryParent(getNodeRef()).getParentRef());
        }
        // initial name to attempt the copy of the item with
        String name = getName();
        String translationPrefix = "";
        if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
            // copy as link was specifically requested by the user
            String linkTo = Application.getMessage(fc, MSG_LINK_TO);
            name = linkTo + ' ' + name;
        }
        // Loop until we find a target name that doesn't exist
        for (; ; ) {
            try {
                final String currentTranslationPrefix = translationPrefix;
                final String currentName = name;
                // attempt each copy/paste in its own transaction
                retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {

                    public Void execute() throws Throwable {
                        if (getMode() == ClipboardStatus.COPY) {
                            if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
                                // LINK operation
                                if (logger.isDebugEnabled())
                                    logger.debug("Attempting to link node ID: " + getNodeRef() + " into node: " + destRef.toString());
                                // create the node using the nodeService (can only use FileFolderService for content)
                                if (checkExists(currentName + LINK_NODE_EXTENSION, destRef) == false) {
                                    Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
                                    String newName = currentName + LINK_NODE_EXTENSION;
                                    props.put(ContentModel.PROP_NAME, newName);
                                    props.put(ContentModel.PROP_LINK_DESTINATION, getNodeRef());
                                    if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT)) {
                                        // create File Link node
                                        ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, QName.createQName(assocRef.getQName().getNamespaceURI(), newName), ApplicationModel.TYPE_FILELINK, props);
                                        // apply the titled aspect - title and description
                                        Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
                                        titledProps.put(ContentModel.PROP_TITLE, currentName);
                                        titledProps.put(ContentModel.PROP_DESCRIPTION, currentName);
                                        nodeService.addAspect(childRef.getChildRef(), ContentModel.ASPECT_TITLED, titledProps);
                                    } else {
                                        // create Folder link node
                                        ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), ApplicationModel.TYPE_FOLDERLINK, props);
                                        // apply the uifacets aspect - icon, title and description props
                                        Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(4, 1.0f);
                                        uiFacetsProps.put(ApplicationModel.PROP_ICON, "space-icon-link");
                                        uiFacetsProps.put(ContentModel.PROP_TITLE, currentName);
                                        uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, currentName);
                                        nodeService.addAspect(childRef.getChildRef(), ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
                                    }
                                }
                            } else {
                                // COPY operation
                                if (logger.isDebugEnabled())
                                    logger.debug("Attempting to copy node: " + getNodeRef() + " into node ID: " + destRef.toString());
                                // first check that we are not attempting to copy a duplicate into the same parent
                                if (destRef.equals(assocRef.getParentRef()) && currentName.equals(getName())) {
                                    // manually change the name if this occurs
                                    throw new FileExistsException(destRef, currentName);
                                }
                                if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
                                    // copy the file/folder
                                    fileFolderService.copy(getNodeRef(), destRef, currentName);
                                } else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
                                    // copy the mlContainer and its translations
                                    multilingualContentService.copyTranslationContainer(getNodeRef(), destRef, currentTranslationPrefix);
                                } else {
                                    // copy the node
                                    if (checkExists(currentName, destRef) == false) {
                                        copyService.copyAndRename(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), true);
                                    }
                                }
                            }
                        } else {
                            // MOVE operation
                            if (logger.isDebugEnabled())
                                logger.debug("Attempting to move node: " + getNodeRef() + " into node ID: " + destRef.toString());
                            if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
                                // move the file/folder
                                fileFolderService.moveFrom(getNodeRef(), getParent(), destRef, currentName);
                            } else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
                                // copy the mlContainer and its translations
                                multilingualContentService.moveTranslationContainer(getNodeRef(), destRef);
                            } else {
                                if (isPrimaryParent) {
                                    // move the node
                                    nodeService.moveNode(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName());
                                } else {
                                    nodeService.removeChild(getParent(), getNodeRef());
                                    nodeService.addChild(destRef, getNodeRef(), assocRef.getTypeQName(), assocRef.getQName());
                                }
                            }
                        }
                        return null;
                    }
                });
                // We got here without error, so no need to loop with a new name
                break;
            } catch (FileExistsException fileExistsErr) {
                // If mode is COPY, have another go around the loop with a new name
                if (getMode() == ClipboardStatus.COPY) {
                    String copyOf = Application.getMessage(fc, MSG_COPY_OF);
                    name = copyOf + ' ' + name;
                    translationPrefix = copyOf + ' ' + translationPrefix;
                } else {
                    // we should not rename an item when it is being moved - so exit
                    throw fileExistsErr;
                }
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : MultilingualContentService(org.alfresco.service.cmr.ml.MultilingualContentService) Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) CopyService(org.alfresco.service.cmr.repository.CopyService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) NavigationBean(org.alfresco.web.bean.NavigationBean) ServiceRegistry(org.alfresco.service.ServiceRegistry) HashMap(java.util.HashMap) Map(java.util.Map) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 2 with NavigationBean

use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.

the class UINavigator method broadcast.

/**
 * @see javax.faces.component.UIInput#broadcast(javax.faces.event.FacesEvent)
 */
public void broadcast(FacesEvent event) throws AbortProcessingException {
    if (event instanceof NavigatorEvent) {
        FacesContext context = FacesContext.getCurrentInstance();
        NavigatorEvent navEvent = (NavigatorEvent) event;
        // node or panel selected?
        switch(navEvent.getMode()) {
            case PANEL_SELECTED:
                {
                    String panelSelected = navEvent.getItem();
                    // a panel was selected, setup the context to make the panel
                    // the focus
                    NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
                    if (nb != null) {
                        try {
                            if (logger.isDebugEnabled())
                                logger.debug("Selecting panel: " + panelSelected);
                            nb.processToolbarLocation(panelSelected, true);
                        } catch (InvalidNodeRefException refErr) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME), Application.getCurrentUser(context).getHomeSpaceId()), refErr);
                        } catch (Exception err) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
                        }
                    }
                    break;
                }
            case NODE_SELECTED:
                {
                    // a node was clicked in the tree
                    boolean nodeExists = true;
                    NodeRef nodeClicked = new NodeRef(navEvent.getItem());
                    // make sure the node exists still before navigating to it
                    UserTransaction tx = null;
                    try {
                        tx = Repository.getUserTransaction(context, true);
                        tx.begin();
                        NodeService nodeSvc = Repository.getServiceRegistry(context).getNodeService();
                        nodeExists = nodeSvc.exists(nodeClicked);
                        tx.commit();
                    } catch (Throwable err) {
                        try {
                            if (tx != null) {
                                tx.rollback();
                            }
                        } catch (Exception tex) {
                        }
                    }
                    if (nodeExists) {
                        // setup the context to make the node the current node
                        BrowseBean bb = (BrowseBean) FacesHelper.getManagedBean(context, BrowseBean.BEAN_NAME);
                        if (bb != null) {
                            if (logger.isDebugEnabled())
                                logger.debug("Selected node: " + nodeClicked);
                            bb.clickSpace(nodeClicked);
                        }
                    } else {
                        String msg = Application.getMessage(context, "navigator_node_deleted");
                        Utils.addErrorMessage(msg);
                    }
                    break;
                }
        }
    } else {
        super.broadcast(event);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NavigationBean(org.alfresco.web.bean.NavigationBean) BrowseBean(org.alfresco.web.bean.BrowseBean) NodeService(org.alfresco.service.cmr.repository.NodeService) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException)

Example 3 with NavigationBean

use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.

the class UINavigator method encodeBegin.

@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
    if (!isRendered())
        return;
    // TODO: pull width and height from user preferences and/or the main config,
    // if present override below using the style attribute
    ResponseWriter out = context.getResponseWriter();
    NavigationBean navBean = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
    NavigatorPluginBean navPluginBean = (NavigatorPluginBean) FacesHelper.getManagedBean(context, NavigatorPluginBean.BEAN_NAME);
    List<TreeNode> rootNodesForArea = null;
    String area = this.getActiveArea();
    String areaTitle = null;
    boolean treePanel = true;
    if (NavigationBean.LOCATION_COMPANY.equals(area)) {
        rootNodesForArea = navPluginBean.getCompanyHomeRootNodes();
        areaTitle = Application.getMessage(context, NavigationBean.MSG_COMPANYHOME);
    } else if (NavigationBean.LOCATION_HOME.equals(area)) {
        rootNodesForArea = navPluginBean.getMyHomeRootNodes();
        areaTitle = Application.getMessage(context, NavigationBean.MSG_MYHOME);
    } else if (NavigationBean.LOCATION_GUEST.equals(area)) {
        rootNodesForArea = navPluginBean.getGuestHomeRootNodes();
        areaTitle = Application.getMessage(context, NavigationBean.MSG_GUESTHOME);
    } else {
        treePanel = false;
        areaTitle = Application.getMessage(context, NavigationBean.MSG_MYALFRESCO);
    }
    // order the root nodes by the tree label
    if (rootNodesForArea != null && rootNodesForArea.size() > 1) {
        QuickSort sorter = new QuickSort(rootNodesForArea, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    // main container div
    out.write("<div id=\"navigator\" class=\"navigator\">");
    // generate the active panel title
    String cxPath = context.getExternalContext().getRequestContextPath();
    out.write("<div class=\"sidebarButtonSelected\" style=\"background-image: url(" + cxPath + "/images/parts/navigator_blue_gradient_bg.gif)\">");
    out.write("<a class='sidebarButtonSelectedLink' onclick=\"");
    out.write(Utils.generateFormSubmit(context, this, getClientId(context), PANEL_ACTION + area));
    out.write("\" href=\"#\">");
    out.write(Utils.encode(areaTitle));
    out.write("</a></div>");
    // generate the javascript method to capture the tree node click events
    if (treePanel) {
        out.write("<script type=\"text/javascript\">");
        out.write("function treeNodeSelected(nodeRef) {");
        out.write(Utils.generateFormSubmit(context, this, getClientId(context), "nodeRef", true, null));
        out.write("}</script>");
        // generate the active panel containing the tree
        out.write("<div class=\"navigatorPanelBody\">");
        UITree tree = (UITree) context.getApplication().createComponent(UITree.COMPONENT_TYPE);
        tree.setId("tree");
        tree.setRootNodes(rootNodesForArea);
        tree.setRetrieveChildrenUrl(AJAX_URL_START + ".retrieveChildren?area=" + area);
        tree.setNodeCollapsedUrl(AJAX_URL_START + ".nodeCollapsed?area=" + area);
        tree.setNodeSelectedCallback("treeNodeSelected");
        tree.setNodeCollapsedCallback("informOfCollapse");
        Utils.encodeRecursive(context, tree);
        out.write("</div>");
    }
    // generate the closed panel title areas
    String sideBarStyle = "style=\"background-image: url(" + cxPath + "/images/parts/navigator_grey_gradient_bg.gif)\"";
    if (NavigationBean.LOCATION_COMPANY.equals(area) == false && navBean.getCompanyHomeVisible()) {
        encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_COMPANY, NavigationBean.MSG_COMPANYHOME);
    }
    if (NavigationBean.LOCATION_HOME.equals(area) == false) {
        encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_HOME, NavigationBean.MSG_MYHOME);
    }
    if (NavigationBean.LOCATION_GUEST.equals(area) == false && navBean.getIsGuest() == false && navBean.getGuestHomeVisible()) {
        encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_GUEST, NavigationBean.MSG_GUESTHOME);
    }
    if (NavigationBean.LOCATION_MYALFRESCO.equals(area) == false) {
        encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_MYALFRESCO, NavigationBean.MSG_MYALFRESCO);
    }
    out.write("</div>");
}
Also used : QuickSort(org.alfresco.web.data.QuickSort) ResponseWriter(javax.faces.context.ResponseWriter) NavigationBean(org.alfresco.web.bean.NavigationBean) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) NavigatorPluginBean(org.alfresco.web.bean.ajax.NavigatorPluginBean)

Example 4 with NavigationBean

use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.

the class UICategoryBrowser method broadcast.

/*
    * (non-Javadoc)
    * 
    * @see org.alfresco.extension.web.ui.repo.component.UINavigator#broadcast(javax.faces.event.FacesEvent)
    */
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
    if (event instanceof CategoryBrowserEvent) {
        FacesContext context = FacesContext.getCurrentInstance();
        CategoryBrowserEvent categoryBrowseEvent = (CategoryBrowserEvent) event;
        NodeRef nodeClicked = new NodeRef(categoryBrowseEvent.getItem());
        boolean subcategories = categoryBrowseEvent.isIncludeSubcategories();
        if (logger.isDebugEnabled())
            logger.debug("Selected category: " + nodeClicked + " subcategories? " + subcategories);
        CategoryBrowserBean categoryBrowserBean = (CategoryBrowserBean) FacesHelper.getManagedBean(context, CategoryBrowserBean.BEAN_NAME);
        categoryBrowserBean.setCurrentCategory(nodeClicked);
        categoryBrowserBean.setIncludeSubcategories(subcategories);
        SearchContext categorySearch = categoryBrowserBean.generateCategorySearchContext();
        NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
        nb.setSearchContext(categorySearch);
        context.getApplication().getNavigationHandler().handleNavigation(context, null, "category-browse");
    } else {
        super.broadcast(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NavigationBean(org.alfresco.web.bean.NavigationBean) SearchContext(org.alfresco.web.bean.search.SearchContext) CategoryBrowserBean(org.alfresco.web.bean.CategoryBrowserBean)

Example 5 with NavigationBean

use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.

the class UserMembersBean method inheritPermissionsValueChanged.

/**
 * Inherit parent Space permissions value changed by the user
 */
public void inheritPermissionsValueChanged(ValueChangeEvent event) {
    try {
        // change the value to the new selected value
        boolean inheritPermissions = (Boolean) event.getNewValue();
        this.getPermissionService().setInheritParentPermissions(getNode().getNodeRef(), inheritPermissions);
        // inform the user that the change occured
        FacesContext context = FacesContext.getCurrentInstance();
        String msg;
        if (inheritPermissions) {
            msg = Application.getMessage(context, MSG_SUCCESS_INHERIT);
        } else {
            msg = Application.getMessage(context, MSG_SUCCESS_INHERIT_NOT);
        }
        // pressing the top level navigation button i.e. My Home
        if (this.getPermissionService().hasPermission(getNode().getNodeRef(), PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED) {
            FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
            context.addMessage(event.getComponent().getClientId(context), facesMsg);
        } else {
            NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
            if (nb != null) {
                try {
                    nb.processToolbarLocation(nb.getToolbarLocation(), true);
                } catch (InvalidNodeRefException refErr) {
                    Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME), Application.getCurrentUser(context).getHomeSpaceId()), refErr);
                } catch (Exception err) {
                    Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
                }
            }
        }
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) NavigationBean(org.alfresco.web.bean.NavigationBean) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) FacesMessage(javax.faces.application.FacesMessage) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Aggregations

NavigationBean (org.alfresco.web.bean.NavigationBean)13 FacesContext (javax.faces.context.FacesContext)7 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)4 UserTransaction (javax.transaction.UserTransaction)3 IOException (java.io.IOException)2 ServiceRegistry (org.alfresco.service.ServiceRegistry)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 NodeService (org.alfresco.service.cmr.repository.NodeService)2 BrowseBean (org.alfresco.web.bean.BrowseBean)2 Node (org.alfresco.web.bean.repository.Node)2 TreeNode (org.alfresco.web.ui.repo.component.UITree.TreeNode)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ResourceBundle (java.util.ResourceBundle)1 Stack (java.util.Stack)1 StringTokenizer (java.util.StringTokenizer)1 FacesMessage (javax.faces.application.FacesMessage)1