/** * Returns a new CmsResourceFilter requiring the given type.<p> * * @param type the required resource type * @return a filter requiring the given type */ public static CmsResourceFilter requireType(I_CmsResourceType type) { return new CmsResourceFilter().addRequireType(type); }
/** * Returns an extended filter to guarantee a distinct resource type of the filtered resources.<p> * * If <code>-1</code> is given as type, the filter will not be extended to require a resource type * * @param type the required resource type * @return a filter requiring the given resource type */ public CmsResourceFilter addRequireType(I_CmsResourceType type) { // TODO: Refactor driver layer to use resource type id classes (or names) instead of int return addRequireType(type.getTypeId()); }
/** * Returns a new CmsResourceFilter requiring the given type.<p> * * @param type the required resource type * @return a filter requiring the given type */ public static CmsResourceFilter requireType(int type) { return new CmsResourceFilter().addRequireType(type); }
/** * Returns a new CmsResourceFilter requiring the given type.<p> * * @param type the required resource type * @return a filter requiring the given type * * @deprecated * Use {@link #requireType(I_CmsResourceType)} instead. * Resource types should always be referenced either by its type class (preferred) or by type name. * Use of int based resource type references will be discontinued in a future OpenCms release. */ @Deprecated public static CmsResourceFilter requireType(int type) { return new CmsResourceFilter().addRequireType(type); }
/** * 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; } }
/** * Loads the available element views.<p> * * @return the element views */ protected Map<CmsUUID, CmsElementView> loadElementViews() { List<CmsElementView> views = new ArrayList<CmsElementView>(); views.add(CmsElementView.DEFAULT_ELEMENT_VIEW); try { CmsResourceFilter filter = CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType( m_elementViewType.getTypeId()); List<CmsResource> groups = m_cms.readResources("/", filter); for (CmsResource res : groups) { try { views.add(new CmsElementView(m_cms, res)); } catch (Exception e) { LOG.error(e.getMessage(), e); } } } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); } Collections.sort(views, new CmsElementView.ElementViewComparator()); Map<CmsUUID, CmsElementView> elementViews = new LinkedHashMap<CmsUUID, CmsElementView>(); for (CmsElementView view : views) { elementViews.put(view.getId(), view); } return elementViews; }
/** * 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); }
/** * 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); } }
/** * Reloads the formatter cache.<p> */ public synchronized void reload() { m_idsToUpdate.clear(); List<CmsResource> formatterResources = new ArrayList<CmsResource>(); try { I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(TYPE_FORMATTER_CONFIG); CmsResourceFilter filter = CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(type); formatterResources.addAll(m_cms.readResources("/", filter)); } catch (CmsException e) { LOG.warn(e.getLocalizedMessage(), e); } try { I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(TYPE_MACRO_FORMATTER); CmsResourceFilter filter = CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(type); formatterResources.addAll(m_cms.readResources("/", filter)); } catch (CmsException e) { LOG.warn(e.getLocalizedMessage(), e); } Map<CmsUUID, I_CmsFormatterBean> newFormatters = Maps.newHashMap(); for (CmsResource formatterResource : formatterResources) { I_CmsFormatterBean formatterBean = readFormatter(formatterResource.getStructureId()); if (formatterBean != null) { newFormatters.put(formatterResource.getStructureId(), formatterBean); } } m_state = new CmsFormatterConfigurationCacheState(newFormatters); }
/** * 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); }
/** * 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); }
/** * 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> getImages() { // get all image resources of the folder int imageId; try { imageId = OpenCms.getResourceManager().getResourceType( CmsResourceTypeImage.getStaticTypeName()).getTypeId(); } catch (CmsLoaderException e1) { // should really never happen LOG.warn(e1.getLocalizedMessage(), e1); imageId = CmsResourceTypeImage.getStaticTypeId(); } CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(imageId); try { return getCms().readResources(getParamResource(), filter, false); } catch (CmsException e) { // log, should never happen if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(getLocale())); } return Collections.emptyList(); } }
/** * Returns all resources in the folder pointed to by the parameter.<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 * @throws CmsIllegalArgumentException if the given param argument is not a link to a single file * */ protected List getAllInFolder(CmsObject cms, String param, boolean tree) throws CmsException, CmsIllegalArgumentException { 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_ROOT_PATH); Collections.reverse(result); return shrinkToFit(result, data.getCount()); }
/** * 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()); }
/** * Reads the local macro formatters from the .formatters folder if present.<p> * * @param node the xml content node * * @return the local formatters */ private Set<String> readLocalMacroFormatters(I_CmsXmlContentLocation node) { Set<String> addFormatters = new HashSet<String>(); String path = m_cms.getSitePath(node.getDocument().getFile()); path = CmsStringUtil.joinPaths(CmsResource.getParentFolder(path), ".formatters"); try { if (m_cms.existsResource(path, CmsResourceFilter.IGNORE_EXPIRATION)) { I_CmsResourceType macroType = OpenCms.getResourceManager().getResourceType( CmsFormatterConfigurationCache.TYPE_MACRO_FORMATTER); CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(macroType); List<CmsResource> macroFormatters = m_cms.readResources(path, filter); for (CmsResource formatter : macroFormatters) { addFormatters.add(formatter.getStructureId().toString()); } } } catch (CmsException e) { LOG.warn(e.getMessage(), e); } return addFormatters; }
/** * 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()); }
/** * Returns all resources in the folder pointed to by the parameter.<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 numResults the number of results * * @return all resources in the folder matching the given criteria * * @throws CmsException if something goes wrong * @throws CmsIllegalArgumentException if the given param argument is not a link to a single file * */ protected List<CmsResource> getAllInFolder(CmsObject cms, String param, boolean tree, int numResults) throws CmsException, CmsIllegalArgumentException { CmsCollectorData data = new CmsCollectorData(param); String foldername = CmsResource.getFolderPath(data.getFileName()); CmsResourceFilter filter = CmsResourceFilter.DEFAULT_FILES.addRequireType(data.getType()).addExcludeFlags( CmsResource.FLAG_TEMPFILE); if (data.isExcludeTimerange() && !cms.getRequestContext().getCurrentProject().isOnlineProject()) { // include all not yet released and expired resources in an offline project filter = filter.addExcludeTimerange(); } List<CmsResource> result = cms.readResources(foldername, filter, tree); Collections.sort(result, I_CmsResource.COMPARE_ROOT_PATH); Collections.reverse(result); return shrinkToFit(result, data.getCount(), numResults); }
/** * 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 * @param numResults the number of results * * @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<CmsResource> allInFolderDateReleasedDesc(CmsObject cms, String param, boolean tree, int numResults) throws CmsException { CmsCollectorData data = new CmsCollectorData(param); String foldername = CmsResource.getFolderPath(data.getFileName()); CmsResourceFilter filter = CmsResourceFilter.DEFAULT_FILES.addRequireType(data.getType()).addExcludeFlags( CmsResource.FLAG_TEMPFILE); if (data.isExcludeTimerange() && !cms.getRequestContext().getCurrentProject().isOnlineProject()) { // include all not yet released and expired resources in an offline project filter = filter.addExcludeTimerange(); } List<CmsResource> result = cms.readResources(foldername, filter, tree); Collections.sort(result, I_CmsResource.COMPARE_DATE_RELEASED); return shrinkToFit(result, data.getCount(), numResults); }