Search in sources :

Example 11 with NodeService

use of org.alfresco.service.cmr.repository.NodeService 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 12 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.

the class UINodeWorkflowInfo method encodeBegin.

@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
    if (!isRendered())
        return;
    // get the node to display the information for
    Node node = getValue();
    if (node != null) {
        // get the services we need
        NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
        DictionaryService ddService = Repository.getServiceRegistry(context).getDictionaryService();
        WorkflowService workflowService = Repository.getServiceRegistry(context).getWorkflowService();
        ResponseWriter out = context.getResponseWriter();
        ResourceBundle bundle = Application.getBundle(context);
        // render simple workflow info
        renderSimpleWorkflowInfo(context, node, nodeService, ddService, out, bundle);
        // render advanced workflow info
        renderAdvancedWorkflowInfo(context, node, nodeService, ddService, workflowService, out, bundle);
    }
}
Also used : DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) ResponseWriter(javax.faces.context.ResponseWriter) Node(org.alfresco.web.bean.repository.Node) NodeService(org.alfresco.service.cmr.repository.NodeService) ResourceBundle(java.util.ResourceBundle)

Example 13 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.

the class UISpaceSelector method getChildrenForNode.

public Collection<NodeRef> getChildrenForNode(FacesContext context) {
    NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), this.navigationId);
    List<ChildAssociationRef> allKids = getNodeService(context).getChildAssocs(nodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
    DictionaryService dd = getDictionaryService(context);
    NodeService service = getFastNodeService(context);
    // filter out those children that are not spaces
    List<NodeRef> spaceKids = new ArrayList<NodeRef>();
    for (ChildAssociationRef ref : allKids) {
        if (dd.isSubClass(service.getType(ref.getChildRef()), ContentModel.TYPE_FOLDER) && dd.isSubClass(service.getType(ref.getChildRef()), ContentModel.TYPE_SYSTEM_FOLDER) == false) {
            spaceKids.add(ref.getChildRef());
        }
    }
    return spaceKids;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) NodeService(org.alfresco.service.cmr.repository.NodeService) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 14 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.

the class UIAjaxTagPicker method encodeBegin.

@SuppressWarnings("unchecked")
@Override
public /**
 * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
 */
