protected CmsResource initResource(
        CmsObject cms,
        String resourceName,
        HttpServletRequest req,
        HttpServletResponse res)
    throws CmsException {

        CmsException tmpException = null;
        CmsResource resource;
        boolean handledSecure = false;

        try {
            // try to read the requested resource
            resource = cms.readDefaultFile(resourceName);
        } catch (CmsException e) {
            // file or folder with given name does not exist, store exception
            tmpException = e;
            resource = null;
        }

        if (resource != null) {
            // set the request uri to the right file
            cms.getRequestContext().setUri(cms.getSitePath(resource));
            // test if this file is only available for internal access operations
            if (resource.isInternal()) {
                throw new CmsException(
                    Messages.get().container(Messages.ERR_READ_INTERNAL_RESOURCE_1, cms.getRequestContext().getUri()));
            }

            resource = handleSecureResource(cms, req, res, resource, resourceName);
            if (resource == null) {
                handledSecure = true;

            }
        }

        boolean clearErrors = false;
        // test if this file has to be checked or modified
        for (I_CmsResourceInit handler : m_resourceInitHandlers) {
            try {
                resource = handler.initResource(resource, cms, req, res);
                // the loop has to be interrupted when the exception is thrown!
            } catch (CmsResourceInitException e) {
                if (e.isClearErrors()) {
                    tmpException = null;
                    clearErrors = true;
                }
                break;
            } catch (CmsSecurityException e) {
                tmpException = e;
                break;
            }
        }

        // file is still null and not found exception was thrown, so throw original exception
        if (resource == null) {
            if (tmpException != null) {
                throw tmpException;
            } else if (!clearErrors) {
                throw new CmsVfsResourceNotFoundException(
                    org.opencms.main.Messages.get().container(
                        org.opencms.main.Messages.ERR_PATH_NOT_FOUND_1,
                        resourceName));

            }
        } else {
            if (!handledSecure) {
                if (cms.getRequestContext().getDetailContentId() != null) {
                    // in theory we should do this for all kinds of resource init handlers,
                    // but I'm not clear on how to handle this in general, so only do this for detail pages for now
                    resource = handleSecureResource(cms, req, res, resource, resourceName);
                    handledSecure = true;
                }
            }
        }

        // return the resource read from the VFS
        return resource;
    }
protected CmsResource initResource ( CmsObject cms , String resourceName , HttpServletRequest req , HttpServletResponse res ) throws CmsException { CmsException tmpException = null ; CmsResource resource ; boolean handledSecure = false ; try { resource = cms . readDefaultFile ( resourceName ) ; } catch ( CmsException e ) { tmpException = e ; resource = null ; } if ( resource != null ) { cms . getRequestContext ( ) . setUri ( cms . getSitePath ( resource ) ) ; if ( resource . isInternal ( ) ) { throw new CmsException ( Messages . get ( ) . container ( Messages . ERR_READ_INTERNAL_RESOURCE_1 , cms . getRequestContext ( ) . getUri ( ) ) ) ; } resource = handleSecureResource ( cms , req , res , resource , resourceName ) ; if ( resource == null ) { handledSecure = true ; } } boolean clearErrors = false ; for ( I_CmsResourceInit handler : m_resourceInitHandlers ) { try { resource = handler . initResource ( resource , cms , req , res ) ; } catch ( CmsResourceInitException e ) { if ( e . isClearErrors ( ) ) { tmpException = null ; clearErrors = true ; } break ; } catch ( CmsSecurityException e ) { tmpException = e ; break ; } } if ( resource == null ) { if ( tmpException != null ) { throw tmpException ; } else if ( ! clearErrors ) { throw new CmsVfsResourceNotFoundException ( org . opencms . main . Messages . get ( ) . container ( org . opencms . main . Messages . ERR_PATH_NOT_FOUND_1 , resourceName ) ) ; } } else { if ( ! handledSecure ) { if ( cms . getRequestContext ( ) . getDetailContentId ( ) != null ) { resource = handleSecureResource ( cms , req , res , resource , resourceName ) ; handledSecure = true ; } } } return resource ; }
Reads the requested resource from the OpenCms VFS,
in case a directory name is requested, the default files of the
directory will be looked up and the first match is returned.<p>

The resource that is returned is always a <code>{@link org.opencms.file.CmsFile}</code>,
even though the content will usually not be loaded in the result. Folders are never returned since
the point of this method is really to load the default file if just a folder name is requested. If
there is no default file in a folder, then the return value is null and no CmsException is thrown.<p>

The URI stored in the given OpenCms user context will be changed to the URI of the resource
that was found and returned.<p>

Implementing and configuring an <code>{@link I_CmsResourceInit}</code> handler
allows to customize the process of default resource selection.<p>

@param cms the current users OpenCms context
@param resourceName the path of the requested resource in the OpenCms VFS
@param req the current http request
@param res the current http response

@return the requested resource read from the VFS

@throws CmsException in case the requested file does not exist or the user has insufficient access permissions

@see OpenCms#initResource(CmsObject, String, HttpServletRequest, HttpServletResponse)