You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-commits@incubator.apache.org by cl...@apache.org on 2006/09/20 19:37:21 UTC
svn commit: r448311 [12/25] - in /incubator/graffito/trunk: ./ api/
api/src/java/org/apache/portals/graffito/context/
api/src/java/org/apache/portals/graffito/exception/
api/src/java/org/apache/portals/graffito/services/core/
api/src/java/org/apache/po...
Modified: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/persistence/impl/ContentPersistenceServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/persistence/impl/ContentPersistenceServiceImpl.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/persistence/impl/ContentPersistenceServiceImpl.java (original)
+++ incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/persistence/impl/ContentPersistenceServiceImpl.java Wed Sep 20 12:37:05 2006
@@ -1,707 +1,707 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- * as applicable.
- *
- * 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.apache.portals.graffito.persistence.impl;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Hashtable;
-import java.util.Iterator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.portals.graffito.exception.CmsIncorrectServerException;
-import org.apache.portals.graffito.exception.CmsInstantiateException;
-import org.apache.portals.graffito.exception.CmsPermissionException;
-import org.apache.portals.graffito.model.core.CmsObject;
-import org.apache.portals.graffito.model.core.HistoryElement;
-import org.apache.portals.graffito.model.core.VersionnedContent;
-import org.apache.portals.graffito.model.core.impl.SysCmsClass;
-import org.apache.portals.graffito.model.server.Server;
-import org.apache.portals.graffito.persistence.ContentPersistenceException;
-import org.apache.portals.graffito.persistence.ContentPersistenceService;
-import org.apache.portals.graffito.persistence.ContentStoreService;
-import org.apache.portals.graffito.services.search.Filter;
-import org.apache.portals.graffito.services.search.impl.FilterImpl;
-import org.apache.portals.graffito.store.ContentStore;
-
-/**
- * Default implementation for
- * {@link org.apache.portals.graffito.persistenceService.ContentPersistenceService}
- *
- */
-public class ContentPersistenceServiceImpl implements ContentPersistenceService
-{
- private final static Log log = LogFactory.getLog(ContentPersistenceServiceImpl.class);
-
- private static Hashtable omClasses = new Hashtable();
-
- /**
- * The Master Graffito Server. The "Graffito Master Server" contains information
- * about external servers like WebDav server, DB server or other proprietary
- * content servers. It may also contain some CmsObject but it is not
- * mandatory.
- *
- */
- private Server graffitoMasterServer;
-
- private ContentStoreService contentStoreService;
-
- /**
- * Constructor.
- *
- * @param graffitoMasterServer the Graffito Master Server.
- * @param contentStoreService The content store service used by this persistenceService store
- */
- public ContentPersistenceServiceImpl(Server graffitoMasterServer, ContentStoreService contentStoreService)
- {
- if (graffitoMasterServer == null)
- {
- throw new IllegalArgumentException("graffitoMasterServer cannot be null for PersistenceServiceImpl");
- }
- this.graffitoMasterServer = graffitoMasterServer;
-
- if (contentStoreService == null)
- {
- throw new IllegalArgumentException("Content store service cannot be null for PersistenceServiceImpl");
- }
- this.contentStoreService = contentStoreService;
-
- // Register all stores
- registerAllStores();
- }
-
- /**
- * @see ContentPersistenceService#createObject(java.lang.String)
- */
- public Object createObject(String omName) throws CmsInstantiateException
- {
- Object cmsObject = null;
- Class omClass = (Class) omClasses.get(omName);
- ContentStore store = null;
- try
- {
- if (null == omClass)
- {
- store = getGraffitoMasterStore();
- Filter filter = store.newFilter();
- filter.addEqualTo("cmsClassId", omName);
- SysCmsClass sysCmsClass = (SysCmsClass) store.getObjectByQuery(SysCmsClass.class, filter);
- omClass = Class.forName(sysCmsClass.getCmsClass());
- omClasses.put(omName, omClass);
- }
- cmsObject = omClass.newInstance();
- }
- catch (Exception e)
- {
- throw new CmsInstantiateException("CmsRespositoruModeService error : Failed to instantiate a cms object : " + omName
- + "- " + e);
- }
- return cmsObject;
- }
-
- /**
- * @see ContentPersistenceService#insert(java.lang.Object)
- */
- public void insert(Object object) throws ContentPersistenceException, CmsPermissionException
- {
- try
- {
- ContentStore store = findPersistenceStore(object);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
- store.insert(object);
- }
- catch (Exception e)
- {
- throw new ContentPersistenceException(e);
- }
- }
-
- /**
- * @see ContentPersistenceService#update(java.lang.Object)
- */
- public void update(Object object) throws ContentPersistenceException, CmsPermissionException
- {
- try
- {
- ContentStore store = findPersistenceStore(object);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
- store.update(object);
- }
- catch (Exception e)
- {
- throw new ContentPersistenceException(e);
- }
- }
-
- /**
- * @see ContentPersistenceService#delete(java.lang.Object)
- */
- public void delete(Object object) throws ContentPersistenceException, CmsPermissionException
- {
- if (object == null)
- return;
-
- try
- {
- ContentStore store = findPersistenceStore(object);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
- store.delete(object);
-
- }
- catch (Exception e)
- {
- throw new ContentPersistenceException(e);
- }
- }
-
- /**
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#delete(java.lang.String)
- */
- public void delete(String uri) throws ContentPersistenceException, CmsPermissionException
- {
- try
- {
- Filter filter = this.newFilter();
- filter.addEqualTo("uri", uri);
- ContentStore store = findPersistenceStore(uri);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
-
- if (uri.equals(store.getScope()))
- {
- throw new ContentPersistenceException("Impossible to delete the server root : " + uri);
- }
-
- store.deleteAll(CmsObject.class, filter);
- }
- catch (Exception e)
- {
- throw new ContentPersistenceException(e);
- }
-
- }
-
- /**
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#deleteAll(Class,
- * Filter)
- */
- public void deleteAll(Class clazz, Filter filter) throws ContentPersistenceException, CmsPermissionException
- {
- ContentStore store = null;
- try
- {
- Iterator iterator = findPersistenceStores(filter).iterator();
- while (iterator.hasNext())
- {
- store = (ContentStore) iterator.next();
- store.deleteAll(clazz, filter);
- }
-
- }
- catch (Exception e)
- {
- throw new ContentPersistenceException(e);
- }
-
- }
-
- /**
- * @see ContentPersistenceService#getCmsObject(String)
- */
- public CmsObject getCmsObject(String uri) throws ContentPersistenceException, CmsPermissionException
- {
-
- //return this.getCmsObject(uri, null);
- ContentStore store = findPersistenceStore(uri);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
-
- Filter filter = store.newFilter();
- filter.addEqualTo("uri", uri);
- CmsObject object = (CmsObject) store.getObjectByQuery(CmsObject.class, filter);
- return object;
- }
-
- /**
- * @see ContentPersistenceService#getCmsObject(String, String)
- */
- public CmsObject getCmsObject(String uri, String versionNumber) throws ContentPersistenceException, CmsPermissionException
- {
- ContentStore store = findPersistenceStore(uri);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
-
- Filter filter = store.newFilter();
-
- // if the versionNum is not provided, get the lastest document
- // version
- if (versionNumber == null)
- {
- filter.addEqualTo("isLastVersion", new Boolean(true));
- }
- else
- {
- filter.addEqualTo("versionNumber", versionNumber);
- }
-
- filter.addEqualTo("uri", uri);
- CmsObject object = (CmsObject) store.getObjectByQuery(VersionnedContent.class, filter);
- return object;
- }
-
- /**
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getChildren(java.lang.String)
- */
- public Collection getChildren(String parentUri) throws ContentPersistenceException
- {
- try
- {
- ContentStore store = findPersistenceStore(parentUri);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
- return store.getChildren(parentUri);
- }
- catch (Exception e)
- {
- throw new ContentPersistenceException("Impossible to get the children", e);
- }
- }
-
- /**
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getContents(java.lang.String)
- */
- public Collection getContents(String uri) throws ContentPersistenceException
- {
- try
- {
- ContentStore store = findPersistenceStore(uri);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
- return store.getContents(uri);
- }
- catch (Exception e)
- {
- throw new ContentPersistenceException("Impossible to get the contents", e);
- }
-
- }
-
- /**
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getLinks(java.lang.String)
- */
- public Collection getLinks(String uri) throws ContentPersistenceException
- {
- try
- {
- ContentStore store = findPersistenceStore(uri);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
- return store.getLinks(uri);
-
- }
- catch (Exception e)
- {
- throw new ContentPersistenceException("Impossible to get the links", e);
- }
- }
-
- /**
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getFolders(java.lang.String)
- */
- public Collection getFolders(String uri) throws ContentPersistenceException
- {
- try
- {
- ContentStore store = findPersistenceStore(uri);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
- return store.getFolders(uri);
-
- }
- catch (Exception e)
- {
- throw new ContentPersistenceException("Impossible to find the associated store", e);
- }
- }
-
-
- /**
- *
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getHistory(org.apache.portals.graffito.model.core.VersionnedContent)
- */
- public HistoryElement getHistory(VersionnedContent versionnedContent) throws ContentPersistenceException, CmsPermissionException
- {
- ContentStore store = findPersistenceStore(versionnedContent);
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
- return store.getHistory(versionnedContent);
-
- }
-
- /**
- *
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#insertHistoryElement(org.apache.portals.graffito.model.core.HistoryElement)
- */
- public void insertHistoryElement(HistoryElement historyElement) throws ContentPersistenceException, CmsPermissionException
- {
- ContentStore store = findPersistenceStore(historyElement.getClass());
- if (store == null)
- {
- throw new ContentPersistenceException("Impossible to find the associated store");
- }
- store.insertHistoryElement(historyElement);
- }
-
- /**
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#newFilter()
- */
- public Filter newFilter()
- {
- return new FilterImpl();
- }
-
- /**
- *
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getCollectionByQuery(java.lang.Class, org.apache.portals.graffito.services.search.Filter)
- */
- public Collection getCollectionByQuery(Class clazz, Filter filter) throws ContentPersistenceException
- {
-
- Collection foundStores = null;
- ArrayList allCmsObjects = new ArrayList();
-
- try
- {
- // Find all stores concerned by the filter criteria
- foundStores = findPersistenceStores(filter);
- Iterator storeIterator = foundStores.iterator();
-
- // Loop on the found stores and execute the query
- while (storeIterator.hasNext())
- {
- ContentStore store = (ContentStore) storeIterator.next();
-
- Collection cmsObjects = store.getCollectionByQuery(clazz, filter);
- allCmsObjects.addAll(cmsObjects);
- }
- }
- catch (CmsPermissionException e)
- {
- return new ArrayList();
- }
- return allCmsObjects;
- }
-
- /**
- *
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getIteratorByQuery(java.lang.Class, org.apache.portals.graffito.services.search.Filter)
- */
- public Iterator getIteratorByQuery(Class clazz, Filter filter) throws ContentPersistenceException
- {
- MultiStoreIterator multiStoreIterator = new MultiStoreIterator();
- try
- {
-
- Collection foundStores = null;
- // Find all stores concerned by the filter criteria
- foundStores = findPersistenceStores(filter);
- Iterator storeIterator = foundStores.iterator();
- while (storeIterator.hasNext())
- {
- ContentStore store = (ContentStore) storeIterator.next();
- Iterator iterator = store.getIteratorByQuery(clazz, filter);
- multiStoreIterator.addIterator(iterator);
-
- }
- return multiStoreIterator;
- }
- catch (CmsPermissionException e)
- {
- return new MultiStoreIterator();
- }
-
- }
-
- /**
- *
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getObjectbyQuery(java.lang.Class, org.apache.portals.graffito.services.search.Filter)
- */
- public Object getObjectbyQuery(Class clazz, Filter filter) throws CmsPermissionException
- {
-
- ContentStore store = null;
- Iterator iterator = findPersistenceStores(filter).iterator();
- while (iterator.hasNext())
- {
- store = (ContentStore) iterator.next();
- Object cmsObject = store.getObjectByQuery(clazz, filter);
- if (cmsObject != null)
- {
- return cmsObject;
- }
- }
-
- return null;
- }
-
- /**
- * @see ContentPersistenceService#getGraffitoMasterStore()
- */
- public ContentStore getGraffitoMasterStore()
- {
- ContentStore store = contentStoreService.getStore(graffitoMasterServer.getAlias());
-
- return store;
- }
-
- /**
- * @see ContentPersistenceService#getStore(String)
- */
- public ContentStore getStore(String persistenceStoreName)
- {
- return contentStoreService.getStore(persistenceStoreName);
- }
-
- /**
- * @see ContentPersistenceService#getServer(String)
- */
- public Server getServer(String scope) throws ContentPersistenceException, CmsPermissionException
- {
- if (scope.equals(graffitoMasterServer.getScope()))
- {
- return graffitoMasterServer;
- }
-
- // All server references are stored into the Graffito Master Store
- ContentStore store = store = getGraffitoMasterStore();
- Filter filter = store.newFilter();
- filter.addEqualTo("scope", scope);
- return (Server) store.getObjectByQuery(Server.class, filter);
- }
-
- /**
- *
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#registerServer(org.apache.portals.graffito.model.server.Server)
- */
- public void registerServer(Server server) throws CmsPermissionException, CmsIncorrectServerException
- {
- try
- {
- if (!contentStoreService.canRegisterServer(server))
- {
- throw new CmsIncorrectServerException("Impossible to instantiate the ContentStore for server "
- + server.getAlias() + " - The server scope already exists");
- }
- contentStoreService.newStore(server);
- }
- catch (CmsInstantiateException e)
- {
- throw new CmsIncorrectServerException("Impossible to instantiate the ContentStore for server " + server.getAlias(), e);
-
- }
- }
-
- /**
- *
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#unRegisterServer(org.apache.portals.graffito.model.server.Server)
- */
- public void unRegisterServer(Server server) throws CmsPermissionException, CmsIncorrectServerException
- {
- // it is not authorized to unregister the Graffito Master Store.
- if (this.graffitoMasterServer.equals(server))
- {
- throw new CmsIncorrectServerException("Cannot unregister the Graffito Master Server");
- }
- contentStoreService.removeStore(server.getAlias());
- }
-
- /**
- * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getServers(boolean)
- */
- public Collection getServers(boolean withMasterServer)
- {
- try
- {
- ContentStore store = getGraffitoMasterStore();
- Filter filter = store.newFilter();
- Collection servers = store.getCollectionByQuery(Server.class, filter);
- if (withMasterServer)
- {
- // Add also the Graffito Master Server
- servers.add(graffitoMasterServer);
- }
- return servers;
- }
- catch (CmsPermissionException e)
- {
- return new ArrayList();
- }
- }
-
- /**
- * Find the persistenceService store associated to all kind of object (CmsObject,
- * Server, ...)
- *
- * @param object The object for which the persistenceService store has to be found
- * @return the persistenceService store found or null
- */
- private ContentStore findPersistenceStore(Object object)
- {
- // if the ojbect is an instance of Server => Get the Graffito Master Server
- // All servers references are stored into the Graffito Master Server
- if (object instanceof Server)
- {
- return this.getGraffitoMasterStore();
- }
-
- //if the object is an instance of CmsObject, try to find a server which
- // match to the object uri
- if (object instanceof CmsObject)
- {
- return this.findPersistenceStore(((CmsObject) object).getUri());
- }
-
- return this.getGraffitoMasterStore();
- }
-
- /**
- * Find the persistenceService store associated to an uri
- *
- * @param uri The uri for which the persistenceService store has to be found
- * @return the persistenceService store found or null
- */
- private ContentStore findPersistenceStore(String uri)
- {
- Iterator servers = this.getServers(true).iterator();
- while (servers.hasNext())
- {
- Server server = (Server) servers.next();
- if (uri.startsWith(server.getScope()))
- {
- return this.findPersistenceStore(server);
- }
- }
- return null;
- }
-
- /**
- * Find the persistenceService store associated to a server
- *
- * @param server The server for which the persistenceService store has to be found
- * @return the persistenceService store found or null
- */
- private ContentStore findPersistenceStore(Server server)
- {
- return getStore(server.getAlias());
- }
-
- /**
- * Find the persistenceService stores associated to an filter. The query can be
- * apply to more than one server. The scope attribute in the filter object
- * defined in which server to look at.
- *
- * @param filter The filter for which the persistenceService stores have to be found
- * @return the persistenceService store collection or null
- */
- private Collection findPersistenceStores(Filter filter)
- {
- String scope = filter.getScope();
- Collection allServers = this.getServers(true);
- ArrayList selectedStores = new ArrayList();
- // if there is no scope, return all stores
- if (scope == null || scope.equals(""))
- {
- Iterator servers = allServers.iterator();
- while (servers.hasNext())
- {
- Server server = (Server) servers.next();
- ContentStore store = findPersistenceStore(server);
- selectedStores.add(store);
- }
- }
- else
- {
- //else loop on all servers in order to find thoses which match to
- // the filter scope
- Iterator servers = allServers.iterator();
- while (servers.hasNext())
- {
- Server server = (Server) servers.next();
- if (scope.startsWith(server.getScope()))
- {
- ContentStore store = findPersistenceStore(server);
- selectedStores.add(store);
- }
- }
- }
- return selectedStores;
- }
-
- private void registerAllStores()
- {
- Server server = null;
- try
- {
- // Add the Graffito Master Server
- server = graffitoMasterServer;
- contentStoreService.newStore(server);
-
- // Get all server references and create one ContenStore per server.
- // Each Server data object contains information on how to
- // connect to the external server.
- Iterator servers = this.getServers(false).iterator();
- while (servers.hasNext())
- {
- server = (Server) servers.next();
-
- contentStoreService.newStore(server);
- }
- }
- catch (CmsInstantiateException e)
- {
- // If a store class is not found, just ignore it
- // TODO : Need to register all incorrect server dao in order to publish them in an admin portlet
- log.error("Impossible to find the store class : " + server.getStoreClassName());
- }
- }
-
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.apache.portals.graffito.persistence.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.exception.CmsIncorrectServerException;
+import org.apache.portals.graffito.exception.CmsInstantiateException;
+import org.apache.portals.graffito.exception.CmsPermissionException;
+import org.apache.portals.graffito.model.core.CmsObject;
+import org.apache.portals.graffito.model.core.HistoryElement;
+import org.apache.portals.graffito.model.core.VersionnedContent;
+import org.apache.portals.graffito.model.core.impl.SysCmsClass;
+import org.apache.portals.graffito.model.server.Server;
+import org.apache.portals.graffito.persistence.ContentPersistenceException;
+import org.apache.portals.graffito.persistence.ContentPersistenceService;
+import org.apache.portals.graffito.persistence.ContentStoreService;
+import org.apache.portals.graffito.services.search.Filter;
+import org.apache.portals.graffito.services.search.impl.FilterImpl;
+import org.apache.portals.graffito.store.ContentStore;
+
+/**
+ * Default implementation for
+ * {@link org.apache.portals.graffito.persistenceService.ContentPersistenceService}
+ *
+ */
+public class ContentPersistenceServiceImpl implements ContentPersistenceService
+{
+ private final static Log log = LogFactory.getLog(ContentPersistenceServiceImpl.class);
+
+ private static Hashtable omClasses = new Hashtable();
+
+ /**
+ * The Master Graffito Server. The "Graffito Master Server" contains information
+ * about external servers like WebDav server, DB server or other proprietary
+ * content servers. It may also contain some CmsObject but it is not
+ * mandatory.
+ *
+ */
+ private Server graffitoMasterServer;
+
+ private ContentStoreService contentStoreService;
+
+ /**
+ * Constructor.
+ *
+ * @param graffitoMasterServer the Graffito Master Server.
+ * @param contentStoreService The content store service used by this persistenceService store
+ */
+ public ContentPersistenceServiceImpl(Server graffitoMasterServer, ContentStoreService contentStoreService)
+ {
+ if (graffitoMasterServer == null)
+ {
+ throw new IllegalArgumentException("graffitoMasterServer cannot be null for PersistenceServiceImpl");
+ }
+ this.graffitoMasterServer = graffitoMasterServer;
+
+ if (contentStoreService == null)
+ {
+ throw new IllegalArgumentException("Content store service cannot be null for PersistenceServiceImpl");
+ }
+ this.contentStoreService = contentStoreService;
+
+ // Register all stores
+ registerAllStores();
+ }
+
+ /**
+ * @see ContentPersistenceService#createObject(java.lang.String)
+ */
+ public Object createObject(String omName) throws CmsInstantiateException
+ {
+ Object cmsObject = null;
+ Class omClass = (Class) omClasses.get(omName);
+ ContentStore store = null;
+ try
+ {
+ if (null == omClass)
+ {
+ store = getGraffitoMasterStore();
+ Filter filter = store.newFilter();
+ filter.addEqualTo("cmsClassId", omName);
+ SysCmsClass sysCmsClass = (SysCmsClass) store.getObjectByQuery(SysCmsClass.class, filter);
+ omClass = Class.forName(sysCmsClass.getCmsClass());
+ omClasses.put(omName, omClass);
+ }
+ cmsObject = omClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new CmsInstantiateException("CmsRespositoruModeService error : Failed to instantiate a cms object : " + omName
+ + "- " + e);
+ }
+ return cmsObject;
+ }
+
+ /**
+ * @see ContentPersistenceService#insert(java.lang.Object)
+ */
+ public void insert(Object object) throws ContentPersistenceException, CmsPermissionException
+ {
+ try
+ {
+ ContentStore store = findPersistenceStore(object);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+ store.insert(object);
+ }
+ catch (Exception e)
+ {
+ throw new ContentPersistenceException(e);
+ }
+ }
+
+ /**
+ * @see ContentPersistenceService#update(java.lang.Object)
+ */
+ public void update(Object object) throws ContentPersistenceException, CmsPermissionException
+ {
+ try
+ {
+ ContentStore store = findPersistenceStore(object);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+ store.update(object);
+ }
+ catch (Exception e)
+ {
+ throw new ContentPersistenceException(e);
+ }
+ }
+
+ /**
+ * @see ContentPersistenceService#delete(java.lang.Object)
+ */
+ public void delete(Object object) throws ContentPersistenceException, CmsPermissionException
+ {
+ if (object == null)
+ return;
+
+ try
+ {
+ ContentStore store = findPersistenceStore(object);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+ store.delete(object);
+
+ }
+ catch (Exception e)
+ {
+ throw new ContentPersistenceException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#delete(java.lang.String)
+ */
+ public void delete(String uri) throws ContentPersistenceException, CmsPermissionException
+ {
+ try
+ {
+ Filter filter = this.newFilter();
+ filter.addEqualTo("uri", uri);
+ ContentStore store = findPersistenceStore(uri);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+
+ if (uri.equals(store.getScope()))
+ {
+ throw new ContentPersistenceException("Impossible to delete the server root : " + uri);
+ }
+
+ store.deleteAll(CmsObject.class, filter);
+ }
+ catch (Exception e)
+ {
+ throw new ContentPersistenceException(e);
+ }
+
+ }
+
+ /**
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#deleteAll(Class,
+ * Filter)
+ */
+ public void deleteAll(Class clazz, Filter filter) throws ContentPersistenceException, CmsPermissionException
+ {
+ ContentStore store = null;
+ try
+ {
+ Iterator iterator = findPersistenceStores(filter).iterator();
+ while (iterator.hasNext())
+ {
+ store = (ContentStore) iterator.next();
+ store.deleteAll(clazz, filter);
+ }
+
+ }
+ catch (Exception e)
+ {
+ throw new ContentPersistenceException(e);
+ }
+
+ }
+
+ /**
+ * @see ContentPersistenceService#getCmsObject(String)
+ */
+ public CmsObject getCmsObject(String uri) throws ContentPersistenceException, CmsPermissionException
+ {
+
+ //return this.getCmsObject(uri, null);
+ ContentStore store = findPersistenceStore(uri);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+
+ Filter filter = store.newFilter();
+ filter.addEqualTo("uri", uri);
+ CmsObject object = (CmsObject) store.getObjectByQuery(CmsObject.class, filter);
+ return object;
+ }
+
+ /**
+ * @see ContentPersistenceService#getCmsObject(String, String)
+ */
+ public CmsObject getCmsObject(String uri, String versionNumber) throws ContentPersistenceException, CmsPermissionException
+ {
+ ContentStore store = findPersistenceStore(uri);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+
+ Filter filter = store.newFilter();
+
+ // if the versionNum is not provided, get the lastest document
+ // version
+ if (versionNumber == null)
+ {
+ filter.addEqualTo("isLastVersion", new Boolean(true));
+ }
+ else
+ {
+ filter.addEqualTo("versionNumber", versionNumber);
+ }
+
+ filter.addEqualTo("uri", uri);
+ CmsObject object = (CmsObject) store.getObjectByQuery(VersionnedContent.class, filter);
+ return object;
+ }
+
+ /**
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getChildren(java.lang.String)
+ */
+ public Collection getChildren(String parentUri) throws ContentPersistenceException
+ {
+ try
+ {
+ ContentStore store = findPersistenceStore(parentUri);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+ return store.getChildren(parentUri);
+ }
+ catch (Exception e)
+ {
+ throw new ContentPersistenceException("Impossible to get the children", e);
+ }
+ }
+
+ /**
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getContents(java.lang.String)
+ */
+ public Collection getContents(String uri) throws ContentPersistenceException
+ {
+ try
+ {
+ ContentStore store = findPersistenceStore(uri);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+ return store.getContents(uri);
+ }
+ catch (Exception e)
+ {
+ throw new ContentPersistenceException("Impossible to get the contents", e);
+ }
+
+ }
+
+ /**
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getLinks(java.lang.String)
+ */
+ public Collection getLinks(String uri) throws ContentPersistenceException
+ {
+ try
+ {
+ ContentStore store = findPersistenceStore(uri);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+ return store.getLinks(uri);
+
+ }
+ catch (Exception e)
+ {
+ throw new ContentPersistenceException("Impossible to get the links", e);
+ }
+ }
+
+ /**
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getFolders(java.lang.String)
+ */
+ public Collection getFolders(String uri) throws ContentPersistenceException
+ {
+ try
+ {
+ ContentStore store = findPersistenceStore(uri);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+ return store.getFolders(uri);
+
+ }
+ catch (Exception e)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store", e);
+ }
+ }
+
+
+ /**
+ *
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getHistory(org.apache.portals.graffito.model.core.VersionnedContent)
+ */
+ public HistoryElement getHistory(VersionnedContent versionnedContent) throws ContentPersistenceException, CmsPermissionException
+ {
+ ContentStore store = findPersistenceStore(versionnedContent);
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+ return store.getHistory(versionnedContent);
+
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#insertHistoryElement(org.apache.portals.graffito.model.core.HistoryElement)
+ */
+ public void insertHistoryElement(HistoryElement historyElement) throws ContentPersistenceException, CmsPermissionException
+ {
+ ContentStore store = findPersistenceStore(historyElement.getClass());
+ if (store == null)
+ {
+ throw new ContentPersistenceException("Impossible to find the associated store");
+ }
+ store.insertHistoryElement(historyElement);
+ }
+
+ /**
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#newFilter()
+ */
+ public Filter newFilter()
+ {
+ return new FilterImpl();
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getCollectionByQuery(java.lang.Class, org.apache.portals.graffito.services.search.Filter)
+ */
+ public Collection getCollectionByQuery(Class clazz, Filter filter) throws ContentPersistenceException
+ {
+
+ Collection foundStores = null;
+ ArrayList allCmsObjects = new ArrayList();
+
+ try
+ {
+ // Find all stores concerned by the filter criteria
+ foundStores = findPersistenceStores(filter);
+ Iterator storeIterator = foundStores.iterator();
+
+ // Loop on the found stores and execute the query
+ while (storeIterator.hasNext())
+ {
+ ContentStore store = (ContentStore) storeIterator.next();
+
+ Collection cmsObjects = store.getCollectionByQuery(clazz, filter);
+ allCmsObjects.addAll(cmsObjects);
+ }
+ }
+ catch (CmsPermissionException e)
+ {
+ return new ArrayList();
+ }
+ return allCmsObjects;
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getIteratorByQuery(java.lang.Class, org.apache.portals.graffito.services.search.Filter)
+ */
+ public Iterator getIteratorByQuery(Class clazz, Filter filter) throws ContentPersistenceException
+ {
+ MultiStoreIterator multiStoreIterator = new MultiStoreIterator();
+ try
+ {
+
+ Collection foundStores = null;
+ // Find all stores concerned by the filter criteria
+ foundStores = findPersistenceStores(filter);
+ Iterator storeIterator = foundStores.iterator();
+ while (storeIterator.hasNext())
+ {
+ ContentStore store = (ContentStore) storeIterator.next();
+ Iterator iterator = store.getIteratorByQuery(clazz, filter);
+ multiStoreIterator.addIterator(iterator);
+
+ }
+ return multiStoreIterator;
+ }
+ catch (CmsPermissionException e)
+ {
+ return new MultiStoreIterator();
+ }
+
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getObjectbyQuery(java.lang.Class, org.apache.portals.graffito.services.search.Filter)
+ */
+ public Object getObjectbyQuery(Class clazz, Filter filter) throws CmsPermissionException
+ {
+
+ ContentStore store = null;
+ Iterator iterator = findPersistenceStores(filter).iterator();
+ while (iterator.hasNext())
+ {
+ store = (ContentStore) iterator.next();
+ Object cmsObject = store.getObjectByQuery(clazz, filter);
+ if (cmsObject != null)
+ {
+ return cmsObject;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @see ContentPersistenceService#getGraffitoMasterStore()
+ */
+ public ContentStore getGraffitoMasterStore()
+ {
+ ContentStore store = contentStoreService.getStore(graffitoMasterServer.getAlias());
+
+ return store;
+ }
+
+ /**
+ * @see ContentPersistenceService#getStore(String)
+ */
+ public ContentStore getStore(String persistenceStoreName)
+ {
+ return contentStoreService.getStore(persistenceStoreName);
+ }
+
+ /**
+ * @see ContentPersistenceService#getServer(String)
+ */
+ public Server getServer(String scope) throws ContentPersistenceException, CmsPermissionException
+ {
+ if (scope.equals(graffitoMasterServer.getScope()))
+ {
+ return graffitoMasterServer;
+ }
+
+ // All server references are stored into the Graffito Master Store
+ ContentStore store = store = getGraffitoMasterStore();
+ Filter filter = store.newFilter();
+ filter.addEqualTo("scope", scope);
+ return (Server) store.getObjectByQuery(Server.class, filter);
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#registerServer(org.apache.portals.graffito.model.server.Server)
+ */
+ public void registerServer(Server server) throws CmsPermissionException, CmsIncorrectServerException
+ {
+ try
+ {
+ if (!contentStoreService.canRegisterServer(server))
+ {
+ throw new CmsIncorrectServerException("Impossible to instantiate the ContentStore for server "
+ + server.getAlias() + " - The server scope already exists");
+ }
+ contentStoreService.newStore(server);
+ }
+ catch (CmsInstantiateException e)
+ {
+ throw new CmsIncorrectServerException("Impossible to instantiate the ContentStore for server " + server.getAlias(), e);
+
+ }
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#unRegisterServer(org.apache.portals.graffito.model.server.Server)
+ */
+ public void unRegisterServer(Server server) throws CmsPermissionException, CmsIncorrectServerException
+ {
+ // it is not authorized to unregister the Graffito Master Store.
+ if (this.graffitoMasterServer.equals(server))
+ {
+ throw new CmsIncorrectServerException("Cannot unregister the Graffito Master Server");
+ }
+ contentStoreService.removeStore(server.getAlias());
+ }
+
+ /**
+ * @see org.apache.portals.graffito.persistenceService.ContentPersistenceService#getServers(boolean)
+ */
+ public Collection getServers(boolean withMasterServer)
+ {
+ try
+ {
+ ContentStore store = getGraffitoMasterStore();
+ Filter filter = store.newFilter();
+ Collection servers = store.getCollectionByQuery(Server.class, filter);
+ if (withMasterServer)
+ {
+ // Add also the Graffito Master Server
+ servers.add(graffitoMasterServer);
+ }
+ return servers;
+ }
+ catch (CmsPermissionException e)
+ {
+ return new ArrayList();
+ }
+ }
+
+ /**
+ * Find the persistenceService store associated to all kind of object (CmsObject,
+ * Server, ...)
+ *
+ * @param object The object for which the persistenceService store has to be found
+ * @return the persistenceService store found or null
+ */
+ private ContentStore findPersistenceStore(Object object)
+ {
+ // if the ojbect is an instance of Server => Get the Graffito Master Server
+ // All servers references are stored into the Graffito Master Server
+ if (object instanceof Server)
+ {
+ return this.getGraffitoMasterStore();
+ }
+
+ //if the object is an instance of CmsObject, try to find a server which
+ // match to the object uri
+ if (object instanceof CmsObject)
+ {
+ return this.findPersistenceStore(((CmsObject) object).getUri());
+ }
+
+ return this.getGraffitoMasterStore();
+ }
+
+ /**
+ * Find the persistenceService store associated to an uri
+ *
+ * @param uri The uri for which the persistenceService store has to be found
+ * @return the persistenceService store found or null
+ */
+ private ContentStore findPersistenceStore(String uri)
+ {
+ Iterator servers = this.getServers(true).iterator();
+ while (servers.hasNext())
+ {
+ Server server = (Server) servers.next();
+ if (uri.startsWith(server.getScope()))
+ {
+ return this.findPersistenceStore(server);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find the persistenceService store associated to a server
+ *
+ * @param server The server for which the persistenceService store has to be found
+ * @return the persistenceService store found or null
+ */
+ private ContentStore findPersistenceStore(Server server)
+ {
+ return getStore(server.getAlias());
+ }
+
+ /**
+ * Find the persistenceService stores associated to an filter. The query can be
+ * apply to more than one server. The scope attribute in the filter object
+ * defined in which server to look at.
+ *
+ * @param filter The filter for which the persistenceService stores have to be found
+ * @return the persistenceService store collection or null
+ */
+ private Collection findPersistenceStores(Filter filter)
+ {
+ String scope = filter.getScope();
+ Collection allServers = this.getServers(true);
+ ArrayList selectedStores = new ArrayList();
+ // if there is no scope, return all stores
+ if (scope == null || scope.equals(""))
+ {
+ Iterator servers = allServers.iterator();
+ while (servers.hasNext())
+ {
+ Server server = (Server) servers.next();
+ ContentStore store = findPersistenceStore(server);
+ selectedStores.add(store);
+ }
+ }
+ else
+ {
+ //else loop on all servers in order to find thoses which match to
+ // the filter scope
+ Iterator servers = allServers.iterator();
+ while (servers.hasNext())
+ {
+ Server server = (Server) servers.next();
+ if (scope.startsWith(server.getScope()))
+ {
+ ContentStore store = findPersistenceStore(server);
+ selectedStores.add(store);
+ }
+ }
+ }
+ return selectedStores;
+ }
+
+ private void registerAllStores()
+ {
+ Server server = null;
+ try
+ {
+ // Add the Graffito Master Server
+ server = graffitoMasterServer;
+ contentStoreService.newStore(server);
+
+ // Get all server references and create one ContenStore per server.
+ // Each Server data object contains information on how to
+ // connect to the external server.
+ Iterator servers = this.getServers(false).iterator();
+ while (servers.hasNext())
+ {
+ server = (Server) servers.next();
+
+ contentStoreService.newStore(server);
+ }
+ }
+ catch (CmsInstantiateException e)
+ {
+ // If a store class is not found, just ignore it
+ // TODO : Need to register all incorrect server dao in order to publish them in an admin portlet
+ log.error("Impossible to find the store class : " + server.getStoreClassName());
+ }
+ }
+
}
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/persistence/impl/ContentPersistenceServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/persistence/impl/ContentStoreServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/persistence/impl/DatasourceEnabledSpringTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/persistence/impl/MultiStoreIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/persistence/impl/PersistenceSupportedTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/security/CmsAccessController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/security/impl/AbstractSecurityTestcase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/security/impl/CmsAccessControllerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/security/impl/EmptyCmsAccessControllerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/security/impl/GraffitoAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/AbstractModelServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/BaseContentServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/ContentModelServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/ContentPermissionServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/ContentPermissionServiceImpl.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/ContentPermissionServiceImpl.java (original)
+++ incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/ContentPermissionServiceImpl.java Wed Sep 20 12:37:05 2006
@@ -1,220 +1,220 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- * as applicable.
- *
- * 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.apache.portals.graffito.services.core.impl;
-
-import java.lang.reflect.Constructor;
-import java.security.Permission;
-import java.security.Permissions;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-
-import org.apache.jetspeed.security.impl.PermissionManagerImpl;
-import org.apache.jetspeed.security.om.InternalPermission;
-import org.apache.jetspeed.security.om.InternalPrincipal;
-import org.apache.jetspeed.security.om.impl.InternalPermissionImpl;
-import org.apache.jetspeed.security.om.impl.InternalPrincipalImpl;
-import org.apache.ojb.broker.query.Criteria;
-import org.apache.ojb.broker.query.Query;
-import org.apache.ojb.broker.query.QueryFactory;
-import org.apache.portals.graffito.exception.ContentManagementException;
-import org.apache.portals.graffito.model.core.CmsObject;
-import org.apache.portals.graffito.model.permission.CmsPermission;
-import org.apache.portals.graffito.model.permission.impl.CmsPermissionImpl;
-import org.apache.portals.graffito.services.core.ContentPermissionService;
-
-
-/**
- * Default implementation for {@link org.apache.portals.graffito.services.core.ContentPermissionService}
- *
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
- * @version $Id: Exp $
- */
-public class ContentPermissionServiceImpl extends PermissionManagerImpl implements ContentPermissionService
-{
- /**
- *
- * @see org.apache.portals.graffito.services.core.ContentPermissionService#createPermission(java.lang.String, java.lang.String)
- */
- public CmsPermission createPermission(String name, String actions) throws ContentManagementException
- {
- return new CmsPermissionImpl(name, actions);
- }
-
- /**
- *
- * @see org.apache.portals.graffito.services.core.ContentPermissionService#getPermissions(org.apache.portals.graffito.model.core.CmsObject)
- */
- public Permissions getPermissions(CmsObject cmsObject)
- {
- return this.getPermissions(cmsObject.getUri());
- }
-
- /**
- *
- * @see org.apache.portals.graffito.services.core.ContentPermissionService#getPermissions(java.lang.String)
- */
- public Permissions getPermissions(String uri)
- {
- Criteria criteria = new Criteria();
-
- // Some permission can contains special char like "*", "-" (see CmsPermissionImpl)
- ArrayList values = new ArrayList();
- values.add(uri);
- values.add(uri + "/*");
- values.add(uri + "/-");
-
- criteria.addIn("name", values);
- Query query = QueryFactory.newQuery(InternalPermissionImpl.class, criteria);
- Collection internalPermissions = getPersistenceBrokerTemplate().getCollectionByQuery(query);
-
- Permissions permissions = appendSecurityPermissions(internalPermissions);
- return permissions;
- }
-
-
- /**
- *
- * @see org.apache.portals.graffito.services.core.ContentPermissionService#grantPermission(java.lang.String, org.apache.portals.graffito.model.permission.CmsPermission)
- */
- public void grantPermission(String fullPath, CmsPermission permission) throws ContentManagementException
- {
-
- Collection internalPermissions = new ArrayList();
-
- InternalPrincipal internalPrincipal = getInternalPrincipal(fullPath);
- if (null == internalPrincipal)
- {
- throw new ContentManagementException("Impossible to find the principal for " + fullPath);
- }
- InternalPermission internalPermission = getInternalPermission(permission);
- if (null == internalPermission)
- {
- throw new ContentManagementException("Impossible to find the internal permission");
- }
-
- if (null != internalPrincipal.getPermissions())
- {
- internalPermissions.addAll(internalPrincipal.getPermissions());
- }
- if (!internalPermissions.contains(internalPermission))
- {
- internalPermissions.add(internalPermission);
- }
- try
- {
- internalPrincipal.setModifiedDate(new Timestamp(System.currentTimeMillis()));
- internalPrincipal.setPermissions(internalPermissions);
-
- getPersistenceBrokerTemplate().store(internalPrincipal);
- }
- catch (Exception e)
- {
- throw new ContentManagementException("Impossible to grant the permission " , e);
- }
-
-
- }
-
- /**
- *
- * Iterate through a collection of {@link InternalPermission}and build a
- * map with key = the principal and value = a collection of {@link Permission}
- * </p>
- *
- * @param omPermissions The collection of {@link InternalPermission}.
- *
- * @return The collection of {@link java.security.Permission}.
- */
- private Permissions appendSecurityPermissions(Collection omPermissions)
- {
- Permissions permissions = new Permissions();
- Iterator internalPermissionsIter = omPermissions.iterator();
- while (internalPermissionsIter.hasNext())
- {
- InternalPermission internalPermission = (InternalPermission) internalPermissionsIter.next();
-
- Permission permission = null;
- try
- {
-
- ArrayList fullPaths = new ArrayList();
- Iterator internalPrincipalsIter = internalPermission.getPrincipals().iterator();
- while (internalPrincipalsIter.hasNext())
- {
- InternalPrincipal internalPrincipal = (InternalPrincipal) internalPrincipalsIter.next();
- fullPaths.add(internalPrincipal.getFullPath());
- }
-
- Class permissionClass = Class.forName(internalPermission.getClassname());
- Class[] parameterTypes = { String.class, String.class, Collection.class };
- Constructor permissionConstructor = permissionClass.getConstructor(parameterTypes);
- Object[] initArgs = { internalPermission.getName(), internalPermission.getActions(), fullPaths };
- permission = (Permission) permissionConstructor.newInstance(initArgs);
- if(!Collections.list(permissions.elements()).contains(permission))
- {
- permissions.add(permission);
- }
-
-
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- return permissions;
- }
-
- /**
- *
- * Returns the {@link InternalPrincipal} from the full path.
- *
- * @param fullPath The full path.
- * @return The {@link InternalPrincipal}.
- */
- InternalPrincipal getInternalPrincipal(String fullPath)
- {
- Criteria filter = new Criteria();
- filter.addEqualTo("fullPath", fullPath);
- Query query = QueryFactory.newQuery(InternalPrincipalImpl.class, filter);
- InternalPrincipal internalPrincipal = (InternalPrincipal) getPersistenceBrokerTemplate().getObjectByQuery(query);
- return internalPrincipal;
- }
-
- /**
- * <p>
- * Returns the {@link InternalPermission} from a Permission object
- * </p>
- *
- * @param permission The permision
- * @return The {@link InternalPermission}.
- */
- InternalPermission getInternalPermission(CmsPermission permission)
- {
- Criteria filter = new Criteria();
- filter.addEqualTo("classname", permission.getClass().getName());
- filter.addEqualTo("name", permission.getName());
- filter.addEqualTo("actions", permission.getActions());
- Query query = QueryFactory.newQuery(InternalPermissionImpl.class, filter);
- InternalPermission internalPermission = (InternalPermission) getPersistenceBrokerTemplate().getObjectByQuery(query);
- return internalPermission;
- }
-
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.apache.portals.graffito.services.core.impl;
+
+import java.lang.reflect.Constructor;
+import java.security.Permission;
+import java.security.Permissions;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.apache.jetspeed.security.impl.PermissionManagerImpl;
+import org.apache.jetspeed.security.om.InternalPermission;
+import org.apache.jetspeed.security.om.InternalPrincipal;
+import org.apache.jetspeed.security.om.impl.InternalPermissionImpl;
+import org.apache.jetspeed.security.om.impl.InternalPrincipalImpl;
+import org.apache.ojb.broker.query.Criteria;
+import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.portals.graffito.exception.ContentManagementException;
+import org.apache.portals.graffito.model.core.CmsObject;
+import org.apache.portals.graffito.model.permission.CmsPermission;
+import org.apache.portals.graffito.model.permission.impl.CmsPermissionImpl;
+import org.apache.portals.graffito.services.core.ContentPermissionService;
+
+
+/**
+ * Default implementation for {@link org.apache.portals.graffito.services.core.ContentPermissionService}
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class ContentPermissionServiceImpl extends PermissionManagerImpl implements ContentPermissionService
+{
+ /**
+ *
+ * @see org.apache.portals.graffito.services.core.ContentPermissionService#createPermission(java.lang.String, java.lang.String)
+ */
+ public CmsPermission createPermission(String name, String actions) throws ContentManagementException
+ {
+ return new CmsPermissionImpl(name, actions);
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.services.core.ContentPermissionService#getPermissions(org.apache.portals.graffito.model.core.CmsObject)
+ */
+ public Permissions getPermissions(CmsObject cmsObject)
+ {
+ return this.getPermissions(cmsObject.getUri());
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.services.core.ContentPermissionService#getPermissions(java.lang.String)
+ */
+ public Permissions getPermissions(String uri)
+ {
+ Criteria criteria = new Criteria();
+
+ // Some permission can contains special char like "*", "-" (see CmsPermissionImpl)
+ ArrayList values = new ArrayList();
+ values.add(uri);
+ values.add(uri + "/*");
+ values.add(uri + "/-");
+
+ criteria.addIn("name", values);
+ Query query = QueryFactory.newQuery(InternalPermissionImpl.class, criteria);
+ Collection internalPermissions = getPersistenceBrokerTemplate().getCollectionByQuery(query);
+
+ Permissions permissions = appendSecurityPermissions(internalPermissions);
+ return permissions;
+ }
+
+
+ /**
+ *
+ * @see org.apache.portals.graffito.services.core.ContentPermissionService#grantPermission(java.lang.String, org.apache.portals.graffito.model.permission.CmsPermission)
+ */
+ public void grantPermission(String fullPath, CmsPermission permission) throws ContentManagementException
+ {
+
+ Collection internalPermissions = new ArrayList();
+
+ InternalPrincipal internalPrincipal = getInternalPrincipal(fullPath);
+ if (null == internalPrincipal)
+ {
+ throw new ContentManagementException("Impossible to find the principal for " + fullPath);
+ }
+ InternalPermission internalPermission = getInternalPermission(permission);
+ if (null == internalPermission)
+ {
+ throw new ContentManagementException("Impossible to find the internal permission");
+ }
+
+ if (null != internalPrincipal.getPermissions())
+ {
+ internalPermissions.addAll(internalPrincipal.getPermissions());
+ }
+ if (!internalPermissions.contains(internalPermission))
+ {
+ internalPermissions.add(internalPermission);
+ }
+ try
+ {
+ internalPrincipal.setModifiedDate(new Timestamp(System.currentTimeMillis()));
+ internalPrincipal.setPermissions(internalPermissions);
+
+ getPersistenceBrokerTemplate().store(internalPrincipal);
+ }
+ catch (Exception e)
+ {
+ throw new ContentManagementException("Impossible to grant the permission " , e);
+ }
+
+
+ }
+
+ /**
+ *
+ * Iterate through a collection of {@link InternalPermission}and build a
+ * map with key = the principal and value = a collection of {@link Permission}
+ * </p>
+ *
+ * @param omPermissions The collection of {@link InternalPermission}.
+ *
+ * @return The collection of {@link java.security.Permission}.
+ */
+ private Permissions appendSecurityPermissions(Collection omPermissions)
+ {
+ Permissions permissions = new Permissions();
+ Iterator internalPermissionsIter = omPermissions.iterator();
+ while (internalPermissionsIter.hasNext())
+ {
+ InternalPermission internalPermission = (InternalPermission) internalPermissionsIter.next();
+
+ Permission permission = null;
+ try
+ {
+
+ ArrayList fullPaths = new ArrayList();
+ Iterator internalPrincipalsIter = internalPermission.getPrincipals().iterator();
+ while (internalPrincipalsIter.hasNext())
+ {
+ InternalPrincipal internalPrincipal = (InternalPrincipal) internalPrincipalsIter.next();
+ fullPaths.add(internalPrincipal.getFullPath());
+ }
+
+ Class permissionClass = Class.forName(internalPermission.getClassname());
+ Class[] parameterTypes = { String.class, String.class, Collection.class };
+ Constructor permissionConstructor = permissionClass.getConstructor(parameterTypes);
+ Object[] initArgs = { internalPermission.getName(), internalPermission.getActions(), fullPaths };
+ permission = (Permission) permissionConstructor.newInstance(initArgs);
+ if(!Collections.list(permissions.elements()).contains(permission))
+ {
+ permissions.add(permission);
+ }
+
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ return permissions;
+ }
+
+ /**
+ *
+ * Returns the {@link InternalPrincipal} from the full path.
+ *
+ * @param fullPath The full path.
+ * @return The {@link InternalPrincipal}.
+ */
+ InternalPrincipal getInternalPrincipal(String fullPath)
+ {
+ Criteria filter = new Criteria();
+ filter.addEqualTo("fullPath", fullPath);
+ Query query = QueryFactory.newQuery(InternalPrincipalImpl.class, filter);
+ InternalPrincipal internalPrincipal = (InternalPrincipal) getPersistenceBrokerTemplate().getObjectByQuery(query);
+ return internalPrincipal;
+ }
+
+ /**
+ * <p>
+ * Returns the {@link InternalPermission} from a Permission object
+ * </p>
+ *
+ * @param permission The permision
+ * @return The {@link InternalPermission}.
+ */
+ InternalPermission getInternalPermission(CmsPermission permission)
+ {
+ Criteria filter = new Criteria();
+ filter.addEqualTo("classname", permission.getClass().getName());
+ filter.addEqualTo("name", permission.getName());
+ filter.addEqualTo("actions", permission.getActions());
+ Query query = QueryFactory.newQuery(InternalPermissionImpl.class, filter);
+ InternalPermission internalPermission = (InternalPermission) getPersistenceBrokerTemplate().getObjectByQuery(query);
+ return internalPermission;
+ }
+
}
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/ContentPermissionServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/ContentServerServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/core/impl/ContentVersionServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/dm/impl/DocumentModelServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/search/impl/ContentIndexServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/search/impl/ContentSearchServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/graffito/trunk/components/src/java/org/apache/portals/graffito/services/search/impl/FilterImpl.java
------------------------------------------------------------------------------
svn:eol-style = native