/** * Reads all resources below the given path matching the filter criteria, * including the full tree below the path.<p> * * @param resourcename the parent path to read the resources from * @param filter the filter * * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria * * @throws CmsException if something goes wrong * * @see #readResources(String, CmsResourceFilter, boolean) */ public List<CmsResource> readResources(String resourcename, CmsResourceFilter filter) throws CmsException { return readResources(resourcename, filter, true); }
/** * Reads all resources below the given path matching the filter criteria, * including the full tree below the path.<p> * * @param resourcename the parent path to read the resources from * @param filter the filter * * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria * * @throws CmsException if something goes wrong * * @see #readResources(String, CmsResourceFilter, boolean) */ public List readResources(String resourcename, CmsResourceFilter filter) throws CmsException { return readResources(resourcename, filter, true); }
/** * Checks if the publish list contains all sub-resources of a given folder.<p> * * @param cms the current CMS context * @param folder the folder for which the check should be performed * @return true if the publish list contains all sub-resources of a given folder * @throws CmsException if something goes wrong */ protected boolean containsSubResources(CmsObject cms, CmsResource folder) throws CmsException { String folderPath = cms.getSitePath(folder); List<CmsResource> subResources = cms.readResources(folderPath, CmsResourceFilter.ALL, true); for (CmsResource resource : subResources) { if (!containsResource(resource)) { return false; } } return true; }
/** * Gets all resources from the folder tree beneath the base folder or the shared folder which have a given type.<p> * * @param type the type to filter by * * @return the list of resources with the given type * * @throws CmsException if something goes wrong */ private List<CmsResource> getDetailResources(I_CmsResourceType type) throws CmsException { String typeName = type.getTypeName(); if (!m_detailResources.containsKey(typeName)) { List<CmsResource> result = new ArrayList<CmsResource>(); CmsResourceFilter filter = CmsResourceFilter.DEFAULT_FILES.addRequireType(type); List<CmsResource> siteFiles = m_guestCms.readResources(m_siteRoot, filter, true); result.addAll(siteFiles); String shared = CmsFileUtil.removeTrailingSeparator(OpenCms.getSiteManager().getSharedFolder()); if (shared != null) { List<CmsResource> sharedFiles = m_guestCms.readResources(shared, filter, true); result.addAll(sharedFiles); } m_detailResources.put(typeName, result); } return m_detailResources.get(typeName); }
/** * Internally reads the resources to use.<p> * * @return the resources to use. */ private List<CmsResource> getResources() { List<CmsResource> result = new LinkedList<CmsResource>(); CmsObject cms = getCms(); CmsResourceFilter filter = CmsResourceFilter.ALL; try { for (String path : m_paths) { List<CmsResource> resources = cms.readResources(path, filter, true); result.addAll(resources); } } catch (CmsException e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_PROPERTYVIEWER_READRESOURCES_0), e); } result = Collections.emptyList(); } return result; }
/** * Returns all sub categories of the given one, including sub sub categories if needed.<p> * * @param cms the current cms context * @param rootPath the base category's root path (this category is not part of the result) * @param includeSubCats flag to indicate if sub categories should also be read * * @return a list of {@link CmsCategory} objects * * @throws CmsException if something goes wrong */ private List internalReadSubCategories(CmsObject cms, String rootPath, boolean includeSubCats) throws CmsException { List categories = new ArrayList(); List resources = cms.readResources( cms.getRequestContext().removeSiteRoot(rootPath), CmsResourceFilter.DEFAULT.addRequireType(CmsResourceTypeFolder.RESOURCE_TYPE_ID), includeSubCats); Iterator it = resources.iterator(); while (it.hasNext()) { CmsResource resource = (CmsResource)it.next(); categories.add(getCategory(cms, resource)); } return categories; } }
/** *@see org.opencms.widgets.A_CmsSelectWidget#parseSelectOptions(CmsObject, I_CmsWidgetDialog, I_CmsWidgetParameter) */ protected List parseSelectOptions(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { List result = new ArrayList(); try { List resources = cms.readResources("/", CmsResourceFilter.DEFAULT.addRequireType(PRESET_TYPE_ID), true); Iterator iter = resources.iterator(); while (iter.hasNext()) { CmsResource res = (CmsResource)iter.next(); String title = cms.readPropertyObject(res, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue(); result.add(new CmsSelectWidgetOption(cms.getSitePath(res), false, title, "")); } } catch (CmsException e) { // noop } return result; } }
/** * Returns the image resources of the gallery folder which are edited in the dialog form. * <p> * * @return the images of the gallery folder which are edited in the dialog form */ protected List<CmsResource> getResources() { List<CmsResource> result = Collections.emptyList(); // get all image resources of the folder CmsResourceFilter filter = CmsResourceFilter.DEFAULT; try { CmsObject cms = getCms(); result = cms.readResources(getParamResource(), filter, false); } catch (CmsException e) { // log, should never happen if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(getLocale())); } } return result; }
/** * Returns the image resources of the gallery folder which are edited in the dialog form. * <p> * * @return the images of the gallery folder which are edited in the dialog form */ @SuppressWarnings("unchecked") protected List<CmsResource> getResources() { List<CmsResource> result = Collections.emptyList(); // get all image resources of the folder CmsResourceFilter filter = CmsResourceFilter.DEFAULT; try { CmsObject cms = getCms(); result = cms.readResources(getParamResource(), filter, false); } catch (CmsException e) { // log, should never happen if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(getLocale())); } } return result; }
/** * Returns the image resources of the gallery folder which are edited in the dialog form.<p> * * @return the images of the gallery folder which are edited in the dialog form */ protected List getImages() { // get all image resources of the folder CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(CmsResourceTypeImage.getStaticTypeId()); try { return getCms().readResources(getParamResource(), filter, false); } catch (CmsException e) { // log, should never happen if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(getLocale())); } return new ArrayList(0); } }
/** * Adds contents of folders to a list of resources.<p> * * @param cms the CMS context to use * @param resources the resource list to which to add the folder contents * @throws CmsException if something goes wrong */ protected void addSubResources(CmsObject cms, Set<CmsResource> resources) throws CmsException { List<CmsResource> subResources = new ArrayList<CmsResource>(); CmsObject rootCms = OpenCms.initCmsObject(cms); rootCms.getRequestContext().setSiteRoot(""); for (CmsResource res : resources) { if (res.isFolder()) { try { List<CmsResource> childrenOfCurrentResource = rootCms.readResources( res.getRootPath(), CmsResourceFilter.ALL, true); subResources.addAll(childrenOfCurrentResource); } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); } } } resources.addAll(subResources); }
/** * Gets the sub-resources of a list of folders which are missing from the publish list.<p> * * @param cms the current CMS context * @param folders the folders which should be checked * @return a list of missing sub resources * * @throws CmsException if something goes wrong */ protected List<CmsResource> getMissingSubResources(CmsObject cms, List<CmsResource> folders) throws CmsException { List<CmsResource> result = new ArrayList<CmsResource>(); CmsObject rootCms = OpenCms.initCmsObject(cms); rootCms.getRequestContext().setSiteRoot(""); for (CmsResource folder : folders) { List<CmsResource> subResources = rootCms.readResources(folder.getRootPath(), CmsResourceFilter.ALL, true); for (CmsResource resource : subResources) { if (!containsResource(resource)) { result.add(resource); } } } return result; }
/** * Returns information about the image count of the selected gallery folder.<p> * * @return information about the image count of the selected gallery folder */ public String buildImageInformation() { // count all image resources of the gallery folder int count = 0; try { CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(CmsResourceTypeImage.getStaticTypeId()); List images = getCms().readResources(getParamResource(), filter, false); count = images.size(); } catch (CmsException e) { // ignore this exception } Object[] args = new Object[] {getParamResource(), new Integer(count)}; return key(Messages.GUI_RENAMEIMAGES_INFO_IMAGECOUNT_2, args); }
/** * Fills the file table with the resources from the given path.<p> * * @param sitePath a folder site path */ public void populateFileTable(String sitePath) { CmsObject cms = A_CmsUI.getCmsObject(); m_searchField.clear(); m_firstVisibleTableItemIndex = 0; try { List<CmsResource> folderResources = cms.readResources(sitePath, FILES_N_FOLDERS, false); m_fileTable.fillTable(cms, folderResources); } catch (CmsException e) { CmsErrorDialog.showErrorDialog(e); LOG.error(e.getLocalizedMessage(), e); } }
/** * Reads the given tree level.<p> * @param cms the CMS context * @param parentId the parent id */ public void readTreeLevel(CmsObject cms, CmsUUID parentId) { try { CmsResource parent = cms.readResource(parentId, m_filter); List<CmsResource> children = cms.readResources(parent, m_filter, false); // sets the parent to leaf mode, in case no child folders are present setChildrenAllowed(parentId, !children.isEmpty()); for (CmsResource resource : children) { addTreeItem(cms, resource, parentId); } } catch (CmsException e) { CmsErrorDialog.showErrorDialog( CmsVaadinUtils.getMessageText(Messages.ERR_EXPLORER_CAN_NOT_READ_RESOURCE_1, parentId), e); LOG.error(e.getLocalizedMessage(), e); } }
/** * Returns information about the image count of the selected gallery folder.<p> * * @return information about the image count of the selected gallery folder */ public String buildImageInformation() { // count all image resources of the gallery folder int count = 0; try { int imageId = OpenCms.getResourceManager().getResourceType( CmsResourceTypeImage.getStaticTypeName()).getTypeId(); CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(imageId); List<CmsResource> images = getCms().readResources(getParamResource(), filter, false); count = images.size(); } catch (CmsException e) { // ignore this exception } Object[] args = new Object[] {getParamResource(), new Integer(count)}; return key(Messages.GUI_RENAMEIMAGES_INFO_IMAGECOUNT_2, args); }
/** * Updates the current folder and removes the given resource items.<p> * * @param removeIds the resource item ids to remove */ protected void updateCurrentFolder(Collection<CmsUUID> removeIds) { for (CmsUUID removeId : removeIds) { m_fileTable.update(removeId, true); } CmsObject cms = A_CmsUI.getCmsObject(); try { CmsResource folder = cms.readResource(m_currentFolder, FOLDERS); List<CmsResource> childResources = cms.readResources(cms.getSitePath(folder), FILES_N_FOLDERS, false); for (CmsResource child : childResources) { m_fileTable.update(child.getStructureId(), false); } } catch (CmsException e) { CmsErrorDialog.showErrorDialog(e); LOG.error(e.getLocalizedMessage(), e); } }
/** * Returns a List of all resources in the folder pointed to by the parameter * sorted by the release date, descending.<p> * * @param cms the current CmsObject * @param param the folder name to use * @param tree if true, look in folder and all child folders, if false, look only in given folder * * @return a List of all resources in the folder pointed to by the parameter * sorted by the release date, descending * * @throws CmsException if something goes wrong */ protected List allInFolderDateReleasedDesc(CmsObject cms, String param, boolean tree) throws CmsException { CmsCollectorData data = new CmsCollectorData(param); String foldername = CmsResource.getFolderPath(data.getFileName()); CmsResourceFilter filter = CmsResourceFilter.DEFAULT.addRequireType(data.getType()).addExcludeFlags( CmsResource.FLAG_TEMPFILE); List result = cms.readResources(foldername, filter, tree); Collections.sort(result, CmsResource.COMPARE_DATE_RELEASED); return shrinkToFit(result, data.getCount()); }
/** * Returns a list of all resource in a specified folder sorted by priority descending, then Title ascending.<p> * * @param cms the current OpenCms user context * @param param the folder name to use * @param tree if true, look in folder and all child folders, if false, look only in given folder * * @return all resources in the folder matching the given criteria * * @throws CmsException if something goes wrong */ protected List allInFolderPriorityTitle(CmsObject cms, String param, boolean tree) throws CmsException { CmsCollectorData data = new CmsCollectorData(param); String foldername = CmsResource.getFolderPath(data.getFileName()); CmsResourceFilter filter = CmsResourceFilter.DEFAULT.addRequireType(data.getType()).addExcludeFlags( CmsResource.FLAG_TEMPFILE); List result = cms.readResources(foldername, filter, tree); // create priority comparator to use to sort the resources CmsPriorityTitleResourceComparator comparator = new CmsPriorityTitleResourceComparator(cms); Collections.sort(result, comparator); return shrinkToFit(result, data.getCount()); }
/** * Returns a list of all resource in a specified folder sorted by priority, then date ascending or descending.<p> * * @param cms the current OpenCms user context * @param param the folder name to use * @param tree if true, look in folder and all child folders, if false, look only in given folder * @param asc if true, the date sort order is ascending, otherwise descending * * @return all resources in the folder matching the given criteria * * @throws CmsException if something goes wrong */ protected List allInFolderPriorityDate(CmsObject cms, String param, boolean tree, boolean asc) throws CmsException { CmsCollectorData data = new CmsCollectorData(param); String foldername = CmsResource.getFolderPath(data.getFileName()); CmsResourceFilter filter = CmsResourceFilter.DEFAULT.addRequireType(data.getType()).addExcludeFlags( CmsResource.FLAG_TEMPFILE); List result = cms.readResources(foldername, filter, tree); // create priority comparator to use to sort the resources CmsPriorityDateResourceComparator comparator = new CmsPriorityDateResourceComparator(cms, asc); Collections.sort(result, comparator); return shrinkToFit(result, data.getCount()); }