Package org.ametys.cms.content.compare
Class ContentComparator
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.cms.content.compare.ContentComparator
-
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
public class ContentComparator extends AbstractLogEnabled implements Component, Serviceable
Object used to compare two contents
-
-
Field Summary
Fields Modifier and Type Field Description private ContentTypesHelper
_contentTypesHelper
static String
ROLE
The Avalon role
-
Constructor Summary
Constructors Constructor Description ContentComparator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
_checkAttributePresence(ContentComparatorResult result, Content content1, Content content2, String attributeDataPath, boolean logChange)
Check if an attribute is present in both contents and add a change if requestedprivate ContentComparatorResult
_compare(Content content1, Content content2, String viewName, boolean strictCompare)
private void
_compareAttribute(ContentComparatorResult result, Content content1, Content content2, ElementDefinition<?> definition, String attributeDataPath)
Compare 2 attributesprivate void
_compareAttributes(ContentComparatorResult result, Content content1, Content content2, ViewItem viewItem, String parentDataPath)
Compare 2 attributes and add the differences in resultprivate void
_compareComposite(ContentComparatorResult result, ModelViewItemGroup viewItemGroup, Content content1, Content content2, ModelItem definition, String compositeDataPath)
Compare 2 compositesprivate void
_compareRepeater(ContentComparatorResult result, ModelViewItemGroup viewItemGroup, Content content1, Content content2, ModelItem definition, String repeaterDataPath)
Compare 2 repeatersprivate String
_concatAttributeDataPathSegments(String... segments)
private View
_generateView(String viewName, Content content)
Generate a view using a name (can be null) and a contentContentComparatorResult
compare(Content content1, Content content2)
Compare 2 contents, for all their common attributes (contents with different contentTypes are rejected)ContentComparatorResult
compare(Content content1, Content content2, boolean strictCompare)
Compare 2 contents, for all their common attributesContentComparatorResult
compare(Content content1, Content content2, String viewName)
Compare 2 contents, filtering with a view (contents with different contentTypes are rejected)ContentComparatorResult
compare(Content content1, Content content2, String viewName, boolean strictCompare)
Compare 2 contents, filtering with a viewvoid
service(ServiceManager manager)
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_contentTypesHelper
private ContentTypesHelper _contentTypesHelper
-
-
Constructor Detail
-
ContentComparator
public ContentComparator()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
compare
public ContentComparatorResult compare(Content content1, Content content2) throws AmetysRepositoryException, IOException
Compare 2 contents, for all their common attributes (contents with different contentTypes are rejected)- Parameters:
content1
- 1st contentcontent2
- new content- Returns:
ContentComparatorResult
- Throws:
AmetysRepositoryException
- repository exceptionIOException
- IO exception
-
compare
public ContentComparatorResult compare(Content content1, Content content2, boolean strictCompare) throws AmetysRepositoryException, IOException
Compare 2 contents, for all their common attributes- Parameters:
content1
- 1st contentcontent2
- new contentstrictCompare
- true to reject contents with different content types- Returns:
ContentComparatorResult
- Throws:
AmetysRepositoryException
- repository exceptionIOException
- IO exception
-
compare
public ContentComparatorResult compare(Content content1, Content content2, String viewName) throws AmetysRepositoryException, IOException
Compare 2 contents, filtering with a view (contents with different contentTypes are rejected)- Parameters:
content1
- 1st contentcontent2
- new contentviewName
- name of the view- Returns:
ContentComparatorResult
- Throws:
AmetysRepositoryException
- repository exceptionIOException
- IO exception
-
compare
public ContentComparatorResult compare(Content content1, Content content2, String viewName, boolean strictCompare) throws AmetysRepositoryException, IOException
Compare 2 contents, filtering with a view- Parameters:
content1
- 1st contentcontent2
- new contentviewName
- name of the viewstrictCompare
- true to reject contents with different content types- Returns:
ContentComparatorResult
- Throws:
AmetysRepositoryException
- repository exceptionIOException
- IO exception
-
_compare
private ContentComparatorResult _compare(Content content1, Content content2, String viewName, boolean strictCompare) throws AmetysRepositoryException, IOException
- Throws:
AmetysRepositoryException
IOException
-
_generateView
private View _generateView(String viewName, Content content)
Generate a view using a name (can be null) and a content- Parameters:
viewName
- name of the view. If null, a __generated__ view will be created using all content's attributescontent
- content where the view should be retrieved- Returns:
View
from the name, or generated
-
_compareAttributes
private void _compareAttributes(ContentComparatorResult result, Content content1, Content content2, ViewItem viewItem, String parentDataPath) throws AmetysRepositoryException, IOException
Compare 2 attributes and add the differences in result- Parameters:
result
- global result where differences will be storedcontent1
- 1st contentcontent2
- 2nd contentviewItem
- view item that will be comparedparentDataPath
- absolute data path of the container of the current view item- Throws:
AmetysRepositoryException
- repository exceptionIOException
- IO Exception (comparison of InputStream mainly)
-
_checkAttributePresence
private boolean _checkAttributePresence(ContentComparatorResult result, Content content1, Content content2, String attributeDataPath, boolean logChange)
Check if an attribute is present in both contents and add a change if requested- Parameters:
result
- The resultcontent1
- 1st contentcontent2
- 2nd contentattributeDataPath
- absolute path of the data to check (also used to log)logChange
- true to add a change in the list (if one has it and the other doesn't)- Returns:
- true if both contents have the node
-
_compareComposite
private void _compareComposite(ContentComparatorResult result, ModelViewItemGroup viewItemGroup, Content content1, Content content2, ModelItem definition, String compositeDataPath) throws AmetysRepositoryException, IOException
Compare 2 composites- Parameters:
result
- global result where differences will be storedviewItemGroup
- view item of the current compositecontent1
- 1st contentcontent2
- 2nd contentdefinition
- definition of the compositecompositeDataPath
- absolute data path of the current composite- Throws:
AmetysRepositoryException
- repository exceptionIOException
- IO Exception
-
_compareRepeater
private void _compareRepeater(ContentComparatorResult result, ModelViewItemGroup viewItemGroup, Content content1, Content content2, ModelItem definition, String repeaterDataPath) throws AmetysRepositoryException, IOException
Compare 2 repeaters- Parameters:
result
- global result where differences will be storedviewItemGroup
- view item of the current repeatercontent1
- 1st contentcontent2
- 2nd contentdefinition
- definition of the repeaterrepeaterDataPath
- absolute data path of the current repeater- Throws:
AmetysRepositoryException
- repository exceptionIOException
- IO Exception
-
_compareAttribute
private void _compareAttribute(ContentComparatorResult result, Content content1, Content content2, ElementDefinition<?> definition, String attributeDataPath) throws AmetysRepositoryException, IOException
Compare 2 attributes- Parameters:
result
- global result where differences will be storedcontent1
- 1st contentcontent2
- 2nd contentdefinition
- definition of the attributeattributeDataPath
- absolute data path of the current attribute- Throws:
AmetysRepositoryException
- repository exceptionIOException
- IO Exception
-
_concatAttributeDataPathSegments
private String _concatAttributeDataPathSegments(String... segments)
-
-