use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class TaskInfoBean method getModel.
// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(WorkflowTask task) {
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
I18NUtil.registerResourceBundle("alfresco.messages.webclient");
// create template api methods and objects
model.put("date", new Date());
model.put("msg", new I18NMessageMethod());
model.put("url", new BaseTemplateContentServlet.URLHelper(context));
model.put("locale", I18NUtil.getLocale());
model.put("task", new Workflow.WorkflowTaskItem(Repository.getServiceRegistry(context), this.imageResolver, task));
return model;
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class TaskInfoBean method sendTaskResources.
/**
* Returns the resource list for the workflow task identified by the 'taskId'
* parameter found in the ExternalContext.
* <p>
* The result is the formatted HTML to show on the client.
*/
public void sendTaskResources() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
String taskId = (String) context.getExternalContext().getRequestParameterMap().get("taskId");
if (taskId == null || taskId.length() == 0) {
throw new IllegalArgumentException("'taskId' parameter is missing");
}
WorkflowTask task = this.getWorkflowService().getTaskById(taskId);
if (task != null) {
Repository.getServiceRegistry(context).getTemplateService().processTemplate("/alfresco/templates/client/task_resource_panel.ftl", getModel(task), out);
} else {
out.write("<span class='errorMessage'>Task could not be found.</span>");
}
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class CategoriesDialog method getCategories.
/**
* @return The list of categories Nodes to display. Returns the list root categories or the
* list of sub-categories for the current category if set.
*/
public List<Node> getCategories() {
List<Node> categories;
UserTransaction tx = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context, true);
tx.begin();
Collection<ChildAssociationRef> refs;
if (getCategoryRef() == null) {
// root categories
refs = getCategoryService().getCategories(Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, Depth.IMMEDIATE);
} else {
// sub-categories of an existing category
refs = getCategoryService().getChildren(getCategoryRef(), Mode.SUB_CATEGORIES, Depth.IMMEDIATE);
}
categories = new ArrayList<Node>(refs.size());
for (ChildAssociationRef child : refs) {
Node categoryNode = new Node(child.getChildRef());
// force early props init within transaction
categoryNode.getProperties();
categories.add(categoryNode);
}
// commit the transaction
tx.commit();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }));
categories = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
categories = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
return categories;
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class CreateCategoryDialog method finishCreate.
public String finishCreate() {
String outcome = DEFAULT_OUTCOME;
try {
FacesContext context = FacesContext.getCurrentInstance();
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// create category using categoryservice
NodeRef ref;
if (getCategoryRef() == null || getCategoryRef().getId().equals("null")) {
ref = getCategoryService().createRootCategory(Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, getName());
} else {
ref = getCategoryService().createCategory(getCategoryRef(), getName());
}
// apply the titled aspect - for description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(1, 1.0f);
titledProps.put(ContentModel.PROP_DESCRIPTION, getDescription());
getNodeService().addAspect(ref, ContentModel.ASPECT_TITLED, titledProps);
return null;
}
};
txnHelper.doInTransaction(callback);
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
outcome = null;
ReportedException.throwIfNecessary(err);
}
return outcome;
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class LoginBean method login.
// ------------------------------------------------------------------------------
// Action event methods
/**
* Login action handler
*
* @return outcome view name
*/
public String login() {
String outcome = null;
FacesContext fc = FacesContext.getCurrentInstance();
if (this.username != null && this.username.length() != 0 && this.password != null && this.password.length() != 0) {
try {
// Perform a full session invalidation to ensure no cached data is left around
// - important if the login page has been accessed directly rather than via the Login/out action links
logout();
// Authenticate via the authentication service, then save the details of user in an object
// in the session - this is used by the servlet filter etc. on each page to check for login
this.getAuthenticationService().authenticate(this.username, this.password.toCharArray());
// Set the user name as stored by the back end
this.username = this.getAuthenticationService().getCurrentUserName();
// setup User object and Home space ID
User user = new User(this.username, this.getAuthenticationService().getCurrentTicket(), getPersonService().getPerson(this.username));
NodeRef homeSpaceRef = (NodeRef) this.getNodeService().getProperty(getPersonService().getPerson(this.username), ContentModel.PROP_HOMEFOLDER);
// check that the home space node exists - else user cannot login
if (homeSpaceRef == null || this.getNodeService().exists(homeSpaceRef) == false) {
throw new InvalidNodeRefException(homeSpaceRef);
}
user.setHomeSpaceId(homeSpaceRef.getId());
// put the User object in the Session - the authentication servlet will then allow
// the app to continue without redirecting to the login page
Application.setCurrentUser(fc, user);
// Save the current username to cookie
AuthenticationHelper.setUsernameCookie((HttpServletRequest) fc.getExternalContext().getRequest(), (HttpServletResponse) fc.getExternalContext().getResponse(), this.username);
// Programatically retrieve the LoginOutcomeBean from JSF
LoginOutcomeBean loginOutcomeBean = (LoginOutcomeBean) fc.getApplication().createValueBinding("#{LoginOutcomeBean}").getValue(fc);
// if a redirect URL has been provided then use that
// this allows servlets etc. to provide a URL to return too after a successful login
String redirectURL = loginOutcomeBean.getRedirectURL();
// ALF-10312: Validate we are redirecting within this web app
if (redirectURL != null && !redirectURL.isEmpty() && !redirectURL.startsWith(fc.getExternalContext().getRequestContextPath())) {
if (logger.isWarnEnabled())
logger.warn("Security violation. Unable to redirect to external location: " + redirectURL);
redirectURL = null;
}
if (redirectURL != null && redirectURL.length() > 0) {
if (logger.isDebugEnabled())
logger.debug("Redirect URL found: " + redirectURL);
try {
fc.getExternalContext().redirect(redirectURL);
fc.responseComplete();
return null;
} catch (IOException ioErr) {
logger.warn("Unable to redirect to url: " + redirectURL, ioErr);
}
} else {
// special case to handle jump to My Alfresco page initially
// note: to enable MT runtime client config customization, need to re-init NavigationBean
// in context of tenant login page
this.navigator.initFromClientConfig();
if (NavigationBean.LOCATION_MYALFRESCO.equals(this.preferences.getStartLocation())) {
return "myalfresco";
} else {
// generally this will navigate to the generic browse screen
return "success";
}
}
} catch (AuthenticationDisallowedException aerr) {
Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_LOGIN_DISALLOWED));
} catch (AuthenticationMaxUsersException aerr) {
Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_LOGIN_MAXUSERS));
} catch (AuthenticationException aerr) {
Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_UNKNOWN_USER));
} catch (InvalidNodeRefException refErr) {
String msg;
if (refErr.getNodeRef() != null) {
msg = refErr.getNodeRef().toString();
} else {
msg = Application.getMessage(fc, MSG_NONE);
}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(fc, Repository.ERROR_NOHOME), msg));
}
} else {
Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_MISSING));
}
return outcome;
}
Aggregations