/** * Checks if the resource is unchanged *and* should be removed.<p> * * @param item the resource to check * @return true if the resource is unchanged and should be removed */ private boolean isUnchangedAndShouldBeRemoved(CmsResource item) { if (item.getState().isUnchanged()) { return !m_keepOriginalUnchangedResources || !m_originalResources.contains(item); } return false; }
/** * @see org.opencms.workflow.CmsDefaultPublishResourceFormatter.I_PublishResourceValidator#findInvalidResources(java.util.Set) */ public Set<CmsResource> findInvalidResources(Set<CmsResource> resources) { Set<CmsResource> result = new HashSet<CmsResource>(); for (CmsResource resource : resources) { if (resource.getState().isUnchanged()) { result.add(resource); } } return result; }
/** * Adds a new resource.<p> * * @param resource the resource to add */ public void add(CmsResource resource) { if (!m_processedIds.contains(resource.getStructureId())) { m_resources.add(resource); m_processedIds.add(resource.getStructureId()); m_changed |= !(resource.getState().isUnchanged()); } }
/** * Adds siblings to a set of publish resources.<p> * * @param publishResources the set to which siblings should be added */ protected void addSiblings(Set<CmsResource> publishResources) { List<CmsResource> toAdd = Lists.newArrayList(); for (CmsResource resource : publishResources) { if (!resource.getState().isUnchanged()) { try { List<CmsResource> changedSiblings = getCmsObject().readSiblings( resource, CmsResourceFilter.ALL_MODIFIED); toAdd.addAll(changedSiblings); } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); } } } publishResources.addAll(toAdd); }
/** * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[]) */ @Override public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, CmsResourceUtil[] resourceUtil) { if (resourceUtil[0].getResource().getState().isUnchanged()) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey( Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_UNCHANGED_0); } return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; }
/** * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[]) */ @Override public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, CmsResourceUtil[] resourceUtil) { if (resourceUtil[0].getResource().getState().isUnchanged()) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_UNCHANGED_0); } return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; }
/** * @see org.opencms.ade.publish.I_CmsVirtualProject#getResources(org.opencms.file.CmsObject, java.util.Map, java.lang.String) */ public List<CmsResource> getResources(CmsObject cms, Map<String, String> params, String workflowId) { String containerpageId = params.get(CmsPublishOptions.PARAM_CONTAINERPAGE); String elementId = params.get(CmsPublishOptions.PARAM_CONTENT); String detailId = params.get(CmsPublishOptions.PARAM_DETAIL); Set<CmsResource> resources = new HashSet<CmsResource>(); for (String id : new String[] {containerpageId, elementId, detailId}) { if (CmsUUID.isValidUUID(id)) { try { CmsResource resource = cms.readResource(new CmsUUID(id), CmsResourceFilter.ALL); resources.add(resource); CmsResource parent = cms.readParentFolder(resource.getStructureId()); if (!parent.getState().isUnchanged()) { resources.add(parent); } } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); } } } return Lists.newArrayList(resources); }
/** * @see org.opencms.ade.publish.I_CmsVirtualProject#getResources(org.opencms.file.CmsObject, java.util.Map, java.lang.String) */ public List<CmsResource> getResources(CmsObject cms, Map<String, String> params, String workflowId) throws CmsException { Set<String> paths = getPaths(params); boolean includeContents = shouldIncludeContents(params); Set<CmsResource> result = Sets.newHashSet(); for (String path : paths) { try { result.add(cms.readResource(path, CmsResourceFilter.ALL)); } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); } } if (includeContents) { addSubResources(cms, result); } List<CmsResource> resultList = new ArrayList<CmsResource>(); for (CmsResource res : result) { if (!res.getState().isUnchanged()) { resultList.add(res); } } return resultList; }
/** * Changes the "expire" date of a resource.<p> * * @param dbc the current database context * @param resource the resource to touch * @param dateExpired the new expire date of the resource * * @throws CmsDataAccessException if something goes wrong * * @see CmsObject#setDateExpired(String, long, boolean) * @see I_CmsResourceType#setDateExpired(CmsObject, CmsSecurityManager, CmsResource, long, boolean) */ public void setDateExpired(CmsDbContext dbc, CmsResource resource, long dateExpired) throws CmsDataAccessException { resource.setDateExpired(dateExpired); if (resource.getState().isUnchanged()) { resource.setState(CmsResource.STATE_CHANGED); } m_vfsDriver.writeResourceState(dbc, dbc.currentProject(), resource, UPDATE_STRUCTURE, false); // modify the last modified project reference m_vfsDriver.writeResourceState(dbc, dbc.currentProject(), resource, UPDATE_RESOURCE_PROJECT, false); // clear the cache m_monitor.clearResourceCache(); // fire the event HashMap data = new HashMap(2); data.put(I_CmsEventListener.KEY_RESOURCE, resource); data.put(I_CmsEventListener.KEY_CHANGE, new Integer(CHANGED_TIMEFRAME)); OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, data)); }
if (resource.getState().isUnchanged()
/** * Returns the id of the project in which the given resource is locked.<p> * * @return the id of the project in which the given resource is locked */ public CmsUUID getLockedInProjectId() { CmsUUID lockedInProject = null; if (getLock().isNullLock() && !getResource().getState().isUnchanged()) { // resource is unlocked and modified lockedInProject = getResource().getProjectLastModified(); } else if (!getResource().getState().isUnchanged()) { // resource is locked and modified lockedInProject = getProjectId(); } else if (!getLock().isNullLock()) { // resource is locked and unchanged lockedInProject = getLock().getProjectId(); } return lockedInProject; }
/** * Returns the id of the project in which the given resource is locked.<p> * * @return the id of the project in which the given resource is locked */ public CmsUUID getLockedInProjectId() { CmsUUID lockedInProject = null; if (getLock().isNullLock() && !getResource().getState().isUnchanged()) { // resource is unlocked and modified lockedInProject = getResource().getProjectLastModified(); } else if (!getResource().getState().isUnchanged()) { // resource is locked and modified lockedInProject = getProjectId(); } else if (!getLock().isNullLock()) { // resource is locked and unchanged lockedInProject = getLock().getProjectId(); } return lockedInProject; }
/** * Writes a resource to the OpenCms VFS.<p> * * @param dbc the current database context * @param resource the resource to write * * @throws CmsException if something goes wrong */ public void writeResource(CmsDbContext dbc, CmsResource resource) throws CmsException { // access was granted - write the resource resource.setUserLastModified(dbc.currentUser().getId()); m_vfsDriver.writeResource(dbc, dbc.currentProject().getUuid(), resource, UPDATE_RESOURCE_STATE); // make sure the written resource has the state correctly set if (resource.getState().isUnchanged()) { resource.setState(CmsResource.STATE_CHANGED); } // delete in content relations if the new type is not parseable if (!(OpenCms.getResourceManager().getResourceType(resource.getTypeId()) instanceof I_CmsLinkParseable)) { deleteRelationsWithSiblings(dbc, resource); } // update the cache m_monitor.clearResourceCache(); 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)); }
/** * Tries to to touch a resource by setting its last modification date, but only if its state is 'unchanged'.<p> * * @param cms the current CMS context * @param resource the resource which should be 'touched'. */ private void touch(CmsObject cms, CmsResource resource) { if (resource.getState().isUnchanged()) { try { CmsLock lock = cms.getLock(resource); if (lock.isUnlocked() || !lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) { cms.lockResourceTemporary(resource); long now = System.currentTimeMillis(); resource.setDateLastModified(now); cms.writeResource(resource); if (lock.isUnlocked()) { cms.unlockResource(resource); } } } catch (CmsException e) { LOG.warn("Could not touch resource after alias modification: " + resource.getRootPath(), e); } } }
/** * Adds a given published resource to the provided search index update data.<p> * * This method decides if the resource has to be included in the "update" or "delete" list.<p> * * @param pubRes the published resource to add * @param updateData the search index update data to add the resource to */ protected void addResourceToUpdateData(CmsPublishedResource pubRes, CmsSearchIndexUpdateData updateData) { if (pubRes.getState().isDeleted()) { // deleted resource just needs to be removed updateData.addResourceToDelete(pubRes); } else if (pubRes.getState().isNew() || pubRes.getState().isChanged() || pubRes.getState().isUnchanged()) { updateData.addResourceToUpdate(pubRes); } }
/** * Writes a resource to the OpenCms VFS.<p> * * @param dbc the current database context * @param resource the resource to write * * @throws CmsException if something goes wrong */ public void writeResource(CmsDbContext dbc, CmsResource resource) throws CmsException { // access was granted - write the resource resource.setUserLastModified(dbc.currentUser().getId()); CmsUUID projectId = ((dbc.getProjectId() == null) || dbc.getProjectId().isNullUUID()) ? dbc.currentProject().getUuid() : dbc.getProjectId(); getVfsDriver(dbc).writeResource(dbc, projectId, resource, UPDATE_RESOURCE_STATE); // make sure the written resource has the state correctly set if (resource.getState().isUnchanged()) { resource.setState(CmsResource.STATE_CHANGED); } // delete in content relations if the new type is not parseable if (!(OpenCms.getResourceManager().getResourceType(resource.getTypeId()) instanceof I_CmsLinkParseable)) { deleteRelationsWithSiblings(dbc, resource); } // update the cache m_monitor.clearResourceCache(); Map<String, Object> data = new HashMap<String, Object>(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)); }
/** * Returns the project state of the given resource.<p> * * <ul> * <li>null: unchanged.</li> * <li>true: locked in current project.</li> * <li>false: not locked in current project.</li> * </ul> * * @return the project state of the given resource */ public CmsResourceProjectState getProjectState() { if (getResource().getState().isUnchanged()) { return STATE_CLEAN; // STATE_CLEAN } else if (getLock().getSystemLock().isPublish()) { return STATE_LOCKED_FOR_PUBLISHING; } else if (getResource().getProjectLastModified().equals(getReferenceProject().getUuid())) { return STATE_MODIFIED_IN_CURRENT_PROJECT; // STATE_MODIFIED_CURRENT_PROJECT } else { return STATE_MODIFIED_IN_OTHER_PROJECT; // STATE_MODIFIED_OTHER_PROJECT } }
/** * Returns the project state of the given resource.<p> * * <ul> * <li>null: unchanged.</li> * <li>true: locked in current project.</li> * <li>false: not locked in current project.</li> * </ul> * * @return the project state of the given resource */ public CmsResourceProjectState getProjectState() { if (getResource().getState().isUnchanged()) { return STATE_CLEAN; // STATE_CLEAN } else if (getLock().getSystemLock().isPublish()) { return STATE_LOCKED_FOR_PUBLISHING; } else if (getResource().getProjectLastModified().equals(getReferenceProject().getUuid())) { return STATE_MODIFIED_IN_CURRENT_PROJECT; // STATE_MODIFIED_CURRENT_PROJECT } else { return STATE_MODIFIED_IN_OTHER_PROJECT; // STATE_MODIFIED_OTHER_PROJECT } }
/** * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[]) */ @Override public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, CmsResourceUtil[] resourceUtil) { if (resourceUtil[0].getResource().getState().isDeleted()) { return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } else if (resourceUtil[0].getResource().getState().isNew() || (resourceUtil[0].getResource().isFile() && resourceUtil[0].getResource().getState().isUnchanged())) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_NEW_UNCHANGED_0); } try { if (!resourceUtil[0].isEditable() || !cms.hasPermissions( resourceUtil[0].getResource(), CmsPermissionSet.ACCESS_WRITE, false, CmsResourceFilter.ALL)) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0); } } catch (CmsException e) { // error checking permissions, disable entry completely return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; }
/** * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[]) */ @Override public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, CmsResourceUtil[] resourceUtil) { if (resourceUtil[0].getResource().getState().isDeleted()) { return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } else if (resourceUtil[0].getResource().getState().isNew() || (resourceUtil[0].getResource().isFile() && resourceUtil[0].getResource().getState().isUnchanged())) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey( Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_NEW_UNCHANGED_0); } try { if (!resourceUtil[0].isEditable() || !cms.hasPermissions( resourceUtil[0].getResource(), CmsPermissionSet.ACCESS_WRITE, false, CmsResourceFilter.ALL)) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey( Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0); } } catch (CmsException e) { // error checking permissions, disable entry completely return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; }