/** * Returns all locked resources in a given folder.<p> * * @param dbc the current database context * @param resource the folder to search in * @param filter the lock filter * * @return a list of locked resource paths (relative to current site) * * @throws CmsException if the current project is locked */ public List getLockedResources(CmsDbContext dbc, CmsResource resource, CmsLockFilter filter) throws CmsException { List lockedResources = new ArrayList(); // get locked resources Iterator it = m_lockManager.getLocks(dbc, resource.getRootPath(), filter).iterator(); while (it.hasNext()) { CmsLock lock = (CmsLock)it.next(); lockedResources.add(dbc.removeSiteRoot(lock.getResourceName())); } Collections.sort(lockedResources); return lockedResources; }
/** * Returns all locked resources in a given folder.<p> * * @param dbc the current database context * @param resource the folder to search in * @param filter the lock filter * * @return a list of locked resource paths (relative to current site) * * @throws CmsException if the current project is locked */ public List<String> getLockedResources(CmsDbContext dbc, CmsResource resource, CmsLockFilter filter) throws CmsException { List<String> lockedResources = new ArrayList<String>(); // get locked resources Iterator<CmsLock> it = m_lockManager.getLocks(dbc, resource.getRootPath(), filter).iterator(); while (it.hasNext()) { CmsLock lock = it.next(); lockedResources.add(dbc.removeSiteRoot(lock.getResourceName())); } Collections.sort(lockedResources); return lockedResources; }
/** * Checks if the given resource contains a resource that has a system lock.<p> * * @param dbc the current database context * @param resource the resource to check * * @throws CmsException in case there is a system lock contained in the given resource */ protected void checkSystemLocks(CmsDbContext dbc, CmsResource resource) throws CmsException { if (m_lockManager.hasSystemLocks(dbc, resource)) { throw new CmsLockException(Messages.get().container( Messages.ERR_RESOURCE_SYSTEM_LOCKED_1, dbc.removeSiteRoot(resource.getRootPath()))); } }
/** * Checks if the given resource contains a resource that has a system lock.<p> * * @param dbc the current database context * @param resource the resource to check * * @throws CmsException in case there is a system lock contained in the given resource */ protected void checkSystemLocks(CmsDbContext dbc, CmsResource resource) throws CmsException { if (m_lockManager.hasSystemLocks(dbc, resource)) { throw new CmsLockException( Messages.get().container( Messages.ERR_RESOURCE_SYSTEM_LOCKED_1, dbc.removeSiteRoot(resource.getRootPath()))); } }
/** * Undelete the resource.<p> * * @param dbc the current database context * @param resource the name of the resource to apply this operation to * * @throws CmsException if something goes wrong * * @see CmsObject#undeleteResource(String, boolean) * @see I_CmsResourceType#undelete(CmsObject, CmsSecurityManager, CmsResource, boolean) */ public void undelete(CmsDbContext dbc, CmsResource resource) throws CmsException { if (!resource.getState().isDeleted()) { throw new CmsVfsException(Messages.get().container( Messages.ERR_UNDELETE_FOR_RESOURCE_DELETED_1, dbc.removeSiteRoot(resource.getRootPath()))); } // set the state to changed resource.setState(CmsResourceState.STATE_CHANGED); // perform the changes updateState(dbc, resource, false); // clear the cache m_monitor.clearResourceCache(); // fire change event HashMap data = new HashMap(2); data.put(I_CmsEventListener.KEY_RESOURCE, resource); data.put(I_CmsEventListener.KEY_CHANGE, new Integer(CHANGED_RESOURCE)); OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, data)); }
/** * @see org.opencms.db.I_CmsVfsDriver#readFolder(org.opencms.db.CmsDbContext, CmsUUID, java.lang.String) */ public CmsFolder readFolder(CmsDbContext dbc, CmsUUID projectId, String folderPath) throws CmsDataAccessException { CmsFolder folder = null; folderPath = CmsFileUtil.removeTrailingSeparator(folderPath); try { Query q = m_sqlManager.createQuery(dbc, projectId, C_RESOURCES_READ); q.setParameter(1, folderPath); try { Object[] o = (Object[])q.getSingleResult(); folder = createFolder(o, projectId, true); } catch (NoResultException e) { throw new CmsVfsResourceNotFoundException( Messages.get().container(Messages.ERR_READ_FOLDER_1, dbc.removeSiteRoot(folderPath))); } } catch (PersistenceException e) { throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e); } return folder; }
/** * Reads a resource from the OpenCms VFS, using the specified resource filter.<p> * * @param dbc the current database context * @param resourcePath the name of the resource to read (full path) * @param filter the resource filter to use while reading * * @return the resource that was read * * @throws CmsException if something goes wrong * * @see CmsObject#readResource(String, CmsResourceFilter) * @see CmsObject#readResource(String) * @see CmsObject#readFile(CmsResource) */ protected CmsResource readResource(CmsDbContext dbc, String resourcePath, CmsResourceFilter filter) throws CmsException { if (resourcePath == null) { throw new CmsVfsResourceNotFoundException(org.opencms.db.generic.Messages.get().container( org.opencms.db.generic.Messages.ERR_READ_RESOURCE_1, dbc.removeSiteRoot(resourcePath))); } // read the resource from the VFS CmsResource resource = m_driverManager.readResource(dbc, resourcePath, filter); // check if the user has read access to the resource checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_READ, true, filter); // access was granted - return the resource return resource; }
/** * Enumeration class for the mode parameter in the * {@link CmsDriverManager#readChangedResourcesInsideProject(CmsDbContext, CmsUUID, CmsReadChangedProjectResourceMode)} * method.<p> */ private static class CmsReadChangedProjectResourceMode { /** * Default constructor.<p> */ protected CmsReadChangedProjectResourceMode() { // noop } }
/** * Adds a new relation to the given resource.<p> * * @param dbc the database context * @param resource the resource to add the relation to * @param target the target of the relation * @param type the type of the relation * @param importCase if importing relations * * @throws CmsException if something goes wrong */ public void addRelationToResource( CmsDbContext dbc, CmsResource resource, CmsResource target, CmsRelationType type, boolean importCase) throws CmsException { if (type.isDefinedInContent()) { throw new CmsIllegalArgumentException(Messages.get().container( Messages.ERR_ADD_RELATION_IN_CONTENT_3, dbc.removeSiteRoot(resource.getRootPath()), dbc.removeSiteRoot(target.getRootPath()), type.getLocalizedName(dbc.getRequestContext().getLocale()))); } CmsRelation relation = new CmsRelation(resource, target, type); m_vfsDriver.createRelation(dbc, dbc.currentProject().getUuid(), relation); if (!importCase) { setDateLastModified(dbc, resource, System.currentTimeMillis()); } }
/** * Deletes all relations for the given resource matching the given filter.<p> * * @param dbc the current db context * @param resource the resource to delete the relations for * @param filter the filter to use for deletion * * @throws CmsException if something goes wrong * * @see CmsSecurityManager#deleteRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter) */ public void deleteRelationsForResource(CmsDbContext dbc, CmsResource resource, CmsRelationFilter filter) throws CmsException { if (filter.includesDefinedInContent()) { throw new CmsIllegalArgumentException(Messages.get().container( Messages.ERR_DELETE_RELATION_IN_CONTENT_2, dbc.removeSiteRoot(resource.getRootPath()), filter.getTypes())); } m_vfsDriver.deleteRelations(dbc, dbc.currentProject().getUuid(), resource, filter); setDateLastModified(dbc, resource, System.currentTimeMillis()); }
/** * Updates/Creates the relations for the given resource.<p> * * @param context the current user context * @param resource the resource to update the relations for * @param relations the relations to update * * @throws CmsException if something goes wrong * * @see CmsDriverManager#updateRelationsForResource(CmsDbContext, CmsResource, List) */ public void updateRelationsForResource(CmsRequestContext context, CmsResource resource, List relations) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); try { m_driverManager.updateRelationsForResource(dbc, resource, relations); } catch (Exception e) { dbc.report(null, Messages.get().container( Messages.ERR_UPDATE_RELATIONS_1, dbc.removeSiteRoot(resource.getRootPath())), e); } finally { dbc.clear(); } }
/** * Updates/Creates the relations for the given resource.<p> * * @param context the current user context * @param resource the resource to update the relations for * @param relations the relations to update * * @throws CmsException if something goes wrong * * @see CmsDriverManager#updateRelationsForResource(CmsDbContext, CmsResource, List) */ public void updateRelationsForResource(CmsRequestContext context, CmsResource resource, List<CmsLink> relations) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); try { m_driverManager.updateRelationsForResource(dbc, resource, relations); } catch (Exception e) { dbc.report( null, Messages.get().container(Messages.ERR_UPDATE_RELATIONS_1, dbc.removeSiteRoot(resource.getRootPath())), e); } finally { dbc.clear(); } }
/** * @see org.opencms.db.I_CmsVfsDriver#readResource(org.opencms.db.CmsDbContext, CmsUUID, org.opencms.util.CmsUUID, boolean) */ public CmsResource readResource(CmsDbContext dbc, CmsUUID projectId, CmsUUID structureId, boolean includeDeleted) throws CmsDataAccessException { CmsResource resource = null; try { Query q = m_sqlManager.createQuery(dbc, projectId, C_RESOURCES_READBYID); q.setParameter(1, structureId.toString()); try { Object[] o = (Object[])q.getSingleResult(); resource = createResource(o, projectId); } catch (NoResultException e) { throw new CmsVfsResourceNotFoundException( Messages.get().container(Messages.ERR_READ_RESOURCE_WITH_ID_1, structureId)); } } catch (PersistenceException e) { throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e); } // check if this resource is marked as deleted and if we are allowed to return a deleted resource if ((resource != null) && resource.getState().isDeleted() && !includeDeleted) { throw new CmsVfsResourceNotFoundException( Messages.get().container( Messages.ERR_READ_DELETED_RESOURCE_1, dbc.removeSiteRoot(resource.getRootPath()))); } return resource; }
/** * Deletes all relations for the given resource matching the given filter.<p> * * @param context the current user context * @param resource the resource to delete the relations for * @param filter the filter to use for deletion * * @throws CmsException if something goes wrong * * @see #addRelationToResource(CmsRequestContext, CmsResource, CmsResource, CmsRelationType, boolean) * @see CmsObject#deleteRelationsFromResource(String, CmsRelationFilter) */ public void deleteRelationsForResource(CmsRequestContext context, CmsResource resource, CmsRelationFilter filter) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); try { checkOfflineProject(dbc); checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL); m_driverManager.deleteRelationsForResource(dbc, resource, filter); } catch (Exception e) { dbc.report( null, Messages.get().container(Messages.ERR_DELETE_RELATIONS_1, dbc.removeSiteRoot(resource.getRootPath())), e); } finally { dbc.clear(); } }
/** * Deletes all relations for the given resource matching the given filter.<p> * * @param context the current user context * @param resource the resource to delete the relations for * @param filter the filter to use for deletion * * @throws CmsException if something goes wrong * * @see #addRelationToResource(CmsRequestContext, CmsResource, CmsResource, CmsRelationType, boolean) * @see CmsObject#deleteRelationsFromResource(String, CmsRelationFilter) */ public void deleteRelationsForResource(CmsRequestContext context, CmsResource resource, CmsRelationFilter filter) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); try { checkOfflineProject(dbc); checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL); m_driverManager.deleteRelationsForResource(dbc, resource, filter); } catch (Exception e) { dbc.report(null, Messages.get().container( Messages.ERR_DELETE_RELATIONS_1, dbc.removeSiteRoot(resource.getRootPath())), e); } finally { dbc.clear(); } }
Messages.get().container( Messages.ERR_DELETE_RELATION_IN_CONTENT_2, dbc.removeSiteRoot(resource.getRootPath()), filter.getTypes()));
/** * Removes a resource from the given organizational unit.<p> * * @param context the current request context * @param orgUnit the organizational unit to remove the resource from * @param resource the resource that is to be removed from the organizational unit * * @throws CmsException if something goes wrong * * @see org.opencms.security.CmsOrgUnitManager#addResourceToOrgUnit(CmsObject, String, String) * @see org.opencms.security.CmsOrgUnitManager#addResourceToOrgUnit(CmsObject, String, String) */ public void removeResourceFromOrgUnit(CmsRequestContext context, CmsOrganizationalUnit orgUnit, CmsResource resource) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); try { checkRole(dbc, CmsRole.ADMINISTRATOR.forOrgUnit(orgUnit.getName())); checkOfflineProject(dbc); m_driverManager.removeResourceFromOrgUnit(dbc, orgUnit, resource); } catch (Exception e) { dbc.report(null, Messages.get().container( Messages.ERR_REMOVE_RESOURCE_FROM_ORGUNIT_2, orgUnit.getName(), dbc.removeSiteRoot(resource.getRootPath())), e); } finally { dbc.clear(); } }
/** * Adds a resource to the given organizational unit.<p> * * @param context the current request context * @param orgUnit the organizational unit to add the resource to * @param resource the resource that is to be added to the organizational unit * * @throws CmsException if something goes wrong * * @see org.opencms.security.CmsOrgUnitManager#addResourceToOrgUnit(CmsObject, String, String) * @see org.opencms.security.CmsOrgUnitManager#removeResourceFromOrgUnit(CmsObject, String, String) */ public void addResourceToOrgUnit(CmsRequestContext context, CmsOrganizationalUnit orgUnit, CmsResource resource) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); try { checkOfflineProject(dbc); checkRole(dbc, CmsRole.ADMINISTRATOR.forOrgUnit(orgUnit.getName())); m_driverManager.addResourceToOrgUnit(dbc, orgUnit, resource); } catch (Exception e) { dbc.report(null, Messages.get().container( Messages.ERR_ADD_RESOURCE_TO_ORGUNIT_2, orgUnit.getName(), dbc.removeSiteRoot(resource.getRootPath())), e); } finally { dbc.clear(); } }
/** * @see org.opencms.db.I_CmsProjectDriver#createProjectResource(org.opencms.db.CmsDbContext, CmsUUID, java.lang.String) */ public void createProjectResource(CmsDbContext dbc, CmsUUID projectId, String resourcePath) throws CmsDataAccessException { // do not create entries for online-project boolean projectResourceExists = false; try { readProjectResource(dbc, projectId, resourcePath); projectResourceExists = true; } catch (CmsVfsResourceNotFoundException e) { // resource does not exist yet, everything is okay projectResourceExists = false; } if (projectResourceExists) { throw new CmsVfsResourceAlreadyExistsException( Messages.get().container( Messages.ERR_RESOURCE_WITH_NAME_ALREADY_EXISTS_1, dbc.removeSiteRoot(resourcePath))); } try { CmsDAOProjectResources pr = new CmsDAOProjectResources(); pr.setProjectId(projectId.toString()); pr.setResourcePath(resourcePath); m_sqlManager.persist(dbc, pr); } catch (PersistenceException e) { throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e); } }
Messages.ERR_ADD_RESOURCE_TO_ORGUNIT_2, orgUnit.getName(), dbc.removeSiteRoot(resource.getRootPath())), e); } finally {