Afternoon merge.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2915 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-05-17 22:42:03 +00:00
parent 009fd6f36f
commit e18a26f4f3
72 changed files with 1300 additions and 5517 deletions

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.action.evaluator;
import org.alfresco.web.action.ActionEvaluator;
import org.alfresco.web.bean.repository.Node;
/**
* UI Action Evaluator - Unlock a locked document.
*
* @author Kevin Roast
*/
public final class UnlockDocEvaluator implements ActionEvaluator
{
/**
* @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
*/
public boolean evaluate(Node node)
{
return (node.isLocked() == true);
}
}

View File

@@ -84,14 +84,14 @@ public class CommandServlet extends BaseServlet
return;
}
uri = uri.substring(req.getContextPath().length());
StringTokenizer t = new StringTokenizer(uri, "/");
int tokenCount = t.countTokens();
if (tokenCount < 4)
if (tokenCount < 3)
{
throw new IllegalArgumentException("Command Servlet URL did not contain all required args: " + uri);
}
t.nextToken(); // skip web app name
t.nextToken(); // skip servlet name
// get the command processor to execute the command e.g. "workflow"
@@ -101,8 +101,8 @@ public class CommandServlet extends BaseServlet
String command = t.nextToken();
// get any remaining uri elements to pass to the processor
String[] args = new String[tokenCount - 4];
for (int i=0; i<tokenCount-4; i++)
String[] args = new String[tokenCount - 3];
for (int i=0; i<tokenCount-3; i++)
{
args[i] = t.nextToken();
}
@@ -127,7 +127,7 @@ public class CommandServlet extends BaseServlet
txn.begin();
// inform the processor to execute the specified command
processor.process(serviceRegistry, req.getSession(), command);
processor.process(serviceRegistry, req, command);
// commit the transaction
txn.commit();
@@ -166,11 +166,18 @@ public class CommandServlet extends BaseServlet
}
/**
* @param procName
* Created the specified CommandProcessor instance. The name of the processor is looked up
* in the client config, it should find a valid class impl and then create it.
*
* @param procName Name of the CommandProcessor to lookup in the client config.
*
* @return CommandProcessor
*
* @throws InstantiationException
* @throws IllegalAccessException
*/
private CommandProcessor createCommandProcessor(String procName) throws InstantiationException, IllegalAccessException
private CommandProcessor createCommandProcessor(String procName)
throws InstantiationException, IllegalAccessException
{
Config config = Application.getConfigService(getServletContext()).getConfig("Command Servlet");
if (config == null)

View File

@@ -114,13 +114,13 @@ public class DownloadContentServlet extends BaseServlet
// TODO: add compression here?
// see http://servlets.com/jservlet2/examples/ch06/ViewResourceCompress.java for example
// only really needed if we don't use the built in compression of the servlet container
uri = uri.substring(req.getContextPath().length());
StringTokenizer t = new StringTokenizer(uri, "/");
if (t.countTokens() < 7)
if (t.countTokens() < 6)
{
throw new IllegalArgumentException("Download URL did not contain all required args: " + uri);
}
t.nextToken(); // skip web app name
t.nextToken(); // skip servlet name
String attachToken = t.nextToken();

View File

@@ -85,20 +85,21 @@ public class ExternalAccessServlet extends BaseServlet
return;
}
uri = uri.substring(req.getContextPath().length());
StringTokenizer t = new StringTokenizer(uri, "/");
int count = t.countTokens();
if (count < 3)
int tokenCount = t.countTokens();
if (tokenCount < 2)
{
throw new IllegalArgumentException("Externally addressable URL did not contain all required args: " + uri);
}
t.nextToken(); // skip web app name
t.nextToken(); // skip servlet name
String outcome = t.nextToken();
// get rest of the tokens arguments
String[] args = new String[count - 3];
for (int i=0; i<count - 3; i++)
String[] args = new String[tokenCount - 2];
for (int i=0; i<tokenCount - 2; i++)
{
args[i] = t.nextToken();
}

View File

@@ -19,12 +19,15 @@ package org.alfresco.web.app.servlet;
import java.io.IOException;
import java.net.SocketException;
import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -100,14 +103,14 @@ public class TemplateContentServlet extends BaseServlet
return;
}
uri = uri.substring(req.getContextPath().length());
StringTokenizer t = new StringTokenizer(uri, "/");
int tokenCount = t.countTokens();
if (tokenCount < 5)
if (tokenCount < 4)
{
throw new IllegalArgumentException("Template Servlet URL did not contain all required args: " + uri);
}
t.nextToken(); // skip web app name
t.nextToken(); // skip servlet name
// get NodeRef to the content
@@ -116,7 +119,7 @@ public class TemplateContentServlet extends BaseServlet
// get NodeRef to the template if supplied
NodeRef templateRef = null;
if (tokenCount >= 8)
if (tokenCount >= 7)
{
storeRef = new StoreRef(t.nextToken(), t.nextToken());
templateRef = new NodeRef(storeRef, t.nextToken());
@@ -165,7 +168,7 @@ public class TemplateContentServlet extends BaseServlet
}
// create the model - put the supplied noderef in as space/document as appropriate
Object model = getModel(serviceRegistry, req, res, nodeRef);
Object model = getModel(serviceRegistry, req, nodeRef);
// process the template against the node content directly to the response output stream
// assuming the repo is capable of streaming in chunks, this should allow large files
@@ -214,12 +217,12 @@ public class TemplateContentServlet extends BaseServlet
* 'person' and also includes the node specified on the servlet URL as 'space' and 'document'
*
* @param services ServiceRegistry required for TemplateNode construction
* @param session HttpSession for accessing current User
* @param req Http request - for accessing Session and url args
* @param nodeRef NodeRef of the space/document to process template against
*
* @return an object model ready for executing template against
*/
private Object getModel(ServiceRegistry services, HttpServletRequest req, HttpServletResponse res, NodeRef nodeRef)
private Object getModel(ServiceRegistry services, HttpServletRequest req, NodeRef nodeRef)
{
// build FreeMarker default model and merge
Map root = DefaultModelHelper.buildDefaultModel(services, Application.getCurrentUser(req.getSession()));
@@ -229,6 +232,16 @@ public class TemplateContentServlet extends BaseServlet
root.put("space", node);
root.put("document", node);
// add URL arguments as a map called 'args' to the root of the model
Map<String, String> args = new HashMap<String, String>(8, 1.0f);
Enumeration names = req.getParameterNames();
while (names.hasMoreElements())
{
String name = (String)names.nextElement();
args.put(name, req.getParameter(name));
}
root.put("args", args);
return root;
}

View File

@@ -18,6 +18,7 @@ package org.alfresco.web.app.servlet.command;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.alfresco.service.ServiceRegistry;
@@ -60,10 +61,10 @@ public interface CommandProcessor
* exception should be thrown to indicate this.
*
* @param serviceRegistry ServiceRegistry
* @param session HttpSession
* @param request HttpServletRequest
* @param command Name of the command to construct and execute
*/
public void process(ServiceRegistry serviceRegistry, HttpSession session, String command);
public void process(ServiceRegistry serviceRegistry, HttpServletRequest request, String command);
/**
* Output a simple status message to the supplied PrintWriter.

View File

@@ -39,8 +39,9 @@ public final class ExecuteScriptCommand implements Command
public static final String PROP_SCRIPT = "script";
public static final String PROP_DOCUMENT = "document";
public static final String PROP_USERPERSON = "person";
public static final String PROP_ARGS = "args";
private static final String[] PROPERTIES = new String[] {PROP_SCRIPT, PROP_DOCUMENT, PROP_USERPERSON};
private static final String[] PROPERTIES = new String[] {PROP_SCRIPT, PROP_DOCUMENT, PROP_USERPERSON, PROP_ARGS};
/**
@@ -90,6 +91,9 @@ public final class ExecuteScriptCommand implements Command
spaceRef,
DefaultModelHelper.imageResolver);
// add the url arguments map
model.put("args", properties.get(PROP_ARGS));
// execute the script and return the result
return serviceRegistry.getScriptService().executeScript(scriptRef, null, model);
}

View File

@@ -17,12 +17,14 @@
package org.alfresco.web.app.servlet.command;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.jscript.ScriptableHashMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
@@ -83,16 +85,27 @@ public final class ScriptCommandProcessor implements CommandProcessor
}
/**
* @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, java.lang.String)
* @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, javax.servlet.http.HttpServletRequest, java.lang.String)
*/
public void process(ServiceRegistry serviceRegistry, HttpSession session, String command)
public void process(ServiceRegistry serviceRegistry, HttpServletRequest request, String command)
{
Map<String, Object> properties = new HashMap<String, Object>(2, 1.0f);
Map<String, Object> properties = new HashMap<String, Object>(4, 1.0f);
properties.put(ExecuteScriptCommand.PROP_SCRIPT, this.scriptRef);
properties.put(ExecuteScriptCommand.PROP_DOCUMENT, this.docRef);
User user = Application.getCurrentUser(session);
User user = Application.getCurrentUser(request.getSession());
properties.put(ExecuteScriptCommand.PROP_USERPERSON, user.getPerson());
// add URL arguments as a special Scriptable Map property called 'args'
Map<String, String> args = new ScriptableHashMap<String, String>();
Enumeration names = request.getParameterNames();
while (names.hasMoreElements())
{
String name = (String)names.nextElement();
args.put(name, request.getParameter(name));
}
properties.put(ExecuteScriptCommand.PROP_ARGS, args);
Command cmd = CommandFactory.getInstance().createCommand(command);
if (cmd == null)
{

View File

@@ -20,6 +20,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -44,9 +45,9 @@ public final class WorkflowCommandProcessor extends BaseNodeCommandProcessor
}
/**
* @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, java.lang.String)
* @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, javax.servlet.http.HttpServletRequest, java.lang.String)
*/
public void process(ServiceRegistry serviceRegistry, HttpSession session, String command)
public void process(ServiceRegistry serviceRegistry, HttpServletRequest request, String command)
{
Map<String, Object> properties = new HashMap<String, Object>(1, 1.0f);
// all workflow commands use a "target" Node property as an argument

View File

@@ -334,6 +334,8 @@ public abstract class BaseDetailsBean
String formId = Utils.getParentForm(fc, event.getComponent()).getClientId(fc);
fc.addMessage(formId + ':' + getPropertiesPanelId(), facesMsg);
getNode().reset();
// commit the transaction
tx.commit();
}

View File

@@ -48,7 +48,6 @@ import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.web.app.AlfrescoNavigationHandler;
@@ -62,7 +61,7 @@ import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.NodePropertyResolver;
import org.alfresco.web.bean.repository.QNameNodeMap;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.wizard.NewSpaceWizard;
import org.alfresco.web.bean.spaces.CreateSpaceWizard;
import org.alfresco.web.config.ViewsConfigElement;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.Utils.URLMode;
@@ -950,7 +949,7 @@ public class BrowseBean implements IContextListener
public Object get(Node node) {
QNameNodeMap props = (QNameNodeMap)node.getProperties();
String icon = (String)props.getRaw("app:icon");
return (icon != null ? icon : NewSpaceWizard.SPACE_ICON_DEFAULT);
return (icon != null ? icon : CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
}
};
@@ -1083,7 +1082,6 @@ public class BrowseBean implements IContextListener
{
// user can either select a descendant of a node display on the page which means we
// must add the it's parent and itself to the breadcrumb
List<IBreadcrumbHandler> location = this.navigator.getLocation();
ChildAssociationRef parentAssocRef = nodeService.getPrimaryParent(nodeRef);
if (logger.isDebugEnabled())

View File

@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.transaction.UserTransaction;
@@ -64,6 +65,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
private static final String MSG_HAS_FOLLOWING_CATEGORIES = "has_following_categories";
private static final String MSG_NO_CATEGORIES_APPLIED = "no_categories_applied";
private static final String MSG_SUCCESS_UNLOCK = "success_unlock";
private static final String MSG_ERROR_ASPECT_INLINEEDITABLE = "error_aspect_inlineeditable";
private static final String MSG_ERROR_ASPECT_VERSIONING = "error_aspect_versioning";
private static final String MSG_ERROR_ASPECT_CLASSIFY = "error_aspect_classify";
@@ -820,6 +822,41 @@ public class DocumentDetailsBean extends BaseDetailsBean
}
}
/**
* Action Handler to unlock a locked document
*/
public void unlock(ActionEvent event)
{
FacesContext fc = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(fc);
tx.begin();
this.lockService.unlock(getNode().getNodeRef());
String msg = Application.getMessage(fc, MSG_SUCCESS_UNLOCK);
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
String formId = Utils.getParentForm(fc, event.getComponent()).getClientId(fc);
fc.addMessage(formId + ':' + getPropertiesPanelId(), facesMsg);
getNode().reset();
// commit the transaction
tx.commit();
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
fc, Repository.ERROR_GENERIC), e.getMessage()), e);
}
}
/**
* Applies the inlineeditable aspect to the current document
*/

