Trys to read the resourcename after removing the file extension and return the
resource if the type id is correct.<p>

@param cms the initialized CmsObject
@param resourcename the name of the resource to read

@return the resource or null if not found
339810
private CmsResource getResource(CmsObject cms, String resourcename) {

        return getResource(cms, resourcename, CmsResourceFilter.DEFAULT);
    }
473240
public static CmsResource readResource(CmsObject cms, CmsHistoryResourceBean bean) throws CmsException {

        CmsHistoryVersion versionBean = bean.getVersion();
        if (versionBean.getVersionNumber() != null) {
            return (CmsResource)(cms.readResource(bean.getStructureId(), versionBean.getVersionNumber().intValue()));
        } else {
            if (versionBean.isOnline()) {
                CmsObject onlineCms = OpenCms.initCmsObject(cms);
                onlineCms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
                return onlineCms.readResource(bean.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
            } else {
                return cms.readResource(bean.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
            }
        }
    }
42897
private CmsJspResourceWrapper readResource(String sitePath) {

        CmsJspResourceWrapper result = null;
        try {
            result = new CmsJspResourceWrapper(m_cms, m_cms.readResource(sitePath));
        } catch (CmsException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(e.getMessage(), e);
            }
        }
        return result;
    }
1356827
public static CmsXmlContentDefinition getContentDefinitionForResource(CmsObject cms, CmsResource resource)
    throws CmsException {

        CmsXmlContentDefinition contentDef = null;
        I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(resource.getTypeId());
        String schema = resType.getConfiguration().get(CmsResourceTypeXmlContent.CONFIGURATION_SCHEMA);
        if (schema != null) {
            try {
                // this wont in most cases read the file content because of caching
                contentDef = unmarshal(cms, schema);
            } catch (CmsException e) {
                // this should never happen, unless the configured schema is different than the schema in the XML
                if (!LOG.isDebugEnabled()) {
                    LOG.warn(e);
                }
                LOG.debug(e.getLocalizedMessage(), e);
            }
        }
        if (contentDef == null) {
            // could still be empty since it is not mandatory to configure the resource type in the XML configuration
            // try through the XSD relation
            List<CmsRelation> relations = cms.getRelationsForResource(
                resource,
                CmsRelationFilter.TARGETS.filterType(CmsRelationType.XSD));
            if ((relations != null) && !relations.isEmpty()) {
                CmsXmlEntityResolver entityResolver = new CmsXmlEntityResolver(cms);
                String xsd = cms.getSitePath(relations.get(0).getTarget(cms, CmsResourceFilter.ALL));
                contentDef = entityResolver.getCachedContentDefinition(xsd);
            }
        }
        if (contentDef == null) {
            // could still be empty if the XML content has been saved with an OpenCms before 8.0.0
            // so, to unmarshal is the only possibility left
            CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, cms.readFile(resource));
            contentDef = content.getContentDefinition();
        }

        return contentDef;
    }
152662
private static I_CmsResourceBundle tryBundle(String localizedName) {

        I_CmsResourceBundle result = null;

        try {

            String resourceName = localizedName.replace('.', '/') + ".properties";
            URL url = CmsResourceBundleLoader.class.getClassLoader().getResource(resourceName);

            I_CmsResourceBundle additionalBundle = m_permanentCache.get(localizedName);
            if (additionalBundle != null) {
                result = additionalBundle.getClone();
            } else if (url != null) {
                // the resource was found on the file system
                InputStream is = null;
                String path = CmsFileUtil.normalizePath(url);
                File file = new File(path);
                try {
                    // try to load the resource bundle from a file, NOT with the resource loader first
                    // this is important since using #getResourceAsStream() may return cached results,
                    // for example Tomcat by default does cache all resources loaded by the class loader
                    // this means a changed resource bundle file is not loaded
                    is = new FileInputStream(file);
                } catch (IOException ex) {
                    // this will happen if the resource is contained for example in a .jar file
                    is = CmsResourceBundleLoader.class.getClassLoader().getResourceAsStream(resourceName);
                } catch (AccessControlException acex) {
                    // fixed bug #1550
                    // this will happen if the resource is contained for example in a .jar file
                    // and security manager is turned on.
                    is = CmsResourceBundleLoader.class.getClassLoader().getResourceAsStream(resourceName);
                }
                if (is != null) {
                    result = new CmsPropertyResourceBundle(is);
                }
            }
        } catch (IOException ex) {
            // can't localized these message since this may lead to a chicken-egg problem
            MissingResourceException mre = new MissingResourceException(
                "Failed to load bundle '" + localizedName + "'",
                localizedName,
                "");
            mre.initCause(ex);
            throw mre;
        }

        return result;
    }
581697
public CmsSitemapTreeNodeData getData(CmsResource resource) {

        try {
            CmsVfsSitemapService svc = new CmsVfsSitemapService();
            CmsObject cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
            cms.getRequestContext().setSiteRoot("");
            svc.setCms(cms);

            CmsClientSitemapEntry ent = svc.getChildren(resource.getRootPath(), resource.getStructureId(), 0);
            CmsSitemapTreeNodeData data = new CmsSitemapTreeNodeData(
                m_localeContext.getRootLocale(),
                m_localeContext.getComparisonLocale());
            data.setClientEntry(ent);
            data.initialize(cms);
            return data;
        } catch (Exception e) {
            LOG.error(e.getLocalizedMessage(), e);
            return null;
        }

    }
713113
@Override
	public Reader getResource(String resourceName) throws ResourceNotFoundException {

		return getResource(null, resourceName, false);
	}
