Search in sources :

Example 86 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class BaseInviteUsersWizard method next.

@Override
public String next() {
    String stepName = Application.getWizardManager().getCurrentStepName();
    if (STEP_NOTIFY.equals(stepName)) {
        FacesContext context = FacesContext.getCurrentInstance();
        // prepare automatic text for email and display
        StringBuilder buf = new StringBuilder(256);
        String personName = Application.getCurrentUser(context).getFullName(this.getNodeService());
        String msgInvitedTo = Application.getMessage(context, MSG_INVITED_TO);
        Node node = this.getNode();
        String path = this.getNodeService().getPath(node.getNodeRef()).toDisplayPath(this.getNodeService(), getPermissionService());
        buf.append(MessageFormat.format(msgInvitedTo, new Object[] { path + '/' + node.getName(), personName }));
        // default the subject line to an informative message
        this.mailHelper.setSubject(buf.toString());
        // add the rest of the automatic body text
        buf.append("\r\n\r\n");
        String msgRole = Application.getMessage(context, MSG_INVITED_ROLE);
        String roleText;
        if (this.userGroupRoles.size() != 0) {
            String roleMsg = Application.getMessage(context, userGroupRoles.get(0).getRole());
            roleText = MessageFormat.format(msgRole, roleMsg);
        } else {
            roleText = MessageFormat.format(msgRole, "[role]");
        }
        buf.append(roleText);
        // set the body content and default text to this text
        this.mailHelper.setAutomaticText(buf.toString());
        this.mailHelper.setBody(this.mailHelper.getAutomaticText());
    }
    return null;
}
Also used : FacesContext(javax.faces.context.FacesContext) Node(org.alfresco.web.bean.repository.Node)

Example 87 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class WizardManager method determineCurrentPage.

/**
 * Sets up the current page to show in the wizard
 */
protected void determineCurrentPage() {
    // reset the current page config in the state object
    this.currentWizardState.setCurrentPageCfg(null);
    PageConfig currentPageCfg = null;
    // get the config for the current step position
    StepConfig stepCfg = this.currentWizardState.getSteps().get(this.currentWizardState.getCurrentStep() - 1);
    // is the step conditional?
    if (stepCfg.hasConditionalPages()) {
        FacesContext context = FacesContext.getCurrentInstance();
        // test each conditional page in turn
        List<ConditionalPageConfig> pages = stepCfg.getConditionalPages();
        for (ConditionalPageConfig pageCfg : pages) {
            String condition = pageCfg.getCondition();
            if (logger.isDebugEnabled())
                logger.debug("Evaluating condition: " + condition);
            ValueBinding vb = context.getApplication().createValueBinding(condition);
            Object obj = vb.getValue(context);
            if (obj instanceof Boolean && ((Boolean) obj).booleanValue()) {
                currentPageCfg = pageCfg;
                break;
            }
        }
    }
    // if none of the conditions passed use the default page
    if (currentPageCfg == null) {
        currentPageCfg = stepCfg.getDefaultPage();
    }
    if (currentPageCfg == null) {
        throw new AlfrescoRuntimeException("Failed to determine page for step '" + stepCfg.getName() + "'. Make sure a default page is configured.");
    }
    // save the current page config in the state object
    this.currentWizardState.setCurrentPageCfg(currentPageCfg);
    if (logger.isDebugEnabled())
        logger.debug("Config for current page: " + this.currentWizardState.getCurrentPageCfg());
}
Also used : FacesContext(javax.faces.context.FacesContext) ConditionalPageConfig(org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig) PageConfig(org.alfresco.web.config.WizardsConfigElement.PageConfig) ConditionalPageConfig(org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig) ValueBinding(javax.faces.el.ValueBinding) StepConfig(org.alfresco.web.config.WizardsConfigElement.StepConfig) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 88 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class TrashcanDialog method buildItemsTable.

/**
 * Build an HTML table of the items that are to be or have been recovered.
 *
 * @param items          List of Node objects to display in the table
 * @param cssClass       CSS style to apply to the table
 * @param report         Set true to report the reason for any failure. This flag requires that the Node
 *                       object has a pseudo property "recoverstatus" containing the RestoreStatus.
 * @param archivedPath   Set true to show the path from the 'sys:archivedOriginalParentAssoc' property,
 *                       else the current Node Path will be used.
 *
 * @return HTML table of node info
 */