View File

@@ -47,7 +47,7 @@ import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.bean.wizard.NewSpaceWizard;
import org.alfresco.web.bean.spaces.CreateSpaceWizard;
import org.alfresco.web.config.ClientConfigElement;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.IBreadcrumbHandler;
@@ -305,6 +305,7 @@ public class NavigationBean
*
* @return model containing current current space info.
*/
@SuppressWarnings("unchecked")
public Map getTemplateModel()
{
HashMap model = new HashMap(1, 1.0f);
@@ -375,7 +376,7 @@ public class NavigationBean
props = node.getProperties();
}
String icon = (String)props.get("app:icon");
props.put("icon", icon != null ? icon : NewSpaceWizard.SPACE_ICON_DEFAULT);
props.put("icon", icon != null ? icon : CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
Path path = this.nodeService.getPath(nodeRef);
// resolve CIFS network folder location for this node
@@ -617,6 +618,7 @@ public class NavigationBean
/**
* @see org.alfresco.web.ui.common.component.IBreadcrumbHandler#navigationOutcome(org.alfresco.web.ui.common.component.UIBreadcrumb)
*/
@SuppressWarnings("unchecked")
public String navigationOutcome(UIBreadcrumb breadcrumb)
{
// set the current node to the specified top level node ID

View File

@@ -53,7 +53,7 @@ import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.NodePropertyResolver;
import org.alfresco.web.bean.repository.QNameNodeMap;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.wizard.NewSpaceWizard;
import org.alfresco.web.bean.spaces.CreateSpaceWizard;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.Utils.URLMode;
import org.alfresco.web.ui.common.component.UIActionLink;
@@ -531,7 +531,7 @@ public class TrashcanBean implements IContextListener
public Object get(Node node) {
QNameNodeMap props = (QNameNodeMap)node.getProperties();
String icon = (String)props.getRaw("app:icon");
return "/images/icons/" + (icon != null ? icon : NewSpaceWizard.SPACE_ICON_DEFAULT) + ".gif";
return "/images/icons/" + (icon != null ? icon : CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME) + ".gif";
}
};
@@ -949,6 +949,7 @@ public class TrashcanBean implements IContextListener
/**
* @return the search query to use when displaying the list of deleted items
*/
@SuppressWarnings("deprecation")
private String buildSearchQuery()
{
String query;

View File

@@ -306,9 +306,10 @@ public class ClipboardBean
if (logger.isDebugEnabled())
logger.debug("Attempting to copy node ID: " + item.Node.getId() + " into node ID: " + destRef.getId());
if (dd.isSubClass(item.Node.getType(), ContentModel.TYPE_CONTENT))
if (dd.isSubClass(item.Node.getType(), ContentModel.TYPE_CONTENT) ||
dd.isSubClass(item.Node.getType(), ContentModel.TYPE_FOLDER))
{
// call the node ops service to initiate the copy
// copy the file/folder
this.fileFolderService.copy(
item.Node.getNodeRef(),
destRef,
@@ -316,6 +317,7 @@ public class ClipboardBean
}
else
{
// copy the node
this.copyService.copy(
item.Node.getNodeRef(),
destRef,
@@ -330,13 +332,14 @@ public class ClipboardBean
if (logger.isDebugEnabled())
logger.debug("Attempting to move node ID: " + item.Node.getId() + " into node ID: " + destRef.getId());
if (dd.isSubClass(item.Node.getType(), ContentModel.TYPE_CONTENT))
if (dd.isSubClass(item.Node.getType(), ContentModel.TYPE_CONTENT) ||
dd.isSubClass(item.Node.getType(), ContentModel.TYPE_FOLDER))
{
// move the node
// move the file/folder
this.fileFolderService.move(
item.Node.getNodeRef(),
destRef,
name); // TODO: could add "Copy of ..." here if move fails
name);
}
else
{

View File

@@ -1,21 +1,4 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the GNU Lesser General Public License as
* published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/lgpl.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
package org.alfresco.web.bean.forums;
import java.io.Serializable;
import java.text.MessageFormat;
@@ -23,7 +6,6 @@ import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -36,35 +18,64 @@ import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Backing bean class used to create discussions for documents
* Bean implementation for the "Create Discusssion Dialog".
*
* @author gavinc
*/
public class NewDiscussionWizard extends NewTopicWizard
public class CreateDiscussionDialog extends CreateTopicDialog
{
private static final Log logger = LogFactory.getLog(NewDiscussionWizard.class);
protected NodeRef discussingNodeRef;
private static final Log logger = LogFactory.getLog(CreateDiscussionDialog.class);
// ------------------------------------------------------------------------------
// Wizard implementation
private NodeRef discussingNodeRef;
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#startWizard(javax.faces.event.ActionEvent)
*/
@Override
public void startWizard(ActionEvent event)
public void init(Map<String, String> parameters)
{
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
super.init(parameters);
// get the id of the node we are creating the discussion for
String id = parameters.get("id");
if (id == null || id.length() == 0)
{
throw new AlfrescoRuntimeException("startDiscussion called without an id");
throw new AlfrescoRuntimeException("createDiscussion called without an id");
}
// create the topic to hold the discussions
createTopic(id);
}
@Override
public String cancel()
{
// if the user cancels the creation of a discussion all the setup that was done
// when the dialog started needs to be undone i.e. removing the created forum
// and the discussable aspect
deleteTopic();
// as we are cancelling the creation of a discussion we know we need to go back
// to the browse screen, this also makes sure we don't end up in the forum that
// just got deleted!
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME +
AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "browse";
}
// ------------------------------------------------------------------------------
// Helper methods
/**
* Creates a topic for the node with the given id
*
* @param id The id of the node to discuss
*/
protected void createTopic(String id)
{
FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
NodeRef forumNodeRef = null;
@@ -78,7 +89,7 @@ public class NewDiscussionWizard extends NewTopicWizard
if (this.nodeService.hasAspect(this.discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE))
{
throw new AlfrescoRuntimeException("startDiscussion called for an object that already has a discussion!");
throw new AlfrescoRuntimeException("createDiscussion called for an object that already has a discussion!");
}
// add the discussable aspect
@@ -123,23 +134,14 @@ public class NewDiscussionWizard extends NewTopicWizard
if (forumNodeRef != null)
{
this.browseBean.clickSpace(forumNodeRef);
// now initialise the wizard and navigate to it
super.startWizard(event);
context.getApplication().getNavigationHandler().handleNavigation(context, null, "dialog:createDiscussion");
}
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
* Deletes the setup performed during the initialisation of the dialog.
*/
@Override
public String cancel()
protected void deleteTopic()
{
// if we cancel the creation of a discussion all the setup that was done
// when the wizard started needs to be undone i.e. removing the created forum
// and the discussable aspect
FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
@@ -165,16 +167,5 @@ public class NewDiscussionWizard extends NewTopicWizard
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
context, Repository.ERROR_GENERIC), e.getMessage()), e);
}
// do cancel processing
super.cancel();
// as we are cancelling the creation of a discussion we know we need to go back
// to the browse screen, this also makes sure we don't end up in the forum that
// just got deleted!
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME +
AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "browse";
}
}

View File

@@ -0,0 +1,34 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ForumModel;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.spaces.CreateSpaceDialog;
/**
* Bean used to implement the "Create Forum Dialog".
*
* @author gavinc
*/
public class CreateForumDialog extends CreateSpaceDialog
{
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.spaceType = ForumModel.TYPE_FORUM.toString();
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "create_forum");
}
}

View File

@@ -0,0 +1,34 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ForumModel;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.spaces.CreateSpaceDialog;
/**
* Bean used to implement the "Create Forums Dialog".
*
* @author gavinc
*/
public class CreateForumsDialog extends CreateSpaceDialog
{
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.spaceType = ForumModel.TYPE_FORUMS.toString();
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "create_forums");
}
}

View File

