Search in sources :

Example 41 with FacesContext

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

the class NodeInfoBean method getModel.

// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(NodeRef nodeRef, Map<String, String> requestMap) throws ContentIOException {
    FacesContext context = FacesContext.getCurrentInstance();
    Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
    I18NUtil.registerResourceBundle("alfresco.messages.webclient");
    // create api methods
    model.put("date", new Date());
    model.put("msg", new I18NMessageMethod());
    model.put("url", new BaseTemplateContentServlet.URLHelper(context));
    model.put("locale", I18NUtil.getLocale());
    if (nodeRef != null) {
        model.put("node", new TemplateNode(nodeRef, Repository.getServiceRegistry(context), this.imageResolver));
    }
    // add URL arguments as a map called 'args' to the root of the model
    Map<String, String> args = new HashMap<String, String>(4, 1.0f);
    for (String name : requestMap.keySet()) {
        args.put(name, requestMap.get(name));
    }
    model.put("args", args);
    return model;
}
Also used : TemplateNode(org.alfresco.repo.template.TemplateNode) FacesContext(javax.faces.context.FacesContext) I18NMessageMethod(org.alfresco.repo.template.I18NMessageMethod) HashMap(java.util.HashMap) BaseTemplateContentServlet(org.alfresco.web.app.servlet.BaseTemplateContentServlet) Date(java.util.Date)

Example 42 with FacesContext

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

the class PickerBean method getTagNodes.

/**
 * Return the JSON objects representing a list of cm:folder nodes.
 *
 * IN: "parent" - noderef (can be null) of the parent to retrieve the child folder nodes for. Null is valid
 *        and specifies the Company Home root as the parent.
 * IN: "child" - non-null value of the child noderef to retrieve the siblings for - the parent value returned
 *        in the JSON response will be the parent of the specified child.
 *
 * The 16x16 pixel folder icon path is output as the 'icon' property for each child folder.
 */
@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void getTagNodes() throws Exception {
    FacesContext fc = FacesContext.getCurrentInstance();
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
        tx.begin();
        Collection<ChildAssociationRef> childRefs;
        NodeRef parentRef = null;
        Map params = fc.getExternalContext().getRequestParameterMap();
        String strParentRef = Utils.encode((String) params.get(ID_PARENT));
        if (strParentRef == null || strParentRef.length() == 0) {
            childRefs = this.getCategoryService().getRootCategories(Repository.getStoreRef(), ContentModel.ASPECT_TAGGABLE);
        } else {
            parentRef = new NodeRef(strParentRef);
            childRefs = this.getCategoryService().getChildren(parentRef, CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE);
        }
        JSONWriter out = new JSONWriter(fc.getResponseWriter());
        out.startObject();
        out.startValue(ID_PARENT);
        out.startObject();
        if (parentRef == null) {
            out.writeNullValue(ID_ID);
            out.writeValue(ID_NAME, Application.getMessage(fc, MSG_TAGS));
            out.writeValue(ID_ISROOT, true);
            out.writeValue(ID_SELECTABLE, false);
        } else {
            out.writeValue(ID_ID, strParentRef);
            out.writeValue(ID_NAME, Repository.getNameForNode(this.getInternalNodeService(), parentRef));
        }
        out.endObject();
        out.endValue();
        out.startValue(ID_CHILDREN);
        out.startArray();
        for (ChildAssociationRef ref : childRefs) {
            NodeRef nodeRef = ref.getChildRef();
            out.startObject();
            out.writeValue(ID_ID, nodeRef.toString());
            out.writeValue(ID_NAME, Repository.getNameForNode(this.getInternalNodeService(), nodeRef));
            out.endObject();
        }
        out.endArray();
        out.endValue();
        out.endObject();
        tx.commit();
    } catch (Throwable err) {
        Utils.addErrorMessage("PickerBean exception in getTagNodes()", err);
        fc.getResponseWriter().write("ERROR: " + err.getMessage());
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) JSONWriter(org.springframework.extensions.webscripts.json.JSONWriter) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap)

Example 43 with FacesContext

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

the class PortletActionsBean method checkinItem.

@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void checkinItem() throws Exception {
    FacesContext fc = FacesContext.getCurrentInstance();
    ResponseWriter out = fc.getResponseWriter();
    Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
    String strNodeRef = (String) requestMap.get("noderef");
    if (strNodeRef != null && strNodeRef.length() != 0) {
        try {
            Map<String, Serializable> props = new HashMap<String, Serializable>(2, 1.0f);
            props.put(Version.PROP_DESCRIPTION, "");
            props.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
            Repository.getServiceRegistry(fc).getCheckOutCheckInService().checkin(new NodeRef(strNodeRef), props);
            out.write("OK: " + strNodeRef);
        } catch (Throwable err) {
            out.write("ERROR: " + err.getMessage());
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ResponseWriter(javax.faces.context.ResponseWriter) HashMap(java.util.HashMap)

Example 44 with FacesContext

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

the class PortletActionsBean method deleteItem.

@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void deleteItem() throws Exception {
    FacesContext fc = FacesContext.getCurrentInstance();
    ResponseWriter out = fc.getResponseWriter();
    Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
    String strNodeRef = (String) requestMap.get("noderef");
    if (strNodeRef != null && strNodeRef.length() != 0) {
        try {
            Repository.getServiceRegistry(fc).getFileFolderService().delete(new NodeRef(strNodeRef));
            out.write("OK: " + strNodeRef);
        } catch (Throwable err) {
            out.write("ERROR: " + err.getMessage());
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResponseWriter(javax.faces.context.ResponseWriter)

Example 45 with FacesContext

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

the class PortletActionsBean method checkoutItem.

@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void checkoutItem() throws Exception {
    FacesContext fc = FacesContext.getCurrentInstance();
    ResponseWriter out = fc.getResponseWriter();
    Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
    String strNodeRef = (String) requestMap.get("noderef");
    if (strNodeRef != null && strNodeRef.length() != 0) {
        try {
            Repository.getServiceRegistry(fc).getCheckOutCheckInService().checkout(new NodeRef(strNodeRef));
            out.write("OK: " + strNodeRef);
        } catch (Throwable err) {
            out.write("ERROR: " + err.getMessage());
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResponseWriter(javax.faces.context.ResponseWriter)

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