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;
}
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) {
}
}
}
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());
}
}
}
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());
}
}
}
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());
}
}
}
Aggregations