@@ -0,0 +1,54 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ForumModel;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.content.CreateContentWizard;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
/**
* Bean implementation of the "New Post Dialog".
*
* @author gavinc
*/
public class CreatePostDialog extends CreateContentWizard
{
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// set up for creating a post
this.objectType = ForumModel.TYPE_POST.toString();
// make sure we don't show the edit properties dialog after creation
this.showOtherProperties = false;
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
// create appropriate values for filename and content type
this.fileName = ForumsBean.createPostFileName();
this.mimeType = Repository.getMimeTypeForFileName(
FacesContext.getCurrentInstance(), this.fileName);
// remove link breaks and replace with <br/>
this.content = Utils.replaceLineBreaks(this.content);
return super.finishImpl(context, outcome);
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "post");
}
}

View File

@@ -0,0 +1,93 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.Application;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation of the "Create Reply Dialog".
*
* @author gavinc
*/
public class CreateReplyDialog extends CreatePostDialog
{
protected String replyContent = null;
private static final Log logger = LogFactory.getLog(CreateReplyDialog.class);
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.replyContent = null;
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
// remove link breaks and replace with <br/>
this.content = Utils.replaceLineBreaks(this.content);
super.finishImpl(context, outcome);
// setup the referencing aspect with the references association
// between the new post and the one being replied to
this.nodeService.addAspect(this.createdNode, ContentModel.ASPECT_REFERENCING, null);
this.nodeService.createAssociation(this.createdNode, this.browseBean.getDocument().getNodeRef(),
ContentModel.ASSOC_REFERENCES);
if (logger.isDebugEnabled())
{
logger.debug("created new node: " + this.createdNode);
logger.debug("existing node: " + this.browseBean.getDocument().getNodeRef());
}
return outcome;
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "reply");
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Returns the content of the post we are replying to
*
* @return The content
*/
public String getReplyContent()
{
if (this.replyContent == null)
{
// get the content reader of the node we are replying to
NodeRef replyNode = this.browseBean.getDocument().getNodeRef();
if (replyNode != null)
{
ContentReader reader = this.contentService.getReader(replyNode, ContentModel.PROP_CONTENT);
if (reader != null)
{
this.replyContent = reader.getContentString();
}
}
}
return this.replyContent;
}
}

View File

@@ -0,0 +1,143 @@
package org.alfresco.web.bean.forums;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.spaces.CreateSpaceDialog;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation of the "Create Topic Dialog".
*
* @author gavinc
*/
public class CreateTopicDialog extends CreateSpaceDialog
{
protected String message;
protected ContentService contentService;
private static final Log logger = LogFactory.getLog(CreateTopicDialog.class);
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.spaceType = ForumModel.TYPE_TOPIC.toString();
this.message = null;
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
super.finishImpl(context, outcome);
// do topic specific processing
// get the node ref of the node that will contain the content
NodeRef containerNodeRef = this.createdNode;
// create a unique file name for the message content
String fileName = ForumsBean.createPostFileName();
FileInfo fileInfo = this.fileFolderService.create(containerNodeRef,
fileName, ForumModel.TYPE_POST);
NodeRef postNodeRef = fileInfo.getNodeRef();
if (logger.isDebugEnabled())
logger.debug("Created post node with filename: " + fileName);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, fileName);
this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_TITLED, titledProps);
if (logger.isDebugEnabled())
logger.debug("Added titled aspect with properties: " + titledProps);
Map<QName, Serializable> editProps = new HashMap<QName, Serializable>(1, 1.0f);
editProps.put(ContentModel.PROP_EDITINLINE, true);
this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_INLINEEDITABLE, editProps);
if (logger.isDebugEnabled())
logger.debug("Added inlineeditable aspect with properties: " + editProps);
// get a writer for the content and put the file
ContentWriter writer = contentService.getWriter(postNodeRef, ContentModel.PROP_CONTENT, true);
// set the mimetype and encoding
writer.setMimetype(Repository.getMimeTypeForFileName(context, fileName));
writer.setEncoding("UTF-8");
writer.putContent(Utils.replaceLineBreaks(this.message));
return outcome;
}
@Override
protected String doPostCommitProcessing(FacesContext context, String outcome)
{
// if the creation was successful we need to simulate a user
// selecting the topic, the dispatching will take us to the
// correct view.
this.browseBean.clickSpace(this.createdNode);
return outcome + AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "showTopic";
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "create_topic");
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Returns the message entered by the user for the first post
*
* @return The message for the first post
*/
public String getMessage()
{
return this.message;
}
/**
* Sets the message
*
* @param message The message
*/
public void setMessage(String message)
{
this.message = message;
}
// ------------------------------------------------------------------------------
// Service Injection
/**
* @param contentService The contentService to set.
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
}

View File

@@ -0,0 +1,82 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.ui.common.Utils;
import org.springframework.util.StringUtils;
/**
* Bean implementation for the "Edit Post Dialog".
*
* @author gavinc
*/
public class EditPostDialog extends CreatePostDialog
{
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// we need to remove the <br> tags and replace with carriage returns
// and then setup the content member variable
Node currentDocument = this.browseBean.getDocument();
ContentReader reader = this.contentService.getReader(currentDocument.getNodeRef(),
ContentModel.PROP_CONTENT);
if (reader != null)
{
String htmlContent = reader.getContentString();
if (htmlContent != null)
{
this.content = StringUtils.replace(htmlContent, "<br/>", "\r\n");
}
}
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
// remove link breaks and replace with <br/>
this.content = Utils.replaceLineBreaks(this.content);
// update the content
NodeRef postNode = this.browseBean.getDocument().getNodeRef();
// check that the name of this post does not contain the :
// character (used in previous versions), if it does rename
// the post.
String name = (String)this.nodeService.getProperty(
postNode, ContentModel.PROP_NAME);
if (name.indexOf(":") != -1)
{
String newName = name.replace(':', '-');
this.fileFolderService.rename(postNode, newName);
}
ContentWriter writer = this.contentService.getWriter(postNode,
ContentModel.PROP_CONTENT, true);
if (writer != null)
{
writer.putContent(this.content);
}
return outcome;
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "ok");
}
}

View File

@@ -14,7 +14,7 @@
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean;
package org.alfresco.web.bean.forums;
import java.io.IOException;
import java.io.Writer;
@@ -54,6 +54,8 @@ import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.IContextListener;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.BrowseBean;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.bean.repository.MapNode;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.NodePropertyResolver;

View File

@@ -212,6 +212,16 @@ public class CreateRuleWizard extends BaseActionWizard
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Determines whether the rule type drop down list should be enabled.
*
* @return false as the rule type drop down should be enabled
*/
public boolean getRuleTypeDisabled()
{
return false;
}
/**
* Returns the properties for all the conditions as a JSF DataModel
*

View File

@@ -136,6 +136,19 @@ public class EditRuleWizard extends CreateRuleWizard
return outcome;
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Determines whether the rule type drop down list should be enabled.
*
* @return true as the rule type drop down should be disabled
*/
public boolean getRuleTypeDisabled()
{
return true;
}
// ------------------------------------------------------------------------------
// Helper methods

View File

@@ -14,6 +14,9 @@ import org.alfresco.web.app.Application;
*/
public class CreateSpaceDialog extends CreateSpaceWizard
{
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public String getFinishButtonLabel()
{

View File

@@ -53,6 +53,7 @@ public class CreateSpaceWizard extends BaseWizardBean
protected String templateSpaceId;
protected String copyPolicy;
protected String name;
protected String title;
protected String description;
protected String templateName;
protected boolean saveAsTemplate;
@@ -63,6 +64,9 @@ public class CreateSpaceWizard extends BaseWizardBean
// the NodeRef of the node created during finish
protected NodeRef createdNode;
// ------------------------------------------------------------------------------
// Wizard implementation
/**
* Initialises the wizard
*/
@@ -85,7 +89,8 @@ public class CreateSpaceWizard extends BaseWizardBean
this.existingSpaceId = null;
this.templateSpaceId = null;
this.name = null;
this.description = "";
this.title = null;
this.description = null;
this.templateName = null;
this.saveAsTemplate = false;
}
@@ -122,7 +127,7 @@ public class CreateSpaceWizard extends BaseWizardBean
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(5);
uiFacetsProps.put(ContentModel.PROP_ICON, this.icon);
uiFacetsProps.put(ContentModel.PROP_TITLE, this.name);
uiFacetsProps.put(ContentModel.PROP_TITLE, this.title);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps);
@@ -141,7 +146,8 @@ public class CreateSpaceWizard extends BaseWizardBean
// copy from existing
NodeRef copiedNode = this.fileFolderService.copy(sourceNode, parentSpace, this.name).getNodeRef();
// also need to set the new description and icon properties
// also need to set the new title, description and icon properties
this.nodeService.setProperty(copiedNode, ContentModel.PROP_TITLE, this.title);
this.nodeService.setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.setProperty(copiedNode, ContentModel.PROP_ICON, this.icon);
@@ -160,7 +166,8 @@ public class CreateSpaceWizard extends BaseWizardBean
NodeRef parentSpace = new NodeRef(Repository.getStoreRef(), this.navigator.getCurrentNodeId());
// copy from the template
NodeRef copiedNode = this.fileFolderService.copy(sourceNode, parentSpace, this.name).getNodeRef();
// also need to set the new description and icon properties
// also need to set the new title, description and icon properties
this.nodeService.setProperty(copiedNode, ContentModel.PROP_TITLE, this.title);
this.nodeService.setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.setProperty(copiedNode, ContentModel.PROP_ICON, this.icon);
@@ -202,6 +209,9 @@ public class CreateSpaceWizard extends BaseWizardBean
return outcome;
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* @return Returns the copyPolicy.
*/
@@ -298,6 +308,22 @@ public class CreateSpaceWizard extends BaseWizardBean
this.name = name;
}
/**
* @return Returns the title.
*/
public String getTitle()
{
return title;
}
/**
* @param title The title to set.
*/
public void setTitle(String title)
{
this.title = title;
}
/**
* @return Returns the saveAsTemplate.
*/
@@ -642,6 +668,9 @@ public class CreateSpaceWizard extends BaseWizardBean
return icons;
}
// ------------------------------------------------------------------------------
// Helper methods
/**
* Formats the error message to display if an error occurs during finish processing
*

View File

@@ -1,36 +1,27 @@
package org.alfresco.web.bean.spaces;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.component.UIListItem;
/**
* Dialog bean to edit an existing space.
*
* @author gavinc
*/
public class EditSpaceDialog extends BaseDialogBean
public class EditSpaceDialog extends CreateSpaceDialog
{
protected Node editableNode;
@@ -41,6 +32,13 @@ public class EditSpaceDialog extends BaseDialogBean
// setup the space being edited
this.editableNode = this.browseBean.getActionSpace();
this.spaceType = this.editableNode.getType().toString();
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "ok");
}
/**
@@ -52,64 +50,6 @@ public class EditSpaceDialog extends BaseDialogBean
{
return this.editableNode;
}
/**
* Returns a list of icons to allow the user to select from.
* The list can change according to the type of space being created.
*
* @return A list of icons
*/
@SuppressWarnings("unchecked")
public List<UIListItem> getIcons()
{
List<UIListItem> icons = null;
QName type = QName.createQName(this.editableNode.getType().toString());
String typePrefixForm = type.toPrefixString(this.namespaceService);
Config config = Application.getConfigService(FacesContext.getCurrentInstance()).
getConfig(typePrefixForm + " icons");
if (config != null)
{
ConfigElement iconsCfg = config.getConfigElement("icons");
if (iconsCfg != null)
{
boolean first = true;
for (ConfigElement icon : iconsCfg.getChildren())
{
String iconName = icon.getAttribute("name");
String iconPath = icon.getAttribute("path");
if (iconName != null && iconPath != null)
{
if (first)
{
icons = new ArrayList<UIListItem>(iconsCfg.getChildCount());
first = false;
}
UIListItem item = new UIListItem();
item.setValue(iconName);
item.getAttributes().put("image", iconPath);
icons.add(item);
}
}
}
}
// if we didn't find any icons display one default choice
if (icons == null)
{
icons = new ArrayList<UIListItem>(1);
UIListItem item = new UIListItem();
item.setValue("space-icon-default");
item.getAttributes().put("image", "/images/icons/space-icon-default.gif");
icons.add(item);
}
return icons;
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
@@ -213,27 +153,4 @@ public class EditSpaceDialog extends BaseDialogBean
return outcome;
}
/**
* Formats the error message to display if an error occurs during finish processing
*
* @param The exception
* @return The formatted message
*/
@Override
protected String formatErrorMessage(Throwable exception)
{
if (exception instanceof FileExistsException)
{
return MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), Repository.ERROR_EXISTS),
((FileExistsException)exception).getExisting().getName());
}
else
{
return MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), "error_space"),
exception.getMessage());
}
}
}

