diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index ed3085aae7..21f7eb4299 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -125,7 +125,7 @@ kilobyte=KB megabyte=MB gigabyte=GB locked_you=Item locked by you -locked_user=Item locked by user +locked_user=Item locked by {0,choice,0#SHOULD_NOT_HAPPEN|1#user|1 p = AVMNodeConverter.ToAVMVersionPath(this.nodeRef); return (avmService.lookup(p.getFirst(), p.getSecond()) == null ? avmService.createFile(AVMNodeConverter.SplitBase(p.getSecond())[0], @@ -194,6 +212,11 @@ public class RenditionImpl this.getRenderingEngineTemplate().render(formInstanceData, this); } + private AVMService getAVMService() + { + return this.getServiceRegistry().getAVMService(); + } + private ServiceRegistry getServiceRegistry() { final FacesContext fc = FacesContext.getCurrentInstance(); diff --git a/source/java/org/alfresco/web/ui/repo/component/UILockIcon.java b/source/java/org/alfresco/web/ui/repo/component/UILockIcon.java index 5f4cd6619f..964996c493 100644 --- a/source/java/org/alfresco/web/ui/repo/component/UILockIcon.java +++ b/source/java/org/alfresco/web/ui/repo/component/UILockIcon.java @@ -25,6 +25,7 @@ package org.alfresco.web.ui.repo.component; import java.io.IOException; +import java.text.MessageFormat; import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; @@ -38,6 +39,7 @@ import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.component.SelfRenderingComponent; import org.alfresco.web.ui.repo.WebResources; +import org.springframework.util.StringUtils; /** * @author Kevin Roast @@ -79,16 +81,17 @@ public class UILockIcon extends SelfRenderingComponent */ public Object saveState(FacesContext context) { - Object values[] = new Object[7]; - // standard component attributes are saved by the super class - values[0] = super.saveState(context); - values[1] = this.lockImage; - values[2] = this.lockOwnerImage; - values[3] = this.align; - values[4] = this.width; - values[5] = this.height; - values[6] = this.value; - return (values); + return new Object[] + { + // standard component attributes are saved by the super class + super.saveState(context), + this.lockImage, + this.lockOwnerImage, + this.align, + this.width, + this.height, + this.value + }; } /** @@ -100,14 +103,10 @@ public class UILockIcon extends SelfRenderingComponent { return; } - - ResponseWriter out = context.getResponseWriter(); - + // get the value and see if the image is locked NodeService nodeService = getNodeService(context); - boolean locked = false; - boolean lockedOwner = false; - + String lockUser = null; Object val = getValue(); NodeRef ref = null; if (val instanceof NodeRef) @@ -115,15 +114,26 @@ public class UILockIcon extends SelfRenderingComponent ref = (NodeRef)val; if (nodeService.exists(ref) && nodeService.hasAspect(ref, ContentModel.ASPECT_LOCKABLE) == true) { - String lockerUser = (String)nodeService.getProperty(ref, ContentModel.PROP_LOCK_OWNER); - if (lockerUser != null) - { - locked = true; - lockedOwner = (lockerUser.equals(Application.getCurrentUser(context).getUserName())); - } + lockUser = (String)nodeService.getProperty(ref, ContentModel.PROP_LOCK_OWNER); } } - + final boolean locked = lockUser != null; + final boolean lockedOwner = locked && (lockUser.equals(Application.getCurrentUser(context).getUserName())); + + this.encodeBegin(context, locked, lockedOwner, new String[] { lockUser }); + } + + protected void encodeBegin(final FacesContext context, + final boolean locked, + final boolean lockedOwner, + final String[] lockUser) + throws IOException + { + if (isRendered() == false) + { + return; + } + ResponseWriter out = context.getResponseWriter(); String msg = null; if (locked == true) @@ -157,15 +167,14 @@ public class UILockIcon extends SelfRenderingComponent } else { - String lockingUser = (String)nodeService.getProperty(ref, ContentModel.PROP_LOCK_OWNER); - msg = Application.getMessage(context, MSG_LOCKED_USER); + msg = MessageFormat.format(Application.getMessage(context, MSG_LOCKED_USER), lockUser.length); if (getLockedUserTooltip() != null) { msg = getLockedUserTooltip(); } StringBuilder buf = new StringBuilder(32); msg = buf.append(msg).append(" '") - .append(lockingUser) + .append(StringUtils.arrayToDelimitedString(lockUser, ", ")) .append("'").toString(); } diff --git a/source/java/org/alfresco/web/ui/wcm/component/UIAVMLockIcon.java b/source/java/org/alfresco/web/ui/wcm/component/UIAVMLockIcon.java new file mode 100644 index 0000000000..319044f7c7 --- /dev/null +++ b/source/java/org/alfresco/web/ui/wcm/component/UIAVMLockIcon.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.ui.wcm.component; + +import java.io.IOException; +import java.util.List; + +import javax.faces.context.FacesContext; +import javax.faces.context.ResponseWriter; +import javax.faces.el.ValueBinding; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.avm.AVMNodeConverter; +import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.avm.locking.AVMLock; +import org.alfresco.service.cmr.avm.locking.AVMLockingService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.repository.User; +import org.alfresco.web.bean.wcm.WebProject; +import org.alfresco.web.ui.repo.component.UILockIcon; + +/** + * @author Ariel Backenroth + */ +public class UIAVMLockIcon extends UILockIcon +{ + // ------------------------------------------------------------------------------ + // Component implementation + + /** + * @see javax.faces.component.UIComponent#getFamily() + */ + public String getFamily() + { + return "org.alfresco.faces.AVMLockIcon"; + } + + + /** + * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext) + */ + public void encodeBegin(FacesContext context) throws IOException + { + if (isRendered() == false) + { + return; + } + + // get the value and see if the image is locked + final AVMService avmService = Repository.getServiceRegistry(context).getAVMService(); + final AVMLockingService avmLockingService = Repository.getServiceRegistry(context).getAVMLockingService(); + + boolean locked = false; + boolean lockedOwner = false; + Object val = getValue(); + List lockUser = null; + final String avmPath = (val instanceof NodeRef + ? AVMNodeConverter.ToAVMVersionPath((NodeRef)val).getSecond() + : (val instanceof String + ? (String)val + : null)); + if (avmPath != null) + { + if (avmService.lookup(-1, avmPath) != null) + { + final WebProject webProject = new WebProject(avmPath); + final AVMLock lock = avmLockingService.getLock(webProject.getStoreId(), avmPath.substring(avmPath.indexOf("/"))); + if (lock != null) + { + locked = true; + final User currentUser = Application.getCurrentUser(context); + lockUser = lock.getOwners(); + lockedOwner = (webProject.isManager(currentUser) || + lockUser.contains(currentUser.getUserName())); + } + } + } + this.encodeBegin(context, + locked, + lockedOwner, + lockUser == null ? new String[0] : (String[])lockUser.toArray(new String[lockUser.size()])); + } +} diff --git a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java index 3c0bc819bb..80cc5b98f9 100644 --- a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java +++ b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java @@ -719,6 +719,10 @@ public class UIUserSandboxes extends SelfRenderingComponent out.write(""); out.write(linkPrefix); out.write(name); + UIAVMLockIcon lockIcon = (UIAVMLockIcon)fc.getApplication().createComponent("org.alfresco.faces.AVMLockIcon"); + lockIcon.setId("lock_" + FacesHelper.makeLegalId(name)); + lockIcon.setValue(sourcePath); + Utils.encodeRecursive(fc, lockIcon); out.write(""); } else diff --git a/source/java/org/alfresco/web/ui/wcm/tag/AVMLockIconTag.java b/source/java/org/alfresco/web/ui/wcm/tag/AVMLockIconTag.java new file mode 100644 index 0000000000..e912e7cc55 --- /dev/null +++ b/source/java/org/alfresco/web/ui/wcm/tag/AVMLockIconTag.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.ui.wcm.tag; + +import org.alfresco.web.ui.repo.tag.LockIconTag; + +/** + * @author Ariel Backenroth + */ +public class AVMLockIconTag extends LockIconTag +{ + /** + * @see javax.faces.webapp.UIComponentTag#getComponentType() + */ + public String getComponentType() + { + return "org.alfresco.faces.AVMLockIcon"; + } +} diff --git a/source/test-resources/xforms/unit-tests/simple-test/simple-test.xsd b/source/test-resources/xforms/unit-tests/simple-test/simple-test.xsd index 57c240b012..f105a6ddb1 100644 --- a/source/test-resources/xforms/unit-tests/simple-test/simple-test.xsd +++ b/source/test-resources/xforms/unit-tests/simple-test/simple-test.xsd @@ -1,7 +1,7 @@ - + diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 0878f5ca5c..f1248b338e 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -2691,7 +2691,7 @@ avmService - #{AVMService} + #{AVMLockingAwareService} avmSyncService @@ -2913,7 +2913,7 @@ session avmService - #{AVMService} + #{AVMLockingAwareService} avmSyncService @@ -2927,10 +2927,6 @@ avmBrowseBean #{AVMBrowseBean} - - nodeService - #{NodeService} - filePickerBean #{FilePickerBean} diff --git a/source/web/WEB-INF/faces-config-wcm.xml b/source/web/WEB-INF/faces-config-wcm.xml index bba753278a..589d14f801 100644 --- a/source/web/WEB-INF/faces-config-wcm.xml +++ b/source/web/WEB-INF/faces-config-wcm.xml @@ -10,13 +10,13 @@ - org.alfresco.faces.UserSandboxes - org.alfresco.web.ui.wcm.component.UIUserSandboxes + org.alfresco.faces.SandboxSnapshots + org.alfresco.web.ui.wcm.component.UISandboxSnapshots - org.alfresco.faces.SandboxSnapshots - org.alfresco.web.ui.wcm.component.UISandboxSnapshots + org.alfresco.faces.AVMLockIcon + org.alfresco.web.ui.wcm.component.UIAVMLockIcon diff --git a/source/web/WEB-INF/wcm.tld b/source/web/WEB-INF/wcm.tld index dea1412e87..64354ccb27 100644 --- a/source/web/WEB-INF/wcm.tld +++ b/source/web/WEB-INF/wcm.tld @@ -411,4 +411,88 @@ + + avmLockIcon + org.alfresco.web.ui.wcm.tag.AVMLockIconTag + JSP + + + id + false + true + + + + binding + false + true + + + + rendered + false + true + + + + style + false + true + + + + styleClass + false + true + + + + lockImage + false + true + + + + lockOwnerImage + false + true + + + + align + false + true + + + + width + false + true + + + + height + false + true + + + + lockedOwnerTooltip + false + true + + + + lockedUserTooltip + false + true + + + + value + true + true + + + diff --git a/source/web/jsp/wcm/browse-sandbox.jsp b/source/web/jsp/wcm/browse-sandbox.jsp index 485ec50197..16a7f5b438 100644 --- a/source/web/jsp/wcm/browse-sandbox.jsp +++ b/source/web/jsp/wcm/browse-sandbox.jsp @@ -157,6 +157,7 @@ + <%-- Description column @@ -243,6 +244,7 @@ + <%-- Description column