### Eclipse Workspace Patch 1.0 #P Ametys - 05 Plugin Explorer Index: main/plugin-explorer/resources_nodetypes.xml =================================================================== --- main/plugin-explorer/resources_nodetypes.xml (revision 15614) +++ main/plugin-explorer/resources_nodetypes.xml (working copy) @@ -14,12 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. --> - + nt:folder - ametys:object + ametys:virtualAware + #P Ametys - 08 WEB Index: main/plugin-web/i18n/messages_en.xml =================================================================== --- main/plugin-web/i18n/messages_en.xml (revision 15614) +++ main/plugin-web/i18n/messages_en.xml (working copy) @@ -1952,6 +1952,10 @@ The scheduled rebuilt of live workspace failed. Your sites are potentially in an unstable state. The full stack trace of the error is displayed at the bottom of this email. You can try a manual rebuild on administration screen to the url : [{0}] Detection of an infinite redirection An infinite redirection was detected on site "{0}". The problem lies in the site map at page '{1}'. This page and its sub-pages have not been published. A infinite redirection is caused by series of page of redirection and/or node pages, leading to a redirection loop. Example: page redirects to page B which redirects to the page A. To correct this problem, go to the CMS to the url {2} and edit or delete one of theses redirections. - + + + Shared resources + Shared resources + Shared resources for all websites, if you disable this option, it won't delete the content of the shared folder but it will be hide for users. \ No newline at end of file Index: main/plugin-web/i18n/messages_fr.xml =================================================================== --- main/plugin-web/i18n/messages_fr.xml (revision 15614) +++ main/plugin-web/i18n/messages_fr.xml (working copy) @@ -1954,5 +1954,9 @@ [{0}] Détection d'une redirection infinie Une redirection infinie a été détectée sur le site "{0}". Le problème se situe dans l'arborescence au niveau de la page '{1}'. Cette page et sa sous-arborescence n'ont pas été mises en ligne. Une redirection infinie est provoquée par un enchaînement de pages de redirection et/ou de pages noeuds, menant à une redirection en boucle. Exemple : la page A redirige vers la page B qui elle-même redirige vers la page A. Pour corriger ce problème, rendez vous sur le CMS à l'url {2} et modifiez ou supprimez une des redirections. + + Ressources partagées + Ressources partargées + Ressources partagées pour tous les sites, la désactivation de cette option ne supprime pas le contenu du répertoire de ressources partagées mais cela rend invisible le répertoire de partage aux utilisateurs. \ No newline at end of file Index: main/plugin-web/plugin.xml =================================================================== --- main/plugin-web/plugin.xml (revision 15614) +++ main/plugin-web/plugin.xml (working copy) @@ -8340,4 +8340,32 @@ class="org.ametys.web.inputdata.SitemapInputDataCachePolicy"/> + + + + + + PLUGINS_WEB_RESOURCES_SHARED_FOLDER_DESCRIPTION + false + plugin.cms:PLUGINS_CMS_CONFIG_CATEGORY_CMS + plugin.cms:PLUGINS_CMS_CONFIG_CATEGORY_CMS_PARAMS_GROUP + + + + + + + + + + + + + + + Index: main/plugin-web/src/org/ametys/web/Init.java =================================================================== --- main/plugin-web/src/org/ametys/web/Init.java (revision 15614) +++ main/plugin-web/src/org/ametys/web/Init.java (working copy) @@ -16,8 +16,15 @@ package org.ametys.web; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.jcr.Node; import javax.jcr.Repository; +import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.Value; import javax.jcr.observation.Event; import javax.jcr.observation.ObservationManager; @@ -25,13 +32,17 @@ import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; +import org.apache.jackrabbit.value.StringValue; +import org.ametys.plugins.explorer.resources.jcr.JCRResourcesCollection; import org.ametys.plugins.repository.AmetysObjectResolver; import org.ametys.plugins.repository.jcr.DefaultTraversableAmetysObject; import org.ametys.plugins.repository.provider.AdminSessionProvider; +import org.ametys.runtime.config.Config; import org.ametys.web.live.LiveWorkspaceListener; import org.ametys.web.repository.site.Site; import org.ametys.web.repository.site.SiteManager; +import org.ametys.web.resources.proxy.VirtualProxyFactory; import org.ametys.web.synchronization.SynchronizeComponent; /** @@ -84,12 +95,41 @@ { root.createChild("ametys:plugins", "ametys:unstructured"); } - + if (root.needsSave()) { root.saveChanges(); } + + // Creates web-explorer space at "/ametys:plugins/web-explorer" if needed + DefaultTraversableAmetysObject pluginsNode = (DefaultTraversableAmetysObject) root.getChild("ametys:plugins"); + if (!pluginsNode.hasChild("web-explorer")) + { + pluginsNode.createChild("web-explorer", "ametys:unstructured"); + } + if (pluginsNode.needsSave()) + { + pluginsNode.saveChanges(); + } + + // Creates resources space at "/ametys:plugins/resources" if needed + DefaultTraversableAmetysObject explorerNode = (DefaultTraversableAmetysObject) pluginsNode.getChild("web-explorer"); + String sharedId = null; + if (!explorerNode.hasChild("shared")) + { + sharedId = ((JCRResourcesCollection) explorerNode.createChild("shared", "ametys:resources-collection")).getNode().getIdentifier(); + } + else + { + sharedId = ((JCRResourcesCollection) explorerNode.getChild("shared")).getNode().getIdentifier(); + } + + if (explorerNode.needsSave()) + { + explorerNode.saveChanges(); + } + // Register a live workspace listener for plugins manager.addEventListener(new LiveWorkspaceListener(_repository, _synchronizeComponent, getLogger()), Event.NODE_ADDED @@ -130,10 +170,68 @@ | Event.PROPERTY_REMOVED, site.getNode().getPath() + "/ametys-internal:resources", true, null, null, false); + // Creates local resources space at "/ametys-internal:resources" if needed + if (!site.hasChild("ametys-internal:resources")) + { + site.createChild("ametys-internal:resources", "ametys:resources-collection"); + } + if (site.needsSave()) { site.saveChanges(); } + + // Add virtual shared folder if shared folder is activate, delete it otherwise + DefaultTraversableAmetysObject internalResourcesNode = site.getChild("ametys-internal:resources"); + boolean sharedFolder = Config.getInstance().getValueAsBoolean("resources.shared.folder"); + _ajustVirtualValues(internalResourcesNode.getNode(), sharedFolder, sharedId); + internalResourcesNode.saveChanges(); + } + } + + private void _ajustVirtualValues(Node node, boolean sharedFolder, String sharedId) throws RepositoryException + { + Value[] values = new Value[]{}; + if (node.hasProperty(AmetysObjectResolver.VIRTUAL_PROPERTY)) + { + values = node.getProperty(AmetysObjectResolver.VIRTUAL_PROPERTY).getValues(); + } + + List valuesAsList = new ArrayList(Arrays.asList(values)); + + int index = _indexOf(values, VirtualProxyFactory.class.getName()); + if (!sharedFolder) + { + valuesAsList.remove(index); + if (node.hasProperty(VirtualProxyFactory.PROPERTY_REF_COLLECTION)) + { + node.getProperty(VirtualProxyFactory.PROPERTY_REF_COLLECTION).remove(); + } } + else if (sharedFolder && index < 0) + { + valuesAsList.add(new StringValue(VirtualProxyFactory.class.getName())); + if (!node.hasProperty(VirtualProxyFactory.PROPERTY_REF_COLLECTION)) + { + node.setProperty(VirtualProxyFactory.PROPERTY_REF_COLLECTION, sharedId); + } + } + + node.setProperty(AmetysObjectResolver.VIRTUAL_PROPERTY, valuesAsList.toArray(new Value[valuesAsList.size()])); + } + + private int _indexOf(Value[] values, String value) throws RepositoryException + { + int index = -1; + + for (int i = 0; i < values.length && index < 0; i++) + { + if (values[i].getString().equals(value)) + { + index = i; + } + } + + return index; } } Index: main/plugin-web/src/org/ametys/web/resources/proxy/ProxyResource.java =================================================================== --- main/plugin-web/src/org/ametys/web/resources/proxy/ProxyResource.java (revision 0) +++ main/plugin-web/src/org/ametys/web/resources/proxy/ProxyResource.java (revision 0) @@ -0,0 +1,330 @@ +/* + * Copyright 2012 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.ametys.web.resources.proxy; + +import java.io.InputStream; +import java.util.Date; + +import org.ametys.plugins.explorer.resources.ModifiableResource; +import org.ametys.plugins.explorer.resources.ResourceCollection; +import org.ametys.plugins.repository.AmetysObject; +import org.ametys.plugins.repository.AmetysRepositoryException; +import org.ametys.plugins.repository.jcr.JCRAmetysObject; + +public class ProxyResource implements ModifiableResource +{ + private ModifiableResource _resource; + private JCRAmetysObject _root; + + public ProxyResource(ModifiableResource resource, JCRAmetysObject root) + { + _resource = resource; + _root = root; + } + + @Override + public String getId() throws AmetysRepositoryException + { + String resourcePath = getResourcePath(); + if (resourcePath.startsWith("/")) + { + resourcePath = resourcePath.substring(1); + } + return VirtualProxyFactory.SCHEME + "://" + resourcePath + "?rootId=" + _root.getId(); + } + + @Override + public String getResourcePath() throws AmetysRepositoryException + { + return ((ResourceCollection) getParent()).getResourcePath() + "/" + getName(); + } + + @Override + public String getName() throws AmetysRepositoryException + { + return _resource.getName(); + } + + @Override + public String getPath() throws AmetysRepositoryException + { + return _resource.getPath(); + } + + @Override + public A getParent() throws AmetysRepositoryException + { + return ProxyResourcesHelper.convertToProxyObject(_resource.getParent(), _root); + } + + @Override + public String getParentPath() throws AmetysRepositoryException + { + return getParent().getParentPath(); + } + + @Override + public InputStream getInputStream() throws AmetysRepositoryException + { + return _resource.getInputStream(); + } + + @Override + public Date getLastModified() throws AmetysRepositoryException + { + return _resource.getLastModified(); + } + + @Override + public long getLength() throws AmetysRepositoryException + { + return _resource.getLength(); + } + + @Override + public String getAuthor() throws AmetysRepositoryException + { + return _resource.getAuthor(); + } + + @Override + public String[] getKeywords() throws AmetysRepositoryException + { + return _resource.getKeywords(); + } + + @Override + public String getKeywordsAsString() throws AmetysRepositoryException + { + return _resource.getKeywordsAsString(); + } + + @Override + public String getMimeType() throws AmetysRepositoryException + { + return _resource.getMimeType(); + } + + @Override + public String getDCTitle() throws AmetysRepositoryException + { + return _resource.getDCTitle(); + } + + @Override + public void setDCTitle(String title) throws AmetysRepositoryException + { + _resource.setDCTitle(title); + } + + @Override + public String getDCCreator() throws AmetysRepositoryException + { + return _resource.getDCCreator(); + } + + @Override + public void setDCCreator(String creator) throws AmetysRepositoryException + { + _resource.setDCCreator(creator); + } + + @Override + public String[] getDCSubject() throws AmetysRepositoryException + { + return _resource.getDCSubject(); + } + + @Override + public void setDCSubject(String[] subject) throws AmetysRepositoryException + { + _resource.setDCSubject(subject); + } + + @Override + public String getDCDescription() throws AmetysRepositoryException + { + return _resource.getDCDescription(); + } + + @Override + public void setDCDescription(String description) throws AmetysRepositoryException + { + _resource.setDCDescription(description); + } + + @Override + public String getDCPublisher() throws AmetysRepositoryException + { + return _resource.getDCPublisher(); + } + + @Override + public void setDCPublisher(String publisher) throws AmetysRepositoryException + { + _resource.setDCPublisher(publisher); + } + + @Override + public String getDCContributor() throws AmetysRepositoryException + { + return _resource.getDCContributor(); + } + + @Override + public void setDCContributor(String contributor) throws AmetysRepositoryException + { + _resource.setDCContributor(contributor); + } + + @Override + public Date getDCDate() throws AmetysRepositoryException + { + return _resource.getDCDate(); + } + + @Override + public void setDCDate(Date date) throws AmetysRepositoryException + { + _resource.setDCDate(date); + } + + @Override + public String getDCType() throws AmetysRepositoryException + { + return _resource.getDCType(); + } + + @Override + public void setDCType(String type) throws AmetysRepositoryException + { + _resource.setDCType(type); + } + + @Override + public String getDCFormat() throws AmetysRepositoryException + { + return _resource.getDCFormat(); + } + + @Override + public void setDCFormat(String format) throws AmetysRepositoryException + { + _resource.setDCFormat(format); + } + + @Override + public String getDCIdentifier() throws AmetysRepositoryException + { + return _resource.getDCIdentifier(); + } + + @Override + public void setDCIdentifier(String identifier) throws AmetysRepositoryException + { + _resource.setDCIdentifier(identifier); + } + + @Override + public String getDCSource() throws AmetysRepositoryException + { + return _resource.getDCSource(); + } + + @Override + public void setDCSource(String source) throws AmetysRepositoryException + { + _resource.setDCSource(source); + } + + @Override + public String getDCLanguage() throws AmetysRepositoryException + { + return _resource.getDCLanguage(); + } + + @Override + public void setDCLanguage(String language) throws AmetysRepositoryException + { + _resource.setDCLanguage(language); + } + + @Override + public String getDCRelation() throws AmetysRepositoryException + { + return _resource.getDCRelation(); + } + + @Override + public void setDCRelation(String relation) throws AmetysRepositoryException + { + _resource.setDCRelation(relation); + } + + @Override + public String getDCCoverage() throws AmetysRepositoryException + { + return _resource.getDCCoverage(); + } + + @Override + public void setDCCoverage(String coverage) throws AmetysRepositoryException + { + _resource.setDCCoverage(coverage); + } + + @Override + public String getDCRights() throws AmetysRepositoryException + { + return _resource.getDCRights(); + } + + @Override + public void setDCRights(String rights) throws AmetysRepositoryException + { + _resource.setDCRights(rights); + } + + @Override + public void setData(InputStream stream, String mimeType, Date lastModified, String author) + { + _resource.setData(stream, mimeType, lastModified, author); + } + + @Override + public void setLastModified(Date lastModified) + { + _resource.setLastModified(lastModified); + } + + @Override + public void setKeywords(String keywords) + { + _resource.setKeywords(keywords); + } + + @Override + public void setKeywords(String[] keywords) + { + _resource.setKeywords(keywords); + } + + @Override + public void setMimeType(String mimeType) + { + _resource.setMimeType(mimeType); + } +} Index: main/plugin-web/src/org/ametys/web/resources/proxy/ProxyResourcesCollection.java =================================================================== --- main/plugin-web/src/org/ametys/web/resources/proxy/ProxyResourcesCollection.java (revision 0) +++ main/plugin-web/src/org/ametys/web/resources/proxy/ProxyResourcesCollection.java (revision 0) @@ -0,0 +1,171 @@ +/* + * Copyright 2012 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.ametys.web.resources.proxy; + +import java.util.ArrayList; +import java.util.List; + +import org.ametys.plugins.explorer.resources.ModifiableResourceCollection; +import org.ametys.plugins.explorer.resources.ResourceCollection; +import org.ametys.plugins.repository.AmetysObject; +import org.ametys.plugins.repository.AmetysObjectIterable; +import org.ametys.plugins.repository.AmetysRepositoryException; +import org.ametys.plugins.repository.CollectionIterable; +import org.ametys.plugins.repository.RepositoryIntegrityViolationException; +import org.ametys.plugins.repository.UnknownAmetysObjectException; +import org.ametys.plugins.repository.jcr.JCRAmetysObject; + +public class ProxyResourcesCollection implements ModifiableResourceCollection +{ + /** application id for resources collections. */ + public static final String APPLICATION_ID = "org.ametys.plugins.explorer.applications.Resources"; + + protected ModifiableResourceCollection _resourcesCollection; + protected JCRAmetysObject _root; + + public ProxyResourcesCollection(ModifiableResourceCollection resourcesCollection, JCRAmetysObject root) + { + _resourcesCollection = resourcesCollection; + _root = root; + } + + @Override + public String getId() throws AmetysRepositoryException + { + String resourcePath = getResourcePath(); + if (resourcePath.startsWith("/")) + { + resourcePath = resourcePath.substring(1); + } + return VirtualProxyFactory.SCHEME + "://" + resourcePath + "?rootId=" + _root.getId(); + } + + @Override + public String getApplicationId() + { + return APPLICATION_ID; + } + + @Override + public A createChild(String name, String type) throws AmetysRepositoryException, RepositoryIntegrityViolationException + { + return ProxyResourcesHelper.convertToProxyObject(_resourcesCollection.createChild(name, type), _root); + } + + @Override + public AmetysObjectIterable getChildren() throws AmetysRepositoryException + { + AmetysObjectIterable children = _resourcesCollection.getChildren(); + List proxyChildren = new ArrayList(); + + for (A child : children) + { + proxyChildren.add((A) ProxyResourcesHelper.convertToProxyObject(child, _root)); + } + return new CollectionIterable(proxyChildren); + } + + @Override + public boolean hasChild(String name) throws AmetysRepositoryException + { + return _resourcesCollection.hasChild(name); + } + + @Override + public A getChild(String path) throws AmetysRepositoryException, UnknownAmetysObjectException + { + A child = _resourcesCollection.getChild(path); + return ProxyResourcesHelper.convertToProxyObject(child, _root); + } + + @Override + public String getName() throws AmetysRepositoryException + { + return _resourcesCollection.getName(); + } + + @Override + public String getPath() throws AmetysRepositoryException + { + return _resourcesCollection.getPath(); + } + + @Override + public A getParent() throws AmetysRepositoryException + { + return ProxyResourcesHelper.convertToProxyObject(_resourcesCollection.getParent(), _root); + } + + @Override + public String getParentPath() throws AmetysRepositoryException + { + return getParent().getPath(); + } + + @Override + public String getIcon() + { + return _resourcesCollection.getIcon(); + } + + @Override + public void remove() throws AmetysRepositoryException, RepositoryIntegrityViolationException + { + _resourcesCollection.remove(); + } + + @Override + public void rename(String newName) throws AmetysRepositoryException + { + _resourcesCollection.rename(newName); + } + + @Override + public String getResourcePath() throws AmetysRepositoryException + { + return ((ResourceCollection) getParent()).getResourcePath() + "/" + getName(); + } + + @Override + public String getResourceType() + { + return _resourcesCollection.getResourceType(); + } + + @Override + public String getCollectionType() + { + return _resourcesCollection.getCollectionType(); + } + + @Override + public boolean needsSave() throws AmetysRepositoryException + { + return _resourcesCollection.needsSave(); + } + + @Override + public void saveChanges() throws AmetysRepositoryException + { + _resourcesCollection.saveChanges(); + } + + @Override + public void revertChanges() throws AmetysRepositoryException + { + _resourcesCollection.revertChanges(); + } +} Index: main/plugin-web/src/org/ametys/web/resources/proxy/ProxyResourcesHelper.java =================================================================== --- main/plugin-web/src/org/ametys/web/resources/proxy/ProxyResourcesHelper.java (revision 0) +++ main/plugin-web/src/org/ametys/web/resources/proxy/ProxyResourcesHelper.java (revision 0) @@ -0,0 +1,59 @@ +/* + * Copyright 2012 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.ametys.web.resources.proxy; + +import javax.jcr.RepositoryException; + +import org.ametys.plugins.explorer.resources.ModifiableResource; +import org.ametys.plugins.explorer.resources.ModifiableResourceCollection; +import org.ametys.plugins.repository.AmetysObject; +import org.ametys.plugins.repository.AmetysRepositoryException; +import org.ametys.plugins.repository.jcr.JCRAmetysObject; + +public final class ProxyResourcesHelper +{ + private ProxyResourcesHelper() + { + // Constructor + } + + public static A convertToProxyObject(AmetysObject child, JCRAmetysObject root) throws AmetysRepositoryException + { + try + { + if (root.getNode().getProperty(VirtualProxyFactory.PROPERTY_REF_COLLECTION).getString().equals(((JCRAmetysObject) child).getNode().getIdentifier())) + { + return (A) new ProxyRootResourcesCollection((ModifiableResourceCollection) child, root); + } + else if (child instanceof ModifiableResourceCollection) + { + return (A) new ProxyResourcesCollection((ModifiableResourceCollection) child, root); + } + else if (child instanceof ModifiableResource) + { + return (A) new ProxyResource((ModifiableResource) child, root); + } + else + { + throw new AmetysRepositoryException("Type not allowed: " + child.getClass().getName()); + } + } + catch (RepositoryException e) + { + throw new AmetysRepositoryException("Unable to get property: " + VirtualProxyFactory.PROPERTY_REF_COLLECTION + " on node: " + root.getPath()); + } + } +} Index: main/plugin-web/src/org/ametys/web/resources/proxy/ProxyRootResourcesCollection.java =================================================================== --- main/plugin-web/src/org/ametys/web/resources/proxy/ProxyRootResourcesCollection.java (revision 0) +++ main/plugin-web/src/org/ametys/web/resources/proxy/ProxyRootResourcesCollection.java (revision 0) @@ -0,0 +1,76 @@ +/* + * Copyright 2012 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.ametys.web.resources.proxy; + +import org.ametys.plugins.explorer.resources.ModifiableResourceCollection; +import org.ametys.plugins.repository.AmetysObject; +import org.ametys.plugins.repository.AmetysRepositoryException; +import org.ametys.plugins.repository.RepositoryIntegrityViolationException; +import org.ametys.plugins.repository.jcr.JCRAmetysObject; +import org.ametys.runtime.util.I18nUtils; +import org.ametys.runtime.util.I18nizableText; + +public class ProxyRootResourcesCollection extends ProxyResourcesCollection +{ + private static final I18nizableText _NAME = new I18nizableText("plugin.web", "PLUGINS_EXPLORER_PROXY_FOLDER"); + + public ProxyRootResourcesCollection(ModifiableResourceCollection resourcesCollection, JCRAmetysObject root) + { + super(resourcesCollection, root); + } + + @Override + public String getName() throws AmetysRepositoryException + { + return I18nUtils.getInstance().translate(_NAME); + } + + @Override + public String getPath() throws AmetysRepositoryException + { + return getParentPath() + "/" + getName(); + } + + @Override + public A getParent() throws AmetysRepositoryException + { + return (A) _root; + } + + @Override + public String getIcon() + { + return "/plugins/web/resources/img/resources/folder_proxy.png"; + } + + @Override + public void remove() throws AmetysRepositoryException, RepositoryIntegrityViolationException + { + // Do nothing + } + + @Override + public void rename(String newName) throws AmetysRepositoryException + { + // Do nothing + } + + @Override + public String getResourcePath() throws AmetysRepositoryException + { + return "/" + getName(); + } +} Index: main/plugin-web/src/org/ametys/web/resources/proxy/VirtualProxyFactory.java =================================================================== --- main/plugin-web/src/org/ametys/web/resources/proxy/VirtualProxyFactory.java (revision 0) +++ main/plugin-web/src/org/ametys/web/resources/proxy/VirtualProxyFactory.java (revision 0) @@ -0,0 +1,152 @@ +/* + * Copyright 2012 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.ametys.web.resources.proxy; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.commons.lang.StringUtils; + +import org.ametys.plugins.explorer.resources.ModifiableResourceCollection; +import org.ametys.plugins.explorer.resources.ResourceCollection; +import org.ametys.plugins.repository.AmetysObject; +import org.ametys.plugins.repository.AmetysObjectFactory; +import org.ametys.plugins.repository.AmetysObjectIterable; +import org.ametys.plugins.repository.AmetysObjectResolver; +import org.ametys.plugins.repository.AmetysRepositoryException; +import org.ametys.plugins.repository.CollectionIterable; +import org.ametys.plugins.repository.UnknownAmetysObjectException; +import org.ametys.plugins.repository.jcr.JCRAmetysObject; +import org.ametys.plugins.repository.virtual.VirtualAmetysObjectFactory; + +/** + * {@link AmetysObjectFactory} for handling "virtual" resources page + */ +public class VirtualProxyFactory implements VirtualAmetysObjectFactory, Serviceable +{ + public static final String SCHEME = "proxy-resources"; + public static final String PROPERTY_REF_COLLECTION = "ametys-internal:ref-collection"; + + private AmetysObjectResolver _resolver; + + @Override + public void service(ServiceManager manager) throws ServiceException + { + _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE); + } + + @Override + public AmetysObject getAmetysObjectById(String id) throws AmetysRepositoryException + { + int i = id.indexOf('?'); + String path = id.substring(getScheme().length() + 3, i); + String rootId = id.substring(i + "?rootId=".length()); + + JCRAmetysObject parent = _resolver.resolveById(rootId); + AmetysObject child = getChild(parent, null); + if (StringUtils.isNotEmpty(path)) + { + List pathParts = new ArrayList(Arrays.asList(path.split("/"))); + pathParts.remove(0); + for (String part : pathParts) + { + child = ((ResourceCollection) child).getChild(part); + } + } + return child; + } + + @Override + public boolean hasAmetysObjectForId(String id) throws AmetysRepositoryException + { + try + { + getAmetysObjectById(id); + return true; + } + catch (UnknownAmetysObjectException e) + { + return false; + } + } + + @Override + public String getScheme() + { + return SCHEME; + } + + @Override + public AmetysObjectIterable getChildren(JCRAmetysObject parent) throws AmetysRepositoryException + { + try + { + Node refCollectionNode = parent.getNode().getProperty(PROPERTY_REF_COLLECTION).getNode(); + ModifiableResourceCollection refCollection = _resolver.resolve(refCollectionNode, false); + ResourceCollection collection = _getRootResourcesCollection(refCollection, parent); + List children = new ArrayList(); + children.add(collection); + + return new CollectionIterable(children); + } + catch (RepositoryException e) + { + throw new AmetysRepositoryException("Unable to retrieve children", e); + } + } + + @Override + public ResourceCollection getChild(JCRAmetysObject parent, String childName) throws AmetysRepositoryException + { + try + { + Node refCollectionNode = parent.getNode().getProperty(PROPERTY_REF_COLLECTION).getNode(); + ModifiableResourceCollection refCollection = _resolver.resolve(refCollectionNode, false); + ResourceCollection collection = _getRootResourcesCollection(refCollection, parent); + return collection; + } + catch (RepositoryException e) + { + throw new AmetysRepositoryException("Unable to retrieve child with name: " + childName, e); + } + } + + @Override + public boolean hasChild(JCRAmetysObject parent, String childName) + { + try + { + parent.getNode().getProperty(PROPERTY_REF_COLLECTION).getNode(); + } + catch (RepositoryException e) + { + return false; + } + return true; + } + + protected ResourceCollection _getRootResourcesCollection(ModifiableResourceCollection refCollection, JCRAmetysObject parent) + { + return new ProxyRootResourcesCollection(refCollection, parent); + } +} Index: main/plugin-web/src/org/ametys/web/resources/shared/SharedRootResourcesCollection.java =================================================================== --- main/plugin-web/src/org/ametys/web/resources/shared/SharedRootResourcesCollection.java (revision 0) +++ main/plugin-web/src/org/ametys/web/resources/shared/SharedRootResourcesCollection.java (revision 0) @@ -0,0 +1,33 @@ +/* + * Copyright 2012 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.ametys.web.resources.shared; + +import org.ametys.plugins.explorer.resources.ModifiableResourceCollection; +import org.ametys.plugins.repository.jcr.JCRAmetysObject; +import org.ametys.web.resources.proxy.ProxyRootResourcesCollection; + +public class SharedRootResourcesCollection extends ProxyRootResourcesCollection +{ + public SharedRootResourcesCollection(ModifiableResourceCollection resourcesCollection, JCRAmetysObject root) + { + super(resourcesCollection, root); + } + + public String getIcon() + { + return "/../../web/resources/img/resources/folder_shared.png"; + } +} Index: main/plugin-web/src/org/ametys/web/resources/shared/VirtualSharedFactory.java =================================================================== --- main/plugin-web/src/org/ametys/web/resources/shared/VirtualSharedFactory.java (revision 0) +++ main/plugin-web/src/org/ametys/web/resources/shared/VirtualSharedFactory.java (revision 0) @@ -0,0 +1,32 @@ +/* + * Copyright 2012 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.ametys.web.resources.shared; + +import org.ametys.plugins.explorer.resources.ModifiableResourceCollection; +import org.ametys.plugins.explorer.resources.ResourceCollection; +import org.ametys.plugins.repository.jcr.JCRAmetysObject; +import org.ametys.web.resources.proxy.VirtualProxyFactory; + +public class VirtualSharedFactory extends VirtualProxyFactory +{ + public static final String SCHEME = "shared-resources"; + + @Override + protected ResourceCollection _getRootResourcesCollection(ModifiableResourceCollection refCollection, JCRAmetysObject parent) + { + return new SharedRootResourcesCollection(refCollection, parent); + } +}