View File

@@ -1,316 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
import java.io.File;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.FileUploadBean;
import org.alfresco.web.bean.repository.Repository;
/**
* Handler class used by the Add Content Wizard
*
* @author gavinc
*/
public class AddContentWizard extends BaseContentWizard
{
// TODO: retrieve these from the config service
private static final String WIZARD_TITLE_ID = "add_content_title";
private static final String WIZARD_DESC_ID = "add_content_desc";
private static final String STEP1_TITLE_ID = "add_conent_step1_title";
private static final String STEP1_DESCRIPTION_ID = "add_conent_step1_desc";
private static final String STEP2_TITLE_ID = "add_conent_step2_title";
private static final String STEP2_DESCRIPTION_ID = "add_conent_step2_desc";
// add content wizard specific properties
private File file;
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#next()
*/
public String next()
{
String outcome = super.next();
// if the outcome is "properties" we pre-set the content type and other
// fields accordingly
if (outcome.equals("properties"))
{
this.contentType = Repository.getMimeTypeForFileName(
FacesContext.getCurrentInstance(), this.fileName);
// set default for in-line editing flag
this.inlineEdit = (this.contentType.equals(MimetypeMap.MIMETYPE_HTML));
// Try and extract metadata from the file
ContentReader cr = new FileContentReader(this.file);
cr.setMimetype(this.contentType);
// create properties for content type
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(5, 1.0f);
if (Repository.extractMetadata(FacesContext.getCurrentInstance(), cr, contentProps))
{
this.author = (String)(contentProps.get(ContentModel.PROP_AUTHOR));
this.title = (String)(contentProps.get(ContentModel.PROP_TITLE));
this.description = (String)(contentProps.get(ContentModel.PROP_DESCRIPTION));
}
if (this.title == null)
{
this.title = this.fileName;
}
}
return outcome;
}
/**
* Deals with the finish button being pressed
*
* @return outcome
*/
public String finish()
{
String outcome = saveContent(this.file, null);
// now we know the new details are in the repository, reset the
// client side node representation so the new details are retrieved
if (this.editMode)
{
this.browseBean.getDocument().reset();
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
*/
public String getWizardDescription()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
*/
public String getWizardTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
*/
public String getStepDescription()
{
String stepDesc = null;
switch (this.currentStep)
{
case 1:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID);
break;
}
case 2:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID);
break;
}
case 3:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID);
break;
}
default:
{
stepDesc = "";
}
}
return stepDesc;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
*/
public String getStepTitle()
{
String stepTitle = null;
switch (this.currentStep)
{
case 1:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
break;
}
case 2:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
break;
}
case 3:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID);
break;
}
default:
{
stepTitle = "";
}
}
return stepTitle;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
clearUpload();
this.file = null;
}
/**
* @return Returns the message to display when a file has been uploaded
*/
public String getFileUploadSuccessMsg()
{
String msg = Application.getMessage(FacesContext.getCurrentInstance(), "file_upload_success");
return MessageFormat.format(msg, new Object[] {getFileName()});
}
/**
* @return Returns the name of the file
*/
public String getFileName()
{
// try and retrieve the file and filename from the file upload bean
// representing the file we previously uploaded.
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean)ctx.getExternalContext().getSessionMap().
get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null)
{
this.file = fileBean.getFile();
this.fileName = fileBean.getFileName();
}
return this.fileName;
}
/**
* @param fileName The name of the file
*/
public void setFileName(String fileName)
{
this.fileName = fileName;
// we also need to keep the file upload bean in sync
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean)ctx.getExternalContext().getSessionMap().
get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null)
{
fileBean.setFileName(this.fileName);
}
}
/**
* @return Returns the summary data for the wizard.
*/
public String getSummary()
{
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
return buildSummary(
new String[] {bundle.getString("file_name"), bundle.getString("type"),
bundle.getString("content_type"), bundle.getString("title"),
bundle.getString("description"), bundle.getString("author"),
bundle.getString("inline_editable")},
new String[] {this.fileName, getSummaryObjectType(), getSummaryContentType(), this.title,
this.description, this.author, Boolean.toString(this.inlineEdit)});
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
*/
protected String determineOutcomeForStep(int step)
{
String outcome = null;
switch(step)
{
case 1:
{
outcome = "upload";
break;
}
case 2:
{
outcome = "properties";
break;
}
case 3:
{
outcome = "summary";
break;
}
default:
{
outcome = CANCEL_OUTCOME;
}
}
return outcome;
}
/**
* Deletes the uploaded file and removes the FileUploadBean from the session
*/
private void clearUpload()
{
// delete the temporary file we uploaded earlier
if (this.file != null)
{
this.file.delete();
}
// remove the file upload bean from the session
FacesContext ctx = FacesContext.getCurrentInstance();
ctx.getExternalContext().getSessionMap().remove(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
}
}

View File

@@ -1,629 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
import java.io.File;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.transaction.UserTransaction;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.config.ConfigService;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.data.IDataContainer;
import org.alfresco.web.data.QuickSort;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Base Handler class used by the Content Wizards
*
* @author gavinc kevinr
*/
public abstract class BaseContentWizard extends AbstractWizardBean
{
private static Log logger = LogFactory.getLog(BaseContentWizard.class);
protected static final String FINISH_INSTRUCTION_ID = "content_finish_instruction";
// content wizard specific attributes
protected String fileName;
protected String author;
protected String title;
protected String description;
protected String contentType;
protected String objectType;
protected boolean inlineEdit;
protected List<SelectItem> contentTypes;
protected List<SelectItem> objectTypes;
protected ContentService contentService;
protected DictionaryService dictionaryService;
// the NodeRef of the node created during finish
protected NodeRef createdNode;
/**
* Save the specified content using the currently set wizard attributes
*
* @param fileContent File content to save
* @param strContent String content to save
*/
protected String saveContent(File fileContent, String strContent)
{
String outcome = FINISH_OUTCOME;
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
if (this.editMode)
{
// update the existing node in the repository
Node currentDocument = this.browseBean.getDocument();
NodeRef nodeRef = currentDocument.getNodeRef();
// move the file - location and name checks will be performed
this.fileFolderService.move(nodeRef, null, this.fileName);
// set up the content data
// update the modified timestamp and other content props
Map<QName, Serializable> contentProps = this.nodeService.getProperties(nodeRef);
contentProps.put(ContentModel.PROP_TITLE, this.title);
contentProps.put(ContentModel.PROP_DESCRIPTION, this.description);
// add author property
if (this.author != null && this.author.length() != 0)
{
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_AUTHOR) == false)
{
Map<QName, Serializable> authorProps = new HashMap<QName, Serializable>(1, 1.0f);
authorProps.put(ContentModel.PROP_AUTHOR, this.author);
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, authorProps);
}
else
{
contentProps.put(ContentModel.PROP_AUTHOR, this.author);
}
}
// set up content properties - copy or create the compound property
ContentData contentData = (ContentData)contentProps.get(ContentModel.PROP_CONTENT);
if (contentData == null)
{
contentData = new ContentData(null, this.contentType, 0L, "UTF-8");
}
else
{
contentData = new ContentData(
contentData.getContentUrl(),
this.contentType,
contentData.getSize(),
contentData.getEncoding());
}
contentProps.put(ContentModel.PROP_CONTENT, contentData);
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_INLINEEDITABLE) == false)
{
Map<QName, Serializable> editProps = new HashMap<QName, Serializable>(1, 1.0f);
editProps.put(ContentModel.PROP_EDITINLINE, this.inlineEdit);
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_INLINEEDITABLE, editProps);
}
else
{
contentProps.put(ContentModel.PROP_EDITINLINE, this.inlineEdit);
}
this.nodeService.setProperties(nodeRef, contentProps);
}
else
{
// get the node ref of the node that will contain the content
NodeRef containerNodeRef;
String nodeId = getNavigator().getCurrentNodeId();
if (nodeId == null)
{
containerNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
}
else
{
containerNodeRef = new NodeRef(Repository.getStoreRef(), nodeId);
}
FileInfo fileInfo = fileFolderService.create(
containerNodeRef,
this.fileName,
Repository.resolveToQName(this.objectType));
NodeRef fileNodeRef = fileInfo.getNodeRef();
// set the author aspect (if we have one)
if (this.author != null && this.author.length() > 0)
{
Map<QName, Serializable> authorProps = new HashMap<QName, Serializable>(1, 1.0f);
authorProps.put(ContentModel.PROP_AUTHOR, this.author);
this.nodeService.addAspect(fileNodeRef, ContentModel.ASPECT_AUTHOR, authorProps);
}
if (logger.isDebugEnabled())
logger.debug("Created file node for file: " + this.fileName);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, this.title);
titledProps.put(ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.addAspect(fileNodeRef, ContentModel.ASPECT_TITLED, titledProps);
if (logger.isDebugEnabled())
logger.debug("Added titled aspect with properties: " + titledProps);
// apply the inlineeditable aspect
if (this.inlineEdit == true)
{
Map<QName, Serializable> editProps = new HashMap<QName, Serializable>(1, 1.0f);
editProps.put(ContentModel.PROP_EDITINLINE, this.inlineEdit);
this.nodeService.addAspect(fileNodeRef, ContentModel.ASPECT_INLINEEDITABLE, editProps);
if (logger.isDebugEnabled())
logger.debug("Added inlineeditable aspect with properties: " + editProps);
}
// get a writer for the content and put the file
ContentWriter writer = contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
// set the mimetype and encoding
writer.setMimetype(this.contentType);
writer.setEncoding("UTF-8");
if (fileContent != null)
{
writer.putContent(fileContent);
}
else if (strContent != null)
{
writer.putContent(strContent);
}
// remember the created node now
this.createdNode = fileNodeRef;
}
// give subclasses a chance to perform custom processing before committing
performCustomProcessing();
// commit the transaction
tx.commit();
}
catch (FileExistsException e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
// print status message
String statusMsg = MessageFormat.format(
Application.getMessage(
FacesContext.getCurrentInstance(), "error_exists"),
e.getExisting().getName());
Utils.addErrorMessage(statusMsg);
// no outcome
outcome = null;
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e);
outcome = null;
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
*/
public String getStepInstructions()
{
String stepInstruction = null;
switch (this.currentStep)
{
case 3:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
break;
}
default:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
}
}
return stepInstruction;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
this.fileName = null;
this.author = null;
this.title = null;
this.description = null;
this.contentType = null;
this.inlineEdit = false;
this.contentTypes = null;
this.objectTypes = null;
this.objectType = ContentModel.TYPE_CONTENT.toString();
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#populate()
*/
public void populate()
{
// get hold of the current document and populate the appropriate values
Node currentDocument = this.browseBean.getDocument();
Map<String, Object> props = currentDocument.getProperties();
Boolean inline = (Boolean)props.get("editInline");
this.inlineEdit = inline != null ? inline.booleanValue() : false;
this.author = (String)props.get("creator");
this.contentType = null;
ContentData contentData = (ContentData)props.get(ContentModel.PROP_CONTENT);
if (contentData != null)
{
this.contentType = contentData.getMimetype();
}
this.description = (String)props.get("description");
this.fileName = currentDocument.getName();
this.title = (String)props.get("title");
}
/**
* @return Returns the contentService.
*/
public ContentService getContentService()
{
return contentService;
}
/**
* @param contentService The contentService to set.
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @return Returns the name of the file
*/
public String getFileName()
{
return this.fileName;
}
/**
* @param fileName The name of the file
*/
public void setFileName(String fileName)
{
this.fileName = fileName;
}
/**
* @return Returns the author
*/
public String getAuthor()
{
return this.author;
}
/**
* @param author Sets the author
*/
public void setAuthor(String author)
{
this.author = author;
}
/**
* @return Returns the content type currenty selected
*/
public String getContentType()
{
return this.contentType;
}
/**
* @param contentType Sets the currently selected content type
*/
public void setContentType(String contentType)
{
this.contentType = contentType;
}
/**
* @return Returns the object type currenty selected
*/
public String getObjectType()
{
return this.objectType;
}
/**
* @param objectType Sets the currently selected object type
*/
public void setObjectType(String objectType)
{
this.objectType = objectType;
}
/**
* @return Returns the description
*/
public String getDescription()
{
return this.description;
}
/**
* @param description Sets the description
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return Returns the title
*/
public String getTitle()
{
return this.title;
}
/**
* @param title Sets the title
*/
public void setTitle(String title)
{
this.title = title;
}
/**
* @return Returns the inline edit flag.
*/
public boolean isInlineEdit()
{
return this.inlineEdit;
}
/**
* @param inlineEdit The inline edit flag to set.
*/
public void setInlineEdit(boolean inlineEdit)
{
this.inlineEdit = inlineEdit;
}
/**
* @return Returns a list of content types to allow the user to select from
*/
public List<SelectItem> getContentTypes()
{
if (this.contentTypes == null)
{
this.contentTypes = new ArrayList<SelectItem>(80);
ServiceRegistry registry = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
MimetypeService mimetypeService = registry.getMimetypeService();
// get the mime type display names
Map<String, String> mimeTypes = mimetypeService.getDisplaysByMimetype();
for (String mimeType : mimeTypes.keySet())
{
this.contentTypes.add(new SelectItem(mimeType, mimeTypes.get(mimeType)));
}
// make sure the list is sorted by the values
QuickSort sorter = new QuickSort(this.contentTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
return this.contentTypes;
}
/**
* @return Returns a list of object types to allow the user to select from
*/
public List<SelectItem> getObjectTypes()
{
if (this.objectTypes == null)
{
FacesContext context = FacesContext.getCurrentInstance();
// add the well known object type to start with
this.objectTypes = new ArrayList<SelectItem>(5);
this.objectTypes.add(new SelectItem(ContentModel.TYPE_CONTENT.toString(),
Application.getMessage(context, "content")));
// add any configured content sub-types to the list
ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
Config wizardCfg = svc.getConfig("Content Wizards");
if (wizardCfg != null)
{
ConfigElement typesCfg = wizardCfg.getConfigElement("content-types");
if (typesCfg != null)
{
for (ConfigElement child : typesCfg.getChildren())
{
QName idQName = Repository.resolveToQName(child.getAttribute("name"));
if (idQName != null)
{
TypeDefinition typeDef = this.dictionaryService.getType(idQName);
if (typeDef != null)
{
if (this.dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT))
{
// try and get the display label from config
String label = Utils.getDisplayLabel(context, child);
// if there wasn't a client based label try and get it from the dictionary
if (label == null)
{
label = typeDef.getTitle();
}
// finally, just use the localname
if (label == null)
{
label = idQName.getLocalName();
}
this.objectTypes.add(new SelectItem(idQName.toString(), label));
}
else
{
logger.warn("Failed to add '" + child.getAttribute("name") +
"' to the list of content types as the type is not a subtype of cm:content");
}
}
else
{
logger.warn("Failed to add '" + child.getAttribute("name") +
"' to the list of content types as the type is not recognised");
}
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
else
{
logger.warn("Could not find 'content-types' configuration element");
}
}
else
{
logger.warn("Could not find 'Content Wizards' configuration section");
}
}
return this.objectTypes;
}
/**
* @return Determines whether the next and finish button should be enabled
*/
public boolean getNextFinishDisabled()
{
boolean disabled = false;
if (this.fileName == null || this.fileName.length() == 0 ||
this.title == null || this.title.length() == 0 ||
this.contentType == null)
{
disabled = true;
}
return disabled;
}
/**
* Returns the display label for the content type currently chosen
*
* @return The human readable version of the content type
*/
protected String getSummaryContentType()
{
ServiceRegistry registry = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
MimetypeService mimetypeService = registry.getMimetypeService();
// get the mime type display name
Map<String, String> mimeTypes = mimetypeService.getDisplaysByMimetype();
return mimeTypes.get(this.contentType);
}
/**
* Returns the display label for the currently selected object type
*
* @return The objevt type label
*/
protected String getSummaryObjectType()
{
String objType = null;
for (SelectItem item : this.getObjectTypes())
{
if (item.getValue().equals(this.objectType))
{
objType = item.getLabel();
break;
}
}
return objType;
}
/**
* Performs any processing sub classes may wish to do before commit is called
*/
protected void performCustomProcessing() throws Exception
{
// used by subclasses if necessary
}
}

View File

@@ -1,296 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
/**
* Handler class used by the Create In-line Content Wizard
*
* @author Kevin Roast
*/
public class CreateContentWizard extends BaseContentWizard
{
protected static final String CONTENT_TEXT = "txt";
protected static final String CONTENT_HTML = "html";
// TODO: retrieve these from the config service
private static final String WIZARD_TITLE_ID = "create_content_title";
private static final String WIZARD_DESC_ID = "create_content_desc";
private static final String STEP1_TITLE_ID = "create_content_step1_title";
private static final String STEP1_DESCRIPTION_ID = "create_content_step1_desc";
private static final String STEP2_TITLE_ID = "create_content_step2_title";
private static final String STEP2_DESCRIPTION_ID = "create_content_step2_desc";
private static final String STEP3_TITLE_ID = "create_content_step3_title";
private static final String STEP3_DESCRIPTION_ID = "create_content_step3_desc";
// create content wizard specific properties
protected String content;
protected String createType = CONTENT_HTML;
/**
* Deals with the finish button being pressed
*
* @return outcome
*/
public String finish()
{
return saveContent(null, this.content);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
*/
public String getWizardDescription()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
*/
public String getWizardTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
*/
public String getStepDescription()
{
String stepDesc = null;
switch (this.currentStep)
{
case 1:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID);
break;
}
case 2:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID);
break;
}
case 3:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_DESCRIPTION_ID);
break;
}
case 4:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID);
break;
}
default:
{
stepDesc = "";
}
}
return stepDesc;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
*/
public String getStepInstructions()
{
String stepInstruction = null;
switch (this.currentStep)
{
case 4:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
break;
}
default:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
}
}
return stepInstruction;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
*/
public String getStepTitle()
{
String stepTitle = null;
switch (this.currentStep)
{
case 1:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
break;
}
case 2:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
break;
}
case 3:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_TITLE_ID);
break;
}
case 4:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID);
break;
}
default:
{
stepTitle = "";
}
}
return stepTitle;
}
/**
* @return Returns the content from the edited form.
*/
public String getContent()
{
return this.content;
}
/**
* @param content The content to edit (should be clear initially)
*/
public void setContent(String content)
{
this.content = content;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
this.content = null;
// created content is inline editable by default
this.inlineEdit = true;
}
/**
* @return Returns the summary data for the wizard.
*/
public String getSummary()
{
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
// TODO: show first few lines of content here?
return buildSummary(
new String[] {bundle.getString("file_name"), bundle.getString("type"),
bundle.getString("content_type"), bundle.getString("title"),
bundle.getString("description"), bundle.getString("author")},
new String[] {this.fileName, getSummaryObjectType(), getSummaryContentType(),
this.title, this.description, this.author});
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
*/
protected String determineOutcomeForStep(int step)
{
String outcome = null;
switch(step)
{
case 1:
{
outcome = "select";
break;
}
case 2:
{
if (getCreateType().equals(CONTENT_HTML))
{
outcome = "create-html";
}
else if (getCreateType().equals(CONTENT_TEXT))
{
outcome = "create-text";
}
break;
}
case 3:
{
this.fileName = "newfile." + getCreateType();
this.contentType = Repository.getMimeTypeForFileName(
FacesContext.getCurrentInstance(), this.fileName);
this.title = this.fileName;
outcome = "properties";
break;
}
case 4:
{
outcome = "summary";
break;
}
default:
{
outcome = CANCEL_OUTCOME;
}
}
return outcome;
}
/**
* Create content type value changed by the user
*/
public void createContentChanged(ValueChangeEvent event)
{
// clear the content as HTML is not compatible with the plain text box etc.
this.content = null;
}
/**
* @return Returns the createType.
*/
public String getCreateType()
{
return this.createType;
}
/**
* @param createType The createType to set.
*/
public void setCreateType(String createType)
{
this.createType = createType;
}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the GNU Lesser General Public License as
* published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/lgpl.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
import org.alfresco.model.ForumModel;
import org.alfresco.web.app.AlfrescoNavigationHandler;
/**
* Wizard bean used for creating and editing forum spaces
*
* @author gavinc
*/
public class NewForumWizard extends NewSpaceWizard
{
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
*/
public void init()
{
super.init();
this.spaceType = ForumModel.TYPE_FORUM.toString();
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
*/
@Override
public String finish()
{
String outcome = super.finish();
// if we had a successful outcome from the creation close the dialog
if (outcome != null);
{
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
*/
@Override
public String cancel()
{
super.cancel();
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the GNU Lesser General Public License as
* published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/lgpl.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
import org.alfresco.model.ForumModel;
import org.alfresco.web.app.AlfrescoNavigationHandler;
/**
* Wizard bean used for creating and editing forums spaces
*
* @author gavinc
*/
public class NewForumsWizard extends NewSpaceWizard
{
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
*/
public void init()
{
super.init();
this.spaceType = ForumModel.TYPE_FORUMS.toString();
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
*/
@Override
public String finish()
{
String outcome = super.finish();
// if we had a successful outcome from the creation close the dialog
if (outcome != null);
{
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
*/
@Override
public String cancel()
{
super.cancel();
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
}

View File

@@ -1,168 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the GNU Lesser General Public License as
* published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/lgpl.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.bean.ForumsBean;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.springframework.util.StringUtils;
/**
* Backing bean for posting forum articles.
*
* @author gavinc
*/
public class NewPostWizard extends CreateContentWizard
{
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
*/
@Override
public void init()
{
super.init();
// set up for creating a post
this.objectType = ForumModel.TYPE_POST.toString();
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#startWizardForEdit(javax.faces.event.ActionEvent)
*/
@Override
public void startWizardForEdit(ActionEvent event)
{
// TODO: Allow action link to have multiple action listeners
// then we wouldn't need to have this coupling back
// to the browse bean in here
// we need to setup the content in the browse bean first
this.browseBean.setupContentAction(event);
super.startWizardForEdit(event);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#populate()
*/
@Override
public void populate()
{
super.populate();
// we need to remove the <br> tags and replace with carriage returns
// and then setup the content member variable
Node currentDocument = this.browseBean.getDocument();
ContentReader reader = this.contentService.getReader(currentDocument.getNodeRef(),
ContentModel.PROP_CONTENT);
if (reader != null)
{
String htmlContent = reader.getContentString();
if (htmlContent != null)
{
this.content = StringUtils.replace(htmlContent, "<br/>", "\r\n");
}
}
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
*/
@Override
public String finish()
{
if (this.editMode)
{
// remove the line breaks before the save
this.content = Utils.replaceLineBreaks(this.content);
}
else
{
// create appropriate values for filename and content type
this.fileName = ForumsBean.createPostFileName();
this.contentType = Repository.getMimeTypeForFileName(
FacesContext.getCurrentInstance(), this.fileName);
// remove link breaks and replace with <br/>
this.content = Utils.replaceLineBreaks(this.content);
}
String outcome = super.finish();
// if we had a successful outcome from the creation close the dialog
if (outcome != null);
{
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.BaseContentWizard#performCustomProcessing()
*/
@Override
protected void performCustomProcessing() throws Exception
{
if (this.editMode)
{
// update the content
NodeRef postNode = this.browseBean.getDocument().getNodeRef();
// check that the name of this post does not contain the :
// character (used in previous versions), if it does rename
// the post.
String name = (String)this.nodeService.getProperty(
postNode, ContentModel.PROP_NAME);
if (name.indexOf(":") != -1)
{
String newName = name.replace(':', '-');
this.fileFolderService.rename(postNode, newName);
}
ContentWriter writer = this.contentService.getWriter(postNode,
ContentModel.PROP_CONTENT, true);
if (writer != null)
{
writer.putContent(this.content);
}
}
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
*/
@Override
public String cancel()
{
super.cancel();
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
}

View File

@@ -1,142 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the GNU Lesser General Public License as
* published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/lgpl.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
import javax.faces.event.ActionEvent;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Backing bean for posting replies to forum articles.
*
* @author gavinc
*/
public class NewReplyWizard extends NewPostWizard
{
private static Log logger = LogFactory.getLog(NewReplyWizard.class);
private String replyContent = null;
/**
* Returns the content of the post we are replying to
*
* @return The content
*/
public String getReplyContent()
{
if (this.replyContent == null)
{
// get the content reader of the node we are replying to
NodeRef replyNode = this.browseBean.getDocument().getNodeRef();
if (replyNode != null)
{
ContentReader reader = this.contentService.getReader(replyNode, ContentModel.PROP_CONTENT);
if (reader != null)
{
this.replyContent = reader.getContentString();
}
}
}
return this.replyContent;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
*/
@Override
public void init()
{
super.init();
this.replyContent = null;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#startWizard(javax.faces.event.ActionEvent)
*/
@Override
public void startWizard(ActionEvent event)
{
super.startWizard(event);
// also setup the content in the browse bean
this.browseBean.setupContentAction(event);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
*/
@Override
public String finish()
{
// remove link breaks and replace with <br/>
this.content = Utils.replaceLineBreaks(this.content);
String outcome = super.finish();
// if we had a successful outcome from the creation close the dialog
if (outcome != null);
{
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.BaseContentWizard#performCustomProcessing()
*/
@Override
protected void performCustomProcessing()
{
if (this.editMode == false)
{
// setup the referencing aspect with the references association
// between the new post and the one being replied to
this.nodeService.addAspect(this.createdNode, ContentModel.ASPECT_REFERENCING, null);
this.nodeService.createAssociation(this.createdNode, this.browseBean.getDocument().getNodeRef(),
ContentModel.ASSOC_REFERENCES);
if (logger.isDebugEnabled())
{
logger.debug("created new node: " + this.createdNode);
logger.debug("existing node: " + this.browseBean.getDocument().getNodeRef());
}
}
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
*/
@Override
public String cancel()
{
super.cancel();
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
}

View File

@@ -1,974 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.transaction.UserTransaction;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.data.IDataContainer;
import org.alfresco.web.data.QuickSort;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIListItem;
import org.alfresco.web.ui.common.component.description.UIDescription;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Handler class used by the New Space Wizard
*
* @author gavinc
*/
public class NewSpaceWizard extends AbstractWizardBean
{
public static final String SPACE_ICON_DEFAULT = "space-icon-default";
private static Log logger = LogFactory.getLog(NewSpaceWizard.class);
// TODO: retrieve these from the config service
private static final String WIZARD_TITLE_ID = "new_space_title";
private static final String WIZARD_DESC_ID = "new_space_desc";
private static final String STEP1_TITLE_ID = "new_space_step1_title";
private static final String STEP1_DESCRIPTION_ID = "new_space_step1_desc";
private static final String STEP2_TITLE_ID = "new_space_step2_title";
private static final String STEP2_DESCRIPTION_ID = "new_space_step2_desc";
private static final String STEP3_TITLE_ID = "new_space_step3_title";
private static final String STEP3_DESCRIPTION_ID = "new_space_step3_desc";
private static final String FINISH_INSTRUCTION_ID = "new_space_finish_instruction";
private static final String ERROR = "error_space";
private static final String DEFAULT_SPACE_TYPE_ICON = "/images/icons/space.gif";
private static final String ICONS_LOOKUP_KEY = " icons";
// new space wizard specific properties
protected SearchService searchService;
protected NamespaceService namespaceService;
protected DictionaryService dictionaryService;
protected String spaceType;
protected String icon;
protected String createFrom;
protected NodeRef existingSpaceId;
protected String templateSpaceId;
protected String copyPolicy;
protected String name;
protected String description;
protected String templateName;
protected boolean saveAsTemplate;
protected List<SelectItem> templates;
protected List<UIListItem> folderTypes;
protected List<UIDescription> folderTypeDescriptions;
// the NodeRef of the node created during finish
protected NodeRef createdNode;
/**
* Deals with the finish button being pressed
*
* @return outcome
*/
public String finish()
{
String outcome = FINISH_OUTCOME;
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin();
if (this.editMode)
{
// update the existing node in the repository
Node currentSpace = this.browseBean.getActionSpace();
NodeRef nodeRef = currentSpace.getNodeRef();
// rename if necessary
fileFolderService.rename(nodeRef, this.name);
// update the properties
Map<QName, Serializable> properties = this.nodeService.getProperties(nodeRef);
properties.put(ContentModel.PROP_NAME, this.name);
properties.put(ContentModel.PROP_ICON, this.icon);
properties.put(ContentModel.PROP_DESCRIPTION, this.description);
// apply properties
this.nodeService.setProperties(nodeRef, properties);
}
else
{
String newSpaceId = null;
if (this.createFrom.equals("scratch"))
{
// create the space (just create a folder for now)
NodeRef parentNodeRef;
String nodeId = getNavigator().getCurrentNodeId();
if (nodeId == null)
{
parentNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
}
else
{
parentNodeRef = new NodeRef(Repository.getStoreRef(), nodeId);
}
FileInfo fileInfo = fileFolderService.create(
parentNodeRef,
this.name,
Repository.resolveToQName(this.spaceType));
NodeRef nodeRef = fileInfo.getNodeRef();
newSpaceId = nodeRef.getId();
if (logger.isDebugEnabled())
logger.debug("Created folder node with name: " + this.name);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(5);
uiFacetsProps.put(ContentModel.PROP_ICON, this.icon);
uiFacetsProps.put(ContentModel.PROP_TITLE, this.name);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps);
if (logger.isDebugEnabled())
logger.debug("Added uifacets aspect with properties: " + uiFacetsProps);
// remember the created node
this.createdNode = nodeRef;
}
else if (this.createFrom.equals("existing"))
{
// copy the selected space and update the name, description and icon
NodeRef sourceNode = this.existingSpaceId;
NodeRef parentSpace = new NodeRef(Repository.getStoreRef(), getNavigator().getCurrentNodeId());
// copy from existing
NodeRef copiedNode = this.fileFolderService.copy(sourceNode, parentSpace, this.name).getNodeRef();
// also need to set the new description and icon properties
this.nodeService.setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.setProperty(copiedNode, ContentModel.PROP_ICON, this.icon);
newSpaceId = copiedNode.getId();
if (logger.isDebugEnabled())
logger.debug("Copied space with id of " + sourceNode.getId() + " to " + this.name);
// remember the created node
this.createdNode = copiedNode;
}
else if (this.createFrom.equals("template"))
{
// copy the selected space and update the name, description and icon
NodeRef sourceNode = new NodeRef(Repository.getStoreRef(), this.templateSpaceId);
NodeRef parentSpace = new NodeRef(Repository.getStoreRef(), getNavigator().getCurrentNodeId());
// copy from the template
NodeRef copiedNode = this.fileFolderService.copy(sourceNode, parentSpace, this.name).getNodeRef();
// also need to set the new description and icon properties
this.nodeService.setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.setProperty(copiedNode, ContentModel.PROP_ICON, this.icon);
newSpaceId = copiedNode.getId();
if (logger.isDebugEnabled())
logger.debug("Copied template space with id of " + sourceNode.getId() + " to " + this.name);
// remember the created node
this.createdNode = copiedNode;
}
// if the user selected to save the space as a template space copy the new
// space to the templates folder
if (this.saveAsTemplate)
{
// get hold of the Templates node
DynamicNamespacePrefixResolver namespacePrefixResolver = new DynamicNamespacePrefixResolver(null);
namespacePrefixResolver.registerNamespace(NamespaceService.APP_MODEL_PREFIX, NamespaceService.APP_MODEL_1_0_URI);
String xpath = Application.getRootPath(FacesContext.getCurrentInstance()) + "/" +
Application.getGlossaryFolderName(FacesContext.getCurrentInstance()) + "/" +
Application.getSpaceTemplatesFolderName(FacesContext.getCurrentInstance());
NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
List<NodeRef> templateNodeList = this.searchService.selectNodes(
rootNodeRef,
xpath, null, namespacePrefixResolver, false);
if (templateNodeList.size() == 1)
{
// get the first item in the list as we from test above there is only one!
NodeRef templateNode = templateNodeList.get(0);
NodeRef sourceNode = new NodeRef(Repository.getStoreRef(), newSpaceId);
// copy this to the template location
fileFolderService.copy(sourceNode, templateNode, this.templateName);
}
}
}
// give subclasses a chance to perform custom processing before committing
performCustomProcessing(context);
// commit the transaction
tx.commit();
// now we know the new details are in the repository, reset the
// client side node representation so the new details are retrieved
String statusMsg = null;
if (this.editMode)
{
this.browseBean.getActionSpace().reset();
statusMsg = MessageFormat.format(Application.getMessage(context, "status_space_updated"),
new Object[]{this.name});
}
else
{
// add a message to inform the user that the creation was OK
statusMsg = MessageFormat.format(Application.getMessage(context, "status_space_created"),
new Object[]{this.name});
}
// add the status message
Utils.addStatusMessage(FacesMessage.SEVERITY_INFO, statusMsg);
}
catch (FileExistsException e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
// print status message
String statusMsg = MessageFormat.format(
Application.getMessage(
FacesContext.getCurrentInstance(), "error_exists"),
e.getExisting().getName());
Utils.addErrorMessage(statusMsg);
// no outcome
outcome = null;
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), ERROR), e.getMessage()), e);
outcome = null;
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
*/
public String getWizardDescription()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
*/
public String getWizardTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
*/
public String getStepDescription()
{
String stepDesc = null;
switch (this.currentStep)
{
case 1:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID);
break;
}
case 2:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID);
break;
}
case 3:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_DESCRIPTION_ID);
break;
}
case 4:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID);
break;
}
default:
{
stepDesc = "";
}
}
return stepDesc;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
*/
public String getStepTitle()
{
String stepTitle = null;
switch (this.currentStep)
{
case 1:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
break;
}
case 2:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
break;
}
case 3:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_TITLE_ID);
break;
}
case 4:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID);
break;
}
default:
{
stepTitle = "";
}
}
return stepTitle;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
*/
public String getStepInstructions()
{
String stepInstruction = null;
switch (this.currentStep)
{
case 4:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
break;
}
default:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
}
}
return stepInstruction;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
// clear the cached query results
if (this.templates != null)
{
this.templates.clear();
this.templates = null;
}
// reset all variables
this.createFrom = "scratch";
this.spaceType = ContentModel.TYPE_FOLDER.toString();
this.icon = null;
this.copyPolicy = "contents";
this.existingSpaceId = null;
this.templateSpaceId = null;
this.name = null;
this.description = "";
this.templateName = null;
this.saveAsTemplate = false;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#populate()
*/
public void populate()
{
// get hold of the current node and populate the appropriate values
Node currentSpace = browseBean.getActionSpace();
Map<String, Object> props = currentSpace.getProperties();
this.name = (String)props.get("name");
this.description = (String)props.get("description");
this.icon = (String)props.get("app:icon");
}
/**
* @return Returns the summary data for the wizard.
*/
public String getSummary()
{
String summaryCreateType = null;
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
if (this.createFrom.equals("scratch"))
{
summaryCreateType = bundle.getString("scratch");
}
else if (this.createFrom.equals("existing"))
{
summaryCreateType = bundle.getString("an_existing_space");
}
else if (this.createFrom.equals("template"))
{
summaryCreateType = bundle.getString("a_template");
}
// String summarySaveAsTemplate = this.saveAsTemplate ? bundle.getString("yes") : bundle.getString("no");
// bundle.getString("save_as_template"), bundle.getString("template_name")},
// summarySaveAsTemplate, this.templateName
String spaceTypeLabel = null;
for (UIListItem item : this.getFolderTypes())
{
if (item.getValue().equals(this.spaceType))
{
spaceTypeLabel = item.getLabel();
break;
}
}
return buildSummary(
new String[] {bundle.getString("space_type"), bundle.getString("name"),
bundle.getString("description"), bundle.getString("creating_from")},
new String[] {spaceTypeLabel, this.name, this.description, summaryCreateType});
}
/**
* @return Returns a list of template spaces currently in the system
*/
public List<SelectItem> getTemplateSpaces()
{
if (this.templates == null)
{
this.templates = new ArrayList<SelectItem>();
FacesContext context = FacesContext.getCurrentInstance();
String xpath = Application.getRootPath(context) + "/" + Application.getGlossaryFolderName(context) +
"/" + Application.getSpaceTemplatesFolderName(context) + "/*";
NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
NamespaceService resolver = Repository.getServiceRegistry(context).getNamespaceService();
List<NodeRef> results = this.searchService.selectNodes(rootNodeRef, xpath, null, resolver, false);
if (results.size() > 0)
{
for (NodeRef assocRef : results)
{
Node childNode = new Node(assocRef);
this.templates.add(new SelectItem(childNode.getId(), childNode.getName()));
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.templates, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
// add an entry (at the start) to instruct the user to select a template
this.templates.add(0, new SelectItem("none", Application.getMessage(FacesContext.getCurrentInstance(), "select_a_template")));
}
return this.templates;
}
/**
* Returns a list of UIListItem objects representing the folder types
* and also constructs the list of descriptions for each type
*
* @return List of UIListItem components
*/
@SuppressWarnings("unchecked")
public List<UIListItem> getFolderTypes()
{
if (this.folderTypes == null)
{
FacesContext context = FacesContext.getCurrentInstance();
this.folderTypes = new ArrayList<UIListItem>(2);
this.folderTypeDescriptions = new ArrayList<UIDescription>(2);
// add the well known 'container space' type to start with
UIListItem defaultItem = new UIListItem();
String defaultLabel = Application.getMessage(context, "container");
defaultItem.setValue(ContentModel.TYPE_FOLDER.toString());
defaultItem.setLabel(defaultLabel);
defaultItem.setTooltip(defaultLabel);
defaultItem.getAttributes().put("image", DEFAULT_SPACE_TYPE_ICON);
this.folderTypes.add(defaultItem);
UIDescription defaultDesc = new UIDescription();
defaultDesc.setControlValue(ContentModel.TYPE_FOLDER.toString());
defaultDesc.setText(Application.getMessage(context, "container_desc"));
this.folderTypeDescriptions.add(defaultDesc);
// add any configured content sub-types to the list
Config wizardCfg = Application.getConfigService(FacesContext.getCurrentInstance()).
getConfig("Space Wizards");
if (wizardCfg != null)
{
ConfigElement typesCfg = wizardCfg.getConfigElement("folder-types");
if (typesCfg != null)
{
for (ConfigElement child : typesCfg.getChildren())
{
QName idQName = Repository.resolveToQName(child.getAttribute("name"));
TypeDefinition typeDef = this.dictionaryService.getType(idQName);
if (typeDef != null &&
this.dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_FOLDER))
{
// try and get the display label from config
String label = Utils.getDisplayLabel(context, child);
// if there wasn't a client based label try and get it from the dictionary
if (label == null)
{
label = typeDef.getTitle();
}
// finally use the localname if we still haven't found a label
if (label == null)
{
label = idQName.getLocalName();
}
// resolve a description string for the type
String description = Utils.getDescription(context, child);
// if we don't have a local description just use the label
if (description == null)
{
description = label;
}
// extract the icon to use from the config
String icon = child.getAttribute("icon");
if (icon == null || icon.length() == 0)
{
icon = DEFAULT_SPACE_TYPE_ICON;
}
UIListItem item = new UIListItem();
item.getAttributes().put("value", idQName.toString());
item.getAttributes().put("label", label);
item.getAttributes().put("tooltip", label);
item.getAttributes().put("image", icon);
this.folderTypes.add(item);
UIDescription desc = new UIDescription();
desc.setControlValue(idQName.toString());
desc.setText(description);
this.folderTypeDescriptions.add(desc);
}
}
}
else
{
logger.warn("Could not find 'folder-types' configuration element");
}
}
else
{
logger.warn("Could not find 'Space Wizards' configuration section");
}
}
return this.folderTypes;
}
/**
* Returns a list of UIDescription objects for the folder types
*
* @return A list of UIDescription objects
*/
public List<UIDescription> getFolderTypeDescriptions()
{
if (this.folderTypeDescriptions == null)
{
// call the getFolderType method to construct the list
getFolderTypes();
}
return this.folderTypeDescriptions;
}
/**
* Returns a list of icons to allow the user to select from.
* The list can change according to the type of space being created.
*
* @return A list of icons
*/
@SuppressWarnings("unchecked")
public List<UIListItem> getIcons()
{
// NOTE: we can't cache this list as it depends on the space type
// which the user can change during the advanced space wizard
List<UIListItem> icons = null;
QName type = QName.createQName(this.spaceType);
String typePrefixForm = type.toPrefixString(this.namespaceService);
Config config = Application.getConfigService(FacesContext.getCurrentInstance()).
getConfig(typePrefixForm + ICONS_LOOKUP_KEY);
if (config != null)
{
ConfigElement iconsCfg = config.getConfigElement("icons");
if (iconsCfg != null)
{
boolean first = true;
for (ConfigElement icon : iconsCfg.getChildren())
{
String iconName = icon.getAttribute("name");
String iconPath = icon.getAttribute("path");
if (iconName != null && iconPath != null)
{
if (first)
{
// if this is the first icon create the list and make
// the first icon in the list the default
icons = new ArrayList<UIListItem>(iconsCfg.getChildCount());
if (this.icon == null)
{
// set the default if it is not already
this.icon = iconName;
}
first = false;
}
UIListItem item = new UIListItem();
item.setValue(iconName);
item.getAttributes().put("image", iconPath);
icons.add(item);
}
}
}
}
// if we didn't find any icons display one default choice
if (icons == null)
{
icons = new ArrayList<UIListItem>(1);
this.icon = SPACE_ICON_DEFAULT;
UIListItem item = new UIListItem();
item.setValue("space-icon-default");
item.getAttributes().put("image", "/images/icons/space-icon-default.gif");
icons.add(item);
}
return icons;
}
/**
* @return Returns the searchService.
*/
public SearchService getSearchService()
{
return searchService;
}
/**
* @param searchService The searchService to set.
*/
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
/**
* @param namespaceService The NamespaceService
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @return Returns the copyPolicy.
*/
public String getCopyPolicy()
{
return copyPolicy;
}
/**
* @param copyPolicy The copyPolicy to set.
*/
public void setCopyPolicy(String copyPolicy)
{
this.copyPolicy = copyPolicy;
}
/**
* @return Returns the createFrom.
*/
public String getCreateFrom()
{
return createFrom;
}
/**
* @param createFrom The createFrom to set.
*/
public void setCreateFrom(String createFrom)
{
this.createFrom = createFrom;
}
/**
* @return Returns the description.
*/
public String getDescription()
{
return description;
}
/**
* @param description The description to set.
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return Returns the existingSpaceId.
*/
public NodeRef getExistingSpaceId()
{
return existingSpaceId;
}
/**
* @param existingSpaceId The existingSpaceId to set.
*/
public void setExistingSpaceId(NodeRef existingSpaceId)
{
this.existingSpaceId = existingSpaceId;
}
/**
* @return Returns the icon.
*/
public String getIcon()
{
return icon;
}
/**
* @param icon The icon to set.
*/
public void setIcon(String icon)
{
this.icon = icon;
}
/**
* @return Returns the name.
*/
public String getName()
{
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name)
{
this.name = name;
}
/**
* @return Returns the saveAsTemplate.
*/
public boolean isSaveAsTemplate()
{
return saveAsTemplate;
}
/**
* @param saveAsTemplate The saveAsTemplate to set.
*/
public void setSaveAsTemplate(boolean saveAsTemplate)
{
this.saveAsTemplate = saveAsTemplate;
}
/**
* @return Returns the spaceType.
*/
public String getSpaceType()
{
return spaceType;
}
/**
* @param spaceType The spaceType to set.
*/
public void setSpaceType(String spaceType)
{
this.spaceType = spaceType;
}
/**
* @return Returns the templateName.
*/
public String getTemplateName()
{
return templateName;
}
/**
* @param templateName The templateName to set.
*/
public void setTemplateName(String templateName)
{
this.templateName = templateName;
}
/**
* @return Returns the templateSpaceId.
*/
public String getTemplateSpaceId()
{
return templateSpaceId;
}
/**
* @param templateSpaceId The templateSpaceId to set.
*/
public void setTemplateSpaceId(String templateSpaceId)
{
this.templateSpaceId = templateSpaceId;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
*/
protected String determineOutcomeForStep(int step)
{
String outcome = null;
switch(step)
{
case 1:
{
outcome = "create-from";
break;
}
case 2:
{
if (createFrom.equalsIgnoreCase("scratch"))
{
outcome = "from-scratch";
}
else if (createFrom.equalsIgnoreCase("existing"))
{
outcome = "from-existing";
}
else if (createFrom.equalsIgnoreCase("template"))
{
outcome = "from-template";
}
break;
}
case 3:
{
outcome = "details";
break;
}
case 4:
{
outcome = "summary";
break;
}
default:
{
outcome = CANCEL_OUTCOME;
}
}
return outcome;
}
/**
* Performs any processing sub classes may wish to do before commit is called
*
* @param context Faces context
*/
protected void performCustomProcessing(FacesContext context) throws Exception
{
// used by subclasses if necessary
}
}

View File

@@ -1,174 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the GNU Lesser General Public License as
* published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/lgpl.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wizard;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.bean.ForumsBean;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Wizard bean used for creating and editing topic spaces
*
* @author gavinc
*/
public class NewTopicWizard extends NewSpaceWizard
{
private static final Log logger = LogFactory.getLog(NewTopicWizard.class);
protected String message;
protected ContentService contentService;
/**
* Returns the message entered by the user for the first post
*
* @return The message for the first post
*/
public String getMessage()
{
return this.message;
}
/**
* Sets the message
*
* @param message The message
*/
public void setMessage(String message)
{
this.message = message;
}
/**
* @param contentService The contentService to set.
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
*/
public void init()
{
super.init();
this.spaceType = ForumModel.TYPE_TOPIC.toString();
this.message = null;
}
/**
* @see org.alfresco.web.bean.wizard.NewSpaceWizard#performCustomProcessing(javax.faces.context.FacesContext)
*/
@Override
protected void performCustomProcessing(FacesContext context) throws Exception
{
if (this.editMode == false)
{
// get the node ref of the node that will contain the content
NodeRef containerNodeRef = this.createdNode;
// create a unique file name for the message content
String fileName = ForumsBean.createPostFileName();
FileInfo fileInfo = this.fileFolderService.create(containerNodeRef,
fileName, ForumModel.TYPE_POST);
NodeRef postNodeRef = fileInfo.getNodeRef();
if (logger.isDebugEnabled())
logger.debug("Created post node with filename: " + fileName);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, fileName);
this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_TITLED, titledProps);
if (logger.isDebugEnabled())
logger.debug("Added titled aspect with properties: " + titledProps);
Map<QName, Serializable> editProps = new HashMap<QName, Serializable>(1, 1.0f);
editProps.put(ContentModel.PROP_EDITINLINE, true);
this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_INLINEEDITABLE, editProps);
if (logger.isDebugEnabled())
logger.debug("Added inlineeditable aspect with properties: " + editProps);
// get a writer for the content and put the file
ContentWriter writer = contentService.getWriter(postNodeRef, ContentModel.PROP_CONTENT, true);
// set the mimetype and encoding
writer.setMimetype(Repository.getMimeTypeForFileName(context, fileName));
writer.setEncoding("UTF-8");
writer.putContent(Utils.replaceLineBreaks(this.message));
}
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
*/
@Override
public String finish()
{
String outcome = super.finish();
// if we had a successful outcome work out the outcome to return
if (outcome != null)
{
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
if (this.editMode == false)
{
// if we are successful in creating the topic we need to setup
// the browse context for the new topic and pass an override
// outcome of 'showTopic'
this.browseBean.clickSpace(this.createdNode);
outcome = outcome + AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "showTopic";
}
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
*/
@Override
public String cancel()
{
super.cancel();
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
}

View File

@@ -45,6 +45,7 @@ import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.spaces.CreateSpaceWizard;
import org.alfresco.web.bean.users.UsersBean;
import org.alfresco.web.config.ClientConfigElement;
import org.alfresco.web.ui.common.Utils;
@@ -98,9 +99,6 @@ public class NewUserWizard extends AbstractWizardBean
/** action context */
private Node person = null;
/** ref to system people folder */
private NodeRef peopleRef = null;
/** ref to the company home space folder */
private NodeRef companyHomeSpaceRef = null;
@@ -497,7 +495,6 @@ public class NewUserWizard extends AbstractWizardBean
props.put(ContentModel.PROP_ORGID, this.companyId);
// create the node to represent the Person
String assocName = QName.createValidLocalName(this.userName);
NodeRef newPerson = this.personService.createPerson(props);
// ensure the user can access their own Person object
@@ -867,7 +864,6 @@ public class NewUserWizard extends AbstractWizardBean
*/
private NodeRef createHomeSpace(String locationId, String spaceName, boolean error)
{
String homeSpaceId = locationId;
NodeRef homeSpaceNodeRef = null;
if (spaceName != null && spaceName.length() != 0)
{
@@ -908,7 +904,7 @@ public class NewUserWizard extends AbstractWizardBean
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(3);
uiFacetsProps.put(ContentModel.PROP_ICON, NewSpaceWizard.SPACE_ICON_DEFAULT);
uiFacetsProps.put(ContentModel.PROP_ICON, CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
uiFacetsProps.put(ContentModel.PROP_TITLE, spaceName);
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps);
@@ -916,7 +912,6 @@ public class NewUserWizard extends AbstractWizardBean
// return the ID of the created space
homeSpaceNodeRef = nodeRef;
homeSpaceId = nodeRef.getId();
}
return homeSpaceNodeRef;