Class UploadedDataHTMLEditionHandler
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.cms.transformation.htmledition.AbstractHTMLEditionHandler
-
- org.ametys.cms.transformation.htmledition.UploadedDataHTMLEditionHandler
-
- All Implemented Interfaces:
Contextualizable
,LogEnabled
,Serviceable
,ContentHandler
,LexicalHandler
public class UploadedDataHTMLEditionHandler extends AbstractHTMLEditionHandler
This transformer extracts uploaded files' ids from the incoming HTML for further processing.
-
-
Field Summary
Fields Modifier and Type Field Description private static Pattern
__INLINE_IMAGE_MARKER
private AmetysObjectResolver
_ametysResolver
private Context
_cocoonContext
private Map
_objectModel
private SourceResolver
_resolver
private ModifiableRichText
_richText
private boolean
_tagToIgnore
private UploadManager
_uploadManager
private Set<String>
_usedLocalFiles
private CurrentUserProvider
_userProvider
-
Fields inherited from class org.ametys.cms.transformation.htmledition.AbstractHTMLEditionHandler
_contentHandler, _context, _lexicalHandler, _manager
-
-
Constructor Summary
Constructors Constructor Description UploadedDataHTMLEditionHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_addDimensionAttributes(InputStream inputStream, AttributesImpl attrs)
Add an image's width and height to the XML attributes.private void
_copyAttributes(Attributes attrs, AttributesImpl newAttrs)
Copy the attributes.private Attributes
_getAttributesForTemp(Attributes attrs)
private String
_getInitialFileName(String src)
protected RichText
_getMeta(CompositeMetadata meta, String metadataName)
Get the rich text metaprivate StringBuilder
_getRequestURI(Request request)
Get the cms uriprivate String
_handleInternalFile(String src, AttributesImpl newAttrs, String initialFileName)
private String
_handleRemoteFile(String src, AttributesImpl newAttrs, String initialFileName)
protected Attributes
_processLocal(Attributes attrs)
Process a local file.protected Attributes
_processResource(Attributes attrs)
Process a resource.protected String
_storeFile(String initialFileName, InputStream is, String mimeType, Date lastModified)
Store a file as rich text data.void
contextualize(Context context)
void
endDocument()
void
endElement(String uri, String loc, String raw)
void
service(ServiceManager sManager)
void
startDocument()
void
startElement(String uri, String loc, String raw, Attributes attrs)
-
Methods inherited from class org.ametys.cms.transformation.htmledition.AbstractHTMLEditionHandler
characters, comment, endCDATA, endDTD, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setContentHandler, setDocumentLocator, setLexicalHandler, skippedEntity, startCDATA, startDTD, startEntity, startPrefixMapping
-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
__INLINE_IMAGE_MARKER
private static final Pattern __INLINE_IMAGE_MARKER
-
_uploadManager
private UploadManager _uploadManager
-
_userProvider
private CurrentUserProvider _userProvider
-
_resolver
private SourceResolver _resolver
-
_ametysResolver
private AmetysObjectResolver _ametysResolver
-
_cocoonContext
private Context _cocoonContext
-
_tagToIgnore
private boolean _tagToIgnore
-
_usedLocalFiles
private Set<String> _usedLocalFiles
-
_richText
private ModifiableRichText _richText
-
_objectModel
private Map _objectModel
-
-
Constructor Detail
-
UploadedDataHTMLEditionHandler
public UploadedDataHTMLEditionHandler()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Overrides:
contextualize
in classAbstractHTMLEditionHandler
- Throws:
ContextException
-
service
public void service(ServiceManager sManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractHTMLEditionHandler
- Throws:
ServiceException
-
startDocument
public void startDocument() throws SAXException
- Specified by:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classAbstractHTMLEditionHandler
- Throws:
SAXException
-
startElement
public void startElement(String uri, String loc, String raw, Attributes attrs) throws SAXException
- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classAbstractHTMLEditionHandler
- Throws:
SAXException
-
_getInitialFileName
private String _getInitialFileName(String src)
-
_handleInternalFile
private String _handleInternalFile(String src, AttributesImpl newAttrs, String initialFileName) throws MalformedURLException, IOException, URISyntaxException
-
_handleRemoteFile
private String _handleRemoteFile(String src, AttributesImpl newAttrs, String initialFileName) throws MalformedURLException, IOException
- Throws:
MalformedURLException
IOException
-
_copyAttributes
private void _copyAttributes(Attributes attrs, AttributesImpl newAttrs)
Copy the attributes.- Parameters:
attrs
- the attributes to copy.newAttrs
- the attributes to copy to.
-
_getRequestURI
private StringBuilder _getRequestURI(Request request)
Get the cms uri- Parameters:
request
- The request- Returns:
- the uri without context path
-
_getAttributesForTemp
private Attributes _getAttributesForTemp(Attributes attrs)
-
_storeFile
protected String _storeFile(String initialFileName, InputStream is, String mimeType, Date lastModified)
Store a file as rich text data.- Parameters:
initialFileName
- the initial file name.is
- an input stream on the file.mimeType
- the file mime type.lastModified
- the last modification date.- Returns:
- the final file name.
-
_processLocal
protected Attributes _processLocal(Attributes attrs)
Process a local file.- Parameters:
attrs
- the img tag attributes.- Returns:
- the new img tag attributes.
-
_processResource
protected Attributes _processResource(Attributes attrs)
Process a resource.- Parameters:
attrs
- the img tag attributes.- Returns:
- the new img tag attributes.
-
_addDimensionAttributes
protected void _addDimensionAttributes(InputStream inputStream, AttributesImpl attrs) throws IOException
Add an image's width and height to the XML attributes.- Parameters:
inputStream
- an input stream on the image.attrs
- the attributes to fill.- Throws:
IOException
- if an error occurs during reading dimension
-
endElement
public void endElement(String uri, String loc, String raw) throws SAXException
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classAbstractHTMLEditionHandler
- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXException
- Specified by:
endDocument
in interfaceContentHandler
- Overrides:
endDocument
in classAbstractHTMLEditionHandler
- Throws:
SAXException
-
_getMeta
protected RichText _getMeta(CompositeMetadata meta, String metadataName)
Get the rich text meta- Parameters:
meta
- The composite metametadataName
- The metadata name (with /)- Returns:
- The rich text meta
-
-