use of javax.faces.event.AbortProcessingException in project acs-community-packaging by Alfresco.
the class BrowseBean method setupContentAction.
/**
* Public helper to setup action pages with content context
*
* @param id of the content node to setup context for
*/
public void setupContentAction(String id, boolean invalidate) {
if (id != null && id.length() != 0) {
if (logger.isDebugEnabled())
logger.debug("Setup for action, setting current document to: " + id);
try {
// create the node ref, then our node representation
NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
Node node = new MapNode(ref);
// store the URL to for downloading the content
if (ApplicationModel.TYPE_FILELINK.equals(node.getType())) {
node.addPropertyResolver("url", this.resolverLinkDownload);
node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
} else {
node.addPropertyResolver("url", this.resolverDownload);
node.addPropertyResolver("downloadUrl", this.resolverDownload);
}
node.addPropertyResolver("webdavUrl", this.resolverWebdavUrl);
node.addPropertyResolver("cifsPath", this.resolverCifsPath);
node.addPropertyResolver("fileType32", this.resolverFileType32);
node.addPropertyResolver("mimetype", this.resolverMimetype);
node.addPropertyResolver("encoding", this.resolverEncoding);
node.addPropertyResolver("size", this.resolverSize);
node.addPropertyResolver("lang", this.resolverLang);
for (NodeEventListener listener : getNodeEventListeners()) {
listener.created(node, node.getType());
}
// get hold of the DocumentDetailsDialog and reset it
DocumentDetailsDialog docDetails = (DocumentDetailsDialog) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("DocumentDetailsDialog");
if (docDetails != null) {
docDetails.reset();
}
// remember the document
setDocument(node);
// setup the dispatch context in case it is required
this.navigator.setupDispatchContext(node);
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
throw new AbortProcessingException("Invalid node reference");
}
} else {
setDocument(null);
}
// clear the UI state in preparation for finishing the next action
if (invalidate == true) {
// use the context service to notify all registered beans
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
}
}
use of javax.faces.event.AbortProcessingException 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);
}
}
use of javax.faces.event.AbortProcessingException in project acs-community-packaging by Alfresco.
the class CreateDiscussionDialog method createTopic.
// ------------------------------------------------------------------------------
// Helper methods
/**
* Creates a topic for the node with the given id
*
* @param id The id of the node to discuss
*/
protected void createTopic(final String id) {
RetryingTransactionCallback<NodeRef> createTopicCallback = new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
NodeRef forumNodeRef = null;
discussingNodeRef = new NodeRef(Repository.getStoreRef(), id);
if (getNodeService().hasAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE)) {
throw new AlfrescoRuntimeException("createDiscussion called for an object that already has a discussion!");
}
// Add the discussable aspect
getNodeService().addAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
// The discussion aspect create the necessary child
List<ChildAssociationRef> destChildren = getNodeService().getChildAssocs(discussingNodeRef, ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
// Take the first one
if (destChildren.size() == 0) {
// Drop the aspect and recreate it. This should not happen, but just in case ...
getNodeService().removeAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE);
getNodeService().addAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
// The discussion aspect create the necessary child
destChildren = getNodeService().getChildAssocs(discussingNodeRef, ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
}
if (destChildren.size() == 0) {
throw new AlfrescoRuntimeException("The discussable aspect behaviour is not creating a topic");
} else {
// We just take the first one
ChildAssociationRef discussionAssoc = destChildren.get(0);
forumNodeRef = discussionAssoc.getChildRef();
}
if (logger.isDebugEnabled())
logger.debug("created forum for content: " + discussingNodeRef.toString());
return forumNodeRef;
}
};
FacesContext context = FacesContext.getCurrentInstance();
NodeRef forumNodeRef = null;
try {
forumNodeRef = getTransactionService().getRetryingTransactionHelper().doInTransaction(createTopicCallback, false);
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
throw new AbortProcessingException("Invalid node reference");
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
// finally setup the context for the forum we just created
if (forumNodeRef != null) {
this.browseBean.clickSpace(forumNodeRef);
}
}
use of javax.faces.event.AbortProcessingException in project acs-community-packaging by Alfresco.
the class StartWorkflowWizard method init.
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters) {
super.init(parameters);
// reset the selected workflow
if (this.availableWorkflows != null && this.availableWorkflows.size() > 0) {
this.selectedWorkflow = (String) this.availableWorkflows.get(0).getValue();
} else {
this.selectedWorkflow = null;
}
this.previouslySelectedWorkflow = null;
this.startTaskNode = null;
this.resources = null;
this.itemsToAdd = null;
this.packageItemsToAdd = new ArrayList<String>();
this.isItemBeingAdded = false;
resetRichList();
// add the item the workflow wizard was started on to the list of resources
String itemToWorkflowId = this.parameters.get("item-to-workflow");
try {
if (itemToWorkflowId != null && itemToWorkflowId.length() > 0) {
// create the node ref for the item and determine its type
NodeRef itemToWorkflow = new NodeRef(Repository.getStoreRef(), itemToWorkflowId);
QName type = this.getNodeService().getType(itemToWorkflow);
if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT) || this.getDictionaryService().isSubClass(type, ApplicationModel.TYPE_FILELINK)) {
this.packageItemsToAdd.add(itemToWorkflow.toString());
}
}
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { itemToWorkflowId }));
throw new AbortProcessingException("Invalid node reference");
}
}
use of javax.faces.event.AbortProcessingException in project acs-community-packaging by Alfresco.
the class CheckinCheckoutDialog method setupContentDocument.
/**
* Setup a content document node context
*
* @param id GUID of the node to setup as the content document context
* @return The Node
*/
protected Node setupContentDocument(String id) {
if (logger.isDebugEnabled())
logger.debug("Setup for action, setting current document to: " + id);
Node node = null;
try {
// create the node ref, then our node representation
NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
node = new Node(ref);
// create content URL to the content download servlet with ID and expected filename
// the myfile part will be ignored by the servlet but gives the browser a hint
String url = DownloadContentServlet.generateDownloadURL(ref, node.getName());
node.getProperties().put("url", url);
node.getProperties().put("workingCopy", node.hasAspect(ContentModel.ASPECT_WORKING_COPY));
node.getProperties().put("fileType32", FileTypeImageUtils.getFileTypeImage(node.getName(), false));
// remember the document
property.setDocument(node);
// refresh the UI, calling this method now is fine as it basically makes sure certain
// beans clear the state - so when we finish here other beans will have been reset
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
throw new AbortProcessingException("Invalid node reference");
}
return node;
}
Aggregations