diff --git a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java index 6e21797927..92c2d57d30 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java @@ -44,6 +44,7 @@ import javax.transaction.UserTransaction; import org.alfresco.config.ConfigElement; import org.alfresco.config.ConfigService; +import org.alfresco.config.JNDIConstants; import org.alfresco.linkvalidation.HrefValidationProgress; import org.alfresco.linkvalidation.LinkValidationService; import org.alfresco.model.ContentModel; @@ -539,7 +540,7 @@ public class AVMBrowseBean implements IContextListener */ public String getStagingPreviewUrl() { - return AVMUtil.buildWebappUrl(getStagingStore(), getWebapp()); + return(AVMUtil.getPreviewURI(getStagingStore(), '/' + JNDIConstants.DIR_DEFAULT_WWW + '/' + JNDIConstants.DIR_DEFAULT_APPBASE + '/' + getWebapp())); } /** @@ -547,7 +548,7 @@ public class AVMBrowseBean implements IContextListener */ public String getSandboxPreviewUrl() { - return AVMUtil.buildWebappUrl(getSandbox(), getWebapp()); + return(AVMUtil.getPreviewURI(getSandbox(), '/' + JNDIConstants.DIR_DEFAULT_WWW + '/' + JNDIConstants.DIR_DEFAULT_APPBASE + '/' + getWebapp())); } /** diff --git a/source/java/org/alfresco/web/bean/wcm/AVMNode.java b/source/java/org/alfresco/web/bean/wcm/AVMNode.java index 88441f440b..30bad51ca9 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMNode.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMNode.java @@ -70,14 +70,9 @@ public class AVMNode extends Node implements Map { return null; } - final ClientConfigElement config = - Application.getClientConfig(FacesContext.getCurrentInstance()); - final String dns = - AVMUtil.lookupStoreDNS(AVMUtil.getStoreName(node.getPath())); - return AVMUtil.buildAssetUrl(AVMUtil.getSandboxRelativePath(node.getPath()), - config.getWCMDomain(), - config.getWCMPort(), - dns); + final String storeId = AVMUtil.getStoreName(node.getPath()); + final String assetPath = AVMUtil.getStoreRelativePath(node.getPath()); + return AVMUtil.getPreviewURI(storeId, assetPath); } }; diff --git a/source/java/org/alfresco/web/bean/wcm/AVMUtil.java b/source/java/org/alfresco/web/bean/wcm/AVMUtil.java index 01484f7eef..5c2bb2fc53 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMUtil.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMUtil.java @@ -36,7 +36,6 @@ import org.alfresco.config.ConfigElement; import org.alfresco.config.ConfigService; import org.alfresco.config.JNDIConstants; import org.alfresco.mbeans.VirtServerRegistry; -import org.alfresco.model.ContentModel; import org.alfresco.model.WCMAppModel; import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.repo.domain.PropertyValue; @@ -52,7 +51,12 @@ import org.alfresco.service.namespace.QName; import org.alfresco.util.VirtServerUtils; import org.alfresco.web.app.Application; import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wcm.preview.PreviewURIService; +import org.alfresco.web.bean.wcm.preview.VirtualisationServerPreviewURIService; import org.alfresco.web.config.ClientConfigElement; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.jsf.FacesContextUtils; /** @@ -603,6 +607,30 @@ public final class AVMUtil return MessageFormat.format(JNDIConstants.PREVIEW_ASSET_URL, dns, domain, port, assetPath); } + public static String getPreviewURI(final String storeId, final String assetPath) + { + if (previewURIGenerator == null) + { + WebApplicationContext wac = FacesContextUtils.getRequiredWebApplicationContext( + FacesContext.getCurrentInstance()); + + if (wac.containsBean(SPRING_BEAN_NAME_PREVIEW_URI_SERVICE)) + { + // if the bean is present retrieve it + previewURIGenerator = (PreviewURIService)wac.getBean(SPRING_BEAN_NAME_PREVIEW_URI_SERVICE, + PreviewURIService.class); + } + else + { + // Backwards compatibility - if the new Spring bean doesn't exist, default to the + // existing behaviour (create a URL to the virtualisation server). + previewURIGenerator = new VirtualisationServerPreviewURIService(); + } + } + + return previewURIGenerator.getPreviewURI(storeId, assetPath); + } + public static String lookupStoreDNS(String store) { if (store == null || store.length() == 0) @@ -987,4 +1015,7 @@ public final class AVMUtil private static ConfigElement deploymentConfig = null; private static ConfigElement linksManagementConfig = null; + + private final static String SPRING_BEAN_NAME_PREVIEW_URI_SERVICE = "PreviewURIService"; + private static PreviewURIService previewURIGenerator = null; } diff --git a/source/java/org/alfresco/web/bean/wcm/preview/NullPreviewURIService.java b/source/java/org/alfresco/web/bean/wcm/preview/NullPreviewURIService.java new file mode 100644 index 0000000000..ce536d3cc8 --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/preview/NullPreviewURIService.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2005-2008 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 received 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.bean.wcm.preview; + + +/** + * A PreviewURIService that always returns null (no preview URI). + * + * @author Peter Monks (peter.monks@alfresco.com) + * @version $Id$ + */ +public class NullPreviewURIService + implements PreviewURIService +{ + /** + * @see org.alfresco.web.bean.wcm.preview.PreviewURIService#getPreviewURI(java.lang.String, java.lang.String) + */ + public String getPreviewURI(final String storeId, final String webapp) + { + return(null); + } + +} \ No newline at end of file diff --git a/source/java/org/alfresco/web/bean/wcm/preview/PreviewURIService.java b/source/java/org/alfresco/web/bean/wcm/preview/PreviewURIService.java new file mode 100644 index 0000000000..de30a87ca8 --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/preview/PreviewURIService.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2005-2008 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 received 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.bean.wcm.preview; + + +/** + * Abstraction for generating preview URLs. + * + * @author Peter Monks (peter.monks@alfresco.com) + * @version $Id$ + */ +public interface PreviewURIService +{ + /** + * @param storeId The id of the store to generate the preview URI for. + * @param pathToAsset The path to the asset to generate the preview URI for. + * @return The Preview URI for the given store id and/or asset (may be null). + */ + String getPreviewURI(String storeId, String pathToAsset); +} diff --git a/source/java/org/alfresco/web/bean/wcm/preview/StoreSpecificPreviewURIService.java b/source/java/org/alfresco/web/bean/wcm/preview/StoreSpecificPreviewURIService.java new file mode 100644 index 0000000000..1f9c22e686 --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/preview/StoreSpecificPreviewURIService.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2005-2008 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 received 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.bean.wcm.preview; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.alfresco.util.Pair; + + +/** + * A PreviewURIService that proxies requests to underlying PreviewURIGenerator implementations based on the store that the Preview URI + * is being generated for. + * + * @author Peter Monks (peter.monks@alfresco.com) + * @version $Id$ + */ +public class StoreSpecificPreviewURIService + implements PreviewURIService +{ + private final List> storeURIGenerators; + private final PreviewURIService fallback; + + + public StoreSpecificPreviewURIService(final List> storeURIGenerators) + { + this(storeURIGenerators, null); + } + + + public StoreSpecificPreviewURIService(final List> storeURIGenerators, + final PreviewURIService fallback) + { + List> compiledStoreURIGenerators = null; + + // Iterate through the list, compiling all of the regex strings into Pattern objects + if (storeURIGenerators != null) + { + Iterator> iter = storeURIGenerators.iterator(); + + compiledStoreURIGenerators = new ArrayList>(storeURIGenerators.size()); + + while (iter.hasNext()) + { + Pair pair = iter.next(); + + if (pair != null) + { + String regex = pair.getFirst(); + + if (regex != null && regex.trim().length() > 0) + { + Pattern pattern = Pattern.compile(regex); + compiledStoreURIGenerators.add(new Pair(pattern, pair.getSecond())); + } + } + } + } + + // We make the list unmodifiable to ensure correct behaviour in the presence of concurrent (multi-threaded) invocations. + this.storeURIGenerators = Collections.unmodifiableList(compiledStoreURIGenerators); + this.fallback = fallback == null ? new VirtualisationServerPreviewURIService() : fallback; + } + + + /** + * @see org.alfresco.web.bean.wcm.preview.PreviewURIService#getPreviewURI(java.lang.String, java.lang.String) + */ + public String getPreviewURI(final String storeId, final String pathToAsset) + { + String result = null; + boolean resultFound = false; + + if (storeURIGenerators != null) + { + Iterator> iter = storeURIGenerators.iterator(); + + while (iter.hasNext()) + { + Pair pair = iter.next(); + Matcher matcher = pair.getFirst().matcher(storeId); + + if (matcher.matches()) + { + result = pair.getSecond().getPreviewURI(storeId, pathToAsset); + resultFound = true; + break; + } + } + } + + // We didn't find an impl for the given store, so use the fallback impl + if (!resultFound) + { + result = fallback.getPreviewURI(storeId, pathToAsset); + } + + return(result); + } +} diff --git a/source/java/org/alfresco/web/bean/wcm/preview/URITemplatePreviewURIService.java b/source/java/org/alfresco/web/bean/wcm/preview/URITemplatePreviewURIService.java new file mode 100644 index 0000000000..5663a9862f --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/preview/URITemplatePreviewURIService.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005-2008 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 received 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.bean.wcm.preview; + + +/** + * A PreviewURIService that takes a URI template and replaces the following parameters per request: + *
    + *
  • {storeId} - the store Id of the preview request
  • + *
  • {pathToAsset} - the full path and filename of the asset being previewed (including a leading '/')
  • + *
+ * + * @author Peter Monks (peter.monks@alfresco.com) + * @version $Id$ + */ +public class URITemplatePreviewURIService + implements PreviewURIService +{ + private final static String URI_TEMPLATE_PARAMETER_STORE_ID = "{storeId}"; + private final static String URI_TEMPLATE_PARAMETER_PATH_TO_ASSET = "{pathToAsset}"; + + + private final String uriTemplate; + + + public URITemplatePreviewURIService(final String uriTemplate) + { + // PRECONDITIONS + assert uriTemplate != null : "uriTemplate must not be null."; + + // Body + this.uriTemplate = uriTemplate; + } + + + /** + * @see org.alfresco.web.bean.wcm.preview.PreviewURIService#getPreviewURI(java.lang.String, java.lang.String) + */ + public String getPreviewURI(final String storeId, final String pathToAsset) + { + String result = uriTemplate; + + if (uriTemplate.contains(URI_TEMPLATE_PARAMETER_STORE_ID)) + { + if (storeId != null && storeId.trim().length() > 0) + { + result = result.replace(URI_TEMPLATE_PARAMETER_STORE_ID, storeId); + } + else + { + // Shouldn't ever happen (store ids are always provided), but better to be safe than sorry + result = result.replace(URI_TEMPLATE_PARAMETER_STORE_ID, ""); + } + } + + if (uriTemplate.contains(URI_TEMPLATE_PARAMETER_PATH_TO_ASSET)) + { + if (pathToAsset != null && pathToAsset.trim().length() > 0) + { + result = result.replace(URI_TEMPLATE_PARAMETER_PATH_TO_ASSET, pathToAsset); + } + else + { + result = result.replace(URI_TEMPLATE_PARAMETER_PATH_TO_ASSET, ""); + } + } + + return(result); + } + +} diff --git a/source/java/org/alfresco/web/bean/wcm/preview/VirtualisationServerPreviewURIService.java b/source/java/org/alfresco/web/bean/wcm/preview/VirtualisationServerPreviewURIService.java new file mode 100644 index 0000000000..269635f74c --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/preview/VirtualisationServerPreviewURIService.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2005-2008 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 received 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.bean.wcm.preview; + +import org.alfresco.config.JNDIConstants; +import org.alfresco.web.bean.wcm.AVMUtil; + + +/** + * A PreviewURIService that constructs a virtualisation server URI. + * + * @author Peter Monks (peter.monks@alfresco.com) + * @version $Id$ + */ +public class VirtualisationServerPreviewURIService + implements PreviewURIService +{ + /** + * @see org.alfresco.web.bean.wcm.preview.PreviewURIService#getPreviewURI(java.lang.String, java.lang.String) + */ + public String getPreviewURI(final String storeId, final String pathToAsset) + { + // Sanity checking + if (!pathToAsset.startsWith('/' + JNDIConstants.DIR_DEFAULT_WWW + '/' + JNDIConstants.DIR_DEFAULT_APPBASE)) + { + throw new IllegalStateException("Invalid asset path in AVM node ref: " + storeId + ":" + pathToAsset); + } + + return(AVMUtil.buildAssetUrl(storeId, pathToAsset)); + } + +} + diff --git a/source/java/org/alfresco/web/bean/workflow/StartWorkflowWizard.java b/source/java/org/alfresco/web/bean/workflow/StartWorkflowWizard.java index 4631a32671..4d4d605392 100644 --- a/source/java/org/alfresco/web/bean/workflow/StartWorkflowWizard.java +++ b/source/java/org/alfresco/web/bean/workflow/StartWorkflowWizard.java @@ -61,6 +61,8 @@ import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.bean.repository.TransientNode; import org.alfresco.web.bean.wizard.BaseWizardBean; +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.UIActionLink; import org.alfresco.web.ui.common.component.data.UIRichList; @@ -601,6 +603,13 @@ public class StartWorkflowWizard extends BaseWizardBean { initializeWorkflows(); } + + // Alphabetical list sorting + // Fix bug reported in https://issues.alfresco.com/browse/ETWOTWO-302 + + QuickSort sorter = new QuickSort(availableWorkflows, "label", true, IDataContainer.SORT_CASEINSENSITIVE); + sorter.sort(); + return availableWorkflows; } 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 e2768f8afb..c780be6a48 100644 --- a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java +++ b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java @@ -44,6 +44,7 @@ import javax.faces.context.ResponseWriter; import javax.faces.el.ValueBinding; import javax.transaction.UserTransaction; +import org.alfresco.config.JNDIConstants; import org.alfresco.model.WCMAppModel; import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.repo.web.scripts.FileTypeImageUtils; @@ -421,7 +422,7 @@ public class UIUserSandboxes extends SelfRenderingComponent implements Serializa out.write(""); // Preview Website - String websiteUrl = AVMUtil.buildWebappUrl(mainStore, getWebapp()); + String websiteUrl = AVMUtil.getPreviewURI(mainStore, '/' + JNDIConstants.DIR_DEFAULT_WWW + '/' + JNDIConstants.DIR_DEFAULT_APPBASE + '/' + getWebapp()); Map requestMap = context.getExternalContext().getRequestMap(); requestMap.put(REQUEST_PREVIEW_REF, websiteUrl); Utils.encodeRecursive(context, aquireAction( @@ -843,8 +844,7 @@ public class UIUserSandboxes extends SelfRenderingComponent implements Serializa // build node context required for actions AVMNode avmNode = new AVMNode(node); String assetPath = sourcePath.substring(rootPathIndex); - String previewUrl = AVMUtil.buildAssetUrl( - assetPath, config.getWCMDomain(), config.getWCMPort(), dns); + String previewUrl = AVMUtil.getPreviewURI(userStore, assetPath); avmNode.getProperties().put("previewUrl", previewUrl); // size of files