Package org.opencms.relations
Class CmsRelationSystemValidator
java.lang.Object
org.opencms.relations.CmsRelationSystemValidator
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
-
Constructor Summary
ConstructorDescriptionCmsRelationSystemValidator
(CmsDriverManager driverManager) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
checkLinkForDeletedLinkTarget
(CmsRelation relation, 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 List<CmsRelation>
validateLinks
(CmsDbContext dbc, CmsResource resource, Map<String, CmsResource> fileLookup, CmsProject project, I_CmsReport report) Validates the links for the specified resource.validateResources
(CmsDbContext dbc, CmsPublishList publishList, I_CmsReport report) Validates the relations against the online project.
-
Field Details
-
m_driverManager
The driver manager.
-
-
Constructor Details
-
CmsRelationSystemValidator
Default constructor.- Parameters:
driverManager
- The Cms driver manager
-
-
Method Details
-
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 contextpublishList
- the publish list to validatereport
- a report to print messages- Returns:
- a map with lists of invalid links
(
objects) keyed by root pathsCmsRelation
} - Throws:
Exception
- if something goes wrong
-
checkLinkForDeletedLinkTarget
protected boolean checkLinkForDeletedLinkTarget(CmsRelation relation, String link, Map<String, CmsResource> fileLookup) Checks a link to a resource which has been deleted.- Parameters:
relation
-link
- the URI of the resource which has a link to the deleted resourcefileLookup
- a lookup table of files to be publishedrelationTargets
-- 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 dbcresource
- the link sourcerelation
- the relationlink
- the link targetproject
- the current projectfileLookup
- a lookup table which contains the files which are going to be published- Returns:
- true if the link will be valid after publishing
-
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 contextresource
- the resource that will be validatedfileLookup
- a map for faster lookup with all resources keyed by their rootpathproject
- the project to validatereport
- 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
-