Package org.ametys.cms.content
Class ContentSaxer
- java.lang.Object
-
- org.ametys.cms.content.ContentSaxer
-
- All Implemented Interfaces:
Component
,Serviceable
- Direct Known Subclasses:
ContentSaxer
public class ContentSaxer extends Object implements Serviceable, Component
Component responsible for generating SAX events representing aContent
.
-
-
Field Summary
Fields Modifier and Type Field Description private LanguagesManager
_languageManager
private UserHelper
_userHelper
private WorkflowProvider
_workflowProvider
private WorkflowHelper
_worklflowHelper
static String
ROLE
Avalon role.
-
Constructor Summary
Constructors Constructor Description ContentSaxer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
_addJcrAttributes(JCRAmetysObject content, AttributesImpl attrs)
private void
_saxContentTypes(Content content, ContentHandler contentHandler)
private void
_saxMixins(Content content, ContentHandler contentHandler)
protected Boolean
booleanValue(org.apache.xpath.objects.XObject xObject)
Consumes anXObject
to retrieve the value as aBoolean
protected Date
dateValue(org.apache.xpath.objects.XObject xObject)
Consumes anXObject
to retrieve the value as aDate
protected void
fillAttributes(ModifiableContent content, Node contentNode, XMLValuesExtractorAdditionalDataGetter additionalDataGetter)
Fills the given content with the attributes from the providedNode
protected void
fillComment(Comment comment, Node commentNode)
Fills the given comment with the values from the providedNode
void
fillContent(ModifiableContent content, Node node, XMLValuesExtractorAdditionalDataGetter additionalDataGetter)
Fills the given content with the values from the providedNode
.protected void
fillContentComments(CommentableContent content, Node contentNode)
Fills the given content with the comments from the providedNode
protected void
fillDublinCore(ModifiableDublinCoreAwareAmetysObject dcObject, Node node)
Fills the given object with the dublin core values from the providedNode
.protected void
fillReactions(ReactionableObject reactionable, Node node)
Fills the givenReactionableObject
with the reactions from the providedNode
protected void
fillReports(ReportableObject reportable, Node node)
Fills the givenReportableObject
with the reports from the providedNode
protected com.opensymphony.workflow.spi.Step
getCurrentStep(WorkflowAwareContent content, WorkflowProvider.AmetysObjectWorkflow workflow)
Get the current workflow step of the content.protected void
saxAttributes(Content content, ContentHandler contentHandler, Locale locale, View view, String tagName, String attributesTagName)
Generates SAX events for actual content's data.protected void
saxBody(Content content, ContentHandler contentHandler, Locale locale, View view, String tagName, boolean saxWorkflowStep, boolean saxWorkflowInfo, boolean saxLanguageInfo, String attributesTagName)
Generates SAX events for the content data.protected void
saxComment(Comment comment, int level, ContentHandler contentHandler)
Generates SAX events for a single comment.protected void
saxComments(List<Comment> comments, String elementName, int level, ContentHandler contentHandler)
Generates SAX events for comments.void
saxContent(Content content, ContentHandler contentHandler, Locale locale, View view, String tagName, boolean saxWorkflowStep, boolean saxWorkflowInfo, boolean saxLanguageInfo, String attributesTagName)
Generates SAX events representing aContent
.protected void
saxContentComments(CommentableContent content, ContentHandler contentHandler)
Generates SAX events for content's comments.protected void
saxContentTypes(Content content, ContentHandler contentHandler, boolean saxMixins)
Generates SAX events forcontent types
, and possiblymixin types
protected void
saxDublinCoreMetadata(DublinCoreAwareAmetysObject dcObject, ContentHandler contentHandler)
Generates SAX events for the DC metadata.protected void
saxIfNotNull(String name, String[] values, ContentHandler contentHandler)
Send values if not null.protected void
saxIfNotNull(String name, String value, ContentHandler contentHandler)
Send a value if not null.protected void
saxIfNotNull(String name, Date value, ContentHandler contentHandler)
Send a value if not null.protected void
saxLanguage(Content content, ContentHandler contentHandler)
Generates SAX events for the content's language.protected void
saxReactions(ReactionableObject reactionable, ContentHandler contentHandler)
Generates SAX events for the given object's reactions.protected void
saxReports(ReportableObject reportable, ContentHandler contentHandler)
Generates SAX events for the given object's reports.protected void
saxRootTag(Content content, ContentHandler contentHandler, Locale locale, String tagName)
Generates a surrounding tag, with content metadata.protected void
saxWorkflowStep(Content content, ContentHandler contentHandler, boolean saxWorkflowInfo)
Generates SAX events representing the current workflow step.void
service(ServiceManager manager)
protected <T> void
setIfNotNull(Node node, String expression, LambdaUtils.ThrowingFunction<org.apache.xpath.objects.XObject,T> retriever, Consumer<T> setter)
Sets a value through the given setter if the value is not nullprotected String[]
values(org.apache.xpath.objects.XObject xObject)
Consumes anXObject
to retrieve the value as a String array
-
-
-
Field Detail
-
_workflowProvider
private WorkflowProvider _workflowProvider
-
_worklflowHelper
private WorkflowHelper _worklflowHelper
-
_languageManager
private LanguagesManager _languageManager
-
_userHelper
private UserHelper _userHelper
-
-
Constructor Detail
-
ContentSaxer
public ContentSaxer()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
saxContent
public void saxContent(Content content, ContentHandler contentHandler, Locale locale, View view, String tagName, boolean saxWorkflowStep, boolean saxWorkflowInfo, boolean saxLanguageInfo, String attributesTagName) throws SAXException
Generates SAX events representing aContent
.
When called with a non null tag name, a surrounding element will be generated, along with XML attributes representing the content's metadata (creation/modification/validation dates and authors, ...).- Parameters:
content
- theContent
.contentHandler
- the ContentHandler receving SAX events.locale
- theLocale
to use for eg. multilingual attributes.view
- the View or null to select all attributes.tagName
- the surrounding tag name or null to SAX events without root tag.saxWorkflowStep
- if true, also produces SAX events for the current workflow step.saxWorkflowInfo
- if true, also produces SAX events for detailed information about the current workflow step.saxLanguageInfo
- if true, also produces SAX events for detailed information about the content language.attributesTagName
- the name of the tag surrounding attributes. Used for legacy purposes.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxBody
protected void saxBody(Content content, ContentHandler contentHandler, Locale locale, View view, String tagName, boolean saxWorkflowStep, boolean saxWorkflowInfo, boolean saxLanguageInfo, String attributesTagName) throws SAXException
Generates SAX events for the content data.- Parameters:
content
- theContent
.contentHandler
- the ContentHandler receving SAX events.locale
- theLocale
to use for eg. multilingual attributes.view
- the View or null to select all attributes.tagName
- the surrounding tag name or null to SAX events without root tag.saxWorkflowStep
- if true, also produces SAX events for the current workflow step.saxWorkflowInfo
- if true, also produces SAX events for detailed information about the current workflow step.saxLanguageInfo
- if true, also produces SAX events for detailed information about the content language.attributesTagName
- the name of the tag surrounding attributes. Used for legacy purposes.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxRootTag
protected void saxRootTag(Content content, ContentHandler contentHandler, Locale locale, String tagName) throws SAXException
Generates a surrounding tag, with content metadata.- Parameters:
content
- theContent
.contentHandler
- the ContentHandler receving SAX events.locale
- theLocale
to use for eg. multilingual attributes.tagName
- the surrounding tag name or null to SAX events without root tag.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
_addJcrAttributes
private void _addJcrAttributes(JCRAmetysObject content, AttributesImpl attrs)
-
saxContentTypes
protected void saxContentTypes(Content content, ContentHandler contentHandler, boolean saxMixins) throws SAXException
Generates SAX events forcontent types
, and possiblymixin types
- Parameters:
content
- theContent
.contentHandler
- the ContentHandler receving SAX events.saxMixins
- if true, also produces SAX events formixin types
.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
_saxContentTypes
private void _saxContentTypes(Content content, ContentHandler contentHandler) throws SAXException
- Throws:
SAXException
-
_saxMixins
private void _saxMixins(Content content, ContentHandler contentHandler) throws SAXException
- Throws:
SAXException
-
saxAttributes
protected void saxAttributes(Content content, ContentHandler contentHandler, Locale locale, View view, String tagName, String attributesTagName) throws SAXException
Generates SAX events for actual content's data.- Parameters:
content
- theContent
.contentHandler
- the ContentHandler receving SAX events.locale
- theLocale
to use for eg. multilingual attributes.view
- the View or null to select all attributes.tagName
- the surrounding tag name or null to SAX events without root tag.attributesTagName
- the name of the tag surrounding attributes. Used for legacy purposes.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxWorkflowStep
protected void saxWorkflowStep(Content content, ContentHandler contentHandler, boolean saxWorkflowInfo) throws SAXException
Generates SAX events representing the current workflow step.- Parameters:
content
- theContent
.contentHandler
- the ContentHandler receving SAX events.saxWorkflowInfo
- if true, also produces SAX events for detailed information about the current workflow step.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
getCurrentStep
protected com.opensymphony.workflow.spi.Step getCurrentStep(WorkflowAwareContent content, WorkflowProvider.AmetysObjectWorkflow workflow) throws com.opensymphony.workflow.WorkflowException
Get the current workflow step of the content.- Parameters:
content
- theContent
.workflow
- the associated workflow.- Returns:
- the current step
- Throws:
com.opensymphony.workflow.WorkflowException
- if somethng got wrong processing workflow data.
-
saxLanguage
protected void saxLanguage(Content content, ContentHandler contentHandler) throws SAXException
Generates SAX events for the content's language.- Parameters:
content
- theContent
.contentHandler
- the ContentHandler receving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxDublinCoreMetadata
protected void saxDublinCoreMetadata(DublinCoreAwareAmetysObject dcObject, ContentHandler contentHandler) throws SAXException
Generates SAX events for the DC metadata.- Parameters:
dcObject
- theContent
.contentHandler
- the ContentHandler receving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxIfNotNull
protected void saxIfNotNull(String name, String value, ContentHandler contentHandler) throws SAXException
Send a value if not null.- Parameters:
name
- the tag name.value
- the value.contentHandler
- the ContentHandler receving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxIfNotNull
protected void saxIfNotNull(String name, String[] values, ContentHandler contentHandler) throws SAXException
Send values if not null.- Parameters:
name
- the tag name.values
- the values.contentHandler
- the ContentHandler receving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxIfNotNull
protected void saxIfNotNull(String name, Date value, ContentHandler contentHandler) throws SAXException
Send a value if not null.- Parameters:
name
- the tag name.value
- the value.contentHandler
- the ContentHandler receving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxContentComments
protected void saxContentComments(CommentableContent content, ContentHandler contentHandler) throws SAXException
Generates SAX events for content's comments.- Parameters:
content
- theContent
.contentHandler
- the ContentHandler receving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxComments
protected void saxComments(List<Comment> comments, String elementName, int level, ContentHandler contentHandler) throws SAXException
Generates SAX events for comments.- Parameters:
comments
- the comments.elementName
- the tag name.level
- the comments level.contentHandler
- the ContentHandler receving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxComment
protected void saxComment(Comment comment, int level, ContentHandler contentHandler) throws SAXException
Generates SAX events for a single comment.- Parameters:
comment
- the comment.level
- the comment level.contentHandler
- the ContentHandler receving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxReactions
protected void saxReactions(ReactionableObject reactionable, ContentHandler contentHandler) throws SAXException
Generates SAX events for the given object's reactions.- Parameters:
reactionable
- theReactionableObject
.contentHandler
- the ContentHandler receiving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
saxReports
protected void saxReports(ReportableObject reportable, ContentHandler contentHandler) throws SAXException
Generates SAX events for the given object's reports.- Parameters:
reportable
- theContent
.contentHandler
- the ContentHandler receiving SAX events.- Throws:
SAXException
- if an error occurs during the SAX events generation.
-
fillContent
public void fillContent(ModifiableContent content, Node node, XMLValuesExtractorAdditionalDataGetter additionalDataGetter) throws Exception
Fills the given content with the values from the providedNode
.
This is the anti-operation ofsaxContent(org.ametys.cms.repository.Content, org.xml.sax.ContentHandler, java.util.Locale, org.ametys.runtime.model.View, java.lang.String, boolean, boolean, boolean, java.lang.String)
, as the org.w3c.dom.Node should be a Node previously generated with SAX events from this method.- Parameters:
content
- The content to fillnode
- The node to read for retrieving values to filladditionalDataGetter
- The object that will retrieve potential additional data for the content's attributes- Throws:
Exception
- if an exception occurs
-
fillDublinCore
protected void fillDublinCore(ModifiableDublinCoreAwareAmetysObject dcObject, Node node) throws Exception
Fills the given object with the dublin core values from the providedNode
.- Parameters:
dcObject
- The object to fillnode
- The node to read to get the values to fill- Throws:
Exception
- if an exception occurs
-
fillContentComments
protected void fillContentComments(CommentableContent content, Node contentNode) throws Exception
Fills the given content with the comments from the providedNode
- Parameters:
content
- The content to fillcontentNode
- the node to read to get the comments' values- Throws:
Exception
- if an error occurs
-
fillComment
protected void fillComment(Comment comment, Node commentNode) throws Exception
Fills the given comment with the values from the providedNode
- Parameters:
comment
- The comment to fillcommentNode
- the node to read to get the comment's values- Throws:
Exception
- if an error occurs
-
fillReactions
protected void fillReactions(ReactionableObject reactionable, Node node) throws Exception
Fills the givenReactionableObject
with the reactions from the providedNode
- Parameters:
reactionable
- TheReactionableObject
to fillnode
- the node to read to get the reactions- Throws:
Exception
- if an error occurs
-
fillReports
protected void fillReports(ReportableObject reportable, Node node) throws Exception
Fills the givenReportableObject
with the reports from the providedNode
- Parameters:
reportable
- TheReportableObject
to fillnode
- the node to read to get the reports- Throws:
Exception
- if an error occurs
-
fillAttributes
protected void fillAttributes(ModifiableContent content, Node contentNode, XMLValuesExtractorAdditionalDataGetter additionalDataGetter) throws Exception
Fills the given content with the attributes from the providedNode
- Parameters:
content
- The content to fillcontentNode
- the node to read to get the attributesadditionalDataGetter
- The object that will retrieve potential additional data for the content's attributes- Throws:
Exception
- if an error occurs
-
setIfNotNull
protected <T> void setIfNotNull(Node node, String expression, LambdaUtils.ThrowingFunction<org.apache.xpath.objects.XObject,T> retriever, Consumer<T> setter) throws Exception
Sets a value through the given setter if the value is not null- Type Parameters:
T
- The type of the value to set- Parameters:
node
- The node to read to get the valueexpression
- The expression to apply on the node to get the valueretriever
- TheFunction
that will retrieve the typed value from theXObject
evaluated from the expressionsetter
- TheConsumer
that will be used to set the value- Throws:
Exception
- if an error occurs
-
dateValue
protected Date dateValue(org.apache.xpath.objects.XObject xObject)
Consumes anXObject
to retrieve the value as aDate
- Parameters:
xObject
- The consumedXObject
- Returns:
- The
Date
value
-
booleanValue
protected Boolean booleanValue(org.apache.xpath.objects.XObject xObject)
Consumes anXObject
to retrieve the value as aBoolean
- Parameters:
xObject
- The consumedXObject
- Returns:
- The
Boolean
value
-
values
protected String[] values(org.apache.xpath.objects.XObject xObject) throws TransformerException
Consumes anXObject
to retrieve the value as a String array- Parameters:
xObject
- The consumedXObject
- Returns:
- The String array
- Throws:
TransformerException
- if an error occurs
-
-