org.opencms.relations
Class CmsRelationSystemValidator

java.lang.Object
  extended by org.opencms.relations.CmsRelationSystemValidator

public class CmsRelationSystemValidator
extends 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.

Since:
6.3.0

Field Summary
protected  CmsDriverManager m_driverManager
          The driver manager.
 
Constructor Summary
CmsRelationSystemValidator(CmsDriverManager driverManager)
          Default constructor.
 
Method Summary
protected  boolean checkLinkForDeletedLinkTarget(String link, Map<String,CmsResource> fileLookup)
          Checks a link to a resource which has been deleted.
protected  boolean checkLinkForNewOrChangedLinkSource(CmsDbContext dbc, CmsResource resource, CmsRelation relation, String link, CmsProject project, Map<String,CmsResource> fileLookup)
          Checks a link from a resource which has changed.
protected  boolean checkLinkValid(CmsDbContext dbc, CmsResource resource, CmsRelation relation, String link, CmsProject project, Map<String,CmsResource> fileLookup)
          Checks whether publishing will not invalidate a link.
protected  List<CmsRelation> getLinkRelations(CmsDbContext dbc, CmsProject project, CmsResource resource)
          Returns the list of link relations for a resource.
protected  List<CmsRelation> validateLinks(CmsDbContext dbc, CmsResource resource, Map<String,CmsResource> fileLookup, CmsProject project, I_CmsReport report)
          Validates the links for the specified resource.
 Map<String,List<CmsRelation>> validateResources(CmsDbContext dbc, CmsPublishList publishList, I_CmsReport report)
          Validates the relations against the online project.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_driverManager

protected CmsDriverManager m_driverManager
The driver manager.

Constructor Detail

CmsRelationSystemValidator

public CmsRelationSystemValidator(CmsDriverManager driverManager)
Default constructor.

Parameters:
driverManager - The Cms driver manager
Method Detail

validateResources

public Map<String,List<CmsRelation>> validateResources(CmsDbContext dbc,
                                                       CmsPublishList publishList,
                                                       I_CmsReport report)
                                                throws 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.

Parameters:
dbc - the database context
publishList - the publish list to validate
report - a report to print messages
Returns:
a map with lists of invalid links (CmsRelation} objects) keyed by root paths
Throws:
Exception - if something goes wrong

checkLinkForDeletedLinkTarget

protected boolean checkLinkForDeletedLinkTarget(String link,
                                                Map<String,CmsResource> fileLookup)
Checks a link to a resource which has been deleted.

Parameters:
link - the URI of the resource which has a link to the deleted resource
fileLookup - a lookup table of files to be published
Returns:
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,
                                                     String link,
                                                     CmsProject project,
                                                     Map<String,CmsResource> fileLookup)
Checks a link from a resource which has changed.

Parameters:
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
sitemapCache -
Returns:
true if the link will be valid after publishing

checkLinkValid

protected boolean checkLinkValid(CmsDbContext dbc,
                                 CmsResource resource,
                                 CmsRelation relation,
                                 String link,
                                 CmsProject project,
                                 Map<String,CmsResource> fileLookup)
Checks whether publishing will not invalidate a link.

Parameters:
dbc - the current dbc
resource - the target resource of the link if it is going to be deleted, else the source of the link
relation - the relation which should be checked
link - the link URI
project - the current project
fileLookup - a lookup table which contains the files which are going to be published
sitemapCache -
Returns:
true if there will be no invalid link after publishing

getLinkRelations

protected List<CmsRelation> getLinkRelations(CmsDbContext dbc,
                                             CmsProject project,
                                             CmsResource resource)
                                      throws CmsException
Returns the list of link relations for a resource.

If the resource is going to be deleted, the ingoing relations will be collected, else the outgoing relations.

Parameters:
dbc - the current database context
project - the project to use
resource - the resource for which the relations should be collected
Returns:
a list of relations
Throws:
CmsException - if something goes wrong

validateLinks

protected List<CmsRelation> validateLinks(CmsDbContext dbc,
                                          CmsResource resource,
                                          Map<String,CmsResource> fileLookup,
                                          CmsProject project,
                                          I_CmsReport report)
Validates the links for the specified resource.

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