/** * Removes a cached XML content from the cache if it matches a given resource.<p> * * @param resource the resource for which the cached XML content should be removed * @param cache the cache from which to remove the XML content */ private <CONTENT extends CmsXmlContent> void removeCachedContent(CmsResource resource, Map<String, CONTENT> cache) { Iterator<Map.Entry<String, CONTENT>> iterator = cache.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, CONTENT> entry = iterator.next(); CONTENT content = entry.getValue(); CmsResource contentFile = content.getFile(); if (contentFile.getStructureId().equals(resource.getStructureId()) || contentFile.getResourceId().equals(resource.getResourceId())) { iterator.remove(); } } } }
/** * Reads an access control entry from the cms.<p> * * The access control entries of a resource are readable by everyone. * * @param dbc the current database context * @param resource the resource * @param principal the id of a group or a user any other entity * @return an access control entry that defines the permissions of the entity for the given resource * @throws CmsException if something goes wrong */ public CmsAccessControlEntry readAccessControlEntry(CmsDbContext dbc, CmsResource resource, CmsUUID principal) throws CmsException { return m_userDriver.readAccessControlEntry(dbc, dbc.currentProject(), resource.getResourceId(), principal); }
/** * Checks whether the content for the resource being imported exists either in the VFS or in the import file.<p> * * @param resource the resource which should be checked * * @return true if the content exists in the VFS or import file */ private boolean hasContentInVfsOrImport(CmsResource resource) { if (m_contentFiles.contains(resource.getResourceId())) { return true; } try { List<CmsResource> resources = getCms().readSiblings(resource, CmsResourceFilter.ALL); if (!resources.isEmpty()) { return true; } } catch (CmsException e) { LOG.warn(e.getLocalizedMessage(), e); } return false; }
/** * Checks whether the content for the resource being imported exists either in the VFS or in the import file.<p> * * @param resource the resource which should be checked * * @return true if the content exists in the VFS or import file */ private boolean hasContentInVfsOrImport(CmsResource resource) { if (m_contentFiles.contains(resource.getResourceId())) { return true; } try { List<CmsResource> resources = getCms().readSiblings(resource, CmsResourceFilter.ALL); if (!resources.isEmpty()) { return true; } } catch (CmsException e) { LOG.warn(e.getLocalizedMessage(), e); } return false; }
/** * Creates a new access control entry and stores it for later write out. * * @param res the resource * @param id the id of the principal * @param allowed the allowed permissions * @param denied the denied permissions * @param flags the flags * * @return the created ACE */ protected CmsAccessControlEntry getImportAccessControlEntry( CmsResource res, String id, String allowed, String denied, String flags) { return new CmsAccessControlEntry( res.getResourceId(), new CmsUUID(id), Integer.parseInt(allowed), Integer.parseInt(denied), Integer.parseInt(flags)); }
/** * Creates a new access control entry and stores it for later write out. * * @param res the resource * @param id the id of the principal * @param allowed the allowed permissions * @param denied the denied permissions * @param flags the flags * * @return the created ACE */ protected CmsAccessControlEntry getImportAccessControlEntry( CmsResource res, String id, String allowed, String denied, String flags) { return new CmsAccessControlEntry( res.getResourceId(), new CmsUUID(id), Integer.parseInt(allowed), Integer.parseInt(denied), Integer.parseInt(flags)); }
/** * Writes a vector of access control entries as new access control entries of a given resource.<p> * * Already existing access control entries of this resource are removed before. * Access is granted, if:<p> * <ul> * <li>the current user has control permission on the resource</li> * </ul> * * @param dbc the current database context * @param resource the resource * @param acEntries a list of <code>{@link CmsAccessControlEntry}</code> objects * * @throws CmsException if something goes wrong */ public void importAccessControlEntries(CmsDbContext dbc, CmsResource resource, List acEntries) throws CmsException { m_userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), resource.getResourceId()); Iterator i = acEntries.iterator(); while (i.hasNext()) { m_userDriver.writeAccessControlEntry(dbc, dbc.currentProject(), (CmsAccessControlEntry)i.next()); } m_monitor.clearAccessControlListCache(); }
/** * Reads an access control entry from the cms.<p> * * The access control entries of a resource are readable by everyone. * * @param dbc the current database context * @param resource the resource * @param principal the id of a group or a user any other entity * @return an access control entry that defines the permissions of the entity for the given resource * @throws CmsException if something goes wrong */ public CmsAccessControlEntry readAccessControlEntry(CmsDbContext dbc, CmsResource resource, CmsUUID principal) throws CmsException { return getUserDriver(dbc).readAccessControlEntry( dbc, dbc.currentProject(), resource.getResourceId(), principal); }
/** * Removes an access control entry for a given resource and principal.<p> * * @param dbc the current database context * @param resource the resource * @param principal the id of the principal to remove the the access control entry for * * @throws CmsException if something goes wrong */ public void removeAccessControlEntry(CmsDbContext dbc, CmsResource resource, CmsUUID principal) throws CmsException { // remove the ace m_userDriver.removeAccessControlEntry(dbc, dbc.currentProject(), resource.getResourceId(), principal); // update the "last modified" information setDateLastModified(dbc, resource, resource.getDateLastModified()); // clear the cache m_monitor.clearAccessControlListCache(); // fire a resource modification event HashMap data = new HashMap(2); data.put(I_CmsEventListener.KEY_RESOURCE, resource); data.put(I_CmsEventListener.KEY_CHANGE, new Integer(CHANGED_ACCESSCONTROL)); OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, data)); }
/** * Writes a vector of access control entries as new access control entries of a given resource.<p> * * Already existing access control entries of this resource are removed before. * Access is granted, if:<p> * <ul> * <li>the current user has control permission on the resource</li> * </ul> * * @param dbc the current database context * @param resource the resource * @param acEntries a list of <code>{@link CmsAccessControlEntry}</code> objects * * @throws CmsException if something goes wrong */ public void importAccessControlEntries( CmsDbContext dbc, CmsResource resource, List<CmsAccessControlEntry> acEntries) throws CmsException { I_CmsUserDriver userDriver = getUserDriver(dbc); userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), resource.getResourceId()); Iterator<CmsAccessControlEntry> i = acEntries.iterator(); while (i.hasNext()) { userDriver.writeAccessControlEntry(dbc, dbc.currentProject(), i.next()); } m_monitor.clearAccessControlListCache(); }
/** * @see org.opencms.db.I_CmsVfsDriver#writeLastModifiedProjectId(org.opencms.db.CmsDbContext, org.opencms.file.CmsProject, CmsUUID, org.opencms.file.CmsResource) */ public void writeLastModifiedProjectId( CmsDbContext dbc, CmsProject project, CmsUUID projectId, CmsResource resource) throws CmsDataAccessException { try { Query q = m_sqlManager.createQuery(dbc, project, C_RESOURCES_UPDATE_PROJECT_LASTMODIFIED); q.setParameter(1, resource.getResourceId().toString()); @SuppressWarnings("unchecked") List<I_CmsDAOResources> res = q.getResultList(); for (I_CmsDAOResources r : res) { r.setProjectLastModified(projectId.toString()); } } catch (PersistenceException e) { throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e); } }
/** * @see org.opencms.db.I_CmsVfsDriver#writeLastModifiedProjectId(org.opencms.db.CmsDbContext, org.opencms.file.CmsProject, CmsUUID, org.opencms.file.CmsResource) */ public void writeLastModifiedProjectId(CmsDbContext dbc, CmsProject project, CmsUUID projectId, CmsResource resource) throws CmsDataAccessException { Connection conn = null; PreparedStatement stmt = null; try { conn = m_sqlManager.getConnection(dbc); stmt = m_sqlManager.getPreparedStatement(conn, project, "C_RESOURCES_UPDATE_PROJECT_LASTMODIFIED"); stmt.setString(1, projectId.toString()); stmt.setString(2, resource.getResourceId().toString()); stmt.executeUpdate(); } catch (SQLException e) { throw new CmsDbSqlException(Messages.get().container( Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)), e); } finally { m_sqlManager.closeAll(dbc, conn, stmt, null); } }
/** * @see org.opencms.db.I_CmsVfsDriver#writeLastModifiedProjectId(org.opencms.db.CmsDbContext, org.opencms.file.CmsProject, CmsUUID, org.opencms.file.CmsResource) */ public void writeLastModifiedProjectId( CmsDbContext dbc, CmsProject project, CmsUUID projectId, CmsResource resource) throws CmsDataAccessException { Connection conn = null; PreparedStatement stmt = null; try { conn = m_sqlManager.getConnection(dbc); stmt = m_sqlManager.getPreparedStatement(conn, project, "C_RESOURCES_UPDATE_PROJECT_LASTMODIFIED"); stmt.setString(1, projectId.toString()); stmt.setString(2, resource.getResourceId().toString()); stmt.executeUpdate(); } catch (SQLException e) { throw new CmsDbSqlException( Messages.get().container(Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)), e); } finally { m_sqlManager.closeAll(dbc, conn, stmt, null); } }
/** * Creates an object for published VFS resources.<p> * * @param resource an CmsResource object to create a CmsPublishedResource from * @param state the resource state * @param publishTag the publish tag */ public CmsPublishedResource(CmsResource resource, int publishTag, CmsResourceState state) { this( resource.getStructureId(), resource.getResourceId(), publishTag, resource.getRootPath(), resource.getTypeId(), resource.isFolder(), state, resource.getSiblingCount()); }
/** * Creates an object for published VFS resources.<p> * * @param resource an CmsResource object to create a CmsPublishedResource from * @param state the resource state * @param publishTag the publish tag */ public CmsPublishedResource(CmsResource resource, int publishTag, CmsResourceState state) { this( resource.getStructureId(), resource.getResourceId(), publishTag, resource.getRootPath(), resource.getTypeId(), resource.isFolder(), state, resource.getSiblingCount()); }
/** * Returns the virtual resource.<p> * * @return the virtual resource */ public CmsResource getResource() { return new CmsResource( m_base.getStructureId(), m_base.getResourceId(), m_rootPath, m_typeId, m_isFolder, m_base.getFlags(), m_base.getProjectLastModified(), m_base.getState(), m_base.getDateCreated(), m_base.getUserCreated(), m_base.getDateLastModified(), m_base.getUserLastModified(), m_base.getDateReleased(), m_base.getDateExpired(), m_base.getSiblingCount(), m_length, m_base.getDateContent(), m_base.getVersion()); }
/** * 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 } }
/** * Constructor, creates a new CmsFolder Object from the given CmsResource.<p> * * @param resource the base resource object to create a folder from */ public CmsFolder(CmsResource resource) { this( resource.getStructureId(), resource.getResourceId(), resource.getRootPath(), resource.getTypeId(), resource.getFlags(), resource.getProjectLastModified(), resource.getState(), resource.getDateCreated(), resource.getUserCreated(), resource.getDateLastModified(), resource.getUserLastModified(), resource.getDateReleased(), resource.getDateExpired(), resource.getVersion()); }
/** * Constructor, creates a new CmsFolder Object from the given CmsResource.<p> * * @param resource the base resource object to create a folder from */ public CmsFolder(CmsResource resource) { this( resource.getStructureId(), resource.getResourceId(), resource.getRootPath(), resource.getTypeId(), resource.getFlags(), resource.getProjectLastModified(), resource.getState(), resource.getDateCreated(), resource.getUserCreated(), resource.getDateLastModified(), resource.getUserLastModified(), resource.getDateReleased(), resource.getDateExpired(), resource.getVersion()); }
/** * Returns the virtual resource.<p> * * @return the virtual resource */ public CmsResource getResource() { return new CmsResource( m_base.getStructureId(), m_base.getResourceId(), m_rootPath, m_typeId, m_isFolder, m_base.getFlags(), m_base.getProjectLastModified(), m_base.getState(), m_base.getDateCreated(), m_base.getUserCreated(), m_base.getDateLastModified(), m_base.getUserLastModified(), m_base.getDateReleased(), m_base.getDateExpired(), m_base.getSiblingCount(), m_length, m_base.getDateContent(), m_base.getVersion()); }