/** * Constructor with an initialized {@link CmsObjectWrapper} and a * {@link CmsRepositoryFilter} to use.<p> * * @param cms the initialized CmsObject * @param filter the repository filter to use */ public CmsRepositorySession(CmsObjectWrapper cms, CmsRepositoryFilter filter) { m_cms = cms; setFilter(filter); }
/** * @see org.opencms.repository.I_CmsRepositorySession#exists(java.lang.String) */ public boolean exists(String path) { try { path = validatePath(path); return m_cms.existsResource(path); } catch (CmsException ex) { return false; } }
src = validatePath(src); dest = validatePath(dest); if (exists(dest)) { delete(dest); } else {
/** * @see org.opencms.repository.I_CmsRepositorySession#delete(java.lang.String) */ public void delete(String path) throws CmsException { path = validatePath(path); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_ITEM_1, path)); } CmsRepositoryLockInfo lock = getLock(path); // lock resource m_cms.lockResource(path); // delete resource m_cms.deleteResource(path, CmsResource.DELETE_PRESERVE_SIBLINGS); // if deleting items out of a xml page restore lock state after deleting try { if (lock == null) { m_cms.unlockResource(path); } } catch (CmsException ex) { // noop } }
/** * @see org.opencms.repository.I_CmsRepositorySession#list(java.lang.String) */ public List list(String path) throws CmsException { List ret = new ArrayList(); path = validatePath(path); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_LIST_ITEMS_1, path)); } List resources = m_cms.getResourcesInFolder(path, CmsResourceFilter.DEFAULT); Iterator iter = resources.iterator(); while (iter.hasNext()) { CmsResource res = (CmsResource)iter.next(); if (!isFiltered(m_cms.getRequestContext().removeSiteRoot(res.getRootPath()))) { // open the original resource (for virtual files this is the resource in the VFS // which the virtual resource is based on) // this filters e.g. property files for resources that are filtered out and thus // should not be displayed CmsResource org = m_cms.readResource(res.getStructureId(), CmsResourceFilter.DEFAULT); if (!isFiltered(m_cms.getRequestContext().removeSiteRoot(org.getRootPath()))) { ret.add(new CmsRepositoryItem(res, m_cms)); } } } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_LIST_ITEMS_SUCESS_1, new Integer(ret.size()))); } return ret; }
/** * @see org.opencms.repository.I_CmsRepository#login(java.lang.String, java.lang.String) */ public I_CmsRepositorySession login(String userName, String password) throws CmsException { CmsObject cms; cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); cms.loginUser(userName, password); CmsUserSettings settings = new CmsUserSettings(cms); cms.getRequestContext().setSiteRoot(settings.getStartSite()); cms.getRequestContext().setCurrentProject(cms.readProject(settings.getStartProject())); // set the object wrapper as an attribute in the request context, so that it can be // used everywhere a CmsObject is accessible. CmsObjectWrapper objWrapper = new CmsObjectWrapper(cms, m_wrappers); cms.getRequestContext().setAttribute(CmsObjectWrapper.ATTRIBUTE_NAME, objWrapper); return new CmsRepositorySession(objWrapper, getFilter()); }
/** * Validates (translates) the given path and checks if it is filtered out.<p> * * @param path the path to validate * * @return the validated path * * @throws CmsSecurityException if the path is filtered out */ private String validatePath(String path) throws CmsSecurityException { // Problems with spaces in new folders (default: "Neuer Ordner") // Solution: translate this to a correct name. String ret = m_cms.getRequestContext().getFileTranslator().translateResource(path); // add site root only works correct if system folder ends with a slash if (CmsResource.VFS_FOLDER_SYSTEM.equals(ret)) { ret = ret.concat("/"); } // filter path if (isFiltered(ret)) { throw new CmsSecurityException(Messages.get().container(Messages.ERR_ITEM_FILTERED_1, path)); } return ret; } }
src = validatePath(src); dest = validatePath(dest); if (exists(dest)) { delete(dest); } else {
/** * @see org.opencms.repository.I_CmsRepositorySession#delete(java.lang.String) */ public void delete(String path) throws CmsException { path = validatePath(path); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_ITEM_1, path)); } CmsRepositoryLockInfo lock = getLock(path); // lock resource m_cms.lockResource(path); // delete resource m_cms.deleteResource(path, CmsResource.DELETE_PRESERVE_SIBLINGS); // if deleting items out of a xml page restore lock state after deleting try { if (lock == null) { m_cms.unlockResource(path); } } catch (CmsException ex) { // noop } }
/** * @see org.opencms.repository.I_CmsRepositorySession#list(java.lang.String) */ public List<I_CmsRepositoryItem> list(String path) throws CmsException { List<I_CmsRepositoryItem> ret = new ArrayList<I_CmsRepositoryItem>(); path = validatePath(path); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_LIST_ITEMS_1, path)); } List<CmsResource> resources = m_cms.getResourcesInFolder(path, CmsResourceFilter.DEFAULT); Iterator<CmsResource> iter = resources.iterator(); while (iter.hasNext()) { CmsResource res = iter.next(); if (!isFiltered(m_cms.getRequestContext().removeSiteRoot(res.getRootPath()))) { // open the original resource (for virtual files this is the resource in the VFS // which the virtual resource is based on) // this filters e.g. property files for resources that are filtered out and thus // should not be displayed CmsResource org = m_cms.readResource(res.getStructureId(), CmsResourceFilter.DEFAULT); if (!isFiltered(m_cms.getRequestContext().removeSiteRoot(org.getRootPath()))) { ret.add(new CmsRepositoryItem(res, m_cms)); } } } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_LIST_ITEMS_SUCESS_1, new Integer(ret.size()))); } return ret; }
/** * @see org.opencms.repository.A_CmsRepository#login(java.lang.String, java.lang.String) */ @Override public I_CmsRepositorySession login(String userName, String password) throws CmsException { CmsObject cms; cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); cms.loginUser(userName, password); CmsUserSettings settings = new CmsUserSettings(cms); cms.getRequestContext().setSiteRoot(settings.getStartSite()); cms.getRequestContext().setCurrentProject(cms.readProject(settings.getStartProject())); // set the object wrapper as an attribute in the request context, so that it can be // used everywhere a CmsObject is accessible. CmsObjectWrapper objWrapper = new CmsObjectWrapper(cms, m_wrappers); cms.getRequestContext().setAttribute(CmsObjectWrapper.ATTRIBUTE_NAME, objWrapper); return new CmsRepositorySession(objWrapper, getFilter()); }
/** * Validates (translates) the given path and checks if it is filtered out.<p> * * @param path the path to validate * * @return the validated path * * @throws CmsSecurityException if the path is filtered out */ private String validatePath(String path) throws CmsSecurityException { // Problems with spaces in new folders (default: "Neuer Ordner") // Solution: translate this to a correct name. String ret = m_cms.getRequestContext().getFileTranslator().translateResource(path); // add site root only works correct if system folder ends with a slash if (CmsResource.VFS_FOLDER_SYSTEM.equals(ret)) { ret = ret.concat("/"); } // filter path if (isFiltered(ret)) { throw new CmsSecurityException(Messages.get().container(Messages.ERR_ITEM_FILTERED_1, path)); } return ret; } }
src = validatePath(src); dest = validatePath(dest); if (exists(dest)) { delete(dest); } else {
/** * @see org.opencms.repository.I_CmsRepositorySession#exists(java.lang.String) */ public boolean exists(String path) { try { path = validatePath(path); return m_cms.existsResource(path); } catch (CmsException ex) { return false; } }
/** * Constructor with an initialized {@link CmsObjectWrapper} and a * {@link CmsRepositoryFilter} to use.<p> * * @param cms the initialized CmsObject * @param filter the repository filter to use */ public CmsRepositorySession(CmsObjectWrapper cms, CmsRepositoryFilter filter) { m_cms = cms; setFilter(filter); }
src = validatePath(src); dest = validatePath(dest); if (exists(dest)) { delete(dest); } else {
/** * @see org.opencms.repository.I_CmsRepositorySession#lock(java.lang.String, org.opencms.repository.CmsRepositoryLockInfo) */ public boolean lock(String path, CmsRepositoryLockInfo lock) throws CmsException { path = validatePath(path); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_LOCK_ITEM_1, path)); } m_cms.lockResource(path); return true; }
/** * @see org.opencms.repository.I_CmsRepositorySession#lock(java.lang.String, org.opencms.repository.CmsRepositoryLockInfo) */ public boolean lock(String path, CmsRepositoryLockInfo lock) throws CmsException { path = validatePath(path); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_LOCK_ITEM_1, path)); } m_cms.lockResource(path); return true; }
/** * @see org.opencms.repository.I_CmsRepositorySession#getItem(java.lang.String) */ public I_CmsRepositoryItem getItem(String path) throws CmsException { path = validatePath(path); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_READ_ITEM_1, path)); } CmsResource res = m_cms.readResource(path, CmsResourceFilter.DEFAULT); CmsRepositoryItem item = new CmsRepositoryItem(res, m_cms); return item; }
/** * @see org.opencms.repository.I_CmsRepositorySession#getItem(java.lang.String) */ public I_CmsRepositoryItem getItem(String path) throws CmsException { path = validatePath(path); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_READ_ITEM_1, path)); } CmsResource res = m_cms.readResource(path, CmsResourceFilter.DEFAULT); CmsRepositoryItem item = new CmsRepositoryItem(res, m_cms); return item; }