void encodeBegin(FacesContext fc) throws IOException {
    if (isRendered() == false) {
        return;
    }
    ResponseWriter out = fc.getResponseWriter();
    String formClientId = Utils.getParentForm(fc, this).getClientId(fc);
    Map attrs = this.getAttributes();
    ResourceBundle msg = Application.getBundle(fc);
    // get values from submitted value or none selected
    String selectedValues = null;
    String selectedNames = null;
    String selectedItems = null;
    List<NodeRef> submitted = null;
    submitted = (List<NodeRef>) getSubmittedValue();
    if (submitted == null) {
        Object objSubmitted = getValue();
        // special case to submit empty lists on multi-select values
        if ((objSubmitted != null) && (objSubmitted.toString().equals("empty"))) {
            submitted = null;
            this.setValue(null);
        } else {
            submitted = (List<NodeRef>) getValue();
        }
    }
    if (submitted != null) {
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(fc, true);
            tx.begin();
            StringBuilder nameBuf = new StringBuilder(128);
            StringBuilder valueBuf = new StringBuilder(128);
            StringBuilder itemBuf = new StringBuilder(256);
            NodeService nodeService = (NodeService) FacesContextUtils.getRequiredWebApplicationContext(fc).getBean("nodeService");
            for (NodeRef value : submitted) {
                String name = (String) nodeService.getProperty(value, ContentModel.PROP_NAME);
                String icon = (String) nodeService.getProperty(value, ApplicationModel.PROP_ICON);
                if (nameBuf.length() != 0) {
                    nameBuf.append(", ");
                    valueBuf.append(",");
                    itemBuf.append(",");
                }
                nameBuf.append(name);
                valueBuf.append(value.toString());
                itemBuf.append(getItemJson(value.toString(), name, icon));
            }
            selectedNames = nameBuf.toString();
            selectedValues = valueBuf.toString();
            selectedItems = "[" + itemBuf.toString() + "]";
            // commit the transaction
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    // generate the Ids for our script object and containing DIV element
    String divId = getId();
    String objId = divId + "Obj";
    // generate the script to create and init our script object
    String contextPath = fc.getExternalContext().getRequestContextPath();
    out.write("<script type='text/javascript'>");
    out.write("function init" + divId + "() {");
    out.write(" window." + objId + " = new AlfTagger('" + divId + "','" + objId + "','" + getServiceCall() + "','" + formClientId + "','" + msg.getString(MSG_ADD) + "','" + msg.getString(MSG_REMOVE) + "');");
    out.write(" window." + objId + ".setChildNavigation(false);");
    if (getDefaultIcon() != null) {
        out.write(" window." + objId + ".setDefaultIcon('" + getDefaultIcon() + "');");
    }
    if (selectedItems != null) {
        out.write(" window." + objId + ".setSelectedItems('" + selectedItems + "');");
    }
    out.write("}");
    out.write("window.addEvent('domready', init" + divId + ");");
    out.write("</script>");
    // generate the DIV structure for our component as expected by the script object
    out.write("<div id='" + divId + "' class='picker'>");
    out.write(" <input id='" + getHiddenFieldName() + "' name='" + getHiddenFieldName() + "' type='hidden' value='");
    if (selectedValues != null) {
        out.write(selectedValues);
    }
    out.write("'>");
    // current selection displayed as link and message to launch the selector
    out.write(" <div id='" + divId + "-noitems'");
    if (attrs.get("style") != null) {
        out.write(" style=\"");
        out.write((String) attrs.get("style"));
        out.write('"');
    }
    if (attrs.get("styleClass") != null) {
        out.write(" class=");
        out.write((String) attrs.get("styleClass"));
    }
    out.write(">");
    if (isDisabled()) {
        out.write("   <span>");
        if (selectedNames != null) {
            out.write(selectedNames);
        }
        out.write("   </span>");
    } else {
        out.write("  <span class='pickerActionButton'><a href='javascript:" + objId + ".showSelector();'>");
        if (selectedNames == null) {
            if ("".equals(getLabel())) {
                setLabel(msg.getString(MSG_CLICK_TO_SELECT_TAG));
            }
            out.write(getLabel());
        } else {
            out.write(selectedNames);
        }
        out.write("   </a></span>");
    }
    out.write(" </div>");
    // container for item navigation
    out.write(" <div id='" + divId + "-selector' class='pickerSelector'>");
    out.write("  <div class='pickerResults'>");
    out.write("   <div class='pickerResultsHeader'>");
    out.write("    <div class='pickerNavControls'>");
    out.write("     <span class='pickerNavUp'>");
    out.write("      <a id='" + divId + "-nav-up' href='#'><img src='");
    out.write(contextPath);
    out.write("/images/icons/arrow_up.gif' border='0' alt='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("' title='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("'></a>");
    out.write("     </span>");
    out.write("     <span class='pickerNavBreadcrumb'>");
    out.write("      <span id='" + divId + "-nav-txt' class='pickerNavBreadcrumbText'></span></a>");
    out.write("     </span>");
    out.write("     <span class='pickerNavAddTag'>");
    out.write("      <span class='pickerAddTagIcon'></span>");
    out.write("      <span id='" + divId + "-addTag-linkContainer' class='pickerAddTagLinkContainer'>");
    out.write("       <a href='#' onclick='window." + objId + ".showAddTagForm(); return false;'>");
    out.write(msg.getString(MSG_ADD_A_TAG));
    out.write("</a>");
    out.write("      </span>");
    out.write("      <span id='" + divId + "-addTag-formContainer' class='pickerAddTagFormContainer'>");
    out.write("       <input id='" + divId + "-addTag-box' class='pickerAddTagBox' name='" + divId + "-addTag-box' type='text'>");
    out.write("       <img id='" + divId + "-addTag-ok' class='pickerAddTagImage' src='");
    out.write(contextPath);
    out.write("/images/office/action_successful.gif' alt='");
    out.write(msg.getString(MSG_ADD));
    out.write("' title='");
    out.write(msg.getString(MSG_ADD));
    out.write("'>");
    out.write("       <img id='" + divId + "-addTag-cancel' class='pickerAddTagImage' src='");
    out.write(contextPath);
    out.write("/images/office/action_failed.gif' alt='");
    out.write(msg.getString(MSG_CANCEL));
    out.write("' title='");
    out.write(msg.getString(MSG_CANCEL));
    out.write("'>");
    out.write("      </span>");
    out.write("     </span>");
    out.write("     <span id='" + divId + "-nav-add'></span>");
    out.write("    </div>");
    out.write("   </div>");
    // container for item selection
    out.write("   <div>");
    out.write("    <div id='" + divId + "-ajax-wait' class='pickerAjaxWait'");
    String height = getHeight();
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("    <div id='" + divId + "-results-list' class='pickerResultsList'");
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("   </div>");
    out.write("  </div>");
    // controls (OK & Cancel buttons etc.)
    out.write("  <div class='pickerFinishControls'>");
    out.write("   <div id='" + divId + "-finish' style='float:left' class='pickerButtons'><a href='javascript:" + objId + ".doneClicked();'>");
    out.write(msg.getString(MSG_OK));
    out.write("</a></div>");
    out.write("   <div style='float:right' class='pickerButtons'><a href='javascript:" + objId + ".cancelClicked();'>");
    out.write(msg.getString(MSG_CANCEL));
    out.write("</a></div>");
    out.write("  </div>");
    out.write(" </div>");
    // container for the selected items
    out.write(" <div id='" + divId + "-selected' class='pickerSelectedItems'></div>");
    out.write("</div>");
}
Also used : UserTransaction(javax.transaction.UserTransaction) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResponseWriter(javax.faces.context.ResponseWriter) NodeService(org.alfresco.service.cmr.repository.NodeService) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) IOException(java.io.IOException)

Example 15 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.

the class BaseAjaxItemPicker method encodeBegin.

/**
 * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
 */
public void encodeBegin(FacesContext fc) throws IOException {
    if (isRendered() == false) {
        return;
    }
    ResponseWriter out = fc.getResponseWriter();
    String formClientId = Utils.getParentForm(fc, this).getClientId(fc);
    Map attrs = this.getAttributes();
    ResourceBundle msg = Application.getBundle(fc);
    // get values from submitted value or none selected
    String selectedValues = null;
    String selectedNames = null;
    String selectedItems = null;
    List<NodeRef> submitted = null;
    if (getSingleSelect() == true) {
        NodeRef ref = (NodeRef) getSubmittedValue();
        if (ref == null) {
            Object objRef = getValue();
            if (objRef instanceof String) {
                ref = new NodeRef((String) objRef);
            } else if (objRef instanceof NodeRef) {
                ref = (NodeRef) objRef;
            }
        }
        if (ref != null) {
            submitted = new ArrayList<NodeRef>(1);
            submitted.add(ref);
        }
    } else {
        Object value = getSubmittedValue();
        if (value == null) {
            value = getValue();
        }
        if (value instanceof List) {
            submitted = (List<NodeRef>) value;
        } else if (value instanceof String) {
            // special case for "empty" submitted value
            if (!value.equals(EMPTY)) {
                submitted = new ArrayList<NodeRef>(1);
                submitted.add(new NodeRef(value.toString()));
            }
        }
    }
    if (submitted != null) {
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(fc, true);
            tx.begin();
            StringBuilder nameBuf = new StringBuilder(128);
            StringBuilder valueBuf = new StringBuilder(128);
            StringBuilder itemBuf = new StringBuilder(256);
            NodeService nodeService = (NodeService) FacesContextUtils.getRequiredWebApplicationContext(fc).getBean("nodeService");
            for (NodeRef value : submitted) {
                String name = (String) nodeService.getProperty(value, ContentModel.PROP_NAME);
                String icon = (String) nodeService.getProperty(value, ApplicationModel.PROP_ICON);
                if (nameBuf.length() != 0) {
                    nameBuf.append(", ");
                    valueBuf.append(",");
                    itemBuf.append(",");
                }
                nameBuf.append(name);
                valueBuf.append(value.toString());
                itemBuf.append(getItemJson(value.toString(), name, icon));
            }
            selectedNames = nameBuf.toString();
            selectedValues = valueBuf.toString();
            selectedItems = "[" + itemBuf.toString() + "]";
            // commit the transaction
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    // generate the Ids for our script object and containing DIV element
    String divId = getId();
    String objId = divId + "Obj";
    // generate the script to create and init our script object
    String contextPath = fc.getExternalContext().getRequestContextPath();
    out.write("<script type='text/javascript'>");
    out.write("function init" + divId + "() {");
    out.write(" window." + objId + " = new AlfPicker('" + divId + "','" + objId + "','" + getServiceCall() + "','" + formClientId + "'," + getSingleSelect() + ");");
    if (getInitialSelection() != null) {
        out.write(" window." + objId + ".setStartId('" + getInitialSelection() + "');");
    }
    if (getDefaultIcon() != null) {
        out.write(" window." + objId + ".setDefaultIcon('" + getDefaultIcon() + "');");
    }
    if ((!getSingleSelect()) && (selectedItems != null)) {
        out.write(" window." + objId + ".setSelectedItems('" + selectedItems + "');");
    }
    // write any addition custom request attributes required by specific picker implementations
    String requestProps = getRequestAttributes();
    if (requestProps != null) {
        out.write(" window." + objId + ".setRequestAttributes('" + requestProps + "');");
    }
    out.write("}");
    out.write("window.addEvent('domready', init" + divId + ");");
    out.write("</script>");
    // generate the DIV structure for our component as expected by the script object
    out.write("<div id='" + divId + "' class='picker'>");
    out.write(" <input id='" + getHiddenFieldName() + "' name='" + getHiddenFieldName() + "' type='hidden' value='");
    if (selectedValues != null) {
        out.write(selectedValues);
    }
    out.write("'>");
    // current selection displayed as link and message to launch the selector
    out.write(" <div id='" + divId + "-noitems'");
    if (attrs.get("style") != null) {
        out.write(" style=\"");
        out.write((String) attrs.get("style"));
        out.write('"');
    }
    if (attrs.get("styleClass") != null) {
        out.write(" class=");
        out.write((String) attrs.get("styleClass"));
    }
    out.write(">");
    out.write("  <span class='pickerActionButton'><a href='javascript:" + objId + ".showSelector();'>");
    if (selectedNames == null) {
        out.write(getLabel());
    } else {
        out.write(selectedNames);
    }
    out.write("</a></span>");
    out.write(" </div>");
    // container for item navigation
    out.write(" <div id='" + divId + "-selector' class='pickerSelector'>");
    out.write("  <div class='pickerResults'>");
    out.write("   <div class='pickerResultsHeader'>");
    out.write("    <div class='pickerNavControls'>");
    out.write("     <span class='pickerNavUp'>");
    out.write("      <a id='" + divId + "-nav-up' href='#'><img src='");
    out.write(contextPath);
    out.write("/images/icons/arrow_up.gif' border='0' alt='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("' title='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("'></a>");
    out.write("     </span>");
    out.write("     <span class='pickerNavBreadcrumb'>");
    out.write("      <div id='" + divId + "-nav-bread' class='pickerNavBreadcrumbPanel'></div>");
    out.write("      <a href='javascript:" + objId + ".breadcrumbToggle();'><span id='" + divId + "-nav-txt'></span><img border='0' src='");
    out.write(contextPath);
    out.write("/images/icons/arrow_open.gif'></a>");
    out.write("     </span>");
    out.write("     <span id='" + divId + "-nav-add'></span>");
    out.write("    </div>");
    out.write("   </div>");
    // container for item selection
    out.write("   <div>");
    out.write("    <div id='" + divId + "-ajax-wait' class='pickerAjaxWait'");
    String height = getHeight();
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("    <div id='" + divId + "-results-list' class='pickerResultsList'");
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("   </div>");
    out.write("  </div>");
    // controls (OK & Cancel buttons etc.)
    out.write("  <div class='pickerFinishControls'>");
    out.write("   <div id='" + divId + "-finish' style='float:left' class='pickerButtons'><a href='javascript:" + objId + ".doneClicked();'>");
    out.write(msg.getString(MSG_OK));
    out.write("</a></div>");
    out.write("   <div style='float:right' class='pickerButtons'><a href='javascript:" + objId + ".cancelClicked();'>");
    out.write(msg.getString(MSG_CANCEL));
    out.write("</a></div>");
    out.write("  </div>");
    out.write(" </div>");
    // container for the selected items
    out.write(" <div id='" + divId + "-selected' class='pickerSelectedItems'></div>");
    out.write("</div>");
}
Also used : UserTransaction(javax.transaction.UserTransaction) NodeService(org.alfresco.service.cmr.repository.NodeService) ArrayList(java.util.ArrayList) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResponseWriter(javax.faces.context.ResponseWriter) ResourceBundle(java.util.ResourceBundle) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

NodeService (org.alfresco.service.cmr.repository.NodeService)53 NodeRef (org.alfresco.service.cmr.repository.NodeRef)36 QName (org.alfresco.service.namespace.QName)15 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)11 ResponseWriter (javax.faces.context.ResponseWriter)10 IOException (java.io.IOException)8 UserTransaction (javax.transaction.UserTransaction)8 ServiceRegistry (org.alfresco.service.ServiceRegistry)8 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)8 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)7 PermissionService (org.alfresco.service.cmr.security.PermissionService)7 PersonService (org.alfresco.service.cmr.security.PersonService)7 SearchService (org.alfresco.service.cmr.search.SearchService)6 ArrayList (java.util.ArrayList)5 ResourceBundle (java.util.ResourceBundle)5 FileInfo (org.alfresco.service.cmr.model.FileInfo)5 Path (org.alfresco.service.cmr.repository.Path)5 TransactionService (org.alfresco.service.transaction.TransactionService)5