private String buildItemsTable(List<Node> items, String cssClass, boolean report, boolean archivedPath) {
    FacesContext fc = FacesContext.getCurrentInstance();
    String contextPath = fc.getExternalContext().getRequestContextPath();
    StringBuilder buf = new StringBuilder(1024);
    // outer table
    buf.append("<table width=100% cellspacing=1 cellpadding=1 border=0 class='");
    buf.append(cssClass);
    buf.append("'>");
    // title row
    buf.append("<tr style='border-bottom:1px'><th></th><th align=left><b>");
    buf.append(Application.getMessage(fc, MSG_NAME));
    buf.append("</b></th>");
    if (report == true) {
        buf.append("<th align=left>");
        buf.append(Application.getMessage(fc, MSG_RECOVERY_REASON));
        buf.append("</th>");
    } else {
        buf.append("<th align=left><b>");
        buf.append(Application.getMessage(fc, MSG_LOCATION));
        buf.append("</b></th>");
    }
    buf.append("</tr>");
    for (Node node : items) {
        // listed item rows
        buf.append("<tr><td width=16>");
        String img;
        if (getDictionaryService().isSubClass(node.getType(), ContentModel.TYPE_FOLDER)) {
            String icon = (String) node.getProperties().get("app:icon");
            img = "/images/icons/" + (icon != null ? icon + "-16.gif" : BrowseBean.SPACE_SMALL_DEFAULT + ".gif");
        } else {
            img = FileTypeImageUtils.getFileTypeImage(node.getName(), true);
        }
        buf.append("<img width=16 height=16 alt='' src='").append(contextPath).append(img).append("'>");
        buf.append("</td><td>");
        buf.append(Utils.encode(node.getName()));
        buf.append("</td>");
        if (report) {
            buf.append("<td>");
            String msg;
            RestoreStatus status = (RestoreStatus) node.getProperties().get(PROP_RECOVERSTATUS);
            String message = (String) node.getProperties().get(PROP_RECOVERERRORMESSAGE);
            switch(status) {
                case FAILURE_INVALID_PARENT:
                    msg = MSG_RECOVERED_ITEM_PARENT_S;
                    break;
                case FAILURE_PERMISSION:
                    msg = MSG_RECOVERED_ITEM_PERMISSION_S;
                    break;
                case FAILURE_INTEGRITY:
                    msg = MSG_RECOVERED_ITEM_INTEGRITY_S;
                    break;
                case FAILURE_DUPLICATE_CHILD_NODE_NAME:
                    msg = MSG_RECOVERED_ITEM_DUPLICATE_S;
                    break;
                default:
                    msg = MSG_RECOVERED_ITEM_FAILURE_S;
                    break;
            }
            buf.append(Application.getMessage(fc, msg));
            buf.append(": ");
            buf.append(message);
            buf.append("</td>");
        } else {
            buf.append("<td>");
            if (archivedPath) {
                ChildAssociationRef childRef = (ChildAssociationRef) node.getProperties().get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
                if (getNodeService().exists(childRef.getParentRef())) {
                    buf.append(Utils.encode(Repository.getNamePath(getNodeService(), getNodeService().getPath(childRef.getParentRef()), null, "/", null)));
                }
            } else {
                buf.append(Utils.encode(Repository.getNamePath(getNodeService(), getNodeService().getPath(node.getNodeRef()), null, "/", null)));
            }
            buf.append("</td>");
        }
        buf.append("</tr>");
    }
    // end table
    buf.append("</table>");
    return buf.toString();
}
Also used : FacesContext(javax.faces.context.FacesContext) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) RestoreStatus(org.alfresco.repo.node.archive.RestoreNodeReport.RestoreStatus) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 89 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class TrashcanRecoverItemDialog method recoverItem.

private String recoverItem(FacesContext context, String outcome) {
    Node item = property.getItem();
    if (item != null) {
        FacesContext fc = context;
        try {
            String msg;
            FacesMessage errorfacesMsg = null;
            // restore the node - the user may have requested a restore to a
            // different parent
            RestoreNodeReport report;
            if (property.getDestination() == null) {
                report = property.getNodeArchiveService().restoreArchivedNode(item.getNodeRef());
            } else {
                report = property.getNodeArchiveService().restoreArchivedNode(item.getNodeRef(), property.getDestination(), null, null);
            }
            switch(report.getStatus()) {
                case SUCCESS:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_SUCCESS), item.getName());
                    FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
                    fc.addMessage(RICHLIST_MSG_ID, facesMsg);
                    break;
                case FAILURE_INVALID_PARENT:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_PARENT), item.getName());
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
                case FAILURE_PERMISSION:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_PERMISSION), item.getName());
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
                case FAILURE_INTEGRITY:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_INTEGRITY), item.getName());
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
                case FAILURE_DUPLICATE_CHILD_NODE_NAME:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_DUPLICATE), item.getName());
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
                default:
                    String reason = report.getCause().getMessage();
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_FAILURE), item.getName(), reason);
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
            }
            // screen
            if (errorfacesMsg != null) {
                fc.addMessage(null, errorfacesMsg);
            }
        } catch (Throwable err) {
            // most exceptions will be caught and returned as
            // RestoreNodeReport objects by the service
            String reason = err.getMessage();
            String msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_FAILURE), item.getName(), reason);
            FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
            fc.addMessage(null, facesMsg);
            ReportedException.throwIfNecessary(err);
        }
    }
    return outcome;
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) FacesContext(javax.faces.context.FacesContext) Node(org.alfresco.web.bean.repository.Node) FacesMessage(javax.faces.application.FacesMessage)

Example 90 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class RulesDialog method getFilterItems.

public List<UIListItem> getFilterItems() {
    FacesContext context = FacesContext.getCurrentInstance();
    List<UIListItem> items = new ArrayList<UIListItem>(2);
    UIListItem item1 = new UIListItem();
    item1.setValue(INHERITED);
    item1.setLabel(Application.getMessage(context, INHERITED));
    items.add(item1);
    UIListItem item2 = new UIListItem();
    item2.setValue(LOCAL);
    item2.setLabel(Application.getMessage(context, LOCAL));
    items.add(item2);
    return items;
}
Also used : FacesContext(javax.faces.context.FacesContext) UIListItem(org.alfresco.web.ui.common.component.UIListItem) ArrayList(java.util.ArrayList)

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