Class CmsRelationSystemValidator

  • public class CmsRelationSystemValidator
    extends java.lang.Object
    Validates relations of resources in the OpenCms VFS.

    Relations are, for instance, href attribs in anchor tags and src attribs in image tags, as well as OpenCmsVfsFile values in Xml Content.

    External links to targets outside the OpenCms VFS don't get validated.

    Objects using this class are responsible to handle detected broken links.

    • Method Detail

      • validateResources

        public java.util.Map<java.lang.String,​java.util.List<CmsRelation>> validateResources​(CmsDbContext dbc,
                                                                                                   CmsPublishList publishList,
                                                                                                   I_CmsReport report)
                                                                                            throws java.lang.Exception
        Validates the relations against the online project.

        The result is printed to the given report.

        Validating references means to answer the question, whether we would have broken links in the online project if the given publish list would get published.

        dbc - the database context
        publishList - the publish list to validate
        report - a report to print messages
        a map with lists of invalid links (CmsRelation} objects) keyed by root paths
        java.lang.Exception - if something goes wrong
      • checkLinkForDeletedLinkTarget

        protected boolean checkLinkForDeletedLinkTarget​(CmsRelation relation,
                                                        java.lang.String link,
                                                        java.util.Map<java.lang.String,​CmsResource> fileLookup,
                                              <java.lang.String,​java.lang.String> relationTargets)
        Checks a link to a resource which has been deleted.

        relation -
        link - the URI of the resource which has a link to the deleted resource
        fileLookup - a lookup table of files to be published
        relationTargets -
        true if the resource which has a link to the deleted resource is also going to be deleted
      • checkLinkForNewOrChangedLinkSource

        protected boolean checkLinkForNewOrChangedLinkSource​(CmsDbContext dbc,
                                                             CmsResource resource,
                                                             CmsRelation relation,
                                                             java.lang.String link,
                                                             CmsProject project,
                                                             java.util.Map<java.lang.String,​CmsResource> fileLookup)
        Checks a link from a resource which has changed.

        dbc - the current dbc
        resource - the link source
        relation - the relation
        link - the link target
        project - the current project
        fileLookup - a lookup table which contains the files which are going to be published
        true if the link will be valid after publishing
      • validateLinks

        protected java.util.List<CmsRelationvalidateLinks​(CmsDbContext dbc,
                                                            CmsResource resource,
                                                            java.util.Map<java.lang.String,​CmsResource> fileLookup,
                                                            CmsProject project,
                                                            I_CmsReport report)
        Validates the links for the specified resource.

        dbc - the database context
        resource - the resource that will be validated
        fileLookup - a map for faster lookup with all resources keyed by their rootpath
        project - the project to validate
        report - the report to write to
        a list with the broken links as CmsRelation objects for the specified resource, or an empty list if no broken links were found