420688
public static String readResource(String resourceName, String charset) {
        InputStream is = Util.class.getResourceAsStream(resourceName);
        try {
            return read(is, charset);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            closeQuietly(is);
        }
    }
976131
public String[] getResourceInfo(CmsResource resource) {

        String rootPath = resource.getRootPath();
        String title = "-";

        try {
            CmsProperty titleProp = m_adminCms.readPropertyObject(
                resource,
                CmsPropertyDefinition.PROPERTY_TITLE,
                false);
            if (!titleProp.isNullProperty()) {
                title = titleProp.getValue();
            }
        } catch (CmsException e) {
            // ignore
        }
        return new String[] {rootPath, title};
    }
434795
public static boolean isResourceTypeNameFree(String name) {

        try {
            OpenCms.getResourceManager().getResourceType(name);
        } catch (CmsLoaderException e) {
            return true;
        }
        return false;
    }
1057445
public static String getResourceName(Resource resource) {
        String result = null;
        if (resource != null) {
            String name = resource.getName();
            if (ResourceUtil.CONTENT_NODE.equals(name)) {
                result = getResourceName(resource.getParent());
            } else {
                result = name;
            }
        }
        return result;
    }
435932
public static String lookup(String resourceName) {
        String resource = null;

        // 1. Check in the JNDI tree
        Context ctx = null;
        try {
            ctx = (Context) new InitialContext().lookup(JNDI_ENVIRONMENT);
            resource = (String) ctx.lookup(resourceName);
        }
        catch (NamingException ignore) {}

        // 2. Check among system properties
        if (null == resource || resource.length() == 0) {
            System.out.println("Resource \"" + resourceName + "\" not published through JNDI...");
            try {
                resource = System.getProperty(resourceName);
            }
            catch (Exception ignore) {}
        }

        if (null == resource || resource.length() == 0) {
            System.out.println("Resource \"" + resourceName + "\" not published through system properties...");
        }
        return resource;
    }
556112
public CmsResource getFolder(CmsObject cms) throws CmsException {

        if (m_folder != null) {
            return m_folder;
        }
        try {
            CmsResource folder = cms.readResource(m_path);
            return folder;
        } catch (CmsVfsResourceNotFoundException e) {
            return null;
        }
    }
340669
public static Resource getBigIconResource(CmsExplorerTypeSettings explorerType, String resourceName) {

        if (explorerType == null) {
            explorerType = OpenCms.getWorkplaceManager().getExplorerTypeSetting(
                (resourceName == null) && !CmsResource.isFolder(resourceName)
                ? CmsResourceTypeUnknownFile.RESOURCE_TYPE_NAME
                : CmsResourceTypeUnknownFolder.RESOURCE_TYPE_NAME);
        }
        if (!explorerType.getIconRules().isEmpty() && (resourceName != null)) {
            String extension = CmsResource.getExtension(resourceName);
            if (extension != null) {
                CmsIconRule rule = explorerType.getIconRules().get(extension);
                if ((rule != null) && (rule.getBigIconStyle() != null)) {
                    return new CmsCssIcon(rule.getBigIconStyle());
                }
            }
        }
        if (explorerType.getBigIconStyle() != null) {
            return new CmsCssIcon(explorerType.getBigIconStyle());
        } else if (explorerType.getBigIcon() != null) {
            return new ExternalResource(
                CmsWorkplace.getResourceUri(CmsWorkplace.RES_PATH_FILETYPES + explorerType.getBigIcon()));
        } else {
            return new CmsCssIcon(CmsExplorerTypeSettings.ICON_STYLE_DEFAULT_BIG);
        }
    }
481608
String getVFSName(CmsObject cms, String oName) {

        oName = CmsStringUtil.substitute(oName, "\\", "/");
        if (!oName.startsWith("/")) {
            oName = "/" + oName;
        }

        if (PATH_TO_VFS_NAME.containsKey(oName)) {
            return PATH_TO_VFS_NAME.get(oName);
        }

        String imgName = oName;
        CmsResource res = null;
        boolean found = false;
        while (!found) {
            String path = CmsResource.getParentFolder(imgName);
            String name = imgName.substring(path.length());
            String ext = CmsFileUtil.getExtension(imgName);
            String nameWoExt = name.substring(0, name.length() - ext.length());
            int pos = nameWoExt.lastIndexOf("_");
            String newName = path;
            found = (pos < 0);
            if (!found) {
                newName += nameWoExt.substring(0, pos);
            } else {
                newName += nameWoExt;
            }
            newName += ext;
            try {
                res = cms.readResource(newName, CmsResourceFilter.ALL);
                found = true;
            } catch (Exception e) {
                // it could be a variation
            }
            imgName = newName;
        }

        if (res != null) {
            PATH_TO_VFS_NAME.put(oName, res.getRootPath());
            return res.getRootPath();
        }
        return "";
    }
407004
public static final String getType(CmsObject cms, String rootPath) {

        String type = null;
        CmsSolrIndex index = CmsSearchManager.getIndexSolr(cms, null);
        if (index != null) {
            I_CmsSearchDocument doc = index.getDocument(CmsSearchField.FIELD_PATH, rootPath);
            if (doc != null) {
                type = doc.getFieldValueAsString(CmsSearchField.FIELD_TYPE);
            }
        }
        return type;
    }
403580
@Override
    public CmsResource getResource(CmsObject cms, CmsListItem item) {

        CmsResource res = null;

        CmsUUID id = new CmsUUID(item.getId());
        if (!id.isNullUUID()) {
            try {
                res = cms.readResource(id, CmsResourceFilter.ALL);
            } catch (CmsException e) {
                // should never happen
                if (LOG.isErrorEnabled()) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            }
        }

        return res;
    }